/* Bytebook — site styles. Tokens first, then layout, then components. */
:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #F8F7F3;
  --surface: #FFFFFF;
  --surface-2: #F2F0EA;
  --surface-3: #E8E5DD;
  --ink: #17171B;
  --ink-2: #393941;
  --muted: #65656F;
  --faint: #95959F;
  --line: #E4E1D8;
  --line-2: #D3CFC4;
  --gold: #A87717;
  --gold-soft: #FBF2DE;
  --good: #187A43; --good-soft: #E4F3E9;
  --bad: #C0362F; --bad-soft: #FBEAE8;
  --warn: #9E5A00; --warn-soft: #FDF0DA;
  --info: #2156C2; --info-soft: #E8EFFC;
  --focus: #2F6FED;
  --shadow-1: 0 1px 2px rgba(23, 23, 27, .06);
  --shadow-2: 0 1px 2px rgba(23, 23, 27, .05), 0 14px 34px -18px rgba(23, 23, 27, .28);
  --shadow-3: 0 30px 70px -24px rgba(23, 23, 27, .38);
  --code-bg: #12141A;
  --code-bg-2: #0C0E12;
  --code-ink: #E2E5EC;
  --code-muted: #828A9C;
  --code-line: #232733;
  --top-h: 105px;
  --side-w: 290px;
  --toc-w: 230px;
  --c: #4B47D6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D0E12; --surface: #15171C; --surface-2: #1B1D24; --surface-3: #252832;
    --ink: #EDEEF2; --ink-2: #C9CBD4; --muted: #969AA8; --faint: #6B6F7D;
    --line: #262932; --line-2: #343844;
    --gold: #E6BC5E; --gold-soft: #2A2314;
    --good: #4FC383; --good-soft: #13281C; --bad: #F27D76; --bad-soft: #321B1B;
    --warn: #F1B24C; --warn-soft: #2D2312; --info: #7DA8FF; --info-soft: #162138;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 36px -18px rgba(0, 0, 0, .7);
    --shadow-3: 0 30px 70px -24px rgba(0, 0, 0, .8);
    --code-bg: #101217; --code-bg-2: #0B0C10; --code-line: #20232C;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D0E12; --surface: #15171C; --surface-2: #1B1D24; --surface-3: #252832;
  --ink: #EDEEF2; --ink-2: #C9CBD4; --muted: #969AA8; --faint: #6B6F7D;
  --line: #262932; --line-2: #343844;
  --gold: #E6BC5E; --gold-soft: #2A2314;
  --good: #4FC383; --good-soft: #13281C; --bad: #F27D76; --bad-soft: #321B1B;
  --warn: #F1B24C; --warn-soft: #2D2312; --info: #7DA8FF; --info-soft: #162138;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 36px -18px rgba(0, 0, 0, .7);
  --shadow-3: 0 30px 70px -24px rgba(0, 0, 0, .8);
  --code-bg: #101217; --code-bg-2: #0B0C10; --code-line: #20232C;
  color-scheme: dark;
}
[data-c] {
  --c-soft: color-mix(in srgb, var(--c) 11%, var(--surface));
  --c-line: color-mix(in srgb, var(--c) 40%, var(--line));
  --c-ink: color-mix(in srgb, var(--c) 72%, var(--ink));
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 20px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.65 var(--font-sans);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
}
a { color: inherit; }
img, svg { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--c) 26%, transparent); }
.i { width: 18px; height: 18px; flex: none; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; z-index: 100; background: var(--surface); padding: 8px 14px; border-radius: 10px; box-shadow: var(--shadow-2); }
kbd {
  display: inline-block; font: 500 11px/1 var(--font-sans); padding: 3px 6px; min-width: 20px; text-align: center;
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); color: var(--muted);
}
.wrap { width: min(1180px, 100% - 40px); margin-inline: auto; }
.link-btn { background: none; border: 0; padding: 0; text-align: left; color: inherit; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: saturate(1.5) blur(16px); backdrop-filter: saturate(1.5) blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 10px; height: 58px; padding: 0 20px; max-width: 1640px; margin: 0 auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font: 650 21px/1 var(--font-serif); letter-spacing: -.015em; color: var(--ink); }
.brand .logo { width: 30px; height: 30px; flex: none; filter: drop-shadow(0 2px 4px rgba(150, 100, 20, .25)); }
.search-trigger {
  margin-left: auto; display: flex; align-items: center; gap: 10px; width: min(380px, 38vw); height: 38px; padding: 0 8px 0 12px;
  border: 1px solid var(--line-2); border-radius: 11px; background: var(--surface); color: var(--muted); box-shadow: var(--shadow-1);
  transition: border-color .15s;
}
.search-trigger:hover { border-color: var(--faint); }
.search-trigger span { flex: 1; text-align: left; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-run {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 15px 0 12px; border-radius: 11px;
  background: var(--ink); color: var(--bg); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: transform .15s, box-shadow .15s;
}
.top-run:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); }
.top-run .i { width: 15px; height: 15px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--line-2); border-radius: 11px; background: var(--surface); color: var(--ink-2);
}
.icon-btn:hover { color: var(--ink); border-color: var(--faint); }
.nav-toggle { display: none; }
.t-moon, :root[data-theme="dark"] .t-sun { display: none; }
:root[data-theme="dark"] .t-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .t-sun { display: none; }
  :root:not([data-theme="light"]) .t-moon { display: inline; }
}
.t-sun .i, .t-moon .i { display: block; }
.course-strip {
  display: flex; gap: 2px; height: 46px; padding: 0 14px; max-width: 1640px; margin: 0 auto;
  overflow-x: auto; scrollbar-width: none; -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent);
  mask-image: linear-gradient(90deg, #000 92%, transparent);
}
.course-strip::-webkit-scrollbar { display: none; }
.course-strip a {
  display: flex; align-items: center; gap: 8px; padding: 0 12px; flex: none;
  text-decoration: none; color: var(--muted); font-weight: 550; font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent; transition: color .15s;
}
.course-strip a .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent); }
.course-strip a:hover { color: var(--ink); }
.course-strip a.active { color: var(--ink); border-bottom-color: var(--c); }
.read-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; }
.read-progress span { display: block; height: 100%; width: 0; background: var(--c); transition: width .1s linear; }

/* ---------------------------------------------------------------- lesson layout */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr) var(--toc-w); max-width: 1640px; margin: 0 auto; align-items: start; }
.sidebar {
  position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); overflow-y: auto; overscroll-behavior: contain;
  border-right: 1px solid var(--line); padding: 22px 14px 40px 18px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.side-top { display: none; }
.main { min-width: 0; padding: 30px clamp(20px, 4.5vw, 64px) 90px; }
.lesson { max-width: 760px; margin: 0 auto; }
.toc { position: sticky; top: var(--top-h); max-height: calc(100vh - var(--top-h)); overflow-y: auto; padding: 34px 22px 30px 8px; scrollbar-width: none; }
.scrim { display: none; }

.side-course { display: block; text-decoration: none; padding: 2px 8px 14px; }
.side-course strong { display: block; margin-top: 10px; font: 600 19px/1.25 var(--font-serif); letter-spacing: -.01em; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 99px;
  font: 650 11.5px/1 var(--font-sans); letter-spacing: .04em; text-transform: uppercase;
  color: var(--c-ink); background: var(--c-soft); border: 1px solid color-mix(in srgb, var(--c) 25%, transparent);
}
.side-progress { padding: 0 8px 18px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--c); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.side-progress small { display: block; margin-top: 8px; color: var(--muted); font-size: 12.5px; }
.side-progress b { color: var(--ink); }
.side-unit h4 { margin: 20px 8px 6px; font: 650 11px/1.3 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
.side-unit ol { list-style: none; margin: 0; padding: 0; }
.side-unit a {
  display: flex; align-items: flex-start; gap: 10px; padding: 7px 9px; border-radius: 9px;
  text-decoration: none; color: var(--ink-2); font-size: 14.5px; line-height: 1.38; transition: background .12s;
}
.side-unit a:hover { background: var(--surface-2); color: var(--ink); }
.side-unit a.current { background: var(--c-soft); color: var(--ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--c); }
.tick {
  position: relative; flex: none; width: 16px; height: 16px; margin-top: 1.5px; border-radius: 50%;
  border: 1.5px solid var(--line-2); background: var(--surface);
}
.current .tick { border-color: var(--c); }
.done .tick { background: var(--good); border-color: var(--good); }
.done .tick::after {
  content: ""; position: absolute; left: 4.2px; top: 2.6px; width: 4px; height: 7px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.side-book {
  display: flex; gap: 10px; align-items: center; margin: 22px 4px 0; padding: 12px 12px; border-radius: 12px;
  border: 1px dashed var(--line-2); color: var(--muted); text-decoration: none; font-size: 13.5px; line-height: 1.35;
}
.side-book:hover { color: var(--ink); border-color: var(--c); }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 26px; font-size: 13.5px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.crumbs span:not(:last-child) { color: var(--faint); }
.eyebrow { margin: 0 0 14px; font: 650 12px/1.3 var(--font-sans); letter-spacing: .1em; text-transform: uppercase; color: var(--c-ink); }
.lesson-head h1 {
  margin: 0 0 16px; font: 600 clamp(34px, 4.6vw, 48px)/1.07 var(--font-serif); letter-spacing: -.022em;
  font-variation-settings: "opsz" 120; text-wrap: balance;
}
.lede { margin: 0 0 22px; font-size: 19.5px; line-height: 1.6; color: var(--ink-2); text-wrap: pretty; }
.lede code { font: 500 .85em var(--font-mono); }
.meta { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 28px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.meta span { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: 99px; background: var(--surface-2); font-size: 13px; font-weight: 500; color: var(--ink-2); }
.meta .i { width: 15px; height: 15px; color: var(--c-ink); }

.toc-inner p { margin: 0 0 12px; font: 650 11px/1 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc a {
  display: block; margin-left: -1px; padding: 5px 0 5px 14px; border-left: 2px solid transparent;
  text-decoration: none; color: var(--muted); font-size: 13.5px; line-height: 1.4; transition: color .15s, border-color .15s;
}
.toc a.d3 { padding-left: 26px; font-size: 13px; }
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--ink); border-left-color: var(--c); font-weight: 550; }

/* ---------------------------------------------------------------- prose */
.prose { font-size: 17px; line-height: 1.78; color: var(--ink-2); }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 1.05em 0; }
.prose h2 {
  position: relative; margin: 2.3em 0 .55em; color: var(--ink);
  font: 600 29px/1.2 var(--font-serif); letter-spacing: -.016em; font-variation-settings: "opsz" 72; text-wrap: balance;
}
.prose h3 { position: relative; margin: 1.9em 0 .45em; color: var(--ink); font: 650 19.5px/1.35 var(--font-sans); letter-spacing: -.01em; }
.prose h4 { margin: 1.6em 0 .3em; color: var(--ink); font: 650 16px/1.4 var(--font-sans); }
.prose .anchor {
  position: absolute; left: -1.05em; top: 0; width: 1em; opacity: 0; text-decoration: none; color: var(--faint);
  font-weight: 400; transition: opacity .15s;
}
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.prose strong { color: var(--ink); font-weight: 650; }
.prose em { font-style: italic; }
.prose a { color: var(--ink); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--c) 70%, transparent); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.prose a:hover { text-decoration-color: var(--c); text-decoration-thickness: 2.5px; }
.prose :not(pre) > code {
  font: 500 .855em/1 var(--font-mono); padding: .18em .4em; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); white-space: break-spaces;
}
.prose ul, .prose ol { padding-left: 1.35em; margin: 1em 0; }
.prose li { margin: .38em 0; padding-left: .2em; }
.prose li::marker { color: var(--c); font-weight: 600; }
.prose li > ul, .prose li > ol { margin: .3em 0; }
.prose blockquote {
  margin: 1.6em 0; padding: .3em 0 .3em 1.2em; border-left: 3px solid var(--c);
  font: italic 400 1.1em/1.6 var(--font-serif); color: var(--ink);
}
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.6em 0; }
.prose img { border-radius: 12px; }
.table-wrap { margin: 1.6em 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow-1); }
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.5; }
.prose th { padding: 10px 14px; text-align: left; font-weight: 650; color: var(--ink); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.prose td { padding: 9px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.prose tbody tr:first-child td { border-top: 0; }
.prose tbody tr:hover td { background: color-mix(in srgb, var(--c) 4%, transparent); }
.prose td code { white-space: nowrap; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 1.5em 0; }
.cols .col > :first-child { margin-top: 0; }
.cols .col > .code:first-child { margin-top: 0; }

/* ---------------------------------------------------------------- code */
.code {
  margin: 1.7em 0; border-radius: 15px; overflow: hidden; background: var(--code-bg); color: var(--code-ink);
  box-shadow: var(--shadow-2), inset 0 0 0 1px rgba(255, 255, 255, .05);
}
.code-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--code-line);
  font: 500 12.5px/1 var(--font-sans); color: var(--code-muted);
}
.code-lang { display: inline-flex; align-items: center; gap: 8px; color: #CDD2DD; font-weight: 600; letter-spacing: .02em; }
.code-lang::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.code-title { font: 500 12.5px/1 var(--font-mono); color: var(--code-muted); }
.code-copy {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 8px;
  background: transparent; border: 1px solid rgba(255, 255, 255, .1); color: #C3C8D4; font-size: 12px; font-weight: 500;
  transition: background .15s, color .15s;
}
.code-copy:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.code-copy .i { width: 14px; height: 14px; }
.code-copy.copied { color: #7EE2A8; border-color: rgba(126, 226, 168, .4); }
.code pre { margin: 0; padding: 16px 18px; overflow-x: auto; font: 450 14px/1.68 var(--font-mono); tab-size: 4; scrollbar-width: thin; scrollbar-color: #343a48 transparent; }
.code pre code { font: inherit; background: none; border: 0; padding: 0; white-space: pre; color: inherit; }
.code-out { border-top: 1px solid var(--code-line); background: var(--code-bg-2); }
.code-plain .code-out { border-top: 0; }
.out-head { display: flex; align-items: center; gap: 7px; padding: 10px 16px 0; font: 650 11px/1 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--code-muted); }
.out-head .i { width: 14px; height: 14px; }
.out-head em { font-style: normal; text-transform: none; letter-spacing: 0; font-weight: 500; }
.code-out pre { margin: 0; padding: 10px 18px 16px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; font: 450 14px/1.6 var(--font-mono); color: #D9DDE6; }
.code-out .in { color: #8BE3B0; font-weight: 600; text-decoration: underline; text-decoration-color: rgba(139, 227, 176, .35); text-underline-offset: 3px; }
.code-out .stderr { color: #FF9C94; }
.code-out .none { color: var(--code-muted); font-style: italic; }
.code-out.bad pre { color: #FF9C94; }
.code-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--code-line); background: var(--code-bg-2); }
.foot-note { margin-right: auto; padding-left: 6px; font-size: 12.5px; color: var(--code-muted); }
.tryit {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 15px; border-radius: 99px;
  background: var(--c); color: #fff; font: 650 13.5px/1 var(--font-sans); text-decoration: none !important;
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--c) 70%, transparent); transition: transform .15s, filter .15s;
}
.tryit:hover { transform: translateY(-1px); filter: brightness(1.08); }
.tryit .i { width: 15px; height: 15px; }
:root[data-theme="dark"] .tryit { color: #0B0C10; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tryit { color: #0B0C10; } }

/* highlight.js tokens tuned for the dark code panel */
.hljs-comment, .hljs-quote { color: #6E768A; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag { color: #C99BFF; }
.hljs-type, .hljs-built_in, .hljs-class .hljs-title, .hljs-title.class_ { color: #7CC7FF; }
.hljs-title, .hljs-title.function_, .hljs-section { color: #82AAFF; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #B9E67F; }
.hljs-number, .hljs-literal { color: #FF9E64; }
.hljs-meta, .hljs-meta .hljs-keyword { color: #FF7FAF; }
.hljs-meta .hljs-string { color: #B9E67F; }
.hljs-variable, .hljs-template-variable, .hljs-attr, .hljs-attribute { color: #FFCB6B; }
.hljs-symbol, .hljs-bullet, .hljs-char.escape_, .hljs-subst, .hljs-operator { color: #89DDFF; }
.hljs-name, .hljs-tag { color: #F07178; }
.hljs-params { color: #E2E5EC; }
.hljs-selector-class, .hljs-selector-id { color: #FFCB6B; }
.hljs-deletion { color: #FF7A7A; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------------------------------------------------------------- callouts */
.callout {
  margin: 1.7em 0; padding: 15px 18px 15px 17px; border-radius: 13px;
  background: var(--k-soft); border: 1px solid color-mix(in srgb, var(--k) 20%, transparent); border-left: 4px solid var(--k);
}
.callout-title { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font: 650 14px/1.3 var(--font-sans); color: var(--k); letter-spacing: .01em; }
.callout-title .i { width: 18px; height: 18px; }
.callout-body { font-size: 16px; line-height: 1.72; }
.callout-body > :first-child { margin-top: 0; }
.callout-body > :last-child { margin-bottom: 0; }
.callout-body .code { margin: 1em 0; }
.callout-note, .callout-info { --k: var(--info); --k-soft: var(--info-soft); }
.callout-tip { --k: var(--good); --k-soft: var(--good-soft); }
.callout-warn { --k: var(--warn); --k-soft: var(--warn-soft); }
.callout-mistake { --k: var(--bad); --k-soft: var(--bad-soft); }
.callout-exam { --k: var(--gold); --k-soft: var(--gold-soft); }
.callout-key, .callout-try { --k: var(--c-ink); --k-soft: var(--c-soft); }
.callout-def { --k: var(--ink); --k-soft: var(--surface); box-shadow: var(--shadow-1); }
.callout-def .callout-body { font-family: var(--font-serif); font-size: 17.5px; color: var(--ink); }

/* ---------------------------------------------------------------- diagrams */
.diagram {
  margin: 1.8em 0; padding: 22px 18px 16px; border: 1px solid var(--line); border-radius: 15px;
  background: var(--surface); text-align: center; overflow-x: auto; box-shadow: var(--shadow-1);
}
.diagram figcaption { margin-top: 12px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.dg { display: inline-block; height: auto; overflow: visible; vertical-align: top; }
.dg .box { fill: var(--surface); stroke: var(--line-2); stroke-width: 1.5; }
.dg .frame { fill: none; stroke: var(--ink-2); stroke-width: 1.6; }
.dg .box.hl, .dg .node.hl { fill: var(--c-soft); stroke: var(--c); stroke-width: 2; }
.dg .box.ok { fill: var(--good-soft); stroke: var(--good); }
.dg .dim { opacity: .38; }
.dg text { dominant-baseline: central; }
.dg .t { font: 500 15px var(--font-mono); fill: var(--ink); text-anchor: middle; }
.dg .lbl { font-family: var(--font-sans); font-weight: 650; }
.dg .s { font: 500 12px var(--font-sans); fill: var(--muted); text-anchor: middle; }
.dg .end { text-anchor: end; }
.dg .start { text-anchor: start; }
.dg text.ptr { fill: var(--c-ink); font-weight: 650; font-size: 12.5px; }
.dg .edge { stroke: var(--ink-2); stroke-width: 1.6; fill: none; }
.dg .edge.hl { stroke: var(--c); stroke-width: 3.2; }
.dg .ah { fill: var(--ink-2); }
.dg .div { stroke: var(--line-2); stroke-width: 1.5; }
.dg .dot { fill: var(--ink-2); }
.dg .slash { stroke: var(--faint); stroke-width: 1.5; }
.dg .node { fill: var(--surface); stroke: var(--ink-2); stroke-width: 1.6; }
.dg .wall { stroke: var(--ink-2); stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dg .wbg { fill: var(--surface); stroke: var(--line-2); }
.dg .w { fill: var(--ink); font-weight: 650; }
.dg .null { fill: var(--muted); font-size: 13px; }
.dg .name { font-weight: 650; }
.dg .addr { font-family: var(--font-mono); font-size: 11.5px; }
.dg .universe { fill: var(--surface-2); stroke: var(--line-2); }
.dg .shade circle, .dg .shade rect { fill: color-mix(in srgb, var(--c) 42%, transparent); stroke: none; }
.dg .unshade circle { fill: var(--surface-2); }
.dg .ring { fill: none; stroke: var(--ink-2); stroke-width: 1.6; }
.dg .cap { font-family: var(--font-sans); font-weight: 650; font-size: 14px; }
.dg .gate .body { fill: var(--surface); stroke: var(--ink-2); stroke-width: 1.8; }
.dg .gate .wire { stroke: var(--ink-2); stroke-width: 1.8; fill: none; }
.dg .fc { fill: var(--surface); stroke: var(--ink-2); stroke-width: 1.6; }
.dg .fc.term { fill: var(--c-soft); stroke: var(--c); }
.dg .fc.dec { fill: var(--gold-soft); stroke: var(--gold); }
.dg .fc + text, .dg .fc ~ text { font-family: var(--font-sans); font-size: 14px; }
.dg .yes { fill: var(--good); font-weight: 650; }
.dg .no { fill: var(--bad); font-weight: 650; }

/* ---------------------------------------------------------------- quiz */
.quiz {
  margin: 3.2em 0 1em; padding: 26px clamp(18px, 3.4vw, 32px) 22px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2);
}
.quiz-head { display: flex; align-items: center; gap: 12px; }
.quiz-head > .i { width: 26px; height: 26px; color: var(--c); }
.quiz .quiz-head h2 { margin: 0; font: 600 25px/1.2 var(--font-serif); color: var(--ink); }
.quiz-score { margin-left: auto; padding: 6px 11px; border-radius: 99px; background: var(--c-soft); color: var(--c-ink); font: 650 13px/1 var(--font-sans); }
.quiz-sub { margin: 4px 0 6px 38px !important; font-size: 14px; color: var(--muted); }
.quiz-list { list-style: none; margin: 0; padding: 0; }
.q { margin: 0; padding: 20px 0 18px; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; }
.q-text { display: flex; gap: 12px; margin-bottom: 12px; color: var(--ink); font-weight: 600; font-size: 16.5px; line-height: 1.55; }
.q-num { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--ink); color: var(--bg); font: 700 13px/1 var(--font-sans); margin-top: 1px; }
.q-body { min-width: 0; flex: 1; }
.q-body > * { margin: 0 !important; }
.q-body > * + * { margin-top: .7em !important; }
.q-body .code { font-weight: 400; }
.q-opts { display: grid; gap: 8px; padding-left: 38px; }
.q-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; text-align: left;
  border: 1.5px solid var(--line-2); border-radius: 12px; background: var(--bg); font-size: 15.5px; line-height: 1.45;
  transition: border-color .15s, background .15s, transform .1s;
}
.q-opt:hover:not(:disabled) { border-color: var(--c); background: var(--c-soft); }
.q-opt:active:not(:disabled) { transform: scale(.995); }
.q-opt:disabled { cursor: default; }
.q-key { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--surface-3); color: var(--muted); font: 700 12.5px/1 var(--font-sans); }
.q-label code { font: 500 .9em var(--font-mono); padding: .1em .35em; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); }
.q-opt.right { border-color: var(--good); background: var(--good-soft); }
.q-opt.right .q-key { background: var(--good); color: #fff; }
.q-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-opt.wrong .q-key { background: var(--bad); color: #fff; }
.q-opt.faded { opacity: .55; }
.q-why { margin: 12px 0 0 38px; padding: 12px 15px; border-radius: 12px; background: var(--surface-2); font-size: 15px; line-height: 1.65; }
.q-why .verdict { font-weight: 700; margin-right: 6px; }
.q-why .verdict.ok { color: var(--good); }
.q-why .verdict.no { color: var(--bad); }
.quiz-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--line); }
.quiz-result { margin: 0 !important; font-weight: 600; color: var(--ink); }
.quiz-reset { padding: 9px 16px; border-radius: 99px; border: 1.5px solid var(--line-2); background: var(--surface); font-weight: 600; font-size: 14px; }
.quiz-reset:hover { border-color: var(--c); }

/* ---------------------------------------------------------------- lesson end */
.complete-box { display: flex; justify-content: center; margin: 3.2em 0 1.6em; }
.complete-btn {
  display: inline-flex; align-items: center; gap: 10px; padding: 13px 22px 13px 16px; border-radius: 99px;
  border: 1.5px solid var(--line-2); background: var(--surface); font-weight: 650; font-size: 15px; box-shadow: var(--shadow-1);
  transition: background .2s, border-color .2s, color .2s, transform .15s;
}
.complete-btn:hover { border-color: var(--good); transform: translateY(-1px); }
.cb-icon { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--line-2); color: transparent; }
.cb-icon .i { width: 14px; height: 14px; }
.complete-btn.is-done { background: var(--good); border-color: var(--good); color: #fff; }
.complete-btn.is-done .cb-icon { border-color: rgba(255, 255, 255, .6); color: #fff; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pager a {
  display: block; padding: 16px 18px 17px; border-radius: 15px; border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; box-shadow: var(--shadow-1); transition: border-color .15s, transform .15s, box-shadow .15s;
}
.pager a:hover { border-color: var(--c); transform: translateY(-2px); box-shadow: var(--shadow-2); }
.pager small { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 650 11.5px/1 var(--font-sans); letter-spacing: .08em; text-transform: uppercase; }
.pager small .i { width: 14px; height: 14px; }
.pager strong { display: block; margin-top: 8px; font: 600 18px/1.3 var(--font-serif); color: var(--ink); }
.pager .next { grid-column: 2; text-align: right; }
.pager .next small { justify-content: flex-end; }

/* ---------------------------------------------------------------- search */
dialog.search {
  width: min(680px, 100% - 24px); max-height: min(640px, 100vh - 80px); margin: 9vh auto auto; padding: 0;
  border: 1px solid var(--line-2); border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3); overflow: hidden;
}
dialog.search::backdrop { background: rgba(10, 10, 14, .42); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.search-box { display: flex; flex-direction: column; max-height: min(640px, 100vh - 80px); }
.search-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.search-row .i { width: 20px; height: 20px; color: var(--muted); }
.search-row input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; }
.search-row input::-webkit-search-cancel-button { display: none; }
.search-results { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.search-results li a {
  display: grid; grid-template-columns: auto 1fr; column-gap: 12px; padding: 10px 12px; border-radius: 11px;
  text-decoration: none; color: var(--ink);
}
.search-results .dot { grid-row: 1 / span 3; width: 9px; height: 9px; margin-top: 7px; border-radius: 50%; background: var(--c); }
.search-results .r-t { font-weight: 600; font-size: 15px; }
.search-results .r-s { font-size: 12.5px; color: var(--muted); }
.search-results .r-x { font-size: 13.5px; color: var(--ink-2); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-results mark { background: color-mix(in srgb, var(--c) 26%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-results li.sel a, .search-results li a:hover { background: var(--surface-2); }
.search-results li.sel a { box-shadow: inset 2px 0 0 var(--c); }
.search-results .empty { padding: 26px 14px; color: var(--muted); text-align: center; font-size: 14.5px; }
.search-results .group { padding: 10px 12px 4px; font: 650 11px/1 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
.search-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.search-foot span { display: inline-flex; align-items: center; gap: 4px; }
.search-count { margin-left: auto; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 9px; height: 46px; padding: 0 20px 0 17px; border-radius: 13px;
  font-weight: 650; font-size: 15px; text-decoration: none; border: 1.5px solid transparent; white-space: nowrap;
  transition: transform .15s, box-shadow .15s, border-color .15s, filter .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn-ink { background: var(--ink); color: var(--bg); box-shadow: var(--shadow-2); }
.btn-course { background: var(--c); color: #fff; box-shadow: 0 10px 26px -10px color-mix(in srgb, var(--c) 80%, transparent); }
.btn-course:hover { filter: brightness(1.07); }
:root[data-theme="dark"] .btn-course { color: #0B0C10; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-course { color: #0B0C10; } }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-2); box-shadow: var(--shadow-1); }
.btn-ghost:hover { border-color: var(--faint); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 26px 0 0; }

/* ---------------------------------------------------------------- home */
.hero { position: relative; overflow: hidden; padding: 64px 0 56px; border-bottom: 1px solid var(--line); }
.hero::before {
  content: ""; position: absolute; inset: -40% -10% auto auto; width: 70%; height: 140%; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--gold) 14%, transparent), transparent);
}
.hero-grid { position: relative; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr); gap: 56px; align-items: center; }
.hero .eyebrow { color: var(--gold); }
.hero h1 {
  margin: 0; font: 600 clamp(40px, 5.6vw, 66px)/1.02 var(--font-serif); letter-spacing: -.028em;
  font-variation-settings: "opsz" 144; text-wrap: balance;
}
.hero h1 em { font-style: italic; color: var(--gold); font-weight: 500; }
.hero .lede { margin-top: 22px; max-width: 34em; font-size: 19px; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 10px 34px; margin: 36px 0 0; }
.hero-stats div { display: flex; flex-direction: column-reverse; }
.hero-stats dd { margin: 0; font: 600 30px/1.1 var(--font-serif); color: var(--ink); }
.hero-stats dt { font-size: 13px; color: var(--muted); }
.shelf-wrap { position: relative; padding: 0 6px; }
.shelf { display: flex; align-items: flex-end; justify-content: center; gap: 9px; height: 390px; padding: 0 18px; }
.spine {
  position: relative; flex: 1 1 0; max-width: 78px; min-width: 0; height: var(--h); border-radius: 7px 7px 3px 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 16px 0 14px; color: #fff; text-decoration: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .28), rgba(0, 0, 0, 0) 16%, rgba(255, 255, 255, .16) 46%, rgba(0, 0, 0, 0) 74%, rgba(0, 0, 0, .3)),
    var(--c-spine);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 14px 22px -12px rgba(0, 0, 0, .45);
  transform-origin: bottom center; transition: transform .35s cubic-bezier(.2, .9, .25, 1.2), box-shadow .3s;
}
.spine:hover, .spine:focus-visible { transform: translateY(-18px) rotate(-1.5deg); box-shadow: 0 30px 40px -18px rgba(0, 0, 0, .5); }
.sp-code { font: 700 9.5px/1 var(--font-sans); letter-spacing: .12em; text-transform: uppercase; opacity: .85; writing-mode: vertical-rl; transform: rotate(180deg); }
.sp-title { flex: 1; display: flex; align-items: center; writing-mode: vertical-rl; transform: rotate(180deg); font: 600 19px/1 var(--font-serif); letter-spacing: .01em; white-space: nowrap; padding: 14px 0; text-shadow: 0 1px 1px rgba(0, 0, 0, .25); }
.sp-band { width: 100%; height: 22px; border-block: 2px solid rgba(255, 255, 255, .38); }
.shelf-board { height: 16px; margin: 0 -2px; border-radius: 4px; background: linear-gradient(#B98E5A, #8C653A); box-shadow: 0 14px 22px -10px rgba(60, 35, 10, .5); }
:root[data-theme="dark"] .shelf-board { background: linear-gradient(#5D4630, #3B2C1D); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .shelf-board { background: linear-gradient(#5D4630, #3B2C1D); } }
.continue { margin-top: 34px; }
.continue-card {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 18px; padding: 18px 22px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); text-decoration: none;
  border-left: 4px solid var(--c);
}
.continue-card .cc-label { font: 650 11.5px/1 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.continue-card strong { font: 600 21px/1.3 var(--font-serif); }
.continue-card small { color: var(--muted); }
.continue-card > .i { grid-row: 1 / span 3; grid-column: 2; width: 24px; height: 24px; color: var(--c); }
.section-head { margin: 64px 0 24px; }
.section-head h2 { margin: 0; font: 600 34px/1.15 var(--font-serif); letter-spacing: -.02em; }
.section-head p { margin: 8px 0 0; color: var(--muted); font-size: 16.5px; }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.course-card {
  position: relative; display: flex; flex-direction: column; padding: 22px 22px 20px; border-radius: 18px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1); overflow: hidden;
  transition: transform .2s, box-shadow .2s, border-color .2s;
}
.course-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--c); }
.course-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); border-color: var(--c-line); }
.cc-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.course-card h3 { margin: 14px 0 6px; font: 600 23px/1.2 var(--font-serif); letter-spacing: -.012em; }
.course-card p { margin: 0 0 18px; color: var(--ink-2); font-size: 15px; line-height: 1.6; flex: 1; }
.cc-progress small { display: block; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 80px; }
.feature { padding: 22px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); }
.feature > .i { width: 26px; height: 26px; padding: 0; color: var(--gold); }
.feature h3 { margin: 12px 0 4px; font: 650 17px/1.3 var(--font-sans); }
.feature p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }

/* ---------------------------------------------------------------- course page */
.course-hero { padding: 34px 0 44px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--c-soft), transparent 75%); }
.ch-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 48px; align-items: center; }
.course-hero h1 { margin: 16px 0 14px; font: 600 clamp(38px, 5vw, 58px)/1.04 var(--font-serif); letter-spacing: -.025em; font-variation-settings: "opsz" 144; text-wrap: balance; }
.course-hero .lede { max-width: 36em; }
.ring-card { position: relative; display: grid; justify-items: center; padding: 24px 22px 18px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); }
.ring { width: 130px; height: 130px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring-bg { stroke: var(--surface-3); }
.ring-fg { stroke: var(--c); stroke-linecap: round; transition: stroke-dasharray .8s cubic-bezier(.2, .8, .2, 1); }
.ring-label { position: absolute; top: 24px; height: 130px; display: grid; place-content: center; text-align: center; }
.ring-label b { font: 600 28px/1 var(--font-serif); }
.ring-label small { font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; width: 100%; margin: 18px 0 0; padding-top: 16px; border-top: 1px solid var(--line); }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dd { margin: 0; font: 600 22px/1.1 var(--font-serif); }
.stats dt { font-size: 12.5px; color: var(--muted); }
.syllabus { padding: 44px 0 90px; }
.learn-card { padding: 24px 26px; margin-bottom: 44px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); }
.learn-card h2, .syl-title { margin: 0 0 14px; font: 600 26px/1.2 var(--font-serif); letter-spacing: -.015em; }
.learn { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px 26px; }
.learn li { display: flex; gap: 10px; font-size: 15.5px; line-height: 1.5; color: var(--ink-2); }
.learn .i { width: 18px; height: 18px; margin-top: 2px; color: var(--good); }
.unit { margin-top: 26px; }
.unit h3 { display: flex; align-items: baseline; gap: 12px; margin: 0 0 10px; font: 650 18px/1.3 var(--font-sans); }
.unit h3 span { font: 650 11.5px/1 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--c-ink); }
.unit-lessons { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); overflow: hidden; }
.unit-lessons li + li { border-top: 1px solid var(--line); }
.unit-lessons a { display: grid; grid-template-columns: 34px 1fr auto 18px; align-items: center; gap: 14px; padding: 13px 18px; text-decoration: none; transition: background .12s; }
.unit-lessons a:hover { background: var(--surface-2); }
.unit-lessons .num { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--surface-2); font: 650 13px/1 var(--font-sans); color: var(--muted); }
.unit-lessons a.done .num { background: var(--good-soft); color: var(--good); }
.ul-text strong { display: block; font-weight: 600; font-size: 16px; color: var(--ink); }
.ul-text small { display: block; margin-top: 2px; font-size: 14px; line-height: 1.45; color: var(--muted); }
.ul-text small code { font: 500 .9em var(--font-mono); }
.ul-meta { font-size: 12.5px; color: var(--faint); white-space: nowrap; }
.unit-lessons .tick { margin: 0; }

/* ---------------------------------------------------------------- ebook view */
.book { width: min(780px, 100% - 40px); margin: 0 auto; padding: 50px 0 90px; }
.book-cover { padding: 30px 0 50px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.book-cover h1 { margin: 0 0 14px; font: 600 clamp(40px, 6vw, 64px)/1.03 var(--font-serif); letter-spacing: -.025em; }
.book-toc { margin-top: 36px; padding: 22px 26px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.book-toc h2 { margin: 0 0 10px; font: 600 20px/1.2 var(--font-serif); }
.book-toc ol { margin: 0; padding-left: 1.4em; columns: 2 260px; column-gap: 30px; }
.book-toc li { margin: 4px 0; break-inside: avoid; }
.book-toc a { text-decoration: none; color: var(--ink-2); }
.book-toc a:hover { color: var(--ink); text-decoration: underline; }
.chapter { padding: 40px 0 10px; border-top: 1px solid var(--line); }
.chapter:first-of-type { border-top: 0; }
.chapter > h1 { margin: 0 0 12px; font: 600 38px/1.1 var(--font-serif); letter-spacing: -.02em; }

/* ---------------------------------------------------------------- footer */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 46px 0 30px; margin-top: 30px; }
.page-lesson .site-footer, .page-pg .site-footer { margin-top: 0; }
.footer-inner { width: min(1180px, 100% - 40px); margin: 0 auto; display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 34px; }
.footer-brand p { margin: 14px 0 0; max-width: 30em; color: var(--muted); font-size: 14.5px; }
.site-footer nav { display: flex; flex-direction: column; gap: 7px; font-size: 14.5px; }
.site-footer nav a, .site-footer nav button { color: var(--ink-2); text-decoration: none; font-size: 14.5px; }
.site-footer nav a:hover, .site-footer nav button:hover { color: var(--ink); text-decoration: underline; }
.site-footer h4 { margin: 0 0 6px; font: 650 11.5px/1 var(--font-sans); letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
.footer-small { width: min(1180px, 100% - 40px); margin: 34px auto 0; padding-top: 18px; border-top: 1px solid var(--line); font-size: 13px; color: var(--faint); }

/* ---------------------------------------------------------------- playground */
.page-pg { --c: #3E7BFA; }
.pg { display: flex; flex-direction: column; height: calc(100vh - var(--top-h)); min-height: 560px; padding: 14px 18px 18px; max-width: 1640px; margin: 0 auto; }
.pg-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.pg-langs { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.pg-langs button { padding: 7px 16px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); }
.pg-langs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.pg-engine { font-size: 13px; color: var(--muted); }
.pg-actions { display: flex; gap: 8px; margin-left: auto; }
.pg-btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 13px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 550; font-size: 14px; }
.pg-btn .i { width: 15px; height: 15px; }
.pg-btn:hover { border-color: var(--faint); }
.pg-run { display: inline-flex; align-items: center; gap: 9px; height: 38px; padding: 0 12px 0 14px; border: 0; border-radius: 11px; background: #1F9D55; color: #fff; font-weight: 700; font-size: 14.5px; box-shadow: 0 8px 20px -10px rgba(31, 157, 85, .9); }
.pg-run:hover { filter: brightness(1.06); }
.pg-run:disabled { opacity: .7; cursor: progress; }
.pg-run .i { width: 15px; height: 15px; }
.pg-run kbd { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .25); color: #fff; }
.pg-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; }
.pg-editor, .pg-panel { display: flex; flex-direction: column; min-height: 0; border-radius: 15px; overflow: hidden; background: var(--code-bg); box-shadow: var(--shadow-2), inset 0 0 0 1px rgba(255, 255, 255, .05); }
.pg-file { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--code-line); font: 500 12.5px/1 var(--font-mono); color: #CDD2DD; }
.pg-hint { margin-left: auto; font-family: var(--font-sans); color: var(--code-muted); }
.pg-editor .CodeMirror { flex: 1; height: auto; min-height: 0; background: transparent; color: var(--code-ink); font: 450 14.5px/1.65 var(--font-mono); }
.pg-side { display: grid; grid-template-rows: minmax(120px, .45fr) minmax(0, 1fr); gap: 14px; min-height: 0; }
.pg-panel label, .pg-out-head { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--code-line); font: 650 11.5px/1 var(--font-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--code-muted); }
.pg-panel label small { text-transform: none; letter-spacing: 0; font-weight: 500; }
.pg-panel textarea { flex: 1; resize: none; border: 0; outline: 0; padding: 12px 16px; background: transparent; color: var(--code-ink); font: 450 14px/1.6 var(--font-mono); }
.pg-out pre { flex: 1; margin: 0; padding: 12px 16px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 450 14px/1.6 var(--font-mono); color: #D9DDE6; background: var(--code-bg-2); }
.pg-out pre .err { color: #FF9C94; }
.pg-out pre .meta-line { color: var(--code-muted); }
.pg-out pre .in { color: #8BE3B0; font-weight: 600; }
.pg-status { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }
.pg-status.ok { color: #7EE2A8; } .pg-status.bad { color: #FF9C94; } .pg-status.busy { color: #FFCB6B; }
/* CodeMirror theme (scoped so it beats codemirror.css, which loads later) */
.pg-editor .CodeMirror-gutters { background: transparent; border-right: 1px solid var(--code-line); }
.pg-editor .CodeMirror-linenumber { color: #4E5567; }
.pg-editor .CodeMirror-cursor { border-left: 2px solid #FFCB6B; }
.pg-editor .CodeMirror-selected, .pg-editor .CodeMirror-focused .CodeMirror-selected { background: rgba(130, 170, 255, .22) !important; }
.pg-editor .CodeMirror-activeline-background { background: rgba(255, 255, 255, .04) !important; }
.pg-editor .CodeMirror-activeline .CodeMirror-gutter-elt { color: #9AA3B5; }
.pg-editor .CodeMirror-matchingbracket { color: #fff !important; background: rgba(255, 203, 107, .25); }
.pg-editor .cm-s-default .cm-keyword { color: #C99BFF; } .pg-editor .cm-s-default .cm-type, .pg-editor .cm-s-default .cm-builtin, .pg-editor .cm-s-default .cm-variable-3 { color: #7CC7FF; }
.pg-editor .cm-s-default .cm-def { color: #82AAFF; } .pg-editor .cm-s-default .cm-variable { color: #E2E5EC; } .pg-editor .cm-s-default .cm-variable-2 { color: #FFCB6B; }
.pg-editor .cm-s-default .cm-string, .pg-editor .cm-s-default .cm-string-2 { color: #B9E67F; } .pg-editor .cm-s-default .cm-number, .pg-editor .cm-s-default .cm-atom { color: #FF9E64; }
.pg-editor .cm-s-default .cm-comment { color: #6E768A; font-style: italic; } .pg-editor .cm-s-default .cm-meta { color: #FF7FAF; }
.pg-editor .cm-s-default .cm-operator { color: #89DDFF; } .pg-editor .cm-s-default .cm-property { color: #E2E5EC; } .pg-editor .cm-s-default .cm-bracket { color: #C3C8D4; }
.pg-editor .cm-s-default .cm-qualifier, .pg-editor .cm-s-default .cm-tag { color: #F07178; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1260px) {
  .shell { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 960px) {
  :root { --top-h: 103px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-grid; }
  .page-home .nav-toggle, .page-course .nav-toggle, .page-pg .nav-toggle, .page-book .nav-toggle { display: none; }
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: min(330px, 88vw); height: 100%;
    background: var(--surface); border-right: 1px solid var(--line); box-shadow: var(--shadow-3);
    transform: translateX(-104%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); visibility: hidden;
  }
  .side-top { display: flex; justify-content: flex-end; margin: -8px -2px 4px; }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(10, 10, 14, .45); opacity: 0; pointer-events: none; transition: opacity .25s; }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .hero-grid { grid-template-columns: 1fr; gap: 40px; }
  .shelf { height: 300px; }
  .ch-grid { grid-template-columns: 1fr; }
  .ring-card { grid-template-columns: auto 1fr; justify-items: start; align-items: center; column-gap: 22px; }
  .ring-card .ring { width: 104px; height: 104px; }
  .ring-label { top: 24px; left: 22px; width: 104px; height: 104px; }
  .ring-card .stats { margin: 0; padding: 0 0 0 22px; border-top: 0; border-left: 1px solid var(--line); }
  .footer-inner { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
  .pg { height: auto; }
  .pg-grid { grid-template-columns: 1fr; }
  .pg-editor { min-height: 380px; }
  .pg-side { grid-template-rows: 150px 300px; }
}
@media (max-width: 640px) {
  .topbar-row { padding: 0 12px; gap: 8px; }
  .brand span { display: none; }
  .search-trigger { width: auto; flex: 1; }
  .search-trigger kbd { display: none; }
  .top-run span { display: none; }
  .top-run { padding: 0 12px; }
  .main { padding: 22px 16px 70px; }
  .prose { font-size: 16.5px; }
  .prose h2 { font-size: 25px; }
  .prose .anchor { display: none; }
  .lede { font-size: 17.5px; }
  .code { margin-inline: -16px; border-radius: 0; }
  .callout .code, .q .code, .cols .code { margin-inline: 0; border-radius: 12px; }
  .code pre { font-size: 13px; padding: 14px 16px; }
  .diagram { margin-inline: -6px; padding: 16px 10px 12px; }
  .quiz { margin-inline: -6px; }
  .q-opts, .q-why { padding-left: 0; margin-left: 0; }
  .quiz-sub { margin-left: 0 !important; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .hero { padding: 40px 0 36px; }
  .hero .lede { font-size: 17px; }
  .hero-stats { gap: 10px 24px; }
  .hero-stats dd { font-size: 25px; }
  .shelf { height: 250px; gap: 6px; padding: 0 6px; }
  .spine { padding: 12px 0 10px; }
  .sp-title { font-size: 15px; }
  .course-grid, .feature-grid { grid-template-columns: 1fr; }
  .section-head h2 { font-size: 28px; }
  .ring-card { grid-template-columns: 1fr; justify-items: center; }
  .ring-label { left: 50%; transform: translateX(-50%); }
  .ring-card .stats { padding: 14px 0 0; border-left: 0; border-top: 1px solid var(--line); margin-top: 14px; }
  .unit-lessons a { grid-template-columns: 30px 1fr 18px; padding: 12px 14px; gap: 12px; }
  .ul-meta { display: none; }
  .footer-inner { grid-template-columns: 1fr; }
  .pg { padding: 10px 10px 14px; }
  .pg-actions { margin-left: 0; width: 100%; }
  .pg-run { margin-left: auto; }
  .pg-btn span { display: none; }
  .pg-run kbd, .pg-hint { display: none; }
}

/* ---------------------------------------------------------------- print / PDF */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f4f4f4; --ink: #000; --ink-2: #222; --muted: #555; --line: #ddd; color-scheme: light; }
  .topbar, .site-footer, .sidebar, .toc, .pager, .complete-box, .no-print, .code-foot, .code-copy, .quiz, .widget, .search, .scrim, .skip { display: none !important; }
  body { background: #fff; font-size: 11.5pt; }
  .main, .book { padding: 0; width: auto; }
  .lesson { max-width: none; }
  .chapter { break-before: page; border: 0; }
  .book-cover { break-after: page; border: 0; }
  .code, .diagram, .callout, .table-wrap { break-inside: avoid; box-shadow: none; }
  .code { border: 1px solid #ccc; }
  .prose a { text-decoration: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
.dg .small { font-size: 13.5px; }

[data-c="c"]{--c:#2F6AE0;--c-spine:#2F6AE0}
[data-c="dsa"]{--c:#0B8A7C;--c-spine:#0B8A7C}
[data-c="cpp"]{--c:#7048E0;--c-spine:#7048E0}
[data-c="python"]{--c:#B7740C;--c-spine:#B7740C}
[data-c="discrete"]{--c:#CC3366;--c-spine:#CC3366}
[data-c="daa"]{--c:#DD5A12;--c-spine:#DD5A12}
[data-c="foundations"]{--c:#2E8B47;--c-spine:#2E8B47}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]) [data-c="c"]{--c:#7DA6FF}:root:not([data-theme="light"]) [data-c="dsa"]{--c:#3FD0BC}:root:not([data-theme="light"]) [data-c="cpp"]{--c:#A78BFF}:root:not([data-theme="light"]) [data-c="python"]{--c:#F2B545}:root:not([data-theme="light"]) [data-c="discrete"]{--c:#FF7FA6}:root:not([data-theme="light"]) [data-c="daa"]{--c:#FF9555}:root:not([data-theme="light"]) [data-c="foundations"]{--c:#62D287}}
:root[data-theme="dark"] [data-c="c"]{--c:#7DA6FF}
:root[data-theme="dark"] [data-c="dsa"]{--c:#3FD0BC}
:root[data-theme="dark"] [data-c="cpp"]{--c:#A78BFF}
:root[data-theme="dark"] [data-c="python"]{--c:#F2B545}
:root[data-theme="dark"] [data-c="discrete"]{--c:#FF7FA6}
:root[data-theme="dark"] [data-c="daa"]{--c:#FF9555}
:root[data-theme="dark"] [data-c="foundations"]{--c:#62D287}
