:root {
  --bg: #0b0d12;            /* deep space background for the sphere */
  --panel: #14171e;
  --panel-2: #1b1f28;
  --text: #e7ebf2;
  --muted: #9aa3b2;
  --accent: #6ea8dc;        /* lighter blue for dark UI */
  --accent-deep: #1f4e79;   /* cosmo-calc academic blue */
  --marker: #d9705f;        /* brick red, brightened for dark bg */
  --good: #6bd39a;
  --warn: #e2b93b;          /* marginal: near an FOR edge, check APT */
  --maz: #e08a52;           /* micrometeoroid avoidance zone (soft constraint) */
  --bad: #e08a7d;
  --sun: #ffd45e;
  --border: #2a2f3a;
  --rule: #cfd6e2;
  --serif: Georgia, "Times New Roman", Cambria, "Source Serif Pro", serif;
  --mono: "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

/* ---- 3D scene fills the area to the right of the panel ---------------- */
#scene {
  position: fixed;
  top: 0;
  left: 22rem;                 /* sit beside the 22rem control panel */
  width: calc(100vw - 22rem);  /* so the globe centres in that region */
  height: 100vh;
}
#scene canvas { display: block; width: 100%; height: 100%; }

/* Caption across the foot of the 3D view. Fades out for good once the user
   starts dragging, and never intercepts the gesture it is describing. */
#scene-hint {
  position: fixed;
  bottom: 1.15rem;
  left: 22rem;                 /* match #scene, so it centres under the globe */
  width: calc(100vw - 22rem);
  margin: 0;
  text-align: center;
  font-size: 0.78rem;
  font-style: italic;
  color: var(--muted);
  opacity: 0.8;
  pointer-events: none;
  transition: opacity 0.7s ease;
}
#scene-hint.dismissed { opacity: 0; }

/* ---- Overlay control + readout panel --------------------------------- */
#panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 22rem;
  max-width: 92vw;
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem 1.4rem 2.5rem;
  background: linear-gradient(180deg, rgba(16, 19, 26, 0.96), rgba(16, 19, 26, 0.9));
  backdrop-filter: blur(6px);
  border-right: 1px solid var(--border);
}

header { margin-bottom: 1.1rem; }

h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0 0 0.2rem;
}

.lede {
  margin: 0 0 0.7rem;
  color: var(--muted);
  font-style: italic;
  font-size: 0.92rem;
}

.rule {
  border: none;
  border-top: 1px solid var(--rule);
  opacity: 0.35;
  margin: 0;
}

h2 {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

a { color: var(--accent); text-decoration-thickness: 0.5px; }

/* ---- Controls -------------------------------------------------------- */
.controls-block { margin: 1.3rem 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
}

.field span {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.field span b { color: var(--text); font-weight: 600; text-transform: none; letter-spacing: 0; }

input[type="date"], input[type="number"] {
  width: 100%;
  min-width: 0;            /* allow shrinking inside the flex coord-row */
  height: 2.4rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 0 0.6rem;
  font-size: 0.95rem;
  font-family: var(--serif);
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(110, 168, 220, 0.18);
}

/* RA/Dec entry: drop the up/down spinner widget (not needed for coordinates) */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

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

.coord-row { display: flex; gap: 0.7rem; }
.coord-row .field { flex: 1 1 0; min-width: 0; }

.btn-row { display: flex; gap: 0.6rem; margin-top: 0.2rem; }

/* ---- Toggle checkboxes (classic fields / meteoroid zone) ------------- */
.check-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.check-title {
  font-size: 0.74rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}
.check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}
/* Push the checkbox's info button to the far right so its popover, which
   opens leftward, stays inside the panel. */
.check .info { margin-left: auto; }

button {
  height: 2.4rem;
  background: var(--accent-deep);
  color: #fff;
  border: 1px solid var(--accent-deep);
  border-radius: 4px;
  padding: 0 1rem;
  font-size: 0.9rem;
  font-family: var(--serif);
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 auto;
}
button:hover { background: #285f92; }
button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  flex: 0 0 auto;
}
button.ghost:hover { color: var(--text); border-color: var(--muted); }

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}

/* ---- Readout tables -------------------------------------------------- */
.readout-block { margin: 1.4rem 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

caption {
  caption-side: top;
  text-align: left;
  font-size: 0.74rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0 0.4rem;
}

td {
  padding: 0.4rem 0.1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: baseline;
  font-size: 0.92rem;
}
tbody tr:first-child td { border-top: 1px solid var(--rule); }
tbody tr:last-child td { border-bottom: 1px solid var(--rule); }

td.label { color: var(--muted); }
td.value { text-align: right; white-space: nowrap; font-weight: 600; }

.unit { color: var(--muted); font-weight: 400; font-size: 0.85em; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.maz { color: var(--maz); }
.bad { color: var(--bad); }

/* ---- Inline info button + hover popover ------------------------------ */
.info {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05em;
  height: 1.05em;
  margin-left: 0.4em;
  border: 1px solid var(--muted);
  border-radius: 50%;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.72em;
  line-height: 1;
  cursor: help;
  vertical-align: middle;
  user-select: none;
}
.info:hover, .info:focus { color: var(--text); border-color: var(--text); outline: none; }
.info-pop {
  position: absolute;
  bottom: calc(100% + 0.4rem);
  right: 0.3rem;
  z-index: 20;
  width: 15rem;
  max-width: 70vw;
  padding: 0.5rem 0.65rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  color: var(--muted);
  font-size: 0.8rem;
  font-style: normal;
  font-weight: 400;
  white-space: normal;   /* override td.value's nowrap so text wraps in the box */
  line-height: 1.45;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.info:hover .info-pop, .info:focus .info-pop { opacity: 1; visibility: visible; }

/* ---- Visibility windows ---------------------------------------------- */
.windows { margin-top: 0.8rem; }
.win-title {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.win {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 0.22rem 0;
  border-bottom: 1px dotted var(--border);
}
.win-none { font-size: 0.88rem; color: var(--bad); font-style: italic; }

/* ---- Visibility timeline bar ---------------------------------------- */
.win-bar {
  position: relative;
  height: 16px;
  margin: 0.1rem 0 0.15rem;
  background: #3a4150;            /* not observable (grey) */
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
}
.win-hover {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--text);
  pointer-events: none;
  display: none;
}

/* ---- V3PA / NIRSpec APA line chart ---------------------------------- */
.pa-chart { width: 100%; height: auto; display: block; margin: 0.15rem 0 0.1rem; }
#pac-hit { cursor: pointer; }
.pac-grid { stroke: var(--border); stroke-width: 0.5; }
.pac-year { stroke: var(--muted); stroke-width: 0.5; stroke-dasharray: 2 2; }
.pac-now { stroke: #ff7a1a; stroke-width: 1; vector-effect: non-scaling-stroke; }
.pac-xtick { stroke: var(--muted); stroke-width: 0.5; }
.pac-ylab { fill: var(--muted); font-size: 8.5px; text-anchor: end; }
.pac-xlab { fill: var(--muted); font-size: 8.5px; text-anchor: end; }
.pac-v3 { fill: none; stroke: var(--accent); stroke-width: 1.3; vector-effect: non-scaling-stroke; }
.pac-apa { fill: none; stroke: var(--good); stroke-width: 1.3; vector-effect: non-scaling-stroke; }
.pac-maz { stroke-dasharray: 3 2.5; }  /* meteoroid unsafe zone: dashed */
.pac-marg { fill: none; stroke: #6a7382; stroke-width: 1.1; vector-effect: non-scaling-stroke; }  /* marginal: grey, treated unavailable */
.pac-vline { stroke: var(--text); stroke-width: 0.5; opacity: 0.6; vector-effect: non-scaling-stroke; pointer-events: none; }
.pac-dot { pointer-events: none; stroke: var(--panel); stroke-width: 0.6; }
.pac-dot-v3 { fill: var(--accent); }
.pac-dot-apa { fill: var(--good); }
.pac-legend { display: flex; gap: 1rem; font-size: 0.72rem; color: var(--muted); margin-top: 0.3rem; }
.pac-key::before {
  content: ""; display: inline-block; width: 11px; height: 2px;
  margin-right: 5px; vertical-align: middle;
}
.pac-key-v3::before { background: var(--accent); }
.pac-key-apa::before { background: var(--good); }
.win-seg {
  position: absolute; top: 0; bottom: 0;
  background: var(--good);         /* observable (green) */
}
.win-seg.marginal {
  /* near an FOR edge — treated unavailable: grey base + orange (warn) stripes */
  background:
    repeating-linear-gradient(45deg, rgba(226, 185, 59, 0.9) 0 2px, transparent 2px 6px),
    #3a4150;
}
.win-seg.maz {
  /* meteoroid unsafe zone: striped shading over the green (soft constraint) */
  background: repeating-linear-gradient(
    45deg,
    rgba(16, 34, 24, 0.35) 0 2px,
    transparent 2px 6px
  );
}
.win-tick {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--text); opacity: 0.55;
}
.win-yeardiv {
  position: absolute; top: 0; bottom: 0; width: 0;
  border-left: 1px dotted var(--muted);
}
.win-now {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--marker);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.win-axis {
  position: relative; height: 1.1em;
  font-size: 0.68rem; color: var(--muted);
  margin-bottom: 0.5rem;
}
.win-axlab { position: absolute; white-space: nowrap; }
.win-axlab-c { transform: translateX(-50%); }

/* ---- Footer ---------------------------------------------------------- */
footer {
  margin-top: 1.6rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}
footer a { color: var(--accent); }

/* ---- Boot / error notice --------------------------------------------- */
/* The [hidden] rule must win over the display below, or the `hidden`
   attribute is ignored and this overlay covers the app permanently. */
#boot-msg[hidden] { display: none; }
#boot-msg {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.boot-card {
  max-width: 30rem;
  padding: 1.6rem 1.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.boot-card h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.1rem; }
.boot-card p { color: var(--muted); font-size: 0.92rem; }
.boot-card code { font-family: var(--mono); color: var(--sun); }
.boot-card pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.7rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--text);
  overflow-x: auto;
}

/* ---- Floating cursor tooltip ----------------------------------------- */
#tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  max-width: 17rem;
  background: rgba(11, 13, 18, 0.94);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.4rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text);
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
#tooltip .unit { color: #b9c2d0; }
#tooltip .warn { color: var(--warn); }
#tooltip .maz { color: var(--maz); }
#tooltip .bad { color: var(--bad); }

/* ---- Small screens: let the panel share space ------------------------ */
@media (max-width: 640px) {
  body { overflow: auto; }
  #panel {
    position: relative;
    width: 100%;
    height: auto;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #scene { position: fixed; left: 0; width: 100vw; z-index: -1; }
  #scene-hint { display: none; } /* the globe sits behind the panel here */
}
