:root {
  --ink: #e9eeff;
  --ink-dim: rgba(220, 228, 255, 0.62);
  --ink-faint: rgba(220, 228, 255, 0.38);
  --line: rgba(170, 190, 255, 0.22);
  --line-strong: rgba(190, 210, 255, 0.55);
  --glass: rgba(10, 14, 32, 0.42);
  --glass-strong: rgba(8, 11, 26, 0.72);
  --accent: #9fc2ff;
  --accent-warm: #ffcf9a;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #01010a;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- */
/* Overlay layer                                                     */
/* ---------------------------------------------------------------- */

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

#ui button, #ui a, #panel { pointer-events: auto; }

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(0, 0, 8, 0.55) 70%, rgba(0, 0, 4, 0.95) 100%);
}

/* brand */
#brand {
  position: absolute;
  top: clamp(14px, 3vh, 28px);
  left: clamp(14px, 3vw, 34px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.brand-title {
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.brand-tag {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* top nav (inside galaxies) */
#topnav {
  position: absolute;
  top: clamp(14px, 3vh, 26px);
  right: clamp(14px, 3vw, 34px);
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
body:not(.at-home) #topnav { opacity: 1; transform: none; }
body.at-home #topnav, body.at-home #topnav * { pointer-events: none !important; }

.nav-btn {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.nav-btn:hover { color: var(--ink); background: rgba(160, 190, 255, 0.1); }
.nav-btn.active { color: #0a0f22; background: var(--ink); }
.nav-home { color: var(--ink); }

/* ---------------------------------------------------------------- */
/* Galaxy buttons (home)                                             */
/* ---------------------------------------------------------------- */

#galaxy-labels, #system-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#galaxy-labels { transition: opacity 0.5s ease; }
body:not(.at-home) #galaxy-labels { opacity: 0; }
body:not([data-state="home"]) #galaxy-labels * { pointer-events: none !important; }

.galaxy-btn {
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 150px;
  padding: 12px 22px 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  white-space: nowrap;
  will-change: transform;
  transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
}
.galaxy-btn.side { translate: 0 -50%; align-items: flex-start; }
.galaxy-btn:hover, .galaxy-btn.hover, .galaxy-btn:focus-visible {
  border-color: var(--line-strong);
  background: rgba(30, 40, 80, 0.5);
  box-shadow: 0 0 32px rgba(120, 160, 255, 0.25);
  outline: none;
}
.g-title {
  font-size: clamp(17px, 1.6vw, 21px);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
/* ---------------------------------------------------------------- */
/* Solar-system labels                                               */
/* ---------------------------------------------------------------- */

.sys-label {
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  max-width: 220px;
  padding: 7px 14px 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  text-align: center;
  will-change: transform, opacity;
  transition: border-color 0.2s, background 0.2s;
}
.sys-label:hover, .sys-label.hover, .sys-label:focus-visible {
  border-color: var(--line);
  background: var(--glass);
  outline: none;
}
.s-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(0, 0, 20, 0.9);
}
.s-status {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  text-shadow: 0 0 10px rgba(0, 0, 20, 0.9);
}
.s-status.prototype { color: #b994ff; }
.s-status.released { color: #6fe3a0; }

/* hint */
#hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(12px, 3vh, 26px);
  margin: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: opacity 0.4s;
}
#hint:empty { opacity: 0; }

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

#panel {
  position: absolute;
  top: 50%;
  right: clamp(14px, 4vw, 60px);
  width: min(400px, 40vw);
  padding: 30px 28px 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translate(30px, -50%);
  pointer-events: none !important;
  transition: opacity 0.45s ease, transform 0.45s ease;
}
#panel.open {
  opacity: 1;
  transform: translate(0, -50%);
  pointer-events: auto !important;
  transition-delay: 0.25s;
}
#panel:not(.open) * { pointer-events: none !important; }
.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
}
.panel-close:hover { color: var(--ink); border-color: var(--line-strong); }
.panel-kicker {
  margin: 0 36px 10px 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.panel-title {
  margin: 0 0 12px;
  font-size: clamp(24px, 2.6vw, 32px);
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.15;
}
.panel-desc {
  margin: 0 0 16px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-dim);
}
.panel-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.panel-tags:empty { display: none; }
.tag {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
}
.panel-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  letter-spacing: 0.06em;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.btn:hover { background: rgba(160, 190, 255, 0.12); }
.btn.primary {
  background: var(--ink);
  color: #0a0f22;
  border-color: var(--ink);
  font-weight: 600;
}
.btn.primary::after { content: "→"; }
.btn.primary:hover { box-shadow: 0 0 28px rgba(160, 200, 255, 0.45); background: #fff; }

/* ---------------------------------------------------------------- */
/* Loader                                                            */
/* ---------------------------------------------------------------- */

#loader {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: #01010a;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: opacity 1.2s ease;
}
#loader.gone { opacity: 0; pointer-events: none; }
#loader span { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10;
  margin: 0;
  background: #01010a;
}

/* ---------------------------------------------------------------- */
/* Small / portrait screens                                          */
/* ---------------------------------------------------------------- */

@media (max-aspect-ratio: 9/10) {
  #panel {
    top: auto;
    bottom: 14px;
    left: 14px;
    right: 14px;
    width: auto;
    max-height: 46vh;
    overflow-y: auto;
    padding: 24px 22px 20px;
    transform: translateY(30px);
  }
  #panel.open { transform: none; }
  .galaxy-btn { min-width: 0; padding: 10px 16px 9px; }
}

@media (max-width: 640px) {
  #topnav { left: 14px; right: 14px; top: auto; bottom: 46px; justify-content: space-between; }
  .nav-btn { padding: 7px 10px; font-size: 12px; }
  .s-title { font-size: 13px; }
  .s-status { font-size: 9.5px; }
  .sys-label { max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  #panel, #topnav { transition: none; }
}

/* ---------------------------------------------------------------- */
/* Back button                                                       */
/* ---------------------------------------------------------------- */

#back {
  position: absolute;
  top: calc(clamp(14px, 3vh, 28px) + 58px);
  left: clamp(14px, 3vw, 34px);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 14px;
  letter-spacing: 0.05em;
  cursor: pointer;
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none !important;
  transition: opacity 0.4s ease, transform 0.4s ease, border-color 0.2s, background 0.2s;
}
#back.show { opacity: 1; transform: none; pointer-events: auto !important; }
#back:disabled { opacity: 0.4; cursor: default; }
#back:not(:disabled):hover { border-color: var(--line-strong); background: rgba(30, 40, 80, 0.55); }
.back-arrow { font-size: 16px; line-height: 1; transition: transform 0.2s; }
#back:not(:disabled):hover .back-arrow { transform: translateX(-3px); }


/* system buttons sit visibly under each solar system */
.sys-label {
  border-color: var(--line);
  background: rgba(10, 14, 32, 0.32);
}
.sys-label:hover, .sys-label.hover, .sys-label:focus-visible {
  border-color: var(--line-strong);
  background: rgba(30, 40, 80, 0.55);
  box-shadow: 0 0 24px rgba(120, 160, 255, 0.2);
}

/* galaxy overview: list of systems */
#panel.info .panel-actions { flex-direction: column; gap: 8px; }
.list-btn {
  justify-content: space-between;
  width: 100%;
  padding: 11px 16px;
  border-radius: 12px;
  border-color: var(--line);
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.list-btn::after { content: "→"; color: var(--ink-faint); }
.list-btn:hover::after { color: var(--ink); }
.lb-title { font-weight: 600; }
.lb-type {
  margin-left: auto;
  margin-right: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  #back { padding: 7px 14px 7px 11px; font-size: 13px; }
  .lb-type { display: none; }
}

/* system buttons beside the system (wide screens) */
.sys-label.side {
  translate: 0 -50%;
  align-items: flex-start;
  text-align: left;
  max-width: 280px;
}

/* ---------------------------------------------------------------- */
/* Header layout: brand top-left, nav top-centre, back top-right     */
/* ---------------------------------------------------------------- */

#topnav {
  left: 50%;
  right: auto;
  translate: -50% 0;
}

#back {
  top: clamp(14px, 3vh, 26px);
  left: auto;
  right: clamp(14px, 3vw, 34px);
  transform: translateY(-8px);
}
#back.show { transform: none; }

/* narrow screens: no room for three things in one row, nav drops to the bottom */
@media (max-width: 760px) {
  #topnav {
    left: 14px;
    right: 14px;
    top: auto;
    bottom: 46px;
    translate: none;
    justify-content: space-between;
  }
}

/* galaxy button text alignment */
.galaxy-btn { text-align: center; }
.galaxy-btn.side { text-align: left; }
