:root {
  --accent: #ff6a1a;
  --accent-2: #ffb300;
  --ink: #f2f4f8;
  --muted: #9aa3b5;
  --glass: rgba(12, 16, 28, 0.55);
  --glass-border: rgba(255, 255, 255, 0.09);
  --good: #3ddc84;
  --bad: #ff3b3b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05070d;
  color: var(--ink);
  font-family: 'Rajdhani', system-ui, sans-serif;
  user-select: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

.label {
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 600;
}

.panel {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 14px;
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }

#hud-score { position: absolute; top: 20px; left: 20px; padding: 12px 18px; min-width: 170px; }
#score { font-size: 42px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
#combo { font-size: 16px; font-weight: 700; color: var(--accent-2); height: 18px; margin-top: 4px; }

#hud-center-top { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); text-align: center; }
#timer { font-size: 38px; font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: 0 2px 14px rgba(0,0,0,.6); }
#timer.low { color: var(--bad); }

#standings { position: absolute; top: 20px; right: 20px; padding: 10px 12px; width: 236px; }
.st-row { display: grid; grid-template-columns: 12px 1fr 54px 52px; align-items: center; gap: 8px; height: 24px; font-size: 15px; font-weight: 600; }
.st-row.dead { opacity: 0.38; text-decoration: line-through; }
.st-row.me { color: var(--accent-2); }
.st-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.st-bar { height: 5px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; }
.st-bar > div { height: 100%; border-radius: 3px; transition: width .2s; }
.st-score { text-align: right; font-variant-numeric: tabular-nums; }

#killfeed { position: absolute; top: 90px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.kf { background: rgba(0,0,0,.55); padding: 4px 12px; border-radius: 8px; font-size: 16px; font-weight: 600; animation: kfIn .25s ease-out; }
.kf b { font-weight: 700; }
.kf .x { color: var(--bad); margin: 0 6px; }
@keyframes kfIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

#hud-damage { position: absolute; left: 20px; bottom: 20px; padding: 12px 16px; display: flex; align-items: center; gap: 14px; }
#damage-svg { width: 46px; height: 80px; }
#damage-svg .zone { fill: var(--good); transition: fill .25s; }
#damage-svg .cabin { fill: rgba(255,255,255,.16); }
.dmg-info { width: 120px; }
#health-num { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bar { height: 7px; background: rgba(255,255,255,.12); border-radius: 4px; overflow: hidden; margin-top: 4px; }
#health-fill { height: 100%; width: 100%; background: var(--good); transition: width .2s, background .2s; }

#hud-speed { position: absolute; right: 28px; bottom: 22px; text-align: right; }
#speed { font-size: 72px; font-weight: 700; line-height: .9; font-variant-numeric: tabular-nums; text-shadow: 0 2px 18px rgba(0,0,0,.6); }

#center-msg { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
#center-main { font-size: 110px; font-weight: 700; letter-spacing: .04em; line-height: 1; text-shadow: 0 6px 40px rgba(0,0,0,.6); }
#center-sub { font-size: 24px; font-weight: 600; color: var(--muted); letter-spacing: .2em; }
#center-msg.pop #center-main { animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
#center-msg.fade { transition: opacity .6s; opacity: 0; }
@keyframes pop { from { transform: scale(1.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#popups { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); }
.popup { position: absolute; left: 0; transform: translateX(-50%); white-space: nowrap; text-align: center; animation: rise 1.3s ease-out forwards; }
.popup .pts { font-size: 40px; font-weight: 700; color: var(--accent-2); text-shadow: 0 2px 16px rgba(255,140,0,.5); }
.popup .lbl { font-size: 18px; font-weight: 700; letter-spacing: .15em; color: var(--ink); }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 100% { opacity: 0; transform: translate(-50%, -70px) scale(1); } }

#damage-flash { position: absolute; inset: 0; box-shadow: inset 0 0 160px rgba(255, 30, 30, .0); transition: box-shadow .5s; }
#damage-flash.on { box-shadow: inset 0 0 160px rgba(255, 30, 30, .55); transition: none; }

#cam-hint { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); font-size: 11px; opacity: .55; }

/* ---------- Lobby ---------- */
#lobby .menu-card { background: var(--glass); border: 1px solid var(--glass-border); backdrop-filter: blur(14px); padding: 28px; border-radius: 18px; }
.lobby-sec { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 15px; font-weight: 600; color: var(--muted); }
.field input, .share input {
  font: inherit; font-size: 22px; font-weight: 700; color: var(--ink); background: rgba(255,255,255,.06);
  border: 1px solid var(--glass-border); border-radius: 10px; padding: 10px 14px; outline: none; min-width: 0; user-select: text;
}
.field input:focus, .share input:focus { border-color: var(--accent); }
#lobby-code { text-transform: uppercase; letter-spacing: .2em; }
.room-code { text-align: center; }
#room-code { font-size: 54px; font-weight: 700; letter-spacing: .25em; line-height: 1; color: var(--accent-2); }
.share { display: flex; gap: 8px; }
.share input { flex: 1; font-size: 14px; font-weight: 600; }
button.small-btn { font-size: 15px; padding: 8px 14px; }
#room-players { display: flex; flex-direction: column; gap: 6px; min-height: 30px; }
.pl-row { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; background: rgba(255,255,255,.04); padding: 6px 12px; border-radius: 8px; }
.pl-row .tag { margin-left: auto; font-size: 12px; letter-spacing: .15em; color: var(--muted); }
.pl-row.me { color: var(--accent-2); }
#lobby-status { min-height: 18px; text-align: center; }
#lobby-status.err { color: var(--bad); opacity: 1; }
#results-wait { text-align: center; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(5,7,13,.25), rgba(5,7,13,.8));
  padding: 16px;
}
#menu { justify-content: flex-start; padding-left: 6vw; background: linear-gradient(90deg, rgba(5,7,13,.88) 0%, rgba(5,7,13,.5) 45%, rgba(5,7,13,0) 75%); }
.menu-card { width: min(460px, 100%); display: flex; flex-direction: column; gap: 18px; }
.menu-card.small { width: min(320px, 100%); align-items: stretch; text-align: center; }
#pause .menu-card, #results .menu-card { background: var(--glass); border: 1px solid var(--glass-border); backdrop-filter: blur(14px); padding: 28px; border-radius: 18px; }

.brand-kicker { font-size: 14px; letter-spacing: .4em; color: var(--accent); font-weight: 700; }
h1 { margin: 0; font-size: 92px; line-height: .85; font-weight: 700; letter-spacing: .02em; }
h1 span { display: block; padding-top: .14em; margin-top: -.08em; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
h2 { margin: 0; font-size: 48px; font-weight: 700; text-align: center; }
.tagline { margin: 8px 0 0; color: var(--muted); font-size: 18px; }

.options { display: flex; flex-direction: column; gap: 12px; }
.options label { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 17px; font-weight: 600; color: var(--muted); }
.seg { display: flex; background: rgba(255,255,255,.06); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 15px; font-weight: 700; padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #140800; }

button.cta, button.ghost {
  font: inherit; font-size: 24px; font-weight: 700; letter-spacing: .12em; border-radius: 12px; padding: 14px 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 12px; transition: transform .1s, filter .1s;
}
button.cta { border: 0; color: #140800; background: linear-gradient(90deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 30px rgba(255,106,26,.35); }
button.ghost { border: 1px solid var(--glass-border); color: var(--ink); background: rgba(255,255,255,.05); }
button.cta:hover, button.ghost:hover { filter: brightness(1.1); transform: translateY(-1px); }
button small { font-size: 12px; opacity: .6; letter-spacing: .1em; }
.row-buttons { display: flex; gap: 12px; }
.row-buttons button { flex: 1; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-size: 15px; color: var(--muted); font-weight: 600; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 4px; border-radius: 5px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); color: var(--ink); font-family: inherit; font-size: 13px; text-align: center; }
.tip { margin: 0; font-size: 14px; color: var(--muted); opacity: .8; }

#results-sub { margin: -8px 0 0; text-align: center; color: var(--muted); font-size: 18px; }
#results-table { width: 100%; border-collapse: collapse; font-size: 17px; font-weight: 600; }
#results-table td { padding: 6px 4px; border-bottom: 1px solid rgba(255,255,255,.06); }
#results-table tr.me td { color: var(--accent-2); }
#results-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
#results-table td.st { color: var(--muted); font-size: 14px; }

#loading { background: #05070d; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid rgba(255,255,255,.1); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  h1 { font-size: 64px; }
  #menu { padding-left: 16px; }
  #standings { display: none; }
  #center-main { font-size: 72px; }
}

/* ---------- Touch (phones / tablets) ---------- */
#touch, #rotate, .touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; overscroll-behavior: none; }
body.touch #game { touch-action: none; }
body.touch .overlay { overflow-y: auto; touch-action: pan-y; }
body.touch .controls, body.touch button small, body.touch #cam-hint { display: none; }

body.touch #touch { display: block; position: absolute; inset: 0; pointer-events: none; }
body.touch:not(.driving) #t-steer, body.touch:not(.driving) #t-right { opacity: 0; pointer-events: none !important; }
#touch button { font: inherit; -webkit-user-select: none; user-select: none; touch-action: none; }

#t-steer {
  position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  width: min(42vw, 300px); height: min(46vh, 190px); pointer-events: auto; touch-action: none;
  border-radius: 26px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
  transition: opacity .2s;
}
#t-steer .t-arrow { font-size: 30px; color: rgba(255,255,255,.35); transition: color .1s; }
#t-steer.left .t-arrow:first-child, #t-steer.right .t-arrow:last-child { color: var(--accent-2); }
#t-knob {
  position: absolute; left: 50%; top: 50%; width: 74px; height: 74px; margin: -37px 0 0 -37px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255,255,255,.35), rgba(255,255,255,.1));
  border: 2px solid rgba(255,255,255,.35); transition: transform .15s, left .15s;
}
#t-steer.on #t-knob { border-color: var(--accent); }

#t-right {
  position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 12px; align-items: end;
  pointer-events: none; transition: opacity .2s;
}
.t-btn {
  pointer-events: auto; border: 2px solid rgba(255,255,255,.22); background: rgba(12,16,28,.45); color: var(--ink);
  font-weight: 700; letter-spacing: .1em; font-size: 15px; border-radius: 50%; width: 88px; height: 88px;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.t-btn.on { background: rgba(255,255,255,.28); transform: scale(.95); }
#t-hb { grid-column: 2; grid-row: 1; justify-self: center; }
#t-brake { grid-column: 1; grid-row: 2; }
#t-gas { grid-column: 2; grid-row: 2; }
.t-small { width: 70px; height: 70px; font-size: 13px; }
.t-gas { width: 112px; height: 112px; font-size: 18px; border-color: rgba(255,106,26,.7); background: rgba(255,106,26,.25); }
.t-gas.on { background: rgba(255,106,26,.6); }

#t-top { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 8px; pointer-events: auto; }
.t-icon { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--glass-border); background: var(--glass); color: var(--ink); padding: 9px; }
.t-icon svg { width: 100%; height: 100%; display: block; }

/* compact HUD so it doesn't sit under the thumbs */
body.touch #standings { display: none; }
body.touch #hud-score { top: max(8px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); padding: 6px 12px; min-width: 0; }
body.touch #hud-score .label { font-size: 10px; }
body.touch #score { font-size: 26px; }
body.touch #combo { font-size: 13px; height: 14px; }
body.touch #hud-damage { top: calc(max(8px, env(safe-area-inset-top)) + 64px); bottom: auto; left: max(10px, env(safe-area-inset-left)); padding: 6px 10px; gap: 8px; }
body.touch #damage-svg { width: 24px; height: 42px; }
body.touch .dmg-info { width: 64px; }
body.touch .dmg-info .label { display: none; }
body.touch #health-num { font-size: 18px; }
body.touch #hud-center-top { top: max(6px, env(safe-area-inset-top)); }
body.touch #timer { font-size: 26px; }
body.touch #alive { font-size: 10px; }
body.touch #hud-speed { right: auto; left: 50%; transform: translateX(-50%); bottom: max(10px, env(safe-area-inset-bottom)); text-align: center; }
body.touch #speed { font-size: 34px; }
body.touch #killfeed { top: 66px; }
body.touch .kf { font-size: 13px; }
body.touch #center-main { font-size: 64px; }
body.touch #center-sub { font-size: 16px; }
body.touch #popups { top: 36%; }
body.touch .popup .pts { font-size: 28px; }

/* short (landscape phone) screens: menus must fit or scroll */
@media (max-height: 560px) {
  .overlay { align-items: flex-start; }
  .overlay > .menu-card { margin: auto 0; }
  #menu { padding-left: max(16px, env(safe-area-inset-left)); }
  h1 { font-size: 44px; }
  h2 { font-size: 30px; }
  .brand-kicker { font-size: 11px; }
  .tagline { font-size: 14px; margin-top: 4px; }
  .menu-card { gap: 10px; }
  #pause .menu-card, #results .menu-card, #lobby .menu-card { padding: 16px; }
  button.cta, button.ghost { font-size: 17px; padding: 10px 14px; }
  .options { gap: 6px; }
  .options label { font-size: 14px; }
  .seg button { font-size: 13px; padding: 5px 10px; }
  #results-table { font-size: 14px; }
  #results-table td { padding: 3px 4px; }
  #room-code { font-size: 36px; }
  .field input { font-size: 18px; padding: 8px 12px; }
  .tip { font-size: 12px; }
}

@media (orientation: portrait) {
  body.touch.driving #rotate { display: flex; background: rgba(5,7,13,.92); z-index: 50; }
}
#rotate svg { margin: 0 auto; color: var(--ink); }
