:root {
  --bg: #0a0c0f;
  --panel: #12161b;
  --panel-2: #1a1f26;
  --line: #262d36;
  --text: #eef1f4;
  --muted: #8b95a3;
  --accent: #ff4b3e;
  --ok: #18d35b;
  --display: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 700px at 50% 35%, #141920 0%, var(--bg) 70%);
  color: var(--text);
  font: 500 16px/1.4 var(--ui);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
[hidden] { display: none !important; }

/* ---------- header */
.top { display: flex; align-items: center; gap: 24px; padding: 18px 28px 6px; }
.brand { font: 800 30px/1 var(--display); letter-spacing: .06em; }
.brand span { color: var(--accent); transition: color .3s; }
.top-actions { display: flex; gap: 10px; margin-left: auto; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 12px 20px; font-size: 15px; display: inline-flex; align-items: center; gap: 10px; min-height: 48px; }
.chip .ico { display: none; font-size: 18px; line-height: 1; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: #444b55; }
.chip[aria-pressed="true"] .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.chip.warn .dot { background: #ffb000; }

/* ---------- layout */
.layout { display: grid; grid-template-columns: minmax(260px, 23%) 1fr minmax(240px, 21%); gap: 24px; padding: 12px 28px; min-height: 0; }

.garage { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.garage h2, .sheet h3 { font: 700 15px var(--ui); color: var(--muted); text-transform: uppercase; letter-spacing: .12em; margin: 4px 0 0; }
.car-list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; min-height: 0; flex: 1; padding-right: 4px; scrollbar-width: thin; scrollbar-color: #2a313b transparent; }
.car {
  text-align: left; background: var(--panel); border: 2px solid var(--line); border-radius: 18px;
  padding: 12px 16px; display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; align-items: center; flex-shrink: 0;
  transition: border-color .2s, background .2s;
}
.car .badge { grid-row: span 2; font: 800 36px/1 var(--display); color: var(--c); min-width: 64px; }
.car .nm { font: 700 21px/1.1 var(--display); letter-spacing: .02em; }
.car .md { font-size: 13px; color: var(--muted); }
.car .sp { grid-column: 1 / -1; display: none; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.car[aria-pressed="true"] .sp { display: flex; }
.car .sp span { font-size: 12px; color: var(--muted); background: var(--panel-2); padding: 3px 8px; border-radius: 6px; }
.car[aria-pressed="true"] { border-color: var(--c); background: linear-gradient(135deg, color-mix(in srgb, var(--c) 14%, var(--panel)), var(--panel) 60%); }
.note { font-size: 13px; color: var(--muted); margin: 0; }

/* ---------- cluster */
.cluster { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 0; }
.leds { display: flex; gap: 8px; height: 26px; }
.leds i { width: 26px; height: 26px; border-radius: 50%; background: #1c2128; border: 1px solid #262d36; transition: background .03s; }
.leds i.on { background: var(--lc); box-shadow: 0 0 14px var(--lc); border-color: transparent; }
.leds.flash i { background: var(--lc); box-shadow: 0 0 18px var(--lc); }
.leds.flash.off i { background: #1c2128; box-shadow: none; }
.dial { position: relative; width: min(52vh, 100%); aspect-ratio: 1; }
.dial canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.readout { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gear { font: 800 clamp(90px, 18vh, 190px)/0.9 var(--display); color: var(--accent); transition: color .3s; }
.rpm { font: 600 24px var(--display); color: var(--muted); letter-spacing: .05em; font-variant-numeric: tabular-nums; }
.rpm span { color: var(--text); }
.speed { font: 700 46px/1 var(--display); font-variant-numeric: tabular-nums; margin-top: 4px; }
.speed small { font-size: 18px; color: var(--muted); margin-left: 6px; }
.paddles { display: flex; align-items: center; gap: 18px; }
.paddle { width: 84px; height: 64px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); font: 700 34px var(--display); }
.paddle:active { background: var(--panel-2); border-color: var(--accent); }
.carname { min-width: 240px; text-align: center; font: 700 22px/1.1 var(--display); letter-spacing: .03em; display: flex; flex-direction: column; }
.carname small { font: 500 13px var(--ui); color: var(--muted); }

/* ---------- pedals */
.controls { display: flex; flex-direction: column; min-height: 0; gap: 10px; }
.pedals { flex: 1; display: grid; grid-template-columns: 1fr 1.25fr; gap: 14px; min-height: 0; }
.pedal {
  position: relative; border-radius: 22px; background: var(--panel); border: 2px solid var(--line);
  overflow: hidden; touch-action: none; display: flex; align-items: flex-start; justify-content: center; padding-top: 18px;
}
.pedal span { position: relative; font: 700 22px var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.pedal i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; transition: height .05s; }
.pedal.gas i { background: linear-gradient(to top, var(--accent), color-mix(in srgb, var(--accent) 30%, transparent)); }
.pedal.brake i { background: linear-gradient(to top, #e8eaed, rgba(232,234,237,.2)); }
.pedal.active { border-color: var(--accent); }
.pedal.brake.active { border-color: #e8eaed; }
.pedals.disabled { opacity: .35; pointer-events: none; }
.hint { font-size: 13px; color: var(--muted); text-align: center; margin: 0; }

/* ---------- bottom bar */
.bar { display: flex; align-items: center; gap: 14px; padding: 10px 28px 6px; }
.start, .rev, .ghost { min-height: 64px; border-radius: 18px; padding: 0 30px; font: 700 22px var(--display); letter-spacing: .05em; text-transform: uppercase; }
.start { background: var(--accent); color: #0a0c0f; min-width: 240px; transition: background .3s; }
.start.running { background: var(--panel-2); color: var(--text); border: 2px solid var(--accent); }
.start:disabled { opacity: .5; }
.rev { background: var(--panel); border: 2px solid var(--line); min-width: 150px; touch-action: none; }
.rev.active { border-color: var(--accent); color: var(--accent); }
.ghost { background: transparent; border: 2px solid var(--line); color: var(--text); }
.ghost.active { border-color: var(--accent); }
.vol { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin-left: 10px; }
.vol input, .row input[type=range] { width: 200px; accent-color: var(--accent); height: 32px; }
.status { margin-left: auto; color: var(--muted); font-size: 14px; text-align: right; }
.disclaimer { margin: 0; padding: 4px 28px 12px; font-size: 12px; color: #5d6672; }

/* ---------- sheets */
.sheet { position: fixed; inset: 0; background: rgba(5,6,8,.72); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 10; }
.sheet-card { background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 28px 32px; width: min(560px, 92vw); display: flex; flex-direction: column; gap: 16px; }
.sheet-card.center { text-align: center; align-items: center; }
.sheet-card h3 { margin: 0 0 4px; }
.sheet-card.center h3 { font: 800 36px var(--display); color: var(--text); text-transform: none; letter-spacing: .02em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 52px; border-bottom: 1px solid var(--line); }
.row input[type=checkbox] { width: 28px; height: 28px; accent-color: var(--accent); }
.row select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font: inherit; }
.small { font-size: 13px; color: var(--muted); margin: 0; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 12px; }
.small-btn { min-width: 0; }

/* ---------- tablet / mobile: one scrolling column
   order: header · garage strip · dashboard · buttons · pedals · disclaimer */
@media (max-width: 1000px) {
  html, body { height: auto; }
  body {
    display: flex; flex-direction: column; overflow-x: hidden; overflow-y: auto; min-height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .layout { display: contents; }

  .top { order: 1; flex-wrap: wrap; gap: 10px 12px; padding: 14px 16px 4px; }
  .brand { font-size: 26px; }
  .top-actions { margin-left: auto; gap: 8px; }
  .chip { min-height: 40px; padding: 8px 14px; font-size: 14px; }
    
  .garage { order: 2; padding: 10px 0 0; gap: 8px; }
  .garage h2 { padding: 0 16px; font-size: 13px; }
  .car-list {
    flex-direction: row; overflow-x: auto; overflow-y: hidden; flex: none;
    padding: 2px 16px 8px; gap: 8px; scroll-snap-type: x mandatory; scroll-padding: 0 16px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .car-list::-webkit-scrollbar { display: none; }
  .car { scroll-snap-align: start; width: min(250px, 72vw); padding: 10px 12px; gap: 0 10px; border-radius: 14px; }
  .car .badge { font-size: 28px; min-width: 50px; }
  .car .nm { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .car .md { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .car .nm, .car .md { min-width: 0; }
  .car[aria-pressed="true"] .sp { display: none; }
  .note { display: none; }

  .cluster { order: 3; padding: 8px 16px 0; gap: 8px; }
  .leds { gap: 5px; height: auto; flex-wrap: nowrap; }
  .leds i { width: clamp(12px, 4.2vw, 22px); height: clamp(12px, 4.2vw, 22px); }
  .dial { width: min(84vw, 420px, 52dvh); }
  .gear { font-size: clamp(72px, 24vw, 150px); }
  .rpm { font-size: 18px; }
  .speed { font-size: 36px; }
  .speed small { font-size: 15px; }
  .paddles { gap: 10px; width: 100%; max-width: 440px; justify-content: space-between; }
  .paddle { width: 64px; height: 52px; font-size: 28px; flex-shrink: 0; }
  .carname { min-width: 0; flex: 1; font-size: 18px; }
  .carname span, .carname small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .bar { order: 4; display: grid; grid-template-columns: 1.6fr 1fr 1.25fr; gap: 8px; padding: 14px 16px 6px; }
  .start, .rev, .ghost { min-width: 0; min-height: 56px; padding: 0 8px; font-size: clamp(15px, 4.4vw, 18px); border-radius: 14px; white-space: nowrap; }
  .vol { grid-column: 1 / -1; margin: 6px 0 0; }
  .vol input { flex: 1; width: auto; }
  .status { grid-column: 1 / -1; margin: 0; text-align: center; font-size: 13px; }
  .status:empty { display: none; }

  .controls { order: 5; padding: 8px 16px 0; }
  .pedals { flex: none; height: clamp(170px, 28dvh, 260px); }
  .pedal { border-radius: 16px; }

  .disclaimer { order: 6; padding: 12px 16px 20px; text-align: center; }

  .sheet-card { padding: 22px 20px; border-radius: 20px; max-height: 90dvh; overflow-y: auto; }
  .row input[type=range] { width: min(200px, 45vw); }
  .sheet-actions { flex-wrap: wrap; }
  .sheet-actions button { flex: 1; }
  .sheet-card.center h3 { font-size: 30px; }
}

/* very narrow phones */
@media (max-width: 400px) {
  #settingsBtn .lbl { display: none; }
  #settingsBtn .ico { display: inline; }
  #settingsBtn { width: 40px; padding: 0; justify-content: center; }
}
@media (max-width: 360px) {
  .chip { padding: 8px 10px; font-size: 13px; }
  .bar { grid-template-columns: 1fr 1fr; }
  .start { grid-column: 1 / -1; }
}

/* phones in landscape: dashboard and pedals side by side */
@media (max-width: 1000px) and (orientation: landscape) and (max-height: 520px) {
  .cluster { order: 3; }
  .dial { width: min(42vw, 78dvh); }
  .leds i { width: 14px; height: 14px; }
  .pedals { height: 200px; }
}
