:root {
  color-scheme: dark;
  --bg: #0a0d0e;
  --panel: #111719;
  --panel-2: #0d1214;
  --line: #273338;
  --text: #edf4f2;
  --muted: #96a8aa;
  --ok: #50d8ff;
  --watch: #ffc845;
  --alarm: #ff4f5f;
  --own: #62df83;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.math-page {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
}

h1 {
  margin-top: 4px;
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

select,
input,
button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

select {
  min-width: 180px;
  padding: 0 10px;
}

input {
  width: 130px;
  padding: 0 10px;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  accent-color: #62df83;
}

button {
  align-self: end;
  padding: 0 14px;
  cursor: pointer;
}

.live-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin: -4px 0 18px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.live-controls p {
  margin: 0;
  min-height: 38px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.checkbox-label {
  min-height: 38px;
  display: flex;
  grid-template-columns: none;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-bottom: 2px;
}

.motion-controls {
  margin: -2px 0 18px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.motion-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  padding: 12px;
  align-items: end;
}

.motion-grid select,
.motion-grid input {
  width: 100%;
  min-width: 0;
}

.motion-grid button {
  min-height: 38px;
}

#motion-status {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
}

.plot-panel,
.instrument-panel,
.live-map-section,
.readout-panel section {
  border: 1px solid var(--line);
  background: var(--panel);
}

.instrument-panel {
  margin-bottom: 16px;
  overflow: hidden;
}

.instrument-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
  padding: 14px;
}

.instrument-display {
  min-width: 0;
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 8px;
  overflow: auto;
}

.instrument-display figcaption {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

#instrument-screen {
  width: 960px;
  height: 576px;
  background: #d8dbcf;
  image-rendering: pixelated;
}

.instrument-controls {
  display: grid;
  gap: 12px;
}

.instrument-controls section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.instrument-controls h3 {
  margin: 0;
  font-size: 14px;
}

.instrument-controls p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.button-row button {
  min-width: 0;
  min-height: 46px;
  align-self: stretch;
  font-weight: 800;
}

.button-row.compact button {
  min-height: 38px;
  font-size: 13px;
}

button.is-pressed {
  transform: translateY(1px);
  border-color: var(--text);
}

.plot-panel {
  min-width: 0;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #080c0d;
}

.live-map-section {
  margin-top: 16px;
  overflow: hidden;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#live-map-status {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

#live-map {
  width: 100%;
  height: min(560px, 72vh);
  min-height: 380px;
  background: #080c0d;
  cursor: grab;
}

#live-map:active {
  cursor: grabbing;
}

#live-map .leaflet-control-layers,
#live-map .leaflet-control-zoom a {
  border-color: rgba(39, 51, 56, 0.8);
  background: rgba(17, 23, 25, 0.94);
  color: var(--text);
}

#live-map .leaflet-control-layers-expanded {
  padding: 10px 12px;
}

#live-map .leaflet-control-attribution {
  background: rgba(8, 12, 13, 0.72);
  color: var(--muted);
}

#live-map .leaflet-control-attribution a {
  color: var(--ok);
}

.ownship-marker {
  width: 18px;
  height: 18px;
  border: 2px solid #edf4f2;
  border-radius: 50%;
  background: var(--own);
  box-shadow: 0 0 0 5px rgba(98, 223, 131, 0.22), 0 0 18px rgba(98, 223, 131, 0.7);
}

.traffic-marker {
  color: #50d8ff;
  font-size: 18px;
  line-height: 18px;
  text-align: center;
  text-shadow: 0 1px 4px #000;
}

.traffic-marker span {
  display: block;
  transform-origin: 50% 52%;
}

.traffic-marker.inactive {
  color: #9fb0b6;
  opacity: 0.78;
}

.traffic-marker.warn {
  color: var(--watch);
}

.traffic-marker.danger {
  color: var(--alarm);
}

.live-map-popup {
  color: #111719;
  font-size: 13px;
  line-height: 1.35;
}

.live-map-popup strong {
  display: block;
  margin-bottom: 3px;
}

.readout-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.readout-panel section {
  padding: 14px;
}

.metrics {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.metrics div,
.target-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

dd {
  margin: 0;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.target-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

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

.target-row strong {
  display: block;
  font-size: 14px;
}

.target-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  min-width: 58px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-align: center;
  font-size: 12px;
}

.badge.warn {
  color: var(--watch);
}

.badge.danger {
  color: var(--alarm);
}

@media (max-width: 980px) {
  .topbar,
  .instrument-workbench,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .controls {
    justify-content: start;
  }

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