:root {
  --yellow: #f2c200;
  --yellow-2: #ffdf4a;
  --ink: #111214;
  --panel: rgba(16, 17, 20, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f1efe8;
  --muted: #a9a79f;
  --red: #e0413a;
  --green: #52d273;
  --blue: #4aa8ff;
  --title: 'Bungee', 'Arial Black', Impact, sans-serif;
  --body: 'Rubik', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a1c16; color: var(--text); font-family: var(--body); }
button, input, select { font: inherit; }
.hidden { display: none !important; }

#game { position: fixed; inset: 0; }
#game canvas { display: block; cursor: crosshair; }

/* ---------------- Menu ---------------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; }
.menu-bg {
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(135deg, rgba(0,0,0,0.25) 0 18px, transparent 18px 36px),
    radial-gradient(ellipse at 30% 20%, #3b4f2c 0%, #1b2217 60%, #0f120d 100%);
}
.menu-inner { position: relative; width: min(560px, calc(100vw - 32px)); max-height: 100vh; overflow-y: auto; overflow-x: hidden; padding: 24px 8px; }
.logo { font-family: var(--title); font-weight: 400; margin: 0; line-height: 0.9; text-align: center; transform: rotate(-3deg); }
.logo span { display: block; font-size: clamp(64px, 16vw, 112px); color: var(--yellow); text-shadow: 5px 5px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; letter-spacing: 2px; }
.logo em { display: inline-block; font-style: normal; font-size: clamp(26px, 6vw, 40px); background: var(--red); color: #fff; padding: 2px 16px; margin-top: 8px; box-shadow: 4px 4px 0 #000; transform: rotate(2deg); }
.tagline { text-align: center; color: var(--muted); margin: 18px 0 20px; }
.panel { background: var(--panel); border: 2px solid #000; box-shadow: 6px 6px 0 rgba(0,0,0,0.6); padding: 20px; border-top: 4px solid var(--yellow); }
.panel h2 { font-family: var(--title); font-weight: 400; margin: 0 0 14px; color: var(--yellow); letter-spacing: 1px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.field input:not([type=range]), .field select, .join-code input {
  width: 100%; padding: 10px 12px; background: #0b0c0e; border: 2px solid #34363b; color: var(--text); border-radius: 0; outline: none;
}
.field input:focus, .join-code input:focus { border-color: var(--yellow); }
.field input[type=range] { width: 100%; accent-color: var(--yellow); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.colors button { width: 28px; height: 28px; border: 2px solid #000; cursor: pointer; padding: 0; }
.colors button.sel { outline: 3px solid #fff; outline-offset: 1px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.btn {
  flex: 1; min-width: 120px; padding: 12px 16px; background: var(--yellow); color: #000; border: 2px solid #000; cursor: pointer;
  font-family: var(--title); font-size: 16px; letter-spacing: 1px; box-shadow: 3px 3px 0 #000; transition: transform 0.06s;
}
.btn:hover { background: var(--yellow-2); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.btn.alt { background: #2b2d31; color: var(--text); }
.btn.alt:hover { background: #3a3d42; }
.btn.big { font-size: 20px; padding: 16px; }
.btn.small { font-family: var(--body); font-weight: 800; font-size: 13px; letter-spacing: 0; padding: 8px 10px; min-width: 0; }
.btn.link { background: none; border: none; box-shadow: none; color: var(--muted); font-family: var(--body); font-size: 14px; text-decoration: underline; flex: none; min-width: 0; padding: 8px 0 0; }
.btn.link:hover { color: var(--text); background: none; }
.join-code { display: flex; gap: 10px; margin-bottom: 16px; }
.join-code input { text-transform: uppercase; font-family: var(--title); font-size: 22px; letter-spacing: 6px; text-align: center; }
.join-code .btn { flex: none; }
.rooms-head { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.rooms { list-style: none; padding: 0; margin: 8px 0 14px; max-height: 260px; overflow-y: auto; }
.rooms li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: #0b0c0e; border: 1px solid #2a2c30; margin-bottom: 6px; cursor: pointer; }
.rooms li:hover { border-color: var(--yellow); }
.rooms li .rn { font-weight: 600; }
.rooms li .rm { color: var(--muted); font-size: 13px; }
.rooms li.empty { cursor: default; color: var(--muted); justify-content: center; }
.keys { width: 100%; border-collapse: collapse; font-size: 14px; }
.keys td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.keys td:first-child { font-family: var(--title); color: var(--yellow); white-space: nowrap; width: 1%; padding-right: 14px; font-size: 13px; }
.small { font-size: 13px; color: var(--muted); line-height: 1.5; }
.error { margin-top: 12px; padding: 10px 14px; background: #5a1512; border: 2px solid #000; color: #fff; }
.credits { text-align: center; color: #6f6d66; font-size: 12px; margin-top: 16px; }

.loader { text-align: center; }
.spin { width: 54px; height: 54px; margin: 0 auto 14px; border: 6px solid #333; border-top-color: var(--yellow); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading { background: #111; }
#loading p { font-family: var(--title); color: var(--yellow); }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; font-family: var(--body); }
#names { position: absolute; inset: 0; }
#damage-flash { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 40%, rgba(200,0,0,0.85) 100%); opacity: 0; transition: opacity 0.35s; }
.hud-tl { position: absolute; left: 16px; top: 16px; width: 240px; }
.bar { position: relative; height: 18px; background: rgba(0,0,0,0.65); border: 2px solid #000; margin-bottom: 5px; }
.bar > div { height: 100%; transition: width 0.15s; }
.bar.hp > div { background: linear-gradient(#6ee07a, #2e9c43); }
.bar.hp > div.low { background: linear-gradient(#ff6a5a, #b3261c); animation: pulse 0.6s infinite alternate; }
.bar.armor { height: 10px; }
.bar.armor > div { background: linear-gradient(#8fc7ff, #2d6fd0); }
.bar span { position: absolute; right: 6px; top: -1px; font-family: var(--title); font-size: 13px; text-shadow: 1px 1px 0 #000; }
@keyframes pulse { to { filter: brightness(1.4); } }
.weapon { display: flex; align-items: baseline; gap: 10px; margin-top: 6px; font-family: var(--title); text-shadow: 2px 2px 0 #000; }
#weapon-name { font-size: 18px; color: var(--yellow); }
#weapon-ammo { font-size: 22px; }
#weapon-slots { display: flex; gap: 3px; margin-top: 4px; }
#weapon-slots .slot { width: 22px; height: 22px; font-family: var(--title); font-size: 12px; display: grid; place-items: center; background: rgba(0,0,0,0.5); color: #555; border: 1px solid #000; }
#weapon-slots .slot.has { color: #ddd; }
#weapon-slots .slot.active { background: var(--yellow); color: #000; }
#powerups { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.pw { font-size: 13px; font-weight: 800; padding: 2px 8px; border: 2px solid #000; width: fit-content; text-shadow: 1px 1px 0 #000; }
.pw-speed { background: #b99400; } .pw-damage { background: #b0142c; } .pw-invis { background: #6a2fb0; }
.hud-tc { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); text-align: center; }
#timer { font-family: var(--title); font-size: 30px; text-shadow: 3px 3px 0 #000; }
#timer.urgent { color: var(--red); animation: pulse 0.5s infinite alternate; }
#score { font-weight: 800; font-size: 14px; text-shadow: 1px 1px 0 #000, 0 0 6px #000; }
.hud-tr { position: absolute; right: 16px; top: 16px; display: flex; flex-direction: column; align-items: flex-end; }
#minimap { width: 190px; height: 190px; border-radius: 50%; border: 3px solid #000; box-shadow: 0 0 0 2px rgba(242,194,0,0.8), 4px 4px 0 rgba(0,0,0,0.5); }
#killfeed { margin-top: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.kf { background: rgba(0,0,0,0.6); padding: 3px 8px; font-size: 14px; font-weight: 800; text-shadow: 1px 1px 0 #000; animation: slidein 0.2s; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
#street { position: absolute; right: 16px; bottom: 18px; font-family: var(--title); font-size: 18px; color: #fff; text-shadow: 2px 2px 0 #000; opacity: 0; text-align: right; max-width: 280px; }
#street.show { animation: street 4s forwards; }
@keyframes street { 0% { opacity: 0; transform: translateX(20px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0.35; } }
#bigtext { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-family: var(--title); font-size: clamp(40px, 8vw, 84px); opacity: 0; transform: scale(0.6); transition: opacity 0.2s, transform 0.25s cubic-bezier(.2,1.6,.4,1); text-shadow: 5px 5px 0 #000; color: var(--yellow); }
#bigtext.show { opacity: 1; transform: scale(1) rotate(-2deg); }
#bigtext.bad { color: var(--red); } #bigtext.good { color: var(--yellow); }
#smalltext { position: absolute; left: 0; right: 0; top: calc(30% + clamp(56px, 10vw, 110px)); text-align: center; font-weight: 800; font-size: 20px; text-shadow: 2px 2px 0 #000; opacity: 0; transition: opacity 0.2s; }
#smalltext.show { opacity: 1; }
#toasts { position: absolute; left: 50%; top: 88px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.toast { background: rgba(0,0,0,0.75); border-left: 4px solid var(--yellow); padding: 5px 14px; font-weight: 800; animation: toast 2.6s forwards; }
.toast.weapon { border-color: var(--yellow); } .toast.power { border-color: #7fe0ff; } .toast.bad { border-color: var(--red); } .toast.ped { border-color: #b01010; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
#hint { position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(0,0,0,0.7); padding: 6px 14px; font-weight: 600; font-size: 14px; border: 1px solid #000; white-space: nowrap; }
#vehicle-info { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,0.7); border: 2px solid #000; padding: 6px 14px; }
.vname { font-family: var(--title); color: var(--yellow); }
.vspeed { font-family: var(--title); font-size: 20px; min-width: 110px; text-align: right; }
.vhp { width: 90px; height: 8px; background: #300; border: 1px solid #000; }
.vhp-fill { height: 100%; background: #e0a030; }
#chat { position: absolute; left: 16px; bottom: 16px; width: min(420px, 60vw); }
#chat-log { max-height: 200px; overflow: hidden; display: flex; flex-direction: column; gap: 2px; opacity: 0.35; transition: opacity 0.4s; }
#chat-log.recent { opacity: 1; }
#chat-log .line { font-size: 14px; text-shadow: 1px 1px 0 #000, 0 0 4px #000; }
#chat-log .line .n { font-weight: 800; }
#chat-log .sys { color: #cfcac0; font-style: italic; }
#chat-input { pointer-events: auto; width: 100%; margin-top: 6px; padding: 8px 10px; background: rgba(0,0,0,0.8); border: 2px solid var(--yellow); color: #fff; outline: none; }
#scoreboard { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 2px solid #000; border-top: 4px solid var(--yellow); padding: 16px 20px; min-width: min(560px, 92vw); box-shadow: 6px 6px 0 rgba(0,0,0,0.5); }
.sb-title { font-family: var(--title); color: var(--yellow); font-size: 20px; margin-bottom: 8px; }
#scoreboard table { width: 100%; border-collapse: collapse; }
#scoreboard th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; padding: 4px 6px; border-bottom: 1px solid var(--line); }
#scoreboard td { padding: 5px 6px; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,0.05); }
#scoreboard tr.me td { background: rgba(242,194,0,0.12); }
#scoreboard .dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 1px solid #000; }
#scoreboard .ping { color: var(--muted); font-weight: 400; font-size: 13px; }
#bigmap { position: absolute; inset: 0; width: 100%; height: 100%; }
#roundend { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 2px solid #000; border-top: 4px solid var(--yellow); padding: 20px 28px; min-width: min(480px, 92vw); text-align: center; box-shadow: 6px 6px 0 rgba(0,0,0,0.5); }
#roundend h2 { font-family: var(--title); color: var(--yellow); font-size: 32px; margin: 0 0 12px; font-weight: 400; }
#roundend ol { text-align: left; padding-left: 24px; margin: 0 0 12px; }
#roundend li { padding: 4px 0; display: flex; justify-content: space-between; gap: 16px; }
#roundend li .n { font-weight: 800; }
#roundend li .s { color: var(--muted); font-size: 14px; }
#roundend li.me { background: rgba(242,194,0,0.12); }
#roundend .next { color: var(--muted); }
#pause { position: absolute; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.pause-box { background: var(--panel); border: 2px solid #000; border-top: 4px solid var(--yellow); padding: 20px; width: min(560px, calc(100vw - 32px)); max-height: 92vh; overflow-y: auto; box-shadow: 6px 6px 0 rgba(0,0,0,0.5); }
.pause-box h2 { font-family: var(--title); font-weight: 400; color: var(--yellow); margin: 0 0 14px; }
.pause-box h3 { font-family: var(--title); font-weight: 400; font-size: 15px; color: var(--yellow); margin: 18px 0 10px; }
.invite { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.invite span { color: var(--muted); font-size: 13px; text-transform: uppercase; }
.invite b { font-family: var(--title); font-size: 26px; letter-spacing: 4px; color: #fff; }
.invite .btn { flex: none; }
.hplayers { list-style: none; padding: 0; margin: 12px 0 0; }
.hplayers li { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: #0b0c0e; margin-bottom: 4px; }
.hplayers li .btn { flex: none; min-width: 0; padding: 4px 10px; font-size: 12px; background: var(--red); color: #fff; }

@media (max-width: 700px) {
  .hud-tl { width: 170px; }
  #minimap { width: 130px; height: 130px; }
  #street { font-size: 14px; }
  #hint { white-space: normal; text-align: center; width: 90vw; }
}
