:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #f1f3fa;
  background: #0b101e;
  --panel: #151c2e;
  --field: #0c1222;
  --line: #3b4864;
  --muted: #b7c3d8;
  --teal: #8ce9e2;
  --gold: #fac486;
  --focus: #a8fff6;
  --mono: Consolas, "Courier New", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; }
button { font: inherit; }
button, canvas { -webkit-tap-highlight-color: transparent; }
button {
  min-height: 44px;
  min-width: 44px;
  padding: 0.58rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: #202a40;
  color: #f1f3fa;
  font-weight: 650;
  cursor: pointer;
}
button:hover { border-color: #8294b2; background: #2a3751; }
button:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
button:disabled, button[aria-disabled="true"] { opacity: 0.6; cursor: default; }
button:disabled:hover, button[aria-disabled="true"]:hover { background: #202a40; border-color: var(--line); }
button.primary { background: var(--gold); border-color: var(--gold); color: #23170f; }
button.primary:hover { background: #ffdab0; border-color: #ffdab0; }
button.primary[aria-disabled="true"]:hover { background: var(--gold); border-color: var(--gold); }
button[aria-pressed="true"] { border-color: var(--teal); }
.wide { width: 100%; }

.topbar {
  max-width: 1160px;
  margin: 0 auto;
  min-height: 72px;
  padding: 0.6rem clamp(0.85rem, 4vw, 2.6rem);
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}
.brand { display: flex; gap: 0.55rem; align-items: center; background: transparent; border-color: transparent; padding-left: 0.15rem; }
.brand-mark { color: var(--teal); font-size: 1.55rem; line-height: 1; }
main { max-width: 1160px; margin: 0 auto; padding: 1rem clamp(0.85rem, 4vw, 2.6rem) 3rem; }
h1, h2, p, dl { margin: 0; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); letter-spacing: -0.055em; line-height: 1; }
h2 { font-size: 1.65rem; letter-spacing: -0.035em; }
.eyebrow, dt {
  color: var(--teal);
  font: 650 0.75rem/1.4 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.intro { max-width: 33ch; color: var(--muted); font-size: clamp(1rem, 2vw, 1.15rem); line-height: 1.55; }
.deck { color: var(--muted); font-size: 0.84rem; line-height: 1.5; }
.actions { display: flex; flex-wrap: wrap; gap: 0.55rem; }

.title-panel {
  min-height: min(580px, 76svh);
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  overflow: hidden;
  background: radial-gradient(ellipse at 70% 44%, #182945, #101629 70%);
}
.title-copy { position: relative; z-index: 1; padding: clamp(1.45rem, 5vw, 4rem); }
.title-copy h1 { font-size: clamp(3.8rem, 8vw, 7rem); margin: 0.7rem 0 1.1rem; line-height: 0.88; }
.title-copy .actions { margin: 1.45rem 0 0.85rem; }
.title-art canvas { width: 100%; height: auto; aspect-ratio: 10 / 7; display: block; }

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 0.35rem 0 1.2rem;
}
.section-head h1 { margin-top: 0.35rem; }
.mission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 0.7rem;
}
.mission-tile {
  min-height: 106px;
  text-align: left;
  display: grid;
  justify-content: start;
  align-content: space-between;
  gap: 0.35rem;
  padding: 0.85rem;
  background: var(--panel);
}
.mission-tile .medal { color: var(--gold); font-size: 0.83rem; }
.mission-tile:disabled .medal { color: var(--muted); }

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 18rem);
  align-items: start;
  gap: 1rem;
}
.field { border: 1px solid var(--line); border-radius: 0.85rem 0.85rem 0 0; background: var(--field); }
.field canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 10 / 7;
  border-radius: inherit;
  touch-action: none;
  cursor: crosshair;
}
.telemetry {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 0.85rem 0.85rem;
}
.telemetry div { padding: 0.7rem 0.9rem; }
.telemetry div + div { border-left: 1px solid var(--line); }
.telemetry dd { margin: 0.1rem 0 0; font-weight: 650; }
.flight-actions { display: flex; gap: 0.55rem; margin-top: 0.65rem; }
.console {
  display: grid;
  gap: 0.65rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  background: var(--panel);
}
.status { min-height: 3rem; }
.status p + p { margin-top: 0.25rem; }
.steppers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.stepper { display: grid; gap: 0.4rem; }
.stepper-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 0.3rem; font-size: 0.83rem; }
.stepper output { color: var(--gold); font: 700 0.9rem var(--mono); }
.stepper-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; }
.stepper-buttons button { padding: 0; font-size: 1.22rem; }
.console-tools { display: flex; flex-wrap: wrap; gap: 0.38rem; padding-top: 0.25rem; }
.console-tools button { flex: 1 1 auto; padding-inline: 0.45rem; }
.mission-hint {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.results {
  min-height: 400px;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: radial-gradient(ellipse at 50% 28%, #203953, #151c2e 60%);
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.65rem;
  text-align: center;
  padding: 2rem 1rem;
}
.results .actions { justify-content: center; margin-top: 0.65rem; }
.result-mark {
  display: grid;
  place-items: center;
  color: var(--teal);
  width: 66px;
  height: 66px;
  border: 1px solid var(--teal);
  border-radius: 50%;
  font-size: 2rem;
}
.result-stars { color: var(--gold); font-size: 2.5rem; letter-spacing: 0.1em; padding-left: 0.1em; }
.results .intro { max-width: 48ch; }
.storage-note { margin-top: 1rem; color: var(--muted); }

dialog {
  width: min(calc(100% - 1.7rem), 480px);
  max-height: calc(100% - 1.7rem);
  padding: clamp(1.15rem, 5vw, 1.6rem);
  border: 1px solid #8294b2;
  border-radius: 0.9rem;
  color: inherit;
  background: var(--panel);
}
dialog::backdrop { background: #060912d9; }
dialog ol { padding-left: 1.3rem; }
dialog li { margin: 0.45rem 0; line-height: 1.5; }
dialog p { margin-top: 0.7rem; line-height: 1.5; color: var(--muted); }
dialog .actions { margin-top: 1rem; }

@media (max-width: 760px) {
  .topbar { min-height: 62px; }
  .game-grid { grid-template-columns: 1fr; gap: 0.7rem; }
  .title-panel { grid-template-columns: 1fr; min-height: 0; }
  .title-art { margin-top: -1.75rem; }
  .title-art canvas { width: min(100%, 440px); margin-inline: auto; }
  .mission-head { margin-top: 0; }
}
@media (max-width: 420px) {
  .section-head { align-items: center; }
  .section-head h1 { font-size: 1.85rem; }
  .telemetry div { padding: 0.5rem 0.65rem; }
  .mission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (forced-colors: active) {
  .field, .telemetry, .console, .title-panel, .results, .result-mark { border-color: CanvasText; }
}
