:root {
  --paper: #f7f0e3;
  --paper-2: #f2e8d6;
  --ink: #5a4628;
  --ink-soft: #7d6a4a;
  --gold: #b48a3f;
  --gold-deep: #8c6724;
  --gold-light: #e6c987;
  --line: rgba(180, 138, 63, .35);
  --ease: cubic-bezier(.22, .8, .2, 1);
  --grain: 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 .45 0 0 0 0 .35 0 0 0 0 .2 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; margin: 0; }
html { background: #1b1712; -webkit-text-size-adjust: 100%; }
body {
  font-family: "Amiri", "Noto Naskh Arabic", serif;
  color: var(--ink);
  line-height: 1.9;
  font-size: 18px;
  min-height: 100svh;
  overflow-x: hidden;
}
body.locked { overflow: hidden; height: 100svh; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ================= الظرف ================= */
#intro {
  position: fixed; inset: 0; z-index: 50;
  max-width: 520px; margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  perspective: 1400px;
  transition: opacity .9s ease, visibility 0s linear .9s;
}
.env {
  position: absolute; inset: 0;
  background: url(/img/envelope.jpg) center / cover no-repeat;
}
.env-flap {
  clip-path: polygon(0 0, 100% 0, 100% 25.5%, 50% 47.5%, 0 25.5%);
  transform-origin: 50% 0;
  backface-visibility: hidden;
  filter: drop-shadow(0 6px 10px rgba(90, 70, 40, .25));
  transition: transform 1.1s var(--ease);
  z-index: 2;
}
.rays {
  position: absolute; left: 50%; top: 50%;
  width: 240vmax; height: 240vmax;
  margin: -120vmax 0 0 -120vmax;
  background: repeating-conic-gradient(from 0deg, rgba(255, 221, 140, .0) 0 7deg, rgba(255, 226, 150, .75) 9deg 11deg, rgba(255, 221, 140, 0) 13deg 20deg);
  -webkit-mask-image: radial-gradient(circle, #000 0, rgba(0,0,0,.5) 18%, transparent 46%);
          mask-image: radial-gradient(circle, #000 0, rgba(0,0,0,.5) 18%, transparent 46%);
  opacity: 0; transform: scale(.2) rotate(0deg);
  mix-blend-mode: screen;
  z-index: 3; pointer-events: none;
}
#seal {
  position: absolute; left: 50%; top: 50%; z-index: 4;
  width: min(34vw, 150px); aspect-ratio: 1;
  margin: 0; padding: 0; border: 0; background: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 8px 14px rgba(70, 50, 15, .45));
  -webkit-tap-highlight-color: transparent;
  animation: breathe 2.6s ease-in-out infinite;
}
#seal img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
#seal::after {
  content: ""; position: absolute; inset: -18%;
  border-radius: 50%;
  border: 1px solid rgba(214, 170, 85, .7);
  animation: ring 2.6s ease-out infinite;
}
@keyframes breathe { 50% { transform: translate(-50%, -50%) scale(1.06); } }
@keyframes ring { 0% { transform: scale(.75); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }

.intro-hint {
  position: absolute; left: 0; right: 0; top: calc(50% + min(22vw, 100px));
  z-index: 4; text-align: center;
  font-family: "Aref Ruqaa", serif; font-size: 1.25rem; color: var(--gold-deep);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
  animation: hint 2.6s ease-in-out infinite;
}
@keyframes hint { 50% { opacity: .45; } }
.flash {
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  background: radial-gradient(circle at 50% 50%, #fffdf5 0, #ffeec2 35%, #f4cf83 70%, #e2b25b 100%);
  opacity: 0;
}

/* تسلسل الفتح */
#intro.opening #seal { animation: sealPress 1.5s var(--ease) forwards; }
#intro.opening #seal::after, #intro.opening .intro-hint { animation: none; opacity: 0; transition: opacity .3s; }
#intro.opening .rays { animation: rays 2.3s ease-out forwards; }
#intro.opening .env-flap { transform: rotateX(-178deg); transition-delay: .75s; }
#intro.opening .env-body { animation: bodyZoom 2.2s ease-in forwards; }
#intro.opening .flash { animation: flash 2.5s ease-in-out forwards; }
#intro.done { opacity: 0; visibility: hidden; pointer-events: none; }

@keyframes sealPress {
  0% { transform: translate(-50%, -50%) scale(1); filter: drop-shadow(0 8px 14px rgba(70,50,15,.45)) brightness(1); }
  14% { transform: translate(-50%, -50%) scale(.9); }
  45% { transform: translate(-50%, -50%) scale(1.14); filter: drop-shadow(0 0 34px rgba(255,210,110,1)) brightness(1.35); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.6); filter: drop-shadow(0 0 60px rgba(255,220,130,1)) brightness(1.9); opacity: 0; }
}
@keyframes rays {
  0% { opacity: 0; transform: scale(.2) rotate(0); }
  35% { opacity: 1; }
  100% { opacity: .9; transform: scale(1.25) rotate(38deg); }
}
@keyframes bodyZoom { 40% { transform: scale(1); } 100% { transform: scale(1.18); } }
@keyframes flash { 0%, 45% { opacity: 0; } 78%, 100% { opacity: 1; } }

/* ================= البطاقة ================= */
#card {
  position: relative;
  max-width: 520px; margin: 0 auto;
  background: var(--grain), linear-gradient(var(--paper), var(--paper-2));
  overflow: hidden;
  box-shadow: 0 0 80px rgba(0, 0, 0, .5);
}

/* الغلاف */
.cover {
  position: relative; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
}
.cover-art {
  position: absolute; inset: 0;
  background: url(/img/cover.jpg) center top / cover no-repeat;
  -webkit-mask-image: linear-gradient(#000 82%, transparent);
          mask-image: linear-gradient(#000 82%, transparent);
}
.cover-art::after { /* هالة فاتحة خلف النص */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse 62% 34% at 50% 37%, rgba(255, 250, 238, .82), rgba(255, 250, 238, 0) 72%);
}
.cover-text { position: relative; margin-top: 17svh; padding: 0 24px; }
.eyebrow { font-family: "Aref Ruqaa", serif; font-size: 1.7rem; color: var(--gold-deep); line-height: 1.3; }
.cover-date {
  font-family: "Cormorant Garamond", serif; font-size: 1.35rem; letter-spacing: .28em;
  color: var(--ink-soft); direction: ltr; margin-top: 2px;
}
.names {
  margin-top: 3.2svh;
  font-family: "Aref Ruqaa", serif; font-weight: 700;
  font-size: clamp(3.4rem, 17vw, 5.2rem); line-height: 1.15;
  color: var(--gold-deep);
  display: flex; flex-direction: column; align-items: center;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .8), 0 0 26px rgba(255, 248, 230, .9);
}
.names .amp {
  font-family: "Cormorant Garamond", serif; font-weight: 400; font-style: italic;
  font-size: .42em; color: var(--gold); line-height: 1; margin: .1em 0 .05em;
}
.scroll-cue {
  position: absolute; bottom: 26px; left: 50%; width: 22px; height: 36px; margin-left: -11px;
  border: 1px solid var(--gold); border-radius: 12px;
}
.scroll-cue span {
  position: absolute; left: 50%; top: 7px; width: 3px; height: 7px; margin-left: -1.5px;
  background: var(--gold); border-radius: 2px; animation: cue 1.8s ease-in-out infinite;
}
@keyframes cue { 0% { transform: translateY(0); opacity: 1; } 80%, 100% { transform: translateY(12px); opacity: 0; } }

/* دخول عناصر الغلاف بعد فتح الظرف */
.in { opacity: 0; transform: translateY(18px); filter: blur(6px); }
body.open .in {
  opacity: 1; transform: none; filter: none;
  transition: opacity 1.1s ease var(--d, 0s), transform 1.2s var(--ease) var(--d, 0s), filter 1.1s ease var(--d, 0s);
}
body.open .cover-art { animation: artIn 2.6s var(--ease) both; }
@keyframes artIn { from { transform: scale(1.12); } to { transform: scale(1); } }

/* الأقسام */
.block { position: relative; padding: 46px 30px; text-align: center; }
h2 {
  font-family: "Aref Ruqaa", serif; font-weight: 700; font-size: 2rem; line-height: 1.4;
  color: var(--gold-deep); margin-bottom: 16px;
}
h2::after {
  content: ""; display: block; width: 54px; height: 1px; margin: 10px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.h2-gap { margin-top: 44px; }
.body { max-width: 30ch; margin: 0 auto; color: var(--ink); }
.bismillah { font-family: "Aref Ruqaa", serif; font-size: 1.35rem; color: var(--gold-deep); margin-bottom: 14px; }
.verse { font-size: 1.05rem; line-height: 2.2; color: var(--ink-soft); max-width: 32ch; margin: 0 auto 30px; }
.motto { font-family: "Aref Ruqaa", serif; font-size: 2rem; line-height: 1.5; color: var(--gold-deep); margin-bottom: 26px; }
.motto span { display: block; }
.families {
  display: flex; justify-content: center; align-items: center; gap: 18px; margin-top: 26px;
  font-family: "Aref Ruqaa", serif; font-size: 1.2rem; color: var(--gold-deep);
}
.families i { width: 1px; height: 26px; background: var(--line); }

/* حافة ورق ممزّق بخط ذهبي */
.tear {
  height: 22px; margin: 6px 0;
  background:
    linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold-light) 50%, var(--gold) 80%, transparent) center / 100% 1.5px no-repeat;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 22' preserveAspectRatio='none'%3E%3Cpath d='M0 11 C30 3 52 18 84 10 S140 4 172 12 228 17 262 9 318 5 348 12 384 15 400 10' fill='none' stroke='%23000' stroke-width='22'/%3E%3C/svg%3E");
          mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 22' preserveAspectRatio='none'%3E%3Cpath d='M0 11 C30 3 52 18 84 10 S140 4 172 12 228 17 262 9 318 5 348 12 384 15 400 10' fill='none' stroke='%23000' stroke-width='22'/%3E%3C/svg%3E");
  opacity: .9;
}
.divider { width: 78%; margin: 0 auto; mix-blend-mode: multiply; filter: brightness(1.05); }

/* العدّاد */
.countdown { display: flex; justify-content: center; gap: 8px; margin: 8px 0 18px; }
.countdown div {
  flex: 1; max-width: 78px; padding: 12px 0 8px;
  border: 1px solid var(--line); border-radius: 40px 40px 10px 10px;
  background: rgba(255, 252, 244, .55);
}
.countdown b {
  display: block; font-family: "Cormorant Garamond", serif; font-weight: 500;
  font-size: 2.1rem; line-height: 1; color: var(--gold-deep);
  font-variant-numeric: tabular-nums; direction: ltr;
}
.countdown i { font-style: normal; font-size: .85rem; color: var(--ink-soft); }
.date-long { font-family: "Aref Ruqaa", serif; font-size: 1.25rem; color: var(--ink-soft); }

/* البرنامج */
.program { list-style: none; padding: 0; position: relative; max-width: 300px; margin: 10px auto 0; }
.program::before {
  content: ""; position: absolute; top: 12px; bottom: 12px; left: 50%; width: 1px;
  background: linear-gradient(transparent, var(--gold) 12%, var(--gold) 88%, transparent);
}
.program li {
  position: relative; display: grid; grid-template-columns: 1fr 34px 1fr; align-items: center;
  padding: 13px 0;
}
.program li::before {
  content: ""; grid-column: 2; grid-row: 1; justify-self: center;
  width: 11px; height: 11px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f6dfa4, var(--gold) 60%, var(--gold-deep));
  box-shadow: 0 0 0 4px var(--paper), 0 0 0 5px var(--line);
}
.program time {
  grid-column: 1; grid-row: 1; text-align: left; padding-left: 4px;
  font-family: "Cormorant Garamond", serif; font-size: 1.45rem; font-weight: 600; color: var(--gold-deep);
  direction: ltr; justify-self: end;
}
.program time { display: inline-flex; align-items: baseline; gap: 6px; }
.program time small { font-family: "Amiri", serif; font-size: .72rem; font-weight: 400; color: var(--ink-soft); }
.program span { grid-column: 3; grid-row: 1; text-align: right; font-size: 1.08rem; }

/* الموقع */
.venue-art { width: 86%; margin: 0 auto 6px; mix-blend-mode: multiply; filter: brightness(1.05); }
.venue-name { font-family: "Aref Ruqaa", serif; font-size: 1.7rem; color: var(--gold-deep); line-height: 1.4; }
.map {
  margin: 20px auto 18px; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line); box-shadow: 0 10px 26px rgba(90, 70, 40, .14);
  aspect-ratio: 4 / 3; background: #e9e2d2;
}
.map iframe { width: 100%; height: 100%; border: 0; filter: sepia(.25) saturate(.85); }

.btn {
  display: inline-block; padding: 9px 28px;
  font-family: "Aref Ruqaa", serif; font-size: 1.15rem; text-decoration: none;
  color: var(--gold-deep); background: transparent;
  border: 1px solid var(--gold); border-radius: 40px;
  transition: background .25s, color .25s, transform .15s;
}
.btn:active { transform: scale(.97); }
.btn.solid {
  width: 100%; color: #fff8e6; border: 0;
  background: linear-gradient(180deg, #c9a154, #a37a30);
  box-shadow: 0 6px 16px rgba(140, 103, 36, .35), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.btn[disabled] { opacity: .6; }
@media (hover: hover) { .btn:not(.solid):hover { background: var(--gold); color: #fff8e6; } }

/* RSVP */
.rsvp { padding-bottom: 0; }
.seal-btn {
  display: block; width: 116px; aspect-ratio: 1; margin: 22px auto 4px; padding: 0; border: 0; background: none;
  filter: drop-shadow(0 8px 12px rgba(70, 50, 15, .4));
  animation: sealFloat 2.8s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}
.seal-btn img { width: 100%; height: 100%; object-fit: contain; }
@keyframes sealFloat { 50% { transform: translateY(-5px) scale(1.04); } }
.tap { font-family: "Aref Ruqaa", serif; color: var(--ink-soft); font-size: 1.1rem; }
.waiting { font-family: "Aref Ruqaa", serif; font-weight: 700; font-size: 2.2rem; color: var(--gold-deep); line-height: 1.4; margin-top: 4px; }
.sign { font-size: 1rem; color: var(--ink-soft); }
.couple {
  width: 100%; margin-top: 10px; mix-blend-mode: multiply;
  -webkit-mask-image: linear-gradient(transparent, #000 22%);
          mask-image: linear-gradient(transparent, #000 22%);
}

/* ظهور مع السكرول */
.rv { opacity: 0; transform: translateY(26px); transition: opacity .9s ease, transform 1s var(--ease); }
.rv.on { opacity: 1; transform: none; }
.program li.rv { transition-delay: calc(var(--i, 0) * 90ms); }

/* نافذة تأكيد الحضور */
dialog {
  width: min(92vw, 420px); max-height: 92svh; margin: auto; padding: 0; border: 0;
  border-radius: 18px; color: var(--ink);
  background: var(--grain), linear-gradient(#fbf6ea, var(--paper-2));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45), inset 0 0 0 1px var(--line);
  font-family: "Amiri", serif;
}
dialog::backdrop { background: rgba(30, 22, 10, .6); backdrop-filter: blur(4px); }
dialog[open] { animation: dlg .45s var(--ease); }
@keyframes dlg { from { opacity: 0; transform: translateY(24px) scale(.97); } }
#rsvp-form, .thanks { padding: 30px 24px 24px; position: relative; }
dialog h3 { font-family: "Aref Ruqaa", serif; font-size: 1.8rem; color: var(--gold-deep); text-align: center; margin-bottom: 14px; }
.close {
  position: absolute; top: 8px; left: 12px; width: 40px; height: 40px;
  border: 0; background: none; font-size: 1.7rem; line-height: 1; color: var(--ink-soft);
}
.field { display: block; border: 0; padding: 0; margin: 0 0 14px; }
.field > span, .field legend { display: block; font-size: .98rem; color: var(--ink-soft); margin-bottom: 4px; padding: 0; }
input[type=text], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 1.05rem; color: var(--ink);
  background: rgba(255, 253, 247, .85); border: 1px solid var(--line); border-radius: 10px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
textarea { resize: none; line-height: 1.6; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, button:focus-visible {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(180, 138, 63, .25);
}
.radio { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 1.08rem; }
.radio input { width: 20px; height: 20px; accent-color: var(--gold-deep); margin: 0; }
.form-msg { min-height: 1.4em; font-size: .95rem; color: #a03b2a; text-align: center; margin-bottom: 6px; }
.thanks { text-align: center; }
.thanks img { width: 90px; margin: 4px auto 10px; filter: drop-shadow(0 6px 10px rgba(70, 50, 15, .35)); }
.thanks p { margin-bottom: 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .2s !important; transition-delay: 0s !important; }
  .rv, .in { transform: none; filter: none; }
}
