/* "على الطاولة": everything is placed in metres of table times --s (px per metre, set by js/table/stage.js);
   type on the cards is set in millimetres of card (--mm). */
:root {
  --s: 2167;
  --mm: calc(var(--s) * 0.001px);
  --ink: #2a1d17;
  --ink-soft: #5d4a3e;
  --red: #8e1b1f;
  --pen: #24305c;
  --linen: #cbbca6;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--linen); }
body {
  font-family: 'Amiri', 'Times New Roman', serif;
  color: var(--ink);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
html.locked, html.locked body { overflow: hidden; height: 100%; overscroll-behavior: none; }
html.locked body { touch-action: none; }
button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- the table */
#table { position: relative; }
.tile { position: relative; overflow: clip; }
.tile + .tile { content-visibility: auto; contain-intrinsic-size: auto 900px; }
.plate {
  position: absolute; top: 0; left: 50%; height: 100%;
  width: calc(var(--pw) * var(--s) * 1px);
  transform: translateX(-50%);
  user-select: none; pointer-events: none;
}
.m {
  position: absolute;
  left: calc(50% + var(--x) * var(--s) * 1px);
  top: calc(var(--y) * var(--s) * 1px);
  width: calc(var(--w) * var(--s) * 1px);
  height: calc(var(--h) * var(--s) * 1px);
}
.m .m { left: calc(var(--x) * var(--s) * 1px); }
.actor { display: block; user-select: none; pointer-events: none; -webkit-user-drag: none; }
.fill { left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; }

/* candle flames: a warm breath of light over the rendered flame */
.glow {
  pointer-events: none; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 196, 120, .5) 0%, rgba(255, 170, 90, .2) 22%, rgba(255, 150, 70, .06) 48%, rgba(255, 140, 60, 0) 70%);
  mix-blend-mode: screen; opacity: .7;
  animation: flick 2.7s var(--d, 0s) infinite ease-in-out paused;
}
.live .glow { animation-play-state: running; }
@keyframes flick {
  0% { opacity: .62; transform: scale(1); }
  21% { opacity: .82; transform: scale(1.05); }
  37% { opacity: .56; transform: scale(.96); }
  58% { opacity: .76; transform: scale(1.02); }
  79% { opacity: .6; transform: scale(.99); }
  100% { opacity: .62; transform: scale(1); }
}

/* ---------------------------------------------------------------- printed type */
.card { pointer-events: none; }
.col {
  position: absolute;
  top: calc(var(--t) * var(--mm)); right: calc(var(--r) * var(--mm));
  bottom: calc(var(--b) * var(--mm)); left: calc(var(--l) * var(--mm));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; pointer-events: auto;
}
.col p, .to p { margin: calc(var(--gap, 0) * var(--mm)) 0 0; font-size: calc(var(--fs) * var(--mm) * var(--k, 1)); line-height: 1.4; max-width: 100%; }
.ink-layer { mix-blend-mode: multiply; }
.ink { color: var(--ink); }
.soft { color: var(--ink-soft); }
.red { color: var(--red); }
.strong { font-weight: 700; }
.ruqaa { font-family: 'Aref Ruqaa', 'Amiri', serif; }
.fit { white-space: nowrap; align-self: stretch; }
.kicker { letter-spacing: .08em; }
.verse { line-height: 1.75 !important; }
.foil {
  font-family: 'Aref Ruqaa', serif; font-weight: 700;
  background: linear-gradient(100deg, #8a6226 0%, #d9b46c 18%, #a77a32 36%, #ecd29a 52%, #9c712d 70%, #d4ac62 88%, #8a6226 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.col p.name { line-height: 1.12; }
.col p.and { line-height: 1; font-family: 'Amiri', serif; }
.rule { display: block; width: calc(26 * var(--mm)); height: 1px; margin-top: calc(var(--gap) * var(--mm)); background: var(--red); opacity: .55; }
.big-day { font-weight: 700; line-height: 1 !important; }

/* words arrive with their card */
.reveal { opacity: 0; transform: translateY(calc(2.5 * var(--mm))); transition: opacity 1s ease, transform 1s ease; }
.reveal.in { opacity: 1; transform: none; }
.rows { list-style: none; margin: calc(4 * var(--mm)) 0 0; padding: 0; width: 100%; }
.rows li { padding: calc(2.6 * var(--mm)) 0; opacity: 0; transition: opacity .7s calc(var(--i) * 140ms + 250ms) ease; }
.rows li + li { border-top: 1px solid rgba(142, 27, 31, .22); }
.rows li p { margin: 0; }
.rows .row-title { font-weight: 700; }
.in .rows li { opacity: 1; }
.reduced .reveal, .reduced .rows li { opacity: 1; transform: none; transition: none; }

/* ---------------------------------------------------------------- scene 0: envelope */
.env { position: absolute; inset: 0; z-index: 3; }
.actor[hidden] { display: none; }
.half { opacity: 0; }
.clip { position: absolute; left: 0; right: 0; top: 0; overflow: hidden; z-index: 4; pointer-events: none; }
.to { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; }
.to .guest { line-height: 1.2; }
.open-btn { background: transparent; border: 0; padding: 0; cursor: pointer; border-radius: calc(2 * var(--mm)); }
.open-btn:focus-visible { outline: 2px solid rgba(142, 27, 31, .7); outline-offset: 4px; }
/* tap here: the seal's shadow deepens and spreads, slowly, as if it were about to lift */
.seal-shadow {
  border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(closest-side, rgba(14, 10, 4, .6), rgba(14, 10, 4, .28) 62%, rgba(14, 10, 4, 0));
  animation: breathe 2.6s 1.2s infinite ease-in-out;
}
@keyframes breathe { 0%, 100% { transform: scale(.8); opacity: 0; } 50% { transform: scale(1.08); opacity: .85; } }
.reduced .seal-shadow { animation: none; opacity: .5; }

.pill, .cue {
  position: fixed; left: 50%; z-index: 20; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  font-size: 16px; color: #fbf3e4; white-space: nowrap;
  transition: opacity .6s ease;
}
.pill { padding: 10px 18px; border-radius: 999px; background: rgba(36, 26, 20, .72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); opacity: 0; }
.ready .pill { opacity: 1; }
.pill.gone, .cue.gone { opacity: 0; pointer-events: none; }
.cue { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: rgba(36, 26, 20, .55); }
.cue[hidden] { display: none; }
.cue i { width: 10px; height: 10px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); animation: nudge 1.6s infinite ease-in-out; }
@keyframes nudge { 50% { transform: translateY(4px) rotate(45deg); } }

.music {
  position: fixed; z-index: 21; top: calc(12px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left));
  width: 44px; height: 44px; border-radius: 50%; border: 0; padding: 11px; cursor: pointer;
  color: #fbf3e4; background: rgba(36, 26, 20, .6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.music svg { width: 100%; height: 100%; display: block; }
.music.on .slash { display: none; }

/* ---------------------------------------------------------------- scene 4: calendar tag */
.count { display: grid; grid-template-columns: repeat(4, 1fr); gap: calc(1.5 * var(--mm)); width: 100%; margin-top: calc(var(--gap) * var(--mm)); }
.count div { display: flex; flex-direction: column; align-items: center; }
.count b { font-size: calc(8 * var(--mm)); line-height: 1.1; font-variant-numeric: tabular-nums; }
.count span { font-size: calc(3.8 * var(--mm)); color: var(--ink-soft); }
.links { display: flex; gap: calc(5 * var(--mm)); justify-content: center; margin-top: calc(var(--gap) * var(--mm)); }
.ink-link {
  font-family: 'Amiri', serif; font-size: max(14px, calc(5.2 * var(--mm))); color: var(--red);
  background: none; border: 0; border-bottom: 1px solid currentColor; padding: 0 0 1px; cursor: pointer; text-decoration: none; line-height: 1.3;
}
.ink-link:focus-visible, .send:focus-visible, .deal-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

/* ---------------------------------------------------------------- scene 5: prints */
.print { margin: 0; isolation: isolate; cursor: grab; touch-action: pan-y; transition: transform .5s cubic-bezier(.2, .8, .2, 1), opacity .35s ease; will-change: transform; }
.print.instant { transition: none; }
.print:active { cursor: grabbing; }
.print .photo { overflow: hidden; background: #d9d4cb; }
.print .photo img { width: 100%; height: 100%; object-fit: cover; display: block; mix-blend-mode: multiply; user-select: none; -webkit-user-drag: none; }
.print figcaption { display: flex; align-items: center; justify-content: center; font-size: calc(6 * var(--mm)); mix-blend-mode: multiply; }
.deal-bar { display: flex; align-items: center; justify-content: space-between; }
.deal-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer; font-size: 22px; line-height: 1;
  color: var(--ink); background: rgba(251, 246, 236, .82); box-shadow: 0 1px 2px rgba(40, 28, 20, .35);
}
.deal-count { font-size: max(14px, calc(5 * var(--mm))); }

/* ---------------------------------------------------------------- scene 6: map */
.map-window { width: 100%; height: calc(90 * var(--mm)); position: relative; margin-top: calc(var(--gap) * var(--mm)); box-shadow: inset 0 0 0 1px rgba(42, 29, 23, .35); }
#leaflet { position: absolute; inset: 0; background: #e8e0d0; filter: sepia(.3) saturate(.8); }
.leaflet-container { font-family: 'Amiri', serif; background: transparent; }
.pin { background: none; border: 0; }

/* ---------------------------------------------------------------- scenes 7, 8: forms written in pen */
.form { display: flex; flex-direction: column; align-items: stretch; width: 100%; gap: calc(3.4 * var(--mm)); margin-top: calc(var(--gap) * var(--mm)); }
.field { display: flex; align-items: baseline; gap: calc(2 * var(--mm)); font-size: calc(5.4 * var(--mm)); border-bottom: 1px dotted rgba(42, 29, 23, .55); padding-bottom: calc(.6 * var(--mm)); }
.field > span { white-space: nowrap; }
.field input, .field textarea, .field output {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 0; resize: none;
  font-family: 'Aref Ruqaa', serif; font-size: max(16px, calc(6.2 * var(--mm))); color: var(--pen); line-height: 1.3;
}
.field textarea { line-height: 1.5; }
.field ::placeholder { color: rgba(42, 29, 23, .4); }
.field.need { border-bottom-color: var(--red); }
.count-field output { text-align: center; }
.step { width: calc(9 * var(--mm)); min-width: 30px; height: calc(9 * var(--mm)); min-height: 30px; border: 1px solid rgba(42, 29, 23, .6); border-radius: 50%; background: transparent; cursor: pointer; line-height: 1; }
.choice { display: flex; justify-content: space-between; gap: calc(2 * var(--mm)); font-size: calc(5.4 * var(--mm)); }
.choice label { display: flex; align-items: center; gap: calc(1.6 * var(--mm)); cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice i { width: calc(4.4 * var(--mm)); height: calc(4.4 * var(--mm)); min-width: 14px; min-height: 14px; border: 1px solid var(--ink); position: relative; flex: none; }
.choice input:checked + i::after { content: '✓'; position: absolute; inset: -40% -10% 0 -10%; color: var(--pen); font-family: 'Aref Ruqaa', serif; font-size: calc(7 * var(--mm)); line-height: 1; text-align: center; }
.choice input:focus-visible + i { outline: 2px solid var(--red); outline-offset: 2px; }
.send {
  align-self: center; border: 0; cursor: pointer; padding: calc(1.6 * var(--mm)) calc(7 * var(--mm));
  font-family: 'Amiri', serif; font-size: max(15px, calc(5.6 * var(--mm))); color: #fbf3e4; background: var(--red);
}
.send.small { padding: calc(1 * var(--mm)) calc(3.5 * var(--mm)); font-size: max(14px, calc(4.8 * var(--mm))); white-space: nowrap; }

.stamp {
  position: absolute; left: 50%; top: 50%; pointer-events: none;
  transform: translate(-50%, -50%) rotate(-11deg);
  padding: calc(1.5 * var(--mm)) calc(6 * var(--mm));
  border: calc(1 * var(--mm)) double #a3192a; border-radius: calc(2 * var(--mm));
  color: #a3192a; font-family: 'Aref Ruqaa', serif; font-weight: 700; font-size: calc(15 * var(--mm)); line-height: 1.2;
  filter: url(#ink); opacity: 0;
}
.stamp.no { color: #2f3d6b; border-color: #2f3d6b; }
.stamp.on { opacity: .86; }
.stamp.press { animation: press .38s cubic-bezier(.2, .9, .3, 1.25); }
@keyframes press { from { transform: translate(-50%, -50%) rotate(-11deg) scale(1.7); opacity: 0; } to { transform: translate(-50%, -50%) rotate(-11deg) scale(1); opacity: .86; } }

.note { margin: 0; transform: rotate(var(--r)); }
.note[hidden] { display: none; }
.note blockquote {
  margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  font-size: calc(5.4 * var(--mm)); line-height: 1.5; text-align: center; mix-blend-mode: multiply; color: var(--pen);
}
.note figcaption { font-size: calc(4.2 * var(--mm)); text-align: center; mix-blend-mode: multiply; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note.drop { animation: drop .7s cubic-bezier(.2, .8, .3, 1); }
@keyframes drop { from { transform: translateY(calc(-14 * var(--mm))) rotate(calc(var(--r) - 8deg)) scale(1.1); opacity: 0; } }

/* ---------------------------------------------------------------- scene 9: the cake */
.mono { display: flex; align-items: center; justify-content: center; direction: rtl; pointer-events: none; line-height: 1;
  font-size: calc(var(--w) * var(--s) * .4px); filter: drop-shadow(0 .5px 0 rgba(90, 60, 20, .4)); }
.mono .amp { font-family: 'Amiri', serif; font-size: .55em; margin: 0 .14em; }
/* the candles catch: the flames show, their glow swells */
.cake-zone { pointer-events: none; }
.cake-flame { opacity: 0; transition: opacity .7s ease; }
.cake-flame.on { opacity: 1; }
.cake-glow { scale: 0; transition: scale 1.1s cubic-bezier(.2, .8, .3, 1.15); }
.cake-glow.on { scale: 1; }
.reduced .cake-flame, .reduced .cake-glow { transition: none; }

.noscript { position: fixed; inset: auto 16px 16px; padding: 12px; background: #fbf3e4; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .glow, .cue i { animation: none; }
  .print { transition: none; }
}
