/* statescript.org — Editorial Light-First + Dark Precision Code/HUD Surfaces */
:root {
  --bg: #fafaf8;
  --bg-subtle: #f2f1ec;
  --surface: #ffffff;
  --border: #e3e1d8;
  --border-strong: #cbc8bc;
  --ink: #11161f;
  --ink-muted: #4b5563;
  --ink-soft: #6b7280;

  /* Functional semantic signals */
  --accent: #0f766e;
  --accent-hover: #0d5f59;
  --accent-soft: #e6f4f1;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --err: #dc2626;
  --err-soft: #fee2e2;
  --blue: #2563eb;

  /* Dark instrument panels (code, playground, HUD) */
  --panel-bg: #0e131b;
  --panel-surface: #151c28;
  --panel-border: #253041;
  --panel-ink: #e8edf5;
  --panel-muted: #93a1b8;
  --panel-dim: #64748b;

  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Monaco, Consolas, monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(17, 22, 31, 0.05);
  --shadow-md: 0 8px 28px rgba(17, 22, 31, 0.08);
  --max-w: 1180px;
}

[data-theme="dark"] {
  --bg: #0b0f16;
  --bg-subtle: #111722;
  --surface: #141b27;
  --border: #222d3f;
  --border-strong: #32415a;
  --ink: #edf2f7;
  --ink-muted: #a0aec0;
  --ink-soft: #7b8ba4;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --err: #f87171;
  --err-soft: rgba(248, 113, 113, 0.14);
  --blue: #60a5fa;
  --panel-bg: #090d14;
  --panel-surface: #101622;
  --panel-border: #222d3f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, kbd { font-family: var(--font-mono); }

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Navbar */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 750;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none !important;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--panel-bg);
  color: #34d399;
  display: inline-grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.8rem;
  border: 1px solid var(--panel-border);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.nav-links a {
  color: var(--ink-muted);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.4rem 0.72rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover, .nav-links a.active {
  color: var(--ink);
  background: var(--bg-subtle);
  text-decoration: none;
}
.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.62rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-muted); transform: translateY(-1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
[data-theme="dark"] .btn-primary { color: #062825; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { padding: 0.36rem 0.72rem; font-size: 0.82rem; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-muted); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--ink); border-color: transparent; transform: none; }
.theme-toggle {
  width: 34px; height: 34px; padding: 0; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-muted);
  cursor: pointer; display: inline-grid; place-items: center; font-size: 0.95rem;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--border-strong); }

/* Badges & Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.24rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  font-family: var(--font-mono);
}
.pill-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill-err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* Hero */
.hero {
  padding: 4.5rem 0 3.5rem;
  border-bottom: 1px solid var(--border);
}
.hero-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 2.5rem;
  align-items: center;
}
.hero h1 {
  font-size: clamp(2.1rem, 4.1vw, 3.25rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  margin: 0.85rem 0 1.15rem;
  font-weight: 800;
}
.hero-sub {
  font-size: 1.12rem;
  color: var(--ink-muted);
  margin: 0 0 1.6rem;
  max-width: 54ch;
}
.hero-cta { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.75rem; }
.hero-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  padding-top: 1.35rem;
  border-top: 1px solid var(--border);
}
.stat-val { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; font-family: var(--font-mono); }
.stat-lbl { font-size: 0.76rem; color: var(--ink-soft); line-height: 1.3; margin-top: 0.15rem; }

/* Dark Instrument Code Panel */
.panel {
  background: var(--panel-bg);
  color: var(--panel-ink);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.panel-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.95rem;
  background: var(--panel-surface);
  border-bottom: 1px solid var(--panel-border);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--panel-muted);
}
.panel-dots { display: inline-flex; gap: 6px; align-items: center; }
.panel-dots span { width: 9px; height: 9px; border-radius: 50%; background: #334155; }
.panel-code {
  margin: 0;
  padding: 1.05rem 1.15rem;
  overflow-x: auto;
  font-size: 0.83rem;
  line-height: 1.55;
  color: var(--panel-ink);
}
.panel-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.15rem;
  padding: 0.62rem 1rem;
  background: #0a0e15;
  border-top: 1px solid var(--panel-border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--panel-muted);
}
.hud-ok { color: #34d399; font-weight: 600; }
.hud-warn { color: #fbbf24; font-weight: 600; }
.hud-info { color: #60a5fa; font-weight: 600; }

/* Syntax highlighting inside dark panels & docs */
.tok-kw { color: #7dd3fc; font-weight: 600; }
.tok-st { color: #fbbf24; font-weight: 600; }
.tok-type { color: #f0abfc; }
.tok-fn { color: #93c5fd; }
.tok-str { color: #86efac; }
.tok-num { color: #fca5a5; }
.tok-cmt { color: #64748b; font-style: italic; }
.tok-doc { color: #34d399; font-style: italic; }
.tok-op { color: #c4b5fd; }

/* Stats grids & HUD dashboard cards */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.15rem;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
.dash-section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.6rem 0 0.75rem;
}
.dash-section-title {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.45rem;
}
.kpi-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.kpi-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.kpi-val {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.kpi-val-sm {
  font-size: 1.32rem;
}
.kpi-sub {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-soft);
  line-height: 1.4;
}
.kpi-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 0.15rem;
}
.kpi-mini {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.48rem 0.6rem;
}
.kpi-mini-k {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}
.kpi-mini-v {
  font-family: var(--font-mono);
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  margin-top: 0.1rem;
}
.kpi-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
  display: flex;
}
.kpi-bar-seg-a { background: var(--ok); height: 100%; transition: width 0.3s ease; }
.kpi-bar-seg-b { background: var(--blue); height: 100%; transition: width 0.3s ease; }
.kpi-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.15rem;
}
.hud-panel {
  background: var(--panel-bg);
  color: var(--panel-ink);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.15rem 1.25rem;
}
.chart-hdr {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.chart-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--panel-muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}
.chart-svg {
  width: 100%;
  height: 155px;
  display: block;
}

/* Rendered Mermaid Diagrams */
.mermaid-wrap {
  margin: 1.25rem 0;
  padding: 1.15rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  text-align: center;
}
.mermaid-wrap svg {
  max-width: 100%;
  height: auto;
}
.mermaid-wrap .mermaid-src-fallback {
  text-align: left;
  margin: 0;
}

/* Sections */
.section { padding: 4.25rem 0; border-bottom: 1px solid var(--border); }
.section-subtle { background: var(--bg-subtle); }
.section-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.45rem;
}
.section-title {
  font-size: clamp(1.55rem, 2.8vw, 2.2rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 0 0 0.7rem;
}
.section-lead {
  font-size: 1.04rem;
  color: var(--ink-muted);
  max-width: 64ch;
  margin: 0 0 2.2rem;
}

/* Pillar cards (3x2 grid on desktop, 2x3 on tablet, 1-col on mobile) */
.pillars {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.15rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.card p { flex: 1; }
.card-kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}
.card h3 { margin: 0 0 0.55rem; font-size: 1.15rem; letter-spacing: -0.015em; }
.card p { margin: 0; color: var(--ink-muted); font-size: 0.95rem; }
.card-proof {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--border);
  font-family: var(--font-mono);
  font-size: 0.79rem;
  color: var(--ink-soft);
}
.card-proof strong { color: var(--ink); }

/* Scenario Tabs (Before vs After) */
.tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
.tab-btn {
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.compare-pane { display: none; }
.compare-pane.active { display: block; }
.compare-note {
  margin-top: 1rem;
  padding: 0.85rem 1.05rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.92rem;
}

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td {
  padding: 0.68rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  background: var(--bg-subtle);
  white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-size: 0.83rem; }
.delta-good { color: var(--ok); font-weight: 700; }
.delta-fast { color: var(--accent); font-weight: 700; }

/* Install Strip */
.install-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--panel-bg);
  color: var(--panel-ink);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  overflow-x: auto;
}

/* Footer */
.footer {
  padding: 2.5rem 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.footer-links { display: flex; flex-wrap: wrap; gap: 1.25rem; }

/* ================= PLAYGROUND + HUD ================= */
.pg-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 60px);
  background: var(--panel-bg);
  color: var(--panel-ink);
}
.pg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.65rem 1rem;
  background: var(--panel-surface);
  border-bottom: 1px solid var(--panel-border);
}
.pg-toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.pg-select {
  background: #0a0e15;
  color: var(--panel-ink);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.7rem;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  min-width: 240px;
}
.pg-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.78rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: #1a2332;
  color: var(--panel-ink);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.pg-btn:hover { background: #243146; }
.pg-btn-run { background: #059669; border-color: #059669; color: #ffffff; }
.pg-btn-run:hover { background: #047857; }
.pg-btn-verify { background: #1d4ed8; border-color: #1d4ed8; color: #ffffff; }
.pg-btn-verify:hover { background: #1e40af; }

/* Telemetry HUD bar */
.hud-bar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
}
.hud-cell {
  background: #0b1018;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}
.hud-label {
  font-family: var(--font-mono);
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--panel-dim);
}
.hud-value {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--panel-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pg-main {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  flex: 1;
  min-height: 540px;
}
.pg-editor-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--panel-border);
  min-width: 0;
}
.pg-example-desc {
  padding: 0.5rem 0.95rem;
  font-size: 0.82rem;
  color: var(--panel-muted);
  background: #101621;
  border-bottom: 1px solid var(--panel-border);
}
.pg-editor-wrap {
  position: relative;
  flex: 1;
  min-height: 460px;
  background: var(--panel-bg);
  overflow: hidden;
}
.pg-editor-hl,
.pg-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 1rem 1.1rem;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.58;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  box-sizing: border-box;
}
.pg-editor-hl {
  pointer-events: none;
  color: var(--panel-ink);
  background: transparent;
  z-index: 1;
}
.pg-editor {
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: #34d399;
  z-index: 2;
  -webkit-text-fill-color: transparent;
}
.pg-editor::selection {
  background: rgba(52, 211, 153, 0.28);
  -webkit-text-fill-color: transparent;
}
.pg-out-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #0c1119;
}
.pg-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel-surface);
}
.pg-tab {
  padding: 0.55rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--panel-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.pg-tab.active { color: #34d399; border-bottom-color: #34d399; }
.pg-tab-panel { display: none; padding: 0.95rem 1.05rem; overflow: auto; flex: 1; }
.pg-tab-panel.active { display: block; }

.pg-section-hdr {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--panel-dim);
  margin: 0.85rem 0 0.45rem;
}
.pg-section-hdr:first-child { margin-top: 0; }
.pg-events-grid { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.pg-ev-form {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #141c29;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0.28rem 0.45rem;
}
.pg-ev-input {
  width: 88px;
  padding: 0.25rem 0.4rem;
  background: #090d14;
  color: var(--panel-ink);
  border: 1px solid #2b384d;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.pg-console {
  background: #070a10;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 290px;
  overflow: auto;
  margin: 0;
}
.pg-views-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}
.pg-view-card {
  background: #131a26;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  font-family: var(--font-mono);
}
.pg-view-k { font-size: 0.72rem; color: var(--panel-muted); }
.pg-view-v { font-size: 0.92rem; color: #34d399; font-weight: 700; margin-top: 0.15rem; overflow-wrap: anywhere; }
.pg-diagram-box {
  background: #080c13;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  overflow: auto;
  min-height: 220px;
}
.pg-error {
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #fecaca;
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
}

/* ================= DOCS PORTAL ================= */
.docs-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 2.25rem;
  padding: 2rem 0 4rem;
  align-items: start;
}
.docs-sidebar {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding-right: 0.5rem;
}
.docs-search {
  width: 100%;
  padding: 0.52rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.88rem;
  margin-bottom: 1rem;
}
.docs-group-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  margin: 1rem 0 0.35rem;
  font-weight: 700;
}
.docs-nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.42rem 0.65rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 0.88rem;
  cursor: pointer;
}
.docs-nav-btn:hover { background: var(--bg-subtle); color: var(--ink); }
.docs-nav-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.docs-article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.docs-article h1 { margin-top: 0; font-size: 2rem; letter-spacing: -0.03em; }
.docs-article h2 { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 1.38rem; letter-spacing: -0.02em; }
.docs-article h3 { margin-top: 1.4rem; font-size: 1.08rem; }
.docs-article pre {
  background: var(--panel-bg);
  color: var(--panel-ink);
  padding: 0.95rem 1.1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.83rem;
  line-height: 1.55;
  border: 1px solid var(--panel-border);
}
.docs-article code {
  background: var(--bg-subtle);
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  font-size: 0.86em;
}
.docs-article pre code { background: transparent; padding: 0; }
.docs-article blockquote {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.docs-article table { margin: 1.25rem 0; border: 1px solid var(--border); }

/* ================= CORPUS EXPLORER ================= */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 1rem;
}
.filter-input {
  flex: 1;
  min-width: 220px;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
}
.cat-pills { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1.15rem; }
.cat-pill {
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
}
.cat-pill.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.corpus-row {
  cursor: pointer;
  transition: background 0.12s ease;
}
.corpus-row:hover {
  background: var(--accent-soft);
}
.corpus-compare-btn {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 0.24rem 0.55rem;
}

/* Side-by-Side Source Comparison Modal */
.diff-modal[hidden] { display: none !important; }
.diff-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}
.diff-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 18, 0.72);
  backdrop-filter: blur(4px);
}
.diff-dialog {
  position: relative;
  z-index: 1;
  width: min(1440px, 100%);
  height: min(90vh, 920px);
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  color: var(--panel-ink);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.diff-hdr {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.15rem;
  background: var(--panel-surface);
  border-bottom: 1px solid var(--panel-border);
}
.diff-hdr-left {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}
.diff-title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  color: var(--panel-ink);
}
.diff-link {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: #7dd3fc;
}
.diff-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.diff-chip {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--panel-muted);
  background: #0b1018;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.18rem 0.5rem;
}
.diff-chip strong { color: var(--panel-ink); }
.diff-hdr-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.diff-hdr-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.diff-note {
  padding: 0.52rem 1.15rem;
  font-size: 0.8rem;
  color: #cbd5e1;
  background: #101826;
  border-bottom: 1px solid var(--panel-border);
}
.diff-note code {
  background: #090d14;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: #93c5fd;
}
.diff-panes {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.diff-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--panel-border);
}
.diff-pane:last-child { border-right: none; }
.diff-pane-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.48rem 0.9rem;
  background: #111824;
  border-bottom: 1px solid var(--panel-border);
}
.diff-pane-title {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  color: #cbd5e1;
}
.diff-file-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}
.diff-file-tab {
  font-family: var(--font-mono);
  font-size: 0.71rem;
  padding: 0.14rem 0.48rem;
  border-radius: 5px;
  border: 1px solid var(--panel-border);
  background: #0a0f17;
  color: var(--panel-muted);
  cursor: pointer;
}
.diff-file-tab.active {
  background: #1d2b40;
  border-color: #38bdf8;
  color: #e0f2fe;
}
.diff-code-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--panel-bg);
}
.diff-loading {
  padding: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--panel-muted);
}
.diff-pre {
  margin: 0;
  padding: 0.65rem 0;
  font-family: var(--font-mono);
  font-size: 0.79rem;
  line-height: 1.52;
  min-width: max-content;
}
.code-line {
  display: flex;
  padding: 0 1rem 0 0;
}
.code-line:hover {
  background: rgba(148, 163, 184, 0.07);
}
.code-ln {
  flex: 0 0 var(--ln-w, 3em);
  text-align: right;
  padding-right: 0.85em;
  color: #475569;
  user-select: none;
}
.code-txt {
  white-space: pre;
}

/* Responsive */
@media (max-width: 1080px) {
  .grid-4, .pillars { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .hero-grid, .pillars, .compare-grid, .pg-main, .docs-layout, .grid-2, .grid-3, .grid-4, .diff-panes { grid-template-columns: 1fr; }
  .diff-pane { border-right: none; border-bottom: 1px solid var(--panel-border); }
  .hud-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pg-editor-pane { border-right: none; border-bottom: 1px solid var(--panel-border); }
  .docs-sidebar { position: static; max-height: none; }
}
