:root {
  --primary: #ff4fd8;
  --secondary: #7cf7ff;
  --accent: #ffe66d;
  --bg: #050011;
  --glass: rgba(14, 7, 35, .48);
  --white: rgba(255, 255, 255, .95);
  --tiltX: 0deg;
  --tiltY: 0deg;
  --spin: 0deg;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, #170033 0%, #070016 45%, #010006 100%);
  color: var(--white);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  touch-action: manipulation;
}

body.started .intro {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.08);
}

#spaceCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 0;
}

.aurora {
  position: fixed;
  width: min(76vw, 920px);
  height: min(76vw, 920px);
  border-radius: 999px;
  pointer-events: none;
  filter: blur(70px);
  opacity: .42;
  mix-blend-mode: screen;
  z-index: 1;
  animation: floatNebula 16s ease-in-out infinite;
}

.aurora-one {
  left: -18vw;
  top: -12vh;
  background: radial-gradient(circle, rgba(255, 79, 216, .72), transparent 65%);
}

.aurora-two {
  right: -20vw;
  bottom: -18vh;
  background: radial-gradient(circle, rgba(124, 247, 255, .55), transparent 66%);
  animation-duration: 19s;
  animation-direction: reverse;
}

.shooting-layer,
.universe {
  position: fixed;
  inset: 0;
  perspective: 820px;
  transform-style: preserve-3d;
  pointer-events: none;
  overflow: hidden;
  transition: transform 120ms linear;
  transform: rotateX(var(--tiltY)) rotateY(var(--tiltX)) rotateZ(calc(var(--spin) * .08));
}

.shooting-layer { z-index: 2; }
.universe { z-index: 3; }

.shooting-star {
  position: absolute;
  left: var(--left);
  top: var(--top);
  width: 140px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,.95), rgba(124,247,255,.95));
  box-shadow: 0 0 18px rgba(124,247,255,.9);
  animation: shooting var(--duration) linear forwards;
}

.space-item {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-style: preserve-3d;
  animation: flyToCamera var(--duration) linear forwards;
  will-change: transform, opacity, filter;
}

.love-message {
  min-width: max-content;
  padding: clamp(10px, 2.3vw, 20px) clamp(18px, 4vw, 42px);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  color: #fff;
  font-size: clamp(1.2rem, 5vw, 4.2rem);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 0 18px var(--primary), 0 0 42px rgba(124,247,255,.6);
  background: linear-gradient(115deg, rgba(255,79,216,.18), rgba(124,247,255,.14));
  box-shadow: 0 0 42px rgba(255,79,216,.32), inset 0 0 28px rgba(255,255,255,.1);
  backdrop-filter: blur(6px);
}

.space-photo {
  width: clamp(120px, 28vw, 260px);
  aspect-ratio: 4 / 5;
  padding: 9px;
  border-radius: 26px;
  background: linear-gradient(135deg, rgba(255,255,255,.95), rgba(255,255,255,.38));
  box-shadow: 0 0 42px rgba(255,79,216,.46), 0 0 70px rgba(124,247,255,.25);
}

.space-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 19px;
  display: block;
}

.planet,
.sticker,
.icon-float,
.heart-float {
  display: grid;
  place-items: center;
  width: clamp(60px, 14vw, 160px);
  height: clamp(60px, 14vw, 160px);
  border-radius: 50%;
  filter: drop-shadow(0 0 24px rgba(255,255,255,.55));
}

.planet img,
.sticker img,
.icon-float img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.heart-float {
  font-size: clamp(2rem, 9vw, 6rem);
  animation-name: flyToCamera, pulseGlow;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: 1, infinite;
}

.experience {
  position: relative;
  z-index: 5;
  width: 100vw;
  height: 100dvh;
  pointer-events: none;
}

.intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: radial-gradient(circle, rgba(255,79,216,.12), rgba(1,0,7,.78));
  transition: opacity .9s ease, transform .9s ease;
  pointer-events: auto;
}

.intro-card {
  width: min(92vw, 520px);
  padding: clamp(24px, 6vw, 48px);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 34px;
  text-align: center;
  background: linear-gradient(145deg, rgba(12, 6, 32, .76), rgba(255,255,255,.08));
  box-shadow: 0 30px 90px rgba(0,0,0,.55), inset 0 0 38px rgba(255,255,255,.08);
  backdrop-filter: blur(16px);
  animation: introIn 1.1s ease both;
}

.intro-heart {
  font-size: clamp(3.2rem, 15vw, 7rem);
  line-height: 1;
  animation: pulseGlow 2.2s ease-in-out infinite;
}

.intro h1,
.intro h2 {
  margin: 6px 0;
  line-height: 1;
  letter-spacing: -.05em;
}

.intro h1 {
  font-size: clamp(3rem, 13vw, 6.8rem);
  background: linear-gradient(90deg, #fff, var(--secondary), var(--primary), #fff);
  background-size: 300%;
  -webkit-background-clip: text;
  color: transparent;
  animation: shimmer 5s linear infinite;
}

.intro h2 {
  font-size: clamp(1.9rem, 8vw, 4rem);
  color: var(--accent);
  text-shadow: 0 0 22px rgba(255, 230, 109, .55);
}

.intro-small,
.intro-subtitle {
  margin: 10px 0;
  color: rgba(255,255,255,.78);
}

.intro-mode {
  display: inline-flex;
  margin: 12px 0 4px;
  padding: 7px 12px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  color: var(--accent);
  background: rgba(255,255,255,.07);
  font-weight: 900;
}

.primary-btn {
  margin-top: 18px;
  border: 0;
  border-radius: 999px;
  padding: 16px 34px;
  color: #19001e;
  font-weight: 900;
  font-size: 1.05rem;
  background: linear-gradient(90deg, var(--accent), var(--secondary), var(--primary));
  box-shadow: 0 0 36px rgba(255,79,216,.45);
  cursor: pointer;
}

.hud {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  top: max(14px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(70vw, 680px);
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  background: rgba(7, 2, 20, .38);
  backdrop-filter: blur(10px);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 18px var(--primary);
  flex: 0 0 auto;
}

.controls {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.round-btn {
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  color: #fff;
  background: rgba(7, 2, 20, .42);
  backdrop-filter: blur(12px);
  box-shadow: 0 0 24px rgba(124,247,255,.18);
  cursor: pointer;
}

.letter-btn {
  font-size: 1.08rem;
  background: linear-gradient(145deg, rgba(255,79,216,.36), rgba(124,247,255,.16));
}

.palette-btn {
  background: linear-gradient(145deg, rgba(255,230,109,.42), rgba(255,79,216,.2));
}

.palette-panel {
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 58px);
  right: max(14px, env(safe-area-inset-right));
  z-index: 8;
  display: flex;
  gap: 9px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(7, 2, 20, .54);
  box-shadow: 0 0 34px rgba(255,79,216,.18);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.palette-panel[hidden] {
  display: none !important;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 2px solid rgba(255,255,255,.42);
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background: linear-gradient(135deg, var(--sw1), var(--sw2), var(--sw3));
  box-shadow: 0 0 16px rgba(255,255,255,.16);
}

.swatch.active {
  border-color: #fff;
  transform: scale(1.1);
  box-shadow: 0 0 24px var(--primary);
}

.swatch:nth-child(1) { --sw1: #ff4fd8; --sw2: #7cf7ff; --sw3: #ffe66d; }
.swatch:nth-child(2) { --sw1: #ff2f6d; --sw2: #ffb3c7; --sw3: #fff0f6; }
.swatch:nth-child(3) { --sw1: #8c35ff; --sw2: #35d6ff; --sw3: #ffffff; }
.swatch:nth-child(4) { --sw1: #ff9f1c; --sw2: #ffd166; --sw3: #fff3b0; }
.swatch:nth-child(5) { --sw1: #00f5d4; --sw2: #00bbf9; --sw3: #fee440; }

.counter-card {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(92vw, 430px);
  padding: 14px 16px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 22px;
  background: rgba(7, 2, 20, .42);
  box-shadow: 0 0 30px rgba(255,79,216,.16);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.counter-card span {
  display: block;
  color: rgba(255,255,255,.68);
  font-size: .88rem;
}

.counter-card strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(1rem, 4vw, 1.32rem);
}

.counter-card em {
  display: block;
  margin-top: 7px;
  color: rgba(255,255,255,.76);
  font-size: .86rem;
  font-style: normal;
  line-height: 1.35;
}

.letter-panel {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(92vw, 440px);
  max-height: min(55dvh, 460px);
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(20,8,45,.68), rgba(255,255,255,.08));
  box-shadow: 0 0 56px rgba(124,247,255,.16);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(22px);
  pointer-events: auto;
}

body.letter-visible .letter-panel {
  animation: letterReveal .8s ease forwards;
}

body.letter-visible .letter-btn {
  box-shadow: 0 0 28px rgba(255,79,216,.58), inset 0 0 18px rgba(255,255,255,.12);
}

.letter-panel h2 {
  margin: 0 0 12px;
}

.letter-panel p {
  margin: 0;
  line-height: 1.65;
  white-space: pre-line;
}

@media (max-width: 720px) {
  html, body { overflow: hidden; }
  .aurora { filter: blur(46px); opacity: .35; }
  .hud { top: max(10px, env(safe-area-inset-top)); }
  .brand { max-width: 58vw; font-size: .86rem; }
  .round-btn { width: 42px; height: 42px; }
  .palette-panel {
    left: 12px;
    right: 12px;
    justify-content: center;
    border-radius: 22px;
  }
  .counter-card {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
  .letter-panel {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 82px);
    max-height: 42dvh;
  }
  .space-photo { width: clamp(104px, 42vw, 190px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
