:root {
  --bg: #0a0d12;
  --bg-2: #10151d;
  --panel: #131a24;
  --line: #222c3a;
  --text: #e6edf5;
  --muted: #8b98a9;
  --accent: #ff3b3b;      /* racing red */
  --accent-2: #22d3ee;    /* telemetry cyan */
  --car-a: #ff3b3b;
  --car-b: #22d3ee;
  --purple: #b26bff;      /* fastest sector */
  --green: #3ddc84;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.mono { font-family: var(--mono); }
.accent { color: var(--accent); }
.car-a { color: var(--car-a); }
.car-b { color: var(--car-b); }
a { color: inherit; }

/* NAV */
.nav {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px clamp(16px, 4vw, 48px);
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { font-family: var(--mono); font-weight: 600; text-decoration: none; font-size: 1.05rem; }
.logo-bracket { color: var(--accent); }
.nav nav { display: flex; gap: clamp(10px, 2vw, 28px); }
.nav nav a { text-decoration: none; color: var(--muted); font-size: .9rem; transition: color .2s; }
.nav nav a:hover { color: var(--text); }

/* HERO */
.hero {
  position: relative; min-height: 100vh;
  display: grid; place-items: center;
  padding: 110px clamp(16px, 4vw, 48px) 60px;
  overflow: hidden;
}
#hero-bg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; }
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 30% 40%, transparent 0%, var(--bg) 75%);
}
.hero-inner {
  position: relative; z-index: 1; max-width: 1180px; width: 100%;
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 48px; align-items: center;
}
.eyebrow { color: var(--accent-2); font-size: .85rem; letter-spacing: .05em; margin: 0 0 10px; }
h1 { font-size: clamp(2.1rem, 5vw, 3.6rem); line-height: 1.08; margin: 0 0 22px; font-weight: 800; letter-spacing: -.02em; }
.rotator {
  background: linear-gradient(90deg, var(--accent), #ff9a3b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  border-right: 3px solid var(--accent); padding-right: 4px;
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { border-color: transparent; } }
.lede { color: var(--muted); font-size: 1.1rem; max-width: 560px; }
.cta-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
.cta-row.center { justify-content: center; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: 10px; font-weight: 600; font-size: .95rem;
  text-decoration: none; cursor: pointer; border: 1px solid transparent;
  font-family: var(--sans); transition: transform .15s, background .2s, border-color .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff5555; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.small { padding: 8px 14px; font-size: .85rem; }

.terminal {
  background: #0d1218; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.7), 0 0 0 1px rgba(255,59,59,.05);
  overflow: hidden;
}
.terminal-bar { display: flex; gap: 7px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); background: #0f151d; }
.terminal-bar span { width: 11px; height: 11px; border-radius: 50%; background: #3a4554; }
.terminal-bar span:nth-child(1) { background: #ff5f57; }
.terminal-bar span:nth-child(2) { background: #febc2e; }
.terminal-bar span:nth-child(3) { background: #28c840; }
.terminal-bar em { margin-left: auto; color: var(--muted); font-style: normal; font-size: .78rem; }
#terminal {
  margin: 0; padding: 18px; min-height: 330px; font-size: .82rem; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word; color: #c9d5e3;
}
#terminal .k { color: #ff7b72; } #terminal .s { color: #a5d6ff; } #terminal .c { color: #6e7b8b; }
#terminal .o { color: var(--green); } #terminal .p { color: var(--accent-2); }
#terminal .cursor { display: inline-block; width: 8px; height: 1em; background: var(--accent-2); vertical-align: text-bottom; animation: caret 1s steps(1) infinite; }

.scroll-hint { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: .8rem; text-decoration: none; z-index: 1; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(-50%, 6px); } }

/* SECTIONS */
.section { max-width: 1180px; margin: 0 auto; padding: 110px clamp(16px, 4vw, 48px) 40px; }
.section-head { max-width: 760px; margin-bottom: 40px; }
h2 { font-size: clamp(1.7rem, 3.5vw, 2.5rem); margin: 0 0 12px; letter-spacing: -.02em; line-height: 1.15; }
.section-head p:not(.eyebrow) { color: var(--muted); font-size: 1.05rem; margin: 0; }
h3 { margin: 0 0 12px; font-size: 1.05rem; }
h4 { margin: 0 0 4px; font-size: 1rem; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; transition: border-color .25s, transform .25s;
}
.card:hover { border-color: #3a4757; transform: translateY(-3px); }
.card p { color: var(--muted); margin: 0; font-size: .95rem; }

.stack-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li {
  font-family: var(--mono); font-size: .78rem; padding: 5px 10px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line); color: #c3cedb;
  transition: border-color .2s, color .2s;
}
.chips li:hover { border-color: var(--accent); color: var(--text); }

/* TELEMETRY */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: .72rem; color: var(--muted); letter-spacing: .06em;
}
.telemetry { display: grid; grid-template-columns: 380px 1fr; gap: 16px; }
.tele-left, .tele-right { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
#track { display: block; width: 100%; aspect-ratio: 1 / .85; }
#traces { display: block; width: 100%; height: 360px; }
.legend { display: flex; align-items: center; gap: 8px; padding: 0 14px 12px; font-size: .7rem; color: var(--muted); }
.ramp { flex: 1; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #3b82f6, #22d3ee, #facc15, #ff3b3b); }

.readouts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.readout { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.readout small { display: block; font-size: .62rem; color: var(--muted); letter-spacing: .08em; }
.readout { min-width: 0; padding: 10px 4px; }
.readout b { font-family: var(--mono); font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.readout em { font-style: normal; font-size: .65rem; color: var(--muted); margin-left: 2px; }
#r-delta.pos { color: var(--car-a); } #r-delta.neg { color: var(--car-b); }

.pedals { display: grid; grid-template-columns: 34px 1fr; gap: 8px 10px; align-items: center; }
.pedals label { font-size: .7rem; color: var(--muted); }
.bar { height: 10px; border-radius: 5px; background: var(--bg-2); border: 1px solid var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; }
.bar .thr { background: var(--green); } .bar .brk { background: var(--accent); }

.controls { display: flex; gap: 4px; }
.mini {
  font-family: var(--mono); font-size: .72rem; background: var(--bg-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; cursor: pointer;
}
.mini:hover { color: var(--text); }
.mini.active { color: var(--text); border-color: var(--accent-2); }

.sectors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sector { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-family: var(--mono); font-size: .8rem; }
.sector h5 { margin: 0 0 6px; font-size: .66rem; color: var(--muted); letter-spacing: .08em; font-weight: 400; }
.sector div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.sector .best { color: var(--purple); font-weight: 600; }
.insight { color: var(--muted); font-size: .85rem; margin-top: 18px; border-left: 2px solid var(--accent); padding-left: 12px; }

/* DATA */
.data-grid { display: grid; grid-template-columns: 1fr 1.1fr; gap: 24px; align-items: start; }
.pipeline { list-style: none; margin: 0; padding: 0; position: relative; }
.pipeline::before { content: ""; position: absolute; left: 19px; top: 10px; bottom: 10px; width: 2px; background: linear-gradient(var(--accent), var(--accent-2)); opacity: .5; }
.pipeline li { display: flex; gap: 16px; padding: 10px 0; position: relative; }
.pipeline p { margin: 0; color: var(--muted); font-size: .93rem; }
.step {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); font-size: .75rem; color: var(--accent-2); z-index: 1;
}
.heat-panel { padding-bottom: 6px; }
.heatmap { display: grid; gap: 3px; padding: 16px; font-family: var(--mono); font-size: .68rem; }
.heatmap .lab { color: var(--muted); display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; white-space: nowrap; }
.heatmap .lab.top { justify-content: center; padding: 0 0 4px; writing-mode: vertical-rl; transform: rotate(180deg); height: 64px; align-items: center; }
.heatmap .cell {
  aspect-ratio: 1; border-radius: 4px; display: grid; place-items: center; color: rgba(255,255,255,.85);
  cursor: crosshair; transform: scale(.2); opacity: 0;
  transition: transform .5s cubic-bezier(.2,.8,.2,1.2), opacity .5s, outline-color .15s;
  outline: 2px solid transparent; outline-offset: 1px;
}
.heatmap.shown .cell { transform: scale(1); opacity: 1; }
.heatmap .cell:hover, .heatmap .cell.hl { outline-color: var(--text); }
.heat-note { color: var(--muted); font-size: .78rem; padding: 0 16px 10px; margin: 0; min-height: 3.2em; }

/* PUZZLE */
.puzzle { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.puzzle-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg-btn { background: none; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 7px; cursor: pointer; font-family: var(--mono); font-size: .8rem; }
.seg-btn.active { background: var(--line); color: var(--text); }
.puzzle-stats { margin-left: auto; display: flex; gap: 16px; font-size: .8rem; color: var(--muted); }
.puzzle-stats b { color: var(--text); }
#grid { display: block; width: 100%; height: 420px; border-radius: 8px; touch-action: none; cursor: crosshair; }
.hint { color: var(--muted); font-size: .75rem; margin: 10px 0 0; text-align: center; }
.approach { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 20px; }

/* CONTACT */
.contact { text-align: center; padding-bottom: 100px; }
.contact p:not(.eyebrow) { color: var(--muted); }
footer { text-align: center; color: var(--muted); font-size: .75rem; padding: 30px 16px; border-top: 1px solid var(--line); }

/* REVEAL */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .7s ease, transform .7s ease; }
.reveal.in { opacity: 1; transform: none; }

/* RESPONSIVE */
@media (max-width: 1000px) {
  .hero-inner, .telemetry, .data-grid { grid-template-columns: 1fr; }
  .stack-grid, .approach { grid-template-columns: repeat(2, 1fr); }
  .tele-left { display: grid; grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .nav nav { display: none; }
  .stack-grid, .approach { grid-template-columns: 1fr; }
  .readouts, .sectors { grid-template-columns: repeat(2, 1fr); }
  #traces { height: 300px; }
  #grid { height: 340px; }
  #terminal { min-height: 280px; font-size: .74rem; }
  .puzzle-stats { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .rotator, .scroll-hint { animation: none; }
}
