:root {
  --indigo-deep: #100726;
  --indigo-1: #180b3a;
  --indigo-2: #2a1160;
  --violet: #7b5cff;
  --magenta: #e63aa0;
  --amber: #ffb454;
  --teal: #33e0c9;
  --rose: #ff7ea8;
  --paper: #f6ecd8;

  --control-size: 3.25rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--indigo-deep);
  color: var(--paper);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

body {
  scrollbar-width: none;
}

body::-webkit-scrollbar {
  display: none;
}

/* The tall element that generates native scroll. Content lives in the fixed cosmos. */
#spacer {
  width: 1px;
  pointer-events: none;
}

#cosmos {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 1;
  isolation: isolate;
}

/* Layered ink-wash background — deep, saturated, never sterile black. */
#cosmos::before {
  content: "";
  position: absolute;
  inset: -12%;
  z-index: 0;
  background:
    radial-gradient(60% 45% at 22% 12%, rgba(230, 58, 160, 0.42), transparent 70%),
    radial-gradient(55% 50% at 82% 30%, rgba(123, 92, 255, 0.4), transparent 72%),
    radial-gradient(70% 55% at 60% 88%, rgba(51, 224, 201, 0.32), transparent 74%),
    radial-gradient(50% 45% at 12% 78%, rgba(255, 180, 84, 0.28), transparent 70%),
    linear-gradient(160deg, var(--indigo-2) 0%, var(--indigo-1) 46%, var(--indigo-deep) 100%);
  background-blend-mode: screen, screen, screen, screen, normal;
  filter: saturate(1.15);
  animation: inkDrift 46s ease-in-out infinite alternate;
  transform-origin: center;
}

@keyframes inkDrift {
  0% {
    transform: scale(1.04) translate3d(-1.5%, -1%, 0);
    filter: saturate(1.1) hue-rotate(-6deg);
  }
  100% {
    transform: scale(1.1) translate3d(2%, 1.5%, 0);
    filter: saturate(1.22) hue-rotate(8deg);
  }
}

.layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  will-change: transform;
  pointer-events: none;
}

.layer[data-layer="bg"] {
  z-index: 1;
  filter: blur(0.4px);
}
.layer[data-layer="mid"] {
  z-index: 2;
}
.layer[data-layer="fg"] {
  z-index: 3;
}

.sector {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  will-change: transform;
  transform: translate3d(0, 0, 0);
}

.el {
  position: absolute;
  display: block;
}

/* Interactive stars accept pointer events; everything else stays inert. */
.layer[data-layer="mid"],
.layer[data-layer="fg"] {
  pointer-events: none;
}

.star {
  pointer-events: auto;
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center center;
  color: var(--c, var(--teal));
  filter:
    drop-shadow(0 0 calc(3px * var(--glow, 1)) var(--c, var(--teal)))
    drop-shadow(0 0 calc(11px * var(--glow, 1)) var(--c, var(--teal)));
  -webkit-tap-highlight-color: transparent;
}

.star:focus-visible {
  outline: 2px solid rgba(246, 236, 216, 0.8);
  outline-offset: 4px;
  border-radius: 50%;
}

.nebula {
  mix-blend-mode: screen;
  filter: blur(26px);
  opacity: 0.5;
  animation: sway var(--dur, 30s) ease-in-out infinite alternate;
}

.dust {
  opacity: 0.7;
  animation: twinkle var(--dur, 6s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.twinkle {
  animation: twinkle var(--dur, 5s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.planet {
  filter: drop-shadow(0 6px 18px rgba(16, 7, 38, 0.55));
}

.comet {
  animation: cometDrift var(--dur, 12s) linear infinite;
  animation-delay: var(--delay, 0s);
  opacity: 0;
}

.whimsy {
  animation: float var(--dur, 22s) ease-in-out infinite alternate;
  animation-delay: var(--delay, 0s);
  filter: drop-shadow(0 10px 22px rgba(16, 7, 38, 0.5));
}

@keyframes twinkle {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@keyframes sway {
  0% { transform: translate3d(0, 0, 0) scale(1); opacity: 0.4; }
  100% { transform: translate3d(2%, -3%, 0) scale(1.12); opacity: 0.62; }
}

@keyframes cometDrift {
  0% { transform: translate3d(0, 0, 0) rotate(var(--rot, 18deg)); opacity: 0; }
  8% { opacity: 0.9; }
  70% { opacity: 0.9; }
  100% { transform: translate3d(var(--travel, 120vw), var(--fall, 22vh), 0) rotate(var(--rot, 18deg)); opacity: 0; }
}

@keyframes float {
  0% { transform: translate3d(0, 0, 0) rotate(-1.5deg); }
  100% { transform: translate3d(3%, -2.4%, 0) rotate(1.5deg); }
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(16, 7, 38, 0.55) 100%);
}

/* Paper grain across the whole viewport. */
.grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 40;
  pointer-events: none;
  mix-blend-mode: soft-light;
  opacity: 0.55;
}

.intro {
  position: fixed;
  z-index: 30;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  width: min(92vw, 40rem);
  animation: introFade 9s ease-in-out forwards;
  animation-delay: 3.2s;
}

.intro__title {
  margin: 0;
  font-size: clamp(2.6rem, 9vw, 5rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--paper);
  text-shadow: 0 0 26px rgba(255, 180, 84, 0.45), 0 0 60px rgba(230, 58, 160, 0.3);
}

.intro__sub {
  margin: 0.6rem 0 0.9rem;
  font-size: clamp(1rem, 3.4vw, 1.35rem);
  font-style: italic;
  color: rgba(246, 236, 216, 0.9);
}

.intro__hint {
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: rgba(246, 236, 216, 0.55);
}

@keyframes introFade {
  0% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

.controls {
  position: fixed;
  z-index: 45;
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
}

.control {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 1rem 0 0.7rem;
  height: var(--control-size);
  border: 1px solid rgba(246, 236, 216, 0.22);
  border-radius: 999px;
  background: rgba(24, 11, 58, 0.55);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  color: var(--paper);
  font: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  cursor: pointer;
  transition: transform 0.35s ease, border-color 0.35s ease, background 0.35s ease;
}

.control:hover {
  transform: translateY(-1px);
  border-color: rgba(51, 224, 201, 0.6);
}

.control:active {
  transform: translateY(0) scale(0.97);
}

.control__icon {
  width: 1.5rem;
  height: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.control__icon path[d]:first-child {
  fill: currentColor;
  stroke: none;
}

.control__icon--on {
  display: none;
  color: var(--teal);
}

.control[aria-pressed="true"] .control__icon--off {
  display: none;
}

.control[aria-pressed="true"] .control__icon--on {
  display: block;
}

.control[aria-pressed="true"] {
  border-color: rgba(51, 224, 201, 0.65);
}

@media (prefers-reduced-motion: reduce) {
  #cosmos::before,
  .nebula,
  .twinkle,
  .dust,
  .comet,
  .whimsy,
  .intro {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
  }
  .comet {
    display: none;
  }
}
