// Shared shell for inner discipline / careers pages.
// Each page mounts <DisciplinePage> with its own content.
// Reuses Nav, Footer, Logo, Icon, Eyebrow from Core.jsx (loaded as globals via window).

const DISCIPLINES = [
  { k: "platform-engineering", num: "01", title: "Platform Engineering",     sub: "smooth ops, happy devs", icon: "layers" },
  { k: "devex",                num: "02", title: "Developer Experience",     sub: "happy developers · better products", icon: "git-branch" },
  { k: "data",                 num: "03", title: "Data Engineering",         sub: "data that delivers", icon: "database" },
  { k: "ai",                   num: "04", title: "AI & Machine Learning",    sub: "AI that empowers people", icon: "zap" },
  { k: "transformation",       num: "05", title: "Tech Transformations",    sub: "ecosystems in harmony", icon: "aperture" },
];

// ---------- Discipline page hero — EDITORIAL variant ----------
const DiscHeroEditorial = ({num, eyebrow, title, lede, body}) => (
  <section id="top" style={{
    background:"var(--bg-dark)", color:"var(--fg-on-dark)",
    padding:"160px 0 96px", position:"relative", overflow:"hidden"
  }}>
    <div className="dl-grid-bg" style={{position:"absolute", inset:0, opacity:.35}}/>
    <div className="dl-container" style={{position:"relative"}}>
      <div style={{display:"flex", alignItems:"center", gap:14, marginBottom:32}}>
        <span style={{
          fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
          letterSpacing:".14em", textTransform:"uppercase"
        }}>// discipline / {num}</span>
        <span style={{flex:1, height:1, background:"rgba(255,255,255,.18)"}}/>
        <span style={{
          fontFamily:"var(--font-mono)", fontSize:11, color:"rgba(255,255,255,.55)",
          letterSpacing:".14em", textTransform:"uppercase"
        }}>{eyebrow}</span>
      </div>
      <h1 style={{
        fontFamily:"var(--font-display)", fontWeight:800,
        fontSize:"clamp(44px, 8vw, 132px)", lineHeight:.95,
        letterSpacing:"-0.04em", margin:"0 0 28px", textTransform:"uppercase",
        textWrap: "balance"
      }}>{title}</h1>
      <p style={{
        fontFamily:"var(--font-display)", fontWeight:600,
        fontSize:"clamp(20px, 2.4vw, 32px)", lineHeight:1.25,
        maxWidth:"40ch", color:"rgba(255,255,255,.86)", margin:"0 0 24px",
        textWrap: "balance"
      }}>{lede}</p>
      {body && (
        <p style={{
          fontFamily:"var(--font-body)", fontSize:"clamp(15px, 1.2vw, 18px)",
          lineHeight:1.65, maxWidth:"60ch", color:"rgba(255,255,255,.7)", margin:0
        }}>{body}</p>
      )}
    </div>
  </section>
);

// ---------- Discipline page hero — TERMINAL variant (V5-style split) ----------
// Tiny self-contained terminal log keyed to the discipline so each page reads differently.
const DiscTerminalLog = ({lines}) => {
  const safeLines = Array.isArray(lines) ? lines.filter(Boolean) : [];
  const [shown, setShown] = React.useState([]);
  const [tick, setTick] = React.useState(0);
  // Stable signature so we re-run the typewriter only when content actually changes,
  // not on every parent re-render (the parent ticks once per second for the ●/○ pulse).
  const sig = React.useMemo(
    () => safeLines.map(l => `${l?.k||""}|${l?.t||""}`).join("\n"),
    // eslint-disable-next-line
    [JSON.stringify(safeLines)]
  );
  React.useEffect(() => {
    setShown([]);
    let i = 0;
    let alive = true;
    const tick1 = () => {
      if (!alive) return;
      if (i >= safeLines.length) return;
      const next = safeLines[i];
      i += 1;
      if (next) setShown(s => [...s, next]);
      timer = setTimeout(tick1, 480 + Math.random() * 320);
    };
    let timer = setTimeout(tick1, 600);
    return () => { alive = false; clearTimeout(timer); };
    // eslint-disable-next-line
  }, [sig]);
  React.useEffect(() => {
    const t = setInterval(() => setTick(x => x + 1), 1100);
    return () => clearInterval(t);
  }, []);
  const cursor = tick % 2 === 0 ? "▌" : " ";
  return (
    <div style={{
      background:"rgba(0,0,0,.42)", border:"1px solid rgba(255,255,255,.14)",
      fontFamily:"var(--font-mono)", fontSize:12, lineHeight:1.7,
      color:"rgba(255,255,255,.84)", borderRadius:2, overflow:"hidden",
      boxShadow:"0 24px 60px -24px rgba(0,0,0,.6)"
    }}>
      <div style={{
        display:"flex", alignItems:"center", gap:8, padding:"10px 14px",
        borderBottom:"1px solid rgba(255,255,255,.1)", background:"rgba(255,255,255,.03)"
      }}>
        <span style={{display:"inline-flex", gap:6}}>
          <span style={{width:9, height:9, borderRadius:999, background:"#FF5F57"}}/>
          <span style={{width:9, height:9, borderRadius:999, background:"#FEBC2E"}}/>
          <span style={{width:9, height:9, borderRadius:999, background:"#28C840"}}/>
        </span>
        <span style={{color:"rgba(255,255,255,.45)", fontSize:11, letterSpacing:".08em"}}>
          ~/devleaps · zsh
        </span>
      </div>
      <div style={{padding:"14px 16px", minHeight:240}}>
        {shown.filter(Boolean).map((l, i) => (
          <div key={i} style={{whiteSpace:"pre-wrap"}}>
            {l.k === "cmd" && <><span style={{color:"var(--accent)"}}>$ </span><span>{l.t}</span></>}
            {l.k === "out" && <span style={{color:"rgba(255,255,255,.6)"}}>{l.t}</span>}
            {l.k === "ok"  && <><span style={{color:"#7EE787"}}>✓ </span><span>{l.t}</span></>}
            {l.k === "warn"&& <><span style={{color:"#FFB454"}}>! </span><span>{l.t}</span></>}
          </div>
        ))}
        {shown.length >= safeLines.length && safeLines.length > 0 && (
          <div><span style={{color:"var(--accent)"}}>$ </span><span style={{color:"var(--accent)"}}>{cursor}</span></div>
        )}
      </div>
    </div>
  );
};

const DiscHeroTerminal = ({num, eyebrow, title, lede, body, terminal}) => {
  const [tick, setTick] = React.useState(0);
  React.useEffect(() => {
    const t = setInterval(() => setTick(x => x + 1), 1200);
    return () => clearInterval(t);
  }, []);
  const dot = tick % 2 === 0 ? "●" : "○";
  return (
    <section id="top" style={{
      background:"var(--bg-dark)", color:"var(--fg-on-dark)",
      padding:"140px 0 88px", position:"relative", overflow:"hidden"
    }}>
      <div className="dl-grid-bg" style={{position:"absolute", inset:0, opacity:.35}}/>
      <div className="dl-container dl-disc-hero-terminal-grid" style={{position:"relative"}}>
        <div>
          <div style={{
            display:"flex", alignItems:"center", gap:10,
            fontFamily:"var(--font-mono)", fontSize:12, color:"var(--accent)",
            letterSpacing:".12em", marginBottom:24
          }}>
            <span>{dot}</span>
            <span>// discipline / {num} · {eyebrow.replace(/^\/\/\s*/, "")}</span>
          </div>
          <h1 style={{
            fontFamily:"var(--font-display)", fontWeight:800,
            fontSize:"clamp(40px, 6.4vw, 96px)", lineHeight:.95,
            letterSpacing:"-0.04em", margin:"0 0 24px", textTransform:"uppercase",
            textWrap:"balance"
          }}>{title}</h1>
          <p style={{
            fontFamily:"var(--font-display)", fontWeight:600,
            fontSize:"clamp(18px, 1.9vw, 24px)", lineHeight:1.3,
            maxWidth:"34ch", color:"rgba(255,255,255,.86)", margin:"0 0 20px",
            textWrap:"balance"
          }}>{lede}</p>
          {body && <p style={{
            fontFamily:"var(--font-body)", fontSize:"clamp(14px, 1.05vw, 16px)",
            lineHeight:1.65, maxWidth:"54ch", color:"rgba(255,255,255,.66)", margin:0
          }}>{body}</p>}
        </div>
        <DiscTerminalLog lines={terminal || DEFAULT_TERMINAL}/>
      </div>
    </section>
  );
};

// Generic fallback if a page doesn't pass terminal lines.
const DEFAULT_TERMINAL = [
  { k:"cmd", t:"devleaps engage --discipline" },
  { k:"out", t:"› reading context · stakeholders · existing systems" },
  { k:"ok",  t:"baseline captured" },
  { k:"cmd", t:"devleaps plan --duration 2w" },
  { k:"out", t:"› drafting paved roads · risks · cost model" },
  { k:"ok",  t:"plan ready" },
  { k:"cmd", t:"devleaps ship --first-value" },
];

// Switching wrapper used by sub-pages — reads variant from SubPageCtx if not passed.
const DiscHero = (props) => {
  const ctx = React.useContext(SubPageCtx);
  const variant = props.heroVariant || ctx.heroVariant || "editorial";
  if (variant === "terminal") return <DiscHeroTerminal {...props}/>;
  return <DiscHeroEditorial {...props}/>;
};

// ---------- Question pillars ----------
const QuestionBlock = ({eyebrow, title, items}) => (
  <section style={{padding:"96px 0", background:"var(--bg)", borderTop:"1px solid var(--line)"}}>
    <div className="dl-container">
      <div style={{
        fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
        letterSpacing:".14em", textTransform:"uppercase", marginBottom:14
      }}>{eyebrow}</div>
      {title && <h2 style={{
        fontFamily:"var(--font-display)", fontWeight:800,
        fontSize:"clamp(32px, 5vw, 64px)", lineHeight:1, letterSpacing:"-0.03em",
        margin:"0 0 56px", textTransform:"uppercase", maxWidth:"24ch", textWrap:"balance"
      }}>{title}</h2>}
      <div className="dl-question-grid" style={{gridTemplateColumns:`repeat(${Math.min(items.length, 4)}, 1fr)`}}>
        {items.map((it, i) => (
          <div key={i} style={{
            padding:"32px 28px",
            borderLeft: i === 0 ? "none" : "1px solid var(--line)"
          }}>
            <div style={{
              fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
              letterSpacing:".14em", textTransform:"uppercase", marginBottom:14
            }}>// {String(i+1).padStart(2,"0")}</div>
            <h3 style={{
              fontFamily:"var(--font-display)", fontWeight:700,
              fontSize:22, letterSpacing:"-0.01em", margin:"0 0 12px",
              textTransform:"uppercase"
            }}>{it.k}</h3>
            <p style={{fontFamily:"var(--font-body)", fontSize:14, lineHeight:1.6,
                       color:"var(--fg-muted)", margin:0}}>{it.d}</p>
          </div>
        ))}
      </div>
    </div>
  </section>
);

// ---------- Capability cards (numbered grid) ----------
const Capabilities = ({eyebrow, title, items, columns = 2}) => (
  <section style={{padding:"96px 0", background:"var(--bg-elev)"}}>
    <div className="dl-container">
      <div className="dl-capabilities-header">
        <div>
          <div style={{
            fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
            letterSpacing:".14em", textTransform:"uppercase", marginBottom:14
          }}>{eyebrow}</div>
          <h2 style={{
            fontFamily:"var(--font-display)", fontWeight:800,
            fontSize:"clamp(32px, 4.4vw, 56px)", lineHeight:.95, letterSpacing:"-0.03em",
            margin:0, textTransform:"uppercase", textWrap:"balance"
          }}>{title}</h2>
        </div>
      </div>
      <div className="dl-capabilities-grid" style={{gridTemplateColumns:`repeat(${columns}, 1fr)`}}>
        {items.map((it, i) => {
          const col = i % columns;
          const row = Math.floor(i / columns);
          const lastRow = Math.floor((items.length-1) / columns);
          return (
            <div key={i} style={{
              padding:"36px 32px",
              background: "var(--bg)",
              borderRight: col < columns-1 ? "1px solid var(--line)" : "none",
              borderBottom: row < lastRow ? "1px solid var(--line)" : "none",
            }}>
              <div style={{display:"flex", alignItems:"baseline", gap:14, marginBottom:14}}>
                <span style={{
                  fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
                  letterSpacing:".14em", textTransform:"uppercase"
                }}>// {it.n || String(i+1).padStart(2,"0")}</span>
                {it.tag && <span style={{
                  fontFamily:"var(--font-mono)", fontSize:10, color:"var(--fg-muted)",
                  letterSpacing:".12em", textTransform:"uppercase"
                }}>{it.tag}</span>}
              </div>
              <h3 style={{
                fontFamily:"var(--font-display)", fontWeight:700,
                fontSize: 24, letterSpacing:"-0.01em", margin:"0 0 14px",
                textTransform:"uppercase"
              }}>{it.t}</h3>
              <p style={{fontFamily:"var(--font-body)", fontSize:15, lineHeight:1.6,
                         color:"var(--fg-muted)", margin: it.bullets ? "0 0 16px" : 0}}>{it.d}</p>
              {it.bullets && (
                <ul style={{listStyle:"none", padding:0, margin:0, display:"flex",
                            flexDirection:"column", gap:6}}>
                  {it.bullets.map((b, j) => (
                    <li key={j} style={{display:"flex", gap:10, alignItems:"baseline",
                                        fontFamily:"var(--font-mono)", fontSize:12,
                                        color:"var(--fg-muted)"}}>
                      <span style={{color:"var(--accent)"}}>›</span>
                      <span>{b}</span>
                    </li>
                  ))}
                </ul>
              )}
            </div>
          );
        })}
      </div>
    </div>
  </section>
);

// ---------- Process strip (horizontal phases) ----------
const ProcessStrip = ({eyebrow, title, phases, dark = true}) => (
  <section style={{
    padding:"96px 0",
    background: dark ? "var(--bg-dark)" : "var(--bg-elev)",
    color: dark ? "var(--fg-on-dark)" : "var(--fg)",
    position:"relative", overflow:"hidden"
  }}>
    {dark && <div className="dl-grid-bg" style={{position:"absolute", inset:0, opacity:.25}}/>}
    <div className="dl-container" style={{position:"relative"}}>
      <div style={{
        fontFamily:"var(--font-mono)", fontSize:11,
        color: "var(--accent)",
        letterSpacing:".14em", textTransform:"uppercase", marginBottom:14
      }}>{eyebrow}</div>
      <h2 style={{
        fontFamily:"var(--font-display)", fontWeight:800,
        fontSize:"clamp(32px, 4.4vw, 56px)", lineHeight:.95, letterSpacing:"-0.03em",
        margin:"0 0 48px", textTransform:"uppercase", maxWidth:"22ch", textWrap:"balance"
      }}>{title}</h2>
      <div className="dl-process-strip-grid" style={{gridTemplateColumns:`repeat(${phases.length}, 1fr)`, borderTop:`1px solid ${dark ? "rgba(255,255,255,.18)" : "var(--line-strong)"}`}}>
        {phases.map((p, i) => (
          <div key={i} style={{
            padding:"32px 24px 0",
            borderLeft: i === 0 ? "none" : `1px solid ${dark ? "rgba(255,255,255,.12)" : "var(--line)"}`,
            position:"relative"
          }}>
            <div style={{
              fontFamily:"var(--font-mono)", fontWeight:600, fontSize:13, color:"var(--accent)",
              letterSpacing:".14em", marginBottom:18
            }}>{String(i+1).padStart(2,"0")} ─</div>
            <h3 style={{
              fontFamily:"var(--font-display)", fontWeight:700,
              fontSize:18, letterSpacing:"-0.01em", margin:"0 0 10px",
              textTransform:"uppercase"
            }}>{p.t}</h3>
            {p.d && <p style={{fontFamily:"var(--font-body)", fontSize:13, lineHeight:1.5,
                       color: dark ? "rgba(255,255,255,.62)" : "var(--fg-muted)", margin:0}}>{p.d}</p>}
          </div>
        ))}
      </div>
    </div>
  </section>
);

// ---------- Plain prose section ----------
const Prose = ({eyebrow, title, paragraphs, blockquote}) => (
  <section style={{padding:"96px 0", background:"var(--bg)", borderTop:"1px solid var(--line)"}}>
    <div className="dl-container" style={{maxWidth:880}}>
      {eyebrow && <div style={{
        fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
        letterSpacing:".14em", textTransform:"uppercase", marginBottom:14
      }}>{eyebrow}</div>}
      {title && <h2 style={{
        fontFamily:"var(--font-display)", fontWeight:800,
        fontSize:"clamp(28px, 3.6vw, 44px)", lineHeight:1.05, letterSpacing:"-0.03em",
        margin:"0 0 32px", textTransform:"uppercase", textWrap:"balance"
      }}>{title}</h2>}
      {paragraphs?.map((p, i) => (
        <p key={i} style={{
          fontFamily:"var(--font-body)", fontSize:"clamp(15px, 1.2vw, 18px)",
          lineHeight:1.7, color:"var(--fg)", margin:"0 0 20px", maxWidth:"68ch"
        }}>{p}</p>
      ))}
      {blockquote && (
        <blockquote style={{
          margin:"32px 0 0", padding:"24px 28px",
          borderLeft:"3px solid var(--accent)",
          fontFamily:"var(--font-display)", fontWeight:600,
          fontSize:"clamp(18px, 1.8vw, 24px)", lineHeight:1.4,
          color:"var(--fg)", maxWidth:"50ch"
        }}>{blockquote}</blockquote>
      )}
    </div>
  </section>
);

// ---------- Big CTA ----------
const PageCTA = ({eyebrow, title, body, btn = "Let's talk"}) => (
  <section style={{
    padding:"112px 0", background:"var(--bg-elev)",
    borderTop:"1px solid var(--line-strong)",
    position:"relative", overflow:"hidden"
  }}>
    <div className="dl-container" style={{position:"relative"}}>
      <div style={{
        fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
        letterSpacing:".14em", textTransform:"uppercase", marginBottom:18
      }}>{eyebrow}</div>
      <h2 style={{
        fontFamily:"var(--font-display)", fontWeight:800,
        fontSize:"clamp(36px, 6vw, 88px)", lineHeight:.95, letterSpacing:"-0.04em",
        margin:"0 0 24px", textTransform:"uppercase", textWrap:"balance"
      }}>{title}</h2>
      {body && <p style={{
        fontFamily:"var(--font-body)", fontSize:"clamp(16px, 1.4vw, 20px)",
        lineHeight:1.6, color:"var(--fg-muted)", margin:"0 0 36px", maxWidth:"54ch"
      }}>{body}</p>}
      <div style={{display:"flex", gap:14, flexWrap:"wrap"}}>
        <a href="mailto:hello@devleaps.nl" className="dl-btn dl-btn-primary">
          {btn} <Icon name="arrow-right" size={16}/>
        </a>
        <a href="index.html" className="dl-btn dl-btn-ghost">
          <Icon name="arrow-right" size={16} style={{transform:"rotate(180deg)"}}/> Back to home
        </a>
      </div>
    </div>
  </section>
);

// ---------- Sibling discipline navigation ----------
const SiblingNav = ({current}) => {
  const others = DISCIPLINES.filter(d => d.k !== current);
  return (
    <section style={{
      padding:"72px 0", background:"var(--bg)",
      borderTop:"1px solid var(--line)"
    }}>
      <div className="dl-container">
        <div style={{
          fontFamily:"var(--font-mono)", fontSize:11, color:"var(--accent)",
          letterSpacing:".14em", textTransform:"uppercase", marginBottom:24
        }}>// other disciplines</div>
        <div className="dl-sibling-nav-grid" style={{gridTemplateColumns:`repeat(${others.length}, 1fr)`}}>
          {others.map((d, i) => (
            <a key={d.k} href={`${d.k}.html`} style={{
              padding:"24px 20px",
              borderLeft: i === 0 ? "none" : "1px solid var(--line)",
              borderBottom:"1px solid var(--line-strong)",
              textDecoration:"none", color:"var(--fg)",
              display:"flex", flexDirection:"column", gap:6,
              transition:"background var(--dur-2)"
            }}
            onMouseEnter={e => e.currentTarget.style.background = "var(--bg-elev)"}
            onMouseLeave={e => e.currentTarget.style.background = "transparent"}>
              <span style={{
                fontFamily:"var(--font-mono)", fontSize:10, color:"var(--accent)",
                letterSpacing:".14em", textTransform:"uppercase"
              }}>// {d.num}</span>
              <span style={{
                fontFamily:"var(--font-display)", fontWeight:700, fontSize:18,
                letterSpacing:"-0.01em", textTransform:"uppercase"
              }}>{d.title}</span>
              <span style={{
                fontFamily:"var(--font-mono)", fontSize:11, color:"var(--fg-muted)",
                letterSpacing:".06em"
              }}>{d.sub} →</span>
            </a>
          ))}
        </div>
      </div>
    </section>
  );
};

// ---------- Floating sub-page controls (theme + hero variant) ----------
const SUB_THEMES = [
  { k:"black", name:"Black/Red"  },
  { k:"green", name:"Green/Red"  },
  { k:"light", name:"Black/Blue" },
  { k:"blue",  name:"Blue/Blue"  },
];
const SUB_VARIANTS = [
  { k:"editorial", name:"Editorial", sub:"Oversized type · full-bleed" },
  { k:"terminal",  name:"Terminal",  sub:"Split hero · live log" },
];

const SubControls = ({theme, onTheme, variant, onVariant}) => {
  const [collapsed, setCollapsed] = React.useState(false);
  const seg = (active) => ({
    background: active ? "rgba(255,255,255,.14)" : "transparent",
    color: active ? "#fff" : "rgba(255,255,255,.6)",
    border:"none", padding:"7px 11px", cursor:"pointer",
    fontFamily:"inherit", fontSize:11, letterSpacing:"0.06em", textTransform:"uppercase",
    transition:"all 160ms", whiteSpace:"nowrap"
  });
  const accent = (active) => ({
    ...seg(active),
    background: active ? "var(--accent)" : "transparent",
    color: active ? "var(--accent-fg)" : "rgba(255,255,255,.65)",
  });
  const groupBox = {display:"inline-flex", border:"1px solid rgba(255,255,255,.16)", borderRadius:2, overflow:"hidden"};
  const div = (i, last) => ({borderRight: i < last ? "1px solid rgba(255,255,255,.14)" : "none"});

  if (collapsed) {
    return (
      <button onClick={()=>setCollapsed(false)} title="show controls" style={{
        position:"fixed", bottom:16, left:"50%", transform:"translateX(-50%)",
        zIndex:90, background:"#0A0A09", color:"var(--accent)",
        border:"1px solid rgba(255,255,255,.18)", borderRadius:999,
        padding:"8px 14px", fontFamily:"var(--font-mono)", fontSize:11,
        letterSpacing:"0.08em", textTransform:"uppercase", cursor:"pointer",
        boxShadow:"0 8px 24px -8px rgba(0,0,0,.5)",
        display:"inline-flex", alignItems:"center", gap:8,
      }}>
        <span style={{display:"inline-block", width:6, height:6, background:"var(--accent)", borderRadius:"50%"}}/>
        // controls
      </button>
    );
  }

  return (
    <div style={{
      position:"fixed", bottom:16, left:"50%", transform:"translateX(-50%)",
      zIndex:90, background:"rgba(10,10,9,.92)", color:"#FAFAF7",
      padding:"8px 10px 8px 14px",
      display:"flex", alignItems:"center", gap:14,
      border:"1px solid rgba(255,255,255,.16)", borderRadius:4,
      backdropFilter:"blur(12px) saturate(140%)", WebkitBackdropFilter:"blur(12px) saturate(140%)",
      fontFamily:"var(--font-mono)", fontSize:11, letterSpacing:"0.06em",
      boxShadow:"0 12px 32px -12px rgba(0,0,0,.6), 0 2px 8px -2px rgba(0,0,0,.3)",
      flexWrap:"wrap", maxWidth:"calc(100vw - 32px)",
    }}>
      <div style={{display:"flex", alignItems:"center", gap:8}}>
        <span style={{color:"var(--accent)", textTransform:"uppercase", fontSize:10}}>hero</span>
        <div style={groupBox}>
          {SUB_VARIANTS.map((v, i) => (
            <button key={v.k} onClick={()=>onVariant(v.k)} title={v.sub}
              style={{...accent(variant === v.k), ...div(i, SUB_VARIANTS.length-1)}}>{v.name}</button>
          ))}
        </div>
      </div>
      <div style={{width:1, height:22, background:"rgba(255,255,255,.14)"}}/>
      <div style={{display:"flex", alignItems:"center", gap:8}}>
        <span style={{color:"var(--accent)", textTransform:"uppercase", fontSize:10}}>theme</span>
        <div style={groupBox}>
          {SUB_THEMES.map((t, i) => (
            <button key={t.k} onClick={()=>onTheme(t.k)}
              style={{...accent(theme === t.k), ...div(i, SUB_THEMES.length-1)}}>{t.name}</button>
          ))}
        </div>
      </div>
      <button onClick={()=>setCollapsed(true)} title="hide" style={{
        background:"transparent", border:"1px solid rgba(255,255,255,.18)",
        color:"rgba(255,255,255,.6)", width:26, height:26, borderRadius:2,
        cursor:"pointer", fontSize:16, lineHeight:1, padding:0,
        display:"inline-flex", alignItems:"center", justifyContent:"center",
        marginLeft:4,
      }}>×</button>
    </div>
  );
};

// Context so DiscHero can read the active variant without prop-drilling.
const SubPageCtx = React.createContext({heroVariant:"editorial"});

// ---------- Top-level page wrapper ----------
// Production: theme from prop, defaultHero variant, no control panels.
const InnerPage = ({theme:initialTheme = "green", current, defaultHero = "editorial", children}) => {
  const heroVariant = defaultHero;

  React.useEffect(() => {
    document.documentElement.dataset.theme = initialTheme;
  }, [initialTheme]);

  return (
    <SubPageCtx.Provider value={{heroVariant}}>
      <Nav theme={initialTheme} heroTheme="dark"/>
      {children}
      <Footer theme={initialTheme}/>
    </SubPageCtx.Provider>
  );
};

// ---------- Pull-quote block (mirrors homepage HumanQuote) ----------
const DiscQuote = ({photo, name, role, quote, eyebrow = "// in our words", flip = false, paper = false}) => {
  const [imgErr, setImgErr] = React.useState(false);
  const portrait = (
    <div style={{
      position:"relative", aspectRatio:"4 / 5",
      background:"var(--bg-dark)", overflow:"hidden", minWidth:0
    }}>
      {photo && !imgErr ? (
        <img src={photo} alt={name} onError={() => setImgErr(true)}
          style={{width:"100%", height:"100%", objectFit:"cover", filter:"grayscale(0.15) contrast(1.04)"}}/>
      ) : (
        <div style={{
          position:"absolute", inset:0, display:"flex", alignItems:"center", justifyContent:"center",
          fontFamily:"var(--font-display)", fontWeight:700, fontSize:120, color:"var(--accent)"
        }}>{name?.[0]}</div>
      )}
      <div style={{
        position:"absolute", left:0, top:0, padding:"8px 14px",
        fontFamily:"var(--font-mono)", fontSize:10, letterSpacing:"0.16em",
        color:"var(--accent)", background:"rgba(10,10,9,.88)",
        textTransform:"uppercase"
      }}>{eyebrow}</div>
    </div>
  );

  const text = (
    <div style={{minWidth:0}}>
      <div aria-hidden style={{
        fontFamily:"var(--font-display)", fontWeight:700, fontSize:120, lineHeight:0.7,
        color:"var(--accent)", marginBottom:4, letterSpacing:"-0.04em"
      }}>"</div>
      <p style={{
        fontFamily:"var(--font-display)", fontWeight:600,
        fontSize:"clamp(26px, 3vw, 42px)", lineHeight:1.18, letterSpacing:"-0.02em",
        margin:0, textWrap:"balance", color:"var(--fg)", maxWidth:"26ch"
      }}>{quote}</p>
      <div style={{marginTop:32, display:"flex", alignItems:"center", gap:16, flexWrap:"wrap"}}>
        <span style={{width:36, height:1, background:"var(--accent)"}}/>
        <span style={{
          fontFamily:"var(--font-display)", fontWeight:700, fontSize:18,
          letterSpacing:"-0.01em", textTransform:"uppercase"
        }}>{name}</span>
        <span style={{
          fontFamily:"var(--font-mono)", fontSize:11, letterSpacing:"0.12em",
          color:"var(--fg-muted)", textTransform:"uppercase"
        }}>{role}</span>
      </div>
    </div>
  );

  return (
    <section className={paper ? "dl-paper" : undefined} style={{
      background: paper ? undefined : "var(--bg)",
      borderTop:"1px solid var(--line)", borderBottom:"1px solid var(--line)",
      paddingBlock:"clamp(56px, 6vw, 88px)"
    }}>
      <div className="dl-container">
        <div className={`dl-disc-quote-grid${flip ? " dl-flip" : ""}`}>
          {flip ? <>{text}{portrait}</> : <>{portrait}{text}</>}
        </div>
      </div>
    </section>
  );
};

// Resolve a team member's photo by name from the global TEAM array.
const teamPhoto = (name) => (typeof TEAM !== "undefined" ? TEAM.find(m => m.name === name)?.photo : undefined);

Object.assign(window, {
  DISCIPLINES, DiscHero, DiscHeroEditorial, DiscHeroTerminal,
  QuestionBlock, Capabilities, ProcessStrip,
  Prose, PageCTA, SiblingNav, InnerPage, SubPageCtx, SubControls,
  DiscQuote, teamPhoto,
});
