:root {
  --bg: #0a0b0d;
  --panel: #131519;
  --panel-2: #1a1d23;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef1f5;
  --muted: #8b93a1;
  --accent: #ff5a1f;
  --accent-2: #ff8a3d;
  --red: #ff2e43;
  --green: #35d18a;
  --amber: #f5b33d;
  --radius: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(255, 90, 31, 0.08), transparent 60%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.brand-mark { width: 30px; height: 30px; color: var(--text); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.chip[data-state="ok"] { color: var(--green); }
.chip[data-state="wait"] { color: var(--amber); }
.chip[data-state="bad"] { color: var(--red); }

/* ---------- dashboard ---------- */

.dash {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  padding: 16px 20px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

.gauge-panel,
.control-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.gauge-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }

.gauge {
  position: relative;
  width: 100%;
  max-width: min(470px, 62vh);
}

#tach { width: 100%; height: auto; display: block; }

.tach-track { fill: none; stroke: var(--panel-2); stroke-width: 22; stroke-linecap: round; }
.tach-red { fill: none; stroke: rgba(255, 46, 67, 0.55); stroke-width: 22; }
.tach-value {
  fill: none;
  stroke: var(--accent);
  stroke-width: 22;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px rgba(255, 90, 31, 0.55));
  transition: stroke 0.15s;
}
.tach-value.shift { stroke: var(--red); filter: drop-shadow(0 0 14px rgba(255, 46, 67, 0.9)); }

.tick { stroke: rgba(255, 255, 255, 0.35); stroke-width: 2; }
.tick.major { stroke: rgba(255, 255, 255, 0.8); stroke-width: 3; }
.tick.red { stroke: var(--red); }
.tick-label { fill: var(--muted); font-size: 21px; font-weight: 600; text-anchor: middle; dominant-baseline: middle; }

.g-speed {
  fill: var(--text);
  font-size: 108px;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
}
.g-unit { fill: var(--muted); font-size: 20px; text-anchor: middle; }
.g-gear-box { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.5; }
.g-gear { fill: var(--text); font-size: 34px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.g-rpm { fill: var(--muted); font-size: 17px; text-anchor: middle; font-variant-numeric: tabular-nums; }

.bars { width: 100%; max-width: 470px; }

.bar { display: flex; align-items: center; gap: 12px; }
.bar-label { color: var(--muted); font-size: 14px; width: 70px; }
.bar-track { flex: 1; height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 4px; }

/* ---------- controls ---------- */

.control-panel { display: flex; flex-direction: column; gap: 12px; }

.car-card {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 10px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 90, 31, 0.16), rgba(255, 90, 31, 0.02));
  border: 1px solid rgba(255, 90, 31, 0.3);
}
.car-name { font-size: 20px; font-weight: 700; }
.car-tag { color: var(--muted); font-size: 14px; }

/* ---------- car picker ---------- */

.car-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.car-picker button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 96px;
  padding: 10px 6px 8px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.car-picker svg { width: 100%; max-width: 150px; height: auto; fill: currentColor; }
.car-picker svg .glass { fill: var(--panel-2); opacity: 0.85; }
.car-picker svg .wheel { fill: var(--panel-2); stroke: currentColor; stroke-width: 4; }
.car-picker .pick-name { font-size: 14px; font-weight: 600; line-height: 1.2; text-align: center; }
.car-picker button[aria-checked="true"] {
  color: var(--text);
  border-color: rgba(255, 90, 31, 0.9);
  background: linear-gradient(135deg, rgba(255, 90, 31, 0.22), rgba(255, 90, 31, 0.04));
}
.car-picker button[aria-checked="true"] svg { color: #ff5a1f; }

.start-btn {
  position: sticky;
  top: 8px;
  z-index: 5;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 76px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(255, 90, 31, 0.3);
  touch-action: manipulation;
}
.start-btn:active { transform: translateY(1px); }
.start-btn.on { background: linear-gradient(180deg, #3a3e46, #2a2d33); box-shadow: none; }
.start-ring { width: 22px; height: 22px; border-radius: 50%; border: 3px solid currentColor; }
.start-btn.on .start-ring { background: var(--red); border-color: var(--red); box-shadow: 0 0 12px var(--red); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--panel-2);
  border-radius: 14px;
  border: 1px solid var(--line);
}
.segmented button {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.segmented button[aria-checked="true"] { background: #2b2f37; color: var(--text); }
.segmented.small button { min-height: 40px; font-size: 15px; padding: 0 14px; }

.pads { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
body:not(.mode-demo) .pads { grid-template-columns: 1fr; }
body:not(.mode-demo) .demo-only { display: none; }

.pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 84px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.pad small { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; text-transform: none; }
.pad.active { transform: scale(0.98); }
.pad-gas.active { background: rgba(53, 209, 138, 0.25); border-color: var(--green); }
.pad-brake.active { background: rgba(255, 46, 67, 0.22); border-color: var(--red); }
.pad-rev.active { background: rgba(255, 90, 31, 0.25); border-color: var(--accent); }
.pad:disabled { opacity: 0.4; }
.mode-demo .pad-rev small { display: none; }

.ghost-btn {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.ghost-btn.running { border-color: var(--accent); color: var(--accent-2); }

.status { min-height: 22px; color: var(--muted); font-size: 15px; }
.status.warn { color: var(--amber); }
.status.error { color: var(--red); }

.settings { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }

.slider { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 12px; font-size: 15px; color: var(--muted); }
.slider span { display: flex; justify-content: space-between; }
.slider output { color: var(--text); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  touch-action: pan-y;
}
input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: var(--panel-2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px;
  height: 30px;
  margin-top: -11px;
  border-radius: 50%;
  background: var(--text);
  border: 4px solid var(--accent);
}
input[type="range"]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--panel-2); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--text); border: 4px solid var(--accent); }

.units { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 15px; padding-top: 4px; }

/* ---------- info ---------- */

.info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 4px 24px 8px;
}
.info h2 { font-size: 18px; margin: 12px 0 10px; }
.info ol { margin: 0; padding-left: 22px; line-height: 1.7; }
.hint { color: var(--muted); font-size: 15px; line-height: 1.55; }

.diag { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 15px; }
.diag li { display: flex; gap: 10px; align-items: baseline; }
.diag .ok { color: var(--green); }
.diag .bad { color: var(--red); }
.diag .warn { color: var(--amber); }
.diag .muted { color: var(--muted); }

.foot { max-width: 1400px; margin: 0 auto; padding: 12px 24px 28px; color: var(--muted); font-size: 13px; }

@media (max-width: 520px) {
  .brand { font-size: 18px; }
  .chip { font-size: 12px; padding: 5px 9px; }
  .slider { grid-template-columns: 112px 1fr; }
}

@media (max-width: 860px) and (orientation: portrait) {
  .gauge { max-width: min(470px, 40vh); }
}

/* Stack only in portrait: the car screen is landscape but under 860 CSS px wide. */
@media (max-width: 860px) and (orientation: portrait) {
  .dash, .info { grid-template-columns: 1fr; }
  .dash { padding: 16px; }
  .info { padding: 4px 16px 8px; }
  .topbar { padding: 12px 16px; }
  .foot { padding: 12px 16px 24px; }
}

/* ---------- pro line + payment modal ---------- */

.pro-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 24px;
  color: var(--muted);
  font-size: 15px;
}
.pro-line.is-pro { color: var(--green); }
.pro-line.is-pro .link-btn { display: none; }

.link-btn {
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--accent-2);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 6, 8, 0.82);
  backdrop-filter: blur(6px);
}
.modal[hidden] { display: none; }

.modal-card {
  position: relative;
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 28px 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { margin: 0 0 6px; font-size: 26px; }
.modal-lead { margin: 0 0 16px; color: var(--muted); font-size: 16px; line-height: 1.5; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.qr {
  width: min(270px, 62vmin);
  min-height: 120px;
  aspect-ratio: 1;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: #fff;   /* QR codes need a light background to scan reliably */
  overflow: hidden;
}
.qr svg { display: block; width: 100%; height: 100%; }
.modal[data-state="ok"] .qr:empty { display: none; }

.pay-hint { min-height: 24px; margin: 0 0 12px; font-size: 16px; line-height: 1.45; }
.modal[data-state="error"] .pay-hint { color: var(--red); }
.modal[data-state="ok"] .pay-hint { color: var(--green); font-size: 20px; font-weight: 700; }
.modal .ghost-btn { padding: 0 24px; margin-bottom: 12px; }
.pay-price { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- payment return page ---------- */

.done {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}
.done h1 { margin: 8px 0 0; font-size: 28px; }
.done p { max-width: 360px; margin: 0; color: var(--muted); font-size: 17px; line-height: 1.5; }
.done-mark { width: 84px; height: 84px; color: var(--green); }
.done-mark.off { color: var(--muted); }
