/* AI Harness Academy — editorial theme modelled on subhdb.co.in
   (warm-amber accent, Fraunces display, Inter text, JetBrains Mono labels). */

:root {
  --bg: #08090b;
  --bg-elevated: #0e1013;
  --bg-sunken: #0b0c0e;
  --fg: #ece8e1;
  --fg-muted: #a7a39b;
  --fg-faint: #6e7378;
  --border: #ffffff1a;
  --border-strong: #ffffff38;
  --accent: #d1934f;
  --accent-hover: #e2b183;
  --accent-soft: #d1934f24;
  --accent-contrast: #0b0c0e;
  --good: #7bc08a;
  --warn: #e0b04f;
  --bad: #e07a6b;
  --info: #7aa7e0;
  --shadow: 0 20px 50px -24px #000c;
  --font-display: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --radius: 4px;
  --header-h: 64px;
  --maxw: 1200px;
  color-scheme: dark;
}

[data-theme='light'] {
  --bg: #f4f1ec;
  --bg-elevated: #faf8f5;
  --bg-sunken: #ece8e1;
  --fg: #16181b;
  --fg-muted: #4c4f54;
  --fg-faint: #7a7d82;
  --border: #0b0d101f;
  --border-strong: #0b0d1047;
  --accent: #9c5a1d;
  --accent-hover: #b9762f;
  --accent-soft: #9c5a1d1a;
  --accent-contrast: #fffdf9;
  --good: #2f7a42;
  --warn: #946b0a;
  --bad: #b13c2c;
  --info: #2f5fa8;
  --shadow: 0 20px 50px -28px #0b0d1055;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 16px; line-height: 1.65;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background-color .25s ease, color .25s ease;
}
img, svg, canvas { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
::selection { background: var(--accent); color: var(--accent-contrast); }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 400; line-height: 1.12; letter-spacing: -0.015em; margin: 0 0 .5em; }
h1 { font-size: clamp(2.6rem, 6.4vw, 5.2rem); letter-spacing: -0.03em; }
h2 { font-size: clamp(1.9rem, 3.8vw, 3rem); }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
em.accent { color: var(--accent); font-style: italic; }
.accent { color: var(--accent); }
code, kbd, pre { font-family: var(--font-mono); }
code { font-size: .88em; background: var(--accent-soft); padding: .1em .38em; border-radius: 3px; }
pre { background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow: auto; font-size: .82rem; line-height: 1.6; margin: 0; white-space: pre-wrap; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-contrast); padding: 8px 14px; z-index: 1000; font-family: var(--font-mono); font-size: .75rem; }
.skip:focus { left: 8px; }

/* ---------- Mono labels ---------- */
.eyebrow, .label {
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--fg-faint);
}
.eyebrow { display: inline-flex; align-items: center; gap: 12px; color: var(--accent); }
.eyebrow::before { content: ''; width: 28px; height: 1px; background: currentColor; }
.num { font-family: var(--font-mono); font-size: .78rem; letter-spacing: .1em; color: var(--accent); }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 28px; }
main { min-height: calc(100vh - var(--header-h) - 240px); outline: none; }
.section { padding: 96px 0; border-top: 1px solid var(--border); }
.section.tight { padding: 56px 0; }
.section-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 48px; align-items: end; margin-bottom: 48px; }
.section-head p { color: var(--fg-muted); font-size: 1.08rem; max-width: 56ch; margin: 0; }
.section-head h2 { margin: 14px 0 0; }
.grid { display: grid; gap: 20px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--border);
  overflow: visible;
}
.site-header .container {
  height: var(--header-h); display: flex; align-items: center; gap: 14px; min-width: 0;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--fg); flex: none; }
.brand:hover { color: var(--fg); }
.brand-mark {
  width: 34px; height: 34px; border: 1px solid var(--border-strong); display: grid; place-items: center;
  font-family: var(--font-display); font-size: .95rem; letter-spacing: .02em; color: var(--accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-family: var(--font-display); font-weight: 400; font-size: 1.08rem; }
.brand-text span { font-family: var(--font-mono); font-size: .6rem; letter-spacing: .18em; text-transform: uppercase; color: var(--fg-faint); }
.back-eng {
  flex: none; font-family: var(--font-mono); font-size: .62rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--fg-faint); padding: 6px 0; border: 0; white-space: nowrap;
}
.back-eng::before { content: '← '; }
.back-eng:hover { color: var(--accent); }
.footer-blurb { max-width: 38ch; margin-top: 18px; }
.nav {
  display: flex; gap: 2px; margin-left: auto; align-items: center; flex-wrap: nowrap;
  min-width: 0; overflow: visible;
}
.nav a, .nav button.nav-link {
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--fg-muted); padding: 10px 9px; border: 0; background: none; cursor: pointer; position: relative;
  white-space: nowrap;
}
.nav a:hover, .nav button.nav-link:hover, .nav a[aria-current='page'] { color: var(--fg); }
.nav a[aria-current='page']::after { content: ''; position: absolute; left: 9px; right: 9px; bottom: 4px; height: 1px; background: var(--accent); }
.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px; background: var(--bg-elevated); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); padding: 8px; display: none; z-index: 60;
}
.menu.open .menu-panel { display: block; }
.menu-panel a { display: block; padding: 10px 12px; letter-spacing: .1em; white-space: normal; }
.menu-panel a small { display: block; font-family: var(--font-body); letter-spacing: 0; text-transform: none; color: var(--fg-faint); font-size: .76rem; margin-top: 2px; }
.tools { display: flex; gap: 8px; align-items: center; flex: none; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; min-width: 36px; padding: 0 10px; justify-content: center;
  background: transparent; border: 1px solid var(--border); color: var(--fg-muted); cursor: pointer; border-radius: var(--radius);
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .1em;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--fg); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.kbd { border: 1px solid var(--border-strong); border-radius: 3px; padding: 1px 6px; font-size: .66rem; color: var(--fg-faint); }
.hamburger { display: none; }
.progress-ring { width: 38px; height: 38px; }
.progress-ring circle { fill: none; stroke-width: 2.4; }
.progress-ring .bg { stroke: var(--border-strong); }
.progress-ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s ease; transform: rotate(-90deg); transform-origin: 50% 50%; }
.progress-ring text { font-family: var(--font-mono); font-size: 9.5px; fill: var(--fg-muted); text-anchor: middle; dominant-baseline: central; }

/* ---------- Buttons / chips ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 10px; padding: 13px 22px; cursor: pointer; border-radius: var(--radius);
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  border: 1px solid var(--border-strong); background: transparent; color: var(--fg); transition: all .2s ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.btn.small { padding: 8px 14px; font-size: .65rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--border); border-radius: 999px;
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-muted);
  background: transparent; cursor: default;
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--border-strong); color: var(--fg); }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tag { font-family: var(--font-mono); font-size: .64rem; letter-spacing: .1em; text-transform: uppercase; padding: 3px 8px; border: 1px solid var(--border); color: var(--fg-muted); border-radius: 2px; }
.tag.accent { color: var(--accent); border-color: var(--accent); }

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--border); }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .9; pointer-events: none; }
.hero::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 20% 40%, transparent 0%, var(--bg) 78%); pointer-events: none; }
.hero .container { position: relative; z-index: 2; padding-top: 112px; padding-bottom: 72px; }
.hero h1 { max-width: 14ch; margin: 22px 0 28px; }
.hero .lede { font-size: 1.22rem; color: var(--fg-muted); max-width: 58ch; margin-bottom: 36px; }
.hero-cta { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 72px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--border); }
.stat { padding: 24px 24px 0 0; }
.stat + .stat { padding-left: 24px; border-left: 1px solid var(--border); }
.stat b { display: block; font-family: var(--font-display); font-weight: 300; font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1; letter-spacing: -.02em; }
.stat span { display: block; margin-top: 10px; }

/* ---------- Cards ---------- */
.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; position: relative; transition: border-color .2s ease, transform .2s ease; }
a.card, button.card { color: inherit; display: block; text-align: left; cursor: pointer; width: 100%; }
a.card:hover, button.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h3 { margin: 8px 0 10px; }
.card p { color: var(--fg-muted); font-size: .96rem; margin: 0 0 14px; }
.card .num { display: block; margin-bottom: 14px; }
.card-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: auto; }
.card.flat { background: transparent; }
.card.accent { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), transparent 70%); }

/* Part card with progress */
.part-card { display: flex; flex-direction: column; min-height: 250px; }
.bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: calc(var(--v, 0) * 1%); background: var(--accent); transition: width .5s ease; }
.bar.tall { height: 8px; border-radius: 4px; }

/* ---------- Timeline / course index ---------- */
.part-block { border-top: 1px solid var(--border); padding: 44px 0; display: grid; grid-template-columns: 300px 1fr; gap: 48px; }
.part-block:first-child { border-top: 0; }
.part-meta { position: sticky; top: calc(var(--header-h) + 24px); align-self: start; }
.part-meta .big { font-family: var(--font-display); font-weight: 300; font-size: 4.4rem; color: var(--accent); line-height: 1; margin-bottom: 8px; }
.part-meta p { color: var(--fg-muted); font-size: .94rem; }
.chapter-list { display: flex; flex-direction: column; }
.chapter-row {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 18px; align-items: start; padding: 20px 12px; border-bottom: 1px solid var(--border);
  color: inherit; transition: background .2s, padding .2s;
}
.chapter-row:hover { background: var(--accent-soft); color: inherit; padding-left: 20px; }
.chapter-row h3 { font-size: 1.28rem; margin: 0 0 6px; }
.chapter-row p { margin: 0; color: var(--fg-muted); font-size: .93rem; max-width: 70ch; }
.chapter-row .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; text-align: right; }
.check { width: 20px; height: 20px; border: 1px solid var(--border-strong); border-radius: 50%; display: grid; place-items: center; flex: none; }
.check svg { width: 12px; height: 12px; stroke: var(--accent-contrast); fill: none; stroke-width: 2.4; opacity: 0; }
.check.done { background: var(--accent); border-color: var(--accent); }
.check.done svg { opacity: 1; }

/* ---------- Chapter reading view ---------- */
.reading-bar { position: fixed; top: var(--header-h); left: 0; height: 2px; background: var(--accent); width: calc(var(--p, 0) * 1%); z-index: 49; transition: width .1s linear; }
.chapter-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 64px; padding-top: 56px; padding-bottom: 96px; }
.crumbs { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-faint); margin-bottom: 26px; display: flex; gap: 10px; flex-wrap: wrap; }
.crumbs a { color: var(--fg-muted); }
.chapter-head h1 { font-size: clamp(2.2rem, 4.6vw, 3.8rem); max-width: 22ch; margin: 14px 0 22px; }
.chapter-head .lede { font-family: var(--font-display); font-size: 1.32rem; line-height: 1.5; color: var(--fg-muted); font-weight: 300; max-width: 60ch; }
.chapter-meta { display: flex; gap: 22px; flex-wrap: wrap; margin: 26px 0 8px; padding: 14px 0; border-block: 1px solid var(--border); }
.chapter-meta div span { display: block; margin-bottom: 2px; }
.prose { max-width: none; }
.prose section > p, .prose .objectives, .prose .callout, .prose section > ul, .prose section > ol { max-width: 70ch; }
.prose h2 { font-size: 1.9rem; margin: 3.2rem 0 1rem; padding-top: 1.4rem; border-top: 1px solid var(--border); display: flex; gap: 14px; align-items: baseline; }
.prose h2 .num { font-size: .8rem; }
.prose h3 { margin-top: 2rem; }
.prose p { color: color-mix(in srgb, var(--fg) 88%, var(--fg-muted)); font-size: 1.04rem; line-height: 1.75; }
.prose ul, .prose ol { padding-left: 1.2em; margin: 0 0 1.2em; }
.prose li { margin-bottom: .5em; color: color-mix(in srgb, var(--fg) 88%, var(--fg-muted)); }
.prose li::marker { color: var(--accent); }
.objectives { background: var(--bg-elevated); border: 1px solid var(--border); border-left: 2px solid var(--accent); padding: 22px 26px; margin: 32px 0; }
.objectives h2 { all: unset; display: block; font-family: var(--font-mono); font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); margin-bottom: 12px; }
.objectives ul { margin: 0; }
.callout { border: 1px solid var(--accent); background: var(--accent-soft); padding: 18px 22px; margin: 28px 0; border-radius: var(--radius); }
.callout .label { color: var(--accent); display: block; margin-bottom: 6px; }
.callout p { margin: 0; font-size: 1rem; }
.callout.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.callout.warn .label { color: var(--warn); }
.terms { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin: 16px 0 0; }
.term { border: 1px solid var(--border); padding: 16px 18px; background: var(--bg-elevated); }
.term dt { font-family: var(--font-display); font-size: 1.1rem; margin-bottom: 4px; }
.term dd { margin: 0; color: var(--fg-muted); font-size: .92rem; line-height: 1.55; }
.lab-card { border: 1px dashed var(--border-strong); padding: 24px 28px; margin-top: 16px; background: var(--bg-elevated); }
.lab-card ol { margin: 14px 0 0; padding-left: 1.3em; }
.refs a { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); color: var(--fg); align-items: baseline; }
.refs a:hover { color: var(--accent); }
.refs a span.host { margin-left: auto; font-family: var(--font-mono); font-size: .68rem; color: var(--fg-faint); }
.toc { position: sticky; top: calc(var(--header-h) + 32px); align-self: start; max-height: calc(100vh - var(--header-h) - 64px); overflow: auto; }
.toc ol { list-style: none; padding: 0; margin: 14px 0 0; border-left: 1px solid var(--border); }
.toc ol a { display: block; padding: 6px 0 6px 16px; margin-left: -1px; border-left: 1px solid transparent; color: var(--fg-faint); font-size: .84rem; line-height: 1.4; }
.toc ol a:hover { color: var(--fg); }
.toc ol a.active { color: var(--accent); border-left-color: var(--accent); }
.toc .actions { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 72px; }
.pager a { border: 1px solid var(--border); padding: 20px 24px; color: inherit; transition: border-color .2s; }
.pager a:hover { border-color: var(--accent); }
.pager a.next { text-align: right; }
.pager h4 { margin: 6px 0 0; }
.notes textarea { width: 100%; min-height: 120px; resize: vertical; background: var(--bg-elevated); color: var(--fg); border: 1px solid var(--border); padding: 14px; font: inherit; border-radius: var(--radius); }

/* ---------- Quiz ---------- */
.quiz-q { border: 1px solid var(--border); padding: 22px 24px; margin-bottom: 16px; background: var(--bg-elevated); }
.quiz-q h4 { font-family: var(--font-body); font-size: 1.02rem; font-weight: 500; margin-bottom: 14px; }
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 10px 14px; border: 1px solid var(--border); margin-bottom: 8px; cursor: pointer; border-radius: var(--radius); transition: border-color .15s, background .15s; }
.opt:hover { border-color: var(--border-strong); }
.opt input { margin-top: 5px; accent-color: var(--accent); }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.explain { font-size: .9rem; color: var(--fg-muted); margin-top: 10px; padding-left: 14px; border-left: 2px solid var(--accent); }
.score { font-family: var(--font-display); font-size: 2.4rem; }

/* ---------- Platform / stacks / controls ---------- */
.pillar-cols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.pillar { border: 1px solid var(--border); background: var(--bg-elevated); padding: 22px; }
.pillar > header { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.pillar > header h3 { margin: 4px 0 4px; font-size: 1.5rem; }
.pillar > header p { margin: 0; font-size: .84rem; color: var(--fg-faint); }
.stack-item { display: block; width: 100%; text-align: left; border: 1px solid var(--border); background: transparent; padding: 14px 16px; margin-bottom: 10px; color: inherit; cursor: pointer; border-radius: var(--radius); transition: all .2s; }
.stack-item:hover, .stack-item.on { border-color: var(--accent); background: var(--accent-soft); }
.stack-item b { font-family: var(--font-display); font-weight: 400; font-size: 1.06rem; display: block; }
.stack-item small { color: var(--fg-muted); font-size: .82rem; }
.detail { border: 1px solid var(--accent); background: var(--bg-elevated); padding: 32px; margin-top: 28px; }
.detail h3 { font-size: 2rem; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 24px; margin: 18px 0; }
.kv dt { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); padding-top: 4px; }
.kv dd { margin: 0; }

.control-card { display: flex; flex-direction: column; gap: 10px; }
.control-card .n { font-family: var(--font-display); font-size: 2.6rem; font-weight: 300; color: var(--accent); line-height: 1; }
.control-card h3 { margin: 0; font-size: 1.25rem; }
.control-card details { border-top: 1px solid var(--border); padding-top: 10px; }
.control-card summary { cursor: pointer; font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.control-card ul { padding-left: 1.1em; margin: 10px 0 0; font-size: .9rem; color: var(--fg-muted); }
.control-card .row small { color: var(--fg-faint); }
.group-title { display: flex; align-items: baseline; gap: 16px; margin: 56px 0 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.group-title h3 { margin: 0; font-size: 1.8rem; }
.group-title:first-child { margin-top: 0; }

.layer { display: grid; grid-template-columns: 54px 1fr; gap: 18px; padding: 22px 0; border-bottom: 1px solid var(--border); }
.layer .code { font-family: var(--font-display); font-size: 2rem; color: var(--accent); font-weight: 300; }
.layer h4 { margin: 0 0 4px; font-size: 1.15rem; }
.layer .sub { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-faint); margin-bottom: 8px; display: block; }
.layer p { margin: 0; color: var(--fg-muted); font-size: .96rem; }
.flow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 20px 0; }
.flow-step { border: 1px solid var(--border); padding: 18px; position: relative; background: var(--bg-elevated); }
.flow-step + .flow-step { border-left: 0; }
.flow-step .num { display: block; margin-bottom: 8px; }
.flow-step h4 { margin: 0 0 6px; }
.flow-step p { margin: 0; font-size: .86rem; color: var(--fg-muted); }

.matrix-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elevated); max-height: 76vh; }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 900px; font-size: .84rem; }
.matrix th, .matrix td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; vertical-align: top; }
.matrix thead th { position: sticky; top: 0; background: var(--bg-sunken); z-index: 2; font-family: var(--font-mono); font-weight: 500; font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; padding: 12px 10px; text-align: left; color: var(--fg-muted); }
.matrix thead th button { all: unset; cursor: pointer; display: block; width: 100%; }
.matrix thead th button:hover { color: var(--accent); }
.matrix tbody th { position: sticky; left: 0; background: var(--bg-sunken); z-index: 1; text-align: left; padding: 12px 14px; font-family: var(--font-display); font-weight: 400; font-size: .95rem; min-width: 150px; }
.matrix td button { all: unset; display: block; padding: 12px 10px; cursor: pointer; min-width: 170px; line-height: 1.45; color: var(--fg-muted); width: 100%; box-sizing: border-box; }
.matrix td button:hover, .matrix td button.sel { background: var(--accent-soft); color: var(--fg); }
.matrix td.col-hl, .matrix th.col-hl { background: var(--accent-soft); }
.matrix td.row-hl button { color: var(--fg); }
.matrix tr.pillar-start > th, .matrix tr.pillar-start > td { border-top: 2px solid var(--accent); }
.matrix .pillar-tag { display: block; font-family: var(--font-mono); font-size: .58rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.matrix tbody th .tag { margin-left: 8px; font-size: .55rem; padding: 1px 5px; }
.cell-detail { position: sticky; bottom: 0; background: var(--bg-elevated); border-top: 1px solid var(--accent); padding: 14px 20px; display: none; z-index: 3; }
.cell-detail.show { display: block; }

.pf-hero { display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: end; }
.scores { display: flex; flex-direction: column; gap: 10px; min-width: 260px; }
.score-row { display: grid; grid-template-columns: 90px 1fr 36px; gap: 10px; align-items: center; font-size: .82rem; }
.score-row .bar { height: 6px; }
.pf-chip-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.headline-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0; border: 1px solid var(--border); margin: 28px 0; }
.headline-grid div { padding: 16px 18px; border-right: 1px solid var(--border); font-family: var(--font-display); font-size: 1.04rem; line-height: 1.35; }
.headline-grid div:last-child { border-right: 0; }
.pattern { border: 1px solid var(--border); padding: 18px 20px; background: var(--bg-elevated); }
.pattern .chain { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0; }
.pattern .chain span { font-family: var(--font-mono); font-size: .68rem; padding: 4px 8px; border: 1px solid var(--border-strong); border-radius: 2px; }
.pattern .chain i { color: var(--accent); font-style: normal; }
.spine { display: flex; flex-wrap: wrap; gap: 0; margin: 20px 0; border: 1px solid var(--border); }
.spine span { flex: 1 1 120px; padding: 14px 12px; text-align: center; font-family: var(--font-mono); font-size: .72rem; letter-spacing: .06em; border-right: 1px solid var(--border); background: var(--bg-elevated); }
.spine span:last-child { border-right: 0; }
.spine span:nth-child(odd) { background: var(--accent-soft); }

/* ---------- Tools ---------- */
.tool-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 40px; align-items: start; }
.panel { background: var(--bg-elevated); border: 1px solid var(--border); padding: 28px; border-radius: var(--radius); }
.assess-item { padding: 16px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.assess-item:last-child { border-bottom: 0; }
.assess-item b { font-family: var(--font-display); font-weight: 400; font-size: 1.05rem; }
.assess-item small { display: block; color: var(--fg-faint); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 7px 12px; cursor: pointer; font-family: var(--font-mono); font-size: .64rem; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-muted); }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.on { background: var(--accent); color: var(--accent-contrast); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); display: flex; justify-content: space-between; }
.field label output { color: var(--accent); }
input[type='number'], input[type='text'], select, textarea.input {
  background: var(--bg-sunken); color: var(--fg); border: 1px solid var(--border-strong); padding: 10px 12px; border-radius: var(--radius); font: inherit; width: 100%;
}
input[type='range'] { width: 100%; accent-color: var(--accent); }
.radar svg { width: 100%; height: auto; overflow: visible; }
.radar .ring { fill: none; stroke: var(--border-strong); stroke-width: 1; }
.radar .axis { stroke: var(--border); stroke-width: 1; }
.radar .shape { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.radar .dot { fill: var(--accent); }
.radar text { font-family: var(--font-mono); font-size: 10px; fill: var(--fg-muted); letter-spacing: .06em; }
.verdict { font-family: var(--font-display); font-size: 2.4rem; line-height: 1.1; margin: 8px 0; }
.big-number { font-family: var(--font-display); font-weight: 300; font-size: 3.4rem; line-height: 1; color: var(--accent); }
.bars { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 54px; gap: 12px; align-items: center; font-size: .86rem; }
.bar-row .bar { height: 10px; border-radius: 5px; }
.bar-row.best .bar > i { background: var(--good); }
table.simple { width: 100%; border-collapse: collapse; font-size: .9rem; }
.simple th, .simple td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.simple th { font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); font-weight: 500; }
.glossary-list dt { font-family: var(--font-display); font-size: 1.3rem; margin-top: 22px; }
.glossary-list dd { margin: 4px 0 0; color: var(--fg-muted); max-width: 72ch; }
.alpha { display: flex; flex-wrap: wrap; gap: 6px; margin: 22px 0; }
.alpha a { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--border); font-family: var(--font-mono); font-size: .72rem; color: var(--fg-muted); }
.alpha a:hover { border-color: var(--accent); color: var(--accent); }
.search-input { position: relative; }
.search-input input { padding-left: 14px; font-size: 1.05rem; padding-block: 14px; }
.copy-box { position: relative; }
.copy-box .btn { position: absolute; top: 10px; right: 10px; }

/* ---------- Team ---------- */
.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; margin-top: 16px; }
.heat i { aspect-ratio: 1; display: grid; place-items: center; font-style: normal; font-family: var(--font-mono); font-size: .6rem; border: 1px solid var(--border); background: color-mix(in srgb, var(--accent) calc(var(--v, 0) * 1%), transparent); color: var(--fg); }

/* ---------- Palette / modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: #000a; backdrop-filter: blur(4px); z-index: 100; display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.overlay.open { display: flex; }
.palette { width: min(680px, 92vw); background: var(--bg-elevated); border: 1px solid var(--border-strong); box-shadow: var(--shadow); border-radius: 6px; overflow: hidden; }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--fg); padding: 18px 22px; font-size: 1.1rem; outline: none; font-family: var(--font-body); }
.palette ul { list-style: none; margin: 0; padding: 8px; max-height: 52vh; overflow: auto; }
.palette li a { display: grid; grid-template-columns: 78px 1fr; gap: 12px; align-items: baseline; padding: 10px 12px; color: var(--fg); border-radius: 4px; }
.palette li a small { color: var(--fg-faint); display: block; font-size: .78rem; }
.palette li a.active, .palette li a:hover { background: var(--accent-soft); }
.palette .empty { padding: 28px; text-align: center; color: var(--fg-faint); }
.palette footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 18px; color: var(--fg-faint); }
.toast-zone { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--bg-elevated); border: 1px solid var(--accent); padding: 12px 18px; font-size: .9rem; box-shadow: var(--shadow); animation: rise .25s ease; max-width: 340px; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Rich topic blocks ---------- */
.prose section > h3 { margin: 2.4rem 0 1rem; font-size: 1.25rem; display: flex; align-items: center; gap: 12px; }
.prose section > h3::before { content: ''; width: 20px; height: 1px; background: var(--accent); }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0; border: 1px solid var(--border); margin: 28px 0; }
.stat-card { padding: 20px 22px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--bg-elevated); display: flex; flex-direction: column; gap: 6px; }
.stat-card b { font-family: var(--font-display); font-weight: 300; font-size: 2.6rem; line-height: 1; color: var(--accent); letter-spacing: -.02em; }
.stat-card span { font-size: .9rem; line-height: 1.45; color: var(--fg); }
.stat-card small { font-family: var(--font-mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-faint); margin-top: auto; padding-top: 6px; }
.data-table { margin: 28px 0; }
.data-table figcaption, .codeblock figcaption { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); margin-bottom: 10px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); background: var(--bg-elevated); }
.data-table table.simple th[scope='row'] { font-family: var(--font-body); font-weight: 500; font-size: .9rem; letter-spacing: 0; text-transform: none; color: var(--fg); }
.codeblock { margin: 28px 0; }
.codeblock figcaption { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.codeblock pre { white-space: pre; tab-size: 4; }
.codeblock code { background: none; padding: 0; font-size: inherit; }
.example { border: 1px solid var(--border); border-left: 2px solid var(--accent); background: var(--bg-elevated); padding: 24px 28px; margin: 20px 0; }
.example h4 { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; margin: 12px 0 8px; }
.example .kv { margin: 14px 0 6px; grid-template-columns: 150px minmax(0, 1fr); }
.example .kv dd { color: var(--fg-muted); font-size: .96rem; line-height: 1.65; }
.example-source { margin: 12px 0 0; font-size: .9rem; }
.takeaways { border: 1px solid var(--border); background: var(--accent-soft); padding: 20px 26px; margin: 28px 0; max-width: 78ch; }
.takeaways .label { color: var(--accent); }
.takeaways ul { margin: 10px 0 0; padding-left: 1.2em; }
.takeaways li { margin-bottom: .45em; }
.read-list { list-style: none; padding: 0; margin: 0 0 12px; border-top: 1px solid var(--border); max-width: 78ch; }
.read-list li { padding: 14px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; }
.read-list li::marker { content: ''; }
.read-list a { font-weight: 500; }
.read-list .host { font-family: var(--font-mono); font-size: .66rem; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-faint); align-self: start; padding-top: 4px; text-align: right; }
.read-list p { grid-column: 1 / -1; margin: 0; font-size: .9rem; color: var(--fg-muted); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 64px 0 40px; margin-top: 64px; }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 40px; }
.footer-grid h4 { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .16em; text-transform: uppercase; color: var(--fg-faint); margin-bottom: 14px; }
.footer-grid a { display: block; color: var(--fg-muted); padding: 4px 0; font-size: .92rem; }
.footer-grid a:hover { color: var(--accent); }
.footer-base { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }

.loading { padding: 140px 0; text-align: center; }
.spinner { width: 28px; height: 28px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-head { padding-top: 84px; padding-bottom: 40px; }
.page-head h1 { font-size: clamp(2.4rem, 5vw, 4rem); margin: 16px 0 18px; max-width: 18ch; }
.page-head p { font-size: 1.08rem; line-height: 1.65; color: var(--fg-muted); max-width: 68ch; }
.notfound { padding: 140px 0; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1060px) {
  .pillar-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chapter-wrap { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
  .part-block { grid-template-columns: 1fr; gap: 20px; }
  .part-meta { position: static; }
  .grid.c4 { grid-template-columns: repeat(2, 1fr); }
  .grid.c3 { grid-template-columns: repeat(2, 1fr); }
  .tool-grid { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat:nth-child(4) { border-left: 0; padding-left: 0; }
}
/* Collapse early so the sticky 64px bar never wraps/clips mid-links. */
@media (max-width: 1280px) {
  .hamburger { display: inline-flex; }
  .nav {
    position: fixed; top: var(--header-h); left: 0; right: 0; background: var(--bg);
    border-bottom: 1px solid var(--border); flex-direction: column; align-items: stretch;
    padding: 12px 20px 20px; display: none; margin: 0; z-index: 60;
    max-height: calc(100vh - var(--header-h)); overflow: auto;
  }
  .nav.open { display: flex; }
  .nav a, .nav button.nav-link { padding: 12px 4px; font-size: .7rem; }
  .menu-panel {
    position: static; display: none; box-shadow: none; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 6px; margin: 4px 0 8px; background: var(--bg-elevated);
  }
  .menu.open .menu-panel { display: block; }
}
@media (min-width: 1281px) {
  .hamburger { display: none !important; }
  .nav { display: flex !important; }
}
@media (max-width: 820px) {
  table.simple { display: block; overflow-x: auto; }
  .example .kv { grid-template-columns: 1fr; }
  .read-list li { grid-template-columns: 1fr; }
  .read-list .host { text-align: left; }
  .section-head, .pf-hero, .pillar-cols, .grid.c2 { grid-template-columns: 1fr; }
  .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .flow { grid-template-columns: 1fr 1fr; }
  .flow-step + .flow-step { border-left: 1px solid var(--border); }
  .chapter-row { grid-template-columns: 38px 1fr; }
  .chapter-row .meta { grid-column: 2; flex-direction: row; align-items: center; text-align: left; }
  .kv { grid-template-columns: 1fr; }
  .pager { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat, .stat + .stat { border-left: 0; padding-left: 0; }
  .bar-row { grid-template-columns: 100px 1fr 46px; }
}
@media (max-width: 520px) {
  .brand-text, #kbd-hint { display: none; }
  .site-header .container { gap: 12px; }
  .tools { margin-left: auto; }
  .container { padding: 0 18px; }
  .section { padding: 64px 0; }
  .hero .container { padding-top: 72px; }
}
@media (min-width: 1061px) { .sticky { position: sticky; top: calc(var(--header-h) + 24px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- Print (whole-book export) ---------- */
@media print {
  :root, [data-theme] { --bg: #fff; --bg-elevated: #fff; --bg-sunken: #f5f5f5; --fg: #111; --fg-muted: #333; --fg-faint: #555; --border: #ccc; --border-strong: #999; --accent: #8a4b12; --accent-soft: #f3e9dd; }
  body { font-size: 11pt; }
  .site-header, .site-footer, .toc, .pager, .reading-bar, .toast-zone, .no-print, .skip { display: none !important; }
  .chapter-wrap { display: block; padding: 0; }
  .book-chapter { break-before: page; }
  .container { max-width: none; padding: 0; }
  a { color: inherit; }
  .card, .callout, .term, .lab-card { break-inside: avoid; }
}
