/* The Impossible Invitation. Brand tokens from repo/src/styles/global.css (ink, paper, gold). */
@font-face {
  font-family: 'Instrument Serif';
  src: url('fonts/instrument-serif-latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Instrument Serif';
  src: url('fonts/instrument-serif-latin-400-italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'Archivo';
  src: url('fonts/archivo-latin-wdth-normal.woff2') format('woff2-variations');
  font-weight: 100 900; font-stretch: 62% 125%; font-display: swap;
}

:root {
  --ink: #0b0b0c;
  --paper: #f3efe6;
  --gold: #c9a063;
  --gold-hi: #e2c18c;
  --print: #3d3428;           /* letterpress ink on the cotton card */
  --muted: #b9b2a5;
  --serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --sans: 'Archivo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --vh: 100vh;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); }
body {
  font-family: var(--sans);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 3px; }

/* ---------- Stage: one 9:16 film frame, always full height. Phones lose a little at the sides, desktops get black sides. */
/* Height is capped at 222vw (= 1.25 x the width a 9:16 frame needs), so very narrow windows lose at most 10 % per side
   and get black above and below instead. Real phones (19.5:9 and wider) are never capped. */
.stage {
  position: fixed; top: 50%; left: 50%;
  height: min(var(--vh), 222.2vw); width: calc(min(var(--vh), 222.2vw) * 9 / 16);
  transform: translate(-50%, -50%);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
.cam { position: absolute; inset: 0; transform-origin: 50% 50%; will-change: transform; }
.still, .clip {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block;
  pointer-events: none;
}
.clip { opacity: 0; }
.clip.is-on { opacity: 1; }
.still { z-index: 2; transition: opacity 0.35s ease; }
.still.is-off { opacity: 0; }
#va { z-index: 1; }
#vc { z-index: 0; }

/* Arrival: the beam finds the object (a soft mask that opens from the top). */
.cam { opacity: 0; }
.is-arriving .cam, .is-ready .cam { opacity: 1; transition: opacity 1.6s ease; }
.is-arriving .cam {
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 var(--reveal, 0%), transparent calc(var(--reveal, 0%) + 30%));
          mask-image: linear-gradient(to bottom, #000 0%, #000 var(--reveal, 0%), transparent calc(var(--reveal, 0%) + 30%));
}

/* ---------- Seal tension (positions measured on K1 / clip A frame 0) */
.seam {
  position: absolute; z-index: 3; pointer-events: none;
  left: 49.91%; top: 23.3%; height: 54.7%; width: 0.9%;
  transform: translateX(-50%) scaleX(0); opacity: 0;
  background: linear-gradient(to bottom, transparent, rgba(255, 214, 150, 0.9) 18%, #fff3da 50%, rgba(255, 214, 150, 0.9) 82%, transparent);
  filter: blur(0.6px);
  mix-blend-mode: screen;
}
.crack {
  position: absolute; z-index: 4; pointer-events: none; overflow: visible;
  left: 42.47%; top: 46.35%; width: 14.87%; height: 8.3%;
}
.crack path {
  fill: none; stroke: rgba(70, 48, 20, 0.85); stroke-width: 0.9; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 1; stroke-dashoffset: 1;
}
.seal {
  position: absolute; z-index: 5;
  left: 49.91%; top: 50.5%; width: 26%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 0; border-radius: 50%; background: transparent; padding: 0; cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
}
.seal-ring {
  position: absolute; left: 50%; top: 50%; width: 62%; aspect-ratio: 1; border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px rgba(226, 193, 140, 0.55);
  opacity: 0;
}
.is-idle-hint .seal-ring { animation: ring 2.8s ease-in-out infinite; }
@keyframes ring {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
}

/* ---------- Card layer: lies exactly on the card in K3 (frames/card-rect.json, 1080 x 1920: 354,750 392 x 592) */
.card {
  position: absolute; z-index: 6;
  left: 32.778%; top: 39.0625%; width: 36.296%; height: 30.833%;
  container-type: inline-size;
  background: url('media/card.webp') center / 100% 100% no-repeat;
  opacity: 0; pointer-events: none;
  color: var(--print);
}
.card.is-on { opacity: 1; }
.card.is-touchable { pointer-events: auto; cursor: pointer; }
.card-text {
  position: absolute; left: 9%; right: 9%; top: 10%; height: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4.5cqw;
  text-align: center;
}
.card-text p { margin: 0; opacity: 0; transition: opacity 0.9s ease; }
.card.is-printed .card-text p { opacity: 1; }
.card.is-printed .card-text p:nth-child(2) { transition-delay: 0.35s; }
.card.is-printed .card-text p:nth-child(3) { transition-delay: 0.7s; }
/* Letterpress: ink pressed into the paper (a light lower edge, a dark upper edge). */
.card-text p, .foil-date {
  text-shadow: 0 0.06em 0 rgba(255, 255, 255, 0.55), 0 -0.03em 0 rgba(0, 0, 0, 0.18);
}
.card-eyebrow {
  font-family: var(--sans); font-size: 3.4cqw; letter-spacing: 0.22em; text-transform: uppercase; font-weight: 500;
}
.card-names { font-family: var(--serif); font-size: 12.5cqw; line-height: 1; }
.card-line { font-family: var(--serif); font-style: italic; font-size: 5.2cqw; line-height: 1.2; }

.foil {
  /* card-local 20,373 352 x 192 of 392 x 592: a few px wider than the foil in the footage, so none of it shows once scratched */
  position: absolute; left: 5.102%; top: 63.007%; width: 89.796%; height: 32.432%;
  background: url('media/paper.webp') center / 100% 100% no-repeat;
}
.foil-date {
  position: absolute; inset: 0; margin: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1cqw;
  text-align: center;
}
.foil-weekday { font-family: var(--sans); font-size: 3.6cqw; letter-spacing: 0.24em; text-transform: uppercase; font-weight: 500; }
.foil-day { font-family: var(--serif); font-size: 11cqw; line-height: 1; }
.foil-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none; cursor: crosshair;
  pointer-events: auto; /* the card layer itself lets touches through; the foil takes them */
  /* A hairline shadow along every scratched edge: the foil reads as a thin layer on the paper. */
  filter: drop-shadow(0 0.5px 0.6px rgba(40, 26, 8, 0.55));
}
.foil-canvas.is-done { visibility: hidden; }

/* ---------- Lines and hints: on the black below the object, never on the film's subject */
.lines {
  position: absolute; z-index: 8; left: 50%; bottom: calc(5% + env(safe-area-inset-bottom));
  width: min(92vw, 100%); transform: translateX(-50%);
  text-align: center; pointer-events: none;
}
.line { margin: 0; font-family: var(--serif); font-weight: 400; color: var(--paper); opacity: 0; transition: opacity 1.2s ease; }
.line-1 { font-size: clamp(1.6rem, 3.4vh, 2.3rem); line-height: 1.1; }
.line-2 { font-size: clamp(1.05rem, 2.1vh, 1.35rem); font-style: italic; color: var(--gold-hi); margin-top: 0.35em; }
.is-ready .line, .is-arriving .line-1 { opacity: 1; }
.is-ready .line-2 { transition-delay: 0.6s; }
.lines.is-gone .line { opacity: 0; transition-duration: 0.5s; transition-delay: 0s; }
.hint {
  display: inline-block; margin: 0.9em 0 0; padding: 0.45em 1em; border-radius: 999px;
  font-size: 0.9rem; letter-spacing: 0.04em; color: var(--paper);
  /* The hint can sit on light marble after the zoom; a dark pill keeps it readable. */
  background: rgba(11, 11, 12, 0.68);
  opacity: 0; transition: opacity 0.6s ease;
}
.hint:empty { display: none; }
.text-button { background: rgba(11, 11, 12, 0.55); border-radius: 999px; }
.hint.is-on { opacity: 1; }
.text-button {
  pointer-events: auto; margin-top: 0.6em; padding: 0.5em 0.9em; min-height: 44px;
  background: none; border: 0; color: var(--gold-hi); text-decoration: underline; text-underline-offset: 0.25em;
  font-size: 0.9rem; cursor: pointer;
}

.skip {
  position: fixed; z-index: 20;
  top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  padding: 0.55em 1em; min-height: 44px; display: inline-flex; align-items: center;
  font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; text-decoration: none;
  color: var(--paper); background: rgba(11, 11, 12, 0.55); border: 1px solid rgba(201, 160, 99, 0.45); border-radius: 999px;
}
.skip[hidden] { display: none; }

/* ---------- The readable invitation */
.invite {
  position: fixed; inset: 0; z-index: 15; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: rgba(11, 11, 12, 0.72);
  padding: calc(28px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
  outline: none;
}
.invite[hidden] { display: none; }
.invite-inner { max-width: 30rem; margin: 0 auto; }
.invite-card-slot { width: min(80vw, 22rem); aspect-ratio: 392 / 592; margin: 0 auto 2rem; position: relative; }
.invite-card-slot .card {
  position: absolute; inset: 0; width: 100%; height: 100%; left: 0; top: 0;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.invite-details { opacity: 0; transform: translateY(12px); transition: opacity 0.8s ease 0.3s, transform 0.8s ease 0.3s; }
.invite.is-open .invite-details { opacity: 1; transform: none; }
.facts { margin: 0; display: grid; gap: 1rem; border-top: 1px solid rgba(201, 160, 99, 0.35); padding-top: 1.4rem; }
.facts div { display: grid; grid-template-columns: 7.5rem 1fr; gap: 0.75rem; }
.facts dt { font-size: 0.75rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-hi); padding-top: 0.2em; }
.facts dd { margin: 0; font-size: 1.05rem; line-height: 1.45; }
.message { margin: 1.6rem 0; font-family: var(--serif); font-size: 1.25rem; line-height: 1.45; color: #ece6da; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0.7em 1.3em;
  border-radius: 999px; border: 1px solid rgba(201, 160, 99, 0.6); background: transparent; color: var(--paper);
  font-size: 0.95rem; text-decoration: none; cursor: pointer;
}
.button-gold { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 600; }
.button[hidden] { display: none; }
.share-status { min-height: 1.3em; margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); }
.replay { display: block; margin: 1.5rem auto 0; color: var(--muted); }

.error { position: fixed; inset: auto 16px 40% 16px; z-index: 30; text-align: center; font-family: var(--serif); font-size: 1.3rem; }
.error[hidden] { display: none; }

@media (max-width: 380px) {
  .facts div { grid-template-columns: 1fr; gap: 0.15rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .card-text p, .line, .hint, .invite-details, .is-arriving .cam, .is-ready .cam { transition-duration: 0.01s !important; transition-delay: 0s !important; }
  .is-arriving .cam { -webkit-mask-image: none; mask-image: none; }
}
