/* ============ Tokens ============ */
:root {
  --bg: #f7f4ee;
  --bg-2: #efeae0;
  --surface: #fffdf9;
  --ink: #1b1a17;
  --ink-2: #4a463f;
  --muted: #807a6f;
  --line: #e3ddd1;
  --line-2: #d4ccbd;
  --accent: #f5a524;
  --accent-ink: #1a1206;
  --accent-text: #a8650a;
  --code-bg: #1d1b18;
  --code-ink: #ece6da;
  --diagram-bg: #f1ece2;
  --shadow: 0 1px 2px rgba(40, 30, 10, .05), 0 8px 30px -12px rgba(40, 30, 10, .18);
  --radius: 18px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --amber: #e8961a;  --amber-soft: #fbecd2;
  --teal: #0e9488;   --teal-soft: #d6f1ee;
  --violet: #7c5cdb; --violet-soft: #e9e3fb;
  --rose: #e0496b;   --rose-soft: #fbe0e6;
  --lime: #5f9a1c;   --lime-soft: #e6f2d3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0e0c; --bg-2: #161512; --surface: #1a1916; --ink: #f1ece3; --ink-2: #c6bfb2; --muted: #8d867a;
    --line: #2a2823; --line-2: #3a362f; --accent-text: #f5b649; --code-bg: #12110f; --code-ink: #ece6da; --diagram-bg: #15140f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 40px -16px rgba(0,0,0,.6);
    --amber: #f5a524; --amber-soft: #33260f; --teal: #2dd4bf; --teal-soft: #0f2c29; --violet: #a78bfa; --violet-soft: #241c3d;
    --rose: #fb7194; --rose-soft: #3a1621; --lime: #a3e635; --lime-soft: #1f2c0e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0e0c; --bg-2: #161512; --surface: #1a1916; --ink: #f1ece3; --ink-2: #c6bfb2; --muted: #8d867a;
  --line: #2a2823; --line-2: #3a362f; --accent-text: #f5b649; --code-bg: #12110f; --code-ink: #ece6da; --diagram-bg: #15140f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 40px -16px rgba(0,0,0,.6);
  --amber: #f5a524; --amber-soft: #33260f; --teal: #2dd4bf; --teal-soft: #0f2c29; --violet: #a78bfa; --violet-soft: #241c3d;
  --rose: #fb7194; --rose-soft: #3a1621; --lime: #a3e635; --lime-soft: #1f2c0e;
  color-scheme: dark;
}
[data-color="amber"]  { --c: var(--amber);  --c-soft: var(--amber-soft); }
[data-color="teal"]   { --c: var(--teal);   --c-soft: var(--teal-soft); }
[data-color="violet"] { --c: var(--violet); --c-soft: var(--violet-soft); }
[data-color="rose"]   { --c: var(--rose);   --c-soft: var(--rose-soft); }
[data-color="lime"]   { --c: var(--lime);   --c-soft: var(--lime-soft); }

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 88px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: hidden;
}
body::before { /* paper grain */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.8' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
main, .topbar, .footer { position: relative; z-index: 1; }
a { color: inherit; }
::selection { background: var(--accent); color: var(--accent-ink); }
kbd {
  font: 500 11px/1 var(--mono); padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--muted);
}
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 24px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font: 600 17px/1.1 var(--serif); letter-spacing: -.01em; }
.brand-sub { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.top-nav { display: flex; gap: 4px; margin-left: auto; }
.top-nav a { text-decoration: none; font-size: 14px; color: var(--ink-2); padding: 6px 12px; border-radius: 999px; }
.top-nav a:hover { background: var(--bg-2); color: var(--ink); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; min-width: 38px; padding: 0 10px; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 12px; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-2); }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: inline-flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: inline-flex; }
}
@media (max-width: 720px) {
  .top-nav { display: none; }
  .top-actions { margin-left: auto; }
  .search-open kbd { display: none; }
  .brand-sub { display: none; }
}

/* ============ Buttons, chips ============ */
.btn {
  display: inline-flex; align-items: center; gap: 10px; padding: 13px 20px; border-radius: 14px; font-weight: 600; font-size: 15px;
  text-decoration: none; transition: transform .15s ease, box-shadow .15s ease, background .15s;
}
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-ghost { border: 1px solid var(--line-2); color: var(--ink); }
.btn-ghost:hover { background: var(--bg-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0; }
.chips li { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--bg-2); color: var(--ink-2); border: 1px solid var(--line); }
.pill { font: 500 11px/1 var(--mono); padding: 5px 8px; border-radius: 999px; background: var(--bg-2); color: var(--muted); white-space: nowrap; }
.pill-live { background: var(--c, var(--accent)); color: #fff; }
:root[data-theme="dark"] .pill-live { color: #0f0e0c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill-live { color: #0f0e0c; } }
.week-num { font: 600 12px/1 var(--mono); letter-spacing: .06em; color: var(--c, var(--accent-text)); text-transform: uppercase; }
.kicker { font: 600 12px/1 var(--mono); text-transform: uppercase; letter-spacing: .14em; color: var(--accent-text); margin: 0 0 14px; }

/* ============ Hero ============ */
.hero {
  position: relative; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, .9fr); gap: 48px; align-items: center;
  max-width: 1240px; margin: 0 auto; padding: clamp(48px, 9vw, 110px) clamp(16px, 4vw, 40px) clamp(40px, 6vw, 80px);
}
.hero-grid {
  position: absolute; inset: 0; z-index: -1; opacity: .6;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(ellipse 70% 60% at 30% 40%, #000 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 30% 40%, #000 20%, transparent 75%);
}
.eyebrow { display: inline-flex; align-items: center; gap: 10px; font: 500 13px/1 var(--mono); color: var(--ink-2); margin: 0 0 28px;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 4px color-mix(in srgb, #22c55e 22%, transparent); animation: pulse 2.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, #22c55e 0%, transparent); } }
.hero h1 {
  font: 400 clamp(42px, 7vw, 86px)/1 var(--serif); letter-spacing: -.035em; margin: 0 0 28px; font-variation-settings: "opsz" 144;
}
.hero h1 em { font-style: italic; font-weight: 300; color: var(--accent-text); }
.lede { font-size: clamp(17px, 1.6vw, 19px); color: var(--ink-2); max-width: 600px; margin: 0 0 32px; }
.lede a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 2px; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 44px; }
.stats { display: flex; gap: clamp(24px, 4vw, 48px); margin: 0 0 18px; }
.stats dt { font-size: 12.5px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font: 500 34px/1 var(--serif); }
.stats dd span { font-size: 18px; color: var(--muted); }

.token-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 26px; box-shadow: var(--shadow);
  transform: rotate(1.5deg); transition: transform .4s ease;
}
.token-card:hover { transform: rotate(0); }
.token-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 16px; }
.blink { width: 9px; height: 16px; background: var(--accent); animation: blink 1.1s steps(1) infinite; border-radius: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.token-prompt { font: 400 26px/1.25 var(--serif); margin: 0 0 22px; letter-spacing: -.01em; }
.slot { color: var(--accent-text); border-bottom: 2px dashed var(--accent); }
.probs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.probs li { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 12px; font-size: 14px; }
.probs .bar { height: 10px; border-radius: 9px; background: var(--bg-2); overflow: hidden; }
.probs .bar span { display: block; height: 100%; width: 0; border-radius: 9px; background: var(--accent);
  animation: grow 1.1s cubic-bezier(.2,.8,.2,1) forwards; animation-delay: calc(var(--i) * 120ms + 200ms); }
.probs li:not(:first-child) .bar span { background: color-mix(in srgb, var(--accent) 45%, var(--line-2)); }
@keyframes grow { to { width: var(--w); } }
.pct { text-align: right; color: var(--muted); }
.token-foot { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line-2); font-size: 12px; }
@media (max-width: 920px) {
  .hero { grid-template-columns: 1fr; gap: 40px; }
  .token-card { transform: none; max-width: 460px; }
}
@media (max-width: 420px) { .btn { width: 100%; justify-content: center; } .stats dd { font-size: 28px; } }

/* ============ Blocks ============ */
.block { max-width: 1240px; margin: 0 auto; padding: clamp(40px, 6vw, 80px) clamp(16px, 4vw, 40px); }
.block-head { margin-bottom: 36px; max-width: 640px; }
.block-head h2 { font: 400 clamp(32px, 4.5vw, 48px)/1.05 var(--serif); letter-spacing: -.025em; margin: 0 0 10px; }
.block-head p.muted { margin: 0; }

/* Note cards */
.note-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 20px; }
.note-card {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 28px; border-radius: var(--radius); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); overflow: hidden; transition: transform .2s ease, box-shadow .2s, border-color .2s;
}
.note-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--c); }
.note-card::after { content: ""; position: absolute; right: -60px; top: -60px; width: 180px; height: 180px; border-radius: 50%; background: var(--c-soft); z-index: 0; transition: transform .4s; }
.note-card > * { position: relative; z-index: 1; }
.note-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--line-2); }
.note-card:hover::after { transform: scale(1.25); }
.note-card-top { display: flex; justify-content: space-between; font-size: 13px; }
.note-card h3 { font: 500 30px/1.1 var(--serif); letter-spacing: -.02em; margin: 6px 0 0; }
.note-sub { margin: 0; color: var(--ink-2); font-style: italic; font-family: var(--serif); font-size: 17px; }
.note-sum { margin: 4px 0 0; color: var(--ink-2); font-size: 14.5px; }
.note-card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 18px; font-size: 13px; color: var(--muted); }
.go { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--bg); transition: transform .2s; }
.note-card:hover .go { transform: translateX(3px); }

/* Section block on home */
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 20px 40px; margin-bottom: 36px; }
.section-head .block-head { margin-bottom: 0; }
.section-head .kicker { color: var(--c); }
.section-head h2 { font-size: clamp(40px, 6vw, 64px); }
.section-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.text-link { font-size: 14px; color: var(--muted); text-decoration: none; }
.text-link:hover { color: var(--ink); }
@media (max-width: 640px) { .section-actions { align-items: flex-start; } }

/* Author */
.avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid var(--accent); padding: 2px; background: var(--surface); flex: none; }
.avatar-sm { width: 40px; height: 40px; border-width: 1.5px; padding: 1px; }
.author { display: inline-flex; align-items: center; gap: 14px; padding: 10px 10px 10px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); max-width: 100%; }
.author-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.author-text strong { font: 600 16px/1.2 var(--serif); }
.author-text span { font-size: 13px; color: var(--muted); }
.author-link { display: inline-flex; align-items: center; gap: 8px; margin-left: 8px; padding: 9px 14px; border-radius: 999px; background: #0a66c2; color: #fff; text-decoration: none; font-size: 13.5px; font-weight: 600; flex: none; }
.author-link:hover { background: #004182; }
@media (max-width: 420px) { .author-link span { display: none; } .author-link { padding: 9px; } }

/* Section page list */
.block-tight { padding-top: 8px; }
.note-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.note-list a {
  display: grid; grid-template-columns: 96px 1fr auto 36px; gap: 20px; align-items: center; padding: 22px 8px;
  border-bottom: 1px solid var(--line); text-decoration: none; transition: background .15s, padding .2s;
}
.note-list a:hover { background: var(--c-soft); padding-left: 16px; }
.nl-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nl-main strong { font: 500 24px/1.2 var(--serif); letter-spacing: -.015em; }
.nl-main .muted { font-family: var(--serif); font-style: italic; }
.nl-meta { font-size: 13px; white-space: nowrap; }
.note-list .go { width: 36px; height: 36px; }
@media (max-width: 640px) {
  .note-list a { grid-template-columns: 1fr 36px; gap: 6px 14px; }
  .nl-label { grid-column: 1; } .nl-main { grid-column: 1; } .nl-meta { grid-column: 1; }
  .note-list .go { grid-column: 2; grid-row: 1 / span 3; }
}
.page-hero .back { display: inline-flex; margin-bottom: 28px; }
.page-hero .btn { margin-top: 4px; }
.page-hero[data-color] .kicker { color: var(--c); }
.footer-meta a { text-decoration: none; }
.footer-meta a:hover { color: var(--ink); }

/* How */
.how-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 20px; }
.how-grid > div { padding: 26px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.how-n { font: 400 40px/1 var(--serif); color: var(--accent-text); font-style: italic; }
.how-grid h4 { margin: 14px 0 6px; font-size: 17px; }
.how-grid p { margin: 0; color: var(--ink-2); font-size: 15px; }

/* ============ Note page ============ */
.read-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 40; }
.read-progress span { display: block; height: 100%; width: 0; background: var(--accent); }
.note-hero { max-width: 1240px; margin: 0 auto; padding: clamp(32px, 6vw, 72px) clamp(16px, 4vw, 40px) 36px; border-bottom: 1px solid var(--line); }
.back { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-size: 14px; color: var(--muted); margin-bottom: 32px; }
.back:hover { color: var(--ink); }
.note-meta { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 13.5px; margin-bottom: 14px; }
.note-hero h1 { font: 400 clamp(44px, 7.5vw, 92px)/.98 var(--serif); letter-spacing: -.04em; margin: 0 0 14px; font-variation-settings: "opsz" 144; }
.note-subtitle { font: italic 300 clamp(20px, 2.4vw, 28px)/1.3 var(--serif); color: var(--ink-2); margin: 0 0 24px; }
.note-facts { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 14px; color: var(--muted); margin-bottom: 18px; }
.note-facts span + span::before { content: "·"; margin-right: 20px; color: var(--line-2); }

.note-layout {
  max-width: 1240px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px);
  display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: clamp(32px, 5vw, 72px);
}
.toc { position: relative; }
.toc nav { position: sticky; top: 88px; max-height: calc(100vh - 110px); overflow: auto; padding: 40px 0 40px; scrollbar-width: thin; }
.toc-title { font: 600 11.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 14px; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc li a { display: block; padding: 5px 0 5px 16px; margin-left: -1px; border-left: 2px solid transparent; text-decoration: none; font-size: 13.5px; color: var(--muted); line-height: 1.4; white-space: pre-wrap; }
.toc li.toc-3 a { padding-left: 30px; font-size: 12.5px; }
.toc li a:hover { color: var(--ink); }
.toc li a.active { color: var(--ink); border-left-color: var(--c); font-weight: 500; }
.toc-toggle { display: none; }
@media (max-width: 1020px) {
  .note-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc { position: sticky; top: 63px; z-index: 20; margin: 0 calc(-1 * clamp(16px, 4vw, 40px)); padding: 0 clamp(16px, 4vw, 40px);
    background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
  .toc-toggle { display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 0; background: none; border: 0; color: var(--ink-2); font: 500 14px var(--sans); cursor: pointer; }
  .toc nav { display: none; position: static; max-height: 60vh; padding: 0 0 16px; }
  .toc.open nav { display: block; }
  .toc-title { display: none; }
}

/* ============ Prose ============ */
.prose { min-width: 0; padding: 40px 0 40px; max-width: 760px; font-size: 17px; line-height: 1.75; color: var(--ink-2); }
.prose > *:first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.15em; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 3px; }
.prose li { margin: .3em 0; }
.prose li::marker { color: var(--c, var(--accent)); }
.prose ol > li::marker { font: 600 14px var(--mono); }
.prose h2, .prose h3, .prose h4 { position: relative; color: var(--ink); scroll-margin-top: 100px; }
.prose h2 { font: 400 clamp(30px, 3.6vw, 40px)/1.12 var(--serif); letter-spacing: -.025em; margin: 2.2em 0 .7em; }
.prose h3 { font: 600 21px/1.3 var(--sans); letter-spacing: -.01em; margin: 2em 0 .6em; }
.prose h2.sec { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; padding-top: 1.4em; border-top: 1px solid var(--line); }
.sec-num {
  font: 500 15px/1 var(--mono); color: var(--c); background: var(--c-soft); padding: 7px 10px; border-radius: 10px; transform: translateY(-6px);
}
.sec-title { flex: 1 1 300px; }
.dur { font: 500 12px/1 var(--mono); color: var(--muted); border: 1px solid var(--line-2); padding: 5px 9px; border-radius: 999px; letter-spacing: 0; vertical-align: middle; margin-left: 10px; white-space: nowrap; }
.sec .dur { margin-left: 0; transform: translateY(-6px); }
.anchor { position: absolute; left: -1.1em; opacity: 0; text-decoration: none; color: var(--muted); font-weight: 400; font-family: var(--sans); transition: opacity .15s; }
.prose h2.sec .anchor { top: 1.45em; }
h2:hover .anchor, h3:hover .anchor { opacity: 1; }
@media (max-width: 720px) { .anchor { display: none; } .prose { font-size: 16.5px; } }

.prose code:not(pre code) {
  font: 500 .86em var(--mono); background: var(--bg-2); border: 1px solid var(--line); padding: .12em .4em; border-radius: 6px; color: var(--ink); white-space: nowrap;
}
.prose blockquote {
  margin: 1.6em 0; padding: 22px 26px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
  font: 400 clamp(19px, 2vw, 22px)/1.5 var(--serif); color: var(--ink);
}
.prose blockquote p { margin: 0; }
.prose blockquote p + p { margin-top: .6em; }

/* Code */
.code { margin: 1.6em 0; border-radius: 16px; overflow: hidden; background: var(--code-bg); border: 1px solid color-mix(in srgb, var(--code-bg) 70%, var(--line)); box-shadow: var(--shadow); }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px 10px 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.code-lang { font: 500 12px/1 var(--mono); color: #a8a091; text-transform: lowercase; display: flex; gap: 8px; align-items: center; }
.code-lang::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.copy { font: 500 12px/1 var(--sans); color: #c9c1b3; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.copy:hover { background: rgba(255,255,255,.12); color: #fff; }
.copy.done { color: #86efac; }
.code pre { margin: 0; padding: 18px 20px; overflow-x: auto; font: 13.5px/1.7 var(--mono); color: var(--code-ink); tab-size: 4; }
.diagram { margin: 1.6em 0; }
.diagram pre {
  margin: 0; padding: 20px 22px; overflow-x: auto; border-radius: 16px; font: 13.5px/1.65 var(--mono); color: var(--ink);
  background: var(--diagram-bg); border: 1px dashed var(--line-2);
  background-image: radial-gradient(var(--line-2) 1px, transparent 1px); background-size: 16px 16px;
}
.diagram pre code { background: none; border: 0; padding: 0; white-space: pre; }

/* hljs theme (warm) */
.hljs-keyword, .hljs-built_in, .hljs-selector-tag { color: #f59e6b; }
.hljs-string, .hljs-attr + .hljs-string { color: #b5d67a; }
.hljs-number, .hljs-literal { color: #f5c46b; }
.hljs-comment { color: #7d776c; font-style: italic; }
.hljs-title, .hljs-title.function_ { color: #8fc7f4; }
.hljs-params, .hljs-variable { color: #ece6da; }
.hljs-meta, .hljs-attr, .hljs-property { color: #c7a4f5; }
.hljs-subst { color: #ece6da; }

/* Tables */
.table-wrap { margin: 1.6em 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.55; }
.prose th { text-align: left; font: 600 12px/1.3 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--bg-2); padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.prose td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose tr:last-child td { border-bottom: 0; }
.prose tbody tr:hover td { background: color-mix(in srgb, var(--c, var(--accent)) 5%, transparent); }
.prose td:first-child { color: var(--ink); }

/* Callouts */
.callout { margin: 1.8em 0; padding: 18px 22px 18px 20px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); position: relative; overflow: hidden; }
.callout::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.callout-label { font: 600 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .12em; margin-bottom: 8px; }
.callout-body p { margin: 0; }
.callout-body p + p { margin-top: .5em; }
.callout-next { background: var(--c-soft); border-color: color-mix(in srgb, var(--c) 30%, transparent); }
.callout-next::before { background: var(--c); }
.callout-next .callout-label { color: var(--c); }
.callout-next .callout-label::after { content: " →"; }
.callout-analogy::before { background: var(--violet); }
.callout-analogy .callout-label { color: var(--violet); }
.callout-analogy .callout-body { font-family: var(--serif); font-size: 18px; font-style: italic; }
.callout-warn::before { background: var(--rose); }
.callout-warn .callout-label { color: var(--rose); }
.callout-tip::before { background: var(--teal); }
.callout-tip .callout-label { color: var(--teal); }

.divider { display: flex; justify-content: center; gap: 10px; margin: 3em 0; }
.divider span { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); }
.divider + h2.sec { border-top: 0; padding-top: 0; }

/* Pager */
.pager { max-width: 1240px; margin: 20px auto 0; padding: 40px clamp(16px, 4vw, 40px) 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; border-top: 1px solid var(--line); }
.pager a, .pager-soon { display: flex; flex-direction: column; gap: 6px; padding: 22px; border-radius: 16px; border: 1px solid var(--line); text-decoration: none; background: var(--surface); }
.pager a:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.pager span { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.pager strong { font: 500 20px/1.25 var(--serif); }
.pager-next, .pager-soon { text-align: right; align-items: flex-end; }
.pager-soon { border-style: dashed; background: transparent; }
@media (max-width: 640px) { .pager { grid-template-columns: 1fr; } .pager > span:empty { display: none; } }

/* ============ Glossary & 404 ============ */
.page-hero { max-width: 1240px; margin: 0 auto; padding: clamp(48px, 8vw, 96px) clamp(16px, 4vw, 40px) 32px; }
.page-hero h1 { font: 400 clamp(48px, 8vw, 96px)/1 var(--serif); letter-spacing: -.04em; margin: 0 0 18px; }
.gloss-filter { width: 100%; max-width: 480px; padding: 14px 18px; border-radius: 14px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font: 16px var(--sans); }
.letters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 22px; }
.letters a { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); text-decoration: none; font: 500 14px var(--mono); background: var(--surface); }
.letters a:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.gloss { max-width: 1240px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 60px; }
.gloss-group { display: grid; grid-template-columns: 80px 1fr; gap: 20px; padding: 26px 0; border-top: 1px solid var(--line); }
.gloss-group h2 { font: 400 56px/1 var(--serif); color: var(--accent-text); margin: 0; }
.gloss-group dl { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 12px; }
.gloss-item { padding: 18px 20px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.gloss-item dt { font-weight: 600; margin-bottom: 4px; }
.gloss-item dd { margin: 0; color: var(--ink-2); font-size: 15px; }
.gloss-item code { font: .88em var(--mono); background: var(--bg-2); padding: .1em .35em; border-radius: 5px; }
.gloss-src { display: block; margin-top: 10px; font: 500 12px var(--mono); color: var(--muted); text-decoration: none; }
.gloss-src:hover { color: var(--accent-text); }
@media (max-width: 640px) { .gloss-group { grid-template-columns: 1fr; gap: 10px; } .gloss-group h2 { font-size: 40px; } }
.nf { min-height: 60vh; }

/* ============ Search ============ */
.search { position: fixed; inset: 0; z-index: 60; display: grid; place-items: start center; padding: 10vh 16px 16px; }
.search[hidden] { display: none; }
.search-backdrop { position: absolute; inset: 0; background: rgba(15, 12, 8, .45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.search-panel { position: relative; width: min(640px, 100%); max-height: 75vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line-2); border-radius: 20px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); overflow: hidden; }
.search-field { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); color: var(--muted); }
.search-field input { flex: 1; border: 0; outline: 0; background: none; font: 17px var(--sans); color: var(--ink); min-width: 0; }
.search-field kbd { cursor: pointer; }
.search-results { list-style: none; margin: 0; padding: 8px; overflow: auto; }
.search-results li a { display: block; padding: 12px 14px; border-radius: 12px; text-decoration: none; }
.search-results li a:hover, .search-results li a.sel { background: var(--bg-2); }
.sr-week { font: 600 11px var(--mono); color: var(--accent-text); text-transform: uppercase; letter-spacing: .08em; }
.sr-title { display: block; font-weight: 600; color: var(--ink); margin: 2px 0; }
.sr-snip { display: block; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.sr-snip mark { background: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--ink); border-radius: 3px; padding: 0 2px; }
.search-empty { padding: 28px; text-align: center; color: var(--muted); font-size: 14px; }

/* ============ Footer ============ */
.footer { border-top: 1px solid var(--line); margin-top: 40px; }
.footer-inner { max-width: 1240px; margin: 0 auto; padding: 32px clamp(16px, 4vw, 40px); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 18px; font-size: 14px; color: var(--muted); }
.footer-brand { display: flex; gap: 12px; align-items: center; }
.footer-brand strong { color: var(--ink); font-family: var(--serif); font-weight: 600; font-size: 16px; }
.footer a { color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .probs .bar span { width: var(--w); }
  html { scroll-behavior: auto; }
}
@media print {
  .topbar, .toc, .pager, .footer, .read-progress, .copy { display: none !important; }
  .note-layout { display: block; }
  body { background: #fff; }
}
