/* ── Measure & Manufacture — companion design system ─────────────────
   Mirrors the defense deck: navy keystones, warm paper content, steel-teal
   + orange accents. Dark-first (phones in a dim seminar room), light kept. */
:root {
  color-scheme: dark;
  --bg: #0F1D2E; --bg2: #0A1626; --panel: #172A40; --panel2: #1F3550; --panel3: #27405E;
  --ink: #EDF2F7; --ink2: #C3D2DF; --muted: #9AA7B4; --faint: #6B7D91; --line: #2B4159; --line2: #3A526E;
  --teal: #5CA8CC; --teal-deep: #2E6E8E; --orange: #EE7D4C; --orange-deep: #D9622B;
  --green: #5DBB8C; --red: #E9705C; --gold: #E4B75A;
  --key-bg: #08121F; --key-ink: #EDF2F7;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 10px;
  --col: 46rem; --wide: 68rem;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #FBF9F4; --bg2: #F4F0E7; --panel: #FFFFFF; --panel2: #F1EDE4; --panel3: #E7E1D4;
    --ink: #1A2733; --ink2: #34465A; --muted: #68788A; --faint: #9AA7B4; --line: #D9D3C6; --line2: #C9C1B0;
    --teal: #2E6E8E; --teal-deep: #24587A; --orange: #D9622B; --orange-deep: #B84E1E;
    --green: #2E7D5B; --red: #B8432F; --gold: #A8801E;
    --key-bg: #0F1D2E; --key-ink: #EDF2F7;
    --shadow: 0 8px 24px rgba(26,39,51,.12);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #FBF9F4; --bg2: #F4F0E7; --panel: #FFFFFF; --panel2: #F1EDE4; --panel3: #E7E1D4;
  --ink: #1A2733; --ink2: #34465A; --muted: #68788A; --faint: #9AA7B4; --line: #D9D3C6; --line2: #C9C1B0;
  --teal: #2E6E8E; --teal-deep: #24587A; --orange: #D9622B; --orange-deep: #B84E1E;
  --green: #2E7D5B; --red: #B8432F; --gold: #A8801E;
  --key-bg: #0F1D2E; --key-ink: #EDF2F7;
  --shadow: 0 8px 24px rgba(26,39,51,.12);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .fade { animation: none !important; } }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; text-wrap: balance; }
p { margin: 0 0 .9em; }
.col { width: min(100% - 2rem, var(--col)); margin-inline: auto; }
.wide { width: min(100% - 2rem, var(--wide)); margin-inline: auto; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.eyebrow { font: 600 .72rem/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--teal); }
.eyebrow.orange { color: var(--orange); }
.eyebrow.muted { color: var(--muted); }

/* ── masthead ── */
.mast { padding: 3.2rem 0 2.2rem; background: var(--key-bg) radial-gradient(900px 420px at 85% -10%, rgba(92,168,204,.22), transparent 65%); color: var(--key-ink); border-bottom: 1px solid rgba(255,255,255,.08); }
.mast .explist a { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.18); color: #EDF2F7; }
.mast .rule { width: 3.6rem; height: 3px; background: var(--orange); margin: .9rem 0 1.1rem; }
.mast h1 { font-size: clamp(1.75rem, 4.6vw, 2.9rem); font-weight: 500; color: var(--key-ink); }
.mast .who { margin-top: 1.1rem; color: #C3D2DF; font-size: .98rem; }
.mast .who b { color: #fff; font-weight: 600; }
.mast .how { margin-top: 1.4rem; padding: .85rem 1rem; border: 1px solid rgba(255,255,255,.14); border-radius: var(--radius); background: rgba(255,255,255,.05); color: #C3D2DF; font-size: .92rem; display: flex; gap: .8rem; align-items: flex-start; }
.mast .how .dot { flex: 0 0 auto; width: .6rem; height: .6rem; margin-top: .45rem; border-radius: 50%; background: var(--orange); }

/* ── sticky chapter nav ── */
.nav { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.nav .row { display: flex; gap: .35rem; overflow-x: auto; padding: .55rem 0; scrollbar-width: none; }
.nav .row::-webkit-scrollbar { display: none; }
.nav a { flex: 0 0 auto; padding: .4rem .8rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: .84rem; font-weight: 500; white-space: nowrap; }
.nav a .n { font-family: var(--mono); font-size: .72rem; color: var(--faint); margin-right: .35rem; }
.nav a.on { color: var(--ink); border-color: var(--teal); background: color-mix(in srgb, var(--teal) 14%, transparent); }
.nav a:hover { text-decoration: none; color: var(--ink); }

/* ── sections & slide cards ── */
section.chapter { padding: 2.4rem 0 1rem; }
.chapter-head { margin-bottom: 1.4rem; }
.chapter-head h2 { font-size: clamp(1.5rem, 3.6vw, 2.2rem); margin-top: .35rem; }
.chapter-head .lede { color: var(--muted); margin-top: .5rem; max-width: 60ch; }
.keystone { background: var(--key-bg); color: var(--key-ink); border-radius: 14px; padding: 1.6rem 1.5rem 1.5rem; margin: 1.6rem 0; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.keystone::before { content: ""; position: absolute; inset: 0; background: radial-gradient(1200px 300px at 80% -20%, rgba(92,168,204,.18), transparent 60%); pointer-events: none; }
.keystone .rule { width: 2.6rem; height: 3px; background: var(--orange); margin: .7rem 0 .9rem; }
.keystone .statement { font-family: var(--serif); font-size: clamp(1.25rem, 3.2vw, 1.75rem); line-height: 1.28; font-weight: 500; color: #EDF2F7; }
.keystone .statement em { font-style: italic; color: #fff; }
.keystone .sub { margin-top: .9rem; color: #C3D2DF; font-size: .95rem; }
.keystone .sub p:last-child { margin-bottom: 0; }

.slide { margin: 1.2rem 0 1.6rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.slide-tag { display: inline-flex; align-items: center; gap: .45rem; font: 500 .74rem/1 var(--mono); color: var(--faint); letter-spacing: .04em; margin-bottom: .55rem; }
.slide-tag .pill { padding: .25rem .5rem; border-radius: 6px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.slide h3 { font-size: clamp(1.18rem, 2.8vw, 1.5rem); }
.slide .sub { color: var(--muted); margin: .45rem 0 .9rem; }
.slide .body { color: var(--ink2); }
.slide .body b { color: var(--ink); }
.slide figure { margin: 1rem 0; }
.slide figure img { border-radius: 8px; box-shadow: var(--shadow); background: #fff; }
.slide figcaption { font-size: .82rem; color: var(--muted); margin-top: .5rem; font-style: italic; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .8rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .8rem; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .6rem; }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .6rem; margin: .9rem 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .8rem .7rem; text-align: center; display: flex; flex-direction: column; justify-content: center; }
.stat .num { font-family: var(--serif); font-size: 1.9rem; font-weight: 600; color: var(--teal); line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat .num.green { color: var(--green); } .stat .num.red { color: var(--red); } .stat .num.orange { color: var(--orange); } .stat .num.muted { color: var(--muted); }
.stat .lab { font-size: .76rem; color: var(--muted); margin-top: .35rem; line-height: 1.25; }

/* tables */
.tbl-wrap { overflow-x: auto; margin: .8rem 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.tbl { border-collapse: collapse; width: 100%; font-size: .86rem; font-variant-numeric: tabular-nums; }
table.tbl th, table.tbl td { padding: .5rem .65rem; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl th { background: var(--panel2); color: var(--muted); font-weight: 600; font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; }
table.tbl td:first-child, table.tbl th:first-child { text-align: left; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td.best { color: var(--green); font-weight: 700; }
.explorer table.tbl td.best { background: color-mix(in srgb, var(--green) 14%, transparent); box-shadow: inset 0 0 0 1.5px var(--green); }
table.tbl td.heat { font-weight: 500; }
table.tbl td.bold { font-weight: 700; color: var(--ink); }
table.tbl.readable th { white-space: normal; }
table.tbl.readable td { padding: .55rem .7rem; font-size: .9rem; }
table.tbl td.bad { color: var(--red); }
table.tbl tr.hl td { background: color-mix(in srgb, var(--green) 12%, transparent); }
table.tbl tr.dim td { color: var(--muted); }
table.tbl .grp td { background: var(--panel2); color: var(--ink); font-weight: 600; text-align: left; font-size: .8rem; }
.tbl-note { font-size: .78rem; color: var(--faint); margin: .35rem .2rem .9rem; font-style: italic; }

/* disclosure ("more") */
details.more { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin: .9rem 0; }
details.more > summary { cursor: pointer; list-style: none; padding: .75rem 1rem; display: flex; align-items: center; gap: .6rem; color: var(--ink); font-weight: 500; font-size: .93rem; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "+"; font-family: var(--mono); color: var(--teal); width: 1.2rem; height: 1.2rem; border: 1px solid var(--teal); border-radius: 5px; display: inline-grid; place-items: center; font-size: .9rem; }
details.more[open] > summary::before { content: "–"; }
details.more > summary .hint { margin-left: auto; color: var(--faint); font-size: .76rem; font-weight: 400; }
details.more > .inner { padding: .2rem 1rem 1rem; border-top: 1px solid var(--line); color: var(--ink2); font-size: .94rem; }
details.more > .inner figure img { background: #fff; border-radius: 6px; }

/* speaker-notes style callout */
.note { border-left: 3px solid var(--orange); padding: .3rem 0 .3rem .9rem; margin: .9rem 0; color: var(--ink2); font-size: .93rem; }
.note b { color: var(--ink); }

/* ── explorers (interactive instruments) ── */
.explorer { margin: 1.4rem auto; width: min(100% - 1rem, var(--wide)); background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.explorer:fullscreen { width: 100%; height: 100%; border-radius: 0; overflow: auto; background: var(--bg); padding: 1rem; }
.explorer .ex-head { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel2); }
.explorer .ex-head .ex-icon { width: 2.1rem; height: 2.1rem; border-radius: 8px; display: grid; place-items: center; background: color-mix(in srgb, var(--teal) 18%, transparent); color: var(--teal); flex: 0 0 auto; }
.explorer .ex-head .ex-icon svg { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }
.explorer .ex-head .ex-title { font-family: var(--serif); font-size: 1.08rem; font-weight: 600; line-height: 1.1; }
.explorer .ex-head .ex-desc { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.explorer .ex-head .ex-tools { margin-left: auto; display: flex; gap: .4rem; }
.explorer .ex-body { padding: .9rem 1rem 1rem; }
.explorer .ex-foot { padding: .55rem 1rem .8rem; color: var(--muted); font-size: .8rem; border-top: 1px dashed var(--line); }
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .42rem .75rem; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel); color: var(--ink); font-size: .84rem; font-weight: 500; cursor: pointer; user-select: none; }
.btn:hover { border-color: var(--teal); }
.btn.on { background: color-mix(in srgb, var(--teal) 18%, transparent); border-color: var(--teal); color: var(--ink); }
.btn.sm { padding: .3rem .55rem; font-size: .78rem; }
.btn.icon { padding: .35rem .5rem; }
.seg { display: inline-flex; flex-wrap: wrap; gap: .3rem; }
.seg .btn { border-radius: 999px; }
.ctrl { display: flex; flex-wrap: wrap; gap: .7rem 1.2rem; align-items: flex-end; margin-bottom: .8rem; }
.ctrl > .btn { margin-bottom: .05rem; }
.ctrl label.lab { font-size: .74rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display: block; margin-bottom: .3rem; }
.ctrl .group { display: flex; flex-direction: column; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--line2); border-radius: 2px; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--teal); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--teal); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--teal); border: 3px solid var(--panel); cursor: pointer; }
.slider { display: grid; grid-template-columns: auto 1fr auto; gap: .7rem; align-items: center; min-width: 14rem; flex: 1 1 16rem; padding-bottom: .35rem; }
.slider .val { font-family: var(--mono); font-size: .86rem; color: var(--ink); min-width: 3.4em; text-align: right; }
.slider .name { font-size: .8rem; color: var(--muted); font-weight: 500; }
.readout { font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.legend .sw { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; vertical-align: -2px; margin-right: .35rem; }
.canvas-wrap { position: relative; width: 100%; background: var(--bg2); border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.canvas-wrap canvas { display: block; width: 100%; height: auto; touch-action: none; }
.frame-stage { position: relative; width: 100%; background: #000; border-radius: 10px; overflow: hidden; }
.frame-stage img { width: 100%; height: auto; display: block; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 640px) { .two { grid-template-columns: 1fr; } }
.chip { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600; letter-spacing: .04em; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.chip.teal { color: var(--teal); border-color: var(--teal); }
.chip.orange { color: var(--orange); border-color: var(--orange); }
.chip.green { color: var(--green); border-color: var(--green); }
.chip.red { color: var(--red); border-color: var(--red); }
.kbd { font-family: var(--mono); font-size: .74rem; padding: .05rem .35rem; border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); }
.gallery { display: grid; gap: .6rem; }
.gallery img { border-radius: 6px; background: #fff; }
.gallery .cap { font-size: .76rem; color: var(--muted); text-align: center; margin-top: .25rem; }
.tip { position: absolute; pointer-events: none; background: var(--panel2); color: var(--ink); border: 1px solid var(--line2); border-radius: 6px; padding: .3rem .5rem; font: .76rem/1.3 var(--mono); box-shadow: var(--shadow); white-space: nowrap; z-index: 5; }
.hidden { display: none !important; }
footer.end { padding: 2.5rem 0 4rem; color: var(--muted); font-size: .88rem; }
footer.end .keystone { margin-bottom: 1.4rem; }
.tocard { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .7rem; margin-top: 1rem; }
.tocard a { display: block; padding: .9rem 1rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-left: 4px solid var(--teal); }
.tocard a.c2 { border-left-color: var(--muted); } .tocard a.c3 { border-left-color: var(--teal); } .tocard a.c4 { border-left-color: var(--orange); }
.tocard a:hover { text-decoration: none; border-color: var(--teal); }
.tocard .t { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; }
.tocard .d { color: var(--muted); font-size: .84rem; margin-top: .25rem; }
.tocard .k { font-family: var(--mono); font-size: .7rem; color: var(--faint); margin-top: .45rem; }
.explist { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; }
.explist a { font-size: .78rem; padding: .3rem .6rem; border-radius: 999px; border: 1px solid var(--line); color: var(--ink2); background: var(--panel); }
.explist a:hover { border-color: var(--teal); text-decoration: none; }

/* panel grids with aligned captions */
.panels { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); }
.panels.n6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panels.n4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .panels.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .panels.n6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.panels .pt { font-weight: 600; font-size: .8rem; line-height: 1.25; min-height: 2.5em; display: flex; align-items: flex-end; margin-bottom: .3rem; }
.panels .pc { font-family: var(--mono); font-size: .74rem; color: var(--muted); margin-top: .3rem; min-height: 3.2em; line-height: 1.3; }
/* wheel cell picker */
.cellpick { display: grid; grid-template-columns: repeat(3, 2.6rem); gap: 4px; margin-top: .35rem; }
.cellpick button { height: 2.6rem; padding: 0; border-radius: 6px; border: 1px solid var(--line2); font: 600 .7rem var(--mono); display: grid; place-items: center; cursor: pointer; }
.seg .btn .sw { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }
.gallery .cap { min-height: 2.4em; line-height: 1.2; }
.readout.center { text-align: center; }

/* ── slide menu: always-visible jumper in the left margin (card), bottom bar on phones ── */
.rail { position: fixed; z-index: 40; top: 4.2rem; width: 10.25rem; left: max(.8rem, calc(50% + 5.75rem - 34rem - 11.25rem)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: .7rem .75rem .65rem; max-height: calc(100vh - 5.2rem); overflow-y: auto; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail .rl { font: 600 .62rem var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-bottom: .1rem; }
.rail .grp { font: 600 .66rem var(--sans); letter-spacing: .03em; color: var(--muted); margin: .55rem 0 .2rem; }
.rail .grp.c4 { color: var(--orange); } .rail .grp.c3 { color: var(--teal); }
.rail .row { display: flex; flex-wrap: wrap; gap: 3px; }
.rail a { flex: 0 0 auto; width: 1.75rem; height: 1.45rem; display: grid; place-items: center; border-radius: 5px; font: 500 .7rem var(--mono); color: var(--muted); background: var(--panel2); border: 1px solid transparent; }
.rail a.dark { background: var(--key-bg); color: #C3D2DF; }
.rail a:hover { text-decoration: none; color: var(--ink); border-color: var(--teal); }
.rail a.on, .rail a.on:hover { background: var(--orange); color: #fff; font-weight: 700; border-color: var(--orange); }
.rail .now { font: .72rem/1.3 var(--sans); color: var(--ink2); margin-top: .65rem; padding-top: .5rem; border-top: 1px solid var(--line); }
.rail .now b { color: var(--orange); font-family: var(--mono); }
[id^="s"], #intro, #ch2, #ch3, #ch4, #close { scroll-margin-top: 3.6rem; }
@media (min-width: 1100px) { body { padding-left: 11.5rem; } }
@media (max-width: 1099px) {
  .rail { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: none; border-radius: 0; border: 0; border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(0,0,0,.12); padding: .35rem .7rem .4rem; overflow: hidden; }
  .rail .rl, .rail .grp { display: none; }
  .rail .now { order: -1; margin: 0 0 .3rem; padding: 0; border: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rail { display: flex; flex-direction: column; }
  .rail .rows { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .rail .rows::-webkit-scrollbar { display: none; }
  .rail .row { flex-wrap: nowrap; gap: 2px; margin-right: .5rem; }
  .rail a { width: 1.85rem; height: 1.6rem; }
  body { padding-bottom: 4.8rem; }
  [id^="s"], #intro, #ch2, #ch3, #ch4, #close { scroll-margin-top: 3.4rem; }
}

/* clickable column headers */
table.tbl th.clickable { cursor: pointer; text-decoration: underline dotted var(--teal); text-underline-offset: 3px; color: var(--teal); }
table.tbl th.clickable:hover { color: var(--ink); background: color-mix(in srgb, var(--teal) 16%, transparent); }
table.tbl th.clickable.sel { color: var(--orange); text-decoration-color: var(--orange); background: color-mix(in srgb, var(--orange) 12%, transparent); }

.ctrl .vsep { width: 1px; align-self: stretch; background: var(--line2); margin: 0 .1rem; }
@media (max-width: 700px) { .ctrl .vsep { display: none; } }
