:root {
  --bg: #04111d;
  --deep: #061b2a;
  --panel: rgba(3, 18, 31, 0.78);
  --panel-strong: rgba(4, 14, 26, 0.96);
  --cyan: #00f5ff;
  --magenta: #ff4da6;
  --yellow: #ffe600;
  --green: #00ff88;
  --coral: #ff6b7a;
  --foam: #f3feff;
  --muted: #a9c7d6;
  --line: rgba(255, 255, 255, 0.15);
}

* {
  box-sizing: border-box;
}

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

body::after {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 5px),
    radial-gradient(circle at 50% 70%, transparent 42%, rgba(0, 8, 18, 0.4));
  mix-blend-mode: overlay;
  opacity: 0.32;
  content: "";
}

@media (hover: none), (pointer: coarse), (max-width: 760px) {
  body::after {
    display: none;
  }
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 18%, rgba(0, 245, 255, 0.22), transparent 28%),
    radial-gradient(circle at 76% 82%, rgba(255, 107, 122, 0.2), transparent 34%),
    linear-gradient(180deg, #072743 0%, #051827 54%, #04111d 100%);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.back-link {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid rgba(0, 245, 255, 0.38);
  border-radius: 8px;
  background: rgba(2, 13, 24, 0.78);
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  backdrop-filter: blur(14px);
  box-shadow: 0 0 28px rgba(0, 245, 255, 0.18);
}

.hud {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, auto));
  gap: 8px;
}

.hud-chip,
.meters {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.3);
}

.hud-chip {
  min-width: 72px;
  padding: 9px 10px;
  text-align: center;
}

.hud-chip span,
.meter-label span,
.best-row span,
.score-label,
.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
}

.hud-chip strong,
.meter-label strong,
.best-row strong,
.score-value,
.stat-value {
  display: block;
  margin-top: 2px;
  color: var(--foam);
  font-family: Orbitron, sans-serif;
}

.hud-chip strong {
  font-size: clamp(0.9rem, 2vw, 1.15rem);
}

.meters {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 12;
  width: min(310px, calc(100vw - 30px));
  padding: 10px;
}

.meter + .meter {
  margin-top: 9px;
}

.meter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.meter-label strong {
  color: var(--yellow);
  font-size: 0.78rem;
}

.meter-track {
  height: 9px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.meter-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transition: width 90ms linear;
}

.oxygen-fill {
  background: linear-gradient(90deg, var(--coral), var(--yellow), var(--green));
}

.sonar-fill {
  background: linear-gradient(90deg, var(--cyan), #7bf7ff, var(--foam));
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.36);
}

.touch-controls {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 13;
  display: none;
  grid-template-columns: repeat(3, 56px);
  gap: 8px;
}

.touch-btn {
  width: 56px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(0, 245, 255, 0.14);
  color: var(--foam);
  font: 800 0.58rem Orbitron, sans-serif;
  box-shadow: 0 0 22px rgba(0, 245, 255, 0.14);
  -webkit-tap-highlight-color: transparent;
}

.thrust-btn,
.fire-btn {
  background: linear-gradient(135deg, var(--cyan), var(--green));
  color: #02101b;
}

.pulse-btn {
  background: linear-gradient(135deg, var(--yellow), var(--coral));
  color: #02101b;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 76px 18px 24px;
  background: rgba(3, 10, 18, 0.46);
  backdrop-filter: blur(7px);
}

.panel {
  width: min(590px, 100%);
  padding: clamp(22px, 5vw, 34px);
  border: 1px solid rgba(0, 245, 255, 0.24);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel-strong), rgba(4, 18, 31, 0.92));
  box-shadow: 0 0 34px rgba(0, 245, 255, 0.18), 0 30px 90px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.title,
.over-title {
  margin: 0;
  color: var(--cyan);
  font-family: Orbitron, sans-serif;
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 800;
  line-height: 0.98;
  text-shadow: 0 0 22px rgba(0, 245, 255, 0.42), 0 0 42px rgba(255, 107, 122, 0.26);
}

.over-title {
  color: var(--coral);
  font-size: clamp(1.9rem, 7vw, 3.3rem);
}

.subtitle,
.over-game-name,
.hint,
.share-feedback {
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.subtitle,
.over-game-name {
  color: var(--yellow);
  font-size: 0.86rem;
}

.best-row,
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 22px 0;
}

.stats {
  grid-template-columns: repeat(3, 1fr);
}

.best-row > div,
.stats > div,
.score-block {
  min-width: 0;
  padding: 13px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.best-row strong,
.stat-value {
  font-size: clamp(1.2rem, 5vw, 1.95rem);
}

.score-block {
  margin-top: 20px;
}

.score-value {
  color: var(--green);
  font-size: clamp(2.2rem, 11vw, 4rem);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #020b12;
  font: 800 0.82rem Orbitron, sans-serif;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--yellow), var(--cyan));
  box-shadow: 0 0 30px rgba(0, 245, 255, 0.28);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--coral), var(--magenta));
  color: var(--foam);
}

.hidden {
  display: none !important;
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}

@media (max-width: 760px) {
  .hud-chip,
  .meters,
  .back-link,
  .overlay {
    backdrop-filter: none;
  }

  .hud {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    top: max(58px, env(safe-area-inset-top));
    grid-template-columns: repeat(4, 1fr);
  }

  .hud-chip {
    min-width: 0;
    padding: 8px 5px;
  }

  .hud-chip span {
    font-size: 0.48rem;
  }

  .hud-chip strong {
    font-size: 0.86rem;
  }

  .meters {
    width: calc(100vw - 210px);
    min-width: 150px;
  }

  .back-link {
    font-size: 0.76rem;
  }
}

@media (max-width: 480px) {
  .meters {
    width: calc(100vw - 206px);
    padding: 8px;
  }

  .touch-controls {
    grid-template-columns: repeat(3, 50px);
    gap: 7px;
  }

  .touch-btn {
    width: 50px;
    height: 45px;
    font-size: 0.5rem;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 22px 14px;
  }
}
