:root {
  --bg: #071429;
  --panel: rgba(10, 22, 44, 0.86);
  --border: rgba(148, 163, 184, 0.24);
  --azure: #38bdf8;
  --solaris: #fbbf24;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --emerald: #34d399;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* HUD Top */
.hud-top {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10;
  pointer-events: none;
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
}

.team-azure { border-color: rgba(56, 189, 248, 0.45); }
.team-solaris { border-color: rgba(251, 191, 36, 0.45); }

.team-tag {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.team-azure .team-tag { color: var(--azure); }
.team-solaris .team-tag { color: var(--solaris); }

.team-score {
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1;
}

.flag-chip {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}
.flag-chip.taken { background: rgba(239, 68, 68, 0.25); color: #fca5a5; }
.flag-chip.dropped { background: rgba(251, 191, 36, 0.22); color: #fde68a; }

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: auto;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.1rem;
  padding: 5px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.room-badge {
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(15, 23, 42, 0.85);
  color: #bae6fd;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.room-badge:hover { background: rgba(56, 189, 248, 0.2); }

/* Top-right utility buttons */
.hud-utils {
  position: fixed;
  top: 12px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 20;
}

.net-pill {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--emerald);
}

.icon-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--azure); }

/* Event Feed */
.feed-region {
  position: fixed;
  top: 56px;
  right: 14px;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
}

.feed-item {
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(10, 22, 44, 0.82);
  border-left: 3px solid var(--azure);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.feed-item.solaris { border-left-color: var(--solaris); }
.feed-item.capture { border-left-color: var(--emerald); font-weight: 700; }

/* Center Banner */
.center-banner {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--azure);
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 12;
}

/* Bottom Ability Bar */
.hud-bottom {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.ability-strip {
  display: flex;
  gap: 8px;
}

.ab-slot {
  position: relative;
  overflow: hidden;
  min-width: 78px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  text-align: center;
}

.ab-slot.disabled { opacity: 0.45; }
.ab-key { display: block; font-size: 0.66rem; font-weight: 800; color: var(--azure); }
.ab-name { display: block; font-size: 0.74rem; font-weight: 700; }
.ab-cd {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.68);
  transform-origin: bottom;
  transform: scaleY(0);
}

.speed-meter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.speed-track {
  width: 140px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.speed-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #34d399, #fbbf24);
}

.speed-text {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 56px;
}

/* Lobby Overlay */
.lobby-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at center, rgba(7, 20, 41, 0.35), rgba(4, 10, 24, 0.78));
  z-index: 30;
}

.lobby-card {
  width: min(560px, 100%);
  padding: 28px 30px;
  border-radius: 20px;
  background: rgba(9, 19, 38, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.38);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
}

.eyebrow {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--azure);
  margin-bottom: 6px;
}

.lobby-card h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 5vw, 2.75rem);
  letter-spacing: 0.03em;
  background: linear-gradient(120deg, #f8fafc, #38bdf8, #fbbf24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 6px;
}

.join-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

input[type="text"], select {
  flex: 1;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  font-size: 0.95rem;
}

.btn-primary {
  padding: 11px 20px;
  border-radius: 10px;
  border: 0;
  background: linear-gradient(135deg, #38bdf8, #0284c7);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.8);
  color: var(--text);
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--azure); }

.lobby-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.controls-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 0.78rem;
  color: var(--muted);
}
.controls-strip b { color: var(--text); }

/* Native Modal Dialogs (Modern Web Guidance) */
dialog {
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow: auto;
  padding: 22px 24px;
  border-radius: 18px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: #0b172c;
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.dialog-head h1 { margin: 0; font-size: 1.35rem; }
.close-x {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.dialog-sub {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0 0 16px;
}

.room-create-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.room-code-join {
  display: flex;
  flex: 1;
  gap: 8px;
}

.invite-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  margin-bottom: 14px;
  font-size: 0.82rem;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
}

.room-meta { font-size: 0.82rem; color: var(--muted); }
.room-id { font-weight: 800; font-size: 0.96rem; color: var(--text); }

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.guide-box {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  line-height: 1.45;
}
.guide-box h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--azure); }
.guide-box ul { margin: 0; padding-left: 18px; }

.dialog-foot {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.scoreboard-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.scoreboard-wrap th, .scoreboard-wrap td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
  text-align: left;
}
.rematch-note {
  margin: 14px 0 0;
  text-align: center;
  color: var(--azure);
  font-weight: 700;
}

/* Popover Toast */
.toast-pop {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--azure);
  background: rgba(15, 23, 42, 0.94);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  margin: 0;
  transition: opacity 0.2s ease;
  transition-behavior: allow-discrete;
}

/* Touch Controls */
.touch-controls {
  position: fixed;
  inset: auto 0 18px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 18px;
  pointer-events: none;
  z-index: 15;
}
.touch-stick {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.55);
  border: 2px solid rgba(56, 189, 248, 0.45);
  position: relative;
  pointer-events: auto;
  touch-action: none;
}
.touch-knob {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.8);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.touch-actions {
  display: grid;
  grid-template-columns: repeat(2, 68px);
  gap: 8px;
  pointer-events: auto;
}
.t-btn {
  height: 52px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  font-weight: 800;
  font-size: 0.72rem;
}
.t-fire { border-color: var(--solaris); color: var(--solaris); }

@media (max-width: 720px) {
  .ability-strip { display: none; }
  .feed-region { display: none; }
  .hud-top { gap: 6px; top: 8px; }
  .hud-pill { padding: 6px 9px; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
