html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #020407;
  color: #d8edf4;
  font: 14px/1.4 system-ui, sans-serif;
}

#app {
  position: fixed;
  inset: 0;
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
}

#hud,
#controls {
  position: fixed;
  left: 16px;
  right: 16px;
  z-index: 2;
  border: 1px solid rgba(74, 213, 232, 0.55);
  background: rgba(0, 8, 14, 0.72);
  box-sizing: border-box;
}

#hud {
  top: 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
}

#hud strong {
  display: block;
  font-size: 13px;
  letter-spacing: 0;
}

#status {
  display: block;
  color: #9eb6bf;
}

#metrics {
  text-align: right;
  max-width: 75%;
  white-space: pre-line;
}

#controls {
  bottom: 16px;
  padding: 9px 12px;
  color: #9eb6bf;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

button {
  border: 1px solid #4ad5e8;
  background: #082330;
  color: #d8edf4;
  font: inherit;
  padding: 8px 14px;
  cursor: pointer;
}

button:hover {
  background: #123b49;
}

button:focus-visible {
  outline: 2px solid #ffd166;
  outline-offset: 3px;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

#primary-action {
  flex-shrink: 0;
}

#page-elements {
  position: fixed;
  inset: 112px 16px 104px;
}

#title-menu {
  position: fixed;
  z-index: 2;
  left: 8%;
  top: 50%;
  transform: translateY(-50%);
  width: min(480px, 75vw);
  padding: 28px 32px;
  box-sizing: border-box;
  background: linear-gradient(120deg, rgba(6, 18, 25, 0.97), rgba(6, 18, 25, 0.76));
  border: 1px solid rgba(128, 179, 185, 0.3);
  border-radius: 8px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.25);
}

#title-menu[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 12px;
  color: #b7cfba;
  font-size: 12px;
  letter-spacing: 0.2em;
}

#title-menu h1 {
  margin: 0 0 14px;
  font-size: clamp(26px, 3vw, 40px);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.title-description {
  color: #afc1c6;
  line-height: 1.7;
  margin: 0 0 24px;
}

.sortie-actions {
  display: flex;
  gap: 10px;
}

.sortie-actions button {
  flex: 1;
  min-height: 46px;
  border-radius: 4px;
}

#terrain-action {
  color: #11251c;
  background: #c7d8a1;
  border-color: #c7d8a1;
  font-weight: 650;
}

#terrain-action:hover {
  background: #e0ecc3;
}

#title-menu button[data-focused="true"] {
  outline: 2px solid #ffd166;
  outline-offset: 3px;
}

.action-caption {
  display: block;
  font-size: 11px;
  font-weight: 400;
  margin-top: 2px;
}

.seed-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  color: #a6b9af;
  font-size: 12px;
}

#terrain-seed-action {
  padding: 5px 10px;
  border-color: #415b54;
  background: transparent;
  border-radius: 4px;
}

.title-hint {
  color: #8fa3ac;
  font-size: 12px;
  margin: 22px 0 0;
}

body[data-game-mode="terrain"] #metrics {
  color: #e2e8cd;
  max-width: none;
  text-align: left;
  margin: 0;
}

body[data-game-mode="terrain"] #hud {
  top: 8px;
  left: 16px;
  right: 16px;
  display: block;
  border: 0;
  border-radius: 8px;
  background: rgba(8, 19, 20, 0.9);
  padding: 7px 16px;
  font-size: 12px;
  line-height: 1.3;
}

body[data-game-mode="terrain"] #hud > div:first-child > strong,
body[data-game-mode="terrain"] #controls,
body[data-deck-menu="true"] #hud {
  display: none;
}

.terrain-metrics {
  display: grid;
  grid-template-columns: 1fr 0.7fr 1fr 1.4fr 0.8fr;
  align-items: center;
  gap: 4px 20px;
}

.terrain-stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.terrain-sector {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 8px;
}

.terrain-sector progress {
  grid-column: 1 / -1;
}

.terrain-roll {
  grid-column: 5;
  grid-row: 1;
}

.terrain-label {
  color: #acbbb2;
  font-size: 11px;
}

body[data-game-mode="terrain"] #hud .terrain-value {
  color: #f0f2dd;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

body[data-game-mode="terrain"] #hud .terrain-shield[data-low="true"] strong {
  color: #ffd096;
}

body[data-game-mode="terrain"] #hud .terrain-roll[data-ready="true"] strong {
  color: #bde4b4;
}

.terrain-metrics progress {
  display: block;
  width: 100%;
  height: 4px;
  margin-top: 5px;
  border: 0;
  border-radius: 3px;
  overflow: hidden;
  appearance: none;
  accent-color: #bed898;
}

.terrain-metrics progress::-webkit-progress-bar {
  background: #3b4842;
}

.terrain-metrics progress::-webkit-progress-value {
  background: #bed898;
}

.terrain-gear {
  position: fixed;
  left: 32px;
  bottom: 18px;
  max-width: calc(100vw - 64px);
  padding: 5px 9px;
  border-radius: 4px;
  background: rgba(8, 19, 20, 0.86);
  color: #c2cebc;
  font-size: 11px;
}

.terrain-boss {
  grid-column: 4;
  grid-row: 1;
  color: #ffd59f;
  text-align: left;
}

.terrain-boss progress::-webkit-progress-value {
  background: #eeae73;
}

body[data-game-mode="terrain"] #status {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 64px);
  padding: 10px 18px;
  border-radius: 6px;
  background: rgba(8, 19, 20, 0.94);
  color: #ffe0a5;
  font-size: 15px;
  text-align: center;
}

#status[hidden],
.terrain-sector[hidden],
.terrain-gear[hidden],
.terrain-boss[hidden],
#deck-menu[hidden] {
  display: none;
}

#deck-menu {
  position: fixed;
  inset: 5% max(24px, 8%);
  z-index: 20;
  overflow: auto;
  box-sizing: border-box;
  padding: clamp(20px, 3vh, 32px);
  border: 1px solid #627c71;
  border-radius: 14px;
  background: rgba(10, 24, 27, 0.98);
  box-shadow: 0 24px 80px #0008;
  color: #edf0df;
}

.deck-heading {
  margin: 0 0 8px;
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 650;
}

.deck-detail {
  margin: 0 0 4px;
  color: #dae8bd;
  font-size: 16px;
}

.deck-explanation {
  margin: 0 0 22px;
  color: #a9bab2;
  font-size: 13px;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.deck-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  min-height: 160px;
  padding: 15px;
  border: 1px solid #607875;
  border-radius: 8px;
  background: #17292f;
  text-align: left;
  color: #eff1e5;
}

.deck-card[data-included="true"] {
  border-color: #85a988;
  background: #233b35;
}

.deck-card:hover {
  background: #243945;
}

.deck-card[data-included="true"]:hover {
  background: #30483e;
}

.card-category {
  color: #b8d3da;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.deck-card[data-category="defense"] .card-category {
  color: #b9d5a9;
}

.deck-card[data-category="utility"] .card-category {
  color: #e0c092;
}

.card-name {
  font-size: 18px;
  font-weight: 600;
}

.card-description,
.card-replacement {
  color: #bacbc4;
  font-size: 13px;
}

.card-state {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  color: #d8e9c2;
  font-size: 13px;
  font-weight: 600;
}

.card-action {
  color: #aebfb5;
  font-size: 11px;
  font-weight: 400;
}

.deck-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 22px;
}

.deck-controls {
  margin: 0;
  color: #99aea5;
  font-size: 12px;
}

.deck-actions {
  display: flex;
  gap: 10px;
}

.deck-actions button {
  min-height: 48px;
  border-radius: 6px;
}

.deck-launch {
  min-width: 215px;
  border-color: #ead190;
  background: #ead190;
  color: #253025;
  font-size: 17px;
  font-weight: 650;
}

.deck-launch:hover {
  background: #f5dfa9;
}

.deck-secondary {
  border-color: #789289;
  background: #213933;
}

#deck-menu button[data-focused="true"] {
  outline: 3px solid #ffd780;
  outline-offset: 3px;
}

@media (max-width: 760px) {
  #deck-menu {
    inset: 16px;
  }

  .deck-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .deck-footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .deck-actions button {
    flex: 1;
  }

  .terrain-metrics {
    gap: 4px 10px;
  }
}

@media (max-height: 600px) {
  body[data-game-mode="terrain"] #hud {
    top: 4px;
    padding-block: 5px;
  }

  #deck-menu {
    inset: 14px max(20px, 5%);
    padding: 18px 22px;
  }

  .deck-card {
    min-height: 130px;
    padding: 12px;
    gap: 5px;
  }

  .deck-explanation {
    margin-bottom: 14px;
  }

  .deck-footer {
    margin-top: 16px;
  }
}

@media (max-height: 600px) {
  #title-menu {
    padding: 20px 26px;
  }

  .title-description {
    margin-bottom: 16px;
  }

  .title-hint {
    margin-top: 14px;
  }
}

.page-element {
  position: absolute;
  box-sizing: border-box;
  padding: 6px 10px;
  overflow: auto;
  border: 1px solid #24616c;
  background: rgba(0, 8, 14, 0.86);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.page-element[data-focused="true"] {
  border-color: #ffd166;
}

@media (max-width: 720px) {
  #hud {
    display: block;
  }

  #metrics {
    margin-top: 6px;
    text-align: left;
    max-width: none;
  }

  #page-elements {
    top: 156px;
  }
}

/* Cartridge-era title over the retained native terrain flyover. */
@font-face {
  font-family: "Press Start 2P";
  src: url("./fonts/press-start-2p.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
body[data-page="title"] #hud,
body[data-page="title"] #controls { display: none; }
body[data-runtime-status="error"] #hud { display: block; }
body[data-page="title"] #title-menu {
  inset: 0;
  width: auto;
  transform: none;
  display: flex;
  padding: 28px 24px 80px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow-y: auto;
  scroll-padding-block: 24px 80px;
  text-align: center;
  background: linear-gradient(0deg, #050d24e8, transparent 25%, transparent 80%, #050d2499),
    radial-gradient(ellipse at center, #08132bed 12%, #08132bcc 42%, #08132b38 100%);
}
body[data-page="title"] #title-menu::before {
  content: "";
  position: fixed;
  inset: 12px;
  border: 2px solid #637ca14d;
  box-shadow: 0 0 0 3px #050d2466, inset 0 0 0 3px #050d2466;
  pointer-events: none;
}
body[data-page="title"] #title-menu::after {
  content: "";
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(transparent 0 3px, #02051612 3px 4px);
  pointer-events: none;
}
.title-stack { position: relative; width: min(560px, 100%); flex-shrink: 0; margin: auto; }
body[data-page="title"] .eyebrow {
  color: #e1e7ee;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font: 9px/1.8 "Press Start 2P", ui-monospace, monospace;
  letter-spacing: 0;
  margin: 0 0 18px;
  text-shadow: 2px 2px #050d24;
}
.brand-mark {
  width: 10px;
  height: 10px;
  background: #ffcc73;
  clip-path: polygon(40% 0, 60% 0, 60% 30%, 70% 30%, 70% 40%, 100% 40%, 100% 60%, 70% 60%, 70% 70%, 60% 70%, 60% 100%, 40% 100%, 40% 70%, 30% 70%, 30% 60%, 0 60%, 0 40%, 30% 40%, 30% 30%, 40% 30%);
}
.edition { color: #aabbd2; font-size: 8px; }
body[data-page="title"] #title-menu h1 { margin: 0 0 16px; font-size: inherit; line-height: 0; }
.title-logo { display: block; width: min(480px, 100%); height: auto; margin: 0 auto; image-rendering: pixelated; }
.mission-tag { color: #ffd18b; font: 8px/1.8 "Press Start 2P", ui-monospace, monospace; margin: 0 0 22px; }
body[data-page="title"] #title-menu .sortie-actions {
  width: min(352px, 100%);
  margin: 0 auto;
  flex-direction: column;
  gap: 6px;
}
body[data-page="title"] #title-menu .sortie-actions button {
  position: relative;
  flex: none;
  min-width: 0;
  min-height: 52px;
  border-radius: 0;
  text-align: left;
  padding: 10px 16px 10px 42px;
  background: #08132b99;
  border: 2px solid transparent;
  color: #bccbe1;
  font: 10px/1.6 "Press Start 2P", ui-monospace, monospace;
  letter-spacing: 0;
  text-shadow: 2px 2px #05091d;
}
body[data-page="title"] #title-menu .sortie-actions button::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 16px;
  width: 12px;
  height: 12px;
  background: #ffd17c;
  clip-path: polygon(0 0, 4px 0, 4px 2px, 8px 2px, 8px 4px, 12px 4px, 12px 8px, 8px 8px, 8px 10px, 4px 10px, 4px 12px, 0 12px);
  visibility: hidden;
}
body[data-page="title"] #title-menu .sortie-actions button[data-focused="true"] {
  color: #fff0be;
  background: #162c4df2;
  border-color: #f3be6b;
  box-shadow: 4px 4px 0 #05091d;
  outline: none;
}
body[data-page="title"] #title-menu .sortie-actions button[data-focused="true"]::before { visibility: visible; }
body[data-page="title"] #title-menu .sortie-actions button:hover { background: #213752; color: #fff0be; }
body[data-page="title"] #title-menu .sortie-actions button:focus-visible { outline: 2px solid #fff2c7; outline-offset: 4px; }
body[data-page="title"] .action-caption { margin-top: 5px; color: #c2cedd; font: 11px/1.4 system-ui, sans-serif; letter-spacing: .03em; text-shadow: none; }
body[data-page="title"] .seed-controls { justify-content: center; color: #b2c2d8; margin-top: 12px; font: 11px/1.4 ui-monospace, monospace; }
body[data-page="title"] .title-hint { display: flex; flex-direction: column; gap: 9px; line-height: 1.6; color: #c1cde0; font-size: 11px; margin: 18px 0 0; }
.start-prompt { color: #ffe2a3; font: 8px/1.8 "Press Start 2P", ui-monospace, monospace; }
kbd { font: 10px system-ui, sans-serif; color: #e6e8d0; padding: 3px 5px; border: 1px solid #60766a; border-radius: 2px; margin-right: 4px; }
.attract-label { color: #bdcfe3; font: 8px/1.8 "Press Start 2P", ui-monospace, monospace; display: flex; justify-content: center; gap: 8px; align-items: center; margin-top: 16px; }
.live-dot { width: 6px; height: 6px; background: #9cdebd; }
.teaser-credit { margin: 14px 0 0; color: #a8bad1; font: 10px/1.6 ui-monospace, monospace; letter-spacing: .08em; }
#flight-controls { position: fixed; z-index: 3; bottom: 10px; left: 24px; right: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #d3dcc5; font-size: 11px; }
#flight-controls[hidden], body[data-deck-menu="true"] #flight-controls { display: none; }
#return-title { font-size: 12px; border-radius: 4px; border-color: #8ba68a; background: #102421e8; padding: 7px 12px; }
#return-title span { color: #94aa9c; font-size: 10px; margin-left: 8px; }
body[data-game-mode="terrain"] .terrain-gear { bottom: 48px; }
@media (max-width: 650px) {
  body[data-page="title"] #title-menu { padding: 26px 22px 80px; }
  body[data-page="title"] .eyebrow { font-size: 8px; gap: 8px; }
  .edition { font-size: 7px; }
  .mission-tag { font-size: 7px; }
  body[data-page="title"] #title-menu .sortie-actions button { font-size: 9px; }
  #flight-controls { left: 12px; right: 12px; }
  #flight-controls > span { max-width: 230px; }
  .terrain-metrics { grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .terrain-roll { grid-column: 2; grid-row: 2; }
  .terrain-boss { grid-column: 1; grid-row: 2; }
  body[data-game-mode="terrain"] #hud { padding: 6px 10px; left: 8px; right: 8px; }
}
@media (max-height: 620px) {
  body[data-page="title"] #title-menu { padding-top: 22px; }
  body[data-page="title"] .eyebrow { margin-bottom: 12px; }
  .title-logo { width: min(310px, 100%); }
  body[data-page="title"] #title-menu h1 { margin-bottom: 14px; }
  .mission-tag { display: none; }
  body[data-page="title"] .action-caption { display: none; }
  body[data-page="title"] #title-menu .sortie-actions { gap: 4px; }
  body[data-page="title"] #title-menu .sortie-actions button { min-height: 44px; padding-top: 10px; padding-bottom: 10px; }
  body[data-page="title"] #title-menu .sortie-actions button::before { top: 14px; }
  body[data-page="title"] .title-hint { margin-top: 12px; }
  .attract-label { display: none; }
  .teaser-credit { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }

#audio-settings { position: fixed; z-index: 10; right: 135px; bottom: 12px; color: #e8e9d0; font-size: 12px; }
#audio-settings summary { cursor: pointer; padding: 6px 10px; border: 1px solid #809986; border-radius: 4px; background: #102421f0; }
.audio-panel { position: absolute; bottom: 38px; right: 0; width: 230px; max-height: calc(100vh - 85px); overflow-y: auto; padding: 16px; background: #102421fa; border: 1px solid #819780; border-radius: 6px; box-shadow: 0 12px 35px #0008; }
.audio-panel label { display: flex; flex-direction: column; gap: 7px; margin-top: 14px; }
.audio-panel input { width: 100%; accent-color: #f4dda6; }
.audio-panel select { padding: 7px; color: #edf0d3; background: #183530; border: 1px solid #82947e; }
#audio-toggle { width: 100%; font-size: 12px; padding: 8px; }
#audio-status { margin: 12px 0 0; color: #b9c9b3; font-size: 11px; line-height: 1.5; }
#music-credit { display: block; margin-top: 10px; color: #f4dda6; font-size: 10px; }
#music-credit[hidden] { display: none; }
#sid-balance-control[hidden] { display: none; }
body[data-page="title"] #audio-settings { right: 24px; bottom: 16px; }
@media (max-width: 650px) {
  #audio-settings { right: 112px; bottom: 10px; }
  body[data-page="title"] #audio-settings { right: 16px; bottom: 12px; }
  .audio-panel { width: 210px; right: -70px; }
  body[data-page="title"] .audio-panel { right: 0; }
  #flight-controls > span { max-width: 175px; font-size: 10px; }
}

/* Persistent keyboard-reachable tools stay outside the scrolling game menus. */
#player-tools {
  position: fixed;
  z-index: 10;
  left: 16px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
}
#player-tools button, #player-tools summary, #return-title {
  box-sizing: border-box;
  min-height: 44px;
  border: 1px solid #809986;
  border-radius: 4px;
  padding: 10px 12px;
  background: #102421f5;
  color: #e8e9d0;
  font-size: 12px;
}
#pause-action[hidden] { display: none; }
#player-tools #audio-settings { position: relative; inset: auto; }
#player-tools .audio-panel { left: 0; right: auto; bottom: 52px; width: min(250px, calc(100vw - 48px)); box-sizing: border-box; }
body[data-page="title"] #title-menu { padding-bottom: 80px; }
#input-requirements { margin: 12px 0 0; color: #c4d0bd; font-size: 12px; }
body[data-page="title"] #input-requirements { color: #c1cde0; font-size: 11px; }
@media (min-height: 621px) and (max-height: 800px) {
  body[data-page="title"] .eyebrow { margin-bottom: 14px; }
  .title-logo { width: min(420px, 100%); }
  .mission-tag { margin-bottom: 16px; }
  body[data-page="title"] .title-hint { margin-top: 14px; }
  .attract-label { margin-top: 12px; }
}
#flight-controls { justify-content: flex-end; pointer-events: none; }
#flight-controls > span { display: none; }
#return-title { pointer-events: auto; }
#player-tools summary:focus-visible, #player-tools input:focus-visible, #player-tools select:focus-visible, a:focus-visible {
  outline: 2px solid #ffd166;
  outline-offset: 3px;
}
#player-dialog {
  box-sizing: border-box;
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: clamp(16px, 4vw, 28px);
  border: 1px solid #8ba68a;
  border-radius: 8px;
  background: #102421;
  color: #e8e9d0;
  font-size: 14px;
  line-height: 1.6;
}
#player-dialog::backdrop { background: #020b10d9; }
#player-dialog h2 { margin: 0 0 12px; color: #ffe7b6; }
.control-list { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; }
.control-list dt { font-weight: 700; color: #ffe7b6; }
.control-list dd { margin: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.dialog-actions button { min-height: 44px; }
#resume-action { color: #182e24; background: #ead190; border-color: #ead190; }
.compatibility-card {
  position: fixed;
  z-index: 20;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: 24px;
  color: #e8e9d0;
  background: #102421;
  border: 1px solid #8ba68a;
  border-radius: 8px;
}
.compatibility-card[hidden] { display: none; }
.compatibility-card a { display: inline-block; padding: 12px 0; color: #ffe7b6; }
@media (max-width: 650px) {
  #player-tools { left: 8px; gap: 6px; }
  #player-tools button, #player-tools summary, #return-title { padding: 10px 8px; }
  #pause-action kbd { display: none; }
  #player-tools .audio-panel { left: auto; right: -30px; }
  .control-list { grid-template-columns: 1fr; gap: 4px; }
  .control-list dd { margin-bottom: 8px; }
}
