/* نافذة الترحيب — مقرأة تاج الوقار
   تستعمل خطوط الموقع وألوانه إن وُجدت، وإلا فقيمًا بديلة. */
html.tw-locked, html.tw-locked body { overflow: hidden; }
#gate { display: none !important; }            /* المقدمة القديمة تُستبدل بهذه النافذة */

#taj-welcome {
  --tw-bg: #fbf8f1;
  --tw-ink: #1f2a24;
  --tw-muted: #5b6660;
  --tw-gold: var(--gold, #b08a3e);
  --tw-green: #1e5a46;
  --tw-on-green: #ffffff;
  --tw-line: #e6dcc6;
  --tw-tile: #f4eee0;
  --tw-veil: rgba(16, 24, 20, .7);
  --tw-head: var(--ff-head, "Amiri", "Times New Roman", serif);
  --tw-text: var(--ff-body, system-ui, "Segoe UI", Tahoma, sans-serif);
  --tw-quran: var(--ff-quran, var(--ff-head, "Amiri Quran", "Amiri", serif));
  position: fixed; inset: 0; z-index: 2147483000;
  display: none; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
           max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--tw-veil);
  font-family: var(--tw-text);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
@media (prefers-color-scheme: dark) {
  #taj-welcome {
    --tw-bg: #17201c; --tw-ink: #f1ece0; --tw-muted: #b4bcb6;
    --tw-gold: var(--gold, #d4b26a); --tw-green: #2f7d62; --tw-line: #34413b;
    --tw-tile: #1e2924; --tw-veil: rgba(0, 0, 0, .78);
  }
}
#taj-welcome.is-open { display: flex; animation: tw-fade .3s ease-out; }
#taj-welcome[dir="ltr"] { text-align: left; }
@keyframes tw-fade { from { opacity: 0 } to { opacity: 1 } }

/* ---------- البطاقة ---------- */
#taj-welcome .tw-card {
  position: relative; box-sizing: border-box; width: 100%; max-width: 560px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - max(16px, env(safe-area-inset-top, 0px)) - max(16px, env(safe-area-inset-bottom, 0px)));
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--tw-bg); color: var(--tw-ink);
  border: 1px solid var(--tw-line); border-radius: 20px;
  padding: clamp(24px, 5vw, 36px) clamp(18px, 5vw, 32px) clamp(20px, 4vw, 28px);
  text-align: center;
  box-shadow: 0 28px 70px rgba(0, 0, 0, .32);
  transition: max-width .5s ease, padding .5s ease;
}
#taj-welcome .tw-card::before {
  content: ""; position: absolute; inset: 8px; border-radius: 13px;
  border: 1px solid var(--tw-gold); opacity: .35; pointer-events: none;
}
#taj-welcome .tw-close {
  position: absolute; top: 12px; inset-inline-end: 12px; width: 40px; height: 40px; z-index: 2;
  border: 0; border-radius: 50%; background: transparent; color: var(--tw-muted);
  font-size: 24px; line-height: 1; cursor: pointer;
}
#taj-welcome .tw-close:hover, #taj-welcome .tw-close:focus-visible { background: var(--tw-line); color: var(--tw-ink); outline: none; }
#taj-welcome[data-stage="crown"] .tw-close { opacity: 0; pointer-events: none; }

/* ---------- ظهور التاج كأيقونة (≤ ثانيتين، بلا صوت) ---------- */
#taj-welcome .tw-crownbox {
  display: flex; justify-content: center; align-items: center;
  height: 64px; margin: 0 auto 8px;
  transition: height .45s ease, margin .45s ease;
}
#taj-welcome .tw-crown {
  width: 72px; height: auto; max-height: 64px; color: var(--tw-gold);
  filter: drop-shadow(0 0 10px rgba(212, 178, 106, .55));
  transition: width .45s ease, max-height .45s ease;
}
#taj-welcome[data-stage="crown"] .tw-card { max-width: 260px; padding-block: 34px; }
#taj-welcome[data-stage="crown"] .tw-crownbox { height: 150px; margin: 0; }
#taj-welcome[data-stage="crown"] .tw-crown { width: 170px; max-height: 150px; animation: tw-crown 1.5s cubic-bezier(.2, .8, .2, 1) both; }
#taj-welcome[data-stage="crown"] .tw-body { display: none; }
@keyframes tw-crown {
  0%   { opacity: 0; transform: translateY(-34px) scale(.6); filter: drop-shadow(0 0 0 rgba(212,178,106,0)); }
  45%  { opacity: 1; transform: translateY(4px) scale(1.04); }
  65%  { transform: translateY(0) scale(1); filter: drop-shadow(0 0 26px rgba(212,178,106,.95)); }
  100% { opacity: 1; transform: none; filter: drop-shadow(0 0 10px rgba(212,178,106,.55)); }
}

/* ---------- النص ---------- */
#taj-welcome .tw-body { animation: tw-rise .5s ease-out both; }
@keyframes tw-rise { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }
#taj-welcome h2 {
  margin: 0 0 4px; font-family: var(--tw-head); font-weight: 700;
  font-size: clamp(23px, 5.6vw, 31px); line-height: 1.35; color: var(--tw-green); text-wrap: balance;
}
#taj-welcome .tw-sub { margin: 0 0 20px; font-size: clamp(13px, 3.4vw, 15px); color: var(--tw-muted); }
@media (prefers-color-scheme: dark) { #taj-welcome h2, #taj-welcome .tw-ayah { color: var(--tw-gold); } }

#taj-welcome [data-step] { display: none; }
#taj-welcome[data-stage="intro"] [data-step="intro"],
#taj-welcome[data-stage="reading"] [data-step="reading"],
#taj-welcome[data-stage="enter"] [data-step="reading"],
#taj-welcome[data-stage="enter"] [data-step="enter"] { display: block; }
#taj-welcome[data-stage="enter"] .tw-skip { display: none; }

#taj-welcome .tw-part { opacity: 0; transform: translateY(8px); transition: opacity 1.1s ease, transform 1.1s ease; }
#taj-welcome .tw-part.is-shown { opacity: 1; transform: none; }

#taj-welcome .tw-ayah {
  font-family: var(--tw-quran); font-size: clamp(21px, 5.4vw, 28px);
  line-height: 2.2; color: var(--tw-green); margin: 0; text-align: center;
}
#taj-welcome .tw-ayah .tw-num {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  width: 1.45em; height: 1.45em; margin-inline: .15em; border: 1.5px solid var(--tw-gold); border-radius: 50%;
  font-family: var(--tw-head); font-size: .55em; line-height: 1; color: var(--tw-gold);
}
#taj-welcome .tw-verse { font-family: var(--tw-head); font-size: clamp(18px, 4.7vw, 23px); line-height: 2; margin: 0; text-align: center; }
#taj-welcome .tw-verse span { display: block; }
#taj-welcome .tw-hadith { font-family: var(--tw-head); font-size: clamp(16px, 4.2vw, 19px); line-height: 1.95; margin: 0; text-align: center; }
#taj-welcome .tw-mean {
  margin: 4px auto 0; max-width: 46ch; font-size: clamp(13px, 3.3vw, 14.5px);
  line-height: 1.65; color: var(--tw-ink); opacity: .85; font-style: italic; text-align: center;
}
#taj-welcome .tw-src { font-size: 12.5px; color: var(--tw-muted); margin: 4px 0 14px; text-align: center; }

#taj-welcome .tw-sep { display: flex; align-items: center; gap: 10px; margin: 0 auto 12px; max-width: 220px; color: var(--tw-gold); }
#taj-welcome .tw-sep::before, #taj-welcome .tw-sep::after { content: ""; flex: 1; height: 1px; background: var(--tw-line); }

/* ---------- الأزرار ---------- */
#taj-welcome .tw-btn {
  display: block; width: 100%; border: 0; cursor: pointer;
  background: var(--tw-green); color: var(--tw-on-green);
  border-radius: 12px; padding: 14px 18px; min-height: 48px;
  font: inherit; font-size: 16px; font-weight: 600;
}
#taj-welcome .tw-btn:hover { filter: brightness(1.08); }
#taj-welcome button:focus-visible, #taj-welcome a:focus-visible { outline: 3px solid var(--tw-gold); outline-offset: 2px; }
#taj-welcome .tw-link {
  display: inline-block; margin-top: 12px; padding: 6px 4px; background: none; border: 0;
  color: var(--tw-muted); font: inherit; font-size: 14px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 4px;
}
#taj-welcome .tw-link:hover { color: var(--tw-ink); }

#taj-welcome .tw-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 10px; margin: 0 0 8px; font-size: 13px; color: var(--tw-muted); }
#taj-welcome .tw-mini {
  border: 1px solid var(--tw-line); background: transparent; color: var(--tw-muted);
  border-radius: 999px; padding: 5px 12px; min-height: 32px; font: inherit; font-size: 12.5px; cursor: pointer;
}
#taj-welcome .tw-mini:hover { color: var(--tw-ink); border-color: var(--tw-gold); }
#taj-welcome .tw-wave { display: inline-flex; gap: 3px; align-items: flex-end; height: 14px; }
#taj-welcome .tw-wave i { width: 3px; background: var(--tw-gold); border-radius: 2px; animation: tw-wave 1.1s ease-in-out infinite; }
#taj-welcome .tw-wave i:nth-child(2) { animation-delay: .2s }
#taj-welcome .tw-wave i:nth-child(3) { animation-delay: .4s }
@keyframes tw-wave { 0%, 100% { height: 4px } 50% { height: 14px } }
#taj-welcome.is-quiet .tw-wave i { animation: none; height: 4px; }

#taj-welcome .tw-roles { display: grid; gap: 10px; margin-top: 4px; }
#taj-welcome .tw-role {
  display: flex; align-items: center; gap: 14px; width: 100%; min-width: 0; min-height: 64px; box-sizing: border-box;
  background: var(--tw-tile); color: var(--tw-ink); border: 1px solid var(--tw-line);
  border-radius: 14px; padding: 12px 16px; text-decoration: none; text-align: start;
  transition: border-color .2s, transform .2s;
}
#taj-welcome .tw-role:hover { border-color: var(--tw-gold); transform: translateY(-1px); }
#taj-welcome .tw-role svg { flex: none; width: 30px; height: 30px; color: var(--tw-green); }
@media (prefers-color-scheme: dark) { #taj-welcome .tw-role svg { color: var(--tw-gold); } }
#taj-welcome .tw-role span { min-width: 0; }
#taj-welcome .tw-role b { display: block; font-size: 15.5px; line-height: 1.4; }
#taj-welcome .tw-role small { display: block; font-size: 12.5px; color: var(--tw-muted); line-height: 1.55; }
#taj-welcome .tw-credit { font-size: 11px; color: var(--tw-muted); margin: 12px 0 0; opacity: .9; text-align: center; }

/* ---------- القياسات ---------- */
/* لوحي وحاسوب: الأدوار الثلاثة في صف واحد عند اتساع المكان */
@media (min-width: 760px) {
  #taj-welcome[data-stage="enter"] .tw-card { max-width: 760px; }
  #taj-welcome[data-stage="enter"] .tw-roles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #taj-welcome[data-stage="enter"] .tw-role { flex-direction: column; text-align: center; justify-content: flex-start; padding: 18px 14px; }
}
/* شاشات قصيرة (جوال بالعرض، حاسوب صغير) */
@media (max-height: 620px) {
  #taj-welcome .tw-card { padding-block: 18px 16px; }
  #taj-welcome .tw-crownbox { height: 44px; margin-bottom: 2px; }
  #taj-welcome .tw-crown { width: 52px; max-height: 44px; }
  #taj-welcome .tw-sub { margin-bottom: 10px; }
  #taj-welcome .tw-ayah { line-height: 1.9; }
  #taj-welcome .tw-src { margin-bottom: 8px; }
}
@media (max-width: 380px) {
  #taj-welcome .tw-role { padding: 10px 12px; gap: 10px; }
  #taj-welcome .tw-role svg { width: 26px; height: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  #taj-welcome.is-open, #taj-welcome .tw-body, #taj-welcome .tw-crown { animation: none !important; }
  #taj-welcome .tw-part, #taj-welcome .tw-card, #taj-welcome .tw-crownbox, #taj-welcome .tw-crown { transition: none; }
  #taj-welcome .tw-wave i { animation: none; }
}
