:root { --red: #d40000; --ink: #0d0d0f; --w: #f4f4f2; --dim: rgba(244,244,242,.55); }
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--ink); color: var(--w);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* start screen */
#start { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 9vh; gap: 28px; transition: opacity .8s; }
#start.fade { opacity: 0; pointer-events: none; }
.brand { position: absolute; top: 34px; left: 40px; display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 28px; letter-spacing: .08em; font-style: italic; }
.brand .mark { width: 10px; height: 28px; background: var(--red); transform: skewX(-14deg); }
#go { position: relative; width: 148px; height: 148px; border-radius: 50%; border: 0; background: #151517; cursor: pointer; color: var(--w);
  display: grid; place-items: center; transition: transform .15s; outline: none; }
#go .ring { position: absolute; inset: 9px; border-radius: 50%; border: 3px solid var(--red); }
#go .label { display: flex; flex-direction: column; align-items: center; line-height: 1.05; font-size: 15px; letter-spacing: .22em; }
#go .label b { font-weight: 800; } #go .label i { font-style: normal; font-weight: 500; color: var(--dim); }
#go .load { position: absolute; bottom: -34px; font-size: 12px; letter-spacing: .2em; color: var(--dim); font-variant-numeric: tabular-nums; }
#go:not(:disabled):hover { transform: scale(1.04); }
#go:not(:disabled):active { transform: scale(.97); }
#go:disabled { cursor: default; } #go:disabled .ring { border-color: #3a3a3e; }
#go:not(:disabled) .ring { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(212,0,0,.0); } 50% { box-shadow: 0 0 0 10px rgba(212,0,0,.18); } }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#cluster { position: absolute; right: 36px; bottom: 30px; width: 300px; }
#rpmbar { display: grid; grid-template-columns: repeat(34, 1fr); gap: 3px; height: 14px; margin-bottom: 10px; transform: skewX(-14deg); }
#rpmbar i { background: rgba(255,255,255,.14); }
#rpmbar i.on { background: var(--w); } #rpmbar i.on.y { background: #ffc400; } #rpmbar i.on.r { background: var(--red); }
#rpmbar.lim i.on { background: var(--red); }
.row { display: flex; align-items: flex-end; justify-content: space-between; }
#gear { width: 64px; height: 64px; background: var(--w); color: var(--ink); font-weight: 900; font-size: 42px; display: grid; place-items: center; font-style: italic; transform: skewX(-8deg); }
#gear.p { background: transparent; color: var(--w); box-shadow: inset 0 0 0 3px var(--w); }
.spd { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
#speed { font-size: 86px; font-weight: 800; font-style: italic; line-height: .85; letter-spacing: -.03em; }
.spd small { font-size: 14px; font-weight: 600; color: var(--dim); letter-spacing: .1em; }
#nitro { height: 4px; margin-top: 12px; background: rgba(255,255,255,.14); transform: skewX(-14deg); }
#nitro i { display: block; height: 100%; width: 100%; background: #20b8ff; transform-origin: left; }
#lap { position: absolute; top: 24px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: baseline; font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
#laptime { font-size: 22px; font-weight: 700; } #best { font-size: 14px; color: var(--dim); font-weight: 600; }
#hint { position: absolute; left: 36px; bottom: 34px; display: flex; gap: 18px; font-size: 12px; color: var(--dim); letter-spacing: .06em; transition: opacity 1.2s; align-items: center; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
#hint span { display: flex; gap: 4px; align-items: center; }
kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 3px; background: rgba(13,13,15,.75); color: var(--w); font: 600 11px/1 inherit; }
#hint.out { opacity: 0; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }

/* touch */
#touch { position: fixed; inset: 0; pointer-events: none; }
#touch .t { pointer-events: auto; border: 0; color: var(--w); background: rgba(13,13,15,.42); font-weight: 700; letter-spacing: .08em; touch-action: none; }
#touch .t.on { background: rgba(244,244,242,.85); color: var(--ink); }
#touch .left { position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: 22px; display: flex; gap: 12px; }
#touch .big { width: 88px; height: 88px; border-radius: 50%; font-size: 26px; }
#touch .right { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: 22px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
#touch .small { display: flex; gap: 8px; }
#touch .s { height: 44px; min-width: 56px; padding: 0 12px; border-radius: 12px; font-size: 11px; }
#touch .pedals { display: flex; gap: 10px; align-items: flex-end; }
#touch .mid { width: 58px; height: 58px; border-radius: 50%; font-size: 11px; }
#touch .pedal { width: 64px; height: 104px; border-radius: 10px; }
#touch .brake { height: 78px; background: rgba(13,13,15,.55); box-shadow: inset 0 -4px 0 #888; }
#touch .gas { box-shadow: inset 0 -4px 0 var(--red); }
body.touch #cluster { right: 50%; transform: translateX(50%) scale(.72); transform-origin: bottom center; bottom: 6px; }
body.touch #hint { display: none; }
@media (max-width: 700px) { .brand { left: 22px; top: 22px; } }

/* gear button */
#gearBtn { position: fixed; z-index: 30; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; color: var(--w); background: rgba(13,13,15,.5); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); cursor: pointer; touch-action: manipulation; transition: background .12s, transform .08s; }
#gearBtn:hover { background: rgba(13,13,15,.7); }
#gearBtn:active { transform: scale(.94); background: rgba(244,244,242,.85); color: var(--ink); }
#gearBtn:focus-visible, #settings button:focus-visible, #settings input:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
body.settings-open #gearBtn { visibility: hidden; }

/* settings */
#settings { position: fixed; inset: 0; z-index: 40; }
#settings .scrim { position: absolute; inset: 0; background: rgba(0,0,0,.28); }
#settings .sheet { position: absolute; top: 12px; right: 12px; bottom: 12px; width: min(400px, calc(100vw - 24px)); display: flex; flex-direction: column;
  background: rgba(24,24,27,.86); -webkit-backdrop-filter: blur(28px) saturate(1.4); backdrop-filter: blur(28px) saturate(1.4);
  border: 1px solid rgba(255,255,255,.09); border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.45); overflow: hidden; animation: sheetIn .22s cubic-bezier(.2,.8,.2,1); }
@keyframes sheetIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
#settings header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 12px 20px; border-bottom: 1px solid rgba(255,255,255,.07); }
#settings h2 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
#settings .body { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 4px 20px 8px; }
#settings section { padding: 14px 0 6px; border-bottom: 1px solid rgba(255,255,255,.06); }
#settings section:last-child { border-bottom: 0; }
#settings h3 { font-size: 13px; font-weight: 600; color: var(--dim); margin-bottom: 4px; }
#settings .row { padding: 6px 0; }
#settings .top { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
#settings output { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 14px; }
#settings .seg-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; flex-wrap: wrap; }
#settings .lab { font-size: 15px; }
#settings .seg { display: flex; gap: 2px; padding: 3px; background: rgba(255,255,255,.08); border-radius: 11px; }
#settings .seg button { min-width: 44px; height: 44px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; color: var(--dim); font: 600 13px/1 inherit; font-family: inherit; cursor: pointer; touch-action: manipulation; transition: background .12s, color .12s; }
#settings .seg button.on { background: var(--w); color: var(--ink); }
#settings .btn { height: 44px; padding: 0 18px; border: 0; border-radius: 10px; background: rgba(255,255,255,.1); color: var(--w); font: 600 15px/1 inherit; font-family: inherit; cursor: pointer; touch-action: manipulation; transition: background .12s, transform .08s; }
#settings .btn:hover { background: rgba(255,255,255,.16); }
#settings .btn:active { transform: scale(.97); }
#settings .btn.primary { background: var(--w); color: var(--ink); }
#settings .btn.primary:hover { background: #fff; }
#settings footer { padding: 12px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(255,255,255,.07); }
#settings footer .btn { width: 100%; }
#settings input[type=range] { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 44px; margin: 0; background: transparent; touch-action: pan-y; cursor: pointer; --p: 50%; }
#settings input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--w) var(--p), rgba(255,255,255,.2) var(--p)); }
#settings input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -10px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
#settings input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255,255,255,.2); }
#settings input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--w); }
#settings input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
@media (max-width: 700px) {
  #settings .scrim { background: rgba(0,0,0,.4); }
  #settings .sheet { top: max(10px, env(safe-area-inset-top)); left: max(0px, env(safe-area-inset-left)); right: max(0px, env(safe-area-inset-right)); bottom: 0; width: auto; border-radius: 18px 18px 0 0; animation: sheetUp .26s cubic-bezier(.2,.8,.2,1); }
  @keyframes sheetUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) { #settings .sheet { animation: none; } }
