/* ===================== base ===================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --panel: #1c2230;
  --card: #232b3b;
  --line: #313a4d;
  --text: #e6edf3;
  --muted: #8b97a8;
  --accent: #5cc8ff;
  --accent2: #2f81f7;
  --red: #e0443e;
  --blue: #3e7be0;
  --green: #39d98a;
  --gold: #f4c430;
}

html, body {
  height: 100%;
  background: #0b0908;
  color: var(--text);
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  overflow: hidden;
}

button, input, select { font-family: inherit; }

/* persistent 3D canvas, behind every screen */
#game-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  background: #0b0908;
}

/* ===================== screens ===================== */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* home is an opaque menu that covers the canvas */
#screen-home {
  z-index: 30;
  overflow-y: auto;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1d2740 0%, transparent 60%),
    var(--bg);
}

/* lobby + game are transparent HUD layers over the 3D world */
.overlay-screen {
  z-index: 10;
  background: transparent;
  pointer-events: none;
}

.panel {
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 24px 60px;
}

.logo {
  font-size: 54px;
  font-weight: 800;
  letter-spacing: 4px;
  text-align: center;
  color: var(--text);
}
.logo span { color: var(--accent); }

.tagline {
  text-align: center;
  color: var(--muted);
  margin: 8px 0 28px;
}

/* ===================== cards / fields ===================== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.card h2 {
  font-size: 16px;
  margin-bottom: 14px;
  color: var(--text);
}

.field { display: block; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent2);
}
#input-code { text-transform: uppercase; letter-spacing: 4px; }

/* ===================== buttons ===================== */
.btn {
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  width: 100%;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent2), #1f6ad6);
  border-color: #1f6ad6;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ===================== home layout ===================== */
.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.lobby-list-card { margin-bottom: 16px; }

.lobby-list { display: flex; flex-direction: column; gap: 8px; }
.lobby-list .empty { color: var(--muted); font-size: 14px; }

.lobby-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  gap: 12px;
}
.lobby-row .lr-code { font-weight: 700; letter-spacing: 2px; color: var(--accent); }
.lobby-row .lr-meta { color: var(--muted); font-size: 13px; flex: 1; }
.lobby-row .lr-tag {
  font-size: 11px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.lobby-row .lr-tag.playing { color: var(--gold); border-color: var(--gold); }
.lobby-row .lr-tag.open { color: var(--green); border-color: var(--green); }
.lobby-row button { width: auto; padding: 7px 14px; }

/* ===================== lobby panel (in-world HUD) ===================== */
.lobby-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 340px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  pointer-events: auto;
  background: rgba(13, 17, 23, .93);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
}
.lobby-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.lobby-title { font-weight: 800; letter-spacing: 3px; color: var(--accent); }
.lobby-code-chip {
  font-weight: 800;
  letter-spacing: 4px;
  font-size: 20px;
  color: var(--gold);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 10px;
}
.lobby-section { margin-bottom: 14px; }
.lobby-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 8px;
}
.lobby-section select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
}

.player-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 14px;
}
.player-list li .host-badge {
  font-size: 10px;
  background: var(--gold);
  color: #1a1a1a;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}
.player-list li .you-badge {
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 1px 5px;
  border-radius: 4px;
}
.mode-desc { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; }
.walk-hint { margin-top: 12px; text-align: center; color: var(--accent); }
.lobby-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}
.error-msg {
  color: var(--red);
  text-align: center;
  margin-top: 8px;
  min-height: 18px;
  font-size: 13px;
}
#home-error { min-height: 20px; margin-top: 14px; }

/* ===================== game HUD ===================== */
.hud { position: absolute; inset: 0; pointer-events: none; font-size: 14px; }

.crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%);
}
.crosshair::before, .crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255,255,255,.85);
  box-shadow: 0 0 2px #000;
}
.crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
.crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }
.crosshair.cooldown::before, .crosshair.cooldown::after { background: rgba(255,90,90,.9); }
.crosshair.hidden { display: none; }

.hud-top {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  text-align: center;
}
.hud-timer {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 2px 6px #000;
}
.hud-timer.urgent { color: var(--red); }
.hud-mode {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 1px 4px #000;
}

/* solo exit-direction indicator */
.exit-hint {
  position: absolute;
  top: 86px; left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.exit-hint.show { display: flex; }
.eh-compass {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(93, 255, 176, .7);
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.eh-arrow {
  font-size: 26px;
  color: var(--green);
  line-height: 1;
  text-shadow: 0 0 6px rgba(93,255,176,.9);
}
.eh-text {
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--green);
  text-shadow: 0 1px 4px #000;
}

/* hot/cold proximity gauge */
.heat {
  position: absolute;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.heat.show { display: flex; }
.heat-label {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 1px 4px #000;
}
.heat-bars { display: flex; gap: 5px; }
.heat-bar {
  width: 32px; height: 15px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .10);
  border: 1px solid rgba(255, 255, 255, .25);
  transition: background .2s, box-shadow .2s;
}
.heat-bar.on:nth-child(1) { background: #49b6ff; box-shadow: 0 0 8px #49b6ff; }
.heat-bar.on:nth-child(2) { background: #46d39a; box-shadow: 0 0 8px #46d39a; }
.heat-bar.on:nth-child(3) { background: #f4c430; box-shadow: 0 0 8px #f4c430; }
.heat-bar.on:nth-child(4) { background: #ff8c3a; box-shadow: 0 0 8px #ff8c3a; }
.heat-bar.on:nth-child(5) { background: #ff4d4d; box-shadow: 0 0 10px #ff4d4d; }

.hud-score {
  position: absolute;
  top: 14px; left: 16px;
  font-size: 15px;
  text-shadow: 0 1px 4px #000;
  line-height: 1.5;
}

/* power-up: enemy detector indicator */
.warn-hint {
  position: absolute;
  top: 60px; left: 16px;
  display: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: rgba(0, 0, 0, .55);
  border: 1px solid var(--line);
  color: #9fd7b0;
  text-shadow: 0 1px 3px #000;
}
.warn-hint.show { display: block; }
.warn-hint.danger {
  color: #ff7b75;
  border-color: #ff7b75;
  background: rgba(70, 12, 12, .72);
}
.hud-score .team-red { color: #ff7b75; font-weight: 700; }
.hud-score .team-blue { color: #7fa9ff; font-weight: 700; }

.killfeed {
  position: absolute;
  top: 14px; right: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-end;
}
.killfeed .kf {
  background: rgba(0,0,0,.55);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.killfeed .kf .k { color: var(--green); }
.killfeed .kf .v { color: #ff7b75; }

.toast {
  position: absolute;
  bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.6);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 16px;
  opacity: 0;
  transition: opacity .25s;
  text-align: center;
}
.toast.show { opacity: 1; }

.scoreboard {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(13,17,23,.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px 26px;
  min-width: 420px;
  display: none;
}
.scoreboard.show { display: block; }
.scoreboard h2 { text-align: center; margin-bottom: 14px; }
.scoreboard table { width: 100%; border-collapse: collapse; }
.scoreboard td, .scoreboard th {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.scoreboard .sb-team-title { font-weight: 700; padding-top: 12px; }
.scoreboard .r { color: #ff7b75; }
.scoreboard .b { color: #7fa9ff; }
.scoreboard .hint { text-align: center; margin-top: 12px; }

/* ===================== blocker / modal ===================== */
.blocker {
  position: absolute;
  inset: 0;
  background: rgba(7,10,15,.86);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  z-index: 20;
}
.blocker.hidden { display: none; }
.blocker-inner { text-align: center; max-width: 540px; padding: 30px; }
.blocker-inner h2 { font-size: 34px; margin-bottom: 12px; }
.blocker-inner p { color: var(--muted); margin-bottom: 8px; font-size: 16px; }
.controls-help {
  margin-top: 22px;
  display: inline-block;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 22px;
}
.controls-help p { color: var(--text); margin: 4px 0; font-size: 14px; }
.controls-help strong { color: var(--accent); }

.title-dead { color: var(--red); }
.title-out { color: var(--green); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(7,10,15,.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-inner {
  text-align: center;
  max-width: 560px;
  padding: 34px;
  background: rgba(20,25,34,.96);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.modal-inner h2 { font-size: 32px; margin-bottom: 6px; }
#results-body {
  margin: 18px 0 22px;
  font-size: 16px;
  line-height: 1.7;
}
#results-body .podium-row { font-size: 18px; margin: 4px 0; }
#results-body .gold { color: var(--gold); font-weight: 700; }
#results-body .silver { color: #cdd4dc; font-weight: 700; }
#results-body .bronze { color: #d99a5b; font-weight: 700; }
#results-body .win-big { font-size: 28px; font-weight: 800; }
#results-body .win-red { color: #ff7b75; }
#results-body .win-blue { color: #7fa9ff; }
#results-body .win-green { color: var(--green); }
#results-body .win-lose { color: var(--red); }
#results-body table { margin: 10px auto 0; border-collapse: collapse; }
#results-body td { padding: 3px 12px; font-size: 14px; }
#btn-back-lobby { width: auto; padding: 12px 28px; margin: 0 auto; }

/* connection lost */
.conn-lost {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--red);
  color: #fff;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  display: none;
  z-index: 100;
}
.conn-lost.show { display: block; }

/* responsive */
@media (max-width: 720px) {
  .home-actions { grid-template-columns: 1fr; }
  .scoreboard { min-width: 90vw; }
  .lobby-panel { width: calc(100vw - 32px); }
  .logo { font-size: 40px; }
}
