* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1b1d20; overflow: hidden; overscroll-behavior: none; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #f2f2f2; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
#app { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; touch-action: none; }
i { font-style: normal; }

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
:root { --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); --sb: env(safe-area-inset-bottom, 0px); }

/* top bar */
#counter { position: absolute; top: 6px; left: calc(8px + var(--sl)); display: flex; gap: 6px; font-size: 13px; pointer-events: none; }
#counter span { background: rgba(20, 22, 25, 0.78); border-radius: 6px; padding: 3px 7px; }
#counter b { font-size: 16px; }
.c-minor b { color: #f5d76e; } .c-serious b { color: #ff9f43; } .c-dangerous b { color: #ff5c5c; }
#toasts { position: absolute; top: 36px; left: calc(8px + var(--sl)); display: flex; flex-direction: column; gap: 4px; pointer-events: none; max-width: 34vw; }
.toast { background: rgba(20, 22, 25, 0.85); border-left: 4px solid #f5d76e; padding: 4px 8px; border-radius: 4px; font-size: 13px; animation: fade 3.4s forwards; }
.toast.serious { border-color: #ff9f43; } .toast.dangerous { border-color: #ff5c5c; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

.mirror { position: absolute; background: rgba(40, 46, 52, 0.55); border: 3px solid #15171a; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 11px; color: rgba(255,255,255,0.6); }
#m-mirror { top: 4px; left: 50%; transform: translateX(-50%); width: 30vw; max-width: 300px; height: 9vh; min-height: 34px; max-height: 70px; }
.wing { top: 16vh; width: 13vw; max-width: 120px; height: 13vh; max-height: 90px; }
.wing.left { left: calc(4px + var(--sl)); } .wing.right { right: calc(4px + var(--sr)); }
.mirror.active span { display: none; }
.look { position: absolute; top: 31vh; height: 15vh; width: 9vw; max-width: 70px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: rgba(255,255,255,0.75); background: rgba(20, 22, 25, 0.25); border: 1px dashed rgba(255,255,255,0.35); border-radius: 8px; }
.look.left { left: calc(4px + var(--sl)); } .look.right { right: calc(4px + var(--sr)); }
.look.active, .mirror.flash { border-color: #f5d76e; }

#speedbox { position: absolute; top: 6px; right: calc(8px + var(--sr)); display: flex; align-items: center; gap: 6px; }
#speed { background: rgba(20, 22, 25, 0.78); padding: 3px 8px; border-radius: 6px; font-size: 13px; pointer-events: none; }
#speed b { font-size: 20px; }
#limit { width: 34px; height: 34px; border-radius: 50%; background: #fff; border: 5px solid #d0161a; color: #111; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 14px; pointer-events: none; }
#limit.nsl { border: 2px solid #111; background: linear-gradient(135deg, #fff 40%, #111 40%, #111 56%, #fff 56%); }
#end-btn { background: rgba(20, 22, 25, 0.78); border: 1px solid #555; border-radius: 6px; padding: 6px 9px; font-size: 12px; }

#examiner { position: absolute; top: calc(min(70px, max(34px, 9vh)) + 10px); left: 50%; transform: translateX(-50%); width: 56vw; text-align: center; pointer-events: none; }
#banner, #direction { display: inline-block; background: rgba(20, 22, 25, 0.85); border-radius: 8px; padding: 5px 12px; margin: 2px 0; font-size: 15px; }
#banner:empty, #direction:empty { display: none; }
#direction { font-size: 14px; color: #cfe6ff; }
#flash { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); font-size: 64px; font-weight: 800; color: #ff3b30; text-shadow: 0 2px 12px #000; pointer-events: none; }
#minimap { position: absolute; bottom: calc(52px + var(--sb)); left: 50%; transform: translateX(-50%); width: 160px; height: 120px; border-radius: 10px; border: 2px solid #15171a; pointer-events: none; }

#showme { position: absolute; top: 40%; left: 50%; transform: translateX(-50%); background: rgba(20, 60, 110, 0.92); padding: 8px 14px; border-radius: 8px; font-size: 15px; max-width: 60vw; text-align: center; pointer-events: none; }

/* controls */
#controls { position: absolute; left: 0; right: 0; bottom: 0; height: 0; }
#wheel-wrap { position: absolute; left: calc(14px + var(--sl)); bottom: calc(8px + var(--sb)); width: min(44vh, 210px); height: min(44vh, 210px); }
#wheel { position: absolute; inset: 0; border-radius: 50%; touch-action: none; }
#wheel svg { width: 100%; height: 100%; display: block; will-change: transform; }
.ind { position: absolute; top: -12px; width: 52px; height: 44px; border-radius: 10px; background: rgba(20, 22, 25, 0.8); border: 1px solid #555; padding: 6px; }
.ind svg { width: 100%; height: 100%; fill: #3c6b3c; }
.ind.on svg { fill: #3fe05a; }
.ind.on.blink svg { fill: #1c3a1c; }
#ind-left { left: -6px; } #ind-right { right: -6px; }

#aux { position: absolute; bottom: calc(6px + var(--sb)); left: 50%; transform: translateX(-50%); display: flex; gap: 4px; }
#aux button { background: rgba(20, 22, 25, 0.8); border: 1px solid #555; border-radius: 6px; padding: 7px 7px; font-size: 11px; }
#aux button.on { border-color: #6fb3ff; color: #cfe6ff; }

#right-cluster { position: absolute; right: calc(10px + var(--sr)); bottom: calc(8px + var(--sb)); display: flex; align-items: flex-end; gap: 10px; }
#gearbox { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
#handbrake { background: rgba(20, 22, 25, 0.85); border: 2px solid #555; border-radius: 8px; padding: 6px 4px; font-size: 11px; }
#handbrake.on { border-color: #ff5c5c; color: #ffb3b3; }
#gears { display: flex; flex-direction: column; background: rgba(20, 22, 25, 0.85); border-radius: 8px; padding: 3px; gap: 3px; }
#gears button { width: 54px; height: min(8.5vh, 40px); border: 0; border-radius: 6px; background: transparent; font-weight: 700; font-size: 17px; color: #8a9096; }
#gears button.sel { background: #f2f2f2; color: #111; }
.pedal { position: relative; border-radius: 10px; background: #2a2d31; border: 2px solid #4a4e53; overflow: hidden; touch-action: none; }
.pedal .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; }
.pedal span { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-size: 10px; overflow-wrap: anywhere; padding: 0 2px; color: #c0c4c8; pointer-events: none; }
#pedal-brake { width: min(20vh, 88px); height: min(34vh, 150px); }
#pedal-brake .fill { background: rgba(255, 80, 80, 0.55); }
#pedal-accel { width: min(17vh, 76px); height: min(46vh, 196px); }
#pedal-accel .fill { background: rgba(80, 220, 120, 0.55); }

/* overlays */
#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#overlay .panel { pointer-events: auto; background: rgba(22, 24, 28, 0.94); border-radius: 14px; padding: 18px 22px; max-width: min(640px, 92vw); max-height: 92vh; overflow-y: auto; text-align: center; touch-action: pan-y; }
.panel h1 { margin: 0 0 8px; font-size: 28px; }
.panel h2 { margin: 0 0 8px; font-size: 22px; }
.panel p { margin: 6px 0 12px; }
.panel .help { color: #b8bcc2; font-size: 14px; }
.big { background: #f2f2f2; color: #111; border: 0; border-radius: 10px; padding: 12px 22px; font-size: 17px; font-weight: 600; margin: 4px; }
.row { display: flex; justify-content: center; gap: 10px; }
#history { margin-top: 12px; font-size: 13px; color: #b8bcc2; }
#history div { margin: 2px 0; }
#plate-view { display: flex; justify-content: center; margin: 8px 0 12px; }
#plate { width: 150px; height: 35px; filter: blur(0.6px); image-rendering: auto; }
#plate-input { font-size: 22px; padding: 8px 10px; width: 220px; text-align: center; text-transform: uppercase; border-radius: 8px; border: 1px solid #555; background: #111; color: #fff; user-select: text; -webkit-user-select: text; }
#eyesight-form { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#tellme-a { display: flex; flex-direction: column; gap: 8px; }
#tellme-a button { background: #2a2d31; border: 1px solid #555; border-radius: 10px; padding: 10px 12px; font-size: 15px; text-align: left; }
#score-totals { display: flex; justify-content: center; gap: 14px; font-size: 18px; margin-bottom: 6px; }
#score-totals b { font-size: 26px; display: block; }
#score-rule { font-size: 13px; color: #b8bcc2; margin-bottom: 10px; }
#score-rule b { color: #f2f2f2; }
#score-table table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 10px; }
#score-table td, #score-table th { padding: 4px 6px; border-bottom: 1px solid #333; text-align: left; }
#score-table td.n { text-align: center; width: 48px; }
#score-table th.n { text-align: center; }

#rotate { display: none; position: absolute; inset: 0; background: #1b1d20; align-items: center; justify-content: center; font-size: 22px; text-align: center; padding: 20px; z-index: 10; }
@media (orientation: portrait) and (max-width: 900px) { #rotate { display: flex; } }
