:root {
  color-scheme: dark;
  --bg: #09090f;
  --bg-soft: #111018;
  --panel: #15141d;
  --panel-strong: #1d1a26;
  --ink: #f7f1df;
  --muted: #b4b0c4;
  --line: #34303f;
  --accent: #62e6b1;
  --accent-strong: #ffd166;
  --accent-hover: #ffdf8f;
  --accent-contrast: #111018;
  --danger: #ef476f;
  --cyan: #48cae4;
  --violet: #9b5de5;
  --warning: #ffd166;
  --topbar-bg: rgb(9 9 15 / 86%);
  --button-bg: #201d2a;
  --button-hover-border: #6ee7b7;
  --field-bg: #111018;
  --field-border: #464052;
  --focus-ring: rgb(98 230 177 / 26%);
  --badge: #9f9aab;
  --modal-backdrop: rgb(3 3 7 / 74%);
  --shadow: 0 22px 70px rgb(0 0 0 / 46%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f3ea;
  --bg-soft: #eee8dc;
  --panel: #fffaf0;
  --panel-strong: #f1eadb;
  --ink: #17151f;
  --muted: #615e6f;
  --line: #d4ccbe;
  --accent: #157a6e;
  --accent-strong: #b85c38;
  --accent-hover: #8f3f24;
  --accent-contrast: #ffffff;
  --danger: #b72d51;
  --cyan: #087e8b;
  --violet: #6c4ba0;
  --warning: #8f5b10;
  --topbar-bg: rgb(246 243 234 / 88%);
  --button-bg: #fffdf7;
  --button-hover-border: #157a6e;
  --field-bg: #fffdf7;
  --field-border: #beb4a3;
  --focus-ring: rgb(21 122 110 / 20%);
  --badge: #706a78;
  --modal-backdrop: rgb(23 21 31 / 60%);
  --shadow: 0 22px 70px rgb(45 36 25 / 20%);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 18%, rgb(239 71 111 / 28%), transparent 28rem),
    radial-gradient(circle at 86% 6%, rgb(72 202 228 / 22%), transparent 24rem),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 62% 34%, var(--accent-strong) 0 10%, transparent 11%),
    linear-gradient(135deg, var(--danger), var(--violet));
  color: var(--accent-contrast);
}

.brand-star {
  width: 20px;
  height: 20px;
  display: block;
  background: currentColor;
  clip-path: polygon(50% 0, 61% 36%, 100% 50%, 61% 64%, 50% 100%, 39% 64%, 0 50%, 39% 36%);
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 0 0 auto;
}

.game-deck {
  width: min(1480px, calc(100% - 32px));
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(340px, 0.85fr);
  gap: 18px;
  align-items: stretch;
  padding: 18px 0;
}

.flight-stack {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.viewport-panel,
.cockpit-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(17 16 24 / 78%);
  box-shadow: var(--shadow);
}

:root[data-theme="light"] .viewport-panel,
:root[data-theme="light"] .cockpit-panel {
  background: rgb(255 250 240 / 84%);
}

.viewport-panel {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 420px;
}

#space-canvas {
  width: 100%;
  height: 100%;
  min-height: 420px;
  display: block;
  background: #05050a;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.canvas-overlay {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.canvas-overlay span {
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 8px 10px;
  border: 1px solid rgb(247 241 223 / 18%);
  border-radius: 8px;
  background: rgb(5 5 10 / 70%);
  color: #f7f1df;
  font-size: 0.83rem;
  font-weight: 800;
}

.cockpit-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 22px;
}

.eyebrow,
.dialog-kicker {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.05;
}

h1 {
  color: var(--ink);
  font-size: 2.15rem;
}

h2 {
  font-size: 1.75rem;
}

.lead {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 0;
}

.status-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 3%);
}

:root[data-theme="light"] .status-grid div {
  background: rgb(23 21 31 / 3%);
}

.status-grid span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-grid strong {
  display: block;
  min-height: 1.25em;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.98rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.command-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 0;
}

.choice-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
}

.choice-button {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--ink);
  font-weight: 750;
  text-align: left;
  transition: border-color 160ms ease, transform 160ms ease;
}

.choice-button:hover {
  border-color: var(--button-hover-border);
}

.mission-log {
  min-height: 118px;
  max-height: 190px;
  display: grid;
  align-content: start;
  gap: 8px;
  margin: 16px 0 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(0 0 0 / 18%);
}

:root[data-theme="light"] .mission-log {
  background: rgb(255 255 255 / 45%);
}

.mission-log p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 32px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.primary-button {
  padding: 0 16px;
  background: var(--accent-strong);
  color: var(--accent-contrast);
  border-color: var(--accent-strong);
  font-weight: 850;
}

.primary-button:hover {
  background: var(--accent-hover);
}

.secondary-button,
.icon-button {
  background: var(--button-bg);
  color: var(--ink);
  border-color: var(--line);
  font-weight: 750;
}

.secondary-button {
  padding: 0 14px;
}

.secondary-button:hover,
.icon-button:hover {
  border-color: var(--button-hover-border);
}

.audio-button {
  min-width: 106px;
}

.theme-toggle-button {
  width: 44px;
  padding: 0;
}

.theme-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 18px;
  margin: 0 auto;
  border-radius: 50%;
  background: currentColor;
  overflow: hidden;
}

.theme-icon::after {
  position: absolute;
  top: -2px;
  right: -3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--button-bg);
  content: "";
}

:root[data-theme="dark"] .theme-icon {
  width: 16px;
  height: 16px;
  overflow: visible;
  border: 2px solid currentColor;
  background: transparent;
  box-shadow:
    0 -9px 0 -6px currentColor,
    0 9px 0 -6px currentColor,
    9px 0 0 -6px currentColor,
    -9px 0 0 -6px currentColor,
    6px 6px 0 -6px currentColor,
    -6px -6px 0 -6px currentColor,
    6px -6px 0 -6px currentColor,
    -6px 6px 0 -6px currentColor;
}

:root[data-theme="dark"] .theme-icon::after {
  content: none;
}

.info-button {
  width: 44px;
  padding: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  font-style: italic;
}

.status-note {
  margin: auto 0 0;
  padding-top: 14px;
  color: var(--warning);
  font-size: 0.9rem;
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--modal-backdrop);
}

.modal-backdrop[hidden] {
  display: none;
}

.feedback-dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateY(12px);
  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
}

.modal-backdrop.is-open .feedback-dialog {
  transform: translateY(0);
  opacity: 1;
}

.close-button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  padding: 0;
}

.feedback-form {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.feedback-form label {
  color: var(--ink);
  font-weight: 750;
}

.feedback-form input,
.feedback-form textarea {
  width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--ink);
  padding: 12px 13px;
  line-height: 1.4;
}

.feedback-form input:focus,
.feedback-form textarea:focus,
.choice-button:focus,
.primary-button:focus,
.secondary-button:focus,
.icon-button:focus {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-color: var(--accent);
}

.feedback-form textarea {
  min-height: 172px;
  resize: vertical;
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 10px;
}

.form-message {
  min-height: 1.4em;
  color: var(--muted);
}

.build-badge {
  position: absolute;
  right: 18px;
  bottom: 12px;
  color: var(--badge);
  font-size: 0.76rem;
}

.history-dialog {
  width: min(680px, 100%);
}

.history-list {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.history-item {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.history-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.history-meta {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 800;
}

.history-comment,
.empty-state {
  margin: 0;
  color: var(--ink);
  line-height: 1.5;
}

.empty-state {
  color: var(--muted);
}

@media (max-width: 980px) {
  .game-deck {
    grid-template-columns: 1fr;
  }

  .viewport-panel,
  #space-canvas {
    min-height: 360px;
  }

  .cockpit-panel {
    min-height: auto;
  }
}

@media (max-width: 700px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .topbar .secondary-button {
    flex: 1 1 136px;
  }

  .game-deck {
    width: min(100% - 20px, 1480px);
    padding: 10px 0;
  }

  .viewport-panel,
  #space-canvas {
    min-height: 320px;
  }

  .cockpit-panel {
    padding: 18px;
  }

  h1 {
    font-size: 1.85rem;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .command-row {
    grid-template-columns: 1fr;
  }

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

  .form-footer .primary-button {
    width: 100%;
  }

  .feedback-dialog {
    padding: 24px 18px 36px;
  }
}

@media (max-width: 420px) {
  .brand {
    gap: 8px;
  }

  .brand-name {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .canvas-overlay {
    align-items: flex-start;
    flex-direction: column;
  }

  .canvas-overlay span {
    max-width: 100%;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  html,
  body {
    height: 100svh;
    min-height: 0;
    overflow: hidden;
  }

  .app-shell {
    height: 100svh;
    min-height: 0;
  }

  .topbar {
    min-height: 48px;
    align-items: center;
    flex-direction: row;
    gap: 10px;
    padding: 7px 10px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
  }

  .brand-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    width: auto;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .topbar .secondary-button {
    flex: 0 0 auto;
  }

  .primary-button,
  .secondary-button,
  .icon-button {
    min-height: 34px;
    font-size: 0.82rem;
  }

  .secondary-button {
    padding: 0 9px;
  }

  .audio-button {
    min-width: 86px;
  }

  .theme-toggle-button,
  .info-button {
    width: 34px;
  }

  .game-deck {
    width: calc(100% - 16px);
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(0, 1.45fr) minmax(240px, 0.8fr);
    gap: 10px;
    align-items: stretch;
    overflow: hidden;
    padding: 8px 0;
  }

  .flight-stack,
  .viewport-panel,
  #space-canvas {
    height: 100%;
    min-height: 0;
  }

  .canvas-overlay {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .canvas-overlay span {
    padding: 6px 8px;
    font-size: 0.74rem;
  }

  .cockpit-panel {
    min-height: 0;
    overflow: hidden;
    padding: 10px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.3rem;
  }

  .lead {
    display: -webkit-box;
    margin-top: 6px;
    overflow: hidden;
    color: var(--ink);
    font-size: 0.78rem;
    line-height: 1.28;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  .status-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 8px;
  }

  .status-grid div {
    padding: 6px;
  }

  .status-grid span {
    margin-bottom: 2px;
    font-size: 0.58rem;
  }

  .status-grid strong {
    min-height: 1.1em;
    font-size: 0.76rem;
  }

  .command-row {
    gap: 6px;
    margin-top: 8px;
  }

  .primary-button {
    padding: 0 9px;
  }

  .choice-list {
    gap: 6px;
    margin-top: 8px;
  }

  .choice-button {
    min-height: 32px;
    padding: 0 8px;
    font-size: 0.78rem;
  }

  .mission-log {
    min-height: 0;
    max-height: none;
    flex: 1 1 auto;
    gap: 5px;
    margin-top: 8px;
    overflow: auto;
    padding: 8px;
  }

  .mission-log p {
    font-size: 0.74rem;
    line-height: 1.25;
  }

  .status-note {
    margin-top: 0;
    padding-top: 6px;
    font-size: 0.7rem;
  }
}
