/* =====================================================================
   Space Invaders — fixed "phosphor arcade" theme.
   Like the other arcade canvas games (Flappy, Asteroids, Neon Dash), this
   page deliberately ignores the center's light/dark mode and its shared
   glass chrome (no glass.css, no mode bootstrap). Every colour is a hard
   copy of the game's own canvas palette: void-black base, phosphor-green
   cannon, cyan / magenta alien ranks, amber saucer, crimson plasma.
   The whole c-* chrome block lives here (it is NOT inherited).
   ===================================================================== */
:root {
  --si-void:    #05060c;   /* CRT black base */
  --si-void2:   #0a1020;
  --si-panel:   #0f1830;
  --si-green:   #38f27a;   /* cannon / primary glow */
  --si-green2:  #12b45a;
  --si-cyan:    #3fe0ff;   /* mid alien ranks */
  --si-mag:     #ff4fd8;   /* top alien rank */
  --si-amber:   #ffd166;   /* saucer / highlight text */
  --si-red:     #ff5566;   /* alien plasma / danger */
  --si-line:    rgba(70, 210, 130, .28);
  --si-text:    #d6ffe6;
  --si-muted:   #83b598;
}

html, body { height: 100%; }
body.si-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: manipulation;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--si-void2) 0%, var(--si-void) 70%);
  color: var(--si-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.si-page *,
body.si-page *::before,
body.si-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(10, 16, 32, .62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--si-green2);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 0 6px rgba(56, 242, 122, .5)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(18px, 3.2vw, 25px);
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--si-green);
  text-shadow: 0 0 12px rgba(56, 242, 122, .6), 0 0 30px rgba(56, 242, 122, .3);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; color: var(--si-muted); }
.stat b { color: var(--si-green); font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- Buttons (phosphor outline chips) ---------- */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--si-line);
  background: rgba(15, 24, 48, .7);
  color: var(--si-text);
  box-shadow: 0 3px 0 rgba(3, 6, 12, .55);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.c-btn:hover { background: rgba(24, 40, 60, .9); border-color: var(--si-green2); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(3, 6, 12, .55); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(56, 242, 122, .45); }
.c-btn--primary {
  background: linear-gradient(140deg, var(--si-green), var(--si-green2));
  border-color: rgba(56, 242, 122, .8);
  color: #04140a;
  text-shadow: none;
  box-shadow: 0 3px 0 rgba(3, 6, 12, .55), 0 0 18px rgba(56, 242, 122, .4);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #66ff9d, var(--si-green)); }

/* ---------- Table / stage ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.si-stage {
  position: relative;
  /* tall portrait play field, capped by the viewport height minus chrome.
     aspect-ratio matches the canvas logical size (440 / 640) so the
     letterboxed canvas scales correctly. */
  width: min(94vw, calc((100vh - 150px) * 0.6875), 460px);
  aspect-ratio: 440 / 640;
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(120% 120% at 50% 30%, #0b1526 0%, #04060d 80%);
  border: 2px solid var(--si-green2);
  box-shadow: 0 0 26px rgba(18, 180, 90, .35), inset 0 0 60px rgba(2, 5, 12, .85);
  touch-action: none;
}
#screen {
  display: block; width: 100%; height: 100%;
  touch-action: none;
}

/* ---------- Ready / pause / game-over overlays ---------- */
.si-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(3, 5, 12, .62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  touch-action: manipulation;
}
.si-overlay[hidden] { display: none; }
.si-card {
  max-width: 300px;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--si-panel), #081020);
  border: 2px solid var(--si-green2);
  box-shadow: 0 0 30px rgba(18, 180, 90, .3), 0 22px 50px rgba(0, 0, 0, .6);
  color: var(--si-text);
  animation: siPop .3s ease;
  touch-action: manipulation;
}
@keyframes siPop { from { transform: scale(.88); opacity: 0; } }
.si-card__big { font-size: 40px; line-height: 1.1; }
.si-card__big svg { width: 84px; height: 84px; display: block; margin: 0 auto; filter: drop-shadow(0 0 8px rgba(56,242,122,.4)); }
.si-card__big svg[hidden] { display: none; }
.si-card h2 {
  margin: 6px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--si-green);
  text-shadow: 0 0 12px rgba(56, 242, 122, .5);
}
.si-card p { margin: 0 0 14px; color: var(--si-muted); font-size: 13.5px; line-height: 1.55; }
.si-card p b { color: var(--si-amber); }
.si-card .c-btn { font-size: 14px; }
.si-card kbd, .c-modal kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--si-green);
  background: rgba(56, 242, 122, .1);
  border: 1px solid var(--si-green2);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(3, 6, 12, .5);
}
.c-win__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Touch pads (coarse pointers only) ---------- */
.si-touch { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.si-touch[hidden] { display: none; }
.si-pad {
  position: absolute;
  pointer-events: auto;
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 2px solid var(--si-green2);
  background: rgba(15, 24, 48, .5);
  color: var(--si-green);
  font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  opacity: .82;
}
.si-pad:active { background: rgba(56, 242, 122, .28); opacity: 1; }
.si-pad--left   { left: 16px;  bottom: 20px; }
.si-pad--right  { left: 106px; bottom: 20px; }
.si-pad--fire   { right: 22px;  bottom: 24px; color: var(--si-red); border-color: var(--si-red); width: 92px; height: 92px; font-size: 38px; }
@media (hover: hover) and (pointer: fine) {
  /* desktop: keep them hidden — the JS also gates on touch support */
  .si-touch { display: none; }
}

/* ---------- Rules modal ----------
   The full-screen overlay itself scrolls, never the card, so no scrollbar
   gutter ever sits inside the panel (see AGENTS.md). */
.c-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;
  background: rgba(2, 4, 10, .68);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.c-modal__panel {
  position: relative; z-index: 1;
  margin: auto;                    /* centres, and a too-tall card scrolls in from the top */
  width: min(92vw, 480px);
  background: linear-gradient(160deg, var(--si-panel), #06101f);
  color: var(--si-text);
  border-radius: 16px;
  border: 2px solid var(--si-green2);
  box-shadow: 0 0 30px rgba(18, 180, 90, .3), 0 24px 60px rgba(0, 0, 0, .65);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--si-line);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--si-green); text-shadow: 0 0 10px rgba(56, 242, 122, .5);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: var(--si-muted); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--si-amber); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--si-amber);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--si-amber); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(63, 224, 255, .1);
  border: 1px solid var(--si-line);
  font-size: 13px;
  color: var(--si-muted);
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn { border-color: var(--si-line); box-shadow: 0 3px 0 rgba(0, 0, 0, .4); }
.c-modal .c-btn--primary { border-color: rgba(56, 242, 122, .8); }

/* ---------- Responsive ---------- */
@media (max-width: 700px), (max-height: 620px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; letter-spacing: .08em; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
  .si-stage { width: min(96vw, calc((100vh - 120px) * 0.6875)); }
}
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
  .si-pad { width: 62px; height: 62px; font-size: 24px; }
  .si-pad--right { left: 84px; }
  .si-pad--fire { width: 76px; height: 76px; font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .si-card { transition: none; animation: none; }
}
