:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f7f2dd;
  background: #242924;
  font-synthesis: none;
  --cream: #f7f2dd;
  --lime: #d8f26d;
  --orange: #ff955f;
  --ink: #242924;
  --edge: clamp(12px, 2vw, 28px);
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { position: relative; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
body > canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; touch-action: none; }
button { color: inherit; font: inherit; cursor: pointer; -webkit-appearance: none; appearance: none; }
button, .touch-stick { -webkit-user-select: none; user-select: none; touch-action: none; }
button:focus-visible { outline: 3px solid var(--cream); outline-offset: 4px; }
button:disabled { cursor: default; opacity: .45; }
button svg, button span, button small { pointer-events: none; }

#hud {
  position: absolute;
  inset: 0 0 auto;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(112px, 1fr) auto auto;
  align-items: start;
  gap: 14px;
  padding: max(var(--edge), env(safe-area-inset-top)) max(var(--edge), env(safe-area-inset-right)) 30px max(var(--edge), env(safe-area-inset-left));
  background: linear-gradient(#1c231ddb 0%, #1c231da8 58%, #1c231d00 100%);
  pointer-events: none;
}
.pilot-status { width: min(100%, 192px); padding-top: 3px; }
.wordmark { display: flex; align-items: center; gap: 6px; font-size: 15px; line-height: 20px; font-weight: 850; letter-spacing: .07em; white-space: nowrap; }
.bolt-mark { color: var(--lime); font-size: 22px; line-height: 18px; }
.meter { overflow: hidden; background: #111810a6; }
.health-meter { height: 6px; margin-top: 9px; box-shadow: 0 0 0 1px #f7f2dd33; }
.meter-fill { width: 100%; height: 100%; transform-origin: left; background: var(--lime); transition: width 100ms linear, background-color 150ms ease; }
.health-meter[data-low="true"] .meter-fill { background: var(--orange); }
.dash-status { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.dash-meter { flex: 1; height: 3px; }
.dash-meter .meter-fill { background: var(--cream); }
#dash-label { font: 9px/12px var(--mono); letter-spacing: .04em; white-space: nowrap; color: #e4e6cbd9; }
.mission-status { display: grid; justify-items: end; min-width: 88px; font-variant-numeric: tabular-nums; }
.wave-label { font: 10px/14px var(--mono); letter-spacing: .07em; color: var(--lime); }
.score-value { font: 700 25px/29px var(--mono); min-width: 6ch; text-align: right; }
.best-score { font: 9px/13px var(--mono); color: #e4e6cbae; white-space: nowrap; }
#best { display: inline-block; min-width: 6ch; text-align: right; }
.hud-actions { display: flex; gap: 4px; pointer-events: auto; }
.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid #f7f2dd2b;
  border-radius: 8px;
  background: #20271f94;
  transition: background-color 120ms ease, transform 120ms ease;
}
.icon-button svg { width: 22px; height: 22px; }
.icon-button:active { transform: scale(.94); background: #f7f2dd26; }
.sound-slash { display: none; }
#sound-button[aria-pressed="true"] .sound-waves { display: none; }
#sound-button[aria-pressed="true"] .sound-slash { display: block; }

#notice {
  position: absolute;
  z-index: 4;
  top: max(92px, calc(env(safe-area-inset-top) + 80px));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-left: 3px solid var(--lime);
  background: #20271fed;
  font: 700 12px/18px var(--mono);
  letter-spacing: .025em;
  text-align: center;
  pointer-events: none;
}

.menu-overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: max(96px, calc(env(safe-area-inset-top) + 80px)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: linear-gradient(#1720180d, #17201880);
}
.menu-panel {
  width: min(100%, 370px);
  padding: 24px 26px 20px;
  border-top: 3px solid var(--lime);
  background: #242b23f2;
  box-shadow: 0 16px 48px #10150e4d;
  text-align: center;
}
.menu-stencil { display: flex; align-items: center; justify-content: center; gap: 10px; color: #b4bd9b; font: 9px/14px var(--mono); letter-spacing: .13em; }
.stencil-line { width: 24px; height: 1px; background: #b4bd9b66; }
#menu-title { margin: 11px 0 7px; font-size: clamp(27px, 4vw, 36px); line-height: 1.08; font-weight: 850; letter-spacing: .01em; text-wrap: balance; }
#menu-description { max-width: 29ch; margin: 0 auto; color: #e4e6cbd9; font-size: 13px; line-height: 1.5; text-wrap: balance; }
.menu-score { margin: 10px 0 0; color: var(--lime); font: 700 17px/22px var(--mono); font-variant-numeric: tabular-nums; }
.menu-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.action-button { display: flex; align-items: center; justify-content: center; gap: 18px; min-height: 46px; padding: 11px 16px; border: 1px solid transparent; border-radius: 4px; font-size: 14px; line-height: 20px; font-weight: 750; }
.primary-action { flex: 1 1 100%; background: var(--lime); color: #242b20; box-shadow: 0 3px 0 #748741; }
.primary-action span { font-size: 19px; font-weight: 400; }
.primary-action:active { transform: translateY(2px); box-shadow: 0 1px 0 #748741; }
.secondary-action { flex: 1 1 100%; min-height: 44px; color: #e4e6cbd9; background: transparent; border-color: #f7f2dd33; }
.secondary-action:active { background: #f7f2dd14; }
.controls-guide { margin: 15px auto 0; max-width: 34ch; color: #bbc4aad9; font: 10px/1.6 var(--mono); text-wrap: balance; }
body[data-phase="gameover"] .menu-panel { border-top-color: var(--orange); }
body[data-phase="gameover"] .menu-stencil { color: var(--orange); }
body[data-phase="won"] #menu-title { color: var(--lime); }

#touch-controls {
  position: absolute;
  z-index: 3;
  inset: auto 0 0;
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(20px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  pointer-events: none;
  background: linear-gradient(transparent, #17201859);
}
.stick-group { display: grid; justify-items: center; gap: 7px; }
.touch-stick { position: relative; display: grid; place-items: center; width: 112px; height: 112px; border: 1px solid #f7f2dd4d; border-radius: 50%; background: #20271f73; pointer-events: auto; }
.stick-cross { position: absolute; inset: 0; pointer-events: none; }
.stick-cross::before, .stick-cross::after { content: ""; position: absolute; background: #f7f2dd33; }
.stick-cross::before { height: 1px; width: 72%; top: 50%; left: 14%; }
.stick-cross::after { width: 1px; height: 72%; top: 14%; left: 50%; }
.knob { display: block; position: relative; width: 44px; height: 44px; border: 1px solid #f7f2dd80; border-radius: 50%; background: #b6c39880; box-shadow: 0 3px 12px #10150e33; pointer-events: none; }
#aim-stick .knob { background: #d8f26d80; border-color: #d8f26d; }
.stick-label { font: 9px/12px var(--mono); letter-spacing: .12em; color: #f7f2ddb3; }
.touch-dash { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 0 0 54px; width: 54px; height: 54px; margin-bottom: 28px; border: 1px solid #f7f2dd66; border-radius: 50%; background: #242b23cc; color: var(--cream); pointer-events: auto; }
.touch-dash span { font-size: 18px; font-weight: 700; line-height: 22px; }
.touch-dash small { font: 8px/12px var(--mono); letter-spacing: .06em; }
.touch-dash:active { background: var(--lime); color: var(--ink); }

@media (hover: hover) {
  .icon-button:hover { background: #f7f2dd20; }
  .primary-action:hover { background: #e3fa8b; }
  .secondary-action:hover { background: #f7f2dd0d; }
}
@media (pointer: coarse) { body:not([data-mode="native"]) #touch-controls { display: flex; } }
body[data-touch="true"]:not([data-mode="native"]) #touch-controls { display: flex; }
body[data-mode="native"] #touch-controls,
body:not([data-phase="playing"]) #touch-controls { display: none !important; }

@media (max-width: 430px) {
  #hud { gap: 10px; }
  .wordmark { gap: 4px; font-size: 11px; letter-spacing: .04em; }
  .bolt-mark { font-size: 18px; }
  .pilot-status { width: min(100%, 142px); }
  .mission-status { min-width: 74px; }
  .score-value { font-size: 21px; line-height: 27px; }
  .hud-actions { gap: 3px; }
  .dash-status { gap: 5px; }
  #dash-label { font-size: 8px; }
  .menu-panel { width: min(100%, 320px); padding-inline: 22px; }
}
@media (max-width: 350px) {
  #hud { gap: 7px; grid-template-columns: minmax(96px, 1fr) auto auto; }
  .wordmark { font-size: 10px; }
  .bolt-mark { display: none; }
  .mission-status { min-width: 66px; }
  .score-value { font-size: 18px; }
  .wave-label { font-size: 9px; }
  .best-score { font-size: 8px; }
  .touch-stick { width: 96px; height: 96px; }
  #touch-controls { padding-inline: 14px; gap: 8px; }
  .touch-dash { flex-basis: 48px; width: 48px; height: 48px; }
}
@media (max-height: 430px) {
  #hud { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: 20px; }
  .menu-overlay { padding-top: max(82px, calc(env(safe-area-inset-top) + 70px)); padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .menu-panel { width: min(100%, 340px); padding: 14px 20px; }
  .menu-stencil { display: none; }
  #menu-title { margin: 0 0 6px; font-size: 27px; }
  #menu-description { font-size: 12px; line-height: 17px; }
  .menu-actions { margin-top: 12px; }
  .primary-action, .secondary-action { flex: 1 1 auto; }
  .controls-guide { margin-top: 10px; font-size: 9px; line-height: 14px; }
  .menu-score { margin-top: 7px; font-size: 15px; line-height: 19px; }
  #notice { top: max(80px, calc(env(safe-area-inset-top) + 68px)); padding-block: 5px; }
  .touch-stick { width: 92px; height: 92px; }
  #touch-controls { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
