:root {
  --bg: #0b0f1a;
  --panel: #121829;
  --panel-2: #182037;
  --line: #242d47;
  --text: #e6e9f2;
  --muted: #8f98b8;
  --dim: #5f6888;
  --blue: #6f9bff;
  --amber: #f0b429;
  --green: #2fb36b;
  --red: #e5484d;
  --easy: #2fb36b;
  --medium: #f0b429;
  --hard: #e5484d;
  --radius: 12px;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--panel-2); padding: 1px 6px; border-radius: 5px; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  background: rgba(11, 15, 26, 0.86); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; letter-spacing: 0.2px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--amber); box-shadow: 14px 0 0 var(--blue), 28px 0 0 var(--green); margin-right: 30px; }
.topbar .spacer { flex: 1; }
.topbar .crumbs { color: var(--muted); font-size: 14px; }
.topbar .topnav { color: var(--text); font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; }
.topbar .topnav:hover { border-color: var(--amber); color: var(--amber); }
@media (max-width: 700px) { .topbar .topnav { padding: 5px 9px; font-size: 12px; } }

.wrap { max-width: 1320px; margin: 0 auto; padding: 24px; }

/* hero */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 28px; align-items: center; margin: 12px 0 28px; }
.hero h1 { font-size: 40px; line-height: 1.12; margin: 0 0 12px; }
.hero h1 em { font-style: normal; color: var(--amber); }
.hero p { color: var(--muted); font-size: 17px; margin: 0 0 18px; }
.hero-stage { aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #0f1320; position: relative; }
.hero-stage canvas { display: block; width: 100%; height: 100%; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 110px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }

/* filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search { flex: 1; min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; padding: 6px 12px; border-radius: 7px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--panel-2); color: var(--text); }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; user-select: none; }

.cat-nav { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 24px; }
.cat-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--muted); }
.cat-chip:hover { color: var(--text); text-decoration: none; border-color: var(--dim); }
.cat-chip b { color: var(--text); font-weight: 600; }

/* category sections */
.cat { margin-bottom: 30px; scroll-margin-top: 70px; }
.cat-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cat-head h2 { margin: 0; font-size: 20px; }
.cat-head .count { color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.card { display: flex; flex-direction: column; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--text); transition: transform 0.15s, border-color 0.15s; }
.card.ready { border-color: #2b3d6b; background: linear-gradient(180deg, #16203b, var(--panel)); }
.card.ready:hover { border-color: var(--blue); text-decoration: none; transform: translateY(-2px); }
.card.soon { opacity: 0.6; }
.card .t { font-weight: 600; }
.card .ch { font-family: ui-monospace, monospace; font-size: 11px; color: var(--dim); letter-spacing: 0.4px; }
.sd-state { font-size: 12px; color: var(--muted); }
.sd-state.on { color: #2fb36b; font-weight: 600; }
/* static walkthrough transcript on pre-rendered SD pages */
.script-panel h3 { margin: 0 0 6px; }
.script-panel h4 { margin: 16px 0 6px; color: var(--amber); font-size: 14px; }
.script-panel ol.script { margin: 0; padding-left: 22px; color: var(--muted); }
.script-panel ol.script li { margin: 6px 0; line-height: 1.55; }

/* ---- system design chapter: long-form layout ---- */
/* problem + requirements, then full-width assumptions and takeaways, then one
   animated section per part with its transcript beside the player */
.assume-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; margin-top: 14px; }
.assume { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.assume .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.7px; }
.assume .v { font-family: var(--mono); font-size: 26px; font-weight: 800; color: var(--amber); margin: 6px 0; }
.assume .note { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.assume-lead { color: var(--muted); max-width: 92ch; }
.sd-wide { margin-bottom: 22px; }
.sd-wide ul { columns: 2; column-gap: 40px; margin: 0; }
.sd-wide li { break-inside: avoid; margin-bottom: 8px; }
.sd-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 18px; margin: 4px 0 20px; color: var(--muted); font-size: 13px; }
.sd-toolbar .hint { margin-right: auto; }
.sd-part { --sd-stage: clamp(320px, 42vw, 580px); margin-bottom: 36px; scroll-margin-top: 70px; }
.sd-part-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 12px; }
.sd-part-head .num { font-family: var(--mono); font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.sd-part-head h2 { margin: 0; font-size: 24px; }
.sd-part-head .blurb { flex-basis: 100%; margin: 0; color: var(--muted); max-width: 100ch; }
.sd-part.finale .sd-part-head .num { color: var(--amber); border-color: #5c4713; }
.sd-part.wild .sd-part-head .num { color: var(--blue); border-color: #2b3d6b; }
.sd-part-body { display: grid; grid-template-columns: minmax(0, 1.42fr) minmax(0, 0.58fr); gap: 18px; align-items: start; }
.sd-player { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.sd-part.finale .sd-player { border-color: #5c4713; }
.sd-part.wild .sd-player { border-color: #2b3d6b; }
.sd-player .stage { aspect-ratio: auto; height: var(--sd-stage); }
.sd-lines { list-style: none; margin: 0; padding: 4px; display: flex; flex-direction: column; gap: 6px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(var(--sd-stage) + 70px); overflow-y: auto; }
.sd-lines li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer; color: var(--muted); }
.sd-lines li .n { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center;
  font-size: 12px; font-weight: 700; font-family: var(--mono); }
.sd-lines li b { display: block; color: var(--text); font-size: 14px; }
.sd-lines li p { margin: 3px 0 0; font-size: 14px; line-height: 1.55; }
.sd-lines li:hover { background: var(--panel-2); }
.sd-lines li.on { background: #1a2647; border-color: var(--blue); }
.sd-lines li.on .n { background: var(--amber); border-color: var(--amber); color: #1b1f2c; }
.sd-lines li.done { opacity: 0.62; }
@media (max-width: 1000px) {
  .sd-part-body { grid-template-columns: minmax(0, 1fr); }
  .sd-player { order: -1; }
  .sd-part { --sd-stage: clamp(260px, 58vw, 420px); }
  .sd-lines { max-height: none; }
  .sd-wide ul { columns: 1; }
}
.meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.pill { border-radius: 999px; padding: 1px 8px; border: 1px solid var(--line); color: var(--muted); }
.pill.Easy { color: var(--easy); border-color: #1f5a3a; }
.pill.Medium { color: var(--medium); border-color: #5c4713; }
.pill.Hard { color: var(--hard); border-color: #5e2326; }
.pill.list { color: #aab3d1; }
.pill.go { margin-left: auto; color: var(--blue); border-color: #2b3d6b; }
.empty-note { color: var(--muted); padding: 20px 0; }

/* problem page */
.p-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.p-head h1 { margin: 0; font-size: 28px; }
.layout { display: grid; gap: 22px; align-items: start; margin-bottom: 22px; }
.layout.top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
/* code on the left, animation on the right: the highlighted line sits next to the step it drives */
.layout.work { grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); }
.solutions .code { max-height: 560px; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.panel h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.panel p { margin: 0 0 10px; }
.panel ul { margin: 0 0 10px; padding-left: 20px; }
.examples { display: grid; gap: 10px; }
.example { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); cursor: pointer; text-align: left; width: 100%; }
.example.on { border-color: var(--amber); }
.example .io { font-family: var(--mono); font-size: 13px; }
.example .io span { color: var(--muted); }
.example .why { color: var(--muted); font-size: 13px; margin-top: 4px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.tab.on { color: var(--text); border-color: var(--blue); background: #1a2647; }
.cx { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px; }
.cx-badge { font-family: var(--mono); font-size: 13px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }
.cx-badge b { color: var(--muted); font-family: var(--sans); font-weight: 600; margin-right: 6px; }
.cx-why { color: var(--muted); font-size: 13px; margin: 0 0 4px; }
.cx-why b { color: var(--text); }
.idea { margin: 8px 0 0; }

.code { font-family: var(--mono); font-size: 13px; line-height: 1.6; background: #0d1222; border: 1px solid var(--line); border-radius: 10px; max-height: 360px; overflow: auto; padding: 8px 0; margin-top: 10px; position: relative; }
.ln { display: flex; padding: 0 12px; border-left: 3px solid transparent; white-space: pre; transition: background 0.2s; }
.ln.on { background: rgba(240, 180, 41, 0.14); border-left-color: var(--amber); }
.ln-no { width: 30px; flex: none; color: var(--dim); user-select: none; }
.tk-kw { color: #c792ea; } .tk-str { color: #c3e88d; } .tk-num { color: #f78c6c; }
.tk-com { color: #5f6888; font-style: italic; } .tk-type { color: #82aaff; } .tk-fn { color: #ffcb6b; }

/* player */
.player { }
.stage { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #0f1320; }
.stage canvas { display: block; width: 100%; height: 100%; }
.step-badge { position: absolute; top: 12px; left: 12px; background: rgba(18, 24, 41, 0.9); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.step-badge b { color: var(--amber); }
.result-badge { position: absolute; top: 12px; right: 12px; max-width: calc(100% - 300px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: rgba(47, 179, 107, 0.16); border: 1px solid var(--green); color: #b9f1cf; border-radius: 8px; padding: 4px 10px; font-family: var(--mono); font-size: 13px; opacity: 0; transform: translateY(-6px); transition: 0.3s; }
.result-badge.show { opacity: 1; transform: none; }
.result-badge.bad { background: rgba(229, 72, 77, 0.16); border-color: var(--red); color: #ffc9cb; }
.subtitle { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(92%, 820px); text-align: center;
  background: rgba(5, 8, 15, 0.84); border-radius: 10px; padding: 9px 14px; font-size: 16px; line-height: 1.45; color: #f4f6fb; }
.subtitle:empty { display: none; }
.subtitle.fade { animation: subIn 0.25s ease-out; }
@keyframes subIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
.io-strip { display: flex; gap: 14px; flex-wrap: wrap; font-family: var(--mono); font-size: 13px; color: var(--muted); padding: 10px 2px 0; }
.io-strip b { color: var(--text); font-weight: 600; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; min-width: 38px; }
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--amber); color: #1b1f2c; border-color: var(--amber); font-weight: 700; min-width: 86px; }
.scrub { flex: 1; min-width: 140px; accent-color: var(--amber); }
.sel { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.audio-src { color: var(--dim); font-size: 12px; margin-top: 6px; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .subtitle.fade { animation: none; } .card { transition: none; } }

.foot-cats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 6px; max-width: 980px; margin: 0 auto; padding: 28px 16px 0; }
.foot-cats a { font-size: 12.5px; color: var(--dim); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; }
.foot-cats a:hover { color: var(--text); border-color: var(--dim); }

.foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; padding: 26px 16px 34px; margin-top: 10px; color: var(--dim); font-size: 13.5px; }
.foot b { color: var(--muted); font-weight: 700; letter-spacing: 0.3px; }
.foot a { color: var(--muted); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.foot a:hover { color: var(--text); }
.foot .dotsep { width: 4px; height: 4px; border-radius: 50%; background: var(--dim); flex: none; }

.pill.co { background: rgba(111, 155, 255, 0.10); border: 1px solid rgba(111, 155, 255, 0.35); color: #a8c1ff; }

.cat-intro { color: var(--muted); max-width: 760px; margin: 2px 0 18px; line-height: 1.55; }
.page { padding: 22px 26px; line-height: 1.65; }
.page h1 { font-size: 26px; margin: 0 0 14px; }
.page h2 { font-size: 17px; margin: 22px 0 8px; }
.page p, .page li { color: var(--text); max-width: 760px; }
.page .muted { color: var(--dim); font-size: 13px; }

/* hamburger + drawer (all problems by category) */
[hidden] { display: none !important; }
.burger { flex: none; width: 38px; height: 38px; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; cursor: pointer; padding: 0; }
.burger:hover { border-color: var(--dim); }
.burger span, .burger span::before, .burger span::after { display: block; width: 16px; height: 2px; background: var(--text); border-radius: 2px; position: relative; content: ""; }
.burger span::before { position: absolute; top: -5px; }
.burger span::after { position: absolute; top: 5px; }
.nav-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(3, 5, 10, 0.6); }
.nav-drawer { position: fixed; top: 0; left: 0; bottom: 0; z-index: 31; width: min(86vw, 340px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border-right: 1px solid var(--line); padding: 0 0 24px; box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4); }
body.nav-open { overflow: hidden; }
.nav-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.nav-head a { font-weight: 700; }
.nav-close { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; width: 36px; height: 36px; }
.nav-drawer details { border-bottom: 1px solid var(--line); }
.nav-drawer summary { list-style: none; cursor: pointer; padding: 12px 14px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.nav-drawer summary::-webkit-details-marker { display: none; }
.nav-drawer summary::after { content: "▸"; color: var(--dim); margin-left: 8px; transition: transform 0.15s; }
.nav-drawer details[open] summary::after { transform: rotate(90deg); }
.nav-drawer summary b { margin-left: auto; color: var(--dim); font-weight: 500; font-size: 13px; }
.nav-drawer ul { list-style: none; margin: 0; padding: 0 0 6px; }
.nav-drawer li a { display: flex; align-items: center; gap: 9px; padding: 7px 14px 7px 22px; color: var(--muted); font-size: 14px; }
.nav-drawer li a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.nav-drawer li a[aria-current="page"] { color: var(--text); background: #1a2647; box-shadow: inset 3px 0 0 var(--amber); }
.nav-drawer .nav-cat { display: block; padding: 4px 22px 12px; font-size: 13px; }
.dotd { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.dotd.Easy { background: var(--easy); } .dotd.Medium { background: var(--medium); } .dotd.Hard { background: var(--hard); }

/* technique tags */
.tags { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12.5px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; }
.tag:hover { color: var(--text); border-color: var(--dim); text-decoration: none; }
.card-tags { font-size: 12px; color: var(--dim); }

@media (max-width: 1000px) {
  .hero, .layout.top, .layout.work { grid-template-columns: minmax(0, 1fr); }
  /* phones/tablets: watch first, read the code after */
  .layout.work .col.right { order: -1; }
}

@media (max-width: 700px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .topbar .kbd-hints { display: none; }
  .topbar .crumbs { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
  .topbar .spacer { display: none; }
  .brand .dot { margin-right: 26px; }
  .wrap { padding: 14px 12px; }
  .hero h1 { font-size: 30px; }
  .p-head { gap: 8px; margin-bottom: 14px; }
  .p-head h1 { font-size: 22px; flex-basis: 100%; }
  .p-head .pill { font-size: 12px; }
  .layout { gap: 14px; margin-bottom: 14px; }
  .panel { padding: 12px 14px; }
  .code { font-size: 12px; max-height: 300px; }
  .solutions .code { max-height: 340px; }
  .ln { padding: 0 8px; }
  .ln-no { width: 24px; }
  .stage { aspect-ratio: 4 / 3; }
  .step-badge { top: 8px; left: 8px; font-size: 12px; padding: 3px 8px; }
  .result-badge { top: 38px; left: 8px; right: auto; max-width: calc(100% - 16px); font-size: 12px; }
  .subtitle { bottom: 8px; width: 94%; font-size: 13.5px; padding: 7px 10px; }
  .io-strip { font-size: 12px; gap: 8px; }
  .controls .btn { min-width: 44px; min-height: 40px; }
  .controls .btn.primary { flex: 1; }
  .controls .scrub { order: 10; flex-basis: 100%; }
  /* keep it simple on phones: no voice/motion toggles */
  .player .controls + .controls, .audio-src { display: none; }
  .tab { padding: 6px 10px; font-size: 14px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
}
