:root {
  --bg: #050607;
  --panel: #101316;
  --panel-2: #161a1f;
  --line: #23292f;
  --text: #f1f4f6;
  --muted: #7f8a94;
  --accent: #ff2a1a;
  --accent-2: #ffb000;
  --c: #ff2a1a; /* selected bike colour, set from JS */
  --ok: #26d07c;
  --warn: #ffb000;
  --bad: #ff2a1a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  background:
    radial-gradient(1200px 500px at 50% -200px, color-mix(in srgb, var(--c) 18%, transparent), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
  max-width: 1200px;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 0; }
.brand { font-size: 22px; font-weight: 900; font-style: italic; letter-spacing: 1px; display: flex; align-items: baseline; gap: 4px; }
.brand span { color: var(--c); }
.brand em { font-size: 13px; font-weight: 600; font-style: normal; color: var(--muted); margin-left: 8px; letter-spacing: 0; }
.source { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.source button { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; color: var(--muted); }
.source button[aria-checked="true"] { background: var(--c); color: #fff; }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* ---------- TFT dash ---------- */
.dash {
  position: relative;
  background: linear-gradient(180deg, #0c0f12, #07090b);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 14px 18px 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04), 0 20px 60px rgba(0,0,0,.5);
  overflow: hidden;
}

.leds { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; margin: 0 auto 10px; max-width: 640px; }
.leds i { height: 12px; border-radius: 6px; background: #1a1f24; transition: background .05s, box-shadow .05s; }
.leds i.on.g { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.leds i.on.y { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }
.leds i.on.r { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.dash.shift .leds i { background: #3aa0ff; box-shadow: 0 0 14px #3aa0ff; }
.dash.shift.blink .leds i { background: #1a1f24; box-shadow: none; }

.tach { display: block; width: 100%; height: clamp(70px, 14vw, 130px); }
.tach rect { fill: #1b2026; transition: fill .04s; }
.tach rect.red { fill: #3a1512; }
.tach rect.on { fill: #f1f4f6; }
.tach rect.on.mid { fill: var(--accent-2); }
.tach rect.on.red { fill: var(--accent); }
.dash.limiter .tach rect.on { fill: var(--accent); }
.tach text { fill: var(--muted); font: 700 22px system-ui, sans-serif; font-style: italic; }
.tach text.red { fill: var(--accent); }

.dash-main { display: grid; grid-template-columns: 1fr 1.6fr 1fr; align-items: center; gap: 10px; margin-top: 6px; }
.gearbox, .rpmbox { text-align: center; }
.gearbox small, .rpmbox small { display: block; color: var(--muted); font-size: 12px; letter-spacing: 2px; font-weight: 700; }
.gear {
  font-size: clamp(64px, 16vw, 132px);
  font-weight: 900;
  font-style: italic;
  line-height: .95;
  color: var(--text);
  text-shadow: 0 0 24px color-mix(in srgb, var(--c) 50%, transparent);
}
.gear.neutral { color: var(--ok); text-shadow: 0 0 24px rgba(38, 208, 124, .5); }
.speedbox { text-align: center; }
.speed { font-size: clamp(60px, 15vw, 128px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -2px; }
.speed small { font-size: 16px; font-weight: 600; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.virt { color: var(--muted); font-size: 14px; margin-top: 4px; }
.virt b { color: var(--text); font-variant-numeric: tabular-nums; }
.rpm { font-size: clamp(26px, 6vw, 44px); font-weight: 800; font-style: italic; font-variant-numeric: tabular-nums; }
.tags { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; font-weight: 800; padding: 2px 7px; border-radius: 5px; border: 1px solid var(--line); color: #333b43; }
.tag.on.qs { color: #000; background: #3aa0ff; border-color: #3aa0ff; }
.tag.on.lim { color: #fff; background: var(--accent); border-color: var(--accent); }

.bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.bars label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.bar { display: block; height: 6px; border-radius: 3px; background: #1a1f24; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; transition: width .06s; }
.bar.thr i { background: var(--ok); }
.bar.brk i { background: var(--accent); }
.bar.vu i { background: var(--c); }
.bike { position: absolute; right: 18px; bottom: 44px; font-size: 12px; color: var(--muted); font-style: italic; font-weight: 700; letter-spacing: 1px; }

@media (max-width: 560px) {
  .dash { padding: 12px 12px 14px; }
  .leds { gap: 4px; }
  .dash-main { grid-template-columns: 1fr 1.7fr 1fr; gap: 4px; }
  .bike { display: none; }
}

/* ---------- controls ---------- */
.controls { display: grid; gap: 14px; margin-top: 16px; }
.buttons { display: grid; grid-template-columns: 1fr 140px; gap: 12px; }
.start {
  padding: 24px 16px;
  font-size: 24px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 1px;
  border: 0;
  border-radius: 18px;
  background: var(--c);
  color: #fff;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--c) 40%, transparent);
}
.start.running { background: var(--panel); border: 2px solid var(--c); color: var(--c); box-shadow: none; }
.start:disabled { opacity: .6; }
.rev {
  border-radius: 18px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.25;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.rev:disabled { opacity: .35; }
.rev.active { background: var(--accent-2); border-color: var(--accent-2); color: #000; }
.hint { color: var(--muted); font-size: 14px; }
.hint.error { color: var(--bad); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.demo { display: grid; gap: 12px; }
.pedals { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.pedal {
  padding: 26px 0;
  font-size: 21px;
  font-weight: 800;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.pedal.gas.active { background: var(--ok); border-color: var(--ok); color: #000; }
.pedal.brake.active { background: var(--bad); border-color: var(--bad); color: #fff; }
.phase { color: var(--warn); min-height: 1.4em; }
.kbd { color: var(--muted); font-size: 13px; }

.sliders { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); column-gap: 28px; }
.sliders label { display: grid; grid-template-columns: 1fr auto; gap: 4px; font-size: 15px; }
.sliders input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--c); height: 28px; }
.switch { display: flex !important; align-items: center; gap: 10px; }
.switch input { width: 22px; height: 22px; accent-color: var(--c); }

/* ---------- library ---------- */
.library h2 { font-size: 18px; margin: 28px 0 12px; font-style: italic; }
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.profile {
  text-align: left;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 16px 16px 14px 20px;
  display: grid;
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.profile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--pc); transform: skewY(-12deg); transform-origin: top left; }
.profile strong { font-size: 17px; font-style: italic; }
.profile span { color: var(--muted); font-size: 14px; }
.profile em { font-style: normal; font-size: 12px; color: var(--muted); }
.profile[aria-pressed="true"] { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 10%, var(--panel)); }

.guide, .diag { margin-top: 20px; }
.guide summary, .diag summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.guide ol { margin: 12px 0 0; padding-left: 22px; display: grid; gap: 8px; font-size: 15px; color: #c9d0d6; }
.diag dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 12px 0 0; font-size: 14px; }
.diag dt { color: var(--muted); }
.diag dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }

footer { margin-top: 24px; color: var(--muted); font-size: 13px; }
