.space-page {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sky {
  position: absolute;
  inset: 0;
  background: radial-gradient(
      1400px 700px at 50% 110%,
      rgba(85, 53, 138, 0.45),
      transparent 60%
    ),
    radial-gradient(900px 500px at 20% -10%, rgba(201, 162, 75, 0.1), transparent 55%),
    linear-gradient(180deg, #08040f 0%, #120a1f 45%, #1f1238 100%);
  overflow: hidden;
}

.sky .nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.5;
  pointer-events: none;
}

.sky .nebula.n1 {
  width: 420px;
  height: 420px;
  left: 10%;
  top: 18%;
  background: radial-gradient(circle, rgba(85, 53, 138, 0.5), transparent 70%);
}

.sky .nebula.n2 {
  width: 360px;
  height: 360px;
  right: 8%;
  bottom: 12%;
  background: radial-gradient(circle, rgba(120, 80, 140, 0.25), transparent 70%);
}

.sky .nebula.n3 {
  width: 300px;
  height: 300px;
  left: 45%;
  top: 40%;
  background: radial-gradient(circle, rgba(201, 162, 75, 0.12), transparent 70%);
}

.space-stars {
  position: absolute;
  inset: 0;
}

.bg-star {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #ffffff;
  opacity: 0.5;
  animation: twinkle 4s var(--ease) infinite;
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 0.9;
  }
}

.star-field {
  position: absolute;
  inset: 0;
  transition: transform 0.3s ease-out;
  will-change: transform;
}

.wish-star {
  position: absolute;
  transform: translate(-50%, -50%);
  border: none;
  background: transparent;
  padding: 14px;
  margin: 0;
  cursor: pointer;
  color: var(--gold-300);
  line-height: 0;
  box-sizing: content-box;
  opacity: var(--brightness, 1);
  animation: twinkle 4s var(--ease) infinite;
}

.wish-star svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 6px rgba(231, 207, 142, 0.6));
}

.wish-star:hover svg,
.wish-star:focus-visible svg {
  filter: drop-shadow(0 0 12px rgba(231, 207, 142, 0.95));
}

.wish-star:hover,
.wish-star:focus-visible {
  color: #fff3d6;
}

.wish-star.is-active {
  color: #fff3d6;
  z-index: 2;
}

.wish-star.is-active svg {
  filter: drop-shadow(0 0 16px rgba(231, 207, 142, 1));
}

@keyframes twinkle {
  0%,
  100% {
    opacity: calc(var(--brightness, 1) * 0.6);
  }
  50% {
    opacity: var(--brightness, 1);
  }
}

.space-intro {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(4, 7, 15, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.4s var(--ease), visibility 0.4s;
}

.space-intro.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.intro-card {
  max-width: 520px;
  width: 100%;
  text-align: center;
  padding: 2.75rem 2rem;
  background: rgba(20, 11, 38, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: rise 0.6s var(--ease);
  max-height: 88vh;
  overflow: auto;
}

.intro-card h1 {
  font-size: 2.4rem;
  color: var(--accent-strong);
}

.intro-card p {
  color: var(--text-soft);
}

.space-nav {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 6;
  display: flex;
  gap: 0.5rem;
}

.space-hud {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  text-align: center;
  pointer-events: none;
}

.space-hud strong {
  color: var(--accent-strong);
  font-family: var(--serif);
  font-size: 1.05rem;
}

.popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: transparent;
}

.popup-backdrop[hidden] {
  display: none;
}

.star-popup {
  position: fixed;
  z-index: 80;
  width: min(320px, calc(100vw - 24px));
}

.star-popup[hidden] {
  display: none;
}

.popup-card {
  position: relative;
  background: linear-gradient(180deg, #fffdf6, #f7f0dd);
  color: #3a2f20;
  border-radius: var(--radius-md);
  padding: 1.5rem 1.4rem 1.4rem;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(169, 130, 58, 0.25);
  max-height: 60vh;
  overflow: auto;
}

.popup-arrow {
  position: absolute;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  left: var(--arrow-left, 50%);
  transform: rotate(45deg);
}

.star-popup.above .popup-arrow {
  bottom: -8px;
  background: #f7f0dd;
}

.star-popup.below .popup-arrow {
  top: -8px;
  background: #fffdf6;
}

.star-popup.is-opening .popup-card {
  animation: popup-zoom-in 0.4s var(--ease);
}

.star-popup.is-closing .popup-card {
  animation: popup-zoom-out 0.35s var(--ease) forwards;
}

.star-popup.above .popup-card {
  transform-origin: 50% 100%;
}

.star-popup.below .popup-card {
  transform-origin: 50% 0%;
}

@keyframes popup-zoom-in {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes popup-zoom-out {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.3);
  }
}

.popup-card .modal-eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: #a9823a;
  margin-bottom: 0.75rem;
}

.popup-card .modal-name {
  font-family: var(--serif);
  font-size: 1.7rem;
  color: #4a3a20;
}

.popup-card .modal-rel {
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #a9823a;
  margin-bottom: 1.25rem;
}

.popup-card .modal-message {
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.65;
  color: #3a2f20;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.popup-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(169, 130, 58, 0.4);
  background: transparent;
  color: #a9823a;
  font-size: 1rem;
  line-height: 1;
}

.popup-close:hover {
  background: rgba(169, 130, 58, 0.12);
}

.space-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  z-index: 5;
}

.space-empty[hidden] {
  display: none;
}

.space-empty .empty-icon {
  font-size: 2.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .wish-star,
  .bg-star {
    animation: none !important;
  }
}

@media (max-width: 560px) {
  .space-hud {
    top: 3.75rem;
  }

  .intro-card {
    padding: 2rem 1.25rem;
  }

  .intro-card h1 {
    font-size: 1.9rem;
  }

  .intro-card p {
    font-size: 0.95rem;
  }

  .popup-card {
    padding: 1.25rem 1.1rem 1.15rem;
  }

  .popup-card .modal-name {
    font-size: 1.5rem;
  }

  .popup-card .modal-message {
    font-size: 1.1rem;
  }
}

@media (pointer: coarse) {
  .wish-star {
    padding: 18px;
  }
}
