:root {
  --bg: #0b1220;
  --panel: rgba(15, 23, 42, 0.9);
  --panel-border: rgba(148, 163, 184, 0.22);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #22c55e;
  --primary-dark: #16a34a;
  --secondary: #38bdf8;
  --accent: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 20% 10%, #1e293b 0%, #090e1a 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* SCREENS */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

.card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.brand-badge {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.3);
}

h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.04em;
  font-weight: 900;
}

h2 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 900;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field-row {
  margin-bottom: 10px;
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 600;
}

.text-input, .select-input {
  width: 100%;
  background: rgba(2, 6, 23, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 12px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 15px;
  font-weight: 600;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.text-input:focus, .select-input:focus {
  border-color: var(--secondary);
}

.color-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.14s, border-color 0.14s;
}

.color-dot.selected {
  border-color: #ffffff;
  transform: scale(1.16);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.section-block {
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  padding-top: 14px;
  margin-top: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #cbd5e1;
  margin-bottom: 10px;
}

.section-head .section-title {
  margin-bottom: 0;
}

.btn {
  border: none;
  border-radius: 13px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  color: #0b1220;
  transition: transform 0.08s, filter 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:active {
  transform: scale(0.96);
}

.btn-lg {
  width: 100%;
  padding: 13px 18px;
  font-size: 16px;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
}

.btn-xs {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, #22c55e, #4ade80);
  color: #052e16;
  box-shadow: 0 6px 20px rgba(34, 197, 94, 0.35);
}

.btn-secondary {
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  color: #082f49;
}

.btn-accent {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #451a03;
}

.btn-ghost {
  background: rgba(148, 163, 184, 0.16);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.join-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  text-align: center;
  font-weight: 900;
  flex: 1;
}

.biome-pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  margin-bottom: 10px;
}

.biome-pill {
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: #cbd5e1;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.biome-pill.active {
  border-color: var(--secondary);
  background: rgba(56, 189, 248, 0.18);
  color: #ffffff;
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toast-inline {
  margin-top: 12px;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
  border-radius: 11px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* LOBBY */
.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.muted-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.room-code {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: #fde047;
  line-height: 1.1;
}

.lobby-header-actions {
  display: flex;
  gap: 8px;
}

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

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.player-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.player-name {
  font-weight: 700;
  flex: 1;
  font-size: 15px;
}

.player-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  color: #e2e8f0;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.7fr;
  gap: 8px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

.setting-item .select-input {
  padding: 8px;
  font-size: 13px;
}

.lobby-footer {
  margin-top: 16px;
}

.wait-note {
  text-align: center;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  background: rgba(2, 6, 23, 0.45);
  border-radius: 12px;
}

/* GAME SCREEN */
.game-screen {
  padding: 0;
  overflow: hidden;
  touch-action: none;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud-top {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.hud-teams {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-width: 42%;
}

.team-chip {
  background: rgba(15, 23, 42, 0.78);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(6px);
}

.team-chip.active {
  box-shadow: 0 0 0 2px #ffffff;
}

.team-chip.dead {
  opacity: 0.4;
  text-decoration: line-through;
}

.team-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.hud-center {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 14px;
  padding: 5px 10px;
  backdrop-filter: blur(8px);
}

.hud-timer {
  min-width: 32px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  color: #fde047;
  font-variant-numeric: tabular-nums;
}

.hud-timer.urgent {
  color: #f87171;
  animation: pulse 0.55s infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.16); }
}

.wind-box {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wind-label {
  font-size: 9px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.06em;
}

.wind-track {
  position: relative;
  width: 68px;
  height: 10px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.3);
  overflow: hidden;
}

.wind-center-mark {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.55);
  transform: translateX(-50%);
}

.wind-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #38bdf8, #a78bfa);
  transition: left 0.3s, width 0.3s;
}

.wind-val {
  font-size: 11px;
  font-weight: 800;
  min-width: 26px;
  text-align: right;
  color: #e2e8f0;
}

.hud-actions {
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.8);
  color: #f8fafc;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.icon-btn:active {
  transform: scale(0.92);
}

.target-hint {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(245, 158, 11, 0.94);
  color: #1c1917;
  font-weight: 900;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 12;
  white-space: nowrap;
}

/* BOTTOM CONTROLS */
.hud-bottom {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.2s;
}

.hud-bottom.disabled {
  opacity: 0.42;
}

.ctrl-left, .ctrl-center, .ctrl-right {
  pointer-events: auto;
}

.ctrl-left {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.move-row, .jump-row {
  display: flex;
  gap: 7px;
}

.touch-btn {
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  background: rgba(15, 23, 42, 0.78);
  color: #ffffff;
  border-radius: 14px;
  font-weight: 800;
  backdrop-filter: blur(8px);
  cursor: pointer;
  touch-action: none;
}

.touch-btn.pressed, .touch-btn:active {
  background: rgba(56, 189, 248, 0.45);
  border-color: #38bdf8;
  transform: scale(0.95);
}

.move-btn {
  width: 58px;
  height: 52px;
  font-size: 20px;
}

.jump-btn {
  height: 38px;
  padding: 0 11px;
  font-size: 12px;
}

.ctrl-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.weapon-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 16px;
  border: 1.5px solid rgba(250, 204, 21, 0.55);
  background: rgba(15, 23, 42, 0.86);
  color: #ffffff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.weapon-pill-icon {
  font-size: 22px;
}

.weapon-pill-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}

.weapon-pill-name {
  font-size: 13px;
  font-weight: 800;
}

.weapon-pill-ammo {
  font-size: 11px;
  color: #fde047;
  font-weight: 800;
}

.weapon-pill-caret {
  font-size: 10px;
  color: var(--muted);
}

.turn-status {
  font-size: 11px;
  font-weight: 800;
  color: #e2e8f0;
  background: rgba(15, 23, 42, 0.72);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* AIM PAD */
.aim-pad {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(239, 68, 68, 0.25), rgba(15, 23, 42, 0.82));
  border: 2px solid rgba(251, 146, 60, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

.aim-pad.active {
  border-color: #fde047;
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.28);
}

.aim-pad-ring {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.26);
  pointer-events: none;
}

.aim-pad-knob {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f97316, #ef4444);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.5);
  pointer-events: none;
  transition: transform 0.04s linear;
}

.aim-pad-label {
  position: absolute;
  bottom: 6px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.75);
  pointer-events: none;
}

/* POPOVERS */
.popover {
  position: fixed;
  z-index: 20;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 18px;
  padding: 10px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
}

.weapon-drawer {
  bottom: max(92px, calc(82px + env(safe-area-inset-bottom)));
  left: 50%;
  transform: translateX(-50%);
  width: min(94vw, 420px);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.weapon-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1.5px solid rgba(148, 163, 184, 0.2);
  background: rgba(2, 6, 23, 0.62);
  color: #f8fafc;
  cursor: pointer;
  text-align: left;
}

.weapon-card.selected {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.16);
}

.weapon-card.empty {
  opacity: 0.36;
  pointer-events: none;
}

.weapon-card-icon {
  font-size: 24px;
}

.weapon-card-info {
  flex: 1;
  min-width: 0;
}

.weapon-card-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 800;
}

.weapon-card-ammo {
  color: #fde047;
}

.weapon-card-desc {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.2;
}

.emote-menu {
  top: max(54px, calc(46px + env(safe-area-inset-top)));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.emote-menu button {
  background: rgba(2, 6, 23, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 10px;
  color: #ffffff;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 30;
  backdrop-filter: blur(6px);
}

.modal-card {
  text-align: center;
  max-width: 360px;
}

.trophy {
  font-size: 52px;
  margin-bottom: 6px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

/* GLOBAL TOAST */
.global-toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--secondary);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  z-index: 40;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* COMPACT MOBILE ADJUSTMENTS */
@media (max-width: 520px) {
  .hud-teams {
    max-width: 34%;
  }
  .team-chip {
    padding: 3px 6px;
    font-size: 11px;
  }
  .wind-label {
    display: none;
  }
  .wind-track {
    width: 48px;
  }
  .move-btn {
    width: 52px;
    height: 48px;
  }
  .aim-pad {
    width: 88px;
    height: 88px;
  }
  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
}
