/* ============================================================
   NITRO RUSH — Arcade Street Racing
   Modern dark / neon racing theme
   ============================================================ */
:root {
  --bg: #06070d;
  --panel: rgba(12, 16, 30, 0.82);
  --panel-line: rgba(0, 229, 255, 0.28);
  --cyan: #00e5ff;
  --magenta: #ff2d78;
  --lime: #b4ff39;
  --amber: #ffb020;
  --text: #e8f4ff;
  --dim: #7d8fa8;
  --font-head: 'Orbitron', 'Rajdhani', system-ui, sans-serif;
  --font-body: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

/* ---------- FX overlays ---------- */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#speedlines { background-repeat: no-repeat; background-position: center; background-size: 130% 130%;
  opacity: 0; transition: opacity .12s linear; }
#vignette { box-shadow: inset 0 0 18vmin rgba(0,0,0,.55); }
#flash { background: radial-gradient(circle, rgba(255,60,60,.35), rgba(255,30,30,.55)); opacity: 0; }
#flash.hit { animation: flashHit .45s ease-out; }
@keyframes flashHit { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- generic screens ---------- */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; }
.hidden { display: none !important; }

/* ---------- loading ---------- */
#loading { background: radial-gradient(120% 120% at 50% 20%, #0d1226 0%, #06070d 60%); z-index: 40; flex-direction: column; }
.loading-inner { text-align: center; width: min(420px, 80vw); }
.load-bar { height: 10px; border: 1px solid var(--panel-line); border-radius: 6px; overflow: hidden; margin: 26px 0 12px; }
#load-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--cyan), var(--magenta)); transition: width .25s ease; border-radius: 6px; }
#load-text { color: var(--dim); letter-spacing: 2px; text-transform: uppercase; font-size: 14px; }

/* ---------- logo ---------- */
.logo { font-family: var(--font-head); font-weight: 800; font-size: clamp(44px, 7vw, 84px); line-height: 1;
  color: #fff; letter-spacing: 2px;
  text-shadow: 0 0 8px rgba(0,229,255,.8), 0 0 28px rgba(0,229,255,.45), 0 0 60px rgba(255,45,120,.35); }
.logo span { color: var(--magenta); text-shadow: 0 0 8px rgba(255,45,120,.9), 0 0 30px rgba(255,45,120,.5); }
.logo.small { font-size: 42px; }
.tagline { text-align: center; letter-spacing: .55em; color: var(--cyan); font-weight: 600; margin-top: 8px; font-size: clamp(11px, 1.4vw, 15px); text-indent: .55em; }

/* ---------- rotate overlay ---------- */
#rotate-overlay { position: fixed; inset: 0; z-index: 100; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(120% 120% at 50% 30%, #101632 0%, #06070d 70%); text-align: center; padding: 24px; }
#rotate-overlay h2 { font-family: var(--font-head); font-size: clamp(18px, 3.4vh, 26px); letter-spacing: 1px; }
#rotate-overlay p { color: var(--dim); }
.phone-icon { position: relative; width: 64px; height: 100px; }
.phone-body { position: absolute; inset: 0; border: 4px solid var(--cyan); border-radius: 12px;
  box-shadow: 0 0 18px rgba(0,229,255,.5), inset 0 0 12px rgba(0,229,255,.25);
  animation: rotatePhone 1.6s ease-in-out infinite; }
.phone-body::after { content: ""; position: absolute; bottom: 6px; left: 50%; width: 16px; height: 3px;
  transform: translateX(-50%); background: var(--cyan); border-radius: 2px; }
@keyframes rotatePhone { 0%, 25% { transform: rotate(0deg); } 60%, 100% { transform: rotate(-90deg); } }
.phone-arrow { position: absolute; right: -34px; top: 50%; width: 0; height: 0; transform: translateY(-50%);
  border-top: 11px solid transparent; border-bottom: 11px solid transparent; border-left: 16px solid var(--magenta);
  animation: arrowPulse 1.6s ease-in-out infinite; }
@keyframes arrowPulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@media (orientation: portrait) { #rotate-overlay { display: flex; } }

/* ---------- menu ---------- */
#menu { flex-direction: column; background: radial-gradient(130% 100% at 50% 0%, #101736 0%, #070910 55%, #05060b 100%); z-index: 25; overflow-y: auto; }
.menu-bg-grid { position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: linear-gradient(rgba(0,229,255,.05) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(0,229,255,.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), transparent 75%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), transparent 75%); }
.menu-head { position: relative; text-align: center; padding: clamp(10px, 2.4vh, 26px) 16px 4px; }
.audio-toggles { position: absolute; right: 14px; top: 14px; display: flex; gap: 8px; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--panel-line); background: var(--panel);
  color: var(--cyan); font-size: 17px; cursor: pointer; }
.icon-btn.off { color: var(--dim); border-color: rgba(125,143,168,.3); text-decoration: line-through; }

.menu-body { position: relative; display: flex; gap: 18px; padding: 6px clamp(12px, 3vw, 40px); flex: 1; min-height: 0; align-items: stretch; justify-content: center; }
.panel { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px; padding: 14px 16px;
  backdrop-filter: blur(6px); box-shadow: 0 10px 40px rgba(0,0,0,.5); display: flex; flex-direction: column; }
.car-panel { flex: 0 1 460px; min-width: 320px; }
.track-panel { flex: 0 1 520px; min-width: 300px; overflow: auto; }
.panel-title { font-family: var(--font-head); font-size: 13px; letter-spacing: .3em; color: var(--cyan); margin-bottom: 10px; }

.carousel { display: flex; align-items: center; gap: 6px; }
#car-canvas { flex: 1; width: 100%; height: clamp(130px, 24vh, 190px); border-radius: 12px;
  background: radial-gradient(90% 120% at 50% 100%, #14203f 0%, #0a0d1c 70%); border: 1px solid rgba(0,229,255,.15); }
.arrow-btn { width: 42px; height: 64px; font-size: 20px; color: var(--cyan); background: rgba(0,229,255,.07);
  border: 1px solid var(--panel-line); border-radius: 10px; cursor: pointer; transition: all .15s; }
.arrow-btn:hover { background: rgba(0,229,255,.2); box-shadow: 0 0 14px rgba(0,229,255,.35); }
.car-name { text-align: center; font-family: var(--font-head); font-weight: 700; font-size: 21px; letter-spacing: .18em; margin: 8px 0 10px; color: #fff; text-shadow: 0 0 12px rgba(0,229,255,.6); }

.stats { display: grid; gap: 7px; }
.stat { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; font-size: 12px; letter-spacing: .12em; color: var(--dim); }
.stat-bar { height: 9px; background: rgba(255,255,255,.07); border-radius: 5px; overflow: hidden; }
.stat-fill { height: 100%; width: 50%; border-radius: 5px; background: linear-gradient(90deg, var(--cyan), var(--lime)); transition: width .4s cubic-bezier(.2,.8,.2,1); box-shadow: 0 0 10px rgba(0,229,255,.5); }

.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.theme-card { border: 1px solid rgba(0,229,255,.16); border-radius: 12px; overflow: hidden; background: #0b0f1e; cursor: pointer; padding: 0; text-align: left; transition: all .15s; }
.theme-card:hover { border-color: var(--cyan); box-shadow: 0 0 16px rgba(0,229,255,.25); }
.theme-card.selected { border-color: var(--magenta); box-shadow: 0 0 20px rgba(255,45,120,.4); }
.theme-img { height: clamp(56px, 10.5vh, 88px); position: relative; overflow: hidden; }
.theme-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.theme-fallback { position: absolute; inset: 0; }
.theme-fallback.city { background: linear-gradient(160deg, #12172e 0%, #2b2350 55%, #0e2038 100%); }
.theme-fallback.village { background: linear-gradient(160deg, #1b4223 0%, #7bb661 60%, #d7e88a 100%); }
.theme-fallback.hill { background: linear-gradient(160deg, #233b57 0%, #4c6b52 55%, #6e5b47 100%); }
.theme-fallback.desert { background: linear-gradient(160deg, #3f2c1d 0%, #c98c4a 55%, #f2d6a0 100%); }
.theme-info { padding: 6px 9px; display: flex; flex-direction: column; }
.theme-info b { font-family: var(--font-head); font-size: 12px; letter-spacing: .14em; }
.theme-info span { font-size: 11px; color: var(--dim); }

.diff-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.diff-btn { padding: 9px 4px; border-radius: 10px; border: 1px solid rgba(0,229,255,.16); background: rgba(255,255,255,.03);
  color: var(--text); font-family: var(--font-head); font-size: 13px; letter-spacing: .12em; cursor: pointer; transition: all .15s; }
.diff-btn:hover { border-color: var(--cyan); }
.diff-btn.selected { background: linear-gradient(90deg, rgba(0,229,255,.25), rgba(255,45,120,.25)); border-color: var(--magenta); box-shadow: 0 0 14px rgba(255,45,120,.3); }
.diff-desc { color: var(--dim); font-size: 13px; margin-top: 8px; min-height: 18px; }

.menu-foot { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 16px clamp(10px, 2.4vh, 24px); }
.best-note { color: var(--amber); font-size: 13px; letter-spacing: .1em; min-height: 16px; }
.start-btn { font-family: var(--font-head); font-weight: 800; font-size: clamp(17px, 2.2vw, 23px); letter-spacing: .22em; text-indent: .22em;
  color: #04101c; background: linear-gradient(90deg, var(--cyan), #43ffb0 60%, var(--lime)); border: none; border-radius: 14px;
  padding: clamp(11px, 1.9vh, 17px) clamp(40px, 8vw, 90px); cursor: pointer; transition: transform .12s, box-shadow .15s;
  box-shadow: 0 0 26px rgba(0,229,255,.5), 0 6px 0 rgba(0,0,0,.35); }
.start-btn:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 0 40px rgba(0,229,255,.8), 0 6px 0 rgba(0,0,0,.35); }
.start-btn:active { transform: translateY(1px); }
.controls-note { color: var(--dim); font-size: 12px; letter-spacing: .08em; }

/* ---------- countdown ---------- */
#countdown { z-index: 30; pointer-events: none; background: transparent; }
#count-num { font-family: var(--font-head); font-weight: 800; font-size: clamp(90px, 24vh, 190px); color: #fff;
  text-shadow: 0 0 18px var(--cyan), 0 0 60px rgba(0,229,255,.6); animation: countPop .9s ease-out infinite; }
#count-num.go { color: var(--lime); text-shadow: 0 0 18px var(--lime), 0 0 70px rgba(180,255,57,.7); }
@keyframes countPop { 0% { transform: scale(1.7); opacity: 0; } 22% { transform: scale(1); opacity: 1; } 85% { opacity: 1; } 100% { opacity: .1; } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top-left { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: calc(14px + env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 6px; }
.hud-position { font-family: var(--font-head); font-weight: 800; font-size: clamp(26px, 4.6vh, 44px); color: #fff;
  text-shadow: 0 0 14px rgba(255,176,32,.9), 0 2px 4px rgba(0,0,0,.6); }
.hud-timer { font-family: var(--font-head); font-size: clamp(14px, 2.2vh, 20px); letter-spacing: .1em; color: var(--cyan); text-shadow: 0 0 10px rgba(0,229,255,.5); }

.hud-top-center { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(46vw, 460px); }
.progress-track { position: relative; height: 9px; background: rgba(255,255,255,.12); border-radius: 6px; border: 1px solid rgba(255,255,255,.14); }
.progress-fill { height: 100%; width: 0%; border-radius: 6px; background: linear-gradient(90deg, var(--cyan), var(--lime)); box-shadow: 0 0 10px rgba(0,229,255,.55); }
.prog-dot { position: absolute; top: 50%; width: 7px; height: 7px; border-radius: 50%; transform: translate(-50%,-50%); box-shadow: 0 0 6px currentColor; background: currentColor; }
.prog-dot.player { width: 12px; height: 12px; background: #fff; box-shadow: 0 0 10px var(--cyan), 0 0 4px #fff; z-index: 2; }
.progress-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); margin-top: 3px; letter-spacing: .12em; }

.hud-top-right { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(14px + env(safe-area-inset-right));
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.pause-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--panel-line); background: var(--panel); color: var(--text);
  font-size: 15px; cursor: pointer; }
.nitro-row { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.nitro-label { font-family: var(--font-head); font-size: 10px; letter-spacing: .22em; color: var(--magenta); text-shadow: 0 0 8px rgba(255,45,120,.7); }
.nitro-bar { width: clamp(120px, 15vw, 190px); height: 13px; border-radius: 7px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,45,120,.35); overflow: hidden; }
.nitro-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ff2d78, #ff8a5c); box-shadow: 0 0 12px rgba(255,45,120,.8); transition: width .12s linear; }

.speedo { position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom));
  width: clamp(150px, 17vw, 220px); filter: drop-shadow(0 4px 14px rgba(0,0,0,.6)); }
#speedo-svg { width: 100%; display: block; }
.speedo-text { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; }
.speedo-text span { font-family: var(--font-head); font-weight: 700; font-size: clamp(24px, 3.6vh, 38px); color: #fff; text-shadow: 0 0 12px rgba(0,229,255,.7); }
.speedo-text em { display: block; font-style: normal; font-size: 11px; letter-spacing: .3em; color: var(--dim); margin-top: -4px; }

/* ---------- touch controls ---------- */
#touch-controls { display: none; position: absolute; inset: 0; pointer-events: none; z-index: 16; }
#touch-controls.visible { display: block; }
.tc-left { position: absolute; left: calc(14px + env(safe-area-inset-left)); bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 12px; }
.tc-right { position: absolute; right: calc(178px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; }
.tc-btn { pointer-events: auto; width: clamp(58px, 12.5vh, 84px); height: clamp(58px, 12.5vh, 84px); border-radius: 18px;
  border: 1px solid var(--panel-line); background: rgba(12,16,30,.55); color: var(--cyan); font-family: var(--font-head);
  font-size: clamp(15px, 3vh, 22px); backdrop-filter: blur(4px); }
.tc-btn.brake { color: var(--amber); font-size: clamp(9px, 1.8vh, 13px); width: clamp(58px, 12.5vh, 84px); height: clamp(44px, 9vh, 62px); }
.tc-btn.nitro { color: var(--magenta); border-color: rgba(255,45,120,.5); box-shadow: 0 0 16px rgba(255,45,120,.35); }
.tc-btn.pressed { background: rgba(0,229,255,.3); transform: scale(.94); }
.tc-btn.nitro.pressed { background: rgba(255,45,120,.4); box-shadow: 0 0 26px rgba(255,45,120,.7); }
@media (max-width: 760px) { .speedo { width: 128px; } .tc-right { right: calc(150px + env(safe-area-inset-right)); } }

/* ---------- modals (pause / results) ---------- */
#pause, #results { background: rgba(4, 6, 12, .78); backdrop-filter: blur(8px); z-index: 35; }
.modal { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 20px; padding: clamp(18px, 4vh, 34px) clamp(22px, 4vw, 46px);
  text-align: center; box-shadow: 0 20px 80px rgba(0,0,0,.7); max-width: min(92vw, 560px); max-height: 92vh; overflow: auto; }
.modal.wide { max-width: min(94vw, 640px); }
.modal h2 { font-family: var(--font-head); letter-spacing: .3em; margin-bottom: 18px; color: var(--cyan); }
.menu-btn { display: block; width: min(300px, 70vw); margin: 10px auto; padding: 12px; border-radius: 12px; cursor: pointer;
  font-family: var(--font-head); font-size: 15px; letter-spacing: .18em; color: #04101c;
  background: linear-gradient(90deg, var(--cyan), var(--lime)); border: none; transition: transform .1s, box-shadow .15s; }
.menu-btn:hover { box-shadow: 0 0 22px rgba(0,229,255,.55); transform: translateY(-1px); }
.menu-btn.dim { background: rgba(255,255,255,.08); color: var(--text); border: 1px solid rgba(255,255,255,.14); }

.result-title { font-family: var(--font-head); font-weight: 800; font-size: clamp(46px, 9vh, 84px); color: #fff;
  text-shadow: 0 0 16px var(--amber), 0 0 50px rgba(255,176,32,.5); }
.result-sub { color: var(--dim); margin: 4px 0 16px; letter-spacing: .06em; }
.result-times { display: flex; justify-content: center; gap: 34px; margin-bottom: 8px; }
.result-times span { display: block; font-size: 11px; letter-spacing: .28em; color: var(--dim); }
.result-times b { font-family: var(--font-head); font-size: 24px; color: var(--cyan); }
.new-record { color: var(--amber); font-family: var(--font-head); letter-spacing: .2em; margin: 6px 0 4px; animation: recPulse 1s ease-in-out infinite; }
@keyframes recPulse { 50% { text-shadow: 0 0 22px rgba(255,176,32,.9); } }
.standings { margin: 14px auto 6px; display: grid; gap: 5px; text-align: left; }
.stand-row { display: grid; grid-template-columns: 34px 1fr 86px; align-items: center; padding: 7px 12px; border-radius: 9px;
  background: rgba(255,255,255,.045); font-size: 15px; }
.stand-row .pos { font-family: var(--font-head); color: var(--amber); }
.stand-row .nm { font-weight: 600; letter-spacing: .05em; }
.stand-row .tm { text-align: right; font-family: var(--font-head); font-size: 13px; color: var(--cyan); }
.stand-row.me { background: linear-gradient(90deg, rgba(0,229,255,.16), rgba(255,45,120,.14)); border: 1px solid var(--panel-line); }
.result-btns { margin-top: 14px; display: grid; gap: 4px; }

/* ---------- responsive tweaks ---------- */
@media (max-width: 900px) {
  #menu { justify-content: flex-start; }
  .menu-body { flex-direction: column; overflow: visible; gap: 10px; padding: 4px 12px; }
  .car-panel, .track-panel { min-width: 0; flex: none; }
  #car-canvas { height: clamp(110px, 20vh, 150px); }
  .stat { grid-template-columns: 92px 1fr; }
  .menu-foot { padding-top: 2px; padding-bottom: 14px; }
  .controls-note { display: none; }
  .hud-top-center { width: 42vw; }
  .menu-head { padding-bottom: 0; }
  .logo { font-size: clamp(30px, 8vh, 44px); }
}
@media (max-height: 480px) {
  .menu-head { padding-top: 6px; }
  .logo { font-size: 34px; }
  .panel { padding: 8px 12px; }
  .panel-title { margin-bottom: 5px; }
  #car-canvas { height: 92px; }
  .stats { gap: 4px; }
  .theme-img { height: 44px; }
  .start-btn { padding: 9px 50px; }
}
