:root {
  --galaxy-room-transition: 760ms;
  --galaxy-space-transition: 1200ms;
}

#memory-galaxy-entry {
  position: relative;
  flex: 0 0 auto;
  z-index: 116;
  width: 2.25rem;
  height: 2.25rem;
  margin: 0 -0.2rem;
  padding: 0;
  border: 1px solid rgba(68, 91, 65, 0.22);
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 255, 255, 0.96), rgba(246, 249, 243, 0.78) 58%, rgba(222, 232, 219, 0.62));
  color: rgba(55, 82, 54, 0.9);
  cursor: pointer;
  opacity: 0.9;
  box-shadow:
    0 2px 10px rgba(56, 80, 54, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.68);
  transition:
    opacity 500ms ease,
    filter 500ms ease,
    transform 500ms ease,
    box-shadow 500ms ease;
  filter: none;
  animation: none;
}

#memory-galaxy-entry::before,
#memory-galaxy-entry::after {
  position: absolute;
  inset: 50% auto auto 50%;
  content: "";
  pointer-events: none;
  transform: translate(-50%, -50%);
}

#memory-galaxy-entry::before {
  width: 0.26rem;
  height: 0.26rem;
  border-radius: 50%;
  background: #fefdf3;
  box-shadow:
    0 0 0 1px rgba(55, 82, 54, 0.52),
    0 0 0.24rem rgba(255, 253, 224, 0.98),
    0 0 0.72rem rgba(93, 119, 89, 0.42);
  animation: galaxy-entry-breathe 7.5s ease-in-out infinite;
}

#memory-galaxy-entry::after {
  width: 1rem;
  height: 1rem;
  background:
    linear-gradient(
      90deg,
      transparent 47.5%,
      rgba(55, 82, 54, 0.62) 49%,
      rgba(55, 82, 54, 0.62) 51%,
      transparent 52.5%
    ),
    linear-gradient(
      transparent 47.5%,
      rgba(55, 82, 54, 0.58) 49%,
      rgba(55, 82, 54, 0.58) 51%,
      transparent 52.5%
    );
  transform: translate(-50%, -50%) rotate(45deg);
}

#memory-galaxy-entry > span {
  position: relative;
  z-index: 1;
  display: block;
  color: rgba(54, 80, 53, 0.92);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1;
  text-shadow: 0 0 0.45rem rgba(97, 124, 92, 0.34);
}

#memory-galaxy-entry:hover,
#memory-galaxy-entry:focus-visible {
  opacity: 1;
  filter: none;
  box-shadow:
    0 3px 14px rgba(56, 80, 54, 0.2),
    0 0 0 3px rgba(240, 246, 237, 0.72),
    inset 0 0 0 1px rgba(255, 255, 255, 0.84);
  transform: scale(1.06);
}

#memory-galaxy-entry:focus-visible,
#memory-galaxy-return:focus-visible {
  outline: 2px solid rgba(55, 82, 54, 0.72);
  outline-offset: 0.25rem;
}

#memory-galaxy-entry[data-fallback-position="true"] {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  left: 1rem;
}

#memory-galaxy-shell {
  position: fixed;
  z-index: 190;
  inset: 0;
  overflow: hidden;
  background: rgba(0, 0, 0, 0);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--galaxy-room-transition) ease,
    background-color var(--galaxy-space-transition) ease;
}

#memory-galaxy-shell[hidden] {
  display: none;
}

#memory-galaxy-shell[data-stage="dimming"],
#memory-galaxy-shell[data-stage="fading"],
#memory-galaxy-shell[data-stage="first-star"],
#memory-galaxy-shell[data-stage="revealing"],
#memory-galaxy-shell[data-stage="active"],
#memory-galaxy-shell[data-stage="leaving"] {
  opacity: 1;
  pointer-events: auto;
}

#memory-galaxy-shell[data-stage="dimming"] {
  background: rgba(0, 0, 0, 0.18);
}

#memory-galaxy-shell[data-stage="fading"] {
  background: rgba(0, 0, 0, 0.64);
}

#memory-galaxy-shell[data-stage="first-star"],
#memory-galaxy-shell[data-stage="revealing"],
#memory-galaxy-shell[data-stage="active"],
#memory-galaxy-shell[data-stage="leaving"] {
  background: #000;
}

body > :not(#memory-galaxy-shell):not(script):not(link) {
  transition:
    opacity var(--galaxy-room-transition) ease,
    filter var(--galaxy-room-transition) ease,
    transform var(--galaxy-space-transition) cubic-bezier(0.22, 0.61, 0.36, 1);
}

body.galaxy-room-dimming
  > :not(#memory-galaxy-shell):not(script):not(link) {
  filter: brightness(0.7) saturate(0.88);
}

body.galaxy-room-fading
  > :not(#memory-galaxy-shell):not(script):not(link) {
  opacity: 0.16;
  filter: brightness(0.3) saturate(0.62);
  transform: scale(1.018);
}

#memory-galaxy-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  opacity: 0;
  transform: scale(1.08);
  transition:
    opacity 1200ms ease,
    transform 1800ms cubic-bezier(0.16, 1, 0.3, 1);
}

#memory-galaxy-shell[data-stage="revealing"] #memory-galaxy-frame,
#memory-galaxy-shell[data-stage="active"] #memory-galaxy-frame {
  opacity: 1;
  transform: scale(1);
}

#memory-galaxy-shell[data-stage="leaving"] #memory-galaxy-frame {
  opacity: 0;
  transform: scale(0.94);
  transition-duration: 760ms;
}

.memory-galaxy-first-star {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 0.22rem;
  height: 0.22rem;
  margin: -0.11rem;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  box-shadow:
    0 0 0.35rem rgba(255, 255, 255, 0.96),
    0 0 1.5rem rgba(246, 249, 255, 0.58);
  transform: scale(0.2);
  transition:
    opacity 800ms ease,
    transform 1700ms cubic-bezier(0.16, 1, 0.3, 1);
}

#memory-galaxy-shell[data-stage="first-star"] .memory-galaxy-first-star,
#memory-galaxy-shell[data-stage="revealing"] .memory-galaxy-first-star {
  opacity: 1;
  transform: scale(1);
}

#memory-galaxy-shell[data-stage="active"] .memory-galaxy-first-star {
  opacity: 0;
}

#memory-galaxy-return {
  position: absolute;
  z-index: 4;
  top: max(1rem, env(safe-area-inset-top));
  left: max(1rem, env(safe-area-inset-left));
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.78rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
  color: rgba(255, 255, 255, 0.74);
  font: 500 0.75rem/1 system-ui, sans-serif;
  letter-spacing: 0.08em;
  opacity: 0;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition:
    opacity 500ms ease,
    color 300ms ease,
    border-color 300ms ease;
}

#memory-galaxy-shell[data-stage="active"] #memory-galaxy-return {
  opacity: 1;
}

#memory-galaxy-return:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.34);
}

@keyframes galaxy-entry-breathe {
  0%,
  100% {
    opacity: 0.62;
    filter: blur(0);
  }
  50% {
    opacity: 1;
    filter: blur(0.02rem);
  }
}

@media (max-width: 719px), (pointer: coarse) {
  .home-topbar-identity > #memory-galaxy-entry {
    width: 2.5rem;
    height: 2.5rem;
  }

  #memory-galaxy-return {
    padding: 0.62rem;
  }

  #memory-galaxy-return span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --galaxy-room-transition: 120ms;
    --galaxy-space-transition: 160ms;
  }

  #memory-galaxy-entry {
    animation: none;
  }
}
