:root {
  --bg: #05070d;
  --panel: rgba(16, 20, 32, 0.92);
  --border: #283044;
  --text: #e4e8f1;
  --muted: #8b93a7;
  --accent: #ffd166;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
.muted { color: var(--muted); }

#map { position: fixed; inset: 0; }
#map canvas { display: block; }

.body-label {
  color: #f3d9ee;
  font-size: 11px;
  transform: translate(9px, -50%);
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 0 3px #000;
}

.planet-label {
  color: var(--muted);
  font-size: 11px;
  transform: translate(8px, -50%);
  pointer-events: none;
  white-space: nowrap;
}

#toolbar, #timebar, #legend, #panel, #calendar, #dist {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
}

#toolbar {
  top: 12px; left: 12px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 8px 14px;
  max-width: calc(100vw - 24px);
}
#toolbar h1 { font-size: 16px; margin: 0; font-weight: 600; }

input, select, button {
  font: inherit; color: var(--text);
  background: #0d111c; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px;
}
button { cursor: pointer; }
button:hover { border-color: var(--muted); }
#search { width: 220px; }

#legend {
  left: 12px; bottom: 64px;
  padding: 8px 12px;
  font-size: 12px;
  max-width: 260px;
}
#legend .row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
#legend .sw { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#legend .bar { height: 10px; border-radius: 3px; margin: 4px 0 2px; }
#legend .ends { display: flex; justify-content: space-between; color: var(--muted); }

#timebar {
  left: 12px; bottom: 12px;
  display: flex; gap: 8px; align-items: center;
  padding: 6px 10px;
}
#play { width: 34px; }

#tooltip {
  position: fixed; pointer-events: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 8px; font-size: 12px;
  transform: translate(12px, -50%);
}

#panel {
  top: 12px; right: 12px; bottom: 12px;
  width: min(420px, calc(100vw - 24px));
  padding: 16px;
  overflow-y: auto;
}
.close {
  position: absolute; top: 10px; right: 10px;
  width: 30px; height: 30px; padding: 0; font-size: 18px; line-height: 1;
}
#panel h2 { margin: 0 36px 2px 0; font-size: 20px; }
#viewer {
  position: relative;
  height: 320px; margin: 12px 0 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: radial-gradient(circle at 50% 40%, #151a28, #06080e);
  overflow: hidden;
}
#viewer canvas { display: block; }
#viewer-msg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 20px;
  pointer-events: none;
}
#model-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
#model-select { max-width: 260px; }

#p-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#p-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 8px 4px 0; vertical-align: top; width: 45%; }
#p-table td { padding: 4px 0; font-variant-numeric: tabular-nums; }
#p-table tr + tr { border-top: 1px solid var(--border); }
#p-table tr.sect th {
  color: var(--accent); font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 14px 0 4px;
}
#p-links { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; }
a { color: var(--accent); }

@media (max-width: 700px) {
  #legend { display: none; }
  #panel { top: auto; height: 70vh; }
}
#model-row[hidden] { display: none; }

#cal-open.on, #dist-open.on { border-color: var(--accent); color: var(--accent); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; margin-right: 6px; vertical-align: -1px; }
.legend-note { margin-top: 6px; font-size: 11px; max-width: 230px; }

/* ---- launch-window section in the body panel ---- */
#p-windows { margin: 4px 0 6px; }
.sect-title {
  color: var(--accent); font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; margin: 8px 0 4px;
}
.sect-title .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.win-chart { width: 100%; height: auto; display: block; }
.win-chart .axis { fill: var(--muted); font-size: 10px; }
.win-chart .grid { stroke: var(--border); }
.win-dot { cursor: pointer; }
.win-dot circle { fill: #b05a9a; stroke: none; }
.win-dot line { stroke: #b05a9a; stroke-width: 2; opacity: 0.5; }
.win-dot.best circle { fill: var(--accent); }
.win-dot.on circle { fill: #ffa94d; stroke: #fff; stroke-width: 1.5; }
.win-dot:hover circle { stroke: #fff; stroke-width: 1; }
.win-list { max-height: 132px; overflow-y: auto; margin-top: 4px; border-top: 1px solid var(--border); }
.win-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: none;
  padding: 4px 2px; font-size: 12px; font-variant-numeric: tabular-nums;
}
.win-row:hover { background: #ffffff0d; }
.win-row.on { background: #ffa94d22; }

/* ---- calendar ---- */
#calendar {
  top: 70px; left: 12px; bottom: 64px;
  width: min(560px, calc(100vw - 24px));
  padding: 16px;
  display: flex; flex-direction: column;
}
#calendar h2 { margin: 0 36px 4px 0; font-size: 18px; }
.cal-intro { margin: 0 0 10px; font-size: 12px; }
.cal-filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 8px; font-size: 13px; }
#cal-dv { vertical-align: middle; width: 140px; padding: 0; }
#cal-dv-out { display: inline-block; width: 72px; font-variant-numeric: tabular-nums; }
#cal-hist svg { width: 100%; height: 48px; display: block; }
#cal-hist rect { fill: #7a4fc0; cursor: pointer; }
#cal-hist rect:hover { fill: var(--accent); }
.cal-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin: 2px 0 6px; }
#cal-summary { font-size: 12px; margin-bottom: 6px; }
.cal-head, .cal-row {
  display: grid; grid-template-columns: 62px 1fr 64px 128px; gap: 8px; align-items: center;
}
.cal-head { font-size: 11px; color: var(--muted); padding: 0 6px 4px; border-bottom: 1px solid var(--border); }
#cal-list { overflow-y: auto; flex: 1; min-height: 0; position: relative; }
.cal-year {
  position: sticky; top: 0; z-index: 1;
  background: #151a28; color: var(--accent); font-weight: 600; font-size: 12px;
  padding: 4px 6px; border-bottom: 1px solid var(--border);
}
.cal-row {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
  background: none; padding: 5px 6px; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.cal-row:hover { background: #ffffff0d; }
.cal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-dv { font-weight: 600; }
.cal-tof { font-size: 11.5px; }
.cal-best { color: var(--accent); }

@media (max-width: 700px) {
  #calendar { top: 120px; bottom: 64px; }
  .cal-head, .cal-row { grid-template-columns: 52px 1fr 48px; }
  .cal-tof, .cal-head span:last-child { display: none; }
}
#legend .sw { margin-right: 0; }
#calendar[hidden], #panel[hidden], #dist[hidden] { display: none; }

/* ---- clickable legend ---- */
#legend { max-height: calc(100vh - 150px); overflow-y: auto; }
#legend .legend-title { font-weight: 600; margin-bottom: 4px; }
#legend button.row {
  display: flex; align-items: center; gap: 6px; width: 100%;
  margin: 0; padding: 2px 4px; border: 0; border-radius: 4px;
  background: none; font-size: 12px; text-align: left;
}
#legend button.row:hover { background: #ffffff12; }
#legend button.row .lbl { flex: 1; }
#legend button.row.off { opacity: 0.4; }
#legend button.row.off .lbl { text-decoration: line-through; }
#legend button.row.off .sw { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--muted); }
.legend-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; font-size: 11px; }
.legend-others, .legend-hint { margin-top: 4px; font-size: 11px; max-width: 240px; line-height: 1.6; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 11px; text-decoration: underline; }
button.chip { padding: 0 6px; font-size: 11px; border-radius: 10px; }
body.cal-open #legend { left: calc(min(560px, 100vw - 24px) + 24px); bottom: 64px; }
@media (max-width: 900px) { body.cal-open #legend { display: none; } }

/* ---- distributions ---- */
#dist {
  top: 70px; left: 12px; bottom: 64px;
  width: min(560px, calc(100vw - 24px));
  padding: 16px;
  display: flex; flex-direction: column;
}
#dist h2 { margin: 0 36px 4px 0; font-size: 18px; }
#dist-body { overflow-y: auto; flex: 1; min-height: 0; padding-right: 4px; }
.dist-chart { padding: 10px 0 12px; border-top: 1px solid var(--border); }
.dist-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 12px; margin-bottom: 4px; }
.dist-title { font-weight: 600; font-size: 13px; }
.dist-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.dist-chart .axis { fill: var(--muted); font-size: 10px; }
.dist-chart .cls { fill: var(--text); font-size: 11px; font-weight: 600; }
.dist-chart .val { fill: var(--muted); font-size: 10px; }
.dist-chart .grid, .dist-chart .tick { stroke: var(--border); }
.dist-chart .ref { stroke: var(--muted); stroke-width: 1; }
.dist-chart .sel { stroke: #ffa94d; stroke-width: 2; }
.dist-chart .sel-label { fill: var(--text); font-size: 10.5px; font-weight: 600; paint-order: stroke; stroke: #10141f; stroke-width: 3px; }
.dist-chart g.on .cls, .dist-chart g.on .val { fill: #ffa94d; }
.dist-chart .hit { fill: transparent; cursor: default; }
.dist-chart .hit:hover { fill: #ffffff10; }
.dist-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.dist-note { font-size: 11px; margin-top: 4px; line-height: 1.45; }
#tooltip b { font-weight: 600; }

#guide-link {
  font-size: 14px; color: var(--text); text-decoration: none;
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; background: #0d111c;
}
#guide-link:hover { border-color: var(--muted); }
.legend-guide { display: block; margin-top: 6px; font-size: 11.5px; }
