/* Study sites — one stylesheet shared by every study site (home page, chapter pages, 404).
   Each site sets --accent-rgb / --accent-2-rgb on <html>; dark mode only redefines tokens. */

:root {
  color-scheme: light;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;

  --bg: #f4f6fb;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #7b8699;
  --surface: rgba(255, 255, 255, 0.7);
  --surface-2: rgba(255, 255, 255, 0.9);
  --header: rgba(244, 246, 251, 0.78);
  --ring: rgba(15, 23, 42, 0.08);
  --edge: rgba(255, 255, 255, 0.9);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px -14px rgba(15, 23, 42, 0.14);
  --shadow-lift: 0 2px 6px rgba(15, 23, 42, 0.05), 0 24px 50px -22px rgba(15, 23, 42, 0.26);
  --ambient-1: rgba(var(--accent-rgb), 0.28);
  --ambient-2: rgba(139, 92, 246, 0.22);
  --ambient-3: rgba(var(--accent-2-rgb), 0.16);
  --ambient-4: rgba(45, 212, 191, 0.18);
  --inline-code: rgba(15, 23, 42, 0.06);
  --accent-mix-base: #1a1405;
  --accent-mix: 58%;

  --code-bg: #0e1424;
  --code-head: #151c30;
  --code-ink: #dbe3f2;
  --code-dim: #7d89a6;
  --code-ring: rgba(255, 255, 255, 0.06);

  --gotcha: 225, 29, 72;
  --tip: 16, 185, 129;
  --note: 59, 130, 246;
  --interview: 139, 92, 246;
  --adv: 79, 70, 229;
  --adv-ink: 67, 56, 202;

  --topbar-h: 60px;
  --sidebar-w: 290px;
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --adv-ink: 165, 160, 255;
    --bg: #080b13;
    --ink: #eef2f8;
    --ink-2: #aab3c5;
    --ink-3: #768099;
    --surface: rgba(24, 30, 48, 0.58);
    --surface-2: rgba(30, 37, 58, 0.78);
    --header: rgba(8, 11, 19, 0.74);
    --ring: rgba(255, 255, 255, 0.08);
    --edge: rgba(255, 255, 255, 0.05);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px -16px rgba(0, 0, 0, 0.7);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.3), 0 26px 56px -22px rgba(0, 0, 0, 0.8);
    --ambient-1: rgba(var(--accent-rgb), 0.11);
    --ambient-2: rgba(124, 92, 255, 0.16);
    --ambient-3: rgba(var(--accent-2-rgb), 0.08);
    --ambient-4: rgba(20, 184, 166, 0.08);
    --inline-code: rgba(255, 255, 255, 0.08);
    --accent-mix-base: #ffffff;
    --accent-mix: 82%;
    --code-bg: #0b1020;
    --code-head: #10172b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --adv-ink: 165, 160, 255;
  --bg: #080b13;
  --ink: #eef2f8;
  --ink-2: #aab3c5;
  --ink-3: #768099;
  --surface: rgba(24, 30, 48, 0.58);
  --surface-2: rgba(30, 37, 58, 0.78);
  --header: rgba(8, 11, 19, 0.74);
  --ring: rgba(255, 255, 255, 0.08);
  --edge: rgba(255, 255, 255, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px -16px rgba(0, 0, 0, 0.7);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.3), 0 26px 56px -22px rgba(0, 0, 0, 0.8);
  --ambient-1: rgba(var(--accent-rgb), 0.11);
  --ambient-2: rgba(124, 92, 255, 0.16);
  --ambient-3: rgba(var(--accent-2-rgb), 0.08);
  --ambient-4: rgba(20, 184, 166, 0.08);
  --inline-code: rgba(255, 255, 255, 0.08);
  --accent-mix-base: #ffffff;
  --accent-mix: 82%;
  --code-bg: #0b1020;
  --code-head: #10172b;
}

/* Base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: calc(var(--topbar-h) + 18px);
  -webkit-text-size-adjust: 100%;
}

body {
  --accent: rgb(var(--accent-rgb));
  --accent-ink: color-mix(in oklab, var(--accent) var(--accent-mix), var(--accent-mix-base));
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: -20%;
  background:
    radial-gradient(46% 40% at 14% 14%, var(--ambient-1), transparent 70%),
    radial-gradient(44% 38% at 86% 10%, var(--ambient-2), transparent 70%),
    radial-gradient(50% 44% at 62% 70%, var(--ambient-3), transparent 70%),
    radial-gradient(40% 38% at 8% 88%, var(--ambient-4), transparent 70%);
  content: "";
  pointer-events: none;
  animation: drift 40s ease-in-out infinite alternate;
}

/* The drifting background costs GPU time on every frame; keep it still on phones and tablets. */
@media (max-width: 900px), (pointer: coarse) {
  body::before {
    animation: none;
  }
}

@keyframes drift {
  to {
    transform: translate3d(3%, -2%, 0) rotate(4deg) scale(1.05);
  }
}

a {
  color: var(--accent-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

h1,
h2,
h3,
h4,
h5,
p {
  margin-top: 0;
}

code {
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: var(--inline-code);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

kbd {
  font-family: var(--font-mono);
}

::selection {
  background: rgba(var(--accent-rgb), 0.3);
}

.skip {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
}

.skip:focus {
  top: 12px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 20px;
  border-bottom: 1px solid var(--ring);
  background: var(--header);
  backdrop-filter: saturate(1.6) blur(18px);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: none;
  place-items: end end;
  width: 34px;
  height: 34px;
  padding: 3px 5px;
  border-radius: 9px;
  background: var(--accent);
  box-shadow: 0 6px 18px -6px rgba(var(--accent-rgb), 0.7), inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  color: var(--on-accent, #111);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  white-space: nowrap;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-text span {
  color: var(--ink-3);
  font-size: 12px;
}

/* Study-site switcher */

.site-switcher {
  position: relative;
  flex: none;
  margin-left: -6px;
}

.site-switcher summary {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--ink-3);
  list-style: none;
  cursor: pointer;
}

.site-switcher summary::-webkit-details-marker {
  display: none;
}

.site-switcher summary:hover,
.site-switcher[open] summary {
  background: var(--surface);
  color: var(--ink);
}

.site-menu {
  position: absolute;
  top: calc(100% + 10px);
  left: -60px;
  z-index: 45;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: var(--shadow-lift);
}

.site-menu p {
  margin: 4px 10px 6px;
  color: var(--ink-3);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.site-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.site-menu a:hover {
  background: var(--surface);
}

.site-menu a[aria-current="page"] {
  background: rgba(var(--accent-rgb), 0.13);
}

.site-menu a[aria-current="page"]::after {
  margin-left: auto;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 500;
  content: "you’re here";
}

.site-dot {
  display: grid;
  flex: none;
  place-items: end end;
  width: 26px;
  height: 26px;
  padding: 2px 4px;
  border-radius: 7px;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1;
}

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
  margin-left: auto;
}

.search input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 36px;
  border: 1px solid var(--ring);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search input::-webkit-search-cancel-button {
  display: none;
}

.search input:focus {
  border-color: rgba(var(--accent-rgb), 0.6);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.16);
}

.search-icon {
  position: absolute;
  top: 11px;
  left: 12px;
  color: var(--ink-3);
  pointer-events: none;
}

.search-kbd {
  position: absolute;
  top: 9px;
  right: 10px;
  min-width: 20px;
  padding: 0 5px;
  border: 1px solid var(--ring);
  border-radius: 6px;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  pointer-events: none;
}

.search input:focus ~ .search-kbd {
  display: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  max-height: min(70vh, 520px);
  margin: 0;
  padding: 6px;
  overflow: auto;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: var(--shadow-lift);
  list-style: none;
}

.search-results a {
  display: block;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
}

.search-results li[aria-selected="true"] a,
.search-results a:hover {
  background: rgba(var(--accent-rgb), 0.14);
}

.search-results .r-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.search-results .r-meta {
  display: block;
  overflow: hidden;
  color: var(--ink-3);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-results mark {
  border-radius: 3px;
  background: rgba(var(--accent-rgb), 0.35);
  color: inherit;
}

.search-results .r-empty {
  padding: 12px;
  color: var(--ink-3);
  font-size: 14px;
}

.topbar-progress {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

button.topbar-progress {
  padding: 4px 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

button.topbar-progress:hover {
  background: var(--surface);
}

.topbar-progress {
  position: relative;
}

.topbar-progress .sync-dot {
  position: absolute;
  top: 4px;
  left: 26px;
  box-shadow: 0 0 0 2px var(--bg);
}

.topbar-progress strong {
  color: var(--ink);
}

.ring-track,
.ring-fill {
  fill: none;
  stroke-width: 4;
}

.ring-track {
  stroke: var(--ring);
}

.ring-fill {
  stroke: var(--accent);
  stroke-dasharray: 94.25;
  stroke-dashoffset: 94.25;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset 0.4s ease;
}

.icon-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--ring);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--ink);
}

.theme-btn .i-moon,
:root[data-theme="dark"] .theme-btn .i-sun {
  display: none;
}

:root[data-theme="dark"] .theme-btn .i-moon {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .i-sun {
    display: none;
  }
  :root:not([data-theme="light"]) .theme-btn .i-moon {
    display: block;
  }
}

.menu-btn {
  display: none;
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  padding: 18px 10px 14px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--ring);
  scrollbar-width: thin;
}

.nav,
.nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-chapter + .nav-chapter {
  margin-top: 4px;
}

.nav-chapter-link {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.nav-chapter-link:hover {
  background: var(--surface);
}

.nav-chapter-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.nav-chapter-row .nav-chapter-link {
  flex: 1;
  min-width: 0;
}

.nav-chapter-link[aria-current="page"] {
  background: rgba(var(--accent-rgb), 0.1);
}

.nav-expand {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
}

.nav-expand:hover {
  background: var(--surface);
  color: var(--ink);
}

.nav-expand svg {
  transition: transform 0.2s ease;
}

.nav-chapter.open .nav-expand svg {
  transform: rotate(90deg);
}

.nav-num {
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
}

.nav-chapter-name {
  flex: 1;
}

.nav-count {
  color: var(--ink-3);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.nav-count.done {
  color: var(--accent-ink);
}

.nav-chapter ul {
  display: none;
  margin: 2px 0 8px 22px;
  padding-left: 10px;
  border-left: 1px solid var(--ring);
}

.nav-chapter.open ul {
  display: block;
}

.nav-chapter ul a {
  position: relative;
  display: block;
  padding: 4px 10px 4px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.4;
  text-decoration: none;
}

.nav-chapter ul a code {
  font-size: 0.9em;
}

.nav-chapter ul a:hover {
  color: var(--ink);
}

.nav-chapter ul a.active {
  background: rgba(var(--accent-rgb), 0.13);
  color: var(--ink);
  font-weight: 600;
}

.nav-chapter ul a.active::before {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: -11px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
  content: "";
}

.nav-chapter ul a.is-learned::after {
  margin-left: 6px;
  color: var(--accent-ink);
  font-size: 12px;
  content: "✓";
}

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: auto;
  padding: 16px 10px 0;
  font-size: 12.5px;
}

.sidebar-foot a {
  color: var(--ink-3);
  text-decoration: none;
}

/* Sync */

.sync-dot {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--ink-3);
  border-radius: 50%;
  vertical-align: 0;
}

body[data-sync="ok"] .sync-dot {
  border-color: rgb(var(--tip));
  background: rgb(var(--tip));
}

body[data-sync="syncing"] .sync-dot {
  border-color: var(--accent);
  background: var(--accent);
  animation: sync-pulse 0.9s ease-in-out infinite alternate;
}

body[data-sync="error"] .sync-dot,
body[data-sync="offline"] .sync-dot {
  border-color: rgb(var(--gotcha));
  background: rgb(var(--gotcha));
}

body:not([data-sync="ok"]):not([data-sync="syncing"]):not([data-sync="error"]):not([data-sync="offline"]) .topbar-progress .sync-dot {
  display: none;
}

@keyframes sync-pulse {
  to {
    opacity: 0.35;
  }
}

body[data-sync-enabled="false"] .sync-status,
body[data-sync-enabled="false"] .legend-sync {
  display: none;
}

body[data-sync-enabled="false"] button.topbar-progress {
  cursor: default;
}

.sidebar-foot {
  flex-wrap: wrap;
  row-gap: 8px;
}

.sidebar-foot > * {
  white-space: nowrap;
}

.sync-status {
  display: inline-flex;
  flex-basis: 100%;
  align-items: center;
  gap: 7px;
}

.legend-sync {
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.sync-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--ring);
  border-radius: 20px;
  background: var(--bg);
  box-shadow: var(--shadow-lift);
  color: var(--ink);
}

.sync-dialog::backdrop {
  background: rgba(2, 6, 23, 0.5);
  backdrop-filter: blur(3px);
}

.sync-card {
  padding: 22px 22px 18px;
}

.sync-card h2 {
  margin-bottom: 10px;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.sync-card p {
  margin-bottom: 12px;
  color: var(--ink-2);
  font-size: 14.5px;
}

.sync-card .sync-fine {
  color: var(--ink-3);
  font-size: 12.5px;
}

.sync-field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
}

.sync-field input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--ring);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
  outline: none;
}

.sync-field input:focus {
  border-color: rgba(var(--accent-rgb), 0.6);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.16);
}

.google-button {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin: 4px 0 6px;
}

.sync-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 12px !important;
  color: var(--ink-3) !important;
  font-size: 12.5px !important;
}

.sync-or::before,
.sync-or::after {
  flex: 1;
  height: 1px;
  background: var(--ring);
  content: "";
}

.sync-google:not([hidden]) ~ .sync-phrase-intro {
  display: none;
}

.sync-card .sync-id-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
}

.sync-id {
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 15px;
  letter-spacing: 0.12em;
}

.sync-card .sync-hint {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--ink);
  font-size: 13.5px;
}

.sync-error {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(var(--gotcha), 0.1);
  color: rgb(var(--gotcha)) !important;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.btn {
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent, #111);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.btn-quiet {
  border-color: var(--ring);
  background: transparent;
  color: var(--ink-2);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.sync-dialog[data-on="true"] .sync-off-view,
.sync-dialog:not([data-on="true"]) .sync-on-view {
  display: none;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font: inherit;
  cursor: pointer;
}

.link-btn:hover,
.sidebar-foot a:hover {
  color: var(--ink);
}

main {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 32px 40px;
}

/* Hero */

.hero {
  padding: 56px 0 30px;
}

.eyebrow {
  margin-bottom: 14px;
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  max-width: 16ch;
  margin-bottom: 16px;
  font-size: clamp(36px, 6vw, 58px);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.02;
}

.hero h1 em {
  background: linear-gradient(100deg, var(--accent-ink), rgb(var(--accent-2-rgb)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-style: normal;
}

.lede {
  max-width: 60ch;
  color: var(--ink-2);
  font-size: 18px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 26px 0 34px;
}

.stats div {
  min-width: 120px;
  padding: 12px 16px;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 1px 0 var(--edge);
}

.stats dt {
  color: var(--ink-3);
  font-size: 12px;
}

.stats dd {
  margin: 0;
  font-size: 24px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.chapter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  overflow: hidden;
  border: 1px solid var(--ring);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow), inset 0 1px 0 var(--edge);
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.chapter-card:hover {
  border-color: rgba(var(--accent-rgb), 0.45);
  box-shadow: var(--shadow-lift), 0 0 0 4px rgba(var(--accent-rgb), 0.08);
  transform: translateY(-2px);
}

.chapter-card-num {
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}

.chapter-card-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chapter-card-summary {
  flex: 1;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.5;
}

.chapter-card-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--ink-3);
  font-size: 12px;
}

.chapter-card-progress {
  font-variant-numeric: tabular-nums;
}

.chapter-card-progress.done {
  color: var(--accent-ink);
  font-weight: 600;
}

.legend {
  margin-top: 22px;
  color: var(--ink-3);
  font-size: 13.5px;
}

.legend-learned {
  color: var(--ink-2);
  font-weight: 600;
}

/* Chapters and topics */

.chapter {
  padding-top: 40px;
}

.chapter-head {
  margin: 0 0 22px;
  padding: 26px 0 0;
  border-top: 1px solid var(--ring);
}

.chapter-num {
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chapter-head h1,
.chapter-head h2 {
  margin: 6px 0 8px;
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.chapter-head p {
  max-width: 62ch;
  margin: 0;
  color: var(--ink-2);
  font-size: 16.5px;
}

.topic {
  margin-bottom: 18px;
  padding: 24px 28px 22px;
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow), inset 0 1px 0 var(--edge);
  /* The browser skips layout and painting for topics that are off screen. With 130+ long topics on one
     page this is the difference between smooth and janky scrolling on phones. "auto" makes it remember
     each topic's real height once it has been shown, so the scrollbar settles. */
  content-visibility: auto;
  contain-intrinsic-size: auto var(--hd, 1500px);
}

@media (max-width: 640px) {
  .topic {
    contain-intrinsic-size: auto var(--hm, 3000px);
  }
}

.topic-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.topic-head h2 {
  position: relative;
  flex: 1 1 auto;
  margin: 0;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.topic-head h2 code {
  font-size: 0.85em;
}

.anchor {
  position: absolute;
  left: -20px;
  color: var(--ink-3);
  font-weight: 500;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.topic-head:hover .anchor,
.anchor:focus-visible {
  opacity: 1;
}

.badge-new {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid rgba(var(--interview), 0.3);
  border-radius: 999px;
  background: rgba(var(--interview), 0.1);
  color: rgb(var(--interview));
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

:root[data-theme="dark"] .badge-new {
  color: #c4b5fd;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-new {
    color: #c4b5fd;
  }
}

.learned {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  padding: 5px 11px 5px 8px;
  border: 1px solid var(--ring);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-3);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.learned:hover {
  color: var(--ink);
}

.learned-box {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 1.5px solid currentColor;
  border-radius: 5px;
}

.learned[aria-pressed="true"] {
  border-color: rgba(var(--accent-rgb), 0.5);
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--accent-ink);
}

.learned[aria-pressed="true"] .learned-box,
.dock-learned[aria-pressed="true"] .learned-box {
  border-color: var(--accent);
  background: var(--accent);
}

.learned[aria-pressed="true"] .learned-box::after,
.dock-learned[aria-pressed="true"] .learned-box::after {
  color: var(--on-accent, #111);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  content: "✓";
}

/* Topic body typography */

.topic-body p code,
.topic-body li code,
.callout code {
  overflow-wrap: anywhere;
}

.topic-body > :last-child {
  margin-bottom: 0;
}

.topic-body p,
.topic-body ul,
.topic-body ol {
  margin: 0 0 14px;
  color: var(--ink);
}

.topic-body ul,
.topic-body ol {
  padding-left: 22px;
}

.topic-body li + li {
  margin-top: 5px;
}

.topic-body li::marker {
  color: var(--ink-3);
}

.topic-body h4 {
  margin: 22px 0 10px;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topic-body h5 {
  margin: 18px 0 8px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topic-body strong {
  font-weight: 650;
}

.topic-body blockquote {
  margin: 0 0 14px;
  padding: 2px 0 2px 16px;
  border-left: 3px solid rgba(var(--accent-rgb), 0.6);
  color: var(--ink-2);
}

/* Code blocks: always dark so syntax colours read the same in both themes */

.code {
  margin: 0 0 16px;
  overflow: hidden;
  border: 1px solid var(--code-ring);
  border-radius: 14px;
  background: var(--code-bg);
  box-shadow: 0 10px 30px -18px rgba(2, 6, 23, 0.55);
}

.code figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 8px 7px 14px;
  border-bottom: 1px solid var(--code-ring);
  background: var(--code-head);
  color: var(--code-dim);
  font-family: var(--font-mono);
  font-size: 12px;
}

.code figcaption span::before {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.8);
  content: "";
  vertical-align: 1px;
}

.copy-btn {
  padding: 3px 9px;
  border: 1px solid var(--code-ring);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--code-dim);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--code-ink);
}

.copy-btn.copied {
  color: #6ee7b7;
}

.code pre {
  margin: 0;
  padding: 14px 16px 16px;
  overflow-x: auto;
  color: var(--code-ink);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.code code {
  padding: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font-size: inherit;
}

/* Prism tokens */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #6b7a99;
  font-style: italic;
}
.token.punctuation {
  color: #a3aec5;
}
.token.keyword,
.token.important,
.token.atrule {
  color: #c792ea;
}
.token.string,
.token.char,
.token.attr-value,
.token.template-string,
.token.regex {
  color: #a5e075;
}
.token.template-punctuation,
.token.interpolation-punctuation {
  color: #89ddff;
}
.token.number,
.token.boolean,
.token.constant {
  color: #f78c6c;
}
.token.function,
.token.method {
  color: #82aaff;
}
.token.class-name,
.token.builtin {
  color: #ffcb6b;
}
.token.operator,
.token.entity,
.token.url {
  color: #89ddff;
}
.token.tag,
.token.selector {
  color: #f07178;
}
.token.attr-name,
.token.property {
  color: #ffcb6b;
}
.token.parameter {
  color: #e6edf8;
}

/* Callouts */

.callout {
  --c: var(--note);
  position: relative;
  margin: 0 0 16px;
  padding: 14px 16px 14px 18px;
  overflow: hidden;
  border: 1px solid rgba(var(--c), 0.24);
  border-radius: 14px;
  background: rgba(var(--c), 0.07);
}

.callout::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: rgb(var(--c));
  content: "";
}

.callout-gotcha {
  --c: var(--gotcha);
}
.callout-tip {
  --c: var(--tip);
}
.callout-note {
  --c: var(--note);
}
.callout-interview {
  --c: var(--interview);
}

.callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: color-mix(in oklab, rgb(var(--c)) var(--accent-mix), var(--accent-mix-base));
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.callout-title::before {
  font-size: 14px;
  content: "ℹ";
}

.callout-gotcha .callout-title::before {
  content: "⚠";
}
.callout-tip .callout-title::before {
  content: "✦";
}
.callout-interview .callout-title::before {
  content: "💬";
}

.callout > :last-child,
.callout p:last-child {
  margin-bottom: 0;
}

.callout p,
.callout ul,
.callout ol {
  font-size: 15px;
}

/* Quiz */

.quiz {
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px dashed rgba(var(--accent-rgb), 0.55);
  border-radius: 14px;
  background: rgba(var(--accent-rgb), 0.06);
}

.quiz-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 700;
}

.quiz-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent, #111);
  font-size: 12px;
  font-weight: 900;
}

.quiz .code {
  margin-bottom: 10px;
}

.quiz details summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--ring);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 650;
  list-style: none;
  cursor: pointer;
}

.quiz details summary::-webkit-details-marker {
  display: none;
}

.quiz details summary::before {
  font-size: 10px;
  content: "▶";
  transition: transform 0.15s;
}

.quiz details[open] summary::before {
  transform: rotate(90deg);
}

.quiz details[open] summary {
  margin-bottom: 12px;
}

.quiz-answer > :last-child {
  margin-bottom: 0;
}

/* "What's happening" walkthroughs — sit directly under the code they explain */

.steps {
  margin: 0 0 18px;
  padding: 14px 18px 16px;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: var(--surface-2);
}

.code:has(+ .steps) {
  margin-bottom: 0;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}

.code + .steps {
  border-top: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.steps-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.steps-title::before {
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  content: "";
}

.steps p,
.steps ul,
.steps li {
  font-size: 15px;
}

.steps > :last-child {
  margin-bottom: 0;
}

.steps ol {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps ol > li {
  position: relative;
  padding-left: 34px;
  counter-increment: step;
}

.steps ol > li + li {
  margin-top: 9px;
}

.steps ol > li::before {
  position: absolute;
  top: 1px;
  left: 0;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(var(--accent-rgb), 0.18);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 750;
  content: counter(step);
}

.steps ol:last-child {
  margin-bottom: 0;
}

.quiz .steps,
.col .steps {
  background: transparent;
}

/* Columns */

.cols {
  display: grid;
  gap: 12px;
  margin-bottom: 4px;
}

.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.col > :last-child {
  margin-bottom: 12px;
}

/* Tables */

.table-wrap {
  margin: 0 0 16px;
  overflow-x: auto;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: var(--surface-2);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--ring);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

td code {
  white-space: nowrap;
}

/* Diagrams */

.diagram {
  margin: 0 0 16px;
  padding: 16px;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: var(--surface-2);
}

.diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

.diagram figcaption {
  margin-top: 10px;
  color: var(--ink-3);
  font-size: 13px;
  text-align: center;
}

.diagram text {
  fill: var(--ink);
  font-family: var(--font-sans);
}

.diagram .d-dim {
  fill: var(--ink-3);
}

.diagram .d-mono {
  font-family: var(--font-mono);
}

.diagram .d-box {
  fill: var(--surface);
  stroke: var(--ring);
  stroke-width: 1.5;
}

.diagram .d-accent {
  fill: rgba(var(--accent-rgb), 0.16);
  stroke: rgba(var(--accent-rgb), 0.7);
  stroke-width: 1.5;
}

.diagram .d-violet {
  fill: rgba(var(--interview), 0.12);
  stroke: rgba(var(--interview), 0.6);
  stroke-width: 1.5;
}

.diagram .d-green {
  fill: rgba(var(--tip), 0.12);
  stroke: rgba(var(--tip), 0.6);
  stroke-width: 1.5;
}

.diagram .d-blue {
  fill: rgba(var(--note), 0.12);
  stroke: rgba(var(--note), 0.6);
  stroke-width: 1.5;
}

.diagram .d-line {
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 1.5;
}

.diagram .d-bar-parse {
  fill: rgba(var(--note), 0.55);
}

.diagram .d-bar-fetch {
  fill: rgba(var(--tip), 0.6);
}

.diagram .d-bar-run {
  fill: rgba(var(--gotcha), 0.65);
}

/* Footer and floating button */

.footer {
  margin-top: 40px;
  padding-top: 22px;
  border-top: 1px solid var(--ring);
  color: var(--ink-3);
  font-size: 13.5px;
}

.footer p {
  margin-bottom: 6px;
}

.footer a {
  color: var(--ink-2);
}

.to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--ring);
  border-radius: 14px;
  background: var(--surface-2);
  box-shadow: var(--shadow-lift);
  color: var(--ink);
  cursor: pointer;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.scrim {
  display: none;
}

/* Responsive */

@media (max-width: 1080px) {
  .topbar-progress span {
    display: none;
  }
}

@media (max-width: 900px) {
  :root {
    --topbar-h: 56px;
  }

  .layout {
    display: block;
  }

  .menu-btn {
    display: grid;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    z-index: 35;
    width: min(320px, 86vw);
    height: auto;
    border-right: 1px solid var(--ring);
    background: var(--bg);
    box-shadow: var(--shadow-lift);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }

  body.nav-open .sidebar {
    transform: none;
  }

  .scrim {
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 34;
    display: block;
    background: rgba(2, 6, 23, 0.4);
  }

  .scrim[hidden] {
    display: none;
  }

  main {
    padding: 0 16px 32px;
  }

  .anchor {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 8px;
    padding: 0 12px;
  }

  .brand-text {
    display: none;
  }

  .search {
    max-width: none;
  }

  .search-kbd {
    display: none;
  }

  .topbar-progress {
    display: none;
  }

  .hero {
    padding-top: 34px;
  }

  .lede {
    font-size: 16.5px;
  }

  .stats div {
    flex: 1 1 40%;
    min-width: 0;
  }

  .topic {
    padding: 18px 16px 16px;
    border-radius: 16px;
  }

  .topic-head h2 {
    font-size: 19px;
  }

  .code {
    margin-right: -6px;
    margin-left: -6px;
  }

  .code pre {
    font-size: 12.5px;
  }

  .cols-2,
  .cols-3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .quiz,
  .callout {
    padding-right: 12px;
    padding-left: 12px;
  }

  .steps {
    padding: 12px 14px 14px;
  }

  .quiz .steps,
  .callout .steps {
    padding: 10px 10px 12px;
  }

  .steps ol > li {
    padding-left: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
  html {
    scroll-behavior: auto;
  }
}

@media print {
  body::before,
  .topbar,
  .sidebar,
  .learned,
  .to-top,
  .dock,
  .toc,
  .read-progress,
  .copy-btn {
    display: none !important;
  }
  .layout {
    display: block;
  }
  .topic {
    break-inside: avoid;
    box-shadow: none;
  }
  .quiz details {
    display: block;
  }
}

[hidden] {
  display: none !important;
}

/* Pages: home "continue" card, progress meters, chapter page header, pager, "on this page", reading
   progress, phone dock and page transitions. */

.meter {
  display: block;
  height: 4px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--ring);
}

.meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), rgb(var(--accent-2-rgb)));
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.5s ease;
}

.chapter-card .meter {
  margin-top: 10px;
}

.continue {
  display: grid;
  grid-template-areas: "kicker arrow" "title arrow" "meta arrow";
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 16px;
  margin: 0 0 22px;
  padding: 18px 22px;
  border: 1px solid rgba(var(--accent-rgb), 0.38);
  border-radius: 18px;
  background: linear-gradient(120deg, rgba(var(--accent-rgb), 0.16), rgba(var(--accent-2-rgb), 0.07)), var(--surface);
  box-shadow: var(--shadow), inset 0 1px 0 var(--edge);
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.continue:hover {
  box-shadow: var(--shadow-lift), 0 0 0 4px rgba(var(--accent-rgb), 0.08);
  transform: translateY(-2px);
}

.continue-kicker {
  grid-area: kicker;
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.continue-title {
  grid-area: title;
  margin: 2px 0;
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.continue-meta {
  grid-area: meta;
  color: var(--ink-2);
  font-size: 13.5px;
}

.continue-arrow {
  display: grid;
  grid-area: arrow;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 8px 20px -8px rgba(var(--accent-rgb), 0.8);
  color: var(--on-accent, #111);
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 30px;
  color: var(--ink-3);
  font-size: 13px;
}

.crumbs a {
  color: var(--ink-2);
  font-weight: 600;
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--accent-ink);
}

.layout-chapter .chapter {
  padding-top: 12px;
}

.layout-chapter .chapter-head {
  margin-bottom: 26px;
  padding-top: 0;
  border-top: 0;
}

.chapter-head h1 {
  font-size: clamp(32px, 5vw, 46px);
}

.chapter-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  color: var(--ink-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.chapter-progress .meter {
  width: 160px;
}

.chapter-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 30px;
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 16px 18px;
  border: 1px solid var(--ring);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow), inset 0 1px 0 var(--edge);
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.pager-link:hover {
  border-color: rgba(var(--accent-rgb), 0.45);
  box-shadow: var(--shadow-lift), 0 0 0 4px rgba(var(--accent-rgb), 0.08);
  transform: translateY(-2px);
}

.pager-next {
  grid-column: 2;
  align-items: flex-end;
  text-align: right;
}

.pager-dir {
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 650;
}

.pager-title {
  font-weight: 700;
  line-height: 1.35;
}

.not-found h1 {
  max-width: none;
}

.toc {
  display: none;
}

@media (min-width: 1400px) {
  .layout-chapter {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 250px;
  }

  .toc {
    position: sticky;
    top: var(--topbar-h);
    display: block;
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
    padding: 34px 18px 24px 4px;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .toc-title {
    margin: 0 0 10px 14px;
    color: var(--ink-3);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .toc ol {
    margin: 0;
    padding: 0;
    border-left: 1px solid var(--ring);
    list-style: none;
  }

  .toc a {
    display: block;
    margin-left: -1px;
    padding: 5px 12px;
    border-left: 2px solid transparent;
    color: var(--ink-3);
    font-size: 13px;
    line-height: 1.4;
    text-decoration: none;
    transition: color 0.15s, border-color 0.15s;
  }

  .toc a:hover {
    color: var(--ink);
  }

  .toc a.active {
    border-left-color: var(--accent);
    color: var(--ink);
    font-weight: 600;
  }

  .toc a.is-learned::after {
    margin-left: 5px;
    color: var(--accent-ink);
    content: "✓";
  }

  .toc a code {
    font-size: 0.9em;
  }
}

/* Thin bar under the top bar that fills as the chapter is read. Driven by scroll position in CSS where
   supported; app.js updates it elsewhere. */
.read-progress {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), rgb(var(--accent-2-rgb)));
  transform: scaleX(var(--read, 0));
  transform-origin: 0 50%;
  pointer-events: none;
}

@supports (animation-timeline: scroll()) {
  .read-progress {
    animation: read-grow linear both;
    animation-timeline: scroll(root block);
  }
}

@keyframes read-grow {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

.dock {
  display: none;
}

@media (max-width: 900px) {
  .dock {
    position: fixed;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 2px;
    height: 56px;
    padding: 5px;
    border: 1px solid var(--ring);
    border-radius: 18px;
    background: var(--surface-2);
    box-shadow: var(--shadow-lift);
    backdrop-filter: saturate(1.6) blur(18px);
    -webkit-backdrop-filter: saturate(1.6) blur(18px);
  }

  .dock-btn,
  .dock-title {
    height: 46px;
    border: 0;
    border-radius: 13px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .dock-btn {
    display: grid;
    flex: none;
    place-items: center;
    width: 46px;
  }

  .dock-btn:active,
  .dock-title:active {
    background: rgba(var(--accent-rgb), 0.14);
  }

  .dock-title {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    padding: 0 8px;
    text-align: left;
  }

  .dock-kicker {
    color: var(--ink-3);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
  }

  .dock-name {
    max-width: 100%;
    overflow: hidden;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .dock-learned {
    color: var(--ink-3);
  }

  .dock-learned .learned-box {
    width: 20px;
    height: 20px;
    border-radius: 6px;
  }

  .dock-learned[aria-pressed="true"] {
    color: var(--accent-ink);
  }

  .layout-chapter main {
    padding-bottom: 96px;
  }

  body[data-page="chapter"] .to-top {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 640px) {
  .chapter-pager {
    grid-template-columns: minmax(0, 1fr);
  }

  .pager-next {
    grid-column: auto;
  }

  .continue {
    padding: 16px 16px 16px 18px;
  }

  .continue-title {
    font-size: 17px;
  }
}

/* Moving between pages: the top bar, sidebar and dock stay put while the page content cross-fades and
   settles upward. Supported in Chrome and Safari 18.2+; other browsers simply load the page. */
@view-transition {
  navigation: auto;
}

.topbar {
  view-transition-name: topbar;
}

.dock {
  view-transition-name: dock;
}

@media (min-width: 901px) {
  .sidebar {
    view-transition-name: sidebar;
  }
}

::view-transition-old(root) {
  animation: vt-out 0.14s ease-out both;
}

::view-transition-new(root) {
  animation: vt-in 0.28s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes vt-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }

  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* Optional "Advanced" depth: labelled, and foldable with one switch. */

.badge-advanced {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid rgba(var(--adv), 0.35);
  border-radius: 999px;
  background: rgba(var(--adv), 0.12);
  color: rgb(var(--adv-ink));
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.6;
  white-space: nowrap;
}

.advanced {
  margin: 20px 0;
  padding: 14px 16px 4px;
  border: 1px dashed rgba(var(--adv), 0.4);
  border-radius: 14px;
  background: rgba(var(--adv), 0.04);
}

.advanced-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 10px;
}

.advanced-title {
  font-size: 15px;
  font-weight: 700;
}

.advanced-body > :last-child {
  margin-bottom: 12px;
}

.advanced-show {
  display: none;
  margin-left: auto;
  padding: 3px 12px;
  border: 1px solid var(--ring);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.advanced-show:hover {
  color: var(--ink);
}

/* Hidden: an advanced block shrinks to its one-line header; an advanced topic to its title row. */
.hide-advanced .advanced:not(.reveal) {
  padding-bottom: 0;
}

.hide-advanced .advanced:not(.reveal) .advanced-head {
  margin-bottom: 12px;
}

.hide-advanced .advanced:not(.reveal) .advanced-body,
.hide-advanced .topic-advanced:not(.reveal) .topic-body {
  display: none;
}

.hide-advanced .advanced:not(.reveal) .advanced-show,
.hide-advanced .topic-advanced:not(.reveal) .advanced-show {
  display: inline-flex;
}

.hide-advanced .topic-advanced:not(.reveal) {
  contain-intrinsic-size: auto 80px;
}

.hide-advanced .topic-advanced:not(.reveal) .topic-head {
  margin-bottom: 0;
}

/* A folded topic's row is just title, badge and Show; Learned comes back once it's shown. */
.hide-advanced .topic-advanced:not(.reveal) .learned {
  display: none;
}

.topic-head .advanced-show {
  margin-left: auto;
}

.hide-advanced .nav a[data-adv] {
  opacity: 0.55;
}

.advanced-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-top: 14px;
  color: var(--ink-3);
  font-size: 13px;
}

.advanced-switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.switch-track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--ring);
  box-shadow: inset 0 0 0 1px var(--ring);
  transition: background 0.2s;
}

.switch-track::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink-3);
  content: "";
  transition: transform 0.2s, background 0.2s;
}

.advanced-switch[aria-checked="true"] .switch-track {
  background: rgba(var(--adv), 0.55);
}

.advanced-switch[aria-checked="true"] .switch-track::after {
  background: #fff;
  transform: translateX(14px);
}

@media (max-width: 640px) {
  .advanced {
    margin-right: -4px;
    margin-left: -4px;
    padding-right: 12px;
    padding-left: 12px;
  }
}
