/* Sky Patrol — layout and theme.
   Container queries (cqw) scale the in-game screens with the stage, so the
   hangar reads the same on a phone and on a desktop. */

:root {
  --bg: #070b1a;
  --bg-2: #0d1430;
  --panel: #141b36;
  --line: #27325a;
  --ink: #f3f6ff;
  --muted: #a9b4d8;
  --accent: #d8fd71;
  --accent-ink: #14210a;
  --sky: #7ec8ff;
  --danger: #ff7a7a;
  --gold: #ffd93d;
  --radius: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Class rules below set `display`, which would otherwise beat [hidden]. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 20% -10%, #1d2a5c 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 0%, #3a1f52 0%, transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- shell ---------- */

.app {
  min-height: 100dvh;
  display: grid;
  /* A definite column, so a percentage width on the stage resolves against it.
     Left to size itself, the stage came out wider than a phone screen. */
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  align-content: start;
  gap: 16px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

@media (min-width: 1024px) {
  .app {
    grid-template-columns: auto minmax(300px, 360px);
    justify-content: center;
    align-items: start;
    gap: 24px;
    padding: 24px;
  }
}

.stage {
  position: relative;
  container-type: inline-size;
  width: min(100%, calc((100dvh - 32px) * 0.6));
  aspect-ratio: 3 / 5;
  border-radius: calc(var(--radius) + 6px);
  overflow: hidden;
  background: #0b1128;
  box-shadow:
    0 0 0 1px var(--line),
    0 30px 70px -20px rgba(0, 0, 0, 0.8);
  touch-action: none;
}

@media (min-width: 1024px) {
  .stage { width: min(calc((100dvh - 48px) * 0.6), 620px); }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- hud ---------- */

.hud {
  position: absolute;
  inset: 0;
  /* room on the right for the pause button, which floats over the sky */
  padding: 10px 62px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  font-size: clamp(11px, 3.1cqw, 17px);
}

.hud__row { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(8, 12, 30, 0.62);
  border: 1px solid rgba(126, 200, 255, 0.25);
  backdrop-filter: blur(3px);
}

.pill__label {
  font-size: 0.72em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.pill b { font-variant-numeric: tabular-nums; }

.hud__gear {
  --weapon: #7ef7ff;
  position: relative;
  margin: 0;
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 12px;
  background: rgba(8, 12, 30, 0.68);
  border: 1px solid rgba(126, 200, 255, 0.4);
  border: 1px solid color-mix(in srgb, var(--weapon) 55%, transparent);
  color: var(--ink);
  font-size: 0.9em;
  min-width: 168px;
}

.gear__dot {
  width: 11px;
  height: 11px;
  flex: none;
  border-radius: 50%;
  background: var(--weapon);
  box-shadow: 0 0 10px var(--weapon);
}

.hud__gear b {
  letter-spacing: 0.1em;
  font-size: 1.02em;
}

.gear__level,
.gear__time {
  font-size: 0.85em;
  color: var(--weapon);
  font-variant-numeric: tabular-nums;
}

.gear__level::before { content: ''; }

.hud__gear[data-levelled="false"] .gear__level {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75em;
}

.gear__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  border-radius: 0 0 12px 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
}

.gear__bar i {
  display: block;
  height: 100%;
  background: var(--weapon);
  box-shadow: 0 0 8px var(--weapon);
  transition: width 120ms linear;
}

.hud__shield {
  margin: 0;
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(8, 12, 30, 0.62);
  border: 1px solid rgba(90, 216, 255, 0.45);
  color: #5ad8ff;
  font-size: 0.85em;
}

.hud__boss { margin-top: 2px; max-width: 70%; }

.hud__boss-name {
  margin: 0 0 3px;
  font-size: 0.78em;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--danger);
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(8, 12, 30, 0.75);
  border: 1px solid rgba(255, 122, 122, 0.45);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff9f43, #ff4d4d);
  transition: width 120ms linear;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(126, 200, 255, 0.3);
  background: rgba(8, 12, 30, 0.68);
  color: var(--ink);
  cursor: pointer;
}

.icon-btn svg { fill: currentColor; }
.icon-btn:hover { background: rgba(20, 30, 60, 0.85); }

.hud__pause {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  z-index: 3;
}

/* ---------- in-stage screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 4cqw;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    linear-gradient(180deg, rgba(8, 12, 32, 0.92) 0%, rgba(10, 16, 40, 0.96) 100%);
  text-align: center;
}

.screen--dim { background: linear-gradient(180deg, rgba(6, 9, 24, 0.8), rgba(6, 9, 24, 0.92)); }

.screen__inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.4cqw;
}

/* keeps "Start run" reachable however long the hangar gets */
.screen__actions {
  position: sticky;
  bottom: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 1.6cqw 0 0.4cqw;
  background: linear-gradient(180deg, rgba(10, 16, 40, 0) 0%, rgba(10, 16, 40, 0.92) 55%);
}

.eyebrow {
  margin: 0;
  font-size: clamp(10px, 2.9cqw, 14px);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}

.title {
  margin: 0;
  font-size: clamp(30px, 11cqw, 58px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #ffffff, var(--sky));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title--sm { font-size: clamp(24px, 8.5cqw, 44px); }

.tagline {
  margin: 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: clamp(12px, 3.3cqw, 17px);
}

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

.masthead {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.4cqw;
}

.ships {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  width: 100%;
}

.ships__legend {
  padding: 0;
  font-size: clamp(13px, 3.4cqw, 18px);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ships__note { margin: 2px 0 0; }

/* Five across in one row. An auto-fit grid looked fine and read terribly: it
   stranded the fifth aircraft on its own row, directly under the start
   button, which read as a mistake rather than a choice. */
.ships__strip {
  margin-top: 2.2cqw;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1.4cqw;
}

.ship {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2cqw 1cqw;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(20, 27, 54, 0.72);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}

.ship:hover { border-color: #4a5c96; transform: translateY(-2px); }

.ship input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.ship canvas {
  display: block;
  width: auto;
  max-width: min(100%, 68px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.ship__name {
  font-size: clamp(9px, 2.5cqw, 13px);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  /* two lines reserved either way, so all five cards keep the same height */
  min-height: 2.3em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ship__blurb { display: none; }

/* bigger cards once there is genuinely room for them */
@container (min-width: 30rem) {
  .ships__strip { gap: 2cqw; }
  .ship canvas { max-width: min(100%, 96px); }
  .ship__name { font-size: clamp(12px, 2.8cqw, 15px); }
}

.ship:has(input:checked) {
  border-color: var(--accent);
  background: rgba(38, 52, 30, 0.75);
  box-shadow: 0 0 0 1px var(--accent), 0 10px 24px -12px rgba(216, 253, 113, 0.6);
}

.ship:has(input:focus-visible) { outline: 3px solid var(--sky); outline-offset: 2px; }

/* Your character is the reason this is on Start.ng at all, so it gets the
   hero position rather than being squeezed into a sidebar. */
.pilot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.4cqw;
  padding: 3.4cqw 3cqw;
  border-radius: 18px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 0%, rgba(126, 200, 255, 0.14), transparent 62%),
    rgba(20, 27, 54, 0.6);
}

.pilot__frame {
  padding: 6px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--sky), #6f7bf0);
  box-shadow: 0 0 0 1px rgba(126, 200, 255, 0.5), 0 12px 28px -14px rgba(126, 200, 255, 0.9);
}

.pilot__art {
  display: block;
  width: clamp(72px, 19cqw, 108px);
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #26305e, #131a36);
}

.pilot__info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.pilot__eyebrow {
  margin: 0;
  font-size: clamp(9px, 2.4cqw, 12px);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.pilot__name {
  margin: 0;
  font-size: clamp(16px, 4.4cqw, 24px);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.pilot__sub {
  margin: 0;
  font-size: clamp(10px, 2.8cqw, 13px);
  color: var(--muted);
}

.pilot__note {
  margin: 4px 0 0;
  font-size: clamp(9px, 2.4cqw, 12px);
}

/* Sign in, on the title screen, where a phone player can actually find it.
   It used to live only in the sidebar, below the whole game. */
.pilot__signin {
  margin-top: 1.6cqw;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid rgba(126, 200, 255, 0.55);
  background: rgba(126, 200, 255, 0.12);
  color: var(--ink);
  font-size: clamp(10px, 2.8cqw, 13px);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}

.pilot__signin:hover {
  background: rgba(126, 200, 255, 0.24);
  border-color: var(--sky);
}

/* the offline explanation belongs in the sidebar card, not on the title screen */
@container (max-width: 30rem) {
  .pilot__note { display: none; }
}

/* ---------- how to ---------- */

.howto {
  width: 100%;
  text-align: left;
  padding: 3cqw;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(13, 19, 44, 0.6);
  font-size: clamp(10px, 2.8cqw, 14px);
}

.howto summary {
  cursor: pointer;
  font-weight: 700;
  font-size: clamp(11px, 3.2cqw, 16px);
}

.howto__grid {
  margin-top: 2cqw;
  display: grid;
  gap: 2.4cqw;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
}

.howto h3 {
  margin: 0 0 4px;
  font-size: 1em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.howto ul { margin: 0; padding-left: 1.1em; }
.howto li { margin-bottom: 2px; color: var(--muted); }

kbd {
  display: inline-block;
  min-width: 1.6em;
  margin-right: 2px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: #1b2448;
  font: inherit;
  font-size: 0.92em;
  text-align: center;
  color: var(--ink);
}

.tag {
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.95em;
  color: #0c1124;
}
.tag--spread { background: #ff8a3d; }
.tag--rapid { background: #a6ff7e; }
.tag--laser { background: #ff5cf0; color: #fff; }
.tag--shield { background: #5ad8ff; }
.tag--repair { background: #7cf07c; }
.tag--emp { background: #c58cff; }
.tag--star { background: var(--gold); }

/* ---------- buttons ---------- */

.btn {
  min-height: 44px;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #1c2549;
  color: var(--ink);
  font: inherit;
  font-size: clamp(13px, 3.4cqw, 17px);
  font-weight: 600;
  cursor: pointer;
  transition: transform 100ms ease, background 120ms ease, border-color 120ms ease;
}

.btn:hover { background: #26315f; border-color: #4a5c96; }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  padding-inline: 30px;
}
.btn--primary:hover { background: #e6ff9a; border-color: #e6ff9a; }

.btn--ghost { background: transparent; }
.btn--small { min-height: 38px; padding: 6px 14px; font-size: 13px; }

/* the one action on the title screen deserves to look like it */
.btn--big {
  min-height: clamp(48px, 12cqw, 60px);
  padding: 0 clamp(28px, 8cqw, 46px);
  font-size: clamp(16px, 4.4cqw, 22px);
  letter-spacing: 0.04em;
  border-radius: 999px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2cqw;
}

/* One obvious action, then the alternatives beneath it. Left to wrap on their
   own they came out 2 + 1, which made the single button look like an orphan. */
.btn-col {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6cqw;
}

.btn-col > .btn { width: 100%; }

.btn-col .btn-row {
  width: 100%;
  gap: 1.6cqw;
}

.btn-col .btn-row > .btn { flex: 1 1 0; min-width: 0; }

:where(button, a, input, summary):focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 2px;
}

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

.results {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2cqw;
}

/* The score is the thing you came to read, so it is the thing that is big. */
.results__hero {
  padding: 3cqw 2.4cqw;
  border-radius: 16px;
  border: 1px solid rgba(216, 253, 113, 0.35);
  background:
    radial-gradient(120% 140% at 50% 0%, rgba(216, 253, 113, 0.12), transparent 70%),
    rgba(24, 33, 20, 0.6);
}

.results__label {
  margin: 0;
  font-size: clamp(9px, 2.6cqw, 13px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.results__score {
  margin: 2px 0 0;
  font-size: clamp(38px, 13cqw, 68px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* two by two, so four stats fill the row evenly. Five equal tiles left an
   awkward short row and a label that wrapped and threw the heights out. */
.results__grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2cqw;
}

.results__grid > div {
  padding: 2.2cqw 1.8cqw;
  border-radius: 12px;
  background: rgba(20, 27, 54, 0.72);
  border: 1px solid var(--line);
}

.results dt {
  font-size: clamp(9px, 2.5cqw, 12px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.25;
}

.results dd {
  margin: 4px 0 0;
  font-size: clamp(16px, 4.6cqw, 26px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* three stats, so a single row rather than a stranded pair */
.results--mini {
  flex-direction: row;
  gap: 1.6cqw;
}

.results--mini > div {
  flex: 1 1 0;
  min-width: 0;
  padding: 2.2cqw 1.6cqw;
  border-radius: 12px;
  background: rgba(20, 27, 54, 0.72);
  border: 1px solid var(--line);
}

.results--mini dd { font-size: clamp(15px, 4.2cqw, 22px); }

.save-note {
  margin: 0;
  min-height: 1.4em;
  font-size: clamp(11px, 3cqw, 15px);
  color: var(--accent);
}

.save-note[data-tone="warn"] { color: var(--gold); }
.save-note[data-tone="bad"] { color: var(--danger); }

/* ---------- side panel ---------- */

.panel {
  width: min(100%, 640px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (min-width: 1024px) {
  .panel { width: auto; position: sticky; top: 24px; max-height: calc(100dvh - 48px); overflow-y: auto; }
}

.panel h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.note {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.startng-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  background: #1a2140;
  border: 1px solid var(--line);
  color: var(--ink);
}

.startng-card img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #2b3566;
  object-fit: cover;
}

.startng-card__initial {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-left: -8px;
  border-radius: 50%;
  background: linear-gradient(180deg, #d8fd71, #7ec8ff);
  color: #101a3d;
  font-size: 20px;
  font-weight: 800;
}

.startng-card[data-has-face="true"] .startng-card__initial { display: none; }

.startng-card__id { min-width: 0; flex: 1; }
.startng-card b { display: block; font-size: 16px; }
.startng-card span { font-size: 12px; opacity: 0.75; }

.startng-card__btn {
  margin-left: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}

.startng-card__btn:hover { background: #e6ff9a; }

.board, .help {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(20, 27, 54, 0.7);
}

.board__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.link-btn {
  border: 0;
  background: none;
  color: var(--sky);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 2px;
}

.board__scroll { overflow-x: auto; }

.board table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.board th, .board td {
  padding: 6px 8px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid rgba(39, 50, 90, 0.7);
}

.board th:nth-child(1), .board td:nth-child(1),
.board th:nth-child(2), .board td:nth-child(2) { text-align: left; }

.board thead th {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.board tbody tr { color: var(--ink); }
.board tbody tr.is-you { background: rgba(216, 253, 113, 0.12); }
.board tbody tr.is-you td:first-child { color: var(--accent); }
.board .board-empty { color: var(--muted); text-align: left; }

.help__list { margin: 8px 0 10px; padding-left: 1.1em; color: var(--muted); font-size: 13px; }
.help__list li { margin-bottom: 4px; }

.panel__foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}