*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --font: "Circular", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --black: #121212;
  --green: #1ed760;
  --pink: #ff4ecd;
  --purple: #8b3dff;
  --orange: #ff6b35;
  --blue: #2d46b9;
  --yellow: #f5e663;
}

html,
body {
  height: 100%;
  background: #000;
  color: #fff;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ---------- Story frame ---------- */

.story {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--black);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (min-width: 600px) {
  .story {
    height: min(100dvh - 48px, 900px);
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- Progress bars ---------- */

.progress {
  position: absolute;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 10px) 10px 0;
  pointer-events: none;
}

.bar {
  flex: 1;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.bar .fill {
  height: 100%;
  width: 0;
  background: #fff;
}

.bar.done .fill {
  width: 100%;
}

.bar.active .fill {
  animation: fill var(--duration, 6000ms) linear forwards;
}

.bar.active.static .fill {
  animation: none;
  width: 100%;
}

.story.paused .bar.active .fill {
  animation-play-state: paused;
}

@keyframes fill {
  from { width: 0; }
  to { width: 100%; }
}

/* ---------- Slides ---------- */

.slides {
  position: absolute;
  inset: 0;
}

.slide {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 48px) 28px calc(env(safe-area-inset-bottom) + 36px);
  background: var(--bg);
  color: var(--fg);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  overflow: hidden;
}

.slide.active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease;
}

.slide > *:not(.blobs) {
  position: relative;
  z-index: 1;
}

/* Themes */
.theme-green  { --bg: var(--green);  --fg: var(--black); --blob1: #b8ff3d; --blob2: #0b8f3c; --accent: var(--black); }
.theme-pink   { --bg: var(--pink);   --fg: var(--black); --blob1: #ffb3ec; --blob2: #c2007f; --accent: var(--black); }
.theme-purple { --bg: var(--purple); --fg: #fff;         --blob1: #ff4ecd; --blob2: #3a0ca3; --accent: var(--yellow); }
.theme-orange { --bg: var(--orange); --fg: var(--black); --blob1: #ffd23f; --blob2: #d7263d; --accent: var(--black); }
.theme-blue   { --bg: var(--blue);   --fg: #fff;         --blob1: #4cc9f0; --blob2: #8b3dff; --accent: var(--green); }
.theme-yellow { --bg: var(--yellow); --fg: var(--black); --blob1: #ff6b35; --blob2: #1ed760; --accent: var(--black); }
.theme-dark   { --bg: var(--black);  --fg: #fff;         --blob1: var(--green); --blob2: var(--purple); --accent: var(--green); }

/* Floating background blobs */
.blobs {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  opacity: 0.85;
}

.blob.b1 {
  width: 110%;
  aspect-ratio: 1;
  top: -35%;
  right: -45%;
  background: radial-gradient(circle, var(--blob1) 0%, transparent 65%);
  animation: float1 9s ease-in-out infinite alternate;
}

.blob.b2 {
  width: 120%;
  aspect-ratio: 1;
  bottom: -45%;
  left: -50%;
  background: radial-gradient(circle, var(--blob2) 0%, transparent 65%);
  animation: float2 11s ease-in-out infinite alternate;
}

@keyframes float1 {
  to { transform: translate(-30%, 25%) scale(1.2); }
}

@keyframes float2 {
  to { transform: translate(25%, -20%) scale(0.9); }
}

/* ---------- Typography ---------- */

.kicker {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 14px;
}

.title {
  font-size: clamp(2.2rem, 10vw, 3.3rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  margin-bottom: 18px;
}

.text {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.35;
  max-width: 30ch;
}

.slide > .hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.8;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

.big-number {
  font-size: clamp(4rem, 22vw, 7rem);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.05em;
  color: var(--accent);
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.big-number small {
  display: block;
  font-size: 0.3em;
  letter-spacing: -0.01em;
  color: var(--fg);
  margin-top: 6px;
}

/* Entrance animations */
.slide.active .anim {
  animation: rise 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.slide.active .anim.d1 { animation-delay: 0.1s; }
.slide.active .anim.d2 { animation-delay: 0.25s; }
.slide.active .anim.d3 { animation-delay: 0.4s; }
.slide.active .anim.d4 { animation-delay: 0.55s; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Photo slides ---------- */

.slide.type-photo {
  justify-content: space-between;
  gap: 18px;
}

.photo-card {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  transform: rotate(var(--tilt, -2deg));
  background: rgba(0, 0, 0, 0.15);
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.slide.type-photo.active .photo-card {
  animation: pop 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateX(var(--from, -130%)) rotate(calc(var(--tilt, -2deg) * -10)) scale(0.8);
  }
  to {
    opacity: 1;
    transform: rotate(var(--tilt, -2deg)) scale(1);
  }
}

/* ---------- Flying photos on non-photo slides ---------- */

.slide > .floaters {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.floater {
  position: absolute;
  transform: rotate(var(--r));
}

.slide.active .floater {
  animation: fly-in 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.15) var(--delay, 0s) both;
}

.floater-inner {
  padding: 6px 6px 18px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
  animation: bob 5s ease-in-out var(--bob-delay, 0s) infinite alternate;
}

.floater img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 3px;
}

@media (max-height: 720px) {
  .floater {
    max-width: 22%;
  }
}

@keyframes fly-in {
  from {
    opacity: 0;
    transform: translate(var(--x0), var(--y0)) rotate(calc(var(--r) * -4)) scale(0.6);
  }
  to {
    opacity: 1;
    transform: rotate(var(--r));
  }
}

@keyframes bob {
  to { transform: translateY(-10px) rotate(2deg); }
}

.slide.type-photo .title {
  font-size: clamp(1.9rem, 8.5vw, 2.6rem);
  margin-bottom: 10px;
}

.slide.type-photo .text {
  font-size: 1.05rem;
}

/* ---------- Gift slide ---------- */

.slide.type-gift {
  align-items: center;
  text-align: center;
}

.gift-box {
  position: relative;
  width: 200px;
  height: 210px;
  margin: 40px auto 30px;
  cursor: pointer;
  animation: wiggle 1.8s ease-in-out infinite;
}

.gift-body {
  position: absolute;
  bottom: 0;
  left: 12px;
  width: 176px;
  height: 135px;
  border-radius: 10px;
  background: var(--pink);
  box-shadow: inset 0 -12px 0 rgba(0, 0, 0, 0.12), 0 20px 40px rgba(0, 0, 0, 0.4);
}

.gift-lid {
  position: absolute;
  top: 40px;
  left: 0;
  width: 200px;
  height: 46px;
  border-radius: 10px;
  background: #ff74da;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.9s cubic-bezier(0.3, 1.4, 0.5, 1), opacity 0.9s ease;
}

.gift-body::before,
.gift-lid::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 30px;
  transform: translateX(-50%);
  background: var(--green);
}

.gift-bow {
  position: absolute;
  bottom: 100%;
  left: 50%;
  width: 0;
  height: 0;
}

.gift-bow::before,
.gift-bow::after {
  content: "";
  position: absolute;
  bottom: -6px;
  width: 50px;
  height: 38px;
  border: 10px solid var(--green);
  border-radius: 50% 50% 10% 50%;
}

.gift-bow::before {
  right: 0;
  transform: rotate(-20deg);
}

.gift-bow::after {
  left: 0;
  transform: scaleX(-1) rotate(-20deg);
}

.gift-glow {
  position: absolute;
  left: 50%;
  top: 55%;
  width: 260px;
  height: 260px;
  transform: translate(-50%, -50%) scale(0);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(245, 230, 99, 0.6) 40%, transparent 70%);
  opacity: 0;
  transition: transform 0.8s ease-out, opacity 0.8s ease-out;
  pointer-events: none;
}

.gift-box.opened {
  animation: none;
}

.gift-box.opened .gift-lid {
  transform: translate(60px, -260px) rotate(35deg);
  opacity: 0;
}

.gift-box.opened .gift-glow {
  transform: translate(-50%, -50%) scale(2.2);
  opacity: 1;
}

@keyframes wiggle {
  0%, 60%, 100% { transform: rotate(0); }
  65% { transform: rotate(-7deg) scale(1.03); }
  72% { transform: rotate(7deg) scale(1.03); }
  79% { transform: rotate(-5deg); }
  86% { transform: rotate(4deg); }
  93% { transform: rotate(-2deg); }
}

/* ---------- Reveal / Plan B / Final ---------- */

.slide.type-reveal .title {
  font-size: clamp(2.6rem, 13vw, 4.2rem);
  color: var(--accent);
}

.subtitle {
  font-size: clamp(1.4rem, 6vw, 1.8rem);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 22px;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.pill {
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid currentColor;
  font-size: 0.9rem;
  font-weight: 800;
}

.pill:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.planb-card {
  margin-top: 24px;
  padding: 22px;
  border-radius: 18px;
  background: var(--black);
  color: #fff;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  transform: rotate(-1.5deg);
}

.badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--green);
  color: var(--black);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.planb-card .artist {
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.planb-card .meta {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--green);
}

.slide.type-final {
  align-items: center;
  text-align: center;
}

.slide.type-final .text {
  margin: 0 auto;
}

.replay {
  margin-top: 36px;
  padding: 16px 30px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.replay:active {
  transform: scale(0.95);
}

/* ---------- Confetti ---------- */

.confetti {
  position: absolute;
  inset: 0;
  z-index: 30;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .blob,
  .gift-box,
  .floater-inner,
  .hint {
    animation: none !important;
  }
}
