/* ══════════════════════════════════════════════════════════════════════════
   The case-study system — one design system, every page.
   Lifted from the Manual (2026 Portfolio/manual/): warm paper, near-black ink,
   hairline rules, Archivo for reading, Geist Mono for every label.

   Entries are siblings: same system, different content. A page's personality
   comes from what it argues and what it shows, never from its palette. Page
   stylesheets add components (a chart, a demo, a table) — they never redefine
   a token, a font or the shell.

   The build inlines this file into every page (tools/casepage.py), so each
   page still ships as one self-contained file.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root{
  color-scheme:light;
  --paper:#F4F3F1;   /* ground */
  --surface:#FAF9F7; /* panels, tables, demos */
  --sunk:#EAE8E4;    /* tags, code, inset */
  --ink:#1A1A18;     /* 15.7:1 on paper — every ratio here is measured, WCAG 2.1 */
  --ink-2:#45443F;   /* reading text, 8.8:1 */
  --muted:#6B6963;   /* captions and labels, 4.9:1 */
  --faint:#97948C;   /* decoration only — never text a reader must read */
  --rule:rgba(26,26,24,.13);
  --rule-strong:rgba(26,26,24,.28);

  /* one accent, for what you can act on: hover, current, focus */
  --accent:#283CC0;  --accent-soft:#E8EBFA;   /* 7.6:1 on paper, 8.0:1 on surface */
  /* two semantic colours, and only where they carry meaning:
     signal = excluded, failing, not shipped · ok = included, passing */
  --signal:#9A4A14;  --signal-soft:#F1E4D6;   /* 5.6:1 on paper */
  --ok:#3F6B4A;      --ok-soft:#DEE7DD;       /* 5.5:1 on paper */

  --rail:252px;
  --col-gap:96px;
  --content:860px;
  --measure:none;    /* body text runs the full content width, same as figures and captions */

  --sans:'Archivo',system-ui,-apple-system,'Helvetica Neue',Arial,sans-serif;
  --mono:'Geist Mono',ui-monospace,'SF Mono',Menlo,monospace;
  --ease:cubic-bezier(.16,1,.3,1);
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
  color-scheme:dark;
  --paper:#151513; --surface:#1C1C1A; --sunk:#232320;
  --ink:#ECEAE5; --ink-2:#C2BFB7; --muted:#9A978F; --faint:#6B6963;
  --rule:rgba(236,234,229,.12); --rule-strong:rgba(236,234,229,.26);
  --signal:#E0A45C; --signal-soft:#2C2116;
  --ok:#8DB597; --ok-soft:#1A251D;
  --accent:#F2D04A; --accent-soft:#2A2610;   /* 12.1:1 on paper, 11.3:1 on surface */
}}
:root[data-theme="dark"]{
  color-scheme:dark;
  --paper:#151513; --surface:#1C1C1A; --sunk:#232320;
  --ink:#ECEAE5; --ink-2:#C2BFB7; --muted:#9A978F; --faint:#6B6963;
  --rule:rgba(236,234,229,.12); --rule-strong:rgba(236,234,229,.26);
  --signal:#E0A45C; --signal-soft:#2C2116;
  --ok:#8DB597; --ok-soft:#1A251D;
  --accent:#F2D04A; --accent-soft:#2A2610;
}

/* ── Base ───────────────────────────────────────────────────────────────── */
*,*::before,*::after{box-sizing:border-box}
html{-webkit-text-size-adjust:100%;scroll-behavior:smooth}
body{
  margin:0;background:var(--paper);color:var(--ink);
  font-family:var(--sans);font-size:1.0625rem;line-height:1.62;letter-spacing:-.01em;
  font-variant-ligatures:none;-webkit-font-smoothing:antialiased;
}
img{display:block;max-width:100%;height:auto}
a{color:inherit;text-decoration-color:var(--rule-strong);text-underline-offset:.18em}
a{transition:color .2s var(--ease),text-decoration-color .2s var(--ease)}
a:hover{color:var(--accent);text-decoration-color:var(--accent)}
::selection{background:var(--ink);color:var(--paper)}
:focus-visible{outline:2px solid var(--accent);outline-offset:3px;border-radius:2px}
p{margin:0 0 1.05rem;text-wrap:pretty}
p:last-child{margin-bottom:0}
strong,b{font-weight:600}
code{font-family:var(--mono);font-size:.84em;background:var(--sunk);padding:.08em .34em;border-radius:2px}
sup{font-size:.62em;color:var(--muted);font-family:var(--mono)}

/* ── Type primitives ────────────────────────────────────────────────────── */
.mono{
  font-family:var(--mono);font-size:0.6875rem;line-height:1.3;letter-spacing:.14em;
  text-transform:uppercase;color:var(--muted);font-weight:400;
}
h1,.h-display{
  font-family:var(--sans);font-size:clamp(2.5rem,6.4vw,4.75rem);line-height:1;
  font-weight:600;font-stretch:112%;letter-spacing:-.036em;margin:0;text-wrap:balance;
}
h2,.h-section{
  font-family:var(--sans);font-size:clamp(1.625rem,3.2vw,2.25rem);line-height:1.08;
  font-weight:500;letter-spacing:-.034em;margin:0;text-wrap:balance;color:var(--ink);
}
h3{
  font-family:var(--sans);font-size:1.1875rem;line-height:1.25;font-weight:500;
  letter-spacing:-.022em;margin:2rem 0 .6rem;color:var(--ink);
}
.lede{
  font-size:clamp(1.125rem,1.7vw,1.375rem);line-height:1.45;letter-spacing:-.021em;
  color:var(--ink);margin:0;max-width:36em;text-wrap:pretty;
}
.lede b{font-weight:600}

/* ── Shell: fixed contents rail + one column ────────────────────────────── */
.shell{
  display:flex;gap:var(--col-gap);
  max-width:calc(var(--rail) + var(--col-gap) + var(--content) + 96px);
  margin:0 auto;padding:0 48px;
}
/* skip link: off screen until a keyboard reaches it */
.skip{position:fixed;top:12px;left:12px;z-index:100;padding:10px 14px;background:var(--ink);color:var(--paper);
  font-size:0.875rem;text-decoration:none;translate:0 -200%;transition:translate .2s var(--ease)}
.skip:focus{translate:0 0}
.main:focus{outline:none}
.rail{
  position:fixed;top:0;
  left:max(48px,calc((100vw - (var(--rail) + var(--col-gap) + var(--content) + 96px)) / 2 + 48px));
  width:var(--rail);height:100vh;padding:56px 0 40px;
  display:flex;flex-direction:column;gap:32px;z-index:20;overflow-y:auto;scrollbar-width:none;
}
.rail::-webkit-scrollbar{display:none}
.rail-mark{display:flex;flex-direction:column;gap:4px;text-decoration:none}
.rail-mark b{font-weight:500;letter-spacing:-.03em;font-size:0.9375rem;color:var(--ink)}
.rail-index{display:flex;flex-direction:column}
.rail-index[hidden]{display:none}
.rail-link{
  display:grid;grid-template-columns:26px 1fr 28px;align-items:center;gap:8px;
  padding:7px 0;text-decoration:none;
  font-family:var(--mono);font-size:0.6875rem;line-height:1.35;letter-spacing:.1em;text-transform:uppercase;
  color:var(--muted);transition:color .28s var(--ease),transform .2s var(--ease);
}
.rail-link em{font-style:normal}
.rail-link i{height:1px;width:28px;background:var(--accent);justify-self:start;transform:scaleX(0);transform-origin:left;transition:transform .12s linear}
.rail-link:hover,.rail-link[aria-current="true"]{color:var(--accent)}
/* the tick is a progress bar for the section being read (--p, 0–1, set by system.js) */
.rail-link[aria-current="true"] i{transform:scaleX(max(.15,var(--p,1)))}
/* case pages: the way home, first thing in the rail at every width */
.rail-back{text-decoration:none;margin-bottom:-16px}
.rail-back:hover{color:var(--accent)}
.rail-foot{margin-top:auto;display:flex;flex-direction:column;gap:8px}
.rail-foot a{text-decoration:none}
.rail-foot a:hover{color:var(--accent)}

.main{
  margin-left:calc(var(--rail) + var(--col-gap));
  width:min(var(--content),calc(100% - var(--rail) - var(--col-gap)));
  flex:none;padding-bottom:96px;
}

/* ── Reading switch ─────────────────────────────────────────────────────── */
.switch{padding:56px 0 0}
.seg{display:inline-flex;border:1px solid var(--rule-strong);border-radius:2px;overflow:hidden}
.seg button{
  appearance:none;border:0;background:transparent;cursor:pointer;white-space:nowrap;
  font-family:var(--mono);font-size:0.6875rem;letter-spacing:.14em;text-transform:uppercase;
  padding:9px 14px;color:var(--muted);transition:color .2s var(--ease),background .2s var(--ease),transform .2s var(--ease);
}
.seg button + button{border-left:1px solid var(--rule-strong)}
.seg button:hover:not([aria-selected="true"]){color:var(--accent);background:var(--accent-soft)}
.seg button[aria-selected="true"]{background:var(--ink);color:var(--paper)}
.seg button span{opacity:.7;margin-left:.5em}
.v[hidden]{display:none}

/* ── Cover ──────────────────────────────────────────────────────────────── */
.cover{padding:64px 0 72px;display:flex;flex-direction:column;gap:28px}
.cover .lede{margin-top:4px}

/* number — rule — label, the Manual's section mark */
.s-num{display:flex;align-items:baseline;gap:14px}
.s-num .mono:first-child{color:var(--ink)}
.s-num .dash{flex:1;height:1px;background:var(--rule);transform:translateY(-4px);min-width:24px}

/* label/value cells between two hairlines */
.meta{
  display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));
  column-gap:24px;border-top:1px solid var(--rule);border-bottom:1px solid var(--rule);
}
.meta > div{padding:12px 0;display:flex;flex-direction:column;gap:6px}
.meta > div > span:last-child{font-size:0.8125rem;line-height:1.4;color:var(--ink)}

/* ── Sections ───────────────────────────────────────────────────────────── */
/* space, not rules, separates sections — the s-num dash is the only mark */
.section{
  padding:88px 0;
  scroll-margin-top:24px;
}
/* Apple-style lockup: a quiet sans eyebrow over a display-size headline */
.section > .s-num{margin-bottom:14px;gap:.5em}
.section > .s-num .dash,.section > .s-num .mono:first-child{display:none}
.section > .s-num .mono{
  font-family:var(--sans);font-size:clamp(1.0625rem,1.5vw,1.3125rem);line-height:1.2;
  letter-spacing:-.012em;text-transform:none;font-weight:600;color:var(--muted);
}
.section > h2,.section > .h-anchor > h2{
  font-size:clamp(2.25rem,5.4vw,4rem);line-height:1.04;font-weight:600;letter-spacing:-.04em;
  max-width:14em;
}
.section > h2,.section > .h-anchor{margin-bottom:40px}
.h-anchor{display:flex;align-items:baseline;gap:.3em}
.h-anchor > h2{margin:0}
.section p,.section li{color:var(--ink-2)}
.section p b,.section p strong,.section li b{color:var(--ink)}
.section p,.section ul:not([class]),.section ol:not([class]){max-width:var(--measure)}
.section ul:not([class]),.section ol:not([class]){padding-left:1.1rem;margin:0 0 1.05rem}
.section li{margin-bottom:.35rem}

/* the closing line of a reading */
.close{border-top:1px solid var(--rule-strong);padding:40px 0 0}
.close p{color:var(--ink);font-size:clamp(1.125rem,1.7vw,1.375rem);line-height:1.45;letter-spacing:-.021em;max-width:36em}

/* ── Quote ──────────────────────────────────────────────────────────────── */
blockquote{
  margin:2rem 0;padding:0 0 0 20px;border-left:1px solid var(--ink);
  font-size:clamp(1.1875rem,1.8vw,1.4375rem);line-height:1.4;letter-spacing:-.022em;color:var(--ink);
  max-width:34em;
}
blockquote p,.section blockquote p{color:var(--ink);margin-bottom:.6rem;max-width:none}
blockquote cite{display:block;margin-top:10px;font-family:var(--mono);font-style:normal;
  font-size:0.6875rem;letter-spacing:.14em;text-transform:uppercase;color:var(--muted)}

/* ── Figures ────────────────────────────────────────────────────────────── */
figure{margin:2.4rem 0}
.panel{background:var(--surface);border:1px solid var(--rule);padding:20px;overflow-x:auto}
.panel img{width:100%}
.panel svg{display:block;width:100%;height:auto;color:var(--ink)}
/* screenshots and design-file exports carry their own white; mount them on a
   white plate in both themes so they read as specimens, not holes */
.plate{background:#fff;border:1px solid var(--rule);overflow:hidden}
.panel.plate{padding:16px}
.plate img{width:100%}
.plate video{display:block;width:100%;height:auto}
/* a whole product screen, shown the way Farsight's Figma shows it: no plate, the DS
   "Shadows/Artboard" effect (0 0 64px, 25% black) scaled to the ~43% the frame renders at */
.artboard{display:block;width:100%;height:auto;box-shadow:0 0 28px rgba(0,0,0,.25)}
/* a video under the title sits in the cover's own gap */
.cover figure{margin:0}
figure.natural .panel{display:flex;justify-content:center}
figure.natural .panel img{width:auto;max-width:100%}
figcaption{margin-top:12px;font-size:0.8125rem;line-height:1.55;color:var(--muted)}   /* spans its figure, same width as the image */
figcaption b{color:var(--ink);font-weight:500}
.pair{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}

/* ── Tags and provenance ────────────────────────────────────────────────── */
.tag{
  display:inline-block;font-family:var(--mono);font-size:0.625rem;letter-spacing:.12em;text-transform:uppercase;
  padding:3px 6px;border-radius:2px;white-space:nowrap;background:var(--sunk);color:var(--muted);
}
.tag.m{background:var(--ink);color:var(--paper)}   /* measured — the strongest claim */
/* copy a link to a section: # beside its title */
.anchor{
  appearance:none;border:0;background:none;cursor:pointer;padding:0 .3em;margin-left:.15em;
  font:inherit;font-size:1.25rem;line-height:1;color:var(--faint);opacity:0;min-height:32px;
  transition:opacity .2s var(--ease),color .2s var(--ease);
}
.h-anchor:hover .anchor,.anchor:focus-visible{opacity:1}
.anchor:hover{color:var(--accent)}
.anchor.done{opacity:1;color:var(--accent);font-family:var(--mono);font-size:0.6875rem;letter-spacing:.14em;text-transform:uppercase}
@media (hover:none){.anchor{opacity:.6}}

/* keyboard hint, only where there is a keyboard to use it */
.keys kbd{font-family:var(--mono);font-size:inherit;padding:1px 4px;border:1px solid var(--rule-strong);border-radius:2px;color:var(--ink-2)}
.theme-toggle{appearance:none;border:0;background:none;padding:0;cursor:pointer;text-align:left;align-self:flex-start;
  text-decoration:underline;text-underline-offset:.2em;text-decoration-color:var(--rule-strong)}
.theme-toggle:hover{color:var(--accent);text-decoration-color:var(--accent)}
@media (hover:none),(pointer:coarse){.keys{display:none}}

/* number · what · how it is known */
.scope{list-style:none;margin:1.8rem 0;padding:0;border-top:1px solid var(--rule-strong)}
.scope li{
  display:grid;grid-template-columns:6rem minmax(0,1fr) auto;gap:20px;align-items:baseline;
  padding:16px 0;border-bottom:1px solid var(--rule);margin:0;
}
.scope .n{font-size:clamp(1.5rem,2.6vw,2rem);font-weight:500;letter-spacing:-.04em;line-height:1;
  color:var(--ink);font-variant-numeric:tabular-nums}
.scope .d{font-size:0.9375rem;line-height:1.45;color:var(--ink)}
.scope .d em{display:block;font-style:normal;font-size:0.8125rem;color:var(--muted);margin-top:3px}

/* ── The honest boundary: what did not ship ─────────────────────────────── */
.boundary{
  border:1px solid var(--signal);background:var(--signal-soft);
  padding:24px;margin:2rem 0;
}
.boundary .lbl{font-family:var(--mono);font-size:0.6875rem;letter-spacing:.14em;text-transform:uppercase;
  color:var(--signal);margin:0 0 12px}
.boundary p{color:var(--ink)}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.colophon{border-top:1px solid var(--rule-strong);padding:32px 0 0;display:flex;flex-direction:column;gap:12px}
.colophon p{font-size:0.8125rem;line-height:1.6;color:var(--muted);max-width:var(--measure);margin:0}
.colophon b{color:var(--ink);font-weight:500}

/* ── Narrow ─────────────────────────────────────────────────────────────── */
@media (max-width:1199px){
  :root{--rail:200px;--col-gap:56px}
  .shell{padding:0 32px}
}
@media (max-width:899px){
  .shell{display:block;padding:0 20px}
  /* a translucent layer the page scrolls under, with a soft scroll edge
     instead of a hard divider */
  .rail{
    position:sticky;top:0;left:0;width:auto;height:auto;padding:0;margin:0 -20px;gap:0;
    background:color-mix(in srgb,var(--paper) 80%,transparent);
    -webkit-backdrop-filter:blur(18px) saturate(160%);backdrop-filter:blur(18px) saturate(160%);
    overflow:visible;
  }
  .rail::after{
    content:"";position:absolute;left:0;right:0;top:100%;height:14px;pointer-events:none;
    background:linear-gradient(color-mix(in srgb,var(--paper) 70%,transparent),transparent);
  }
  .rail{flex-direction:row;align-items:center}
  .rail-mark,.rail-foot{display:none}
  .rail-back{flex:none;margin:0;padding:12px 14px 12px 20px;white-space:nowrap;border-right:1px solid var(--rule)}
  .rail-index{flex:1;min-width:0}
  .rail-index{flex-direction:row;overflow-x:auto;scrollbar-width:none;padding:0 20px}
  .rail-index::-webkit-scrollbar{display:none}
  .rail-link{grid-template-columns:auto auto;gap:6px;padding:12px 16px 12px 0;white-space:nowrap}
  .rail-link i{display:none}
  .main{margin-left:0;width:auto}
  .switch{padding-top:28px}
  .cover{padding:40px 0 48px;gap:22px}
  .section{padding:56px 0;scroll-margin-top:56px}
  .pair{grid-template-columns:minmax(0,1fr)}
  .scope li{grid-template-columns:minmax(0,1fr) auto;gap:6px 16px}
  .scope .d{grid-column:1 / -1;grid-row:2}
}

/* ── Response: feedback on press, instantly ─────────────────────────────── */
.rail-link:active,.seg button:active{transform:scale(.97);transition-duration:60ms}

/* ── Accessibility preferences ──────────────────────────────────────────── */
@media (prefers-reduced-transparency:reduce){
  .rail{background:var(--paper)!important;-webkit-backdrop-filter:none!important;backdrop-filter:none!important}
}
@media (prefers-contrast:more){
  :root{--muted:var(--ink-2);--rule:var(--rule-strong)}
  .rail-link,.mono{color:var(--ink-2)}
}

@media (prefers-reduced-motion:reduce){
  html{scroll-behavior:auto}
  *,*::before,*::after{transition-duration:.01ms!important;animation-duration:.01ms!important}
}

/* ── What I'd do differently: numbered lessons closing every case ── */
.redo{list-style:none;margin:1.6rem 0 0;padding:0;counter-reset:r;border-top:1px solid var(--rule-strong)}
.redo li{counter-increment:r;display:grid;grid-template-columns:2.2rem minmax(0,1fr);gap:.9rem;
  padding:16px 0;border-bottom:1px solid var(--rule);margin:0}
.redo li::before{content:counter(r,decimal-leading-zero);font-family:var(--mono);font-size:0.6875rem;
  letter-spacing:.14em;color:var(--muted);padding-top:.3rem;font-variant-numeric:tabular-nums}
.redo li>*{grid-column:2}
.redo b{display:block;color:var(--ink);font-weight:500;margin-bottom:.25rem}
.redo span{display:block;font-size:0.9375rem;line-height:1.5;color:var(--ink-2);max-width:var(--measure)}

/* ── Previous / next case, closing every case page ── */
.pager{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin-top:64px;
  padding-top:24px;border-top:1px solid var(--rule-strong)}
.pg{display:flex;flex-direction:column;gap:8px;padding:18px 20px;border:1px solid var(--rule);
  border-radius:2px;color:var(--ink);text-decoration:none;transition:border-color .2s var(--ease),background .2s var(--ease)}
.pg.next{text-align:right;grid-column:2}
.pg span{font-family:var(--mono);font-size:0.6875rem;letter-spacing:.14em;text-transform:uppercase;color:var(--muted)}
.pg b{font-weight:500;font-size:clamp(1.0625rem,1.6vw,1.25rem);line-height:1.25;letter-spacing:-.02em}
.pg:hover{border-color:var(--ink);background:var(--surface)}
.pg:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (max-width:560px){.pager{grid-template-columns:minmax(0,1fr)}.pg.next{grid-column:auto}}

/* ── Night (Lab game pages) ───────────────────────────────────────────────
   A section can bring its game's night to the whole page while it holds the reader's eye. The page
   opts in with <html data-night>, names the night's colours as --night-* on :root, and toggles
   html.night; the system owns the swap and the ease. :root.night sits last so it outranks the dark
   theme's :root rules by source order. */
:root.night{
  --paper:var(--night-paper); --surface:var(--night-surface); --sunk:var(--night-sunk);
  --ink:var(--night-ink); --ink-2:var(--night-ink-2); --muted:var(--night-muted); --faint:var(--night-faint);
  --rule:var(--night-rule); --rule-strong:var(--night-rule-strong);
  --accent:var(--night-accent); --accent-soft:var(--night-accent-soft); color-scheme:dark;
}
[data-night] :is(body,.rail,.section :is(h2,h3,p,li,figcaption,.mono,b),.rail-link,.rail-mark b,.pg,.redo li,.close,.stage.game,.stage.game *){
  transition:background-color .9s var(--ease),color .9s var(--ease),border-color .9s var(--ease)}

/* ── Touch: every control gets a 44 px target (fingers, not cursors) ── */
@media (pointer:coarse){
  .anchor{min-width:44px;min-height:44px}
  .rail-link{min-height:44px}
  .rail-back{display:inline-flex;align-items:center;min-height:44px}
  .skip{min-height:44px}
}
