:root {
  --navy: #174e7c;
  --navy-dark: #103a5d;
  --ink: #174e7c;
  --paper: #ffffff;
  --bg: #eaf1f7;
  --radius: 22px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; }
html { scroll-behavior: smooth; }
body { background: var(--bg); color: var(--ink); line-height: 1.4; }
a { color: inherit; text-decoration: none; }
.icon { width: 1em; height: 1em; fill: currentColor; vertical-align: -0.12em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  padding: 14px 24px; border-radius: 999px; font-weight: 700; cursor: pointer;
  background: var(--navy); color: #fff; border: 2px solid var(--navy);
  transition: transform .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn--outline { background: transparent; color: var(--navy); }
.btn--outline:hover { background: var(--navy); color: #fff; }
.btn--light { background: #fff; color: var(--navy); border-color: #fff; }

/* ---------- Cover ---------- */
.cover {
  min-height: 100svh; display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 24px; padding: 40px 16px; color: #fff; text-align: center; overflow: hidden;
  background:
    radial-gradient(circle at 85% 20%, rgba(255,255,255,.12), transparent 40%),
    linear-gradient(160deg, var(--navy) 0%, var(--navy-dark) 100%);
}
.cover__route { letter-spacing: .25em; font-size: .78rem; font-weight: 700; opacity: .85; }
.cover__hint { font-size: 1.4rem; font-weight: 800; transition: opacity .4s ease; }
.cover__hint span { font-size: .9rem; font-weight: 500; opacity: .8; }
.cover__cta { white-space: nowrap; padding: 14px 20px; font-size: clamp(.82rem, 3.8vw, 1rem); opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity .6s ease 2.4s, transform .6s ease 2.4s; }
.is-opened .cover__hint { opacity: 0; height: 0; margin: -12px 0; overflow: hidden; }
.is-opened .cover__cta { opacity: 1; pointer-events: auto; transform: none; }

/* ---------- Envelope ----------
   Layers, back to front: back (1) → letter (2, jumps to 6 once it is out) → front pocket (3) → flap (4) → seal (5).
   --W/--H size everything so the opening animation scales with the screen. */
.envelope-stage {
  --W: min(86vw, 360px); --H: calc(var(--W) * .66);
  padding-top: 0; transition: padding-top 1s ease .6s;
}
.is-opened .envelope-stage { padding-top: calc(var(--H) * 1.2); }
.envelope {
  position: relative; width: var(--W); height: var(--H); perspective: 900px; cursor: pointer;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .35)); animation: nudge 2.4s ease-in-out infinite;
}
.envelope:focus-visible { outline: 3px solid #bfe0ff; outline-offset: 8px; border-radius: 8px; }
.is-opened .envelope { cursor: default; animation: none; }
@keyframes nudge { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-3deg); } 90% { transform: rotate(3deg); } 95% { transform: rotate(-2deg); } }

.envelope__back { position: absolute; inset: 0; background: #d7e2ee; border-radius: 10px; z-index: 1; }
.envelope__front {
  position: absolute; inset: 0; z-index: 3; border-radius: 0 0 10px 10px; background: #f6f9fc;
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; padding-bottom: 18px;
  color: var(--navy);
}
.envelope__label { font-size: .72rem; font-weight: 800; letter-spacing: .28em; transition: opacity .3s ease 1.3s; }
.is-opened .envelope__label { opacity: 0; } /* the opened letter covers it only partly */
.envelope__to { font-size: .95rem; }
.envelope__flap {
  position: absolute; left: 0; top: 0; width: 100%; height: 60%; z-index: 4; background: #e9f0f7;
  clip-path: polygon(0 0, 100% 0, 50% 100%); transform-origin: top;
  transition: transform .6s ease, z-index 0s linear .3s;
}
.is-opened .envelope__flap { transform: rotateX(180deg); z-index: 1; }
.envelope__seal {
  position: absolute; left: 50%; top: 60%; z-index: 5; width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.6rem; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #e8c25a, #b8892a); box-shadow: 0 3px 8px rgba(0,0,0,.3), inset 0 0 0 4px rgba(255,255,255,.25);
  transition: opacity .3s ease, transform .3s ease;
}
.is-opened .envelope__seal { opacity: 0; transform: translate(-50%, -50%) scale(.6); }

/* Letter: starts tucked inside, slides up out of the envelope, then grows and settles in front of it */
.letter {
  position: absolute; left: 4%; width: 92%; bottom: 8px; height: calc(var(--H) - 16px); z-index: 2;
  display: flex; flex-direction: column; align-items: center; overflow: hidden; border-radius: 8px;
  padding: 18px 16px 0; color: var(--navy);
  background: radial-gradient(circle at 50% 70%, #ffe1c2 0, transparent 62%), #fffdf8;
  box-shadow: inset 0 0 0 6px #fffdf8, inset 0 0 0 7px rgba(23, 78, 124, .25);
}
.is-opened .letter { animation: letter-out 1.6s cubic-bezier(.5, 0, .25, 1) .5s forwards; }
@keyframes letter-out {
  0%   { transform: translateY(0);                       height: calc(var(--H) - 16px); z-index: 2; }
  45%  { transform: translateY(calc(var(--H) * -1.05));  height: calc(var(--H) - 16px); z-index: 2; }
  50%  { transform: translateY(calc(var(--H) * -1.05));  height: calc(var(--H) - 16px); z-index: 6; }
  100% { transform: translateY(calc(var(--H) * -.2));    height: calc(var(--H) * 1.95); z-index: 6; }
}
.letter__dear { font-size: .9rem; }
.letter__title { font-family: "Dancing Script", cursive; font-size: 2.3rem; line-height: 1.1; margin: 2px 0 4px; }
.letter__photo { flex: 1; min-height: 0; width: 100%; object-fit: cover; object-position: top; }
/* Photo wipes in from the top of the head down, once the letter is in front of the envelope */
.is-opened .letter__photo { animation: photo-reveal 1s ease-out 1.3s both; }
@keyframes photo-reveal { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }
.letter__meta {
  align-self: stretch; margin: 0 -16px; padding: 10px; background: var(--navy); color: #fff;
  font-size: clamp(.68rem, 3.2vw, .8rem); font-weight: 700; letter-spacing: .1em; white-space: nowrap;
}

/* The rest of the invitation stays hidden until the envelope is opened */
.js:not(.is-opened) main, .js:not(.is-opened) .footer { display: none; }

/* ---------- Sections ---------- */
.section { padding: 64px 16px; display: flex; flex-direction: column; align-items: center; gap: 32px; }
.section--navy { background: var(--navy); color: #fff; }
.section__title { font-size: 1.8rem; font-weight: 800; letter-spacing: .04em; text-align: center; }
.section__title--navy { color: var(--navy); }

/* ---------- Ticket (mobile first: stacked) ---------- */
.ticket {
  width: 100%; max-width: 1100px; display: grid; grid-template-columns: 1fr;
  background: var(--paper); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 20px 50px rgba(16, 58, 93, .18);
}
.ticket__rail {
  background: var(--navy); color: #fff; text-align: center; padding: 12px;
  font-weight: 700; letter-spacing: .3em; font-size: .8rem;
}
.ticket__code { display: none; }
.ticket__main { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; padding: 20px 24px; }
.ticket__center {
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px 24px 28px;
  border-top: 3px dotted var(--navy); text-align: center;
}
.ticket__class { font-size: 2rem; font-weight: 800; line-height: 1.05; align-self: flex-start; }
.ticket__plane { width: 120px; height: 120px; fill: var(--navy); transform: rotate(-12deg); }
.ticket__msg { font-size: .95rem; }
.ticket__stub {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; padding: 24px;
  background: var(--navy); color: #fff; border-radius: var(--radius) var(--radius) 0 0;
}
.ticket__stub .field { border-color: rgba(255,255,255,.6); }
.ticket__stub .barcode { grid-column: 1 / -1; height: 56px; margin-bottom: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; padding: 12px 0; border-bottom: 1.5px dotted var(--navy); min-width: 0; }
.field--full { grid-column: 1 / -1; }
.field__link { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; }
.field__link .icon { width: 1.25em; height: 1.25em; transition: transform .2s ease; }
.field__link:hover .icon { transform: translateY(-3px); }
.field__label { font-size: .85rem; opacity: .85; }
.field__value { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.ticket [data-guest] { text-transform: uppercase; }
.ticket__main .field:last-child { border-bottom: 0; }

/* Barcode: bars are generated in script.js; flex-basis sets bar thickness */
.barcode { display: flex; gap: 3px; overflow: hidden; }
.barcode i { flex: 0 0 var(--w); background: currentColor; }
.barcode--rows { flex-direction: column; color: var(--navy); }
.barcode--cols { flex-direction: row; color: #fff; }

/* ---------- Ticket (desktop: horizontal like the printed card) ---------- */
@media (min-width: 900px) {
  .ticket { grid-template-columns: 64px 120px 1.3fr 1fr 1.4fr; min-height: 440px; }
  .ticket__rail {
    writing-mode: vertical-rl; transform: rotate(180deg); display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius) 0 0 var(--radius); /* rotated 180°, so this rounds the right edge */
  }
  .ticket__code {
    display: flex; align-items: center; gap: 10px; padding: 20px 12px; border-right: 3px dotted var(--navy);
  }
  .ticket__code .barcode { flex: 1; }
  .ticket__number {
    writing-mode: vertical-rl; transform: rotate(180deg); font-weight: 800; letter-spacing: .15em; text-align: center;
  }
  .ticket__main { grid-auto-rows: min-content; align-content: center; }
  .ticket__center { border-top: 0; border-left: 3px dotted var(--navy); justify-content: center; }
  .ticket__stub { margin: 16px 16px 16px 0; border-radius: var(--radius); align-content: center; }
  .ticket__stub .barcode { height: 64px; }
}

/* ---------- Timeline ---------- */
.timeline {
  position: relative; width: 100%; max-width: 760px;
  display: flex; justify-content: space-between;
  --stop: 120px; /* fixed stop width so the plane can land exactly on each star */
}
.timeline__track {
  position: absolute; left: 0; right: 0; top: 50%; border-top: 2px dotted rgba(255,255,255,.8);
}
.timeline__plane {
  position: absolute; left: calc(var(--stop) / 2); top: 0; width: 44px; height: 44px; fill: #fff;
  transform: translate(-50%, -50%); transition: left 2.6s cubic-bezier(.45, .05, .25, 1);
}
.timeline.is-flying .timeline__plane { left: calc(100% - var(--stop) / 2); }
.timeline__stop { width: var(--stop); position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 1; }
.timeline__time { font-size: 1.5rem; font-weight: 800; }
.timeline__star { font-size: 2.6rem; line-height: 1; text-shadow: 0 0 18px rgba(255,255,255,.6); }
/* The landing star fades out just as the plane arrives, so the plane takes its place */
.timeline__stop:last-child .timeline__star { transition: opacity .4s ease 2.2s; }
.timeline.is-flying .timeline__stop:last-child .timeline__star { opacity: 0; }
.timeline__label { font-size: .95rem; opacity: .9; }

/* ---------- Countdown ---------- */
.countdown { text-align: center; }
.countdown__caption { letter-spacing: .2em; text-transform: uppercase; font-size: .8rem; opacity: .85; margin-bottom: 12px; }
.countdown__grid { display: flex; gap: 12px; justify-content: center; }
.countdown__grid div {
  min-width: 68px; padding: 12px 6px; border-radius: 14px; background: rgba(255,255,255,.12);
  display: flex; flex-direction: column;
}
.countdown__grid strong { font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.countdown__grid span { font-size: .75rem; opacity: .8; }

/* ---------- Actions ---------- */
.actions { display: grid; gap: 12px; width: 100%; max-width: 640px; }
@media (min-width: 600px) { .actions { grid-template-columns: repeat(3, 1fr); } }
.closing { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.closing__sub { font-size: 1.05rem; }

.footer { padding: 28px 16px; text-align: center; font-size: .8rem; letter-spacing: .15em; background: var(--navy-dark); color: #fff; }

/* ---------- Reveal on scroll (only hidden when JS is running) ---------- */
.js .reveal { opacity: 0; transform: translateY(24px); transition: opacity .7s ease, transform .7s ease; }
.js .reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js .reveal, .timeline__plane, .btn { transition: none; }
  .envelope { animation: none; }
  .is-opened .letter, .is-opened .letter__photo { animation-duration: .01s; animation-delay: 0s; }
  .envelope-stage, .envelope__flap, .cover__cta { transition-duration: .01s; transition-delay: 0s; }
}
