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

:root {
  --ice: #a8d8ff;
  --ice-dim: rgba(168, 216, 255, 0.45);
  --ink: #101216;
  --panel: rgba(24, 28, 34, 0.85);
  --line: rgba(255, 255, 255, 0.08);
  --text: #e6ecf2;
  --muted: rgba(230, 236, 242, 0.5);
  --faint: rgba(230, 236, 242, 0.28);
}

@font-face {
  font-family: 'UI';
  src: local('Segoe UI'), local('Arial'), sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--ink);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

canvas#gameCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.scanlines {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.05) 2px,
    rgba(0, 0, 0, 0.05) 4px
  );
  mix-blend-mode: overlay;
}

/* ===== Starfield warp overlay ===== */
#warpCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  pointer-events: none;
}

/* ===== Screens ===== */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
}

.screen.fade-out {
  opacity: 0;
  visibility: visible;
  pointer-events: none;
}

/* ===== Audio prompt ===== */
.audio-prompt {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: rgba(20, 24, 30, 0.85);
  border: 1px solid var(--line);
  border-radius: 24px;
  color: var(--ice);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  pointer-events: none;
}

.audio-prompt.show {
  opacity: 1;
  transform: translateY(0);
}

.audio-icon {
  animation: audioPulse 1.4s ease-in-out infinite;
}

@keyframes audioPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ===== Intro ===== */
.game-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
  letter-spacing: 14px;
  text-transform: uppercase;
}

.title-line {
  font-weight: 300;
  font-size: clamp(38px, 8vw, 92px);
  color: var(--text);
  opacity: 0.92;
}

.title-line.accent {
  font-weight: 200;
  color: var(--ice);
  text-shadow: 0 0 24px rgba(168, 216, 255, 0.25);
  letter-spacing: 18px;
}

.click-hint {
  margin-top: 44px;
  font-size: 13px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--faint);
  animation: hintPulse 2.6s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.6; }
}

/* ===== Ship select ===== */
.section-title {
  font-weight: 300;
  font-size: clamp(20px, 3vw, 34px);
  letter-spacing: 8px;
  text-transform: uppercase;
  color: var(--ice);
  margin-bottom: 44px;
}

.ship-grid {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 44px;
}

.ship-card {
  width: 200px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.3s ease,
    box-shadow 0.3s ease,
    background 0.3s ease;
}

.ship-card:hover {
  transform: translateY(-4px);
  border-color: var(--ice-dim);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.4);
}

.ship-card.selected {
  border-color: var(--ice);
  box-shadow: 0 0 0 1px var(--ice), 0 8px 34px rgba(0, 0, 0, 0.45);
  background: rgba(28, 34, 42, 0.9);
  transform: translateY(-4px);
}

.ship-preview {
  display: block;
  margin: 0 auto 10px;
}

.ship-info h3 {
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 3px;
}

.ship-stat {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 12px;
}

.ship-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--faint);
}

.stat-bar span {
  width: 26px;
  text-align: right;
}

.bar {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--ice);
  opacity: 0.55;
  border-radius: 2px;
}

/* ===== Buttons ===== */
.btn {
  padding: 12px 34px;
  font-family: inherit;
  font-weight: 400;
  font-size: 14px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--ice);
  background: transparent;
  border: 1px solid var(--ice-dim);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
}

.btn:hover {
  background: rgba(168, 216, 255, 0.12);
  border-color: var(--ice);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  background: rgba(168, 216, 255, 0.2);
}

.btn.ghost {
  color: var(--muted);
  border-color: var(--line);
}

.btn.ghost:hover {
  color: var(--text);
  border-color: var(--ice-dim);
  background: rgba(255, 255, 255, 0.04);
}

.sound-btn {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 20;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20, 24, 30, 0.85);
  color: var(--ice);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, transform 0.4s ease, border-color 0.25s ease;
}

.sound-btn.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.sound-btn:hover {
  border-color: var(--ice-dim);
}

/* ===== HUD ===== */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: linear-gradient(180deg, rgba(16, 18, 22, 0.6) 0%, transparent 100%);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.hud.hidden {
  opacity: 0;
  transform: translateY(-16px);
}

.hud-left, .hud-right {
  display: flex;
  gap: 26px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hud-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--faint);
  text-transform: uppercase;
}

.hud-val {
  font-size: 22px;
  font-weight: 300;
  color: var(--text);
  letter-spacing: 1px;
}

.hud-val.combo {
  color: var(--ice);
}

.hud-val.combo.high {
  color: #cfe8ff;
}

.hud-item.wave .hud-val {
  color: var(--ice);
}

.hud-item.best .hud-val {
  color: var(--muted);
  font-size: 17px;
}

.hud-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

/* ===== Game over ===== */
.go-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 40px 58px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform: scale(0.96);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
}

.screen.active .go-panel {
  transform: scale(1);
  opacity: 1;
}

.go-title {
  font-weight: 300;
  font-size: clamp(24px, 4vw, 40px);
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--ice);
  margin-bottom: 26px;
}

.fs-label {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--faint);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.fs-value {
  font-size: clamp(44px, 8vw, 72px);
  font-weight: 200;
  color: var(--text);
  letter-spacing: 2px;
  margin-bottom: 26px;
}

.score-details {
  display: flex;
  gap: 36px;
  justify-content: center;
  margin-bottom: 34px;
}

.sd-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sd-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--faint);
  text-transform: uppercase;
}

.sd-item span:last-child {
  font-size: 19px;
  font-weight: 300;
  color: var(--ice);
}

.go-buttons {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.go-buttons .btn {
  font-size: 12px;
  padding: 11px 26px;
}

.credit {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--faint);
  opacity: 0.6;
  pointer-events: none;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .ship-grid {
    flex-direction: column;
    align-items: center;
  }

  .ship-card {
    width: 240px;
  }

  .hud {
    padding: 10px 14px;
  }

  .hud-left, .hud-right {
    gap: 14px;
  }

  .hud-val {
    font-size: 17px;
  }

  .go-panel {
    padding: 30px 22px;
    margin: 0 16px;
  }

  .score-details {
    gap: 18px;
  }

  .credit {
    display: none;
  }
}