:root {
  --ink: #ffffff;
  --ink-2: rgba(255, 255, 255, 0.82);
  --panel: rgba(13, 27, 42, 0.55);
  --panel-solid: #12263b;
  --line: rgba(255, 255, 255, 0.22);
  --gold: #ffcf3d;
  --hot: #ff5a3c;
  --display: "Lilita One", "Arial Black", sans-serif;
  --sans: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pad: clamp(12px, 2vw, 22px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d1b2a; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ------------------------------------------------------------------ HUD */
.hud { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 500ms var(--ease); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45); }
.hud.live { opacity: 1; }
.hud button { pointer-events: auto; }

.clock { position: absolute; top: var(--pad); left: 50%; transform: translateX(-50%); padding: 6px 18px; border-radius: 999px; background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font: 400 26px/1 var(--display); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.clock.low { color: var(--hot); }

.feed { position: absolute; top: var(--pad); left: var(--pad); display: grid; gap: 6px; width: min(340px, 44vw); }
.feed div { padding: 5px 10px; border-radius: 10px; background: var(--panel); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: 13px; font-weight: 800; animation: feedIn 300ms var(--ease) both; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed div.me { background: rgba(255, 90, 60, 0.6); }
.feed .w { opacity: 0.75; font-weight: 600; margin: 0 4px; }
@keyframes feedIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

.board { position: absolute; top: calc(var(--pad) + 46px); right: var(--pad); margin: 0; padding: 8px; list-style: none; border-radius: 14px; background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); min-width: 190px; font-size: 13px; font-weight: 800; }
.board li { display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; align-items: center; padding: 3px 6px; border-radius: 8px; }
.board li.me { background: rgba(255, 207, 61, 0.25); }
.board .rk { opacity: 0.6; font-size: 11px; }
.board .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .sc { font: 400 16px var(--display); color: var(--gold); }
.board .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

.tools { position: absolute; top: var(--pad); right: var(--pad); display: flex; gap: 6px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 12px; background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: background 200ms; }
.icon-btn:hover { background: rgba(13, 27, 42, 0.8); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg path:first-child { fill: currentColor; }
#btnLeave svg path:first-child { fill: none; }
#btnSound .mute, #btnSound.off .wave { display: none; }
#btnSound.off .mute { display: inline; }

.health { position: absolute; left: 50%; bottom: calc(var(--pad) + 92px + env(safe-area-inset-bottom)); width: 220px; height: 8px; transform: translateX(-50%); border-radius: 999px; background: rgba(0, 0, 0, 0.35); overflow: hidden; opacity: 0; transition: opacity 300ms; }
.health.show { opacity: 1; }
.health i { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, #ff5a3c, #ffcf3d 60%, #7be36b); transition: width 150ms; }

.weapon { position: absolute; left: 50%; bottom: calc(var(--pad) + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 10px; border-radius: 18px; background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); min-width: 250px; border: 1px solid var(--line); transition: transform 300ms var(--ease), border-color 300ms; }
.weapon.has { border-color: rgba(255, 207, 61, 0.7); box-shadow: 0 0 0 1px rgba(255, 207, 61, 0.3), 0 0 30px rgba(255, 160, 60, 0.25); }
.weapon.rolling .w-icon { animation: roll 90ms linear infinite; }
.weapon.got { animation: pop 450ms var(--ease); }
@keyframes roll { 50% { transform: translateY(-3px) rotate(8deg); } }
@keyframes pop { 0% { transform: translateX(-50%) scale(1); } 40% { transform: translateX(-50%) scale(1.12); } 100% { transform: translateX(-50%) scale(1); } }
.w-icon { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 14px; background: rgba(255, 255, 255, 0.1); }
.w-icon svg { width: 38px; height: 38px; }
.w-text { display: grid; }
.w-text b { font: 400 20px/1.1 var(--display); letter-spacing: 0.02em; }
.w-text span { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.w-ammo { margin-left: auto; display: flex; gap: 4px; }
.w-ammo i { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px rgba(255, 207, 61, 0.8); }

.center-msg { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); text-align: center; font: 400 clamp(28px, 5vw, 54px)/1.1 var(--display); letter-spacing: 0.02em; opacity: 0; transition: opacity 250ms, transform 400ms var(--ease); white-space: nowrap; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25), 0 6px 24px rgba(0, 0, 0, 0.4); }
.center-msg.show { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
.center-msg small { display: block; margin-top: 6px; font: 800 15px var(--sans); letter-spacing: 0.06em; opacity: 0.85; }
.center-msg.bad { color: #ffd0c4; }
.center-msg.good { color: var(--gold); }

.keys { position: absolute; left: var(--pad); bottom: calc(var(--pad) + env(safe-area-inset-bottom)); font-size: 11px; font-weight: 800; letter-spacing: 0.06em; opacity: 0.75; }

/* touch controls */
.stick, .tbtn { display: none; pointer-events: auto; }
.touch .stick { display: block; position: absolute; left: calc(var(--pad) + 10px); bottom: calc(var(--pad) + 20px + env(safe-area-inset-bottom)); width: 130px; height: 130px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.25); }
.stick i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: rgba(255, 255, 255, 0.4); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
.touch .tbtn { display: grid; place-items: center; position: absolute; right: calc(var(--pad) + 10px); border: 2px solid rgba(255, 255, 255, 0.35); border-radius: 50%; font: 400 16px var(--display); letter-spacing: 0.06em; }
.touch .tbtn.fire { bottom: calc(var(--pad) + 30px + env(safe-area-inset-bottom)); width: 92px; height: 92px; background: rgba(255, 90, 60, 0.55); }
.touch .tbtn.drift { bottom: calc(var(--pad) + 140px + env(safe-area-inset-bottom)); width: 64px; height: 64px; background: rgba(13, 27, 42, 0.55); font-size: 12px; }
.touch .tbtn.on { filter: brightness(1.3); transform: scale(0.95); }
.touch .keys { display: none; }
.touch .weapon { bottom: auto; top: calc(var(--pad) + 46px); left: var(--pad); transform: none; min-width: 0; padding: 6px 10px 6px 6px; gap: 8px; }
.touch .weapon.got { animation: none; }
.touch .w-text { display: none; }
.touch .w-ammo { flex-direction: column; }
.touch .feed { top: calc(var(--pad) + 110px); }
.touch .w-icon { width: 40px; height: 40px; }
.touch .w-icon svg { width: 30px; height: 30px; }
.touch .health { bottom: auto; top: calc(var(--pad) + 110px); }

/* ------------------------------------------------------------------ overlays */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at center, rgba(13, 27, 42, 0.25), rgba(13, 27, 42, 0.75)); opacity: 0; visibility: hidden; transition: opacity 400ms var(--ease), visibility 0s 400ms; overflow-y: auto; }
.overlay.show { opacity: 1; visibility: visible; transition: opacity 400ms var(--ease); }

.menu { display: grid; justify-items: center; text-align: center; gap: 14px; width: min(560px, 100%); }
.logo { margin: 0; display: flex; gap: 14px; font: 400 clamp(54px, 11vw, 104px)/0.95 var(--display); letter-spacing: 0.02em; }
.logo span:first-child { color: #fff; text-shadow: 0 6px 0 #d8352a, 0 14px 30px rgba(0, 0, 0, 0.45); }
.logo span:last-child { color: var(--gold); text-shadow: 0 6px 0 #c76a12, 0 14px 30px rgba(0, 0, 0, 0.45); }
.tag { margin: -4px 0 6px; font-size: 16px; font-weight: 800; color: var(--ink-2); }
.name { display: grid; gap: 6px; font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.name input { width: 240px; padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px; background: rgba(13, 27, 42, 0.6); color: #fff; font: 800 18px var(--sans); text-align: center; outline: none; transition: border-color 200ms; }
.name input:focus { border-color: var(--gold); }
.chars { display: grid; grid-template-columns: repeat(9, 1fr); gap: 8px; width: 100%; }
.chars button { position: relative; aspect-ratio: 1; padding: 0; border: 3px solid transparent; border-radius: 16px; background: rgba(255, 255, 255, 0.1); overflow: hidden; transition: transform 250ms var(--ease), border-color 200ms, background 200ms; }
.chars button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chars button:hover { transform: translateY(-3px); background: rgba(255, 255, 255, 0.18); }
.chars button.sel { border-color: var(--gold); background: rgba(255, 207, 61, 0.25); transform: translateY(-3px); }
.chars button span { position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 0; font-size: 10px; font-weight: 900; background: rgba(0, 0, 0, 0.45); }
.play { margin-top: 6px; min-width: 240px; height: 60px; border: 0; border-radius: 999px; background: linear-gradient(180deg, #ffde5a, #ffb423); color: #4a2400; font: 400 30px var(--display); letter-spacing: 0.06em; box-shadow: 0 6px 0 #c76a12, 0 16px 30px rgba(0, 0, 0, 0.35); transition: transform 200ms var(--ease), box-shadow 200ms var(--ease), filter 200ms; }
.play:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: 0 8px 0 #c76a12, 0 20px 36px rgba(0, 0, 0, 0.4); }
.play:active { transform: translateY(4px); box-shadow: 0 2px 0 #c76a12, 0 8px 16px rgba(0, 0, 0, 0.35); }
.play:disabled { filter: grayscale(0.6) brightness(0.8); cursor: default; transform: none; }
.online { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.online b { color: #7be36b; }
.loading { margin: 0; font-size: 12px; color: var(--ink-2); }
.loading:empty { display: none; }

.card { width: min(420px, 100%); padding: 22px; border-radius: 22px; background: rgba(18, 38, 59, 0.88); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); text-align: center; }
.eyebrow { font-size: 11px; font-weight: 900; letter-spacing: 0.2em; color: var(--ink-2); }
.card h2 { margin: 4px 0 14px; font: 400 38px var(--display); color: var(--gold); }
.results { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; text-align: left; }
.results li { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-weight: 800; }
.results li.me { background: rgba(255, 207, 61, 0.22); }
.results .rk { font: 400 18px var(--display); text-align: center; }
.results .k { font: 400 18px var(--display); color: var(--gold); }
.results .d { font-size: 12px; opacity: 0.7; }
.next { margin: 14px 0 0; font-weight: 800; color: var(--ink-2); }

@media (max-width: 640px) {
  .chars { grid-template-columns: repeat(5, 1fr); }
  .board { min-width: 150px; font-size: 12px; }
  .feed { width: 54vw; }
  .feed div { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .hud, .overlay, .center-msg, .weapon { transition-duration: 1ms; animation: none !important; }
}
