:root {
  color-scheme: dark;
  --bg-top: #091321;
  --bg-bottom: #020711;
  --panel: rgba(5, 12, 22, 0.72);
  --panel-hi: rgba(18, 33, 54, 0.78);
  --panel-border: rgba(95, 188, 255, 0.22);
  --panel-border-strong: rgba(126, 224, 255, 0.46);
  --text: #eef7ff;
  --muted: #84a3bd;
  --accent: #7ee0c6;
  --accent-2: #7ec8ff;
  --danger: #ff8170;
  --gold: #ffcf70;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.36);
  --glow: 0 0 18px rgba(126, 224, 255, 0.12);
  font-family: "Orbitron", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(58, 141, 196, 0.22), transparent 38%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text);
}

body {
  position: relative;
  font-family: "Orbitron", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  letter-spacing: 0.03em;
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.panel {
  position: absolute;
  pointer-events: auto;
  background:
    linear-gradient(180deg, rgba(16, 28, 46, 0.78), rgba(4, 10, 18, 0.8)),
    linear-gradient(135deg, rgba(126, 224, 255, 0.05), transparent 46%);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.025), var(--glow);
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0, transparent 18px, rgba(126, 224, 255, 0.08) 18px, rgba(126, 224, 255, 0.08) 22px, transparent 22px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 34%);
  opacity: 0.9;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.stats {
  top: 20px;
  left: 20px;
  width: 320px;
  padding: 14px 14px 12px;
}

.status-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  margin-bottom: 8px;
}

.status-chip {
  min-width: 82px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(142, 192, 234, 0.12);
  background: linear-gradient(180deg, rgba(14, 26, 44, 0.88), rgba(8, 14, 25, 0.82));
  text-align: right;
}

.status-chip span,
.status-readouts span,
.status-bar-meta span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.status-chip strong,
.status-readouts strong,
.status-bar-meta strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stats h1,
.upgrades h2,
.leaderboard h2,
.overlay-card h2 {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(126, 224, 255, 0.12);
  overflow-wrap: anywhere;
}

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

.panel-toggle {
  display: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(161, 211, 255, 0.16);
  background: rgba(142, 192, 234, 0.08);
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.subtitle {
  margin: 2px 0 10px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.weapon-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.status-bars {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.status-bar-card {
  padding: 9px 10px 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(14, 26, 44, 0.88), rgba(8, 14, 25, 0.82));
  border: 1px solid rgba(142, 192, 234, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.status-bar-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.status-bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.status-bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width 120ms ease;
}

.status-bar-card.shield .status-bar-fill {
  background: linear-gradient(90deg, #53a9ff, #9ee7ff);
  box-shadow: 0 0 12px rgba(126, 224, 255, 0.22);
}

.status-bar-card.hull .status-bar-fill {
  background: linear-gradient(90deg, #58d2a0, #aaf3da);
  box-shadow: 0 0 12px rgba(126, 224, 198, 0.2);
}

.status-bar-card.torpedo .status-bar-fill {
  background: linear-gradient(90deg, #ff7aa6, #ffd1df);
  box-shadow: 0 0 12px rgba(255, 122, 166, 0.18);
}

.status-readouts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.status-readouts > div {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(14, 26, 44, 0.88), rgba(8, 14, 25, 0.82));
  border: 1px solid rgba(142, 192, 234, 0.1);
}

.weapon-pill {
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(142, 192, 234, 0.18);
  background: linear-gradient(180deg, rgba(142, 192, 234, 0.12), rgba(142, 192, 234, 0.05));
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, opacity 120ms ease;
  white-space: nowrap;
}

.weapon-pill.active {
  border-color: rgba(126, 224, 198, 0.52);
  background: linear-gradient(180deg, rgba(126, 224, 198, 0.26), rgba(126, 224, 198, 0.12));
  color: var(--text);
  box-shadow: inset 0 0 12px rgba(126, 224, 198, 0.08), 0 0 14px rgba(126, 224, 198, 0.1);
}

.weapon-pill.unavailable {
  opacity: 0.42;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.stat-grid div {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(14, 26, 44, 0.88), rgba(8, 14, 25, 0.82));
  border: 1px solid rgba(142, 192, 234, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.stat-grid span {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-grid strong {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}

.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
  font-size: 11px;
}

.mobile-hint {
  display: none;
}

.upgrades {
  right: 20px;
  top: 20px;
  width: 300px;
  padding: 14px;
}

.upgrade-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  max-height: min(42vh, 420px);
  overflow: auto;
}

.upgrade-button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(126, 224, 198, 0.18);
  background:
    linear-gradient(180deg, rgba(11, 25, 34, 0.9), rgba(8, 16, 24, 0.86)),
    linear-gradient(90deg, rgba(126, 224, 198, 0.08), transparent 54%);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.upgrade-button:hover {
  transform: translateY(-1px);
  border-color: rgba(126, 224, 198, 0.4);
  background:
    linear-gradient(180deg, rgba(14, 31, 42, 0.94), rgba(9, 18, 28, 0.9)),
    linear-gradient(90deg, rgba(126, 224, 198, 0.14), transparent 58%);
}

.upgrade-button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
}

.upgrade-button strong,
.upgrade-button span {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.upgrade-button span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.leaderboard {
  left: 20px;
  bottom: 20px;
  width: 220px;
  padding: 14px;
}

.leaderboard h2 {
  font-size: 15px;
  letter-spacing: 0.08em;
}

.minimap {
  right: 20px;
  bottom: 20px;
  width: 200px;
  padding: 12px;
}

.minimap-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid rgba(161, 211, 255, 0.18);
  background:
    radial-gradient(circle at center, rgba(44, 88, 146, 0.18), transparent 65%),
    rgba(3, 10, 18, 0.84);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), 0 0 16px rgba(126, 224, 255, 0.08);
}

.leaderboard ol {
  margin: 10px 0 0;
  padding-left: 20px;
  line-height: 1.55;
  font-size: 12px;
}

.leaderboard li {
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kill-feed {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px));
}

.kill-feed ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.kill-feed li {
  padding: 8px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(8, 19, 31, 0.84), rgba(5, 11, 18, 0.88));
  border: 1px solid rgba(161, 211, 255, 0.16);
  box-shadow: var(--shadow), 0 0 14px rgba(126, 224, 255, 0.06);
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.mobile-controls {
  position: fixed;
  inset: auto 0 0;
  display: none;
  align-items: end;
  justify-content: space-between;
  padding: 0 16px calc(18px + env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 3;
}

.touch-pad,
.touch-actions {
  pointer-events: auto;
}

.touch-pad {
  display: grid;
  gap: 8px;
  justify-items: center;
  user-select: none;
  touch-action: none;
}

.touch-label {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(6, 16, 25, 0.48);
  border: 1px solid rgba(161, 211, 255, 0.12);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.touch-ring {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(138, 207, 255, 0.16), rgba(6, 16, 25, 0.2)),
    radial-gradient(circle at center, rgba(126, 224, 255, 0.08), transparent 64%);
  border: 1px solid rgba(161, 211, 255, 0.16);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.22), inset 0 0 18px rgba(126, 224, 255, 0.06);
}

.aim-ring {
  width: 150px;
  height: 150px;
}

.touch-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-left: -24px;
  margin-top: -24px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(222, 244, 255, 0.34), rgba(126, 224, 255, 0.2));
  border: 1px solid rgba(222, 244, 255, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 0 16px rgba(126, 224, 255, 0.08);
  transition: transform 80ms ease;
}

.aim-thumb {
  width: 42px;
  height: 42px;
  margin-left: -21px;
  margin-top: -21px;
  background: rgba(126, 224, 198, 0.24);
  border-color: rgba(126, 224, 198, 0.42);
}

.touch-actions {
  display: grid;
  gap: 10px;
  align-self: center;
}

.touch-button {
  min-width: 88px;
  min-height: 56px;
  padding: 0 18px;
  border-radius: 18px;
  border: 1px solid rgba(161, 211, 255, 0.18);
  background: linear-gradient(180deg, rgba(16, 29, 44, 0.92), rgba(10, 18, 29, 0.88));
  color: var(--text);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  touch-action: manipulation;
  box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.02), 0 0 18px rgba(126, 224, 255, 0.06);
  white-space: nowrap;
}

.touch-button.primary {
  background: linear-gradient(135deg, rgba(126, 224, 198, 0.84), rgba(99, 182, 255, 0.76));
  color: #072130;
}

.touch-button.secondary {
  color: var(--muted);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 12, 0.6);
  backdrop-filter: blur(8px);
}

.overlay-card {
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 20px;
  border: 1px solid rgba(161, 211, 255, 0.18);
  background:
    linear-gradient(180deg, rgba(9, 18, 31, 0.95), rgba(4, 9, 16, 0.94)),
    linear-gradient(135deg, rgba(126, 224, 255, 0.07), transparent 44%);
  box-shadow: var(--shadow), 0 0 24px rgba(126, 224, 255, 0.1);
  text-align: center;
}

.overlay-card p {
  color: var(--muted);
  line-height: 1.5;
}

.field-label {
  display: block;
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.name-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(161, 211, 255, 0.18);
  background: linear-gradient(180deg, rgba(14, 26, 44, 0.88), rgba(8, 14, 25, 0.82));
  color: var(--text);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.06em;
  outline: none;
}

.name-input:focus {
  border-color: rgba(126, 224, 198, 0.45);
  box-shadow: 0 0 0 3px rgba(126, 224, 198, 0.12);
}

.palette-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 6px;
}

.palette-option {
  padding: 8px;
  border-radius: 14px;
  border: 1px solid rgba(161, 211, 255, 0.16);
  background: linear-gradient(180deg, rgba(14, 26, 44, 0.88), rgba(8, 14, 25, 0.82));
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.palette-option.active {
  border-color: rgba(126, 224, 255, 0.42);
  box-shadow: 0 0 16px rgba(126, 224, 255, 0.12);
  transform: translateY(-1px);
}

.palette-swatch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  height: 22px;
  margin-bottom: 8px;
}

.palette-swatch span {
  border-radius: 999px;
}

.palette-option-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.spawn-button {
  width: 100%;
  margin-top: 14px;
  padding: 14px 16px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(126, 224, 198, 0.96), rgba(99, 182, 255, 0.92));
  color: #072130;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.overlay-hint {
  margin-top: 12px;
}

.hidden {
  display: none;
}

@media (max-width: 960px) {
  .stats,
  .upgrades,
  .leaderboard,
  .minimap {
    width: calc(100vw - 24px);
    left: 12px;
    right: 12px;
  }

  .stats {
    top: 12px;
  }

  .upgrades {
    top: auto;
    bottom: 160px;
  }

  .leaderboard {
    bottom: 12px;
  }

  .minimap {
    bottom: 224px;
  }

  .kill-feed {
    top: auto;
    bottom: 248px;
  }
}

@media (pointer: coarse), (max-width: 960px) {
  .stats {
    top: 10px;
    left: 10px;
    right: auto;
    width: calc(100vw - 176px);
    max-width: 430px;
    padding: 10px 12px;
  }

  .status-head {
    gap: 8px;
    margin-bottom: 8px;
  }

  .status-chip {
    min-width: 72px;
    padding: 7px 8px;
  }

  .upgrades {
    left: 10px;
    right: 10px;
    width: auto;
    top: auto;
    bottom: 168px;
    padding: 10px 12px;
    max-height: 62px;
    overflow: hidden;
    transition: max-height 160ms ease, background 160ms ease;
  }

  .upgrades.is-open {
    max-height: 32vh;
    background: rgba(6, 16, 25, 0.78);
  }

  .upgrades .upgrade-list,
  .upgrades .hint {
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
  }

  .upgrades.is-open .upgrade-list,
  .upgrades.is-open .hint {
    opacity: 1;
    pointer-events: auto;
  }

  .leaderboard {
    left: auto;
    right: 10px;
    bottom: auto;
    top: 10px;
    width: 150px;
    padding: 10px 12px;
  }

  .minimap {
    left: auto;
    right: 10px;
    top: 178px;
    bottom: auto;
    width: 150px;
    padding: 10px;
  }

  .leaderboard ol {
    font-size: 12px;
    line-height: 1.4;
    max-height: 148px;
    overflow: auto;
  }

  .kill-feed {
    top: 86px;
    width: min(260px, calc(100vw - 180px));
  }

  .desktop-hint {
    display: none;
  }

  .mobile-hint {
    display: none;
  }

  .mobile-controls {
    display: flex;
  }

  .stats h1 {
    font-size: 17px;
    letter-spacing: 0.08em;
  }

  .subtitle {
    display: none;
  }

  .weapon-strip {
    margin-bottom: 8px;
  }

  .status-bars {
    gap: 6px;
    margin-bottom: 8px;
  }

  .status-bar-card {
    padding: 8px 8px 9px;
  }

  .status-bar-meta strong,
  .status-readouts strong,
  .status-chip strong {
    font-size: 11px;
  }

  .status-readouts {
    gap: 6px;
  }

  .status-readouts > div {
    padding: 7px 8px;
  }

  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 0;
  }

  .stat-grid div {
    padding: 7px 8px;
  }

  .stat-grid span {
    margin-bottom: 3px;
    font-size: 10px;
  }

  .stat-grid strong {
    font-size: 11px;
    letter-spacing: 0.04em;
  }

  .weapon-pill {
    font-size: 9px;
    padding: 6px 8px;
  }

  .upgrade-button strong {
    font-size: 11px;
  }

  .upgrade-button span {
    font-size: 10px;
  }

  .leaderboard li,
  .kill-feed li {
    font-size: 10px;
  }

  .stats .hint {
    display: none;
  }

  .panel-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}
