:root {
  --bg: #0f1115;
  --panel: rgba(16, 18, 24, 0.72);
  --panel-solid: #161922;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f1f2f4;
  --muted: #a3a8b3;
  --accent: #ff4b3e;
  --good: #3ddc84;
  --bad: #ff5d5d;
  --gold: #ffd23f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.hud-top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: stretch; gap: 8px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; backdrop-filter: blur(6px); display: flex; flex-direction: column; justify-content: center; font-size: 13px; gap: 2px; }
.lapchip { align-items: center; min-width: 52px; }
.lapchip b { font-size: 22px; line-height: 1; }
.lbl { color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; margin-right: 6px; }
.sides b { font-variant-numeric: tabular-nums; }
.timebox { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px; min-width: 150px; text-align: center; backdrop-filter: blur(6px); }
.cur { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.cur.invalid { color: var(--bad); }
.delta { font-size: 14px; min-height: 18px; font-variant-numeric: tabular-nums; font-weight: 600; }
.delta.fast { color: var(--good); }
.delta.slow { color: var(--bad); }
.speed { position: absolute; right: 14px; top: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 14px; text-align: right; backdrop-filter: blur(6px); }
.speed span { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }
.speed small { margin-left: 5px; color: var(--muted); font-size: 12px; }
.hud.offtrack .speed { border-color: var(--bad); }

.tel { position: absolute; right: 14px; top: 76px; width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 12px; backdrop-filter: blur(6px); }
.tel-title { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; margin-bottom: 6px; }
.tel-row { display: grid; grid-template-columns: 1fr 96px; gap: 8px; align-items: center; margin: 4px 0; }
.tel-row span { color: var(--muted); }
.tel-row b { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; width: 0; background: var(--good); transition: width .06s linear; }
.bar i.hot { background: var(--bad); }
.bar.split i { background: #5aa9ff; }
.bar.split i.r { background: #ffb347; }

.banner { position: absolute; left: 50%; top: 24%; width: max-content; max-width: 86vw; transform: translate(-50%, -10px); padding: 10px 20px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
  font-weight: 600; opacity: 0; transition: opacity .25s, transform .25s; text-align: center; max-width: 86vw; }
.banner.show { opacity: 1; transform: translate(-50%, 0); }
.banner.good { border-color: var(--gold); color: var(--gold); }
.banner.bad { border-color: var(--bad); color: #ffb0b0; }

/* ---------- touch ---------- */
.touch { position: fixed; left: 0; right: 0; bottom: 0; height: 40%; max-height: 190px; padding: 0 14px calc(14px + env(safe-area-inset-bottom)); display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; pointer-events: none; }
.touch.idle { opacity: .35; }
.steerpad { pointer-events: auto; position: relative; flex: 1 1 52%; max-width: 440px; height: 92px; border-radius: 46px; background: rgba(16, 18, 24, .55); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; touch-action: none; margin-left: env(safe-area-inset-left); }
.steerpad .rail { position: absolute; left: 22px; right: 22px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.22); }
.steerpad .knob { width: 64px; height: 64px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #c9cdd6 60%, #8e93a0); box-shadow: 0 4px 12px rgba(0,0,0,.45); transition: transform .05s linear; }
.pedals { display: flex; gap: 12px; pointer-events: none; margin-right: env(safe-area-inset-right); }
.pedal { pointer-events: auto; touch-action: none; border: 1px solid var(--line); border-radius: 22px; font-weight: 800; letter-spacing: .06em; font-size: 15px; color: #fff; }
.pedal.gas { width: 108px; height: 120px; background: linear-gradient(180deg, #3bbf74, #1f8a4f); }
.pedal.brake { width: 84px; height: 92px; background: linear-gradient(180deg, #e0534a, #a82a25); }
.pedal.down { filter: brightness(1.3); transform: scale(.97); }
.pausebtn { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: calc(150px + env(safe-area-inset-right)); display: none; pointer-events: auto; width: 40px; height: 40px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-weight: 800; }
body.has-touch .pausebtn { display: block; }
@media (max-width: 760px) {
  .hud-top { top: 8px; gap: 6px; }
  .sides { display: none; }
  .cur { font-size: 24px; }
  .timebox { min-width: 120px; }
  .speed { top: 62px; right: 10px; padding: 4px 10px; }
  .speed span { font-size: 24px; }
  .tel { top: 112px; right: 10px; width: 200px; }
  .pausebtn { right: calc(10px + env(safe-area-inset-right)); top: calc(8px + env(safe-area-inset-top)); }
}
@media (max-height: 460px) {
  .touch { height: 96px; }
  .steerpad { height: 76px; }
  .steerpad .knob { width: 54px; height: 54px; }
  .pedal.gas { width: 96px; height: 92px; }
  .pedal.brake { width: 76px; height: 72px; }
  .tel { top: 60px; }
}

/* ---------- schermate ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(10,12,16,.55), rgba(8,9,12,.9)); overflow: auto; }
.card { position: relative; width: min(560px, 100%); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 18px; padding: 24px 24px 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); max-height: 100%; overflow: auto; touch-action: pan-y; }
.card.small { width: min(340px, 100%); text-align: center; display: flex; flex-direction: column; gap: 10px; }
h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: -.01em; }
h2 { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.sub { margin: 0; color: var(--muted); }
.help { margin: 0; padding-left: 18px; color: #d7dae1; font-size: 14px; line-height: 1.5; }
.opts { display: grid; gap: 8px; }
.opts label { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; }
select { background: #20242e; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; }
.btn { display: block; width: 100%; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: #20242e; font-weight: 700; font-size: 16px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: transparent; margin-top: 20px; }
.card.small .btn.primary { margin-top: 8px; }
.btn:active { filter: brightness(1.15); }
.wip, .ver { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
.lang { position: absolute; right: 16px; top: 16px; display: flex; gap: 4px; }
.lang button { background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; color: var(--muted); }
.lang button.on { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- gomme e scelta auto ---------- */
.tyrebox { position: absolute; right: 14px; top: 76px; display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; backdrop-filter: blur(6px); font-size: 11px; }
.cmp { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #14151a; background: #f2c230; border: 3px solid #14151a; box-shadow: 0 0 0 2px rgba(255,255,255,.2); }
.tcols { display: grid; gap: 4px; }
.trow { display: grid; grid-template-columns: 34px 64px 38px; gap: 6px; align-items: center; }
.trow span { color: var(--muted); letter-spacing: .05em; }
.trow b { text-align: right; font-variant-numeric: tabular-nums; }
.trow b.cold { color: #6db8ff; } .trow b.hot { color: #ff6b5e; } .trow b.ok { color: var(--good); }
.trow .bar i.warn { background: #f2c230; }
.tel { top: 128px; }
.carpick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.carbtn { background: #20242e; border: 2px solid var(--line); border-radius: 12px; padding: 8px 6px 10px; cursor: pointer; text-align: center; display: grid; gap: 4px; justify-items: center; }
.carbtn.on { border-color: var(--accent); background: #2a2230; }
.carbtn canvas { width: 100%; max-width: 110px; height: auto; }
.carbtn b { font-size: 14px; }
.carbtn .st { display: grid; grid-template-columns: 22px 1fr; gap: 4px; width: 100%; font-size: 9px; color: var(--muted); align-items: center; text-align: left; }
.carbtn .st i { display: block; height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--good) var(--v), rgba(255,255,255,.12) var(--v)); }
.cmppick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cmpbtn { background: #20242e; border: 2px solid var(--line); border-radius: 12px; padding: 8px 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.cmpbtn.on { border-color: var(--accent); background: #2a2230; }
.cmpbtn i { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #14151a; box-shadow: 0 0 0 1.5px rgba(255,255,255,.3); display: block; }
.cardesc { margin: 6px 0 0; font-size: 12px; color: var(--muted); min-height: 2.6em; }
@media (max-width: 760px) {
  .tyrebox { top: 108px; right: 10px; padding: 4px 8px; }
  .tel { top: 160px; }
}
@media (max-height: 460px) {
  .tyrebox { top: 56px; right: 10px; }
  .tel { top: 110px; }
}

details.ctrl { margin-top: 14px; }
details.ctrl summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: 4px 0; }
details.ctrl .help { margin-top: 6px; }
.startbar { position: sticky; bottom: -18px; margin: 0 -24px; padding: 14px 24px 10px; background: linear-gradient(180deg, rgba(22,25,34,0), var(--panel-solid) 28%); }
.startbar .btn.primary { margin-top: 0; }

/* ---------- pannello debug ---------- */
.dbtn { pointer-events: auto; align-self: center; width: 40px; height: 40px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 18px; cursor: pointer; backdrop-filter: blur(6px); }
.btn.small { padding: 8px 12px; font-size: 13px; margin-top: 14px; }
.debug { position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 86vw); z-index: 30; display: flex; flex-direction: column; background: rgba(14, 16, 22, .88); border-left: 1px solid var(--line); backdrop-filter: blur(8px); padding-top: env(safe-area-inset-top); }
.dhead { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.dhead button { width: 32px; height: 32px; border-radius: 8px; background: #20242e; border: 1px solid var(--line); cursor: pointer; }
.dlive { margin: 0; padding: 8px 12px; font: 11px/1.45 ui-monospace, Consolas, monospace; color: #cfe3ff; border-bottom: 1px solid var(--line); white-space: pre-wrap; min-height: 3.4em; }
.dbody { flex: 1; overflow-y: auto; padding: 4px 12px 10px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.dbody h3 { margin: 14px 0 4px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.drow { padding: 5px 0; }
.drow .dtop { display: grid; grid-template-columns: 1fr auto 28px; gap: 6px; align-items: center; font-size: 12px; }
.drow .dname { color: #d7dae1; }
.drow .dval { font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.drow.changed .dval { color: var(--gold); }
.drow .dreset { background: transparent; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); cursor: pointer; height: 24px; }
.drow input[type=range] { width: 100%; margin: 4px 0 0; touch-action: pan-y; accent-color: var(--accent); height: 28px; }
.dfoot { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.dfoot textarea { width: 100%; background: #0d0f14; color: #cfe3ff; border: 1px solid var(--line); border-radius: 8px; font: 11px/1.4 ui-monospace, Consolas, monospace; user-select: text; -webkit-user-select: text; }
.dbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dbtns .btn.small { margin-top: 6px; }
body.debug-open .tel, body.debug-open .speed, body.debug-open .tyrebox { right: min(354px, calc(86vw + 14px)); }
@media (max-width: 760px) { .debug { width: min(330px, 92vw); } body.debug-open .speed, body.debug-open .tyrebox, body.debug-open .tel { display: none; } }

.dbench { border-top: 1px solid var(--line); padding: 6px 12px 2px; max-height: 34%; overflow-y: auto; }
.dbench .dbhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
.dbench .btn.small { margin-top: 0; padding: 6px 10px; width: auto; }
.dbench pre { border: 0; padding: 6px 0; min-height: 0; }
.dhint { margin: 0 0 6px; font-size: 10px; color: var(--muted); }

/* ---------- telefono in verticale: barra di sterzo più larga, pedali impilati, bersagli da 44 px ---------- */
.dbtn, .pausebtn { width: 44px; height: 44px; }
@media (max-width: 520px) and (orientation: portrait) {
  .touch { max-height: 210px; }
  .steerpad { flex: 1 1 auto; max-width: none; height: 96px; }
  .pedals { flex-direction: column; gap: 10px; }
  .pedal.gas { width: 104px; height: 84px; }
  .pedal.brake { width: 104px; height: 64px; }
}

/* ================= v0.5: stanza multiplayer, box, comandi touch a scelta ================= */
.namefield { display: grid; gap: 6px; margin-top: 16px; font-size: 13px; color: var(--muted); }
.namefield input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #20242e; color: var(--text); font: inherit; font-size: 17px; font-weight: 600; user-select: text; -webkit-user-select: text; }
.namefield input:focus { outline: 2px solid var(--accent); }
.colorpick { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; box-shadow: inset 0 0 0 2px rgba(0,0,0,.35); cursor: pointer; }
.swatch.on { border-color: #fff; box-shadow: inset 0 0 0 2px rgba(0,0,0,.35), 0 0 0 2px var(--accent); }
.netstatus { margin-top: 12px; text-align: center; font-size: 13px; color: var(--muted); min-height: 1.4em; }
.netstatus.ok { color: var(--good); } .netstatus.bad { color: #ffb0b0; }
.cmppick .cmpbtn { padding: 8px 4px; }

/* giocatori nella stanza */
.players { position: absolute; left: 12px; top: 214px; display: flex; flex-direction: column; gap: 4px; max-width: 150px; font-size: 11px; }
.players span { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px 3px 6px; display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; backdrop-filter: blur(6px); }
.players i { width: 9px; height: 9px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1.5px rgba(255,255,255,.5); }
@media (max-width: 760px) { .players { top: 266px; } }
@media (max-height: 460px) { .players { top: 190px; max-width: 120px; } }

/* pulsante debug: sul bordo destro, fuori dalla barra del sito e dai comandi */
.dbtn { position: fixed; right: 8px; top: 42%; z-index: 25; width: 46px; height: 46px; display: block; }
body.debug-open .dbtn { right: min(350px, 90vw); }
.hud .dbtn { display: none; }

/* messaggio di benvenuto con freccia verso il pulsante debug */
.welcome { position: fixed; right: 62px; top: calc(42% - 54px); z-index: 40; display: flex; align-items: center; gap: 8px; max-width: min(330px, calc(100vw - 80px)); }
.wbubble { background: #f6f0d8; color: #20222a; border-radius: 14px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.45); border: 2px solid var(--gold); font-size: 14px; line-height: 1.4; pointer-events: auto; }
.wbubble p { margin: 0 0 8px; font-weight: 600; }
.wbubble .btn { background: #20222a; color: #fff; width: auto; margin: 0; padding: 7px 14px; }
.warrow { font-size: 40px; color: var(--gold); text-shadow: 0 2px 8px rgba(0,0,0,.6); animation: nudge .8s ease-in-out infinite alternate; }
@keyframes nudge { from { transform: translateX(-6px); } to { transform: translateX(8px); } }

/* box */
.pitbtn { position: absolute; left: 50%; transform: translateX(-50%); top: 88px; display: none; pointer-events: auto; padding: 10px 22px; border-radius: 999px; border: 2px solid #ffb02e; background: rgba(40, 28, 8, .8); color: #ffd27a; font-weight: 800; letter-spacing: .1em; font-size: 15px; backdrop-filter: blur(6px); }
.pitbtn.show { display: block; }
.pitbtn.active { background: #ffb02e; color: #2a1c08; }
.pitpanel { position: absolute; right: 68px; top: 150px; width: 270px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; box-shadow: 0 12px 40px rgba(0,0,0,.5); pointer-events: auto; }
.pp-title { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: 12px; color: #ffd27a; display: flex; justify-content: space-between; margin-bottom: 8px; }
.pp-row { display: flex; justify-content: space-between; font-size: 13px; margin: 8px 0 4px; color: #d7dae1; }
.pp-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.pp-btns .btn { padding: 10px; margin: 0; font-size: 14px; }
.pitpanel .btn.primary { margin-top: 0; }
#pitStep3 .pp-btns { grid-template-columns: 1fr; }
.pitpanel input[type=range] { width: 100%; accent-color: #ffb02e; height: 30px; touch-action: pan-x; }
.pbar { height: 12px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; margin-top: 8px; }
.pbar i { display: block; height: 100%; width: 0; background: #ffb02e; transition: width .1s linear; }
@media (max-width: 760px) { .pitpanel { right: 50%; transform: translateX(50%); top: 130px; width: min(310px, 92vw); } .pitbtn { top: 74px; } }
@media (max-height: 460px) { .pitpanel { top: 58px; right: 70px; transform: none; } .pitbtn { top: 64px; } }

/* comandi touch: modalità scelte dall'utente */
.touch { max-height: 280px; }
.tleft, .tright { display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.tleft { flex: 1 1 auto; min-width: 0; align-items: flex-start; }
.tright { align-items: flex-end; }
.modebtn { pointer-events: auto; min-width: 48px; height: 36px; padding: 0 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 15px; color: var(--text); }
.touch[data-steer="slider"] .steerwheel, .touch[data-steer="slider"] .steerbtns,
.touch[data-steer="wheel"] .steerpad, .touch[data-steer="wheel"] .steerbtns,
.touch[data-steer="buttons"] .steerpad, .touch[data-steer="buttons"] .steerwheel { display: none; }
.touch[data-pedal="buttons"] .pedalsliders, .touch[data-pedal="sliders"] .pedals { display: none; }
.tleft .steerpad { width: 100%; max-width: 440px; margin-left: 0; }
.steerwheel { pointer-events: auto; width: 128px; height: 128px; touch-action: none; }
.wheelimg { width: 100%; height: 100%; border-radius: 50%; border: 13px solid #23262e; box-shadow: 0 6px 18px rgba(0,0,0,.5), inset 0 0 0 2px rgba(255,255,255,.12); position: relative;
  background: radial-gradient(circle, #353a45 0 17%, transparent 18%), linear-gradient(#23262e, #23262e) 50% 50% / 100% 14px no-repeat, linear-gradient(#23262e, #23262e) 50% 100% / 14px 50% no-repeat, rgba(20,22,28,.35); }
.wheelimg i { position: absolute; left: 50%; top: -13px; width: 10px; height: 13px; margin-left: -5px; background: var(--accent); border-radius: 3px; }
.steerbtns { display: flex; gap: 14px; pointer-events: none; }
.sbtn { pointer-events: auto; touch-action: none; width: 96px; height: 90px; border-radius: 22px; background: linear-gradient(180deg, #4a4f5c, #2c2f38); border: 1px solid var(--line); font-size: 32px; color: #fff; }
.sbtn.down { filter: brightness(1.4); transform: scale(.97); }
.pedalsliders { display: flex; gap: 12px; pointer-events: none; }
.vslider { pointer-events: auto; position: relative; width: 78px; height: 154px; border-radius: 20px; background: rgba(16,18,24,.62); border: 1px solid var(--line); overflow: hidden; touch-action: none; }
.vslider i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; }
.vslider.gas i { background: linear-gradient(180deg, #3bbf74, #1f8a4f); }
.vslider.brake i { background: linear-gradient(180deg, #e0534a, #a82a25); }
.vslider span { position: absolute; top: 8px; left: 0; right: 0; text-align: center; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-shadow: 0 1px 3px #000; pointer-events: none; }
@media (max-width: 520px) and (orientation: portrait) {
  .touch { max-height: 280px; }
  .steerwheel { width: 118px; height: 118px; }
  .sbtn { width: 84px; height: 84px; }
  .vslider { width: 64px; height: 140px; }
  .tleft .steerpad { max-width: none; }
}
@media (max-height: 460px) {
  .touch { max-height: none; height: auto; }
  .steerwheel { width: 98px; height: 98px; }
  .sbtn { width: 84px; height: 66px; }
  .vslider { height: 100px; width: 66px; }
  .modebtn { height: 30px; }
}

/* pannello debug: area scorrevole unica */
.dscroll { flex: 1; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.dscroll .dbody { flex: none; overflow: visible; }
.dscroll .dbench { max-height: none; overflow: visible; }
.dpresets { border-top: 1px solid var(--line); padding: 8px 12px 6px; }
.dsave { display: flex; gap: 6px; }
.dsave input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: #20242e; color: var(--text); font: inherit; font-size: 14px; user-select: text; -webkit-user-select: text; }
.dsave .btn.small { width: auto; margin: 0; padding: 8px 14px; }
.plist { margin-top: 6px; display: grid; }
.prow { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.prow b { display: block; font-size: 13px; }
.prow small { color: var(--muted); }
.prow button { background: #20242e; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; cursor: pointer; }
.prow button.del { color: #ffb0b0; }
.pempty { color: var(--muted); font-size: 12px; padding: 6px 0; }

@media (max-height: 460px) { .tyrebox { top: 76px; } .tel { top: 150px; } .pitpanel { top: 76px; right: 70px; } }

.drivepick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.drvbtn { background: #20242e; border: 2px solid var(--line); border-radius: 12px; padding: 8px 4px; cursor: pointer; display: grid; gap: 2px; justify-items: center; color: inherit; font: inherit; }
.drvbtn b { font-size: 18px; letter-spacing: .06em; }
.drvbtn span { font-size: 11px; color: var(--muted); }
.drvbtn.on { border-color: var(--accent); background: #2a2230; }
.dsel { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 0 4px; font-size: 12px; }
.dsel select { background: #20242e; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; }

.dkeys { font-size: 12px; padding: 4px 0 8px; }
.dkeys .kt { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.dkeys .kt b { font-family: ui-monospace, Consolas, monospace; color: var(--accent); min-height: 1.2em; }
.dkeys .khint { color: var(--muted, #9aa3b5); margin: 6px 0; line-height: 1.35; }
.krow { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 3px 0; }
.krow .kcodes { color: var(--muted, #9aa3b5); font-family: ui-monospace, Consolas, monospace; }
.dkeys button { background: #20242e; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; font: inherit; }
/* iOS Safari: niente menu di pressione prolungata, selezione o evidenziazione sui comandi a schermo e sulla pista */
canvas#game, .touch, .touch * { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: none; }
.touch button { -webkit-appearance: none; appearance: none; }

.drow .dread { font-size: 11px; color: var(--muted, #9aa3b5); padding-top: 2px; }

#touchLog { position: fixed; left: 50%; top: 6px; transform: translateX(-50%); z-index: 90; margin: 0; padding: 6px 8px; max-width: 46vw; font: 10px/1.25 ui-monospace, Consolas, monospace; color: #bff0c8; background: rgba(0,0,0,.6); border-radius: 8px; pointer-events: none; white-space: pre; overflow: hidden; }
/* i comandi stanno lontani dal bordo dello schermo: i gesti di sistema di iOS (indietro, barra in basso) partono lì e annullano i tocchi */
.touch { padding-left: max(30px, env(safe-area-inset-left)); padding-right: max(30px, env(safe-area-inset-right)); padding-bottom: calc(26px + env(safe-area-inset-bottom)); }

.tyreiconbox { width: 34px; height: 56px; flex: none; }
.tyreiconbox.pit { width: 36px; height: 59px; }
.tyreicon { width: 100%; height: 100%; display: block; }
.tyreicon .cbody { fill: rgba(255,255,255,.14); }
.tyreicon .whl { fill: #6a7080; stroke: rgba(0,0,0,.55); stroke-width: .8; }
.tyreicon .wearbg { fill: rgba(255,255,255,.18); }
.tyreicon .wear { fill: var(--good); } .tyreicon .wear.warn { fill: #f2c230; } .tyreicon .wear.bad { fill: var(--bad); }
.tyreicon g.slip .whl { stroke: #fff; stroke-width: 2; animation: tyreflash .28s steps(2, start) infinite; }
@keyframes tyreflash { 50% { stroke: #ff3b30; } }

/* chat: sempre gli ultimi messaggi in semitrasparenza, si espande per leggere e scrivere */
.chat { position: fixed; left: 12px; bottom: 12px; z-index: 40; width: min(340px, 56vw); font-size: 12px; line-height: 1.3; pointer-events: none; display: flex; flex-direction: column; gap: 4px; }
body.has-touch .chat { bottom: calc(min(40vh, 190px) + 26px); width: min(280px, 38vw); font-size: 11px; }
.chat[hidden] { display: none; }
.chat-lines { max-height: 4.6em; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; opacity: .58; pointer-events: auto; cursor: pointer; text-shadow: 0 1px 2px rgba(0,0,0,.85); }
.chat .cl { padding: 1px 6px; overflow-wrap: anywhere; color: #fff; }
.chat .cl.sys { color: #c9d1e0; font-style: italic; }
.chat-form, .chat-toggle { display: none; }
.chat-toggle { pointer-events: auto; align-self: flex-start; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 3px 8px; font-size: 14px; position: relative; }
.chat:not(.open) .chat-toggle { display: block; opacity: .75; }
.chat-toggle b { position: absolute; top: -6px; right: -6px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; display: grid; place-items: center; }
.chat.open { width: min(380px, 70vw); pointer-events: auto; background: rgba(12,14,19,.82); border: 1px solid var(--line); border-radius: 12px; padding: 6px; backdrop-filter: blur(6px); }
body.has-touch .chat.open { bottom: auto; top: 8px; width: min(420px, 62vw); }
.chat.open .chat-lines { opacity: 1; max-height: min(40vh, 14em); overflow-y: auto; justify-content: flex-start; cursor: default; }
.chat.open .chat-form { display: flex; gap: 6px; pointer-events: auto; }
.chat-form input { flex: 1; min-width: 0; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line); background: #20242e; color: var(--text); font: inherit; font-size: 16px; user-select: text; -webkit-user-select: text; }
.chat-form button { padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--accent, #3b82f6); color: #fff; font: inherit; font-weight: 700; }
/* telefono: la chat chiusa sta sopra lo sterzo, sotto la minimappa; il pulsante sta accanto alle righe */
body.has-touch .chat { bottom: calc(132px + env(safe-area-inset-bottom)); left: max(14px, env(safe-area-inset-left)); width: min(270px, 36vw); }
body.has-touch .chat-lines { max-height: 3em; }
body.has-touch .chat:not(.open) .chat-toggle { position: absolute; right: -38px; bottom: 0; padding: 2px 6px; }
body.has-touch .chat.open .chat-lines { max-height: min(34vh, 9em); }

/* classifica dei tempi (al posto dell'elenco giocatori) */
.players { max-width: 190px; cursor: pointer; pointer-events: auto; }
.players.open { max-height: 55vh; overflow-y: auto; }
.players .lbrow { display: grid; grid-template-columns: 14px 10px 1fr auto; gap: 5px; align-items: center; border-radius: 8px; padding: 2px 7px 2px 5px; background: var(--panel); }
.players .lbrow em { font-style: normal; color: var(--muted); font-size: 10px; text-align: right; }
.players .lbrow u { text-decoration: none; overflow: hidden; text-overflow: ellipsis; }
.players .lbrow b { font-variant-numeric: tabular-nums; font-size: 10.5px; }
.players .lbrow.me { border-color: var(--accent, #3b82f6); background: rgba(59,130,246,.28); }
.players .lbrow.rec b { color: var(--gold); }
.players .lbrow.off { opacity: .6; }
.players .lbmore { background: none; border: 0; color: var(--muted); font-size: 10px; padding: 0 6px; }
.sides small { color: var(--muted); font-size: 9px; margin-left: 2px; }
@media (max-width: 760px), (max-height: 460px) { .players { max-width: 150px; font-size: 10px; } body.has-touch .chat { left: 160px; } }
