:root {
  --bg: #0b0d10;
  --panel: #15181d;
  --line: #262b33;
  --text: #e9edf2;
  --muted: #8a94a3;
  --accent: #ff5a1f;
  --accent-2: #ffb020;
  --red: #e5262b;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.3rem; margin: 0; letter-spacing: 0.02em; }
h2 { font-size: 1rem; margin: 0 0 10px; }
.status { font-size: 0.85rem; color: var(--muted); }
.status.on { color: var(--accent-2); }

.dash {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}
#tach { width: 100%; max-width: 320px; aspect-ratio: 1; display: block; }
.readout { text-align: right; min-width: 120px; }
.gear {
  font-size: 4rem; font-weight: 800; line-height: 1;
  color: var(--accent-2); font-variant-numeric: tabular-nums;
}
.speed { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.speed small { font-size: 0.9rem; color: var(--muted); margin-left: 4px; font-weight: 500; }
.rpm { color: var(--muted); font-variant-numeric: tabular-nums; }
.loadbar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 10px; }
#loadFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.small { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

button, select, input { font: inherit; color: inherit; }

.start {
  width: 100%;
  padding: 18px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
}
.start.on { background: #2a2f37; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-top: 16px;
}

.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }

.pedals { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; margin-top: 12px; }
.pad {
  position: relative;
  height: 170px;
  border-radius: 12px;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 12px;
  font-weight: 700;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  overflow: hidden;
  cursor: pointer;
}
.pad.brake { background: #2a1a1c; border: 1px solid #4a2428; }
.pad.brake.active { background: #5a1f25; }
.pad.gas { background: #1d2420; border: 1px solid #2f3d33; }
.pad span { position: relative; }
.gasFill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0;
  background: linear-gradient(0deg, var(--accent), var(--accent-2));
  opacity: 0.85;
}

.paddles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.paddles[hidden] { display: none; }
.paddles button {
  padding: 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 700; cursor: pointer;
}

.field { margin-top: 14px; }
.field:first-of-type { margin-top: 0; }
.label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.value { color: var(--text); }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; min-width: 0; padding: 9px 6px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 0.9rem; cursor: pointer;
}
.seg button.sel { background: #2a2f37; color: var(--text); }

select {
  width: 100%; padding: 10px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line);
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

.sensors { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 12px; font-size: 0.9rem; }
.sensors dt { color: var(--muted); }
.sensors dd { margin: 0; }
.ghost {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; cursor: pointer;
}

.safety { color: var(--muted); font-size: 0.8rem; margin-top: 18px; text-align: center; }

[hidden] { display: none !important; }

@media (max-width: 420px) {
  .dash { gap: 8px; margin: 10px 0; }
  .readout { min-width: 104px; }
  .gear { font-size: 3rem; }
  .speed { font-size: 1.8rem; }
  .pad { height: 140px; }
}
