/* Direction B — "Lab Console / Cognitive Instrument"
   The website IS the lab. A research monitoring console:
   live signal feed, episodes as numbered "experiments",
   terminal-driven question deconstruction.
   Less cinematic, more instrument. */

const B_W = 1440;

function BHeader({ accent }) {
  const [t, setT] = React.useState(new Date());
  React.useEffect(() => {
    const i = setInterval(() => setT(new Date()), 1000);
    return () => clearInterval(i);
  }, []);
  const stamp = t.toISOString().replace('T', ' ').slice(0, 19) + ' UTC';
  return (
    <div style={{
      borderBottom: '1px solid var(--tql-line-2)',
      background: '#08080B',
      fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.12em',
      color: 'rgba(255,255,255,0.65)',
    }}>
      {/* Top status strip */}
      <div style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 24px', borderBottom: '1px solid var(--tql-line)' }}>
        <div style={{ display: 'flex', gap: 22 }}>
          <span style={{ color: accent || 'var(--tql-accent)' }} className="pulse">● ONLINE</span>
          <span>SYSTEM: TQL-MAIN/0.42</span>
          <span>SESSION: {stamp}</span>
        </div>
        <div style={{ display: 'flex', gap: 22 }}>
          <span>USER: anon-{(Math.floor(Math.random()*99999)).toString(36)}</span>
          <span>LOCALE: EN-US</span>
          <span style={{ color: '#fff' }}>[ ?HELP ]</span>
        </div>
      </div>
      {/* Main nav */}
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '14px 24px' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
          <TQLMark size={26} color={accent || 'var(--tql-accent)'} />
          <div style={{ display: 'flex', flexDirection: 'column', lineHeight: 1.1 }}>
            <span style={{ fontFamily: 'var(--font-display)', fontSize: 17, fontWeight: 700, letterSpacing: '-0.02em', color: '#fff' }}>The Question Lab</span>
            <span style={{ fontSize: 10, color: 'rgba(255,255,255,0.45)', letterSpacing: '0.18em' }}>// AFTER-AI · COGNITIVE EXPERIMENTS</span>
          </div>
        </div>
        <div style={{ display: 'flex', gap: 4, fontSize: 11 }}>
          {[
            ['HOME', '/', true],
            ['EPISODES', '/eps', false],
            ['QUESTION_INDEX', '/q', false],
            ['MANIFESTO', '/m', false],
            ['SUBSCRIBE', '/sub', false],
          ].map(([k, , active]) => (
            <span key={k} style={{
              padding: '8px 14px',
              border: '1px solid ' + (active ? 'var(--tql-accent)' : 'var(--tql-line-2)'),
              color: active ? 'var(--tql-accent)' : 'rgba(255,255,255,0.7)',
              background: active ? 'rgba(198,255,0,0.05)' : 'transparent',
              cursor: 'pointer',
              letterSpacing: '0.15em',
            }}>{k}</span>
          ))}
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
          <span style={{ fontSize: 10 }}>SIG <span style={{ color: '#fff' }}>0.91</span></span>
          <span style={{ fontSize: 10 }}>NSE <span style={{ color: '#fff' }}>0.34</span></span>
          <span style={{
            background: accent || 'var(--tql-accent)', color: '#0B0B0F',
            padding: '8px 14px', fontWeight: 700, letterSpacing: '0.15em',
            cursor: 'pointer'
          }}>EP.42 ▶</span>
        </div>
      </div>
    </div>
  );
}

// Hero — terminal interrogator + signal display
function BHero({ accent, mouse }) {
  const [typed, setTyped] = React.useState('');
  const [step, setStep] = React.useState(0);
  const [out, setOut] = React.useState(null);
  const [loading, setLoading] = React.useState(false);
  const fullQ = 'Will AI replace creativity?';
  const samples = [
    'Will AI replace creativity?',
    'Is consciousness just computation?',
    'Can a machine be wise?',
    'What is meaning, after autocomplete?',
  ];
  const [sampleIdx, setSampleIdx] = React.useState(0);

  // type-out animation
  React.useEffect(() => {
    if (step !== 0) return;
    const cur = samples[sampleIdx];
    let i = 0;
    setTyped('');
    const t = setInterval(() => {
      i++;
      setTyped(cur.slice(0, i));
      if (i >= cur.length) {
        clearInterval(t);
        setTimeout(() => setSampleIdx((s) => (s + 1) % samples.length), 2400);
      }
    }, 60);
    return () => clearInterval(t);
  }, [sampleIdx, step]);

  async function ask(q) {
    setLoading(true);
    setStep(1);
    setOut(null);
    try {
      const text = await window.claude.complete(
        `You are the interrogation engine of The Question Lab — cold, precise, skeptical. The user submitted a question. Do not answer. Deconstruct it. Return JSON only:
{
  "trace": ["log line 1", "log line 2", "log line 3"],   // 3 short status lines, each <60 chars, monospaced lab-log style
  "assumption": "one sentence, <22 words, naming the hidden assumption",
  "frame": "philosophy term that names the frame, 1-3 words (e.g., 'substance dualism', 'productivist epistemology')",
  "sub_a": "reframed question A, <14 words, ends with ?",
  "sub_b": "reframed question B, <14 words, ends with ?",
  "linked_episode": { "ep": 28, "title": "short ep title" }
}

User question: "${q}"`
      );
      const json = JSON.parse(text.replace(/```json\n?|\n?```/g, '').trim());
      setOut(json);
    } catch (e) {
      setOut({
        trace: ['parse: ok', 'frame_detect: productivist_episteme', 're-pose: 2 candidates'],
        assumption: 'That creativity is a substance one entity can take from another.',
        frame: 'productivist epistemology',
        sub_a: 'What changes about creativity when scarcity ends?',
        sub_b: 'Whose creativity is being measured here?',
        linked_episode: { ep: 36, title: 'Where does meaning come from?' },
      });
    }
    setLoading(false);
  }

  return (
    <div style={{ position: 'relative', background: '#0B0B0F', borderBottom: '1px solid var(--tql-line-2)' }}>
      {/* Section label */}
      <div style={{ display: 'flex', justifyContent: 'space-between', padding: '14px 24px', borderBottom: '1px solid var(--tql-line)', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>
        <span><span style={{ color: accent || 'var(--tql-accent)' }}>▸</span> 00 / INTERROGATION_CONSOLE — submit a question, observe its deconstruction</span>
        <span>F1 INPUT · F2 TRACE · F3 RESULT · ESC RESET</span>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '1.5fr 1fr', minHeight: 720 }}>
        {/* LEFT — terminal */}
        <div style={{ borderRight: '1px solid var(--tql-line-2)', padding: '40px 36px', position: 'relative' }}>
          <div className="bg-grid-fine" style={{ position: 'absolute', inset: 0, opacity: 0.5, pointerEvents: 'none' }} />
          <div style={{ position: 'relative' }}>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.22em', color: 'rgba(255,255,255,0.45)', marginBottom: 18 }}>
              tql.console &nbsp;//&nbsp; cognitive_instrument v0.42 &nbsp;//&nbsp; ready
            </div>

            <div style={{ fontFamily: 'var(--font-display)', fontWeight: 500, fontSize: 76, lineHeight: 1.0, letterSpacing: '-0.035em', color: '#fff' }}>
              We don&rsquo;t<br />
              answer questions.
            </div>
            <div style={{ fontFamily: 'var(--font-display)', fontWeight: 400, fontSize: 38, lineHeight: 1.1, letterSpacing: '-0.02em', color: 'rgba(255,255,255,0.55)', marginTop: 16 }}>
              We <span style={{ color: accent || 'var(--tql-accent)', fontWeight: 500 }}>re-pose</span> them.
            </div>

            {/* terminal */}
            <div style={{ marginTop: 48, border: '1px solid var(--tql-line-2)', background: '#0E0E12' }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '10px 14px', borderBottom: '1px solid var(--tql-line)', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.5)' }}>
                <span style={{ width: 8, height: 8, background: '#ff5555', display: 'inline-block' }} />
                <span style={{ width: 8, height: 8, background: '#FFB454', display: 'inline-block' }} />
                <span style={{ width: 8, height: 8, background: accent || 'var(--tql-accent)', display: 'inline-block' }} />
                <span style={{ marginLeft: 12 }}>tql.interrogate &nbsp;|&nbsp; sh ~ </span>
              </div>
              <div style={{ padding: '20px 18px', fontFamily: 'var(--font-mono)', fontSize: 14, color: 'rgba(255,255,255,0.85)', lineHeight: 1.7, minHeight: 200 }}>
                <div><span style={{ color: 'rgba(255,255,255,0.4)' }}>$</span> tql --interrogate</div>
                <div style={{ color: 'rgba(255,255,255,0.5)', fontSize: 12 }}>// Type any philosophical question. The lab will not answer.</div>
                {step === 0 && (
                  <div style={{ marginTop: 12 }}>
                    <span style={{ color: accent || 'var(--tql-accent)' }}>{'>'}</span>{' '}
                    <span style={{ color: '#fff' }}>{typed}</span>
                    <span className="term-cursor" style={{ width: 8, height: 16, background: accent || 'var(--tql-accent)' }} />
                  </div>
                )}
                {step === 1 && loading && (
                  <div style={{ marginTop: 12 }}>
                    <div style={{ color: 'rgba(255,255,255,0.5)' }}>[parsing...]</div>
                    <div style={{ color: 'rgba(255,255,255,0.5)' }}>[detecting frame...]</div>
                    <div style={{ color: 'rgba(255,255,255,0.5)' }}>[re-posing...]</div>
                  </div>
                )}
                {step === 1 && out && !loading && (
                  <div style={{ marginTop: 12 }}>
                    {out.trace?.map((l, i) => (
                      <div key={i} style={{ color: 'rgba(255,255,255,0.5)' }}>[{String(i + 1).padStart(2, '0')}] {l}</div>
                    ))}
                    <div style={{ marginTop: 16, color: 'rgba(255,255,255,0.4)' }}>—— frame —— <span style={{ color: accent || 'var(--tql-accent)' }}>{out.frame}</span></div>
                    <div style={{ marginTop: 8, color: 'rgba(255,255,255,0.4)' }}>—— assumption ——</div>
                    <div style={{ color: '#fff' }}>{out.assumption}</div>
                    <div style={{ marginTop: 16, color: 'rgba(255,255,255,0.4)' }}>—— re-posed ——</div>
                    <div style={{ color: accent || 'var(--tql-accent)' }}>A) {out.sub_a}</div>
                    <div style={{ color: accent || 'var(--tql-accent)' }}>B) {out.sub_b}</div>
                    <div style={{ marginTop: 12, color: 'rgba(255,255,255,0.4)' }}>see also: <span className="link-line" style={{ color: '#fff' }}>EP.{String(out.linked_episode.ep).padStart(2, '0')} — {out.linked_episode.title}</span></div>
                    <div style={{ marginTop: 12 }}>
                      <span onClick={() => { setStep(0); setOut(null); }} style={{ color: accent || 'var(--tql-accent)', cursor: 'pointer' }} className="link-line">[ press ESC to interrogate another ]</span>
                    </div>
                  </div>
                )}
              </div>
              <div style={{ borderTop: '1px solid var(--tql-line)', padding: '12px 14px', display: 'flex', alignItems: 'center', gap: 10 }}>
                <input
                  placeholder="type a question and press enter…"
                  onKeyDown={e => {
                    if (e.key === 'Enter' && e.currentTarget.value.trim()) { ask(e.currentTarget.value.trim()); e.currentTarget.value=''; }
                    if (e.key === 'Escape') { setStep(0); setOut(null); }
                  }}
                  style={{
                    flex: 1, background: 'transparent', border: 'none', outline: 'none',
                    fontFamily: 'var(--font-mono)', fontSize: 14, color: '#fff',
                  }}
                />
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.4)' }}>↵ ENTER</span>
              </div>
            </div>
          </div>
        </div>

        {/* RIGHT — live signal panel */}
        <div style={{ padding: '40px 32px', display: 'flex', flexDirection: 'column', gap: 24, position: 'relative' }}>
          <div style={{ position: 'absolute', inset: 0, opacity: 0.4 }}>
            {/* signal interference */}
            <svg viewBox="0 0 600 720" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
              {Array.from({ length: 36 }).map((_, i) => {
                const y = i * 22;
                const noise = (mouse?.x || 0) * 30;
                const path = Array.from({ length: 60 }).map((_, j) => {
                  const x = j * 10;
                  const dy = Math.sin((j + i * 0.7) * 0.3) * (4 + Math.abs(noise) * 0.4) + (j === 30 ? noise : 0);
                  return `${j === 0 ? 'M' : 'L'} ${x} ${y + dy}`;
                }).join(' ');
                return <path key={i} d={path} fill="none" stroke="rgba(198,255,0,0.18)" strokeWidth="0.5" />;
              })}
            </svg>
          </div>
          <div style={{ position: 'relative', flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
            <div>
              <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.22em', color: 'rgba(255,255,255,0.45)' }}>
                ▸ LIVE SIGNAL · WAVEFORM RESPONDS TO CURSOR
              </div>
              <div style={{ marginTop: 28, fontFamily: 'var(--font-display)', fontSize: 22, color: '#fff', fontWeight: 400, lineHeight: 1.4 }}>
                Every question carries an assumption. Most pass undetected.
              </div>
            </div>
            {/* small stats grid */}
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, marginTop: 32 }}>
              {[
                ['QUESTIONS RECEIVED', '14,082'],
                ['ASSUMPTIONS DETECTED', '13,867'],
                ['EPISODES PUBLISHED', '42'],
                ['HOURS OF LISTENING', '1,206'],
              ].map(([k, v]) => (
                <div key={k} style={{ border: '1px solid var(--tql-line-2)', padding: '14px 16px', background: 'rgba(11,11,15,0.7)' }}>
                  <div style={{ fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>{k}</div>
                  <div style={{ fontFamily: 'var(--font-display)', fontSize: 30, color: '#fff', fontWeight: 600, letterSpacing: '-0.02em', marginTop: 6 }}>{v}</div>
                </div>
              ))}
            </div>
            {/* sample chips */}
            <div style={{ marginTop: 28, position: 'relative' }}>
              <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.22em', color: 'rgba(255,255,255,0.45)', marginBottom: 12 }}>
                ▸ TRY ONE
              </div>
              <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
                {samples.map(s => (
                  <span key={s} onClick={() => ask(s)} style={{
                    padding: '8px 12px', border: '1px solid var(--tql-line-2)',
                    fontFamily: 'var(--font-mono)', fontSize: 11, color: 'rgba(255,255,255,0.85)',
                    cursor: 'pointer', background: 'rgba(11,11,15,0.7)'
                  }}>"{s}"</span>
                ))}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

// Episode log — research-archive style
function BEpisodeLog({ accent }) {
  const eps = EPISODES.slice().reverse();
  const [hovered, setHovered] = React.useState(null);
  return (
    <div style={{ background: '#0B0B0F', borderBottom: '1px solid var(--tql-line-2)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', padding: '14px 24px', borderBottom: '1px solid var(--tql-line)', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>
        <span><span style={{ color: accent || 'var(--tql-accent)' }}>▸</span> 01 / EPISODE_LOG — 42 cognitive experiments, indexed</span>
        <span>SORT: ▾ NEWEST &nbsp;|&nbsp; FILTER: ALL &nbsp;|&nbsp; VIEW: ▾ TABLE</span>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '1.1fr 1fr' }}>
        {/* Left: table */}
        <div style={{ borderRight: '1px solid var(--tql-line-2)' }}>
          <div style={{
            display: 'grid', gridTemplateColumns: '60px 70px 1fr 100px 50px',
            padding: '10px 24px',
            borderBottom: '1px solid var(--tql-line-2)',
            fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.45)',
            background: '#08080B'
          }}>
            <span>EP</span><span>FRAME</span><span>QUESTION</span><span>DURATION</span><span></span>
          </div>
          {eps.map((e, i) => {
            const isHover = hovered === e.ep;
            return (
              <div key={e.ep}
                onMouseEnter={() => setHovered(e.ep)}
                onMouseLeave={() => setHovered(null)}
                style={{
                  display: 'grid', gridTemplateColumns: '60px 70px 1fr 100px 50px',
                  padding: '14px 24px', alignItems: 'center', gap: 8,
                  borderBottom: '1px solid var(--tql-line)',
                  background: isHover ? 'rgba(198,255,0,0.04)' : 'transparent',
                  cursor: 'pointer',
                  transition: 'background .12s'
                }}
              >
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.15em', color: isHover ? (accent || 'var(--tql-accent)') : 'rgba(255,255,255,0.7)' }}>
                  {String(e.ep).padStart(2, '0')}
                </span>
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.55)', textTransform: 'uppercase' }}>
                  {e.theme}
                </span>
                <span style={{ fontFamily: 'var(--font-display)', fontSize: 18, color: isHover ? '#fff' : 'rgba(255,255,255,0.85)', letterSpacing: '-0.015em', lineHeight: 1.2 }}>
                  {e.title} <span style={{ color: accent || 'var(--tql-accent)' }}>{e.accent}</span>
                </span>
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, color: 'rgba(255,255,255,0.5)', letterSpacing: '0.1em' }}>
                  {20 + (e.ep % 30)}:{(e.ep * 7 % 60).toString().padStart(2,'0')}
                </span>
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, color: isHover ? (accent || 'var(--tql-accent)') : 'rgba(255,255,255,0.4)', textAlign: 'right' }}>
                  ▶
                </span>
              </div>
            );
          })}
        </div>
        {/* Right: preview pane */}
        <div style={{ position: 'sticky', top: 0, alignSelf: 'flex-start', padding: '24px' }}>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.22em', color: 'rgba(255,255,255,0.45)', marginBottom: 14 }}>
            ▸ PREVIEW &nbsp;//&nbsp; {hovered ? `EP.${String(hovered).padStart(2,'0')}` : 'hover an episode'}
          </div>
          {(() => {
            const e = eps.find(x => x.ep === (hovered || 42));
            return (
              <>
                <EpisodeCard {...e} title={e.title} titleAccent={e.accent} size="lg" />
                <div style={{ marginTop: 18, fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>
                  RUNTIME {20 + (e.ep % 30)} MIN · PUBLISHED {2026 - (e.ep > 30 ? 0 : 1)} · {e.theme.toUpperCase()}
                </div>
                <div style={{ marginTop: 16, fontFamily: 'var(--font-display)', fontSize: 14, lineHeight: 1.55, color: 'rgba(255,255,255,0.65)' }}>
                  In this experiment, we open a question that has been quietly answered for us by infrastructure, and ask what was lost in the translation.
                </div>
              </>
            );
          })()}
        </div>
      </div>
    </div>
  );
}

// Question Index — radial / tag matrix
function BQuestionIndex({ accent }) {
  const themes = [
    { name: 'COGNITION', count: 7, x: 1, y: 1 },
    { name: 'SELF', count: 5, x: 2, y: 0 },
    { name: 'TRUTH', count: 4, x: 3, y: 1 },
    { name: 'LANGUAGE', count: 6, x: 0, y: 2 },
    { name: 'FREE_WILL', count: 3, x: 4, y: 2 },
    { name: 'MEANING', count: 5, x: 1, y: 3 },
    { name: 'ETHICS', count: 6, x: 3, y: 3 },
    { name: 'REALITY', count: 4, x: 2, y: 4 },
  ];
  return (
    <div style={{ background: '#0B0B0F', borderBottom: '1px solid var(--tql-line-2)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', padding: '14px 24px', borderBottom: '1px solid var(--tql-line)', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>
        <span><span style={{ color: accent || 'var(--tql-accent)' }}>▸</span> 02 / QUESTION_INDEX — eight territories of philosophical inquiry</span>
        <span>40 QUESTIONS · 8 FRAMES</span>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', minHeight: 600 }}>
        {/* matrix */}
        <div style={{ borderRight: '1px solid var(--tql-line-2)', position: 'relative', overflow: 'hidden' }}>
          <div className="bg-grid" style={{ position: 'absolute', inset: 0, opacity: 0.5 }} />
          <div style={{ position: 'relative', padding: '40px', display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gridTemplateRows: 'repeat(5, 1fr)', gap: 8, height: 600 }}>
            {themes.map((t) => (
              <div key={t.name} style={{
                gridColumn: t.x + 1, gridRow: t.y + 1,
                border: '1px solid var(--tql-line-2)',
                background: 'rgba(11,11,15,0.7)',
                padding: '14px 16px',
                display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
                cursor: 'pointer',
                transition: 'background .15s, border-color .15s'
              }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = accent || 'var(--tql-accent)'; e.currentTarget.style.background = 'rgba(198,255,0,0.06)'; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = ''; e.currentTarget.style.background = 'rgba(11,11,15,0.7)'; }}>
                <div style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.15em', color: '#fff' }}>{t.name}</div>
                <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginTop: 16 }}>
                  <span style={{ fontFamily: 'var(--font-display)', fontSize: 32, fontWeight: 600, color: accent || 'var(--tql-accent)' }}>{String(t.count).padStart(2,'0')}</span>
                  <span style={{ fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>EPS →</span>
                </div>
              </div>
            ))}
          </div>
        </div>
        {/* descriptive */}
        <div style={{ padding: '40px 32px' }}>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 44, fontWeight: 500, lineHeight: 1.1, color: '#fff', letterSpacing: '-0.025em', maxWidth: 460 }}>
            We index every <span style={{ color: accent || 'var(--tql-accent)' }}>episode</span> under one of philosophy&rsquo;s perennial <span style={{ color: accent || 'var(--tql-accent)' }}>questions</span> — re-asked under AI conditions.
          </div>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.55)', marginTop: 36, lineHeight: 1.7 }}>
            ▸ THINK — what changes when something else can think for you<br/>
            ▸ SELF — where the I ends and the model begins<br/>
            ▸ LANGUAGE — whose words are these, exactly<br/>
            ▸ TRUTH — testimony from a system that has never lived<br/>
            ▸ ETHICS — responsibility when no one decided<br/>
            ▸ MEANING — production at zero marginal cost<br/>
            ▸ FREE WILL — is freedom computable<br/>
            ▸ REALITY — consensus or renderer
          </div>
          <div style={{ marginTop: 36, display: 'inline-flex', alignItems: 'center', gap: 10, padding: '12px 20px', border: '1px solid var(--tql-accent)', color: accent || 'var(--tql-accent)', fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.2em', cursor: 'pointer' }}>
            OPEN FULL INDEX →
          </div>
        </div>
      </div>
    </div>
  );
}

// Manifesto — printout style
function BManifesto({ accent }) {
  return (
    <div style={{ background: '#0B0B0F', borderBottom: '1px solid var(--tql-line-2)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', padding: '14px 24px', borderBottom: '1px solid var(--tql-line)', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>
        <span><span style={{ color: accent || 'var(--tql-accent)' }}>▸</span> 03 / MANIFESTO — the lab&rsquo;s working principles</span>
        <span>FILE 03.MANIFESTO.MD · LAST EDITED 2026-04-22</span>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: '300px 1fr', minHeight: 600 }}>
        <div style={{ borderRight: '1px solid var(--tql-line-2)', padding: '40px 24px' }}>
          {[
            ['§01', 'On asking'],
            ['§02', 'On not answering'],
            ['§03', 'On the after-AI'],
            ['§04', 'On responsibility'],
            ['§05', 'On the language we still own'],
          ].map(([n, t]) => (
            <div key={n} style={{ display: 'flex', gap: 16, padding: '14px 0', borderBottom: '1px solid var(--tql-line)' }}>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, color: accent || 'var(--tql-accent)', letterSpacing: '0.18em' }}>{n}</span>
              <span style={{ fontFamily: 'var(--font-display)', fontSize: 16, color: '#fff' }}>{t}</span>
            </div>
          ))}
        </div>
        <div style={{ padding: '40px 80px 60px', maxWidth: 920 }}>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: accent || 'var(--tql-accent)', marginBottom: 18 }}>§ 01 — ON ASKING</div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 30, lineHeight: 1.3, letterSpacing: '-0.02em', color: '#fff', fontWeight: 400 }}>
            For 2,500 years, philosophy was a discipline of asking. Knowledge was rare. Authority was loud. The question, like fire, had to be tended.
          </div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 22, lineHeight: 1.5, color: 'rgba(255,255,255,0.7)', marginTop: 28, textWrap: 'pretty' }}>
            Then knowledge became searchable. Opinions became autocompleted. Answers arrived before the question was finished.
          </div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 22, lineHeight: 1.5, color: 'rgba(255,255,255,0.7)', marginTop: 18 }}>
            What is left of <span style={{ color: accent || 'var(--tql-accent)' }}>thinking</span> when its conclusion can be summoned?
          </div>
          <div style={{ marginTop: 48, padding: '24px 28px', borderLeft: '2px solid var(--tql-accent)', background: 'rgba(198,255,0,0.04)' }}>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 26, color: '#fff', lineHeight: 1.3, letterSpacing: '-0.015em' }}>
              This lab does not provide answers. It re-poses the question.
            </div>
          </div>
          <div style={{ marginTop: 36, fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.5)' }}>
            — THE QUESTION LAB · EST. 2026 · BEIJING / BERLIN / SF &nbsp; ▸ READ §02 →
          </div>
        </div>
      </div>
    </div>
  );
}

// Subscribe block (terminal style)
function BSubscribe({ accent }) {
  return (
    <div style={{ background: '#0B0B0F' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', padding: '14px 24px', borderBottom: '1px solid var(--tql-line)', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', color: 'rgba(255,255,255,0.5)' }}>
        <span><span style={{ color: accent || 'var(--tql-accent)' }}>▸</span> 04 / SUBSCRIBE — receive one new question every Sunday</span>
        <span>12,407 SUBSCRIBED · NO TRACKING · 1-CLICK UNSUB</span>
      </div>
      <div style={{ padding: '64px 60px 80px', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'center' }}>
        <div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 60, fontWeight: 500, lineHeight: 1.0, letterSpacing: '-0.035em', color: '#fff' }}>
            One question.<br/>
            <span style={{ color: 'rgba(255,255,255,0.55)' }}>Every Sunday.</span>
          </div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 18, lineHeight: 1.6, color: 'rgba(255,255,255,0.65)', marginTop: 28, maxWidth: 460 }}>
            Each issue: a primary text, a counter-text, and one question to take into the week. Four minutes to read. A lifetime to answer.
          </div>
        </div>
        <div style={{ border: '1px solid var(--tql-line-2)', background: '#0E0E12' }}>
          <div style={{ padding: '10px 14px', borderBottom: '1px solid var(--tql-line)', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.5)' }}>
            tql.subscribe &nbsp;//&nbsp; weekly_dispatch
          </div>
          <div style={{ padding: 24, fontFamily: 'var(--font-mono)', fontSize: 13, color: 'rgba(255,255,255,0.85)', lineHeight: 1.7 }}>
            <div><span style={{ color: 'rgba(255,255,255,0.4)' }}>$</span> tql --subscribe</div>
            <div style={{ color: 'rgba(255,255,255,0.4)' }}>// please enter your contact</div>
            <div style={{ marginTop: 12, display: 'flex', alignItems: 'center', gap: 10 }}>
              <span style={{ color: accent || 'var(--tql-accent)' }}>{'>'}</span>
              <input placeholder="email@elsewhere.net" style={{
                flex: 1, background: 'transparent', border: 'none', outline: 'none',
                fontFamily: 'var(--font-mono)', fontSize: 14, color: '#fff',
                borderBottom: '1px solid var(--tql-line-2)', padding: '4px 0'
              }} />
            </div>
            <div style={{ marginTop: 24, display: 'flex', justifyContent: 'space-between' }}>
              <span style={{ color: 'rgba(255,255,255,0.4)', fontSize: 11 }}>// 4-min read · sundays · ~52/yr</span>
              <span style={{
                background: accent || 'var(--tql-accent)', color: '#0B0B0F',
                padding: '8px 14px', fontWeight: 700, letterSpacing: '0.18em', fontSize: 11, cursor: 'pointer'
              }}>SUBSCRIBE [↵]</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

function BFooter({ accent }) {
  return (
    <div style={{ background: '#08080B', borderTop: '1px solid var(--tql-line-2)', padding: '24px', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.5)', display: 'flex', justifyContent: 'space-between', textTransform: 'uppercase' }}>
      <span>© 2026 THE QUESTION LAB · ALL QUESTIONS RESERVED</span>
      <span style={{ display: 'flex', gap: 24 }}>
        <span>YOUTUBE</span><span>SPOTIFY</span><span>RSS</span><span>CONTACT</span>
      </span>
      <span>SYSTEM v0.42 · UPTIME 312D · NO TRACKING</span>
    </div>
  );
}

function DirectionB({ accent }) {
  const ref = React.useRef(null);
  const mouse = useMouse(ref);
  return (
    <div ref={ref} className="tql-root" style={{ width: B_W, background: '#0B0B0F', color: '#EDEDED', overflow: 'hidden', position: 'relative' }}>
      <BHeader accent={accent} />
      <BHero accent={accent} mouse={mouse} />
      <BEpisodeLog accent={accent} />
      <BQuestionIndex accent={accent} />
      <BManifesto accent={accent} />
      <BSubscribe accent={accent} />
      <BFooter accent={accent} />
    </div>
  );
}

Object.assign(window, { DirectionB, B_W });
