:root {
  --bg: #0b101b;
  --bg-elev: #111827;
  --bg-card: #151e2e;
  --bg-code: #0a0f18;
  --border: #24324a;
  --border-strong: #334869;
  --text: #e6edf7;
  --text-muted: #94a6c2;
  --accent: #22d3ee;
  --accent-dim: rgba(34, 211, 238, 0.14);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.14);
  --red: #f43f5e;
  --red-dim: rgba(244, 63, 94, 0.16);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 16, 27, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand-badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(34, 211, 238, 0.35);
}
.topbar-links {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  flex-wrap: wrap;
}
.topbar-links a {
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
}
.topbar-links a:hover {
  color: var(--text);
  border-color: var(--border);
  text-decoration: none;
}
.topbar-links a.cta-pill {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(34, 211, 238, 0.4);
  font-weight: 600;
}

/* Layout */
.layout {
  max-width: 1320px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 32px;
  padding: 28px 24px 80px;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 76px;
  align-self: start;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
}
.progress-track {
  height: 6px;
  border-radius: 999px;
  background: #1e293b;
  overflow: hidden;
  margin-bottom: 14px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width 0.25s ease;
}
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.toc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.15s;
}
.toc-item:hover, .toc-item.active {
  background: rgba(34, 211, 238, 0.08);
  color: var(--text);
}
.toc-item input[type="checkbox"] {
  accent-color: var(--green);
  cursor: pointer;
  flex-shrink: 0;
}
.toc-item a {
  color: inherit;
  flex: 1;
  text-decoration: none;
  line-height: 1.35;
}
.env-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.env-box strong { color: var(--text); display: block; margin-bottom: 6px; }
.env-row { display: flex; justify-content: space-between; padding: 2px 0; gap: 8px; }
.env-row code { color: var(--accent); font-family: var(--mono); font-size: 11px; }

/* Main Content */
.content { min-width: 0; }

.hero {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.09), rgba(16, 185, 129, 0.05) 55%, rgba(17, 24, 39, 0.9));
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px 30px;
  margin-bottom: 28px;
}
.hero-kicker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.chip {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.chip.cyan { color: var(--accent); border-color: rgba(34, 211, 238, 0.4); }
.chip.green { color: var(--green); border-color: rgba(16, 185, 129, 0.4); }

.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(26px, 3.2vw, 36px);
  line-height: 1.18;
  letter-spacing: -0.03em;
}
.hero p {
  margin: 0 0 18px;
  color: #cbd5e1;
  font-size: 15.5px;
  max-width: 78ch;
}
.hero-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.metric-card {
  background: rgba(10, 15, 24, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.metric-val {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.metric-lbl {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Sections / Codelab Steps */
.step-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 28px;
  margin-bottom: 24px;
  scroll-margin-top: 76px;
}
.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.step-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
.step-num {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-dim);
  border: 1px solid rgba(34, 211, 238, 0.45);
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step-section h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.02em;
}
.step-time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-code);
  border: 1px solid var(--border);
}
.step-section h3 {
  margin: 20px 0 8px;
  font-size: 15.5px;
  color: #f1f5f9;
}
.step-section p { margin: 10px 0; color: #cbd5e1; }
.step-section ul, .step-section ol { color: #cbd5e1; padding-left: 20px; }
.step-section li { margin: 5px 0; }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(34, 211, 238, 0.09);
  color: #a5f3fc;
  padding: 1px 5px;
  border-radius: 4px;
}

/* Code Blocks */
.code-wrap {
  position: relative;
  margin: 14px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-code);
}
.code-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  background: #0f1726;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
}
.copy-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 9px;
  cursor: pointer;
}
.copy-btn:hover { background: var(--accent-dim); }
pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.55;
  color: #e2e8f0;
}
pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* Callouts */
.callout {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: 10px;
  border-left: 3px solid var(--accent);
  background: rgba(34, 211, 238, 0.07);
  font-size: 14px;
}
.callout.warn {
  border-left-color: var(--amber);
  background: var(--amber-dim);
}
.callout.good {
  border-left-color: var(--green);
  background: var(--green-dim);
}
.callout strong { color: var(--text); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 14px 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th, td {
  text-align: left;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
}
th {
  font-family: var(--mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: #0f1726;
}
td.num, th.num { text-align: right; font-family: var(--mono); }

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
}
.badge.ok { background: var(--green-dim); color: var(--green); }
.badge.dead { background: var(--red-dim); color: var(--red); }
.badge.late { background: var(--amber-dim); color: var(--amber); }

/* Architecture SVG container */
.diagram-box {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
  overflow-x: auto;
}
.diagram-box svg { width: 100%; height: auto; display: block; min-width: 620px; }

/* Screenshots Grid */
.shots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 16px;
  margin: 16px 0;
}
.shot-card {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.shot-card img { width: 100%; display: block; border-bottom: 1px solid var(--border); }
.shot-card figcaption { padding: 10px 12px; font-size: 12.5px; color: var(--text-muted); }

/* Interactive Stage Benchmark Explorer */
.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 14px 0;
}
.tab-btn {
  background: var(--bg-code);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(34, 211, 238, 0.55);
}

.hist-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 14px;
}
.hist-card {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.hist-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.hist-bars {
  display: grid;
  grid-template-columns: repeat(16, minmax(24px, 1fr));
  gap: 5px;
  align-items: end;
  height: 150px;
  padding: 10px 4px 4px;
  border-bottom: 1px solid var(--border);
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 4px;
}
.bar-count {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--text-muted);
  min-height: 13px;
}
.bar-rect {
  width: 100%;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  transition: height 0.25s ease;
}
.bar-rect.hot { background: var(--red); }
.bar-rect.warn { background: var(--amber); }
.hist-labels {
  display: grid;
  grid-template-columns: repeat(16, minmax(24px, 1fr));
  gap: 5px;
  margin-top: 6px;
}
.hist-labels span {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-muted);
  text-align: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  height: 52px;
}

/* Interactive WCRT Lab */
.lab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.field {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
}
.field label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field label output {
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 700;
}
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.preset-btn {
  background: #172133;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
}
.preset-btn:hover { border-color: var(--accent); color: var(--accent); }

.verdict-box {
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-code);
  margin-top: 14px;
}
.verdict-box.ok { border-color: rgba(16, 185, 129, 0.55); background: rgba(16, 185, 129, 0.08); }
.verdict-box.caution { border-color: rgba(245, 158, 11, 0.55); background: rgba(245, 158, 11, 0.08); }
.verdict-box.warn, .verdict-box.danger { border-color: rgba(244, 63, 94, 0.65); background: rgba(244, 63, 94, 0.1); }
.verdict-title {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.verdict-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.v-stat {
  background: rgba(11, 16, 27, 0.7);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.v-stat span { display: block; font-size: 11px; color: var(--text-muted); }
.v-stat strong { font-family: var(--mono); font-size: 15px; }

.step-done-bar {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.done-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--green);
  font-weight: 600;
}

.footer {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 18px 14px 60px; }
  .sidebar { position: static; }
  .step-section { padding: 20px 18px; }
  .hist-bars, .hist-labels { min-width: 480px; }
  .hist-scroll { overflow-x: auto; }
}
