/* ============================================================
   100 Things I Love About You — kawaii "love letters" theme
   ============================================================ */

:root {
  --cream: #fff6f9;
  --pink: #ff9ec3;
  --pink-deep: #ff6fa5;
  --blush: #ffd5e6;
  --flap: #ffb9d4;
  --cherry: #ff4d6d;
  --cherry-deep: #e23a59;
  --gold: #ffce5b;
  --ink: #5b3a48;
  --ink-soft: #a86b7e;
  --paper: #fffdf7;
  --sky: #7cc6ff;
  --radius: 18px;
  --shadow: 0 14px 30px rgba(226, 58, 89, 0.18);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Baloo 2", system-ui, sans-serif;
  background:
    radial-gradient(1100px 700px at 8% -8%, #ffe3ee, transparent 60%),
    radial-gradient(1000px 700px at 108% 4%, #fff0cf, transparent 55%),
    radial-gradient(1000px 800px at 50% 116%, #ffd9ea, transparent 55%),
    var(--cream);
  overflow-x: hidden;
}

/* polka-dot texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: radial-gradient(#ffd5e6 2px, transparent 2.5px);
  background-size: 30px 30px;
  opacity: 0.4;
}

.wrap { position: relative; z-index: 1; }

/* ---------------- Hero ---------------- */
.hero {
  text-align: center;
  padding: 44px 18px 14px;
  max-width: 1100px;
  margin: 0 auto;
}

.hero__kitty .kitty {
  width: clamp(120px, 21vw, 188px);
  margin: 0 auto 6px;
  animation: bob 4.5s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}

.title {
  font-family: "Pacifico", cursive;
  font-weight: 400;
  line-height: 1.08;
  margin: 4px 0 8px;
  color: var(--cherry);
  font-size: clamp(2.3rem, 7vw, 4.5rem);
  text-shadow: 0 3px 0 #fff, 0 6px 18px rgba(226, 58, 89, 0.25);
}

.title .name {
  position: relative;
  color: var(--cherry-deep);
}
.title .name::after {
  content: "🎀";
  font-size: 0.5em;
  position: absolute;
  top: -0.25em;
  right: -1em;
  -webkit-text-fill-color: initial;
}

.subtitle {
  font-size: clamp(1rem, 2.4vw, 1.25rem);
  font-weight: 600;
  color: var(--ink-soft);
  margin: 0 0 16px;
}

/* polaroid photo wall */
.photos {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 6px 0 18px;
}
.polaroid {
  position: relative;
  margin: 0;
  background: #fff;
  padding: 10px 10px 28px;
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(226, 58, 89, 0.2);
  transform: rotate(var(--r));
  transition: transform 0.25s ease;
}
.polaroid::before {
  content: "♥";
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--cherry);
  font-size: 1.3rem;
  filter: drop-shadow(0 2px 2px rgba(226, 58, 89, 0.3));
}
.polaroid:hover { transform: rotate(0) scale(1.06); }
.polaroid__img {
  width: 112px;
  height: 112px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 38%, #fff, #ffe6f1);
}
.polaroid__img .kitty { width: 92px; }
.polaroid figcaption {
  font-family: "Gochi Hand", cursive;
  color: var(--cherry-deep);
  text-align: center;
  margin-top: 8px;
  font-size: 1.1rem;
}

/* progress heart */
.progress {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin: 4px 0 6px;
}
.progress__heart {
  width: 78px;
  height: 75px;
  filter: drop-shadow(0 6px 10px rgba(226, 58, 89, 0.25));
}
.progress__text {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  color: var(--cherry-deep);
  font-size: 1.7rem;
  text-align: left;
  line-height: 1;
}
.progress__slash { color: #ffb3c8; margin: 0 2px; }
.progress__text small {
  display: block;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 4px;
}

/* controls */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 14px 0 6px;
}
.btn {
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  padding: 0.66em 1.25em;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, #ff7aa8, var(--cherry));
  box-shadow: 0 8px 18px rgba(226, 58, 89, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translateY(-2px) scale(1.03); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn--ghost {
  background: #fff;
  color: var(--cherry-deep);
  box-shadow: 0 6px 14px rgba(226, 58, 89, 0.16);
}
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.tip {
  font-family: "Gochi Hand", cursive;
  font-size: 1.2rem;
  color: var(--ink-soft);
  margin: 10px 0 0;
}

/* ---------------- Grid of letters ---------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  gap: clamp(12px, 2vw, 20px);
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 14px 44px;
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 12px; }
}

.card {
  all: unset;
  cursor: pointer;
  display: block;
  perspective: 1100px;
  aspect-ratio: 4 / 5;
  /* Skip rendering work for off-screen cards — this is what keeps
     "Open all" (100 simultaneous 3D flips) smooth. */
  content-visibility: auto;
  contain-intrinsic-size: auto 220px;
}
.card:focus-visible {
  outline: 3px solid var(--cherry);
  outline-offset: 4px;
  border-radius: var(--radius);
}

.card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.25, 1);
}
.card:not(.is-open):hover .card__inner { transform: translateY(-5px) rotate(-1.2deg); }
.card.is-open .card__inner { transform: rotateY(180deg); }

.card__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
}
.card__back { transform: rotateY(180deg); }

/* envelope (front) */
.envelope {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 120%, #ffd0e2, #ffe6f0 60%, #fff2f8);
  border: 3px solid #fff;
  box-shadow: inset 0 0 0 2px #ffd0e2, var(--shadow);
}
.envelope__flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 62%;
  background: linear-gradient(180deg, var(--pink), var(--pink-deep));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  box-shadow: 0 6px 10px rgba(226, 58, 89, 0.16);
}
.envelope__shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 42%, rgba(255, 255, 255, 0.55) 50%, transparent 58%);
  transform: translateX(-130%);
}
.card:hover .envelope__shine { transition: transform 0.85s ease; transform: translateX(130%); }

.seal {
  position: absolute;
  left: 50%;
  top: 57%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
}
.seal__heart { position: absolute; inset: 0; width: 100%; height: 100%; }
.seal__num {
  position: relative;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  color: #fff;
  font-size: 1.05rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
}
.envelope__tag {
  position: absolute;
  left: 50%;
  bottom: 9px;
  transform: translateX(-50%);
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--cherry-deep);
  background: #fff;
  padding: 3px 11px;
  border-radius: 999px;
  box-shadow: 0 3px 8px rgba(226, 58, 89, 0.18);
  white-space: nowrap;
}

/* note (back) */
.note {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 34px 14px 14px;
  overflow: hidden;
  background: linear-gradient(180deg, #fffdf7, #fff6fb);
  border: 3px solid #fff;
  box-shadow: inset 0 0 0 2px #ffe0ec, var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
}
.note::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 9px;
  background: repeating-linear-gradient(90deg, var(--pink) 0 10px, var(--blush) 10px 20px);
}
.note__num {
  position: absolute;
  top: 13px;
  left: 50%;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 0.68rem;
  color: var(--cherry-deep);
  background: #ffe0ec;
  padding: 2px 10px;
  border-radius: 999px;
  transform: translateX(-50%) rotate(-3deg);
}
.note__text {
  font-family: "Gochi Hand", cursive;
  font-size: clamp(0.95rem, 1.5vw, 1.18rem);
  line-height: 1.34;
  color: var(--ink);
  margin: 0;
  overflow: hidden;
}
.note__kitty { width: 44px; flex: none; }
.note__kitty .kitty { width: 44px; }

@keyframes pulseAnim {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 109, 0); }
  30% { box-shadow: 0 0 0 12px rgba(255, 77, 109, 0.2); }
}
.card.pulse { animation: pulseAnim 0.9s ease-out; border-radius: var(--radius); }

/* ---------------- Footer ---------------- */
.footer {
  text-align: center;
  padding: 10px 20px 40px;
  color: var(--ink-soft);
  font-weight: 600;
}
.footer__kitty .kitty { width: 64px; margin: 0 auto 2px; }

/* ---------------- Kitty base ---------------- */
.kitty {
  width: 120px;
  height: auto;
  display: block;
}
/* Soft shadow only on the few large kitties — NOT the 100 tiny card-back
   ones, where 100 filters would tank paint performance on "Open all". */
.hero__kitty .kitty,
.finale__kitty .kitty,
.polaroid__img .kitty,
.footer__kitty .kitty {
  filter: drop-shadow(0 8px 10px rgba(226, 58, 89, 0.18));
}

/* ---------------- Floating background ---------------- */
#floaties { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.floaty {
  position: fixed;
  bottom: -60px;
  z-index: 0;
  pointer-events: none;
  animation: floatUp linear infinite;
  will-change: transform;
}
@keyframes floatUp {
  0% { transform: translateY(0) rotate(0); }
  100% { transform: translateY(-118vh) rotate(220deg); }
}

/* cursor sparkles */
.spark {
  position: fixed;
  z-index: 120;
  pointer-events: none;
  transform: translate(-50%, -50%);
  font-size: 15px;
  animation: sparkAnim 0.7s ease-out forwards;
}
@keyframes sparkAnim {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), -190%) scale(0.4); }
}

/* confetti canvas — kept ABOVE the finale modal (z-index 80) so the burst is
   visible AND, crucially, so it isn't behind the modal's backdrop-filter, which
   would otherwise force an expensive full-screen blur recompute every frame. */
#fx { position: fixed; inset: 0; z-index: 90; pointer-events: none; }

/* ---------------- Finale modal ---------------- */
#finale {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(91, 58, 72, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease;
}
#finale.show { opacity: 1; visibility: visible; }
.finale__card {
  background: linear-gradient(180deg, #fff, #fff4fa);
  border-radius: 28px;
  max-width: 440px;
  width: 100%;
  padding: 26px 24px 24px;
  text-align: center;
  box-shadow: 0 30px 60px rgba(226, 58, 89, 0.35);
  border: 4px solid #fff;
  transform: translateY(18px) scale(0.95);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.25, 1);
}
#finale.show .finale__card { transform: none; }
.finale__kitty .kitty { width: 116px; margin: 0 auto 4px; }
.finale__title {
  font-family: "Pacifico", cursive;
  color: var(--cherry);
  font-size: 1.85rem;
  margin: 0.3em 0 0.2em;
}
.finale__msg {
  font-family: "Baloo 2", sans-serif;
  font-weight: 600;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 0;
}
.finale__actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

/* ---------------- Reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
  html { scroll-behavior: auto; }
  .card__inner { transition: transform 0.25s ease; }
  .floaty { display: none; }
}
