/* ============================================================
   Grei-vee — Gracie's birthday letter
   Two phases:
     theme-bw   = a plain draft / envelope ("not alive yet")
     theme-pink = a warm handwritten letter on paper
   Phone-first, single screen, no scroll.
   ============================================================ */

:root {
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---- Black & white (the plain "draft") ---- */
body.theme-bw {
  --bg: #0c0c0c;
  --bg-2: #161616;
  --fg: #f1f1f1;
  --muted: #8c8c8c;
  --accent: #ffffff;
  --accent-strong: #ffffff;
  --btn-bg: #1b1b1b;
  --btn-fg: #f1f1f1;
  --btn-border: #3a3a3a;
  --paper: transparent;
  --font: "JetBrains Mono", ui-monospace, monospace;
  --font-hand: "JetBrains Mono", ui-monospace, monospace;
  --font-script: "JetBrains Mono", ui-monospace, monospace;
  --line-weight: 400;
}

/* ---- Pink & white (the warm letter) ---- */
body.theme-pink {
  --bg: #fff2f7;
  --bg-2: #ffe9f1;
  --fg: #614453;
  --muted: #bf93a6;
  --accent: #ff8fb6;
  --accent-strong: #d96690;
  --em: #e25b89;
  --btn-bg: #ffffff;
  --btn-fg: #cf5f88;
  --btn-border: #ffc7dc;
  --paper: #fffaf4;
  --font: "Quicksand", system-ui, sans-serif;
  --font-hand: "Caveat", "Quicksand", cursive;
  --font-script: "Dancing Script", "Caveat", cursive;
  --line-weight: 500;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  transition: background 1.2s var(--ease), color 1.2s var(--ease);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  user-select: none;
}

/* warm light that blooms in with the pink letter */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.4s var(--ease);
  background:
    radial-gradient(70% 55% at 18% 12%, rgba(255, 196, 222, 0.75), transparent 70%),
    radial-gradient(60% 50% at 85% 85%, rgba(255, 222, 196, 0.6), transparent 72%),
    radial-gradient(50% 40% at 60% 40%, rgba(255, 235, 245, 0.5), transparent 75%);
  z-index: 0;
}
body.theme-pink::before {
  opacity: 1;
}

/* dramatic glow for the birthday climax */
body.dramatic::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(60% 50% at 50% 45%, rgba(255, 170, 205, 0.5), transparent 70%);
  animation: glowpulse 3.4s ease-in-out infinite;
}
@keyframes glowpulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.95; }
}

/* ============================================================
   Stage + layers
   ============================================================ */
#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.layer {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(env(safe-area-inset-top) + 26px)
    calc(env(safe-area-inset-right) + 22px)
    calc(env(safe-area-inset-bottom) + 26px)
    calc(env(safe-area-inset-left) + 22px);
}
.layer.is-active {
  display: flex;
}

/* ============================================================
   Gate
   ============================================================ */
.gate-inner {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}
.gate-q {
  font-size: clamp(1.05rem, 5vw, 1.4rem);
  letter-spacing: 0.5px;
  line-height: 1.5;
  color: var(--fg);
}
#gate-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  align-items: center;
}
/* underline-only input + inline arrow — feels like filling in a blank */
.gate-field {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(280px, 90%);
  border-bottom: 1.5px solid rgba(255, 255, 255, 0.3);
  padding-bottom: 10px;
  transition: border-color 0.25s var(--ease);
}
.gate-field:focus-within {
  border-bottom-color: rgba(255, 255, 255, 0.65);
}
#code-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  text-align: center;
  padding: 4px 0;
  outline: none;
  letter-spacing: 3px;
}
#code-input::placeholder {
  color: rgba(255, 255, 255, 0.2);
  letter-spacing: 1px;
  font-size: 0.9rem;
}
#gate-submit {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.35);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s var(--ease);
}
#gate-submit:hover {
  color: rgba(255, 255, 255, 0.75);
}
#gate-msg {
  min-height: 1.4em;
  font-size: 0.95rem;
  color: var(--muted);
  letter-spacing: 0.3px;
}
#gate-msg.error {
  color: #ff7a7a;
}
.gate-inner.shake {
  animation: shake 0.42s var(--ease);
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ============================================================
   The letter card
   ============================================================ */
#experience {
  gap: 0;
}
.letter-card {
  position: relative;
  width: min(580px, 100%);
  min-height: min(62vh, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: clamp(26px, 6vw, 40px) clamp(22px, 5vw, 34px);
  border-radius: 24px;
  background: transparent;
  transition: background 1.2s var(--ease), box-shadow 1.2s var(--ease),
    border-color 1.2s var(--ease);
}
/* paper appears only once the letter has bloomed */
body.theme-pink .letter-card {
  background-color: var(--paper);
  background-image:
    radial-gradient(rgba(214, 140, 170, 0.05) 1px, transparent 1px);
  background-size: 16px 16px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 22px 60px rgba(214, 122, 160, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
body.theme-pink.dramatic .letter-card {
  box-shadow: 0 0 70px rgba(255, 150, 190, 0.55),
    0 22px 60px rgba(214, 122, 160, 0.3);
}

/* little corner doodles (pink phase only) */
.card-corner {
  position: absolute;
  font-size: 20px;
  opacity: 0;
  transition: opacity 1.2s var(--ease);
  pointer-events: none;
}
body.theme-pink .card-corner {
  opacity: 0.55;
}
.card-corner.tl { top: 10px; left: 14px; transform: rotate(-12deg); }
.card-corner.tr { top: 10px; right: 14px; transform: rotate(10deg); }
.card-corner.bl { bottom: 10px; left: 14px; transform: rotate(8deg); }
.card-corner.br { bottom: 10px; right: 14px; transform: rotate(-10deg); }
.card-corner.tl::before { content: "🌷"; }
.card-corner.tr::before { content: "🌸"; }
.card-corner.bl::before { content: "✨"; }
.card-corner.br::before { content: "🎀"; }

/* ============================================================
   Visual + lines + controls
   ============================================================ */
.scene-visual {
  height: clamp(96px, 22vh, 170px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(64px, 20vw, 116px);
  line-height: 1;
  filter: drop-shadow(0 10px 22px rgba(180, 90, 130, 0.25));
  margin-bottom: 4px;
}
.scene-visual:empty {
  height: 0;
  margin: 0;
}
/* Fiona's photo — little tilted polaroid */
.scene-visual .cat-pic {
  width: clamp(127px, 34.5vw, 173px);
  height: clamp(127px, 34.5vw, 173px);
  object-fit: cover;
  border-radius: 14px;
  border: 4px solid #fff;
  box-shadow: 0 12px 26px rgba(180, 90, 130, 0.3);
  transform: rotate(-3deg);
}
.scene-visual img {
  width: clamp(74px, 23vw, 134px);
  height: clamp(74px, 23vw, 134px);
  object-fit: contain;
}
.scene-visual .emo {
  display: inline-block;
  transform-origin: center bottom;
}


.scene-lines {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.line {
  font-size: clamp(1.15rem, 5.2vw, 1.5rem);
  font-weight: var(--line-weight);
  line-height: 1.5;
  letter-spacing: 0.2px;
  color: var(--fg);
  opacity: 0; /* revealed by JS */
}
.line.big {
  font-family: var(--font-hand);
  font-size: clamp(2rem, 9vw, 2.9rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--accent-strong);
}
.line.dear {
  font-family: var(--font-script);
  font-size: clamp(2.1rem, 10vw, 3.1rem);
  font-weight: 700;
  color: var(--accent-strong);
  align-self: flex-start;
}
.line.sig {
  font-family: var(--font-script);
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  font-weight: 700;
  color: var(--accent-strong);
  align-self: flex-end;
  margin-top: 4px;
}
.line.muted {
  color: var(--muted);
  font-size: clamp(1rem, 4.4vw, 1.2rem);
}

/* her words, quoted — handwriting + decorative quotation marks */
.line.quote {
  position: relative;
  font-family: var(--font-hand);
  font-size: clamp(1.45rem, 7vw, 2rem);
  font-weight: 600;
  line-height: 1.25;
  color: var(--accent-strong);
  padding: 0 0.2em;
}
.line.quote::before,
.line.quote::after {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.5;
}
.line.quote::before { content: "\201C"; margin-right: 0.03em; }
.line.quote::after { content: "\201D"; margin-left: 0.03em; }

/* emphasis words (color + the JS pop; no underline) */
.em {
  color: var(--em, var(--accent-strong));
  font-weight: 700;
}

/* emotional "swell" — a soft warm halo blooms behind the words and fades */
@keyframes lineglow {
  0% { text-shadow: 0 0 0 rgba(255, 143, 182, 0); }
  40% { text-shadow: 0 0 22px rgba(255, 143, 182, 0.6); }
  100% { text-shadow: 0 0 0 rgba(255, 143, 182, 0); }
}
.line.glow {
  animation: lineglow 1.7s ease-out;
}
body.theme-bw .em {
  color: #fff;
}

/* typewriter */
.tw { white-space: pre-wrap; }
.cursor {
  display: inline-block;
  margin-left: 1px;
  font-weight: 400;
  color: var(--muted);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.scene-controls {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  width: min(520px, 100%);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  font-family: var(--font);
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  padding: 12px 26px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.16s var(--ease), box-shadow 0.25s var(--ease);
  opacity: 0; /* revealed by JS */
}
.btn:active {
  transform: scale(0.94);
}
body.theme-pink .btn {
  font-family: var(--font-hand);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  background: linear-gradient(180deg, #ffffff, #ffeaf2);
  color: var(--accent-strong);
  border: 1.5px solid var(--btn-border);
  box-shadow: 0 8px 18px rgba(255, 143, 182, 0.3);
}
body.theme-pink .btn:hover {
  box-shadow: 0 12px 26px rgba(255, 143, 182, 0.45);
  transform: translateY(-1px);
}
.btn.subtle {
  font-size: 1.05rem;
  padding: 9px 18px;
  background: transparent;
  box-shadow: none;
  border-color: transparent;
  color: var(--muted);
}

/* secondary/muted option — appears below the main button without competing.
   Opacity is controlled by GSAP (fades to 0.65); color carries the "secondary" feel. */
.btn.btn-subtle {
  font-size: 0.8rem;
  padding: 7px 16px;
  box-shadow: none;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
body.theme-pink .btn.btn-subtle {
  font-size: 0.92rem;
  background: transparent;
  box-shadow: none;
  border-color: transparent;
  color: var(--muted);
}

/* "make it you" — the bloom trigger. A grey button with a hint of the color
   that's coming: an animated gradient border + a slow breathing glow. */
.btn.btn-bloom {
  border: 1.5px solid transparent;
  border-radius: 999px;
  padding: 15px 34px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: lowercase;
  color: #f3f3f3;
  /* dark fill (padding-box) + animated grey→pink gradient ring (border-box) */
  background:
    linear-gradient(#141414, #141414) padding-box,
    linear-gradient(110deg, #6a6a6a, #ff8fb6, #ffd2a8, #6a6a6a) border-box;
  background-size: 100% 100%, 240% 100%;
  animation: bloomRing 3.2s linear infinite, bloomBreath 2.8s ease-in-out infinite;
}
.btn.btn-bloom:hover {
  color: #fff;
}
@keyframes bloomRing {
  to { background-position: 0 0, 240% 0; }
}
@keyframes bloomBreath {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 143, 182, 0); }
  50% { box-shadow: 0 0 26px rgba(255, 143, 182, 0.28); }
}

/* mute toggle */
#sound-toggle {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  right: calc(env(safe-area-inset-right) + 12px);
  z-index: 50;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--btn-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: opacity 0.25s var(--ease), transform 0.15s var(--ease),
    background 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
#sound-toggle:hover {
  opacity: 0.95;
}
#sound-toggle:active {
  transform: scale(0.88);
}
body.theme-pink #sound-toggle {
  background: rgba(255, 255, 255, 0.65);
  box-shadow: 0 5px 14px rgba(255, 143, 182, 0.28);
}

.tap-hint {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  left: 0;
  right: 0;
  font-family: var(--font);
  font-size: 0.8rem;
  letter-spacing: 1px;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease);
  text-transform: lowercase;
}
.tap-hint.show {
  opacity: 0.55;
  animation: hintpulse 2.4s ease-in-out infinite;
}
@keyframes hintpulse {
  0%, 100% { opacity: 0.22; }
  50% { opacity: 0.6; }
}

/* ============================================================
   Envelope (opening moment)
   ============================================================ */
.envelope-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}
.envelope-label {
  font-family: var(--font);
  font-size: clamp(1.05rem, 5vw, 1.35rem);
  color: var(--fg);
  letter-spacing: 0.5px;
  opacity: 0;
}
.envelope-hint {
  margin-top: -12px;
  font-family: var(--font);
  font-size: 0.8rem;
  letter-spacing: 1.5px;
  text-transform: lowercase;
  color: var(--muted);
  opacity: 0;
  animation: hintpulse 2.4s ease-in-out infinite;
}
/* handwritten address on the envelope front */
.env-addr {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 18%;
  text-align: center;
  font-family: "Caveat", cursive;
  font-size: 1.5rem;
  color: #5a5a5a;
  transform: rotate(-2deg);
  pointer-events: none;
}
.envelope {
  position: relative;
  width: clamp(190px, 64vw, 250px);
  height: clamp(126px, 42vw, 166px);
  cursor: pointer;
  opacity: 0;
}
.env-base {
  position: absolute;
  inset: 0;
  background: #ededed;
  border-radius: 12px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.env-pocket {
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: 12px;
  background: linear-gradient(180deg, transparent 49.5%, #d8d8d8 50%);
  clip-path: polygon(0 50%, 50% 100%, 100% 50%, 100% 100%, 0 100%);
}
.env-letter {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 14%;
  height: 86%;
  background: #fafafa;
  border-radius: 8px 8px 0 0;
  z-index: 3;
  transition: transform 0.9s var(--ease);
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.12);
}
.env-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 52%;
  background: #e0e0e0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform 0.7s var(--ease), background 0.4s var(--ease);
  z-index: 6;
  backface-visibility: hidden;
}
.env-seal {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 7;
  font-size: 26px;
  transition: opacity 0.3s var(--ease);
}
.envelope.open .env-flap {
  transform: rotateX(180deg);
  z-index: 2;
}
.envelope.open .env-seal {
  opacity: 0;
}
.envelope.open .env-letter {
  transform: translateY(-58%);
}

/* ============================================================
   Siopao mini-interaction
   ============================================================ */
.siopao {
  position: relative;
  font-size: clamp(104px, 34.5vw, 173px);
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s var(--ease);
}
.siopao:active {
  transform: scale(0.9) rotate(-3deg);
}
.bite {
  position: absolute;
  pointer-events: none;
  font-size: 0.4em;
  opacity: 0;
}



/* ============================================================
   Message box
   ============================================================ */
.msg-wrap {
  width: min(460px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}
.msg-wrap textarea {
  width: 100%;
  min-height: 110px;
  resize: none;
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid var(--btn-border);
  border-radius: 16px;
  color: var(--fg);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  padding: 14px 16px;
  outline: none;
  user-select: text;
}
.msg-wrap textarea:focus {
  border-color: var(--accent);
}
.msg-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ============================================================
   Ambient particles
   ============================================================ */
#petals {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0; /* behind the card/text */
  opacity: 0;
  transition: opacity 1.5s var(--ease);
}
body.theme-pink #petals {
  opacity: 1;
}
.petal {
  position: absolute;
  top: -8%;
  font-size: 18px;
  will-change: transform;
  animation: fall linear infinite;
}
@keyframes fall {
  0% { transform: translateY(-10vh) translateX(0) rotate(0deg); opacity: 0; }
  10% { opacity: 0.85; }
  90% { opacity: 0.85; }
  100% { transform: translateY(110vh) translateX(40px) rotate(360deg); opacity: 0; }
}

/* celebratory bursts (hearts/sparkles) — above the card on purpose */
#hearts {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.burst-bit {
  position: absolute;
  will-change: transform, opacity;
  font-size: 22px;
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .petal,
  .tap-hint.show,
  body.dramatic::after,
  .cursor,
  .line.glow,
  .btn.btn-bloom {
    animation: none;
  }
}
