:root {
  --fondo: #121416;
  --superficie: #1B1E22;
  --superficie-2: #24282D;
  --bordo: #30353B;
  --testo: #EDEBE6;
  --testo-2: #9A9EA3;
  --accento: #F2B134;
  --accento-testo: #1A1200;
  --rosso: #D8402F;
  --arco: #2C3137;
  --ombra: 0 12px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}
:root[data-theme="chiaro"] {
  --fondo: #E6E4DE;
  --superficie: #F3F2EE;
  --superficie-2: #E9E7E1;
  --bordo: #CFCCC4;
  --testo: #1A1B1D;
  --testo-2: #66696E;
  --accento: #D99A12;
  --accento-testo: #1A1200;
  --rosso: #C8342A;
  --arco: #D6D3CB;
  --ombra: 0 12px 40px rgba(0,0,0,.12);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="scuro"]):not([data-theme="chiaro"]) {
    --fondo: #E6E4DE; --superficie: #F3F2EE; --superficie-2: #E9E7E1; --bordo: #CFCCC4;
    --testo: #1A1B1D; --testo-2: #66696E; --accento: #D99A12; --rosso: #C8342A; --arco: #D6D3CB;
    --ombra: 0 12px 40px rgba(0,0,0,.12); color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--testo);
  font-family: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 20px;
  line-height: 1.35;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: manipulation;
}
h2, h3 { margin: 0; font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif; font-weight: 500; font-size: 22px; color: var(--testo-2); letter-spacing: .01em; }
button { font: inherit; color: inherit; }
p { margin: 0; }
.nota { font-size: 16px; color: var(--testo-2); line-height: 1.4; }

.barra {
  display: flex; align-items: center; gap: 20px;
  height: 64px; padding: 0 20px;
}
.marchio { display: flex; align-items: center; gap: 12px; font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: 30px; letter-spacing: .03em; }
.logo { width: 26px; height: 26px; border-radius: 50%; border: 5px solid var(--accento); border-bottom-color: transparent; transform: rotate(45deg); display: inline-block; }
.stato { flex: 1; text-align: center; color: var(--testo-2); font-size: 18px; }
.stato.attivo { color: var(--accento); }
.stato.errore { color: var(--rosso); }
.tasto-icona { background: transparent; border: 0; color: var(--testo-2); width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; cursor: pointer; font-size: 30px; }
.tasto-icona:active { background: var(--superficie-2); }

.scena {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
  gap: 24px; padding: 0 24px 24px; height: calc(100% - 64px);
}
.quadro { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; min-height: 0; }

.tachimetro {
  position: relative; width: min(100%, 70vh, 640px); aspect-ratio: 1 / 1; cursor: pointer;
}
.contagiri { width: 100%; height: 100%; display: block; }
.arco-fondo { stroke: var(--arco); stroke-linecap: butt; }
.arco-rosso { stroke: var(--rosso); opacity: .55; }
.arco-pieno { stroke: var(--accento); stroke-linecap: butt; transition: stroke-dasharray .06s linear; }
#tacche line { stroke: var(--testo-2); stroke-width: 3; }
#tacche line.grande { stroke: var(--testo); stroke-width: 4; }
#numeri text { fill: var(--testo); font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: 30px; text-anchor: middle; dominant-baseline: middle; }
#numeri text.rosso { fill: var(--rosso); }
.lancetta path { fill: var(--testo); }
.lancetta circle { fill: var(--superficie-2); stroke: var(--testo); stroke-width: 3; }
.lancetta { transform-origin: 200px 200px; transform: rotate(-135deg); transition: transform .07s linear; }
.centro { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -38%); text-align: center; pointer-events: none; }
.marcia-etichetta { font-size: 18px; color: var(--testo-2); }
.marcia { font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: clamp(72px, 16vh, 128px); line-height: 1; }
.marcia.limitatore { color: var(--rosso); }
.giri { font-size: 18px; color: var(--testo-2); font-variant-numeric: tabular-nums; }
.velocita { position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%); font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: clamp(40px, 8vh, 64px); line-height: 1; pointer-events: none; font-variant-numeric: tabular-nums; }
.velocita small { font-size: 18px; font-weight: 500; margin-left: 8px; color: var(--testo-2); font-family: "Barlow", sans-serif; }

.comandi-marcia { display: flex; gap: 16px; width: min(100%, 70vh, 640px); }
.tasto {
  background: var(--superficie-2); border: 1px solid var(--bordo); border-radius: 16px;
  padding: 14px 22px; cursor: pointer; font-size: 20px; min-height: 60px;
}
.tasto:active { background: var(--bordo); }
.tasto.grande { flex: 1; min-height: 80px; font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: 30px; }
.tasto[disabled] { opacity: .35; cursor: default; }

.pannello {
  background: var(--superficie); border-radius: 24px; padding: 22px;
  display: flex; flex-direction: column; gap: 22px; overflow-y: auto; min-height: 0;
  box-shadow: var(--ombra);
}
.gruppo { display: flex; flex-direction: column; gap: 12px; }
.lista-motori { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.motore {
  text-align: left; background: var(--superficie-2); border: 2px solid transparent; border-radius: 16px;
  padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-height: 76px;
}
.motore strong { font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: 24px; line-height: 1.05; }
.motore span { font-size: 15px; color: var(--testo-2); }
.motore.scelto { border-color: var(--accento); }
.motore.scelto strong { color: var(--accento); }

.riga { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.riga h2, .riga h3 { flex: 0 0 auto; min-width: 120px; }
.segmenti { display: inline-flex; background: var(--superficie-2); border-radius: 14px; padding: 4px; gap: 4px; }
.segmenti button { background: transparent; border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer; min-height: 48px; color: var(--testo-2); }
.segmenti button.scelto { background: var(--fondo); color: var(--testo); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
:root[data-theme="chiaro"] .segmenti button.scelto { background: #fff; }

.pedaliera { display: flex; gap: 12px; }
.pedale { flex: 1; min-height: 110px; border-radius: 18px; border: 2px solid var(--bordo); background: var(--superficie-2); font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: 28px; cursor: pointer; }
.pedale.gas { flex: 1.6; }
.pedale.premuto, .pedale:active { background: var(--accento); color: var(--accento-testo); border-color: var(--accento); }
.pedale.freno.premuto, .pedale.freno:active { background: var(--rosso); color: #fff; border-color: var(--rosso); }

.azioni { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.tasto.avvia { background: var(--accento); color: var(--accento-testo); border: 0; min-height: 84px; font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: 32px; letter-spacing: .02em; }
.tasto.avvia.acceso { background: var(--superficie-2); color: var(--testo); border: 2px solid var(--bordo); }

.velo { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 24px; z-index: 10; }
.velo[hidden] { display: none; }
.finestra { background: var(--superficie); border-radius: 24px; padding: 28px; width: min(100%, 760px); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; box-shadow: var(--ombra); }
.finestra h2 { font-size: 32px; color: var(--testo); font-weight: 700; }
.finestra-testa { display: flex; align-items: center; justify-content: space-between; }
.lista-auto { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lista-auto button { text-align: left; background: var(--superficie-2); border: 2px solid transparent; border-radius: 14px; padding: 14px 16px; cursor: pointer; min-height: 60px; font-size: 20px; }
.lista-auto button.scelto { border-color: var(--accento); }
.lista-auto button small { display: block; color: var(--testo-2); font-size: 15px; }
input[type=range] { flex: 1; min-width: 200px; accent-color: var(--accento); height: 44px; }

@media (max-width: 900px) {
  body { overflow: auto; font-size: 18px; }
  .scena { grid-template-columns: 1fr; height: auto; padding: 0 16px 24px; }
  .tachimetro { width: min(100%, 420px); }
  .comandi-marcia { width: min(100%, 420px); }
  .lista-motori, .lista-auto { grid-template-columns: 1fr; }
  .riga h2, .riga h3 { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .lancetta, .arco-pieno { transition: none; }
}
button:focus-visible { outline: 3px solid var(--accento); outline-offset: 2px; }
