/* ── Laith & Noora — save the date ─────────────────────────────
   Flow: sealed envelope → tap → flap opens → dissolves into the
   page → scratch the oval → details fade in.                      */

:root {
  --linen: #f4eede;
  --linen-deep: #ebe2cd;
  --ink: #3b332a;
  --ink-soft: #6f6353;
  --gold: #b08d57;
  --gold-deep: #96743f;
  --card-paper: #fffcf4;
  --env-inside: #f6eedb;
  --env-flap: #efe3c9;
  --env-pocket: #e7dabc;
  --env-pocket-lo: #e0d1b0;
  --serif: "Cormorant Garamond", "Amiri", Georgia, serif;
  --sans: "Jost", "Amiri", -apple-system, "Segoe UI", sans-serif;
  --script: "Great Vibes", "Amiri", cursive;

  /* Photo clip — intentionally a hair LARGER than the frame's true oval opening
     (31.905% / 36.607%, see assets/frame.svg). The frame-overlay is opaque outside
     its own hole and paints on top, so this margin is always hidden underneath it;
     it exists purely so tiny sub-pixel/scaling differences between the two
     independently-rendered layers can never show as a gap between the photo and
     the decorative ring. Do NOT shrink this to match the frame exactly. */
  --oval-rx: 33.5%;
  --oval-ry: 38.4%;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  font-weight: 300;
  color: var(--ink);
  background: var(--linen);
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
html[lang="ar"] body { font-family: "Amiri", var(--sans); font-weight: 400; }
html[lang="ar"] .eyebrow,
html[lang="ar"] .date,
html[lang="ar"] .seal-eyebrow,
html[lang="ar"] .seal-hint,
html[lang="ar"] .solid-btn,
html[lang="ar"] .scratch-hint span,
html[lang="ar"] .footer-note { letter-spacing: 0; }

/* ── persistent controls ─────────────────────────────────── */
.ctrl {
  position: fixed;
  z-index: 60;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(107, 91, 68, 0.28);
  background: rgba(255, 252, 244, 0.72);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: var(--ink-soft);
  cursor: pointer;
  display: grid; place-items: center;
  transition: color 0.2s, border-color 0.2s, transform 0.2s;
}
.ctrl:hover { color: var(--gold-deep); border-color: var(--gold); transform: scale(1.06); }
.ctrl[hidden] { display: none; }

/* kept in the layout (not display:none) so iOS doesn't pause it; just invisible/inert */
.bg-video {
  position: fixed; inset: 0 auto auto 0;
  width: 1px; height: 1px;
  opacity: 0; pointer-events: none;
}
.lang-toggle {
  top: max(16px, env(safe-area-inset-top)); inset-inline-end: 16px;
  font-family: var(--serif); font-size: 19px; line-height: 1; padding-bottom: 3px;
}
.music-toggle { bottom: max(18px, env(safe-area-inset-bottom)); inset-inline-end: 16px; }
.music-toggle svg { width: 21px; height: 21px; }
.music-toggle .icon-on { display: none; }
.music-toggle.playing .icon-on { display: block; }
.music-toggle.playing .icon-off { display: none; }

/* ── envelope landing ────────────────────────────────────── */
.seal-screen {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(120% 100% at 50% 42%, rgba(255,250,240,0.35), rgba(214,197,163,0.5) 70%, rgba(196,178,145,0.66)),
    url("../assets/lace.svg?v=13");
  background-size: cover, 190px 190px;
  transition: opacity 1.1s ease;
}
body.entering .seal-screen { opacity: 0; }
body.opened .seal-screen { opacity: 0; pointer-events: none; }

.seal-inner { display: flex; flex-direction: column; align-items: center; gap: 30px; }

.seal-eyebrow {
  font-family: var(--serif);
  font-size: 15px; letter-spacing: 0.42em; text-transform: uppercase;
  color: var(--gold-deep);
  transition: opacity 0.5s ease;
}
html[lang="ar"] .seal-eyebrow { font-size: 20px; }
.seal-hint {
  font-size: 12.5px; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--ink-soft);
  animation: hintFade 2.8s ease-in-out infinite;
  transition: opacity 0.5s ease;
}
@keyframes hintFade { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }
body.opening .seal-eyebrow, body.opening .seal-hint,
body.entering .seal-eyebrow, body.entering .seal-hint { opacity: 0; animation: none; }

/* the envelope itself */
.envelope {
  position: relative;
  width: min(84vw, 384px);
  aspect-ratio: 3 / 2;
  perspective: 950px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 20px 40px rgba(120, 96, 58, 0.34));
  /* one long continuous zoom-in (transform) that carries through the whole open;
     opacity fades only in the back half so it dissolves into the page */
  transform: scale(1); /* explicit base so the zoom has a clean "from" state */
  transition: transform 3s cubic-bezier(0.32, 0, 0.24, 1), opacity 1.1s ease;
  transform-origin: center center;
}
.envelope:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 16px; border-radius: 10px; }
body.opening .envelope { transform: scale(3.2); }
body.entering .envelope { opacity: 0; }
.envelope.idle { animation: envBreath 4.6s ease-in-out infinite; }
@keyframes envBreath { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.env-inside, .env-pocket, .env-flap {
  position: absolute; inset: 0; border-radius: 9px;
}
.env-inside { background: linear-gradient(180deg, var(--env-inside), #efe4cd); }

/* three static pockets that form the envelope front (triangles meeting at center) */
.env-pocket { }
.env-left   { background: linear-gradient(90deg, var(--env-pocket), var(--env-pocket-lo)); clip-path: polygon(0 0, 0 100%, 50% 50%); }
.env-right  { background: linear-gradient(-90deg, var(--env-pocket), var(--env-pocket-lo)); clip-path: polygon(100% 0, 100% 100%, 50% 50%); }
.env-bottom { background: linear-gradient(0deg, var(--env-pocket-lo), var(--env-pocket)); clip-path: polygon(0 100%, 100% 100%, 50% 50%); box-shadow: inset 0 -1px 0 rgba(176,141,87,0.25); }
/* faint gold seams down to the center */
.env-pocket::after { content: ""; position: absolute; inset: 0; }
.env-left::after  { border-right: 1px solid rgba(176,141,87,0.16); clip-path: polygon(0 0, 0 100%, 50% 50%); }

/* the top flap — hinged at the top edge, sealed at its point */
.env-flap {
  height: 50%;
  transform-origin: top center;
  transform: rotateX(0deg);
  background: linear-gradient(180deg, #f2e7ce 0%, var(--env-flap) 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  backface-visibility: hidden;
  z-index: 3;
  filter: drop-shadow(0 3px 3px rgba(150, 116, 63, 0.22));
  transition: transform 1.2s cubic-bezier(0.5, 0.05, 0.2, 1);
}
body.opening .env-flap, body.entering .env-flap { transform: rotateX(180deg); }

.wax-seal {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 78px; height: 78px;
  z-index: 5;
  transition: opacity 0.6s ease 0.2s, transform 0.8s ease 0.2s;
}
.wax-seal img {
  width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 5px 7px rgba(138, 116, 77, 0.42));
}
body.opening .wax-seal, body.entering .wax-seal { opacity: 0; transform: translate(-50%, -50%) scale(0.72); }

/* ── main page ───────────────────────────────────────────── */
.main {
  min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: clamp(16px, 3vh, 28px);
  /* start below the language button so the card never sits under it; the page
     scrolls if the content is taller than the viewport */
  padding: max(96px, calc(env(safe-area-inset-top) + 70px)) 20px 44px;
  background: linear-gradient(120% 120% at 50% 0%, #f9f3e6 0%, var(--linen) 55%, var(--linen-deep) 100%);
  opacity: 0;
  transform: scale(1.14);
  transition: opacity 1.3s ease, transform 1.8s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.main::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.5;
  background-image:
    repeating-linear-gradient(0deg, rgba(150,124,78,0.05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(150,124,78,0.05) 0 1px, transparent 1px 3px);
}
body.entering .main, body.opened .main { opacity: 1; transform: scale(1); }

/* framed oval photo */
.frame-wrap {
  position: relative;
  width: min(80vw, 344px);
  aspect-ratio: 420 / 560;
  filter: drop-shadow(0 18px 40px rgba(90, 72, 44, 0.24));
  touch-action: none;
}
.photo, #scratchCanvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
/* photo is clipped to the oval; the canvas is NOT (a full-rect touch target is
   reliable on mobile — clip-path hit-testing isn't). The overlay paint is
   clipped to the oval in JS, and the frame mat hides everything outside it. */
.photo {
  object-fit: cover; user-select: none; -webkit-user-select: none;
  clip-path: ellipse(var(--oval-rx) var(--oval-ry) at 50% 50%);
}
#scratchCanvas { touch-action: none; cursor: pointer; transition: opacity 1s ease; }
.frame-wrap.revealed #scratchCanvas { opacity: 0; pointer-events: none; }
.frame-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; user-select: none; }
/* confetti stays within the card (image borders) */
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 7; }

.scratch-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px;
  background: rgba(255, 252, 244, 0.82);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(176, 141, 87, 0.4);
  color: var(--ink-soft);
  font-size: 12.5px; letter-spacing: 0.14em; text-transform: uppercase; white-space: nowrap;
  pointer-events: none;
  animation: hintFade 2.6s ease-in-out infinite;
  transition: opacity 0.4s;
}
.scratch-hint svg { width: 18px; height: 18px; }
/* animation: none is required — a running keyframe animation overrides `opacity: 0` */
.frame-wrap.scratching .scratch-hint, .frame-wrap.revealed .scratch-hint { opacity: 0; animation: none; }
.frame-wrap.revealed .scratch-hint { visibility: hidden; }

/* details — hidden until the scratch is finished */
.details {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  text-align: center; max-width: 420px;
  opacity: 0; transform: translateY(20px); pointer-events: none;
  transition: opacity 0.9s ease, transform 1s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.details.shown { opacity: 1; transform: none; pointer-events: auto; }

.eyebrow { font-size: 11px; letter-spacing: 0.4em; text-transform: uppercase; color: var(--gold-deep); }
html[lang="ar"] .eyebrow { font-size: 15px; }
.names {
  font-family: var(--script);
  font-weight: 400;
  font-size: clamp(46px, 13vw, 66px);
  letter-spacing: 0.01em;
  line-height: 1.05;
  color: var(--gold-deep);
}
html[lang="ar"] .names { font-family: "Amiri", serif; font-size: clamp(34px, 10vw, 50px); }
.rule { display: flex; align-items: center; gap: 10px; width: 150px; color: var(--gold); font-size: 11px; margin: 3px 0; }
.rule::before, .rule::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, rgba(176,141,87,0.6), transparent); }
.date { font-size: 15px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink); }
html[lang="ar"] .date { font-size: 18px; }
.venue { font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--ink-soft); }
.actions { display: flex; flex-direction: column; align-items: center; gap: 11px; margin-top: 16px; }
.solid-btn {
  padding: 13px 32px; border: none; border-radius: 999px;
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-deep) 100%);
  color: #fdfaf2; font-family: var(--sans); font-size: 12.5px; font-weight: 500;
  letter-spacing: 0.22em; text-transform: uppercase; cursor: pointer;
  box-shadow: 0 8px 20px -8px rgba(150, 116, 63, 0.7);
  transition: transform 0.2s, box-shadow 0.2s;
}
.solid-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -8px rgba(150, 116, 63, 0.85); }
.text-link { color: var(--ink-soft); font-size: 13px; letter-spacing: 0.06em; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.text-link:hover { color: var(--gold-deep); }

/* ── reduced motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .seal-hint, .scratch-hint, .envelope.idle { animation: none; }
  .env-flap, .envelope, .main, #scratchCanvas, .details { transition-duration: 0.25s; }
}
