/* Stackline — a transit map for full-stack interview prep.
   Tokens first; every colour below derives from these. */
:root {
  --paper: #edf0f4;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --ink: #0e1a2b;
  --muted: #5b6779;
  --rule: #d5dbe3;
  --signal: #f5b700;      /* the "you are here" yellow */
  --signal-ink: #3d2e00;
  --ok: #1f8a4c;
  --bad: #c62f2f;
  --focus: #2563eb;

  /* line colours, one per track */
  --java: #e8590c; --spring: #3f9b2f; --arch: #0e7490; --javascript: #c99400;
  --typescript: #2f6fd6; --react: #0aa2c0; --css: #7c3aed; --dsa: #0f9d8a;
  --sql: #b4235a; --hr: #6b7280; --algo: #c2410c; --patterns: #9333ea; --sysdesign: #b45309; --collections: #be123c; --streams: #0369a1; --microservices: #15803d; --microfrontends: #c026d3;

  --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;

  --r-sm: 6px; --r: 12px; --r-lg: 20px;
  --shadow: 0 1px 2px rgb(14 26 43 / .06), 0 4px 14px rgb(14 26 43 / .06);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --rail: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0b1220; --surface: #121b2e; --surface-2: #17223a; --ink: #e7ecf3; --muted: #93a0b4;
    --rule: #26324b; --signal-ink: #1a1400; --focus: #7aa7ff; --ok: #4cc283; --bad: #ff6b6b;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 18px rgb(0 0 0 / .25);
    --javascript: #e3b21b; --hr: #9ca3af; --sql: #e05289; --arch: #22a6c7; --css: #a074ff; --spring: #5cbf4a; --algo: #f97316; --patterns: #c084fc; --sysdesign: #f59e0b; --collections: #fb7185; --streams: #38bdf8; --microservices: #4ade80; --microfrontends: #e879f9;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0b1220; --surface: #121b2e; --surface-2: #17223a; --ink: #e7ecf3; --muted: #93a0b4;
  --rule: #26324b; --signal-ink: #1a1400; --focus: #7aa7ff; --ok: #4cc283; --bad: #ff6b6b;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 18px rgb(0 0 0 / .25);
  --javascript: #e3b21b; --hr: #9ca3af; --sql: #e05289; --arch: #22a6c7; --css: #a074ff; --spring: #5cbf4a; --algo: #f97316; --patterns: #c084fc; --sysdesign: #f59e0b; --collections: #fb7185; --streams: #38bdf8; --microservices: #4ade80; --microfrontends: #e879f9;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; touch-action: pan-x pan-y; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 17px/1.6 var(--font-body);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 .5em; }
h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: 1.45rem; font-weight: 700; }
h3 { font-size: 1.15rem; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: inherit; }
code, pre, kbd { font-family: var(--font-mono); font-size: .88em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; letter-spacing: -0.02em; }
.brand svg { width: 30px; height: 30px; flex: none; }
.search-box { flex: 1; min-width: 0; max-width: 520px; margin-left: auto; position: relative; }
.search-box input {
  width: 100%; padding: 10px 14px 10px 38px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink); font: inherit; font-size: 16px;
}
.search-box svg { position: absolute; left: 13px; top: 50%; translate: 0 -50%; width: 16px; color: var(--muted); }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); cursor: pointer; flex: none; }
.icon-btn svg { width: 18px; height: 18px; }
.net-pill { font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--signal); color: var(--signal-ink); display: none; }
body.offline .net-pill { display: inline-block; }

.layout { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); max-width: 100vw; min-height: calc(100dvh - 61px); }
.rail { position: sticky; top: 61px; align-self: start; height: calc(100dvh - 61px); overflow: auto; padding: 20px 12px; border-right: 1px solid var(--rule); }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r);
  text-decoration: none; color: var(--muted); font-weight: 700;
}
.nav-link svg { width: 20px; height: 20px; flex: none; }
@media (hover: hover) and (pointer: fine) { .nav-link:hover { color: var(--ink); background: var(--surface-2); } }
.nav-link[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
.nav-link[aria-current="page"] svg { color: var(--focus); }
.rail-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 22px 12px 6px; font-weight: 700; }
.rail-track { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: var(--r-sm); text-decoration: none; font-size: .92rem; color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .rail-track:hover { color: var(--ink); background: var(--surface-2); } }
.rail-track i { width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--c); flex: none; }

main { padding: 28px clamp(16px, 4vw, 48px) 120px; min-width: 0; overflow-x: clip; }
main:focus { outline: none; }
/* clip, not hidden: overflow hidden on the root silently breaks position: sticky */
html, body { overflow-x: clip; }
.page { max-width: 1100px; margin: 0 auto; animation: page-in .35s var(--ease-out); }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }

.tabbar { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .brand span { display: none; }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  /* floating glass tab bar: a translucent capsule that refracts the page behind it */
  .tabbar {
    --glass-tint: rgb(255 255 255 / .55); --glass-rim: rgb(255 255 255 / .9); --glass-edge: rgb(14 26 43 / .08);
    --lens: rgb(255 255 255 / .75);
    display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; z-index: 30;
    left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); width: min(calc(100% - 32px), 360px);
    translate: -50% 0; padding: 5px; border-radius: 999px; isolation: isolate;
    background: linear-gradient(180deg, rgb(255 255 255 / .22), rgb(255 255 255 / 0) 55%), var(--glass-tint);
    backdrop-filter: blur(18px) saturate(190%) brightness(1.05); -webkit-backdrop-filter: blur(18px) saturate(190%) brightness(1.05);
    box-shadow:
      inset 0 1px 0 var(--glass-rim), inset 0 -1px 0 rgb(255 255 255 / .25),
      inset 0 0 0 1px var(--glass-edge), inset 0 0 18px rgb(255 255 255 / .18),
      0 10px 30px rgb(14 26 43 / .16), 0 2px 6px rgb(14 26 43 / .08);
  }
  /* specular sheen along the top edge */
  .tabbar::after {
    content: ''; position: absolute; inset: 1px 14% auto; height: 45%; border-radius: 999px; pointer-events: none; z-index: -1;
    background: linear-gradient(180deg, rgb(255 255 255 / .35), transparent); filter: blur(2px);
  }
  /* the lens: a brighter glass pill that glides to the active tab */
  .tabbar::before {
    content: ''; position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc((100% - 10px) / 3); border-radius: 999px; z-index: -1;
    background: var(--lens); opacity: var(--lens-on, 1);
    box-shadow: inset 0 1px 0 var(--glass-rim), inset 0 0 0 1px var(--glass-edge), 0 2px 8px rgb(14 26 43 / .1);
    transform: translateX(calc(var(--i, 0) * 100%));
    transition: transform .55s cubic-bezier(.3, 1.35, .45, 1), opacity .2s;
  }
  .tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 6px 0 5px; border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .01em; color: color-mix(in srgb, var(--ink) 62%, transparent); text-decoration: none; transition: padding .45s var(--bar-spring); }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--focus); }
  .tabbar a span { display: block; height: 1.25em; line-height: 1.25; margin-top: 1px; overflow: hidden; transition: height .4s var(--bar-spring), margin .4s var(--bar-spring), opacity .2s; }
  /* scrolling down tucks the bar into a narrower icon-only capsule (labels fold away so the icons
     sit centred); a tap on it or any upward scroll opens it back up */
  .tabbar { --bar-spring: cubic-bezier(.3, 1.25, .5, 1); transition: width .45s var(--bar-spring), padding .45s var(--bar-spring); }
  .tabbar.is-min { width: min(calc(100% - 32px), 210px); padding: 4px; cursor: pointer; }
  .tabbar.is-min::before { top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 3); }
  .tabbar.is-min a { padding: 8px 0; }
  .tabbar.is-min a span { height: 0; margin-top: 0; opacity: 0; }
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .tabbar { --glass-tint: color-mix(in srgb, var(--surface) 94%, transparent); } }
}

/* ---------- primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--rule);
  background: var(--surface-2); color: var(--ink); font: 600 .875rem/1.2 var(--font-body); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .12s var(--ease-out), background .15s;
  user-select: none; -webkit-user-select: none;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:active { transform: scale(.97); }
@media (hover: hover) { .btn:hover { background: var(--surface-2); } }
.btn.primary { background: var(--signal); color: var(--signal-ink); border-color: transparent; }
@media (hover: hover) { .btn.primary:hover { background: color-mix(in srgb, var(--signal) 88%, var(--ink)); } }
.btn.icon { width: 38px; padding: 0; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.signal { background: var(--signal); color: var(--signal-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 0 11px; font-size: .8rem; border-radius: 8px; }
.btn[aria-pressed="true"] { background: color-mix(in srgb, var(--focus) 18%, var(--surface)); color: var(--ink); border-color: var(--focus); }
.field { font: inherit; font-size: 15px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--rule); background: var(--surface); color: var(--ink); min-height: 38px; max-width: 100%; min-width: 0; }
input.field { width: auto; }
input[type=number].field, input[type=text].field { width: 7.5em; }
@media (max-width: 600px) { .field { font-size: 16px; } }
.field-wrap { display: inline-flex; align-items: center; gap: 8px; }
.field-label { font-size: .85rem; color: var(--muted); font-weight: 700; }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow); }
.eyebrow { font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; color: var(--muted); margin: 0 0 .4em; }
.muted { color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); border: 1px solid var(--rule); white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); }
.lvl-easy { color: var(--ok); } .lvl-medium { color: var(--javascript); } .lvl-hard { color: var(--bad); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spacer { flex: 1; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 96px; translate: -50% 0; z-index: 50; background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: .9rem; animation: toast 2.6s var(--ease-out) forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(10px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- home: the transit map ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 28px; }
.hero h1 { max-width: 16ch; }
.hero-lede { font-size: 1.12rem; color: var(--muted); max-width: 52ch; }
.map-wrap { position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 12px; box-shadow: var(--shadow); overflow-x: auto; }
.map-wrap svg { display: block; min-width: 720px; width: 100%; height: auto; }
.map-line { fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.map-line.draw { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1.6s var(--ease-out) forwards; animation-delay: var(--d); }
@keyframes draw { to { stroke-dashoffset: 0; } }
.map-stop { fill: var(--surface); stroke-width: 3.5; transition: r .2s var(--ease-out); cursor: pointer; transform-box: fill-box; transform-origin: center; animation: stop-in .35s var(--ease-out) backwards; animation-delay: var(--d, 0ms); }
@keyframes stop-in { from { opacity: 0; transform: scale(.2); } }
.map-stop.done { fill: var(--c); }
.map-stop:focus-visible { r: 9; outline: none; }
@media (hover: hover) and (pointer: fine) { .map-stop:hover { r: 9; } }
.map-label { font: 700 13px var(--font-display); fill: var(--ink); }
.map-sub { font: 11px var(--font-body); fill: var(--muted); }
.map-train { fill: var(--signal); stroke: var(--ink); stroke-width: 2; }
.map-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0 32px; }
.stat { padding: 16px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); }
.stat b { display: block; font: 800 1.8rem/1 var(--font-display); margin-bottom: 4px; }
.stat span { font-size: .85rem; color: var(--muted); }
.continue { display: flex; gap: 16px; align-items: center; border-left: 6px solid var(--c); }
.continue > div { min-width: 0; }
.continue > svg { width: 22px; height: 22px; flex: none; color: var(--muted); }
/* safety net for any inline icon inside text-like containers */
.card svg:not([width]), .result svg:not([width]), .lesson-nav svg:not([width]) { width: 20px; height: 20px; flex: none; }

/* track cards with a mini station strip */
.track-card { display: block; text-decoration: none; position: relative; overflow: hidden; transition: transform .2s var(--ease-out); }
@media (hover: hover) { .track-card:hover { transform: translateY(-2px); } }
.track-card h3 { margin-bottom: .25em; }
.strip { display: flex; align-items: center; margin: 14px 0 6px; }
.strip i { flex: 1; height: 5px; background: var(--c); opacity: .35; }
.strip b { width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--c); background: var(--surface); flex: none; }
.strip b.done { background: var(--c); }
.strip i.done { opacity: 1; }

/* track page: vertical line of stations */
.line-list { list-style: none; padding: 0; margin: 24px 0; position: relative; }
.line-list::before { content: ''; position: absolute; left: 13px; top: 14px; bottom: 14px; width: 6px; border-radius: 3px; background: var(--c); opacity: .3; }
.line-list li { position: relative; padding-left: 52px; margin-bottom: 12px; }
.line-list li::before { content: ''; position: absolute; left: 4px; top: 18px; width: 24px; height: 24px; border-radius: 50%; background: var(--surface); border: 5px solid var(--c); box-sizing: border-box; }
.line-list li.done::before { background: var(--c); }
.line-list a { display: block; text-decoration: none; padding: 14px 18px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); }
@media (hover: hover) { .line-list a:hover { border-color: var(--c); } }
.line-list .meta { font-size: .82rem; color: var(--muted); }

/* ---------- lesson reader ---------- */
.reader { display: grid; min-width: 0; grid-template-columns: minmax(0, 1fr) 240px; gap: 40px; }
@media (max-width: 1100px) { .reader { grid-template-columns: minmax(0, 1fr); } .reader aside { display: none; } }
.reader aside { position: sticky; top: 90px; align-self: start; font-size: .9rem; }
.reader aside ol { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 4px solid color-mix(in srgb, var(--c) 35%, transparent); }
.reader aside li { margin: 0 0 8px; }
.reader aside a { text-decoration: none; color: var(--muted); }
.reader aside a[aria-current] { color: var(--ink); font-weight: 700; }
.prose { max-width: 72ch; min-width: 0; }
.reader article { min-width: 0; }
.prose h2 { margin-top: 1.8em; padding-top: .2em; }
.prose h3 { margin-top: 1.4em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin-bottom: .35em; }
.prose :not(pre) > code { background: var(--surface-2); border: 1px solid var(--rule); padding: .08em .35em; border-radius: 5px; }
.prose table { border-collapse: collapse; width: 100%; margin: 1em 0 1.4em; font-size: .93rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--rule); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); font-family: var(--font-display); }
.tip { border-left: 5px solid var(--signal); background: color-mix(in srgb, var(--signal) 12%, var(--surface)); padding: 12px 16px; border-radius: 0 var(--r) var(--r) 0; margin: 1.2em 0; }
.tip p:last-child { margin: 0; }
.code { position: relative; margin: 1em 0 1.4em; }
.code pre { margin: 0; padding: 16px 18px; background: #0f1828; color: #dce6f5; border-radius: var(--r); overflow-x: auto; line-height: 1.55; font-size: .86rem; }
.code .lang { position: absolute; top: 8px; right: 52px; font: 700 .68rem var(--font-mono); text-transform: uppercase; color: #8a9bb5; }
.code .copy { position: absolute; top: 6px; right: 6px; min-height: 28px; padding: 2px 10px; font-size: .72rem; background: #1d2a40; color: #dce6f5; border-color: #2d3b55; }
.tok-k { color: #ff9e64; } .tok-s { color: #9ece6a; } .tok-c { color: #6b7d99; font-style: italic; } .tok-n { color: #e0af68; } .tok-a { color: #7dcfff; }
/* figures and step slideshows (book chapters use light-background PNGs, so keep a light mat in dark mode) */
.fig, .slides { margin: 1.2em 0 1.6em; }
.fig img { display: block; width: 100%; height: auto; border-radius: var(--r); background: #fff; border: 1px solid var(--rule); }
.fig figcaption { font-size: .88rem; color: var(--muted); margin-top: 6px; text-align: center; }
/* animated step player: every frame sits in the same grid cell; the active one dissolves in on top */
.slides { --fade: 650ms; position: relative; border-radius: var(--r); outline: none; }
.slides:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 45%, transparent); }
.slides-bar { display: flex; gap: 4px; margin-bottom: 8px; }
.slides-seg { flex: 1; height: 14px; padding: 5px 0; border: 0; background: none; cursor: pointer; }
.slides-seg i { display: block; height: 4px; border-radius: 2px; background: var(--signal); transform: scaleX(0); transform-origin: left; }
.slides-seg { background: linear-gradient(var(--rule), var(--rule)) center / 100% 4px no-repeat; }
.slides-seg.is-cur { background-image: linear-gradient(color-mix(in srgb, var(--signal) 25%, var(--rule)), color-mix(in srgb, var(--signal) 25%, var(--rule))); }
.slides-stage { display: grid; overflow: hidden; border-radius: var(--r); background: #fff; border: 1px solid var(--rule); cursor: pointer; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.slides-stage img { grid-area: 1 / 1; align-self: center; display: block; width: 100%; height: auto; opacity: 0; pointer-events: none; -webkit-user-drag: none; }
.slides-stage img.is-prev { opacity: 1; z-index: 1; }
.slides-stage img.is-on { opacity: 1; z-index: 2; animation: frame-in var(--fade) cubic-bezier(.33, 0, .2, 1) both; }
@keyframes frame-in {
  0% { opacity: 0; filter: blur(2.5px); transform: scale(1.012); }
  60% { filter: blur(0); }
  100% { opacity: 1; filter: none; transform: none; }
}
.slides-ctl { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: .88rem; }
.slides-ctl .btn.icon { width: 34px; }
.slides-ctl svg { width: 16px; height: 16px; }
.slides-play .i-pause, .slides.is-playing .slides-play .i-play { display: none; }
.slides.is-playing .slides-play .i-pause { display: inline; }
.slides-speed { min-width: 3.4em; font: 700 .76rem var(--font-mono); }
.slides-pos { font: .8rem var(--font-mono); color: var(--muted); margin-left: 4px; }
.slides-alt { flex: 1 1 100%; }
@media (min-width: 640px) { .slides-alt { flex-basis: 0; min-width: 12em; } }
@media (prefers-reduced-motion: reduce) { .slides-stage img.is-on { animation: none; } }
.code-tabs { margin: 1em 0 1.4em; }
.code-tabs [role=tablist] { gap: 6px; margin-bottom: 6px; }
.code-tabs [aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.code-tabs .code { margin-top: 0; }
.fold { border: 1px solid var(--rule); border-radius: var(--r); padding: 10px 14px; margin: 1em 0; background: var(--surface); }
.fold summary { cursor: pointer; font-weight: 700; }
.fold[open] summary { margin-bottom: 8px; }
.credit { font-size: .85rem; color: var(--muted); border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 28px; }
.keypoints { margin-top: 2em; border-top: 6px solid var(--c); }
.keypoints ul { margin: 0; padding-left: 1.2em; }
.lesson-nav { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.lesson-nav a { flex: 1; min-width: 200px; }
.progress-top { position: fixed; top: 0; left: 0; height: 3px; background: var(--c, var(--signal)); z-index: 40; transform-origin: left; width: 100%; transform: scaleX(0); }

/* ---------- interview ---------- */
.qa-head { display: grid; gap: 18px 40px; align-items: end; margin-bottom: 22px; }
.qa-head h1 { margin-bottom: .35em; }
.qa-head .hero-lede { margin: 0; }
@media (min-width: 1000px) { .qa-head { grid-template-columns: minmax(0, 1fr) 300px; } }
.qa-progress { display: grid; gap: 10px; padding: 14px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--rule); box-shadow: var(--shadow); }
.qa-meter { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--rule); }
.qa-meter i { display: block; height: 100%; min-width: 0; transition: width .5s var(--ease-out); }
.qa-progress i.k { background: var(--ok); } .qa-progress i.r { background: var(--signal); }
.qa-progress dl { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; }
.qa-progress dl div + div { border-left: 1px solid var(--rule); padding-left: 12px; }
.qa-progress dt { display: flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 700; color: var(--muted); }
.qa-progress dt i { width: 8px; height: 8px; border-radius: 50%; background: var(--rule); }
.qa-progress dd { margin: 0; font: 700 1.15rem var(--font-display); font-variant-numeric: tabular-nums; }

.qa-panel { display: grid; gap: 14px; padding: 14px; border-radius: 18px; background: var(--surface); border: 1px solid var(--rule); box-shadow: var(--shadow); }
.qa-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.qa-search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--rule); color: var(--muted); cursor: text; transition: border-color .15s, box-shadow .15s; }
.qa-search:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.qa-search svg { flex: none; }
.qa-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; color: var(--ink); font: inherit; font-size: 16px; outline: none; }
.qa-search input::placeholder { color: var(--muted); }

/* segmented control with a sliding thumb */
.qa-seg { position: relative; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); padding: 3px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--rule); isolation: isolate; }
.qa-seg::before { content: ''; position: absolute; z-index: -1; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / var(--n)); border-radius: 9px; background: var(--surface); box-shadow: 0 1px 2px rgb(14 26 43 / .12), 0 2px 8px rgb(14 26 43 / .08), inset 0 0 0 1px var(--rule); transform: translateX(calc(var(--i, 0) * 100%)); transition: transform .4s cubic-bezier(.3, 1.3, .5, 1); }
.qa-seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 12px; border: 0; border-radius: 9px; background: none; font: 700 .86rem var(--font-body); color: var(--muted); cursor: pointer; white-space: nowrap; transition: color .2s; }
.qa-seg button[aria-pressed="true"] { color: var(--ink); }
.qa-seg button.lvl-easy[aria-pressed="true"] { color: var(--ok); }
.qa-seg button.lvl-medium[aria-pressed="true"] { color: var(--javascript); }
.qa-seg button.lvl-hard[aria-pressed="true"] { color: var(--bad); }
.qa-seg svg { width: 16px; height: 16px; flex: none; }
.qa-seg button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
#mode { height: 44px; }
#mode button { min-height: 0; }

/* topic chips: wrap on desktop, one swipeable strip on phones */
.qa-topics { display: flex; flex-wrap: wrap; gap: 6px; }
.qa-topic { display: inline-flex; align-items: center; gap: 7px; flex: none; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); color: var(--ink); font: 700 .84rem var(--font-body); cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.qa-topic i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.qa-topic small { font: 600 .72rem var(--font-mono); color: var(--muted); }
@media (hover: hover) { .qa-topic:hover { background: var(--surface-2); } }
.qa-topic[aria-pressed="true"] { background: color-mix(in srgb, var(--c) 14%, var(--surface)); border-color: var(--c); }
.qa-topic:not([style])[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.qa-topic:not([style])[aria-pressed="true"] small { color: color-mix(in srgb, var(--paper) 70%, transparent); }

.qa-sub { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 20px; padding-top: 14px; border-top: 1px solid var(--rule); }
.qa-group { display: grid; gap: 6px; }
.qa-label { font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.qa-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; margin: 16px 4px 4px; font-size: .9rem; color: var(--muted); font-weight: 600; }
.qa-clear { border: 0; background: none; padding: 6px 2px; font: 700 .86rem var(--font-body); color: var(--focus); cursor: pointer; }
@media (max-width: 600px) {
  .qa-head { margin-bottom: 16px; gap: 14px; }
  .qa-progress { padding: 10px 14px; gap: 8px; }
  .qa-progress dd { font-size: 1rem; }
  .qa-panel { padding: 12px; gap: 12px; border-radius: 16px; }
  #mode button span { display: none; }
  #mode button { padding: 0 14px; }
  .qa-topics { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; scroll-padding: 0 12px;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 24px), transparent); }
  .qa-topics::-webkit-scrollbar { display: none; }
  .qa-sub { grid-template-columns: minmax(0, 1fr); padding-top: 12px; }
  .qa-seg button { padding: 0 6px; font-size: .82rem; }
}
@media (prefers-reduced-motion: reduce) { .qa-seg::before, .qa-meter i { transition: none; } }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.qa { border-bottom: 1px solid var(--rule); }
.qa summary { list-style: none; cursor: pointer; padding: 16px 4px; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; }
.qa summary::-webkit-details-marker { display: none; }
.qa summary .num { font: 700 .8rem var(--font-mono); color: var(--muted); padding-top: 3px; min-width: 3ch; }
.qa summary .q { font-weight: 700; }
.qa summary .chev { transition: rotate .25s var(--ease-out); color: var(--muted); }
.qa[open] summary .chev { rotate: 90deg; }
.qa .ans { padding: 0 4px 20px 46px; }
.qa .ans-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.qa.known .num { color: var(--ok); }
.qa.revise .num { color: var(--bad); }

.flash { perspective: 1400px; max-width: 760px; margin: 24px auto; }
.flash-inner { position: relative; min-height: 340px; transition: transform .6s var(--ease-out); transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: auto; display: flex; flex-direction: column; }
.flash-face.front { justify-content: center; align-items: center; text-align: center; font: 700 1.4rem/1.35 var(--font-display); padding: 32px; border-top: 8px solid var(--c); }
.flash-face.back { transform: rotateY(180deg); }

/* ---------- quiz ---------- */
.quiz-q { font-size: 1.15rem; font-weight: 700; }
.opts { display: grid; gap: 10px; margin: 18px 0; }
.opt { text-align: left; padding: 14px 16px; border-radius: var(--r); border: 2px solid var(--rule); background: var(--surface); cursor: pointer; display: flex; gap: 12px; align-items: flex-start; font-size: 1rem; }
.opt b { font-family: var(--font-mono); color: var(--muted); }
@media (hover: hover) { .opt:hover:not(:disabled) { border-color: var(--ink); } }
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); animation: shake .35s; }
.opt:disabled { cursor: default; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--rule); }
.meter > i { display: block; height: 100%; background: var(--c, var(--focus)); transition: width .4s var(--ease-out); }
.score-ring { width: 160px; height: 160px; margin: 0 auto 12px; }
.score-ring circle { fill: none; stroke-width: 12; }

/* ---------- glossary ---------- */
.az { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0 20px; }
.az a { width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--r-sm); text-decoration: none; font-weight: 700; font-size: .85rem; background: var(--surface); border: 1px solid var(--rule); }
.term { padding: 14px 0; border-bottom: 1px solid var(--rule); }
.term dt { font-weight: 700; font-family: var(--font-display); font-size: 1.05rem; }
.term dd { margin: 4px 0 0; }
.term .eg { color: var(--muted); font-size: .92rem; }

/* ---------- search ---------- */
.result { display: block; padding: 14px 16px; border-radius: var(--r); text-decoration: none; border: 1px solid transparent; }
.result:focus-visible { background: var(--surface); border-color: var(--rule); }
@media (hover: hover) and (pointer: fine) { .result:hover { background: var(--surface); border-color: var(--rule); } }
.result small { color: var(--muted); }
mark { background: color-mix(in srgb, var(--signal) 55%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ---------- visualizers ---------- */
.viz { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: clamp(12px, 2.5vw, 20px); margin: 1.4em 0; box-shadow: var(--shadow); min-width: 0; max-width: 100%; overflow: hidden; }
.viz > div { min-width: 0; }
.viz-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.viz-head h3 { margin: 0; }
.viz-head .chip { margin-left: auto; }
.viz-inputs, .viz-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.viz-inputs > * { min-width: 0; }
.viz-controls { padding-top: 12px; border-top: 1px solid var(--rule); }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; background: var(--surface-2); flex: none; }
.seg .btn { border: 0; border-radius: 0; background: transparent; }
.seg .btn + .btn { border-left: 1px solid var(--rule); }
.seg .btn.primary { background: var(--signal); min-width: 84px; }
.scrub { flex: 1 1 140px; min-width: 100px; accent-color: var(--c, var(--focus)); height: 24px; }
.viz-controls .field { min-height: 38px; }
.viz-inputs:empty { display: none; }
.viz-stage { position: relative; min-height: 240px; margin: 12px 0; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--rule); padding: clamp(10px, 2vw, 18px); overflow: auto; max-width: 100%; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.viz-stage > svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.viz-stage.tall { min-height: 380px; }
.viz-caption { min-height: 3.2em; margin: 0 0 12px; font-size: .98rem; line-height: 1.55; padding-left: 12px; border-left: 3px solid var(--c, var(--focus)); }
.viz-caption b { color: var(--ink); }
.viz-pos { font: .78rem var(--font-mono); color: var(--muted); white-space: nowrap; }
.viz svg text { font-family: var(--font-body); fill: var(--ink); }
/* shared cell/node look for diagrams */
.cell { display: inline-grid; place-items: center; min-width: 46px; height: 46px; padding: 0 8px; border-radius: 10px; border: 2px solid var(--rule); background: var(--surface); font: 700 .95rem var(--font-mono); transition: transform .3s var(--ease-out), background .2s, border-color .2s; }
.cell.hl { border-color: var(--focus); background: color-mix(in srgb, var(--focus) 14%, var(--surface)); }
.cell.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 16%, var(--surface)); }
.cell.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.cell.dim { opacity: .35; }
.cell.sig { border-color: var(--signal); background: color-mix(in srgb, var(--signal) 30%, var(--surface)); }
.cell-label { font: .72rem var(--font-mono); color: var(--muted); text-align: center; }
@keyframes pop-in { from { transform: scale(.4); opacity: 0; } }
.pop-in { animation: pop-in .35s var(--ease-out); }
/* sorting bars */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 220px; }
.bar { flex: 1; background: color-mix(in srgb, var(--dsa) 45%, var(--surface)); border-radius: 6px 6px 2px 2px; position: relative; transition: height .3s var(--ease-out), background .2s; min-width: 14px; }
.bar span { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font: 700 .7rem var(--font-mono); color: var(--ink); }
.bar.is-cmp { background: var(--focus); } .bar.is-cmp span { color: #fff; }
.bar.is-swap { background: var(--signal); }
.bar.is-pivot { background: var(--bad); } .bar.is-pivot span { color: #fff; }
.bar.is-done { background: var(--dsa); } .bar.is-done span { color: #fff; }
.bar.is-dim { opacity: .3; }

.lab-card { text-decoration: none; display: flex; flex-direction: column; gap: 6px; }
.lab-card .thumb { height: 90px; border-radius: var(--r); background: var(--surface-2); display: grid; place-items: center; color: var(--c, var(--muted)); }
.lab-card .thumb svg { width: 56px; height: 56px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .map-line.draw { stroke-dashoffset: 0; }
}
@media print { .topbar, .rail, .tabbar, .lesson-nav, .viz-controls { display: none; } .layout { display: block; } }

/* ---------- phone polish ---------- */
@media (max-width: 600px) {
  body { font-size: 16px; }
  main { padding-top: 18px; }
  h1 { font-size: 1.75rem; }
  .hero-lede { font-size: 1rem; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .card { padding: 16px; border-radius: var(--r); }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat b { font-size: 1.45rem; }
  .viz { padding: 12px; border-radius: var(--r); margin-left: -4px; margin-right: -4px; }
  .viz-head .chip { display: none; }
  .viz-controls { gap: 6px; }
  .scrub { order: 5; flex-basis: 100%; }
  .viz-pos { margin-left: auto; }
  .qa .ans { padding-left: 4px; }
  .qa summary { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; }
  .lesson-nav a { min-width: 0; flex-basis: 100%; }
  .code pre { font-size: .8rem; padding: 14px; }
  .prose { overflow-wrap: anywhere; }
  .filters { flex-wrap: nowrap; overflow-x: auto; margin-left: -16px; margin-right: -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .filters .btn { flex: none; }
  .flash-inner { min-height: 300px; }
  .flash-face.front { font-size: 1.15rem; padding: 22px; }
}
.prose pre, .prose table { max-width: 100%; }

/* phone version of the transit map: one row per line */
.map-list { display: none; }
@media (max-width: 600px) {
  .map-wrap { display: none; }
  .map-list { display: grid; gap: 2px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); padding: 6px; }
  .map-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name count" "strip strip"; align-items: center; gap: 2px 10px; padding: 10px 10px 8px; border-radius: 10px; text-decoration: none; }
  .map-row:active { background: var(--surface-2); }
  .map-row-name { grid-area: name; font: 700 .95rem var(--font-display); }
  .map-row small { grid-area: count; color: var(--muted); font: .78rem var(--font-mono); }
  .map-row .strip { grid-area: strip; margin: 4px 0 0; }
}
.flash-bar { max-width: 760px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.flash-nav { display: flex; align-items: center; gap: 12px; font: .85rem var(--font-mono); }
.flash-marks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 1 1 260px; max-width: 360px; }
@media (max-width: 600px) { .flash-bar { flex-direction: column; align-items: stretch; } .flash-nav { justify-content: space-between; } .flash-marks { max-width: none; } }

/* ---------- app feel on touch devices ---------- */
button, .btn, .nav-link, .rail-track, .tabbar a, .chip, .opt, .map-row, .track-card, .lab-card, .line-list a, .result, .az a, .qa summary, .flash, [role="tab"] {
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
/* press feedback on the finger going down, not on release */
.opt, .map-row, .track-card, .lab-card, .line-list a, .result, .tabbar a, .nav-link, .qa summary, .card[href] { transition: transform .12s var(--ease-out), background .12s; }
.opt:active:not(:disabled), .map-row:active, .track-card:active, .lab-card:active, .line-list a:active, .result:active, .card[href]:active { transform: scale(.985); }
.tabbar a:active svg, .nav-link:active svg { transform: scale(.88); }
.tabbar a svg { transition: transform .12s var(--ease-out); }
@media (pointer: coarse) { input, textarea, select, .field { font-size: 16px; } }
h1, h2, h3, .card, .chip, .q, .lesson-nav strong { overflow-wrap: anywhere; }
.prose p, .prose li { hyphens: auto; -webkit-hyphens: auto; }
body { min-height: 100dvh; }

/* tab bar: active pill like a native tab bar */
@media (max-width: 860px) {
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
  .topbar .icon-btn { display: none; }
}
/* glass tab bar in dark mode: smoky tint, softer rim */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tabbar { --glass-tint: rgb(28 38 58 / .55); --glass-rim: rgb(255 255 255 / .16); --glass-edge: rgb(255 255 255 / .08); --lens: rgb(255 255 255 / .12); box-shadow: inset 0 1px 0 var(--glass-rim), inset 0 0 0 1px var(--glass-edge), inset 0 0 18px rgb(255 255 255 / .04), 0 10px 30px rgb(0 0 0 / .45), 0 2px 6px rgb(0 0 0 / .3); } }
:root[data-theme="dark"] .tabbar { --glass-tint: rgb(28 38 58 / .55); --glass-rim: rgb(255 255 255 / .16); --glass-edge: rgb(255 255 255 / .08); --lens: rgb(255 255 255 / .12); box-shadow: inset 0 1px 0 var(--glass-rim), inset 0 0 0 1px var(--glass-edge), inset 0 0 18px rgb(255 255 255 / .04), 0 10px 30px rgb(0 0 0 / .45), 0 2px 6px rgb(0 0 0 / .3); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tabbar::after { opacity: .25; } }
:root[data-theme="dark"] .tabbar::after { opacity: .25; }
@media (prefers-reduced-motion: reduce) { .tabbar, .tabbar::before { transition: none; } }
/* installed app: no browser chrome, so tighten the header */
@media (display-mode: standalone) {
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
}
.more-list { display: grid; gap: 8px; margin: 16px 0 28px; }
.more-list a, .more-list button { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--rule); text-decoration: none; font: 600 1rem var(--font-body); color: var(--ink); text-align: left; width: 100%; cursor: pointer; }
.more-list svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
.more-list small { margin-left: auto; color: var(--muted); font-weight: 400; }

/* diagrams scaled to fit by js/viz/index.js: no sideways scroll needed */
.viz-stage.is-fitted { overflow-x: hidden; }

/* phone: diagram gallery as compact rows instead of tall cards */
@media (max-width: 600px) {
  .lab-card { display: grid; grid-template-columns: 44px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 14px; row-gap: 2px; align-items: center; padding: 12px 14px; }
  .lab-card .thumb { grid-row: span 2; width: 44px; height: 44px; border-radius: 10px; }
  .lab-card .thumb svg { width: 24px; height: 24px; }
  .lab-card h3 { margin: 0 !important; font-size: 1rem; }
  .lab-card small { font-size: .78rem; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
}
@media (max-width: 600px) { .code .lang { display: none; } }

/* long button labels (e.g. "Start: <lesson title>") wrap instead of running off a phone screen */
.btn { max-width: 100%; }
@media (max-width: 600px) { .btn { white-space: normal; text-align: left; line-height: 1.3; padding-top: 8px; padding-bottom: 8px; } .seg .btn, .btn.icon, .btn.small { white-space: nowrap; padding-top: 0; padding-bottom: 0; } }
