/* ==========================================================================
   VWSS public sky viewer
   Dark by default — deliberately a deep desaturated slate rather than #000,
   so that the sky itself is the darkest thing on the page and UI edges stay
   readable. All text/background pairs below clear WCAG AA at their size.
   ========================================================================== */

:root {
  /* surfaces: 0 is the sky (darkest), rising toward the chrome */
  --sky:        #05070c;
  --surface-0:  #0b1017;
  --surface-1:  #121926;
  --surface-2:  #1a2432;
  --surface-3:  #24303f;

  /* ink */
  --ink:        #e8eef6;   /* 14.9:1 on surface-1 */
  --ink-dim:    #a8b6c8;   /*  7.1:1 on surface-1 */
  --ink-faint:  #7d8b9d;   /*  4.6:1 on surface-1 — large / non-essential only */

  /* accent: a warm amber reads as "instrument", not "website", and stays
     distinguishable from every colour in an astronomical image */
  --accent:     #ffb454;
  --accent-ink: #1a1204;
  --accent-dim: #6a4a17;

  --edge:       #2c3949;
  --edge-soft:  #1e2836;

  --warn-bg:    #2a2113;
  --warn-edge:  #6d5220;
  --warn-ink:   #f5d9a4;

  --focus:      #7cc7ff;

  --radius:     8px;
  --radius-sm:  5px;

  --panel-w:    19.5rem;
  --topbar-h:   3.25rem;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "IBM Plex Mono",
          "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;

  --dur: 160ms;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--sky);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;             /* the sky owns the viewport */
  overscroll-behavior: none;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
  letter-spacing: -0.01em;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: #ffc978; }

h2, h3 { line-height: 1.25; }

kbd {
  font-family: var(--mono);
  font-size: 0.82em;
  padding: 0.1em 0.36em;
  border: 1px solid var(--edge);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink-dim);
  white-space: nowrap;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.08em 0.32em;
  border-radius: 4px;
}

/* --- focus -------------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}
/* Never remove focus rings; only opt the mouse out. */
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  transition: top var(--dur);
}
.skip-link:focus { top: 0.5rem; }

/* --- buttons ------------------------------------------------------------ */

.btn {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.7rem;
  min-height: 2.25rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur), border-color var(--dur);
}
.btn:hover  { background: var(--surface-3); border-color: #3b4a5d; }
.btn:active { background: var(--surface-1); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover  { background: #ffc978; border-color: #ffc978; }
.btn-primary:active { background: #eda63f; }

.btn-icon {
  padding: 0.4rem;
  min-width: 2.25rem;
  display: inline-grid;
  place-items: center;
}

/* Icons are inline SVG, not glyphs: ⛶ and ◫ are missing from most system
   font stacks and render as tofu. */
.icon {
  width: 1rem;
  height: 1rem;
  display: block;
}

/* --- top bar ------------------------------------------------------------ */

.topbar {
  position: relative;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.75rem;
  padding-left: max(0.75rem, env(safe-area-inset-left));
  padding-right: max(0.75rem, env(safe-area-inset-right));
  background: var(--surface-1);
  border-bottom: 1px solid var(--edge);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  min-width: 0;
}
.brand-mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  flex: none;
}
.brand-name {
  font-size: 0.8rem;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search {
  display: flex;
  gap: 0.4rem;
  flex: 1 1 22rem;
  max-width: 34rem;
  min-width: 0;
}
.search input {
  font: inherit;
  font-size: 0.875rem;
  flex: 1 1 auto;
  min-width: 0;
  color: var(--ink);
  background: var(--surface-0);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  min-height: 2.25rem;
}
.search input::placeholder { color: var(--ink-faint); }
.search input:hover { border-color: #3b4a5d; }

.topbar-actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
  flex: none;
}
.panel-toggle { display: none; }

/* --- search status ------------------------------------------------------ */

.search-status {
  position: absolute;
  z-index: 29;
  top: calc(var(--topbar-h) + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(90vw, 34rem);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--edge);
  box-shadow: 0 4px 18px rgb(0 0 0 / 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur);
}
.search-status.is-shown { opacity: 1; }
.search-status.is-error { background: var(--warn-bg); border-color: var(--warn-edge); color: var(--warn-ink); }

/* --- stage / sky -------------------------------------------------------- */

.stage {
  position: relative;
  height: calc(100% - var(--topbar-h));
}

/* Aladin turns this very element into its `.aladin-container` and injects a
   stylesheet that forces `position: relative` on it. That rule is appended
   inside the element, so it lands after this file and wins at equal
   specificity — which silently collapsed an `inset: 0` host to zero height.
   Size it as a plain block instead; Aladin sets no width or height itself. */
.aladin-host {
  width: 100%;
  height: 100%;
  background: var(--sky);
  font-family: var(--sans);
}
.aladin-host:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.boot {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: var(--sky);
  transition: opacity 240ms;
}
.boot[hidden] { display: none; }
.boot.is-gone { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; color: var(--ink-dim); font-size: 0.9rem; }
.boot-inner p { margin: 0.9rem 0 0; }

.spinner {
  width: 26px; height: 26px;
  margin: 0 auto;
  border: 2px solid var(--edge);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- panel -------------------------------------------------------------- */

.panel {
  position: absolute;
  z-index: 25;
  top: 0.75rem;
  right: max(0.75rem, env(safe-area-inset-right));
  width: var(--panel-w);
  max-height: calc(100% - 1.5rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: 0 10px 34px rgb(0 0 0 / 0.55);
}
@supports not (backdrop-filter: blur(1px)) {
  .panel { background: var(--surface-1); }
}
.panel[hidden] { display: none; }

.group {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--edge-soft);
}
.group:last-child { border-bottom: 0; }
.group[hidden] { display: none; }

.group-title {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.group-title label { cursor: pointer; }

.title-hint {
  float: right;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: none;
  color: var(--ink-faint);
}

.group-note {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ink-faint);
}

.group-credit p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/* --- notice ------------------------------------------------------------- */

.notice {
  margin: 0;
  padding: 0.7rem 0.9rem;
  font-size: 0.8rem;
  line-height: 1.5;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-bottom: 1px solid var(--warn-edge);
}
.notice[hidden] { display: none; }
.notice strong { color: #ffd489; }

.notice-block {
  position: absolute;
  z-index: 40;
  inset: auto 1rem 1rem 1rem;
  max-width: 40rem;
  margin-inline: auto;
  border: 1px solid var(--warn-edge);
  border-radius: var(--radius);
}

/* --- select ------------------------------------------------------------- */

.field select {
  font: inherit;
  font-size: 0.875rem;
  width: 100%;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  min-height: 2.25rem;
}

/* --- radios ------------------------------------------------------------- */

.radios { display: grid; gap: 0.15rem; }

.radio {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.32rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur);
}
.radio:hover { background: var(--surface-2); }
.radio input {
  accent-color: var(--accent);
  width: 1rem; height: 1rem;
  margin: 0;
  flex: none;
  transform: translateY(0.15rem);
}
.radio-text { min-width: 0; }
.radio-label { display: block; font-size: 0.875rem; }
.radio-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-faint);
}
.radio:has(input:checked) { background: var(--surface-2); }
.radio:has(input:checked) .radio-label { color: var(--accent); font-weight: 600; }

/* --- blend slider ------------------------------------------------------- */

.blend-ends {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-bottom: 0.3rem;
}
#blend-left  { color: var(--accent); font-weight: 600; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.5rem;
  margin: 0;
  background: transparent;
  cursor: grab;
}
input[type="range"]:active { cursor: grabbing; }
input[type="range"][disabled] { cursor: not-allowed; opacity: 0.5; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-dim), var(--surface-3));
  border: 1px solid var(--edge);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-dim), var(--surface-3));
  border: 1px solid var(--edge);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface-0);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.6);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface-0);
}

.blend-value {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-dim);
}

/* --- readout ------------------------------------------------------------ */

.readout {
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  gap: 0.18rem 0.6rem;
  margin: 0;
  font-size: 0.83rem;
}
.readout dt { color: var(--ink-faint); }
.readout dd { margin: 0; color: var(--ink); white-space: nowrap; }
.readout dd.is-stale { color: var(--ink-dim); }

/* --- about dialog ------------------------------------------------------- */

.about {
  width: min(46rem, calc(100vw - 2rem));
  max-height: min(84vh, 54rem);
  padding: 1.6rem 1.75rem 2rem;
  color: var(--ink);
  background: var(--surface-1);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgb(0 0 0 / 0.7);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.about::backdrop { background: rgb(2 4 8 / 0.75); }
.about h2 { margin: 0 0 0.5rem; font-size: 1.4rem; }
.about h3 {
  margin: 1.75rem 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}
.about p { margin: 0 0 0.7rem; max-width: 62ch; }
.about ul { margin: 0; padding-left: 1.15rem; max-width: 62ch; }
.about li { margin-bottom: 0.55rem; }

.about-close-form { float: right; margin: -0.4rem -0.5rem 0 0.5rem; }

.lede { font-size: 1.02rem; color: var(--ink-dim); }

.specs {
  display: grid;
  grid-template-columns: minmax(7.5rem, auto) 1fr;
  gap: 0.3rem 1rem;
  margin: 0;
  font-size: 0.85rem;
}
.specs dt { color: var(--ink-faint); }
.specs dd { margin: 0; }

/* A measured result that contradicts the spec sheet — worth setting apart. */
.finding {
  margin-top: 0.9rem !important;
  padding: 0.7rem 0.85rem;
  font-size: 0.875rem;
  color: var(--ink-dim);
  background: var(--surface-0);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.finding[hidden] { display: none; }

.region-card {
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.7rem;
  background: var(--surface-0);
}
.region-card h4 { margin: 0 0 0.35rem; font-size: 0.98rem; }
.region-card p  { margin: 0 0 0.5rem; font-size: 0.875rem; color: var(--ink-dim); }
.region-card .specs { font-size: 0.8rem; }

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  vertical-align: 0.12em;
  margin-left: 0.45rem;
}
.badge-pending { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-edge); }
.badge-live    { background: #10291a; color: #8fe3ac; border: 1px solid #235c37; }

.fine { font-size: 0.78rem; color: var(--ink-faint); margin-top: 1.25rem; }

/* --- copy fallback ------------------------------------------------------ */

.copy-fallback {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: calc(var(--topbar-h) + 0.75rem);
  transform: translateX(-50%);
  width: min(38rem, calc(100vw - 1.5rem));
  padding: 0.85rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgb(0 0 0 / 0.6);
}
.copy-fallback[hidden] { display: none; }
.copy-fallback label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.4rem;
}
.copy-fallback input {
  font-size: 0.8rem;
  width: 100%;
  color: var(--ink);
  background: var(--surface-0);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.55rem;
  margin-bottom: 0.6rem;
}

/* ==========================================================================
   Responsive — the panel becomes a bottom sheet under 800px
   ========================================================================== */

@media (max-width: 800px) {
  :root { --topbar-h: auto; }

  .topbar {
    flex-wrap: wrap;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    row-gap: 0.5rem;
  }
  .brand-name { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .topbar-actions { order: 2; }
  .panel-toggle { display: inline-grid; }

  body { display: flex; flex-direction: column; }
  .topbar { flex: none; }
  .stage { height: auto; flex: 1 1 0%; min-height: 0; }

  .search-status { top: 0.5rem; }

  .panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: auto;
    max-height: 62%;
    border-radius: var(--radius) var(--radius) 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .about { padding: 1.25rem 1.1rem 1.75rem; }
  .specs { grid-template-columns: 1fr; gap: 0.05rem; }
  .specs dt { margin-top: 0.5rem; }
}

@media (max-width: 400px) {
  #about-open { display: none; }   /* reachable from the About link in the credit line */
}

/* Larger hit targets where the pointer is a finger. */
@media (pointer: coarse) {
  .btn { min-height: 2.6rem; }
  .radio { padding: 0.55rem 0.5rem; }
  input[type="range"] { height: 2.25rem; }
  input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -10px; }
  input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; }
}

/* ==========================================================================
   Preferences
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .spinner {
    animation: none;
    border-top-color: var(--edge);
    border-right-color: var(--accent);
  }
  .search-status { opacity: 1; }
  .search-status:not(.is-shown) { visibility: hidden; }
}

@media (prefers-contrast: more) {
  :root {
    --ink: #ffffff;
    --ink-dim: #d7e1ec;
    --ink-faint: #b9c6d4;
    --edge: #52657c;
    --edge-soft: #3b4a5d;
  }
  .panel { background: var(--surface-1); backdrop-filter: none; }
}

@media print {
  .topbar, .panel, .boot, .search-status, .copy-fallback { display: none !important; }
}

/* A comparison layer whose coverage does not reach the current view. Distinct
   from a tile-server failure, which has its own message — this one is expected
   behaviour, so it is advisory rather than an error. */
#layer-note.layer-note-outside {
  border-left: 2px solid var(--accent);
  padding-left: 0.7em;
}
#layer-note.layer-note-outside::first-line {
  font-weight: 600;
}
