/*
 * Layout targets the Tesla browser first: a landscape panel that can be as
 * small as ~850×650 (split view next to the car visualization) or the full
 * screen. Sizes that depend on the panel (dial, pedals, cards) are set from
 * JS (see layout() in main.js); CSS avoids newer features (inset,
 * aspect-ratio, dvh) so older in-car Chromium builds render it the same.
 */

:root {
  --bg: #050607;
  --glass: rgba(18, 21, 26, 0.72);
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #f3f5f8;
  --muted: #8a93a0;
  --accent: #ff4d1a;
  --accent-2: #ffb21f;
  --red: #ff2a3d;
  --green: #35e08a;
  --gas: 92, 230, 140;
  --brake: 255, 74, 94;
  --display: "Rajdhani", "Inter", system-ui, sans-serif;
  --app-h: 100vh;
  --pad: 14px;
  --card-h: 96px;
  --pedal-w: 140px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  height: var(--app-h);
  overflow-x: hidden;
  overflow-y: auto; /* never trap content below the fold */
  display: flex;
  flex-direction: column;
  padding: var(--pad);
  font: 15px/1.4 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 50% 0%, rgba(255, 77, 26, 0.09), transparent 60%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- top bar ---------- */

.top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.brand { display: flex; align-items: center; }
.brand-mark {
  position: relative;
  width: 24px;
  height: 24px;
  margin-right: 10px;
  border-radius: 50%;
  background: conic-gradient(from 210deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: 0 0 22px rgba(255, 77, 26, 0.55);
}
.brand-mark::after {
  content: "";
  position: absolute;
  top: 6px; right: 6px; bottom: 6px; left: 6px;
  border-radius: 50%;
  background: var(--bg);
}
.brand-name {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.18em;
}
.brand-name b { font-weight: 700; color: var(--accent); }

.toggles { display: flex; align-items: center; }
.toggles .seg + .seg { margin-left: 8px; }

.seg {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
}
.seg button {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.seg button.on { background: rgba(255, 255, 255, 0.1); color: var(--text); }

/* Small push-start / stop in the corner */
.push-start {
  position: relative;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, #3a3f47 0%, #1a1d22 55%, #0c0e11 100%);
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.6),
    inset 0 2px 1px rgba(255, 255, 255, 0.12),
    0 0 0 5px #121418,
    0 0 0 6px rgba(255, 255, 255, 0.08);
}
.push-ring {
  position: absolute;
  top: 7px; right: 7px; bottom: 7px; left: 7px;
  border-radius: 50%;
  border: 2px solid var(--red);
  box-shadow: 0 0 12px rgba(255, 42, 61, 0.7);
}
.push-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.1em;
  line-height: 1.05;
}
.push-label small { font-size: 8px; letter-spacing: 0.2em; color: var(--muted); }
.push-start.running .push-ring { border-color: var(--green); box-shadow: 0 0 14px rgba(53, 224, 138, 0.75); }

/* ---------- stage: brake | dial | gas ---------- */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 54px 18px 30px;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #0d1014 0%, #07080a 100%);
  border: 1px solid var(--line);
}

.stage-backdrop, .stage-shade {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  pointer-events: none;
}
.stage-backdrop {
  background-size: cover;
  background-position: center 60%;
  opacity: 0.4;
  -webkit-mask-image: radial-gradient(ellipse 80% 75% at 50% 55%, #000 30%, transparent 100%);
  mask-image: radial-gradient(ellipse 80% 75% at 50% 55%, #000 30%, transparent 100%);
}
.stage-shade { background: radial-gradient(ellipse 42% 55% at 50% 52%, rgba(5, 6, 7, 0.7), transparent 75%); }

.car-title { position: absolute; top: 14px; left: 20px; z-index: 2; }
.car-name {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.1;
}
.car-spec { color: var(--muted); font-size: 13px; }

.wing {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  width: var(--pedal-w);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cluster {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

/* Square dial; width/height set from JS to fit the cluster box. */
.dial { position: relative; width: 300px; height: 300px; }
#tach { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

.readout {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: opacity 300ms ease;
}
body:not(.running) .readout { opacity: 0; }

.shift-lights { display: flex; margin-bottom: 0.6em; font-size: var(--dial-font, 16px); }
.shift-lights i {
  width: 0.75em;
  height: 0.75em;
  margin: 0 0.22em;
  border-radius: 50%;
  background: #1c2026;
}
.shift-lights i.on.g { background: var(--green); box-shadow: 0 0 10px var(--green); }
.shift-lights i.on.y { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }
.shift-lights i.on.r { background: var(--red); box-shadow: 0 0 12px var(--red); }

.speed {
  font-family: var(--display);
  font-size: calc(var(--dial-font, 16px) * 6.2);
  font-weight: 700;
  line-height: 0.9;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.12);
}
.unit {
  font-family: var(--display);
  font-weight: 600;
  font-size: calc(var(--dial-font, 16px) * 0.85);
  letter-spacing: 0.3em;
  color: var(--muted);
  margin-top: 0.3em;
}
.gear {
  margin-top: 0.7em;
  width: 2.1em;
  height: 2.1em;
  line-height: 2.1em;
  text-align: center;
  border-radius: 0.4em;
  font-family: var(--display);
  font-size: calc(var(--dial-font, 16px) * 1.6);
  font-weight: 700;
  color: var(--accent-2);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line-2);
  text-shadow: 0 0 14px rgba(255, 178, 31, 0.5);
}

/* Big start button in the middle of the dial */
.big-start {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46%;
  height: 46%;
  margin: -23% 0 0 -23%;
  border-radius: 50%;
  z-index: 3;
  transition: opacity 250ms ease, transform 250ms ease;
}
body.running .big-start { opacity: 0; transform: scale(0.85); pointer-events: none; }

.big-start-glow {
  position: absolute;
  top: -6%; right: -6%; bottom: -6%; left: -6%;
  border-radius: 50%;
  border: 3px solid var(--accent);
  box-shadow: 0 0 30px rgba(255, 77, 26, 0.8), inset 0 0 22px rgba(255, 77, 26, 0.45);
  animation: breathe 1.8s ease-in-out infinite;
}
.big-start-face {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #ff6a2b 0%, #e23a12 45%, #8f1d07 100%);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.6), inset 0 3px 2px rgba(255, 255, 255, 0.35), inset 0 -8px 16px rgba(0, 0, 0, 0.35);
  font-family: var(--display);
  color: #fff;
}
.big-start-face strong { font-size: calc(var(--dial-font, 16px) * 2.6); letter-spacing: 0.08em; line-height: 1; }
.big-start-face small { font-size: calc(var(--dial-font, 16px) * 0.75); font-weight: 700; letter-spacing: 0.25em; opacity: 0.85; }
.big-start:active .big-start-face { transform: scale(0.96); }

@keyframes breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.04); }
}

.status {
  position: absolute;
  left: 0; right: 0; bottom: 10px;
  z-index: 2;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.status.ok { color: var(--green); }
.status.warn { color: var(--accent-2); }

/* ---------- pedals ---------- */

.pedal {
  --v: 0;
  --tone: var(--gas);
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 340px;
  border-radius: 20px 20px 28px 28px;
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: linear-gradient(180deg, #23272e 0%, #15181c 100%);
  border: 1px solid rgba(var(--tone), 0.3);
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform: perspective(700px) rotateX(calc(var(--v) * 14deg));
  transform-origin: 50% 100%;
}
.pedal.brake { --tone: var(--brake); }

.pedal-grip {
  position: absolute;
  top: 12px; right: 12px; bottom: 12px; left: 12px;
  border-radius: 14px;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.55) 0 4px, rgba(255, 255, 255, 0.05) 4px 6px, transparent 6px 16px);
  opacity: 0.8;
}
.pedal-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--v) * 100%);
  background: linear-gradient(to top, rgba(var(--tone), 0.6), rgba(var(--tone), 0.12));
  box-shadow: 0 -2px 18px rgba(var(--tone), 0.5);
}
.pedal-plate {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 18px;
  pointer-events: none;
}
.pedal-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.2em;
  color: rgb(var(--tone));
  text-shadow: 0 0 12px rgba(var(--tone), 0.5);
}
.pedal-pct { font-family: var(--display); font-weight: 600; font-size: 15px; opacity: 0.85; }
.pedal.held { box-shadow: 0 0 0 2px rgba(var(--tone), 0.75), 0 0 40px rgba(var(--tone), 0.3); }

/* GPS mode: the side slots show signal and a rev pad instead of pedals */
.gps-card, .rev-pad {
  display: none;
  width: 100%;
  height: 70%;
  max-height: 240px;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--line);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.mode-gps .gps-card, .mode-gps .rev-pad { display: flex; }
.mode-gps .pedal { display: none; }

.gps-bars { display: flex; align-items: flex-end; height: 32px; margin-bottom: 8px; }
.gps-bars i { width: 8px; margin: 0 2px; border-radius: 3px; background: #262b33; }
.gps-bars i:nth-child(1) { height: 25%; }
.gps-bars i:nth-child(2) { height: 50%; }
.gps-bars i:nth-child(3) { height: 75%; }
.gps-bars i:nth-child(4) { height: 100%; }
.gps-card[data-level="1"] .gps-bars i:nth-child(-n+1),
.gps-card[data-level="2"] .gps-bars i:nth-child(-n+2),
.gps-card[data-level="3"] .gps-bars i:nth-child(-n+3),
.gps-card[data-level="4"] .gps-bars i:nth-child(-n+4) { background: var(--green); box-shadow: 0 0 8px rgba(53, 224, 138, 0.6); }
.gps-title { font-family: var(--display); font-weight: 700; letter-spacing: 0.2em; }
.gps-text { color: var(--muted); font-size: 13px; padding: 2px 8px 0; }

.rev-pad {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.14em;
  line-height: 1.15;
  border-color: rgba(255, 77, 26, 0.35);
}
.rev-pad:disabled { opacity: 0.45; cursor: default; }
.rev-pad.held { box-shadow: 0 0 0 2px var(--accent), 0 0 36px rgba(255, 77, 26, 0.35); }
.rev-icon {
  width: 38px;
  height: 38px;
  margin-bottom: 10px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  border-right-color: transparent;
  transform: rotate(-45deg);
}

/* ---------- garage ---------- */

.garage {
  flex: 0 0 auto;
  margin-top: 10px;
  padding: 10px 14px 10px;
  border-radius: 22px;
  background: linear-gradient(180deg, #0d1014, #08090b);
  border: 1px solid var(--line);
}

.garage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.garage-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}
.garage-title { display: flex; align-items: center; }
.garage-title h2 { margin-right: 14px; }
.seg-sm { padding: 3px; }
.seg-sm button { min-height: 32px; padding: 4px 12px; font-size: 12px; }

.settings { display: flex; }

/* Loudness meter on each card */
.loud {
  position: absolute;
  top: 8px;
  left: 9px;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  height: 14px;
  padding: 3px 5px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
}
.loud b { width: 3px; margin-right: 2px; border-radius: 1px; background: rgba(255, 255, 255, 0.25); }
.loud b:last-child { margin-right: 0; }
.loud b:nth-child(1) { height: 30%; }
.loud b:nth-child(2) { height: 48%; }
.loud b:nth-child(3) { height: 66%; }
.loud b:nth-child(4) { height: 83%; }
.loud b:nth-child(5) { height: 100%; }
.loud b.on { background: var(--accent-2); }
.loud b.on:nth-child(n+4) { background: var(--accent); }
.slider { display: flex; align-items: center; margin-left: 18px; color: var(--muted); font-size: 13px; font-weight: 600; }
.slider input { width: 130px; margin-left: 8px; accent-color: var(--accent); }

/* Swipeable strip of big cards. */
.cars {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 2px 2px 6px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: #2a2f37 transparent;
}

.car {
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--card-h) * 1.78);
  height: var(--card-h);
  margin-right: 10px;
  scroll-snap-align: start;
  border-radius: 14px;
  overflow: hidden;
  text-align: left;
  background: #0e1013 center 55% / cover no-repeat;
  border: 1px solid var(--line);
}
.car:active { transform: scale(0.98); }
.car::before {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0, 0, 0, 0.85) 100%);
}
/* Separator before the electric group at the end of the strip */
.cars-divider {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: var(--card-h);
  margin: 0 10px 0 4px;
  border-left: 1px solid var(--line-2);
  color: var(--muted);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.cars-divider span { margin-bottom: 6px; font-size: 16px; color: var(--accent-2); transform: rotate(180deg); }

.car-meta { position: absolute; left: 10px; right: 10px; bottom: 7px; }
.car-meta strong { display: block; font-size: 14px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.car-meta span { display: block; color: #b4bcc8; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.car[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset, 0 8px 24px rgba(255, 77, 26, 0.25);
}
.car[aria-checked="true"]::after {
  content: "";
  position: absolute;
  top: 9px; right: 9px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

/* ---------- ad + consent ---------- */

.ad-row { display: flex; align-items: center; }
.ad-slot { flex: 1 1 auto; min-width: 0; text-align: center; overflow: hidden; }
.has-ad .ad-slot { height: 50px; margin-top: 6px; }
/* Never compete for the driver's eyes: keep the space, hide the ad. */
body.driving .ad-slot { visibility: hidden; }
.ad-placeholder {
  height: 50px;
  line-height: 48px;
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
}
.site-links { flex: 0 0 auto; display: flex; margin-left: auto; padding-left: 10px; }
.site-links a { margin-left: 12px; color: var(--muted); font-size: 11px; text-decoration: none; white-space: nowrap; }
.site-links a:hover { color: var(--text); }
.has-ad .site-links { margin-top: 6px; }

.consent {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 10px 12px 10px 16px;
  border-radius: 14px;
  background: rgba(20, 23, 28, 0.96);
  border: 1px solid var(--line-2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  color: var(--muted);
}
.consent a { color: var(--text); }
.consent button {
  margin-left: 10px;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}
.consent button[data-c="yes"] { background: var(--accent); color: #111; }

/* ---------- compact (short panels, e.g. split view) ---------- */

body.compact { --pad: 10px; }
body.compact .push-start { width: 60px; height: 60px; }
body.compact .push-label { font-size: 13px; }
body.compact .seg button { min-height: 36px; padding: 6px 13px; font-size: 13px; }
body.compact .brand-name { font-size: 18px; }
body.compact .stage { padding: 46px 12px 26px; }
body.compact .car-name { font-size: 19px; }
body.compact .car-spec { font-size: 12px; }
body.compact .garage { padding: 8px 10px; }
body.compact .garage-head h2 { font-size: 13px; }
body.compact .slider input { width: 100px; }
body.compact .pedal-name { font-size: 16px; }

/* ---------- portrait phones: stack the cockpit ---------- */

body.portrait { height: auto; min-height: var(--app-h); }
body.portrait .stage { flex-wrap: wrap; padding-top: 60px; }
body.portrait .cluster { order: -1; flex: 0 0 100%; margin-bottom: 14px; }
body.portrait .wing { width: 48%; height: 200px; }
body.portrait .brand-name { font-size: 16px; }
body.portrait .toggles { flex-direction: column; align-items: flex-end; }
body.portrait .toggles .seg + .seg { margin: 6px 0 0; }
body.portrait .garage-head { flex-wrap: wrap; }
