/* ==========================================================================
   Moon Lander — Mission Control visual layer
   --------------------------------------------------------------------------
   Builds on tokens.css / base.css / components.css. Adds a space-flight
   palette and the game-specific layout, telemetry and control components.
   All colors flow through semantic tokens so light/dark theming still works.
   ========================================================================== */

:root {
  /* Mission-control primitives */
  --space-950: #070d18;
  --space-900: #0b1424;
  --space-800: #14213a;
  --space-700: #1d3050;
  --space-600: #2a4368;
  --mint-400: #5eead4;
  --mint-500: #2dd4bf;
  --mint-600: #14b8a6;
  --gold-400: #fbbf24;
  --gold-500: #f59e0b;
  --sky-400: #7dd3fc;
  --sky-500: #38bdf8;

  /* Semantic aliases consumed by game components */
  --ml-stage-sky-top: #101927;
  --ml-stage-sky-bottom: #28354a;
  --ml-stage-ground: #cabb96;
  --ml-pad: #82c7b1;
  --ml-pad-ink: #173c3b;
  --ml-ship: #fffdf4;
  --ml-ship-trim: #326f8e;
  --ml-flame: #efd17a;
  --ml-trail: rgb(239 209 122 / 0.48);
  --ml-wind-pos: #8ac9db;
  --ml-wind-neg: #efd17a;

  --ml-field: var(--space-900);
  --ml-field-border: var(--space-600);
  --ml-panel-bg: color-mix(in srgb, var(--surface) 94%, var(--space-900));
  --ml-item-bg: color-mix(in srgb, var(--surface) 88%, var(--space-800));
  --ml-item-active: color-mix(in srgb, var(--accent-subtle) 70%, var(--surface));
  --ml-item-border: var(--border);
}

[data-theme="dark"] {
  --ml-stage-sky-top: #070d18;
  --ml-stage-sky-bottom: #16233a;
  --ml-field: var(--space-950);
  --ml-field-border: var(--space-700);
  --ml-panel-bg: color-mix(in srgb, var(--surface) 92%, var(--space-900));
  --ml-item-bg: color-mix(in srgb, var(--surface-sunken) 80%, var(--space-900));
  --ml-item-active: color-mix(in srgb, var(--accent-subtle) 55%, var(--surface));
}

/* ---------- App shell ---------- */
.ml-app {
  width: min(1480px, 100%);
  margin-inline: auto;
}

.ml-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--ml-panel-bg);
  box-shadow: var(--shadow-lg);
}

.ml-topbar h1 {
  font-size: var(--font-size-3xl);
  margin-bottom: var(--space-2);
}

.ml-topbar p {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  max-width: 62ch;
}

.ml-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

.ml-actions .btn {
  min-height: 44px;
}

.ml-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 300px;
  gap: var(--space-3);
  margin-top: var(--space-3);
  align-items: start;
}

.ml-panel {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--ml-panel-bg);
  box-shadow: var(--shadow-md);
}

.ml-panel h2 {
  font-size: var(--font-size-base);
  margin-bottom: var(--space-3);
}

.ml-panel + .ml-panel {
  margin-top: var(--space-3);
}

/* ---------- Mission list ---------- */
.ml-mission-list {
  display: grid;
  gap: var(--space-2);
  max-height: 670px;
  overflow-y: auto;
}

.ml-mission {
  width: 100%;
  min-height: 56px;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border: 1px solid var(--ml-item-border);
  border-radius: var(--radius-sm);
  background: var(--ml-item-bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}

.ml-mission:hover:not(:disabled) {
  border-color: var(--primary);
}

.ml-mission.is-active {
  border-color: var(--primary);
  background: var(--ml-item-active);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 22%, transparent);
}

.ml-mission:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ml-mission strong,
.ml-mission small {
  display: block;
}

.ml-mission strong {
  font-size: var(--font-size-sm);
}

.ml-mission small {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--font-size-2xs);
}

.ml-mission .ml-stars {
  float: right;
  color: var(--gold-500);
  font-size: var(--font-size-xs);
}

/* ---------- Flight stage ---------- */
.ml-flight-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.ml-flight-head h2 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-1);
}

.ml-flight-head p {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.ml-contract {
  text-align: right;
  white-space: nowrap;
}

.ml-contract b {
  display: block;
  color: var(--primary);
  font-size: var(--font-size-xl);
  font-variant-numeric: tabular-nums;
}

.ml-contract span {
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

.ml-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--ml-field-border);
  border-radius: var(--radius-md);
  background: var(--ml-field);
  aspect-ratio: 16 / 10;
}

.ml-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.ml-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: var(--overlay);
  backdrop-filter: blur(3px);
}

.ml-overlay.is-hidden {
  display: none;
}

.ml-modal {
  width: min(460px, 100%);
  padding: var(--space-5);
  text-align: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
}

.ml-modal h3 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-2);
}

.ml-modal p {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-5);
}

/* ---------- Touch controls ---------- */
.ml-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.ml-control {
  min-height: 48px;
  padding: var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-xs);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.ml-control:active,
.ml-control.is-pressed {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

.ml-control--main {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary-subtle-text);
}

.ml-message {
  min-height: 1.5em;
  margin-top: var(--space-3);
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  text-align: center;
}

/* ---------- Telemetry ---------- */
.ml-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.ml-stat {
  padding: var(--space-2);
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--ml-item-bg);
}

.ml-stat b {
  display: block;
  font-family: var(--font-family-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--font-size-md);
}

.ml-stat small {
  color: var(--text-muted);
  font-size: var(--font-size-2xs);
}

.ml-meter {
  margin-top: var(--space-4);
}

.ml-meter > span {
  display: flex;
  justify-content: space-between;
  font-size: var(--font-size-xs);
  margin-bottom: var(--space-2);
}

.ml-meter em {
  font-style: normal;
  font-family: var(--font-family-mono);
  font-variant-numeric: tabular-nums;
}

.ml-bar {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
}

.ml-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint-500), var(--gold-400));
  transition: width var(--duration-base) var(--ease-out);
}

.ml-goals {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.ml-goal {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--ml-item-bg);
  font-size: var(--font-size-xs);
}

.ml-goal b {
  color: var(--error-text);
}

.ml-goal.is-ok b {
  color: var(--success-text);
}

/* ---------- Lander + modules ---------- */
.ml-landers,
.ml-modules {
  display: grid;
  gap: var(--space-2);
}

.ml-choice {
  width: 100%;
  min-height: 48px;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border: 1px solid var(--ml-item-border);
  border-radius: var(--radius-sm);
  background: var(--ml-item-bg);
  color: var(--text);
  cursor: pointer;
}

.ml-choice strong,
.ml-choice small {
  display: block;
}

.ml-choice small {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--font-size-2xs);
}

.ml-choice.is-active {
  border-color: var(--primary);
  background: var(--ml-item-active);
}

.ml-choice:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ml-hint {
  margin-top: var(--space-2);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

/* ---------- Archive ---------- */
.ml-archive {
  margin-top: var(--space-3);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--ml-panel-bg);
  box-shadow: var(--shadow-md);
}

.ml-archive[hidden] {
  display: none;
}

.ml-archive h2 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-2);
}

.ml-archive p {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-3);
}

.ml-archive textarea {
  width: 100%;
  min-height: 96px;
  padding: var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  resize: vertical;
}

.ml-feedback {
  min-height: 1.5em;
  margin-top: var(--space-2);
  color: var(--success-text);
  font-size: var(--font-size-sm);
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .ml-layout {
    grid-template-columns: 1fr;
  }

  .ml-mission-list {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    max-height: none;
  }

  .ml-panel + .ml-panel {
    margin-top: var(--space-3);
  }
}

@media (max-width: 560px) {
  .ml-topbar {
    padding: var(--space-4);
  }

  .ml-actions {
    justify-content: flex-start;
  }

  .ml-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .ml-controls {
    grid-template-columns: repeat(2, 1fr);
  }
}
