:root {
  --bg: #101a24; --panel: #1b2a38; --panel2: #263a4c; --line: #4a6a85; --text: #eef4fa; --muted: #9db4c8;
  --accent: #f2b544; --good: #7ddc7a; --bad: #ef7b6c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; touch-action: none; }
.hidden { display: none !important; }
button, input { font: inherit; color: inherit; }
#cv { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.top { position: fixed; top: var(--site-bar, 0px); left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px max(10px, env(safe-area-inset-right)) 4px max(10px, env(safe-area-inset-left)); z-index: 5; pointer-events: none; }
.top > * { pointer-events: auto; }
.top h1 { margin: 0; font-size: 1.2rem; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); text-shadow: 0 1px 4px rgba(0,0,0,.7); white-space: nowrap; }
.top-right { display: flex; align-items: center; gap: 6px; }
.langs { display: inline-flex; }
.chip { background: rgba(27,42,56,.85); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: .85rem; cursor: pointer; }
.langs .chip:first-child { border-radius: 999px 0 0 999px; }
.langs .chip:last-child { border-radius: 0 999px 999px 0; border-left: 0; }
.chip.active { background: var(--accent); color: #1a1208; border-color: var(--accent); font-weight: 700; }

.hud { position: fixed; top: calc(var(--site-bar, 0px) + 46px); left: max(10px, env(safe-area-inset-left)); display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px; z-index: 4; pointer-events: none; max-width: calc(100% - 20px); }
.panel { background: rgba(14,24,34,.7); border: 1px solid rgba(150,190,220,.3); border-radius: 12px; padding: 5px 12px; }
.panel small { display: block; color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; }
.panel b { font-variant-numeric: tabular-nums; }
.speed .spd { display: flex; align-items: baseline; gap: 6px; }
.speed .spd b { font-size: 2.2rem; line-height: 1; min-width: 2.4ch; text-align: right; }
.speed .spd small { display: inline; }
.speed.over .spd b { color: var(--bad); }
.tag { background: var(--accent); color: #1a1208; border-radius: 6px; padding: 0 6px; font-size: .75rem; font-weight: 800; }
.limitrow { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.limit { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: #fff; color: #111; border: 4px solid #d02a22; font-weight: 800; font-size: .85rem; }
.sub { color: var(--muted); font-size: .8rem; }
.next { min-width: 190px; }
.next b { font-size: 1.1rem; display: block; }
.next .row { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; font-size: .92rem; }
.next .late { color: var(--bad); }
.next .ok { color: var(--good); }
.score b { font-size: 1.4rem; display: block; }

.levers { position: fixed; left: max(10px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 8px; z-index: 4; pointer-events: none; }
.lev { background: rgba(14,24,34,.7); border: 1px solid rgba(150,190,220,.3); border-radius: 12px; padding: 5px 9px; text-align: center; }
.lev small { display: block; color: var(--muted); font-size: .62rem; text-transform: uppercase; letter-spacing: .05em; }
.vbar { position: relative; display: block; width: 18px; height: 84px; margin: 4px auto 0; background: rgba(255,255,255,.14); border-radius: 5px; overflow: hidden; }
.vbar i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(0deg, #2f9a5a, #7ddc7a); }
.vbar.brk i { background: linear-gradient(0deg, #d98a2b, #ef6a4c); }
.vbar u { position: absolute; left: -1px; right: -1px; height: 3px; bottom: 0; background: #fff; text-decoration: none; }
.doors { background: rgba(14,24,34,.7); border: 1px solid rgba(150,190,220,.3); border-radius: 12px; padding: 5px 10px; font-size: .8rem; }
.doors.open { border-color: var(--good); color: var(--good); }

.hint-bar { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(14,24,34,.75); border: 1px solid rgba(242,181,68,.6); border-radius: 12px; padding: 6px 16px; z-index: 4; pointer-events: none; text-align: center; font-weight: 700; color: var(--accent); max-width: min(60vw, 560px); }
.toast { position: fixed; left: 50%; top: 24%; transform: translate(-50%, -50%); z-index: 6; pointer-events: none; text-align: center; font-size: 1.25rem; font-weight: 800; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,.9); background: rgba(14,24,34,.55); border-radius: 12px; padding: 8px 18px; max-width: 90vw; }
.toast.bad { color: var(--bad); }
.toast.good { color: var(--good); }
.banner { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 7; pointer-events: none; text-align: center; font-size: 2rem; font-weight: 800; letter-spacing: .08em; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,.9); }
.cross { position: fixed; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255,255,255,.6); z-index: 3; pointer-events: none; }

.pad { position: fixed; left: 0; right: 0; bottom: 0; display: none; z-index: 4; pointer-events: none; padding: 0 max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
body.touch .pad:not(.hidden) { display: block; }
.padset { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.padset > * { pointer-events: auto; }
.pcol { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pcol small { color: var(--muted); font-size: .65rem; text-transform: uppercase; }
.pmid { display: grid; grid-template-columns: repeat(3, auto); gap: 8px; align-self: flex-end; }
.pbtn { width: 66px; height: 66px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); background: rgba(27,42,56,.6); color: #fff; font-size: 1.5rem; touch-action: none; user-select: none; -webkit-user-select: none; }
.pbtn.sm { width: 50px; height: 50px; font-size: 1.15rem; }
.pbtn.brake { border-color: rgba(240,120,80,.9); }
.pbtn.danger { border-color: #e03a2a; color: #ff9a8a; }
.pbtn.on, .pbtn:active { background: rgba(242,181,68,.75); color: #1a1208; }
.joy { position: relative; width: 120px; height: 120px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); background: rgba(27,42,56,.45); touch-action: none; }
.joy i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255,255,255,.35); }

.overlay { position: fixed; inset: 0; background: rgba(6,12,18,.55); z-index: 10; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: calc(var(--site-bar, 0px) + 52px) 12px 16px; touch-action: pan-y; }
#account { z-index: 2147483001; background: rgba(0,0,0,.65); align-items: center; padding-top: 12px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; width: 100%; max-width: 520px; margin: auto; display: grid; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.sheet.wide { max-width: 640px; margin-top: 0; }
.sheet h2, .sheet h3 { margin: 0; }
.sheet h3 { font-size: .95rem; color: var(--muted); font-weight: 600; }
.sheet p { margin: 0; }
.hint { color: var(--muted); font-size: .85rem; }
.error { color: var(--bad); min-height: 1.2em; font-size: .9rem; }
.big { font-size: 1.3rem; font-weight: 800; color: var(--accent); text-align: center; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats > div { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; text-align: center; }
.stats small { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.stats b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.btn { background: var(--accent); color: #1c1408; border: 0; border-radius: 12px; padding: 12px 14px; font-weight: 700; cursor: pointer; min-height: 46px; }
.btn.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.big-btn { font-size: 1.25rem; min-height: 56px; }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }
.help { margin: 0; padding-left: 1.1em; color: var(--text); font-size: .88rem; display: grid; gap: 3px; }
kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font: inherit; font-size: .85em; }
label { display: block; font-size: .88rem; color: var(--muted); margin: 6px 0 4px; }
input[type=text], input[type=password], input[type=email] { width: 100%; background: #0d151d; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.top-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.top-table td, .top-table th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.top-table th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; }
.top-table td:first-child, .top-table th:first-child { text-align: left; }
#top .top-table td:first-child { width: 2em; color: var(--muted); }
#top .top-table td:nth-child(2) { text-align: left; }
.top-table tr.me td { color: var(--accent); font-weight: 700; }

@media (max-height: 520px) { .stats b { font-size: 1.05rem; } .big-btn { min-height: 46px; } .pbtn { width: 54px; height: 54px; } .pbtn.sm { width: 44px; height: 44px; } .vbar { height: 56px; } .joy { width: 100px; height: 100px; } .speed .spd b { font-size: 1.7rem; } }

/* telefono: i comandi a schermo occupano gli angoli, il resto si sposta */
body.touch .levers { left: calc(max(12px, env(safe-area-inset-left)) + 84px); }
body.touch .hint-bar { bottom: max(122px, calc(env(safe-area-inset-bottom) + 118px)); max-width: 70vw; font-size: .9rem; }
@media (max-height: 520px) {
  .toast { top: 56%; font-size: 1rem; padding: 6px 14px; }
  .next { min-width: 150px; }
  .hud { gap: 4px; }
  .panel { padding: 3px 9px; }
}
