/* AI fluency site: shared styles.
   Palette is deliberately small: one warm accent for "the path taken",
   one cool for "candidates", one green for verification, one red for warnings. */
:root {
  --page:        #F7F5F1;
  --ink:         #1A1D21;
  --ink-soft:    #4B5560;
  --rule:        #DFD9D0;
  --card:        #FFFFFF;
  --stage:       #0B1014;
  --accent:      #E0913A;   /* chosen path / focal */
  --cool:        #4A88B0;   /* candidates */
  --deep:        #2B5D7D;   /* structural */
  --verify:      #4E8E6A;   /* checking habits */
  --warn:        #C2543D;   /* misconception being named */

  /* Text-strength versions of the meaning colours. The base hues above are
     for fills, strokes and large type; small text on a tint needs these. */
  --accent-ink:  #9A5F14;
  --accent-soft: #F3C58F;   /* accent as text on --ink */
  --deep-strong: #21495F;
  --verify-ink:  #2F6147;
  --warn-ink:    #A8432F;
  --ink-strong:  #2A2F35;   /* hover on ink-filled controls */

  /* Tints: the same meanings as quiet backgrounds, plus their edges. */
  --accent-tint: #FDEBD3;
  --cool-tint:   #EEF5FA;
  --verify-tint: #F1F7F3;
  --verify-rule: #BFD8C8;
  --warn-tint:   #FBF1EE;
  --warn-rule:   #E8C9C0;
  --note-tint:   #FFF8E8;
  --note-rule:   #E8D9AE;
  --sunk:        #F0EDE7;   /* inline code and quoted prompts */
  --rule-strong: #C2B6A6;

  /* Text on the dark 3D stage. */
  --stage-ink:   #EAF1F6;
  --stage-soft:  #D7E2EA;
  --stage-dim:   #90A4B2;

  /* Surfaces that stay dark in both themes (the key idea) and the one
     solid call to action. */
  --inverse:     #1A1D21;
  --on-inverse:  #F7F5F1;
  --cta:         #1A1D21;
  --cta-hover:   #2A2F35;
  --on-cta:      #F7F5F1;

  --paper-stage: #F6EBDC;   /* the paper theatre's card: the same in both themes */
  --maxw: 44rem;
  color-scheme: light;
}

/* Dark theme: follows the reader's system setting. Same meanings, same
   accent; tints become deep washes and text colours lift to keep AA. */
@media screen and (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page:        #16191D;
    --ink:         #E8E6E1;
    --ink-soft:    #A5AEB8;
    --rule:        #2F343A;
    --card:        #1E2227;
    --cool:        #6FA5C8;
    --deep:        #8CC0E0;
    --verify:      #6DB08A;
    --warn:        #E07A62;

    --accent-ink:  #E8A65A;
    --deep-strong: #A9D1EA;
    --verify-ink:  #8FD0AA;
    --warn-ink:    #F0A08C;
    --ink-strong:  #FFFFFF;

    --accent-tint: #3A2A17;
    --cool-tint:   #1B2A35;
    --verify-tint: #16261D;
    --verify-rule: #2E4F3C;
    --warn-tint:   #2E1B17;
    --warn-rule:   #5A322A;
    --note-tint:   #2C2615;
    --note-rule:   #5A4E2B;
    --sunk:        #262A30;
    --rule-strong: #4A4F56;

    --inverse:     #0E1114;
    --on-inverse:  #F1EFEA;
    --cta:         #E8E6E1;
    --cta-hover:   #FFFFFF;
    --on-cta:      #16191D;
  }
  .keyidea { box-shadow: inset 0 0 0 1px var(--rule); }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 1.0625rem/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
/* Browser surfaces, from the palette: selection is the highlighter tint,
   the caret is the accent, the scrollbar sits in the page's rule colour. */
::selection { background: var(--accent-tint); color: var(--ink); }
html { scrollbar-color: var(--rule-strong) var(--page); }
input, textarea { caret-color: var(--accent-ink); }

/* ---------- skip link & focus ---------- */
.skip { position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--page); padding: .6rem 1rem; z-index: 100; }
.skip:focus { left: .5rem; top: .5rem; }
:focus-visible { outline: 3px solid var(--deep); outline-offset: 2px; }

/* ---------- layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }
.wide { max-width: 64rem; }

header.site { border-bottom: 1px solid var(--rule); background: var(--card);
  position: sticky; top: 0; z-index: 20; }
header.site .wrap { max-width: 64rem; display: flex; align-items: center;
  justify-content: space-between; gap: 1rem; min-height: 3.5rem; flex-wrap: wrap; }
header.site a.brand { display: inline-flex; align-items: center; min-height: 44px;
  font-weight: 650; letter-spacing: -.01em; color: var(--ink); text-decoration: none; white-space: nowrap; }
header.site nav { display: flex; gap: .5rem; flex-wrap: wrap; }
header.site nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 .25rem;
  color: var(--ink-soft); text-decoration: none; font-size: .9375rem; white-space: nowrap;
  text-underline-offset: 4px; }
/* Phones: one row. The brand already links home, and the nav scrolls
   sideways rather than wrapping into a second sticky row. */
@media (max-width: 560px) {
  header.site .wrap { flex-wrap: nowrap; gap: .75rem; min-height: 3rem; padding-right: 0; }
  header.site nav { flex-wrap: nowrap; gap: .25rem; overflow-x: auto; scrollbar-width: none;
    padding-right: 1rem; }
  header.site nav::-webkit-scrollbar { display: none; }
  header.site nav a { font-size: .875rem; }
  header.site nav a:first-child { display: none; }
}
header.site nav a:hover, header.site nav a[aria-current="page"] { color: var(--deep); text-decoration: underline; }

main { padding: 2.5rem 0 4rem; }
footer.site { border-top: 1px solid var(--rule); padding: 2rem 0 3rem;
  color: var(--ink-soft); font-size: .9375rem; }

/* ---------- type ---------- */
h1 { margin: 0 0 .75rem; }
h2 { font-size: 1.3125rem; line-height: 1.3; margin: 2.25rem 0 .5rem; font-weight: 650; }
h3 { font-size: 1.0625rem; margin: 1.5rem 0 .35rem; font-weight: 650; }
p  { margin: 0 0 1rem; }
a  { color: var(--deep); }
.lede { font-size: 1.1875rem; color: var(--ink-soft); }
.stage-label { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem;
  font-weight: 650; color: var(--ink-soft); margin: 0 0 .35rem; }

/* ---------- the wrong version, named out loud (P2) ---------- */
.prior { background: var(--warn-tint);
  padding: .9rem 1.1rem; margin: 1.5rem 0; border-radius: 0 6px 6px 0; }
.prior p { margin: 0; }
.prior .tag { display: block; text-transform: uppercase; letter-spacing: .07em;
  font-size: .6875rem; font-weight: 700; color: var(--warn-ink); margin-bottom: .3rem; }

/* ---------- analogy + its limit (P7) ---------- */
.analogy { background: var(--card); border: 1px solid var(--rule); border-radius: 8px;
  padding: 1rem 1.1rem; margin: 1.5rem 0; }
.analogy .limit { margin: .6rem 0 0; color: var(--warn-ink); font-size: .9375rem; }

/* ---------- the move to make (P6) ---------- */
.move { border: 1px solid var(--verify); background: var(--verify-tint);
  border-radius: 8px; padding: 1rem 1.1rem; margin: 2rem 0; }
.move .tag { display: block; text-transform: uppercase; letter-spacing: .07em;
  font-size: .6875rem; font-weight: 700; color: var(--verify-ink); margin-bottom: .3rem; }
.move p { margin: 0; }

/* ---------- honesty note (P10) ---------- */
.uncertain { font-size: .9375rem; color: var(--ink-soft);
  border-top: 1px dashed var(--rule); padding-top: .75rem; margin-top: 2rem; }

/* ---------- 3D stage ---------- */
figure.diagram { margin: 2rem 0; }
.stage { position: relative; width: 100%; aspect-ratio: 16 / 10;
  min-height: 300px; background: var(--stage); border-radius: 10px;
  overflow: hidden; touch-action: pan-y; }
.stage canvas { display: block; width: 100%; height: 100%; }
@media (max-width: 560px) { .stage { aspect-ratio: 4 / 3; } }

.stage .labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; color: var(--stage-ink); font-size: .8125rem; font-weight: 550;
  text-shadow: 0 1px 3px rgba(0,0,0,.85); white-space: nowrap;
  transform: translate(-50%, -50%); }
.lbl.chosen { color: var(--accent); }
.lbl.dim    { color: var(--stage-dim); }

.stage .hint { position: absolute; left: .75rem; bottom: .6rem;
  color: var(--stage-dim); font-size: .75rem; pointer-events: none; }
.stage .fallback { position: absolute; inset: 0; display: grid; place-items: center;
  padding: 1.5rem; text-align: center; color: var(--stage-soft); font-size: .9375rem; }

/* ---------- controls under a stage ---------- */
.controls { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0 0; align-items: center; }
button.pill { font: inherit; font-size: .9375rem; cursor: pointer; min-height: 44px;
  background: var(--card); color: var(--ink); border: 1px solid var(--rule);
  border-radius: 999px; padding: .4rem .9rem;
  display: inline-flex; align-items: center; justify-content: center; }
button.pill:hover { border-color: var(--deep); color: var(--deep); }
button.pill.primary { background: var(--deep); border-color: var(--deep); color: var(--card); }
button.pill.primary:hover { background: var(--deep-strong); color: var(--card); }
button.pill:disabled { opacity: .45; cursor: default; }
.word-choices { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 0; }
button.word { font: inherit; font-size: .9375rem; cursor: pointer;
  border: 1px solid var(--cool); background: var(--card); color: var(--deep);
  border-radius: 6px; padding: .3rem .6rem; min-height: 44px; }
button.word:hover { background: var(--cool-tint); }
button.word .p { color: var(--ink-soft); font-size: .8125rem; margin-left: .35rem;
  font-variant-numeric: tabular-nums; }

figcaption { font-size: .9375rem; color: var(--ink-soft); margin-top: .75rem; }
.sentence-readout { font-size: 1.0625rem; margin: .75rem 0 0; min-height: 1.65em; }
.sentence-readout .given { color: var(--ink-soft); }
.sentence-readout .picked { color: var(--accent-ink); font-weight: 600; }

/* ---------- text equivalent (P9) ---------- */
details.equiv { margin: .25rem 0 0; font-size: .9375rem; }
details.equiv summary { cursor: pointer; color: var(--deep); padding: .6rem 0; }
details.equiv > div { border-left: 2px solid var(--rule); padding-left: .9rem; margin-top: .6rem; }
details.equiv table { border-collapse: collapse; font-size: .875rem; margin: .5rem 0; }
details.equiv th, details.equiv td { text-align: left; padding: .2rem .7rem .2rem 0; }
details.equiv th { color: var(--ink-soft); font-weight: 550; }

abbr.term { text-decoration: underline dotted var(--cool); cursor: help; text-underline-offset: 3px;
  border-radius: 3px; transition: background-color .15s var(--ease), text-decoration-color .15s var(--ease); }
abbr.term:hover, abbr.term.is-open { --term-hl: color-mix(in srgb, var(--cool) 18%, transparent);
  background: var(--cool-tint); background: var(--term-hl); box-shadow: 0 0 0 2px var(--term-hl);
  text-decoration-style: solid; }
abbr.term:focus-visible { outline-offset: 1px; }

/* Definition popover for abbr.term (reading.js). A small card above the word,
   flipped below near the top of the screen, with a notch pointing at it. */
.term-tip { position: absolute; z-index: 60; width: max-content; max-width: min(19rem, calc(100vw - 2rem));
  padding: .7rem .9rem .75rem; border-radius: 10px; background: var(--card); color: var(--ink);
  border: 1px solid var(--rule); font-size: .9375rem; line-height: 1.5; text-align: left;
  box-shadow: 0 1px 2px rgba(20, 25, 30, .08), 0 10px 28px -10px rgba(20, 25, 30, .35);
  opacity: 0; transform: translateY(4px); pointer-events: none;
  transition: opacity .16s var(--ease), transform .2s var(--ease); }
.term-tip.below { transform: translateY(-4px); }
.term-tip.is-open { opacity: 1; transform: none; pointer-events: auto; }
.term-tip[hidden] { display: none; }
.term-tip-word { display: block; margin-bottom: .15rem; font-family: var(--display);
  font-weight: 650; letter-spacing: -.01em; color: var(--deep-strong); }
.term-tip::after { content: ""; position: absolute; left: var(--notch, 50%); bottom: -6px;
  width: 10px; height: 10px; margin-left: -5px; background: inherit; transform: rotate(45deg);
  border: solid var(--rule); border-width: 0 1px 1px 0; }
.term-tip.below::after { bottom: auto; top: -6px; border-width: 1px 0 0 1px; }
@media (prefers-reduced-motion: reduce) {
  .term-tip, .term-tip.below { transform: none; transition: opacity .12s linear; }
}
@media print { .term-tip { display: none !important; } }

/* ---------- lesson list ---------- */
ol.lessons { list-style: none; counter-reset: l; padding: 0; margin: 1.5rem 0; }
ol.lessons li { counter-increment: l; border-top: 1px solid var(--rule); }
ol.lessons li:last-child { border-bottom: 1px solid var(--rule); }
ol.lessons a { display: grid; grid-template-columns: 2.25rem 1fr auto; gap: .9rem;
  align-items: baseline; padding: .9rem .25rem; text-decoration: none; color: var(--ink); }
ol.lessons a:hover { background: var(--card); }
ol.lessons a::before { content: counter(l); color: var(--ink-soft);
  font-variant-numeric: tabular-nums; font-size: .9375rem; }
ol.lessons .t { font-weight: 600; }
ol.lessons .d { grid-column: 2; color: var(--ink-soft); font-size: .9375rem; }
ol.lessons .badge { font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-soft); border: 1px solid var(--rule); border-radius: 999px;
  padding: .1rem .5rem; white-space: nowrap; }
ol.lessons .badge.is3d { color: var(--deep); border-color: var(--deep); }

nav.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem;
  border-top: 1px solid var(--rule); padding-top: 1.25rem; font-size: .9375rem; }
nav.pager a { text-decoration: none; }
nav.pager .n { display: block; color: var(--ink-soft); font-size: .8125rem; }

table.plain { border-collapse: collapse; width: 100%; font-size: .9375rem; margin: 1.25rem 0; }
table.plain th, table.plain td { text-align: left; vertical-align: top;
  padding: .5rem .7rem .5rem 0; border-bottom: 1px solid var(--rule); }
table.plain th { color: var(--ink-soft); font-weight: 550; }

.paired { display: grid; gap: .9rem; margin: 1.5rem 0; }
@media (min-width: 680px) { .paired.two { grid-template-columns: 1fr 1fr; } }
.paired .box { background: var(--card); border: 1px solid var(--rule);
  border-radius: 8px; padding: .9rem 1rem; font-size: .9375rem; }
.paired .box .box-h { margin: 0 0 .4rem; font-size: .8125rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-soft); }
.paired .box.bad  { border-color: var(--warn-rule); }
.paired .box.good { border-color: var(--verify-rule); }
.paired .box p:last-child { margin-bottom: 0; }
.quote { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .875rem; background: var(--sunk); padding: .15rem .35rem; border-radius: 3px; }

.notice { background: var(--note-tint); border: 1px solid var(--note-rule); border-radius: 8px;
  padding: .9rem 1.1rem; margin: 1.5rem 0; font-size: .9375rem; }
.notice p:last-child { margin-bottom: 0; }

/* ---------- state line under a stage ---------- */
.stage-state { margin: .6rem 0 0; font-weight: 600; min-height: 1.65em; }
.stage.tall { aspect-ratio: 16 / 9; }
button.pill[aria-pressed="true"] { background: var(--verify-tint); border-color: var(--verify); color: var(--verify-ink); }
/* "On" is never colour alone: a pressed toggle also carries a check mark. */
button.pill[aria-pressed="true"]::before { content: ""; flex: none; width: .85em; height: .85em;
  margin-right: .4em; background: currentColor;
  -webkit-mask: var(--check) center / contain no-repeat; mask: var(--check) center / contain no-repeat; }
button.pill.small { font-size: .8125rem; padding: .25rem .7rem; min-height: 0; position: relative; }
/* Small pills keep their size in the row but take a full-size tap. */
button.pill.small::after { content: ""; position: absolute; inset: -.5rem -.2rem; }
ol.citations { margin: .5rem 0 0; padding-left: 1.4rem; font-size: .875rem; color: var(--ink-soft); }
ol.citations li { margin-bottom: .2rem; }
.tag-real { color: var(--verify-ink); font-weight: 650; }
.tag-fake { color: var(--warn-ink); font-weight: 650; }
.sliders { display: grid; gap: .6rem; margin: .8rem 0 0; }
@media (min-width: 560px) { .sliders { grid-template-columns: 1fr 1fr; gap: 1.2rem; } }
.sliders label { display: grid; gap: .2rem; font-size: .9375rem; font-weight: 600; }
.sliders input[type=range] { width: 100%; height: 44px; margin: 0; accent-color: var(--deep); cursor: pointer; }

/* ---------- workbench (hands-on tools) ---------- */
.workbench { background: var(--card); border: 1px solid var(--rule);
  border-radius: 8px; padding: 1.1rem 1.2rem 1.2rem; margin: 2.25rem 0; }
.workbench h2 { margin: 0 0 .4rem; }
.wb-intro { color: var(--ink-soft); font-size: .9375rem; }
.wb-q { font-size: .9375rem; color: var(--ink-soft); font-style: italic; margin-bottom: .5rem; }
.wb-answer { background: var(--page); border-radius: 6px; padding: .8rem .9rem; line-height: 1.8; margin: 0; }
button.seg { font: inherit; text-align: left; background: none; border: 0; padding: .05rem .1rem;
  border-radius: 3px; cursor: pointer; color: inherit; border-bottom: 1px dashed var(--rule-strong); }
button.seg:hover { background: var(--cool-tint); }
button.seg[aria-pressed="true"] { background: var(--accent-tint);
  border-bottom: 2px solid var(--accent); }   /* solid, thicker: picked without relying on colour */
button.seg.risky { box-shadow: inset 0 -2px 0 var(--warn); }
.wb-result { margin-top: .8rem; font-size: .9375rem; }
.wb-result ul { padding-left: 1.2rem; margin: .4rem 0 0; }
.wb-result li { margin-bottom: .35rem; }
.wb-you { color: var(--accent-ink); }
.wb-note { font-size: .9375rem; color: var(--ink-soft); margin: .7rem 0 0; }
.wb-cards { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .6rem; }
@media (min-width: 680px) { .wb-cards { grid-template-columns: 1fr 1fr; } }
.wb-card { border: 1px solid var(--rule); border-radius: 6px; padding: .7rem .8rem; }
.wb-claim { margin: 0; font-weight: 550; }
.wb-card .controls { margin-top: .5rem; }
.wb-why { font-size: .875rem; color: var(--ink-soft); margin: .5rem 0 0; }
.wb-label { display: block; font-weight: 600; font-size: .9375rem; margin: .8rem 0 .25rem; }
.wb-input { width: 100%; min-height: 44px; font: inherit; font-size: .9375rem; padding: .5rem .6rem;
  border: 1px solid var(--rule); border-radius: 6px; background: var(--card); color: var(--ink); }
.wb-input:focus { border-color: var(--deep); }
textarea.wb-input { resize: vertical; }
.wb-output { background: var(--page); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .875rem; }
.wb-qs { padding-left: 1.3rem; margin: .8rem 0 0; }
.wb-qs li { margin-bottom: .6rem; }
.wb-qs .controls { display: inline-flex; margin: 0 0 0 .5rem; vertical-align: middle; }
.wb-verdict { padding: .6rem .8rem; border-radius: 6px; margin: 0 0 .4rem; }
.wb-verdict.peak { background: var(--verify-tint); border: 1px solid var(--verify-rule); }
.wb-verdict.slope { background: var(--note-tint); border: 1px solid var(--note-rule); }
.wb-verdict.trough { background: var(--warn-tint); border: 1px solid var(--warn-rule); }
.wb-checks { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .9375rem; }
.wb-checks .yes { color: var(--verify-ink); font-weight: 600; }
.wb-checks .no { color: var(--ink-soft); }
.wb-fieldset { border: 0; padding: 0; margin: 0; }
.wb-fieldset legend { font-weight: 600; margin-bottom: .4rem; }
/* Radio and checklist rows: the label is the target, a full 44px row. The
   control's top margin centres it on the label's first line. */
.wb-radio { display: flex; gap: .6rem; align-items: flex-start; }
.wb-radio input, .wb-checklist input { width: 1.25rem; height: 1.25rem; margin: .7rem 0 0; flex: none; cursor: pointer; }
.wb-radio input { accent-color: var(--deep); }
.wb-radio label, .wb-checklist label { flex: 1; min-height: 44px; padding: .6rem 0; cursor: pointer; }
p.wb-result:not(:empty) { background: var(--verify-tint); border: 1px solid var(--verify-rule); padding: .6rem .8rem; border-radius: 6px; }
.wb-marked { background: var(--page); border-radius: 6px; padding: .7rem .8rem; white-space: pre-wrap; margin: .5rem 0 0; }
.wb-marked mark { background: var(--accent-tint); border-bottom: 2px solid var(--accent); padding: 0 .1rem; }
.wb-checklist { list-style: none; padding: 0; margin: .4rem 0 0; }
.wb-checklist li { display: flex; gap: .6rem; align-items: flex-start; border-bottom: 1px solid var(--rule); }
.wb-checklist input { accent-color: var(--verify); }

ol.lessons .badges { display: flex; gap: .3rem; }
ol.lessons .badge.istool { color: var(--verify-ink); border-color: var(--verify); }

/* ---------- toolkit ---------- */
.pocket { border: 2px solid var(--ink); border-radius: 10px; padding: 1rem 1.2rem 1.2rem; margin: 2rem 0; background: var(--card); }
.pocket-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.pocket-head h2 { margin: 0; }
.pocket-grid { display: grid; gap: .9rem 1.4rem; margin-top: .9rem; }
@media (min-width: 620px) { .pocket-grid { grid-template-columns: 1fr 1fr; } }
.pocket-cell h3 { margin: 0 0 .25rem; font-size: .9375rem; text-transform: uppercase; letter-spacing: .05em; color: var(--deep); }
.pocket-cell p, .pocket-cell ol { font-size: .9375rem; margin: 0 0 .3rem; }
.pocket-cell ol { padding-left: 1.2rem; }
ol.moves li { margin-bottom: .5rem; }

/* ---------- evidence ---------- */
.toc { display: flex; flex-wrap: wrap; gap: 0 1.1rem; font-size: .9375rem; margin: 1rem 0 0;
  padding: .15rem 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.toc a { display: inline-flex; align-items: center; min-height: 44px; }
.scroll-x { overflow-x: auto; }
.doc { margin-top: 2.5rem; border-top: 1px solid var(--rule); }
.doc h4 { margin: 1.3rem 0 .3rem; }
.doc code { font-size: .875em; background: var(--sunk); padding: .05rem .3rem; border-radius: 3px; }
.stats-grid { display: grid; gap: 1rem; }
table.stats caption { text-align: left; font-weight: 650; padding: .3rem 0; }
table.stats td.num, table.stats th.num { text-align: right; font-variant-numeric: tabular-nums; width: 4rem; }
table.stats td.barcell { width: 40%; }
table.stats .bar { display: block; height: .55rem; background: var(--cool); border-radius: 2px; }
figure.plainfig { margin: 1.5rem 0; }
figure.plainfig img { max-width: 100%; height: auto; border: 1px solid var(--rule); border-radius: 6px;
  background: #fff; /* the charts are drawn for a white ground in both themes */ }
ul.downloads li { margin-bottom: .4rem; }

/* ---------- print: the pocket card and checklists travel well ---------- */
@media print {
  header.site, footer.site, .skip, nav.pager, .controls, figure.diagram, .toc { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  main { padding: 0; }
  .workbench, .pocket { break-inside: avoid; border-color: #000; }
  a { color: inherit; text-decoration: none; }
}

/* =====================================================================
   Reading layer: type hierarchy for key points, and scroll motion.
   Motion only runs when html.motion is set (JS present, IntersectionObserver
   available, prefers-reduced-motion not set). Without it every element
   below renders in its final state.
   ===================================================================== */
:root {
  /* Headings: Schibsted Grotesk, a newspaper grotesque (SIL OFL, self-hosted,
     licence in assets/fonts/). Plain and factual, like the site's voice. */
  --display: "Schibsted Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI",
             Roboto, "Helvetica Neue", Arial, sans-serif;
  --hl: rgba(224, 145, 58, .42);   /* highlighter: --accent at 42% */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
html { scroll-padding-top: 5rem; }

/* ---------- display type ---------- */
@font-face {
  font-family: "Schibsted Grotesk";
  src: url("../fonts/schibsted-grotesk-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 900; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
                 U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
                 U+2212, U+2215, U+FEFF, U+FFFD;
}
h1, h2, h3, .keyline { font-family: var(--display); font-weight: 650; }
h1 { font-size: clamp(2.1rem, 1.4rem + 3vw, 3rem); line-height: 1.06; letter-spacing: -.028em;
  font-weight: 700; text-wrap: balance; }
h2 { letter-spacing: -.018em; text-wrap: balance; }
h3 { letter-spacing: -.01em; }
.lesson h2, .wrap > h2, .sheet > h2, .doc h2 { font-size: clamp(1.45rem, 1.2rem + 1vw, 1.75rem);
  margin-top: 3rem; }
.lesson h2::before, .wrap > h2::before, .sheet > h2::before, .doc h2::before { content: ""; display: block; width: 2rem; height: 3px;
  background: var(--accent); border-radius: 2px; margin-bottom: .7rem; }
.workbench h2::before { content: none; }
.workbench h2 { font-size: 1.3125rem; margin-top: 0; }

/* ---------- lesson hero ---------- */
.lesson-hero { padding: .5rem 0 1.75rem; margin-bottom: .5rem; }
.lesson-hero .stage-label { display: flex; align-items: baseline; gap: .6rem; }
.lesson-hero .stage-label .num { font-family: var(--display); font-weight: 700; font-size: 1.5rem; letter-spacing: -.02em;
  color: var(--accent-ink); font-variant-numeric: lining-nums tabular-nums; text-transform: none; }
.course-track { display: flex; gap: 4px; margin: .4rem 0 1.4rem; max-width: 22rem; }
.course-track span { flex: 1; height: 4px; border-radius: 2px; background: var(--rule); }
.course-track span.done { background: var(--rule-strong); }
.course-track span.now  { background: var(--accent); }
.lesson-hero .lede { font-size: clamp(1.15rem, 1.05rem + .4vw, 1.3125rem); line-height: 1.5;
  color: var(--ink); max-width: 38rem; margin-bottom: 1rem; }
.lesson-meta { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap;
  gap: .35rem .5rem; font-size: .8125rem; color: var(--ink-soft); }
.lesson-meta li { border: 1px solid var(--rule); border-radius: 999px; padding: .15rem .65rem;
  background: var(--card); }

/* ---------- the shift: wrong version, then the idea to leave with ---------- */
.shift { display: grid; gap: .75rem; margin: 0 0 2.25rem; }
.shift .prior { margin: 0; border: 1px solid var(--warn-rule); border-radius: 10px; padding: 1rem 1.15rem; }
.prior strong { background: linear-gradient(var(--warn), var(--warn)) 0 60% / 100% 2px no-repeat;
  padding-bottom: 1px; }
.keyidea { position: relative; background: var(--inverse); color: var(--on-inverse); border-radius: 12px;
  padding: 1.35rem 1.4rem 1.25rem; }
.keyidea .tag { display: block; text-transform: uppercase; letter-spacing: .08em;
  font-size: .6875rem; font-weight: 700; color: var(--accent); margin-bottom: .45rem; }
.keyline { font-size: clamp(1.3rem, 1.1rem + 1vw, 1.625rem); line-height: 1.3; margin: 0;
  letter-spacing: -.015em; font-weight: 600; text-wrap: balance; }
a.keyjump { display: inline-flex; align-items: center; gap: .35rem; margin-top: .85rem;
  color: var(--accent-soft); font-size: .875rem; text-decoration: none; min-height: 44px; }
a.keyjump::after { content: "\2193"; transition: transform .3s var(--ease); }
a.keyjump:hover { text-decoration: underline; }
a.keyjump:hover::after { transform: translateY(3px); }
.keyidea a.keyjump:focus-visible { outline-color: var(--accent-soft); }

/* ---------- key sentence in the body: a highlighter stroke ---------- */
mark.key { color: inherit; font-weight: 600; padding: 0 .12em; border-radius: 2px;
  background: linear-gradient(transparent 48%, var(--hl) 48%) 0 0 / 100% 100% no-repeat;
  -webkit-box-decoration-break: clone; box-decoration-break: clone; }
strong { font-weight: 650; }
.lesson > p strong { color: var(--ink); }

/* ---------- the move: the page's closing beat ---------- */
.move { position: relative; border-width: 1.5px; border-radius: 12px; padding: 1.2rem 1.3rem 1.25rem 3.6rem; }
.move::before { content: ""; position: absolute; left: 1.2rem; top: 1.25rem; width: 1.6rem; height: 1.6rem;
  border-radius: 50%; background: var(--verify) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 60% no-repeat; }
.move p { font-size: 1.125rem; line-height: 1.55; }
/* A recap in the shape of a move: neutral card, quiet label. */
.move.recap { background: var(--card); border-color: var(--rule); }
.move.recap .tag { color: var(--ink-soft); }

/* ---------- reading progress, under the sticky header ---------- */
.readbar { position: absolute; left: 0; bottom: -1px; height: 3px; width: 100%;
  background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); pointer-events: none; }

/* =====================================================================
   Motion
   ===================================================================== */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* hero: staggered entrance on load */
html.motion .lesson-hero > * { animation: rise .8s var(--ease) both; }
html.motion .lesson-hero > :nth-child(2) { animation-delay: .06s; }
html.motion .lesson-hero > :nth-child(3) { animation-delay: .12s; }
html.motion .lesson-hero > :nth-child(4) { animation-delay: .2s; }
html.motion .lesson-hero > :nth-child(5) { animation-delay: .28s; }
html.motion .course-track span { transform-origin: 0 50%; animation: fill .5s var(--ease) both; }
html.motion .course-track span.done,
html.motion .course-track span.now { animation-delay: calc(.25s + var(--i, 0) * 45ms); }

/* everything below the hero: rise into place as it enters the viewport */
html.motion main .wrap > :where(:not(.lesson-hero, ol.lessons, script, noscript, .shift, .paper-stage, .paper-beat)),
html.motion ol.lessons > li,
html.motion .shift > * {
  opacity: 0; transform: translateY(22px);
  transition: opacity .7s var(--ease), transform .8s var(--ease);
  transition-delay: var(--rd, 0ms);
}
html.motion main .wrap > .in,
html.motion ol.lessons > li.in,
html.motion .shift > .in { opacity: 1; transform: none; }

/* the wrong version is struck through as you read past it */
html.motion .prior strong { background-size: 0% 2px; transition: background-size .9s var(--ease) .45s; }
html.motion .prior.in strong { background-size: 100% 2px; }

/* the key sentence is highlighted as it reaches the reading line */
html.motion mark.key { background-size: 0% 100%; transition: background-size 1.1s var(--ease); }
html.motion mark.key.lit { background-size: 100% 100%; }
mark.key.flash { animation: keyflash 1.4s var(--ease); }
@keyframes keyflash { 0%, 100% { box-shadow: 0 0 0 0 rgba(224,145,58,0); }
  30% { box-shadow: 0 0 0 6px rgba(224,145,58,.25); } }

@media (prefers-reduced-motion: reduce) {
  .readbar { display: none; }
  mark.key.flash { animation: none; }
}

/* paper-cut preloader: first page of a session only (see preloader.js). It
   is inert markup unless the head flag sets html.preload. The canvas draws
   the whole five-second sequence; the sheet then lifts away. */
.preloader { display: none; }
html.preload .preloader { display: block; position: fixed; inset: 0; z-index: 200;
  background: var(--paper-stage); cursor: pointer;
  transition: transform .7s cubic-bezier(.7, 0, .3, 1); }
html.preload .preloader.is-lifting { transform: translateY(-100%); }
html.preload:not(.preload-out) { overflow: hidden; }
html.preload:not(.preload-out) .lesson-hero > *,
html.preload:not(.preload-out) .course-track span { animation-play-state: paused; }
.preloader canvas { display: block; width: 100%; height: 100%; }
.preloader-skip { position: absolute; left: 0; right: 0; bottom: max(1rem, env(safe-area-inset-bottom));
  margin: 0; text-align: center; font-size: .8125rem; color: #6B4E36; letter-spacing: .01em; }

@media print {
  .preloader { display: none !important; }
  html.motion * { opacity: 1 !important; transform: none !important; animation: none !important; }
  .keyidea { background: #fff; color: #000; border: 2px solid #000; }
  .readbar, a.keyjump { display: none; }
}

/* =====================================================================
   Landing page
   ===================================================================== */
.landing .lesson-hero.home { padding: 2.5rem 0 2.25rem; }
.landing .lesson-hero h1 { font-size: clamp(2.3rem, 1.4rem + 4vw, 3.5rem); max-width: 14ch; }
.cta-row { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: 1.5rem; }
.cta-sep { width: 1px; height: 1.5rem; background: var(--rule); margin: 0 .25rem; }
@media (max-width: 480px) {
  .cta-row { flex-direction: column; align-items: stretch; gap: .6rem; }
  .cta-row a.cta { justify-content: center; }
  .cta-sep { width: 2.5rem; height: 1px; margin: 0; align-self: center; }
}
a.cta { display: inline-flex; align-items: center; min-height: 44px; padding: .55rem 1.15rem;
  border-radius: 999px; border: 1px solid var(--rule); background: var(--card);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: .9375rem;
  transition: border-color .2s, transform .2s var(--ease); }
a.cta:hover { border-color: var(--deep); color: var(--deep); transform: translateY(-1px); }
a.cta.primary { background: var(--cta); border-color: var(--cta); color: var(--on-cta); }
a.cta.primary:hover { background: var(--cta-hover); color: var(--on-cta); }
a.cta.primary::after { content: "\2192"; margin-left: .5rem; transition: transform .25s var(--ease); }
a.cta.primary:hover::after { transform: translateX(3px); }

/* about the author */
.about { background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
  padding: 1.5rem 1.5rem 1.25rem; margin: .5rem 0 1rem; }
.about-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.about h2 { margin: 0; font-size: 1.5rem; }
.about h2::before { content: none !important; }
.about-role { margin: .15rem 0 0; color: var(--ink-soft); font-size: .875rem; line-height: 1.45; }
.about-text p { margin-bottom: .85rem; }
.about-text p:first-child { font-size: 1.125rem; }
.about-text p:last-child { margin-bottom: 0; }

/* lesson list, segmented into the five parts */
.part-head { margin: 2.5rem 0 .25rem; }
.part-meta { margin: 0 0 .1rem; font-size: .75rem; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-soft); }
.part-head h3 { margin: 0 0 .3rem; font-size: 1.35rem; letter-spacing: -.015em; }
.part-gist { margin: 0; color: var(--ink-soft); font-size: .9375rem; }
.part-head + ol.lessons { margin-top: .9rem; }

/* a full reference under a claim */
p.source { font-size: .8125rem; line-height: 1.5; color: var(--ink-soft); margin-top: -.25rem; }
p.source cite { font-style: italic; }

/* author photo in "Why I made this": a small portrait, 180 x 240 */
.about { display: grid; gap: 1.25rem; }
.about-photo { margin: 0; }
.about-photo img { display: block; width: 180px; max-width: 100%; height: auto;
  aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; background: var(--rule); }
@media (min-width: 680px) {
  .about { grid-template-columns: minmax(0, 1fr) 180px; align-items: start; gap: 1.5rem; }
  .about-photo { order: 2; }
}

/* =====================================================================
   Paper story: a paper-cut theatre that follows the lesson (paper-core.js).
   Wide screens: a sticky stage in a second column. Narrow screens: still
   frames between sections. Hidden entirely if WebGL is unavailable.
   ===================================================================== */
.paper-stage { display: none; }
/* The sheet of paper is a layer under the image, so the card is in place
   before its frame is drawn and the frame fades in on matching paper. */
.paper-card { margin: 1.75rem 0; display: grid; }
.paper-card::before { content: ""; grid-area: 1 / 1; aspect-ratio: 4 / 3; border-radius: 14px;
  background: var(--paper-stage);
  box-shadow: 0 1px 2px rgba(60, 40, 20, .12), 0 8px 24px -12px rgba(60, 40, 20, .35); }
.paper-card img { grid-area: 1 / 1; display: block; width: 100%; height: auto; aspect-ratio: 4 / 3;
  border-radius: 14px; transition: opacity .5s var(--ease); }
.paper-card:not(.is-ready) img { opacity: 0; }
.paper-card figcaption { grid-row: 2; font-size: .875rem; color: var(--ink-soft); margin-top: .55rem; }
html.paper-off .paper-card { display: none; }

@media (min-width: 1100px) {
  .wrap.has-paper { max-width: 80rem; position: relative;
    padding-right: calc(1.25rem + min(36rem, 40vw)); }
  .has-paper .paper-stage { display: block; position: absolute; top: 0; bottom: 0;
    right: 1.25rem; width: calc(min(36rem, 40vw) - 2rem); }
  .paper-sticky { position: sticky; top: 4.75rem; transition: opacity .6s var(--ease), filter .6s var(--ease); }
  .paper-canvas { position: relative; width: 100%; aspect-ratio: 1 / 1.02; max-height: calc(100vh - 9rem);
    border-radius: 16px; overflow: hidden; background: var(--paper-stage);
    box-shadow: 0 1px 2px rgba(60, 40, 20, .12), 0 14px 36px -18px rgba(60, 40, 20, .45); }
  .paper-canvas canvas { display: block; width: 100%; height: 100%; }
  .paper-cap { margin: .7rem .25rem 0; font-size: .875rem; line-height: 1.45; color: var(--ink-soft);
    min-height: 2.9em; text-wrap: pretty; }
  .paper-stage.is-resting .paper-sticky { opacity: .38; filter: saturate(.6); }
  .paper-card { display: none; }
  html.paper-off .wrap.has-paper { max-width: var(--maxw); padding-right: 1.25rem; }
  html.paper-off .paper-stage { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .paper-sticky, .paper-card img { transition: none; }
}
@media print { .paper-stage, .paper-card { display: none !important; } }

/* =====================================================================
   Home page story: the paper scene is the page's backdrop, and each section
   is a sheet of paper that scrolls over it (paper-core.js, backdrop mode).
   The scene has the screen to itself in the gaps between sheets, and keeps
   playing, a little dimmer, while a sheet is being read.
     --lead   space above the first sheet
     --gap    space between sheets
     --col    width of the column of sheets
     --align  the column's left margin: centred, or at the left on wide screens
   Without WebGL or JavaScript the backdrop is hidden and the sheets stack as
   a plain page (html.paper-off here; PAPER_OFF_NOSCRIPT in build_site.py).
   ===================================================================== */
main:has(> .paper-story) { padding-top: 0; }
.paper-story { --lead: 46vh; --gap: 56vh; --col: 40rem; --align: auto; display: grid; }
.paper-story > * { grid-area: 1 / 1; min-width: 0; }
.paper-backdrop .paper-canvas { position: sticky; top: 0; height: 100vh; height: 100lvh;
  width: 100%; aspect-ratio: auto; max-height: none; border-radius: 0; box-shadow: none;
  overflow: hidden; background: var(--paper-stage);
  transition: opacity .9s var(--ease), filter .9s var(--ease); }
.paper-backdrop canvas { display: block; width: 100%; height: 100%; }
.paper-backdrop.is-reading .paper-canvas { opacity: .82; filter: saturate(.8); }

.paper-story .story-flow { position: relative; width: 100%; max-width: 64rem;
  padding-top: var(--lead); padding-bottom: 5rem; }
.paper-story .sheet { max-width: var(--col); margin: 0 auto var(--gap) var(--align);
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
  padding: 1.5rem 1.5rem 1.4rem;
  box-shadow: 0 1px 2px rgba(60, 40, 20, .12), 0 14px 36px -18px rgba(60, 40, 20, .45); }
.paper-story .sheet:last-child { margin-bottom: 0; }
.paper-story .sheet.lesson-hero { padding: 1.75rem 1.75rem 1.6rem; }
.sheet > h2:first-child, .sheet .part-head { margin-top: 0; }
.sheet > :last-child { margin-bottom: 0; }
.sheet ol.lessons { margin-bottom: 0; }
.sheet ol.lessons li:last-child { border-bottom: 0; }
.sheet ol.lessons a:hover { background: var(--page); }
@media (min-width: 680px) {
  .paper-story .about { grid-template-columns: minmax(0, 1fr) 140px; }
}

@media (min-width: 1100px) {
  .paper-story { --lead: 3rem; --gap: 50vh; --col: 37rem; --align: 0px; }
}
html.paper-off .paper-backdrop { display: none; }
html.paper-off .paper-story { --lead: 2.5rem; --gap: 1.25rem; --col: var(--maxw); --align: auto; }
@media (prefers-reduced-motion: reduce) {
  .paper-backdrop .paper-canvas { transition: none; }
}
@media print {
  .paper-backdrop { display: none !important; }
  .paper-story { --lead: 0px; --gap: 1.25rem; --col: none; --align: auto; }
  .paper-story .sheet { box-shadow: none; }
}

/* Windows high contrast: the system repaints tints and borders in one
   colour, so pressed toggles switch to the system highlight pair. */
@media (forced-colors: active) {
  button.pill[aria-pressed="true"], button.seg[aria-pressed="true"] {
    forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight; }
  button.seg.risky { text-decoration: underline wavy; text-underline-offset: 3px; }
  .course-track span.now { forced-color-adjust: none; background: Highlight; }
}
