:root {
  --bg: #0d0f12;
  --panel: rgba(16, 19, 24, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --text: #e9ecef;
  --muted: #9aa3ad;
  --accent: #f2b33d;
  --blue: #4d8dff;
  --red: #ff5a4d;
  --ice: #9fe8ff;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }

/* ── Screens ─────────────────────────────────────────────────────────────── */

.screen {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: max(16px, env(safe-area-inset-top)) 16px 24px;
}
#menu, #vote {
  background:
    radial-gradient(ellipse at 70% 20%, rgba(242, 179, 61, 0.12), transparent 55%),
    radial-gradient(ellipse at 20% 90%, rgba(77, 141, 255, 0.12), transparent 50%),
    linear-gradient(160deg, #15191f 0%, #0b0d10 100%);
}
#loadout, #pause, #matchend { background: rgba(8, 10, 13, 0.55); backdrop-filter: blur(3px); }
#menu, #pause, #matchend { justify-content: center; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.menu-panel { width: min(520px, 100%); display: flex; flex-direction: column; gap: 10px; }

.logo {
  margin: 0; font-size: clamp(44px, 11vw, 72px); letter-spacing: 0.18em; font-weight: 900; text-align: center;
  background: linear-gradient(180deg, #fff 20%, #9aa3ad 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo.win { background-image: linear-gradient(180deg, #ffe29a, #f2b33d); }
.logo.lose { background-image: linear-gradient(180deg, #ffb0a8, #c43b30); }
.tag { margin: -4px 0 6px; text-align: center; color: var(--muted); }
h2 { margin: 0; font-size: 26px; letter-spacing: 0.04em; }
h3 { margin: 10px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }

.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choices button, .menu-panel > button {
  flex: 1 1 0; min-width: 64px; padding: 11px 10px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 600;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.choices button small { font-weight: 400; color: var(--muted); font-size: 12px; }
.choices button:hover, .menu-panel > button:hover { background: rgba(255, 255, 255, 0.1); }
.choices button.on { border-color: var(--accent); background: rgba(242, 179, 61, 0.15); }
button:active { transform: scale(0.97); }
button.primary { background: var(--accent) !important; color: #1b1405; border: none; font-weight: 800; letter-spacing: 0.12em; }
button.primary:hover { filter: brightness(1.08); }
button.big { padding: 15px; font-size: 18px; border-radius: 12px; margin-top: 8px; }

.sens { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; margin-top: 4px; }
.sens input { flex: 1; accent-color: var(--accent); }

.help { color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; padding: 4px 0; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-top: 8px; }
.help-grid b { color: var(--text); }
.touch-help { margin: 10px 0 0; }

.screen-head {
  width: min(1100px, 100%); display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 14px;
}
.sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.timer {
  min-width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  font-size: 24px; font-weight: 800; border: 2px solid var(--accent); color: var(--accent); flex: none;
}
.hint { color: var(--muted); text-align: center; max-width: 640px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.cards { width: min(1100px, 100%); display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.card {
  text-align: left; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 12px;
  display: flex; flex-direction: column; gap: 6px; transition: border-color 0.15s, transform 0.15s, opacity 0.3s;
}
.card:hover { border-color: rgba(255, 255, 255, 0.3); }
.card-title { font-weight: 800; font-size: 18px; }
.card-text { color: var(--muted); font-size: 13px; line-height: 1.35; }
.map-card canvas { width: 100%; height: auto; border-radius: 8px; background: #111; }
.map-card.mine { border-color: var(--accent); }
.map-card.winner { border-color: var(--accent); transform: scale(1.03); box-shadow: 0 0 40px rgba(242, 179, 61, 0.35); }
.map-card.loser { opacity: 0.35; }
.votes { display: flex; align-items: center; gap: 8px; min-height: 26px; flex-wrap: wrap; }
.votes .count { font-size: 22px; font-weight: 900; min-width: 22px; }
.voters { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-style: normal; font-size: 11px; padding: 2px 7px; border-radius: 99px; font-weight: 600; }
.chip.blue { background: rgba(77, 141, 255, 0.22); color: #b9d2ff; }
.chip.red { background: rgba(255, 90, 77, 0.22); color: #ffc1bb; }

.loadout-cols { width: min(1100px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.loadout-col { display: flex; flex-direction: column; gap: 8px; }
.loadout-col h3 { margin: 0 0 2px; }
.weapon-card { padding: 10px 12px; gap: 4px; }
.weapon-card.on { border-color: var(--accent); background: linear-gradient(180deg, rgba(242, 179, 61, 0.12), var(--panel)); }
.weapon-card .card-title { font-size: 16px; }
.stat { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.stat b { height: 5px; background: rgba(255, 255, 255, 0.08); border-radius: 3px; overflow: hidden; }
.stat b i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.stat-note { font-size: 11px; color: var(--muted); margin-top: 2px; }
#deploy-btn { width: min(420px, 100%); margin-top: 18px; position: sticky; bottom: 12px; flex: none; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6); }

@media (max-width: 760px) {
  .loadout-cols { grid-template-columns: 1fr; }
  .weapon-card .card-text { display: none; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .map-card .card-text { display: none; }
  .map-card { padding: 8px; }
}

/* ── HUD ─────────────────────────────────────────────────────────────────── */

#hud { position: fixed; inset: 0; z-index: 2; pointer-events: none; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); }
#vignette, #frost, #flash, #scope { position: absolute; inset: 0; opacity: 0; }
#vignette { background: radial-gradient(ellipse at center, transparent 45%, rgba(170, 0, 0, 0.75) 100%); }
#frost {
  background:
    radial-gradient(ellipse at center, transparent 35%, rgba(159, 232, 255, 0.55) 85%, rgba(220, 248, 255, 0.9) 100%);
  mix-blend-mode: screen;
}
#flash { background: #fff; }
#scope { opacity: 1; background: radial-gradient(circle at center, transparent 0, transparent 34vmin, #000 34.3vmin); }
.scope-ring {
  position: absolute; left: 50%; top: 50%; width: 68vmin; height: 68vmin; transform: translate(-50%, -50%);
  border-radius: 50%; box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
  background:
    linear-gradient(#000, #000) center / 1.5px 100% no-repeat,
    linear-gradient(#000, #000) center / 100% 1.5px no-repeat;
}

#topbar {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
}
.score { font-size: 30px; font-weight: 900; min-width: 36px; text-align: center; }
.score.blue { color: var(--blue); }
.score.red { color: var(--red); }
.clock { text-align: center; background: rgba(0, 0, 0, 0.45); padding: 4px 14px; border-radius: 8px; }
#round-label { font-size: 10px; letter-spacing: 0.18em; color: var(--muted); }
#round-timer { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
#round-timer.low { color: var(--red); }
.pips { display: flex; gap: 3px; }
.pips i { width: 9px; height: 18px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); }
#pips-blue i.on { background: var(--blue); }
#pips-red i.on { background: var(--red); }

#killfeed { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 14px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.kf { background: rgba(0, 0, 0, 0.5); padding: 4px 10px; border-radius: 6px; font-size: 13px; transition: opacity 0.6s; }
.kf.fade { opacity: 0; }
.kf span { color: var(--muted); margin: 0 6px; }
.kf b.blue { color: var(--blue); }
.kf b.red { color: var(--red); }
.kf b.you { text-decoration: underline; }

#crosshair { --gap: 6px; position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
#crosshair i { position: absolute; background: rgba(255, 255, 255, 0.92); box-shadow: 0 0 2px #000; }
#crosshair .t, #crosshair .b { width: 2px; height: 9px; left: -1px; }
#crosshair .l, #crosshair .r { width: 9px; height: 2px; top: -1px; }
#crosshair .t { bottom: var(--gap); }
#crosshair .b { top: var(--gap); }
#crosshair .l { right: var(--gap); }
#crosshair .r { left: var(--gap); }
#crosshair .dot { width: 2px; height: 2px; left: -1px; top: -1px; }
#crosshair.ads .t, #crosshair.ads .b, #crosshair.ads .l, #crosshair.ads .r { opacity: 0.35; }

#hitmarker { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%) rotate(45deg); opacity: 0; }
#hitmarker.show { opacity: 1; }
#hitmarker::before, #hitmarker::after { content: ""; position: absolute; background: #fff; }
#hitmarker::before { left: 10px; top: 0; width: 2px; height: 22px; }
#hitmarker::after { top: 10px; left: 0; height: 2px; width: 22px; }
#hitmarker.head::before, #hitmarker.head::after { background: var(--accent); }
#hitmarker.kill::before, #hitmarker.kill::after { background: var(--red); }
#hitmarker.kill { width: 30px; height: 30px; }

#dmg-indicators { position: absolute; left: 50%; top: 50%; }
.dmg {
  position: absolute; left: -60px; top: -60px; width: 120px; height: 120px;
  animation: dmgfade 1.2s forwards;
}
.dmg::before {
  content: ""; position: absolute; left: 50%; top: -38px; width: 70px; height: 22px; transform: translateX(-50%);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0; border-top: 5px solid rgba(255, 50, 40, 0.9);
}
@keyframes dmgfade { from { opacity: 1; } to { opacity: 0; } }

#banner { position: absolute; left: 0; right: 0; top: 26%; text-align: center; }
#banner-big { font-size: clamp(34px, 7vw, 60px); font-weight: 900; letter-spacing: 0.14em; }
#banner-small { color: var(--muted); font-size: 16px; margin-top: 4px; }
#spectate { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(0, 0, 0, 0.5); padding: 6px 14px; border-radius: 8px; font-size: 14px; }
#click-to-play {
  position: absolute; left: 50%; top: 60%; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6); padding: 10px 20px; border-radius: 10px; font-weight: 700; letter-spacing: 0.1em;
}

#health { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); width: 220px; }
.hp-num { font-size: 40px; font-weight: 900; line-height: 1; }
.hp-bar { height: 8px; background: rgba(255, 255, 255, 0.15); border-radius: 4px; overflow: hidden; margin-top: 4px; }
#hp-fill { height: 100%; background: linear-gradient(90deg, #7ad66f, #b3ee8e); transition: width 0.15s; }
#hp-fill.low { background: linear-gradient(90deg, #d13a2f, #ff6b5d); }
#status-tags { display: flex; gap: 6px; margin-top: 6px; }
#status-tags i { font-style: normal; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 4px; letter-spacing: 0.1em; }
#status-tags .ice { background: rgba(159, 232, 255, 0.25); color: var(--ice); }
#status-tags .burn { background: rgba(255, 120, 30, 0.3); color: #ffb070; }

#ammo { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); text-align: right; }
.weapon-name { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.ammo-count { font-size: 40px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.ammo-count small { font-size: 18px; color: var(--muted); margin-left: 6px; font-weight: 600; }
#ammo-mag.low { color: var(--red); }
.reload-bar { height: 4px; width: 160px; margin: 6px 0 0 auto; background: rgba(255, 255, 255, 0.15); border-radius: 2px; overflow: hidden; }
#reload-fill { height: 100%; background: var(--accent); }
.slots { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.slots .slot { background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 12px; color: var(--muted); }
.slots .slot small { color: var(--accent); margin-right: 5px; font-weight: 800; }
.slots .slot.on { color: var(--text); border-color: var(--accent); }
.slots .slot.empty { opacity: 0.35; }

/* ── Scoreboard ──────────────────────────────────────────────────────────── */

#scoreboard { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; pointer-events: none; padding: 16px; }
#scoreboard .panel { width: min(720px, 100%); }
#sb-title { font-size: 18px; margin-bottom: 12px; text-align: center; }
.sb-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.sb { width: 100%; border-collapse: collapse; font-size: 14px; }
.sb th { text-align: left; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; padding: 4px 6px; }
.sb.blue th:first-child { color: var(--blue); }
.sb.red th:first-child { color: var(--red); }
.sb td { padding: 5px 6px; border-top: 1px solid var(--line); }
.sb td:not(:first-child), .sb th:not(:first-child) { text-align: right; width: 34px; }
.sb tr.dead td { opacity: 0.4; text-decoration: line-through; }
.sb tr.you td:first-child { color: var(--accent); font-weight: 700; }

.me-score { text-align: center; font-size: 44px; font-weight: 900; }
.me-score .blue { color: var(--blue); }
.me-score .red { color: var(--red); }
.me-stats { text-align: center; color: var(--muted); line-height: 1.6; }
.me-stats b { color: var(--text); }
.me-stats b.blue { color: var(--blue); }
.me-stats b.red { color: var(--red); }

#loading {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  background: rgba(8, 10, 13, 0.85); font-size: 20px; letter-spacing: 0.1em;
}

/* ── Touch controls ──────────────────────────────────────────────────────── */

body.touch, body.touch #scene canvas { touch-action: none; -webkit-user-select: none; -webkit-touch-callout: none; }
body.touch .help-grid { display: none; }
#touch-ui { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#stick-zone { position: absolute; left: 0; top: 18%; bottom: 0; width: 45%; pointer-events: auto; }
#look-zone { position: absolute; right: 0; top: 18%; bottom: 0; width: 55%; pointer-events: auto; }
#stick-base {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.25);
}
#stick-knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); }
.tb {
  pointer-events: auto; border: 1px solid rgba(255, 255, 255, 0.3); background: rgba(10, 12, 15, 0.45);
  border-radius: 50%; width: 58px; height: 58px; font-size: 11px; font-weight: 800; letter-spacing: 0.05em;
  -webkit-tap-highlight-color: transparent; touch-action: none; color: #fff;
}
.tb.down, .tb.on { background: rgba(242, 179, 61, 0.45); border-color: var(--accent); }
.tb.fire {
  position: absolute; right: calc(max(16px, env(safe-area-inset-right)) + 70px); bottom: calc(max(16px, env(safe-area-inset-bottom)) + 120px);
  width: 86px; height: 86px; font-size: 15px; background: rgba(200, 50, 40, 0.45); border-color: rgba(255, 120, 110, 0.7);
}
.tb.fire.down { background: rgba(255, 70, 50, 0.7); }
#touch-buttons {
  position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: calc(max(16px, env(safe-area-inset-bottom)) + 110px);
  display: grid; grid-template-columns: 58px; gap: 8px;
}
#touch-slots { position: absolute; right: calc(max(12px, env(safe-area-inset-right)) + 160px); bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 6px; }
.tb.slot { border-radius: 10px; width: 62px; height: 40px; font-size: 10px; }
#touch-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); display: flex; gap: 8px; }
.tb.small { width: 42px; height: 42px; font-size: 16px; }
body.touch #health { width: 150px; bottom: auto; top: calc(max(10px, env(safe-area-inset-top)) + 54px); }
body.touch .hp-num { font-size: 26px; }
body.touch #ammo { bottom: auto; right: auto; left: max(16px, env(safe-area-inset-left)); top: calc(max(10px, env(safe-area-inset-top)) + 100px); text-align: left; }
body.touch .reload-bar { margin: 6px 0 0; }
body.touch .ammo-count { font-size: 26px; }
body.touch .slots { display: none; }
body.touch #killfeed { top: calc(max(10px, env(safe-area-inset-top)) + 140px); }
body.touch .kf { font-size: 11px; }
body.touch #spectate { bottom: auto; top: 40%; }
@media (max-height: 460px) {
  body.touch .score { font-size: 22px; }
  body.touch #round-timer { font-size: 16px; }
  #touch-buttons { grid-template-columns: 58px 58px; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 56px); }
  .tb.fire { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 56px); right: calc(max(16px, env(safe-area-inset-right)) + 136px); }
  #touch-slots { right: calc(max(12px, env(safe-area-inset-right)) + 240px); }
}
