/* ===========================================================================
   Happy Father's Day, Dad — styles
   Mobile-first. Cinematic dusk palette inside; warm stationery on the card.
   =========================================================================== */

:root {
  --ink:        #0b1020;
  --ink-2:      #15102a;
  --plum:       #2a1c3a;
  --wine:       #3a2230;
  --cream:      #f7efe3;
  --cream-dim:  rgba(247, 239, 227, 0.72);
  --cream-faint:rgba(247, 239, 227, 0.45);
  --gold:       #e8b873;
  --gold-bright:#ffdca6;
  --paper:      #f3e7d2;
  --paper-2:    #e8d6b6;
  --card-ink:   #43342a;

  --serif: "Iowan Old Style", "Palatino Linotype", "Palatino", "Georgia", "Times New Roman", serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

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

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

html, body { height: 100%; }

body {
  font-family: var(--sans);
  color: var(--cream);
  background:
    radial-gradient(120% 90% at 50% -10%, #241834 0%, transparent 55%),
    radial-gradient(120% 120% at 80% 110%, #3a2231 0%, transparent 50%),
    linear-gradient(160deg, #0b1020 0%, #15102a 55%, #1c1430 100%);
  background-attachment: fixed;
  overflow: hidden;
  position: fixed;
  inset: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ---- Background FX ------------------------------------------------------- */
#fx {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: 1;
  pointer-events: none;
}

#grain {
  position: fixed; inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- The montage stage --------------------------------------------------- */
#stage {
  position: fixed; inset: 0;
  height: 100vh; height: 100dvh;
  z-index: 2;
  opacity: 0;
  visibility: hidden;
  transition: opacity 1s var(--ease);
}
body.is-open #stage { opacity: 1; visibility: visible; }

.photo-layer {
  position: absolute; inset: 0;
  opacity: 0;
  transform-origin: center;
  will-change: opacity, transform, filter;
}

.photo-layer .photo-bg {
  position: absolute; inset: -12%;
  background-size: cover;
  background-position: center;
  filter: blur(34px) brightness(0.45) saturate(1.25);
  transform: scale(1.18);
}
.photo-layer .photo-fg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  transform-origin: center;
  will-change: transform;
  filter: drop-shadow(0 18px 44px rgba(0, 0, 0, 0.55));
}

#vignette {
  position: absolute; inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    radial-gradient(130% 100% at 50% 38%, transparent 52%, rgba(7, 8, 18, 0.72) 100%),
    linear-gradient(to bottom, rgba(7, 8, 18, 0.35) 0%, transparent 22%, transparent 62%, rgba(7, 8, 18, 0.78) 100%);
}

/* ---- Overlay text (caption / chapter / beat) ----------------------------- */
.overlay-text { position: absolute; z-index: 4; pointer-events: none; }

#caption {
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 6vh);
  text-align: center;
  padding: 0 8vw;
  font-family: var(--sans);
  font-size: clamp(0.95rem, 4.4vw, 1.4rem);
  letter-spacing: 0.01em;
  color: var(--cream);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.85);
  opacity: 0;
  transform: translateY(14px);
}
#caption span {
  display: inline-block;
  background: rgba(8, 9, 18, 0.46);
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
  padding: 0.4em 1.05em;
  border-radius: 999px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
}
#caption.show { animation: captionIn 0.7s var(--ease) forwards; }
#caption.hide { animation: captionOut 0.5s var(--ease) forwards; }

#chapter {
  left: 0; right: 0;
  top: auto; bottom: 19%;          /* lower third — clear of faces */
  text-align: center;
  padding: 0.7em 8vw;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.8rem, 9.5vw, 3.6rem);
  font-weight: 500;
  color: var(--cream);
  letter-spacing: 0.01em;
  /* layered shadow keeps it legible on light photos without a visible box */
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 2px 12px rgba(0, 0, 0, 0.88), 0 4px 44px rgba(0, 0, 0, 0.6);
  opacity: 0;
}
#chapter .chapter-kicker {
  display: block;
  font-family: var(--sans);
  font-style: normal;
  font-size: clamp(0.7rem, 3.2vw, 0.95rem);
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.7em;
  padding-left: 0.42em;
}

/* Beats — full-screen text moments */
#beat {
  inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 0 9vw;
  gap: 0.35em;
  opacity: 0;
}
#beat .beat-num {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 0.9;
  font-size: clamp(6rem, 42vw, 18rem);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 30px rgba(232, 184, 115, 0.3));
}
#beat .beat-sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.2rem, 6vw, 2.2rem);
  color: var(--cream);
}
#beat .beat-kicker {
  font-family: var(--sans);
  letter-spacing: 0.4em; text-transform: uppercase;
  font-size: clamp(0.7rem, 3.4vw, 1rem);
  color: var(--gold);
}
#beat .beat-line {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 8vw, 3rem);
  color: var(--cream);
  line-height: 1.15;
}
#beat .beat-title {
  font-family: var(--serif);
  font-size: clamp(2rem, 10vw, 3.6rem);
  color: var(--cream);
  line-height: 1.1;
}
#beat .beat-sign {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.2rem, 6vw, 2rem);
  color: var(--gold-bright);
  margin-top: 0.5em;
}

/* progress hairline */
#progress {
  position: absolute; z-index: 5;
  left: 0; right: 0;
  top: env(safe-area-inset-top, 0px);
  height: 2px;
  background: rgba(255, 255, 255, 0.12);
  opacity: 0;
  transition: opacity 0.6s;
}
body.is-open #progress { opacity: 1; }
#progress span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  box-shadow: 0 0 12px rgba(232, 184, 115, 0.6);
}

#lingerHint {
  position: absolute; z-index: 5;
  left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 18px);
  font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--cream-dim);
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 14px; border-radius: 999px;
  backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.3s;
}
#lingerHint.show { opacity: 1; }

/* ===========================================================================
   The greeting card (cover)
   =========================================================================== */
#cover {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4vh;
  padding: max(4vh, env(safe-area-inset-top)) 6vw max(4vh, env(safe-area-inset-bottom));
  transition: opacity 0.8s var(--ease);
}
body.is-open #cover { opacity: 0; pointer-events: none; }

.cover-scene {
  perspective: 1600px;
  perspective-origin: 50% 40%;
  width: min(86vw, 340px);
  aspect-ratio: 5 / 7;
  position: relative;
}

.gcard {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  animation: cardFloat 7s ease-in-out infinite;
}

/* inside-left page (revealed when the front opens) */
.gcard__inside {
  position: absolute; inset: 0;
  border-radius: 14px;
  background:
    linear-gradient(125deg, #fbf3e3, #ecdcc0);
  box-shadow: inset 0 0 60px rgba(120, 86, 44, 0.18);
  display: flex; align-items: center; justify-content: center;
  color: #b59161;
  font-family: var(--serif); font-style: italic;
  font-size: 1rem;
}
.gcard__inside-text { opacity: 0.7; }

/* front cover — swings open on the left hinge */
.gcard__front {
  position: absolute; inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  border-radius: 14px;
  background:
    radial-gradient(140% 100% at 50% 0%, #fbf1dd 0%, var(--paper) 45%, var(--paper-2) 100%);
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(160, 120, 70, 0.35),
    inset 0 0 0 7px rgba(255, 255, 255, 0.35),
    inset 0 0 0 8px rgba(160, 120, 70, 0.22);
  will-change: transform;
}
.gcard__face {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.5rem;
  padding: 12% 9%;
  text-align: center;
  color: var(--card-ink);
}
.gcard__rule {
  width: 46px; height: 2px;
  background: linear-gradient(90deg, transparent, #b88a4e, transparent);
}
.gcard__rule.top { margin-bottom: 0.4rem; }
.gcard__rule.bottom { margin-top: 0.4rem; }

.eyebrow {
  font-family: var(--sans);
  font-size: 0.66rem; letter-spacing: 0.34em; text-transform: uppercase;
  color: #a9803f;
  padding-left: 0.34em;
}
.gcard__title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.5rem, 7.4vw, 1.9rem);
  line-height: 1.12;
  /* gold-foil lettering with a slow shimmer sweep */
  background: linear-gradient(100deg,
    #7c4f24 0%, #b9863a 22%, #f0d089 44%, #fff4d8 50%, #f0d089 56%, #b9863a 78%, #7c4f24 100%);
  background-size: 240% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  filter: drop-shadow(0 1px 1px rgba(120, 80, 30, 0.35));
  animation: foilShine 5.5s linear infinite;
}

/* music-reactive warm glow */
#beatGlow {
  position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: 0;
  background: radial-gradient(62% 52% at 50% 56%,
    rgba(255, 220, 166, 0.55), rgba(232, 184, 115, 0.14) 45%, transparent 74%);
  mix-blend-mode: screen;
}
#leak {
  position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: 0;
  background: linear-gradient(118deg, rgba(255, 240, 212, 0) 36%, rgba(255, 236, 205, 0.82) 50%, rgba(255, 240, 212, 0) 64%);
  mix-blend-mode: screen;
}

/* twinkling foil sparkles on the cover */
.sparkle {
  position: absolute; width: 11px; height: 11px;
  transform: translate(-50%, -50%); border-radius: 50%; opacity: 0;
  background: radial-gradient(circle, #fff6e6 0%, #e8b873 42%, transparent 70%);
  filter: drop-shadow(0 0 5px rgba(232, 184, 115, 0.85));
  animation: twinkle 2.8s ease-in-out infinite;
  pointer-events: none;
}
.gcard__sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: #936f3f;
}

/* wax-seal open button */
.seal {
  position: relative;
  width: 74px; height: 74px;
  margin-top: 0.4rem;
  border: none; cursor: pointer;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #c0532f, #8c2f1c 70%, #6f2114);
  color: #f7d9c4;
  font-family: var(--serif); font-weight: 700;
  font-size: 1.5rem; letter-spacing: 0.04em;
  box-shadow: 0 8px 20px rgba(110, 33, 20, 0.5), inset 0 2px 6px rgba(255, 255, 255, 0.25), inset 0 -6px 12px rgba(0, 0, 0, 0.35);
  display: grid; place-items: center;
  animation: sealPulse 2.4s ease-in-out infinite;
  transition: transform 0.2s var(--ease);
}
.seal:active { transform: scale(0.94); }
.seal__ring {
  position: absolute; inset: 7px;
  border-radius: 50%;
  border: 1.5px dashed rgba(247, 217, 196, 0.55);
}
.seal__mono { position: relative; z-index: 1; }

.gcard__cta {
  font-family: var(--sans);
  font-size: 0.74rem; letter-spacing: 0.26em; text-transform: uppercase;
  color: #a9803f;
  margin-top: 0.2rem;
  animation: ctaBlink 2.4s ease-in-out infinite;
}

.cover-hint {
  font-family: var(--sans);
  font-size: 0.8rem; letter-spacing: 0.06em;
  color: var(--cream-dim);
}
.cover-loading {
  position: absolute;
  bottom: max(2.4vh, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 0.55rem;
  font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--cream-faint);
  transition: opacity 0.5s;
}
.cover-loading i {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(247, 239, 227, 0.25);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
.cover-loading.done { opacity: 0; }

/* ---- Controls / end actions --------------------------------------------- */
#controls {
  position: fixed; z-index: 11;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 14px);
}
#muteBtn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.35);
  color: var(--cream); font-size: 1.05rem; cursor: pointer;
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  transition: transform 0.2s, opacity 0.4s;
}
#muteBtn:active { transform: scale(0.9); }

#endActions {
  position: fixed; z-index: 11;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 5vh);
  opacity: 0; transition: opacity 0.8s var(--ease) 0.3s;
}
#endActions.show { opacity: 1; }
#replayBtn {
  font-family: var(--sans);
  font-size: 0.86rem; letter-spacing: 0.14em;
  color: var(--cream);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(232, 184, 115, 0.5);
  border-radius: 999px;
  padding: 12px 26px; cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.2s, background 0.3s;
}
#replayBtn:hover { background: rgba(232, 184, 115, 0.16); }
#replayBtn:active { transform: scale(0.95); }

[hidden] { display: none !important; }

/* ---- Keyframes ----------------------------------------------------------- */
@keyframes captionIn  { to { opacity: 1; transform: translateY(0); } }
@keyframes captionOut { to { opacity: 0; transform: translateY(-10px); } }
@keyframes spin       { to { transform: rotate(360deg); } }
@keyframes sealPulse  {
  0%, 100% { box-shadow: 0 8px 20px rgba(110,33,20,0.5), inset 0 2px 6px rgba(255,255,255,0.25), inset 0 -6px 12px rgba(0,0,0,0.35), 0 0 0 0 rgba(232,184,115,0.4); }
  50%      { box-shadow: 0 8px 20px rgba(110,33,20,0.5), inset 0 2px 6px rgba(255,255,255,0.25), inset 0 -6px 12px rgba(0,0,0,0.35), 0 0 0 14px rgba(232,184,115,0); }
}
@keyframes ctaBlink   { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@keyframes cardFloat  {
  0%, 100% { transform: translateY(0) rotateZ(-0.4deg); }
  50%      { transform: translateY(-10px) rotateZ(0.4deg); }
}
@keyframes foilShine  { 0% { background-position: 140% 0; } 100% { background-position: -40% 0; } }
@keyframes twinkle    {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  50%      { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---- Desktop polish ------------------------------------------------------ */
@media (min-width: 900px) {
  .cover-scene { width: 360px; }
  #caption { bottom: calc(env(safe-area-inset-bottom, 0px) + 8vh); }
  .photo-layer .photo-fg {
    /* keep portraits from feeling tiny on wide screens — gentle inset */
    padding: 3vh 0;
  }
}

/* ---- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .gcard,
  .seal,
  .gcard__cta,
  .gcard__title,
  .sparkle { animation: none !important; }
  .gcard__title { -webkit-text-fill-color: #6b4a22; color: #6b4a22; }
  .photo-layer .photo-fg { transition: none !important; }
  #caption.show { animation: none; opacity: 1; transform: none; }
}
