/* SANGAM invite. A 90s Indian picture-book comic, one panel at a time.
   Motion language is borrowed from Ishan's TV app (tvhome): see docs/adr/0002. */

@property --p { syntax: '<percentage>'; inherits: false; initial-value: 120%; }
@property --r { syntax: '<percentage>'; inherits: false; initial-value: 160%; }

:root {
  --paper: #f6ecd6;
  --paper-deep: #ecdcb8;
  --table: #e6d3ab;
  --ink: #2b1a14;
  --ink-soft: #5a4134;
  --sindoor: #d2361f;
  --maroon: #6e1b22;
  --marigold: #eea320;
  --brass: #a8823f;
  --brass-ink: #7c5c22;

  --display: 'Rozha One', 'Times New Roman', serif;
  --hand: 'Kalam', 'Comic Sans MS', cursive;
  --body: 'Mukta', system-ui, sans-serif;

  /* tvhome easings */
  --ease: cubic-bezier(.2,.8,.2,1);          /* lifts and rises */
  --spring: cubic-bezier(.34,1.56,.64,1);    /* pills, here speech bubbles */
  --out: cubic-bezier(.4,0,1,1);             /* exits are quick and ease in */

  /* build timeline, first entry only */
  --t-frame: 0ms;
  --t-ink: 150ms;
  --t-wash: 800ms;
  --t-pop: 1700ms;
  --t-cap: 2150ms;   /* JS moves this later when a panel has more bubbles */

  --top: 46px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--table); color: var(--ink);
  font: 400 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overflow: hidden; overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- paper ---------- */
.grain {
  position: fixed; inset: 0; z-index: 50; pointer-events: none; opacity: .5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35  0 0 0 0 .25  0 0 0 0 .15  0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- top bar ---------- */
.top {
  position: fixed; left: 0; right: 0; top: 0; z-index: 40; height: calc(var(--top) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0; display: flex; align-items: center; gap: 12px;
  background: linear-gradient(var(--table) 70%, transparent);
}
.progress { flex: 1; display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.progress li { flex: 1; }
.progress button {
  display: block; width: 100%; height: 22px; padding: 0; border: 0; background: none; cursor: pointer;
  position: relative;
}
.progress button::before {
  content: ''; position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 999px;
  background: rgba(43,26,20,.16); transition: background 260ms ease;
}
.progress button[aria-current="step"]::before { background: var(--maroon); }
.progress button.seen::before { background: var(--brass); }
.facts-btn {
  flex: none; border: 1.5px solid var(--ink); background: var(--paper); border-radius: 999px;
  padding: 4px 12px; font: 800 12px/1.4 var(--body); letter-spacing: .02em; cursor: pointer;
}

/* ---------- panels ---------- */
#book { position: fixed; inset: 0; }
.panel {
  position: absolute; inset: calc(var(--top) + env(safe-area-inset-top)) 0 0 0;
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  visibility: hidden; opacity: 0; pointer-events: none;
}
.panel.on { visibility: visible; opacity: 1; pointer-events: auto; transition: opacity 280ms ease-out; }
.panel.leaving { visibility: visible; opacity: 0; transform: translateY(-10px); transition: opacity 160ms var(--out), transform 160ms var(--out); }
.panel.leaving.back { transform: translateY(10px); }

.page {
  width: min(100%, 470px); min-height: 100%; margin: 0 auto;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
@media (min-width: 520px) {
  .page { min-height: calc(100% - 24px); margin: 4px auto 20px; border-radius: 4px; background: var(--paper);
          box-shadow: 0 1px 0 rgba(43,26,20,.12), 0 18px 40px -24px rgba(43,26,20,.45); padding-top: 18px; }
}
@media (max-width: 519px) { body { background: var(--paper); } .top { background: linear-gradient(var(--paper) 70%, transparent); } }

/* ---------- the painted panel ---------- */
.art {
  position: relative; margin: 0; width: 100%; aspect-ratio: var(--a);
  background: var(--paper-deep); overflow: hidden; isolation: isolate;
}
/* figure + caption share one plate, sized so the art never pushes the caption off screen */
.plate { --hmax: 54dvh; flex: none; width: min(100%, calc(var(--hmax) * var(--a))); }
#cover .plate { --hmax: 60dvh; }
#rsvp .plate { --hmax: 28dvh; }
#when .plate { --hmax: 40dvh; }
.art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* print misregistration: the colour plate sits a hair off the key line */
.art .wash { transform: translate(.9px, .7px); }
.art .ink { mix-blend-mode: multiply; z-index: 1; }
.art::after { /* the inked panel border */
  content: ''; position: absolute; inset: 0; z-index: 4; pointer-events: none;
  border: 2.5px solid var(--ink); border-radius: 2px;
}
.art.pending { background:
  repeating-linear-gradient(-45deg, transparent 0 9px, rgba(43,26,20,.07) 9px 10px), var(--paper-deep); }
.art.pending img { display: none; }
.art.pending::before {
  content: 'Chitra ban raha hai…'; position: absolute; left: 0; right: 0; bottom: 14px; z-index: 3; text-align: center;
  font: 700 15px/1 var(--hand); color: var(--ink-soft);
}

/* ---------- speech bubbles ---------- */
.bubble {
  position: absolute; left: var(--x); top: var(--y); z-index: 3; margin: 0; max-width: 46%;
  padding: 6px 11px 7px; background: #fffdf5; border: 2px solid var(--ink); border-radius: 20px 18px 19px 17px;
  font: 700 15px/1.15 var(--hand); color: var(--ink); transform-origin: 18% 120%;
}
.bubble.small { font-size: 14px; }
.bubble::after {
  content: ''; position: absolute; bottom: -8px; left: 18px; width: 13px; height: 13px; background: #fffdf5;
  border: solid var(--ink); border-width: 0 2px 2px 0; transform: rotate(45deg) skew(12deg, 12deg);
}
.bubble.tail-br { transform-origin: 82% 120%; }
.bubble.tail-br::after { left: auto; right: 18px; }

/* the real date, set over the painted circle so it is always correct */
.date-stamp {
  position: absolute; left: var(--x); top: var(--y); z-index: 3; margin: 0; transform: translate(-50%, -50%);
  text-align: center; color: #fff6e4; line-height: 1;
}
.date-stamp b { display: block; font: 400 clamp(44px, 14vw, 64px)/.9 var(--display); text-shadow: 2px 2px 0 var(--ink); }
.date-stamp span { display: block; margin-top: 2px; font: 800 11px/1 var(--body); letter-spacing: .12em; text-transform: uppercase; }
.play .date-stamp { animation: stampin 420ms var(--spring) calc(var(--t-pop) - 120ms) both; }
/* the venue name, painted onto the blank signboard as real text */
.signboard {
  position: absolute; left: var(--x); top: var(--y); width: var(--w); height: var(--h); z-index: 3; margin: 0;
  transform: translate(-50%, -50%) rotate(-1deg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  color: var(--maroon); line-height: 1;
}
.signboard b { font: 400 clamp(15px, 5.2vw, 24px)/1 var(--display); }
.signboard span { margin-top: 3px; font: 800 clamp(6px, 1.8vw, 8px)/1.15 var(--body); letter-spacing: .08em; text-transform: uppercase; color: var(--brass); }
.play .signboard { animation: stampin 420ms var(--spring) calc(var(--t-pop) - 120ms) both; }
@keyframes stampin { from { opacity: 0; transform: translate(-50%, -50%) scale(1.8) rotate(-8deg); } }

/* ---------- cover title ---------- */
.masthead {
  width: min(100%, calc(60dvh * .8)); margin: 0 0 8px; padding: 5px 0; display: flex; justify-content: space-between; gap: 8px;
  border-top: 3px double var(--maroon); border-bottom: 3px double var(--maroon);
  font: 800 9.5px/1.2 var(--body); letter-spacing: .07em; text-transform: uppercase; color: var(--maroon); white-space: nowrap;
}
.masthead span:first-child { overflow: hidden; text-overflow: ellipsis; }
.title-block { position: absolute; left: 0; right: 0; top: 4.5%; z-index: 3; text-align: center; transform-origin: 50% 0; }
.sangam {
  margin: 0; font: 400 clamp(46px, 15vw, 66px)/.95 var(--display); letter-spacing: .04em; color: var(--sindoor);
  text-shadow: 2px 2px 0 var(--ink), -1px -1px 0 #fff4dc; /* misregistered key plate */
}
.sangam span { display: block; font-size: .42em; letter-spacing: 0; color: var(--maroon); text-shadow: 1px 1px 0 #fff4dc; margin-top: 4px; }
.sub {
  display: inline-block; margin: 8px 0 0; padding: 2px 14px 4px; background: var(--paper); border: 2px solid var(--ink); border-radius: 999px;
  font: 700 17px/1.2 var(--hand); color: var(--maroon);
}

/* ---------- caption bar ---------- */
.caption {
  width: 100%; margin: 0; padding: 9px 12px 10px; position: relative; z-index: 1;
  background: #fbf3df; border: 2.5px solid var(--ink); border-top: 0;
  font: 800 15.5px/1.35 var(--body); text-align: center; color: var(--ink);
}
.caption b { color: var(--maroon); }

.hint { margin: 14px 0 0; font: 700 14px/1 var(--hand); color: var(--ink-soft); }
.hint::after { content: ' →'; display: inline-block; animation: nudge 3.2s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(6px); } }

/* ---------- text blocks ---------- */
.text { width: 100%; margin-top: 16px; }
.text p { margin: 0 0 10px; font-size: 16px; line-height: 1.55; color: var(--ink-soft); }
.eyebrow { margin: 0 0 6px !important; font: 800 12px/1.2 var(--body) !important; letter-spacing: .1em; text-transform: uppercase; color: var(--brass-ink) !important; }

.facts { width: 100%; margin: 16px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-top: 1.5px solid rgba(43,26,20,.2); }
.facts > div { padding: 10px 0; border-bottom: 1.5px solid rgba(43,26,20,.2); }
.facts dt { font: 800 11px/1.2 var(--body); letter-spacing: .1em; text-transform: uppercase; color: var(--brass-ink); }
.facts dd { margin: 3px 0 0; font: 600 16px/1.35 var(--body); }
.facts dd.tbd { color: var(--ink-soft); font-family: var(--hand); font-weight: 700; }
.facts.stack { grid-template-columns: 1fr; }
.facts small { color: var(--ink-soft); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; margin-top: 14px;
  padding: 10px 20px; border: 2px solid var(--ink); border-radius: 999px; background: var(--maroon); color: #fbf0d9;
  font: 800 15px/1 var(--body); text-decoration: none; cursor: pointer; box-shadow: 2px 2px 0 var(--ink);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.big { width: 100%; min-height: 52px; font-size: 16px; }
.link { border: 0; background: none; padding: 0; color: var(--maroon); font-weight: 800; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: 0 10px; }

.where-row { width: 100%; display: flex; gap: 16px; align-items: center; margin-top: 16px; }
.qr { flex: none; width: 112px; padding: 6px; background: #f6ecd6; border: 2px solid var(--ink); border-radius: 6px; transform: rotate(-2deg); box-shadow: 2px 2px 0 var(--ink); }
.venue { margin: 0; font: 400 26px/1 var(--display); color: var(--maroon); }
.venue-line { margin: 4px 0 0; font-size: 14px; line-height: 1.35; color: var(--ink-soft); }
.where-row .btn { margin-top: 10px; }

.swatches { width: 100%; margin: 16px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 10px 14px; font: 600 14px/1 var(--body); }
.swatches li { display: flex; align-items: center; gap: 6px; }
.swatches i { width: 22px; height: 22px; border-radius: 50%; background: var(--c); border: 2px solid var(--ink); }
.swatches li.no { flex-basis: 100%; color: var(--maroon); font-weight: 800; }
.swatches li.no i { border-style: dashed; }

/* ---------- RSVP register ---------- */
.register { width: 100%; margin-top: 18px; }
.field { display: block; margin: 0 0 16px; padding: 0; border: 0; min-width: 0; }
.field > span, .field legend { display: block; margin-bottom: 4px; padding: 0; font: 800 13px/1.3 var(--body); letter-spacing: .02em; color: var(--ink); }
.field em { font-style: normal; font-weight: 400; color: var(--ink-soft); }
.field input:not([type=radio]), .field textarea {
  width: 100%; border: 0; border-bottom: 2px solid var(--ink); border-radius: 0; background:
    repeating-linear-gradient(transparent 0 29px, rgba(110,27,34,.18) 29px 30px); padding: 4px 2px;
  font: 700 19px/30px var(--hand); color: #1d2a5a; /* register ink is blue */ outline: none; resize: none;
}
.field input::placeholder, .field textarea::placeholder { color: rgba(43,26,20,.35); font-weight: 400; }
.field input:focus-visible, .field textarea:focus-visible { border-bottom-color: var(--maroon); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.chips span { display: inline-block; padding: 9px 15px; border: 2px solid var(--ink); border-radius: 999px; font: 700 15px/1 var(--body); background: var(--paper); transition: background 160ms ease, color 160ms ease; }
.chips input:checked + span { background: var(--maroon); color: #fbf0d9; }
.chips input:focus-visible + span { outline: 3px solid var(--marigold); outline-offset: 2px; }
.stepper { display: inline-flex; align-items: center; gap: 14px; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); font: 800 22px/1 var(--body); cursor: pointer; box-shadow: 2px 2px 0 var(--ink); }
.stepper button:active { transform: translate(2px,2px); box-shadow: none; }
.stepper output { min-width: 2ch; text-align: center; font: 400 30px/1 var(--display); color: #1d2a5a; }
.form-err { margin: 0 0 8px; color: var(--sindoor); font-weight: 700; font-size: 14px; }
.thanks { width: 100%; margin-top: 22px; text-align: center; }
.stamp {
  display: inline-block; margin: 0; padding: 6px 16px; border: 3px solid var(--sindoor); border-radius: 6px; transform: rotate(-6deg);
  font: 400 26px/1 var(--display); color: var(--sindoor); letter-spacing: .04em; text-transform: uppercase; opacity: .9;
  animation: stamp 420ms var(--spring) both;
}
@keyframes stamp { from { transform: rotate(-6deg) scale(2.2); opacity: 0; } }
.thanks-line { font: 700 18px/1.4 var(--hand); margin: 16px 0 0; }

/* ---------- plain details view ---------- */
.plain .page, .scrolls .page { justify-content: flex-start; }
.plain .page { align-items: stretch; }
.plain h2 { margin: 0; font: 400 40px/1 var(--display); color: var(--maroon); }
.plain h2 span { display: block; margin-top: 6px; font: 700 18px/1.2 var(--hand); color: var(--ink-soft); }
.plain .eyebrow { margin-top: 8px !important; }
.plain .back { margin-top: 22px; align-self: flex-start; }

/* =========================================================
   THE BUILD. First visit to a panel only.
   1 border and ink lines draw in  2 colour washes in like wet paint
   3 bubbles pop  4 caption bar slides up last
   ========================================================= */
.play .art::after { animation: frame 520ms var(--ease) var(--t-frame) both; }
@keyframes frame { from { clip-path: inset(0 100% 100% 0); } 60% { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }

.art .ink {
  -webkit-mask-image: linear-gradient(105deg, #000 calc(var(--p) - 10%), transparent calc(var(--p) + 6%));
          mask-image: linear-gradient(105deg, #000 calc(var(--p) - 10%), transparent calc(var(--p) + 6%));
}
.play .art .ink { animation: ink 950ms cubic-bezier(.45,.05,.35,1) var(--t-ink) both; }
@keyframes ink { from { --p: -12%; } to { --p: 120%; } }

.art .wash {
  -webkit-mask-image: radial-gradient(circle at var(--wx) var(--wy), #000 calc(var(--r) - 14%), transparent var(--r));
          mask-image: radial-gradient(circle at var(--wx) var(--wy), #000 calc(var(--r) - 14%), transparent var(--r));
}
.play .art .wash { animation: wash 1100ms var(--ease) var(--t-wash) both; }
@keyframes wash {
  from { --r: 0%; filter: saturate(.55) blur(2.5px); transform: translate(3px, 2px); }
  55%  { filter: saturate(1.15) blur(.6px); }
  to   { --r: 160%; filter: none; transform: translate(.9px, .7px); }
}

.play .bubble, .play .title-block { animation: pop 380ms var(--spring) calc(var(--t-pop) + var(--k, 0) * 140ms) both; }
@keyframes pop { from { opacity: 0; transform: scale(.25); } to { opacity: 1; transform: none; } }
.built .bubble { animation: idle 6s ease-in-out calc(1.5s + var(--k, 0) * .7s) infinite; }
@keyframes idle { 0%, 13%, 100% { transform: none; } 3% { transform: scale(1.05, .94); } 6.5% { transform: scale(.97, 1.05); } 10% { transform: scale(1.01, .99); } }

.play .caption { animation: rise 420ms var(--ease) var(--t-cap) both; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.play .masthead { animation: fade 400ms ease-out 100ms both; }
@keyframes fade { from { opacity: 0; } }
.play .rise-in { animation: rise 320ms var(--ease) calc(var(--t-cap) + 220ms + var(--i, 0) * 40ms) both; }
/* the plain view does not build; it just rises like tvhome's inner rows */
.plain.play .rise-in { animation-delay: calc(var(--i, 0) * 40ms); }

@media (prefers-reduced-motion: reduce) {
  .play .art::after, .play .art .ink, .play .art .wash, .play .bubble, .play .title-block,
  .play .caption, .play .masthead, .play .date-stamp, .play .signboard, .play .rise-in, .built .bubble, .hint::after, .stamp { animation: none !important; }
  .panel.on, .panel.leaving { transition: none; transform: none; }
}
