/* ==========================================================================
 * styles.css — dark "instrument panel" theme for the Solar System orrery.
 *
 * Layout: a 3-column CSS grid (sidebar / stage / footer). The inspector is an
 * overlay inside the stage so the canvas never resizes when it opens, which
 * keeps the projection stable while the user is inspecting a body.
 * ========================================================================== */

/* ---------------------------------------------------------------- tokens */
:root {
  --bg:            #05060c;
  --bg-panel:      #0c1020;
  --bg-panel-2:    #111731;
  --bg-input:      #161d3a;
  --line:          #232c52;
  --line-soft:     #1a2244;
  --text:          #e8ecff;
  --text-dim:      #97a1cc;
  --text-faint:    #6b76a3;
  --accent:        #6ea8fe;
  --accent-2:      #ffd257;
  --accent-dim:    #2b4a86;
  --good:          #6ee7a8;
  --warn:          #ffb35c;
  --sun:           #ffd257;
  --radius:        10px;
  --radius-sm:     7px;
  --shadow:        0 12px 34px rgba(0, 0, 0, .55);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --topbar-h: 56px;
  --sidebar-w: 296px;
  --foot-h: 30px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { overflow: hidden; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------ app grid */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--foot-h);
  grid-template-areas:
    "topbar topbar"
    "sidebar stage"
    "foot    foot";
  height: 100vh;
  height: 100dvh;
}

/* -------------------------------------------------------------- topbar */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px 0 16px;
  background: linear-gradient(180deg, #0e1428, #0a0e1e);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 15px; line-height: 1.15; white-space: nowrap; }
.brand-text p {
  margin: 0; font-size: 11px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.clock {
  margin-left: auto;
  display: flex; flex-direction: column; align-items: flex-end;
  line-height: 1.2; min-width: 0;
}
.clock-date {
  font-family: var(--mono); font-size: 13px; color: var(--text);
  white-space: nowrap;
}
.clock-meta {
  font-size: 11px; color: var(--text-faint); font-family: var(--mono);
  white-space: nowrap;
}
.clock-meta .dot { opacity: .5; margin: 0 4px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 12px;
  min-height: 34px;
  background: var(--bg-panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:hover { background: #1a2246; border-color: #33406f; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .42; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary {
  background: linear-gradient(180deg, #2f5da8, #24478a);
  border-color: #3d6fbe;
  color: #fff;
}
.btn-primary:hover { background: linear-gradient(180deg, #376bbd, #2a5199); }

.btn-wide { width: 100%; }
.btn.icon-only { padding: 7px; width: 34px; }

/* The play button's icon switches between pause and play via aria-pressed. */
#btnPlay .icon {
  width: 12px; height: 14px; flex: none; position: relative;
}
#btnPlay .icon::before,
#btnPlay .icon::after {
  content: ""; position: absolute; background: currentColor; border-radius: 1px;
  transition: all .15s ease;
}
/* playing -> show pause bars */
#btnPlay[aria-pressed="false"] .icon::before { left: 0; top: 0; width: 4px; height: 14px; }
#btnPlay[aria-pressed="false"] .icon::after  { right: 0; top: 0; width: 4px; height: 14px; }
/* paused -> show a play triangle */
#btnPlay[aria-pressed="true"] .icon::before {
  left: 1px; top: 0; width: 0; height: 0; background: none;
  border-left: 11px solid currentColor;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-radius: 0;
}
#btnPlay[aria-pressed="true"] .icon::after { display: none; }

/* -------------------------------------------------------------- sidebar */
.sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
}

.panel {
  background: var(--bg-panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px;
}

.panel-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.panel-title svg { width: 15px; height: 15px; flex: none; opacity: .8; }
.panel-title .count {
  margin-left: auto; font-size: 11px; color: var(--text-faint);
  font-family: var(--mono); letter-spacing: 0;
}

.field-label {
  display: block; font-size: 11px; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px;
}

.hint { margin: 8px 0 0; font-size: 11px; line-height: 1.45; color: var(--text-faint); }
.hint em { color: var(--text-dim); font-style: normal; }

.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.row-label {
  font-size: 11px; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .06em; flex: none;
}
.row input[type="range"] { flex: 1; min-width: 0; }

/* ------------------------------------------------------------- ranges */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent; cursor: pointer; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-dim), #1a2244);
}
input[type="range"]::-moz-range-track {
  height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-dim), #1a2244);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; margin-top: -5px;
  border-radius: 50%; background: var(--accent);
  border: 2px solid #0b1020;
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2px solid #0b1020;
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]:focus-visible { outline-offset: 6px; }

/* --------------------------------------------------------- speed block */
.speed-row, .zoom-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 2px;
}
.speed-readout, .zoom-readout {
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  color: var(--accent-2);
  background: #0a0e1e; border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 4px 8px;
  white-space: nowrap;
}
.speed-presets { display: flex; gap: 4px; margin-left: auto; }

.chip {
  background: #161d3a; border: 1px solid var(--line);
  border-radius: 5px; color: var(--text-dim);
  font-size: 11px; font-family: var(--mono);
  padding: 3px 7px; cursor: pointer; line-height: 1.4;
}
.chip:hover { background: #1e2750; color: var(--text); }
.chip.is-active { background: var(--accent-dim); color: #fff; border-color: var(--accent); }

.segmented {
  display: inline-flex; border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden; background: #0f1530;
}
.segmented button {
  background: transparent; border: 0; color: var(--text-dim);
  font-size: 11px; padding: 5px 9px; cursor: pointer;
  border-right: 1px solid var(--line-soft); white-space: nowrap;
}
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: #1a2246; color: var(--text); }
.segmented button.is-active { background: var(--accent-dim); color: #fff; }
#viewPresets { margin-left: auto; }

/* ------------------------------------------------------------- toggles */
.toggles { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }

.toggle {
  display: flex; align-items: center; gap: 9px;
  cursor: pointer; font-size: 12.5px; color: var(--text-dim);
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track {
  width: 32px; height: 18px; flex: none; border-radius: 9px;
  background: #1c2447; border: 1px solid var(--line);
  position: relative; transition: background .15s ease, border-color .15s ease;
}
.toggle .knob {
  position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-faint); transition: transform .15s ease, background .15s ease;
}
.toggle input:checked + .track { background: var(--accent-dim); border-color: var(--accent); }
.toggle input:checked + .track .knob { transform: translateX(14px); background: #fff; }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:checked ~ .toggle-text { color: var(--text); }

/* ------------------------------------------------------------ focus box */
.focus-current {
  display: flex; align-items: center; gap: 8px;
  background: #0a0e1e; border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 7px 9px; margin-bottom: 8px;
}
.focus-dot {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  background: var(--text-faint); box-shadow: 0 0 8px currentColor;
}
.focus-name {
  font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel .btn-wide + .btn-wide { margin-top: 6px; }

/* ---------------------------------------------------------- body list */
.panel-bodies { padding-bottom: 8px; }
.body-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
}
.body-item {
  display: flex; align-items: center; gap: 7px;
  background: transparent; border: 1px solid transparent;
  border-radius: 6px; padding: 5px 7px;
  color: var(--text-dim); font-size: 12px; cursor: pointer;
  text-align: left; min-width: 0;
  transition: background .12s ease, color .12s ease;
}
.body-item:hover { background: #1a2246; color: var(--text); }
.body-item.is-selected {
  background: var(--accent-dim); color: #fff; border-color: var(--accent);
}
.body-item .swatch {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  box-shadow: 0 0 6px rgba(255, 255, 255, .18);
}
.body-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.body-item .per {
  margin-left: auto; font-family: var(--mono); font-size: 10px;
  color: var(--text-faint); flex: none;
}
.body-item.is-selected .per { color: #d8e4ff; }
.body-item.is-moon { padding-left: 14px; }
.body-item.is-moon .swatch { width: 7px; height: 7px; }
.body-group-label {
  grid-column: 1 / -1;
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin: 7px 0 2px;
}

.sidebar-foot {
  margin: auto 0 0; font-size: 11px; color: var(--text-faint);
  line-height: 1.5; padding: 4px 2px 0;
}

/* --------------------------------------------------------------- stage */
.stage {
  grid-area: stage;
  position: relative;
  min-width: 0; min-height: 0;
  background: radial-gradient(120% 90% at 50% 40%, #0a0f22 0%, #05060c 70%);
  overflow: hidden;
}
#sky {
  display: block; width: 100%; height: 100%;
  cursor: grab; touch-action: none;
}
#sky.is-panning { cursor: grabbing; }
#sky.is-hot { cursor: pointer; }

.stage-overlay {
  position: absolute; pointer-events: none;
  font-family: var(--mono); font-size: 11.5px;
}
.stage-overlay.top-left { top: 10px; left: 12px; }
.stage-overlay.top-center {
  top: 10px; left: 50%; transform: translateX(-50%);
}
.stage-overlay.bottom-right { bottom: 12px; right: 12px; pointer-events: auto; }
.zoom-buttons { display: flex; flex-direction: column; gap: 6px; }

.readout {
  background: rgba(10, 14, 30, .74);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 4px 9px; color: var(--text);
  backdrop-filter: blur(6px);
  white-space: nowrap;
}
.readout.is-dim { color: var(--text-dim); margin-top: 4px; }

#toast {
  background: rgba(20, 28, 56, .92);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 12px; color: var(--text);
  box-shadow: var(--shadow);
  max-width: min(520px, 80vw);
  text-align: center; line-height: 1.4;
}

/* ---------------------------------------------------------- inspector */
.inspector {
  position: absolute; top: 12px; right: 12px; bottom: 12px;
  width: 330px; max-width: calc(100% - 24px);
  background: rgba(12, 16, 32, .96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: inspector-in .18s ease;
}
@keyframes inspector-in {
  from { opacity: 0; transform: translateX(10px); }
  to   { opacity: 1; transform: none; }
}

.inspector-close {
  position: absolute; top: 9px; right: 9px;
  width: 28px; height: 28px; padding: 0;
  background: transparent; border: 0; border-radius: 6px;
  color: var(--text-faint); cursor: pointer;
  display: grid; place-items: center;
}
.inspector-close:hover { background: #1a2246; color: var(--text); }
.inspector-close svg { width: 16px; height: 16px; }

.inspector-head {
  display: flex; align-items: center; gap: 11px;
  padding-right: 30px; margin-bottom: 10px;
}
.inspector-swatch {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  box-shadow: 0 0 14px currentColor, inset -3px -3px 7px rgba(0, 0, 0, .5);
}
.inspector-head h2 { font-size: 19px; line-height: 1.15; }
.inspector-head p {
  margin: 2px 0 0; font-size: 11.5px; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .06em;
}

.inspector-blurb {
  margin: 0 0 12px; font-size: 12.5px; line-height: 1.5; color: var(--text-dim);
}

.inspector-grid {
  display: grid; grid-template-columns: auto 1fr;
  gap: 3px 10px; margin: 0;
  font-size: 12px;
}
.inspector-grid dt { color: var(--text-faint); }
.inspector-grid dd {
  margin: 0; font-family: var(--mono); text-align: right; color: var(--text);
}
.inspector-grid dd.is-live { color: var(--accent-2); }

.inspector-more { margin: 12px 0 0; }
.inspector-more summary {
  cursor: pointer; font-size: 11.5px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 5px 0; list-style: none;
}
.inspector-more summary::-webkit-details-marker { display: none; }
.inspector-more summary::before { content: "▸ "; color: var(--text-faint); }
.inspector-more[open] summary::before { content: "▾ "; }
.inspector-more .inspector-grid { margin-top: 6px; }
.inspector-more .inspector-grid dd { font-family: var(--sans); }

.inspector-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 14px;
}

.inspector-siblings { margin-top: 14px; border-top: 1px solid var(--line-soft); padding-top: 11px; }
.inspector-siblings h3 {
  font-size: 11.5px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px;
}
.sibling-list { display: flex; flex-direction: column; gap: 4px; }
.sibling {
  display: flex; align-items: center; gap: 8px;
  background: #0f1530; border: 1px solid var(--line-soft);
  border-radius: 6px; padding: 6px 8px;
  font-size: 12px; color: var(--text-dim); cursor: pointer; text-align: left;
}
.sibling:hover { background: #1a2246; color: var(--text); }
.sibling.is-selected { border-color: var(--accent); color: #fff; background: var(--accent-dim); }
.sibling .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.sibling .per { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.sibling.is-selected .per { color: #d8e4ff; }

/* ---------------------------------------------------------------- foot */
.foot {
  grid-area: foot;
  display: flex; align-items: center; gap: 18px;
  padding: 0 14px;
  background: #080b16;
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--text-faint);
  overflow: hidden;
}
.foot span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* -------------------------------------------------------------- dialog */
.dialog {
  width: min(620px, 92vw);
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(3, 5, 12, .72); backdrop-filter: blur(3px); }
.dialog h2 { font-size: 17px; margin-bottom: 14px; }
.dialog-cols {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 16px;
}
.dialog h3 {
  font-size: 11.5px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px;
}
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 12.5px; }
.keys dt { color: var(--text); font-family: var(--mono); font-size: 11.5px; }
.keys dd { margin: 0; color: var(--text-dim); }
kbd {
  display: inline-block; min-width: 20px; text-align: center;
  background: #1a2246; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px;
  padding: 1px 5px; font-family: var(--mono); font-size: 11px;
}

/* ------------------------------------------------------------ responsive */
@media (max-width: 1000px) {
  :root { --sidebar-w: 262px; }
  .inspector { width: 300px; }
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) 44vh minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "stage"
      "sidebar";
  }
  body { overflow: auto; }
  .sidebar { border-right: 0; border-top: 1px solid var(--line); }
  .foot { display: none; }
  .inspector {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    width: auto; max-width: none; max-height: 62vh;
    border-radius: 14px 14px 0 0;
    animation: inspector-up .2s ease;
  }
  @keyframes inspector-up {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
  }
  .body-list { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
}

@media (max-width: 560px) {
  .brand-text p { display: none; }
  .clock-date { font-size: 12px; }
  #btnResetTime { display: none; }
  .dialog-cols { grid-template-columns: 1fr; }
  .stage-overlay.top-left .readout.is-dim { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .inspector { animation: none; }
  * { transition-duration: .01ms !important; }
}
