:root {
  --bg: #0b0d10;
  --panel: #14171c;
  --panel-2: #1b1f26;
  --line: #2a2f38;
  --text: #f2f4f7;
  --muted: #8a93a3;
  --accent: #e0303a;
  --ok: #2ecc71;
  --warn: #f5a623;
  --red: #ff3b3b;
  --radius: 18px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
}
body.theme-light {
  --bg: #eef0f3;
  --panel: #ffffff;
  --panel-2: #f3f5f8;
  --line: #d9dde3;
  --text: #121418;
  --muted: #545c6a;
  --ok: #157a3c;
  --warn: #9a5800;
  --red: #c41d1d;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; }
b { font-weight: 800; }

#app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; gap: 12px; padding: 12px 16px 14px; }

/* ---------- barra superior ---------- */
.topbar { display: flex; align-items: center; gap: 14px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 20px; letter-spacing: 0.02em; }
.brand b { color: var(--accent); }
.pill { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 18px 8px 12px; min-height: 52px; }
.engine-pill { text-align: left; }
.engine-pill > span:nth-child(2) { display: flex; flex-direction: column; line-height: 1.15; font-weight: 700; font-size: 17px; }
.engine-pill small { font-weight: 500; color: var(--muted); font-size: 13px; }
.engine-pill .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.chev { color: var(--muted); }
.chips { display: flex; gap: 8px; margin-left: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; font-weight: 600; color: var(--muted); min-height: 40px; }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.chip.warn { color: var(--warn); }
.chip.bad { color: var(--red); }
.chip.pro { color: #111; background: linear-gradient(135deg, #ffd36b, #ff9f43); border-color: transparent; }
.top-actions { display: flex; gap: 8px; }
.icon-btn { width: 52px; height: 52px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); font-size: 22px; display: grid; place-items: center; }

/* ---------- salpicadero ---------- */
.dash { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(360px, 2.2fr) minmax(220px, 1fr); gap: 14px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: hidden; }
.panel h3 { margin: 0; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.gball { flex: 1; min-height: 0; display: grid; place-items: center; }
.gball svg { width: 100%; max-height: 100%; aspect-ratio: 1; }
.ring { fill: none; stroke: var(--line); stroke-width: 2; }
.ring.dim { stroke-dasharray: 4 5; }
.glabel { fill: var(--muted); font-size: 10px; text-anchor: middle; font-family: var(--mono); }
.gdot { fill: var(--accent); filter: drop-shadow(0 0 6px var(--accent)); transition: cx 0.12s linear, cy 0.12s linear; }
.stats { margin: 0; display: grid; gap: 8px; }
.stats div { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.stats dt { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }
.stats dd { margin: 0; font-family: var(--mono); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats.big dd { font-size: 26px; }
.tag { margin: 0; align-self: flex-start; font-size: 11px; letter-spacing: 0.16em; padding: 4px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.meters { display: grid; gap: 10px; margin-top: auto; }
.meter { display: grid; grid-template-columns: 90px 1fr 48px; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.meter .bar { height: 12px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.meter .bar i { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.08s linear; }
.meter.brake .bar i { background: var(--red); }
.meter b { text-align: right; font-family: var(--mono); color: var(--text); }
.free-left { margin: 0; font-size: 14px; color: var(--warn); font-weight: 600; }

.center { position: relative; background: radial-gradient(circle at 50% 45%, var(--panel-2), var(--panel) 70%); border: 1px solid var(--line); border-radius: var(--radius); display: grid; place-items: center; min-height: 0; overflow: hidden; }
.cockpit, .minimal { width: 100%; height: 100%; display: none; }
.layout-cockpit .cockpit { display: grid; place-items: center; position: relative; }
.layout-minimal .minimal { display: grid; }
#tach { height: 100%; max-height: 100%; width: auto; max-width: 100%; aspect-ratio: 1; padding: 8px; }
/* Cuadro: cada motor define --face, --ink, --needle y --dash-accent (ver engines.js → dash) */
.cockpit { --face: transparent; --ink: var(--text); --needle: var(--text); --dash-accent: var(--accent); }
#tachFace { fill: var(--face); }
#tachBezel { fill: none; stroke: color-mix(in srgb, var(--ink) 18%, transparent); stroke-width: 3; }
.arc-bg { fill: none; stroke: color-mix(in srgb, var(--ink) 10%, transparent); stroke-width: 18; stroke-linecap: round; }
.arc-fill { fill: none; stroke: var(--dash-accent); stroke-width: 18; stroke-linecap: round; filter: drop-shadow(0 0 8px var(--dash-accent)); }
.tick { stroke: color-mix(in srgb, var(--ink) 60%, transparent); stroke-width: 2; }
.tick.major { stroke: var(--ink); stroke-width: 3; }
.tick.red { stroke: var(--red); }
.tick-label { fill: var(--ink); font-size: 18px; font-weight: 700; font-family: var(--mono); text-anchor: middle; dominant-baseline: middle; }
.tick-label.red { fill: var(--red); }
#needle line { stroke: var(--needle); stroke-width: 5; stroke-linecap: round; filter: drop-shadow(0 0 4px var(--needle)); }
.dash-analog .arc-fill { opacity: 0; }
.dash-analog .cockpit-readout .gear { color: var(--ink); }
.dash-analog .cockpit-readout .speed, .dash-analog .cockpit-readout .rpm-num, .cockpit .unit { color: var(--ink); }
body.limiter .cockpit-readout .gear { color: var(--red); }
.tick-label.small { font-size: 12px; font-weight: 500; }
.dash-digital #needle, .dash-race #needle { display: none; }
.dash-digital .arc-fill, .dash-race .arc-fill { stroke-linecap: butt; stroke-width: 26; stroke-dasharray: 6 3; }
.dash-digital .arc-bg, .dash-race .arc-bg { stroke-width: 26; stroke-linecap: butt; stroke-dasharray: 6 3; }
.dash-digital .gear, .dash-race .gear { color: var(--dash-accent); }
.dash-race .speed { color: var(--ink); }
.shiftlights { display: none; position: absolute; top: 14px; left: 50%; transform: translateX(-50%); gap: 8px; z-index: 2; }
.dash-race .shiftlights { display: flex; }
.shiftlights i { width: 22px; height: 22px; border-radius: 50%; background: #1b1d22; border: 1px solid #2c2f36; }
.shiftlights i.on.g { background: #19e05a; box-shadow: 0 0 10px #19e05a; }
.shiftlights i.on.y { background: #ffd000; box-shadow: 0 0 10px #ffd000; }
.shiftlights i.on.r { background: #ff2020; box-shadow: 0 0 10px #ff2020; }
.shiftlights.flash i { background: #2a7bff; box-shadow: 0 0 14px #2a7bff; }
.subgauge { display: grid; grid-template-columns: auto 120px auto; gap: 8px; align-items: center; justify-self: center; margin-top: 8px; font-size: 12px; letter-spacing: 0.1em; color: var(--ink); opacity: 0.85; font-family: var(--mono); }
.subgauge .bar { height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--ink) 15%, transparent); overflow: hidden; }
.subgauge .bar i { display: block; height: 100%; width: 0; background: var(--dash-accent); }
.subgauge[hidden] { display: none; }
#needle { transform-origin: 200px 200px; }
.cockpit-readout { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; padding-top: 40px; }
.gear { font-size: clamp(64px, 11vh, 132px); font-weight: 800; line-height: 1; color: var(--accent); }
.speed { font-family: var(--mono); font-size: clamp(30px, 5vh, 54px); font-weight: 700; }
.speed small, .m-speed small { font-size: 0.4em; color: var(--muted); margin-left: 6px; font-family: var(--font); }
.rpm-num { color: var(--muted); font-family: var(--mono); font-size: 16px; }
.limiter .gear, .limiter .arc-fill { color: var(--red); stroke: var(--red); }

.minimal { grid-template-columns: 1fr auto; grid-template-rows: 1fr auto auto; padding: 24px 36px; align-items: center; gap: 12px 40px; }
.m-speed small { font-size: 0.16em; letter-spacing: 0; }
.m-speed { font-size: clamp(110px, 26vh, 260px); font-weight: 300; line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.revbar { grid-column: 1; position: relative; height: 10px; border-radius: 5px; background: var(--panel-2); overflow: hidden; }
.revbar #revFill { height: 100%; width: 0; background: var(--text); border-radius: 5px; transition: width 0.05s linear; }
.revbar .redzone { position: absolute; top: 0; bottom: 0; right: 0; background: color-mix(in srgb, var(--red) 45%, transparent); }
.m-row { grid-column: 1; color: var(--muted); font-family: var(--mono); }
.gearcol { grid-column: 2; grid-row: 1 / 4; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 4px; font-size: 26px; font-weight: 700; color: var(--muted); }
.gearcol li { padding: 2px 16px; border-radius: 10px; text-align: center; }
.gearcol li.on { color: var(--bg); background: var(--text); }

/* ---------- controles ---------- */
.controls { display: flex; flex-wrap: wrap; align-items: stretch; gap: 12px; min-height: 92px; }
.ctl-group { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.start-btn { width: 132px; height: 76px; border-radius: 16px; border: 2px solid var(--line); background: radial-gradient(circle at 50% 40%, #2a2f38, #15181d); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; letter-spacing: 0.12em; }
.start-btn span { font-size: 11px; color: #9aa3b2; }
.start-btn b { font-size: 22px; }
.start-btn.busy { opacity: 0.7; }
.start-btn.running { border-color: var(--accent); box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 55%, transparent), inset 0 0 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.ctl { min-width: 76px; height: 76px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel-2); font-size: 34px; font-weight: 700; }
.ctl.wide { min-width: 110px; display: flex; flex-direction: column; justify-content: center; font-size: 20px; }
.ctl.wide small { font-size: 11px; color: var(--muted); letter-spacing: 0.12em; }
.ctl:disabled { opacity: 0.35; }
.gear-mini { min-width: 64px; text-align: center; font-size: 40px; font-weight: 800; color: var(--accent); }
.seg { display: flex; gap: 4px; }
.seg button { min-width: 92px; height: 76px; border: 1px solid transparent; border-radius: 12px; background: transparent; font-weight: 700; color: var(--muted); font-size: 17px; }
.seg button.on { background: var(--panel-2); border-color: var(--line); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }
.seg.small button { min-width: 0; height: 46px; padding: 0 16px; font-size: 15px; }
.vol { flex: 1 1 200px; min-width: 180px; padding: 8px 18px; gap: 14px; font-size: 22px; color: var(--muted); }
.vol input { flex: 1; }
input[type='range'] { -webkit-appearance: none; appearance: none; height: 44px; background: transparent; }
input[type='range']::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); }
input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; margin-top: -12px; border-radius: 50%; background: var(--text); border: 3px 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: 26px; height: 26px; border-radius: 50%; background: var(--text); border: 3px solid var(--accent); }
.pedal { display: none; width: 150px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); font-weight: 800; letter-spacing: 0.1em; font-size: 14px; touch-action: none; }
.sim .pedal { display: block; }
.gas-pedal.down { background: color-mix(in srgb, var(--ok) 35%, var(--panel)); border-color: var(--ok); }
.brake-pedal.down { background: color-mix(in srgb, var(--red) 35%, var(--panel)); border-color: var(--red); }

/* ---------- capas ---------- */
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); display: grid; place-items: center; z-index: 10; }
.overlay[hidden] { display: none; }
.overlay-card { text-align: center; max-width: 560px; padding: 36px; }
.overlay-card h1 { font-size: 44px; margin: 12px 0; }
.overlay-card h1 b { color: var(--accent); }
.overlay-card p { color: var(--muted); font-size: 18px; line-height: 1.5; }
.cta { display: inline-block; margin-top: 12px; min-width: 260px; padding: 22px 36px; border-radius: 16px; border: 0; background: var(--accent); color: #fff; font-size: 22px; font-weight: 800; letter-spacing: 0.12em; text-decoration: none; text-align: center; }
.cta.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.link { display: block; margin: 18px auto 0; background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 16px; padding: 10px; }
.btn { padding: 14px 20px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 700; font-size: 16px; }
.btn.danger { color: var(--red); }

dialog.sheet { width: min(1100px, 94vw); max-height: 88vh; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); color: var(--text); padding: 0; overflow: auto; }
dialog.sheet.narrow { width: min(620px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
dialog > header { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 1; }
dialog h2 { margin: 0; font-size: 22px; }
dialog > p, dialog > .cta { margin: 20px; }
#proBody { padding: 20px; display: grid; gap: 16px; }

.cars { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; padding: 18px; }
.car { position: relative; text-align: left; border-radius: 16px; border: 1px solid var(--line); background: var(--panel-2); padding: 16px 16px 14px 20px; display: grid; gap: 4px; min-height: 128px; overflow: hidden; }
.car::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c); }
.car h5 { margin: 0; font-size: 18px; padding-right: 72px; }
.car .spec { font-size: 13px; color: var(--muted); font-weight: 600; }
.car p { margin: 4px 0 0; font-size: 13px; color: var(--muted); line-height: 1.35; }
.car.on { border-color: var(--c); box-shadow: 0 0 0 2px var(--c) inset; }
.car .badge { position: absolute; top: 12px; right: 12px; font-size: 11px; font-weight: 800; letter-spacing: 0.1em; padding: 3px 8px; border-radius: 6px; background: var(--panel); color: var(--muted); }
.car .badge.pro { background: linear-gradient(135deg, #ffd36b, #ff9f43); color: #111; }
.car.locked { opacity: 0.7; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; padding: 20px; }
.settings-grid h4 { margin: 0 0 10px; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.settings-grid section { display: grid; gap: 10px; align-content: start; }
.slider { display: grid; grid-template-columns: 120px 1fr 48px; align-items: center; gap: 10px; }
.slider output { text-align: right; font-family: var(--mono); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 52px; }
.row.check input { width: 28px; height: 28px; accent-color: var(--accent); }
.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.plan { border: 1px solid var(--line); border-radius: 16px; padding: 18px; background: var(--panel-2); text-align: left; display: grid; gap: 4px; min-height: 120px; }
.plan:disabled { opacity: 0.6; }
.plan b { font-size: 28px; }
.plan small { color: var(--muted); }
.plan.best { border-color: var(--warn); }
.feat { margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.7; }
.qr { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: center; }
.qr .code { background: #fff; border-radius: 12px; padding: 8px; }
.qr .code svg { display: block; width: 100%; height: auto; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-size: 18px; text-transform: uppercase; letter-spacing: 0.15em; }
.bigcode { font-family: var(--mono); font-size: 44px; letter-spacing: 0.25em; text-align: center; padding: 12px; border-radius: 12px; background: var(--panel-2); }
.muted { color: var(--muted); }
.err { color: var(--red); margin: 0; }

.toast { position: fixed; inset: auto auto 120px 50%; margin: 0; border: 0; max-width: min(720px, 90vw); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 14px 22px; border-radius: 14px; font-weight: 700; font-size: 17px; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 20; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.resume-bar { position: fixed; left: 50%; top: 84px; transform: translateX(-50%); z-index: 15; padding: 18px 28px; border-radius: 16px; border: 2px solid var(--warn); background: var(--panel); color: var(--text); font-size: 18px; font-weight: 700; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.stats.compact dd { font-size: 16px; }
.sub { margin: 6px 0 0; font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); min-height: 56px; }
.devices small { color: var(--muted); }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; }
.btn.small { padding: 10px 14px; font-size: 14px; }
.warnbox { margin: 0; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--warn); color: var(--warn); font-weight: 600; }
.inline-form.stack { flex-wrap: wrap; margin-top: 10px; }
.inline-form.stack input[type=email] { text-transform: none; letter-spacing: normal; flex-basis: 100%; }
details > summary { cursor: pointer; color: var(--muted); padding: 10px 0; min-height: 44px; }
.err:empty { display: none; }

/* Ventanas medianas (navegador del coche sin pantalla completa, portátiles) */
@media (max-width: 1440px) {
  .pedal { width: 120px; }
  .seg button { min-width: 76px; }
  .ctl { min-width: 64px; }
  .ctl.wide { min-width: 96px; }
}

/* Pantallas estrechas (pruebas en móvil) */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100dvh; }
  .dash { grid-template-columns: 1fr; }
  .center { min-height: 340px; order: -1; }
  .side.left { display: none; }
  #app { padding: 10px 10px 14px; }
  .topbar { gap: 8px; }
  .engine-pill { flex: 1; min-width: 0; padding-right: 12px; }
  .engine-pill small { display: none; }
  .ctl-group { flex: 1 1 100%; justify-content: center; }
  .ctl { min-width: 56px; height: 64px; }
  .ctl.wide { min-width: 88px; }
  .seg button { flex: 1; min-width: 0; height: 60px; }
  .start-btn { width: 100%; }
  .dash { gap: 10px; }
  .tick-label.small { display: none; }
  .side.right { padding: 12px 14px; }
  .stats.big dd { font-size: 20px; }
  .controls { flex-wrap: wrap; }
  .chips #planChip { display: none; }
  .brand span { display: none; }
  .pedal { width: calc(50% - 6px); min-height: 80px; order: 10; }
}
