/* الصفحة الرئيسية v3: بوابة ← فيديو (طولي للهاتف / عرضي للحاسوب) ← بطاقة QR ← الشجرة */
body { overscroll-behavior: none; }

/* ١) البوابة */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--plum); }
.gate { overflow: hidden; background: #0B0A1E; }
/* الغلاف بنسبة الصورة نفسها ويغطي الشاشة (يحاكي cover) كي تبقى المؤثرات فوق مواضعها؛ gate.js يضبط مقاسه */
.gate-scene { position: absolute; left: 50%; bottom: 0; width: 100vw; height: 100vh;
  transform: translateX(-50%) translate(calc(var(--px, 0) * -14px), calc(var(--py, 0) * -10px)); will-change: transform; }
.gate-cam { position: absolute; inset: 0; animation: gateCam 28s ease-in-out infinite alternate; transform-origin: 42% 55%; }
.gate-scene picture, .gate-poster { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.gate-poster { object-fit: cover; }
.gate-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
  transform: translate(calc(var(--px, 0) * -9px), calc(var(--py, 0) * -6px)); }   /* طبقة الضوء أقرب للعين: تتحرك أكثر فيظهر العمق */
@keyframes gateCam { from { transform: scale(1.04); } to { transform: scale(1.12) translate(-1%, -.6%); } }
.gate-scene.still .gate-cam { animation: none; transform: scale(1.04); }
.gate-title { position: absolute; z-index: 1; top: calc(7vh + env(safe-area-inset-top)); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #FFF3D6; text-align: center; pointer-events: none; animation: titleIn 2.4s cubic-bezier(.2, .8, .2, 1) .3s both;
  text-shadow: 0 0 22px rgba(255, 200, 110, .55), 0 2px 10px rgba(11, 10, 30, .9); }
.gate-title .t1 { font-family: var(--f-head); font-weight: 600; font-size: clamp(54px, 15vw, 96px); line-height: 1.05; letter-spacing: .5px; }
.gate-title .t2 { font-family: var(--f-head); font-weight: 600; font-size: clamp(24px, 6.4vw, 38px); color: #F1D9A6; }
body.land .gate-title { top: 10vh; left: auto; right: 6vw; width: auto; }
body.land .gate-title .t1 { font-size: clamp(60px, 8vw, 120px); } body.land .gate-title .t2 { font-size: clamp(26px, 3vw, 44px); }
@keyframes titleIn { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
.gate-ui { position: absolute; inset: auto 0 0 0; display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 80px 16px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(to top, rgba(11, 10, 30, .82), rgba(11, 10, 30, 0)); gap: 6px; }
.gate-ui .btn-hero { box-shadow: 0 0 0 2px rgba(255, 226, 150, .35), 0 6px 26px rgba(255, 190, 90, .45); }
.btn-hero { min-height: 64px; font-size: 26px; padding: 0 44px; border-radius: 18px; }
.btn-link { background: none; border: 0; color: var(--paper); font-family: var(--f-body); font-size: 16px; min-height: 44px; min-width: 44px; padding: 0 12px;
  text-decoration: underline; text-underline-offset: 4px; cursor: pointer; opacity: .95; }
.btn-link.small { font-size: 15px; }

/* ٢) الفيديو */
.film { position: fixed; inset: 0; background: #000; display: grid; place-items: center; transition: opacity .6s ease; }
.film.leaving { opacity: 0; }
.film-frame { position: relative; overflow: hidden; aspect-ratio: 9 / 16; height: 100%; max-height: 100dvh; max-width: 100vw; }
body.land .film-frame { aspect-ratio: 16 / 9; width: 100%; height: auto; max-height: 100dvh; max-width: calc(100dvh * 16 / 9); }
.film-frame video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.cap { position: absolute; inset: auto 6% calc(13% + env(safe-area-inset-bottom)) 6%; margin: 0; text-align: center;
  font-family: var(--f-msg); font-size: clamp(19px, 4.6vh, 30px); line-height: 1.55; color: #FFF8EA;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9), 0 0 12px rgba(0, 0, 0, .65); pointer-events: none; opacity: 0; transition: opacity .3s ease; }
/* العرضي: الترجمة في اللوحة اليسرى بجانب إطار الفيلم (الفيلم في اليمين) */
body.land .cap { inset: 30% 50% auto 6%; font-size: clamp(22px, 3.1vw, 46px); line-height: 1.7; text-align: center; }
.cap.on { opacity: 1; }
.film-tools { position: absolute; top: calc(12px + env(safe-area-inset-top)); inset-inline: 12px; display: flex; justify-content: space-between; align-items: center; z-index: 2; }
.film-tools .btn-link { background: rgba(30, 15, 42, .55); border-radius: 22px; text-decoration: none; }

/* ٣) بطاقة الـQR */
.endcard { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); text-align: center; animation: rise .9s cubic-bezier(.2, .8, .2, 1) both;
  background: radial-gradient(ellipse at 50% 45%, rgba(30, 15, 42, .55), rgba(30, 15, 42, .82)); }
body.land .endcard { inset: 6% 5% 6% auto; width: min(44%, 560px); border-radius: 26px; background: rgba(30, 15, 42, .80); }
.end-title { font-family: var(--f-head); font-weight: 600; font-size: clamp(20px, 3.1vh, 28px); line-height: 1.5; margin: 0; max-width: 22em; color: var(--paper); }
.closing { margin: 0; min-height: 1.6em; font-family: var(--f-msg); font-size: clamp(17px, 2.3vh, 22px); color: var(--glow); max-width: 24em; opacity: 0; transition: opacity .5s; }
.closing.on { opacity: 1; }
.qr { width: max(280px, min(74vw, 380px, 42vh)); aspect-ratio: 1; background: var(--paper); border-radius: 12px; box-shadow: 0 0 0 6px rgba(232, 176, 74, .35); }
body.land .qr { width: min(36vh, 300px, 80%); }
.qr svg { display: block; width: 100%; height: 100%; }
.qr-url { margin: 0; font-family: system-ui, sans-serif; font-size: 16px; color: var(--paper); letter-spacing: .02em; }
.end-actions { display: flex; flex-direction: column; gap: 10px; width: min(100%, 360px); }
.only-touch { display: none; }
@media (pointer: coarse) { .only-touch { display: inline-flex; } }
@media (max-height: 700px) { .endcard { gap: 8px; padding-top: 14px; } .end-title { font-size: 18px; } .closing { font-size: 15px; } .end-actions .btn { min-height: 48px; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ٤) الشجرة */
.tree { position: fixed; inset: 0; background: var(--plum); overflow: hidden; animation: fadeIn .6s ease both; }
.tree-backdrop { position: absolute; inset: -40px; background: center / cover no-repeat; filter: blur(24px) brightness(.45); }
.tree-bar { position: absolute; z-index: 4; inset: 0 0 auto 0; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: linear-gradient(to bottom, rgba(30, 15, 42, .9), rgba(30, 15, 42, 0)); pointer-events: none; }
.tree-bar > * { pointer-events: auto; }
.tree-count { margin: 0; font-family: var(--f-head); font-size: 19px; color: var(--paper); text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
.tree-actions { display: flex; gap: 8px; align-items: center; }
.tree-foot { position: absolute; z-index: 3; inset: auto 0 calc(6px + env(safe-area-inset-bottom)) 0; margin: 0; text-align: center; font-size: 12px; color: var(--muted); pointer-events: none; text-shadow: 0 1px 2px #000; }
.viewport { position: absolute; inset: 0; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.viewport.dragging { cursor: grabbing; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.stage.fly { transition: transform 1.4s cubic-bezier(.45, .05, .25, 1); }
.plate { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.spiral { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.spiral path { fill: none; stroke: rgba(232, 176, 74, .45); stroke-width: 6; stroke-linecap: round; filter: drop-shadow(0 0 10px rgba(232, 176, 74, .7)); }
.leaves { position: absolute; inset: 0; }
.ambient { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fit-btn { position: absolute; z-index: 5; right: 14px; bottom: calc(40px + env(safe-area-inset-bottom)); box-shadow: 0 0 0 2px rgba(232, 176, 74, .7); }

/* الورقة: شكل ورقة لبان (قناع SVG: بيضاوية مدبّبة بحافة مسنّنة) + عِرق أوسط + توهج */
.leaf { position: absolute; left: 0; top: 0; width: var(--w, 96px); height: var(--h, 42px); margin: calc(var(--h, 42px) / -2) 0 0 calc(var(--w, 96px) / -2);
  transform: rotate(var(--r, 0deg)); filter: drop-shadow(0 0 7px rgba(201, 240, 122, .65)); display: grid; place-items: center; }
.leaf i { position: absolute; inset: 0; background:
    linear-gradient(to bottom, transparent 47%, rgba(248, 255, 224, .55) 49%, rgba(248, 255, 224, .55) 51%, transparent 53%),
    radial-gradient(ellipse at 45% 40%, #F1FFC4 0%, #C9F07A 35%, #86BE4B 75%, #5E9A34 100%);
  -webkit-mask: url(/img/leaf.svg) center / 100% 100% no-repeat; mask: url(/img/leaf.svg) center / 100% 100% no-repeat; }
.leaf span { position: relative; z-index: 1; max-width: 76%; font-family: var(--f-msg); font-size: var(--fs, 15px); line-height: 1.12; color: #12240A; text-align: center;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; word-break: break-word; opacity: 0; transition: opacity .3s; }
.viewport.readable .leaf span { opacity: 1; }
.leaf.sp { --fs: 13px; }
.viewport.readable-sp .leaf.sp span { opacity: 1; }
.viewport.readable:not(.readable-sp) .leaf.sp span { opacity: 0; }
.leaf.sp.back { opacity: .42; filter: saturate(.7) brightness(.85); }
.leaf.sp:not(.back) { z-index: 2; }
.leaf:not(.sp) { z-index: 1; }
.leaf.mizoon { filter: drop-shadow(0 0 14px rgba(232, 176, 74, .95)); z-index: 3; }
.leaf.mizoon i { background: linear-gradient(to bottom, transparent 47%, rgba(255, 246, 214, .7) 49%, rgba(255, 246, 214, .7) 51%, transparent 53%),
  radial-gradient(ellipse at 45% 40%, #FFF1C4 0%, #F4C45A 40%, #D99A2B 80%, #A86A12 100%); }
.leaf.mizoon span { color: #3A1A05; font-weight: 700; }
.leaf.mine { filter: drop-shadow(0 0 16px rgba(255, 255, 255, .95)) drop-shadow(0 0 6px rgba(232, 176, 74, 1)); z-index: 4; }
.leaf { animation: sway var(--sd, 6s) ease-in-out var(--sdl, 0s) infinite; }
.leaf.pulse { animation: breathe 3.2s ease-in-out infinite, sway 6s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(calc(var(--r, 0deg) - 1.8deg)); } 50% { transform: rotate(calc(var(--r, 0deg) + 1.8deg)); } }
.leaf.new { animation: sprout 1.2s cubic-bezier(.2, 1.4, .4, 1) both; }
.leaf.new::before { content: ""; position: absolute; inset: -60%; border-radius: 50%; background: radial-gradient(circle, rgba(232, 176, 74, .9), rgba(232, 176, 74, 0) 70%); animation: halo 1.2s ease-out both; }
.leaf.sel { outline: 3px solid var(--gold); outline-offset: 4px; border-radius: 40%; }
@keyframes sprout { 0% { transform: rotate(calc(var(--r, 0deg) - 40deg)) scale(0); } 100% { transform: rotate(var(--r, 0deg)) scale(1); } }
@keyframes halo { 0% { opacity: 1; transform: scale(.4); } 100% { opacity: 0; transform: scale(2.2); } }
@keyframes breathe { 0%, 100% { filter: drop-shadow(0 0 10px rgba(232, 176, 74, .8)); } 50% { filter: drop-shadow(0 0 22px rgba(232, 176, 74, 1)); } }

/* ميزون تعلّق */
.mz { position: absolute; z-index: 5; inset: auto auto calc(36px + env(safe-area-inset-bottom)) 14px; display: flex; align-items: center; gap: 10px; max-width: min(88vw, 420px);
  animation: rise .5s cubic-bezier(.2, .8, .2, 1) both; pointer-events: none; }
.mz img { width: 64px; height: 64px; border-radius: 50%; box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(232, 176, 74, .7); flex: none; }
.mz-text { margin: 0; padding: 10px 16px; border-radius: 18px 18px 18px 4px; background: var(--paper); color: var(--ink); font-family: var(--f-msg); font-size: 20px; line-height: 1.4; }
.snd-ask { position: absolute; z-index: 5; top: calc(68px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); box-shadow: 0 4px 18px rgba(0, 0, 0, .35); }

/* بطاقة القراءة */
.card { border: 0; border-radius: 20px; padding: 26px 22px 20px; width: min(92vw, 460px); background: var(--paper); color: var(--ink); text-align: center; }
.card::backdrop { background: rgba(20, 8, 26, .72); }
.card-stamp { display: inline-block; margin: 0 0 8px; padding: 2px 14px; border-radius: 999px; background: var(--gold); color: var(--ink); font-family: var(--f-head); font-size: 15px; }
.card-text { font-family: var(--f-msg); font-size: 28px; line-height: 1.6; margin: 6px 0 10px; overflow-wrap: anywhere; }
.card-time { margin: 0 0 16px; color: #5E4A52; font-size: 15px; }

/* بطاقة القراءة: أزرار */
.card-acts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.card-acts form { margin: 0; }
.btn-danger { background: #8E2431; color: #FFF3F3; }

/* الإعدادات */
.settings { border: 0; border-radius: 20px; padding: 20px 18px; width: min(94vw, 560px); max-height: 88dvh; background: #2A1636; color: var(--paper); }
.settings::backdrop { background: rgba(20, 8, 26, .75); }
.set-title { font-family: var(--f-head); font-size: 22px; margin: 0 0 12px; text-align: center; }
.pin-view { display: grid; gap: 10px; justify-items: center; }
.pin-view label { font-size: 17px; }
#pin { width: 9ch; min-height: 56px; text-align: center; font-size: 30px; letter-spacing: .5em; border-radius: var(--r); border: 2px solid rgba(232, 176, 74, .6); background: var(--paper); color: var(--ink); padding: 0 0 0 .5em; }
.set-err { min-height: 1.4em; margin: 0; color: #FFD27A; text-align: center; }
.set-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; margin: 8px 0; }
.set-all { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; color: var(--muted); }
.set-all input, .set-list input { width: 26px; height: 26px; accent-color: var(--gold); }
.set-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.set-stats div { background: var(--plum); border-radius: 12px; padding: 8px; text-align: center; }
.set-stats b { display: block; font-family: var(--f-head); font-size: 24px; color: var(--gold); }
.set-stats span { font-size: 13px; color: var(--muted); }
.set-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; max-height: 42dvh; overflow: auto; }
.set-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; background: var(--plum); border-radius: 12px; padding: 6px 10px; }
.set-list .t { font-family: var(--f-msg); font-size: 18px; overflow-wrap: anywhere; }
.set-list .t small { display: block; font-family: var(--f-body); font-size: 12px; color: var(--muted); }

/* وضع العرض على شاشة كبيرة ?tv=1 */
body.tv .tree-actions, body.tv .tree-foot, body.tv .snd-ask { display: none; }
body.tv .tree-count { font-size: 30px; }

@media (prefers-reduced-motion: reduce) {
  .leaf, .leaf.pulse, .leaf.new, .leaf.new::before, .mz, .endcard, .gate-cam, .gate-title { animation: none !important; }
  .stage.fly { transition: none; }
}

/* شريط الشجرة على الشاشات الضيقة: الأزرار في سطر واحد */
.tree-actions .btn-small { white-space: nowrap; }
@media (max-width: 420px) {
  .tree-bar { padding-inline: 8px; gap: 6px; }
  .tree-actions { gap: 5px; }
  .tree-actions .btn-small { padding: 0 10px; font-size: 15px; }
  .tree-actions .icon-btn { width: 44px; height: 44px; }
  .tree-count { font-size: 16px; }
}

/* هاتف مُدار (شاشة عرضية قصيرة): بطاقة الـQR والإعدادات مضغوطة وتمرير داخلي */
.settings { overflow: auto; }
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  body.land .endcard { inset: 3% 3% 3% auto; width: min(52%, 460px); gap: 6px; padding: 10px 14px; overflow: auto; }
  body.land .end-title { font-size: 15px; line-height: 1.4; }
  body.land .closing { font-size: 13px; min-height: 0; }
  body.land .qr { width: min(46vh, 190px); }
  body.land .qr-url { font-size: 13px; }
  body.land .end-actions { flex-direction: row; gap: 8px; }
  body.land .end-actions .btn { min-height: 44px; font-size: 15px; padding: 0 12px; flex: 1; }
  .settings { max-height: 94dvh; padding: 12px 14px; }
  .set-stats b { font-size: 18px; }
  .set-list { max-height: 24dvh; }
  .set-row { margin: 4px 0; }
}
.gate-ui .btn-hero, .gate-ui .btn-link { font-family: var(--f-head); font-weight: 600; }   /* خط العنوان المحمَّل أصلًا: لا خطوط إضافية قبل الفيديو */
