:root {
  --bg-1: #29d7ff;
  --bg-2: #2766ff;
  --bg-3: #ff3d92;
  --bg-4: #00f2b1;
  --ink: #192242;
  --paper: #f4e2bd;
  --paper-deep: #ddc28c;
  --vintage-ink: #57381d;
  --burn-soft: #9a6a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Baloo 2", cursive;
  background: linear-gradient(120deg, var(--bg-1), var(--bg-2) 35%, var(--bg-3) 68%, var(--bg-4));
  background-size: 220% 220%;
  animation: aurora-shift 14s ease-in-out infinite;
  overflow-x: hidden;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 32 32'%3E%3Ctext y='24' font-size='24'%3E%F0%9F%90%BE%3C/text%3E%3C/svg%3E") 4 4, auto;
}

@keyframes aurora-shift {
  0%, 100% { background-position: 0% 45%; }
  50% { background-position: 100% 55%; }
}

.bg-gradient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 255, 255, 0.5), transparent 34%),
    radial-gradient(circle at 84% 24%, rgba(0, 242, 177, 0.44), transparent 34%),
    radial-gradient(circle at 50% 86%, rgba(255, 220, 78, 0.34), transparent 42%),
    radial-gradient(circle at 18% 72%, rgba(255, 92, 174, 0.32), transparent 36%);
  animation: glow-drift 12s ease-in-out infinite alternate;
  z-index: -2;
}

.bg-gradient::before,
.bg-gradient::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(1px);
  opacity: 0.3;
}

.bg-gradient::before {
  width: min(54vw, 520px);
  height: min(54vw, 520px);
  left: -12%;
  top: 8%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0));
  animation: orb-float-1 11s ease-in-out infinite;
}

.bg-gradient::after {
  width: min(48vw, 460px);
  height: min(48vw, 460px);
  right: -10%;
  bottom: -4%;
  background: radial-gradient(circle, rgba(46, 255, 219, 0.42), rgba(46, 255, 219, 0));
  animation: orb-float-2 13s ease-in-out infinite;
}

@keyframes glow-drift {
  0% { transform: translate3d(-1.5%, -1%, 0) scale(1); }
  100% { transform: translate3d(1.5%, 1%, 0) scale(1.04); }
}

@keyframes orb-float-1 {
  0%, 100% { transform: translateY(0) translateX(0); }
  50% { transform: translateY(20px) translateX(18px); }
}

@keyframes orb-float-2 {
  0%, 100% { transform: translateY(0) translateX(0); }
  50% { transform: translateY(-20px) translateX(-14px); }
}

#floatingHeads {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.float-head {
  position: absolute;
  font-size: clamp(18px, 2vw, 30px);
  animation: drift var(--dur) linear infinite;
  opacity: 0.7;
}

@keyframes drift {
  from { transform: translateY(110vh) rotate(0deg); }
  to { transform: translateY(-20vh) rotate(360deg); }
}

.hero {
  width: min(980px, calc(100% - 2rem));
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(0.8rem, 3.5vw, 1.5rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.eyebrow {
  margin: 0;
  color: #fff;
  background: #11356f;
  width: fit-content;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  letter-spacing: 0.4px;
}

h1,
h3 {
  margin: 0.4rem 0 0.35rem;
  font-family: "Chewy", cursive;
  letter-spacing: 0.8px;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.6rem);
}

.hero-line {
  margin: 0.2rem 0 1rem;
  font-size: clamp(1rem, 2.6vw, 1.3rem);
  max-width: 640px;
}

.hero-center {
  display: grid;
  place-items: center;
  margin: 1rem 0;
}

.stitch {
  --size: clamp(190px, 35vw, 320px);
  width: var(--size);
  height: auto;
  border: none;
  background: transparent;
  position: relative;
  transform-origin: center bottom;
  animation: idle-bounce 2.1s ease-in-out infinite, suspicious-look 4.5s ease-in-out infinite;
}

.stitch:hover {
  transform: scale(1.05);
}

.stitch img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 12px 18px rgba(11, 32, 78, 0.35));
}

.hug-label {
  margin: 0.35rem 0 0;
  font-size: clamp(1.1rem, 2.8vw, 1.35rem);
  font-weight: 800;
  color: #0b2f6a;
}

@keyframes idle-bounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-8px) rotate(-2deg); }
  50% { transform: translateY(-2px) rotate(2deg); }
  75% { transform: translateY(-6px) rotate(-1deg); }
}

@keyframes suspicious-look {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  20% { transform: translateY(-6px) rotate(-1deg); }
  35% { transform: translateY(-3px) rotate(2deg); }
  68% { transform: translateY(-5px) rotate(-2deg); }
}

.stitch.hug-attack {
  animation: hug-attack 0.56s cubic-bezier(0.2, 0.8, 0.22, 1.4), hug-spin 0.56s ease;
}

@keyframes hug-attack {
  0% { transform: scale(1); }
  50% { transform: scale(1.23) translateY(-5px); }
  100% { transform: scale(1); }
}

@keyframes hug-spin {
  0% { rotate: 0deg; }
  40% { rotate: -4deg; }
  75% { rotate: 3deg; }
  100% { rotate: 0deg; }
}

.hero-actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.8rem;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.2s ease;
}

.btn:hover {
  animation: button-pop 0.45s ease;
}

@keyframes button-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.05); }
  100% { transform: scale(1.02); }
}

.btn:active {
  transform: scale(0.96);
}

.primary {
  background: linear-gradient(120deg, #00efb9, #00c9ff);
  color: #072438;
  box-shadow: 0 10px 18px rgba(3, 64, 86, 0.22);
}

.outline {
  background: #f4e2bd;
  color: #5d3f20;
  border: 2px solid #8e6235;
}

.letter-modal {
  border: none;
  padding: 0;
  width: min(86vw, 600px);
  max-width: 600px;
  background: transparent;
}

.letter-modal::backdrop {
  background: rgba(15, 10, 7, 0.65);
  animation: backdrop-fade 0.25s ease;
}

@keyframes backdrop-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.letter-modal-shell {
  position: relative;
  padding: 0.8rem;
  --paper-shift-x: 0px;
  --paper-shift-y: 0px;
}

.close-letter {
  position: absolute;
  right: 0.35rem;
  top: 0.25rem;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(16, 31, 83, 0.88);
  color: #fff;
  cursor: pointer;
  z-index: 5;
}

.vintage-letter {
  width: 100%;
  perspective: 1300px;
  transform-style: preserve-3d;
}

.vintage-letter.open {
  animation: letter-pop-in 0.65s ease both, letter-float 4.4s ease-in-out 0.7s infinite;
}

.letter-fold {
  width: 100%;
  height: 170px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(180deg, #e8ca94, #d9b271);
  border: 2px solid #8e6235;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  transform-origin: top center;
  transform: rotateX(0deg);
  opacity: 1;
  display: grid;
  place-items: center;
}

.wax-seal {
  width: clamp(58px, 9vw, 74px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #ffd8a2;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  background:
    radial-gradient(circle at 35% 35%, #b01f2f, #8b1725 58%, #6c111c);
  border: 2px solid #4f0d15;
  box-shadow: 0 6px 10px rgba(42, 10, 15, 0.35);
  position: relative;
  transform: rotate(2deg) scale(1);
}

.seal-crack {
  position: absolute;
  inset: 16% 46% 16% 46%;
  background: transparent;
  transform: rotate(-8deg) scaleY(0.05);
  opacity: 0;
}

.vintage-letter.cracking .wax-seal {
  animation: seal-shiver 0.35s ease-in-out 2;
}

.vintage-letter.cracking .seal-crack {
  opacity: 1;
  background: linear-gradient(180deg, rgba(255, 220, 180, 0.95), rgba(255, 220, 180, 0.4));
  box-shadow: -8px 8px 0 -6px rgba(255, 220, 180, 0.9), 8px -8px 0 -6px rgba(255, 220, 180, 0.9);
  animation: crack-grow 0.55s ease forwards;
}

@keyframes crack-grow {
  from { transform: rotate(-8deg) scaleY(0.05); }
  to { transform: rotate(-8deg) scaleY(1); }
}

@keyframes seal-shiver {
  0%, 100% { transform: rotate(2deg) scale(1); }
  35% { transform: rotate(-4deg) scale(1.03); }
  70% { transform: rotate(5deg) scale(0.98); }
}

.vintage-letter.open .letter-fold {
  animation: fold-away 0.85s cubic-bezier(0.14, 0.86, 0.21, 1.02) forwards;
}

.letter-paper {
  position: relative;
  margin-top: -4px;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 250, 231, 0.95), transparent 38%),
    linear-gradient(180deg, var(--paper), #ead3a5 58%, var(--paper-deep));
  border: 2px solid #8f6c3f;
  border-top: none;
  border-radius: 12px 8px 16px 10px;
  box-shadow:
    calc(0px + var(--paper-shift-x)) calc(16px + var(--paper-shift-y)) 25px rgba(58, 35, 14, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  padding: clamp(1rem, 3vw, 1.35rem);
  transform-origin: top center;
  transform: rotateX(-90deg) translateY(-26px) rotate(-1.2deg) scale(0.96);
  opacity: 0;
  isolation: isolate;
  transition: box-shadow 0.12s ease;
  min-height: 360px;
  overflow: hidden;
}

.vintage-letter.open .letter-paper {
  animation:
    unfold-paper 1.08s cubic-bezier(0.17, 0.88, 0.23, 1.06) 0.12s forwards,
    paper-crumple 0.4s ease-in-out 0.95s 2 alternate;
}

/* Grain texture overlay for old paper feel. */
.letter-paper::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 20% 35%, rgba(80, 51, 23, 0.09) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 75%, rgba(87, 56, 29, 0.1) 0 1px, transparent 1px),
    radial-gradient(circle at 40% 60%, rgba(87, 56, 29, 0.06) 0 1px, transparent 1px);
  background-size: 4px 4px, 5px 5px, 6px 6px;
  mix-blend-mode: multiply;
  opacity: 0.6;
  z-index: 0;
}

/* Burnt-corner effect around the letter frame. */
.letter-paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 0 0, rgba(78, 43, 20, 0.72), transparent 24%),
    radial-gradient(circle at 100% 0, rgba(78, 43, 20, 0.72), transparent 24%),
    radial-gradient(circle at 100% 100%, rgba(78, 43, 20, 0.74), transparent 24%),
    radial-gradient(circle at 0 100%, rgba(78, 43, 20, 0.74), transparent 24%);
  filter: blur(0.4px);
  opacity: 0.62;
  z-index: 0;
}

.letter-paper > * {
  position: relative;
  z-index: 1;
}

.letter-paper h3 {
  margin: 0;
  color: var(--vintage-ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  max-width: 64%;
}

.letter-placeholder {
  margin-top: 0.45rem;
  margin-bottom: 0.5rem;
  min-height: 0;
  color: #5c4930;
  font-family: "Comic Sans MS", "Bradley Hand", cursive;
  font-size: clamp(1rem, 2.3vw, 1.2rem);
  line-height: 1.58;
  padding: 0.1rem 0.2rem;
  letter-spacing: 0.2px;
}

.typing-caret::after {
  content: "|";
  opacity: 0.75;
  margin-left: 2px;
  animation: caret-blink 0.7s step-end infinite;
}

@keyframes caret-blink {
  50% { opacity: 0; }
}

.letter-text-wrap {
  max-width: 67%;
  margin-top: 0.45rem;
  display: grid;
  gap: 0.25rem;
}

.letter-photo {
  position: absolute;
  top: 62px;
  right: 14px;
  width: clamp(140px, 24vw, 210px);
  border: 6px solid #fff8ea;
  border-radius: 8px;
  transform: rotate(6deg);
  box-shadow: 0 10px 18px rgba(54, 36, 17, 0.28);
  filter: saturate(1.06) drop-shadow(0 6px 10px rgba(44, 27, 11, 0.2));
}

.paper-spark,
.paper-heart,
.paper-stamp {
  position: absolute;
}

.paper-spark {
  color: #8f5d2e;
  opacity: 0.7;
  animation: twinkle 1.8s ease-in-out infinite;
}

.spark-1 {
  top: 13px;
  right: 166px;
}

.spark-2 {
  top: 94px;
  right: 24px;
  animation-delay: 0.4s;
}

.paper-heart {
  right: 30px;
  bottom: 20px;
  color: #b64558;
  font-size: 1.2rem;
  transform: rotate(-10deg);
}

.paper-stamp {
  top: 15px;
  left: 14px;
  border: 2px dashed #a16c3b;
  color: #8d5c33;
  padding: 0.18rem 0.48rem;
  font-size: 0.72rem;
  border-radius: 6px;
  transform: rotate(-8deg);
  letter-spacing: 0.6px;
}

@keyframes fold-away {
  0% { transform: rotateX(0deg); opacity: 1; }
  70% { transform: rotateX(-145deg); opacity: 1; }
  100% { transform: rotateX(-170deg); opacity: 0.3; }
}

@keyframes unfold-paper {
  0% {
    transform: rotateX(-90deg) translateY(-26px) rotate(-1.2deg) scale(0.96);
    opacity: 0;
  }
  55% {
    transform: rotateX(13deg) translateY(2px) rotate(-0.4deg) scale(1.01);
    opacity: 1;
  }
  100% {
    transform: rotateX(0deg) translateY(0) rotate(-0.8deg) scale(1);
    opacity: 1;
  }
}

@keyframes letter-pop-in {
  0% {
    opacity: 0;
    transform: scale(0.94);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes letter-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.3; transform: scale(0.95); }
  50% { opacity: 0.85; transform: scale(1.1); }
}

@keyframes paper-crumple {
  0% { filter: none; transform: rotateX(0deg) translateY(0) skewX(0deg); }
  100% { filter: contrast(1.02) saturate(1.04); transform: rotateX(0deg) translateY(0) skewX(0.35deg); }
}

.vintage-confirm {
  border: none;
  padding: 0;
  border-radius: 8px;
  max-width: min(92vw, 520px);
  width: 100%;
  background: transparent;
}

.vintage-confirm::backdrop {
  background: rgba(16, 11, 7, 0.52);
}

.confirm-shell {
  position: relative;
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 250, 231, 0.95), transparent 35%),
    linear-gradient(180deg, #f3dfb7, #e3c68c 62%, #d6af70);
  border: 2px solid var(--burn-soft);
  box-shadow: 0 16px 30px rgba(54, 31, 11, 0.35);
  padding: 1rem 1rem 0.95rem;
}

.confirm-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 0 0, rgba(78, 43, 20, 0.65), transparent 20%),
    radial-gradient(circle at 100% 0, rgba(78, 43, 20, 0.65), transparent 20%),
    radial-gradient(circle at 100% 100%, rgba(78, 43, 20, 0.65), transparent 20%),
    radial-gradient(circle at 0 100%, rgba(78, 43, 20, 0.65), transparent 20%);
  opacity: 0.55;
}

.confirm-shell h3 {
  color: #5c3b1e;
  margin: 0;
}

.confirm-shell p {
  margin: 0.3rem 0 1rem;
  font-size: 1.07rem;
  color: #5b4228;
}

.confirm-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  position: relative;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  max-width: min(92vw, 360px);
  background: #101f53;
  color: #fff;
  padding: 0.8rem 0.95rem;
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(8, 14, 37, 0.35);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.screen-shake {
  animation: shake 0.35s linear;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(5px); }
}

.special-mode {
  animation: rainbow 1.8s linear infinite;
}

@keyframes rainbow {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

.clone {
  position: fixed;
  width: 80px;
  height: 70px;
  border-radius: 40% 40% 30% 30%;
  background: linear-gradient(160deg, #9de1ff, #4b86ff);
  border: 3px solid #1d3f8a;
  box-shadow: 0 10px 18px rgba(8, 29, 78, 0.25);
  animation: clone-jump 2.8s ease-in-out forwards;
  z-index: 10;
}

@keyframes clone-jump {
  0% { transform: translateY(0) scale(0.9); opacity: 0; }
  20% { opacity: 1; }
  70% { transform: translateY(-22px) scale(1.05); }
  100% { transform: translateY(0) scale(0.9); opacity: 0; }
}

@media (max-width: 640px) {
  .btn {
    width: 100%;
  }

  .confirm-actions {
    justify-content: stretch;
  }

  .letter-fold {
    height: 132px;
  }

  .letter-paper h3,
  .letter-text-wrap {
    max-width: 100%;
  }

  .letter-photo {
    position: relative;
    top: auto;
    right: auto;
    width: min(76%, 220px);
    margin: 0.7rem auto 0;
    transform: rotate(2deg);
  }

  .spark-1,
  .spark-2,
  .paper-heart {
    display: none;
  }
}
