/* Math Invaders — a dark arcade skin over gamekit.
 *
 * Two rules from the family's hard-won list are load-bearing here and must not
 * be "tidied":
 *
 *   1. No `#screen-*` rule ever sets `display`. An ID selector outranks
 *      gk-base's `.screen{display:none}` / `.screen.active{display:flex}`, so
 *      one stray `display:flex` pins a screen visible on top of every other one
 *      forever, with nothing in the console.
 *   2. `.screen` keeps `position: fixed`. Overriding only `align-items` is
 *      right (gk-base centres its children, which collapses a full-width canvas
 *      stage to zero); dropping it to `position: static` trades that for a
 *      zero-HEIGHT stage, which looks identical and is worse.
 */

:root {
  --ink: #05081a;
  --deep: #0b1024;
  --panel: #141a38;
  --panel-2: #1c2450;
  --paper: #e9edff;
  --dim: #a3aed4;
  --cyan: #38bdf8;
  --lime: #4ade80;

  /* gk-base's own button colours carry white lettering and do not pass at
   * small sizes (green 2.37:1, blue 3.01:1). These are the measured-safe
   * replacements, chosen for the SMALLEST button in the game — the 15px row of
   * three, which needs 4.5:1, not the 3:1 large-text floor. */
  --gk-accent: #2670ab;
  --gk-accent-sh: #17456a;
  --gk-green: #1a8253;
  --gk-blue: #2670ab;
  --gk-grey: #616675;
  --gk-danger: #c0463d;

  --gk-bg: var(--deep);
  --gk-text: var(--paper);
  --gk-card: rgba(255, 255, 255, 0.055);
  /* `--gk-ink` is the one that matters on a DARK game and the one it is easy to
   * miss: gk-base paints `.profile-card` and `.lb-row` with `color:
   * var(--gk-ink)`, which defaults to near-black. Leaving it made the family
   * leaderboard render every pilot's name at 1.26:1 — black lettering on a dark
   * card, completely invisible, on a screen nobody opens while testing. */
  --gk-ink: var(--paper);
  color-scheme: dark;
}

* { -webkit-tap-highlight-color: transparent; }

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #1b2352 0%, transparent 62%),
    linear-gradient(180deg, #0b1024 0%, #070a1c 100%);
  background-attachment: fixed;
  color: var(--paper);
  font-family: "Baloo 2", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}

/* gk-base centres and pins .screen children; the game stage has to fill the
 * width or a canvas whose only sibling is absolutely positioned measures 0. */
.screen { align-items: stretch; justify-content: flex-start; }
.content { width: 100%; max-width: 560px; margin: 0 auto; padding: 12px 14px 30px; }

/* ------------------------------------------------------------------ chrome */

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px calc(10px);
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(8, 12, 30, 0.82);
  border-bottom: 1px solid rgba(120, 150, 255, 0.16);
  position: sticky; top: 0; z-index: 4;
}
.topbar h2 { font-size: 19px; margin: 0; font-weight: 800; }
.grow { flex: 1 1 auto; min-width: 0; }
.iconbtn {
  background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(140, 165, 255, 0.2);
  color: var(--paper); border-radius: 10px; width: 38px; height: 38px;
  font-size: 17px; cursor: pointer; flex: 0 0 auto;
}
.iconbtn.small { width: 32px; height: 32px; font-size: 14px; }

/* gk-base styles .btn as white-on-accent with a chunky drop shadow; overriding
 * a component means overriding all of it, or the label and shadow survive. */
.btn {
  font-family: inherit; font-weight: 800; letter-spacing: 0.2px;
  border-radius: 12px; border: none; margin: 6px 0;
}
.btn.ghost {
  background: rgba(255, 255, 255, 0.06); color: var(--paper);
  box-shadow: none; border: 1px solid rgba(140, 165, 255, 0.24); font-weight: 700;
}
.btn.ghost:active { box-shadow: none; }
.btn.wide { width: 100%; }
.row-btns2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.row-btns3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 4px 0 2px; }
.row-btns3 .btn { font-size: 14px; padding: 11px 4px; margin: 0; }

/* gk-base dresses `.sheet`, NOT `.modal-box` — without this rule the pause and
 * how-to sheets are dark ink floating on a 50% black scrim at 1.2:1. */
.modal-box {
  background: linear-gradient(170deg, #1a2148, #10152f);
  border: 1px solid rgba(140, 165, 255, 0.26);
  border-radius: 18px; padding: 18px 16px 16px;
  width: min(92vw, 400px); max-height: 86vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-box h2 { margin: 0 0 10px; font-size: 21px; }
.howto { margin: 0 0 14px; padding-left: 20px; font-size: 14px; line-height: 1.5; color: #cdd6ff; }
.howto li { margin-bottom: 7px; }
.howto b { color: var(--paper); }
/* The profile, PIN and delete modals are `.sheet`, injected by gk-profiles.js,
 * and gk-base dresses them for the LIGHT kit: `background:#fff`. Recolouring
 * only the text — which is all this rule used to do — put near-white lettering
 * on a white card and made "New Player" invisible. Overriding a gk-base
 * component means overriding all of it: background, inputs, keys and tiles. */
.sheet {
  background: linear-gradient(170deg, #1a2148, #10152f); color: var(--paper);
  border: 1px solid rgba(140, 165, 255, 0.26);
}
.sheet input {
  background: rgba(0, 0, 0, 0.32); color: var(--paper);
  border-color: rgba(140, 165, 255, 0.3); font-family: inherit; font-weight: 700;
}
.sheet input::placeholder { color: #8b96c4; }
.sheet p { color: #c3cbf0; opacity: 1; }
/* A 1fr track will not shrink below its content, so six emoji columns overflow
 * the sheet on a narrow phone. Always minmax(0, 1fr). */
.avatar-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)) !important; gap: 6px; }
.avatar-choice { font-size: 22px; background: rgba(255, 255, 255, 0.08); color: var(--paper); }
.avatar-choice.selected { border-color: var(--cyan); background: rgba(56, 189, 248, 0.2); }
.pin-key { background: rgba(255, 255, 255, 0.08); color: var(--paper); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
.pin-dots span { background: rgba(255, 255, 255, 0.08); border-color: rgba(140, 165, 255, 0.3); }
.pin-dots span.on { background: var(--cyan); border-color: var(--cyan); }

.nudge { color: var(--dim); font-size: 14px; line-height: 1.45; margin: 2px 0 12px; }
.nudge.small { font-size: 13px; }
.sec { font-size: 15px; text-transform: uppercase; letter-spacing: 1.4px; color: #a9b5e6; margin: 18px 0 8px; }

/* ------------------------------------------------------------------ splash */

/* `margin: auto` on both axes, NOT `justify-content: center` on the screen.
 * `.screen` is a scroll container, and centring it with justify-content clips
 * the top of anything taller than the viewport with no way to scroll back to
 * it. Auto margins centre when there is room and collapse to zero when there
 * isn't, so a short phone still starts at the top of the content. */
.splash-inner {
  width: 100%; max-width: 460px; margin: auto;
  padding: max(20px, env(safe-area-inset-top)) 20px 26px; text-align: center;
}
.splash-row { display: flex; justify-content: center; gap: 14px; align-items: center; margin-bottom: 6px; }
.splash-row span { font-size: 30px; animation: hover 3.2s ease-in-out infinite; }
.splash-row span:nth-child(2) {
  font-size: 21px; font-weight: 800; color: var(--cyan);
  background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 4px 12px; border-radius: 9px; animation-delay: -1.1s;
}
.splash-row span:nth-child(3) { animation-delay: -2s; }
@keyframes hover { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.logo {
  font-size: clamp(34px, 12vw, 52px); line-height: 0.92; margin: 4px 0 10px;
  font-weight: 800; letter-spacing: 2px; color: #ffffff;
}
.logo span { display: block; color: var(--cyan); }
.tagline { color: #b9c3ee; font-size: 15px; line-height: 1.5; margin: 0 0 18px; }
.keys-hint { color: #929dc7; font-size: 12px; margin: 12px 0 0; }
.splash-foot { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; }
#sync-badge { color: #929dc7; font-size: 12px; }

/* -------------------------------------------------------------------- base */

.base-player { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.base-stars { font-size: 14px; font-weight: 800; color: #fcd34d; flex: 0 0 auto; }

.skill-meter {
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.16);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.skill-head { display: flex; justify-content: space-between; font-size: 13px; color: #c3cbf0; margin-bottom: 7px; }
.skill-track { height: 8px; background: rgba(0, 0, 0, 0.35); border-radius: 6px; overflow: hidden; }
.skill-track i { display: block; height: 100%; background: linear-gradient(90deg, #22d3ee, #4ade80); transition: width 0.4s; }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.stat {
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.16);
  border-radius: 12px; padding: 9px 11px; display: flex; flex-direction: column; gap: 3px;
}
.stat .k { font-size: 12px; color: #a3adda; }
.stat .v { font-size: 18px; font-weight: 800; }

.sector-list { display: flex; flex-direction: column; gap: 7px; }
.sector {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.18);
  border-radius: 13px; padding: 9px 11px; color: var(--paper);
  font-family: inherit; cursor: pointer;
}
.sector.done { border-color: rgba(74, 222, 128, 0.4); background: rgba(74, 222, 128, 0.08); }
.sector.locked { opacity: 0.42; cursor: default; }
.sec-icon {
  width: 42px; height: 42px; flex: 0 0 auto; display: grid; place-items: center;
  font-size: 21px; border-radius: 11px;
  background: color-mix(in srgb, var(--tint) 24%, transparent);
  border: 1px solid color-mix(in srgb, var(--tint) 55%, transparent);
}
.sec-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sec-name { font-weight: 800; font-size: 15px; }
.sec-sub { font-size: 12.5px; color: #a3adda; line-height: 1.3; }
.sec-stars { flex: 0 0 auto; font-size: 14px; letter-spacing: 1px; }
.sec-stars b { color: #fcd34d; }
.sec-stars i { color: rgba(148, 163, 184, 0.45); font-style: normal; }

/* ------------------------------------------------- classic / practice grids */

.diff-list { display: flex; flex-direction: column; gap: 9px; }
.diff {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.2);
  border-radius: 14px; padding: 12px; color: var(--paper); font-family: inherit; cursor: pointer;
}
.diff-icon { font-size: 26px; flex: 0 0 auto; }
.diff-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.diff-name { font-weight: 800; font-size: 17px; }
.diff-sub { font-size: 12.5px; color: #a3adda; line-height: 1.3; }
.diff-best { font-weight: 800; color: #fcd34d; font-size: 16px; flex: 0 0 auto; }

.prac-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.prac {
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.18);
  border-radius: 13px; padding: 11px 10px; color: var(--paper); font-family: inherit;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.prac-icon {
  width: 38px; height: 38px; display: grid; place-items: center; font-size: 19px;
  border-radius: 10px; background: color-mix(in srgb, var(--tint) 24%, transparent);
  border: 1px solid color-mix(in srgb, var(--tint) 55%, transparent);
}
.prac-name { font-size: 13px; font-weight: 700; text-align: center; line-height: 1.25; }
.prac-bar { width: 100%; height: 6px; background: rgba(0, 0, 0, 0.35); border-radius: 4px; overflow: hidden; }
.prac-bar i { display: block; height: 100%; }
.prac-pct { font-size: 11px; color: #a3adda; }

/* ------------------------------------------------------------------ hangar */

.cos-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cos {
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.18);
  border-radius: 13px; padding: 9px 6px; color: var(--paper); font-family: inherit;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.cos.on { border-color: var(--lime); background: rgba(74, 222, 128, 0.12); }
.cos.locked { opacity: 0.45; cursor: default; }
.cos-swatch {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-size: 19px; border: 1px solid rgba(255, 255, 255, 0.22);
}
.cos-name { font-size: 12.5px; font-weight: 700; }
.cos-need { font-size: 10.5px; color: #a3adda; text-align: center; line-height: 1.2; }

/* ------------------------------------------------------------------ medals */

.award-list { display: flex; flex-direction: column; gap: 7px; }
.award {
  display: flex; align-items: center; gap: 11px;
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.16);
  border-radius: 12px; padding: 9px 11px; opacity: 0.5;
}
.award.got { opacity: 1; border-color: rgba(252, 211, 77, 0.42); background: rgba(252, 211, 77, 0.09); }
.aw-icon { font-size: 22px; flex: 0 0 auto; width: 30px; text-align: center; }
.aw-body { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.aw-body span { color: #a3adda; font-size: 12px; line-height: 1.3; }

/* ------------------------------------------------------------- leaderboard */

.lb-rows { display: flex; flex-direction: column; gap: 7px; }
.lb-stat { font-size: 12.5px; color: #c3cbf0; margin-right: 9px; white-space: nowrap; }

/* -------------------------------------------------------------------- game */
/* Never a `display` here — see the header comment. */
#screen-game { padding: 0; overflow: hidden; touch-action: none; }

.gamebar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top));
  background: rgba(6, 9, 24, 0.9);
  border-bottom: 1px solid rgba(120, 150, 255, 0.16);
}
.hud { font-size: 14px; font-weight: 800; white-space: nowrap; }
.hud.lives { color: #fb7185; letter-spacing: -1px; }
.hud.chain { color: #fcd34d; }
.hud.wave { flex: 1 1 auto; text-align: center; color: #9aa5cc; font-weight: 700; font-size: 12.5px; }
.hud.score { color: #ffffff; font-size: 17px; }

.game-stage { flex: 1 1 auto; position: relative; width: 100%; min-height: 0; }
/* The DISPLAY size comes from here and only from here, so it can never
 * disagree with the stage; JS sets the backing store (width/height attrs). */
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.keypad {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(6, 9, 24, 0.94);
  border-top: 1px solid rgba(120, 150, 255, 0.16);
}
.key {
  font-family: inherit; font-weight: 800; font-size: 21px; color: var(--paper);
  background: linear-gradient(180deg, #232c58, #182047);
  border: 1px solid rgba(140, 165, 255, 0.24); border-radius: 11px;
  height: 46px; cursor: pointer; user-select: none; touch-action: manipulation;
}
.key:active { background: linear-gradient(180deg, #2f3a72, #232c58); transform: translateY(1px); }
.key.alt { font-size: 17px; color: #c3cbf0; background: linear-gradient(180deg, #1b2246, #131938); }
/* The measured-safe green is the TOP stop and the gradient darkens downward.
 * Putting a lighter stop on top of a colour you measured undoes the measurement
 * — a #1f9260 crown took white lettering here from 4.81 to 3.93. */
.key.fire {
  grid-column: span 3; font-size: 17px; letter-spacing: 1.4px; color: #ffffff;
  background: linear-gradient(180deg, #1a8253, #10603b);
  border-color: rgba(74, 222, 128, 0.5);
}
.key.fire:active { background: linear-gradient(180deg, #146b43, #0c4f31); }
@media (max-height: 720px) { .key { height: 40px; font-size: 19px; } .keypad { gap: 5px; padding: 6px; } }
@media (min-width: 620px) { .keypad { max-width: 560px; margin: 0 auto; width: 100%; } }

/* ----------------------------------------------------------------- results */

.res-inner {
  width: 100%; max-width: 460px; margin: auto; text-align: center;
  padding: max(24px, env(safe-area-inset-top)) 18px 28px;
}
.res-emoji { font-size: 52px; line-height: 1; }
.res-title { font-size: 25px; margin: 8px 0 4px; font-weight: 800; }
.res-stars { font-size: 27px; color: #fcd34d; letter-spacing: 3px; height: 32px; }
.res-score { font-size: 42px; font-weight: 800; color: #ffffff; line-height: 1.1; }
.res-sub { color: #a3adda; font-size: 14px; margin-bottom: 12px; }
.res-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-bottom: 12px; }
.res-stats div {
  background: var(--gk-card); border: 1px solid rgba(140, 165, 255, 0.16);
  border-radius: 10px; padding: 8px; font-size: 13px; font-weight: 700;
}
.res-note {
  font-size: 13.5px; line-height: 1.5; color: #c3cbf0; margin: 0 0 12px;
  padding: 10px; border-radius: 11px; min-height: 0;
}
.res-note.work { background: rgba(252, 211, 77, 0.1); border: 1px solid rgba(252, 211, 77, 0.3); }
.res-note.perfect { background: rgba(74, 222, 128, 0.1); border: 1px solid rgba(74, 222, 128, 0.32); }
.res-unlocks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.unlock {
  background: rgba(252, 211, 77, 0.12); border: 1px solid rgba(252, 211, 77, 0.36);
  border-radius: 11px; padding: 9px; font-size: 13px; line-height: 1.35;
}
.res-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.toast { font-family: inherit; }
