/* ============ الثيمات: مخمل + ورق عاجي + ذهب ============ */
.theme-rose    { --v1: #5a1426; --v2: #2e0912; --env: #7a1d33; --env-2: #651629; --wax-1: #f3dfa6; --wax-2: #b08442; --wax-ink: #5a3a12; }
.theme-night   { --v1: #16264a; --v2: #070e1e; --env: #1e3160; --env-2: #172851; --wax-1: #f3dfa6; --wax-2: #b08442; --wax-ink: #4c3312; }
.theme-classic { --v1: #2f3d33; --v2: #121a15; --env: #3e4d40; --env-2: #334136; --wax-1: #f3dfa6; --wax-2: #b08442; --wax-ink: #4c3312; }

body {
  min-height: 100vh;
  color: var(--paper);
  background: radial-gradient(120% 80% at 50% 0%, var(--v1) 0%, var(--v2) 70%) fixed, var(--v2);
  overflow-x: hidden;
}
/* حبيبات خفيفة زي القماش */
body::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .09; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

.stage {
  position: relative; z-index: 1;
  min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 2.5rem 1.25rem;
}
.nf { color: var(--gold-1); font-size: 1.2rem; }

/* ============ ١. الظرف ============ */
.to-line { margin: 0 0 2.2rem; line-height: 1.2; }
.to-label { display: block; font-size: 1.05rem; color: rgba(251, 246, 238, .6); margin-bottom: .2rem; }
.to-name { font-family: var(--script); font-weight: 700; font-size: clamp(2.8rem, 13vw, 4.6rem); line-height: 1.35; }

.envelope {
  position: relative; width: min(330px, 84vw); aspect-ratio: 1.5;
  perspective: 1400px; margin-bottom: 2.4rem;
}
.env-back, .env-pocket, .env-flap { position: absolute; inset: 0; border-radius: 6px; }
.env-back {
  background: var(--env-2);
  box-shadow: 0 50px 70px -35px rgba(0, 0, 0, .75), 0 0 0 1px rgba(243, 223, 166, .12);
}
.env-letter {
  position: absolute; inset: 7% 7% 10%; z-index: 1;
  background: var(--paper); border-radius: 3px;
  display: flex; flex-direction: column; gap: 10%; padding: 14% 12% 0;
  transition: transform 1.1s cubic-bezier(.2, .8, .2, 1) .95s;
}
.env-letter-line { height: 2px; background: var(--paper-2); border-radius: 2px; }
.env-letter-line.short { width: 55%; }
.env-pocket {
  z-index: 2;
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), rgba(243, 223, 166, .35) 50%, transparent calc(50% + 1px)) left / 50.2% 100% no-repeat,
    linear-gradient(to top left, transparent calc(50% - 1px), rgba(243, 223, 166, .35) 50%, transparent calc(50% + 1px)) right / 50.2% 100% no-repeat,
    var(--env);
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
}
.env-pocket::after { /* إطار ذهبي رفيع */
  content: ''; position: absolute; inset: 9px; border: 1px solid rgba(243, 223, 166, .45); border-radius: 3px;
}
.env-flap {
  z-index: 3; bottom: auto; height: 60%;
  background: linear-gradient(180deg, var(--env) 0%, var(--env-2) 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform 1s cubic-bezier(.5, 0, .2, 1) .35s, z-index 0s .85s;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .35));
}
.seal {
  position: absolute; z-index: 4; left: 50%; top: 58%;
  width: 84px; height: 84px; transform: translate(-50%, -50%);
  border: 0; padding: 0; cursor: pointer; border-radius: 47% 53% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 34% 28%, var(--wax-1) 0%, #d9b673 28%, var(--wax-2) 70%, #7d5a26 100%);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .45), inset 0 -3px 6px rgba(0, 0, 0, .25), inset 0 2px 3px rgba(255, 255, 255, .45);
  transition: transform .25s ease;
}
.seal:hover { transform: translate(-50%, -50%) scale(1.05); }
.seal-rim {
  position: absolute; inset: 11px; border-radius: 50%;
  border: 1.5px solid rgba(90, 58, 18, .45);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25), 0 1px 0 rgba(255, 255, 255, .35);
}
.seal-letter {
  position: relative; font-family: var(--script); font-weight: 700; font-size: 2.1rem; line-height: 84px;
  color: var(--wax-ink); text-shadow: 0 1px 0 rgba(255, 255, 255, .45), 0 -1px 0 rgba(0, 0, 0, .2);
}
.seal::after { /* نبضة هادية تقول «اضغطي» */
  content: ''; position: absolute; inset: -6px; border-radius: 50%;
  border: 1px solid rgba(243, 223, 166, .55); animation: halo 2.6s ease-out infinite;
}
@keyframes halo { 0% { transform: scale(.9); opacity: .9; } 100% { transform: scale(1.45); opacity: 0; } }

.g-title { font-size: clamp(1.25rem, 5vw, 1.55rem); font-weight: 700; margin: 0 0 .2rem; max-width: 30ch; }
.g-sub { margin: 0; color: rgba(251, 246, 238, .65); max-width: 36ch; }
.g-hint { margin: 1.6rem 0 0; font-size: .9rem; color: var(--gold-2); }

/* حركة الفتح */
.opening .seal { animation: seal-break .55s cubic-bezier(.5, 0, .75, 0) forwards; pointer-events: none; }
.opening .seal::after { display: none; }
.opening .env-flap { transform: rotateX(180deg); z-index: 0; }
.opening .env-letter { transform: translateY(-62%); }
.opening .g-title, .opening .g-sub, .opening .g-hint, .opening .to-line { opacity: 0; transition: opacity .5s; }
.leaving { animation: gate-out .7s ease forwards; }
@keyframes seal-break {
  30% { transform: translate(-50%, -50%) scale(1.12) rotate(-6deg); }
  100% { transform: translate(-50%, 40%) scale(.6) rotate(24deg); opacity: 0; }
}
@keyframes gate-out { to { opacity: 0; transform: scale(1.04); } }

/* ============ ٢. الرسالة ============ */
#story { position: relative; z-index: 1; animation: rise 1s ease backwards; }
@keyframes rise { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }

.letter {
  position: relative; color: var(--ink);
  width: min(640px, calc(100% - 1.5rem)); margin: 3.5rem auto 0;
  padding: clamp(2.6rem, 8vw, 4rem) clamp(1.5rem, 7vw, 3.75rem) 3rem;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, .7), transparent 60%),
    linear-gradient(180deg, #fdf9f2, var(--paper) 40%, #f6eddf);
  border-radius: 4px;
  box-shadow: 0 60px 90px -50px rgba(0, 0, 0, .8), inset 0 0 60px rgba(160, 120, 60, .12);
}
.letter-frame { position: absolute; inset: 14px; border: 1px solid rgba(143, 106, 46, .45); pointer-events: none; }
.letter-frame::after { content: ''; position: absolute; inset: 4px; border: 1px solid rgba(143, 106, 46, .22); }
.letter-frame .c { position: absolute; width: 16px; height: 16px; background: var(--paper); }
.letter-frame .c::before { content: ''; position: absolute; inset: 4px; transform: rotate(45deg); background: var(--gold); }
.letter-frame .tl { top: -8px; right: -8px; } .letter-frame .tr { top: -8px; left: -8px; }
.letter-frame .bl { bottom: -8px; right: -8px; } .letter-frame .br { bottom: -8px; left: -8px; }

.salute { text-align: center; margin-bottom: 2.5rem; }
.salute-word { display: block; color: var(--muted); font-size: 1.05rem; }
.salute-name { font-family: var(--script); font-size: clamp(2.6rem, 11vw, 3.8rem); color: var(--accent); margin: 0; line-height: 1.4; }

.chapter { margin: 0 0 3rem; }
.orn { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 auto 3rem; }
.orn::before, .orn::after { content: ''; width: 40px; height: 1px; background: var(--gold-2); }
.orn i { width: 7px; height: 7px; transform: rotate(45deg); background: var(--gold); }
.ch-mark { display: flex; align-items: baseline; gap: .7rem; margin-bottom: .4rem; }
.ch-num { font-family: var(--script); font-size: 1.9rem; line-height: 1; color: var(--gold-3); }
.ch-title { font-size: clamp(1.4rem, 5.5vw, 1.75rem); margin: 0; color: var(--accent); }
.ch-date { display: block; color: var(--muted); font-size: .95rem; margin: 0 0 1rem; }
.ch-text { font-size: 1.2rem; line-height: 2.15; margin: 0; white-space: pre-line; }

/* إطار القوس */
.arch {
  margin: 0 auto 1.5rem; width: min(100%, 420px); padding: 8px;
  border-radius: 999px 999px 6px 6px; border: 1px solid rgba(143, 106, 46, .55);
  background: linear-gradient(#fff, #fbf5ea);
}
.arch img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 999px 999px 3px 3px; }

.sign { margin-top: 3rem; text-align: left; }
.sign-word { display: block; color: var(--muted); }
.sign-name { font-family: var(--script); font-size: 2.4rem; color: var(--accent); line-height: 1.4; }

/* ============ ٣. السؤال ============ */
.ask { padding-top: 5rem; }
.ring { width: 96px; height: 96px; margin-bottom: 1.4rem; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .45)); }
.glint { opacity: 0; transform-origin: 66px 29px; }
.ask.seen .glint { animation: glint 2.8s ease-in-out .4s infinite; }
@keyframes glint { 0%, 70%, 100% { opacity: 0; transform: scale(.2); } 80% { opacity: 1; transform: scale(1.4); } }
.q-pre { max-width: 32ch; font-size: 1.2rem; color: rgba(251, 246, 238, .8); white-space: pre-line; margin: 0 0 .6rem; }
.q-text { font-family: var(--script); font-size: clamp(3rem, 15vw, 5.4rem); line-height: 1.45; margin: 0 0 2.2rem; }
.choices { display: flex; flex-direction: column; align-items: center; gap: 1.1rem; }
#yes { min-width: 210px; justify-content: center; transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), filter .2s; }
.no-btn {
  font: inherit; font-size: 1.05rem; color: rgba(251, 246, 238, .7); background: transparent;
  border: 0; padding: .4em 1em; cursor: pointer; text-decoration: underline; text-underline-offset: 6px;
  text-decoration-color: rgba(243, 223, 166, .35);
}
.no-btn.runaway {
  position: fixed; z-index: 50; text-decoration: none; color: var(--ink);
  background: var(--paper); border-radius: 999px; box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .6);
  transition: left .28s ease, top .28s ease;
}

/* ============ ٤. النهاية ============ */
#final .arch { width: min(260px, 70vw); border-color: rgba(243, 223, 166, .6); background: rgba(243, 223, 166, .08); }
.f-title { font-family: var(--script); font-size: clamp(2.4rem, 10vw, 3.8rem); line-height: 1.45; margin: 0 0 .6rem; }
.f-msg { max-width: 34ch; font-size: 1.25rem; line-height: 2; white-space: pre-line; margin: 0; }
.reply {
  width: min(440px, 100%); margin: 2.4rem auto 0; text-align: right;
  background: var(--paper); color: var(--ink); padding: 1.4rem; border-radius: 6px;
  box-shadow: 0 40px 60px -40px rgba(0, 0, 0, .8);
}
.reply label { margin-top: 0; }
.reply textarea { margin-bottom: .9rem; background: #fffdf9; }
.reply .btn { width: 100%; justify-content: center; }
.r-done { margin-top: 2rem; font-size: 1.2rem; color: var(--gold-1); }

/* ============ أدوات ============ */
.mute {
  position: fixed; bottom: 18px; left: 18px; z-index: 60;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  background: rgba(0, 0, 0, .25); color: var(--gold-1); border: 1px solid rgba(243, 223, 166, .4);
  backdrop-filter: blur(6px);
}
.mute.off { opacity: .45; }
.preview-badge {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 70;
  background: rgba(0, 0, 0, .55); color: var(--gold-1); border: 1px solid rgba(243, 223, 166, .35);
  padding: .15em 1em; border-radius: 99px; font-size: .85rem;
}

@media (prefers-reduced-motion: reduce) {
  .seal::after, .ask.seen .glint, #story { animation: none; }
  .env-flap, .env-letter { transition-duration: .01s; transition-delay: 0s; }
}
