:root {
  --bg: #0e0f11;
  --panel: #17191c;
  --panel-2: #1f2226;
  --line: #2c3036;
  --text: #ece7df;
  --muted: #8b8f96;
  --accent: #ff8a2a;
  --accent-2: #ffb35c;
  --red: #ff3b30;
  --green: #3ccf7a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  background-image: radial-gradient(120% 60% at 50% -10%, #241a12 0%, var(--bg) 60%);
  color: var(--text);
  font: 17px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-height: 56px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:active { transform: translateY(1px); }
button[aria-pressed="true"] { border-color: var(--accent); background: #2a1e14; color: var(--accent-2); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}
.brand { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
.mark { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px var(--accent); }
.top-actions { display: flex; gap: 10px; align-items: center; }

.seg { display: flex; }
.seg button { border-radius: 0; min-height: 44px; padding: 8px 14px; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 44px; }
.switch input { appearance: none; width: 48px; height: 28px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); position: relative; margin: 0; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .15s; }
.switch input:checked { background: #2a1e14; border-color: var(--accent); }
.switch input:checked::after { transform: translateX(20px); background: var(--accent); }

main {
  display: grid;
  gap: 16px;
  padding: 0 16px 32px;
  max-width: 1400px;
  margin: 0 auto;
  grid-template-columns: minmax(0, 1fr);
}

.dash, .settings, .dev, .controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 18px;
}

.readout { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.speed { display: flex; align-items: baseline; gap: 10px; }
.speed output { font-size: clamp(72px, 16vw, 150px); font-weight: 800; line-height: .9; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.speed span, .gear span, .rpm-text { color: var(--muted); }
.gear { display: flex; flex-direction: column; align-items: center; }
.gear output { font-size: clamp(56px, 11vw, 100px); font-weight: 800; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }

.rpm { margin-top: 18px; }
.rpm-bar {
  height: 22px; border-radius: 11px; overflow: hidden; position: relative;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), var(--bg) calc(10% - 2px) 10%), var(--panel-2);
}
.rpm-bar::after { content: ""; position: absolute; inset: 0 0 0 90%; background: rgba(255, 59, 48, .25); }
#rpmFill {
  position: absolute; inset: 0; transform-origin: left; transform: scaleX(0);
  background: linear-gradient(90deg, #7a3a10, var(--accent) 70%, var(--accent-2));
}
#rpmFill.red { background: linear-gradient(90deg, #7a3a10, var(--accent) 60%, var(--red)); }
.rpm-text { margin-top: 6px; font-variant-numeric: tabular-nums; }
.rpm-text output { color: var(--text); font-weight: 700; font-size: 22px; }

.controls { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; align-items: stretch; }
.start { font-size: 26px; font-weight: 800; min-height: 96px; background: var(--accent); color: #1a0e04; border: 0; letter-spacing: .04em; }
.start.on { background: var(--panel-2); color: var(--accent-2); border: 2px solid var(--accent); }
.rev, .pedal { display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; min-height: 96px; touch-action: none; }
.rev small, .pedal small, .engines small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
.held { background: #3a2412; border-color: var(--accent); }
.controls .volume { grid-column: 1 / -1; }

.slider { display: grid; gap: 6px; }
.slider span { color: var(--muted); }
.slider small { opacity: .8; }
input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); margin: 0; }

[hidden] { display: none !important; }

.engines { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.engines button { min-height: 76px; text-align: left; }
.engines b { font-size: 19px; }

.status { margin: 0; min-height: 1.4em; color: var(--green); }
.status.warn { color: var(--accent-2); }
.hint { margin: 0; color: var(--muted); font-size: 15px; }

.settings summary { cursor: pointer; font-weight: 700; min-height: 32px; }
.settings .grid { display: grid; gap: 14px; margin-top: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.dev { border-color: #4a3320; display: grid; gap: 14px; }
.dev h2 { margin: 0; font-size: 18px; color: var(--accent-2); }
.pedals { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.pedal.gas.held { background: #1c3a26; border-color: var(--green); }
.pedal.brake.held { background: #3a1614; border-color: var(--red); }
.keys { margin: 0; color: var(--muted); font-size: 14px; }
.profiles { display: flex; flex-wrap: wrap; gap: 10px; }
.gpssim { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: center; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); }
.debug { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 0; }
.debug div { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.debug dt { color: var(--muted); font-size: 13px; }
.debug dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 700; }
#graph { width: 100%; height: auto; background: var(--bg); border-radius: 10px; border: 1px solid var(--line); }
.legend { margin: 0; display: flex; gap: 16px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; }
.l-raw::before { background: var(--muted); }
.l-smooth::before { background: var(--text); }
.l-rpm::before { background: var(--accent); }

/* Breite Bildschirme (Auto-Display): Anzeige links, Bedienung rechts. */
@media (min-width: 980px) {
  main { grid-template-columns: 1.3fr 1fr; align-items: start; }
  .dash { grid-row: span 2; }
  .engines, .status, .hint { grid-column: 2; }
  .settings, .dev { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .engines { grid-template-columns: 1fr 1fr; }
  .engines button { min-height: 64px; }
  .engines b { font-size: 16px; }
  .brand { font-size: 15px; }
}
