/* Base layout, typography and shared controls. Section-specific styles live in css/sections/*.css. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 500 17px/1.45 var(--font);
  font-optical-sizing: auto;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, video, canvas, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus, #3355ff); outline-offset: 4px; border-radius: 6px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum", "ss01"; }

/* ---------- Sections: full-bleed colour slabs that stack with rounded tops ---------- */
.section {
  position: relative;
  padding: var(--section-pad) var(--gutter);
  border-radius: var(--radius-section) var(--radius-section) 0 0;
  margin-top: calc(var(--radius-section) * -1);
  background: var(--field, var(--paper));
  color: var(--section-ink, var(--ink));
  overflow: clip;
  isolation: isolate;
}
.section:first-of-type { margin-top: 0; border-radius: 0; }
.section[data-tone="dark"] { --section-ink: var(--on-dark); --focus: #ffd34d; color-scheme: dark; }
/* Until a section's module has rendered, reserve a viewport of height so lazy loading measures
   real distances (otherwise every empty section looks "near" at page load). */
.js [data-section]:not(.is-mounted) { min-height: 100vh; }
.section__inner { max-width: var(--max); margin-inline: auto; }
.section__head { max-width: 1100px; margin-bottom: clamp(40px, 6vh, 80px); }
.section__head--center { margin-inline: auto; text-align: center; }

.headline {
  margin: 0;
  font-size: var(--t-h2);
  font-weight: 750;
  line-height: 0.98;
  letter-spacing: -0.045em;
  text-wrap: balance;
}
.headline--display { font-size: var(--t-display); letter-spacing: -0.055em; }
.lead {
  margin: 0.6em 0 0;
  max-width: 34em;
  font-size: var(--t-lead);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.012em;
  color: var(--lead-ink, color-mix(in oklab, currentColor 72%, transparent));
  text-wrap: pretty;
}
.section__head--center .lead { margin-inline: auto; }
.eyebrow { margin: 0 0 13px; color: var(--ink-2); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.13em; }
.label { font-size: var(--t-label); font-weight: 650; letter-spacing: -0.005em; }
.small { font-size: var(--t-small); font-weight: 550; color: color-mix(in oklab, currentColor 70%, transparent); }

/* ---------- Vehicle marks ---------- */
.v-r1s { --c: var(--r1s); --c-ink: var(--r1s-ink); --c-glow: var(--r1s-glow); --c-soft: var(--r1s-soft); }
.v-r2  { --c: var(--r2);  --c-ink: var(--r2-ink);  --c-glow: var(--r2-glow);  --c-soft: var(--r2-soft); }
.vname { font-weight: 800; letter-spacing: -0.03em; color: var(--c-ink); }
[data-tone="dark"] .vname { color: var(--c-glow); }
.vdot { display: inline-block; width: 0.62em; height: 0.62em; border-radius: 50%; background: var(--c); vertical-align: 0.06em; margin-right: 0.38em; }

/* ---------- Pills, segmented controls, chips ---------- */
.pill {
  --bg: var(--white); --fg: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  min-height: 46px; padding: 0 20px;
  border: 0; border-radius: var(--radius-pill);
  background: var(--bg); color: var(--fg);
  font-size: var(--t-label); font-weight: 650; letter-spacing: -0.01em;
  box-shadow: var(--shadow-pop);
  transition: transform var(--dur-press) var(--ease-out), box-shadow var(--dur-press) var(--ease-out), background-color 200ms;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.pill:hover { transform: translateY(-1px); }
.pill:active { transform: translateY(1px) scale(0.96); box-shadow: var(--shadow-press); transition-duration: 60ms; }
.pill[aria-pressed="true"], .pill.is-active { --bg: var(--ink); --fg: var(--white); }
.pill--ghost { --bg: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
[data-tone="dark"] .pill { --bg: rgb(255 255 255 / 0.1); --fg: var(--on-dark); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.16); }
[data-tone="dark"] .pill[aria-pressed="true"], [data-tone="dark"] .pill.is-active { --bg: var(--on-dark); --fg: var(--ink); }
.pill svg { width: 18px; height: 18px; }
.pill:disabled { opacity: 0.45; cursor: default; transform: none; }

/* Segmented control. JS (js/lib/ui.js#segmented) springs the .seg__thumb to the pressed option. */
.seg {
  position: relative; display: inline-flex; gap: 2px; padding: 5px;
  border-radius: var(--radius-pill);
  background: rgb(13 15 28 / 0.08);
  isolation: isolate;
}
[data-tone="dark"] .seg { background: rgb(255 255 255 / 0.1); }
.seg__thumb {
  position: absolute; z-index: -1; top: 5px; bottom: 5px; left: 0; width: 0;
  border-radius: var(--radius-pill); background: var(--white); box-shadow: var(--shadow-press);
  pointer-events: none;
}
[data-tone="dark"] .seg__thumb { background: var(--on-dark); }
.seg button {
  min-height: 40px; padding: 0 18px; border: 0; border-radius: var(--radius-pill);
  background: transparent; font-size: var(--t-label); font-weight: 650; letter-spacing: -0.01em;
  color: color-mix(in oklab, currentColor 72%, transparent);
  transition: color 200ms, transform var(--dur-press) var(--ease-out);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.seg button[aria-pressed="true"] { color: var(--ink); }
.seg button:active { transform: scale(0.95); }
.seg:not(.has-thumb) button[aria-pressed="true"] { background: var(--white); box-shadow: var(--shadow-press); }

/* Vehicle configuration chips (shared by Range and Speed). */
.chip {
  display: inline-flex; align-items: center; gap: 0.45em;
  min-height: 42px; padding: 0 16px; border: 0; border-radius: var(--radius-pill);
  background: color-mix(in oklab, var(--c) 14%, transparent);
  color: var(--c-ink);
  font-size: var(--t-label); font-weight: 650; letter-spacing: -0.01em;
  box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--c) 35%, transparent);
  transition: transform var(--dur-press) var(--ease-out), background-color 200ms, color 200ms;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.chip:hover { background: color-mix(in oklab, var(--c) 22%, transparent); }
.chip:active { transform: scale(0.95); }
.chip[aria-pressed="true"] { background: var(--c); color: var(--white); box-shadow: 0 8px 18px -10px var(--c); }
[data-tone="dark"] .chip { color: var(--c-glow); }
[data-tone="dark"] .chip[aria-pressed="true"] { color: var(--white); }

/* ---------- Data status (EPA / estimate / target) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.35em;
  padding: 3px 9px 3px 8px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 700; letter-spacing: 0.01em; line-height: 1.2; white-space: nowrap;
  vertical-align: middle;
}
.badge--epa { background: var(--ink); color: var(--white); }
.badge--estimate { background: transparent; color: var(--status-estimate); box-shadow: inset 0 0 0 1.5px currentColor; }
.badge--target { background: transparent; color: var(--status-target); box-shadow: inset 0 0 0 1.5px currentColor; border: 0; background-image: none; }
.badge--target::before { content: ""; width: 7px; height: 7px; border-radius: 50%; border: 1.5px dashed currentColor; }
[data-tone="dark"] .badge--epa { background: var(--on-dark); color: var(--ink); }
[data-tone="dark"] .badge--estimate { color: #b9a8ff; }
[data-tone="dark"] .badge--target { color: #ff8ad8; }
/* Fills: colour = vehicle, texture = status. Apply with .v-r1s / .v-r2 on an ancestor. */
.fill--epa { background: var(--c); }
.fill--estimate { background: repeating-linear-gradient(-45deg, var(--c) 0 9px, color-mix(in oklab, var(--c) 55%, white) 9px 14px); }
.fill--target { background: color-mix(in oklab, var(--c) 18%, transparent); box-shadow: inset 0 0 0 2.5px var(--c); }

/* Source marker: tiny link into the reference drawer. */
.src {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; margin-left: 4px;
  border-radius: 10px; font-size: 11px; font-weight: 700; text-decoration: none; vertical-align: super;
  color: inherit; background: rgb(13 15 28 / 0.08);
}
[data-tone="dark"] .src { background: rgb(255 255 255 / 0.14); }
.src:hover { background: rgb(13 15 28 / 0.16); }

/* ---------- Reveal on entry (progressive: hidden only when JS is running) ---------- */
.js [data-reveal] { opacity: 0; transform: translateY(28px) scale(0.985); }
.js [data-reveal].is-in {
  opacity: 1; transform: none;
  transition: opacity 500ms var(--ease-out), transform 900ms var(--ease-spring);
  transition-delay: calc(var(--i, 0) * 70ms);
}
@media (prefers-reduced-motion: reduce) {
  .js [data-reveal] { opacity: 1; transform: none; }
}

/* ---------- Loading affordance used by media stages ---------- */
.loading-ring {
  --p: 0;
  width: 46px; height: 46px; border-radius: 50%;
  background: conic-gradient(currentColor calc(var(--p) * 1turn), rgb(13 15 28 / 0.1) 0);
  -webkit-mask: radial-gradient(circle, transparent 55%, #000 57%);
          mask: radial-gradient(circle, transparent 55%, #000 57%);
}

/* ---------- Presenter dock ---------- */
.dock {
  position: fixed; z-index: 50; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 6px;
  border-radius: var(--radius-pill);
  background: rgb(250 250 252 / 0.78);
  -webkit-backdrop-filter: blur(18px) saturate(1.6); backdrop-filter: blur(18px) saturate(1.6);
  box-shadow: 0 0 0 1px rgb(13 15 28 / 0.08), 0 18px 40px -18px rgb(13 15 28 / 0.45);
  max-width: calc(100vw - 24px); overflow-x: auto; scrollbar-width: none;
  transition: transform 500ms var(--ease-spring), opacity 300ms;
}
.dock::-webkit-scrollbar { display: none; }
.dock.is-hidden { transform: translate(-50%, 140%); opacity: 0; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .dock { transition: none; } }
.dock a {
  position: relative; display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px;
  border-radius: var(--radius-pill); text-decoration: none; white-space: nowrap;
  font-size: 14px; font-weight: 650; letter-spacing: -0.01em; color: var(--ink-2);
  transition: color 200ms, background-color 200ms, transform var(--dur-press) var(--ease-out);
}
.dock a:hover { background: rgb(13 15 28 / 0.06); }
.dock a:active { transform: scale(0.94); }
.dock a[aria-current="true"] { background: var(--ink); color: var(--white); }

/* ---------- Generic stage helpers ---------- */
.stack { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; font-size: var(--t-label); font-weight: 650; }
.legend .swatch { display: inline-block; width: 22px; height: 12px; border-radius: 6px; margin-right: 8px; vertical-align: -1px; }
.footnote { margin-top: 22px; font-size: var(--t-small); font-weight: 550; color: color-mix(in oklab, currentColor 64%, transparent); }
.footnote a { color: inherit; }

@media (max-width: 760px) {
  .dock a { padding: 0 11px; font-size: 13px; }
}
