/* RaceSim: full-screen 3D view with a race HUD. Uses the tokens from styles.css. */
body.racesim { padding: 0; margin: 0; overflow: hidden; background: #0D0F12; height: 100vh; height: 100dvh; touch-action: none; }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }

/* HUD: white on dark glass, tabular numbers, like a timing screen */
.hud { position: fixed; inset: 0; pointer-events: none; color: #F2F4F7; font-variant-numeric: tabular-nums; }
.hud[hidden] { display: none; }
.hud-box { position: absolute; background: rgba(13, 15, 18, 0.72); border-radius: 12px; padding: 10px 14px; backdrop-filter: blur(6px); }
.hud-timing { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); min-width: 180px; }
.hud-best { top: max(12px, env(safe-area-inset-top)); right: max(60px, calc(env(safe-area-inset-right) + 60px)); text-align: right; font-size: 0.95rem; }
.hud-label { color: #8A95A3; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; }
.hud-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.hud-flag { background: #B3261E; color: #fff; font-size: 0.7rem; font-weight: 700; padding: 2px 6px; border-radius: 4px; letter-spacing: 0.06em; }
.hud-flag[hidden] { display: none; }
.hud-time { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.hud-delta { font-weight: 700; min-height: 1.3em; }
.hud-delta.faster { color: #4ADE80; }
.hud-delta.slower { color: #F87171; }
.hud-sectors { display: flex; gap: 6px; margin-top: 6px; }
.hud-sectors span { flex: 1; text-align: center; font-size: 0.75rem; padding: 3px 4px; border-radius: 4px; background: rgba(255,255,255,0.1); color: #AEB8C4; min-width: 48px; }
.hud-sectors span.pb { background: #16A34A; color: #fff; }
.hud-sectors span.slow { background: #CA8A04; color: #fff; }
.hud-robot { margin-top: 6px; color: #FFA25C; font-weight: 700; font-size: 0.8rem; letter-spacing: 0.06em; }
.hud-robot[hidden] { display: none; }

.hud-dash { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(13, 15, 18, 0.78); border-radius: 14px; padding: 10px 16px 12px; min-width: 250px; }
.revs { display: grid; grid-template-columns: repeat(15, 1fr); gap: 3px; margin-bottom: 8px; }
.revs i { height: 8px; border-radius: 2px; background: rgba(255,255,255,0.12); }
.revs i.on.g { background: #22C55E; } .revs i.on.r { background: #EF4444; } .revs i.on.b { background: #60A5FA; }
.revs.flash i.on { animation: flash 0.12s steps(2) infinite; }
@keyframes flash { 50% { opacity: 0.2; } }
.dash-main { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.dash-speed b { font-size: 2.6rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.dash-speed span { color: #8A95A3; font-size: 0.8rem; margin-left: 4px; }
.dash-gear { font-size: 2.4rem; font-weight: 700; color: #FFA25C; width: 1.2em; text-align: center; }
.drs { font-weight: 700; font-size: 0.85rem; padding: 4px 8px; border-radius: 6px; color: #5b6570; border: 2px solid #3a414a; letter-spacing: 0.05em; }
.drs.available { color: #4ADE80; border-color: #22C55E; }
.drs.open { background: #22C55E; color: #0D0F12; border-color: #22C55E; }
.dash-tyres { display: flex; gap: 8px; margin-top: 8px; font-size: 0.78rem; }
.tyre { flex: 1; text-align: center; padding: 2px 6px; border-radius: 4px; background: #2457A6; }
.tyre.ok { background: #16A34A; } .tyre.hot { background: #DC2626; } .tyre.cold { background: #2457A6; }

.minimap { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); width: 170px; height: 130px; background: rgba(13, 15, 18, 0.6); border-radius: 12px; }
.hud-msg { position: absolute; top: 28%; left: 50%; transform: translateX(-50%); font-size: 1.4rem; font-weight: 700; text-align: center; text-shadow: 0 2px 8px rgba(0,0,0,0.6); transition: opacity 0.3s; max-width: 90vw; }
.hud-msg.good { color: #4ADE80; } .hud-msg.bad { color: #F87171; }
.hud-pause { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); width: 40px; height: 40px; border-radius: 10px; border: 0; background: rgba(13, 15, 18, 0.72); color: #fff; font-weight: 700; pointer-events: auto; }

/* Touch controls */
.touch { position: fixed; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 0 max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); pointer-events: none; }
.touch[hidden] { display: none; }
.touch button { pointer-events: auto; border: 0; border-radius: 16px; background: rgba(255,255,255,0.14); color: #fff; font-weight: 700; font-size: 1.1rem; min-width: 76px; min-height: 76px; -webkit-user-select: none; user-select: none; touch-action: none; }
.touch button.held { background: rgba(255,255,255,0.35); }
.touch-left, .touch-right { display: flex; gap: 10px; align-items: flex-end; }
.touch .touch-throttle { background: rgba(34, 197, 94, 0.35); min-height: 120px; }
.touch .touch-brake { background: rgba(239, 68, 68, 0.35); min-height: 96px; }
.touch .touch-drs { min-width: 56px; min-height: 48px; font-size: 0.85rem; }
body.has-touch .minimap { bottom: auto; top: 130px; width: 120px; height: 90px; }
body.has-touch .hud-dash { bottom: auto; top: max(12px, env(safe-area-inset-top)); padding: 6px 12px 8px; min-width: 200px; }
body.has-touch .hud-best { display: none; }
body.has-touch .dash-speed b { font-size: 1.8rem; }
body.has-touch .dash-gear { font-size: 1.8rem; }

/* Menu */
.menu { position: fixed; inset: 0; overflow-y: auto; background: rgba(13, 15, 18, 0.55); padding: 16px; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.menu[hidden] { display: none; }
.menu-card { max-width: 720px; margin: 0 auto; background: var(--paper); border-radius: 18px; padding: 0 18px 22px; color: var(--ink); }
.menu-card .top { margin: 0 -18px 18px; border-radius: 18px 18px 0 0; }
.menu-card h1 { font-size: 2rem; letter-spacing: -0.02em; }
.menu-card h2 { font-size: 1.15rem; }
.setup-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.setup-chips span { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 0.85rem; }
.setup-chips b { color: var(--orange); }
.menu-card .readout a { color: var(--blue); font-weight: 500; }
.assists { border: 1px solid var(--line); border-radius: 12px; margin: 16px 0; padding: 10px 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 16px; background: var(--surface); }
.assists legend { font-weight: 600; padding: 0 6px; }
.assists label { display: flex; align-items: baseline; gap: 8px; min-height: 36px; flex-wrap: wrap; }
.assists input { width: 18px; height: 18px; accent-color: var(--orange); }
.assists small { color: var(--ink-3); flex-basis: 100%; margin-left: 26px; margin-top: -6px; }
.menu-card .actions a.tool { text-decoration: none; display: inline-flex; align-items: center; }
.menu-card .actions[hidden] { display: none; }
.controls-help { margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 12px; }
.controls-help summary { cursor: pointer; font-weight: 600; min-height: 40px; display: flex; align-items: center; }
.controls-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px 24px; font-size: 0.9rem; color: var(--ink-2); align-items: start; }
.controls-col h3 { font-size: 0.88rem; color: var(--ink); margin-bottom: 6px; }
.controls-col dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 10px; margin: 0; align-items: baseline; }
.controls-col dt { font-weight: 600; color: var(--ink); white-space: nowrap; }
.controls-col dd { margin: 0; }
.controls-note { color: var(--ink-3); font-size: 0.85rem; margin-top: 10px; }
.aids-quick { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.aids-quick .tool { min-height: 38px; padding: 6px 12px; font-size: 0.88rem; }
.controls-help .limits { color: var(--ink-2); font-size: 0.9rem; padding-left: 18px; margin: 4px 0 0; display: flex; flex-direction: column; gap: 6px; }
.menu-lb { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.lb .aids { color: var(--ink-3); font-size: 0.8rem; }

/* Paint your car */
.paint { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 14px; margin-top: 16px; }
.paint-head h2 { font-size: 1.15rem; }
.paint-body { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 14px; align-items: start; margin-top: 12px; }
@media (max-width: 620px) { .paint-body { grid-template-columns: 1fr; } }
#paint-preview { width: 100%; aspect-ratio: 16 / 10; border-radius: 10px; background: var(--paper); display: block; }
.paint-controls { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.paint-row { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; align-items: center; }
@media (max-width: 480px) { .paint-row { grid-template-columns: 1fr; gap: 4px; } }
.paint-row > span { color: var(--ink-2); font-size: 0.9rem; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(16,22,31,0.15); padding: 0; }
.swatch[aria-checked="true"] { border-color: var(--ink); transform: scale(1.12); box-shadow: inset 0 0 0 2px #fff, 0 0 0 1px var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; min-height: 36px; font-size: 0.88rem; color: var(--ink-2); }
.chip[aria-checked="true"], .chip.on { background: var(--orange-soft); border-color: var(--orange); color: var(--ink); font-weight: 600; }
.paint-inputs { display: flex; gap: 8px; flex-wrap: wrap; }
.paint-inputs input { font: inherit; width: 5.5em; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; min-height: 40px; text-transform: uppercase; }
.paint-inputs #in-number { width: 3.5em; text-align: center; }
.paint-inputs .tool { min-height: 40px; padding: 6px 12px; }
.lb .car-chip { display: inline-flex; align-items: center; gap: 4px; }
.lb .car-chip i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgba(16,22,31,0.2); }
.lb .car-chip b { font-size: 0.8rem; color: var(--ink-3); font-weight: 600; min-width: 1.2em; }

/* Driving classes */
.assists-note { grid-column: 1 / -1; margin: 0 0 4px; }
.class-line { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.class-line b { font-size: 1rem; }
.class-badge { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 999px; white-space: nowrap; background: var(--grid); color: var(--ink-2); }
.class-badge[data-class="pro"] { background: var(--blue-soft); color: var(--blue); }
.class-badge[data-class="unaided"] { background: var(--orange); color: #fff; }
.lb-filter { margin-bottom: 10px; }
.lb-filter .chip { min-height: 32px; padding: 4px 10px; font-size: 0.82rem; }
#lb-me { line-height: 1.5; }

/* On screen: the racing line, and how sharp the steering is */
.view-options { grid-template-columns: 1fr; }
.view-options .slider { margin-top: 10px; }
.view-options .slider label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-weight: 600; min-height: 0; }
.view-options .slider output { font-weight: 700; color: var(--orange); font-variant-numeric: tabular-nums; }
.view-options .slider input[type="range"] { width: 100%; accent-color: var(--orange); margin: 4px 0 2px; height: 28px; }
.view-options .slider-hint { color: var(--ink-3); font-size: 0.85rem; max-width: 62ch; }

/* Changing the keys */
.keys-col { min-width: 0; }
.keybinds { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 10px; }
.keybind { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.keybind-what { color: var(--ink-2); font-size: 0.88rem; min-width: 0; }
.keybind-keys { display: flex; gap: 4px; flex: 0 0 auto; }
.keycap {
  min-width: 42px; min-height: 30px; padding: 3px 8px; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 7px; background: var(--surface); color: var(--ink); font-size: 0.85rem; font-weight: 600;
}
.keycap:hover { border-color: var(--orange); }
.keycap.empty { color: var(--ink-3); font-weight: 400; }
.keycap.listening { border-color: var(--orange); background: var(--orange-soft); color: var(--orange); font-weight: 600; min-width: 92px; }
#keys-note { min-height: 1.2em; font-size: 0.85rem; }
