/* Turkey Invaders — page shell styles.
   The canvas fills the viewport edge-to-edge; all game-space scaling happens
   in js/boot.js (fitCanvas), which overrides the CSS size with exact pixel
   values on every resize. These rules are the pre-boot fallback.
   The --sa-* custom props republish the safe-area insets so fitCanvas can
   read them with getComputedStyle (JS cannot read env() directly). */
:root {
  color-scheme: dark;
  --hud: #7af7ff;
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-right: env(safe-area-inset-right, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px);
}
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #02030c;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  color: var(--hud);
  overflow: hidden;
}
#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* mobile toolbars: small-viewport height, not the large one */
  display: block;
  background: #02030c;
  touch-action: none; /* the canvas owns all gestures; no scroll/zoom stealing */
}
#fullscreen-btn,
#pause-btn,
#settings-btn,
#waves-btn {
  position: fixed;
  right: calc(10px + var(--sa-right));
  width: 40px;
  height: 40px;
  padding: 9px;
  background: rgba(2, 3, 12, 0.55);
  border: 1px solid rgba(122, 247, 255, 0.35);
  border-radius: 8px;
  color: var(--hud);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}
#fullscreen-btn { top: calc(10px + var(--sa-top)); }
#pause-btn { top: calc(58px + var(--sa-top)); }
/* Above their backdrops (z 10) so the same button also closes its panel. */
#settings-btn { top: calc(106px + var(--sa-top)); z-index: 11; }
#waves-btn { top: calc(154px + var(--sa-top)); z-index: 11; }
/* iOS hides the fullscreen button; the others slide up a slot. */
#fullscreen-btn.hidden ~ #pause-btn { top: calc(10px + var(--sa-top)); }
#fullscreen-btn.hidden ~ #settings-btn { top: calc(58px + var(--sa-top)); }
#fullscreen-btn.hidden ~ #waves-btn { top: calc(106px + var(--sa-top)); }
#fullscreen-btn:hover,
#fullscreen-btn:focus-visible,
#pause-btn:hover,
#pause-btn:focus-visible,
#settings-btn:hover,
#settings-btn:focus-visible,
#waves-btn:hover,
#waves-btn:focus-visible { opacity: 1; }
#fullscreen-btn svg,
#pause-btn svg,
#settings-btn svg,
#waves-btn svg { width: 100%; height: 100%; display: block; }
#fullscreen-btn.hidden { display: none; }
/* While a dialog is open, only the button that closes it stays on screen —
   the others would float over the panel's own content (a phone-width wave
   card reaches the corner) and invite a mis-tap. */
body.dialog-waves #fullscreen-btn,
body.dialog-waves #pause-btn,
body.dialog-waves #settings-btn,
body.dialog-settings #fullscreen-btn,
body.dialog-settings #pause-btn,
body.dialog-settings #waves-btn,
body.dialog-rotate #fullscreen-btn,
body.dialog-rotate #pause-btn,
body.dialog-rotate #settings-btn,
body.dialog-rotate #waves-btn { display: none; }

/* Rotate gate: phones are held to landscape (js/helpers.js
   requiresLandscape). Opaque and above everything — while it is up there is
   no game to interact with, so nothing beneath it should be reachable. */
#rotate-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px max(24px, var(--sa-right)) 24px max(24px, var(--sa-left));
  background: #02030c;
  text-align: center;
}
#rotate-gate.hidden { display: none; }
#rotate-icon {
  width: 84px;
  height: 84px;
  color: var(--hud);
  animation: rotate-hint 2.6s ease-in-out infinite;
}
/* The icon tips the way the player should turn the phone. Motion is a hint,
   not decoration, so it is dropped for anyone who asked for less of it. */
@keyframes rotate-hint {
  0%, 45% { transform: rotate(0deg); }
  60%, 90% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  #rotate-icon { animation: none; transform: rotate(-90deg); }
}
#rotate-gate h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--hud);
}
#rotate-gate p {
  margin: 0;
  max-width: 34ch;
  font-size: 9px;
  line-height: 1.9;
  color: rgba(223, 250, 255, 0.6);
}

/* Settings dialog: a full-screen backdrop (swallows canvas taps while
   open) with a centred card. */
#settings-panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 3, 12, 0.72);
  z-index: 10;
}
#settings-panel.hidden { display: none; }
#settings-card {
  background: #060818;
  border: 1px solid rgba(122, 247, 255, 0.4);
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(122, 247, 255, 0.12);
  padding: 24px;
  width: min(420px, calc(100vw - 40px));
  font-size: 11px;
  line-height: 1.5;
}
#settings-card h2 {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--hud);
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 14px 0;
  color: #dffaff;
}
.setting-row button {
  font: inherit;
  min-width: 90px;
  padding: 10px 14px;
  background: rgba(122, 247, 255, 0.08);
  border: 1px solid rgba(122, 247, 255, 0.35);
  border-radius: 8px;
  color: #ffd166;
  cursor: pointer;
}
.setting-row button[disabled] { cursor: default; }
.setting-row.dimmed { opacity: 0.4; }
#settings-note {
  margin: 12px 0 18px;
  font-size: 8px;
  color: rgba(223, 250, 255, 0.6);
}
#settings-close {
  font: inherit;
  width: 100%;
  padding: 12px;
  background: rgba(255, 209, 102, 0.1);
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 8px;
  color: #ffd166;
  cursor: pointer;
}

/* Wave select: the campaign grid. Same backdrop language as the settings
   dialog, but the card is a scrolling sheet — twenty cards never fit a
   phone, and native scrolling beats anything a canvas could fake. */
#waves-panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 3, 12, 0.82);
  z-index: 10;
  padding: max(12px, var(--sa-top)) max(12px, var(--sa-right))
           max(12px, var(--sa-bottom)) max(12px, var(--sa-left));
}
#waves-panel.hidden { display: none; }
#waves-card {
  display: flex;
  flex-direction: column;
  background: #060818;
  border: 1px solid rgba(122, 247, 255, 0.4);
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(122, 247, 255, 0.12);
  padding: 18px;
  width: min(880px, 100%);
  max-height: 100%;
  font-size: 11px;
}
#waves-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
#waves-head h2 { margin: 0; font-size: 14px; color: var(--hud); }
#waves-summary {
  font-size: 9px;
  color: #ffd166;
  flex: 1 1 auto;
}
#waves-close {
  font: inherit;
  font-size: 9px;
  padding: 8px 14px;
  background: rgba(255, 209, 102, 0.1);
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 8px;
  color: #ffd166;
  cursor: pointer;
}
#waves-note {
  margin: 10px 0;
  font-size: 8px;
  line-height: 1.6;
  color: rgba(223, 250, 255, 0.6);
}
#waves-note.warn { color: #ffd166; }
#waves-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px;
  min-height: 0; /* let the grid, not the card, do the scrolling */
}
.wave-card {
  position: relative;
  display: grid;
  gap: 6px;
  justify-items: center;
  font: inherit;
  font-size: 8px;
  padding: 12px 8px 10px;
  background: rgba(122, 247, 255, 0.06);
  border: 1px solid rgba(122, 247, 255, 0.3);
  border-radius: 10px;
  color: #dffaff;
  cursor: pointer;
  text-align: center;
}
.wave-card:hover:not([disabled]),
.wave-card:focus-visible { background: rgba(122, 247, 255, 0.14); }
.wave-card .wave-num { font-size: 16px; color: var(--hud); }
.wave-card .wave-name {
  line-height: 1.4;
  overflow-wrap: anywhere;
  color: rgba(223, 250, 255, 0.85);
}
.wave-card .wave-foot { font-size: 7px; color: rgba(223, 250, 255, 0.5); }
.wave-card .wave-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 6px;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(255, 107, 107, 0.2);
  color: #ff9b9b;
}
.wave-card.boss { border-color: rgba(255, 107, 107, 0.5); }
.wave-card.boss .wave-num { color: #ff9b9b; }
.wave-card.mastered { border-color: rgba(255, 209, 102, 0.7); }
.wave-card.locked {
  opacity: 0.4;
  cursor: default;
  border-style: dashed;
}
.wave-stars { display: flex; gap: 3px; }
.wave-stars .star { width: 13px; height: 13px; display: block; }
.wave-stars .star.on { fill: #ffd166; }
.wave-stars .star.off { fill: rgba(223, 250, 255, 0.16); }
#waves-reset {
  font: inherit;
  font-size: 8px;
  margin-top: 12px;
  padding: 9px;
  background: transparent;
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: 8px;
  color: rgba(255, 155, 155, 0.9);
  cursor: pointer;
}
#waves-reset.armed {
  background: rgba(255, 107, 107, 0.18);
  color: #ff9b9b;
}
