:root {
  --bg: #0f1013;
  --surface: #16181d;
  --surface-2: #1b1e24;
  --border: #262a31;
  --border-strong: #343943;
  --text: #e7e9ec;
  --muted: #9aa0a8;
  --faint: #6b717a;
  --accent: #7aa2f7;
  --accent-dim: rgba(122, 162, 247, 0.14);
  --ok: #6ee7a8;
  --bad: #f38ba8;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 96px;
}

/* --- header / nav ------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15, 16, 19, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.brand {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
}
.topbar nav { display: flex; gap: 18px; }
.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.topbar nav a:hover, .topbar nav a[aria-current] { color: var(--accent); }

/* --- typography --------------------------------------------------------- */

h1, h2, h3 { line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 12px; }
h2 { font-size: 1.35rem; margin: 0 0 8px; }
h3 { font-size: 1.05rem; margin: 0 0 6px; }

p { margin: 0 0 14px; color: var(--text); }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 62ch; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.8rem; }
section { margin-top: 56px; }
section > h2 { padding-bottom: 8px; border-bottom: 1px solid var(--border); }

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

code, .mono, .hex {
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.hex {
  display: block;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

/* --- cards / grid ------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}
.card + .card { margin-top: 20px; }
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.card-head svg { color: var(--accent); flex: none; }
.card-head h3 { margin: 0; }

.grid { display: grid; gap: 20px; }
@media (min-width: 720px) {
  .grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}

/* --- forms -------------------------------------------------------------- */

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 5px; }
input, select, textarea, button {
  font-family: inherit;
  font-size: 0.9rem;
}
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 11px;
}
textarea { resize: vertical; font-family: var(--font-mono); font-size: 0.85rem; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  background: transparent;
}

.btn {
  background: var(--accent);
  color: #0b0d10;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 500;
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.controls {
  display: grid;
  gap: 14px;
  margin: 18px 0;
}
@media (min-width: 720px) { .controls.cols-2 { grid-template-columns: 1fr 1fr; } }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

/* --- pills / badges ----------------------------------------------------- */

.pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}
.chip {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 5px 12px;
}
.chip:hover { color: var(--accent); border-color: var(--accent); }
.chip[aria-pressed="true"] { color: #0b0d10; background: var(--accent); border-color: var(--accent); }

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  padding: 2px 8px;
}
.badge.ok { color: var(--ok); background: rgba(110, 231, 168, 0.12); }
.badge.bad { color: var(--bad); background: rgba(243, 139, 168, 0.12); }

/* --- key/value lists ---------------------------------------------------- */

.kv { display: grid; gap: 8px; }
.kv > div { display: grid; gap: 2px; }
.kv dt, .kv .k {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
}

/* --- charts ------------------------------------------------------------- */

canvas { display: block; width: 100%; }
.chart { height: 220px; }
.chart.sm { height: 170px; }
.chart.tall { height: 300px; }
.chart-caption { font-size: 0.8rem; color: var(--faint); margin-top: 8px; }

/* --- pipeline ----------------------------------------------------------- */

.pipeline { display: grid; gap: 12px; }
details.stage {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: 10px;
  padding: 0 16px;
}
details.stage[open] { border-left-color: var(--accent); }
details.stage > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 14px 0;
  list-style: none;
}
details.stage > summary::-webkit-details-marker { display: none; }
details.stage > summary svg { color: var(--accent); flex: none; }
.stage-name { font-weight: 600; }
.stage-value { margin-left: auto; font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
details.stage > .body { padding: 0 0 16px; color: var(--muted); font-size: 0.9rem; }
details.stage > .body .hex { margin-top: 8px; }

/* --- timeline ----------------------------------------------------------- */

.timeline {
  position: relative;
  margin: 8px 0 0;
  padding-left: 22px;
  border-left: 1px solid var(--border-strong);
  display: grid;
  gap: 18px;
}
.timeline .event { position: relative; }
.timeline .event::before {
  content: "";
  position: absolute;
  left: -27px;
  top: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline .year { font-family: var(--font-mono); color: var(--accent); font-size: 0.85rem; }

/* --- tables ------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
@media (max-width: 720px) { table { display: block; overflow-x: auto; white-space: nowrap; } }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--faint); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr:hover { background: var(--surface-2); }

/* --- home --------------------------------------------------------------- */

.home h1 { margin-bottom: 10px; }
.hw-list { display: grid; gap: 14px; margin-top: 28px; }
.hw-link {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, transform .15s;
}
.hw-link:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.hw-link svg { color: var(--accent); flex: none; }
.hw-link .arrow { margin-left: auto; color: var(--faint); }
.hw-link:hover .arrow { color: var(--accent); }
.hw-link .title { display: block; font-weight: 600; }
.hw-link .sub { display: block; color: var(--muted); font-size: 0.9rem; }

.note {
  border-left: 3px solid var(--accent);
  background: var(--accent-dim);
  border-radius: 0 10px 10px 0;
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--text);
}
.note.warn { border-left-color: var(--bad); background: rgba(243, 139, 168, 0.1); }

.curve-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-top: 10px; }
.curve-legend span { display: inline-flex; align-items: center; gap: 7px; }
.curve-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

figure { margin: 0; }
figcaption { font-size: 0.8rem; color: var(--faint); margin-top: 8px; }

.hidden { display: none !important; }
