/* ==========================================================================
   Neural Guide — stylesheet
   Design tokens follow Examples/site-002/design.md (SAP-style system):
   4px spacing scale, 8/12px radii, three elevation levels, one sans family.
   ========================================================================== */

/* ---------- Fonts (self-hosted, SIL OFL 1.1) ---------- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../fonts/inter-latin-var.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-latin-var.woff2") format("woff2");
}

/* ---------- Tokens: light (default) ---------- */
:root {
  color-scheme: light;

  --blue: #0057d2;
  --blue-bright: #0070f2;
  --blue-dark: #0040b0;
  --blue-light: #ebf8ff;

  --text: #354a5f;
  --text-2: #545454;
  --text-inverse: #ffffff;
  --heading: #223649;

  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f6f7;
  --bg-dark: #222222;
  --bg-footer: #f5f6f7;

  --border: #eaecee;
  --border-strong: #475e75;
  --icon: #475e75;

  --link: var(--blue);
  --link-hover: var(--blue-dark);
  --btn-bg: var(--blue);
  --btn-bg-hover: var(--blue-dark);
  --chip-bg: var(--blue-light);
  --chip-text: var(--blue-dark);
  --focus: rgba(0, 87, 210, 0.35);
  --mark: rgba(0, 112, 242, 0.16);

  --warn: #a14a00;
  --warn-bg: #fff6e8;
  --warn-border: #e76500;

  --code-bg: #f5f6f7;
  --pre-bg: #222222;
  --pre-text: #e8edf2;
  --pre-muted: #8fa1b3;

  /* Diagram palette — SVGs use classes, so they re-theme automatically */
  --d-fill: #ffffff;
  --d-stroke: #475e75;
  --d-accent: #0057d2;
  --d-accent-fill: #ebf8ff;
  --d-muted-fill: #f5f6f7;
  --d-text: #354a5f;
  --d-text-2: #545454;

  --shadow-1: rgba(34, 54, 73, 0.2) 0px 2px 4px 0px;
  --shadow-2: rgba(34, 54, 73, 0.25) 0px 10px 30px 0px;
  --shadow-3: rgba(0, 0, 0, 0.3) 0px 0px 20px 0px;

  --r-xs: 2px;
  --r-sm: 4px;
  --r: 8px;
  --r-lg: 12px;

  --font: "Inter", "72 Brand Variable", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", Menlo, Consolas, Monaco, "Courier New", monospace;

  --maxw: 1280px;
  --gutter: 32px;
  --header-h: 64px;
}

/* ---------- Tokens: dark (derived from the same palette) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --blue-light: #13263d;
  --text: #dfe6ed;
  --text-2: #a9b5c1;
  --heading: #f2f5f8;

  --bg: #16191d;
  --surface: #1e2227;
  --surface-2: #252a30;
  --bg-dark: #0f1114;
  --bg-footer: #1b1f24;

  --border: #2f363e;
  --border-strong: #7d93a8;
  --icon: #a9b5c1;

  --link: #5aa2ff;
  --link-hover: #8cbfff;
  --btn-bg: #0070f2;
  --btn-bg-hover: #0057d2;
  --chip-bg: #13263d;
  --chip-text: #8cbfff;
  --focus: rgba(90, 162, 255, 0.45);
  --mark: rgba(90, 162, 255, 0.24);

  --warn: #ffb870;
  --warn-bg: #2b2117;
  --warn-border: #e76500;

  --code-bg: #252a30;
  --pre-bg: #0f1114;
  --pre-text: #e8edf2;
  --pre-muted: #8fa1b3;

  --d-fill: #1e2227;
  --d-stroke: #8fa1b3;
  --d-accent: #5aa2ff;
  --d-accent-fill: #13263d;
  --d-muted-fill: #252a30;
  --d-text: #dfe6ed;
  --d-text-2: #a9b5c1;

  --shadow-1: rgba(0, 0, 0, 0.4) 0px 2px 4px 0px;
  --shadow-2: rgba(0, 0, 0, 0.5) 0px 10px 30px 0px;
  --shadow-3: rgba(0, 0, 0, 0.6) 0px 0px 20px 0px;
}

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

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

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

main {
  flex: 1 0 auto;
}

img,
svg {
  max-width: 100%;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  color: var(--heading);
  line-height: 1.2;
  font-weight: 700;
}

h1 { font-size: 32px; }
h2 { font-size: 28px; }
h3 { font-size: 24px; }
h4 { font-size: 20px; font-weight: 400; line-height: 1.5; }

p {
  margin: 0;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--blue-bright);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection {
  background: var(--mark);
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -64px;
  z-index: 100;
  padding: 12px 16px;
  background: var(--btn-bg);
  color: #ffffff;
  border-radius: var(--r);
}

.skip-link:focus {
  top: 12px;
  color: #ffffff;
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.section {
  padding: 64px 0;
}

.section-alt {
  background: var(--surface-2);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

.section-head p {
  margin-top: 8px;
  color: var(--text-2);
  font-size: 15px;
  font-weight: 350;
  max-width: 640px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--link);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-dark);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 32px;
  min-height: var(--header-h);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
}

.logo:hover {
  color: #ffffff;
  text-decoration: none;
}

.logo-mark {
  width: 32px;
  height: 32px;
  flex: none;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  color: #ffffff;
  font-size: 15px;
  font-weight: 400;
  transition: background-color 0.2s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  box-shadow: inset 0 -2px 0 var(--blue-bright);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--r);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.search-trigger:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.4);
}

.search-trigger svg {
  width: 16px;
  height: 16px;
}

.search-trigger kbd {
  margin-left: 16px;
  padding: 2px 4px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.nav-toggle {
  display: none;
}

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: var(--r);
  font-family: var(--font);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn:hover {
  text-decoration: none;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  padding: 16px 20px;
  border: 1px solid var(--btn-bg);
  background: var(--btn-bg);
  color: #ffffff;
  font-size: 16px;
  font-weight: 500;
}

.btn-primary:hover {
  border-color: var(--btn-bg-hover);
  background: var(--btn-bg-hover);
  color: #ffffff;
}

.btn-secondary {
  padding: 8px 16px;
  border: 1px solid var(--link);
  background: transparent;
  color: var(--link);
  font-size: 15px;
  font-weight: 400;
}

.btn-secondary:hover {
  background: var(--blue-light);
  color: var(--link-hover);
}

.btn-inverse {
  padding: 16px 20px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: transparent;
  color: #ffffff;
  font-size: 16px;
  font-weight: 500;
}

.btn-inverse:hover {
  border-color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.btn-text {
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--link-hover);
  font-size: 14px;
}

.btn-text:hover {
  background: rgba(0, 87, 210, 0.05);
  text-decoration: underline;
}

.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.link-arrow::after {
  content: "\2192";
  transition: transform 0.2s ease;
}

.link-arrow:hover::after {
  transform: translateX(4px);
}

/* ---------- Hero (home) ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background: var(--bg-dark);
  color: #ffffff;
}

.hero-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  align-items: center;
  gap: 48px;
  padding-top: 96px;
  padding-bottom: 96px;
}

.hero .eyebrow {
  color: #8cbfff;
}

.hero h1 {
  color: #ffffff;
  font-size: 57px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.hero h1 em {
  font-style: normal;
  color: #8cbfff;
}

.hero-lede {
  margin-top: 24px;
  max-width: 560px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 20px;
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 40px;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 40px;
  margin: 48px 0 0;
  padding: 24px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.hero-stats div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-stats dt {
  order: 2;
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.hero-stats dd {
  order: 1;
  margin: 0;
  color: #ffffff;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.hero-visual svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Neural-graph illustration */
.ng-edge {
  stroke: rgba(255, 255, 255, 0.14);
  stroke-width: 1;
  fill: none;
}

.ng-pulse {
  stroke: #0070f2;
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
  stroke-dasharray: 10 100;
  stroke-dashoffset: 10;
  opacity: 0;
}

.ng-node {
  fill: #222222;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 1.5;
}

.ng-node-active {
  fill: #0057d2;
  stroke: #8cbfff;
}

.ng-label {
  fill: rgba(255, 255, 255, 0.6);
  font-family: var(--mono);
  font-size: 12px;
}

.ng-token {
  fill: rgba(255, 255, 255, 0.08);
  stroke: rgba(255, 255, 255, 0.24);
}

.ng-token-text {
  fill: #ffffff;
  font-family: var(--mono);
  font-size: 13px;
}

.ng-token-out {
  fill: #0057d2;
  stroke: #0070f2;
}

@media (prefers-reduced-motion: no-preference) {
  .ng-pulse {
    animation: ng-flow 3.6s cubic-bezier(0.45, 0, 0.25, 1) infinite;
  }
  .ng-pulse:nth-of-type(2n) { animation-delay: 0.6s; }
  .ng-pulse:nth-of-type(3n) { animation-delay: 1.2s; }
  .ng-pulse:nth-of-type(5n) { animation-delay: 1.8s; }
  .ng-pulse:nth-of-type(7n) { animation-delay: 2.4s; }

  .ng-node-active {
    animation: ng-glow 3.6s ease-in-out infinite;
  }
  .ng-blink {
    animation: ng-blink 1.2s steps(2, start) infinite;
  }
}

@keyframes ng-flow {
  0% { stroke-dashoffset: 10; opacity: 0; }
  10% { opacity: 1; }
  80% { opacity: 1; }
  100% { stroke-dashoffset: -100; opacity: 0; }
}

@keyframes ng-glow {
  0%, 100% { fill: #0057d2; }
  50% { fill: #0070f2; }
}

@keyframes ng-blink {
  to { visibility: hidden; }
}

.ng-caret {
  fill: #8cbfff;
}

/* ---------- Page hero (inner pages) ---------- */
.page-hero {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 48px 0 40px;
}

.page-hero h1 {
  max-width: 880px;
}

.page-hero .lede {
  margin-top: 16px;
  max-width: 760px;
  color: var(--text-2);
  font-size: 20px;
  line-height: 1.5;
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  font-size: 14px;
  color: var(--text-2);
}

.breadcrumb li + li::before {
  content: "/";
  margin-right: 8px;
  color: var(--border-strong);
}

.breadcrumb a {
  color: var(--text-2);
}

.breadcrumb a:hover {
  color: var(--link);
}

/* ---------- Chips, levels, meta ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}

a.chip:hover {
  text-decoration: none;
  background: var(--border);
}

.tag {
  display: inline-flex;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 14px;
}

.level {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 14px;
  white-space: nowrap;
}

.level-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.level-bars i {
  display: block;
  width: 4px;
  border-radius: 1px;
  background: var(--border);
}

.level-bars i:nth-child(1) { height: 4px; }
.level-bars i:nth-child(2) { height: 8px; }
.level-bars i:nth-child(3) { height: 12px; }

.level-1 .level-bars i:nth-child(-n + 1),
.level-2 .level-bars i:nth-child(-n + 2),
.level-3 .level-bars i:nth-child(-n + 3) {
  background: var(--blue);
}

:root[data-theme="dark"] .level-1 .level-bars i:nth-child(-n + 1),
:root[data-theme="dark"] .level-2 .level-bars i:nth-child(-n + 2),
:root[data-theme="dark"] .level-3 .level-bars i:nth-child(-n + 3) {
  background: var(--link);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  color: var(--text-2);
  font-size: 14px;
}

.meta-sep {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border-strong);
  opacity: 0.6;
}

/* ---------- Cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card:hover,
.card:focus-within {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card :is(h2, h3) {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}

.card :is(h2, h3) a {
  color: var(--heading);
}

.card :is(h2, h3) a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--r);
}

.card :is(h2, h3) a:hover {
  color: var(--link);
  text-decoration: none;
}

.card :is(h2, h3) a:focus-visible {
  outline: none;
}

.card :is(h2, h3) a:focus-visible::after {
  outline: 2px solid var(--blue-bright);
  outline-offset: 2px;
}

.card-summary {
  color: var(--text-2);
  font-size: 15px;
  font-weight: 350;
  line-height: 1.5;
}

.card .meta {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.card-num {
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 14px;
}

/* Highlight container (no shadow by design) */
.highlight {
  background: var(--blue-light);
  border-radius: var(--r-lg);
  padding: 32px;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

.topic {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topic-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--r);
  background: var(--surface);
  color: var(--blue);
}

:root[data-theme="dark"] .topic-icon {
  color: var(--link);
}

.topic-icon svg {
  width: 24px;
  height: 24px;
}

.topic h3 {
  font-size: 24px;
}

.topic p {
  color: var(--text-2);
  font-size: 15px;
  font-weight: 350;
}

.topic ul {
  margin: 4px 0 8px;
  padding: 0;
  list-style: none;
  font-size: 15px;
}

.topic li {
  padding: 4px 0;
}

.topic .link-arrow {
  margin-top: auto;
}

/* Learning path */
.path {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.path li {
  position: relative;
  counter-increment: step;
}

.path li::before {
  content: "";
  position: absolute;
  top: 20px;
  left: 48px;
  right: -16px;
  height: 2px;
  background: var(--border);
}

.path li:last-child::before {
  display: none;
}

.path a {
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--text);
}

.path a:hover {
  text-decoration: none;
}

.path a::before {
  content: counter(step);
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 2px solid var(--blue);
  border-radius: 50%;
  background: var(--bg);
  color: var(--blue);
  font-weight: 700;
  transition: background-color 0.2s ease, color 0.2s ease;
}

:root[data-theme="dark"] .path a::before {
  border-color: var(--link);
  color: var(--link);
}

.path a:hover::before {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: #ffffff;
}

.path-title {
  font-weight: 700;
  color: var(--heading);
}

.path a:hover .path-title {
  color: var(--link);
}

.path-desc {
  color: var(--text-2);
  font-size: 15px;
  font-weight: 350;
}

/* Glossary teaser */
.teaser {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 48px;
  align-items: center;
}

.teaser p {
  margin-top: 12px;
  color: var(--text-2);
}

.teaser .btn {
  margin-top: 24px;
}

.term-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.term-cloud a {
  display: inline-flex;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.term-cloud a:hover {
  border-color: var(--link);
  color: var(--link);
  text-decoration: none;
}

/* ---------- Catalog filters ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 32px;
  margin-bottom: 32px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.filter-group legend {
  float: left;
  margin-right: 8px;
  color: var(--text-2);
  font-size: 14px;
}

.filter-chip {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.filter-chip:hover {
  border-color: var(--link);
  color: var(--link);
}

.filter-chip[aria-pressed="true"] {
  border-color: var(--btn-bg);
  background: var(--btn-bg);
  color: #ffffff;
}

.result-count {
  margin-left: auto;
  color: var(--text-2);
  font-size: 14px;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-2);
}

[hidden] {
  display: none !important;
}

/* ---------- Article layout ---------- */
.article-head .chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.article-head .meta {
  margin-top: 24px;
}

.article-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 760px);
  justify-content: center;
  gap: 64px;
  padding-top: 48px;
  padding-bottom: 96px;
}

.toc {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 48px);
  overflow-y: auto;
  font-size: 14px;
}

.toc-title {
  margin-bottom: 12px;
  color: var(--heading);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

.toc a {
  display: block;
  margin-left: -2px;
  padding: 8px 12px;
  border-left: 2px solid transparent;
  color: var(--text-2);
  line-height: 1.4;
}

.toc a:hover {
  border-left-color: var(--link);
  color: var(--link);
  text-decoration: none;
}

/* ---------- Prose ---------- */
.prose {
  min-width: 0;
  font-size: 16px;
  line-height: 1.5;
}

.prose > * + * {
  margin-top: 16px;
}

.prose h2 {
  margin-top: 48px;
  padding-top: 8px;
  font-size: 28px;
}

.prose h3 {
  margin-top: 32px;
  font-size: 20px;
  line-height: 1.3;
}

.prose h2 + *,
.prose h3 + * {
  margin-top: 12px;
}

.prose > :first-child {
  margin-top: 0;
}

.prose ul,
.prose ol {
  padding-left: 24px;
}

.prose li + li {
  margin-top: 8px;
}

.prose li > ul,
.prose li > ol {
  margin-top: 8px;
}

.prose strong {
  color: var(--heading);
  font-weight: 600;
}

.prose a {
  text-decoration: underline;
  text-decoration-color: rgba(0, 87, 210, 0.35);
  text-underline-offset: 3px;
}

.prose a:hover {
  text-decoration-color: currentColor;
}

.prose a.term {
  color: inherit;
  text-decoration: underline dotted;
  text-decoration-color: var(--link);
  text-decoration-thickness: 1.5px;
}

.prose a.term:hover {
  color: var(--link);
}

.prose :not(pre) > code {
  padding: 2px 4px;
  border-radius: var(--r-sm);
  background: var(--code-bg);
  color: var(--heading);
  font-size: 0.875em;
  overflow-wrap: break-word;
}

.prose blockquote {
  margin-left: 0;
  margin-right: 0;
  padding: 4px 0 4px 20px;
  border-left: 4px solid var(--border);
  color: var(--text-2);
}

.prose hr {
  margin: 48px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.prose .lead {
  font-size: 20px;
  color: var(--heading);
}

/* Code blocks */
.prose pre,
.code-block pre {
  margin: 0;
  padding: 16px 20px;
  overflow-x: auto;
  border-radius: var(--r);
  background: var(--pre-bg);
  color: var(--pre-text);
  font-size: 14px;
  line-height: 1.6;
  tab-size: 2;
}

.prose pre code {
  font-size: inherit;
}

.prose pre .c {
  color: var(--pre-muted);
}

.prose pre .s {
  color: #9fd3a8;
}

.prose pre .k {
  color: #8cbfff;
}

.code-block {
  border-radius: var(--r);
  background: var(--pre-bg);
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 4px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--pre-muted);
  font-family: var(--mono);
  font-size: 12px;
  text-transform: lowercase;
}

.copy-btn {
  min-height: 32px;
  padding: 4px 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--pre-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.code-block pre {
  border-radius: 0;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.5;
}

.prose th,
.prose td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.prose th {
  background: var(--surface-2);
  color: var(--heading);
  font-weight: 600;
  white-space: nowrap;
}

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

.prose caption {
  padding: 12px 16px;
  caption-side: bottom;
  color: var(--text-2);
  font-size: 14px;
  text-align: left;
}

/* Callouts */
.callout {
  padding: 16px 20px;
  border-left: 4px solid var(--blue);
  border-radius: var(--r);
  background: var(--blue-light);
}

:root[data-theme="dark"] .callout {
  border-left-color: var(--link);
}

.callout > * + * {
  margin-top: 8px;
}

.callout-title {
  color: var(--heading);
  font-size: 15px;
  font-weight: 700;
}

.callout--warning {
  border-left-color: var(--warn-border);
  background: var(--warn-bg);
}

:root[data-theme="dark"] .callout--warning {
  border-left-color: var(--warn-border);
}

.callout--warning .callout-title {
  color: var(--warn);
}

/* Diagrams */
.diagram {
  margin-left: 0;
  margin-right: 0;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.prose > .diagram {
  margin-top: 24px;
  margin-bottom: 8px;
}

.diagram-scroll {
  overflow-x: auto;
}

.diagram svg {
  display: block;
  width: 100%;
  min-width: 560px;
  height: auto;
  margin: 0 auto;
}

.diagram figcaption {
  margin-top: 16px;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.5;
}

.d-box { fill: var(--d-fill); stroke: var(--d-stroke); stroke-width: 1.5; }
.d-box-accent { fill: var(--d-accent-fill); stroke: var(--d-accent); stroke-width: 1.5; }
.d-box-solid { fill: var(--d-accent); stroke: var(--d-accent); stroke-width: 1.5; }
.d-box-muted { fill: var(--d-muted-fill); stroke: var(--d-stroke); stroke-width: 1; stroke-dasharray: 4 4; }
.d-edge { fill: none; stroke: var(--d-stroke); stroke-width: 1.5; }
.d-edge-accent { fill: none; stroke: var(--d-accent); stroke-width: 2; }
.d-edge-dashed { stroke-dasharray: 4 4; }
.d-arrowhead { fill: var(--d-stroke); }
.d-arrowhead-accent { fill: var(--d-accent); }
.d-dot { fill: var(--d-accent); }
.d-label { fill: var(--d-text); font-family: var(--font); font-size: 14px; }
.d-label-sm { fill: var(--d-text-2); font-family: var(--font); font-size: 12px; }
.d-label-strong { font-weight: 700; }
.d-label-accent { fill: var(--d-accent); }
.d-label-inverse { fill: #ffffff; }
.d-mono { font-family: var(--mono); }

/* Key takeaways + sources */
.key-takeaways {
  margin-top: 48px;
  padding: 32px;
  border-radius: var(--r-lg);
  background: var(--blue-light);
}

.prose .key-takeaways h2 {
  margin-top: 0;
  padding-top: 0;
  font-size: 24px;
}

.key-takeaways ul {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.key-takeaways li {
  position: relative;
  padding-left: 32px;
}

.key-takeaways li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--btn-bg);
}

.key-takeaways li::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  width: 5px;
  height: 9px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.sources {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 15px;
}

.prose .sources h2 {
  margin-top: 0;
  padding-top: 0;
  font-size: 20px;
}

.sources ol,
.sources ul {
  color: var(--text-2);
}

.sources li {
  overflow-wrap: anywhere;
}

/* ---------- Glossary ---------- */
.glossary-tools {
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  padding: 16px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.glossary-tools .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.az {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.az a,
.az span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
}

.az a:hover {
  background: var(--blue-light);
  text-decoration: none;
}

.az span {
  color: var(--border-strong);
  opacity: 0.45;
  font-weight: 400;
}

.text-input {
  width: 100%;
  max-width: 320px;
  min-height: 44px;
  margin-left: auto;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.text-input::placeholder {
  color: var(--text-2);
}

.text-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--focus);
}

.glossary-body {
  padding-top: 32px;
  padding-bottom: 96px;
}

.glossary-letter {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 24px;
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
}

.glossary-letter > h2 {
  color: var(--blue);
  font-size: 40px;
  line-height: 1;
}

:root[data-theme="dark"] .glossary-letter > h2 {
  color: var(--link);
}

.glossary-letter dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin: 0;
}

.gterm {
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
}

.gterm:target {
  border-color: var(--blue-bright);
  box-shadow: 0 0 0 2px var(--focus);
}

.gterm dt {
  color: var(--heading);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}

.gterm dt small {
  margin-left: 8px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 400;
}

.gterm dd {
  margin: 8px 0 0;
  color: var(--text);
  font-size: 15px;
}

.gterm-used {
  margin-top: 12px !important;
  color: var(--text-2);
  font-size: 14px;
}

.gterm-used a + a::before {
  content: "\00B7";
  margin: 0 8px;
  color: var(--text-2);
}

/* ---------- Search dialog ---------- */
.search-dialog {
  width: calc(100% - 32px);
  max-width: 640px;
  max-height: min(640px, calc(100vh - 128px));
  margin: 96px auto auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}

.search-dialog[open] {
  display: flex;
  flex-direction: column;
}

.search-dialog::backdrop {
  background: rgba(15, 17, 20, 0.6);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.search-field svg {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--icon);
}

.search-field input {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  border: 0;
  background: transparent;
  color: var(--heading);
  font-family: var(--font);
  font-size: 16px;
}

.search-field input:focus {
  outline: none;
}

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

.search-close {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}

.search-results {
  flex: 1;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  list-style: none;
}

.search-group {
  padding: 12px 12px 4px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.search-result a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border-radius: var(--r);
  color: var(--text);
}

.search-result a:hover {
  text-decoration: none;
}

.search-result[aria-selected="true"] a {
  background: var(--blue-light);
}

.search-result-title {
  color: var(--heading);
  font-weight: 600;
}

.search-result-kicker {
  color: var(--text-2);
  font-size: 12px;
}

.search-result-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text-2);
  font-size: 14px;
}

.search-result mark {
  border-radius: var(--r-xs);
  background: var(--mark);
  color: inherit;
}

.search-empty {
  padding: 32px 16px;
  color: var(--text-2);
  text-align: center;
  font-size: 15px;
}

.search-foot {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
}

.search-foot kbd {
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 12px;
}

/* ---------- Footer ---------- */
.site-footer {
  flex-shrink: 0;
  background: var(--bg-footer);
  border-top: 1px solid var(--border);
  font-size: 15px;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, minmax(0, 1fr));
  gap: 32px;
  padding: 64px 0 48px;
}

.footer-brand .logo {
  color: var(--heading);
}

.footer-brand p {
  margin-top: 16px;
  max-width: 360px;
  color: var(--text-2);
  font-weight: 350;
}

.footer-col h2 {
  margin-bottom: 16px;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.footer-col ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.footer-col li + li {
  margin-top: 8px;
}

.footer-col a {
  color: var(--text);
}

.footer-col a:hover {
  color: var(--link);
}

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font-size: 14px;
}

/* ---------- 404 ---------- */
.not-found {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  padding: 96px 0;
}

.not-found .code {
  color: var(--blue);
  font-family: var(--mono);
  font-size: 57px;
  font-weight: 700;
  line-height: 1.2;
}

/* ---------- Responsive ---------- */
@media (max-width: 1279px) {
  .article-layout {
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 48px;
  }
}

@media (max-width: 1023px) {
  .nav-toggle {
    display: inline-flex;
  }

  .main-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px 16px 16px;
    background: var(--bg-dark);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .main-nav.is-open {
    display: flex;
  }

  .header-actions {
    margin-left: auto;
  }

  .hero-inner {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 64px;
    padding-bottom: 64px;
  }

  .hero-visual {
    max-width: 560px;
  }

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

  .path {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .path li {
    padding-bottom: 24px;
  }

  .path li::before {
    top: 40px;
    bottom: 0;
    left: 19px;
    right: auto;
    width: 2px;
    height: auto;
  }

  .path a {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    column-gap: 16px;
    row-gap: 4px;
  }

  .path a::before {
    flex: none;
  }

  .path-title {
    flex: 1 1 calc(100% - 56px);
    padding-top: 8px;
  }

  .path-desc {
    flex: 1 1 100%;
    padding-left: 56px;
  }

  .teaser {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
  }

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

  .footer-brand {
    grid-column: 1 / -1;
  }

  .article-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
    max-width: 808px;
  }

  .toc {
    position: static;
    max-height: none;
    padding: 20px 24px;
    border: 1px solid var(--border);
    border-radius: var(--r);
  }

  .glossary-letter dl {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 767px) {
  :root {
    --gutter: 16px;
  }

  h1 { font-size: 28px; }
  h2 { font-size: 24px; }

  .section {
    padding: 48px 0;
  }

  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-trigger span,
  .search-trigger kbd {
    display: none;
  }

  .search-trigger {
    width: 44px;
    height: 44px;
    justify-content: center;
    padding: 0;
    border-color: transparent;
    background: transparent;
  }

  .hero h1 {
    font-size: 40px;
  }

  .hero-lede {
    font-size: 16px;
  }

  .hero-inner {
    padding-top: 48px;
    padding-bottom: 48px;
  }

  .hero-stats {
    gap: 24px;
  }

  .card-grid,
  .topic-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .highlight {
    padding: 24px;
  }

  .page-hero {
    padding: 32px 0;
  }

  .page-hero .lede {
    font-size: 16px;
  }

  .prose h2 {
    font-size: 24px;
  }

  .key-takeaways {
    padding: 24px;
  }

  .diagram {
    padding: 16px;
  }

  .filters {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-count {
    margin-left: 0;
  }

  .text-input {
    max-width: none;
    margin-left: 0;
  }

  .glossary-tools {
    position: static;
  }

  .glossary-letter {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .footer-grid {
    grid-template-columns: minmax(0, 1fr);
    padding: 48px 0 32px;
  }

  .search-dialog {
    margin-top: 16px;
    max-height: calc(100vh - 32px);
  }
}

@media (max-width: 479px) {
  .hero h1 {
    font-size: 36px;
  }

  .logo {
    font-size: 18px;
  }
}

@media print {
  .site-header,
  .site-footer,
  .toc,
  .copy-btn {
    display: none !important;
  }

  .article-layout {
    display: block;
    padding: 0;
  }
}
