/* One current gear inside the speedometer. No strip, extra card or controls. */
.speed-gauge .speed-gauge-readout > .gear-indicator {
  display: block;
  margin: 4px 0 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  min-height: 0;
  background: none;
  color: var(--gear-rpm-color, var(--accent, #79e8f1));
  transition: color .14s ease-out;
  font-family: var(--font-data, monospace);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.speed-gauge .speed-gauge-readout > .gear-indicator[hidden] { display: none; }
.gear-indicator-value {
  display: inline-block;
  transform-origin: center;
  text-shadow: 0 0 12px rgba(121, 232, 241, .22);
}
.gear-indicator-value[hidden] { display: none; }
.speed-gauge .gear-indicator[data-direction="down"] { color: var(--warn, #ffd18b); }
.speed-gauge .gear-indicator[data-mode="waiting"] { color: var(--text-dim, #a9bac6); }
.gear-indicator:not([data-direction="steady"])[data-pulse="0"] .gear-indicator-value {
  animation: gear-number-pop-a .32s ease-out;
}
.gear-indicator:not([data-direction="steady"])[data-pulse="1"] .gear-indicator-value {
  animation: gear-number-pop-b .32s ease-out;
}
/* Alternate names restart successive shifts without forced layout or timers. */
@keyframes gear-number-pop-a {
  0% { transform: translateY(2px) scale(.85); }
  45% { transform: translateY(-1px) scale(1.25); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes gear-number-pop-b {
  0% { transform: translateY(2px) scale(.85); }
  45% { transform: translateY(-1px) scale(1.25); }
  100% { transform: translateY(0) scale(1); }
}
@media (orientation: landscape) and (max-height: 700px) {
  .speed-gauge .speed-gauge-readout > .gear-indicator { font-size: 1rem; margin-top: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  .speed-gauge .speed-gauge-readout > .gear-indicator { transition: none !important; }
  .gear-indicator-value { animation: none !important; }
}
body.performance-lite .speed-gauge .speed-gauge-readout > .gear-indicator { transition: none !important; }
body.performance-lite .gear-indicator-value { animation: none !important; }

/* ============================================================================
   DESIGN TOKENS — instrument-grade
   ----------------------------------------------------------------------------
   This is a display read at a glance from the driver's seat, so the palette is
   built the way an instrument cluster is, not the way a landing page is:

   - Colour carries MEANING, not decoration. Cyan = running normally, amber =
     into the top of the range, red = at the ceiling. Nothing else is coloured.
   - Readouts are set in a monospaced face with tabular figures so digits keep
     a fixed width. A proportional font makes a live speed readout jitter
     sideways as the numbers change, which is exactly what you don't want to
     track from the corner of your eye.
   - Glow is used sparingly. Blurred text-shadow softens letter edges and
     lowers contrast; on a moving vehicle's display that costs legibility. The
     old treatment glowed nearly everything.
   - The background is a lifted neutral graphite rather than pure black. Pure
     black behind bright text on a phone backlight produces harsh halation at
     night.

   Legacy variable names are kept as aliases so every existing rule and the
   eco-HUD / paywall / studio stylesheets keep working untouched.
   ========================================================================== */
:root {
  --app-height: 100vh;
  /* Surfaces */
  --bg: #080a0d;
  --surface: rgba(18, 23, 30, 0.72);
  --surface-raised: rgba(27, 34, 44, 0.92);
  --hairline: rgba(150, 178, 196, 0.16);
  --hairline-strong: rgba(150, 178, 196, 0.32);

  /* Text */
  --text: #e6edf2;
  --text-dim: #93a4b2;
  --text-faint: #647686;

  /* Functional accents */
  --accent: #5fd3e4;   /* running normally */
  --warn: #f2a93b;     /* approaching the limit */
  --limit: #e2564d;    /* at the ceiling */
  --gas: #ff8a3d;      /* throttle / rev control */

  /* Type */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --font-data: ui-monospace, SFMono-Regular, "SF Mono", Menlo, "Roboto Mono", monospace;

  /* Spacing + radii */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 999px;

  /* Elevation */
  --shadow-panel: 0 10px 34px rgba(0, 0, 0, 0.45);

  /* ---- Legacy aliases (still referenced across the app) ---- */
  --cyan: var(--accent);
  --cyan-dim: var(--text-dim);
  --cyan-soft: rgba(95, 211, 228, 0.45);
  --panel-bg: var(--surface);
  --panel-border: var(--hairline);
  --favorite-active: #ffc94d;
  --dropdown-bg: #10161e;
}

/* ---- Daytime theme ----
   Same token names, daylight values. Every panel/text/border in the app reads
   these rather than hardcoded colours, so this re-themes the whole app.
   Applied to <body> by daynight.js, either from real sunrise/sunset for the
   driver's location or the manual override in Settings. Accents darken rather
   than just desaturating, because the night palette's luminous values have no
   contrast against white. */
body.theme-day {
  --bg: #f7f9fb;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-raised: #ffffff;
  --hairline: rgba(18, 44, 58, 0.14);
  --hairline-strong: rgba(18, 44, 58, 0.28);

  --text: #10222d;
  --text-dim: #4d6473;
  --text-faint: #7c909d;

  --accent: #00778f;
  --warn: #a86000;
  --limit: #b3241a;
  --gas: #b8501a;

  --cyan-soft: rgba(0, 119, 143, 0.3);
  --favorite-active: #9a6b00;
  --dropdown-bg: #ffffff;
  --shadow-panel: 0 10px 30px rgba(16, 34, 45, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#driveScene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
}

/* The scene selector uses the same low-contrast glass language as the HUD.
   It is intentionally compact: scene changes are a parked-car action, while
   the active scene remains obvious from the full-screen artwork itself. */
.scene-picker {
  --surface: rgba(10, 14, 20, 0.7);
  --surface-raised: rgba(26, 31, 39, 0.94);
  --hairline: rgba(218, 232, 241, 0.2);
  --hairline-strong: rgba(218, 232, 241, 0.34);
  --text: #f5f7fa;
  --text-dim: #aab8c4;
  --accent: #7ce7f4;
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: calc(100vw - 24px);
  padding: 4px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transform: translateX(-50%);
  overflow-x: auto;
  scrollbar-width: none;
}

.scene-picker::-webkit-scrollbar { display: none; }

.scene-picker-label {
  padding: 0 9px;
  color: var(--text-dim);
  font-family: var(--font-data);
  font-size: 0.54rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.scene-picker button {
  min-width: 62px;
  min-height: 30px;
  padding: 5px 10px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-data);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}

.scene-picker button:hover,
.scene-picker button:focus-visible {
  color: var(--text);
}

.scene-picker button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.scene-picker button[aria-pressed="true"] {
  color: #071014;
  background: #eafcff;
}

.scene-picker button:active {
  transform: scale(0.95);
}

.scene-picker button[data-drive-scene="starflyby"] {
  min-width: 86px;
}

.scene-picker button[data-drive-scene="aurora"] {
  min-width: 70px;
}

.scene-picker button[data-drive-scene="portal"] {
  min-width: 66px;
}

.scene-picker button[data-drive-scene="galaxy"] {
  min-width: 68px;
}

/* Fixed, permanently-minimized sidebar — same spot and size whether stopped
   or driving, so it never moves around and stays out of the way of the
   starfield.
   max-height/overflow is a safety net for short viewports (e.g. a car's
   built-in landscape display) so the sidebar scrolls internally instead of
   ever overlapping the bottom-anchored .speed-hud — see the "short
   landscape" media query further down for the actual size compaction that
   normally keeps this from being needed. */
main {
  position: fixed;
  top: 50%;
  left: 20px;
  transform: translateY(-50%);
  z-index: 1;
  /* The toggle sits at left:238px, so a stable 218px sidebar plus the 20px
     edge gap keeps the tab physically attached instead of drifting away
     when the collapsed settings make the panel's contents narrower. */
  width: 218px;
  max-width: 240px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  text-align: left;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


.subtitle,
.note {
  display: none;
}

.legal-footer {
  margin: 10px 0 0;
  font-size: 0.62rem;
  color: var(--cyan-dim);
  text-align: center;
}

.legal-footer a {
  color: var(--cyan-dim);
  text-decoration: underline;
}

.legal-footer a:hover {
  color: var(--cyan);
}

/* One compact, minimal panel instead of the old two stacked boxes — meant
   to recede into a corner rather than compete with the HUD, and can be
   hidden entirely via #panelToggle to leave a clean, uncluttered view. */
.control-strip {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--s4);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.voice-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

/* Hidden state-holders only now — Tesla's in-car browser doesn't reliably
   render native <select> option pickers, so these are driven programmatically
   by the custom dropdowns below instead of ever being shown/tapped directly. */
.visually-hidden-select {
  display: none;
}

/* ---------- Custom dropdown (replaces native <select> everywhere) ---------- */

.custom-select {
  position: relative;
  flex: 1;
  min-width: 0;
}

.custom-select-trigger {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  background: var(--surface-raised);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  color: var(--text);
  padding: var(--s3);
  font-size: 0.9rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.custom-select-trigger:hover {
  border-color: var(--accent);
}

/* Keep the current selection readable in the closed trigger rather than
   letting it collide with the chevron. */
.custom-select-trigger > span:first-child {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-arrow {
  color: var(--cyan-dim);
  font-size: 0.75rem;
  flex: 0 0 auto;
}

.custom-select-panel {
  position: absolute;
  top: calc(100% + var(--s2));
  left: 0;
  right: 0;
  z-index: 30;
  /* Taller than before (260px) — rows below are also bigger now, so this
     keeps roughly the same number of options visible at once instead of
     scrolling sooner. */
  /* Grow past the trigger so long names fit on one line. The trigger is only
     260px, which was clipping or wrapping "Supercharged V8 Howl" and friends,
     and the SHIFT/CUSTOM tags were taking a bite out of that too. Capped to
     the viewport so it can never run off screen. */
  min-width: 100%;
  width: max-content;
  max-width: min(92vw, 420px);
  /* left-anchored by default; app.js flips this when it would overflow */
  max-height: min(60vh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--dropdown-bg);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-panel);
  padding: var(--s1);
}

.custom-select-group-label {
  font-family: var(--font-data);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: var(--s3) var(--s3) var(--s1);
}

/* The name gets all remaining space and never wraps; the tags never shrink
   it. Previously label and tag were equal flex citizens, so a long name lost
   room to a short badge. */
.custom-select-option-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
}

.custom-select-option .shift-tag,
.custom-select-option .custom-tag {
  flex: 0 0 auto;
}

/* Group headings stay put while the list scrolls, so you always know whether
   you are looking at engines or sci-fi. With 21 voices the heading otherwise
   scrolls away immediately and every row looks the same. */
.custom-select-group-label {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--dropdown-bg);
}

/* 46px rows — comfortably above the 44px touch-target minimum, since this
   is the control reached for most often while driving. */
/* Flipped by app.js when a left-anchored panel would run off the screen. */
.custom-select-panel.anchor-right {
  left: auto;
  right: 0;
}

/* app.js chooses the vertical anchor after measuring the actually visible
   viewport. This matters most on phones: the driving picker normally opens
   upward, while the paywall picker normally opens downward. */
.custom-select-panel.anchor-up {
  top: auto;
  bottom: calc(100% + var(--s2));
}

.custom-select-panel.anchor-down {
  top: calc(100% + var(--s2));
  bottom: auto;
}

.custom-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  /* Tag sits hard right, name takes the rest — see the label rule below. */
  min-height: 46px;
  padding: var(--s3) var(--s4);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}

.custom-select-option:hover {
  background: var(--surface-raised);
}

.custom-select-option.selected {
  background: var(--surface-raised);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}

.favorite-btn {
  flex: 0 0 auto;
  width: 44px;
  min-height: 44px;
  background: var(--surface-raised);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  color: var(--text-dim);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.favorite-btn.active {
  color: var(--favorite-active);
  border-color: var(--favorite-active);
}


/* Primary control. Sized well past the 44px minimum touch target because
   it is pressed in a vehicle, and the running state is shown by a solid fill
   change rather than a pulsing glow — a state you read instantly beats one
   you have to watch for a moment to interpret. */
#startBtn {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--surface-raised);
  color: var(--accent);
  font-family: var(--font-data);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  font-weight: 700;
  box-shadow: var(--shadow-panel);
  transition: transform 0.12s ease, background 0.2s ease, color 0.2s ease;
  margin: 0 auto;
  display: block;
  cursor: pointer;
}

#startBtn:active {
  transform: scale(0.96);
}

#startBtn.running {
  background: var(--accent);
  color: #05171b;
  border-color: var(--accent);
}

/* Orange/"gas pedal" accent — deliberately distinct from the cyan Start
   button so the two are never confused at a glance. */
#revBtn {
  width: 100%;
  min-height: 48px;
  margin: var(--s3) auto 0;
  padding: var(--s3) 0;
  border-radius: var(--r-pill);
  border: 1px solid var(--gas);
  background: var(--surface-raised);
  color: var(--gas);
  font-family: var(--font-data);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  font-weight: 700;
  cursor: pointer;
  display: block;
  transition: all 0.1s ease;
  /* A held press is the whole interaction here — this stops a long hold from
     scrolling the page, selecting text, or popping a context menu instead. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#revBtn:active:not(:disabled) {
  transform: scale(0.97);
  background: var(--gas);
  color: #1c0c02;
}

#revBtn:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}

.status {
  font-size: 0.7rem;
  text-align: left;
}

.status .row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
}

.status .row:last-child { border-bottom: none; }

.status .row span:first-child {
  color: var(--cyan-dim);
}

.status .row span:last-child {
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
}

/* Tucks the secondary sliders (Volume/Exterior Boost/Max Speed) away by
   default so the default view is just logo + Start/Rev + sound picker —
   a cleaner, more filmable default without removing any functionality
   (the existing #panelToggle full-hide button still works independently). */
.settings-toggle {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: 1px solid var(--hairline);
  color: var(--cyan-dim);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  min-height: 44px;
}

.settings-toggle:hover,
.settings-toggle[aria-expanded="true"] {
  color: var(--cyan);
  border-color: var(--accent);
}

.controls {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

/* .controls[hidden], not just [hidden] — needed to actually beat the plain
   .controls rule's own display:flex above (equal specificity, so without
   this the hidden attribute alone does nothing and #settingsToggle's toggle
   is invisible). */
.controls[hidden] {
  display: none;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.62rem;
  color: var(--cyan-dim);
  line-height: 1.3;
}

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

.controls label.exterior-boost-toggle {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.controls label.exterior-boost-toggle input[type="checkbox"] {
  accent-color: var(--cyan);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.settings-group,
.advanced-settings {
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: rgba(2, 18, 28, 0.5);
}

.settings-group-title,
.settings-heading-row {
  color: var(--cyan-dim);
  font-size: 0.64rem;
}

.settings-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.settings-value {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.range-end-labels {
  display: flex;
  justify-content: space-between;
  margin-top: -3px;
  color: var(--cyan-dim);
  font-size: 0.54rem;
}

.settings-help {
  margin: 6px 0 0;
  color: var(--cyan-dim);
  font-size: 0.55rem;
  line-height: 1.4;
}

.segmented-setting {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 7px;
  padding: 3px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.38);
}

.segmented-setting button {
  min-width: 0;
  min-height: 40px;
  padding: 6px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--cyan-dim);
  font: inherit;
  font-size: 0.58rem;
  cursor: pointer;
}

.segmented-setting button.active {
  background: var(--accent);
  color: #021218;
  box-shadow: 0 0 12px rgba(24, 226, 255, 0.24);
}

.controls label.settings-switch {
  flex-direction: row;
  align-items: flex-start;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: rgba(2, 18, 28, 0.5);
  cursor: pointer;
}

.settings-switch input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  flex: 0 0 auto;
  accent-color: var(--cyan);
}

.settings-switch span {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-switch strong {
  color: var(--cyan);
  font-size: 0.63rem;
  font-weight: 600;
}

.settings-switch small {
  color: var(--cyan-dim);
  font-size: 0.54rem;
  line-height: 1.4;
}

.advanced-settings {
  padding: 0;
  overflow: hidden;
}

.advanced-settings summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--cyan-dim);
  font-size: 0.64rem;
  cursor: pointer;
  list-style: none;
}

.advanced-settings summary::-webkit-details-marker { display: none; }

.advanced-settings summary::after {
  content: '+';
  margin-left: auto;
  color: var(--cyan);
  font-size: 1rem;
}

.advanced-settings[open] summary::after { content: '−'; }

.advanced-settings-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 10px 10px;
}

.advanced-settings-body .settings-switch {
  padding: 0;
  border: 0;
  background: transparent;
}

.sensor-quality-row {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
  color: var(--cyan-dim);
  font-size: 0.6rem;
}

.gps-quality {
  padding: 3px 8px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-pill);
  font-family: var(--font-data);
  font-size: 0.55rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.gps-quality-good { color: var(--eco-green, #4ed9a4); }
.gps-quality-fair { color: var(--warn, #f2a93b); }
.gps-quality-weak { color: var(--limit, #e2564d); }
.gps-quality-waiting { color: var(--cyan-dim); }

/* Day/Auto/Night picker — same segmented-button look as the eco HUD's own
   HUD/Minimal/Analysis picker, inserted by daynight.js. */
.theme-toggle {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.theme-toggle-label {
  font-size: 0.62rem;
  color: var(--cyan-dim);
}

.theme-toggle-buttons {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 2px;
}

.theme-toggle-buttons button {
  flex: 1;
  border: none;
  background: none;
  color: var(--cyan-dim);
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
}

.theme-toggle-buttons button.active {
  background: var(--surface-raised);
  color: var(--cyan);
}

body.theme-day .theme-toggle-buttons button.active {
  background: rgba(0, 137, 168, 0.16);
}

/* Minimize/restore control. On landscape displays this mirrors the labelled
   ECO tab on the opposite edge: the name makes its purpose obvious and the
   taller hit area is much easier to use on an in-car touchscreen. Portrait
   screens turn the same control into a horizontal action pill. */
#panelToggle {
  position: fixed;
  top: 50%;
  left: 238px;
  transform: translateY(-50%);
  z-index: 2;
  width: 48px;
  height: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 0;
  overflow: hidden;
  border-radius: 0 14px 14px 0;
  border: 1px solid var(--hairline-strong);
  border-left: 0;
  background: var(--surface-raised);
  color: var(--accent);
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-panel), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: left 0.25s ease, border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#panelToggle:hover,
#panelToggle:focus-visible {
  border-color: var(--accent);
  color: var(--text);
}

#panelToggle:active {
  background: var(--surface);
}

.panel-toggle-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.22s ease;
}

.panel-toggle-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--font-data);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--text-dim);
  line-height: 1;
  white-space: nowrap;
}

.panel-toggle-text {
  display: none;
  font-family: var(--font-data);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#panelToggle.is-collapsed .panel-toggle-icon {
  transform: rotate(180deg);
}

body.panel-hidden main {
  display: none;
}

body.panel-hidden #panelToggle {
  left: 12px;
  border-radius: 14px;
  border-left: 1px solid var(--hairline-strong);
}

/* ---- Paywall: always light, independent of the driving HUD's day/night
   theme ---- */
/* The embedded Stripe pricing table is permanently a white card (Stripe
   renders it in a closed shadow DOM — only outer sizing is reachable from
   here), so a dark paywall card cuts jarringly into it. People are also
   just more used to seeing payment/checkout screens on a light background
   (Stripe, Apple, banks all default light) — reads as more "standard" right
   at the moment you're asking for a card number. Scoped to #paywallOverlay
   itself, not body.theme-day, since this should hold regardless of whether
   the driving HUD is currently in day or night mode — the paywall is a
   different context with a different job, not just "whatever theme happens
   to be active right now." Custom properties inherit down the DOM tree, so
   redefining them here re-themes every descendant (card, Test Me panel,
   pricing tiers, dropdowns, etc.) without touching each one individually. */
#paywallOverlay {
  --cyan: #0089a8;
  --cyan-dim: #4d7480;
  --cyan-soft: rgba(0, 137, 168, 0.35);
  --text: #0d2b3a;
  --panel-bg: rgba(255, 255, 255, 0.97);
  --panel-border: rgba(0, 137, 168, 0.3);
  --favorite-active: #b8860b;
  --dropdown-bg: #f4fbff;
}

#paywallOverlay .paywall-card,
#paywallOverlay .test-me-panel {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

/* Sound preview picker gets the same bold dark-navy accent card treatment
   as the main app's Sound picker in the day theme, for consistency. */
#paywallOverlay .custom-select-trigger {
  background: #0d2b3a;
  border-color: #0d2b3a;
  color: #eafffa;
}

#paywallOverlay .custom-select-arrow {
  color: rgba(234, 255, 250, 0.7);
}

#paywallOverlay .test-me-circle-rev {
  background: #ff7a1a;
  border-color: #ff7a1a;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(255, 122, 26, 0.35);
}

#paywallOverlay .test-me-circle-rev:active {
  background: #e56a10;
  border-color: #e56a10;
  box-shadow: 0 4px 18px rgba(255, 122, 26, 0.45);
}

/* Paywall — fail-closed: covers everything until verify-access confirms an
   active subscription, then body.unlocked hides it. */
html.preview-ui #paywallOverlay {
  display: none !important;
}

#paywallOverlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  /* flex-start, not center — the embedded Stripe pricing table (plus its
     product description) can be taller than the viewport, and centering an
     overflowing flex item clips both the top and bottom with no reliable
     way to scroll to either. Starting at the top and allowing vertical
     scroll guarantees nothing is ever unreachable. */
  align-items: flex-start;
  justify-content: center;
  /* wrap + gap: the Test Me circle is a flex sibling of .paywall-card, not
     nested inside it — wraps below the card automatically on narrow
     screens since the card's own width:100% leaves no room beside it. */
  flex-wrap: wrap;
  gap: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* A light veil regardless of whatever's animating behind it (dark
     Starfield or the white/red daySky, depending on the driving HUD's own
     theme) — see the "always light" block above. Not fully opaque: still
     lets a hint of that motion read through the margins around the card,
     rather than a flat dead white. */
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  text-align: center;
  padding: 24px;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
}

#paywallOverlay .paywall-card {
  max-width: 480px;
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 32px 28px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.paywall-pricing {
  margin: 0 0 20px;
}

.paywall-pricing-title {
  color: var(--cyan);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0 0 12px;
}

.paywall-pricing-tiers {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
}

.paywall-tier {
  flex: 1;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}

.paywall-tier-best {
  border-color: var(--eco-green, #34ffb0);
  background: rgba(52, 255, 176, 0.08);
  box-shadow: 0 0 24px rgba(52, 255, 176, 0.2);
}

.paywall-tier-badge {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--eco-green, #34ffb0);
  color: #04140c;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.paywall-tier-label {
  color: var(--cyan-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.paywall-tier-price {
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 800;
}

.paywall-tier-period {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--cyan-dim);
}

.paywall-tier-sub {
  color: var(--eco-green, #34ffb0);
  font-size: 0.68rem;
  font-weight: 600;
}

.paywall-pricing-reassure {
  color: var(--cyan-dim);
  font-size: 0.78rem;
  line-height: 1.5;
  margin: 0 0 10px;
}

.paywall-competitor {
  color: var(--cyan-dim);
  font-size: 0.72rem;
  line-height: 1.5;
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.paywall-logo {
  display: block;
  width: 100%;
  max-width: 220px;
  height: auto;
  margin: 0 auto 16px;
}

#paywallOverlay h2 {
  color: var(--cyan);
  letter-spacing: 0.16em;
  font-size: 1.2rem;
  margin: 0 0 10px;
  text-shadow: 0 0 16px var(--cyan-soft);
}

#paywallOverlay p {
  color: var(--cyan-dim);
  font-size: 0.85rem;
  margin: 0 0 20px;
  line-height: 1.5;
}

.paywall-features {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paywall-features li {
  color: var(--cyan-dim);
  font-size: 0.85rem;
  line-height: 1.5;
  padding-left: 22px;
  position: relative;
}

.paywall-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--eco-green, #34ffb0);
  font-weight: 700;
}

.paywall-features li strong {
  color: var(--cyan);
  font-weight: 600;
}

/* Deliberately more prominent than the .link-btn/restore-access treatment
   below the pricing table — this is a real, glanceable CTA, not a quiet
   afterthought link. */
.affiliate-banner {
  display: block;
  margin: 0 0 var(--s5);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  border: 1px solid var(--hairline-strong);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s ease;
}

.affiliate-banner:hover {
  border-color: var(--accent);
}

.affiliate-banner-sub {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--cyan-dim);
}

/* Used in the compact driving-screen sidebar (main is only 240px wide),
   same branding as the paywall's banner just scaled down to fit. */
.affiliate-banner-compact {
  margin: 10px 0 0;
  padding: 10px 12px;
  font-size: 0.8rem;
  border-radius: 10px;
}

.affiliate-banner-compact .affiliate-banner-sub {
  font-size: 0.62rem;
}

/* Stripe renders this inside a closed Shadow DOM, so only outer sizing is
   reachable from here — colors/fonts inside the widget itself can only be
   changed from the pricing table's "Branding" settings in the Stripe
   Dashboard, not from this stylesheet. */
stripe-pricing-table {
  display: block;
  width: 100%;
  margin: 4px 0 4px;
}

#paywallStatus {
  margin-top: 14px;
  margin-bottom: 0;
  font-size: 0.75rem;
  min-height: 1em;
}

body.unlocked #paywallOverlay {
  display: none;
}

/* Sits outside the subscription card entirely, as its own flex sibling of
   .paywall-card (see the flex-wrap/gap on #paywallOverlay above) — the
   logo/feature showcase plus the sound preview, so the card itself can stay
   short and focused on pricing/subscribing without scrolling. */
.test-me-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  /* Centered against the row's height (i.e. the card's height) rather than
     anchored to the top — the card is tall enough that top-anchoring left
     Test Me floating up by the logo instead of near Subscribe. Only this
     panel is re-centered, not the card itself, so the card's own
     top-anchored/scrollable behavior (needed for tall content) is untouched. */
  align-self: center;
  width: 280px;
  max-width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 24px 20px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

/* .custom-select normally lives in a flex row (e.g. .voice-row) where
   flex:1 sizes it against siblings — here it's alone in a centered flex
   column, so it needs its own explicit width. */
.preview-select {
  width: min(220px, 100%);
  margin-bottom: 10px;
}

.preview-sound-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.preview-sound-choice #previewSoundLabel {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Social proof is limited to the paywall preview: it does not reorder or
   decorate the regular in-app sound picker. */
.popular-tag {
  flex: 0 0 auto;
  font-family: var(--font-data);
  font-size: 0.54rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #04140c;
  background: var(--eco-green, #4ed9a4);
  border-radius: var(--r-pill);
  padding: 3px 7px;
}

.popular-tag[hidden] {
  display: none;
}

/* Same circular treatment as the real #startBtn — a deliberate visual
   echo, since this is previewing exactly what pressing Start will sound
   like once they're actually in the app. */
.test-me-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 0 auto 10px;
}

.test-me-circle {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--surface-raised);
  color: var(--accent);
  font-family: var(--font-data);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  font-weight: 700;
  box-shadow: var(--shadow-panel);
  transition: transform 0.12s ease, background 0.2s ease, color 0.2s ease;
  margin: 0;
  cursor: pointer;
}

.test-me-circle:active {
  transform: scale(0.96);
}

.test-me-circle.playing {
  background: var(--accent);
  color: #05171b;
}

/* Orange, matching the real #revBtn's color language elsewhere in the app —
   a held press is the whole interaction, so touch-action/user-select are
   locked down the same way #revBtn's own comment explains: a long hold
   shouldn't scroll the page, select text, or pop a context menu. */
.test-me-circle-rev {
  width: 68px;
  height: 68px;
  border-color: rgba(255, 130, 40, 0.55);
  background: radial-gradient(circle at 50% 40%, rgba(255, 130, 40, 0.16), rgba(255, 130, 40, 0.03));
  color: #ff9a52;
  box-shadow: 0 0 22px rgba(255, 130, 40, 0.35), inset 0 0 18px rgba(255, 130, 40, 0.14);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.test-me-circle-rev:active {
  transform: scale(0.94);
  background: radial-gradient(circle at 50% 40%, rgba(255, 130, 40, 0.45), rgba(255, 130, 40, 0.12));
  box-shadow: 0 0 30px rgba(255, 130, 40, 0.55);
}

.preview-caption {
  color: var(--cyan-dim);
  font-size: 0.7rem;
  font-style: italic;
  margin: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--cyan-dim);
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px 10px;
  min-height: 44px;
  margin-top: 14px;
  display: block;
}

.link-btn:hover {
  color: var(--cyan);
}

/* Entry point into the Sound Studio tool — a real, on-brand button (not the
   understated .link-btn treatment) since it's a customer-facing feature now,
   not a diagnostic/account link. */
.studio-link {
  display: block;
  text-align: center;
  background: var(--surface-raised);
  border: 1px solid var(--hairline-strong);
  color: var(--accent);
  border-radius: var(--r-md);
  min-height: 44px;
  padding: var(--s3);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.studio-link:hover {
  border-color: var(--accent);
}

#restoreForm {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

#restoreForm[hidden] { display: none; }

#restoreForm input[type="email"] {
  flex: 1;
  min-width: 0;
  background: var(--surface-raised);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  min-height: 44px;
  padding: var(--s2) var(--s3);
  font-size: 0.9rem;
}

#restoreForm button {
  background: var(--surface-raised);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--r-sm);
  min-height: 44px;
  padding: var(--s2) var(--s4);
  cursor: pointer;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

#manageSubBtn {
  margin: 14px auto 0;
}

/* ---------- HUD: badge + speedometer cluster ---------- */

.mode-badge {
  --surface: rgba(8, 13, 19, 0.72);
  --panel-bg: var(--surface);
  --panel-border: rgba(200, 221, 233, 0.2);
  --text-dim: #a9bac6;
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text-dim);
  font-family: var(--font-data);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  font-weight: 600;
  text-transform: uppercase;
  box-shadow: var(--shadow-panel);
}

.speed-hud {
  --surface: rgba(8, 13, 19, 0.72);
  --surface-raised: rgba(24, 31, 40, 0.94);
  --hairline: rgba(200, 221, 233, 0.2);
  --hairline-strong: rgba(200, 221, 233, 0.36);
  --text: #f4f8fb;
  --text-dim: #a9bac6;
  --text-faint: #718796;
  --accent: #6ce3f2;
  --warn: #ffc45c;
  --limit: #ff6258;
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 28px;
}

/* Un-groups back into plain flex siblings of .speed-gauge on the wide
   layout — order below reproduces the original Sound / Gauge / RPM
   sequence exactly, so this markup change is a no-op here. Mobile
   overrides this to a real box (see the max-width:899px block) so Sound
   and RPM can be laid out as their own row under the gauge. */
.speed-hud-secondary {
  display: contents;
}

.drive-center-stack {
  order: 2;
}

.speed-hud-secondary .soundboard {
  order: 1;
}

.speed-hud-secondary .speed-hud-side:not(.soundboard) {
  order: 3;
}

.speed-hud-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 74px;
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.hud-side-title {
  font-family: var(--font-data);
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.hud-side-value {
  font-family: var(--font-data);
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

/* Fixed-scale RPM rail. Unlike the former auto-scaling sparkline, this keeps
   idle and redline in stable places, so an upshift reads as a real drop rather
   than the graph quietly stretching its own axis to hide it. */
.rpm-panel {
  min-width: 300px;
  width: 300px;
  gap: 5px;
  overflow: hidden;
}

.rpm-panel-heading {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.rpm-rail {
  position: relative;
  width: 100%;
  height: 8px;
  border-radius: var(--r-pill);
  overflow: hidden;
  background: rgba(132, 157, 176, 0.2);
}

.rpm-rail-redline,
.rpm-rail-fill {
  position: absolute;
  inset-block: 0;
}

.rpm-rail-redline {
  left: 82%;
  right: 0;
  background: rgba(226, 86, 77, 0.26);
}

.rpm-rail-fill {
  left: 0;
  width: 0;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(95, 211, 228, 0.5);
  transition: width 0.08s linear, background 0.18s ease;
}

.rpm-panel.is-near-redline .rpm-rail-fill {
  background: var(--warn);
  box-shadow: 0 0 14px rgba(242, 169, 59, 0.55);
}

.rpm-panel.is-at-redline .rpm-rail-fill {
  background: var(--limit);
  box-shadow: 0 0 16px rgba(226, 86, 77, 0.7);
}

.rpm-trace {
  display: block;
  width: 100%;
  height: 54px;
  margin-top: 1px;
}

.rpm-scale {
  width: 100%;
  display: flex;
  justify-content: space-between;
  color: var(--text-faint);
  font-family: var(--font-data);
  font-size: 0.46rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
}

@keyframes rpm-shift-pulse {
  0% { border-color: var(--hairline); transform: translateY(0); }
  30% { border-color: var(--warn); transform: translateY(3px); }
  100% { border-color: var(--hairline); transform: translateY(0); }
}

.rpm-panel.shift-pulse {
  animation: rpm-shift-pulse 0.36s ease-out;
}

/* Small vertical "MPG-style" gauge — green zone at the bottom (gentle
   inputs), climbing through yellow to red the harder you get on the gas or
   brake. Narrow/tall rather than the RPM trace's wide/short shape, so it
   reads as a level bar rather than a scrolling line. */
.driving-style-bar {
  display: block;
  width: 26px;
  height: 72px;
  margin-top: 2px;
  border-radius: 4px;
}

/* Compact sound picker living right next to the speedometer (replaces the
   old sidebar Linear/Manual boxes entirely) — same custom-select machinery,
   just sized down to fit a HUD pill and opening upward since this whole
   cluster sits low on the screen. */
.speed-hud-side.soundboard {
  /* Wider now that MPG Style no longer shares this row with Sound/RPM —
     the trigger/options below were also deliberately shrunk smaller than
     every other dropdown in the app (e.g. the eco HUD's vehicle picker),
     which was the real source of "too compact," not just this box's width. */
  min-width: 260px;
  gap: 8px;
}

.soundboard .voice-row {
  width: 100%;
}

/* Previously smaller than the base .custom-select-trigger — this was the
   main reason the sound picker specifically felt cramped compared to every
   other dropdown in the app. Now bigger than the base default, not just
   matching it, since this is the one people reach for constantly while
   driving. */
.soundboard-select .custom-select-trigger {
  padding: 12px 14px;
  font-size: 0.95rem;
}

.soundboard-select .custom-select-panel {
  top: auto;
  bottom: calc(100% + 6px);
}

.soundboard .favorite-btn {
  width: 46px;
  font-size: 1.3rem;
}

/* Inline tag marking the shifting (manual) sounds now that they're mixed
   into one list instead of living in their own separate box. */
.shift-tag {
  flex: 0 0 auto;
  font-family: var(--font-data);
  font-size: 0.56rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gas);
  border: 1px solid var(--gas);
  border-radius: var(--r-pill);
  padding: 2px 7px;
  opacity: 0.85;
}

/* Marks a customer's own Sound Studio creation in the sound picker list. */
.custom-tag {
  flex: 0 0 auto;
  font-family: var(--font-data);
  font-size: 0.56rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--r-pill);
  padding: 2px 7px;
  opacity: 0.85;
}

.speed-gauge {
  position: relative;
  width: 190px;
  height: 190px;
  flex: 0 0 auto;
}

/* Brief glow/scale punch on hard acceleration and lift-off — a camera-
   friendly visual jolt tied to the same moments the audio already accents
   (triggerKick/fireLiftoff in app.js), not a speed-driven effect. */
@keyframes gauge-kick-pulse {
  0% { filter: drop-shadow(0 0 0 var(--cyan-soft)); transform: scale(1); }
  25% { filter: drop-shadow(0 0 20px var(--cyan-soft)); transform: scale(1.03); }
  100% { filter: drop-shadow(0 0 0 var(--cyan-soft)); transform: scale(1); }
}

.speed-gauge.kick-pulse {
  animation: gauge-kick-pulse 0.45s ease-out;
}

.speed-gauge-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg); /* start the fill from the top, going clockwise */
}

/* ---------- Instrument face ----------
   Ticks, track, limit zone and fill are drawn as concentric layers so the
   ring reads as a graduated scale you can judge at a glance, rather than a
   featureless progress arc. Tick geometry is generated once by
   drawGaugeTicks() in app.js. */
.gauge-ticks .gauge-tick {
  stroke: var(--hairline-strong);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.gauge-ticks .gauge-tick-major {
  stroke: var(--text-faint);
  stroke-width: 2.5;
}

.gauge-track {
  fill: none;
  stroke: var(--hairline);
  stroke-width: 10;
}

/* The top slice of the range, painted where a tachometer paints its redline
   so you can see the ceiling coming before you reach it. Dash geometry is set
   by initGaugeFace() in app.js from GAUGE_LIMIT_START. */
.gauge-limit {
  fill: none;
  stroke: var(--limit);
  stroke-width: 10;
  opacity: 0.34;
}

.gauge-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: butt;
  stroke-dasharray: 502.65; /* 2 * pi * r(80) — kept in sync with GAUGE_CIRCUMFERENCE in app.js */
  stroke-dashoffset: 502.65; /* empty at rest; app.js animates this with speed */
  transition: stroke 0.25s ease;
}

.speed-gauge-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* Tabular monospaced figures: digits keep a fixed width, so a live speed
   readout counts up in place instead of shifting sideways as the numbers
   change — the difference between glanceable and distracting at speed. */
.speed-gauge-value {
  font-family: var(--font-data);
  font-size: 3.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
}

/* Live gear from the pulse engine's gearbox. */
.speed-gauge-gear {
  margin-top: var(--s2);
  font-family: var(--font-data);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--accent);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  min-height: 20px;
}

.speed-gauge-gear[hidden] { display: none; }

.speed-gauge-unit {
  font-family: var(--font-data);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  color: var(--text-dim);
  margin-top: var(--s1);
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 3px 10px;
  min-width: 44px;
  min-height: 44px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.speed-gauge-unit:hover,
.speed-gauge-unit:focus-visible {
  color: var(--accent);
  border-color: var(--hairline-strong);
  background: var(--surface-raised);
}

.speed-gauge-unit:active {
  transform: scale(0.92);
}

/* ---------- Mobile / portrait layout ----------
   Below 900px wide this is treated as a phone, not Tesla's wide touchscreen
   — a genuinely different arrangement, not just a scaled-down version of
   the wide one. The sidebar becomes a collapsible bottom sheet instead of a
   floating left-side box (which on a narrow screen would either overlap the
   HUD or eat most of the available width), and the HUD wraps into a
   stacked cluster — gauge on top, sound picker and RPM side by side
   underneath it — instead of the wide 3-column row that only really works
   with horizontal room to spare. */
/* This used to key off max-width:899px alone, which misclassified any
   short-but-wide landscape screen under 900px (a car's built-in touchscreen,
   e.g. ~773px wide) as "mobile" and gave it the portrait phone's stacked
   bottom-sheet treatment — wrong layout for a wide landscape display.
   Orientation is the real signal for "is this a narrow phone screen":
   the phone use case in the README is always portrait (mounted on a dash),
   while both the car's built-in display and desktop are landscape. A short
   *landscape* screen (the car display) is handled separately below by
   scaling the normal wide layout down, not by swapping to this one. */
@media (orientation: portrait) {
  .speed-hud {
    top: 88px;
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: column;
    width: 100%;
    max-width: 360px;
    gap: 8px;
    padding: 0 12px;
    /* Defensive bound: main's own bottom sheet reserves the bottom 50vh of
       the screen (see .control-strip's max-height below) — without a limit
       here, .speed-hud (anchored at a fixed top:88px with unbounded height)
       can grow tall enough on some devices/content combos to run straight
       into that sheet and visually overlap it (seen on an iPhone once the
       MPG Style box pushed this row's height past the available room).
       Scrolling internally here is a much smaller UX cost than overlapping
       the logo/controls beneath it. */
    max-height: calc(50vh - 88px - 8px);
    overflow-y: auto;
  }

  .speed-gauge {
    order: 1;
    width: 145px;
    height: 145px;
    /* No flex-basis/flex-grow here — this is what caused the gauge to be
       force-stretched to the full row width earlier (flex-basis beats an
       explicit width), which in turn threw off the row below it. A plain
       block-ish flex item in a column container just takes its own
       width/height, nothing more. */
  }

  /* Becomes a real box instead of display:contents, so Sound + RPM form
     their own row below the gauge instead of being flattened back into
     .speed-hud's own (now column) flex flow. */
  .speed-hud-secondary {
    display: flex;
    order: 2;
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .speed-gauge-value {
    font-size: 1.9rem;
  }

  .speed-gauge-gear {
    margin-top: var(--s1);
    font-size: 0.62rem;
    padding: 1px 6px;
    min-height: 16px;
  }

  /* .speed-hud-side.soundboard, not just .soundboard — has to match the
     base rule's specificity (two classes) or its min-width:190px wins
     regardless of media query, since media queries don't add specificity.
     Narrower than before (was 150-200) so the Sound / RPM / MPG Style trio
     has a better chance of fitting on one row instead of wrapping to a
     second one and pushing the whole HUD taller. */
  .speed-hud-side.soundboard {
    min-width: 128px;
    max-width: 160px;
  }

  .speed-hud-side {
    padding: 6px 8px;
  }

  .speed-hud-side:not(.soundboard) {
    min-width: 54px;
  }

  .hud-side-title {
    font-size: 0.56rem;
  }

  /* Sidebar becomes a collapsible bottom sheet instead of a floating
     left-side box. */
  main {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
  }

  .control-strip {
    border-radius: 18px 18px 0 0;
    max-height: 50vh;
    overflow-y: auto;
    padding-bottom: 24px;
  }

  /* Without this, the column flex layout shrinks Start/Rev (and anything
     else with an explicit size) to fit inside max-height:50vh before ever
     falling back to the scrollbar above — that's what was squashing them
     into flattened ovals instead of leaving them their real size and
     letting the sheet scroll instead. */
  .control-strip > * {
    flex-shrink: 0;
  }

  /* A labelled floating pill above the sheet instead of an ambiguous rotated
     arrow. bottom:50vh (not 100%) — #panelToggle is a fixed element that isn't
     nested inside <main>, so a percentage here resolves against the
     viewport, not against main's own height; 100% was sending it to the
     very top of the screen. 50vh lines it up with the sheet's max-height
     cap instead. */
  #panelToggle {
    top: auto;
    bottom: 50vh;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 999px;
    width: 124px;
    height: 44px;
    flex-direction: row;
    padding: 0 13px;
    border-left: 1px solid var(--hairline-strong);
    transition: bottom 0.25s ease, border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  }

  #panelToggle .panel-toggle-text {
    display: inline;
  }

  #panelToggle .panel-toggle-label {
    display: none;
  }

  #panelToggle .panel-toggle-icon {
    width: 18px;
    height: 18px;
    transform: rotate(-90deg);
  }

  #panelToggle.is-collapsed .panel-toggle-icon {
    transform: rotate(90deg);
  }

  body.panel-hidden #panelToggle {
    left: 50%;
    border-radius: 999px;
  }
}

/* ---------- Short landscape (car built-in display) ----------
   Targets a wide-but-short landscape screen — e.g. a Tesla-style center
   touchscreen at roughly 773×601 — that's landscape like desktop (so it
   should NOT get the portrait phone's bottom-sheet layout above) but far
   shorter than a desktop window (so the desktop layout's full-size sidebar,
   vertically centered, is tall enough to reach down into the bottom-
   anchored .speed-hud).

   Rather than a third distinct layout, this keeps the exact same structure
   as desktop (sidebar left, HUD row bottom-center) and just scales both
   down and re-anchors the sidebar to the top instead of vertical-center —
   at these sizes that alone opens enough clearance that the two never
   overlap, without touching anything on tall/short-width portrait phones
   or on full-height desktop windows. */
@media (orientation: landscape) and (max-height: 700px) {
  main {
    top: 16px;
    bottom: auto;
    transform: none;
    max-height: calc(100vh - 32px);
  }

  .control-strip {
    padding: 10px 12px;
    gap: 6px;
  }

  #startBtn {
    width: 60px;
    height: 60px;
    font-size: 0.62rem;
  }

  #revBtn {
    width: 110px;
    margin-top: 6px;
    padding: 6px 0;
  }

  .settings-toggle {
    margin-top: 6px;
    padding: 4px 10px;
    font-size: 0.62rem;
  }

  .controls {
    margin-top: 8px;
    gap: 8px;
  }

  .studio-link {
    padding: 7px 10px;
    font-size: 0.72rem;
  }

  .legal-footer {
    margin-top: 6px;
  }

  .affiliate-banner-compact {
    margin-top: 6px;
    padding: 7px 10px;
    font-size: 0.7rem;
  }

  /* Recentered on the sidebar's new (shorter, top-anchored) height instead
     of the viewport's vertical center. */
  #panelToggle {
    top: 170px;
  }

.mode-badge {
    top: 12px;
    right: 12px;
    padding: 4px 12px;
    font-size: 0.62rem;
  }

  .speed-hud {
    bottom: 14px;
    gap: 14px;
  }

  .speed-gauge {
    width: 120px;
    height: 120px;
  }

  .speed-gauge-value {
    font-size: 1.7rem;
  }

  /* The car's built-in display is short — the gauge is only 120px here, so
     the gear badge drops its box and sits as bare text to save vertical room. */
  .speed-gauge-gear {
    margin-top: 2px;
    font-size: 0.58rem;
    padding: 0;
    border: none;
    min-height: 0;
  }

  .speed-hud-side {
    min-width: 56px;
    padding: 6px 8px;
  }

  .speed-hud-side.soundboard {
    min-width: 140px;
  }

  .soundboard-select .custom-select-trigger {
    padding: 6px 8px;
    font-size: 0.7rem;
  }
}

/* ---------- Phone layout hardening ----------
   These overrides sit after the broad portrait/short-landscape branches so
   they can account for modern mobile browser chrome, notches and the smallest
   supported screens without changing the desktop or in-car layout. */
@media (orientation: portrait) {
  .mode-badge {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
  }

  .speed-hud {
    top: calc(68px + env(safe-area-inset-top, 0px));
    max-height: none;
    overflow: visible;
  }

  main {
    max-height: 47vh;
    max-height: 47dvh;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .control-strip {
    max-height: none;
    overflow: visible;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  #panelToggle {
    bottom: 47vh;
    bottom: 47dvh;
    width: 124px;
    height: 44px;
  }

  body.panel-hidden #panelToggle {
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  /* The driving picker opens upward on desktop because the HUD is bottom-
     anchored. On a portrait phone the HUD is at the top, so downward is the
     safe default; app.js can still flip it if the visible viewport is short. */
  .soundboard-select .custom-select-panel {
    top: calc(100% + 6px);
    bottom: auto;
    max-height: min(40dvh, 300px);
  }
}

@media (orientation: portrait) and (max-height: 650px) {
  .speed-hud {
    top: calc(56px + env(safe-area-inset-top, 0px));
    gap: 6px;
  }

  .speed-gauge {
    width: 104px;
    height: 104px;
  }

  .speed-gauge-value { font-size: 1.55rem; }
  .speed-gauge-unit { min-height: 32px; }
  .speed-hud-secondary { gap: 6px; }
  .speed-hud-side { padding: 4px 6px; }
  .rpm-trace { height: 32px; }

  .control-strip {
    gap: 8px;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  #startBtn {
    width: 72px;
    height: 72px;
  }
}

@media (max-width: 600px) {
  #paywallOverlay {
    gap: 16px;
    padding:
      max(12px, env(safe-area-inset-top, 0px))
      max(12px, env(safe-area-inset-right, 0px))
      calc(16px + env(safe-area-inset-bottom, 0px))
      max(12px, env(safe-area-inset-left, 0px));
    scroll-padding-top: max(12px, env(safe-area-inset-top, 0px));
  }

  #paywallOverlay .paywall-card {
    border-radius: 16px;
    padding: 24px 16px;
  }

  .test-me-panel {
    width: 100%;
    border-radius: 16px;
    padding: 20px 16px;
  }

  .paywall-pricing-tiers { gap: 8px; }
  .paywall-tier { padding: 16px 6px 12px; }
  .paywall-tier-price { font-size: 1.18rem; }
  .paywall-tier-sub { font-size: 0.62rem; }

  #restoreForm input[type="email"] {
    font-size: 16px; /* prevents iOS from zooming the page on focus */
  }
}

/* A phone held sideways is much shorter than a car display. Keep the sidebar
   and driving cluster side-by-side in the remaining width instead of letting
   the centered cluster overlap the left controls. */
@media (orientation: landscape) and (max-height: 500px) {
  main {
    top: max(8px, env(safe-area-inset-top, 0px));
    left: max(8px, env(safe-area-inset-left, 0px));
    width: min(36vw, 210px);
    max-width: min(36vw, 210px);
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  .control-strip { padding: 8px 10px; }
  #startBtn { width: 56px; height: 56px; }
  #revBtn { min-height: 44px; }

  #panelToggle {
    top: 50%;
    left: calc(max(8px, env(safe-area-inset-left, 0px)) + min(36vw, 210px));
  }

  .legal-footer,
  .affiliate-banner-compact {
    display: none;
  }

  .speed-hud {
    left: 70%;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    gap: 8px;
    max-width: 60vw;
  }

  .speed-gauge { width: 94px; height: 94px; }
  .speed-gauge-value { font-size: 1.45rem; }
  .speed-hud-side.soundboard { min-width: 140px; max-width: 150px; }
  .speed-hud-side:not(.soundboard) { min-width: 50px; }
  .rpm-trace { height: 30px; }

  .mode-badge {
    top: max(8px, env(safe-area-inset-top, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
  }
}

/* Fixed translucent layers are expensive on phone GPUs and can steal time
   from audio rendering. Opaque mobile cards keep the same hierarchy while
   avoiding repeated full-screen backdrop compositing. */
@media (max-width: 600px), (orientation: landscape) and (max-height: 500px) {
  #paywallOverlay,
  .control-strip,
  .speed-hud-side,
  .mode-badge,
  #panelToggle {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  #paywallOverlay { background: rgba(255, 255, 255, 0.96); }
  .control-strip,
  .speed-hud-side,
  .mode-badge,
  #panelToggle { background: rgba(18, 23, 30, 0.96); }

  body.theme-day .control-strip,
  body.theme-day .speed-hud-side,
  body.theme-day .mode-badge,
  body.theme-day #panelToggle { background: rgba(255, 255, 255, 0.98); }
}

/* While the sound engine is running, fixed glass layers sit over a constantly
   changing full-screen canvas. Recomputing several backdrop blurs every frame
   is disproportionately expensive on in-car GPUs and can steal time from the
   audio fallback. Keep the same dark hierarchy with opaque surfaces instead. */
body.driving-active .scene-picker,
body.driving-active .control-strip,
body.driving-active .speed-hud-side,
body.driving-active .mode-badge,
body.driving-active #panelToggle,
body.driving-active .eco-hud-toggle,
body.driving-active .eco-hud-panel {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body.driving-active .scene-picker,
body.driving-active .control-strip,
body.driving-active .speed-hud-side,
body.driving-active .mode-badge,
body.driving-active #panelToggle {
  background: rgba(10, 14, 20, 0.96);
}

body.theme-day.driving-active .scene-picker,
body.theme-day.driving-active .control-strip,
body.theme-day.driving-active .speed-hud-side,
body.theme-day.driving-active .mode-badge,
body.theme-day.driving-active #panelToggle {
  background: rgba(255, 255, 255, 0.98);
}

body.driving-active.performance-lite .rpm-panel.shift-pulse,
body.driving-active.performance-lite .speed-gauge.kick-pulse {
  animation: none;
}

/* ================= Daytime theme: solid cards, not glass ================= */
/* The glow-heavy translucent-glass treatment above reads fine against a dark
   background but falls flat on white — a semi-transparent white panel over a
   white page barely shows any separation, and the neon glows just look like
   clutter instead of atmosphere. Opaque cards + a plain soft drop shadow
   instead, for the day theme only; night is untouched. */
body.theme-day .control-strip,
body.theme-day .eco-hud-panel,
body.theme-day .test-me-panel,
body.theme-day #paywallOverlay .paywall-card,
body.theme-day .speed-hud-side {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

/* REV as a solid filled pill instead of an outlined glow — easier to spot
   at a glance against white than the dark theme's translucent-orange-on-
   near-black version needs to be. */
body.theme-day #revBtn,
body.theme-day .test-me-circle-rev {
  background: #ff7a1a;
  border-color: #ff7a1a;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(255, 122, 26, 0.35);
}

body.theme-day #revBtn:active:not(:disabled),
body.theme-day .test-me-circle-rev:active {
  background: #e56a10;
  border-color: #e56a10;
  box-shadow: 0 4px 18px rgba(255, 122, 26, 0.45);
}

/* Sound Studio / the Sound picker get a bold dark accent card instead of a
   light outline — deliberate high-contrast anchors against all the
   surrounding white, the same way the reference mockup used a dark card to
   make its top action pop rather than blending into the page. */
body.theme-day .studio-link,
body.theme-day .custom-select-trigger {
  background: #0d2b3a;
  border-color: #0d2b3a;
  color: #eafffa;
}

body.theme-day .studio-link:hover {
  background: #123a4d;
}

body.theme-day .custom-select-arrow {
  color: rgba(234, 255, 250, 0.7);
}

/* MPG Style's whole box tints to match its current zone (app.js toggles
   these classes in drawDrivingStyleBar) — a glanceable cue at a distance,
   not just the small colored label text. Day theme only; the dark theme
   already reads fine from the label color alone. */
body.theme-day #mpgStyleBox.zone-green {
  background: rgba(61, 255, 160, 0.16);
  border-color: rgba(61, 255, 160, 0.45);
}

body.theme-day #mpgStyleBox.zone-yellow {
  background: rgba(255, 224, 102, 0.2);
  border-color: rgba(255, 224, 102, 0.5);
}

body.theme-day #mpgStyleBox.zone-red {
  background: rgba(255, 82, 82, 0.16);
  border-color: rgba(255, 82, 82, 0.45);
}


/* ============================================================================
   QUALITY FLOOR
   ----------------------------------------------------------------------------
   Keyboard focus and reduced-motion support. Both matter more than usual here:
   the app runs on a car's built-in browser as well as a phone, and it animates
   a full-screen field continuously, which is exactly the kind of motion people
   set the reduced-motion preference to avoid.
   ========================================================================== */

/* One visible focus treatment for every interactive element. :focus-visible so
   it appears for keyboard users without ringing every tap on a touchscreen. */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
[role="option"]:focus-visible,
.custom-select-trigger:focus-visible,
.custom-select-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Range inputs get a real thumb size — the default is well under a comfortable
   touch target, which matters for controls adjusted in a vehicle. */
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

button,
a,
input,
select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  /* The gauge kick is a decorative jolt — drop it entirely rather than just
     shortening it. */
  .speed-gauge.kick-pulse {
    animation: none;
  }
}

/* Honour the OS "increase contrast" setting by firming up every hairline. */
@media (prefers-contrast: more) {
  :root {
    --hairline: rgba(150, 178, 196, 0.4);
    --hairline-strong: rgba(150, 178, 196, 0.6);
    --text-dim: #b6c4cf;
    --text-faint: #93a4b2;
  }
}

/* ---------- Manual shift dock ----------
   The controls live in normal layout below the instrument instead of
   overlapping its speed, unit, gear or progress ring. */
.drive-center-stack {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.speed-gauge-ring {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.speed-gauge-readout {
  z-index: 3;
  pointer-events: none;
}

.speed-gauge-unit { pointer-events: auto; }

.shift-control-dock {
  display: grid;
  grid-template-columns: 52px auto 52px;
  align-items: center;
  gap: 7px;
  padding: 4px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.steering-paddle {
  width: 52px;
  min-height: 48px;
  padding: 6px 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.steering-paddle-down {
  border-radius: 12px 7px 7px 12px;
}

.steering-paddle-up {
  border-radius: 7px 12px 12px 7px;
}

.steering-paddle span {
  font-family: var(--font-data);
  font-size: 1.25rem;
  line-height: 1;
}

.steering-paddle small {
  color: var(--text-faint);
  font-family: var(--font-data);
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.steering-paddle:disabled {
  opacity: 0.24;
  cursor: default;
}

.steering-paddle:active:not(:disabled),
.steering-paddle.shift-flash {
  color: var(--warn);
  border-color: var(--warn);
  transform: scale(0.94);
}

body.gearbox-manual .steering-paddle:not(:disabled) {
  color: var(--warn);
}

.gearbox-mode-control {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-pill);
  background: var(--surface-raised);
  box-shadow: var(--shadow-panel);
}

.gearbox-mode-control button {
  min-width: 54px;
  min-height: 30px;
  padding: 5px 8px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-faint);
  font-family: var(--font-data);
  font-size: 0.54rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.gearbox-mode-control button[aria-checked="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--hairline);
}

.gearbox-mode-control button:disabled {
  opacity: 0.34;
  cursor: default;
}

body.gearbox-manual .gearbox-mode-control button[aria-checked="true"] {
  color: var(--warn);
}

body.theme-day .steering-paddle,
body.theme-day .gearbox-mode-control,
body.theme-day .shift-control-dock {
  background: rgba(255, 255, 255, 0.96);
}

@media (orientation: portrait) {
  .drive-center-stack { order: 1; gap: 6px; }
  .shift-control-dock { grid-template-columns: 46px auto 46px; gap: 4px; }
  .steering-paddle { width: 46px; min-height: 44px; }
  .gearbox-mode-control button { min-width: 49px; min-height: 28px; padding: 4px 6px; }
}

@media (orientation: portrait) and (max-height: 650px) {
  .drive-center-stack { gap: 4px; }
  .shift-control-dock { transform: scale(0.9); transform-origin: top center; margin-bottom: -5px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .drive-center-stack { gap: 4px; }
  .shift-control-dock { grid-template-columns: 44px auto 44px; gap: 3px; padding: 3px; }
  .steering-paddle { width: 44px; min-height: 42px; }
  .gearbox-mode-control button { min-width: 45px; min-height: 28px; padding: 4px; }
}

/* Scene and RPM controls stay compact on the two constrained dashboard
   shapes the app supports: a portrait phone mount and a short car display. */
@media (orientation: portrait) {
  .scene-picker {
    top: max(8px, env(safe-area-inset-top, 0px));
    left: max(8px, env(safe-area-inset-left, 0px));
    transform: none;
  }

  .scene-picker-label { display: none; }
  .scene-picker {
    max-width: calc(100vw - 16px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .scene-picker::-webkit-scrollbar { display: none; }
  .scene-picker button { min-width: 50px; padding-inline: 7px; }
  .scene-picker button[data-drive-scene="starflyby"] { min-width: 72px; }
  .scene-picker button[data-drive-scene="aurora"] { min-width: 62px; }
  .scene-picker button[data-drive-scene="portal"] { min-width: 60px; }
  .scene-picker button[data-drive-scene="galaxy"] { min-width: 62px; }

  .rpm-panel {
    min-width: 180px !important;
    width: 180px;
  }

  .rpm-trace { height: 40px; }
}

@media (orientation: landscape) and (max-height: 700px) {
  .scene-picker { top: 10px; }
  .scene-picker button { min-width: 54px; padding-inline: 8px; }

  .rpm-panel {
    min-width: 190px;
    width: 190px;
  }

  .rpm-trace { height: 38px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .scene-picker { top: 6px; }
  .scene-picker-label { display: none; }
  .scene-picker button { min-width: 48px; min-height: 28px; }
  .scene-picker button[data-drive-scene="starflyby"] { min-width: 68px; }
  .scene-picker button[data-drive-scene="aurora"] { min-width: 60px; }
  .scene-picker button[data-drive-scene="portal"] { min-width: 58px; }
  .scene-picker button[data-drive-scene="galaxy"] { min-width: 60px; }

  .rpm-panel {
    min-width: 164px;
    width: 164px;
  }

  .rpm-trace { height: 30px; }
  .rpm-scale { display: none; }
}

@media (max-width: 600px), (orientation: landscape) and (max-height: 500px) {
  .scene-picker {
    background: rgba(10, 14, 20, 0.94);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

/* Phone layout only. Desktop/car layouts and audio behavior stay unchanged. */
@media (max-width: 700px) and (orientation: portrait),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  html { height: auto; scroll-padding-block: 20px; }
  body {
    position: relative;
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100svh;
    padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    overflow-x: clip;
  }
  .scene-picker {
    position: relative;
    inset: auto;
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    padding: 5px;
    gap: 4px;
    transform: none;
    border-radius: 16px;
  }
  .scene-picker button {
    flex: 0 0 auto;
    min-width: 72px;
    min-height: 44px;
    padding: 10px 14px;
    font-size: .75rem;
    letter-spacing: .035em;
    white-space: nowrap;
    border-radius: 11px;
  }
  .mode-badge {
    position: absolute;
    top: calc(max(16px, env(safe-area-inset-top)) + 70px);
    left: max(20px, env(safe-area-inset-left));
    right: auto;
    max-width: calc(100% - 128px);
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
    font-size: .75rem;
    letter-spacing: .06em;
    transform: none;
  }
  .speed-hud {
    position: relative;
    z-index: 5;
    inset: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: 'gauge rpm' 'sound sound';
    gap: 18px 16px;
    width: 100%;
    max-width: none;
    max-height: none;
    margin: 76px 0 16px;
    padding: 0;
    overflow: visible;
    transform: none;
  }
  .speed-hud-secondary { display: contents; }
  .drive-center-stack { grid-area: gauge; justify-content: center; min-width: 0; }
  .speed-gauge { width: min(100%, 160px); height: auto; aspect-ratio: 1; }
  .speed-gauge-value { font-size: 2.6rem; }
  .speed-gauge-unit { font-size: .75rem; margin-top: 2px; }
  .speed-gauge-gear { font-size: .75rem; margin-top: 0; padding: 3px 8px; }
  .speed-hud .speed-hud-side { background: rgba(13, 19, 27, .96); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .speed-hud .rpm-panel {
    grid-area: rpm;
    min-width: 0 !important;
    width: 100%;
    padding: 16px 12px;
    gap: 12px;
    align-self: center;
  }
  .rpm-panel-heading { gap: 6px; }
  .hud-side-title { font-size: .75rem; letter-spacing: .08em; color: var(--text-dim); }
  .hud-side-value { font-size: 1.25rem; }
  .rpm-trace { height: 56px; }
  .rpm-scale { font-size: .625rem; letter-spacing: .035em; color: var(--text-dim); }
  .speed-hud .speed-hud-side.soundboard {
    position: relative;
    grid-area: sound;
    width: 100%;
    min-width: 0;
    max-width: none;
    align-items: stretch;
    gap: 12px;
    padding: 16px;
    z-index: 4;
  }
  .voice-row { gap: 12px; }
  .soundboard .custom-select { position: static; }
  .soundboard .custom-select-trigger {
    min-height: 56px;
    padding: 12px;
    font-size: 1rem;
    line-height: 1.4;
  }
  #soundDropdownLabel { white-space: normal; overflow: visible; text-overflow: clip; }
  .favorite-btn { width: 52px; min-height: 56px; }
  #soundDropdownPanel {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    left: 0;
    right: 0;
    max-height: min(55dvh, 420px);
  }
  .custom-select-option { min-height: 52px; padding: 14px 12px; font-size: 1rem; gap: 8px; }
  .custom-select-option-label { white-space: normal; line-height: 1.4; overflow-wrap: anywhere; }
  .custom-select-group-label { font-size: .75rem; line-height: 1.5; letter-spacing: .04em; padding: 14px 12px 8px; }
  #panelToggle, body.panel-hidden #panelToggle {
    position: relative;
    inset: auto;
    align-self: flex-end;
    flex-direction: row;
    width: auto;
    height: auto;
    min-height: 44px;
    margin: 0 0 12px;
    padding: 10px 14px;
    font-size: .875rem;
    border: 1px solid var(--hairline-strong);
    border-radius: 12px;
    transform: none;
  }
  #panelToggle .panel-toggle-text { display: inline; white-space: normal; line-height: 1.4; }
  #panelToggle .panel-toggle-label { display: none; }
  #controlsSidebar {
    position: relative;
    inset: auto;
    width: 100%;
    max-width: none;
    max-height: none;
    transform: none;
    overflow: visible;
  }
  .control-strip {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    padding: 16px;
    max-height: none;
    overflow: visible;
    background: rgba(13, 19, 27, .96);
    border-radius: 18px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .control-strip > * { grid-column: 1 / -1; min-width: 0; }
  #startBtn, #revBtn {
    grid-column: auto;
    width: 100%;
    height: 56px;
    min-height: 56px;
    margin: 0;
    padding: 12px;
    border-radius: 12px;
    font-size: 1rem;
    letter-spacing: .06em;
  }
  #settingsToggle { margin: 0; width: 100%; min-height: 48px; font-size: .875rem; border-radius: 12px; }
  .controls { margin-top: 8px; gap: 24px; }
  .controls label { gap: 10px; font-size: 1rem; line-height: 1.5; }
  .controls input[type='range'] { height: 44px; }
  .controls input[type='checkbox'] { width: 22px; height: 22px; }
  .settings-group, .advanced-settings, .controls label.settings-switch { padding: 16px; border-radius: 14px; }
  .settings-group-title, .settings-heading-row, .settings-value, .advanced-settings summary { font-size: .9375rem; line-height: 1.5; }
  .settings-help, .settings-switch small { font-size: .875rem; line-height: 1.6; margin-top: 10px; }
  .settings-switch strong { font-size: .9375rem; line-height: 1.5; }
  .segmented-setting { margin-top: 12px; gap: 4px; }
  .segmented-setting button { min-height: 48px; font-size: .875rem; }
  .range-end-labels, .sensor-quality-row, .gps-quality { font-size: .75rem; }
  .advanced-settings summary { min-height: 44px; }
  .studio-link { margin: 0; min-height: 52px; padding: 14px; font-size: .875rem; line-height: 1.5; }
  .legal-footer { margin-top: 20px; font-size: .75rem; line-height: 1.6; }
  #controlsSidebar > .affiliate-banner { margin-top: 20px; padding: 16px; font-size: .875rem; line-height: 1.5; }
  .affiliate-banner-sub { font-size: .8125rem; line-height: 1.5; }

  /* A compact utility button; the open panel becomes a wide, readable sheet. */
  html.js-narrow .eco-hud {
    position: absolute;
    top: calc(max(16px, env(safe-area-inset-top)) + 70px);
    right: max(20px, env(safe-area-inset-right));
    z-index: 30;
    flex-direction: column;
    align-items: flex-end;
  }
  html.js-narrow .eco-hud-toggle { width: 76px; min-height: 44px; padding: 10px 14px; align-self: flex-end; border-radius: 12px; }
  html.js-narrow .eco-hud-toggle-label { font-size: .75rem; }
  html.js-narrow .eco-hud:not(.collapsed) { position: fixed; top: max(16px, env(safe-area-inset-top)); }
  html.js-narrow .eco-hud .eco-hud-panel,
  html.js-narrow .eco-hud[data-display-mode='analysis'] .eco-hud-panel {
    width: calc(100vw - 40px);
    max-height: calc(var(--app-height, 100dvh) - 92px);
    margin: 12px 0 0;
    padding: 20px;
    gap: 20px;
    border-radius: 18px;
    background: #0d1218;
    box-shadow: 0 16px 50px rgba(0, 0, 0, .55);
  }
  html.js-narrow .eco-hud.collapsed .eco-hud-panel { display: none; }
  .eco-mode-btn, .eco-control-btn { min-height: 48px; font-size: .875rem; }
  .eco-hud-subtitle, .eco-section-subtitle, .eco-estimate-disclosure, .eco-feedback { font-size: .8125rem; line-height: 1.5; }
}

/* A rotated phone keeps the roomy controls without changing desktop/car screens. */
@media (min-width: 700px) and (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  .speed-hud {
    grid-template-columns: 150px minmax(150px, .8fr) minmax(260px, 1.2fr);
    grid-template-areas: 'gauge rpm sound';
    align-items: center;
  }
  html.js-narrow .eco-hud .eco-hud-panel,
  html.js-narrow .eco-hud[data-display-mode='analysis'] .eco-hud-panel { width: 420px; }
}

/* No backdrop filters, animated previews, or image carousels: this control
   stays inexpensive even on the main-thread audio fallback. */
/* Preserve the app-wide keyboard ring formerly supplied by Eco's CSS. */
button:focus-visible,
select:focus-visible,
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.scene-picker.background-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 22px;
  width: 480px;
  max-width: calc(100vw - 40px);
  padding: 13px 16px 10px;
  overflow: visible;
  border-radius: 18px;
  background: #10171f;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  z-index: 32;
}
.background-choice { min-width: 0; }
.background-eyebrow {
  display: block;
  color: #aab8c4;
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.background-picker #backgroundTrigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 5px 0;
  border-radius: 6px;
  color: #f5f7fa;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
}
#backgroundName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.background-chevron { font-size: 20px; color: #7ce7f4; }
.background-motion { border-left: 1px solid #34404b; padding-left: 22px; }
.background-switch { display: flex; align-items: center; gap: 9px; position: relative; min-height: 44px; cursor: pointer; color: #f5f7fa; font-size: 13px; font-weight: 600; white-space: nowrap; }
.background-switch input { position: absolute; width: 100%; height: 100%; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.background-switch-track { width: 34px; height: 20px; flex: 0 0 34px; border-radius: 20px; background: #42515f; border: 1px solid #6f8293; }
.background-switch-track::after { content: ''; display: block; width: 14px; height: 14px; margin: 2px; border-radius: 50%; background: #eff7ff; }
.background-switch input:checked + .background-switch-track { background: #7ce7f4; border-color: #7ce7f4; }
.background-switch input:checked + .background-switch-track::after { background: #0d2028; transform: translateX(14px); }
.background-switch input:focus-visible + .background-switch-track { outline: 2px solid #7ce7f4; outline-offset: 4px; }
#backgroundMotionWarning { display: block; color: #b2bec9; font-size: 10px; line-height: 1.5; }
.background-status { grid-column: 1 / -1; margin: 1px 0 0; color: #9eafbd; font-size: 10px; line-height: 1.4; }
.background-picker .background-choices {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: min(440px, 60vh);
  max-height: min(440px, 60dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  background: #10171f;
  border: 1px solid #46545f;
  border-radius: 16px;
  box-shadow: 0 16px 36px #0008;
}
.background-picker [hidden] { display: none !important; }
.background-menu-heading { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; margin: 2px 8px 10px; color: #d9e4eb; font-size: 12px; }
.background-menu-heading span { color: #9eafbd; font-size: 10px; }
.background-picker .background-choices button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  width: 100%;
  min-height: 57px;
  padding: 9px 40px 9px 12px;
  border-radius: 9px;
  font-family: var(--font-ui);
  text-transform: none;
  letter-spacing: 0;
  text-align: left;
  color: #e2ebf2;
  font-size: 14px;
}
.background-choices button small { font-size: 11px; color: #aab8c4; font-weight: 400; line-height: 1.7; }
.background-picker .background-choices button:hover { background: #20333f; }
.background-picker .background-choices button[aria-pressed='true'] { background: #18343e; color: #9af0fa; }
.background-choices button[aria-pressed='true']::after { content: '✓'; position: absolute; right: 16px; color: #9af0fa; }
.gps-settling-tip { margin: 0; color: var(--text-dim); font-size: 11px; line-height: 1.6; }
.gps-settling-tip strong { display: block; margin-bottom: 3px; color: var(--text); font-size: 12px; font-weight: 600; }

@media (max-width: 700px) and (orientation: portrait),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  .scene-picker.background-picker { position: relative; inset: auto; transform: none; width: 100%; max-width: none; padding: 12px; gap: 4px 12px; min-height: 110px; }
  .background-motion { padding-left: 12px; }
  .background-picker #backgroundTrigger { font-size: 15px; }
  .background-switch { font-size: 12px; gap: 6px; }
  .background-picker .background-choices button { min-height: 62px; font-size: 16px; }
  .background-choices button small { font-size: 12px; }
  .background-status, #backgroundMotionWarning { font-size: 10px; }
  /* Keep the drive-mode badge below the taller background bar. */
  .mode-badge { top: calc(max(16px, env(safe-area-inset-top)) + 126px); }
  .gps-settling-tip { font-size: 12px; line-height: 1.6; }
  .gps-settling-tip strong { font-size: 13px; }
}
@media (max-width: 370px) and (orientation: portrait) {
  .scene-picker.background-picker { padding: 10px; gap: 4px 8px; }
  .background-motion { padding-left: 8px; }
  .background-picker #backgroundTrigger { font-size: 13px; }
  .background-switch { font-size: 11px; gap: 5px; }
  #backgroundMotionWarning { max-width: 112px; font-size: 9px; }
}

/* Apex Racing is entirely still: no filters, parallax, 3D canvas or decorative
   animation. These inexpensive, static housings belong to the live controls,
   not to baked-in artwork, so their shadows always line up. */
.racing-signature { display: none; }

body[data-drive-scene="apex-racing"] .speed-hud {
  --apex-edge: #3b4c59;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px minmax(0, 1fr);
  grid-template-areas: 'brand brand brand' 'sound gauge rpm';
  gap: 24px;
  left: calc(50% + 122px);
  bottom: 40px;
  width: calc(100% - 324px);
  max-width: 1050px;
  padding: 20px 26px 30px;
  border: 1px solid #42535f;
  border-top-color: #71848e;
  border-radius: 32px;
  background: linear-gradient(135deg, #283139, #121a21 28%, #0a1118 72%, #202a33);
  box-shadow: inset 0 1px 0 #bfddeb24, inset 0 -5px 0 #020508,
    0 7px 0 #080c11, 0 8px 0 #39444c, 0 24px 38px #000b;
}
body[data-drive-scene="apex-racing"] .racing-signature {
  grid-area: brand;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  min-width: 0;
  pointer-events: none;
}
body[data-drive-scene="apex-racing"] .racing-signature::before,
body[data-drive-scene="apex-racing"] .racing-signature::after {
  content: '';
  flex: 1;
  height: 4px;
  border-block: 1px solid #090f15;
  background: linear-gradient(90deg, transparent, #2889a6 70%, #9edfeb);
  box-shadow: 0 1px 0 #a0e1f017;
}
body[data-drive-scene="apex-racing"] .racing-signature::after { transform: scaleX(-1); }
.racing-brand-inlay {
  flex: 0 0 auto;
  padding: 0 12px 11px;
  border: 1px solid #344752;
  border-bottom-color: #58717e;
  border-radius: 12px;
  background: #000;
  box-shadow: 0 1px 0 #c6ecff1c, inset 0 3px 10px #000, 0 -3px 8px #0007;
  text-align: center;
}
.racing-logo-window { display: block; position: relative; overflow: hidden; width: 166px; height: 99px; }
.racing-logo-window img { display: block; position: absolute; width: 166px; height: 166px; max-width: none; top: -33px; left: 0; }
.racing-edition { display: block; font: 600 9px/1.4 var(--font-data); color: #9bb2c2; letter-spacing: .25em; text-transform: uppercase; }

body[data-drive-scene="apex-racing"] .drive-center-stack { grid-area: gauge; justify-content: center; }
body[data-drive-scene="apex-racing"] .speed-gauge {
  border-radius: 50%;
  background: radial-gradient(circle at 40% 20%, #21303a, #0b121a 58%, #04080d 76%);
  box-shadow: inset 0 3px 10px #000, inset 0 -1px 2px #7ba6bb50,
    0 0 0 5px #05090e, 0 0 0 6px #576a77, 0 0 0 11px #202c36,
    0 0 0 12px #080e15, 0 14px 0 9px #05090e, 0 22px 24px 8px #0009;
}
body[data-drive-scene="apex-racing"] .speed-gauge::before {
  content: '';
  position: absolute;
  inset: 20%;
  border-radius: 50%;
  border: 1px solid #84c8eb14;
  pointer-events: none;
}
body[data-drive-scene="apex-racing"] .speed-gauge-value { text-shadow: 0 2px 1px #000; }
body[data-drive-scene="apex-racing"] .speed-gauge-ring { display: block; }
body[data-drive-scene="apex-racing"] .speed-gauge-value { position: absolute; top: 23%; }
body[data-drive-scene="apex-racing"] .speed-gauge-unit { position: absolute; top: 48%; margin: 0; }
body[data-drive-scene="apex-racing"] .speed-gauge-readout > .gear-indicator { position: absolute; bottom: 12%; margin: 0; }
body[data-drive-scene="apex-racing"] .speed-hud .speed-hud-side {
  position: relative;
  min-width: 0 !important;
  width: 100%;
  max-width: none;
  padding: 19px 16px;
  border: 1px solid var(--apex-edge);
  border-top-color: #6e808b;
  border-radius: 16px;
  background: linear-gradient(160deg, #1d2a34, #0b131c 65%);
  box-shadow: inset 0 1px 0 #d2f1ff1a, inset 0 -3px 0 #03090e,
    0 5px 0 #04090f, 0 6px 0 #32404b, 0 15px 20px #0009;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body[data-drive-scene="apex-racing"] .soundboard { grid-area: sound; align-items: stretch; gap: 12px; z-index: 4; }
body[data-drive-scene="apex-racing"] .rpm-panel { grid-area: rpm; gap: 12px; }
body[data-drive-scene="apex-racing"] .hud-side-title { color: #b4c8d5; font-size: 11px; letter-spacing: .14em; }
body[data-drive-scene="apex-racing"] .rpm-rail {
  box-shadow: inset 0 2px 5px #000, 0 1px 0 #88bfd038;
  background: #040b12;
}
body[data-drive-scene="apex-racing"] .soundboard .custom-select-trigger {
  background: #08121c;
  border-color: #3e6579;
  box-shadow: inset 0 2px 6px #0008, 0 1px 0 #8bc7db24;
}
body[data-drive-scene="apex-racing"] .favorite-btn { background: #131f29; box-shadow: inset 0 1px 0 #b4e2fb22, 0 3px 0 #050a11; }
body[data-drive-scene="apex-racing"] .control-strip {
  background: linear-gradient(150deg, #202b34, #0b121b 70%);
  border-color: #465966;
  box-shadow: inset 0 1px 0 #d2f1ff20, 0 5px 0 #04090f, 0 15px 24px #0009;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body[data-drive-scene="apex-racing"] .speed-gauge.kick-pulse,
body[data-drive-scene="apex-racing"] .rpm-panel.shift-pulse { animation: none; }

/* Keep the console clear of the existing control sidebar on shorter car
   displays. The physical screen remains static at every breakpoint. */
@media (min-width: 701px) and (max-width: 1100px) and (orientation: landscape),
       (orientation: landscape) and (max-height: 600px) {
  body[data-drive-scene="apex-racing"] .speed-hud {
    left: calc(50% + 108px); width: calc(100% - 276px); bottom: 26px;
    grid-template-columns: minmax(0, 1fr) 132px minmax(0, 1fr);
    padding: 12px 16px 22px; gap: 18px;
  }
  body[data-drive-scene="apex-racing"] .speed-gauge { width: 132px; height: 132px; }
  body[data-drive-scene="apex-racing"] .speed-hud .speed-hud-side { padding: 12px 10px; }
  body[data-drive-scene="apex-racing"] .racing-logo-window { width: 122px; height: 73px; }
  body[data-drive-scene="apex-racing"] .racing-logo-window img { width: 122px; height: 122px; top: -24px; }
  body[data-drive-scene="apex-racing"] .racing-brand-inlay { padding-bottom: 8px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  body[data-drive-scene="apex-racing"] .speed-hud { bottom: 20px; padding-block: 8px 20px; row-gap: 16px; }
  body[data-drive-scene="apex-racing"] .racing-logo-window { width: 82px; height: 49px; }
  body[data-drive-scene="apex-racing"] .racing-logo-window img { width: 82px; height: 82px; top: -16px; }
  body[data-drive-scene="apex-racing"] .racing-brand-inlay { padding: 0 10px 3px; }
  body[data-drive-scene="apex-racing"] .racing-edition { display: none; }
}
@media (min-width: 701px) and (max-width: 1100px) and (orientation: landscape) {
  body[data-drive-scene="apex-racing"] .scene-picker {
    left: calc(50% + 108px); width: calc(100% - 276px); max-width: none;
  }
}
@media (min-width: 701px) and (max-width: 1100px) and (max-height: 500px) and (orientation: landscape) and (pointer: fine) {
  /* The mode is inlaid in the console header, clear of the background chooser
     and the sidebar's Start/Rev controls on a short dashboard. */
  body[data-drive-scene="apex-racing"] .mode-badge { top: auto; bottom: 206px; right: 44px; z-index: 6; font-size: 8px; padding: 5px 9px; }
  body[data-drive-scene="apex-racing"] .soundboard .hud-side-title { display: flex; align-items: center; min-height: 32px; }
  body[data-drive-scene="apex-racing"] .soundboard .voice-row { display: block; }
  body[data-drive-scene="apex-racing"] .soundboard .custom-select-trigger { min-height: 44px; }
  body[data-drive-scene="apex-racing"] .soundboard .favorite-btn { position: absolute; top: 3px; right: 6px; width: 44px; min-height: 44px; }
}

/* Flow layout on phones/tablets: the brand is an inlaid part of the console,
   never a floating overlay over a button. Leave room for the gauge bezel. */
@media (orientation: portrait),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  body[data-drive-scene="apex-racing"] .speed-hud {
    position: relative;
    inset: auto;
    transform: none;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: 'brand brand' 'gauge rpm' 'sound sound';
    width: 100%; max-width: none; max-height: none;
    padding: 14px 14px 18px;
    margin: 76px 0 22px;
    gap: 26px 24px;
    overflow: visible;
    border-radius: 24px;
  }
  body[data-drive-scene="apex-racing"] .racing-signature { gap: 12px; }
  body[data-drive-scene="apex-racing"] .scene-picker { left: auto; width: 100%; max-width: none; }
  body[data-drive-scene="apex-racing"] .speed-hud-secondary { display: contents; }
  body[data-drive-scene="apex-racing"] .racing-logo-window { width: 132px; height: 79px; }
  body[data-drive-scene="apex-racing"] .racing-logo-window img { width: 132px; height: 132px; top: -26px; }
  body[data-drive-scene="apex-racing"] .racing-brand-inlay { padding: 0 8px 8px; }
  body[data-drive-scene="apex-racing"] .racing-edition { display: block; }
  body[data-drive-scene="apex-racing"] .speed-gauge { width: min(100%, 160px); height: auto; aspect-ratio: 1; }
  body[data-drive-scene="apex-racing"] .speed-hud .speed-hud-side { padding: 14px 10px; }
  body[data-drive-scene="apex-racing"] .speed-hud .soundboard { padding: 16px 12px; }
  body[data-drive-scene="apex-racing"] .rpm-trace { height: 44px; }
  body[data-drive-scene="apex-racing"] .rpm-scale { font-size: 9px; letter-spacing: 0; }
}
/* The old tablet branch used a fixed bottom sheet. Apex's larger instrument
   housing uses the same unambiguous document flow as the phone instead. */
@media (min-width: 701px) and (orientation: portrait) {
  body[data-drive-scene="apex-racing"] { display: flex; flex-direction: column; position: relative; height: auto; min-height: 100svh; padding: 20px; overflow-x: clip; }
  body[data-drive-scene="apex-racing"] .scene-picker { position: relative; inset: auto; transform: none; width: 100%; max-width: 640px; min-height: 110px; margin-inline: auto; }
  body[data-drive-scene="apex-racing"] .mode-badge { position: absolute; top: 146px; left: 20px; right: auto; }
  body[data-drive-scene="apex-racing"] .speed-hud { max-width: 640px; margin-inline: auto; padding: 20px 26px 30px; }
  body[data-drive-scene="apex-racing"] .drive-center-stack { min-width: 0; }
  body[data-drive-scene="apex-racing"] #panelToggle { position: relative; inset: auto; transform: none; align-self: flex-end; width: auto; height: auto; min-height: 44px; padding: 12px; margin-bottom: 16px; }
  body[data-drive-scene="apex-racing"] #panelToggle .panel-toggle-label,
  body[data-drive-scene="apex-racing"] #panelToggle .panel-toggle-icon { display: none; }
  body[data-drive-scene="apex-racing"] #panelToggle .panel-toggle-text { display: inline; }
  body[data-drive-scene="apex-racing"] #controlsSidebar { position: relative; inset: auto; width: 100%; max-width: 640px; max-height: none; margin-inline: auto; transform: none; }
  body[data-drive-scene="apex-racing"].panel-hidden #controlsSidebar { display: none; }
  body[data-drive-scene="apex-racing"] .control-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-height: none; overflow: visible; border-radius: 20px; padding: 20px; }
  body[data-drive-scene="apex-racing"] .control-strip > * { grid-column: 1 / -1; }
  body[data-drive-scene="apex-racing"] #startBtn,
  body[data-drive-scene="apex-racing"] #revBtn { grid-column: auto; width: 100%; height: 56px; margin: 0; border-radius: 12px; }
}
@media (max-width: 370px) and (orientation: portrait) {
  body[data-drive-scene="apex-racing"] .speed-hud { padding-inline: 12px; column-gap: 22px; }
  body[data-drive-scene="apex-racing"] .speed-gauge-value { font-size: 2rem; }
  body[data-drive-scene="apex-racing"] .speed-gauge-unit { font-size: .625rem; }
  body[data-drive-scene="apex-racing"] .speed-hud .rpm-panel { padding-inline: 8px; }
}

.labor-day-sale {
  margin: 0 0 24px;
  padding: 22px;
  border: 1px solid #dd762b;
  border-radius: 16px;
  background: #102b3a;
  color: #fff;
  text-align: left;
}
.labor-day-sale-kicker { color: #ffba80; font-size: 0.875rem; font-weight: 800; letter-spacing: 0.08em; }
.labor-day-sale h2 { margin: 10px 0; color: #fff; font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.15; letter-spacing: -0.025em; }
.labor-day-sale p { margin: 0; color: #e0ebf0; font-size: 1rem; line-height: 1.5; }
.labor-day-sale-code { margin: 16px 0; padding: 12px; border-radius: 9px; background: #fff0e3; color: #422007; font-size: 0.875rem; line-height: 1.7; }
.labor-day-sale-code strong { display: inline-block; margin: 0 3px; font-size: 1.05rem; letter-spacing: 0.08em; }
.labor-day-sale .labor-day-sale-deadline { color: #c8d8e1; font-size: 0.875rem; }
.labor-day-monthly-note { font-size: 0.875rem; line-height: 1.4; color: #234755; text-align: center; }
@media (max-width: 480px) { .labor-day-sale { padding: 17px; } }

.paywall-tier[data-checkout-plan] { font-family: inherit; color: inherit; cursor: pointer; text-align: center; min-height: 44px; appearance: none; }
.paywall-tier[data-checkout-plan]:hover { border-color: #ffae66; box-shadow: 0 0 0 2px #ffae6633; }
.paywall-tier[data-checkout-plan]:focus-visible { outline: 3px solid #ffae66; outline-offset: 4px; }
.paywall-tier[data-checkout-plan]:disabled { cursor: wait; opacity: .65; }
.plan-card-action { font-size: 14px; font-weight: 700; margin-top: 10px; display: block; color: #ffb979; }
.plan-checkout-status { font-size: 14px; line-height: 1.5; text-align: center; }
.plan-checkout-status:empty { display: none; }

.evfx-qr-launch{min-height:44px;border:1px solid #405b68;border-radius:10px;padding:11px 16px;background:#11242e;color:#ecf9ff;font:600 14px/1.4 system-ui,sans-serif;cursor:pointer}
.evfx-qr-launch-inline{width:100%;margin-top:14px}
.evfx-qr-launch-floating{position:fixed;right:22px;bottom:22px;z-index:80;box-shadow:0 5px 24px #0006}
body.unlocked .evfx-qr-launch{display:none}
.evfx-qr-dialog{color-scheme:dark;width:min(460px,calc(100vw - 24px));max-height:calc(100dvh - 24px);padding:26px;border:1px solid #3f5967;border-radius:18px;background:#0d1720;color:#edf6fa;box-shadow:0 24px 90px #0009;font:16px/1.5 system-ui,sans-serif;text-align:center}
.evfx-qr-dialog::backdrop{background:#02090dd9}
.evfx-qr-dialog *{box-sizing:border-box}
.evfx-qr-dialog h2{margin:0 0 8px;font-size:24px;line-height:1.15;letter-spacing:-.03em}
.evfx-qr-dialog p{margin:10px 0;color:#b8cad6;font-size:14px}
.evfx-qr-dialog img{display:block;width:224px;height:224px;max-width:100%;margin:20px auto;background:white;border:10px solid white;border-radius:10px;image-rendering:pixelated}
.evfx-qr-dialog a{color:#a4dff5;text-decoration:underline;text-underline-offset:3px}
.evfx-qr-dialog button{display:block;min-height:44px;width:100%;margin-top:20px;border:1px solid #3c5565;border-radius:9px;padding:11px 16px;background:#1b303e;color:#eef7fc;font:600 14px system-ui,sans-serif;cursor:pointer}
.evfx-qr-dialog :focus-visible,.evfx-qr-launch:focus-visible{outline:3px solid #88d6f4;outline-offset:4px}
.evfx-qr-dialog .evfx-qr-steps{padding:14px;background:#142531;border-radius:10px;text-align:left}
@media(max-width:700px){.evfx-qr-launch-floating{display:none}.evfx-qr-dialog{padding:20px}.evfx-qr-dialog img{width:200px;height:200px}}

.soundboard.sl-enhanced > .voice-row,.soundboard.sl-enhanced > .hud-side-title{display:none!important}
#soundLibrary{width:100%;min-width:0;color:#eef6fa;font-family:Arial,sans-serif;text-align:left}
#soundLibrary *{box-sizing:border-box}
#soundLibrary [hidden]{display:none!important}
#soundLibrary .sl-heading{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
#soundLibrary .sl-eyebrow{font:11px monospace;letter-spacing:1.4px;text-transform:uppercase;color:#a9bdcb}
#soundLibrary h2{font-size:20px;line-height:1.3;font-weight:500;margin:6px 0;overflow-wrap:anywhere}
#soundLibrary button{font-family:inherit;cursor:pointer;touch-action:manipulation}
#soundLibrary .sl-toggle,#soundLibrary .sl-done{min-height:44px;padding:10px 12px;border:1px solid #466270;border-radius:9px;background:#162c39;color:#64dbea;font-size:13px;white-space:nowrap}
#soundLibrary .sl-group{border-top:1px solid #344957;margin-top:18px;padding-top:16px}
#soundLibrary .sl-group-heading{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}
#soundLibrary h3{margin:0;font-size:15px;line-height:1.4;font-weight:500}
#soundLibrary .sl-group-heading>span{font-size:12px;color:#a9bdcb;white-space:nowrap}
#soundLibrary .sl-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:9px}
#soundLibrary .sl-tile{display:flex;min-width:0;border:1px solid #3a4d5b;border-radius:10px;overflow:hidden;background:#152530}
#soundLibrary .sl-pick{display:flex;align-items:center;gap:8px;flex:1;min-width:0;min-height:62px;padding:10px;border:0;background:transparent;color:#e3edf3;text-align:left;font-size:14px;line-height:1.35;overflow-wrap:anywhere}
#soundLibrary .sl-mark{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;width:15px;height:15px;border-radius:50%;border:1px solid #8ba1ae;font-size:11px}
#soundLibrary .sl-selected{background:#183742;border-color:#64dbea}
#soundLibrary .sl-selected .sl-pick{color:#64dbea}
#soundLibrary .sl-selected .sl-mark{background:#64dbea;border-color:#64dbea;color:#071620}
#soundLibrary .sl-star{flex:0 0 44px;min-height:44px;padding:0;border:0;border-left:1px solid #3a4d5b;border-radius:0;background:transparent;color:#b1c5d1;font-size:24px}
#soundLibrary .sl-star[aria-pressed=true]{color:#ffcf77;background:#302c25}
#soundLibrary .sl-empty{font-size:13px;line-height:1.5;color:#b0c3cf;background:#152530;padding:14px;margin:0;border-radius:9px}
#soundLibrary .sl-bottom{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px;margin-top:20px;color:#a9bdcb;font-size:12px}
#soundLibrary .sl-status{font-size:12px;line-height:1.5;color:#b0c3cf}
#soundLibrary .sl-status:empty{display:none}
/* Expanded library shares the HUD, never the audio or GPS update loop. */
body.sound-library-open .speed-hud{display:grid!important;grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;grid-template-areas:'brand brand' 'gauge rpm' 'sound sound'!important;max-height:calc(100dvh - 140px);overflow-y:auto;overscroll-behavior:contain;align-items:center;gap:20px!important}
body.sound-library-open .speed-hud-secondary{display:contents!important}
body.sound-library-open .drive-center-stack{grid-area:gauge;justify-content:center}
body.sound-library-open .racing-signature{grid-area:brand}
body.sound-library-open .rpm-panel{grid-area:rpm}
body.sound-library-open .speed-hud .soundboard{grid-area:sound;width:100%!important;max-width:none!important;min-width:0!important;align-items:stretch}
@media(max-width:1000px){#soundLibrary .sl-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:700px) and (orientation:portrait){body.sound-library-open .speed-hud{max-height:none;overflow:visible}#soundLibrary .sl-pick{font-size:13px;padding:10px 8px}#soundLibrary .sl-heading>div{flex:1 1 145px}#soundLibrary .sl-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:480px){#soundLibrary .sl-grid{grid-template-columns:minmax(0,1fr)}#soundLibrary .sl-pick{font-size:14px;min-height:56px;overflow-wrap:normal}}

/* Selectable gauge styles (gauge-styles.js). Classic keeps the original HUD;
   any other style hides the speed ring and RPM panel and shows one combined
   instrument in their place. Apex Racing's artwork is built around the
   classic ring, so that scene always keeps it. */
#gaugeStyleMount { display: none; }
body.gauge-style-custom:not([data-drive-scene="apex-racing"]) #speedGaugeEl,
body.gauge-style-custom:not([data-drive-scene="apex-racing"]) #rpmPanel { display: none; }
body.gauge-style-custom:not([data-drive-scene="apex-racing"]) #gaugeStyleMount {
  display: flex; justify-content: center; align-items: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent; border-radius: 16px;
}
#gaugeStyleMount:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
body.hide-speedometer #gaugeStyleMount { visibility: hidden; pointer-events: none; }

.gs-svg { display: block; height: auto; overflow: visible; }
.gs-data { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
.gs-ui { font-family: var(--font-ui); }
#gaugeStyleMount .gs-round { width: 230px; }
#gaugeStyleMount .gs-wide { width: 470px; }
#gaugeStyleMount .gs-svg { filter: drop-shadow(0 10px 28px rgba(0, 0, 0, .45)); }

@keyframes gs-kick { 0% { transform: translateY(0); } 30% { transform: translateY(3px); } 100% { transform: translateY(0); } }
.gs-kick { animation: gs-kick .34s ease-out; }
@media (prefers-reduced-motion: reduce) { .gs-kick { animation: none; } }

/* Phones: the gauge takes the whole top row the RPM panel used to share. */
@media (max-width: 700px) and (orientation: portrait),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  body.gauge-style-custom:not([data-drive-scene="apex-racing"]) .drive-center-stack { grid-column: 1 / -1; }
  #gaugeStyleMount .gs-round { width: min(62vw, 220px); }
  #gaugeStyleMount .gs-wide { width: min(calc(100vw - 32px), 420px); }
}
/* Shorter desktop and in-car windows: step down so the dial clears the edge. */
@media (min-width: 701px) and (max-height: 760px) {
  #gaugeStyleMount .gs-round { width: 196px; }
  #gaugeStyleMount .gs-wide { width: 410px; }
}
/* Short in-car and landscape phone screens. */
@media (orientation: landscape) and (max-height: 500px) {
  #gaugeStyleMount .gs-round { width: 150px; }
  #gaugeStyleMount .gs-wide { width: 330px; }
}

/* Settings picker */
#driverSettingsDialog .ds-gauge-style { margin: 18px 0; font-size: 15px; }
#driverSettingsDialog .gs-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
#driverSettingsDialog .gs-choices button {
  display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 44px;
  padding: 10px 8px 9px; border: 1px solid var(--hairline-strong); border-radius: 14px;
  background: var(--surface-raised); color: var(--text-dim); font: 600 13px var(--font-ui); cursor: pointer;
}
#driverSettingsDialog .gs-choices button[aria-checked="true"] { border-color: var(--accent); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }
/* The whole card is the tap target; iOS WebKit can drop taps that land on SVG. */
#driverSettingsDialog .gs-choices button * { pointer-events: none; }
#driverSettingsDialog .gs-thumb { display: flex; align-items: center; justify-content: center; width: 100%; height: 64px; pointer-events: none; }
#driverSettingsDialog .gs-thumb .gs-round { height: 64px; width: auto; }
#driverSettingsDialog .gs-thumb .gs-wide { width: 100%; max-height: 64px; }
@media (max-width: 520px) { #driverSettingsDialog .gs-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* The two styles without their own instrument face get the HUD's frosted
   surface so they stay legible over bright scenes. */
body.gauge-style-custom[data-gauge-style="hypercar"] #gaugeStyleMount,
body.gauge-style-custom[data-gauge-style="ev-minimal"] #gaugeStyleMount {
  background: var(--surface); border: 1px solid var(--hairline);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
body.gauge-style-custom[data-gauge-style="hypercar"] #gaugeStyleMount { padding: 6px 14px 8px; border-radius: 24px; }
body.gauge-style-custom[data-gauge-style="ev-minimal"] #gaugeStyleMount { padding: 8px; border-radius: 50%; }
body.gauge-style-custom[data-gauge-style="hypercar"] #gaugeStyleMount .gs-svg,
body.gauge-style-custom[data-gauge-style="ev-minimal"] #gaugeStyleMount .gs-svg { filter: none; }

/* Boost gauge (boost-gauge.js): lives in the RPM panel, replacing the
   decorative RPM trace while a forced-induction sound is playing. */
.boost-gauge { display: none; width: 100%; max-width: 230px; margin: 2px auto 0; }
#rpmPanel.has-boost .boost-gauge, #gaugeStyleMount.has-boost .boost-gauge { display: block; }
#rpmPanel.has-boost .rpm-trace { display: none; }
#rpmPanel.has-boost .rpm-scale { display: none; }

/* Custom gauge styles: the gauge sits beside the instrument inside
   #gaugeStyleMount as a pod skinned to match it (boost-gauge.js). */
#gaugeStyleMount.has-boost { gap: 14px; }
#gaugeStyleMount .boost-gauge.is-pod { margin: 0; max-width: none; flex: none; width: 150px; }
#gaugeStyleMount.has-boost .gs-wide + .boost-gauge.is-pod { width: 172px; }
#gaugeStyleMount .is-pod .bg-svg { filter: drop-shadow(0 10px 28px rgba(0, 0, 0, .45)); }
#gaugeStyleMount .skin-bare .bg-svg { filter: none; }
.bg-dash-face { fill: #05070a; stroke: rgba(150, 178, 196, .2); }
.skin-dash .bg-kind, .skin-dash .bg-unit { letter-spacing: .24em; }
/* EV Minimal's frosted disc becomes a capsule around dial + pod. */
body[data-gauge-style="ev-minimal"] #gaugeStyleMount.has-boost { border-radius: 999px !important; padding: 8px 22px 8px 8px !important; }

/* Shorter desktop and in-car windows (Tesla): match gauge-styles.css steps. */
@media (min-width: 701px) and (max-height: 760px) {
  #gaugeStyleMount .boost-gauge.is-pod { width: 150px; }
  #gaugeStyleMount.has-boost .gs-wide + .boost-gauge.is-pod { width: 168px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #gaugeStyleMount.has-boost { gap: 8px; }
  #gaugeStyleMount .boost-gauge.is-pod { width: 104px; }
  #gaugeStyleMount.has-boost .gs-wide + .boost-gauge.is-pod { width: 112px; }
  #gaugeStyleMount.has-boost .gs-wide { width: 300px; }
}
/* Phones: round dials share the row with the pod; wide dashes stack it below. */
@media (max-width: 700px) and (orientation: portrait),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  #gaugeStyleMount.has-boost { gap: 10px; }
  #gaugeStyleMount.has-boost .gs-round { width: min(52vw, 200px); }
  #gaugeStyleMount .boost-gauge.is-pod { width: min(36vw, 150px); }
  #gaugeStyleMount.has-boost:has(.gs-wide) { flex-direction: column; gap: 6px; }
  #gaugeStyleMount.has-boost .gs-wide + .boost-gauge.is-pod { width: min(38vw, 150px); }
  body[data-gauge-style="ev-minimal"] #gaugeStyleMount.has-boost { padding: 6px 14px 6px 6px !important; }
}

.bg-svg { display: block; width: 100%; height: auto; overflow: visible; }
.bg-track { fill: none; stroke: rgba(255, 255, 255, .08); stroke-width: 10; stroke-linecap: round; }
.bg-zone-vac { fill: none; stroke: rgba(95, 211, 228, .18); stroke-width: 10; }
.bg-zone-boost { fill: none; stroke: url(#bgBoostGrad); stroke-opacity: .22; stroke-width: 10; }
.bg-zone-red { fill: none; stroke: #ff2d55; stroke-opacity: .32; stroke-width: 10; stroke-linecap: round; }
.bg-fill { fill: none; stroke: url(#bgBoostGrad); stroke-width: 10; stroke-linecap: round; filter: drop-shadow(0 0 5px rgba(255, 120, 50, .75)); }
.bg-fill.is-vac { stroke: #5fd3e4; filter: drop-shadow(0 0 4px rgba(95, 211, 228, .6)); }
.bg-tick { stroke: rgba(255, 255, 255, .55); stroke-width: 1.6; }
.bg-tick-minor { stroke: rgba(255, 255, 255, .28); stroke-width: 1; }
.bg-tick-zero { stroke: rgba(255, 255, 255, .85); stroke-width: 2; }
.bg-num { fill: rgba(255, 255, 255, .62); font: 600 9.5px/1 ui-monospace, "SF Mono", Menlo, monospace; text-anchor: middle; }
.bg-num-vac { fill: rgba(95, 211, 228, .75); font-size: 8px; letter-spacing: .08em; }
.bg-needle-line { stroke: #fff; stroke-width: 2.4; stroke-linecap: round; }
.bg-needle-glow { stroke: #ff7a3a; stroke-width: 7; stroke-linecap: round; opacity: .35; filter: blur(2px); }
.bg-hub { fill: #0b1219; stroke: rgba(255, 255, 255, .7); stroke-width: 2; }
.bg-peak { fill: #ffd27a; transition: opacity .3s; }
.bg-value { fill: #fff; font: 700 25px/1 ui-monospace, "SF Mono", Menlo, monospace; text-anchor: middle; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.bg-unit { fill: rgba(255, 255, 255, .55); font: 700 7.5px/1 system-ui, sans-serif; text-anchor: middle; letter-spacing: .16em; }
.bg-kind { fill: #ffb347; font: 800 8px/1 system-ui, sans-serif; text-anchor: middle; letter-spacing: .2em; }
.bg-lamp { fill: rgba(255, 255, 255, .16); font: 800 6.5px/1 system-ui, sans-serif; text-anchor: middle; letter-spacing: .12em; transition: fill .12s; }
.bg-lamp.is-on { fill: #ff4d6d; filter: drop-shadow(0 0 4px rgba(255, 77, 109, .9)); }
.boost-gauge.is-high .bg-value { fill: #ffcf9e; }

/* low-power devices (Tesla Atom): no filter effects */
.boost-gauge.lite .bg-fill, .boost-gauge.lite .bg-fill.is-vac, .boost-gauge.lite .bg-lamp.is-on { filter: none; }
.boost-gauge.lite .bg-needle-glow { display: none; }

/* light theme */
body.theme-day .boost-gauge:is(.skin-panel, .skin-bare) .bg-track { stroke: rgba(16, 34, 45, .1); }
body.theme-day .boost-gauge:is(.skin-panel, .skin-bare) .bg-tick { stroke: rgba(16, 34, 45, .55); }
body.theme-day .boost-gauge:is(.skin-panel, .skin-bare) .bg-num { fill: rgba(16, 34, 45, .65); }
body.theme-day .boost-gauge:is(.skin-panel, .skin-bare) .bg-value { fill: #10222d; }
body.theme-day .boost-gauge:is(.skin-panel, .skin-bare) .bg-unit { fill: rgba(16, 34, 45, .55); }
body.theme-day .boost-gauge:is(.skin-panel, .skin-bare) .bg-needle-line { stroke: #10222d; }
body.theme-day .boost-gauge:is(.skin-panel, .skin-bare) .bg-hub { fill: #fff; stroke: rgba(16, 34, 45, .6); }

/* Settings are independent of the scene canvases and audio/GPS pipeline. */
#driverSettingsDialog {
  color: var(--text); background: #111923; border: 1px solid var(--hairline-strong);
  width: min(620px, calc(100vw - 32px)); max-width: none;
  max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);
  padding: 0; margin: auto; border-radius: 24px; overflow-y: auto;
  box-shadow: 0 30px 100px #0008; text-align: left; overscroll-behavior: contain;
  font-family: var(--font-ui); color-scheme: dark;
}
#driverSettingsDialog:not([open]) { display: none; }
#driverSettingsDialog::backdrop { background: rgb(3 10 17 / 66%); }
body.driver-settings-open { overflow: hidden; }
#driverSettingsDialog .ds-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 28px 18px; background: inherit; border-bottom: 1px solid var(--hairline); }
#driverSettingsDialog h2 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -.6px; color: var(--text); }
#driverSettingsDialog .ds-kicker { margin: 0 0 5px; color: var(--accent); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; }
#driverSettingsDialog #closeDriverSettings { width: 44px; height: 44px; padding: 0; border: 1px solid var(--hairline); border-radius: 50%; background: transparent; color: var(--text-dim); font: 28px var(--font-ui); }
#driverSettingsDialog .controls { display: flex; margin: 0; padding: 24px 28px 28px; gap: 22px; }
#driverSettingsDialog .controls label { font-size: 15px; line-height: 1.5; gap: 10px; color: var(--text); }
#driverSettingsDialog input[type=range] { min-height: 38px; width: 100%; accent-color: var(--accent); }
#driverSettingsDialog input[type=checkbox] { accent-color: var(--accent); width: 22px; height: 22px; flex-shrink: 0; }
#driverSettingsDialog #hideSpeedometer { appearance: none; position: relative; width: 46px; height: 28px; margin: 0; border: 1px solid var(--hairline-strong); border-radius: 20px; background: var(--surface-raised); cursor: pointer; }
#driverSettingsDialog #hideSpeedometer::after { content: ''; position: absolute; width: 20px; height: 20px; top: 3px; left: 3px; border-radius: 50%; background: var(--text-dim); }
#driverSettingsDialog #hideSpeedometer:checked { background: var(--accent); border-color: var(--accent); }
#driverSettingsDialog #hideSpeedometer:checked::after { transform: translateX(18px); background: #fff; }
#driverSettingsDialog .ds-volume-label { display: flex; justify-content: space-between; gap: 12px; }
#driverSettingsDialog output { font-variant-numeric: tabular-nums; color: var(--text-dim); }
#driverSettingsDialog .ds-section { border-top: 1px solid var(--hairline); padding-top: 23px; }
#driverSettingsDialog h3 { color: var(--text-dim); text-transform: uppercase; letter-spacing: .14em; font-size: 11px; margin: 0 0 18px; font-weight: 600; }
#driverSettingsDialog .ds-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 18px 0; font-size: 15px; line-height: 1.45; }
#driverSettingsDialog label.ds-row { flex-direction: row; }
#driverSettingsDialog .ds-segments { display: inline-flex; flex-shrink: 0; gap: 4px; padding: 4px; border: 1px solid var(--hairline-strong); border-radius: 30px; }
#driverSettingsDialog .ds-segments button { min-height: 40px; min-width: 62px; padding: 8px 13px; border: 0; border-radius: 24px; font: 14px var(--font-ui); letter-spacing: 0; text-transform: none; color: var(--text-dim); background: transparent; cursor: pointer; }
#driverSettingsDialog .ds-segments button[aria-pressed=true] { background: var(--accent); color: #071a20; font-weight: 600; }
#driverSettingsDialog .ds-help { color: var(--text-dim); font-size: 12px; line-height: 1.6; margin: -8px 0 20px; }
#driverSettingsDialog .ds-save-note { color: var(--text-dim); font-size: 12px; line-height: 1.6; margin: 0; }
#driverSettingsDialog .ds-terms { color: var(--text-dim); font-size: 13px; text-underline-offset: 3px; }
#driverSettingsDialog .settings-group, #driverSettingsDialog .advanced-settings, #driverSettingsDialog .settings-switch { padding: 16px; background: var(--surface-raised); border-color: var(--hairline); }
#driverSettingsDialog .settings-group-title, #driverSettingsDialog .advanced-settings summary, #driverSettingsDialog .settings-switch strong { font-size: 14px; color: var(--text); }
#driverSettingsDialog .settings-help, #driverSettingsDialog .settings-switch small { font-size: 12px; line-height: 1.6; color: var(--text-dim); }
#driverSettingsDialog .segmented-setting button { min-height: 44px; font-size: 13px; }
#driverSettingsDialog .settings-switch { flex-direction: row; align-items: flex-start; }
#driverSettingsDialog button:focus-visible, #driverSettingsDialog input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
body.hide-speedometer #speedGaugeEl { visibility: hidden; pointer-events: none; }
body.theme-day #driverSettingsDialog { background: #f8fafb; color-scheme: light; }
body.theme-day #driverSettingsDialog .ds-segments button[aria-pressed=true] { color: white; }
/* Existing new scenes remain untouched; only interface surfaces change theme. */
body.theme-day .background-picker, body.theme-day .background-choices { background: #f8fafb; border-color: #b8c8d1; }
body.theme-day .background-picker { --text: #10222d; --text-dim: #4d6473; --accent: #00778f; }
body.theme-day .background-picker #backgroundTrigger, body.theme-day .background-switch, body.theme-day .background-menu-heading, body.theme-day .background-picker .background-choices button { color: #10222d; }
body.theme-day .background-eyebrow, body.theme-day #backgroundMotionWarning, body.theme-day .background-status, body.theme-day .background-choices button small, body.theme-day .background-menu-heading span { color: #4d6473; }
body.theme-day .background-picker .background-choices button:hover, body.theme-day .background-picker .background-choices button[aria-pressed=true] { background: #dbeef2; color: #006e83; }
body.theme-day #soundLibrary { color: #10222d; }
body.theme-day #soundLibrary .sl-eyebrow, body.theme-day #soundLibrary .sl-group-heading>span, body.theme-day #soundLibrary .sl-status, body.theme-day #soundLibrary .sl-bottom { color: #4d6473; }
body.theme-day #soundLibrary .sl-tile, body.theme-day #soundLibrary .sl-empty { background: #edf3f6; color: #365463; border-color: #b8c8d1; }
body.theme-day #soundLibrary .sl-pick, body.theme-day #soundLibrary .sl-star { color: #163d4b; }
body.theme-day #soundLibrary .sl-toggle, body.theme-day #soundLibrary .sl-done, body.theme-day #soundLibrary .sl-selected { background: #dbeef2; color: #006e83; border-color: #83aeba; }
body.theme-day #soundLibrary .sl-selected .sl-pick { color: #006e83; }
#backgroundMotionWarning { max-width: 180px; }
@media (min-width: 1000px) and (min-height: 501px) {
  body.controls-right #controlsSidebar { left: auto; right: 20px; width: 218px; }
  body.controls-right #panelToggle { left: auto; right: 238px; border-left: 1px solid var(--hairline-strong); border-right: 0; border-radius: 14px 0 0 14px; }
  body.controls-right #panelToggle .panel-toggle-icon { transform: rotate(180deg); }
  body.controls-right.panel-hidden #controlsSidebar { transform: translateY(-50%) translateX(120%); }
  body.controls-right.panel-hidden #panelToggle { left: auto; right: 0; }
  body.controls-right.panel-hidden #panelToggle .panel-toggle-icon { transform: none; }
}
@media (max-width: 520px) {
  #driverSettingsDialog { width: calc(100vw - 20px); max-height: calc(100dvh - 24px); border-radius: 20px; }
  #driverSettingsDialog .ds-header { padding: 18px; }
  #driverSettingsDialog .controls { padding: 20px 18px 24px; }
  #driverSettingsDialog .ds-row { flex-wrap: wrap; gap: 10px; }
  #driverSettingsDialog .ds-segments button { min-height: 44px; padding: 8px 12px; }
  #driverSettingsDialog h2 { font-size: 24px; }
}

/* ==========================================================================
   UI polish layer: loaded last, visual only.
   One consistent "smoked glass" surface for every driving-screen panel so
   more of the road shows through, tighter spacing, and calmer secondary
   text. No layout logic in app.js depends on anything here; deleting this
   file restores the previous look exactly.
   ========================================================================== */

:root {
  --glass-bg: rgba(9, 13, 18, 0.34);
  --glass-bg-strong: rgba(9, 13, 18, 0.5);
  --glass-menu: rgba(11, 16, 22, 0.86);
  --glass-border: rgba(255, 255, 255, 0.09);
  --glass-border-strong: rgba(255, 255, 255, 0.16);
  --glass-blur: blur(22px) saturate(160%);
  --glass-shadow: 0 12px 40px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --glass-text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

/* ---------- Shared glass surface ---------- */
.scene-picker.background-picker,
.control-strip,
.speed-hud .speed-hud-side,
#panelToggle,
.mode-badge,
#controlsSidebar > .affiliate-banner {
  background: var(--glass-bg) !important;
  border: 1px solid var(--glass-border) !important;
  backdrop-filter: var(--glass-blur) !important;
  -webkit-backdrop-filter: var(--glass-blur) !important;
  box-shadow: var(--glass-shadow) !important;
}

.control-strip, .speed-hud .speed-hud-side, .scene-picker.background-picker { text-shadow: var(--glass-text-shadow); }

/* ---------- Background picker: one slim row instead of a help card ---------- */
.scene-picker.background-picker {
  width: auto;
  min-width: 340px;
  padding: 6px 8px 6px 18px;
  gap: 0 18px;
  border-radius: 16px;
}
.background-eyebrow { font-size: 9px; letter-spacing: .16em; color: rgba(230, 240, 246, .6); }
.background-picker #backgroundTrigger { min-height: 36px; padding: 0; font-size: 15px; }
.background-chevron { font-size: 16px; opacity: .8; }
.background-motion { padding-left: 18px; border-left-color: var(--glass-border-strong); }
.background-switch { min-height: 40px; font-size: 12px; font-weight: 500; color: rgba(245, 247, 250, .86); }
.background-switch-track { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .22); }
/* Same information, kept for screen readers, but not printed on the road. */
#backgroundMotionWarning,
.background-status {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.background-picker .background-choices {
  background: var(--glass-menu);
  border-color: var(--glass-border-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  text-shadow: none;
}
.background-picker .background-choices button { min-height: 52px; }
.background-picker .background-choices button:hover { background: rgba(255, 255, 255, .06); }
.background-picker .background-choices button[aria-pressed='true'] { background: rgba(95, 211, 228, .12); }

/* ---------- Drive-mode badge ---------- */
.mode-badge { padding: 5px 13px; font-size: .58rem; color: rgba(230, 240, 246, .72); }

/* ---------- Sidebar ---------- */
.control-strip { padding: 18px 16px 14px; gap: 12px; border-radius: 20px; }
#startBtn {
  background: rgba(95, 211, 228, .08);
  box-shadow: 0 0 0 6px rgba(95, 211, 228, .06), 0 8px 24px rgba(0, 0, 0, .25);
}
#startBtn.running { box-shadow: 0 0 0 6px rgba(95, 211, 228, .16), 0 8px 28px rgba(95, 211, 228, .25); }
#revBtn { background: rgba(255, 138, 61, .07); margin-top: 4px; }
#revBtn:disabled { opacity: .28; }
.gps-settling-tip {
  padding: 10px 0 0;
  border-top: 1px solid var(--glass-border);
  color: rgba(214, 226, 234, .66);
  font-size: 11px;
  line-height: 1.5;
}
.gps-settling-tip strong { font-size: 11.5px; margin-bottom: 2px; color: rgba(240, 246, 250, .9); }

/* Settings and Sound Studio: a matched pair of quiet row buttons. */
.settings-toggle,
.studio-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 42px;
  margin: 0;
  padding: 0 14px;
  border: 1px solid var(--glass-border-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, .04);
  color: rgba(236, 243, 247, .9);
  font: 500 13px var(--font-ui);
  letter-spacing: 0;
  text-align: left;
  text-shadow: none;
  transition: background .15s ease, border-color .15s ease;
}
.settings-toggle::after { content: '⚙'; font-size: 14px; opacity: .65; }
.studio-link::after { content: '→'; opacity: .65; }
.settings-toggle:hover, .studio-link:hover,
.settings-toggle[aria-expanded="true"] { background: rgba(255, 255, 255, .09); border-color: rgba(95, 211, 228, .55); color: #fff; }
.studio-link { color: var(--accent); }

.legal-footer { margin-top: 10px; font-size: .6rem; color: rgba(214, 226, 234, .5); text-shadow: var(--glass-text-shadow); }
.legal-footer a { color: inherit; }

#controlsSidebar > .affiliate-banner {
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: .74rem;
  font-weight: 500;
  color: rgba(240, 246, 250, .88);
  text-shadow: var(--glass-text-shadow);
}
#controlsSidebar > .affiliate-banner .affiliate-banner-sub { margin-top: 2px; font-size: .62rem; color: rgba(214, 226, 234, .6); }
#controlsSidebar > .affiliate-banner:hover { border-color: rgba(95, 211, 228, .5) !important; }

/* Collapse tab */
#panelToggle { color: rgba(236, 243, 247, .8); }
#panelToggle:hover, #panelToggle:focus-visible { color: #fff; }

/* ---------- Bottom HUD ---------- */
.speed-hud .speed-hud-side { border-radius: 18px; }
.hud-side-title { color: rgba(214, 226, 234, .62); }
.rpm-rail { background: rgba(255, 255, 255, .1); }

/* Sound picker card */
#soundLibrary { font-family: var(--font-ui); }
#soundLibrary .sl-eyebrow { font-family: var(--font-data); color: rgba(214, 226, 234, .62); }
#soundLibrary h2 { font-weight: 550; letter-spacing: -.01em; }
#soundLibrary .sl-toggle, #soundLibrary .sl-done {
  border-color: rgba(95, 211, 228, .4);
  background: rgba(95, 211, 228, .1);
  color: #8fe6f1;
  border-radius: 11px;
  text-shadow: none;
}
#soundLibrary .sl-toggle:hover, #soundLibrary .sl-done:hover { background: rgba(95, 211, 228, .18); }

/* Expanded library: roomier tiles so names never break mid-word. */
#soundLibrary .sl-group { border-top-color: var(--glass-border-strong); }
#soundLibrary .sl-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
#soundLibrary .sl-tile { background: rgba(255, 255, 255, .045); border-color: var(--glass-border-strong); border-radius: 12px; transition: border-color .15s ease, background .15s ease; }
#soundLibrary .sl-tile:hover { background: rgba(255, 255, 255, .08); }
#soundLibrary .sl-pick { min-height: 54px; font-size: 13.5px; overflow-wrap: normal; word-break: normal; hyphens: manual; text-shadow: none; }
#soundLibrary .sl-star { flex-basis: 42px; border-left-color: var(--glass-border); color: rgba(214, 226, 234, .6); font-size: 20px; }
#soundLibrary .sl-star[aria-pressed=true] { background: rgba(255, 207, 119, .1); }
#soundLibrary .sl-selected { background: rgba(95, 211, 228, .13); border-color: rgba(95, 211, 228, .7); }
#soundLibrary .sl-empty { background: rgba(255, 255, 255, .04); border: 1px dashed var(--glass-border-strong); color: rgba(214, 226, 234, .7); text-shadow: none; }
body.sound-library-open .speed-hud .soundboard { background: var(--glass-bg-strong) !important; }
/* With a combined gauge style the RPM slot is empty, so the gauge centres. */
body.sound-library-open.gauge-style-custom:not([data-drive-scene="apex-racing"]) .drive-center-stack { grid-column: 1 / -1; }

/* ---------- Settings dialog: a touch of depth, still fully legible ---------- */
#driverSettingsDialog {
  background: rgba(14, 20, 28, .9);
  border-color: var(--glass-border-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
/* Sticky header must be opaque, or scrolled rows ghost through the title. */
#driverSettingsDialog .ds-header { background: #0f161e; }
body.theme-day #driverSettingsDialog .ds-header { background: #f8fafb; }
/* Plain-span labels (Theme, Gauge style) inherited a light colour in day mode. */
body.theme-day #driverSettingsDialog { color: #10222d; }
#driverSettingsDialog::backdrop { background: rgba(3, 8, 13, .5); backdrop-filter: blur(3px); }

/* ---------- Phones & short in-car screens ---------- */
@media (max-width: 700px) and (orientation: portrait),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  .speed-hud .speed-hud-side,
  #controlsSidebar,
  .control-strip { background: var(--glass-bg) !important; }
  .scene-picker.background-picker { min-width: 0; min-height: 0; padding: 6px 8px 6px 14px; }
  .mode-badge { top: calc(max(16px, env(safe-area-inset-top)) + 72px); }
  .settings-toggle, .studio-link { min-height: 48px; font-size: 14px; }
  #panelToggle, body.panel-hidden #panelToggle { width: auto; height: auto; border-radius: 12px; }
  #soundLibrary .sl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  #soundLibrary .sl-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Light theme keeps the same idea with frosted white ---------- */
body.theme-day {
  --glass-bg: rgba(255, 255, 255, .5);
  --glass-bg-strong: rgba(255, 255, 255, .68);
  --glass-menu: rgba(250, 252, 253, .92);
  --glass-border: rgba(16, 34, 45, .1);
  --glass-border-strong: rgba(16, 34, 45, .18);
  --glass-shadow: 0 12px 36px rgba(16, 34, 45, .14), inset 0 1px 0 rgba(255, 255, 255, .6);
  --glass-text-shadow: none;
}
body.theme-day .settings-toggle, body.theme-day .legal-footer,
body.theme-day #controlsSidebar > .affiliate-banner, body.theme-day .gps-settling-tip strong { color: #10222d; }
body.theme-day .gps-settling-tip, body.theme-day #controlsSidebar > .affiliate-banner .affiliate-banner-sub { color: #4d6473; }
body.theme-day .studio-link { color: #00778f; }

/* Respect users who ask for less transparency. */
@media (prefers-reduced-transparency: reduce) {
  :root { --glass-bg: rgba(12, 17, 23, .9); --glass-bg-strong: rgba(12, 17, 23, .94); }
}

/* Text-bearing sidebar panels get slightly more tint than the HUD so small
   copy stays readable over bright skies. */
.control-strip { background: rgba(9, 13, 18, .44) !important; }
body.theme-day .control-strip { background: rgba(255, 255, 255, .62) !important; }

/* ---------- Paywall ---------- */
/* The affiliate CTA inherited the dark HUD surface but the paywall's dark
   text colour, leaving it nearly unreadable. Match it to the light card. */
#paywallOverlay .affiliate-banner {
  background: linear-gradient(180deg, #f3fbfc, #e6f5f8);
  border: 1px solid #b9dfe6;
  color: #0d2b3a;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset;
}
#paywallOverlay .affiliate-banner .affiliate-banner-sub { color: #3f6170; }
#paywallOverlay .affiliate-banner:hover { border-color: #00778f; }

/* Desktop: the collapse tab stays attached to the sidebar edge. */
@media (min-width: 701px) and (min-height: 501px) {
  #panelToggle:not(#x) { border-left: 0 !important; width: 40px; height: 92px; }
  body.controls-right #panelToggle:not(#x) { border-left: 1px solid var(--glass-border) !important; border-right: 0 !important; }
}

/* Light theme fix-ups for controls that carried a dark-mode style. */
body.theme-day .studio-link:not(#x) { background: rgba(255, 255, 255, .55); border-color: var(--glass-border-strong); color: #00778f; }
body.theme-day .studio-link:not(#x):hover { background: rgba(255, 255, 255, .8); }
body.theme-day .settings-toggle { background: rgba(255, 255, 255, .55); }
body.theme-day #panelToggle { color: #10222d; }
body.theme-day .control-strip, body.theme-day .speed-hud .speed-hud-side, body.theme-day .scene-picker.background-picker { text-shadow: none; }

/* Touch screens: no hover colour/transition on the background picker. iOS
   WebKit treats a hover-triggered transition as "hover content" and swallows
   the first tap, so the picker needed two taps to open or choose. */
@media (hover: none) {
  .scene-picker button,
  .background-picker .background-choices button { transition: none; }
  .scene-picker button:hover { color: inherit; }
  .background-picker .background-choices button:hover { background: transparent; }
  .background-picker .background-choices button[aria-pressed='true']:hover { background: rgba(95, 211, 228, .12); }
}

/* ---------- Low-power devices (Tesla Intel Atom, 4-core, Stability Mode) ----------
   Live background blur over the animated road is one of the most expensive
   things a browser can draw, and on in-car hardware it competes with audio for
   CPU. In performance-lite the glass keeps its translucency but drops the blur. */
body.performance-lite *,
body.performance-lite *::before,
body.performance-lite *::after {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body.performance-lite { --glass-blur: none; }   /* the shared glass rule reads its blur from this */
body.performance-lite:not(.theme-day) {
  --glass-bg: rgba(10, 14, 20, .58);
}
body.performance-lite.theme-day {
  --glass-bg: rgba(255, 255, 255, .72);
}

/* ==========================================================================
   Twin Pill drive controls (Start/Stop + Rev).
   Visual only: app.js still owns #startBtn / #revBtn, their text
   (START/STOP), the .running class, the disabled state and every pointer
   handler. gauge-styles.js feeds --rev-fill (0–1) and .redline while Rev is
   held. The ":not(#x)" suffix outranks the older per-breakpoint rules in
   style.css / mobile-ui.css / apex-racing.css without !important.
   ========================================================================== */

.drive-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px;
  border-radius: 20px;
  background: rgba(9, 13, 18, .42);
  border: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .06);
}
/* Inside the (already glass) sidebar the bar only needs a subtle tray. */
.control-strip .drive-pills { background: rgba(0, 0, 0, .18); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25); backdrop-filter: none; -webkit-backdrop-filter: none; }

#startBtn:not(#x),
#revBtn:not(#x) {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 54px;
  min-height: 54px;
  margin: 0;
  padding: 0 10px;
  border: 0;
  border-radius: 15px;
  font: 700 13px var(--font-ui);
  letter-spacing: .08em;
  text-shadow: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform .08s ease, background-color .2s ease, color .2s ease, box-shadow .2s ease, opacity .2s ease;
  -webkit-tap-highlight-color: transparent;
}
#startBtn:not(#x)::before,
#revBtn:not(#x)::before {
  content: '';
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: var(--pill-icon) center / contain no-repeat;
  mask: var(--pill-icon) center / contain no-repeat;
  position: relative;
}
#startBtn:not(#x):active:not(:disabled),
#revBtn:not(#x):active:not(:disabled) { transform: scale(.97); }

/* Start → solid instrument cyan with a play glyph. */
#startBtn:not(#x) {
  --pill-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5.5v13l11-6.5z'/%3E%3C/svg%3E");
  background: var(--accent);
  color: #04161b;
  box-shadow: 0 6px 18px rgba(95, 211, 228, .28);
}
#startBtn:not(#x):disabled { opacity: .6; cursor: progress; }
/* Running → quiet red outline with a stop glyph. */
#startBtn.running:not(#x) {
  --pill-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='6' y='6' width='12' height='12' rx='2.5'/%3E%3C/svg%3E");
  background: rgba(226, 86, 77, .14);
  color: #ff8f86;
  box-shadow: inset 0 0 0 1.5px rgba(226, 86, 77, .7);
}

/* Rev → orange outline; fills left-to-right with live RPM while held. */
#revBtn:not(#x) {
  --pill-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M13 3 5 13.5h6L10 21l8-10.5h-6z'/%3E%3C/svg%3E");
  --fill-pct: calc(var(--rev-fill, 0) * 100%);
  background:
    linear-gradient(90deg, rgba(255, 138, 61, .55), rgba(255, 138, 61, .9)) left / var(--fill-pct) 100% no-repeat,
    rgba(255, 138, 61, .12);
  color: #ffb27d;
  box-shadow: inset 0 0 0 1.5px rgba(255, 138, 61, .55);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#revBtn.redline:not(#x) {
  background:
    linear-gradient(90deg, rgba(255, 138, 61, .6), var(--limit)) left / var(--fill-pct) 100% no-repeat,
    rgba(255, 138, 61, .12);
}
#revBtn:not(#x):active:not(:disabled) { color: #fff; }
#revBtn:not(#x):disabled { opacity: .38; cursor: not-allowed; }

/* ---------- Web sidebar: pills sit side by side at the top ---------- */
.control-strip > .drive-pills { width: 100%; }

/* ---------- Light theme ---------- */
body.theme-day .control-strip .drive-pills { background: rgba(16, 34, 45, .06); }
body.theme-day #startBtn:not(#x) { background: #00778f; color: #fff; box-shadow: 0 6px 16px rgba(0, 119, 143, .25); }
body.theme-day #startBtn.running:not(#x) { background: rgba(179, 36, 26, .08); color: #b3241a; box-shadow: inset 0 0 0 1.5px rgba(179, 36, 26, .6); }
body.theme-day #revBtn:not(#x) {
  background:
    linear-gradient(90deg, rgba(255, 122, 26, .7), #ff7a1a) left / var(--fill-pct) 100% no-repeat,
    rgba(255, 122, 26, .1);
  color: #b8501a;
  box-shadow: inset 0 0 0 1.5px rgba(184, 80, 26, .55);
}

@media (prefers-reduced-motion: reduce) {
  #startBtn:not(#x), #revBtn:not(#x) { transition: none; }
}
