/* ============================================================
   walgit — an interactive explainer
   Design system: dark editorial / technical. One accent per world:
   pain = coral, insight = sky, realization = lime, payoff = gold.
   ============================================================ */

:root {
  --bg: #0a0c11;
  --bg-2: #0e1118;
  --panel: #12161f;
  --panel-2: #171c27;
  --line: #232a38;
  --line-soft: #1a2030;
  --ink: #e8ecf4;
  --ink-2: #aab3c5;
  --ink-3: #6d7789;
  --pain: #ff6b57;
  --pain-dim: #5a2c26;
  --insight: #38bdf8;
  --insight-dim: #16405a;
  --real: #a3e635;
  --real-dim: #33480f;
  --gold: #f5c451;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --maxw: 1180px;
  --rad: 14px;
  --rad-s: 8px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection { background: rgba(56, 189, 248, .28); }

/* ---------- utility ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
.narrow { max-width: 780px; }
.mono { font-family: var(--mono); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
a { color: var(--insight); text-decoration-color: rgba(56,189,248,.4); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }

/* ---------- top chrome ---------- */
.progressbar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--pain), var(--insight), var(--real));
  z-index: 60;
}
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px;
  background: linear-gradient(rgba(10,12,17,.92), rgba(10,12,17,.75) 70%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}
.topnav > * { pointer-events: auto; }
.topnav .brand {
  font-family: var(--mono); font-weight: 700; font-size: 15px;
  color: var(--ink); text-decoration: none; letter-spacing: -.02em;
}
.topnav .brand em { color: var(--real); font-style: normal; }
.topnav .links { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.topnav .links a {
  font-size: 12.5px; font-family: var(--mono); color: var(--ink-3);
  text-decoration: none; padding: 4px 9px; border-radius: 6px;
  transition: color .15s, background .15s;
}
.topnav .links a:hover { color: var(--ink); background: rgba(255,255,255,.05); }
.topnav .links a.active { color: var(--ink); background: rgba(255,255,255,.07); }
@media (max-width: 760px) { .topnav .links { display: none; } }

/* chapter dots (desktop) */
.dots {
  position: fixed; right: 18px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 14px; z-index: 40;
}
.dots a {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--line); position: relative;
  transition: background .2s, transform .2s;
}
.dots a:hover, .dots a.active { background: var(--ink); transform: scale(1.25); }
.dots a .tip {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  background: var(--panel); border: 1px solid var(--line);
  padding: 3px 8px; border-radius: 6px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.dots a:hover .tip { opacity: 1; }
@media (max-width: 1000px) { .dots { display: none; } }

/* ---------- hero ---------- */
.hero {
  min-height: 100svh;
  display: flex; flex-direction: column; justify-content: center;
  position: relative; padding: 120px 0 60px;
  overflow: hidden;
}
.hero .grid-bg {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 40%, black 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 40%, black 30%, transparent 75%);
}
.hero-inner { position: relative; text-align: center; }
.hero .kicker {
  font-family: var(--mono); font-size: 13px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--real);
  margin-bottom: 22px;
}
.hero h1 {
  font-size: clamp(40px, 7.2vw, 88px);
  line-height: 1.02; letter-spacing: -.035em; font-weight: 800;
  margin: 0 auto 24px; max-width: 15ch;
}
.hero h1 .thin { color: var(--ink-3); font-weight: 600; }
.hero .lede {
  font-size: clamp(17px, 2.2vw, 21px); color: var(--ink-2);
  max-width: 58ch; margin: 0 auto 40px;
}
.hero .lede b { color: var(--ink); font-weight: 600; }
.hero-cta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 14px; font-weight: 500;
  padding: 12px 22px; border-radius: 10px; text-decoration: none;
  border: 1px solid var(--line); color: var(--ink);
  background: var(--panel);
  transition: transform .15s, border-color .15s, background .15s;
  cursor: pointer;
}
.btn:hover { transform: translateY(-1px); border-color: var(--ink-3); background: var(--panel-2); }
.btn.primary { background: var(--real); border-color: var(--real); color: #10160a; font-weight: 700; }
.btn.primary:hover { background: #b8f24d; }
.scroll-hint {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  letter-spacing: .18em; text-transform: uppercase;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.scroll-hint::after {
  content: ''; width: 1px; height: 34px;
  background: linear-gradient(var(--ink-3), transparent);
  animation: drip 2.2s ease-in-out infinite;
}
@keyframes drip { 0% { transform: scaleY(.2); transform-origin: top; } 55% { transform: scaleY(1); } 100% { transform: scaleY(.2); transform-origin: top; opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .scroll-hint::after { animation: none; } }

/* hero mini figure */
.hero-fig { margin: 56px auto 0; max-width: 860px; }

/* ---------- chapters ---------- */
.chapter { padding: 110px 0 40px; position: relative; }
.chapter-head { max-width: 780px; margin-bottom: 18px; }
.chapter .eyebrow {
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .16em;
  text-transform: uppercase; display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
}
.chapter .eyebrow::before { content: ''; width: 26px; height: 2px; background: currentColor; }
.chapter h2 {
  font-size: clamp(30px, 4.6vw, 52px); line-height: 1.06;
  letter-spacing: -.03em; font-weight: 800; margin: 0 0 18px;
}
.chapter .sub { font-size: 18.5px; color: var(--ink-2); margin: 0; max-width: 62ch; }
.chapter .sub b, .chapter p b { color: var(--ink); font-weight: 600; }

#ch-pain .eyebrow { color: var(--pain); }
#ch-pain h2 .accent { color: var(--pain); }
#ch-insight .eyebrow { color: var(--insight); }
#ch-insight h2 .accent { color: var(--insight); }
#ch-real .eyebrow { color: var(--real); }
#ch-real h2 .accent { color: var(--real); }
#ch-payoff .eyebrow { color: var(--gold); }
#ch-payoff h2 .accent { color: var(--gold); }

.prose p { max-width: 68ch; margin: 0 0 18px; color: var(--ink-2); }
.prose p.lead { font-size: 19px; color: var(--ink); }
.term {
  font-family: var(--mono); font-size: .86em; color: var(--ink);
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 5px; white-space: nowrap;
}

/* ---------- diagram frame ---------- */
.fig {
  margin: 44px 0 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  overflow: hidden;
  box-shadow: 0 24px 60px -30px rgba(0,0,0,.7);
}
.fig-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line-soft);
  background: var(--bg-2);
}
.fig-head .fig-title {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink-2);
  letter-spacing: .02em;
}
.fig-head .fig-title b { color: var(--ink); font-weight: 600; }
.fig-controls { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.fig-controls .lbl { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.ctl {
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 12px; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
  min-height: 34px; min-width: 34px;
}
.ctl:hover { color: var(--ink); border-color: var(--ink-3); }
.ctl[aria-pressed="true"], .ctl.on { color: #10160a; background: var(--real); border-color: var(--real); font-weight: 700; }
.ctl:disabled { opacity: .4; cursor: default; }
.fig-stage { position: relative; }
.fig-stage svg { display: block; width: 100%; height: auto; }
.fig-cap {
  padding: 12px 16px; border-top: 1px solid var(--line-soft);
  font-size: 13.5px; color: var(--ink-3); background: var(--bg-2);
}
.fig-cap b { color: var(--ink-2); font-weight: 600; }
.fig-cap .step-line { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); display: block; min-height: 1.4em; }

/* scrubber */
.scrub {
  -webkit-appearance: none; appearance: none;
  width: 140px; height: 4px; border-radius: 2px;
  background: var(--line); outline: none; cursor: pointer;
}
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); border: 2px solid var(--bg);
}
.scrub::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); border: 2px solid var(--bg); }

/* transcript / alt text disclosure */
.fig details.alt {
  border-top: 1px solid var(--line-soft); background: var(--bg-2);
}
.fig details.alt summary {
  cursor: pointer; padding: 10px 16px;
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
  list-style: none;
}
.fig details.alt summary::before { content: '▸ '; }
.fig details.alt[open] summary::before { content: '▾ '; }
.fig details.alt summary:hover { color: var(--ink-2); }
.fig details.alt .alt-body {
  padding: 0 16px 14px; font-size: 13.5px; color: var(--ink-2); max-width: 75ch;
}

/* ---------- stat / callout strips ---------- */
.strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px; margin: 40px 0;
}
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--rad-s); padding: 18px 18px 16px;
}
.stat .n { font-family: var(--mono); font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .t { font-size: 13px; color: var(--ink-3); margin-top: 6px; line-height: 1.45; }
.stat.pain .n { color: var(--pain); }
.stat.insight .n { color: var(--insight); }
.stat.real .n { color: var(--real); }
.stat.gold .n { color: var(--gold); }

.callout {
  border: 1px solid var(--line); border-left: 3px solid var(--insight);
  background: var(--panel); border-radius: 0 var(--rad-s) var(--rad-s) 0;
  padding: 16px 20px; margin: 34px 0; max-width: 780px;
  font-size: 15.5px; color: var(--ink-2);
}
.callout b { color: var(--ink); }
.callout.pain { border-left-color: var(--pain); }
.callout.real { border-left-color: var(--real); }
.callout.gold { border-left-color: var(--gold); }

/* invariant ticker */
.invariants {
  margin: 70px 0 30px; padding: 26px 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 10px 26px; justify-content: center;
}
.invariants span {
  font-family: var(--mono); font-size: 13px; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 9px;
}
.invariants span::before { content: '◆'; color: var(--real); font-size: 9px; }

/* ---------- terminal ---------- */
.termwin {
  margin: 40px 0; background: #0c0f15; border: 1px solid var(--line);
  border-radius: var(--rad); overflow: hidden; max-width: 760px;
  box-shadow: 0 24px 60px -30px rgba(0,0,0,.7);
}
.termwin .tbar {
  display: flex; align-items: center; gap: 7px;
  padding: 11px 14px; background: var(--bg-2); border-bottom: 1px solid var(--line-soft);
}
.termwin .tbar i { width: 11px; height: 11px; border-radius: 50%; background: var(--line); }
.termwin .tbar i:nth-child(1) { background: #ff5f57; }
.termwin .tbar i:nth-child(2) { background: #febc2e; }
.termwin .tbar i:nth-child(3) { background: #28c840; }
.termwin .tbar .tt { margin-left: 8px; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.termwin pre {
  margin: 0; padding: 20px 22px; overflow-x: auto;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.75; color: var(--ink-2);
}
.termwin .c { color: var(--ink-3); }            /* comment */
.termwin .p { color: var(--real); }            /* prompt */
.termwin .k { color: var(--insight); }         /* key */
.termwin .s { color: var(--gold); }            /* string */
.termwin .ok { color: var(--real); }
.termwin .cmd { color: var(--ink); font-weight: 500; }

/* ---------- comparison ---------- */
.compare { margin: 48px 0; overflow-x: auto; border-radius: var(--rad); }
.compare table {
  width: 100%; min-width: 720px; border-collapse: collapse;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 14.5px;
}
.compare th, .compare td {
  padding: 14px 16px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--line-soft);
}
.compare thead th {
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .04em;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.compare tbody th { font-weight: 600; color: var(--ink-2); font-size: 13px; font-family: var(--mono); white-space: nowrap; }
.compare td { color: var(--ink-2); }
.compare td.good { color: var(--real); }
.compare td.bad { color: var(--pain); }
.compare td.mid { color: var(--gold); }
.compare tr:last-child th, .compare tr:last-child td { border-bottom: none; }
.compare .col-pain { border-left: 3px solid var(--pain-dim); }
.compare .col-insight { border-left: 3px solid var(--insight-dim); }
.compare .col-real { border-left: 3px solid var(--real-dim); background: rgba(163,230,53,.045); }

/* summary card */
.sharecard {
  margin: 56px auto; max-width: 720px;
  background: linear-gradient(145deg, #10141d, #0c0f15);
  border: 1px solid var(--line); border-radius: 18px;
  padding: 40px 44px; position: relative; overflow: hidden;
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.8);
}
.sharecard::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(600px 200px at 80% -10%, rgba(163,230,53,.12), transparent 60%);
}
.sharecard .sc-k { font-family: var(--mono); font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--real); margin-bottom: 14px; }
.sharecard .sc-t { font-size: clamp(22px, 3.4vw, 30px); font-weight: 800; letter-spacing: -.025em; line-height: 1.15; margin: 0 0 18px; }
.sharecard .sc-l { color: var(--ink-2); font-size: 15.5px; margin: 0 0 22px; }
.sharecard .sc-f { display: flex; flex-wrap: wrap; gap: 8px 20px; font-family: var(--mono); font-size: 12.5px; color: var(--ink-3); }
.sharecard .sc-f span::before { content: '✓ '; color: var(--real); }

/* footer */
footer {
  border-top: 1px solid var(--line); margin-top: 100px;
  padding: 60px 0 80px; color: var(--ink-3); font-size: 14px;
}
footer .cols { display: flex; gap: 60px; flex-wrap: wrap; }
footer h4 { font-family: var(--mono); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 14px; }
footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
footer .colophon { margin-top: 50px; font-family: var(--mono); font-size: 12px; color: var(--ink-3); }

/* reveal on scroll */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity .7s ease, transform .7s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .chapter { padding: 80px 0 24px; }
  .fig-head { flex-wrap: wrap; }
  .fig-controls { margin-left: 0; width: 100%; }
  .scrub { flex: 1; }
  .sharecard { padding: 28px 24px; }
  .compare { margin-left: -24px; margin-right: -24px; border-radius: 0; }
}

/* focus */
:focus-visible { outline: 2px solid var(--insight); outline-offset: 2px; border-radius: 4px; }
