/* =====================================================
   شجرة العائلة — الطراز الحساوي
   انترو سينمائي ليلي  →  شجرة رملية مضيئة  +  دوك عائم
   ===================================================== */

:root {
  --sand: #f3e9d2;
  --sand-2: #ecdfc0;
  --sand-3: #e2cfa3;
  --mud: #7a5636;
  --mud-dark: #54371f;
  --wood: #6f4a2a;
  --ink: #3d2b1c;
  --terracotta: #b4582e;
  --gold: #c9a227;
  --gold-soft: #caa23c;
  --gold-bright: #e7c668;
  --palm: #476b38;
  --palm-soft: #6d8a4a;
  --night-1: #1c130a;
  --night-2: #34240f;
  --night-3: #241809;
  --card-bg: #f9efdb;
  --card-bg-2: #efdfbb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Amiri', 'Traditional Arabic', serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 520px at 50% -90px, #f8efdb 0%, transparent 62%),
    linear-gradient(var(--sand), var(--sand-2));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* نقشة جصية هندسية خفيفة على صفحة الشجرة */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23b99b5f' stroke-opacity='0.15' stroke-width='1'%3E%3Crect x='20' y='20' width='24' height='24'/%3E%3Crect x='20' y='20' width='24' height='24' transform='rotate(45 32 32)'/%3E%3Ccircle cx='32' cy='32' r='3'/%3E%3Cpath d='M0 32h12M52 32h12M32 0v12M32 52v12'/%3E%3C/g%3E%3C/svg%3E");
  z-index: 0;
}

/* =====================================================
   شاشة البداية (الانترو)
   ===================================================== */
#intro {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(900px 460px at 78% 18%, rgba(201, 162, 39, 0.16), transparent 60%),
    radial-gradient(700px 500px at 12% 92%, rgba(180, 88, 46, 0.12), transparent 60%),
    linear-gradient(150deg, var(--night-2) 0%, var(--night-3) 48%, var(--night-1) 100%);
  transition: opacity 0.85s ease, visibility 0s linear 0.85s;
}
#intro::after { /* نقشة هندسية ذهبية خافتة */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='72' height='72' viewBox='0 0 72 72'%3E%3Cg fill='none' stroke='%23c9a227' stroke-opacity='0.08' stroke-width='1'%3E%3Crect x='22' y='22' width='28' height='28'/%3E%3Crect x='22' y='22' width='28' height='28' transform='rotate(45 36 36)'/%3E%3Ccircle cx='36' cy='36' r='3'/%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.9;
}
body.entered #intro { opacity: 0; visibility: hidden; pointer-events: none; }

.introEditBtn {
  position: absolute;
  z-index: 8;
  top: 28px;
  left: 18px;
  font-family: 'Amiri', serif;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  color: #f0dca8;
  background: rgba(28, 19, 10, 0.55);
  border: 1.5px solid rgba(201, 162, 39, 0.75);
  padding: 8px 16px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
.introEditBtn:hover {
  background: rgba(201, 162, 39, 0.28);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

#loginScreen, #nameEditScreen {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 10, 4, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 18px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s, visibility 0.3s;
}
#loginScreen.open, #nameEditScreen.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
#nameEditScreen { z-index: 1200; }
.nameEditField { margin-bottom: 14px; text-align: start; }
.nameEditField label { display: block; color: #c4a35a; font-size: 14px; margin-bottom: 4px; }
.nameEditInput {
  width: 100%;
  font-family: inherit;
  font-size: 18px;
  text-align: center;
  background: rgba(12, 8, 4, 0.72);
  color: #f0dca8;
  border: 1.5px solid rgba(201, 162, 39, 0.55);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
.nameEditInput:focus { border-color: var(--gold-bright); box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.25); }
.loginBox {
  width: min(420px, 94vw);
  background:
    radial-gradient(420px 180px at 50% 0%, rgba(201, 162, 39, 0.16), transparent 70%),
    linear-gradient(180deg, #2a1c0c, #1c130a);
  border: 1.6px solid var(--gold);
  border-radius: 18px;
  padding: 28px 24px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.loginBox h2 {
  font-family: 'Aref Ruqaa', serif;
  color: var(--gold-bright);
  font-size: 28px;
  margin-bottom: 6px;
}
.loginSub { color: #c4a35a; font-size: 15px; margin-bottom: 18px; }
#loginPass {
  width: 100%;
  font-family: inherit;
  font-size: 20px;
  letter-spacing: 3px;
  text-align: center;
  background: rgba(12, 8, 4, 0.72);
  color: #f0dca8;
  border: 1.5px solid rgba(201, 162, 39, 0.55);
  border-radius: 12px;
  padding: 12px;
  outline: none;
}
#loginPass:focus { border-color: var(--gold-bright); box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.25); }
.loginErr { color: #e08a6a; font-size: 14px; margin: 12px 0 0; }
.loginErr[hidden] { display: none !important; }
.loginActions { display: flex; gap: 8px; margin-top: 16px; justify-content: center; }
.loginActions .pAddPrimary, .loginActions .pAddGhost { min-width: 96px; }

#saveBar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: linear-gradient(180deg, #3d2b1c, #2a1c0c);
  color: #f0dca8;
  padding: 10px 16px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  border-bottom: 1px solid rgba(201, 162, 39, 0.55);
  font-size: 15px;
}
body.editing #saveBar { display: flex; }
body.editing #panel { top: 62px; }
#saveBar.dirty #saveBarBtn { box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.45); }

/* شريطا الإطار العلوي والسفلي (شرفات طين + جص) */
.introTop, .introBottom { position: absolute; left: 0; right: 0; z-index: 3; }
.introTop {
  top: 0; height: 18px;
  background:
    linear-gradient(90deg, var(--gold) 0 22px, transparent 22px 38px) 0 0 / 38px 10px repeat-x,
    linear-gradient(#7a5a22, #7a5a22) 0 10px / 100% 8px no-repeat;
  opacity: 0.85;
}
.introBottom {
  bottom: 0; height: 30px;
  border-top: 1px solid rgba(201, 162, 39, 0.4);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='26' viewBox='0 0 30 26'%3E%3Cg fill='none' stroke='%23c9a227' stroke-opacity='0.4' stroke-width='1.1'%3E%3Cpath d='M15 2 l7 5 v10 l-7 5 -7 -5 V7 Z'/%3E%3Ccircle cx='15' cy='13' r='2'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 30px 26px;
}

/* حبيبات الغبار الذهبية الطافية */
.motes { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 2; }
.mote {
  position: absolute;
  bottom: -12px;
  width: var(--sz, 3px);
  height: var(--sz, 3px);
  border-radius: 50%;
  background: radial-gradient(circle, var(--gold-bright), rgba(201, 162, 39, 0.1));
  box-shadow: 0 0 6px rgba(231, 198, 104, 0.7);
  opacity: 0;
  animation: floatUp var(--d, 9s) linear var(--delay, 0s) infinite;
}
@keyframes floatUp {
  0%   { transform: translateY(0) translateX(0); opacity: 0; }
  12%  { opacity: 0.85; }
  88%  { opacity: 0.7; }
  100% { transform: translateY(-104vh) translateX(var(--drift, 0)); opacity: 0; }
}

/* شبكة الانترو غير المتماثلة */
.introGrid {
  position: relative;
  z-index: 4;
  width: min(1180px, 92vw);
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: clamp(28px, 5vw, 80px);
  align-items: center;
}

/* عمود النص */
.kicker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--gold-bright);
  text-transform: uppercase;
}
.kicker::before { content: ''; width: 34px; height: 1.5px; background: linear-gradient(90deg, transparent, var(--gold)); }

.introTitle { line-height: 0.92; margin: 14px 0 4px; }
.introTitle .t-small {
  display: block;
  font-family: 'Amiri', serif;
  font-size: clamp(22px, 3vw, 34px);
  color: #d8c39a;
  font-weight: 400;
}
.introTitle .t-big {
  display: block;
  font-family: 'Aref Ruqaa', serif;
  font-weight: 700;
  font-size: clamp(36px, 7vw, 96px);
  color: var(--gold-bright);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 0 34px rgba(201, 162, 39, 0.35);
  letter-spacing: 1px;
}

.seal {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 16px 0 6px;
  padding: 12px 32px;
  max-width: 100%;
  border: 1.5px solid rgba(201, 162, 39, 0.6);
  border-radius: 999px;
  position: relative;
  background: rgba(201, 162, 39, 0.06);
  box-shadow: inset 0 0 0 3px rgba(28, 19, 10, 0.6), inset 0 0 0 4px rgba(201, 162, 39, 0.35);
}
.seal::before, .seal::after {
  content: '◆';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gold);
  font-size: 9px;
}
.seal::before { right: 8px; }
.seal::after { left: 8px; }
.seal span {
  font-family: 'Aref Ruqaa', serif;
  font-size: clamp(16px, 2.2vw, 26px);
  color: #f0dca8;
  text-align: center;
  line-height: 1.35;
}
.introNameEdit {
  display: inline-flex;
  margin-top: 10px;
  font-family: 'Amiri', serif;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  color: #f0dca8;
  background: rgba(28, 19, 10, 0.45);
  border: 1.4px solid rgba(201, 162, 39, 0.7);
  padding: 6px 14px;
  border-radius: 999px;
}
.introNameEdit:hover { background: rgba(201, 162, 39, 0.28); }
.seal i { font-style: normal; font-size: 11px; letter-spacing: 2px; color: #b89a63; margin-top: 2px; }

.introDesc {
  max-width: 46ch;
  font-size: clamp(15px, 1.5vw, 18px);
  line-height: 1.95;
  color: #cdb98f;
  margin: 14px 0 22px;
}

.introActions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
#enterBtn {
  font-family: 'Amiri', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--night-1);
  padding: 13px 30px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  box-shadow: 0 8px 24px rgba(201, 162, 39, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.2s, box-shadow 0.2s;
}
#enterBtn:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(201, 162, 39, 0.5); }
#enterBtn .arr { transition: transform 0.2s; }
#enterBtn:hover .arr { transform: translateX(-5px); }
.introActions .hint { font-size: 12.5px; color: #8f7a52; }

.loadWrap { margin-top: 26px; display: flex; align-items: center; gap: 12px; }
.loadTrack { width: 180px; height: 3px; border-radius: 3px; background: rgba(201, 162, 39, 0.18); overflow: hidden; }
.loadBar { height: 100%; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--gold), var(--gold-bright)); transition: width 1.6s cubic-bezier(0.4, 0, 0.2, 1); }
.loadTxt { font-size: 11.5px; letter-spacing: 1px; color: #8f7a52; }
.loadTxt::after { content: 'يُهيّئ الواحة…'; }
#intro.ready .loadTxt::after { content: 'جاهز'; color: var(--gold-bright); }

/* عمود المشهد: نخلة تنمو داخل إطار */
.introScene { position: relative; display: flex; flex-direction: column; align-items: center; }
.frame {
  position: absolute;
  inset: -6px 6px 56px;
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 18px;
}
.frame::before, .frame::after {
  content: '◆';
  position: absolute;
  color: var(--gold);
  font-size: 11px;
  background: var(--night-3);
  padding: 0 4px;
}
.frame::before { top: -7px; right: 18px; }
.frame::after { bottom: -7px; left: 18px; }

.palm { width: min(300px, 70%); height: auto; filter: drop-shadow(0 0 8px rgba(201, 162, 39, 0.22)); }
.grow { fill: none; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; }
.grow.trunk { stroke: #d8b25a; stroke-width: 6; }
.grow.frond { stroke-width: 4; }
#intro.ready .grow.trunk { animation: draw 1.1s ease forwards; }
#intro.ready .grow.frond { animation: draw 0.7s ease forwards; animation-delay: calc(0.7s + var(--i) * 0.08s); }
@keyframes draw { to { stroke-dashoffset: 0; } }
.dates .date { transform-box: fill-box; transform-origin: center; transform: scale(0); }
#intro.ready .dates .date { animation: pop 0.4s cubic-bezier(0.3, 1.5, 0.5, 1) forwards; animation-delay: calc(1.5s + var(--j) * 0.07s); }
@keyframes pop { to { transform: scale(1); } }

.sceneStats {
  margin-top: 18px;
  display: flex;
  gap: 26px;
  padding: 12px 22px;
  border-top: 1px solid rgba(201, 162, 39, 0.3);
  border-bottom: 1px solid rgba(201, 162, 39, 0.3);
}
.sceneStats div { text-align: center; }
.sceneStats b { display: block; font-family: 'Aref Ruqaa', serif; font-size: 30px; color: var(--gold-bright); line-height: 1; }
.sceneStats span { font-size: 12px; color: #b89a63; letter-spacing: 1px; }

/* تتابع الظهور */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.2, 0.8, 0.3, 1); }
#intro.ready .reveal { opacity: 1; transform: none; }
#intro.ready .r1 { transition-delay: 0.15s; }
#intro.ready .r2 { transition-delay: 0.3s; }
#intro.ready .r3 { transition-delay: 0.45s; }
#intro.ready .r4 { transition-delay: 0.7s; }
#intro.ready .r5 { transition-delay: 0.95s; }
#intro.ready .r6 { transition-delay: 1.2s; }

/* =====================================================
   منطقة الشجرة
   ===================================================== */
#viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  z-index: 1;
}
#viewport:active { cursor: grabbing; }
#viewport::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 120px rgba(120, 90, 40, 0.22);
  z-index: 20;
}

#stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; overflow: visible; }
#stage.anim { transition: transform 0.6s cubic-bezier(0.22, 0.8, 0.3, 1); }
#scene { position: absolute; top: 0; left: 0; display: block; overflow: visible; }
#cards { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: visible; }

/* بطاقات الأسماء — أقواس حساوية
   خلفية البطاقة (نفس مكان خضار الجيل السادس) تتدرج أبيض: الأول أغمق والعاشر أفتح */
.node {
  --s: 1;
  position: absolute;
  transform: translate(-50%, -100%) scale(var(--s));
  transform-origin: 50% 100%;
  width: var(--w, 104px);
  padding: 10px 8px 11px;
  font-family: 'Amiri', serif;
  background: linear-gradient(var(--card-top, var(--card-bg)), var(--card-bot, var(--card-bg-2)));
  border: 1.6px solid #8f6238;
  border-radius: 999px 999px 9px 9px;
  box-shadow:
    inset 0 0 0 2px #f7ecd4,
    inset 0 0 0 3.5px rgba(201, 162, 39, 0.5),
    0 3px 7px rgba(62, 42, 20, 0.28);
  cursor: grab;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  z-index: 3;
  transition: transform 0.18s, box-shadow 0.18s, opacity 0.25s, border-color 0.18s;
}
.node::before {
  content: '';
  position: absolute;
  top: -6px; left: 50%;
  width: 9px; height: 9px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--gold);
  border: 1px solid #a5851f;
}
.node::after {
  content: '';
  position: absolute;
  bottom: 3px;
  inset-inline: 16px;
  height: 4px;
  border-radius: 2px;
  background: var(--gen, var(--wood));
  opacity: 0.85;
}
.node .nm { font-weight: 700; font-size: var(--fs, 19px); line-height: 1.05; color: #4a3320; white-space: nowrap; }
.node .ft { font-size: calc(var(--fs, 19px) * 0.55); color: #8a6a45; white-space: nowrap; line-height: 1; }

.gen1 { --w: 150px; --fs: 26px; --gen: #8a5a2b; --card-top: #cfc0a8; --card-bot: #c4b49a; border-width: 2px; }
.gen2 { --w: 136px; --fs: 23px; --gen: #b4582e; --card-top: #d8cbb6; --card-bot: #cec0aa; }
.gen3 { --w: 128px; --fs: 21px; --gen: #c9a227; --card-top: #e0d4c2; --card-bot: #d6c9b6; }
.gen4 { --w: 124px; --fs: 20px; --gen: #7a8a3f; --card-top: #e8dece; --card-bot: #dfd4c4; }
.gen5 { --w: 116px; --fs: 19px; --gen: #476b38; --card-top: #eee6d8; --card-bot: #e6ddcf; }
.gen6 { --w: 104px; --fs: 18px; --gen: #2f5c32; --card-top: #f3ece0; --card-bot: #ece5d8; }
.gen7 { --w: 100px; --fs: 17px; --gen: #24522a; --card-top: #f6f1e8; --card-bot: #f1ebe2; }
.gen8 { --w: 100px; --fs: 17px; --gen: #24522a; --card-top: #f9f6f0; --card-bot: #f5f1ea; }
.gen9 { --w: 100px; --fs: 17px; --gen: #24522a; --card-top: #fcfaf6; --card-bot: #f9f7f2; }
.gen10, .gen11, .gen12 {
  --w: 100px; --fs: 17px; --gen: #24522a;
  --card-top: #ffffff; --card-bot: #fdfcfb;
}

.node:hover { --s: 1.08; z-index: 6; box-shadow:
  inset 0 0 0 2px #f7ecd4, inset 0 0 0 3.5px rgba(201, 162, 39, 0.6), 0 7px 16px rgba(62, 42, 20, 0.38); }
.node.sel { --s: 1.12; z-index: 7; border-color: var(--gold); box-shadow:
  inset 0 0 0 2px #fbf3df, inset 0 0 0 3.5px rgba(201, 162, 39, 0.75), 0 0 0 3.5px rgba(201, 162, 39, 0.4), 0 8px 18px rgba(62, 42, 20, 0.4); }
.node.hot { border-color: var(--gold-soft); z-index: 5; }
.node.dragging {
  --s: 1.06;
  z-index: 10;
  cursor: grabbing;
  transition: none;
  box-shadow:
    inset 0 0 0 2px #fbf3df,
    inset 0 0 0 3.5px rgba(201, 162, 39, 0.75),
    0 10px 22px rgba(62, 42, 20, 0.42);
}
body.card-dragging { cursor: grabbing; user-select: none; }
body.card-dragging .node { pointer-events: none; }
body.card-dragging .node.dragging { pointer-events: auto; }
body.card-dragging .node:hover { --s: 1; }
body.card-dragging .node.dragging:hover { --s: 1.06; }
#stage.dim .node.dragging { opacity: 1; }

#stage.dim .node:not(.sel):not(.hot):not(.dragging) { opacity: 0.26; }
#stage.dim .edge:not(.hot) { opacity: 0.14; }
.edge { transition: opacity 0.25s; }

body.pdf-capturing .node {
  box-shadow: none !important;
  filter: none !important;
  text-shadow: none !important;
}
body.pdf-capturing #viewport::after { display: none !important; }

/* إطار بيانات الشجرة الحي فوق التربة تحت الجذع */
.treePlaque {
  position: absolute;
  z-index: 2;
  width: 560px;
  height: 128px;
  pointer-events: none;
  color: #6e4a17;
  background: #f7ecd4;
  border: 2.6px solid #8f6238;
  border-radius: 16px;
  box-shadow:
    0 4px 14px rgba(62, 42, 20, 0.28),
    inset 0 0 0 7px #f7ecd4,
    inset 0 0 0 8.6px #c9a227,
    inset 0 0 0 13px #f7ecd4,
    inset 0 0 0 13.9px rgba(185, 155, 95, 0.8);
}
.treePlaqueGem {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #c9a227;
  border: 1px solid #8a6520;
  transform: rotate(45deg);
  z-index: 2;
  pointer-events: none;
}
.treePlaqueGem.g-tl { top: 12px; left: 12px; }
.treePlaqueGem.g-tr { top: 12px; right: 12px; }
.treePlaqueGem.g-bl { bottom: 12px; left: 12px; }
.treePlaqueGem.g-br { bottom: 12px; right: 12px; }
.treePlaqueGem.g-tm { top: 2px; left: 50%; margin-left: -5px; }
.treePlaqueGem.g-bm { bottom: 2px; left: 50%; margin-left: -5px; }
.treePlaqueBody {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 36px 12px;
  text-align: center;
}
.treePlaqueTitle {
  font-family: 'Aref Ruqaa', serif;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
  color: #6e4a17;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.treePlaqueOrn {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #c9a227;
  font-size: 11px;
  line-height: 1;
}
.treePlaqueOrn::before,
.treePlaqueOrn::after {
  content: '';
  width: 72px;
  height: 1px;
  background: linear-gradient(90deg, transparent, #c9a227, transparent);
}
.treePlaqueStats {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-top: 2px;
}
.treePlaqueStat {
  min-width: 92px;
  padding: 0 22px;
  text-align: center;
}
.treePlaqueStat b {
  display: block;
  font-family: 'Aref Ruqaa', serif;
  font-size: 24px;
  color: #8a5a2b;
  line-height: 1;
}
.treePlaqueStat span {
  display: block;
  font-family: 'Amiri', serif;
  font-size: 13px;
  color: #8a6a45;
  letter-spacing: 0.6px;
  margin-top: 2px;
}
.treePlaqueEdit {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  z-index: 3;
  pointer-events: auto;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #6e4a17;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1.3px solid #c2a468;
  background: linear-gradient(#f7ecd4, #ecdab4);
  cursor: pointer;
}
.treePlaqueEdit:hover { border-color: var(--gold); background: #f3e3ba; }
body.pdf-capturing #treePlaque { display: none !important; }

/* لوحة المعلومات */
#panel {
  position: absolute;
  top: 14px;
  inset-inline-start: 14px;
  width: 302px;
  max-height: calc(100% - 110px);
  overflow-y: auto;
  background: linear-gradient(#fbf3df, #f3e5c4);
  border: 1.6px solid #b99b5f;
  border-radius: 26px 26px 14px 14px;
  box-shadow: 0 14px 34px rgba(62, 42, 20, 0.35);
  padding: 0 14px 14px;
  z-index: 30;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#panel.open { opacity: 1; transform: translateY(0); pointer-events: auto; }
#pClose {
  position: absolute; top: 8px; inset-inline-end: 10px;
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid #b99b5f; background: #f7ecd4; color: #8a6a45;
  font-size: 12px; cursor: pointer; z-index: 2;
}
#pClose:hover { border-color: var(--terracotta); color: var(--terracotta); }
.pArch {
  text-align: center; padding: 18px 10px 12px; margin: 0 -14px 12px;
  background: linear-gradient(rgba(201, 162, 39, 0.16), rgba(201, 162, 39, 0));
  border-bottom: 1.5px solid rgba(185, 155, 95, 0.5); border-radius: 24px 24px 0 0;
}
.pName { font-family: 'Aref Ruqaa', serif; font-size: 27px; font-weight: 700; color: #6e4a17; }
.pLineage { font-size: 13.5px; color: #8a6a45; margin-top: 4px; line-height: 1.7; }
.pGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.pItem {
  background: rgba(255, 251, 240, 0.75); border: 1px solid rgba(185, 155, 95, 0.55);
  border-radius: 10px; padding: 6px 10px; display: flex; flex-direction: column; gap: 1px;
}
.pItem span { font-size: 12px; color: #a5854e; }
.pItem b { font-size: 15.5px; color: var(--terracotta); }
.pRel { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.relLabel { font-size: 12.5px; color: #a5854e; width: 100%; margin-top: 4px; }
.chip {
  font-family: inherit; font-size: 13.5px; padding: 4px 12px; border-radius: 999px;
  border: 1.3px solid #b99b5f; background: #fbf3df; color: #6e4a17; cursor: pointer; transition: all 0.15s;
}
.chip:hover { background: #eed9a8; border-color: var(--gold); }
.pHint { margin-top: 12px; font-size: 12px; color: #b39b6d; text-align: center; }
.pHintEdit { display: none; }
body.editing .pHintPublic { display: none; }
body.editing .pHintEdit { display: block; }

.pAdd { margin-top: 14px; padding-top: 12px; border-top: 1.4px dashed rgba(185, 155, 95, 0.65); display: none; }
body.editing #pAdd { display: block; }
body:not(.editing) .editorOnly { display: none !important; }
.pAddRow { display: flex; flex-wrap: wrap; gap: 6px; }
.pAddRow[hidden] { display: none !important; }
.pAddBtn, .pAddPrimary, .pAddGhost {
  font-family: inherit; cursor: pointer; transition: all 0.15s;
}
.pAddBtn {
  flex: 1 1 0; min-width: 0; width: auto;
  font-size: 13px; font-weight: 700; color: #6e4a17;
  padding: 8px 6px; border-radius: 999px;
  border: 1.4px solid #c2a468; background: linear-gradient(#f7ecd4, #ecdab4);
}
.pAddBtn:hover { border-color: var(--gold); background: #f3e3ba; }
.pAddBtn[hidden] { display: none !important; }
.pDelBtn { color: #8a3a22; border-color: #c48968; background: linear-gradient(#f6e0d0, #edd0bc); }
.pDelBtn:hover { border-color: var(--terracotta); background: #f0d0bc; }
.pAddWizard { display: flex; flex-direction: column; gap: 10px; }
.pAddWizard[hidden], .pAddWizard [hidden] { display: none !important; }
.pAddWizard label {
  display: block; font-size: 13.5px; color: #8a6a45; margin-bottom: 6px;
}
#pAddCount, #pEditName, .pAddNames input {
  font-family: inherit; font-size: 16px; color: var(--ink);
  width: 100%; padding: 8px 10px;
  background: rgba(255, 251, 240, 0.9);
  border: 1.3px solid rgba(185, 155, 95, 0.7);
  border-radius: 10px; outline: none;
}
#pAddCount:focus, #pEditName:focus, .pAddNames input:focus { border-color: var(--gold); }
.pAddNames { display: flex; flex-direction: column; gap: 7px; max-height: 220px; overflow-y: auto; }
.pAddNames label { margin: 0; font-size: 12.5px; color: #a5854e; }
.pAddNames label span { display: block; margin-bottom: 3px; }
.pAddActions { display: flex; gap: 8px; margin-top: 10px; }
.pAddPrimary {
  flex: 1; font-size: 14.5px; font-weight: 700; color: #3d2b1c;
  padding: 8px 12px; border-radius: 999px;
  border: 1.3px solid #b99b5f; background: linear-gradient(#d9b45c, #c9a227);
}
.pAddPrimary:hover { filter: brightness(1.05); }
.pAddGhost {
  flex: none; font-size: 14px; color: #8a6a45;
  padding: 8px 12px; border-radius: 999px;
  border: 1.3px solid transparent; background: transparent;
}
.pAddGhost:hover { background: rgba(201, 162, 39, 0.14); }

/* =====================================================
   الدوك السفلي العائم
   ===================================================== */
#dock {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(rgba(251, 243, 223, 0.92), rgba(240, 224, 188, 0.92));
  border: 1.5px solid rgba(185, 155, 95, 0.85);
  box-shadow: 0 12px 34px rgba(62, 42, 20, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  max-width: calc(100vw - 24px);
  transition: opacity 0.5s ease 0.45s, transform 0.6s cubic-bezier(0.2, 0.8, 0.3, 1) 0.45s;
}
body:not(.entered) #dock { opacity: 0; transform: translate(-50%, 170%); pointer-events: none; transition-delay: 0s; }

.searchBox { position: relative; display: flex; align-items: center; }
.dockIcon { color: #a5854e; font-size: 17px; margin-inline-end: 6px; line-height: 1; }
#search {
  font-family: inherit; font-size: 15px; color: var(--ink);
  width: 190px; padding: 7px 6px; background: transparent; border: none; outline: none;
}
#search::placeholder { color: #a5854e; }

.dockSep { width: 1px; height: 22px; background: rgba(185, 155, 95, 0.5); flex: none; }

.branchWrap { position: relative; }
.dockBtn {
  font-family: inherit; font-size: 14px; color: #6e4a17; cursor: pointer;
  padding: 7px 14px; border-radius: 999px;
  border: 1.4px solid #c2a468; background: linear-gradient(#f7ecd4, #ecdab4);
  display: inline-flex; align-items: center; gap: 6px; transition: all 0.16s;
}
.dockBtn:hover { border-color: var(--gold); transform: translateY(-1px); }
.dockBtn .caret { font-size: 10px; color: #a5854e; }
.dockBtn.ghost { padding: 7px 11px; background: transparent; border-color: transparent; color: var(--gold); font-size: 16px; }
.dockBtn.ghost:hover { background: rgba(201, 162, 39, 0.14); transform: none; }
.dockBtn.dirty {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.38);
}
.dockBtn.dirty::after {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--terracotta);
  box-shadow: 0 0 6px rgba(180, 88, 46, 0.7);
}

#toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  z-index: 80;
  padding: 8px 18px;
  border-radius: 999px;
  background: linear-gradient(#fbf3df, #f0dfb6);
  border: 1.4px solid #b99b5f;
  color: #6e4a17;
  font-family: 'Amiri', serif;
  font-size: 16px;
  box-shadow: 0 10px 24px rgba(62, 42, 20, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.branchPop {
  position: absolute;
  bottom: calc(100% + 12px);
  inset-inline-start: 0;
  min-width: 168px;
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: #fbf3df;
  border: 1.5px solid #b99b5f;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(62, 42, 20, 0.32);
  z-index: 50;
}
.branchPop.open { display: flex; }
.branchPop::after { /* سهم صغير نحو الزر */
  content: ''; position: absolute; top: 100%; inset-inline-start: 22px;
  border: 7px solid transparent; border-top-color: #b99b5f;
}
.bchip {
  font-family: inherit; font-size: 14px; text-align: start;
  padding: 8px 12px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: #6e4a17; transition: all 0.15s;
}
.bchip:hover { background: #f3e5c4; }
.bchip.on { background: linear-gradient(#d9b45c, #c9a227); color: #3d2b1c; font-weight: 700; }

.zoomBtns { display: flex; gap: 4px; }
.zoomBtns button {
  font-family: inherit; width: 34px; height: 34px; font-size: 17px; line-height: 1;
  border-radius: 50%; border: 1.4px solid #c2a468;
  background: linear-gradient(#f7ecd4, #ead9b2); color: #6e4a17; cursor: pointer; transition: all 0.15s;
}
.zoomBtns button:hover { border-color: var(--gold); transform: translateY(-1px); background: #f3e3ba; }

.dockStat { font-size: 12.5px; color: #8a6a45; white-space: nowrap; padding-inline: 2px; }

/* قائمة نتائج البحث (تظهر فوق الدوك) */
.searchList {
  position: absolute;
  bottom: calc(100% + 12px);
  inset-inline-start: -8px;
  width: 280px;
  max-height: 320px;
  overflow-y: auto;
  background: #fbf3df;
  border: 1.5px solid #b99b5f;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(62, 42, 20, 0.32);
  overflow-x: hidden;
  display: none;
  z-index: 50;
}
.searchList.open { display: block; }
.srItem {
  display: block; width: 100%; text-align: start; font-family: inherit; font-size: 14px;
  padding: 8px 12px; background: none; border: none;
  border-bottom: 1px solid rgba(185, 155, 95, 0.35); cursor: pointer; color: var(--ink);
}
.srItem:last-child { border-bottom: none; }
.srItem strong { color: var(--terracotta); margin-inline-end: 6px; }
.srItem span { color: #8a6a45; font-size: 12.5px; }
.srItem:hover { background: #f3e5c4; }
.srItem.empty { cursor: default; color: #a5854e; text-align: center; }

/* =====================================================
   شاشات صغيرة
   ===================================================== */
@media (max-width: 820px) {
  .introGrid { grid-template-columns: 1fr; text-align: center; gap: 18px; }
  .kicker { justify-content: center; }
  .introDesc { margin-inline: auto; }
  .introActions { justify-content: center; }
  .loadWrap { justify-content: center; }
  .introScene { order: -1; }
  .frame { inset: -4px 24px 50px; }
  #panel { width: min(88vw, 300px); }
  #dock {
    gap: 6px;
    row-gap: 8px;
    padding: 8px 10px;
    flex-wrap: wrap;
    justify-content: center;
    border-radius: 20px;
    max-width: calc(100vw - 16px);
    bottom: 10px;
  }
  #search { width: 110px; }
  .dockStat { display: none; }
  .dockSep { display: none; }
  .dockBtn { padding: 6px 11px; font-size: 13px; }
}

#pdfBusy {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(62, 42, 20, 0.5);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  color: #fbf3df; font-family: 'Amiri', serif; font-size: 22px;
}
#pdfBusy .spin {
  width: 38px; height: 38px;
  border: 3px solid rgba(251, 243, 223, 0.28);
  border-top-color: #d4a93c; border-radius: 50%;
  animation: pdfSpin 0.8s linear infinite;
}
@keyframes pdfSpin { to { transform: rotate(360deg); } }

@media print {
  #intro, #dock, #panel, #pdfBusy, #loginScreen, #nameEditScreen, #saveBar { display: none !important; }
  #viewport { overflow: visible; }
  #viewport::after { display: none; }
  #stage { transform: none !important; }
}
