/* ==========================================================================
   20261230-KHAG: TYPEWRITER & RISING PAPER OPENING CEREMONY
   Background: #152238 | Paper: #FAEBD7 | HD typewriter, envelope on paper
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400&family=Cormorant+Garamond:ital,wght@0,500;0,600;0,700;1,400&display=swap');

body.is-opening-locked {
  overflow: hidden;
  background-color: #152238;
}

body.is-opening-locked .invitation {
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px);
}
body.is-opening-locked.is-revealing-invitation .invitation {
  opacity: 1;
  transform: none;
}

.invitation {
  transition: opacity 0.9s cubic-bezier(0.22, 1, 0.36, 1), transform 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ==========================================================================
   OPENING SCREEN CONTAINER (#152238)
   ========================================================================== */
.typewriter-opening {
  position: fixed;
  inset: 0;
  z-index: 9999;
  width: 100%;
  height: 100vh;
  height: 100svh;
  background-color: #152238;
  background-image: radial-gradient(circle at 50% 42%, rgba(33, 55, 92, 0.45) 0%, rgba(21, 34, 56, 1) 75%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(20px, 4svh, 40px);
  padding: max(18px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  user-select: none;
  overflow: hidden;
  transition: opacity 0.85s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.85s;
}

.typewriter-opening.is-dismissed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ==========================================================================
   TOP MESSAGE: "You have a message" (Typewriter Font & Typing Effect)
   ========================================================================== */
.typewriter-header {
  position: relative;
  z-index: 10;
  margin-top: clamp(12px, 4svh, 40px);
  margin-bottom: 0;
  flex-shrink: 0;
  min-height: 2.2em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.typewriter-headline {
  margin: 0;
  font-family: "Courier New", monospace;
  font-weight: 400;
  font-size: clamp(20px, 4.6vw, 29px);
  letter-spacing: 0.06em;
  color: #FAEBD7;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  display: inline-flex;
  align-items: center;
}

.typewriter-cursor {
  display: inline-block;
  width: 2.5px;
  height: 1.05em;
  background-color: #fff;
  margin-left: 4px;
  vertical-align: middle;
  animation: cursorBlink 0.85s steps(1) infinite;
}

.typewriter-cursor.is-done {
  animation: cursorBlink 1.1s steps(1) infinite;
  opacity: 0.75;
}

@keyframes cursorBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ==========================================================================
   CENTER/BOTTOM STAGE: TYPEWRITER + RISING PAPER
   ========================================================================== */
.typewriter-stage-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  container-type: size;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: clamp(12px, 3svh, 32px);
}

/* The assembly coordinates paper slot relative to the typewriter width */
.typewriter-assembly {
  position: relative;
  /* Reserve room for BOTH the machine and its fully raised paper below the header. */
  width: min(100cqw, calc(100cqh / 1.5), 420px);
  aspect-ratio: 4 / 3;
  flex-shrink: 0;
}

/* Subtle mechanical keystroke vibration while typing/feeding */
.typewriter-assembly.is-typing-active .typewriter-front-layer,
.typewriter-assembly.is-typing-active .typewriter-back-layer {
  animation: machineChatter 0.14s ease-in-out infinite alternate;
}

@keyframes machineChatter {
  0% { transform: translateY(0px); }
  100% { transform: translateY(0.8px); }
}

/* Layer 1: Back Platen & Side Levers (Behind the Paper) */
.typewriter-back-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 16px 18px rgba(5, 11, 22, 0.4));
}

/* Layer 2: Match the paper viewport to its portrait proportions.
   Its height scales with the machine instead of extending into the headline. */
.paper-slot-viewport {
  position: absolute;
  left: 22.5%;
  width: 55%;
  bottom: 87.5%;
  aspect-ratio: 3 / 4;
  z-index: 2;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* The physical textured paper sheet */
.rising-paper-sheet {
  position: relative;
  width: 100%;
  background-color: #FAEBD7;
  background-image: url('./assets/floral-paper-blue.png');
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  aspect-ratio: 3 / 4;
  border-radius: 2px 2px 0 0;
  padding: 5% 6% 16%;
  flex-shrink: 0;
  box-shadow:
    0 -4px 18px rgba(7, 14, 26, 0.38),
    inset 0 0 0 1px rgba(21, 34, 56, 0.08),
    inset 0 -16px 20px -10px rgba(15, 23, 38, 0.28);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  /* Start tucked deep inside the typewriter platen slot: only a small blank top lip shows */
  transform: translate3d(0, 88%, 0);
  will-change: transform;
}

/* Slow, realistic paper feed upwards out of the typewriter */
.rising-paper-sheet.is-rising {
  transition: transform 4.2s cubic-bezier(0.22, 0.68, 0.32, 1);
  transform: translate3d(0, 0%, 0);
}

/* Bottom roller shadow on the paper right where it meets the platen */
.paper-Slot-shadow {
  position: absolute;
  left: 22.5%;
  width: 55%;
  bottom: 87.5%;
  height: 14px;
  z-index: 3;
  background: linear-gradient(to top, rgba(10, 16, 26, 0.48) 0%, rgba(10, 16, 26, 0.12) 55%, transparent 100%);
  pointer-events: none;
}

/* Metal Paper Bail Bar across the paper (with two small rubber rollers) */
.typewriter-bail-bar {
  position: absolute;
  left: 21.8%;
  width: 56.4%;
  top: 10.4%;
  height: 3px;
  z-index: 4;
  background: linear-gradient(180deg, #f0f2f5 0%, #8b929a 55%, #2c3137 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.42);
  pointer-events: none;
}

.typewriter-bail-bar::before,
.typewriter-bail-bar::after {
  content: "";
  position: absolute;
  top: -3px;
  width: 11%;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(180deg, #45494e 0%, #17191c 60%, #0d0e10 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.typewriter-bail-bar::before {
  left: 17%;
}

.typewriter-bail-bar::after {
  right: 17%;
}

/* Layer 3: Front Typewriter Carriage & Keyboard (In front of the bottom of the paper) */
.typewriter-front-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  clip-path: polygon(0 0, 22.5% 0, 22.5% 12.5%, 77.5% 12.5%, 77.5% 0, 100% 0, 100% 100%, 0 100%);
}

/* Text button to read the invitation */
.paper-envelope-btn {
  position: relative;
  appearance: none;
  border: none;
  background: transparent;
  padding: 2px 0 0;
  margin: 0 auto;
  width: 92%;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  outline: none;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.paper-envelope-btn:hover {
  transform: translateY(-2px) scale(1.02);
}

.paper-envelope-btn:active {
  transform: translateY(0) scale(0.99);
}

.paper-envelope-btn:focus-visible {
  outline: 1.5px dashed #152238;
  outline-offset: 3px;
}

.paper-envelope-picture {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 5px 8px rgb(21 34 56 / .18));
}
.paper-envelope-art {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 475 / 560;
}
.paper-envelope-art .paper-envelope-picture {
  position: absolute;
  left: 0;
  bottom: 0;
  transition: opacity .55s ease, transform .65s ease;
}
.paper-envelope-closed {
  clip-path: inset(2.4% 1.5% 3% 1.7%);
}
.paper-envelope-art .paper-envelope-open {
  opacity: 0;
  transform: translateY(8px);
}
.paper-envelope-btn.is-opening .paper-envelope-closed { opacity: 0; }
.paper-envelope-btn.is-opening .paper-envelope-open { opacity: 1; transform: none; }

/* ==========================================================================
   REPLAY BUTTON ON MAIN INVITATION VIEW
   ========================================================================== */
.invitation-controls {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 90;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.replay-typewriter-btn,
.music-toggle-btn {
  background: #FAEBD7;
  color: #152238;
  border: 1px solid #152238;
  padding: 8px 14px;
  font-family: "Courier Prime", "Courier New", monospace;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.replay-typewriter-btn:hover,
.music-toggle-btn:hover {
  background: #152238;
  color: #FAEBD7;
  transform: translateY(-1px);
}
.music-toggle-btn[hidden] { display: none; }
.music-toggle-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  background: #152238;
  color: #FAEBD7;
  border: 1px solid #FAEBD7;
  letter-spacing: 0;
}
.music-clef {
  display: block;
  width: 100%;
  text-align: center;
  font: 32px/1 "Segoe UI Symbol", "Apple Symbols", "Noto Music", serif;
  transform: translateY(-1px);
}
.music-toggle-btn:hover { background: #1d2f4a; color: #FAEBD7; }
.music-toggle-btn[aria-pressed="true"] { box-shadow: 0 0 0 3px rgb(250 235 215 / .15), 0 4px 14px rgb(0 0 0 / .25); }
.music-toggle-btn[aria-pressed="false"]::after {
  content: "";
  position: absolute;
  width: 28px;
  height: 2px;
  background: currentColor;
  transform: rotate(-45deg);
  border-radius: 2px;
}
.invitation-controls button:focus-visible { outline: 2px solid #FAEBD7; outline-offset: 3px; }

/* One envelope travels from the typewriter paper into the page. */
.envelope-transition {
  position: relative;
  display: grid;
  justify-items: center;
  gap: clamp(24px, 4vw, 36px);
  padding-bottom: 24px;
  opacity: 0;
}
.envelope-transition[hidden] { display: none; }
.envelope-transition.is-visible { opacity: 1; }
.hero-couple-names {
  position: relative;
  display: block;
  width: min(100%, 720px);
  height: auto;
  margin: 0 auto;
}
.opening-envelope {
  position: relative;
  width: min(78vw, 420px, 60svh);
  aspect-ratio: 475 / 560;
  container-type: inline-size;
  transform-origin: top left;
  filter: drop-shadow(0 12px 18px rgb(21 34 56 / .18));
}
.opening-envelope.is-in-paper { width: 100%; }
.opening-envelope.is-zooming { z-index: 10001; }
.envelope-state-closed, .envelope-state-open {
  position: absolute;
  width: 100%;
  height: auto;
  left: 0;
  bottom: 0;
  pointer-events: none;
  transition: opacity .5s ease, transform .6s cubic-bezier(.22, 1, .36, 1);
}
.envelope-state-closed { clip-path: inset(2.4% 1.5% 3% 1.7%); }
.envelope-state-open { opacity: 0; transform: translateY(10%); }
.opening-envelope.is-unsealed .envelope-state-closed { opacity: 0; }
.opening-envelope.is-unsealed .envelope-state-open { opacity: 1; transform: none; }
.envelope-letter {
  position: absolute;
  z-index: 2;
  inset: 0;
  color: #152238;
  text-align: center;
  opacity: 0;
  clip-path: inset(0 -15% 0 -15%);
  transition: opacity .5s ease;
  pointer-events: none;
}
.opening-envelope.is-unsealed .envelope-letter { opacity: 1; transform: none; }
.letter-photo, .letter-paper-backing, .letter-paper, .letter-bouquet, .letter-date {
  opacity: 0;
  translate: 0 25cqw;
  transition: translate 2s cubic-bezier(.25, .46, .45, .94), opacity 2s ease;
}
.opening-envelope.is-unsealed :is(.letter-photo, .letter-paper-backing, .letter-paper, .letter-bouquet, .letter-date) {
  opacity: 1;
  translate: 0 0;
}
.letter-photo {
  position: absolute;
  top: 16%;
  left: 6%;
  width: 45%;
  height: 51%;
  margin: 0;
  filter: drop-shadow(0 4px 6px rgb(21 34 56 / .18));
  transform: rotate(-8deg);
}
.letter-photo .letter-portrait {
  position: absolute;
  left: 15%;
  top: 16%;
  display: block;
  width: 70%;
  height: 66%;
  object-fit: cover;
  border-radius: 50%;
}
.letter-photo .letter-ornate-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.letter-paper-backing {
  position: absolute;
  top: 14%;
  left: 49%;
  width: 44%;
  height: 52%;
  background: repeating-linear-gradient(90deg, #152238 0 1.5cqw, #f9f0e2 1.5cqw 3cqw);
  box-shadow: 0 3px 8px rgb(21 34 56 / .12);
  transform: rotate(2deg);
}
.letter-paper {
  position: absolute;
  top: 18%;
  left: 51%;
  width: 40%;
  height: 48%;
  padding: 5% 2% 2%;
  background: #faf3e7 url('./assets/paper-texture.jpg') center / cover;
  border: 1px solid #b7a382;
  outline: 1px solid #b7a382;
  outline-offset: -5px;
  box-shadow: 0 4px 12px rgb(21 34 56 / .16);
  transform: rotate(5deg);
}
.letter-kicker { margin: 0 0 9%; font: 1.7cqw/1.4 "Courier Prime", monospace; letter-spacing: .15cqw; }
.letter-heading { margin: 0 0 8%; font: italic 9.2cqw/.95 "Cormorant Garamond", Georgia, serif; font-weight: 500; letter-spacing: -.25cqw; }
.letter-envelope-front {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  clip-path: polygon(0 44%, 49% 71%, 100% 44%, 100% 100%, 0 100%);
}
.letter-date {
  position: absolute;
  z-index: 2;
  top: 48%;
  left: 27%;
  width: 47%;
  height: 27%;
  margin: 0;
  color: #152238;
  font: 5cqw/1.3 "Cormorant Garamond", Georgia, serif;
  letter-spacing: .15cqw;
  filter: drop-shadow(0 2px 4px rgb(21 34 56 / .15));
}
.letter-heart { position: absolute; inset: 0; width: 100%; height: 100%; }
.letter-date .letter-date-value { position: absolute; top: 39%; left: 0; width: 100%; margin: 0; font: inherit; letter-spacing: inherit; }
.letter-date-value small { display: block; margin-top: 2%; font: 1.8cqw/1.3 "Courier Prime", monospace; letter-spacing: .15cqw; }
.letter-matching-seal {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 35.5%;
  width: 100%;
  height: auto;
  /* Reuse the original gold seal, instead of the open asset's brown seal. */
  clip-path: ellipse(9% 13% at 50.5% 62%);
}
.letter-bouquet {
  position: absolute;
  z-index: 5;
  top: 39%;
  right: -11%;
  width: 44%;
  height: auto;
  filter: drop-shadow(0 3px 4px rgb(21 34 56 / .15));
  transform: none;
}
body.is-opening-locked .invitation-controls { visibility: hidden; }
.typewriter-opening.is-zooming-away {
  background-color: transparent;
  background-image: none;
  pointer-events: none;
}
.typewriter-opening.is-zooming-away .typewriter-header,
.typewriter-opening.is-zooming-away .typewriter-stage-wrap {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 1.2s ease, transform 1.2s ease;
}
body.is-revealing-invitation .invitation { transition: none; }

@media (prefers-reduced-motion: reduce) {
  .typewriter-opening,
  .invitation,
  .rising-paper-sheet.is-rising,
  .paper-envelope-btn,
  .paper-tap-prompt { transition: none; }
  .envelope-transition,
  .envelope-state-open,
  .envelope-state-closed,
  .envelope-letter,
  .letter-photo, .letter-paper-backing, .letter-paper, .letter-bouquet, .letter-date,
  .typewriter-opening.is-zooming-away .typewriter-header,
  .typewriter-opening.is-zooming-away .typewriter-stage-wrap { transition: none; }
  .paper-envelope-art .paper-envelope-picture { transition: none; }
  .typewriter-cursor,
  .typewriter-assembly.is-typing-active .typewriter-front-layer,
  .typewriter-assembly.is-typing-active .typewriter-back-layer,
  .typewriter-opening.is-ready-to-open .paper-tap-prompt { animation: none; }
}
