:root {
  color-scheme: dark;
  --void: #0a192f;
  --ink: #ffffff;
  --muted: rgba(255, 255, 255, 0.66);
  --dim: rgba(255, 255, 255, 0.42);
  --panel: rgba(255, 255, 255, 0.05);
  --panel-strong: rgba(10, 25, 47, 0.74);
  --line: rgba(255, 255, 255, 0.15);
  --accent: #ffd700;
  --terminal: #00ff00;
  --draft-red: #d23b30;
  --magenta: #d946ef;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--void);
  font-family:
    "Helvetica Neue", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  min-width: 320px;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 520px;
  overflow: hidden;
  background:
    radial-gradient(circle at 58% 42%, rgba(217, 70, 239, 0.1), transparent 32%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    var(--void);
  background-size: auto, 34px 34px, 34px 34px, auto;
}

.stage::before,
.stage::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
}

.stage::before {
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.24) 1px, transparent 1.5px) 0 0 / 22px 22px,
    linear-gradient(125deg, transparent 0 18%, rgba(255, 255, 255, 0.1) 18.2% 18.55%, transparent 18.8% 100%);
  opacity: 0.34;
  mix-blend-mode: screen;
}

.stage::after {
  background:
    linear-gradient(118deg, transparent 0 62%, rgba(255, 255, 255, 0.82) 62.25% 63.1%, transparent 63.35%),
    linear-gradient(90deg, transparent 0 74%, rgba(255, 255, 255, 0.58) 74.3% 75%, transparent 75.3%);
  opacity: 0.16;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  color: var(--ink);
  text-shadow: none;
}

.hud-top {
  top: clamp(16px, 3vw, 38px);
  left: clamp(16px, 4vw, 52px);
}

.kicker,
.panel-title {
  color: var(--muted);
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

.kicker {
  margin-bottom: 6px;
}

h1 {
  margin: 0;
  color: transparent;
  font-size: clamp(42px, 6vw, 84px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: 0;
  -webkit-text-stroke: 2px #ffffff;
  text-stroke: 2px #ffffff;
}

.mission-label {
  margin-top: 8px;
  color: rgba(245, 249, 255, 0.78);
  font-family: "Times New Roman", "PT Serif", serif;
  font-size: 14px;
  font-style: italic;
  font-weight: 400;
}

.coordinate-readout {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 10px solid rgba(255, 255, 255, 0.86);
  color: var(--terminal);
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  font-weight: 760;
  text-shadow: 0 0 8px rgba(0, 255, 0, 0.35);
}

button,
select,
input {
  font: inherit;
}

button,
select {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
}

button {
  min-height: 36px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 760;
  letter-spacing: 0;
  cursor: pointer;
}

button:hover,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  border-color: rgba(243, 200, 75, 0.68);
  outline: none;
}

button.is-active,
button[aria-pressed="true"] {
  border-color: rgba(243, 200, 75, 0.7);
  background: rgba(255, 215, 0, 0.18);
}

.mode-switch,
.layer-panel,
.inspector,
.model-panel,
.mission-graph,
.timeline {
  position: absolute;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 18px 44px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(15px);
}

.mode-switch::before,
.layer-panel::before,
.inspector::before,
.model-panel::before,
.mission-graph::before,
.timeline::before {
  position: absolute;
  top: 0;
  left: 18px;
  width: 64px;
  height: 10px;
  background: rgba(255, 255, 255, 0.9);
  content: "";
  transform: translateY(-1px);
}

.layer-panel::after,
.inspector::after,
.model-panel::after,
.mission-graph::after,
.timeline::after {
  position: absolute;
  inset: 10px;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 18px 18px;
  opacity: 0.12;
  mask-image: linear-gradient(to bottom, black, transparent 78%);
}

.mode-switch {
  top: clamp(18px, 3vw, 34px);
  left: 50%;
  z-index: 5;
  display: flex;
  gap: 6px;
  padding: 7px;
  transform: translateX(-50%);
}

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

.layer-panel {
  top: clamp(142px, 18vh, 210px);
  left: clamp(14px, 3vw, 30px);
  z-index: 4;
  display: grid;
  width: 174px;
  gap: 10px;
  padding: 13px;
}

.layer-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(245, 249, 255, 0.84);
  font-family: "Courier New", Courier, monospace;
  font-size: 13px;
  font-weight: 690;
}

.layer-panel input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

/* Operating mode legend — aligns the on-canvas badge colors with the
   doctrine §4 mode taxonomy. Sits below the layer toggles. */
.panel-divider {
  border-top: 1px solid var(--line);
  margin: 14px 0 10px;
}

.panel-subtitle {
  color: var(--ink);
  font-family: "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.panel-subtitle-ref {
  color: var(--dim);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: none;
}

.mode-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.mode-legend li {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-family: "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 0.66rem;
  font-weight: 700;
  gap: 8px;
  letter-spacing: 0.1em;
}

.mode-legend li em {
  color: var(--dim);
  font-style: normal;
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-left: 4px;
}

.mode-swatch {
  background: var(--mode-color, currentColor);
  border-radius: 1px;
  box-shadow: 0 0 8px var(--mode-color, currentColor);
  display: inline-block;
  flex-shrink: 0;
  height: 8px;
  width: 8px;
}

.inspector {
  right: clamp(14px, 3vw, 34px);
  bottom: 112px;
  z-index: 4;
  width: clamp(280px, 24vw, 380px);
  max-height: 250px;
  min-height: 166px;
  overflow: auto;
  padding: 15px;
}

.inspector h2,
.mission-graph h2 {
  margin: 7px 0 8px;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.05;
  letter-spacing: 0;
}

.inspector p {
  margin: 0 0 12px;
  color: rgba(233, 241, 255, 0.74);
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  line-height: 1.45;
}

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

.meta-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid rgba(222, 234, 255, 0.1);
  padding-top: 8px;
}

.meta-list dt {
  color: var(--dim);
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.meta-list dd {
  margin: 0;
  color: rgba(245, 249, 255, 0.88);
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  font-weight: 720;
  text-align: right;
}

.model-panel {
  left: clamp(208px, 19vw, 280px);
  right: clamp(414px, 31vw, 470px);
  bottom: 92px;
  z-index: 4;
  padding: 14px;
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    visibility 160ms ease;
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 11px;
}

.model-grid label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  color: rgba(245, 249, 255, 0.78);
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  font-weight: 720;
}

.model-grid input,
.model-grid select {
  grid-column: 1 / -1;
  width: 100%;
}

.model-grid span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 780;
}

input[type="range"] {
  accent-color: var(--accent);
}

select {
  height: 32px;
  padding: 0 9px;
}

.primary-action {
  margin-top: 12px;
  border-color: rgba(243, 200, 75, 0.72);
  background: rgba(255, 215, 0, 0.2);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.metric {
  border-top: 1px solid rgba(222, 234, 255, 0.11);
  padding-top: 8px;
}

.metric strong {
  display: block;
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
}

.metric span {
  color: var(--dim);
  font-size: 10px;
  font-weight: 760;
  text-transform: uppercase;
}

.mission-graph {
  top: clamp(112px, 14vh, 140px);
  right: clamp(14px, 3vw, 34px);
  z-index: 3;
  width: clamp(360px, 33vw, 510px);
  max-width: calc(100vw - 28px);
  padding: 14px;
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease,
    inset 180ms ease,
    width 180ms ease;
}

.mission-graph.is-hidden,
.model-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

.stage.mode-graph .mission-graph {
  inset: 96px clamp(300px, 27vw, 420px) 92px clamp(210px, 18vw, 270px);
  width: auto;
  max-width: none;
  padding: 18px;
  z-index: 4;
}

.stage.mode-graph .layer-panel,
.stage.mode-graph .model-panel {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.graph-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.graph-count {
  flex: 0 0 auto;
  padding-top: 2px;
  color: rgba(225, 235, 255, 0.58);
  font-size: 12px;
  font-weight: 720;
}

#graphSvg {
  width: 100%;
  aspect-ratio: 1.45;
  display: block;
  overflow: visible;
}

.stage.mode-graph #graphSvg {
  height: calc(100% - 48px);
  aspect-ratio: auto;
}

.graph-edge {
  stroke: rgba(255, 255, 255, 0.6);
  stroke-width: 1;
  fill: none;
  transition: opacity 140ms ease, stroke 140ms ease;
}

.graph-edge.core {
  stroke: rgba(255, 215, 0, 0.72);
  stroke-width: 1.2;
}

.graph-edge.is-muted {
  opacity: 0.12;
}

.graph-edge.is-active {
  opacity: 1;
  stroke: rgba(243, 200, 74, 0.9);
  stroke-width: 2;
}

.graph-edge-label {
  fill: rgba(224, 235, 255, 0.58);
  font-family: "Courier New", Courier, monospace;
  font-size: 20px;
  font-weight: 650;
  paint-order: stroke;
  stroke: rgba(2, 10, 22, 0.82);
  stroke-width: 5px;
}

.graph-node {
  cursor: pointer;
}

.graph-node text {
  fill: rgba(245, 249, 255, 0.92);
  font-family: "Courier New", Courier, monospace;
  font-size: 22px;
  font-weight: 720;
  paint-order: stroke;
  stroke: rgba(2, 10, 22, 0.82);
  stroke-width: 5px;
}

.graph-node .type {
  fill: rgba(225, 235, 255, 0.54);
  font-size: 15px;
  font-weight: 760;
}

.graph-node circle {
  fill: transparent;
  stroke: rgba(255, 255, 255, 0.86);
  stroke-width: 2;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.22));
}

.graph-node.is-muted {
  opacity: 0.24;
}

.graph-node.is-active circle {
  stroke: var(--accent);
  stroke-width: 4;
}

.timeline {
  position: absolute;
  left: clamp(14px, 3vw, 34px);
  right: clamp(14px, 3vw, 34px);
  bottom: clamp(14px, 3vw, 30px);
  z-index: 5;
  display: grid;
  grid-template-columns: auto auto auto minmax(180px, 1fr) 58px;
  gap: 8px;
  align-items: center;
  padding: 8px;
}

.timeline output {
  color: rgba(245, 249, 255, 0.82);
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  font-weight: 780;
  text-align: right;
}

.is-hidden {
  display: none;
}

@media (max-width: 900px) {
  .stage {
    min-height: 720px;
    overflow: hidden;
  }

  .hud-top {
    top: 16px;
    left: 16px;
  }

  h1 {
    font-size: 38px;
  }

  .mission-label {
    display: none;
  }

  .coordinate-readout {
    display: none;
  }

  .mode-switch {
    top: 88px;
    left: 12px;
    right: 12px;
    transform: none;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mode-button {
    min-width: 0;
  }

  .layer-panel {
    top: 148px;
    left: 12px;
    width: 154px;
    gap: 8px;
    padding: 10px;
  }

  .layer-panel label {
    font-size: 12px;
  }

  .mission-graph {
    top: 148px;
    left: 178px;
    right: 12px;
    width: auto;
    padding: 10px;
    overflow: hidden;
  }

  .stage.mode-graph .mission-graph {
    inset: 148px 12px 88px 12px;
  }

  #graphSvg {
    aspect-ratio: 1.18;
  }

  .graph-edge-label {
    font-size: 17px;
  }

  .graph-node text {
    font-size: 18px;
  }

  .graph-node .type {
    font-size: 12px;
  }

  .inspector {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 88px;
    width: auto;
    max-height: 136px;
    min-height: 120px;
    padding: 11px;
  }

  .inspector h2 {
    font-size: 16px;
  }

  .inspector p {
    font-size: 12px;
  }

  .meta-list {
    display: none;
  }

  .model-panel {
    left: 12px;
    right: 12px;
    bottom: 232px;
    max-height: 300px;
    overflow: auto;
  }

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

  .timeline {
    left: 12px;
    right: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr)) 52px;
    gap: 6px;
    padding: 6px;
  }

  .timeline input {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .timeline output {
    grid-column: 4;
    grid-row: 2;
  }

  .timeline button {
    min-width: 0;
    padding-inline: 5px;
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .layer-panel {
    display: none;
  }

  .mission-graph {
    left: 12px;
  }

  .stage.mode-model .mission-graph,
  .stage.mode-observe .mission-graph {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .model-panel {
    bottom: 220px;
  }
}
