/* =============================================================
   Storybook train theme — elegant & loveable
   soft sky · friendly blue engine · warm cream · gentle greens
   ============================================================= */
:root {
  --sky-1: #BFE3FB;
  --sky-2: #E8F4FF;
  --cream: #FCFAF4;       /* card */
  --cream-2: #F5F0E5;     /* panels */
  --blue: #3B86CC;
  --blue-deep: #205E9C;
  --red: #E15B53;
  --yellow: #F4C84A;
  --grass: #8DBE82;
  --ink: #33414C;
  --ink-soft: #6E7B86;
  --line: rgba(32, 94, 156, 0.16);
  --shadow: 0 30px 70px -28px rgba(32, 70, 110, 0.45);
  --radius: 22px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;            /* grow with content so the page can scroll */
  overflow-x: hidden;          /* never allow sideways scroll */
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, #D8EEFC 44%, var(--sky-2) 100%);
  background-attachment: fixed;
  /* flex-start so a tall card never gets clipped at the top */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 18px 28px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Confetti canvas ---------- */
#confetti {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 60;
}

/* ---------- Drifting background clouds ---------- */
.clouds { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.cloud {
  position: absolute;
  width: 96px; height: 30px;
  background: #ffffff;
  border-radius: 30px;
  opacity: 0.55;
  filter: blur(0.3px);
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; background: #fff; border-radius: 50%;
}
.cloud::before { width: 48px; height: 48px; top: -22px; left: 14px; }
.cloud::after  { width: 34px; height: 34px; top: -14px; left: 48px; }
.c1 { top: 12%; left: -120px; transform: scale(1);    animation: sail 48s linear infinite; }
.c2 { top: 26%; left: -160px; transform: scale(0.7);  animation: sail 66s linear infinite 8s; opacity: 0.4; }
.c3 { top: 8%;  left: -140px; transform: scale(1.25); animation: sail 80s linear infinite 20s; opacity: 0.5; }
@keyframes sail {
  from { transform: translateX(0); }
  to   { transform: translateX(115vw); }
}

/* ---------- Card ---------- */
.card {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 600px;
  min-width: 0;                /* allow shrink below the SVG's intrinsic width */
  flex-shrink: 0;              /* never shrink vertically (would clip the form) */
  background: var(--cream);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;            /* clips the hero to the rounded top */
  animation: rise 0.8s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Hero train ---------- */
.hero { line-height: 0; }
.hero-svg { display: block; width: 100%; max-width: 100%; height: auto; }

.train { transform-box: fill-box; transform-origin: center; animation: chug 0.45s ease-in-out infinite; }
@keyframes chug { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-1.5px); } }

/* spinning wheels */
.wheel { transform-box: fill-box; transform-origin: center; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* scrolling sleepers — seamless because ties repeat every 50 units */
.ties { animation: roll 0.9s linear infinite; }
@keyframes roll { from { transform: translateX(0); } to { transform: translateX(-50px); } }

/* steam puffs that rise and trail backward (engine faces left) */
.smoke .puff { opacity: 0; transform-box: fill-box; transform-origin: center; }
.smoke .p1 { animation: puff 1.8s ease-out infinite; }
.smoke .p2 { animation: puff 1.8s ease-out infinite 0.6s; }
.smoke .p3 { animation: puff 1.8s ease-out infinite 1.2s; }
@keyframes puff {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.45); }
  25%  { opacity: 0.9; }
  100% { opacity: 0; transform: translate(26px, -30px) scale(1.5); }
}
.puffcloud { transform-box: fill-box; }
.cl-a { animation: floatx 24s ease-in-out infinite; }
.cl-b { animation: floatx 30s ease-in-out infinite; }
@keyframes floatx { 0%,100% { transform: translateX(0); } 50% { transform: translateX(12px); } }

/* ---------- Content ---------- */
.content { padding: 48px 56px 50px; text-align: center; }

.eyebrow {
  font-family: "Nunito", sans-serif;
  font-weight: 600;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--blue-deep);
  margin: 0 0 16px;
  padding-left: 0.34em;
}

.title { margin: 0; line-height: 1; }
.honoree {
  display: block;
  font-family: "Cormorant Garamond", serif;
  font-weight: 600;
  font-size: clamp(3.8rem, 15vw, 6rem);
  color: var(--ink);
  letter-spacing: 0.01em;
  line-height: 0.98;
}
.age-line {
  display: block;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-weight: 500;
  color: var(--ink-soft);
  font-size: clamp(1.45rem, 5.4vw, 2rem);
  margin-top: 12px;
}
.age {
  font-family: "Fredoka", sans-serif;
  font-style: normal;
  font-weight: 600;
  color: var(--red);
  font-size: 1.15em;
  margin-left: 2px;
}

/* ---------- Ornament divider ---------- */
.ornament {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; margin: 24px auto; max-width: 220px;
}
.ornament .rule { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--blue) 70%); }
.ornament .rule:last-child { background: linear-gradient(90deg, var(--blue), transparent 70%); }
.ornament .mark { color: var(--blue); font-size: 0.8rem; }

.intro {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.55rem;
  line-height: 1.55;
  color: var(--ink);
  margin: 0 auto 36px;
  max-width: 34ch;
}

/* ---------- Details ---------- */
.details {
  list-style: none;
  margin: 0;
  padding: 34px 6px;
  display: grid;
  gap: 24px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.details li { display: grid; grid-template-columns: 104px 1fr; align-items: baseline; gap: 18px; }
.details li[hidden] { display: none; }
.d-label {
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.7rem;
  color: var(--blue-deep);
  padding-top: 5px;
}
.d-value {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.45rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.35;
}
.details a { color: var(--blue-deep); text-decoration: none; border-bottom: 1px solid var(--blue); padding-bottom: 1px; }
.details a:hover { color: var(--blue); }

/* ---------- Form ---------- */
.rsvp { margin-top: 34px; text-align: left; }
.rsvp-heading {
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.26em;
  font-size: 0.82rem;
  color: var(--blue-deep);
  text-align: center;
  margin: 0 0 26px;
  padding-left: 0.26em;
}

.field { display: block; margin-bottom: 24px; border: none; padding: 0; }
.label-text {
  display: block;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 0.92rem;
  margin-bottom: 10px;
  color: var(--ink);
}
.optional { font-weight: 400; color: var(--ink-soft); font-size: 0.82rem; }

input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  font-family: "Nunito", sans-serif;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid rgba(51,65,76,0.16);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input::placeholder, textarea::placeholder { color: #aeb6bd; }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,134,204,0.16);
}
textarea { resize: vertical; min-height: 76px; }

/* attending choices */
.attending .choices { display: flex; gap: 10px; }
.choice { flex: 1; position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.pill {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 56px;
  font-family: "Nunito", sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1.5px solid rgba(51,65,76,0.16);
  color: var(--ink-soft);
  transition: all 0.2s;
  user-select: none;
}
.choice:hover .pill { border-color: var(--blue); color: var(--ink); }
.choice input:checked + .pill {
  background: var(--blue);
  border-color: var(--blue-deep);
  color: #fff;
  box-shadow: 0 10px 22px -12px rgba(32,94,156,0.9);
}
.choice input:focus-visible + .pill { box-shadow: 0 0 0 3px rgba(59,134,204,0.3); }

/* collapsing guests field */
#guestsField { overflow: hidden; max-height: 140px; opacity: 1;
  transition: max-height 0.35s ease, opacity 0.3s ease, margin 0.35s ease; }
#guestsField.hidden { max-height: 0; opacity: 0; margin-bottom: 0; }

.error {
  color: #c0392b;
  font-family: "Nunito", sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0 0 14px;
  text-align: center;
}

/* ---------- RSVPs closed notice ---------- */
.closed {
  margin: 30px auto 4px;
  padding: 26px;
  max-width: 38ch;
  background: var(--cream-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: "Cormorant Garamond", serif;
  font-size: 1.35rem;
  line-height: 1.55;
  color: var(--ink);
}

/* ---------- Buttons ---------- */
.submit {
  width: 100%;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #fff;
  background: linear-gradient(180deg, var(--blue) 0%, var(--blue-deep) 100%);
  border: none;
  border-radius: var(--radius-sm);
  padding: 17px;
  cursor: pointer;
  box-shadow: 0 14px 28px -14px rgba(32,94,156,0.95);
  transition: transform 0.15s, box-shadow 0.2s, filter 0.2s;
}
.submit:hover { transform: translateY(-2px); box-shadow: 0 18px 34px -14px rgba(32,94,156,0.95); filter: brightness(1.04); }
.submit:active { transform: translateY(0); }
.submit[disabled] { filter: grayscale(0.3) brightness(0.97); cursor: wait; opacity: 0.85; }

.rsvp-by {
  text-align: center;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.1rem;
  margin: 20px 0 0;
}

.ghost {
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--blue-deep);
  background: transparent;
  border: 1.5px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 13px 26px;
  cursor: pointer;
  transition: all 0.2s;
}
.ghost:hover { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- Thank-you ---------- */
.thanks { animation: rise 0.6s cubic-bezier(.2,.7,.2,1) both; padding: 16px 0 8px; text-align: center; }
.thanks-emoji { font-size: 3.4rem; }
.thanks-title {
  font-family: "Cormorant Garamond", serif;
  font-weight: 600;
  color: var(--blue-deep);
  font-size: 2.2rem;
  margin: 12px 0 12px;
}
.thanks-msg {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.32rem;
  line-height: 1.55;
  color: var(--ink);
  margin: 0 auto 28px;
  max-width: 32ch;
}

/* ---------- Add to calendar ---------- */
.cal {
  margin: 6px auto 26px;
  padding: 24px;
  background: var(--cream-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.cal-label {
  margin: 0 0 14px;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  font-size: 0.9rem;
}
.cal-btns { display: flex; gap: 10px; justify-content: center; }
.cal-btn {
  flex: 1;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--blue-deep);
  background: #fff;
  border: 1.5px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 13px 8px;
  transition: all 0.2s;
}
.cal-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- Footer ---------- */
.footer {
  position: relative;
  z-index: 10;
  margin-top: 24px;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  color: var(--blue-deep);
  opacity: 0.75;
  font-size: 1.05rem;
  text-align: center;
}

@media (max-width: 460px) {
  .content { padding: 30px 24px 34px; }
  .details li { grid-template-columns: 80px 1fr; gap: 12px; }
  .attending .choices { flex-direction: column; }
  .cal-btns { flex-direction: column; }
}

/* ---------- Sound toggle ---------- */
.sound-toggle {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 70;
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.82);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  box-shadow: 0 8px 20px -10px rgba(32,70,110,0.6);
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, color 0.2s;
}
.sound-toggle:hover { transform: scale(1.07); }
.sound-toggle[aria-pressed="true"] { background: var(--blue); border-color: var(--blue-deep); }
.sound-toggle.playing { animation: soundpulse 0.9s ease-in-out infinite; }
@keyframes soundpulse { 0%,100% { box-shadow: 0 8px 20px -10px rgba(32,94,156,0.7); } 50% { box-shadow: 0 8px 26px -6px rgba(32,94,156,0.95); } }

@media (prefers-reduced-motion: reduce) {
  .card, .thanks, .train, .wheel, .ties, .smoke .puff, .puffcloud, .cloud, .sound-toggle { animation: none; }
}
