/* «بين السطور» — الروح المشتركة (الكتلة أ): الخط، وشريط التنقل، ومكونات البطاقات والأسئلة.
 * ثيم كل محطة في themes/<المعرف>.css (الكتلة ت) محصور في [data-station="<المعرف>"] ويعرف المتغيرات الست:
 * --bg --ink --accent --accent-2 --card --pattern. وهذه قيمها الافتراضية حتى يسلم الثيم. */
:root {
  --bg: #f6f1e7;
  --ink: #2b2520;
  --accent: #8a5a2b;
  --accent-2: #2f6f6a;
  --card: #fffdf8;
  --pattern: none;
  --ok: #2e7d4f;
  --no: #b3402e;
  --line: rgba(43, 37, 32, .16);
  --radius: 14px;
  --font-text: "Noto Naskh Arabic", "Traditional Arabic", serif;
  --font-head: "El Messiri", "Noto Naskh Arabic", sans-serif;
  --bar-h: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font-text); font-size: 19px; line-height: 1.9;
  overflow-x: hidden; overscroll-behavior-y: contain; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
bdi[dir="ltr"] { unicode-bidi: isolate; direction: ltr; }

/* ------------------------------------------------------------------ الهيكل */
.b-app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.b-bar {
  position: sticky; top: 0; z-index: 20; height: var(--bar-h); display: flex; align-items: center; gap: 8px;
  padding: 0 10px; background: rgba(255, 253, 248, .94); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.b-bar-title { flex: 1; min-width: 0; text-align: center; font-family: var(--font-head); font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-ico { display: inline-block; height: 28px; width: auto; max-width: 40px; object-fit: contain; vertical-align: middle; margin-inline-end: 6px; flex: none; }
.b-ico.is-temp { height: auto; }
.b-story-src { margin: 0 auto 8px; max-width: 760px; text-align: center; font-size: 15px; opacity: .75; }
.b-nav { min-width: 44px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); cursor: pointer; touch-action: manipulation; white-space: nowrap; }
.b-nav:disabled { opacity: .35; cursor: default; }
.b-nav.is-ready { background: var(--accent); color: #fff; border-color: transparent; animation: b-pulse 1.4s ease-in-out infinite; }
.b-menu-btn, .b-who { height: 40px; min-width: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; }
.b-stage { flex: 1; position: relative; width: 100%; max-width: 920px; margin: 0 auto; padding: 18px 14px 120px; }
.b-station { position: relative; }
[data-station] { background-image: var(--pattern); }

/* شريط الفكرة الجامعة (رسم مؤقت؛ الكتلة ت تبدله بأصولها) */
.b-road { position: sticky; top: var(--bar-h); z-index: 19; height: 30px; padding: 4px 18px; background: rgba(255, 253, 248, .9); border-bottom: 1px solid var(--line); }
.b-lane { position: relative; height: 100%; display: flex; gap: 4px; align-items: center; background: linear-gradient(transparent 46%, var(--line) 46%, var(--line) 54%, transparent 54%); }
.b-seg { flex: 1; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, .06); }
.b-seg.is-done { background: var(--accent); }
.b-cart { position: absolute; top: 0; width: 28px; height: 20px; border-radius: 4px 4px 8px 8px; background: var(--accent-2); color: #fff; font-size: 9px; line-height: 20px; text-align: center; transition: inset-inline-start .6s ease; }
.b-stones { position: absolute; inset-inline-end: 0; top: 2px; font-size: 11px; color: var(--accent); letter-spacing: 1px; }
.b-pass { display: flex; gap: 10px; justify-content: center; align-items: center; height: 100%; }
.b-stamp { width: 20px; height: 20px; border-radius: 50%; border: 2px dashed var(--line); }
.b-stamp.is-done { border: 2px solid var(--accent); background: radial-gradient(circle, var(--accent) 0 35%, transparent 36%); }
.b-stamp.is-here { box-shadow: 0 0 0 3px rgba(47, 111, 106, .25); }

/* قائمة المحطات */
.b-menu { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35); display: flex; justify-content: flex-start; }
.b-menu-panel { width: min(360px, 88vw); height: 100%; overflow-y: auto; background: var(--card); padding: 16px; box-shadow: 0 0 30px rgba(0, 0, 0, .2); }
.b-menu h2 { font-family: var(--font-head); margin: 0 0 10px; font-size: 20px; }
.b-menu ol { list-style: none; margin: 0; padding: 0; }
.b-menu li a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; color: inherit; text-decoration: none; }
.b-menu li a[aria-current="page"] { background: var(--bg); font-weight: 700; }
.b-menu li a.is-done::after { content: "✓"; margin-inline-start: auto; color: var(--ok); }
.b-menu-foot { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 16px; }

/* ------------------------------------------------------------------ البطاقات والأسئلة */
.b-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px; box-shadow: 0 2px 10px rgba(0, 0, 0, .05); margin: 0 0 16px; }
.b-card h2, .b-card h3 { font-family: var(--font-head); margin: 0 0 8px; }
.b-q { font-size: 21px; font-weight: 600; margin: 0 0 14px; }
.b-opts { display: grid; gap: 10px; }
.b-opt {
  display: block; width: 100%; text-align: start; padding: 12px 14px; min-height: 48px; border: 2px solid var(--line); border-radius: 12px;
  background: #fff; cursor: pointer; line-height: 1.7; touch-action: manipulation; transition: border-color .15s, background .15s;
}
.b-opt:hover:not(:disabled) { border-color: var(--accent); }
.b-opt:focus-visible, .b-btn:focus-visible, .b-tok:focus-visible, .b-nav:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.b-opt.is-sel { border-color: var(--accent-2); background: rgba(47, 111, 106, .08); }
.b-opt.is-right { border-color: var(--ok); background: rgba(46, 125, 79, .1); }
.b-opt.is-wrong { border-color: var(--no); background: rgba(179, 64, 46, .08); opacity: .7; }
.b-opt.is-picked { box-shadow: 0 0 0 3px rgba(47, 111, 106, .25); }
.b-opt:disabled { cursor: default; }
.b-chip { width: auto; display: inline-block; }
.b-clue { margin: 12px 0 0; padding: 10px 12px; border-inline-start: 4px solid var(--accent); background: rgba(138, 90, 43, .08); border-radius: 8px; }
.b-model { margin: 14px 0 0; padding: 12px 14px; border-radius: 10px; background: rgba(47, 111, 106, .09); border: 1px dashed var(--accent-2); }
.b-frame { margin: 0 0 8px; color: var(--accent); font-weight: 600; }
.b-write { width: 100%; min-height: 120px; padding: 12px; border: 2px solid var(--line); border-radius: 12px; font: inherit; line-height: 1.9; background: #fff; resize: vertical; }
.b-write:focus { outline: none; border-color: var(--accent-2); }
.b-check { list-style: none; padding: 0; margin: 12px 0 0; }
.b-check li { padding: 6px 0; }
.b-check input { width: 20px; height: 20px; vertical-align: middle; }
.b-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.b-btn { padding: 10px 18px; min-height: 46px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; cursor: pointer; touch-action: manipulation; font-weight: 600; }
.b-btn:disabled { opacity: .4; cursor: default; }
.b-btn.is-ghost { background: transparent; color: var(--accent); border: 2px solid var(--accent); }

/* وصل وفرز وترتيب */
.b-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.b-col { display: grid; gap: 10px; align-content: start; }
.b-col .b-chip { width: 100%; }
.b-opt[data-n]::before { content: attr(data-n); display: inline-grid; place-items: center; width: 24px; height: 24px; margin-inline-end: 8px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 14px; }
.b-pool { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.b-bins { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.b-bin { border: 2px dashed var(--line); border-radius: 14px; padding: 8px; min-height: 110px; }
.b-bin-head { width: 100%; padding: 8px; border: 0; border-radius: 10px; background: var(--bg); font-family: var(--font-head); cursor: pointer; }
.b-bin-body { display: grid; gap: 8px; margin-top: 8px; }
.b-slots { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 8px; counter-reset: slot; }
.b-slot { counter-increment: slot; display: flex; align-items: center; gap: 8px; min-height: 50px; border: 2px dashed var(--line); border-radius: 12px; padding: 4px 8px; }
.b-slot::before { content: counter(slot); font-weight: 700; color: var(--accent); min-width: 1.2em; }
.b-slot.is-wrong { border-color: var(--no); }
.b-slot .b-chip { flex: 1; }
.is-shake { animation: b-shake .35s; }

/* النقر في النص */
.b-tap-text { line-height: 2.3; margin: 0; }
.b-tok { display: inline; padding: 2px 2px; border: 0; background: none; border-radius: 6px; cursor: pointer; line-height: inherit; touch-action: manipulation; }
.b-tok:hover:not(:disabled) { background: rgba(138, 90, 43, .12); }
.b-tok.is-right { background: rgba(46, 125, 79, .2); color: var(--ok); }
.b-tok.is-wrong { background: rgba(179, 64, 46, .18); }

/* ------------------------------------------------------------------ التعليق والراوي */
.b-toast {
  position: fixed; inset-inline: 0; bottom: 92px; z-index: 50; width: max-content; max-width: 90vw; margin: 0 auto; padding: 10px 20px;
  border-radius: 999px; color: #fff; font-weight: 700; opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.b-toast.is-on { opacity: 1; transform: none; }
.b-toast.is-yes { background: var(--ok); }
.b-toast.is-no { background: var(--no); }
.b-narr { position: fixed; z-index: 30; inset-inline-start: 12px; bottom: 12px; display: flex; align-items: flex-end; gap: 8px; max-width: min(560px, calc(100vw - 24px)); opacity: 0; transform: translateY(12px); transition: opacity .25s, transform .25s; pointer-events: none; }
.b-narr.is-on { opacity: 1; transform: none; pointer-events: auto; }
.b-narr-img { width: 96px; height: 96px; object-fit: contain; flex: none; animation: b-breathe 3.2s ease-in-out infinite; }
.b-narr-bubble { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; box-shadow: 0 4px 16px rgba(0, 0, 0, .1); }
.b-narr-text { margin: 0; font-size: 18px; }
.b-narr-text:empty { display: none; }
.b-narr-bubble[hidden] { display: none; }

/* ------------------------------------------------------------------ مشغل القصة */
.b-story { position: relative; border-radius: var(--radius); overflow: hidden; background: #111; color: #fff; }
.b-story-video { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #111; }
.b-story-text { padding: 14px 16px; font-size: 20px; line-height: 2; background: rgba(0, 0, 0, .78); }
.b-story-note { margin: 0; padding: 6px 16px; font-size: 15px; opacity: .8; }
.b-story .b-actions { padding: 0 16px 14px; margin: 0; }
.b-story-play { position: absolute; inset: 0 0 auto 0; width: 100%; aspect-ratio: 16 / 9; margin: 0; border-radius: 0; background: rgba(0, 0, 0, .4); color: #fff; font-size: 22px; z-index: 1; }
.b-story-play[hidden] { display: none; }

/* ------------------------------------------------------------------ الدخول ورمز المتعلم
 * الاتجاه «المرافق بالفانوس» (غسان 2026-12-02): ورق دافئ وضوء فانوس، وبطاقة مستديرة بظل بني.
 * يعم بطاقة .b-gate أينما كانت: رمز المتعلم، و«حصة جديدة» في شاشة المعلم، ودخول السجل. والخلفية بـ :has فلا تبقى بعد مغادرة الشاشة. */
/* بلا fixed (يهمله Safari على iOS): التدرج لا يتكرر، ولون الصفحة تحته لون حافته فلا يظهر حد عند التمرير */
body:has(.b-home, .b-gate) { background: radial-gradient(ellipse 120% 70% at 50% 0%, #fff6e3 0, #f4e8d4 48%, #ead9bd 100%) no-repeat, #ead9bd; }
body:has(.b-home, .b-gate) .b-bar { background: rgba(255, 250, 240, .72); }
body:has(.b-home, .b-gate) .b-nav { visibility: hidden; }
.b-gate {
  position: relative; max-width: 470px; margin: 8vh auto 0; padding: 26px 22px 22px; text-align: center;
  border-radius: 22px; border-color: rgba(138, 90, 43, .2); box-shadow: 0 12px 30px rgba(110, 70, 20, .16);
  animation: b-rise .5s ease-out both;
}
.b-gate h2 { font-size: 26px; }
.b-gate .b-actions { justify-content: center; }
.b-gate .b-btn:not(.is-ghost) { min-width: 140px; }
.b-gate a { color: var(--accent); font-weight: 600; }
.b-gate input[type="text"], .b-gate input[type="password"] {
  width: 100%; padding: 12px; border: 2px solid rgba(138, 90, 43, .35); border-radius: 14px; background: #fff9ef; color: var(--ink);
  font-size: 22px; text-align: center; letter-spacing: .1em; direction: ltr;
}
.b-gate input[type="text"]:focus, .b-gate input[type="password"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(138, 90, 43, .15); }
.b-gate:has(.b-gate-narr) { margin-top: calc(8vh + 92px); padding-top: 34px; }
.b-gate-narr {
  position: absolute; top: -118px; inset-inline: 0; margin: 0 auto; width: 136px; height: 136px; object-fit: contain; pointer-events: none;
  filter: drop-shadow(0 8px 12px rgba(120, 80, 30, .22)); animation: b-float 4s ease-in-out infinite;
}
.b-gate .b-known { justify-content: center; }
/* لوحة المفاتيح مفتوحة على الهاتف (ارتفاع قصير): الراوي أصغر والبطاقة أعلى، فيبقى الحقل و«ادخل» ظاهرين */
@media (max-height: 620px) {
  .b-gate { margin-top: 3vh; }
  .b-gate:has(.b-gate-narr) { margin-top: calc(3vh + 58px); padding-top: 26px; }
  .b-gate-narr { width: 84px; height: 84px; top: -72px; }
  .b-gate h2 { font-size: 22px; }
  .b-gate .b-err { min-height: 0; }
}
.b-err { color: var(--no); min-height: 1.6em; margin: 6px 0 0; }
.b-muted { opacity: .75; font-size: 16px; }

@keyframes b-pulse { 50% { box-shadow: 0 0 0 6px rgba(138, 90, 43, .22); } }
@keyframes b-shake { 25% { transform: translateX(5px); } 75% { transform: translateX(-5px); } }
@keyframes b-breathe { 50% { transform: scale(1.03); } }
@keyframes b-float { 50% { transform: translateY(-6px); } }
@keyframes b-rise { from { opacity: 0; transform: translateY(14px); } }

@media (max-width: 520px) {
  body { font-size: 18px; }
  .b-q { font-size: 19px; }
  .b-cols { grid-template-columns: 1fr 1fr; gap: 8px; }
  .b-nav { padding: 0 10px; }
  .b-nav .b-nav-label { display: none; }
  .b-narr-img { width: 64px; height: 64px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ------------------------------------------------------------------ الصفحة الأولى والختام */
.b-home { text-align: center; padding-top: 3vh; }
.b-home-hero { display: flex; align-items: center; justify-content: center; gap: 18px; animation: b-rise .5s ease-out both; }
.b-home-narr { width: 190px; height: 190px; object-fit: contain; flex: none; filter: drop-shadow(0 10px 16px rgba(120, 80, 30, .25)); animation: b-float 4s ease-in-out infinite; }
.b-home-say {
  position: relative; max-width: 360px; padding: 12px 22px 10px; text-align: start; background: var(--card);
  border: 1px solid rgba(138, 90, 43, .22); border-radius: 20px; box-shadow: 0 8px 22px rgba(120, 80, 30, .12);
}
/* ذيل الفقاعة نحو الراوي: على الحاسوب جانبي، وعلى الهاتف إلى أعلى */
.b-home-say::after {
  content: ""; position: absolute; inset-inline-start: -9px; top: 50%; width: 16px; height: 16px; margin-top: -8px; background: var(--card);
  border-inline-start: 1px solid rgba(138, 90, 43, .22); border-bottom: 1px solid rgba(138, 90, 43, .22); transform: rotate(45deg);
}
.b-home-say .b-muted { margin: 0; }
.b-home-title { font-family: var(--font-head); font-size: clamp(38px, 8vw, 58px); line-height: 1.35; margin: 0; color: var(--accent); }
.b-home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-top: 26px; text-align: start; }
.b-home-card {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; color: inherit; text-decoration: none;
  border-radius: 20px; border-color: rgba(138, 90, 43, .18); box-shadow: 0 10px 26px rgba(110, 70, 20, .15);
  transition: transform .18s, box-shadow .18s; animation: b-rise .5s ease-out .12s both;
}
.b-home-card + .b-home-card { animation-delay: .22s; }
.b-home-card:hover { transform: translateY(-3px); box-shadow: 0 14px 32px rgba(110, 70, 20, .2); }
.b-home-card:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; }
.b-home-pic { display: block; width: 100%; height: 150px; object-fit: cover; object-position: center 62%; background: #efe4d2; }
.b-home-tx { display: flex; flex-direction: column; align-items: flex-start; flex: 1; padding: 14px 18px 18px; }
.b-home-tx h2 { font-size: 24px; margin: 0 0 2px; }
.b-home-tx p { margin: 0 0 12px; }
.b-home-go { margin-top: auto; padding: 7px 18px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; }
.b-home-card[data-track="abjad"] .b-home-go { background: #1F4E79; }
@media (max-width: 560px) {
  .b-home-hero { flex-direction: column; gap: 4px; }
  .b-home-narr { width: 150px; height: 150px; }
  .b-home-say { text-align: center; }
  .b-home-say::after { inset-inline-start: calc(50% - 8px); top: -9px; margin: 0; transform: rotate(135deg); }
  .b-home-pic { height: 140px; }
}
.b-known { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.b-known .b-muted { width: 100%; margin: 0; }
.b-end { text-align: center; }

/* «أستطيع أن» */
.b-scale-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.b-scale-row:last-of-type { border-bottom: 0; }
.b-scale-row p { margin: 0 0 8px; }
.b-scale-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.b-scale-opts .b-opt { width: auto; min-width: 96px; text-align: center; }

/* الانتقال بين المحطات (View Transitions): تلاش قصير، والشريط ثابت لا يتلاشى */
.b-bar { view-transition-name: b-bar; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .28s; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
