/* ==========================================================================
   The Weaving: styles (mobile first)
   ========================================================================== */

/* Display font: Moistly Vengions (demo, letters A–Z only, free for personal use).
   Anything it lacks, like punctuation, falls back to Cormorant Garamond. */
@font-face {
  font-family: "Moistly Vengions";
  src: url("../assets/fonts/moistly-vengions-demo.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Palette from the ppid site: warm creams, burnt orange, charcoal */
  --cream:       #FBF1E7;
  --soft:        #FAF9F7;
  --accent:      #C65102;
  --accent-deep: #A84302;
  --accent-line: rgba(198, 81, 2, 0.22);
  --text:        #2A2A2A;
  --text-muted:  #5A5A5A;

  --gold:        #E8B33D;  /* kente thread, wax seals, her name */
  --gold-soft:   #FFD98A;
  --paper:       #F7EFDF;  /* letter paper */
  --ink:         #2A1E14;  /* handwriting ink */

  /* The deep orange of the hero and the birthday wish */
  --hero-bg:
    radial-gradient(70% 55% at 50% 58%, #E8761C 0%, rgba(232, 118, 28, 0) 70%),
    linear-gradient(180deg, #C65102 0%, #B44702 60%, #8F3502 100%);

  --pattern-size: 340px;

  /* Frosted glass, used behind text that sits on the pattern */
  --glass-bg: rgba(255, 251, 246, 0.66);
  --glass-border: rgba(255, 255, 255, 0.8);
  --glass-blur: blur(14px) saturate(1.3);
  --glass-shadow: 0 12px 34px -14px rgba(42, 26, 14, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.85);

  --font-script: "Moistly Vengions", "Cormorant Garamond", Garamond, serif;
  --font-poster: "Anton", "Oswald", "Impact", "Arial Narrow", sans-serif;
  --font-label: "Syne", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-serif: "Cormorant Garamond", "Cormorant", Garamond, "Iowan Old Style", "Times New Roman", serif;
  --font-hand: "Kalam", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;

  --ease-out: cubic-bezier(0.22, 0.8, 0.24, 1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* Fine over-under weave, laid over every cloth */
  --weave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='6' height='6'%3E%3Crect width='3' height='1.2' fill='%23fff' fill-opacity='.22'/%3E%3Crect x='3' y='3' width='3' height='1.2' fill='%23fff' fill-opacity='.22'/%3E%3Crect x='3' y='0' width='1.1' height='3' fill='%23000' fill-opacity='.2'/%3E%3Crect x='0' y='3' width='1.1' height='3' fill='%23000' fill-opacity='.2'/%3E%3C/svg%3E");

  /* Paper grain, drawn with SVG noise */
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .22 0 0 0 0 .1 .3 0 0 0 -.06'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--cream);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Petroglyph pattern behind everything, sized to the large viewport so it
   doesn't jump when mobile browser bars show and hide. */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  z-index: -2;
  pointer-events: none;
  background: var(--cream) url("../assets/pattern.svg") 0 0 / var(--pattern-size) var(--pattern-size) repeat;
}

/* Twinkling flecks, over a frosted veil so the pattern reads as texture */
.sky {
  position: fixed;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  z-index: -1;
  pointer-events: none;
  background: rgba(251, 241, 231, 0.45);
  -webkit-backdrop-filter: blur(2.5px);
  backdrop-filter: blur(2.5px);
}

/* Golden confetti, in front of everything but never in the way */
.confetti {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 58;
  pointer-events: none;
}

.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Words that must never break mid-word (see Util.appendWords) */
.fit-word { display: inline-block; white-space: nowrap; }

main {
  position: relative;
  overflow-x: clip;
}

[hidden] { display: none !important; }

/* Gates: until its button is pressed, nothing exists below the hero (or the wish) to scroll to */
html.lock-hero #legend,
html.lock-hero #wish,
html.lock-wish #letters,
html.lock-wish #finale { display: none; }

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.section-label {
  margin: 0;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent);
}
.section-label--light { color: var(--gold-soft); }

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.8rem 1.75rem;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.3s var(--ease-out);
}
.pill-btn:hover { background: var(--accent-deep); }
.pill-btn:active { transform: scale(0.97); }

/* Glass panels behind text that sits on the pattern */
.loom-bar,
.letters-intro,
.finale-lines {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .loom-bar, .letters-intro, .finale-lines { background: rgba(255, 251, 246, 0.94); }
}

/* ---------- Scroll hints ---------- */

.scroll-hint {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 1.25rem + var(--player-space, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  padding: 0.25rem 1rem;
  color: #fff;
  text-decoration: none;
  transition: bottom 0.6s var(--ease-out);
}
.scroll-hint-label {
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  white-space: nowrap;
}
.scroll-hint-track {
  position: relative;
  width: 2px;
  height: 42px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.35);
  overflow: hidden;
}
.scroll-hint-dot {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 14px;
  border-radius: 2px;
  background: currentColor;
  animation: scroll-dot 1.8s var(--ease-out) infinite;
}
.scroll-hint--dark {
  position: relative;
  left: auto;
  bottom: auto;
  transform: none;
  margin: 3rem auto 0;
  width: max-content;
  color: var(--accent-deep);
}
.scroll-hint--dark .scroll-hint-track { background: var(--accent-line); }

/* ---------- Music player (Spotify playlist) ---------- */

.player {
  position: fixed;
  z-index: 35;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 32px);
  width: 320px;
  transform: translateX(-50%);
  border-radius: 14px;
  /* "backwards", not "both": a held animation would override .is-hidden */
  animation: fade-in 0.6s var(--ease-out) backwards;
  transition: opacity 0.32s ease;
}
.player::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 1px rgba(198, 81, 2, 0.5), 0 0 0 10px rgba(198, 81, 2, 0.14), 0 8px 36px rgba(198, 81, 2, 0.25);
  opacity: 0;
  pointer-events: none;
  animation: player-glow 2.8s ease-in-out infinite;
}
.player.is-cornered {
  left: auto;
  right: calc(var(--safe-right) + 24px);
  bottom: calc(var(--safe-bottom) + 24px);
  transform: none;
}
.player.is-settled::before { animation: none; }
/* Hidden, not removed, so the music keeps playing */
.player.is-hidden { opacity: 0; pointer-events: none; }

.player-inner {
  border-radius: inherit;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--accent-line);
  box-shadow: 0 6px 32px rgba(42, 26, 14, 0.16);
}
.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 6px 14px;
  border-bottom: 1px solid var(--accent-line);
  background: var(--soft);
}
.player-note { flex: none; width: 16px; height: 16px; fill: var(--accent); }
.player-text { flex: 1; min-width: 0; }
.player-label {
  display: block;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--accent);
}
.player-sub {
  display: block;
  margin-top: 3px;
  font-style: italic;
  font-size: 0.92rem;
  line-height: 1.3;
  color: var(--text-muted);
}
.player-pulse {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.4s ease-in-out infinite;
}
.player.is-settled .player-pulse { animation: none; opacity: 0.35; }
.player-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s;
}
.player-close:hover { color: var(--accent); }
.player-embed iframe { display: block; width: 100%; height: 80px; border: 0; }

.player-mini {
  position: fixed;
  z-index: 35;
  right: calc(var(--safe-right) + 24px);
  bottom: calc(var(--safe-bottom) + 24px);
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 14px rgba(198, 81, 2, 0.18);
  animation: fade-in 0.4s var(--ease-out) both;
  transition: background-color 0.25s, color 0.25s;
}
.player-mini:hover { background: var(--accent); color: #fff; }
.player-mini svg { width: 20px; height: 20px; fill: currentColor; }

@media (max-width: 480px) {
  .player {
    width: calc(100% - 32px - var(--safe-left) - var(--safe-right));
    bottom: calc(var(--safe-bottom) + 16px);
  }
  .player.is-cornered { right: calc(var(--safe-right) + 16px); bottom: calc(var(--safe-bottom) + 16px); }
  .player-mini { right: calc(var(--safe-right) + 16px); bottom: calc(var(--safe-bottom) + 16px); }
}

/* ==========================================================================
   1. Hero
   ========================================================================== */

.hero {
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 560px;
  overflow: hidden;
  isolation: isolate;
  color: #fff;
  background: var(--hero-bg);
}

/* The pattern, recoloured light, drifting behind her */
.hero-pattern {
  position: absolute;
  inset: -10% 0;
  z-index: 0;
  background: rgba(255, 228, 200, 0.55);
  -webkit-mask: url("../assets/pattern.svg") 0 0 / var(--pattern-size) var(--pattern-size) repeat;
  mask: url("../assets/pattern.svg") 0 0 / var(--pattern-size) var(--pattern-size) repeat;
  transform: translateY(calc(var(--p, 0) * 90px));
  pointer-events: none;
}

/* A dark fade along the bottom, so white text stays readable over her blouse */
.hero::after {
  content: "";
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  height: 46%;
  background: linear-gradient(to bottom, rgba(60, 18, 0, 0) 0%, rgba(48, 14, 0, 0.55) 50%, rgba(30, 9, 0, 0.82) 100%);
  pointer-events: none;
}

/* A warm halo behind her head */
.hero-glow {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 34%;
  width: 92vmin;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 210, 140, 0.55) 0%, rgba(255, 190, 110, 0.18) 45%, rgba(255, 190, 110, 0) 68%);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.hero-portrait {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 0;
  width: auto;
  max-width: none;
  /* On phones the photo starts just below the title, so no text crosses her face */
  height: min(calc(100vh - 14.5rem - var(--safe-top)), 165vw);
  height: min(calc(100svh - 14.5rem - var(--safe-top)), 165vw);
  transform: translate(-50%, calc(var(--p, 0) * 14%)) scale(calc(1 + var(--p, 0) * 0.06));
  transform-origin: 50% 100%;
  filter: drop-shadow(0 26px 40px rgba(60, 18, 0, 0.4));
  animation: portrait-rise 1.6s 0.1s var(--ease-out) both;
  pointer-events: none;
}

.hero-kicker {
  position: absolute;
  z-index: 4;
  top: calc(var(--safe-top) + 1.25rem);
  left: calc(var(--safe-left) + 1.25rem);
  right: 1.25rem;
  margin: 0;
  animation: fade-up 1s 0.2s var(--ease-out) both;
}
.hero-kicker span {
  display: block;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}
.hero-kicker strong {
  display: block;
  margin-top: 0.3rem;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  font-size: 1.35rem;
  line-height: 1.15;
}

/* "A story is waiting for you": solid behind her, outline in front of her */
.hero-title {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  top: calc(var(--safe-top) + 5.9rem);
  margin: 0;
  padding: 0 calc(var(--safe-right) + 0.75rem) 0 calc(var(--safe-left) + 0.75rem);
  font-family: var(--font-script);
  font-weight: 400;
  font-size: clamp(2.6rem, 12.6vw, 12rem);
  line-height: 0.92;
  text-align: center;
  color: #fff;
  font-feature-settings: "dlig" 1, "liga" 1;
  transform: translateY(calc(var(--p, 0) * -45%));
  pointer-events: none;
}
.hero-title--outline {
  z-index: 3;
  color: transparent;
  -webkit-text-stroke: 1.2px rgba(255, 255, 255, 0.95);
}

.hero-letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.5em) rotate(-12deg) scale(0.6);
  filter: blur(10px);
}
.hero.is-ready .hero-letter {
  animation: letter-in 1.2s var(--ease-out) forwards;
  animation-delay: calc(0.5s + var(--i) * 55ms);
}
/* After the letters land, a soft golden shimmer runs through them now and then */
.hero.is-ready .hero-title--fill .hero-letter {
  animation:
    letter-in 1.2s calc(0.5s + var(--i) * 55ms) var(--ease-out) forwards,
    letter-shimmer 6s calc(2.6s + var(--i) * 70ms) ease-in-out infinite;
}

/* Note and button, centred along the bottom of the hero */
.hero-aside {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 6.5rem + var(--player-space, 0px));
  width: min(22rem, calc(100% - 2.5rem));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fade-in 1s 2s var(--ease-out) both;
  transition: bottom 0.6s var(--ease-out);
}
.hero-aside p {
  margin: 0 0 1.1rem;
  font-weight: 600;
  font-size: 1.12rem;
  line-height: 1.35;
  text-shadow: 0 1px 14px rgba(40, 12, 0, 0.7);
}

.hero-cta {
  min-width: 13rem;
  min-height: 54px;
  padding: 0.9rem 2.5rem;
  border: 0;
  border-radius: 999px;
  background: #EE8A3C;
  color: #fff;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(120, 40, 0, 0.45);
  cursor: pointer;
  box-shadow: 0 12px 28px -10px rgba(40, 12, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.25s var(--ease-out), background-color 0.25s, box-shadow 0.25s;
}
.hero-cta:hover { background: #F39A4E; box-shadow: 0 16px 32px -10px rgba(40, 12, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.hero-cta:active { transform: scale(0.97); }
.hero-cta:focus-visible { outline: 2px solid #fff; outline-offset: 4px; }

/* ==========================================================================
   2. The legend
   ========================================================================== */

/* Tone-on-tone poster type: deep rust with peach letters, one line per screen */
.legend {
  position: relative;
  isolation: isolate;
  background: #6B2608;
  color: #FFC59A;
}
.legend-pattern {
  inset: 0;
  background: rgba(255, 197, 154, 0.09);
  transform: none;
}
.section-label--peach { color: #FFC59A; opacity: 0.85; }

.legend-step {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100svh;
  max-width: 78rem;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 3rem) calc(var(--safe-right) + 1.25rem) calc(var(--safe-bottom) + 3rem + var(--player-space, 0px)) calc(var(--safe-left) + 1.25rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
}

.legend-text {
  margin: 0;
  font-family: var(--font-poster);
  font-weight: 400;
  font-size: min(13vw, 11vh);
  line-height: 0.95;
  letter-spacing: 0.005em;
  text-transform: uppercase;
}
.legend-text--long { font-size: min(10vw, 8.2vh); }
.legend-text--gold { font-size: min(15vw, 13vh); }

/* Words light up one after another when the line comes into view */
.legend-word {
  color: rgba(255, 197, 154, 0.18);
  transition: color 0.5s ease-out;
  transition-delay: calc(0.2s + var(--i) * 90ms);
}
.legend-step.is-in .legend-word { color: #FFC59A; }
.legend-step.is-in .legend-text--gold .legend-word { color: var(--gold-soft); }

.continue-btn {
  min-width: 11rem;
  min-height: 52px;
  margin-top: 0.75rem;
  padding: 0.85rem 2.25rem;
  border: 0;
  border-radius: 999px;
  background: #EE8A3C;
  color: #fff;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(120, 40, 0, 0.45);
  cursor: pointer;
  box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.6s, transform 0.6s var(--ease-out), background-color 0.25s;
}
.legend-step.is-in .continue-btn { opacity: 1; transform: none; transition-delay: 1.2s, 1.2s, 0s; }
.continue-btn:hover { background: #F39A4E; }
.continue-btn:active { transform: scale(0.97); }
.continue-btn:focus-visible { outline: 2px solid #fff; outline-offset: 4px; }

/* ==========================================================================
   3. The birthday wish
   ========================================================================== */

.wish {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 5rem calc(var(--safe-right) + 1.25rem) calc(var(--safe-bottom) + 5rem + var(--player-space, 0px)) calc(var(--safe-left) + 1.25rem);
  overflow: hidden;
  isolation: isolate;
  text-align: center;
  color: #fff;
  background: var(--hero-bg);
}
.wish .hero-pattern { transform: none; }

.wish-inner {
  position: relative;
  z-index: 1;
  max-width: 62rem;
}
.wish-inner > * {
  opacity: 0;
  transform: translateY(26px);
  transition: opacity 1s var(--ease-out), transform 1s var(--ease-out);
}
.wish.is-in .wish-inner > * { opacity: 1; transform: none; }
.wish.is-in .wish-inner > :nth-child(2) { transition-delay: 0.15s; }
.wish.is-in .wish-inner > :nth-child(3) { transition-delay: 0.6s; }
.wish.is-in .wish-inner > :nth-child(4) { transition-delay: 1.1s; }
.wish-cta { margin-top: 1.75rem; }

.wish-title {
  margin: 0.6rem 0 1.4rem;
  font-family: var(--font-script);
  font-weight: 400;
  line-height: 0.9;
}
.wish-happy {
  display: block;
  font-size: clamp(3.8rem, 19vw, 12.5rem);
}
.wish-name {
  display: block;
  margin-top: 0.15em;
  font-size: clamp(2.6rem, 12.5vw, 8rem);
  color: var(--gold-soft);
  text-shadow: 0 0 30px rgba(255, 200, 100, 0.35);
}
/* The message sits on a frosted cream panel, dark text on light, so it
   reads clearly over the orange without any dark shadow */
.wish-sub {
  max-width: 32rem;
  margin: 0 auto;
  padding: 1.1rem 1.5rem 1.2rem;
  border-radius: 20px;
  background: rgba(255, 246, 236, 0.86);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 14px 34px -16px rgba(80, 25, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  font-weight: 700;
  font-size: clamp(1.2rem, 4.8vw, 1.5rem);
  line-height: 1.4;
  color: #3A1A08;
}

/* ==========================================================================
   4. The letters
   ========================================================================== */

.letters {
  position: relative;
  padding-bottom: calc(var(--safe-bottom) + 4rem + var(--player-space, 0px));
}

/* The loom bar: pinned to the top, gains a strip per letter */
.loom-bar {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 20;
  padding:
    calc(var(--safe-top) + 0.6rem)
    calc(var(--safe-right) + 1rem)
    0.45rem
    calc(var(--safe-left) + 1rem);
  --glass-bg: rgba(255, 251, 246, 0.8);
  border-width: 0 0 1px;
  border-bottom-color: var(--accent-line);
}
.loom-bar-inner { max-width: 960px; margin: 0 auto; }

.loom-cloth {
  display: flex;
  height: 44px;
  border-radius: 4px;
  overflow: hidden;
  background: #2E241C; /* the dark loom the strips are woven on */
  box-shadow: inset 0 0 0 1px rgba(42, 26, 14, 0.4), 0 4px 14px -6px rgba(42, 26, 14, 0.5);
}
.loom-slot {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  /* faint warp threads waiting for a strip */
  background: repeating-linear-gradient(90deg, rgba(246, 217, 138, 0.22) 0 1px, transparent 1px 5px);
}
.loom-slot + .loom-slot { box-shadow: inset 1px 0 0 rgba(232, 179, 61, 0.12); }
.loom-slot.is-flash::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 246, 224, 0.95), rgba(246, 217, 138, 0) 70%);
  pointer-events: none;
  animation: flash 0.9s ease-out forwards;
}

.strip {
  position: absolute;
  inset: 0;
  display: block;
  background-repeat: repeat-y;
  background-size: 100% auto;
  box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.35), inset -1px 0 0 rgba(0, 0, 0, 0.35);
}
.strip.is-new {
  transform-origin: 50% 0;
  animation: strip-in 0.9s var(--ease-out) both;
}

.loom-counter {
  margin: 0.3rem 0 0;
  font-style: italic;
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent-deep);
  text-align: center;
}

.letters-intro {
  width: calc(100% - 2rem);
  max-width: 34rem;
  margin: 2.5rem auto 0;
  padding: 1.75rem 1.5rem 1.9rem;
  border-radius: 24px;
  text-align: center;
}
.letters-title {
  margin: 0.4rem 0 0.6rem;
  font-family: var(--font-script);
  font-weight: 400;
  font-size: clamp(3.2rem, 15vw, 6.5rem);
  line-height: 0.95;
  color: var(--accent);
}
.letters-lede {
  margin: 0;
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1.4;
}

/* Four to a row on wider screens, two on phones so names stay readable */
.letter-list {
  list-style: none;
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem calc(var(--safe-right) + 1rem) 0 calc(var(--safe-left) + 1rem);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1rem;
  row-gap: 1.25rem;
}

.envelope-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  /* room above for the flap once it folds back (~42% of the envelope's width) */
  padding-top: 44%;
}

/* ---------- Envelopes ---------- */

.envelope {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10.5;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  container-type: inline-size;
}
.envelope:focus-visible { outline-offset: 6px; }

.env-body {
  position: absolute;
  inset: 0;
  perspective: 1000px;
}

/* Until it's opened, each envelope keeps trying to open: a wiggle, the flap
   lifting, the letter peeking out. Staggered so they take turns. */
.envelope:not(.is-open) .env-body { animation: env-wiggle 4.2s var(--try-delay, 0s) ease-in-out infinite; }
.envelope:not(.is-open) .env-flap { animation: flap-try 4.2s var(--try-delay, 0s) ease-in-out infinite; }
.envelope:not(.is-open) .env-letter { animation: letter-peek 4.2s var(--try-delay, 0s) ease-in-out infinite; }
.envelope:not(.is-open):hover .env-flap { animation-duration: 1.4s; }
.letter-list.is-inviting .envelope:not(.is-open) .env-body { animation-delay: calc(var(--try-delay, 0s) * 0.25); }

/* Inside of the envelope: plain woven cotton lining */
.env-back {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  background: var(--weave) 0 0 / 5px 5px, linear-gradient(#E9DFCB, #DCCFB5);
  box-shadow: 0 24px 40px -14px rgba(42, 26, 14, 0.6), 0 2px 6px rgba(42, 26, 14, 0.2);
}

/* The letter tucked inside */
.env-letter {
  position: absolute;
  z-index: 1;
  left: 6%;
  right: 6%;
  top: 5%;
  height: 88%;
  border-radius: 3px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 14px, rgba(42, 30, 20, 0.08) 14px 15px) 0 22px / 100% auto no-repeat,
    var(--paper);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.55s var(--ease-out), opacity 0.5s;
}
.envelope.is-open .env-letter { transform: translateY(-16%); }
.envelope.is-pulling .env-letter { transform: translateY(-58%); }
.envelope.is-out .env-letter { opacity: 0; transform: translateY(-16%); }

/* The cloth. Every panel covers the whole envelope and is clipped to its
   shape, so the pattern runs on unbroken across the folds. Layers: light and
   shade for the fold, the fine over-under weave, then the cloth itself. */
.env-panel,
.env-flap-front {
  position: absolute;
  inset: 0;
  background-image: var(--shade, none), var(--weave), var(--fabric);
  background-size: 100% 100%, 5px 5px, var(--fabric-size, 60% auto);
  background-position: 0 0, 0 0, 0 0;
}
.env-panel { z-index: 2; border-radius: 4px; }
.env-side--left {
  -webkit-clip-path: polygon(0 0, 46% 56%, 0 100%);
  clip-path: polygon(0 0, 46% 56%, 0 100%);
  --shade: linear-gradient(90deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.26));
}
.env-side--right {
  -webkit-clip-path: polygon(100% 0, 54% 56%, 100% 100%);
  clip-path: polygon(100% 0, 54% 56%, 100% 100%);
  --shade: linear-gradient(270deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.26));
}
.env-bottom {
  -webkit-clip-path: polygon(0 100%, 46% 56%, 54% 56%, 100% 100%);
  clip-path: polygon(0 100%, 46% 56%, 54% 56%, 100% 100%);
  --shade: linear-gradient(to top, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.08) 60%, rgba(0, 0, 0, 0.2));
}

/* Creases and hand stitching along the folds and around the edge */
.env-seams {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.env-crease { fill: none; stroke: rgba(0, 0, 0, 0.45); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.env-stitch { fill: none; stroke: rgba(255, 240, 210, 0.75); stroke-width: 1.2; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }

/* Flap: the full envelope's size, clipped to a deep V with a rounded tip.
   Front is the cloth; the inside, seen once it folds back, is the lining. */
.env-flap {
  position: absolute;
  z-index: 3;
  inset: 0;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.5, 0, 0.2, 1), z-index 0s 0.35s;
}
.env-flap-front,
.env-flap-inside {
  -webkit-clip-path: polygon(0% 0%, 100% 0%, 94.5% 9.7%, 89.1% 18.8%, 83.8% 27.2%, 78.5% 35%, 73.3% 42.2%, 68.1% 48.8%, 63% 54.7%, 58% 60%, 56% 62%, 54% 63.4%, 52% 64.2%, 50% 64.5%, 48% 64.2%, 46% 63.4%, 44% 62%, 42% 60%, 37% 54.7%, 31.9% 48.8%, 26.7% 42.2%, 21.5% 35%, 16.2% 27.2%, 10.9% 18.8%, 5.5% 9.7%);
  clip-path: polygon(0% 0%, 100% 0%, 94.5% 9.7%, 89.1% 18.8%, 83.8% 27.2%, 78.5% 35%, 73.3% 42.2%, 68.1% 48.8%, 63% 54.7%, 58% 60%, 56% 62%, 54% 63.4%, 52% 64.2%, 50% 64.5%, 48% 64.2%, 46% 63.4%, 44% 62%, 42% 60%, 37% 54.7%, 31.9% 48.8%, 26.7% 42.2%, 21.5% 35%, 16.2% 27.2%, 10.9% 18.8%, 5.5% 9.7%);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.env-flap-front {
  --shade: radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.1) 70%);
}
.env-flap-inside {
  position: absolute;
  inset: 0;
  background: var(--weave) 0 0 / 5px 5px, linear-gradient(#E3D7BF, #D2C3A6);
  transform: rotateX(180deg);
}
.env-hem { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.env-hem path { fill: none; stroke: rgba(255, 240, 210, 0.8); stroke-width: 1.2; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.envelope.is-open .env-flap { transform: rotateX(180deg); z-index: 0; }

/* The flap's soft shadow on the panels below it */
.env-flap-shade {
  position: absolute;
  z-index: 2;
  inset: 0;
  filter: blur(3px);
  transition: opacity 0.3s;
  pointer-events: none;
}
.env-flap-shade::before {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateY(5%);
  background: rgba(20, 8, 0, 0.55);
  -webkit-clip-path: polygon(0% 0%, 100% 0%, 94.5% 9.7%, 89.1% 18.8%, 83.8% 27.2%, 78.5% 35%, 73.3% 42.2%, 68.1% 48.8%, 63% 54.7%, 58% 60%, 56% 62%, 54% 63.4%, 52% 64.2%, 50% 64.5%, 48% 64.2%, 46% 63.4%, 44% 62%, 42% 60%, 37% 54.7%, 31.9% 48.8%, 26.7% 42.2%, 21.5% 35%, 16.2% 27.2%, 10.9% 18.8%, 5.5% 9.7%);
  clip-path: polygon(0% 0%, 100% 0%, 94.5% 9.7%, 89.1% 18.8%, 83.8% 27.2%, 78.5% 35%, 73.3% 42.2%, 68.1% 48.8%, 63% 54.7%, 58% 60%, 56% 62%, 54% 63.4%, 52% 64.2%, 50% 64.5%, 48% 64.2%, 46% 63.4%, 44% 62%, 42% 60%, 37% 54.7%, 31.9% 48.8%, 26.7% 42.2%, 21.5% 35%, 16.2% 27.2%, 10.9% 18.8%, 5.5% 9.7%);
}
.envelope.is-open .env-flap-shade { opacity: 0; }
.envelope:not(.is-open) .env-flap-shade { animation: shade-try 4.2s var(--try-delay, 0s) ease-in-out infinite; }

/* Gold wax seal at the tip of the flap, which breaks in two when opened */
.env-seal {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 64.5%;
  width: 16%;
  aspect-ratio: 1;
  transform: translate(-50%, -62%);
}
.env-seal svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45));
}
.env-seal::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 55%);
  opacity: 0;
  pointer-events: none;
  animation: seal-shimmer 3.6s ease-in-out infinite;
  animation-delay: var(--try-delay, 0s);
}
.seal-half {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.6s var(--ease-out), opacity 0.6s;
}
.envelope.is-open .seal-left { transform: translate(-12%, 6%) rotate(-16deg); opacity: 0.8; }
.envelope.is-open .seal-right { transform: translate(12%, 6%) rotate(16deg); opacity: 0.8; }
.envelope.is-open .env-seal::after { display: none; }

/* A small cream name label sewn onto the front */
.env-label {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 7%;
  max-width: 90%;
  padding: 0.1em 0.6em 0.15em;
  transform: translateX(-50%) rotate(-1.5deg);
  border-radius: 2px;
  background: var(--weave) 0 0 / 5px 5px, #F6EEDC;
  outline: 1px dashed rgba(42, 30, 20, 0.45);
  outline-offset: -3px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  font-family: var(--font-hand);
  font-size: 1rem;
  font-size: clamp(0.72rem, 7.4cqw, 1.3rem);
  line-height: 1.15;
  color: var(--ink);
  text-align: center;
  /* long names wrap onto a second line rather than being cut off */
  white-space: normal;
  overflow-wrap: anywhere;
}

/* "Read" stamp, pressed on once the letter has been opened */
.env-stamp {
  position: absolute;
  z-index: 5;
  top: 8%;
  right: 6%;
  padding: 0.15em 0.5em;
  border: 2px solid var(--accent);
  border-radius: 4px;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.6rem;
  font-size: clamp(0.5rem, 4.4cqw, 0.8rem);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(255, 251, 246, 0.85);
  opacity: 0;
  transform: rotate(-12deg) scale(1.8);
  transition: opacity 0.35s, transform 0.45s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.envelope-item.is-read .env-stamp { opacity: 1; transform: rotate(-12deg); }

/* Under each envelope: "Tap to open", then "Read · Gold thread" */
.env-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 251, 246, 0.86);
  box-shadow: 0 4px 14px -8px rgba(42, 26, 14, 0.4);
  font-style: italic;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
  text-align: center;
  color: var(--text-muted);
}
.envelope-item.is-read .env-tag { color: var(--accent-deep); }
.env-tag-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--thread);
  box-shadow: 0 0 0 1.5px rgba(42, 26, 14, 0.45);
}

/* ---------- The letter, opening in the page below its row ---------- */

.letter-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 0 1.5rem;
  scroll-margin-top: 7.5rem;
}

.fold-btn {
  min-height: 48px;
  padding: 0.6rem 1.75rem;
  border-radius: 999px;
  border: 1.5px solid var(--accent);
  background: rgba(255, 251, 246, 0.9);
  color: var(--accent-deep);
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.5s 0.9s, background-color 0.3s;
}
.fold-btn:hover { background: #fff; }
.letter-panel.is-open .fold-btn { opacity: 1; }

.letter {
  position: relative;
  z-index: 5;
  width: min(100%, 40rem);
  filter: drop-shadow(0 18px 28px rgba(42, 26, 14, 0.28));
  opacity: 0;
  transform: translateY(-36px) scale(0.96);
  -webkit-clip-path: inset(-40px -40px 100% -40px);
  clip-path: inset(-40px -40px 100% -40px);
  transition:
    opacity 0.6s,
    transform 1s var(--ease-out),
    -webkit-clip-path 1.3s var(--ease-out),
    clip-path 1.3s var(--ease-out);
}
.letter-panel.is-open .letter {
  opacity: 1;
  transform: none;
  -webkit-clip-path: inset(-40px -40px -60px -40px);
  clip-path: inset(-40px -40px -60px -40px);
}

/* Every letter is the same size; long ones scroll inside the paper */
.letter-paper {
  position: relative;
  height: 64vh;
  height: min(64svh, 36rem);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    var(--noise),
    radial-gradient(ellipse at 15% 0%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 60%),
    radial-gradient(ellipse at 100% 100%, rgba(181, 140, 82, 0.2), rgba(181, 140, 82, 0) 55%);
}

.letter-content {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(198, 81, 2, 0.55) transparent;
  padding: 2.25rem 1.5rem 2rem;
  font-family: var(--font-hand);
  font-size: clamp(1.25rem, 5.2vw, 1.4rem);
  line-height: 1.6;
}
.letter-content::-webkit-scrollbar { width: 8px; }
.letter-content::-webkit-scrollbar-track { background: transparent; margin: 14px 0; }
.letter-content::-webkit-scrollbar-thumb { background: rgba(198, 81, 2, 0.5); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
.letter-content:focus-visible { outline: 2px dashed rgba(42, 30, 20, 0.45); outline-offset: -8px; }

/* Fade and hint at the bottom while there's more to read */
.letter-paper::after {
  content: "";
  position: absolute;
  left: 0;
  right: 10px;
  bottom: 0;
  height: 5.5rem;
  background: linear-gradient(to bottom, rgba(247, 239, 223, 0), rgba(240, 228, 206, 0.97) 75%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.letter-more {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 0.9rem;
  transform: translateX(-50%);
  padding: 0.2rem 0.85rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.letter-paper.has-more::after,
.letter-paper.has-more .letter-more { opacity: 1; }
.letter-panel.is-open .letter-paper.has-more .letter-more { animation: more-nudge 2.2s 1.6s ease-in-out infinite; }

.letter-greeting { margin: 0 0 1rem; font-size: 1.15em; }
.letter-body { margin: 0 0 1.5rem; white-space: pre-line; overflow-wrap: anywhere; }
.letter-signoff { margin: 0; }
.letter-from { margin: 0 0 1.75rem; font-weight: 700; font-size: 1.15em; }

.letter-thread {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0;
  padding-top: 1.1rem;
  border-top: 1px dashed rgba(42, 30, 20, 0.28);
  font-size: 0.95em;
}
.letter-thread strong { font-weight: 700; }

.thread-swatch {
  flex: none;
  display: block;
  width: 48px;
  height: 24px;
  margin-top: 0.3em;
}
.thread-swatch svg { display: block; width: 100%; height: 100%; overflow: visible; }
.thread-swatch path { fill: none; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; }
.thread-swatch-edge { stroke: rgba(42, 30, 20, 0.55); stroke-width: 6; }
.thread-swatch-core { stroke-width: 3.6; }
.letter-panel.is-open .thread-swatch path { animation: draw 0.9s 1.3s var(--ease-out) forwards; }

/* Lines appear one after another, as if just written */
.letter-content > * { opacity: 0; }
.letter-panel.is-open .letter-content > * { animation: write-in 0.7s var(--ease-out) forwards; }
.letter-panel.is-open .letter-greeting { animation-delay: 0.35s; }
.letter-panel.is-open .letter-body { animation-delay: 0.5s; }
.letter-panel.is-open .letter-signoff { animation-delay: 0.75s; }
.letter-panel.is-open .letter-from { animation-delay: 0.85s; }
.letter-panel.is-open .letter-thread { animation-delay: 1.1s; }

/* ==========================================================================
   5. The finished cloth
   ========================================================================== */

.finale {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 4.5rem calc(var(--safe-right) + 1.25rem) calc(var(--safe-bottom) + 5rem + var(--player-space, 0px)) calc(var(--safe-left) + 1.25rem);
  text-align: center;
}

.finale-waiting {
  margin: -1rem 0 0;
  font-style: italic;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--text-muted);
}
.finale.is-revealed .finale-waiting { display: none; }

.finale-cloth-wrap {
  position: relative;
  width: min(86vw, 32rem);
}
.finale-cloth-wrap::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 10px;
  box-shadow: 0 0 46px 10px rgba(232, 179, 61, 0.7);
  opacity: 0;
  pointer-events: none;
}
.finale.is-pulsing .finale-cloth-wrap::before { animation: glow-pulse 1.8s ease-in-out forwards; }

.finale-cloth {
  display: flex;
  height: 44vh;
  height: clamp(15rem, 46dvh, 28rem);
  border-radius: 4px;
  /* the loom, waiting, until the strips arrive */
  background: #2E241C repeating-linear-gradient(90deg, rgba(246, 217, 138, 0.2) 0 1px, transparent 1px 6px);
  box-shadow: 0 24px 50px -18px rgba(42, 26, 14, 0.6);
}

.finale-strip {
  position: relative;
  inset: auto;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  opacity: 0;
  transform: translate(var(--dx), var(--dy));
  transition:
    transform 1.3s cubic-bezier(0.2, 0.8, 0.2, 1) var(--delay),
    opacity 0.7s var(--delay);
}
.finale.is-revealed .finale-strip { opacity: 1; }
.finale.is-woven .finale-strip { transform: none; }

/* Stitches where the strips are sewn edge to edge */
.finale-strip::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: 2%;
  bottom: 2%;
  right: -1px;
  border-right: 2px dashed rgba(246, 217, 138, 0.85);
  transform: scaleY(0);
  transform-origin: 50% 0;
  transition: transform 0.8s var(--ease-out) calc(var(--delay) * 1.5);
}
.finale-strip:last-child::after { display: none; }
.finale.is-stitched .finale-strip::after { transform: none; }

/* One ripple of gold light */
.finale-ripple {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.finale-ripple::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -60%;
  width: 60%;
  background: linear-gradient(100deg, rgba(246, 217, 138, 0) 15%, rgba(255, 240, 190, 0.7) 50%, rgba(246, 217, 138, 0) 85%);
  opacity: 0;
}
.finale.is-pulsing .finale-ripple::before { animation: ripple 1.5s ease-in-out forwards; }

/* Her name, stitched across the cloth */
.finale-name-band {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: -4%;
  right: -4%;
  padding: 1rem 1rem 1.1rem;
  background: rgba(42, 30, 20, 0.92);
  border-top: 2px dashed rgba(232, 179, 61, 0.8);
  border-bottom: 2px dashed rgba(232, 179, 61, 0.8);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(-50%) scaleX(0.6);
  transition: opacity 0.6s, transform 0.8s var(--ease-out);
}
.finale.is-named .finale-name-band { opacity: 1; transform: translateY(-50%); }

.finale-name {
  margin: 0;
  font-family: var(--font-script);
  font-weight: 400;
  font-size: clamp(2.4rem, 12vw, 4.6rem);
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(232, 179, 61, 0.55), 0 0 34px rgba(232, 179, 61, 0.25);
}
.stitch-letter { display: inline-block; opacity: 0; }
.finale.is-named .stitch-letter {
  animation: stitch-in 0.7s var(--ease-out) forwards;
  animation-delay: calc(0.35s + var(--i) * 110ms);
}

.finale-lines {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: min(100%, 32rem);
  padding: 1.5rem 1.4rem;
  border-radius: 24px;
  opacity: 0;
  transition: opacity 0.8s;
}
.finale.is-named .finale-lines { opacity: 1; }
.finale-line {
  margin: 0;
  font-style: italic;
  font-weight: 600;
  font-size: clamp(1.25rem, 5vw, 1.6rem);
  line-height: 1.35;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1s var(--ease-out), transform 1s var(--ease-out);
}
.finale-line.is-in { opacity: 1; transform: none; }
.finale-wish {
  margin-top: 0.4rem;
  font-family: var(--font-script);
  font-style: normal;
  font-weight: 400;
  font-size: clamp(2rem, 9vw, 3.2rem);
  line-height: 1.05;
  color: var(--accent);
}
.finale-sign {
  font-family: var(--font-hand);
  font-style: normal;
  font-size: 1.35rem;
  color: var(--accent-deep);
}

.again-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s, background-color 0.3s, transform 0.3s var(--ease-out);
}
.finale.is-complete .again-btn { opacity: 1; pointer-events: auto; }

/* ==========================================================================
   Thread flight (letter → loom)
   ========================================================================== */

.thread-flight {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 55;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(198, 81, 2, 0.5)) drop-shadow(0 0 12px rgba(232, 179, 61, 0.65));
}
.thread-flight path { fill: none; stroke-linecap: round; }
.thread-flight-glow { stroke: var(--gold); stroke-width: 8; opacity: 0.6; }
.thread-flight-core { stroke-width: 3.4; }
.thread-flight-head { fill: var(--accent); }

/* ==========================================================================
   Larger screens
   ========================================================================== */

@media (min-width: 760px) {
  :root { --pattern-size: 480px; }

  .loom-bar { padding-top: calc(var(--safe-top) + 0.9rem); padding-bottom: 0.6rem; }
  .loom-cloth { height: 64px; }
  /* Keep strips narrow, like real kente, instead of stretching across the screen */
  .loom-bar-inner { max-width: max(28rem, calc(var(--slots, 8) * 64px)); }

  .letter-content { padding: 2.75rem 3rem 2.5rem; }
  .letter-paper { height: min(70vh, 38rem); }
  .letter-list { grid-template-columns: repeat(4, minmax(0, 1fr)); column-gap: 1.75rem; row-gap: 2rem; padding-top: 3rem; }
  .letter-panel { scroll-margin-top: 9rem; }

  .finale-cloth-wrap { width: min(70vw, 36rem); }
  .finale-cloth { height: clamp(16rem, 50vh, 30rem); }
}

/* Laptop hero: like a magazine cover. Title across her, note bottom right. */
@media (min-width: 900px) {
  .hero-kicker { top: calc(var(--safe-top) + 2rem); left: 3rem; }
  .hero-kicker strong { font-size: 1.7rem; }
  .hero-title {
    top: 48vh;
    padding: 0 3rem;
    font-size: min(10.5vw, 17vh);
    line-height: 0.88;
  }
  .hero-portrait { height: 94vh; }
  .hero-aside { bottom: 2rem; width: 26rem; }
  .hero-aside p { font-size: 1.25rem; }
  .scroll-hint:not(.scroll-hint--dark) { left: 3rem; transform: none; align-items: flex-start; }
}

/* ==========================================================================
   Reduced motion: fades instead of movement
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .legend-word { transition-delay: 0s; }
  .env-body,
  .envelope .env-body,
  .envelope .env-flap,
  .envelope .env-letter,
  .env-seal::after,
  .scroll-hint-dot,
  .player::before,
  .player-pulse { animation: none !important; }

  .hero-portrait { animation-name: fade-in; }
  .hero-letter { transform: none; filter: none; }
  .hero.is-ready .hero-letter,
  .hero.is-ready .hero-title--fill .hero-letter { animation: fade-in 0.8s 0.3s both; }
  .hero-kicker, .hero-aside { animation-name: fade-in; }

  .legend-text,
  .continue-btn,
  .wish-inner > *,
  .letter,
  .finale-line { transform: none !important; }
  .letter { -webkit-clip-path: none; clip-path: none; }

  .env-flap { transition-duration: 0.25s, 0s; transition-delay: 0s, 0.12s; }
  .env-letter { transition: opacity 0.4s; }
  .seal-half { transition: opacity 0.4s; }
  .envelope.is-open .seal-left,
  .envelope.is-open .seal-right { transform: none; opacity: 0.5; }
  .letter-panel.is-open .letter-content > * { animation-name: fade-in; }

  .strip.is-new { animation-name: fade-in; }
  .finale-strip { transform: none !important; transition: opacity 0.6s; }
  .finale-strip::after { transform: none; opacity: 0; transition: opacity 0.6s; }
  .finale.is-stitched .finale-strip::after { opacity: 1; }
  .finale-name-band { transform: translateY(-50%); }
  .finale.is-pulsing .finale-ripple::before { animation: none; }
  .finale.is-named .stitch-letter { animation: fade-in 0.8s both; animation-delay: 0.2s; }
}

/* ==========================================================================
   Keyframes
   ========================================================================== */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes portrait-rise {
  from { opacity: 0; -webkit-clip-path: inset(100% 0 0 0); clip-path: inset(100% 0 0 0); }
  to { opacity: 1; -webkit-clip-path: inset(0 0 0 0); clip-path: inset(0 0 0 0); }
}
@keyframes letter-in {
  60% { opacity: 1; filter: blur(0); }
  to { opacity: 1; transform: none; filter: blur(0); }
}
@keyframes letter-shimmer {
  0%, 14%, 100% { text-shadow: none; }
  7% { text-shadow: 0 0 18px rgba(255, 220, 150, 0.95), 0 0 42px rgba(255, 200, 110, 0.6); }
}
@keyframes scroll-dot {
  0% { transform: translateY(-16px); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translateY(44px); opacity: 0; }
}
@keyframes player-glow { 0%, 100% { opacity: 0.15; } 50% { opacity: 1; } }
@keyframes pulse-dot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.3; transform: scale(0.6); } }
@keyframes env-wiggle {
  0%, 62%, 100% { transform: none; }
  66% { transform: rotate(-2.5deg) translateY(-3px); }
  70% { transform: rotate(2deg) translateY(-3px); }
  74% { transform: rotate(-1.5deg); }
  78% { transform: rotate(1deg); }
  82% { transform: none; }
}
@keyframes more-nudge {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, 3px); }
}
@keyframes shade-try {
  0%, 62%, 100% { opacity: 1; }
  70% { opacity: 0.35; }
  84% { opacity: 1; }
}
@keyframes flap-try {
  0%, 62%, 100% { transform: none; }
  70% { transform: rotateX(38deg); }
  76% { transform: rotateX(22deg); }
  84% { transform: none; }
}
@keyframes letter-peek {
  0%, 62%, 100% { transform: none; }
  72% { transform: translateY(-14%); }
  84% { transform: none; }
}

@keyframes seal-shimmer { 0%, 70%, 100% { opacity: 0; } 82% { opacity: 0.9; } }
@keyframes strip-in { from { opacity: 0.2; transform: scaleY(0); } to { opacity: 1; transform: none; } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes write-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ripple {
  0% { opacity: 0; transform: translateX(0); }
  15%, 85% { opacity: 1; }
  100% { opacity: 0; transform: translateX(270%); }
}
@keyframes glow-pulse { 0% { opacity: 0; } 45% { opacity: 1; } 100% { opacity: 0.35; } }
@keyframes stitch-in {
  0% { opacity: 0; transform: translateY(0.35em) scale(0.6); }
  60% { opacity: 1; transform: scale(1.12); }
  100% { opacity: 1; transform: none; }
}
