:root {
  --bg: #0b0e14;
  --panel: #131824;
  --line: #262d3f;
  --text: #e6e9f2;
  --muted: #8d97b0;
  --accent: #6ea8ff;
  --danger: #ff7b7b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: grid;
  grid-template-columns: 340px 1fr;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

h1 { margin: 0; font-size: 18px; letter-spacing: 0.01em; }
.step { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="text"], input:not([type]), select {
  width: 100%;
  padding: 9px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

#coord-form input { margin-bottom: 12px; }

button {
  padding: 9px 14px;
  background: var(--accent);
  color: #071225;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
button.secondary:hover { border-color: var(--accent); }
#coord-form button { width: 100%; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
}

.demo-banner {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #c9a227;
  border-radius: 6px;
  background: #3a2f0b;
  color: #ffe08a;
  font-size: 13px;
}
.demo-banner[hidden] { display: none; }
.demo-banner code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

.note { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.note.error { color: var(--danger); }

.chip {
  padding: 3px 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#obs-summary { margin-top: 8px; }
#obs-summary:empty, #obs-list:empty { display: none; }

.obs-list {
  margin-top: 8px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.obs-list table { width: 100%; border-collapse: collapse; font-size: 12px; }
.obs-list th, .obs-list td { padding: 4px 8px; text-align: left; }
.obs-list th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--muted);
  font-weight: 500;
}
.obs-list tr + tr td { border-top: 1px solid var(--line); }
.obs-list td { font-variant-numeric: tabular-nums; }

.error { margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.error[hidden] { display: none; }

.readout {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.readout span { display: inline-block; width: 32px; color: var(--muted); }
.readout code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

#stage { position: relative; height: 100vh; min-width: 0; }
#aladin-lite-div { position: absolute; inset: 0; }

.tabs { display: flex; gap: 6px; }
.tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.tab.active { background: var(--accent); color: #071225; border-color: var(--accent); }

/* ---- blink view: sits on top of the map ---- */
#blink-view {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 20px;
  background: var(--bg);
  overflow-y: auto;
}
#blink-view[hidden] { display: none; }
#blink-view .note { margin: 0; }

.blink-bar, .blink-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}
.blink-bar label, .blink-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}
.blink-bar select, .blink-controls select { width: auto; }
.blink-controls input[type="range"] { width: 120px; }
#b-frame { flex: 1 1 160px; min-width: 120px; }
#b-speed-out { min-width: 44px; font-variant-numeric: tabular-nums; }
button:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.blink-stage {
  display: flex;
  align-items: center;
  justify-content: center;
}
/* v0.6.6: nothing in the SPHEREx tab is squeezed when the Target motion panel is open;
   the tab scrolls instead (the image used to be overlapped by the text under it). */
#blink-view > * { flex-shrink: 0; }
/* The frame and its overlay share one square box, so drawn marks line up with pixels. */
.frame-box {
  position: relative;
  /* As large as the screen height allows (at least 420 px), never wider than the tab. */
  width: min(100%, max(420px, calc(100vh - 330px)));
  max-width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  background: #000;
}
.frame-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#b-canvas { image-rendering: pixelated; }   /* show real pixels, do not smooth them */
#b-overlay { pointer-events: none; }
#b-flags { image-rendering: pixelated; pointer-events: none; }
#b-flags[hidden] { display: none; }
.frame-box[hidden], #b-empty[hidden], .legend[hidden] { display: none; }
.legend { display: flex; align-items: center; gap: 8px; }
.ring-key {
  width: 14px; height: 14px; flex: none;
  border: 2px dashed #ffb547; border-radius: 50%;
}

/* ---- target motion panel ---- */
.motion {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}
.motion > summary {
  padding: 8px 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.motion-body { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px; }
.motion-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.motion-row > label {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}
.motion-row #t-name { flex: 1 1 180px; width: auto; min-width: 0; }
.motion-row input.num { width: 110px; font-variant-numeric: tabular-nums; }
.choice { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.choice input { accent-color: var(--accent); }
.muted { color: var(--muted); }
.motion .note { margin: 0; }
button.small { padding: 5px 9px; font-size: 12px; font-weight: 500; }
button.attention { box-shadow: 0 0 0 3px rgba(110, 168, 255, 0.45); }
.readout-line {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  min-height: 1.4em;
}

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto 80vh; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  #stage { height: 80vh; }
}

/* ---- v0.5: view bar, six-detector panels ---- */
.view-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}
.view-bar label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}
.view-bar select { width: auto; max-width: 100%; }
select:disabled { opacity: 0.5; }
#b-single[hidden], #b-panels[hidden], #b-blink-controls[hidden] { display: none; }
#b-single { display: flex; flex-direction: column; gap: 10px; flex: 0 0 auto; }
#b-single > * { flex-shrink: 0; }   /* v0.6.6: never squeeze the image; the tab scrolls instead */
#b-blink-controls { display: contents; }

.panels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.panel-cell { margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.panel-box {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 1px solid var(--line);
  background: #000;
}
.panel-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.panel-box.panel-empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; background: var(--panel);
}
.panel-open {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background: transparent; border: 0; padding: 0; cursor: zoom-in;
}
.panel-open:hover { box-shadow: inset 0 0 0 2px var(--accent); filter: none; }
.panel-cell figcaption { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.panel-cell figcaption strong { color: var(--text); font-weight: 600; }
@media (max-width: 760px) {
  .panels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- v0.6: known stars (Gaia, WISE) ---- */
.cat-bar .bar-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.cat-key { display: inline-block; width: 12px; height: 12px; border: 2px solid; flex: none; }
.cat-key.gaia { border-color: #5be37d; border-radius: 50%; }
.cat-key.wise { border-color: #c792ff; }
.small-note { font-size: 12px; flex: 1 1 260px; min-width: 0; }
#b-box { cursor: crosshair; }
.src-info { padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); overflow-wrap: anywhere; }
.src-info[hidden] { display: none; }
.panel-box canvas.panel-overlay { image-rendering: auto; pointer-events: none; }

/* ---- v0.6.6: loading progress, measure at target ---- */
.progress { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.progress[hidden] { display: none; }
.progress-track { position: relative; display: flex; flex: 1 1 240px; max-width: 420px; height: 10px;
  border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-ok { background: var(--accent); transition: width 0.3s ease;
  background-image: linear-gradient(45deg, rgba(255,255,255,0.18) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.18) 50%, rgba(255,255,255,0.18) 75%, transparent 75%);
  background-size: 16px 16px; animation: progress-stripes 1s linear infinite; }
.progress-bad { background: #ff6b6b; transition: width 0.3s ease; }
.progress-text { font-size: 13px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.progress-text.error { color: #ff9b9b; }
@keyframes progress-stripes { from { background-position: 0 0; } to { background-position: 16px 0; } }
@media (prefers-reduced-motion: reduce) { .progress-ok { animation: none; } }
.measure { overflow-wrap: anywhere; }
.measure[hidden] { display: none; }
.sig { display: inline-block; padding: 1px 8px; border-radius: 999px; font-variant-numeric: tabular-nums;
  background: rgba(150, 160, 180, 0.18); color: var(--text); }
.sig.detected { background: rgba(91, 227, 125, 0.18); color: #7ef0a0; }
.sig.tentative { background: rgba(255, 181, 71, 0.18); color: #ffc66e; }
.sig.not-detected { background: rgba(150, 160, 180, 0.15); color: var(--muted); }
.sig.small { font-size: 11px; padding: 0 6px; margin-top: 2px; align-self: flex-start; }

/* ---- v0.6.7: blends ---- */
.measure { display: flex; flex-direction: column; gap: 6px; }
.measure p { margin: 0; }
.sig.blended { background: rgba(255, 181, 71, 0.2); color: #ffc66e; }

/* ---- v0.6.8: pre-fill page ---- */
.prefill { position: fixed; inset: 0; z-index: 50; overflow-y: auto; background: rgba(8, 11, 18, 0.92);
  display: flex; justify-content: center; padding: 32px 16px; }
.prefill-card { width: min(900px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 24px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); height: fit-content; }
.prefill-card h2 { margin: 0; }
.prefill-options, .prefill-buttons { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; }
.secondary-link { color: var(--muted); }
.prefill-log { margin: 0; padding-left: 20px; max-height: 320px; overflow-y: auto; font-size: 12px; color: var(--muted); }
.prefill-log .error { color: #ff9b9b; }

/* ---- v0.7: spectrum and light curve ---- */
.spec { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel); }
.spec[hidden] { display: none; }
.spec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.spec-title { margin: 0; font-size: 15px; }
.spec-tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.spec-tab { border: 0; border-radius: 0; background: transparent; color: var(--muted); padding: 5px 12px; }
.spec-tab.active { background: var(--accent); color: #071225; }
.spec-chart { width: 100%; min-height: 0; }
.spec-chart svg { display: block; max-width: 100%; }
.chart-grid line { stroke: rgba(150, 165, 190, 0.14); stroke-width: 1; }
.chart-frame { fill: none; stroke: rgba(150, 165, 190, 0.35); }
.chart-zero { stroke: rgba(230, 233, 242, 0.45); stroke-dasharray: 4 4; }
.chart-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-label { fill: var(--muted); font-size: 12px; }
.chart-band { fill: var(--muted); font-size: 10px; }
.chart-binned { fill: none; stroke: #f2f4fa; stroke-width: 2; stroke-linejoin: round; opacity: 0.9; }
.chart-point { cursor: help; }
.chart-point:focus { outline: none; }
.chart-point:focus circle, .chart-point:hover circle { stroke-width: 3; }

/* ---- v0.8: flags and frame details ---- */
.flag-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; font-size: 13px; color: var(--muted); }
.flag-legend[hidden] { display: none; }
.flag-legend label { display: inline-flex; align-items: center; gap: 6px; margin: 0; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }
.flag-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.flag-legend .flag-bits { flex-basis: 100%; font-size: 12px; overflow-wrap: anywhere; }
.frame-meta { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; background: var(--panel); }
.frame-meta[hidden] { display: none; }
.frame-meta summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.frame-meta dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0 4px; font-size: 13px; }
.frame-meta dt { color: var(--muted); }
.frame-meta dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* v0.9 embed mode: only the image view */
body.embed > aside.panel, body.embed .tabs, body.embed #map-view { display: none !important; }
body.embed { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.irsa-links a { white-space: nowrap; }

/* v1.0 polish */
:focus-visible { outline: 2px solid #6aa8ff; outline-offset: 2px; }
.help { margin: 8px 0; font-size: 0.9em; }
.help summary { cursor: pointer; font-weight: 600; }
.help ol { padding-left: 1.2em; margin: 6px 0; }
.help li { margin: 4px 0; }
@media (max-width: 700px) {
  .blink-bar, .blink-controls { flex-wrap: wrap; }
  #b-canvas, .frame-box { max-width: 100%; }
  select, input { max-width: 100%; }
  label:has(> #b-detector) { display: flex; min-width: 0; max-width: 100%; }
  #b-detector { min-width: 0; flex: 1 1 auto; }
}

/* v1.0.7.1: percentage loaded, beside the bar */
.progress-pct { min-width: 3.2em; text-align: right; font-size: 15px; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums; }

/* v1.1: data-source status badge */
.data-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; font-size: 12px; }
.data-status[hidden] { display: none; }
.data-status-title { color: var(--muted, #9aa4b2); text-transform: uppercase; letter-spacing: 0.06em; font-size: 11px; }
.data-status-list { display: flex; flex-wrap: wrap; gap: 6px; }
.ds { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line, #2a3140); color: var(--text, #e6e9ef); cursor: default; }
.ds::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #8a93a3; }
.ds-ok::before { background: #4cd27a; }
.ds-slow::before { background: #f2c94c; }
.ds-down::before { background: #ff6b6b; }

.chart-reference { fill: none; stroke: #c9cfdc; stroke-width: 1.4; stroke-dasharray: 5 4; opacity: 0.85; }

.cube-note:empty { display: none; }
.cube-note.ok { color: #c9cfdc; border-left: 3px dashed #c9cfdc; padding-left: 8px; }
.cube-note.error { color: #ff9b9b; }

/* v1.2: moving-object finder, explainer, tour */
.mv-panel { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 79, 216, 0.04); }
.mv-panel[hidden] { display: none; }
.mv-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mv-list { margin: 8px 0 0; padding-left: 1.3em; font-size: 13px; }
.mv-list li { margin: 3px 0; font-variant-numeric: tabular-nums; }
.mv-list li.candidate { color: #ff8be6; font-weight: 600; }
.mv-list li.known { color: var(--muted); }
.mv-report { margin-top: 10px; display: grid; gap: 6px; }
.mv-report[hidden] { display: none; }
.mv-report textarea { width: 100%; box-sizing: border-box; background: rgba(255,255,255,0.03); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; resize: vertical; }
.mv-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.explain-bar { margin-top: 6px; }
.explain { max-width: 70ch; line-height: 1.5; border-left: 3px solid var(--accent); padding-left: 10px; }
.tour-start { width: 100%; margin: 6px 0; }
.tour { position: fixed; z-index: 1000; right: max(16px, env(safe-area-inset-right, 0px)); bottom: 16px; width: min(380px, calc(100vw - 32px));
  background: #141a29; color: var(--text); border: 1px solid var(--accent); border-radius: 12px; padding: 14px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); }
.tour-title { margin: 0 0 6px; font-size: 15px; }
.tour-text { margin: 0 0 12px; font-size: 13.5px; line-height: 1.5; }
.tour-actions { display: flex; gap: 8px; justify-content: flex-end; }
.tour-lit { outline: 3px solid var(--accent) !important; outline-offset: 4px; border-radius: 8px; transition: outline-color 0.2s; }

/* v1.2.1: headline result box (period / spectrum check) and mover key */
.spec-highlight { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 4px 14px; margin: 10px 0;
  padding: 12px 16px; border-radius: 10px; border: 1px solid var(--accent); background: rgba(110, 168, 255, 0.08); }
.spec-highlight[hidden] { display: none; }
.hl-label { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }
.hl-value { font-size: 24px; line-height: 1.2; color: var(--text); font-variant-numeric: tabular-nums; }
.hl-extra { font-size: 13px; color: var(--muted); align-self: center; }
.hl-detail { grid-column: 1 / -1; font-size: 13px; color: var(--text); opacity: 0.85; line-height: 1.45; }
.mv-list li.known .mv-key { color: #ffffff; font-weight: 700; }
.mv-list li.candidate .mv-key { color: #ff4fd8; font-weight: 700; }
.mv-list li.known { color: var(--text); }
