/* space.css: the "observatory" skin, loaded after style.css. Everything here is an override, so the
   layout and behaviour stay in style.css and app.js.

   Direction: a mission-control / observatory instrument feel, kept restrained. Translucent glass
   panels with hairline edges, one technical face (IBM Plex Mono, already loaded) for labels and
   numbers, the serif kept for documentary captions, glow only on a few key numbers and on focus or
   selection. The semantic colours are untouched: the spectral red-to-gold ramp, water = blue,
   gold = focus / current / SPHEREx.

   Reusable hooks for panels that do not exist yet (new views pick the look up automatically):
     .sheet, .panel, .pane, .view-panel, [data-panel]   glass instrument panel
     .sx-glass                                            same, as an opt-in utility class
     .sx-brackets                                         corner brackets (use on key panels only)
     .kicker, .eyebrow, .sx-label                         small mono tracking label
     .sx-num / .num.key / dd.val                          glowing key number
   Tokens: --sx-glass, --sx-glass-strong, --sx-edge, --sx-edge-hi, --sx-blur, --sx-bracket. */

:root {
  --space: #05070d;                         /* matches the 3D renderer's clear colour */
  --ink-3: rgba(236, 232, 226, 0.58);       /* was 0.42: small labels now pass WCAG AA on the panels */
  --rule: rgba(178, 196, 232, 0.15);        /* hairlines a touch cooler, like instrument rules */
  --veil: rgba(6, 8, 13, 0.78);

  --sx-glass: rgba(9, 11, 18, 0.80);
  --sx-glass-strong: rgba(9, 11, 18, 0.92);
  --sx-edge: rgba(178, 198, 240, 0.17);
  --sx-edge-hi: rgba(206, 220, 255, 0.30);
  --sx-blur: 14px;
  --sx-bracket: rgba(214, 226, 255, 0.55);
  --sx-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 0 32px rgba(110, 140, 220, 0.035) inset, 0 20px 50px rgba(0, 0, 0, 0.5);
  --sx-glow: 0 0 14px rgba(255, 236, 205, 0.30);
  --sx-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --rp-glass: var(--sx-glass);

  /* The data drawer used to follow the system theme; on a deep-space stage a white sheet is
     jarring, so it is dark in both themes now (canvas plots read these same names). */
  --bg: #0b0d14; --surface: rgba(178, 198, 240, 0.07); --text: #ece8e2; --muted: #a8a39b; --line: rgba(178, 196, 232, 0.15);
  --error-bg: #3a1714; --error-text: #ffb8ad;
  --plot-bg: #080a10; --plot-axis: #a8a39b; --plot-grid: rgba(178, 196, 232, 0.12); --plot-fit: #ece8e2;
  --plot-point: #f08a35; --plot-later: rgba(240, 138, 53, 0.25);
  --tip-bg: rgba(12, 15, 24, 0.97); --tip-text: #ece8e2;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d14; --surface: rgba(178, 198, 240, 0.07); --text: #ece8e2; --muted: #a8a39b; --line: rgba(178, 196, 232, 0.15);
    --plot-bg: #080a10; --plot-axis: #a8a39b; --plot-grid: rgba(178, 196, 232, 0.12); --plot-fit: #ece8e2;
    --tip-bg: rgba(12, 15, 24, 0.97); --tip-text: #ece8e2;
  }
}
:root[data-theme="dark"], :root[data-theme="light"] {
  --bg: #0b0d14; --surface: rgba(178, 198, 240, 0.07); --text: #ece8e2; --muted: #a8a39b; --line: rgba(178, 196, 232, 0.15);
  --plot-bg: #080a10; --plot-axis: #a8a39b; --plot-grid: rgba(178, 196, 232, 0.12); --plot-fit: #ece8e2;
  --plot-point: #f08a35; --plot-later: rgba(240, 138, 53, 0.25);
  --tip-bg: rgba(12, 15, 24, 0.97); --tip-text: #ece8e2;
  color-scheme: dark;
}

body { background: var(--space); }
::selection { background: rgba(242, 193, 78, 0.32); color: #fff; }

/* ---------- backdrop (space.js) ---------- */
.sx-sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; background: var(--space); }
.sx-sky canvas { position: absolute; left: -48px; top: -48px; display: block; }
.space3d, .space3d.o3d { background: transparent; z-index: 0; }   /* the WebGL canvas is opaque anyway */
/* the 3D scene draws its own real-direction sky: step aside so there is never a double starfield */
.sx-3d .sx-sky { visibility: hidden; }
.sx-atmos {
  position: fixed; inset: -8%; z-index: 1; pointer-events: none;
  background:
    radial-gradient(ellipse 55% 45% at 8% 100%, rgba(163, 32, 46, 0.09), transparent 70%),
    radial-gradient(ellipse 40% 35% at 24% 92%, rgba(240, 138, 53, 0.04), transparent 70%),
    radial-gradient(ellipse 50% 40% at 96% 0%, rgba(70, 100, 180, 0.11), transparent 70%);
}
.sketch { z-index: 0; }

/* ---------- glass instrument panels ---------- */
.sheet, .panel, .pane, .view-panel, [data-panel], .sx-glass,
.rpsky, .rppanel, .rpclock, .rpnotice, .drawerinner {
  background: var(--sx-glass);
  border: 1px solid var(--sx-edge);
  box-shadow: var(--sx-shadow);
  -webkit-backdrop-filter: blur(var(--sx-blur)) saturate(125%);
  backdrop-filter: blur(var(--sx-blur)) saturate(125%);
}
/* a luminous top hairline: the light catching the panel's edge */
.rpsky, .rppanel, .rpclock, .rpnotice, .drawerinner, .panel, .pane, .view-panel, [data-panel], .sx-glass {
  border-top-color: var(--sx-edge-hi);
  border-radius: 6px;
}
/* text-heavy panels stay nearly opaque so long reading is never over busy scenery */
.sheet, .drawerinner { background: var(--sx-glass-strong); }
.sheet {
  border: 0; border-left: 1px solid var(--sx-edge);
  box-shadow: inset 1px 0 0 rgba(206, 220, 255, 0.05), -28px 0 60px rgba(0, 0, 0, 0.5);
}

/* corner brackets: key panels only (the instrument view, the mission clock, the data drawer) */
.sx-brackets, .rpsky, .rpclock, .drawerinner { position: relative; }
.rpclock, .rpsky { position: absolute; }
.sx-brackets::before, .rpsky::before, .rpclock::before, .drawerinner::before {
  content: ""; position: absolute; inset: -5px; pointer-events: none; z-index: 1;
  --b: var(--sx-bracket); --l: 10px;
  background:
    linear-gradient(var(--b), var(--b)) left top / var(--l) 1px no-repeat,
    linear-gradient(var(--b), var(--b)) left top / 1px var(--l) no-repeat,
    linear-gradient(var(--b), var(--b)) right top / var(--l) 1px no-repeat,
    linear-gradient(var(--b), var(--b)) right top / 1px var(--l) no-repeat,
    linear-gradient(var(--b), var(--b)) left bottom / var(--l) 1px no-repeat,
    linear-gradient(var(--b), var(--b)) left bottom / 1px var(--l) no-repeat,
    linear-gradient(var(--b), var(--b)) right bottom / var(--l) 1px no-repeat,
    linear-gradient(var(--b), var(--b)) right bottom / 1px var(--l) no-repeat;
}

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(to bottom, rgba(5, 7, 13, 0.92), rgba(5, 7, 13, 0.62));
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  backdrop-filter: blur(10px) saturate(120%);
}
.brand h1 { letter-spacing: 0; }
.tagline { color: var(--ink-2); }
.tag { border-color: var(--sx-edge); border-radius: 3px; padding: 6px 8px 5px; letter-spacing: 0.1em; }
.tag.real { background: rgba(143, 209, 158, 0.06); box-shadow: 0 0 12px rgba(143, 209, 158, 0.08); }
.tag.real::before {
  content: ""; display: inline-block; width: 5px; height: 5px; margin-right: 7px; vertical-align: 1px;
  border-radius: 50%; background: var(--real); box-shadow: 0 0 6px var(--real);
}
.topramp { height: 1px; opacity: 1; box-shadow: 0 0 10px rgba(240, 138, 53, 0.35); }

@media (max-width: 720px) {
  .topactions {
    background: var(--sx-glass-strong); border-bottom: 1px solid var(--sx-edge);
    -webkit-backdrop-filter: blur(var(--sx-blur)); backdrop-filter: blur(var(--sx-blur));
  }
}

/* ---------- controls: hover glow, targeting-bracket focus ---------- */
.link, .close, .menubtn { transition: border-color 0.15s, color 0.15s, text-shadow 0.2s; }
.link:not(:disabled):hover, .close:hover, .menubtn:hover { color: #fff; text-shadow: 0 0 12px rgba(242, 193, 78, 0.35); }
.link.quiet:hover { color: var(--ink); }
.rpbtn:hover { color: var(--accent); }
.btn { border-color: var(--sx-edge-hi); border-radius: 3px; background: rgba(178, 198, 240, 0.04); transition: border-color 0.15s, color 0.15s, box-shadow 0.2s, background 0.15s; }
.btn:hover { box-shadow: 0 0 0 1px rgba(242, 193, 78, 0.25), 0 0 16px rgba(242, 193, 78, 0.16); background: rgba(242, 193, 78, 0.06); }
.cta { transition: background 0.15s, border-color 0.15s, box-shadow 0.25s; }
.cta:hover { box-shadow: 0 0 22px rgba(242, 193, 78, 0.22); }
.cta.floating {
  background-color: rgba(18, 15, 9, 0.78);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.rpplay { box-shadow: 0 0 18px rgba(242, 193, 78, 0.18); transition: background 0.15s, box-shadow 0.2s; }
.rpplay:hover { box-shadow: 0 0 26px rgba(242, 193, 78, 0.34); }

/* Focus looks like a targeting reticle: four gold corner brackets around the control. The plain
   outline comes back in forced-colours mode. */
/* :where keeps this at zero specificity, so positioned controls (.close, .cta.floating) keep theirs */
:where(.link, .close, .menubtn, .btn, .tag, .cta, .rpplay, .rpspeeds button, .rail button, .rphandle, button.card) { position: relative; }
.drawerhead .close { position: relative; }
:is(.link, .close, .menubtn, .btn, .tag, .cta, .rpplay, .rpspeeds button, .rail button, .rphandle, button.card)::after {
  content: ""; position: absolute; inset: -4px -6px; pointer-events: none; opacity: 0;
  border-radius: 2px;
  --b: var(--accent); --l: 7px;
  background:
    linear-gradient(var(--b), var(--b)) left top / var(--l) 1.5px no-repeat,
    linear-gradient(var(--b), var(--b)) left top / 1.5px var(--l) no-repeat,
    linear-gradient(var(--b), var(--b)) right top / var(--l) 1.5px no-repeat,
    linear-gradient(var(--b), var(--b)) right top / 1.5px var(--l) no-repeat,
    linear-gradient(var(--b), var(--b)) left bottom / var(--l) 1.5px no-repeat,
    linear-gradient(var(--b), var(--b)) left bottom / 1.5px var(--l) no-repeat,
    linear-gradient(var(--b), var(--b)) right bottom / var(--l) 1.5px no-repeat,
    linear-gradient(var(--b), var(--b)) right bottom / 1.5px var(--l) no-repeat;
  filter: drop-shadow(0 0 3px rgba(242, 193, 78, 0.6));
  transition: opacity 0.15s, inset 0.18s var(--sx-ease);
}
:is(.cta, .rpplay)::after { inset: -6px -8px; border-radius: 999px; }
.rpspeeds button::after, .rphandle::after { inset: 1px; }
:is(.link, .close, .menubtn, .btn, .tag, .cta, .rpplay, .rpspeeds button, .rail button, .rphandle, button.card):focus-visible { outline: none; }
:is(.link, .close, .menubtn, .btn, .tag, .cta, .rpplay, .rpspeeds button, .rail button, .rphandle, button.card):focus-visible::after { opacity: 1; }
@media (forced-colors: active) {
  :is(.link, .close, .menubtn, .btn, .tag, .cta, .rpplay, .rpspeeds button, .rail button, .rphandle, button.card):focus-visible { outline: 2px solid CanvasText; }
}
/* everything else (inputs, summaries, rows) keeps an outline, with a soft halo */
:is(input, summary, tbody tr, .rprow, select, textarea, a):focus-visible {
  outline: 1.5px solid var(--accent); outline-offset: 2px; box-shadow: 0 0 0 4px rgba(242, 193, 78, 0.14);
}

/* ---------- typography: one technical face for labels and numbers ---------- */
.kicker, .eyebrow, .sx-label { font: 500 0.68rem/1.4 var(--f-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-2); }
.kind, .fliphead, .info h4.fliphead, .listhead, .rplabel, .layers summary { letter-spacing: 0.14em; }
.sx-num, .num.key, .stats dd.val, .rpcounts dd b, .rpdate { text-shadow: var(--sx-glow); }
.rpdate { font: 400 1.4rem/1.15 var(--f-mono); letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.rpdate small { margin-right: 10px; }

/* ---------- layers ---------- */
.layers { left: calc(var(--gutter) - 12px); padding: 6px 12px; border: 1px solid transparent; border-radius: 4px; transition: background 0.2s, border-color 0.2s; }
.layers[open] {
  background: var(--sx-glass); border-color: var(--sx-edge); box-shadow: var(--sx-shadow);
  -webkit-backdrop-filter: blur(var(--sx-blur)); backdrop-filter: blur(var(--sx-blur));
  padding: 6px 14px 10px 12px;
}
.layers summary { color: var(--ink-2); }
.layers summary:hover { color: var(--ink); }

/* ---------- narration ---------- */
.narration {
  background: linear-gradient(to top, rgba(5, 7, 13, 0.96) 0%, rgba(5, 7, 13, 0.93) 50%, rgba(5, 7, 13, 0.8) 74%, rgba(5, 7, 13, 0.45) 89%, rgba(5, 7, 13, 0) 100%);
}
.rail button[aria-current="step"]::before { text-shadow: 0 0 10px rgba(242, 193, 78, 0.55); }
.rail button[aria-current="step"] { border-bottom-color: var(--accent); box-shadow: 0 1px 0 rgba(242, 193, 78, 0.25), 0 6px 12px -8px rgba(242, 193, 78, 0.6); }
.cards, .ledger { border-top-color: var(--sx-edge-hi); }
#insetSky, canvas.strip, .flipstage, .rpstamp, .rpskywrap { border-color: var(--sx-edge); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); }
.rpskywrap { border: 1px solid var(--sx-edge); }

/* ---------- details sheet ---------- */
.info h3, .detail h3 { letter-spacing: 0; }
.slowproof { border-top-width: 1px; }
.sharefield { background: rgba(0, 0, 0, 0.55); border-color: var(--sx-edge); border-radius: 3px; }
.sci { border-top-color: var(--sx-edge); }

/* ---------- free-explore time track ---------- */
.timebar {
  padding: 0 14px; border-radius: 6px;
  background: rgba(9, 11, 18, 0.62); border: 1px solid var(--sx-edge);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.ramprange::-webkit-slider-thumb { width: 3px; box-shadow: 0 0 8px rgba(255, 241, 207, 0.8); border-radius: 1px; }
.ramprange::-moz-range-thumb { width: 3px; box-shadow: 0 0 8px rgba(255, 241, 207, 0.8); }

/* ---------- replay ---------- */
.rptag { box-shadow: 0 0 12px rgba(242, 193, 78, 0.28); }
.rpnotice { border-color: rgba(242, 193, 78, 0.38); border-top-color: rgba(242, 193, 78, 0.55); }
/* panel titles get a short steel lead-in rule, like a section mark on an instrument face */
:is(.rpskyhead, .rphead, .rphandle) .rplabel::before, .sx-label::before {
  content: ""; display: inline-block; width: 12px; height: 1px; margin-right: 8px; vertical-align: 0.3em;
  background: linear-gradient(90deg, var(--sx-edge-hi), rgba(206, 220, 255, 0.85));
}
.rpskyhead { padding-bottom: 8px; border-bottom: 1px solid var(--rule); margin-bottom: 10px; }
.rphead { padding-top: 14px; }
.rpheadnote { color: var(--ink-3); }
.rpcounts { border-bottom-color: var(--sx-edge); }
.rpcounts dd b { color: #fff; }
.rplisthead { color: var(--ink-3); border-bottom-color: var(--sx-edge); }
.rprow { transition: opacity 0.5s, background-color 0.15s; }
.rprow:hover { background-color: rgba(178, 198, 240, 0.06); }
.rprow[data-state="waiting"] { opacity: 0.6; }   /* was 0.42: dimmed rows stay readable */
.rprow[aria-pressed="true"] { background-color: rgba(242, 193, 78, 0.08); }
.rppick { background: rgba(178, 198, 240, 0.03); border-top-color: var(--sx-edge); }
.rpspeeds { border-color: var(--sx-edge); }
.rpspeeds button + button { border-left-color: var(--sx-edge); }
.rpspeeds button[aria-pressed="true"] { text-shadow: 0 0 10px rgba(242, 193, 78, 0.5); }
.rpclock { border-radius: 6px; }

/* a reticle on the selected object's chip in the tracking list */
.rpchip { position: relative; }
.rprow[aria-pressed="true"] .rpchip::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; pointer-events: none;
  background: repeating-conic-gradient(from -14deg, var(--accent) 0 28deg, transparent 28deg 90deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1px));
  filter: drop-shadow(0 0 2px rgba(242, 193, 78, 0.7));
}

/* ---------- data drawer ---------- */
.drawer { background: rgba(2, 3, 7, 0.62); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.drawerinner { border-radius: 6px; }
.stats { border-color: var(--sx-edge); }
.mapwrap { border: 1px solid var(--sx-edge); border-radius: 3px; }
th { background: #0c0e15; }
tbody tr.sel { box-shadow: inset 2px 0 0 var(--accent); }
tbody tr { transition: background 0.12s; }

/* ---------- tooltip ---------- */
.tooltip { border: 1px solid var(--sx-edge-hi); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.tip[aria-expanded="true"] { background: var(--accent); color: #15120a; border-color: var(--accent); }

/* ---------- motion (all of it optional) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .sx-far { animation: sx-drift 240s ease-in-out infinite alternate; }
  .sx-near { animation: sx-drift-near 160s ease-in-out infinite alternate, sx-twinkle 7s ease-in-out infinite alternate; }
  .sx-atmos { animation: sx-breathe 90s ease-in-out infinite alternate; }
  @keyframes sx-drift { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(-24px, 14px, 0); } }
  @keyframes sx-drift-near { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(-44px, 26px, 0); } }
  @keyframes sx-twinkle { 0% { opacity: 1; } 50% { opacity: 0.72; } 100% { opacity: 0.92; } }
  @keyframes sx-breathe { from { transform: translate3d(0, 0, 0); opacity: 1; } to { transform: translate3d(2%, -1.5%, 0); opacity: 0.8; } }

  /* panels arrive gently */
  @keyframes sx-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
  @keyframes sx-fade { from { opacity: 0; } to { opacity: 1; } }
  .rpsky { animation: sx-rise 0.55s var(--sx-ease) 0.05s both; }
  .rpnotice { animation: sx-rise 0.55s var(--sx-ease) 0.12s both; }
  .rppanel { animation: sx-rise 0.55s var(--sx-ease) 0.1s both; }
  .rpclock { animation: sx-rise 0.55s var(--sx-ease) 0.18s both; }
  .drawerinner { animation: sx-rise 0.45s var(--sx-ease) both; }
  .layers[open] label { animation: sx-fade 0.3s ease-out both; }
  .panel, .pane, .view-panel, [data-panel] { animation: sx-rise 0.5s var(--sx-ease) both; }

  /* the reticle turns slowly */
  .rprow[aria-pressed="true"] .rpchip::after { animation: sx-spin 8s linear infinite; }
  @keyframes sx-spin { to { transform: rotate(360deg); } }
}
/* hidden tab: everything stops */
.sx-paused *, .sx-paused *::before, .sx-paused *::after { animation-play-state: paused !important; }

/* ---------- phones ---------- */
@media (max-width: 720px) {
  .rpclock::before, .rpsky::before, .drawerinner::before { display: none; }
  .rppanel, .rpclock { border-radius: 12px 12px 0 0; border-left: 0; border-right: 0; border-bottom: 0; }
  .rpclock { border-radius: 10px 10px 0 0; }
  .rpdate { font-size: 1.08rem; }
  .sheet { border-left: 0; border-top: 1px solid var(--sx-edge-hi); box-shadow: 0 -24px 48px rgba(0, 0, 0, 0.5); }
  .timebar { padding: 0 10px; }
  :root { --sx-blur: 10px; }
}
