
/* Layout: blueprint reference manual. Sticky chapter index on the left, one reading column, wide tables scroll inside their own frames. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #17202c;
  --muted: #566274;
  --rule: #d9dee6;
  --accent: #1f4fbf;
  --accent-soft: #e6edfb;
  --key: #1f4fbf;      --key-bg: #eef3fd;
  --staff: #6b3fb8;    --staff-bg: #f3eefb;
  --pitfall: #b5402a;  --pitfall-bg: #fbefec;
  --numbers: #0f7a6c;  --numbers-bg: #e9f6f3;
  --interviewer: #9a6200; --interviewer-bg: #fbf3e2;
  --code-bg: #eef1f5;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --side-w: 300px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #161d27; --ink: #e4e9f0; --muted: #9aa6b6; --rule: #2a3442;
    --accent: #7ea6ff; --accent-soft: #1c2a45;
    --key: #7ea6ff; --key-bg: #172238;
    --staff: #b79bf0; --staff-bg: #221a35;
    --pitfall: #f08c76; --pitfall-bg: #2e1a16;
    --numbers: #5fd0bd; --numbers-bg: #11292a;
    --interviewer: #e8b250; --interviewer-bg: #2b2213;
    --code-bg: #1b2430;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #161d27; --ink: #e4e9f0; --muted: #9aa6b6; --rule: #2a3442;
  --accent: #7ea6ff; --accent-soft: #1c2a45;
  --key: #7ea6ff; --key-bg: #172238;
  --staff: #b79bf0; --staff-bg: #221a35;
  --pitfall: #f08c76; --pitfall-bg: #2e1a16;
  --numbers: #5fd0bd; --numbers-bg: #11292a;
  --interviewer: #e8b250; --interviewer-bg: #2b2213;
  --code-bg: #1b2430;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 17.5px; line-height: 1.62;
  margin: 0;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* top bar */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-bottom: 1px solid var(--rule);
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  font-family: var(--font-display);
}
.topbar .brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; white-space: nowrap; }
.topbar .brand span { color: var(--accent); }
.topbar .where { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.topbar button {
  font: 600 13px/1 var(--font-display); color: var(--ink); background: var(--accent-soft);
  border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; cursor: pointer;
}
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
.side {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 53px);
  height: calc(100vh - 53px - env(safe-area-inset-top, 0px)); overflow-y: auto;
  border-right: 1px solid var(--rule); background: var(--surface);
  padding: 16px 14px 40px max(16px, env(safe-area-inset-left, 0px));
  font-family: var(--font-display); font-size: 14px;
}
.side input[type="search"] {
  width: 100%; font: 14px var(--font-display); padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--bg); color: var(--ink); margin-bottom: 10px;
}
.progress-line { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; letter-spacing: 0.02em; }
.toc-part { margin-top: 14px; }
.toc-part > p { margin: 0 0 4px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.toc-part ol { list-style: none; margin: 0; padding: 0; }
.toc-part li { display: flex; align-items: flex-start; gap: 6px; }
.toc-part li a { display: block; flex: 1; padding: 4px 6px; border-radius: 5px; color: var(--ink); text-decoration: none; line-height: 1.3; }
.toc-part li a:hover { background: var(--accent-soft); }
.toc-part li a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toc-part li input { margin-top: 6px; accent-color: var(--accent); }
.toc-part li.done a { color: var(--muted); }

main {
  padding-block: 28px 120px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  min-width: 0;
}
.col { max-width: 800px; margin: 0 auto; }

.hero { padding: 24px 0 8px; border-bottom: 1px solid var(--rule); margin-bottom: 8px; }
.hero .eyebrow { font: 700 12px var(--font-display); letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
.hero h1 { font-family: var(--font-display); font-weight: 700; font-size: clamp(32px, 5vw, 52px); line-height: 1.05; letter-spacing: -0.025em; margin: 0 0 14px; text-wrap: balance; }
.hero p { color: var(--muted); font-size: 18px; max-width: 62ch; margin: 0 0 18px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; padding: 0; list-style: none; font: 13px var(--font-display); }
.legend li { border: 1px solid var(--rule); border-radius: 999px; padding: 4px 10px; background: var(--surface); }
.legend li b { font-weight: 700; }
.legend .l-key b { color: var(--key); } .legend .l-staff b { color: var(--staff); } .legend .l-pit b { color: var(--pitfall); }
.legend .l-num b { color: var(--numbers); } .legend .l-int b { color: var(--interviewer); }

.part-divider { margin: 72px 0 0; padding: 22px 0 6px; border-top: 3px solid var(--ink); }
.part-divider p { margin: 0; font: 700 12px var(--font-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.part-divider h2 { font: 700 34px/1.1 var(--font-display); letter-spacing: -0.02em; margin: 6px 0 0; text-wrap: balance; }

section.chapter { margin-top: 56px; padding-top: 8px; }
section.chapter > h2 {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(26px, 3.4vw, 34px);
  line-height: 1.12; letter-spacing: -0.02em; margin: 0 0 10px; text-wrap: balance;
}
section.chapter.design > h2::before { content: "Worked design"; display: block; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.lede { font-size: 19px; color: var(--muted); margin-top: 0; }
h3 { font-family: var(--font-display); font-weight: 700; font-size: 22px; line-height: 1.25; letter-spacing: -0.01em; margin: 40px 0 10px; text-wrap: balance; padding-top: 10px; border-top: 1px solid var(--rule); }
h4 { font-family: var(--font-display); font-weight: 700; font-size: 18px; margin: 28px 0 8px; text-wrap: balance; }
p, li { max-width: 72ch; }
ul, ol { padding-left: 1.3em; }
li { margin: 4px 0; }
strong { font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 28px 0; }
dl { margin: 12px 0; }
dt { font-family: var(--font-display); font-weight: 700; margin-top: 10px; }
dd { margin: 2px 0 0 0; padding-left: 14px; border-left: 2px solid var(--rule); }

code { font-family: var(--font-mono); font-size: 0.84em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
pre.code { background: var(--code-bg); border: 1px solid var(--rule); border-radius: 8px; padding: 14px 16px; overflow-x: auto; font-size: 14px; line-height: 1.5; }
pre.code code { background: none; padding: 0; font-size: inherit; }

.table-wrap { overflow-x: auto; margin: 16px 0 22px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 1.45; font-variant-numeric: tabular-nums; }
th, td { text-align: left; vertical-align: top; padding: 9px 12px; border-bottom: 1px solid var(--rule); min-width: 120px; }
th { font-family: var(--font-display); font-size: 13px; letter-spacing: 0.02em; background: var(--code-bg); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child { font-weight: 600; }

.callout { border-radius: 8px; padding: 12px 16px; margin: 20px 0; border: 1px solid var(--rule); border-left-width: 4px; }
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-family: var(--font-display); font-weight: 700; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; margin: 0 0 6px; }
.callout.key { background: var(--key-bg); border-left-color: var(--key); } .callout.key .callout-title { color: var(--key); }
.callout.staff { background: var(--staff-bg); border-left-color: var(--staff); } .callout.staff .callout-title { color: var(--staff); }
.callout.pitfall { background: var(--pitfall-bg); border-left-color: var(--pitfall); } .callout.pitfall .callout-title { color: var(--pitfall); }
.callout.numbers { background: var(--numbers-bg); border-left-color: var(--numbers); } .callout.numbers .callout-title { color: var(--numbers); }
.callout.interviewer { background: var(--interviewer-bg); border-left-color: var(--interviewer); } .callout.interviewer .callout-title { color: var(--interviewer); }

blockquote.say { margin: 18px 0; padding: 4px 0 4px 18px; border-left: 3px solid var(--accent); font-style: italic; }
blockquote.say::before { content: "Say it like this"; display: block; font: 700 11.5px var(--font-display); font-style: normal; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-bottom: 2px; }
blockquote.say p { margin: 6px 0; }

figure.diagram { margin: 22px 0; padding: 14px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); overflow-x: auto; }
figure.diagram pre.mermaid { margin: 0; text-align: center; background: none; font-family: var(--font-display); }
figure.diagram figcaption { font-size: 14.5px; color: var(--muted); margin-top: 10px; font-style: italic; }

details.qa { border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); margin: 10px 0; }
details.qa summary { cursor: pointer; padding: 10px 14px; font-family: var(--font-display); font-weight: 600; font-size: 16px; line-height: 1.35; list-style-position: outside; margin-left: 18px; }
details.qa[open] summary { border-bottom: 1px solid var(--rule); }
details.qa > div { padding: 4px 16px 10px; }

/* animated walkthroughs */
figure.anim { margin: 28px 0; padding: 16px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); }
.anim-eyebrow { font: 700 11.5px var(--font-display); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin: 0 0 2px; }
figure.anim h4 { margin: 0 0 4px; font-size: 20px; }
.anim-intro { color: var(--muted); margin: 0 0 12px; font-size: 16px; }
.anim-scenes { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.anim-scenes button { font: 600 13px var(--font-display); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); cursor: pointer; }
.anim-scenes button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.anim-stage { overflow-x: auto; border: 1px solid var(--rule); border-radius: 8px; background: var(--bg); }
.anim-stage svg { display: block; width: 100%; min-width: 680px; height: auto; }
.anim .edge { fill: none; stroke: var(--rule); stroke-width: 2; transition: stroke .3s; }
.anim .edge.active { stroke: var(--accent); stroke-width: 2.5; }
.anim .arrowhead { fill: var(--muted); }
.anim .node rect { fill: var(--surface); stroke: var(--muted); stroke-width: 1.5; transition: fill .3s, stroke .3s; }
.anim .node.store rect { fill: var(--numbers-bg); stroke: var(--numbers); }
.anim .node.queue rect { fill: var(--interviewer-bg); stroke: var(--interviewer); }
.anim .node.client rect { stroke-dasharray: 5 4; }
.anim .node.hot rect { stroke: var(--accent); stroke-width: 3; }
.anim .node.down rect { fill: var(--pitfall-bg); stroke: var(--pitfall); stroke-width: 3; stroke-dasharray: 6 4; }
.anim .node.flash rect { fill: var(--pitfall); }
.anim .node text { fill: var(--ink); font-family: var(--font-display); font-size: 14px; font-weight: 700; text-anchor: middle; }
.anim .node text.sub { fill: var(--muted); font: 500 11px var(--font-mono); }
.anim .node.down text.sub { fill: var(--pitfall); }
.anim .packet { fill: var(--accent); }
.anim .packet.reply { fill: var(--numbers); }
.anim-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
.anim-controls button, .anim-controls select { font: 600 13px var(--font-display); padding: 7px 12px; border-radius: 7px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); cursor: pointer; }
.anim-controls button.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); min-width: 78px; }
.anim-controls button:disabled { opacity: .45; cursor: default; }
.anim-dots { display: flex; gap: 5px; margin-left: auto; }
.anim-dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--rule); }
.anim-dots span.on { background: var(--accent); }
.anim-narr { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 12px; }
.anim-panel { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px; min-width: 0; font-size: 15.5px; line-height: 1.5; }
.anim-panel p { margin: 0; max-width: none; }
.anim-step { font: 600 11.5px var(--font-mono); color: var(--muted); margin-bottom: 3px !important; }
.anim-title { font: 700 17px/1.3 var(--font-display); margin-bottom: 4px !important; }
.anim-note { background: var(--interviewer-bg); border-left: 4px solid var(--interviewer); }
.anim-note .anim-label { font: 700 11.5px var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--interviewer); margin-bottom: 4px; }
.anim-note.empty { opacity: .55; }
@media (max-width: 760px) { .anim-narr { grid-template-columns: minmax(0, 1fr); } .anim-dots { margin-left: 0; } }

.toplink { position: fixed; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); font: 600 13px var(--font-display); background: var(--surface); color: var(--ink); border: 1px solid var(--rule); border-radius: 999px; padding: 9px 13px; text-decoration: none; box-shadow: 0 2px 10px rgba(0,0,0,.08); }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-block; }
  .side { display: none; position: fixed; inset: calc(env(safe-area-inset-top, 0px) + 53px) 0 0 0; height: auto; z-index: 4; border-right: 0; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  body.menu-open .side { display: block; }
  body { font-size: 17px; }
}
