:root {
  --paper: #f4f1ea;
  --ink: #14202a;
  --soft: #6c706e;
  --line: #d6d1c2;
  --ship: #e24a3b;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#game,
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#scene {
  display: block;
  touch-action: none;
}

.hud {
  position: fixed;
  z-index: 5;
  top: max(23px, env(safe-area-inset-top));
  left: max(25px, env(safe-area-inset-left));
  right: max(25px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  pointer-events: none;
  font-size: 14px;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.hud-group { display: grid; gap: 2px; }
.hud-group-right { justify-items: end; }
.hud .label { color: var(--soft); font-size: 10px; font-weight: 600; letter-spacing: .15em; }
.hud strong { font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums; }
.hud-title { font-weight: 600; letter-spacing: .13em; }

.lives {
  position: fixed;
  z-index: 5;
  left: max(25px, env(safe-area-inset-left));
  bottom: max(23px, env(safe-area-inset-bottom));
  display: flex;
  gap: 7px;
  pointer-events: none;
}

.life {
  width: 13px;
  height: 18px;
  background: var(--ship);
  clip-path: polygon(50% 0, 100% 100%, 50% 76%, 0 100%);
  filter: drop-shadow(0 1px 0 rgb(20 32 42 / 18%));
}

.wave {
  position: fixed;
  z-index: 6;
  top: 50%;
  left: 50%;
  opacity: 0;
  color: var(--ink);
  font-size: clamp(15px, 2vw, 21px);
  font-weight: 500;
  letter-spacing: .14em;
  pointer-events: none;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  transition: opacity .35s ease;
}

.wave.is-visible { opacity: 1; }

.panel {
  position: fixed;
  z-index: 10;
  top: 50%;
  left: 50%;
  width: min(520px, calc(100% - 44px));
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, calc(-50% + 12px));
  transition: opacity .45s ease, transform .45s ease;
}

.panel-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.eyebrow {
  margin: 0 0 13px;
  color: var(--soft);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(58px, 10vw, 122px);
  font-weight: 500;
  letter-spacing: -.07em;
  line-height: .86;
}

h2 { font-size: clamp(50px, 8vw, 94px); }
.intro { margin: 26px 0 25px; color: var(--soft); font-size: 16px; }
.final-score { margin: 27px 0 25px; color: var(--soft); }
.final-score strong { margin-left: 8px; color: var(--ink); font-variant-numeric: tabular-nums; }

.primary-button {
  min-width: 118px;
  padding: 11px 20px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform .15s ease, background .15s ease;
}

.primary-button:hover { background: #293943; transform: translateY(-1px); }
.primary-button:active { transform: translateY(1px); }
.primary-button:focus-visible,
.secondary-button:focus-visible,
.sound-button:focus-visible,
.touch-controls button:focus-visible { outline: 3px solid rgb(226 74 59 / 35%); outline-offset: 4px; }

.button-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.secondary-button {
  min-width: 118px;
  padding: 10px 20px 11px;
  border: 1px solid rgb(20 32 42 / 28%);
  border-radius: 999px;
  background: rgb(244 241 234 / 72%);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}

.secondary-button:hover { border-color: var(--ink); background: var(--paper); transform: translateY(-1px); }
.secondary-button:active { transform: translateY(1px); }

.controls-copy {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 29px 0 0;
  color: var(--soft);
  font-size: 11px;
  letter-spacing: .05em;
}

.controls-copy span { color: var(--ink); font-weight: 600; }
.controls-copy i { width: 2px; height: 2px; border-radius: 50%; background: var(--line); }

.sound-button {
  position: fixed;
  z-index: 8;
  right: max(25px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--soft);
  cursor: pointer;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.touch-controls { display: none; }

@media (pointer: coarse), (max-width: 700px) {
  .hud { top: max(17px, env(safe-area-inset-top)); left: 18px; right: 18px; }
  .hud-title { display: none; }
  .hud { grid-template-columns: 1fr 1fr; }
  .controls-copy { display: none; }
  .lives { left: 19px; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 62px); }
  .sound-button { right: 18px; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 67px); }
  .touch-controls {
    position: fixed;
    z-index: 8;
    right: 14px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 14px;
    display: grid;
    grid-template-columns: repeat(3, 50px) 1fr 58px;
    gap: 8px;
    pointer-events: none;
  }
  .touch-controls button {
    width: 50px;
    height: 50px;
    border: 1px solid rgb(20 32 42 / 16%);
    border-radius: 50%;
    background: rgb(244 241 234 / 72%);
    color: var(--ink);
    pointer-events: auto;
    touch-action: none;
    backdrop-filter: blur(4px);
  }
  .touch-controls .fire-control {
    grid-column: 5;
    width: 58px;
    height: 58px;
    border-color: rgb(226 74 59 / 24%);
    color: var(--ship);
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .wave, .primary-button { transition: none; }
}
