/* Stellar Atlas — a printed star atlas, reversed onto the night.
   Ink on night; one rose (H-alpha) for what is selected, one teal (O III)
   for what responds to you. Spectral names places, Instrument Sans reads data. */

:root {
  --night: #060a12;
  --ink: #e8e3d6;
  --ink-2: #aab0bd;
  --ink-3: #737c8e;
  --grid: #3a5a7c;
  --rule: rgba(232, 227, 214, 0.10);
  --rule-2: rgba(232, 227, 214, 0.18);
  --panel: rgba(8, 13, 23, 0.80);
  --panel-solid: #0b111d;
  --halpha: #ef8a80;
  --oiii: #79d3c4;
  --oiii-dim: rgba(121, 211, 196, 0.14);
  --serif: "Spectral", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --gutter: 20px;
  --radius-s: 6px;
  --radius-l: 12px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--night); color: var(--ink);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
[hidden] { display: none !important; }
kbd {
  font: 500 11px/1 var(--sans); color: var(--ink-2);
  border: 1px solid var(--rule-2); border-radius: 4px; padding: 2px 5px;
}
:focus-visible { outline: 2px solid var(--oiii); outline-offset: 2px; border-radius: 4px; }

#view {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none; cursor: grab;
}
#view:active { cursor: grabbing; }

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

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 24px;
  padding: max(16px, env(safe-area-inset-top)) var(--gutter) 0;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar-place { display: flex; align-items: baseline; gap: 22px; min-width: 0; }

.brand {
  font: italic 400 21px/1 var(--serif); letter-spacing: 0.01em;
  color: var(--ink); text-decoration: none; white-space: nowrap;
  padding: 8px 0;
}

.trail { display: flex; flex-wrap: wrap; align-items: baseline; list-style: none; gap: 2px 0; min-width: 0; }
.trail li { display: flex; align-items: baseline; font-size: 13px; }
.trail li + li::before { content: "›"; color: var(--ink-3); margin: 0 8px; }
.trail button {
  color: var(--ink-2); padding: 2px 0;
  border-bottom: 1px solid transparent; transition: color 0.15s, border-color 0.15s;
}
.trail button:hover { color: var(--ink); border-bottom-color: var(--rule-2); }
.trail [aria-current] { color: var(--ink); font-weight: 500; }

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

.search { position: relative; width: min(340px, 34vw); flex-shrink: 0; }
.search-icon {
  position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%);
  fill: none; stroke: var(--ink-3); stroke-width: 1.6; stroke-linecap: round; pointer-events: none; z-index: 1;
}
#search {
  width: 100%; height: 38px; padding: 0 36px 0 36px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-s);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  outline: none; transition: border-color 0.15s, background 0.15s;
}
#search::placeholder { color: var(--ink-3); }
#search::-webkit-search-cancel-button { display: none; }
#search:focus { border-color: rgba(121, 211, 196, 0.5); background: var(--panel-solid); }
.search-key { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }
#search:focus ~ .search-key { opacity: 0; }

.results {
  position: absolute; top: 44px; left: 0; right: 0; list-style: none;
  background: var(--panel-solid); border: 1px solid var(--rule-2); border-radius: var(--radius-s);
  padding: 6px; max-height: min(420px, 60vh); overflow-y: auto;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}
.results-head { font-size: 12px; color: var(--ink-3); padding: 6px 10px 4px; }
.results-empty { font-size: 13px; color: var(--ink-2); padding: 10px; }
.result {
  display: grid; grid-template-columns: 14px 1fr auto; align-items: baseline; gap: 10px;
  padding: 8px 10px; border-radius: 4px; cursor: pointer;
}
.result.is-active { background: var(--oiii-dim); }
.result-name { font: 400 15px/1.25 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.result-glyph { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--ink-2); align-self: center; }
.glyph-planet, .glyph-moon { border-color: #c9b48f; }
.glyph-sun { background: #f5d48a; border-color: #f5d48a; }
.glyph-star { background: var(--ink); border-color: var(--ink); width: 6px; height: 6px; margin-left: 1px; }
.glyph-system, .glyph-exoPlanet { border-color: var(--oiii); }
.glyph-dso, .glyph-tracer { border-color: var(--halpha); border-style: dotted; }
.glyph-region, .glyph-place { border-radius: 2px; border-color: #8fb0d8; transform: rotate(45deg); }
.glyph-craft { border-color: #e0b872; border-radius: 1px; transform: rotate(45deg) scale(0.9); }
.glyph-blackhole { background: #05080f; border-color: #c08cff; box-shadow: 0 0 0 1.5px rgba(192, 140, 255, 0.25); }
.glyph-extgal { border-color: #f0dcae; border-radius: 50% / 35%; width: 11px; transform: rotate(-30deg); }

/* ---------------- map labels ---------------- */

#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.label {
  position: absolute; top: 0; left: 0; white-space: nowrap;
  font-size: 12px; line-height: 1; color: rgba(232, 227, 214, 0.86);
  padding: 2px 4px 2px 12px; margin: -7px 0 0 -6px;
  text-shadow: 0 0 4px var(--night), 0 0 10px rgba(6, 10, 18, 0.9);
  will-change: transform;
}
.label::before {
  content: ""; position: absolute; left: 2px; top: 50%; width: 5px; height: 5px; margin-top: -3px;
  border-radius: 50%; border: 1px solid currentColor; opacity: 0.7;
}
.label.is-link { pointer-events: auto; cursor: pointer; }
.label.is-link:hover { color: var(--oiii); }
.label-home { color: var(--ink); font-weight: 600; }
.label-planet { font-size: 12.5px; color: var(--ink); }
.label-moon, .label-star, .label-minor { font-size: 11.5px; color: var(--ink-2); }
.label-bh { font-size: 11.5px; color: rgba(200, 160, 255, 0.92); }
.label-craft { font-size: 11.5px; color: rgba(224, 184, 114, 0.95); }
.label-craft::before { border-radius: 1px; transform: rotate(45deg) scale(0.85); }
.label-exo { font-size: 11.5px; color: rgba(121, 211, 196, 0.85); }
.label-dso, .label-poi { font: italic 400 13.5px/1 var(--serif); color: rgba(244, 196, 186, 0.9); }
.label-axis { font-size: 11px; color: rgba(143, 176, 216, 0.6); font-variant-numeric: tabular-nums; padding-left: 4px; }
.label-axis::before { display: none; }
.label-region {
  font: italic 400 16px/1 var(--serif); letter-spacing: 0.06em;
  color: rgba(170, 198, 236, 0.78); padding: 2px 6px; margin: -8px 0 0 0;
  translate: -50% 0;
}
.label-region::before { display: none; }

/* ---------------- reticle ---------------- */

#reticle {
  --size: 30px;
  position: fixed; top: 0; left: 0; z-index: 6; pointer-events: none;
  width: 0; height: 0;
}
#reticle::before {
  content: ""; position: absolute;
  width: var(--size); height: var(--size); left: calc(var(--size) / -2); top: calc(var(--size) / -2);
  border-radius: 50%;
  border: 1.5px solid var(--halpha);
  -webkit-mask: conic-gradient(#000 0 30deg, transparent 30deg 60deg, #000 60deg 120deg, transparent 120deg 150deg,
    #000 150deg 210deg, transparent 210deg 240deg, #000 240deg 300deg, transparent 300deg 330deg, #000 330deg);
          mask: conic-gradient(#000 0 30deg, transparent 30deg 60deg, #000 60deg 120deg, transparent 120deg 150deg,
    #000 150deg 210deg, transparent 210deg 240deg, #000 240deg 300deg, transparent 300deg 330deg, #000 330deg);
  transition: width 0.25s var(--ease), height 0.25s var(--ease), left 0.25s var(--ease), top 0.25s var(--ease);
}
#reticle-name {
  position: absolute; left: 0; top: calc(var(--size) / 2 + 6px); translate: -50% 0;
  font-size: 12px; font-weight: 500; color: var(--halpha); white-space: nowrap;
  text-shadow: 0 0 6px var(--night);
}

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

.panel {
  position: fixed; z-index: 15;
  top: 72px; right: var(--gutter); width: 340px;
  max-height: calc(100% - 72px - 84px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-l);
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  padding: 20px 22px 18px;
  opacity: 0; transform: translateX(12px);
  transition: opacity 0.25s var(--ease), transform 0.3s var(--ease);
  scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent;
}
.panel.is-open { opacity: 1; transform: none; }
.panel-close { position: absolute; top: 12px; right: 12px; }
.panel-kind { font-size: 13px; color: var(--halpha); padding-right: 36px; }
.panel-title {
  font: 400 32px/1.08 var(--serif); letter-spacing: -0.005em;
  margin: 4px 36px 0 0; overflow-wrap: anywhere;
}
.panel-lede { font: italic 400 15px/1.5 var(--serif); color: var(--ink-2); margin-top: 10px; max-width: 34em; }

.facts { margin-top: 16px; border-top: 1px solid var(--rule); }
.fact {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid var(--rule);
}
.fact dt { font-size: 12.5px; color: var(--ink-3); }
.fact dd { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }

.panel-list { margin-top: 18px; }
.panel-list h3 { font: italic 400 15px/1.2 var(--serif); color: var(--ink-2); margin-bottom: 6px; }
.panel-list ul { list-style: none; }
.list-row {
  width: 100%; display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 6px 8px; margin: 0 -8px; width: calc(100% + 16px); border-radius: 4px;
  font-size: 13.5px; text-align: left;
}
button.list-row:hover { background: var(--oiii-dim); color: var(--oiii); }
.list-row.is-static { color: var(--ink-2); }
.list-sub { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }

.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.panel-actions:empty { display: none; }
.btn {
  height: 34px; padding: 0 14px; border-radius: var(--radius-s);
  border: 1px solid var(--rule-2); font-size: 13px; font-weight: 500; color: var(--ink);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: rgba(121, 211, 196, 0.6); color: var(--oiii); }
.btn-primary { background: var(--oiii); border-color: var(--oiii); color: #06201c; }
.btn-primary:hover { background: #95e0d3; color: #06201c; }
.btn[aria-pressed="true"] { background: var(--oiii-dim); border-color: rgba(121, 211, 196, 0.6); color: var(--oiii); }
.btn-details { display: none; }
.btn[aria-pressed="true"]::before { content: "● "; font-size: 9px; vertical-align: 2px; }

/* ---------------- bottom bar ---------------- */

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 16px;
  padding: 0 var(--gutter) max(16px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.bottombar > * { pointer-events: auto; }

.coords {
  display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2);
  font-variant-numeric: tabular-nums; pointer-events: none; padding-bottom: 8px;
}
.coord-k { color: var(--ink-3); }

.timebar {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-l);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 6px 8px 6px 16px;
}
.clock { display: flex; flex-direction: column; line-height: 1.15; min-width: 98px; }
.clock-date { font: 400 15px/1.15 var(--serif); }
.clock-time { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.time-buttons { display: flex; align-items: center; gap: 2px; }
.clock-rate { font-size: 12px; color: var(--oiii); min-width: 124px; padding-right: 8px; }

.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: var(--radius-s);
  color: var(--ink-2); transition: background 0.15s, color 0.15s;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover:not(:disabled) { background: rgba(232, 227, 214, 0.07); color: var(--ink); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
#time-play .i-play { display: none; }
#time-play.is-paused .i-play { display: block; fill: currentColor; }
#time-play.is-paused .i-pause { display: none; }
#time-play.is-paused { color: var(--oiii); }
.text-btn {
  height: 28px; padding: 0 10px; margin-left: 4px; border-radius: var(--radius-s);
  border: 1px solid var(--rule-2); font-size: 12px; color: var(--ink-2);
}
.text-btn:hover:not(:disabled) { color: var(--ink); border-color: var(--ink-3); }
.text-btn:disabled { opacity: 0.35; cursor: default; }
.clock-rate.is-live::before {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 7px; vertical-align: 1px;
  border-radius: 50%; background: var(--oiii); box-shadow: 0 0 6px var(--oiii);
}

.tools { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.scale { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; margin-right: 12px; }
.scale-text { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.scale-bar {
  display: block; height: 6px; min-width: 2px;
  border: 1px solid var(--ink-2); border-top: 0;
}

.layers { position: relative; }
.layers-menu {
  position: absolute; right: 0; bottom: 44px; width: 220px;
  background: var(--panel-solid); border: 1px solid var(--rule-2); border-radius: var(--radius-s);
  padding: 10px 12px; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}
.layers-title { font: italic 400 14px/1.2 var(--serif); color: var(--ink-2); margin-bottom: 6px; }
.layers-menu label { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; cursor: pointer; }
.layers-menu input { accent-color: var(--oiii); width: 15px; height: 15px; }

/* ---------------- hint ---------------- */

.hint {
  position: fixed; left: 50%; bottom: 92px; z-index: 18; translate: -50% 8px;
  max-width: min(520px, calc(100% - 2 * var(--gutter)));
  font: italic 400 15px/1.45 var(--serif); color: var(--ink); text-align: center;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-l);
  padding: 10px 18px; opacity: 0; pointer-events: none;
  transition: opacity 0.4s var(--ease), translate 0.4s var(--ease);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.hint.is-shown { opacity: 1; translate: -50% 0; }
.hint kbd { font-style: normal; }

/* ---------------- help ---------------- */

.help {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(3, 5, 10, 0.6); padding: var(--gutter);
}
.help-sheet {
  position: relative; width: min(880px, 100%); max-height: 100%; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--rule-2); border-radius: var(--radius-l);
  padding: 30px 34px 32px;
}
.help-close { position: absolute; top: 14px; right: 14px; }
.help h2 { font: italic 400 34px/1.1 var(--serif); }
.help-intro { font: 400 17px/1.5 var(--serif); color: var(--ink-2); margin-top: 8px; max-width: 36em; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 34px; margin-top: 26px; }
.help h3 { font: italic 400 17px/1.2 var(--serif); margin-bottom: 10px; color: var(--ink); }
.keys > div { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.keys dt { color: var(--ink-2); }
.sources { list-style: none; }
.sources li { font-size: 13.5px; line-height: 1.55; color: var(--ink-2); margin-bottom: 10px; max-width: 40em; }
.sources b { color: var(--ink); font-weight: 600; }
.help-note { font: italic 400 14px/1.5 var(--serif); color: var(--ink-3); margin-top: 6px; }

/* ---------------- loading ---------------- */

.loading {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 55%, #0c1424 0%, var(--night) 60%);
  transition: opacity 0.7s ease;
}
.loading.is-done { opacity: 0; pointer-events: none; }
.loading-title { font: italic 400 40px/1 var(--serif); letter-spacing: 0.01em; }
.loading-track { width: 220px; height: 1px; background: var(--rule-2); overflow: hidden; }
.loading-fill { height: 100%; width: 0; background: var(--ink); transition: width 0.3s var(--ease); }
.loading-stage { font-size: 12.5px; color: var(--ink-3); min-height: 1.4em; }
.loading.is-error .loading-stage { color: var(--halpha); max-width: 32em; text-align: center; padding: 0 var(--gutter); }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; z-index: 60; background: var(--night); font: italic 18px var(--serif); }

/* ---------------- narrow screens ---------------- */

@media (max-width: 760px) {
  :root { --gutter: 14px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .topbar-place { gap: 14px; flex-wrap: wrap; }
  .brand { padding: 4px 0; font-size: 19px; }
  .trail li { font-size: 12px; }
  .search { width: 100%; }
  .search-key { display: none; }

  .panel {
    top: auto; bottom: 0; left: 0; right: 0; width: auto;
    max-height: 48%; border-radius: var(--radius-l) var(--radius-l) 0 0;
    border-bottom: 0; padding: 16px var(--gutter) max(18px, env(safe-area-inset-bottom));
    transform: translateY(16px); background: var(--panel-solid);
  }
  .panel-title { font-size: 26px; }
  .panel:not(.is-expanded) .facts, .panel:not(.is-expanded) .panel-list { display: none; }
  .panel:not(.is-expanded) .panel-actions { margin-top: 12px; }
  .btn-details { display: inline-block; margin-left: auto; }
  .panel-lede { font-size: 14px; }

  .bottombar { grid-template-columns: 1fr auto; }
  .has-panel .bottombar, .has-panel .hint { display: none; }
  .coords { display: none; }
  .timebar { gap: 6px; padding: 4px 6px 4px 12px; }
  .clock { min-width: 0; }
  .clock-rate { min-width: 0; font-size: 11.5px; padding-right: 4px; }
  .scale { margin-right: 4px; }
  .hint { bottom: 80px; font-size: 14px; }
  .help-sheet { padding: 24px 20px; }
  .help-cols { grid-template-columns: 1fr; gap: 20px; }
  .keys > div { grid-template-columns: 120px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
