:root { --bg: #0d1118; --fg: #eef0f2; --dim: #9aa3ad; --accent: #f0c428; --panel: rgba(13, 17, 24, .72); --line: rgba(255, 255, 255, .14); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
#stage { position: fixed; inset: 0; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #000; outline: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
kbd { border: 1px solid #5b6470; border-bottom-width: 2px; border-radius: 4px; padding: 0 6px; font: 12px ui-monospace, monospace; color: var(--fg); }
a { color: var(--dim); }

/* overlays */
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center;
  background: rgba(8, 10, 14, .9); text-align: center; padding: 18px; z-index: 20; overflow-y: auto; }
.overlay h1 { margin: 0; font-size: clamp(30px, 6vw, 54px); letter-spacing: .06em; font-weight: 900; font-style: italic; }
.overlay h1 span, .overlay h2 { color: var(--accent); }
.overlay h2 { margin: 0; font-size: 34px; letter-spacing: .08em; font-style: italic; }
.overlay p { margin: 0; color: var(--dim); max-width: 660px; }
.overlay .tag { font-size: 14px; }
.overlay .keys { font-size: 13px; line-height: 2; }
.overlay .credit { font-size: 12px; }
.go { background: var(--accent); color: #17130a; font-weight: 800; border-radius: 999px; padding: 12px 34px; font-size: 17px; cursor: pointer; border: 0; }
.go:active { transform: scale(.97); }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 10px 24px; cursor: pointer; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
#results { background: rgba(8, 10, 14, .72); }
#results table { border-collapse: collapse; min-width: min(460px, 86vw); font-variant-numeric: tabular-nums; }
#results td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; }
#results td.num { text-align: right; }
#results tr.me td { color: var(--accent); font-weight: 700; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; width: min(680px, 94vw);
  display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.field.two { flex-direction: row; gap: 22px; flex-wrap: wrap; }
.field.two > div { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.label { font-size: 11px; letter-spacing: .14em; color: var(--dim); font-weight: 700; }
.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choice { background: rgba(255, 255, 255, .06); border: 2px solid transparent; border-radius: 10px; padding: 8px 12px; cursor: pointer; text-align: left; min-width: 44px; }
.choice.sel { border-color: var(--accent); background: rgba(240, 196, 40, .12); }
.choice b { display: block; font-size: 15px; }
.choice small { color: var(--dim); font-size: 12px; }
.choice .bars { display: grid; grid-template-columns: auto 70px; gap: 2px 8px; margin-top: 4px; font-size: 10px; color: var(--dim); align-items: center; }
.choice .bars i { display: block; height: 5px; background: #2a3340; border-radius: 3px; overflow: hidden; }
.choice .bars i u { display: block; height: 100%; background: var(--accent); }
.swatch { width: 34px; height: 34px; border-radius: 50%; padding: 0; min-width: 0; border: 3px solid rgba(255, 255, 255, .18); }
.swatch.sel { border-color: var(--accent); box-shadow: 0 0 0 2px #000 inset; }

#bar { width: min(420px, 70vw); height: 8px; background: #232a35; border-radius: 4px; overflow: hidden; }
#bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
#status { color: var(--dim); font-size: 13px; min-height: 1.4em; }
#err { color: #ff8d7a; white-space: pre-wrap; max-width: 760px; font: 12px ui-monospace, monospace; user-select: text; -webkit-user-select: text; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; font-variant-numeric: tabular-nums;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.hud-box { position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; line-height: 1.15; }
.hud-box b { font-size: 34px; font-weight: 900; font-style: italic; }
.hud-box small { color: var(--dim); font-size: 16px; margin-left: 2px; }
.hud-box .label { display: inline-block; min-width: 42px; }
#hud-pos { left: 12px; top: 12px; }
#hud-pos .label, #hud-lap .label { display: block; }
#hud-lap { left: 112px; top: 12px; }
#hud-time { right: 12px; top: 12px; text-align: right; font-size: 15px; min-width: 168px; }
#hud-time b { font-size: 22px; }
#hud-speed { position: absolute; right: 14px; bottom: 14px; text-align: right; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 14px 6px; min-width: 190px; }
#hud-speed b { font-size: 46px; font-weight: 900; font-style: italic; line-height: 1; }
#hud-speed small { color: var(--dim); margin: 0 10px 0 4px; }
#gear { display: inline-block; min-width: 30px; text-align: center; font-size: 26px; font-weight: 900; color: var(--accent); }
#rev { height: 8px; background: #232a35; border-radius: 4px; overflow: hidden; margin-bottom: 6px; }
#rev-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #4bc26a 0 60%, #f0c428 60% 85%, #ef4a3a 85%); background-size: 190px 100%; }
#banner { position: absolute; left: 0; right: 0; top: 26%; text-align: center; font-size: clamp(60px, 16vw, 150px); font-weight: 900; font-style: italic;
  color: var(--accent); text-shadow: 0 4px 0 #000, 0 0 28px rgba(0, 0, 0, .7); letter-spacing: .04em; }
#notice { position: absolute; left: 50%; top: 14%; transform: translateX(-50%); background: #c8281e; color: #fff; font-weight: 900; letter-spacing: .12em;
  padding: 6px 18px; border-radius: 8px; font-size: 20px; }

/* top bar and touch */
#topbar { position: absolute; left: 50%; top: max(8px, env(safe-area-inset-top)); transform: translateX(-50%); display: flex; gap: 8px; z-index: 12; }
#topbar button { width: 40px; height: 40px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); cursor: pointer; font-size: 18px; opacity: .8; }
#topbar button.off { opacity: .35; }
#touch { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.tbtn { position: absolute; pointer-events: auto; background: rgba(13, 17, 24, .42); border: 2px solid rgba(255, 255, 255, .28); border-radius: 18px;
  font-weight: 800; font-size: 20px; width: 86px; height: 86px; touch-action: none; }
.tbtn.on { background: rgba(240, 196, 40, .45); }
.tbtn.small { width: 56px; height: 56px; font-size: 15px; border-radius: 50%; }
#t-left { left: max(14px, env(safe-area-inset-left)); bottom: 86px; }
#t-right { left: calc(max(14px, env(safe-area-inset-left)) + 100px); bottom: 86px; }
#t-gas { right: max(14px, env(safe-area-inset-right)); bottom: 96px; height: 120px; }
#t-brake { right: calc(max(14px, env(safe-area-inset-right)) + 100px); bottom: 96px; }
#t-reset { left: max(14px, env(safe-area-inset-left)); bottom: 190px; }
#t-cam { left: calc(max(14px, env(safe-area-inset-left)) + 70px); bottom: 190px; }
@media (max-height: 520px) {
  .hud-box b { font-size: 24px; }
  #hud-speed b { font-size: 34px; }
  #hud-speed { bottom: 8px; min-width: 150px; }
  .tbtn { width: 74px; height: 74px; }
  #t-left, #t-right { bottom: 20px; }
  #t-right { left: calc(max(14px, env(safe-area-inset-left)) + 88px); }
  #t-gas { bottom: 70px; height: 96px; }
  #t-brake { bottom: 70px; right: calc(max(14px, env(safe-area-inset-right)) + 88px); }
  #t-reset, #t-cam { bottom: 108px; }
  .overlay { justify-content: flex-start; gap: 8px; }
  .overlay .keys { display: none; }
}
/* touch screens: the speedometer moves to the bottom centre, clear of the pedals */
.touch-on #hud-speed { right: auto; left: 50%; transform: translateX(-50%); bottom: 8px; min-width: 150px; padding: 5px 12px 4px; }
.touch-on #hud-speed b { font-size: 32px; }
