:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: #020812;
  color: #e8f5fb;
  --gold: #f2c35b;
  --blue: #79c8e8;
  --panel: rgba(7, 24, 39, 0.94);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-width: 320px; width: 100%; height: 100%; background: #020812; }
html.video-production-bootstrap body { visibility: hidden; }

body.video-production .topbar, body.video-production .visual-tabs { display: none !important; }
body.video-production .app-shell { grid-template-rows: minmax(0, 1fr) auto; }
body.video-production .source-credit, body.video-production .playback, body.video-production #status-output { display: none !important; }
body.video-production .timeline-panel { padding: .22rem .75rem .34rem; }
body.video-production .timeline-wrap { margin-top: 0; }
body.video-production .station-panel { top: .7rem; max-height: calc(100% - 1.4rem); }
body.video-production .legend { bottom: .55rem; }

body { overflow: hidden; }

button, input, select { font: inherit; }

button, select, input[type="search"] {
  border: 1px solid #3f708b;
  border-radius: 7px;
  background: #0c273d;
  color: #edf9ff;
  padding: 0.5rem 0.68rem;
}

button:hover, button:focus-visible, select:focus-visible, input:focus-visible {
  border-color: var(--gold);
  outline: 2px solid rgba(242, 195, 91, 0.32);
  outline-offset: 1px;
}

button[aria-pressed="true"] { background: #1f627e; border-color: var(--gold); }
button:disabled { opacity: 0.48; cursor: not-allowed; }

.app-shell { width: 100%; height: 100dvh; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; overflow: hidden; }

.visual-tabs { display: flex; gap: 0.35rem; padding: 0.3rem 0.72rem; border-bottom: 1px solid #31546a; background: #071725; }
.visual-tabs button { padding: 0.34rem 0.8rem; }
.visual-tabs button[aria-selected="true"] { border-color: var(--gold); background: #1f627e; }

.topbar {
  display: grid;
  grid-template-columns: minmax(390px, 1.15fr) minmax(220px, 0.7fr) minmax(380px, 1.1fr) minmax(340px, 1fr);
  gap: 0.55rem;
  align-items: stretch;
  padding: 0.48rem 0.72rem;
  background: linear-gradient(180deg, #102c43, #071725);
  border-bottom: 1px solid #31546a;
}

.brand-navigation-group {
  display: grid;
  grid-template-columns: minmax(165px, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
  padding-right: 0.35rem;
}

.toolbar-group {
  position: relative;
  min-width: 0;
  padding: 1.12rem 0.42rem 0.12rem 0.62rem;
  border-left: 1px solid rgba(121, 200, 232, 0.45);
}
.toolbar-group-title {
  position: absolute;
  top: 0;
  left: 0.62rem;
  color: #d9eff8;
  font-size: 0.7rem;
  font-weight: 600;
}

.brand { display: flex; gap: 0.65rem; align-items: center; min-width: 0; }
.brand img { width: 52px; height: 52px; flex: 0 0 auto; }
.brand h1 { margin: 0; font-size: clamp(1.12rem, 2.2vw, 1.72rem); }
.brand p { margin: 0.15rem 0 0; color: #a7c8d7; font-size: 0.78rem; }

.view-nav { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.view-nav a {
  border: 1px solid #3f708b;
  border-radius: 7px;
  padding: 0.48rem 0.62rem;
  color: #d9eff8;
  text-decoration: none;
  white-space: nowrap;
}
.view-nav a:hover, .view-nav a:focus-visible, .view-nav a.active {
  border-color: var(--gold);
  background: #174b66;
  outline: 2px solid rgba(242, 195, 91, 0.28);
  outline-offset: 1px;
}

.object-controls { display: grid; gap: 0.38rem; align-items: start; }
.object-toolbar .object-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.view-toolbar .object-controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.display-toolbar-content { display: grid; grid-template-columns: minmax(92px, 0.7fr) minmax(250px, 2fr); gap: 0.42rem; align-items: start; }
.display-toolbar .night-control { display: grid; gap: 0.24rem; color: #bcd6e2; font-size: 0.75rem; }
.view-mode-control { grid-column: span 2; }
.trajectory-camera-control { grid-column: span 2; }
.earth-scale-control { grid-column: span 1; }
.object-controls label { display: grid; gap: 0.24rem; color: #bcd6e2; font-size: 0.75rem; }
.object-status-help { color: #f2c35b; font-size: 0.62rem; line-height: 1.18; }
.code-toggle-control button { padding-block: 0.46rem; }
.night-control span { display: flex; align-items: center; gap: 0.35rem; min-height: 2.05rem; }
.night-control input { width: min(120px, 100%); min-width: 60px; }
.night-control output { min-width: 2.4rem; color: #fff; }

.readouts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.32rem; }
.readout { min-width: 0; padding: 0.38rem 0.48rem; border: 1px solid #294d62; border-radius: 7px; background: rgba(2, 12, 22, 0.56); }
.readout span { display: block; color: #93b7c7; font-size: 0.68rem; }
.readout strong { display: block; margin-top: 0.1rem; color: #fff; font-size: 0.77rem; overflow-wrap: anywhere; }
.observation-readout strong .event-count-line { display: block; white-space: nowrap; }
.observation-readout abbr { color: #bfeaff; text-decoration: underline dotted; text-underline-offset: 2px; cursor: help; }

.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #020812; }
#earth-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.legend {
  position: absolute;
  left: 0.75rem;
  bottom: 6.35rem;
  display: grid;
  gap: 0.24rem;
  padding: 0.5rem 0.62rem;
  border: 1px solid #3d6478;
  border-radius: 8px;
  background: rgba(2, 12, 21, 0.8);
  color: #c5dce6;
  font-size: 0.72rem;
}

.legend i { display: inline-block; width: 0.65rem; height: 0.65rem; margin-right: 0.35rem; border-radius: 50%; vertical-align: -0.05rem; }
.legend .front { background: #e9443f; border: 1px solid #ffe06a; }
.legend .back { background: transparent; border: 1px dashed #dcecf4; }
.legend .observation-ring { background: transparent; border: 2px solid #ffd166; }
.legend .submission-fill { background: conic-gradient(#ffd166 0 60%, transparent 60% 100%); border: 2px solid #ffd166; }
.legend .sub-asteroid-marker, .impact-map-legend .sub-asteroid-marker { border: 2px solid #ffd166; background: #ffd166; box-shadow: 0 -0.34rem 0 -0.25rem #ffd166, 0 0.34rem 0 -0.25rem #ffd166, -0.34rem 0 0 -0.25rem #ffd166, 0.34rem 0 0 -0.25rem #ffd166; }
.legend label { display: flex; align-items: center; gap: 0.25rem; margin-top: 0.2rem; }
.station-size-legend { display: flex; align-items: center; gap: 0.25rem; }
.station-size-legend i { width: auto; height: auto; margin: 0 0.05rem 0 0.2rem; border: 2px solid #ffd166; background: transparent; }
.station-size-legend .size-one { width: 0.55rem; height: 0.55rem; }
.station-size-legend .size-five { width: 0.78rem; height: 0.78rem; }
.station-size-legend .size-many { width: 1.05rem; height: 1.05rem; }

.station-panel {
  position: absolute;
  right: 0.75rem;
  top: 0.7rem;
  bottom: 0.7rem;
  width: min(300px, calc(100% - 1.5rem));
  max-height: none;
  overflow: hidden;
  padding: 0.48rem;
  border: 1px solid #3d6478;
  border-radius: 8px;
  background: rgba(2, 12, 21, 0.84);
  font-size: 0.68rem;
}
.station-panel strong { display: block; margin-bottom: 0.28rem; color: #f4dc92; }
.station-panel table { width: 100%; border-collapse: collapse; }
.station-panel th, .station-panel td { padding: 0.08em 0.18em; line-height: 1.12; text-align: left; vertical-align: top; border-top: 1px solid rgba(94, 139, 160, 0.32); }
.station-panel th:last-child, .station-panel td:last-child { text-align: right; }
.station-code-key { display: inline-flex; align-items: center; gap: 0.28rem; font-weight: 700; white-space: nowrap; }
.station-code-key i { width: 0.68rem; height: 0.68rem; border: 2px solid currentColor; border-radius: 50%; }
.station-code-key:hover, .station-code-key:focus-visible { color: #fff !important; }
.submission-note { margin: 0.38rem 0 0; color: #9fbfce; font-size: var(--station-note-size, 0.62rem); line-height: 1.25; }

.camera-help {
  position: absolute;
  left: 50%;
  top: 0.7rem;
  transform: translateX(-50%);
  max-width: calc(100% - 640px);
  padding: 0.35rem 0.55rem;
  border: 1px solid rgba(121, 200, 232, 0.65);
  border-radius: 7px;
  background: rgba(2, 12, 21, 0.8);
  color: #cce8f2;
  font-size: 0.69rem;
  text-align: center;
  pointer-events: none;
}

.timeline-panel { padding: 0.55rem 0.85rem 0.7rem; background: #071725; border-top: 1px solid #31546a; }
.playback { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.playback label { display: flex; align-items: center; gap: 0.35rem; color: #bcd5e0; font-size: 0.78rem; }
#speed { width: 6.2rem; }

.timeline-wrap { position: relative; display: grid; grid-template-columns: 1.65rem minmax(0, 1fr) 1.65rem; align-items: center; gap: 0.3rem; margin-top: 0.35rem; padding-top: 1.05rem; padding-bottom: 0.65rem; }
#timeline { width: 100%; accent-color: var(--gold); }
.timeline-step { min-width: 1.65rem; width: 1.65rem; height: 1.5rem; padding: 0; font-size: 0.68rem; line-height: 1; }
#timeline-markers { position: absolute; left: 2.05rem; right: 2.05rem; top: 0; height: 2.35rem; pointer-events: none; }
.timeline-marker {
  --events: 1;
  position: absolute;
  bottom: 1.12rem;
  width: calc(2px + var(--events) * 1px);
  height: calc(7px + var(--events) * 2px);
  min-width: 2px;
  padding: 0;
  border: 0;
  border-radius: 1px;
  background: #f2c35b;
  transform: translateX(-50%);
  pointer-events: auto;
}
.timeline-marker.submission-marker { top: 1.22rem; bottom: auto; background: #62c9ed; transform: translateX(-50%); }
.timeline-marker.dual-event { box-shadow: 0 0 0 1px #fff; }

.impact-marker { width: 9px; min-width: 9px; height: 18px; border-radius: 50% 50% 1px 1px; background: #ff4b45; box-shadow: 0 0 0 2px #fff1a8; }

#status-output { margin: 0.42rem 0 0; color: #a9c9d7; font-size: 0.75rem; }
.timeline-key { color: #9fc7d7; font-size: 0.7rem; white-space: nowrap; }
#event-detail { position: absolute; z-index: 12; left: 0.8rem; bottom: 0.8rem; max-width: min(480px, calc(100% - 1.6rem)); white-space: pre-wrap; padding: 0.55rem; border: 1px solid var(--gold); border-radius: 7px; background: rgba(2, 10, 18, 0.9); font-size: 0.74rem; }
.impact-map-panel { position: absolute; inset: 0; z-index: 8; background: #071522; }
.impact-map-panel[hidden] { display: none; }
#impact-map-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#impact-map-canvas:active { cursor: grabbing; }
.impact-map-controls { position: absolute; top: 0.75rem; right: 0.75rem; display: flex; flex-wrap: wrap; align-items: end; gap: 0.4rem; padding: 0.5rem; border: 1px solid #49768c; border-radius: 8px; background: rgba(2, 12, 21, 0.88); }
.impact-map-controls label { display: grid; gap: 0.2rem; color: #bcd6e2; font-size: 0.7rem; }
.impact-map-controls button { min-width: 2.4rem; }
.impact-map-follow { display: flex !important; align-items: center; padding: 0.45rem; }
.impact-map-legend { position: absolute; left: 0.75rem; bottom: 0.75rem; display: grid; gap: 0.32rem; max-width: min(680px, calc(100% - 1.5rem)); padding: 0.55rem 0.7rem; border: 1px solid #49768c; border-radius: 8px; background: rgba(2, 12, 21, 0.88); color: #d5e9f2; font-size: 0.72rem; }
.impact-map-legend span { display: flex; align-items: center; gap: 0.4rem; }
.impact-map-legend i { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; }
.impact-map-impact-marker { border: 2px solid #ff453f; background: #ff453f; }
.impact-map-track-marker { width: 1.1rem !important; height: 0 !important; border: 0 !important; border-top: 3px solid #69dcfa !important; border-radius: 0 !important; }
body.impact-map-mode .earth-source-credit,
body.impact-map-mode .sky-source-credit,
body.impact-map-mode .legend,
body.impact-map-mode .station-panel,
body.impact-map-mode .camera-help { display: none !important; }
.trajectory-camera-control[hidden] { display: none !important; }

#load-progress { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 5, 10, 0.78); }
#load-progress[hidden] { display: none; }
.progress-card { width: min(560px, calc(100% - 2rem)); padding: 1rem; border: 1px solid #5f8ca2; border-radius: 10px; background: #0b2235; }
.progress-card progress { width: 100%; height: 1.25rem; }
.progress-card p { color: #c1dce7; font-size: 0.8rem; }

.source-credit { position: absolute; left: 0.7rem; top: 5rem; color: #aac8d5; font-size: 0.66rem; }
.source-credit a { color: #cdeeff; }
.sky-source-credit { display: none; }
body.sky-chart-mode .earth-source-credit,
body.sky-chart-mode .legend { display: none; }
body.sky-chart-mode .sky-source-credit { display: block; }
body.sky-chart-mode .source-credit { top: auto; bottom: 0.12rem; max-width: calc(100% - 360px); }

body.stereo-mode .brand-navigation-group,
body.stereo-mode .object-toolbar,
body.stereo-mode .display-toolbar,
body.stereo-mode .brand,
body.stereo-mode .view-nav,
body.stereo-mode .object-search-control,
body.stereo-mode .object-select-control,
body.stereo-mode .earth-scale-control,
body.stereo-mode .marker-mode-control,
body.stereo-mode .code-toggle-control,
body.stereo-mode .night-control,
body.stereo-mode .readouts,
body.stereo-mode .legend,
body.stereo-mode .station-panel,
body.stereo-mode .camera-help,
body.stereo-mode .source-credit,
body.stereo-mode #event-detail,
body.stereo-mode .playback,
body.stereo-mode #status-output { display: none !important; }
body.stereo-mode .topbar { display: block; padding: 0.28rem 0.55rem; }
body.stereo-mode .object-controls { display: block; }
body.stereo-mode .view-toolbar { padding: 0; border: 0; }
body.stereo-mode .view-toolbar > .toolbar-group-title { display: none; }
body.stereo-mode .view-mode-control { display: flex; align-items: center; justify-content: center; gap: 0.5rem; font-size: 0.72rem; }
body.stereo-mode .view-mode-control select { padding-block: 0.32rem; }
body.stereo-mode .timeline-panel { padding: 0.18rem 0.55rem 0.32rem; }
body.stereo-mode .timeline-wrap { margin-top: 0; }

@media (max-width: 1320px) {
  .topbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .brand-navigation-group { grid-column: 1 / -1; }
  .object-toolbar { grid-column: 1; }
  .view-toolbar { grid-column: 2; }
  .display-toolbar { grid-column: 1 / -1; }
}

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr; }
  .brand-navigation-group, .object-toolbar, .view-toolbar, .display-toolbar { grid-column: 1; }
  .view-nav { justify-content: end; }
  .display-toolbar-content { grid-template-columns: minmax(90px, .45fr) minmax(0, 1.55fr); }
  .camera-help { max-width: calc(100% - 640px); }
}

@media (max-width: 650px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0.32rem 0.4rem; gap: 0.35rem; }
  .view-nav { justify-content: end; }
  .brand img { width: 36px; height: 36px; }
  .brand p { display: none; }
  .object-controls { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.3rem; }
  .object-controls label { font-size: 0.66rem; }
  .object-controls input, .object-controls select { min-width: 0; padding: 0.34rem 0.4rem; }
  .readouts { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.25rem; }
  .readout { padding: 0.24rem 0.36rem; }
  .readout strong { font-size: 0.7rem; }
  .legend { left: 0.35rem; bottom: 4.2rem; max-width: 58%; padding: 0.35rem; }
  .station-panel { top: 0.35rem; bottom: 0.35rem; right: 0.5rem; width: min(210px, 42%); max-height: none; }
  .camera-help { left: 0.5rem; top: auto; bottom: 0.5rem; transform: none; max-width: calc(100% - 1rem); }
  .source-credit { max-width: 65%; }
  body.sky-chart-mode .source-credit { max-width: 48%; font-size: 0.55rem; }
  .timeline-panel { padding: 0.35rem 0.45rem 0.42rem; }
  .playback { gap: 0.25rem; }
  .playback button, .playback select, .playback input { padding: 0.3rem 0.4rem; }
  #status-output { margin-top: 0.25rem; max-height: 2.4em; overflow: hidden; }
}
