:root {
  --bg-deep: #03111c;
  --bg-mid: #062135;
  --panel-bg: rgba(5, 22, 36, 0.9);
  --panel-border: rgba(56, 189, 248, 0.34);
  --cyan: #22d3ee;
  --sky: #38bdf8;
  --gold: #fbbf24;
  --amber: #f59e0b;
  --coral: #fb7185;
  --emerald: #34d399;
  --violet: #c084fc;
  --text-main: #e2f1f8;
  --text-dim: #8bb4c9;
  --shadow-glow: 0 18px 48px rgba(0, 0, 0, 0.58);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #0a3049 0%, #03111c 75%);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.hidden {
  display: none !important;
}

/* HUD */
.hud-top {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  z-index: 10;
}

.hud-cluster {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.hud-right {
  align-items: center;
}

.stat-card,
.score-card,
.gold-card {
  background: rgba(4, 19, 31, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 146px;
  backdrop-filter: blur(8px);
}

.gold-card {
  min-width: 104px;
  border-color: rgba(251, 191, 36, 0.42);
}

.gold-num {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
  color: #fde047;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 12px rgba(251, 191, 36, 0.4);
}

.chest-hint {
  color: #fde047 !important;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.score-card {
  min-width: 142px;
  text-align: right;
}

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

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.stat-sub {
  margin-top: 4px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.score-num {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: #f0f9ff;
  text-shadow: 0 0 14px rgba(56, 189, 248, 0.35);
}

.combo-pill {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(245, 158, 11, 0.7);
  color: #fcd34d;
}

.bar-track {
  width: 100%;
  height: 8px;
  margin-top: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.emp-track {
  height: 6px;
  margin-top: 6px;
}

.bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  transition: width 0.1s linear;
}

.hull-fill {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.hull-fill.low {
  background: linear-gradient(90deg, #ef4444, #fb7185);
}

.dash-fill {
  background: linear-gradient(90deg, #0284c7, #22d3ee);
}

.emp-fill {
  background: linear-gradient(90deg, #d97706, #fbbf24);
}

.emp-fill.ready {
  background: linear-gradient(90deg, #f59e0b, #fef08a);
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.8);
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.wave-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(4, 19, 31, 0.82);
  border: 1px solid rgba(34, 211, 238, 0.4);
  backdrop-filter: blur(8px);
}

.wave-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--cyan);
}

.wave-num {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.boss-bar-wrap {
  width: min(360px, 42vw);
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(34, 6, 16, 0.84);
  border: 1px solid rgba(251, 113, 133, 0.55);
}

.boss-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fda4af;
  text-align: center;
}

.boss-track {
  height: 10px;
}

.boss-fill {
  background: linear-gradient(90deg, #e11d48, #fb7185);
}

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

.icon-btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(5, 22, 36, 0.84);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover {
  border-color: var(--cyan);
  background: rgba(14, 52, 78, 0.92);
}

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

.weapon-strip {
  position: absolute;
  bottom: 44px;
  left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: 72vw;
  pointer-events: none;
  z-index: 10;
}

.weapon-badge {
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(7, 27, 44, 0.86);
  border: 1px solid rgba(251, 191, 36, 0.55);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.07em;
  color: #fef08a;
}

.weapon-badge.starter {
  border-color: rgba(56, 189, 248, 0.55);
  color: #bae6fd;
}

.upgrade-strip {
  position: absolute;
  bottom: 14px;
  left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 72vw;
  pointer-events: none;
  z-index: 10;
}

.upgrade-chip {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(4, 19, 31, 0.78);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-size: 11px;
  font-weight: 600;
  color: #bae6fd;
}

/* Overlays */
.overlay-backdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(2, 11, 20, 0.74);
  backdrop-filter: blur(7px);
  z-index: 20;
  overflow-y: auto;
}

.title-layout,
.gameover-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(290px, 0.9fr);
  gap: 16px;
  width: 100%;
  max-width: 1020px;
  align-items: stretch;
}

.panel {
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 24px 26px;
  box-shadow: var(--shadow-glow);
}

.upgrade-panel {
  max-width: 920px;
}

.compact-panel {
  max-width: 440px;
  text-align: center;
}

.eyebrow-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.eyebrow-row .eyebrow {
  margin-bottom: 0;
}

.version-pill {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.42);
  background: rgba(8, 37, 58, 0.85);
  color: #bae6fd;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--cyan);
  margin-bottom: 6px;
}

.danger-eyebrow {
  color: var(--coral);
}

.game-title {
  margin: 0;
  font-size: clamp(30px, 4.6vw, 46px);
  font-weight: 900;
  letter-spacing: 0.05em;
  line-height: 1;
  color: #f8fafc;
  text-shadow: 0 0 28px rgba(34, 211, 238, 0.35);
}

.title-sub {
  display: block;
  margin-top: 6px;
  font-size: clamp(15px, 2.2vw, 20px);
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--sky);
}

.panel-title {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #f8fafc;
}

.lb-title {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fde047;
}

.hero-copy,
.panel-copy {
  margin: 12px 0 18px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
}

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

.control-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(12, 42, 64, 0.55);
  border: 1px solid rgba(56, 189, 248, 0.2);
  font-size: 12px;
  color: var(--text-dim);
}

kbd {
  display: inline-block;
  width: fit-content;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(2, 14, 24, 0.9);
  border: 1px solid rgba(125, 211, 252, 0.35);
  color: #e0f2fe;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
}

.hero-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.best-banner {
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.best-banner strong {
  color: #fcd34d;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.primary-btn,
.secondary-btn {
  padding: 12px 22px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.11em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

.primary-btn {
  border: none;
  color: #03111c;
  background: linear-gradient(135deg, #22d3ee, #38bdf8);
  box-shadow: 0 8px 24px rgba(34, 211, 238, 0.35);
}

.primary-btn:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.secondary-btn {
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 39, 58, 0.85);
  color: var(--text-main);
}

.secondary-btn:hover:not(:disabled) {
  border-color: var(--sky);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

/* Drydock Armory Shop */
.shop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.shop-wallet {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 8px 16px;
  border-radius: 12px;
  background: rgba(35, 26, 6, 0.82);
  border: 1px solid rgba(251, 191, 36, 0.55);
}

.wallet-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fcd34d;
}

.wallet-num {
  font-size: 26px;
  font-weight: 900;
  color: #fef08a;
  font-variant-numeric: tabular-nums;
}

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

.upgrade-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 7px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.34);
  background: rgba(9, 34, 54, 0.8);
  color: var(--text-main);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.upgrade-card.weapon-card {
  border-color: rgba(251, 191, 36, 0.5);
  background: rgba(34, 24, 12, 0.72);
}

.upgrade-card:hover:not(:disabled),
.upgrade-card:focus-visible:not(:disabled) {
  outline: none;
  transform: translateY(-2px);
  border-color: var(--cyan);
  background: rgba(14, 52, 80, 0.95);
  box-shadow: 0 10px 26px rgba(34, 211, 238, 0.22);
}

.upgrade-card.weapon-card:hover:not(:disabled) {
  border-color: var(--gold);
  background: rgba(54, 36, 12, 0.92);
}

.upgrade-card.purchased {
  border-color: rgba(52, 211, 153, 0.65);
  background: rgba(6, 40, 32, 0.72);
}

.card-top-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.upgrade-tier {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.18);
  color: var(--cyan);
}

.upgrade-tier.weapon-tier {
  background: rgba(251, 191, 36, 0.22);
  color: #fde047;
}

.price-tag {
  font-size: 13px;
  font-weight: 900;
  color: #fde047;
  font-variant-numeric: tabular-nums;
}

.price-tag.cant-afford {
  color: #fb7185;
}

.price-tag.bought {
  color: #34d399;
}

.upgrade-name {
  font-size: 15px;
  font-weight: 800;
  color: #f8fafc;
}

.upgrade-desc {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-dim);
}

.shop-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.shop-footer-left {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Leaderboard Table */
.leaderboard-panel {
  display: flex;
  flex-direction: column;
  min-height: 360px;
  max-height: 520px;
}

.lb-status {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.lb-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(56, 189, 248, 0.45) rgba(3, 15, 25, 0.4);
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.2);
  background: rgba(3, 15, 25, 0.72);
}

.lb-scroll::-webkit-scrollbar {
  width: 8px;
}

.lb-scroll::-webkit-scrollbar-track {
  background: rgba(3, 15, 25, 0.45);
  border-radius: 0 10px 10px 0;
}

.lb-scroll::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.42);
  border-radius: 999px;
}

.lb-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(34, 211, 238, 0.7);
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.lb-table th,
.lb-table td {
  padding: 7px 9px;
  text-align: left;
  border-bottom: 1px solid rgba(56, 189, 248, 0.12);
}

.lb-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(6, 26, 43, 0.96);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.lb-table td:last-child,
.lb-table th:last-child {
  text-align: right;
  font-weight: 800;
  color: #f0f9ff;
}

.lb-table tr.highlight-row {
  background: rgba(34, 211, 238, 0.18);
}

.lb-table tr.top-one td:first-child {
  color: #fde047;
  font-weight: 900;
}

/* Game Over + Submit Form */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.summary-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(12, 42, 64, 0.55);
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.summary-stat span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.summary-stat strong {
  font-size: 21px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
}

.new-best-tag {
  margin-bottom: 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fcd34d;
}

.submit-box {
  margin-top: 12px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(7, 29, 46, 0.72);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.submit-label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--cyan);
  margin-bottom: 8px;
}

.submit-row {
  display: flex;
  gap: 8px;
}

.name-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid rgba(125, 211, 252, 0.4);
  background: rgba(2, 13, 22, 0.92);
  color: #f8fafc;
  font-size: 14px;
  font-weight: 700;
  user-select: text;
  -webkit-user-select: text;
}

.name-input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.25);
}

.submit-btn {
  padding: 10px 16px;
}

.submit-feedback {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.submit-feedback.ok {
  color: var(--emerald);
  font-weight: 700;
}

.submit-feedback.err {
  color: var(--coral);
  font-weight: 700;
}

/* Touch buttons */
.mobile-controls {
  position: absolute;
  bottom: 18px;
  right: 18px;
  display: flex;
  gap: 10px;
  z-index: 15;
}

.mobile-action-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 2px solid var(--cyan);
  background: rgba(5, 24, 39, 0.85);
  color: #e0f2fe;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.mobile-action-btn.emp-btn {
  border-color: var(--amber);
  color: #fde68a;
}

@media (max-width: 860px) {
  .title-layout,
  .gameover-layout {
    grid-template-columns: 1fr;
  }

  .leaderboard-panel {
    max-height: 260px;
    min-height: 200px;
  }
}

@media (max-width: 720px) {
  .controls-grid,
  .upgrade-grid {
    grid-template-columns: 1fr;
  }

  .hud-top {
    flex-wrap: wrap;
    top: 8px;
    left: 8px;
    right: 8px;
  }

  .stat-card,
  .score-card,
  .gold-card {
    min-width: 112px;
    padding: 6px 8px;
  }

  .panel {
    padding: 18px;
  }
}
