:root {
  --sand: #d8bf8a;
  --sand-dim: #9c8659;
  --ink: #16110c;
  --panel: rgba(22, 17, 12, 0.78);
  --amber: #f2b33d;
  --red: #c8483b;
  --blue: #4a7fd1;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--sand);
  overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-text-size-adjust: 100%;
}

#app { position: fixed; inset: 0; overflow: hidden; }
#gl, #plan-overlay, #touch-layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#plan-overlay { z-index: 3; }
#touch-layer { z-index: 4; }
.hidden { display: none !important; }

button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r)) calc(24px + var(--safe-b)) calc(20px + var(--safe-l));
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 44, 26, 0.75), rgba(14, 10, 7, 0.96) 70%);
  overflow-y: auto; touch-action: pan-y;
}
#screen-menu { background: radial-gradient(ellipse at 50% 35%, rgba(40, 28, 16, 0.3), rgba(14, 10, 7, 0.88) 78%); }
#screen-pause { z-index: 30; }
#screen-help { z-index: 35; }
.screen h2 { margin: 0; font-size: 26px; letter-spacing: 3px; text-transform: uppercase; color: var(--amber); }
.logo { width: min(64vw, 300px); height: auto; filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.6)); }
.tagline { margin: -6px 0 6px; letter-spacing: 4px; text-transform: uppercase; font-size: 13px; color: var(--sand-dim); }
.foot { position: absolute; bottom: calc(10px + var(--safe-b)); font-size: 11px; opacity: 0.5; letter-spacing: 1px; margin: 0; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; width: min(84vw, 320px); }
.btn {
  border: 1px solid rgba(216, 191, 138, 0.35); background: rgba(216, 191, 138, 0.08); padding: 14px 18px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: 2px; font-weight: 700; font-size: 15px;
}
.btn:active { transform: translateY(1px); background: rgba(216, 191, 138, 0.18); }
.btn.primary { background: linear-gradient(180deg, #c99b45, #9a6e27); color: #1b130a; border-color: #e4bb68; box-shadow: 0 4px 0 #5e4116; }
.btn.primary:active { box-shadow: 0 2px 0 #5e4116; }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: 0.4; }

.field { display: flex; flex-direction: column; gap: 6px; width: min(84vw, 320px); font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--sand-dim); }
.field input[type="text"], .field input:not([type]) , .field input[maxlength] {
  font: inherit; font-size: 18px; letter-spacing: 1px; text-transform: none; color: var(--sand); background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(216, 191, 138, 0.3); border-radius: 6px; padding: 12px; user-select: text; -webkit-user-select: text;
}
.field em { font-style: normal; color: var(--amber); float: right; }
.field input[type="range"] { width: 100%; accent-color: var(--amber); }
.toggle { display: flex; gap: 12px; align-items: center; width: min(84vw, 320px); font-size: 14px; line-height: 1.3; }
.toggle input { width: 22px; height: 22px; accent-color: var(--amber); flex: none; }

.help { width: min(88vw, 420px); padding-left: 20px; margin: 0; line-height: 1.45; font-size: 15px; }
.help li { margin-bottom: 10px; }
.help b { color: var(--amber); }
.hint-desktop { width: min(88vw, 420px); font-size: 12px; opacity: 0.6; margin: 0; }

.loadbar { width: min(60vw, 260px); height: 6px; background: rgba(255, 255, 255, 0.08); border-radius: 3px; overflow: hidden; }
.loadbar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width 0.2s; }
#load-text { font-size: 12px; letter-spacing: 2px; text-transform: uppercase; opacity: 0.7; margin: 0; }

/* ---------- HUD (CS 1.6-style amber numerals) ---------- */
#hud { position: absolute; inset: 0; z-index: 5; pointer-events: none; color: var(--amber); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
.hud-top { position: absolute; top: calc(6px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 6px; }
.scorebar { display: flex; align-items: stretch; gap: 2px; background: var(--panel); border-radius: 6px; padding: 4px 6px; }
.scorebar .team { display: flex; flex-direction: column; align-items: center; min-width: 40px; font-weight: 800; font-size: 20px; }
.scorebar .team.red { color: #ec7462; }
.scorebar .team.blue { color: #7aa7f0; }
.scorebar .dots { display: flex; gap: 2px; margin-top: 2px; }
.scorebar .dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.scorebar .dots i.dead { opacity: 0.2; }
.scorebar .clock { display: flex; flex-direction: column; align-items: center; padding: 0 10px; }
.clock span { font-size: 9px; letter-spacing: 2px; text-transform: uppercase; color: var(--sand-dim); white-space: nowrap; }
.clock b { font-size: 22px; font-variant-numeric: tabular-nums; }
.top-right { justify-self: end; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.money { font-weight: 800; font-size: 18px; color: #8fd16a; background: var(--panel); border-radius: 6px; padding: 4px 8px; }
.money.off { visibility: hidden; }
.leave-btn { pointer-events: auto; width: 36px; height: 36px; border-radius: 8px; border: 0; background: var(--panel); display: grid; place-items: center; padding: 0; }
.leave-btn svg { width: 16px; height: 16px; fill: var(--sand); }
.hud-top .scorebar { grid-column: 2; }
.hud-top .top-right { grid-column: 3; }
#killfeed { position: absolute; left: 0; top: 56px; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; font-size: 11px; max-width: 72vw; }
#killfeed div { background: var(--panel); border-radius: 4px; padding: 3px 6px; color: var(--sand); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: fadeout 5s forwards; }
#killfeed .r { color: #ec7462; }
#killfeed .b { color: #7aa7f0; }
#killfeed .me { outline: 1px solid var(--amber); }
#killfeed img { height: 12px; width: auto; vertical-align: -2px; margin: 0 2px; }
#killfeed em { font-style: normal; font-weight: 800; color: #ff7a5a; }
@keyframes fadeout { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#crosshair { position: absolute; left: 50%; top: var(--cross-y, 44%); width: 0; height: 0; }
#crosshair i { position: absolute; background: #6cff6c; box-shadow: 0 0 2px #000; }
#crosshair i:nth-child(1), #crosshair i:nth-child(2) { width: 2px; height: 9px; left: -1px; }
#crosshair i:nth-child(3), #crosshair i:nth-child(4) { height: 2px; width: 9px; top: -1px; }
#crosshair i:nth-child(1) { top: calc(-9px - var(--gap, 4px)); }
#crosshair i:nth-child(2) { top: var(--gap, 4px); }
#crosshair i:nth-child(3) { left: calc(-9px - var(--gap, 4px)); }
#crosshair i:nth-child(4) { left: var(--gap, 4px); }
#crosshair.on-target i { background: #ff4a3d; }
#hitmarker { position: absolute; left: 50%; top: var(--cross-y, 44%); width: 22px; height: 22px; margin: -11px 0 0 -11px; opacity: 0;
  background: linear-gradient(45deg, transparent 45%, #fff 45%, #fff 55%, transparent 55%), linear-gradient(-45deg, transparent 45%, #fff 45%, #fff 55%, transparent 55%);
  -webkit-mask: radial-gradient(circle, transparent 5px, #000 6px); mask: radial-gradient(circle, transparent 5px, #000 6px); }
#hitmarker.show { animation: hm 0.18s ease-out; }
#hitmarker.head { filter: hue-rotate(-50deg) saturate(4) brightness(1.2); }
@keyframes hm { 0% { opacity: 1; transform: scale(1.3); } 100% { opacity: 0; transform: scale(1); } }
#dmg-indicator { position: absolute; left: 50%; top: var(--cross-y, 44%); width: 160px; height: 160px; margin: -80px 0 0 -80px; opacity: 0;
  border-radius: 50%; border-top: 6px solid rgba(220, 40, 30, 0.85); }
#dmg-indicator.show { animation: dmgfade 0.9s ease-out forwards; }
@keyframes dmgfade { 0% { opacity: 1; } 100% { opacity: 0; } }
#vignette { position: absolute; inset: 0; box-shadow: inset 0 0 90px 30px rgba(170, 0, 0, 0.7); opacity: 0; transition: opacity 0.3s; }

#plant-bar { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); width: min(60vw, 260px); text-align: center; font-weight: 700; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; }
#plant-bar div { margin-top: 4px; height: 8px; background: rgba(0, 0, 0, 0.5); border-radius: 4px; overflow: hidden; }
#plant-bar i { display: block; height: 100%; width: 0; background: #ec7462; }
#center-msg { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); font-size: 15px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; background: var(--panel); padding: 8px 14px; border-radius: 6px; white-space: nowrap; }

#route-info { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(118px + var(--safe-b)); display: flex; gap: 8px; align-items: center; font-size: 12px; letter-spacing: 1px; color: var(--sand); white-space: nowrap; }
#route-next { background: var(--panel); padding: 4px 8px; border-radius: 4px; }
#hold-badge { background: var(--amber); color: #1b130a; font-weight: 800; padding: 4px 8px; border-radius: 4px; letter-spacing: 2px; }

.hud-bottom { position: absolute; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); display: flex; justify-content: space-between; align-items: flex-end; }
.vitals { display: flex; flex-direction: column; gap: 4px; background: var(--panel); border-radius: 8px; padding: 6px 10px; }
.vitals > div { display: flex; align-items: center; gap: 6px; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.vitals svg { width: 20px; height: 20px; fill: currentColor; }
.vitals .armor { font-size: 18px; opacity: 0.9; }
.vitals.low .hp { color: #ff5a4a; animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.weapon-box { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-right: 96px; pointer-events: auto; }
.weapon-btn { background: var(--panel); border: 0; border-radius: 8px; padding: 4px 8px; height: 44px; display: flex; align-items: center; }
.weapon-btn img { height: 32px; width: auto; max-width: 110px; object-fit: contain; }
.ammo { background: var(--panel); border: 0; border-radius: 8px; padding: 4px 10px; color: var(--amber); display: flex; align-items: baseline; gap: 4px; }
.ammo b { font-size: 26px; font-variant-numeric: tabular-nums; }
.ammo span { font-size: 14px; opacity: 0.85; }
.ammo.reloading b { opacity: 0.4; }
.fire-btn {
  position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); width: 86px; height: 86px; border-radius: 50%;
  border: 2px solid rgba(242, 179, 61, 0.7); background: radial-gradient(circle at 40% 35%, rgba(200, 72, 59, 0.75), rgba(90, 20, 14, 0.75));
  color: #ffe2b0; font-weight: 800; letter-spacing: 2px; font-size: 14px; pointer-events: auto; touch-action: none;
}
.fire-btn.active { transform: scale(0.94); background: radial-gradient(circle at 40% 35%, rgba(255, 110, 80, 0.9), rgba(140, 30, 20, 0.9)); }

/* ---------- plan phase ---------- */
#screen-plan { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.plan-top { position: absolute; top: calc(8px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); display: flex; gap: 10px; align-items: center; background: var(--panel); border-radius: 8px; padding: 8px 12px; }
.plan-title { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.plan-title b { color: var(--amber); text-transform: uppercase; letter-spacing: 2px; font-size: 15px; }
.plan-title span { font-size: 12px; opacity: 0.8; line-height: 1.3; }
.plan-timer { display: flex; flex-direction: column; align-items: center; min-width: 54px; }
.plan-timer b { font-size: 26px; color: var(--amber); font-variant-numeric: tabular-nums; }
.plan-timer .bar { width: 54px; height: 4px; background: rgba(255, 255, 255, 0.1); border-radius: 2px; overflow: hidden; }
.plan-timer .bar i { display: block; height: 100%; background: var(--amber); width: 100%; }
.plan-bottom { position: absolute; bottom: calc(10px + var(--safe-b)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
#plan-summary { background: var(--panel); border-radius: 8px; padding: 8px 12px; font-size: 13px; line-height: 1.35; }
#plan-summary b { color: var(--amber); }
#plan-summary .dim { opacity: 0.7; font-size: 12px; }
.plan-actions { display: flex; gap: 10px; }
.plan-actions .btn { flex: 1; }
.plan-actions .btn.primary { flex: 2; }

/* ---------- round end / over ---------- */
#screen-roundend { position: absolute; inset: 0; z-index: 7; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.banner { display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--panel); padding: 14px 26px; border-radius: 10px; border-top: 3px solid var(--amber); animation: pop 0.3s ease-out; }
.banner b { font-size: 28px; letter-spacing: 3px; text-transform: uppercase; color: var(--amber); }
.banner span { font-size: 14px; letter-spacing: 1px; }
.banner.red { border-color: var(--red); }
.banner.red b { color: #ec7462; }
.banner.blue { border-color: var(--blue); }
.banner.blue b { color: #7aa7f0; }
@keyframes pop { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.big-score { font-size: 42px; font-weight: 800; margin: 0; color: var(--sand); }
.scoreboard { width: min(92vw, 420px); border-collapse: collapse; font-size: 14px; }
.scoreboard td, .scoreboard th { padding: 6px 8px; text-align: left; border-bottom: 1px solid rgba(216, 191, 138, 0.12); }
.scoreboard th { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--sand-dim); }
.scoreboard td.num, .scoreboard th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scoreboard tr.red td:first-child { color: #ec7462; }
.scoreboard tr.blue td:first-child { color: #7aa7f0; }
.scoreboard tr.me td { background: rgba(242, 179, 61, 0.1); }

#toast { position: absolute; z-index: 40; left: 50%; bottom: calc(140px + var(--safe-b)); transform: translateX(-50%); background: var(--panel); padding: 8px 14px; border-radius: 6px; font-size: 13px; pointer-events: none; }

@media (min-aspect-ratio: 4/3) {
  .weapon-box { margin-right: 110px; }
}
