:root {
  --pink: #ff2bd6;
  --cyan: #00f0ff;
  --yellow: #ffe600;
  --purple: #7c4dff;
  --orange: #ff6a00;
  --bg: #0b0018;
  --panel: rgba(20, 0, 45, 0.78);
  --text: #f5e9ff;
  --muted: #b39ddb;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Rajdhani', system-ui, sans-serif; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }

/* ---------------- screens ---------------- */
#screens { position: fixed; inset: 0; pointer-events: none; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  pointer-events: auto; padding: 24px 16px; overflow-y: auto;
  background: radial-gradient(ellipse at 50% 120%, rgba(255, 43, 214, 0.25), transparent 60%), linear-gradient(180deg, rgba(11,0,24,0.55), rgba(11,0,24,0.82));
}
.screen.overlay { background: rgba(8, 0, 20, 0.72); backdrop-filter: blur(3px); }
h2, h3 { font-family: 'Orbitron', sans-serif; letter-spacing: 0.12em; margin: 0; }
h2 { font-size: clamp(22px, 4vw, 40px); color: var(--cyan); text-shadow: 0 0 12px var(--cyan), 0 0 30px rgba(0,240,255,.5); }
h3 { font-size: 16px; color: var(--pink); text-shadow: 0 0 10px var(--pink); margin: 6px 0 10px; }

.logo { text-align: center; line-height: 0.9; user-select: none; }
.logo-neon { font-family: 'Monoton', cursive; font-size: clamp(56px, 13vw, 150px); color: #fff; text-shadow: 0 0 6px #fff, 0 0 14px var(--pink), 0 0 32px var(--pink), 0 0 64px var(--pink); animation: flicker 6s infinite; }
.logo-chrome {
  font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: clamp(22px, 5.4vw, 64px); letter-spacing: 0.08em;
  background: linear-gradient(180deg, #fff 0%, #cfe9ff 40%, #3a2a6b 52%, #ff9be8 60%, #fff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 8px rgba(0,240,255,.8)) drop-shadow(0 3px 0 #2a0055);
  font-style: italic; transform: skew(-8deg);
}
.logo.small .logo-neon { font-size: clamp(40px, 8vw, 90px); }
.logo.small .logo-chrome { font-size: clamp(18px, 3.4vw, 40px); }
.tagline { font-family: 'Orbitron'; letter-spacing: .5em; color: var(--yellow); text-shadow: 0 0 10px var(--yellow); font-size: clamp(11px, 1.6vw, 16px); text-align: center; }
.footer { position: absolute; bottom: 14px; font-size: 13px; color: var(--muted); text-align: center; padding: 0 16px; }
.motd { color: var(--yellow); font-family: 'Orbitron'; font-size: 13px; letter-spacing: .1em; text-align: center; min-height: 1em; }

@keyframes flicker { 0%, 18%, 22%, 25%, 53%, 57%, 100% { opacity: 1; } 20%, 24%, 55% { opacity: 0.55; } }
@keyframes blink { 50% { opacity: .35; } }
.blink { animation: blink 1.2s infinite; }

.menu { display: flex; flex-direction: column; gap: 10px; width: min(360px, 90vw); }
.btn {
  font-family: 'Orbitron', sans-serif; font-weight: 700; letter-spacing: .14em; font-size: 15px; color: #fff; cursor: pointer;
  background: linear-gradient(90deg, rgba(255,43,214,.18), rgba(0,240,255,.18)); border: 2px solid var(--pink); border-radius: 4px;
  padding: 12px 18px; box-shadow: 0 0 10px rgba(255,43,214,.6), inset 0 0 12px rgba(255,43,214,.25); text-shadow: 0 0 8px var(--pink);
  transition: transform .08s, box-shadow .15s, border-color .15s;
}
.btn:hover, .btn:focus-visible { border-color: var(--cyan); box-shadow: 0 0 18px var(--cyan), inset 0 0 16px rgba(0,240,255,.35); transform: translateX(4px); outline: none; }
.btn.big { font-size: 22px; padding: 16px 36px; }
.btn.small { font-size: 12px; padding: 8px 12px; }
.btn.back { margin-top: 6px; border-color: var(--purple); box-shadow: 0 0 10px rgba(124,77,255,.6); }

.panel { background: var(--panel); border: 1px solid rgba(255,43,214,.45); border-radius: 8px; padding: 16px 18px; box-shadow: 0 0 22px rgba(124,77,255,.35); width: min(560px, 94vw); }
.panel.wide { width: min(860px, 96vw); }
.panel label { display: flex; flex-direction: column; gap: 6px; font-family: 'Orbitron'; font-size: 12px; letter-spacing: .12em; color: var(--muted); margin-bottom: 14px; }
.panel label.check { flex-direction: row; align-items: center; }
input, select { font-family: 'Rajdhani'; font-size: 17px; background: rgba(0,0,0,.45); color: #fff; border: 1px solid var(--purple); border-radius: 4px; padding: 8px 10px; }
input[type=range] { padding: 0; accent-color: var(--pink); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row.center { justify-content: center; }
.row input { flex: 1; min-width: 160px; }
.hint { color: var(--muted); font-size: 14px; margin-top: 8px; }

.table { width: 100%; border-collapse: collapse; font-size: 16px; }
.table th { font-family: 'Orbitron'; font-size: 11px; letter-spacing: .14em; color: var(--cyan); text-align: left; padding: 6px; border-bottom: 1px solid rgba(0,240,255,.4); }
.table td { padding: 6px; border-bottom: 1px solid rgba(255,255,255,.07); }
.table tr.me td { color: var(--yellow); text-shadow: 0 0 6px var(--yellow); }
.table tr.p1 td:first-child { color: var(--yellow); }
.table tr.p2 td:first-child { color: #d9d9d9; }
.table tr.p3 td:first-child { color: #ff9b4d; }

.garage, .lb { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.garage .panel, .lb .panel { width: min(440px, 94vw); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; box-shadow: 0 0 10px currentColor; }
.swatch.sel { border-color: #fff; transform: scale(1.15); }
.car-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.car-card { padding: 8px 10px; border: 1px solid var(--purple); border-radius: 6px; cursor: pointer; background: rgba(0,0,0,.3); }
.car-card b { display: block; font-family: 'Orbitron'; font-size: 12px; letter-spacing: .08em; }
.car-card.sel { border-color: var(--cyan); box-shadow: 0 0 12px var(--cyan); }
.garage-preview canvas { width: 100%; height: auto; border-radius: 6px; background: #12002a; }
#car-desc { margin-top: 8px; color: var(--muted); }
.profile-chip { position: absolute; top: 14px; right: 16px; font-family: 'Orbitron'; font-size: 12px; color: var(--muted); text-align: right; }
.profile-chip b { color: var(--cyan); }
.howto { font-size: 17px; line-height: 1.4; }
.items { padding-left: 18px; }
.i-rocket { color: var(--orange); } .i-mine { color: var(--pink); } .i-boost { color: var(--cyan); } .i-shield { color: var(--purple); } .i-repair { color: #39ff14; }

.spinner { width: 64px; height: 64px; border: 4px solid rgba(255,43,214,.25); border-top-color: var(--pink); border-radius: 50%; animation: spin 0.8s linear infinite; box-shadow: 0 0 18px var(--pink); }
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { font-family: 'Orbitron'; letter-spacing: .2em; color: var(--cyan); text-align: center; }

#toast { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); background: rgba(40,0,60,.92); border: 1px solid var(--pink); padding: 10px 16px; border-radius: 6px; font-size: 16px; opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 92vw; text-align: center; }
#toast.show { opacity: 1; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; font-family: 'Orbitron', sans-serif; }
.hud-top-left { position: absolute; top: 14px; left: 16px; text-shadow: 0 0 10px var(--pink); }
.hud-place { font-size: 64px; font-weight: 900; line-height: 1; color: #fff; text-shadow: 0 0 10px var(--pink), 0 0 30px var(--pink); }
.hud-place sup { font-size: 24px; } .hud-place small { font-size: 22px; color: var(--muted); }
.hud-lap { font-size: 22px; color: var(--cyan); text-shadow: 0 0 10px var(--cyan); margin-top: 4px; }
.hud-times { font-size: 13px; color: var(--muted); margin-top: 6px; letter-spacing: .1em; }
.hud-times span { color: #fff; }
.hud-top-right { position: absolute; top: 14px; right: 14px; }
#minimap { width: 180px; height: 180px; border-radius: 50%; background: rgba(10,0,30,.55); box-shadow: 0 0 18px rgba(0,240,255,.45); border: 1px solid rgba(0,240,255,.5); }
.hud-bottom-left { position: absolute; bottom: 18px; left: 16px; width: min(260px, 40vw); }
.bar-label { font-size: 11px; letter-spacing: .2em; color: var(--muted); margin-top: 6px; }
.bar { height: 12px; border: 1px solid rgba(255,255,255,.3); border-radius: 3px; background: rgba(0,0,0,.5); overflow: hidden; }
.bar-fill { height: 100%; width: 100%; transition: width .1s; }
.bar-fill.hp { background: linear-gradient(90deg, #39ff14, var(--cyan)); box-shadow: 0 0 10px #39ff14; }
.bar-fill.hp.low { background: linear-gradient(90deg, #ff1744, var(--orange)); box-shadow: 0 0 10px #ff1744; }
.bar-fill.heat { background: linear-gradient(90deg, var(--yellow), var(--orange), #ff1744); }
.bar-fill.heat.over { animation: blink .3s infinite; }
.hud-bottom-center { position: absolute; bottom: 110px; right: 20px; }
.item-slot { width: 96px; height: 96px; border: 2px solid var(--cyan); border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(0,0,0,.45); box-shadow: 0 0 16px rgba(0,240,255,.5); }
.item-slot .item-icon { font-size: 26px; font-weight: 900; }
.item-slot small { font-size: 9px; color: var(--muted); letter-spacing: .1em; margin-top: 4px; }
.item-slot.has { animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 30px var(--pink); border-color: var(--pink); } }
.hud-bottom-right { position: absolute; bottom: 18px; right: 20px; text-align: right; }
.speedo { font-size: 56px; font-weight: 900; color: #fff; text-shadow: 0 0 12px var(--cyan), 0 0 30px var(--cyan); line-height: 1; }
.speedo small { display: block; font-size: 12px; letter-spacing: .3em; color: var(--muted); }
#killfeed { position: absolute; top: 210px; right: 16px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; font-family: 'Rajdhani'; font-size: 16px; }
#killfeed div { background: rgba(20,0,40,.7); padding: 3px 8px; border-left: 3px solid var(--pink); border-radius: 3px; animation: fadeout 5s forwards; }
@keyframes fadeout { 80% { opacity: 1; } 100% { opacity: 0; } }
#center-msg { position: absolute; top: 34%; width: 100%; text-align: center; font-size: clamp(48px, 10vw, 120px); font-weight: 900; color: #fff; text-shadow: 0 0 14px var(--pink), 0 0 40px var(--pink); }
#sub-msg { position: absolute; top: 52%; width: 100%; text-align: center; font-size: clamp(16px, 2.6vw, 26px); color: var(--yellow); text-shadow: 0 0 10px var(--yellow); letter-spacing: .15em; }
#lobby-panel { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: auto; width: min(420px, 92vw); text-align: center; }
#lobby-panel ul { list-style: none; padding: 0; margin: 8px 0; text-align: left; font-family: 'Rajdhani'; font-size: 18px; }
#lobby-panel li { padding: 3px 6px; display: flex; align-items: center; gap: 8px; }
#lobby-panel li i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; box-shadow: 0 0 8px currentColor; }
#lobby-timer { font-size: 26px; color: var(--yellow); text-shadow: 0 0 10px var(--yellow); margin: 8px 0; }
#lobby-track { color: var(--cyan); }
#chat { position: absolute; left: 16px; bottom: 120px; width: min(360px, 60vw); font-family: 'Rajdhani'; pointer-events: auto; }
#chat-log { max-height: 140px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 15px; text-shadow: 0 0 4px #000; }
#chat-log div { animation: fadeout 12s forwards; }
#chat-input { width: 100%; opacity: 0; transition: opacity .2s; font-size: 15px; }
#chat-input:focus { opacity: 1; }
#stats-overlay { position: fixed; top: 4px; left: 50%; transform: translateX(-50%); font: 12px monospace; color: #0f0; background: rgba(0,0,0,.5); padding: 2px 6px; z-index: 5; pointer-events: none; }

#touch-controls { position: absolute; inset: auto 0 0 0; height: 160px; pointer-events: none; }
#touch-controls button { pointer-events: auto; width: 72px; height: 72px; border-radius: 50%; border: 2px solid var(--cyan); background: rgba(0,0,0,.35); color: #fff; font-family: 'Orbitron'; font-weight: 700; font-size: 14px; margin: 6px; touch-action: none; }
.touch-left { position: absolute; left: 10px; bottom: 20px; }
.touch-right { position: absolute; right: 10px; bottom: 20px; display: grid; grid-template-columns: repeat(2, auto); }

@media (max-width: 720px) {
  .hud-place { font-size: 44px; }
  #minimap { width: 120px; height: 120px; }
  .speedo { font-size: 38px; }
  .item-slot { width: 70px; height: 70px; }
  #killfeed { top: 150px; font-size: 14px; }
  #chat { display: none; }
  .hud-bottom-left, .hud-bottom-right { bottom: 175px; }
  .hud-bottom-center { bottom: 235px; }
}
