// Tweaks for the translucent top bar (running head + control pills).
// Defaults preserve the just-shipped translucent look; users can dial things
// up/down or fall back to the original solid pills.

const TWEAK_DEFAULTS = {
  fadeStrength: 100,     // % opacity of the top gradient fade
  fadeHeight: 88,        // px tall — how far the fade reaches down the page
  pillBlur: 16,          // px backdrop-filter blur on the pills
  pillStyle: 'glass',    // 'glass' | 'solid' | 'outline'
  runningHeadBg: 'none', // 'none' | 'glass'  — give the "Freedman, A." mark its own chip
};

function applyTweaks(t) {
  const root = document.documentElement;
  root.style.setProperty('--top-fade-strength', String(Math.max(0, Math.min(1, t.fadeStrength / 100))));
  root.style.setProperty('--top-fade-height', `${t.fadeHeight}px`);
  root.style.setProperty('--top-pill-blur', `${t.pillBlur}px`);
  root.setAttribute('data-pill-style', t.pillStyle);
  root.setAttribute('data-running-head-bg', t.runningHeadBg);
}

function TweaksApp() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);

  React.useEffect(() => { applyTweaks(t); }, [t]);

  return (
    <TweaksPanel title="Tweaks">
      <TweakSection label="Top fade" />
      <TweakSlider
        label="Fade strength"
        value={t.fadeStrength} min={0} max={100} step={5} unit="%"
        onChange={(v) => setTweak('fadeStrength', v)}
      />
      <TweakSlider
        label="Fade height"
        value={t.fadeHeight} min={40} max={180} step={4} unit="px"
        onChange={(v) => setTweak('fadeHeight', v)}
      />

      <TweakSection label="Pills" />
      <TweakRadio
        label="Style"
        value={t.pillStyle}
        options={['glass', 'solid', 'outline']}
        onChange={(v) => setTweak('pillStyle', v)}
      />
      <TweakSlider
        label="Blur"
        value={t.pillBlur} min={0} max={32} step={1} unit="px"
        onChange={(v) => setTweak('pillBlur', v)}
      />

      <TweakSection label="Running head" />
      <TweakRadio
        label="Background"
        value={t.runningHeadBg}
        options={['none', 'glass']}
        onChange={(v) => setTweak('runningHeadBg', v)}
      />
    </TweaksPanel>
  );
}

const __twkMount = document.createElement('div');
document.body.appendChild(__twkMount);
ReactDOM.createRoot(__twkMount).render(<TweaksApp />);
