/* =========================================================
   FOR YOU — Premium cinematic apology experience
   Design: Apple launch × elegant love letter
   ========================================================= */

/* ---------- Design tokens ---------- */
:root {
  --bg-deep: #0f172a;
  --bg-slate: #1e293b;
  --accent-violet: #2d1b69;
  --blush: #f8b4d9;
  --blush-soft: #fde7ef;
  --white: #ffffff;

  --text-primary: rgba(255, 255, 255, 0.96);
  --text-secondary: rgba(253, 231, 239, 0.78);
  --text-muted: rgba(248, 180, 217, 0.55);

  --glass-bg: rgba(30, 41, 59, 0.45);
  --glass-border: rgba(253, 231, 239, 0.14);
  --glass-highlight: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 24px 64px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(248, 180, 217, 0.06);

  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Poppins", system-ui, sans-serif;

  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --radius-xl: 36px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);

  --scene-pad: clamp(1.25rem, 4vw, 3rem);
  --content-max: 720px;
  --content-wide: 960px;
}

/* ---------- Reset & base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  font-weight: 300;
  font-size: clamp(0.95rem, 1.6vw, 1.05rem);
  line-height: 1.65;
  color: var(--text-primary);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: none;
  touch-action: manipulation;
}

@media (hover: none), (pointer: coarse) {
  body {
    cursor: auto;
  }

  #cursor-glow {
    display: none;
  }
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: var(--font-body);
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

button:focus-visible {
  outline: 2px solid var(--blush);
  outline-offset: 4px;
}

/* ---------- Ambient background ---------- */
#bg-gradient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 30%, rgba(45, 27, 105, 0.55), transparent 55%),
    radial-gradient(ellipse 70% 50% at 80% 70%, rgba(248, 180, 217, 0.12), transparent 50%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(30, 41, 59, 0.9), transparent 60%),
    linear-gradient(160deg, #0f172a 0%, #1a1235 40%, #0f172a 100%);
  animation: gradient-drift 18s ease-in-out infinite alternate;
}

@keyframes gradient-drift {
  0% {
    filter: hue-rotate(0deg) brightness(1);
    transform: scale(1);
  }
  100% {
    filter: hue-rotate(12deg) brightness(1.05);
    transform: scale(1.04);
  }
}

#stars-canvas,
#particles-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

#grain {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

#cursor-glow {
  position: fixed;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(
    circle,
    rgba(248, 180, 217, 0.14) 0%,
    rgba(45, 27, 105, 0.08) 40%,
    transparent 70%
  );
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.4s var(--ease-soft);
  will-change: transform;
}

body.is-cursor-active #cursor-glow {
  opacity: 1;
}

/* Heart rain overlay (ending) */
body.is-heart-rain #bg-gradient {
  animation: gradient-warm 8s ease-in-out infinite alternate;
}

@keyframes gradient-warm {
  0% {
    filter: hue-rotate(0deg) brightness(1);
  }
  100% {
    filter: hue-rotate(-8deg) brightness(1.08) saturate(1.15);
  }
}

/* ---------- Music toggle ---------- */
.music-toggle {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 100;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--glass-shadow);
  color: var(--blush-soft);
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s var(--ease-out);
  touch-action: manipulation;
}

.music-toggle:hover {
  transform: scale(1.06);
  box-shadow: 0 0 28px rgba(248, 180, 217, 0.25);
}

.music-toggle.is-playing {
  animation: music-pulse 2.4s ease-in-out infinite;
}

.music-toggle.is-finale-pulse {
  animation: music-pulse 1.6s ease-in-out infinite;
}

@keyframes music-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(248, 180, 217, 0.35), var(--glass-shadow);
  }
  50% {
    box-shadow: 0 0 24px 6px rgba(248, 180, 217, 0.28), var(--glass-shadow);
  }
}

.music-toggle__icon {
  position: relative;
  width: 22px;
  height: 22px;
}

.music-toggle__icon svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: opacity 0.3s var(--ease-soft);
}

.music-toggle .icon-playing {
  opacity: 0;
}

.music-toggle .icon-muted {
  opacity: 1;
}

.music-toggle.is-playing .icon-playing {
  opacity: 1;
}

.music-toggle.is-playing .icon-muted {
  opacity: 0;
}

/* ---------- App & scenes ---------- */
#app {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  /* Opacity owned by GSAP — avoids CSS/JS double-fade blink */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* Isolate layout so inactive scenes never flash */
  will-change: opacity;
}

.scene.scene--active {
  visibility: visible;
  pointer-events: auto;
}

.scene[hidden] {
  display: none !important;
}

.scene__inner {
  width: 100%;
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: var(--scene-pad);
  padding-top: max(clamp(3.5rem, 8vh, 5rem), calc(env(safe-area-inset-top) + 3rem));
  padding-bottom: max(clamp(2rem, 5vh, 3.5rem), calc(env(safe-area-inset-bottom) + 1.5rem));
  padding-left: max(var(--scene-pad), env(safe-area-inset-left));
  padding-right: max(var(--scene-pad), env(safe-area-inset-right));
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.scene__inner--center {
  max-width: var(--content-max);
  justify-content: center;
  align-items: center;
  text-align: center;
}

.scene-header {
  text-align: center;
  margin-bottom: clamp(1.5rem, 4vh, 2.5rem);
  flex-shrink: 0;
}

.scene-header__sub {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 400;
}

.scene-footer {
  margin-top: auto;
  padding-top: 2rem;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding-bottom: 0.25rem;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(15, 23, 42, 0.55) 40%,
    rgba(15, 23, 42, 0.85) 100%
  );
}

/* ---------- Typography ---------- */
.heading {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--white);
  line-height: 1.15;
}

.heading--display {
  font-size: clamp(2.75rem, 8vw, 4.5rem);
  font-weight: 500;
  margin-bottom: 1.25rem;
}

.heading--section {
  font-size: clamp(2rem, 5.5vw, 3.25rem);
  font-weight: 500;
}

.heading--hero {
  font-size: clamp(2.5rem, 7vw, 4.75rem);
  font-weight: 500;
  background: linear-gradient(135deg, var(--white) 0%, var(--blush-soft) 50%, var(--blush) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 1.25rem;
}

.body-text {
  color: var(--text-secondary);
  font-weight: 300;
  max-width: 38em;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 2rem;
  font-size: clamp(1rem, 2vw, 1.1rem);
}

.heart-inline {
  color: var(--blush);
  font-style: normal;
  font-size: 0.85em;
  vertical-align: baseline;
}

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.95rem 2.25rem;
  min-height: 48px;
  border-radius: 999px;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.35s var(--ease-out);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn span {
  position: relative;
  z-index: 1;
}

.btn--primary {
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--blush-soft) 0%, var(--blush) 100%);
  box-shadow:
    0 8px 32px rgba(248, 180, 217, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  animation: btn-breathe 3.2s ease-in-out infinite;
}

.btn--primary::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    120deg,
    transparent 30%,
    rgba(255, 255, 255, 0.45) 50%,
    transparent 70%
  );
  transform: translateX(-120%);
  transition: transform 0.7s var(--ease-out);
  z-index: 0;
}

.btn--primary:hover {
  transform: translateY(-2px) scale(1.02);
}

.btn--primary:hover::before {
  transform: translateX(120%);
}

.btn--primary:active {
  transform: translateY(0) scale(0.98);
}

.btn--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.btn--pulse {
  animation: btn-breathe 2s ease-in-out infinite;
}

@keyframes btn-breathe {
  0%,
  100% {
    box-shadow: 0 8px 32px rgba(248, 180, 217, 0.28),
      inset 0 1px 0 rgba(255, 255, 255, 0.45);
  }
  50% {
    box-shadow: 0 12px 40px rgba(248, 180, 217, 0.42),
      inset 0 1px 0 rgba(255, 255, 255, 0.5);
  }
}

.btn--forgive {
  min-width: 160px;
}

/* ---------- Glass cards ---------- */
.glass-card {
  position: relative;
  width: 100%;
  padding: clamp(2rem, 5vw, 3.25rem);
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
  transform-style: preserve-3d;
  will-change: transform;
}

.glass-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--glass-highlight),
    rgba(248, 180, 217, 0.35),
    var(--glass-highlight),
    transparent
  );
  pointer-events: none;
}

.glass-card::after {
  content: "";
  position: absolute;
  top: -40%;
  left: -20%;
  width: 60%;
  height: 80%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.06), transparent 70%);
  pointer-events: none;
  transform: rotate(-12deg);
}

.glass-card--compact {
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-md);
  text-align: left;
}

.glass-card--apology,
.glass-card--promise {
  max-width: 520px;
  margin: 0 auto;
}

/* ---------- Scene 1: Typewriter ---------- */
.typewriter-block {
  min-height: 4.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2.5rem;
  padding: 0 0.5rem;
}

.typewriter {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 5.5vw, 3rem);
  font-weight: 400;
  font-style: italic;
  color: var(--blush-soft);
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.typewriter::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.9em;
  margin-left: 3px;
  background: var(--blush);
  vertical-align: -0.05em;
  animation: caret-blink 0.9s steps(1) infinite;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.typewriter.is-complete::after {
  animation: none;
  opacity: 0;
}

/* ---------- Scene 3: Thank you ---------- */
.thank-you {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.thank-you__list {
  list-style: none;
  width: 100%;
  max-width: 34em;
  margin: 1.75rem 0 2.25rem;
  padding: 0;
  text-align: left;
}

.thank-you__item {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 2.6vw, 1.35rem);
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.55;
  padding: 0.85rem 0 0.85rem 1.35rem;
  border-bottom: 1px solid rgba(248, 180, 217, 0.12);
  opacity: 0;
}

.thank-you__item:last-child {
  border-bottom: none;
}

.thank-you__item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1.35em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blush);
  box-shadow: 0 0 10px rgba(248, 180, 217, 0.5);
  transform: translateY(-50%);
}

/* ---------- Scene 4: Love cards ---------- */
.love-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
  width: 100%;
}

@media (min-width: 640px) {
  .love-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
}

@media (min-width: 900px) {
  .love-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 1.1rem;
  }

  .love-card--wide {
    grid-column: span 2;
  }
}

.love-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 110px;
  padding: 1.15rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  background: linear-gradient(
    145deg,
    rgba(45, 27, 105, 0.55),
    rgba(30, 41, 59, 0.65)
  );
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
  transition: border-color 0.35s var(--ease-out), box-shadow 0.35s var(--ease-out),
    transform 0.35s var(--ease-out);
  opacity: 0;
}

@media (min-width: 640px) {
  .love-card {
    min-height: 130px;
  }
}

.love-card span {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-align: center;
  color: var(--blush-soft);
}

/* ---------- Scene 6: Letter ---------- */
.letter {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3rem) clamp(1.5rem, 4vw, 2.75rem);
  border-radius: 4px 4px var(--radius-sm) var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(253, 231, 239, 0.97) 0%, rgba(248, 240, 245, 0.95) 100%);
  color: #2a2035;
  box-shadow:
    0 28px 64px rgba(0, 0, 0, 0.4),
    inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  text-align: left;
  overflow: hidden;
}

.letter__sheen {
  position: absolute;
  top: 0;
  left: -30%;
  width: 40%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.35),
    transparent
  );
  transform: skewX(-18deg);
  pointer-events: none;
  opacity: 0.5;
}

.letter__salutation {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-style: italic;
  margin-bottom: 1.25rem;
  color: #3d2a4a;
}

.letter__body {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 2.4vw, 1.3rem);
  line-height: 1.75;
  color: #3a2f45;
  margin-bottom: 1.75rem;
  white-space: pre-line;
}

.letter__closing {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.15rem;
  color: #3d2a4a;
}

.letter__signature {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-style: italic;
  color: #2d1b69;
  margin-top: 0.25rem;
}

#scene-6 .scene-footer {
  margin-top: 2rem;
}

/* ---------- Scene 7: Gallery ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
  width: 100%;
}

@media (min-width: 720px) {
  .gallery {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.15rem;
  }
}

.gallery__item {
  opacity: 0;
}

.gallery__frame {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: rgba(30, 41, 59, 0.6);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.gallery__frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.6s var(--ease-out);
}

.gallery__frame img.is-placeholder {
  display: none;
}

.gallery__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  background:
    linear-gradient(145deg, rgba(45, 27, 105, 0.4), rgba(30, 41, 59, 0.7));
}

.gallery__frame img:not(.is-placeholder) + .gallery__placeholder {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .gallery__item:hover .gallery__frame img:not(.is-placeholder) {
    transform: scale(1.06);
  }

  .love-card:hover {
    border-color: rgba(248, 180, 217, 0.35);
    box-shadow: 0 12px 36px rgba(248, 180, 217, 0.12);
    transform: translateY(-3px);
  }
}

/* ---------- Scene 9: Finale ---------- */
.finale {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.finale__text {
  max-width: 28em;
}

/* ---------- Scene 10: Forgive ---------- */
.forgive {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.forgive__heart {
  width: clamp(100px, 22vw, 160px);
  margin-bottom: 1.5rem;
  filter: drop-shadow(0 0 24px rgba(248, 180, 217, 0.45));
}

.heart-svg {
  width: 100%;
  height: auto;
  fill: url(#heart-grad);
  fill: var(--blush);
  animation: heart-beat 1.8s ease-in-out infinite;
  transform-origin: center;
}

@keyframes heart-beat {
  0%,
  100% {
    transform: scale(1);
  }
  14% {
    transform: scale(1.08);
  }
  28% {
    transform: scale(1);
  }
  42% {
    transform: scale(1.05);
  }
  70% {
    transform: scale(1);
  }
}

.forgive__question {
  margin-bottom: 2rem;
  max-width: 14em;
}

.forgive__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

.forgive__response {
  margin-top: 2.5rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  font-style: italic;
  color: var(--blush-soft);
  opacity: 0;
}

.forgive__response.is-shown {
  display: block;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  #bg-gradient {
    animation: none;
  }

  .typewriter::after {
    animation: none;
  }
}

/* ---------- Small phone tweaks ---------- */
@media (max-height: 700px) and (orientation: landscape) {
  .scene__inner {
    padding-top: 3rem;
    padding-bottom: 1.5rem;
  }

  .heading--display {
    font-size: clamp(2rem, 6vw, 3rem);
  }

  .love-card {
    min-height: 100px;
  }
}

@media (max-width: 380px) {
  .btn {
    padding: 0.85rem 1.75rem;
    font-size: 0.88rem;
  }

  .glass-card {
    padding: 1.5rem;
  }
}

/* ---------- Mobile UX ---------- */
@media (max-width: 640px) {
  .heading--display {
    font-size: clamp(2.25rem, 10vw, 3rem);
  }

  .thank-you__list {
    margin: 1.25rem 0 1.75rem;
  }

  .thank-you__item {
    font-size: clamp(1.02rem, 4.2vw, 1.2rem);
    padding: 0.75rem 0 0.75rem 1.2rem;
  }

  .love-card {
    min-height: 96px;
  }

  .forgive__actions {
    flex-direction: column;
    width: 100%;
    max-width: 280px;
  }

  .btn--forgive {
    width: 100%;
    min-width: 0;
  }

  .letter {
    padding: 1.5rem 1.25rem;
  }

  .typewriter-block {
    min-height: 3.5em;
    margin-bottom: 2rem;
  }
}
