@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,400&family=JetBrains+Mono:wght@400;500&family=Caveat:wght@500;600&display=swap');

:root {
  --term-bg: #2b2524;
  --term-surface: #403331;
  --term-accent: #b9785e;
  --term-text: #f3e5d6;
  --term-glow: #e0a27e;

  --main-bg: #faf3ea;
  --main-surface: #fff9f2;
  --main-accent: #e8829f;
  --main-accent-deep: #d1637f;
  --main-text: #3a2a35;

  --font-serif: 'Fraunces', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --font-hand: 'Caveat', cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--font-mono);
}

body {
  background-color: var(--term-bg);
  background-image:
    linear-gradient(rgba(224, 162, 126, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(224, 162, 126, 0.055) 1px, transparent 1px),
    radial-gradient(circle at 50% 45%, rgba(121, 78, 62, 0.34), transparent 58%);
  background-size: 32px 32px, 32px 32px, auto;
  color: var(--term-text);
  transition: background-color 0.9s ease, color 0.9s ease;
  overflow-x: hidden;
}

body.main-active {
  background: var(--main-bg);
  color: var(--main-text);
}

.scene { display: none; }
.scene.active { display: block; }

/* ================= SCENE 1: TERMINAL ================= */
#scene-terminal.active {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 6vh 6vw;
}

.terminal-box {
  width: 100%;
  max-width: 640px;
  background: linear-gradient(145deg, rgba(75, 57, 51, 0.97), rgba(40, 34, 33, 0.97));
  border: 1px solid rgba(224, 162, 126, 0.34);
  border-radius: 12px;
  padding: clamp(16px, 4vw, 32px);
  min-height: 300px;
  box-shadow: 0 20px 70px rgba(28, 19, 16, 0.42), 0 0 40px rgba(185, 120, 94, 0.14);
}

.terminal-guide {
  margin-top: 20px;
  padding: 10px 12px;
  border-left: 2px solid var(--term-glow);
  background: rgba(224, 162, 126, 0.1);
  color: rgba(243, 229, 214, 0.8);
  font-size: 12px;
  line-height: 1.6;
}

.terminal-line {
  font-size: clamp(13px, 2.4vw, 15px);
  line-height: 1.7;
  color: var(--term-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal-line.dim { color: rgba(243, 229, 214, 0.58); }
.terminal-line.accent { color: var(--term-glow); }

.terminal-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.terminal-prompt {
  color: var(--term-glow);
  font-size: clamp(13px, 2.4vw, 15px);
  white-space: nowrap;
}

#terminal-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--term-text);
  font-family: var(--font-mono);
  font-size: clamp(13px, 2.4vw, 15px);
  caret-color: var(--term-glow);
}

/* ================= SCENE 2: MAIN ================= */
#scene-main.active {
  display: block;
  position: relative;
  overflow: hidden;
}

/* atmospheric background photo — fixed, full-bleed, faded in with the scene */
#main-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  background-color: var(--main-bg);
  background-image: url('assets/bg/main-bg.jpg');
  background-size: cover;
  background-position: center 55%;
  background-attachment: fixed;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 1.4s ease;
}
body.main-active #main-bg { opacity: 1; }

#main-overlay {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background: linear-gradient(180deg,
    rgba(20, 14, 18, 0.30) 0%,
    rgba(20, 14, 18, 0.18) 45%,
    rgba(20, 14, 18, 0.42) 100%);
  opacity: 0;
  transition: opacity 1.4s ease;
}
body.main-active #main-overlay { opacity: 1; }

/* atmospheric background glows — ties back to the terminal's purple while
   settling into the cream/pink world */
.glow-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: -1;
  opacity: 0;
  transition: opacity 1.4s ease;
}
body.main-active .glow-orb { opacity: 1; }
.orb-1 {
  width: 46vw; height: 46vw;
  max-width: 480px; max-height: 480px;
  background: radial-gradient(circle, rgba(156, 126, 219, 0.18) 0%, transparent 70%);
  top: -10%; left: -10%;
}
.orb-2 {
  width: 40vw; height: 40vw;
  max-width: 420px; max-height: 420px;
  background: radial-gradient(circle, rgba(232, 130, 159, 0.22) 0%, transparent 70%);
  bottom: -5%; right: -8%;
}
.orb-3 {
  width: 30vw; height: 30vw;
  max-width: 320px; max-height: 320px;
  background: radial-gradient(circle, rgba(244, 201, 161, 0.22) 0%, transparent 70%);
  top: 40%; left: 60%;
}

/* falling flowers */
#flower-fall-container {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  display: none;
}
body.main-active #flower-fall-container { display: block; }

.falling-flower {
  position: absolute;
  top: -60px;
  will-change: transform, opacity;
  animation: flower-fall linear infinite;
  filter: drop-shadow(0 2px 3px rgba(58, 42, 53, 0.2));
}
@keyframes flower-fall {
  0%   { transform: translateY(0) translateX(0) rotate(0deg); opacity: 0; }
  8%   { opacity: 0.9; }
  50%  { transform: translateY(55vh) translateX(24px) rotate(180deg); }
  92%  { opacity: 0.9; }
  100% { transform: translateY(112vh) translateX(-18px) rotate(360deg); opacity: 0; }
}

/* butterflies */
.butterfly {
  position: fixed;
  font-size: 1.4rem;
  z-index: -1;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(58, 42, 53, 0.3));
  opacity: 0;
  transition: opacity 1.4s ease;
  animation: flutter-move linear infinite, flutter-wing 0.6s ease-in-out infinite alternate;
}
body.main-active .butterfly { opacity: 1; }
.butterfly.b1 { top: 18%; left: -5%; animation-duration: 26s, 0.5s; }
.butterfly.b2 { top: 55%; left: -8%; animation-duration: 34s, 0.7s; animation-delay: 4s, 0s; }
.butterfly.b3 { top: 75%; left: -6%; animation-duration: 30s, 0.55s; animation-delay: 12s, 0s; }
@keyframes flutter-move {
  0%   { transform: translate(0, 0) rotate(0deg); }
  25%  { transform: translate(28vw, -6vh) rotate(6deg); }
  50%  { transform: translate(55vw, 4vh) rotate(-4deg); }
  75%  { transform: translate(80vw, -8vh) rotate(5deg); }
  100% { transform: translate(115vw, 2vh) rotate(0deg); }
}
@keyframes flutter-wing {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0.75); }
}

/* blooming flowers (hero decoration) */
.bloom-flower {
  position: absolute;
  font-size: 3.2rem;
  line-height: 1;
  pointer-events: none;
  z-index: 0;
  filter: drop-shadow(0 4px 10px rgba(58, 42, 53, 0.25));
  animation: bloom-pulse 5s ease-in-out infinite;
  transform-origin: center bottom;
}
@keyframes bloom-pulse {
  0%, 100% { transform: scale(0.55); opacity: 0.55; }
  45%      { transform: scale(1);    opacity: 1; }
  55%      { transform: scale(1);    opacity: 1; }
}
.bloom-flower.f1 { top: 2%; left: 4%; font-size: 2.6rem; }
.bloom-flower.f2 { top: 6%; right: 6%; font-size: 3.2rem; animation-delay: 1.6s; }

.main-section {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 10vh 6vw 4vh;
  text-align: center;
  position: relative;
  z-index: 2;
}

#fireworks-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.hero-eyebrow {
  position: relative;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(255, 250, 240, 0.85);
  margin-bottom: 18px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.hero-title {
  position: relative;
  z-index: 2;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(32px, 7vw, 54px);
  color: #fbf3e2;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45), 0 0 40px rgba(0, 0, 0, 0.25);
  margin: 0 0 16px;
  line-height: 1.1;
}

.hero-divider {
  position: relative;
  z-index: 2;
  width: 56px;
  height: 1px;
  background: linear-gradient(90deg, transparent, #fbf3e2, transparent);
  margin: 0 auto 20px;
  opacity: 0.7;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

.hero-subtitle {
  position: relative;
  z-index: 2;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(15px, 2.6vw, 19px);
  color: #fbf3e2;
  opacity: 0.92;
  max-width: 520px;
  margin: 0 auto;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7), 0 3px 10px rgba(0, 0, 0, 0.5);
}

/* light surface for the letter paper */
.glass-card {
  background: rgba(255, 249, 242, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 10px 24px rgba(58, 42, 53, 0.16);
}

/* birthday countdown — direct on photo, glowing numbers (no card) */
#birthday-timer {
  position: relative;
  z-index: 2;
  margin-top: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.countdown-caption {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 250, 240, 0.85);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.countdown-numbers {
  display: flex;
  gap: clamp(14px, 3.6vw, 26px);
  justify-content: center;
}

.countdown-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
}

.countdown-value {
  font-family: var(--font-mono);
  font-size: clamp(24px, 4.6vw, 36px);
  font-weight: 500;
  color: #fbf3e2;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5), 0 0 20px rgba(232, 130, 159, 0.4);
}

.countdown-unit-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255, 250, 240, 0.8);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}

.section-eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255, 250, 240, 0.85);
  margin-bottom: 10px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.section-heading {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(22px, 4.4vw, 30px);
  color: #f6d3d6;
  margin-bottom: 32px;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
}

/* gallery */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: clamp(16px, 3vw, 28px);
}

.polaroid {
  background: var(--main-surface);
  padding: 10px 10px 24px;
  border-radius: 4px;
  box-shadow: 0 8px 22px rgba(58, 42, 53, 0.16);
  cursor: pointer;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  position: relative;
}

.polaroid::after {
  content: '✦';
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 12px;
  color: var(--main-accent-deep);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.polaroid:nth-child(1) { --tilt: -3deg; }
.polaroid:nth-child(2) { --tilt: 2deg; }
.polaroid:nth-child(3) { --tilt: -2deg; }
.polaroid:nth-child(4) { --tilt: 3deg; }

.polaroid:hover {
  transform: rotate(0deg) scale(1.04) translateY(-4px);
  box-shadow: 0 18px 34px rgba(58, 42, 53, 0.24);
}
.polaroid:hover::after { opacity: 1; }

.polaroid img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
  border-radius: 2px;
}

.polaroid-caption {
  font-family: var(--font-hand);
  color: var(--main-text);
  font-size: 18px;
  text-align: center;
  margin-top: 10px;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 10, 20, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 5vw;
}

.lightbox-overlay.visible { display: flex; }

.lightbox-overlay img {
  max-width: 90vw;
  max-height: 80vh;
  border-radius: 6px;
}

/* letter */
#scene-main .envelope-wrap {
  width: min(88vw, 420px);
  margin: 0 auto;
  cursor: pointer;
  position: relative;
}

#letter-section {
  padding-bottom: clamp(24vh, 32vh, 320px);
}

.envelope-label {
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--main-accent-deep);
  margin-bottom: 14px;
}

.envelope {
  position: relative;
  width: 100%;
  aspect-ratio: 1.55;
  background: #b97961;
  border: 1px solid rgba(255, 249, 242, 0.45);
  border-radius: 10px;
  box-shadow: 0 16px 28px rgba(38, 25, 33, 0.22);
  overflow: hidden;
  z-index: 2;
  transition: transform 0.4s ease, opacity 0.4s ease;
}

.envelope-back,
.envelope-letter,
.envelope-flap {
  position: absolute;
}

.envelope-back {
  inset: 0;
  background: #ead8bd;
}

.envelope-letter {
  top: 10%;
  left: 9%;
  width: 82%;
  height: 76%;
  border-radius: 4px 4px 2px 2px;
  background: #fffaf0;
  box-shadow: 0 3px 8px rgba(58, 42, 53, 0.12);
  transform: translateY(28%);
  transition: transform 0.45s ease;
}

.envelope-flap {
  top: 0;
  left: 0;
  width: 100%;
  height: 62%;
  background: #c98968;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transition: clip-path 0.45s ease, opacity 0.45s ease;
}

.envelope-front {
  position: absolute;
  inset: 32% 0 0;
  background: #a96752;
  clip-path: polygon(0 0, 50% 48%, 100% 0, 100% 100%, 0 100%);
  z-index: 3;
}

.envelope-seal {
  position: absolute;
  left: 50%;
  top: 53%;
  z-index: 4;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #d6ad69;
  color: #744936;
  font-size: 16px;
  box-shadow: 0 3px 8px rgba(58, 42, 53, 0.18);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.envelope-wrap.open .envelope-flap {
  clip-path: polygon(0 0, 100% 0, 100% 10%, 0 10%);
  opacity: 0.5;
}

.envelope-wrap.open .envelope-letter {
  transform: translateY(-8%);
}

.envelope-wrap.open .envelope-seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.7);
}

.envelope-wrap.open .envelope {
  transform: scale(0.88);
  opacity: 0.38;
}

.letter-hint {
  color: var(--main-text);
  opacity: 0.68;
  font-size: 12px;
  margin-top: 14px;
  max-height: 18px;
  transition: opacity 0.2s ease, max-height 0.2s ease, margin 0.2s ease;
}

.envelope-wrap.open .letter-hint {
  max-height: 0;
  margin: 0;
  opacity: 0;
}

.letter-paper {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(88vw, 480px);
  box-sizing: border-box;
  color: var(--main-text);
  border-radius: 4px;
  padding: clamp(20px, 4vw, 36px);
  font-family: var(--font-serif);
  font-size: clamp(14px, 2.4vw, 16px);
  line-height: 1.7;
  text-align: justify;
  opacity: 0;
  max-height: min(82vh, 680px);
  overflow-y: auto;
  z-index: 5;
  transform: translate(-50%, -50%) scale(0.72);
  transform-origin: center center;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s ease;
}

.letter-paper.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

.letter-paper p { margin: 0 0 16px; }

.letter-close {
  display: block;
  margin: 0 0 18px auto;
  padding: 5px 0;
  border: 0;
  background: transparent;
  color: var(--main-accent-deep);
  font-family: var(--font-serif);
  font-size: 12px;
  cursor: pointer;
  opacity: 0.72;
}

.letter-close:hover,
.letter-close:focus-visible {
  opacity: 1;
  text-decoration: underline;
}

.letter-closing {
  font-style: italic;
  color: var(--main-accent-deep);
  margin-top: 24px;
}

.letter-signature {
  text-align: right;
  font-family: var(--font-hand);
  font-size: 24px;
  margin-top: 12px;
  padding-bottom: 4px;
}

/* ---------------- mute button ---------------- */
#mute-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 50;
  background: transparent;
  border: 1px solid transparent;
  color: var(--term-text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
}

body.main-active #mute-btn {
  background: transparent;
  border-color: transparent;
  color: var(--main-accent-deep);
  box-shadow: none;
}

@media (max-width: 480px) {
  .main-section { padding: 8vh 5vw 3vh; }
  .polaroid img { height: 130px; }

  .letter-paper {
    width: min(92vw, 480px);
    padding: 20px 22px;
    font-size: 15px;
    line-height: 1.65;
  }
}
