/* GoSpace — Core Tactical HUD Grid, Top Bar, 6-Gauge Strip & Shared Popups (fluid rem) */

body[data-stage="0"] #hud-layer {
  visibility: hidden;
  pointer-events: none;
}

body.hud-collapsed #hud-top,
body.hud-collapsed .hud-mid,
body.hud-collapsed #hud-bottom,
body.hud-collapsed #codex-menu,
body.hud-collapsed #mel-drawer,
.hud-layer.is-hidden > #hud-top,
.hud-layer.is-hidden > .hud-mid,
.hud-layer.is-hidden > #hud-bottom,
.hud-layer.is-hidden > #codex-menu,
.hud-layer.is-hidden > #mel-drawer {
  opacity: 0;
  pointer-events: none !important;
}

.hud-layer.is-hidden > .hud-mid * {
  pointer-events: none !important;
}

.hud-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: grid;
  grid-template-rows: 2.75rem minmax(0, 1fr) auto;
  gap: 0.57rem;
  padding: 0.57rem 0.71rem 0.71rem;
}

/* ------------------------------------------------------------------
   TOP BAR (2.75rem tactical header)
   ------------------------------------------------------------------ */
/* Floating cockpit capsule bar */
.hud-top {
  height: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.5rem 0 1.05rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.71rem;
  pointer-events: auto;
  min-width: 0;
  z-index: 30;
  border-radius: var(--r-pill);
  --plate-ring: linear-gradient(90deg, rgba(94, 231, 255, 0.6) 0%, rgba(148, 197, 255, 0.1) 25%, rgba(148, 197, 255, 0.06) 75%, rgba(167, 139, 250, 0.6) 100%);
}

.hud-top::after {
  background: var(--star-dust);
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 0.57rem;
  flex-shrink: 0;
  min-width: 0;
}

.brand-wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.43rem;
  cursor: default;
  pointer-events: none;
  user-select: none;
  color: var(--accent);
}

.brand-glyph {
  width: 1.35rem;
  height: 1.35rem;
  color: var(--plasma);
  filter: drop-shadow(0 0 0.35rem rgba(94, 231, 255, 0.7));
}

.brand-name {
  font-family: var(--font-hud);
  font-size: var(--fs-md);
  font-weight: 900;
  letter-spacing: 0.18em;
  white-space: nowrap;
  background: linear-gradient(90deg, #ffffff 0%, var(--plasma-bright) 45%, var(--nebula) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.mission-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.29rem;
  cursor: default;
  pointer-events: none;
  user-select: none;
  min-width: 0;
}

.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.71rem;
  flex: 1 1 auto;
  min-width: 0;
}

/* Mission stages sit on a dashed flight path, like waypoints on a trajectory */
.stage-bar {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.stage-bar::before {
  content: '';
  position: absolute;
  left: 1rem;
  right: 1rem;
  top: 50%;
  z-index: -1;
  height: 0;
  border-top: 1.5px dashed rgba(94, 231, 255, 0.4);
  filter: drop-shadow(0 0 0.25rem rgba(94, 231, 255, 0.5));
}

#stage-switcher .stage-btn {
  height: 1.9rem;
  min-height: 0;
  padding: 0 0.85rem 0 0.75rem;
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

#stage-switcher .stage-btn .gi {
  width: 0.95rem;
  height: 0.95rem;
}

#stage-switcher .stage-btn.active {
  color: var(--accent-bright);
}

/* Locked waypoints stay opaque (so the flight path doesn't show through) and just dim */
#stage-switcher .stage-btn.is-locked,
#stage-switcher .stage-btn.is-locked:disabled,
#stage-switcher .stage-btn.is-breadcrumb.is-locked:disabled {
  opacity: 1;
  filter: none;
  cursor: not-allowed;
  --fill: linear-gradient(180deg, rgba(12, 18, 40, 0.98) 0%, rgba(6, 10, 24, 0.98) 100%);
  --rim: linear-gradient(135deg, rgba(148, 197, 255, 0.22), rgba(148, 197, 255, 0.08));
  --bar: transparent;
  color: var(--text-muted);
}

#stage-switcher .stage-btn.is-breadcrumb:not(.is-locked) {
  cursor: default;
}

#stage-switcher .stage-btn.is-breadcrumb:not(.is-locked):not(.active) {
  color: var(--text-main);
}

#stage-switcher .stage-btn.is-breadcrumb:disabled {
  opacity: 1;
}

/* Narrower windows: tighten the flight path so every waypoint label fits */
@media (max-width: 1400px) {
  .stage-bar {
    gap: 0.4rem;
  }

  #stage-switcher .stage-btn {
    padding: 0 0.6rem 0 0.55rem;
    letter-spacing: 0.06em;
  }
}

/* Concept maturity as a row of little planets linked by an orbit line */
.cml-nodes {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  height: 1.9rem;
  padding: 0 0.75rem 0 0.5rem;
  background: rgba(148, 197, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  flex-shrink: 0;
}

.node-dots {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.node-dots::before {
  content: '';
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  top: 50%;
  z-index: -1;
  border-top: 1px solid rgba(148, 197, 255, 0.3);
}

.cnode {
  width: 1.15rem;
  height: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0;
  font-weight: 700;
  color: var(--text-muted);
  background: radial-gradient(circle at 35% 30%, #2a3a66 0%, #0b1228 75%);
  border: 1px solid rgba(148, 197, 255, 0.25);
  border-radius: 50%;
}

.cnode.lit {
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, var(--plasma) 38%, #1d4ed8 100%);
  border-color: var(--plasma-bright);
  box-shadow: 0 0 0.5rem rgba(94, 231, 255, 0.75);
}

.cnode.lit-max {
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, #6ee7b7 38%, #047857 100%);
  border-color: #a7f3d0;
  box-shadow: 0 0 0.55rem rgba(52, 211, 153, 0.8);
}

.cml-text {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-main);
  white-space: nowrap;
}

.topbar-utils {
  display: flex;
  align-items: center;
  gap: 0.29rem;
  flex-shrink: 0;
}

/* Round porthole switch (labelled variants stretch into capsules) */
.icon-toggle {
  width: 2rem;
  height: 2rem;
  min-height: 0;
  padding: 0 !important;
  flex-shrink: 0;
  --bar: transparent;
  --btn-radius: 50%;
}

.icon-toggle .gi {
  filter: drop-shadow(0 0 0.25rem rgba(94, 231, 255, 0.45));
}

/* Icon buttons carry a short word so players don't have to guess */
.icon-toggle.has-lbl {
  --btn-radius: var(--r-pill);
  width: auto;
  height: 1.9rem;
  gap: 0.36rem;
  padding: 0 0.78rem 0 0.62rem !important;
}

.util-lbl {
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-main);
}

.audio-toggle-btn.is-muted .util-lbl {
  color: var(--text-dim);
  text-decoration: line-through;
}

/* Smaller windows fall back to round porthole icons + tooltip */
@media (max-width: 1360px) {
  .icon-toggle.has-lbl {
    --btn-radius: 50%;
    width: 2rem;
    height: 2rem;
    padding: 0 !important;
  }

  .util-lbl {
    display: none;
  }
}

.audio-toggle-btn {
  color: var(--accent-bright);
}

.audio-toggle-btn.is-muted {
  color: var(--text-dim);
  opacity: 0.6;
}

.btn-quit-mission {
  height: 1.9rem;
  min-height: 0;
  padding: 0 0.72rem 0 0.8rem;
  font-size: var(--fs-xs);
  font-weight: 700;
}

.btn-quit-mission .gi {
  width: 0.95rem;
  height: 0.95rem;
}

/* ------------------------------------------------------------------
   TOOLS / HELP POPOVER MENU
   ------------------------------------------------------------------ */
.codex-menu {
  position: fixed;
  top: 3.7rem;
  right: 0.71rem;
  z-index: 55;
  width: max(16rem, 240px);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: auto;
  border-radius: var(--r-lg);
}

.codex-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.36rem 0.57rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
}

/* Sandbox checkbox drawn as a glowing power toggle */
.codex-row {
  border-radius: var(--r-pill);
}

.codex-row input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 2.3rem;
  height: 1.25rem;
  margin: 0;
  border-radius: var(--r-pill);
  background: rgba(4, 7, 20, 0.9);
  border: 1px solid var(--border-mid);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.codex-row input::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0.18rem;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff, #7180a6);
  transform: translateY(-50%);
  transition: left 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.codex-row input:checked {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.6), rgba(94, 231, 255, 0.6));
  border-color: rgba(52, 211, 153, 0.7);
}

.codex-row input:checked::after {
  left: calc(100% - 1.03rem);
  background: radial-gradient(circle at 35% 35%, #ffffff, #6ee7b7);
  box-shadow: 0 0 0.6rem rgba(52, 211, 153, 0.9);
}

.codex-row input:focus-visible {
  outline: 2px solid var(--plasma-bright);
  outline-offset: 2px;
}

.codex-menu .btn-sci {
  width: 100%;
  justify-content: flex-start;
  font-size: var(--fs-sm);
}

/* ------------------------------------------------------------------
   MIDDLE 3-COLUMN GRID (Viewport-first >=80% open center)
   ------------------------------------------------------------------ */
.hud-mid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0.71rem;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}

.hud-col-left {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 0.57rem;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}

.hud-col-left > *:not([hidden]) {
  pointer-events: auto;
}

.hud-col-center {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 0.57rem;
  min-width: 0;
  min-height: 0;
  position: relative;
  pointer-events: none;
}

.center-top-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.57rem;
  width: 100%;
  max-width: 46rem;
  pointer-events: none;
}

.center-top-stack > *:not([hidden]) {
  pointer-events: auto;
}

.center-action-hud {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.43rem;
  pointer-events: auto;
}

.hud-col-right {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 0.57rem;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}

body[data-stage="1"] .hud-col-right {
  justify-content: flex-end;
}

.stage-hud {
  pointer-events: auto;
  min-width: 0;
  max-height: 100%;
}

.left-hud-stack {
  display: flex;
  flex-direction: column;
  gap: 0.43rem;
  max-width: 17rem;
  pointer-events: none;
}

.left-hud-stack > *:not([hidden]) {
  pointer-events: auto;
}

.comms-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.43rem 0.64rem;
  font-size: var(--fs-xs);
}

.comms-badge {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--accent-bright);
}

.mission-progress-bar {
  padding: 0.36rem 0.57rem;
  font-size: var(--fs-xs);
}

/* ------------------------------------------------------------------
   BOTTOM 6-GAUGE STRIP & LAUNCH CTA
   ------------------------------------------------------------------ */
.hud-bottom {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  pointer-events: none;
}

body[data-stage="2"] #hud-bottom,
body[data-stage="4"] #hud-bottom {
  display: none;
}

/* Bar hosts gauge tooltips that rise above it — no clip-path here */
.status-cta-bar {
  pointer-events: auto;
  width: 100%;
  max-width: min(92rem, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.71rem;
  padding: 0.5rem 0.6rem 0.5rem 0.71rem;
  border-radius: var(--r-lg);
}

.gauges-mini {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.45rem;
}

/* Each gauge is a small instrument pod */
.gm-item {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
  padding: 0.32rem 0.6rem 0.4rem;
  border: 1px solid rgba(148, 197, 255, 0.1);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(148, 197, 255, 0.06), rgba(148, 197, 255, 0.01));
  cursor: help;
  transition: background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.2s ease;
}

.gm-item:hover,
.gm-item:focus-within {
  background: linear-gradient(180deg, rgba(94, 231, 255, 0.12), rgba(94, 231, 255, 0.03));
  border-color: var(--border-focus);
  box-shadow: 0 0 0.9rem -0.2rem rgba(94, 231, 255, 0.45);
}

.gm-item:focus-visible {
  outline: 2px solid var(--plasma-bright);
  outline-offset: 2px;
}

.gm-item.is-violation {
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.18), rgba(244, 63, 94, 0.05));
  border-color: rgba(244, 63, 94, 0.5);
  box-shadow: 0 0 0.9rem -0.3rem rgba(244, 63, 94, 0.6);
}

.gm-item.is-near-cap {
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.14), rgba(251, 191, 36, 0.03));
  border-color: rgba(251, 191, 36, 0.42);
}

.gm-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.29rem;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.gm-top span {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  color: var(--text-dim);
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.gm-top span .gi {
  width: 0.9rem;
  height: 0.9rem;
  color: var(--accent);
}

.gm-item.is-violation .gm-top span .gi {
  color: var(--status-bad);
}

/* Smaller windows: drop the gauge glyph so the value keeps its room */
@media (max-width: 1400px) {
  .gm-top span .gi {
    display: none;
  }
}

.gm-top b {
  color: var(--text-main);
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gm-top b.is-bad {
  color: #fca5a5;
}

.gm-top b.is-inf {
  color: var(--accent-bright);
}

.gm-fill {
  transition: width 0.2s ease, background-color 0.2s ease;
}

.gm-fill.ok {
  background: linear-gradient(90deg, #10b981 0%, #34d399 60%, #5ee7ff 100%);
  box-shadow: 0 0 0.5rem rgba(52, 211, 153, 0.55);
}

.gm-fill.warn {
  background: linear-gradient(90deg, #f59e0b 0%, var(--status-warn) 100%);
  box-shadow: 0 0 0.5rem rgba(251, 191, 36, 0.55);
}

.gm-fill.bad {
  background: linear-gradient(90deg, #be123c 0%, var(--status-bad) 70%, #fb7185 100%);
  box-shadow: 0 0 0.5rem rgba(244, 63, 94, 0.6);
}

.gm-tooltip {
  position: absolute;
  bottom: calc(100% + 0.71rem);
  left: 50%;
  transform: translateX(-50%);
  width: max(19rem, 260px);
  padding: 0.57rem 0.71rem;
  background:
    radial-gradient(120% 90% at 0% 0%, rgba(94, 231, 255, 0.12), transparent 60%),
    var(--panel-strong);
  border: 1px solid var(--border-focus);
  border-radius: var(--r-md);
  box-shadow: 0 0.7rem 1.9rem rgba(0, 0, 0, 0.78), 0 0 1.2rem -0.3rem rgba(94, 231, 255, 0.45);
  z-index: 70;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  font-size: var(--fs-sm);
}

.gm-item:first-child .gm-tooltip {
  left: 0;
  transform: none;
}

.gm-item:last-child .gm-tooltip {
  left: auto;
  right: 0;
  transform: none;
}

.gm-item:hover .gm-tooltip,
.gm-item:focus .gm-tooltip,
.gm-item:focus-within .gm-tooltip {
  opacity: 1;
  visibility: visible;
}

.gm-tip-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.43rem;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--accent-bright);
  margin-bottom: 0.21rem;
}

.gm-tip-reason {
  color: var(--text-main);
  font-size: var(--fs-xs);
  margin-bottom: 0.29rem;
}

.gm-tip-debuff {
  color: #fca5a5;
  font-size: var(--fs-xs);
  margin-bottom: 0.14rem;
}

.gm-tip-fix {
  color: var(--accent-bright);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.gm-tip-ok {
  color: #6ee7b7;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

/* Red gauges in the Hangar jump to the tab that fixes them */
.gm-item.is-jump {
  cursor: pointer;
}

.gm-item.is-jump:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.75);
}

.gm-tip-jump {
  margin-top: 0.29rem;
  padding-top: 0.29rem;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: var(--fs-xs);
  font-weight: 700;
}

/* Two-line "Launch Anyway / N issues: ..." risk button */
.btn-rollout .cta-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
  min-width: 0;
}

.btn-rollout .cta-main {
  font-size: var(--fs-sm);
}

.btn-rollout .cta-sub {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: #fca5a5;
  max-width: max(16rem, 220px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Primary Roll Out / Bottom Stage CTA */
.btn-rollout {
  flex-shrink: 0;
  min-height: 2.45rem;
  height: auto;
  padding: 0.28rem 1.35rem 0.28rem 1.2rem;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.btn-rollout .gi {
  width: 1.3rem;
  height: 1.3rem;
}

/* Launch-with-issues: solar-warning capsule */
.btn-rollout.is-risk {
  --fill:
    radial-gradient(120% 140% at 50% 120%, rgba(251, 191, 36, 0.28) 0%, transparent 60%),
    linear-gradient(180deg, rgba(70, 44, 10, 0.85) 0%, rgba(24, 16, 8, 0.92) 100%);
  --rim: linear-gradient(135deg, #fde68a 0%, rgba(251, 191, 36, 0.4) 50%, #f59e0b 100%);
  --bar: rgba(251, 191, 36, 0.45);
  color: #fde68a;
}

/* ------------------------------------------------------------------
   SHARED FLOATING TOOLTIPS, TOAST POPUPS & RESTORE BUTTON
   ------------------------------------------------------------------ */
.game-tooltip {
  position: fixed;
  z-index: 120;
  max-width: 18.5rem;
  padding: 0.5rem 0.71rem;
  pointer-events: none;
  font-size: var(--fs-sm);
  line-height: 1.35;
  color: var(--text-main);
  --plate-bg: var(--panel-strong);
  --plate-ring: linear-gradient(135deg, var(--border-focus) 0%, rgba(148, 197, 255, 0.1) 50%, var(--border-focus) 100%);
}

.hud-restore {
  position: fixed;
  top: 0.71rem;
  right: 0.71rem;
  z-index: 80;
  pointer-events: auto;
}

.score-popups {
  position: fixed;
  top: 3.86rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.36rem;
}

.score-pop,
.pop-float {
  padding: 0.3rem 0.86rem 0.3rem 0.95rem;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--accent-bright);
  background: var(--panel-strong);
  border: 1px solid var(--border-focus);
  box-shadow: inset 2px 0 0 var(--accent);
  border-radius: var(--r-sm);
  animation: popFloat 1.5s ease forwards;
}

@keyframes popFloat {
  0% { opacity: 0; transform: translateY(0.43rem); }
  14% { opacity: 1; transform: translateY(0); }
  75% { opacity: 1; transform: translateY(-0.29rem); }
  100% { opacity: 0; transform: translateY(-1rem); }
}
