/* الكتاب الحي — الأوراق التجارية. هوية هادئة: مكتب أخضر، كتاب مفتوح بإطار بنفسجي، ورق كريمي، وحاشية بخط اليد. */
:root {
  --desk: #c7d5ca; --desk2: #b6c7ba; --frame: #4a3d6b; --frame2: #6a5a92;
  --paper: #fbf7ee; --paper2: #f3ecdb; --line: #e6dcc4; --ink: #2a2733; --muted: #7a7466;
  --hand: #2c4f93; --red: #b8433a; --ok: #2f7d55; --ok-soft: #e2f1e7; --bad: #b8433a; --bad-soft: #f8e3df; --warn: #a8781c; --warn-soft: #f8eed4;
  --gold: #b8892f; --blue: #3c6fb0; --violet: #7d55b5;
  --ui: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  --read: 'Noto Naskh Arabic', 'Traditional Arabic', serif;
  --title: 'Amiri', 'Noto Naskh Arabic', serif;
  --hw: 'Aref Ruqaa', 'Amiri', serif;
  --fs: 17px;
}
[data-theme="dark"] {
  --desk: #1d2522; --desk2: #18201d; --frame: #3a3156; --frame2: #54487a;
  --paper: #23211d; --paper2: #2b2823; --line: #3b362c; --ink: #ece6d8; --muted: #a59d8b;
  --hand: #8fb2ee; --ok-soft: #1d3326; --bad-soft: #3a2220; --warn-soft: #3a301c;
}
* { box-sizing: border-box; }
html { font-size: var(--fs); }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 50% 20%, color-mix(in srgb, var(--desk) 80%, white), var(--desk) 55%, var(--desk2)); color: var(--ink); font-family: var(--read); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; right: -999px; } .skip:focus { right: 10px; top: 10px; z-index: 99; background: var(--paper); padding: 6px; }

/* ── الشريط العلوي: لافتة صغيرة كما في الكتاب المرجعي */
.crown { display: flex; justify-content: center; padding: 14px 12px 6px; }
.crown-pill { font-family: var(--ui); font-size: .82rem; background: color-mix(in srgb, var(--paper) 88%, transparent); border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px; color: var(--muted); box-shadow: 0 2px 10px rgba(0,0,0,.06); display: flex; gap: 10px; align-items: center; }
.crown-pill b { color: var(--ink); font-weight: 600; } .crown-pill a { color: var(--muted); text-decoration: none; border-inline-start: 1px solid var(--line); padding-inline-start: 10px; }
.crown-pill a:hover { color: var(--ink); }

/* ── الكتاب المفتوح */
.book-wrap { padding: 4px 18px 96px; perspective: 2400px; }
.book { position: relative; max-width: 1480px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; background: var(--frame); border-radius: 16px; padding: 10px; box-shadow: 0 30px 60px -20px rgba(30, 30, 50, .45), 0 6px 18px rgba(0,0,0,.12); height: calc(100vh - 150px); min-height: 560px; }
.page { position: relative; background: var(--paper); overflow: hidden; display: flex; flex-direction: column; }
.page.text { border-radius: 0 8px 8px 0; box-shadow: inset 18px 0 22px -18px rgba(0,0,0,.25); }
.page.lab { border-radius: 8px 0 0 8px; box-shadow: inset -18px 0 22px -18px rgba(0,0,0,.25); }
.page-in { flex: 1; overflow: auto; padding: 30px 40px 26px; scrollbar-width: thin; scroll-behavior: smooth; }
.page.lab .page-in { padding: 22px 26px 18px; display: flex; flex-direction: column; gap: 10px; }
.run-head { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--ui); font-size: .74rem; color: var(--muted); margin-bottom: 10px; letter-spacing: .2px; }
.src-pill { font-family: var(--ui); font-size: .76rem; color: var(--muted); background: none; border: 1px dashed var(--line); border-radius: 999px; padding: 2px 10px; cursor: pointer; }
.src-pill:hover { color: var(--ink); border-color: var(--muted); }

/* ── صفحة النص */
.kicker { font-family: var(--ui); font-size: .78rem; color: var(--violet); font-weight: 600; margin: 0 0 4px; }
.page h1 { font-family: var(--title); font-weight: 700; font-size: 2.05rem; line-height: 1.35; margin: 0 0 14px; color: var(--ink); }
.page h2 { font-family: var(--title); font-size: 1.25rem; margin: 18px 0 6px; }
.tx { display: grid; grid-template-columns: 1fr 150px; gap: 0 18px; }
.tx-main > p { line-height: 2; margin: 0 0 12px; font-size: 1.02rem; }
.tx-margin { position: relative; }
.mnote { font-family: var(--hw); color: var(--hand); font-size: 1.02rem; line-height: 1.55; transform: rotate(-2deg); margin: 6px 0 22px; padding: 2px 2px 2px 0; border-inline-start: 2px solid color-mix(in srgb, var(--hand) 35%, transparent); padding-inline-start: 8px; opacity: 0; animation: ink .9s ease forwards; }
.mnote:nth-child(2) { animation-delay: .35s; transform: rotate(1.5deg); } .mnote:nth-child(3) { animation-delay: .7s; }
.mnote.red { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
@keyframes ink { from { opacity: 0; clip-path: inset(0 0 0 100%); } to { opacity: 1; clip-path: inset(0 0 0 0); } }
/* النص الأصلي: مميز دائماً، بمرجع صفحته */
.orig { position: relative; margin: 10px 0 16px; padding: 12px 16px 10px; background: var(--paper2); border-inline-start: 4px solid #8a6d3b; border-radius: 4px 0 0 4px; font-family: var(--read); line-height: 2.05; font-size: .98rem; }
.orig::before { content: 'نص الملزمة'; display: inline-block; font-family: var(--ui); font-size: .68rem; font-weight: 600; color: #8a6d3b; background: color-mix(in srgb, #8a6d3b 14%, transparent); padding: 1px 8px; border-radius: 999px; margin-inline-end: 6px; }
.orig q { quotes: '«' '»'; } .orig q::before, .orig q::after { color: #8a6d3b; font-weight: 700; }
.orig .pg { font-family: var(--ui); font-size: .72rem; color: #8a6d3b; cursor: pointer; text-decoration: underline dotted; margin-inline-start: 6px; background: none; border: 0; padding: 0; }
/* الشرح المبسط: نص الكتاب العادي. المثال الافتراضي: إطار متقطع ووسم */
.ex { margin: 10px 0 16px; padding: 10px 14px; border: 1.5px dashed color-mix(in srgb, var(--violet) 55%, transparent); border-radius: 10px; line-height: 1.9; background: color-mix(in srgb, var(--violet) 5%, transparent); }
.ex::before { content: 'مثال افتراضي للتوضيح — ليس قضية حقيقية'; display: block; font-family: var(--ui); font-size: .7rem; color: var(--violet); font-weight: 600; margin-bottom: 2px; }
.defbox { margin: 10px 0 16px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--paper2) 60%, transparent); line-height: 1.95; }
.defbox b.term { font-family: var(--title); font-size: 1.08rem; color: var(--ink); }
.limit { margin: 10px 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); line-height: 1.85; font-size: .95rem; }
.limit::before { content: '⚠ حدود المصدر'; display: block; font-family: var(--ui); font-size: .72rem; font-weight: 700; color: var(--warn); }
.keys { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 14px; font-size: .92rem; line-height: 1.7; }
.keys span b { font-family: var(--title); }

/* ── توقّع قبل أن تجرّب + ارفع الورقة */
.predict { margin: 18px 0 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.predict h3 { font-family: var(--ui); font-size: .85rem; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
.predict .q { font-family: var(--title); font-size: 1.12rem; margin: 0 0 8px; line-height: 1.7; }
.popt { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; background: none; border: 0; padding: 5px 2px; cursor: pointer; line-height: 1.6; font-family: var(--read); font-size: 1rem; }
.popt .box { position: relative; flex: none; width: 18px; height: 18px; border: 1.6px solid var(--ink); border-radius: 3px; }
.popt.on .box::after { content: '✓'; position: absolute; inset: -6px 0 0 -2px; font-size: 20px; color: var(--hand); font-family: var(--hw); }
.popt .circle { position: absolute; inset: -9px -12px; pointer-events: none; }
.popt .circle path { fill: none; stroke: var(--hand); stroke-width: 2; stroke-dasharray: 160; stroke-dashoffset: 160; animation: draw .7s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.flap { position: relative; margin: 14px 0 6px; min-height: 92px; perspective: 900px; }
.flap-note { position: absolute; inset: 0; z-index: 2; background: #f6e7a8; color: #3b3320; border-radius: 4px; box-shadow: 0 6px 16px rgba(0,0,0,.16); display: grid; place-content: center; text-align: center; cursor: pointer; transform-origin: top; transition: transform .7s cubic-bezier(.4,0,.2,1), opacity .7s; border: 0; width: 100%; font-family: var(--title); font-size: 1.15rem; }
[data-theme="dark"] .flap-note { background: #5b5232; color: #f3ead0; }
.flap-note small { font-family: var(--ui); font-size: .72rem; opacity: .75; display: block; margin-top: 2px; }
.flap-note::after { content: 'ارفعها'; position: absolute; bottom: -1px; left: 14px; font-family: var(--hw); font-size: .8rem; opacity: .6; }
.flap.locked .flap-note { cursor: not-allowed; } .flap.shake .flap-note { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(5px); } 75% { transform: translateX(-5px); } }
.flap.open .flap-note { transform: rotateX(82deg) translateY(-40px); opacity: 0; pointer-events: none; }
.flap-body { padding: 12px 14px; border-radius: 6px; background: var(--ok-soft); line-height: 1.95; }
.flap-body .verdict { font-family: var(--hw); color: var(--hand); font-size: 1.1rem; }

/* ── صفحة المختبر */
.lab-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-family: var(--ui); }
.lab-tag { font-size: .72rem; letter-spacing: .5px; color: var(--muted); }
.lab-reset { font-family: var(--ui); font-size: .78rem; border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 3px 12px; cursor: pointer; color: var(--muted); }
.lab-reset:hover { color: var(--ink); }
.stage { position: relative; width: 100%; aspect-ratio: 16 / 9.6; min-height: 250px; border-radius: 10px; overflow: hidden; background: linear-gradient(to bottom, color-mix(in srgb, var(--paper) 92%, #dfe8f2) 0 72%, color-mix(in srgb, var(--paper2) 90%, #c9b99a) 72% 100%); border: 1px solid var(--line); touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.stage:has(.sheet) { aspect-ratio: 4 / 3.3; }
.stage.map { background: radial-gradient(circle at 75% 45%, #e9e1c8 0 16%, transparent 17%), radial-gradient(circle at 22% 50%, #e4ddc6 0 15%, transparent 16%), linear-gradient(#eef0e6, #e6e3d0); }
[data-theme="dark"] .stage.map { background: linear-gradient(#2a2d27, #23251f); }
.stage .floor { position: absolute; inset: 72% 0 0; border-top: 2px solid color-mix(in srgb, #8a6d3b 35%, transparent); pointer-events: none; }
.stage svg.links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.links path { fill: none; stroke: color-mix(in srgb, var(--ink) 30%, transparent); stroke-width: 2; }
.links path.on { stroke: var(--blue); stroke-width: 2.6; stroke-dasharray: 7 6; animation: flow 1s linear infinite; }
.links path.bad { stroke: var(--bad); stroke-dasharray: 4 5; } .links path.ok { stroke: var(--ok); }
.links text { font-family: var(--ui); font-size: 11.5px; fill: var(--muted); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; text-anchor: middle; }
.links text.on { fill: var(--blue); font-weight: 700; }
@keyframes flow { to { stroke-dashoffset: -26; } }
.ent { position: absolute; transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; transition: left .7s cubic-bezier(.4,0,.2,1), top .7s cubic-bezier(.4,0,.2,1), opacity .4s, filter .4s; z-index: 2; touch-action: none; }
.ent.dragging { transition: none; z-index: 9; filter: drop-shadow(0 10px 10px rgba(0,0,0,.25)); pointer-events: none; }
.ent.hidden { opacity: 0; pointer-events: none; }
.ent.dim { opacity: .35; filter: grayscale(1); }
.ent .fig { width: 64px; height: 100px; animation: idle 3.2s ease-in-out infinite; transform-origin: bottom; }
.ent:nth-child(2n) .fig { animation-delay: -1.4s; }
@keyframes idle { 50% { transform: translateY(-2px) scaleY(1.01); } }
.ent.small .fig { width: 46px; height: 72px; } .ent.mid .fig { width: 55px; height: 86px; }
.ent .plate { margin-top: 2px; text-align: center; line-height: 1.25; font-family: var(--ui); white-space: nowrap; }
.ent .plate b { display: block; font-size: .8rem; color: var(--ink); }
.ent .plate i { display: block; font-style: normal; font-size: .7rem; color: var(--muted); }
.ent .badge { margin-top: 3px; font-family: var(--ui); font-size: .68rem; padding: 1px 8px; border-radius: 999px; background: var(--paper2); color: var(--muted); white-space: nowrap; transition: background .4s, color .4s; }
.ent .badge.ok { background: var(--ok-soft); color: var(--ok); font-weight: 700; } .ent .badge.bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; } .ent .badge.warn { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.ent .badge:empty { display: none; }
.ent.can { cursor: grab; } .ent.picked .fig, .ent.picked .ptok, .ent.picked .bld { outline: 3px dashed var(--gold); outline-offset: 4px; border-radius: 8px; }
.ent.hot .fig, .ent.hot .bld, .ent.hot .ptok { filter: drop-shadow(0 0 8px var(--gold)); }
.ent.focus-ring:focus-visible { outline: none; } .ent:focus-visible .fig, .ent:focus-visible .ptok, .ent:focus-visible .bld { outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 8px; }
.bubble { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: #fff; color: #222; border: 1.5px solid #3a3a3a; border-radius: 12px; padding: 4px 10px; font-family: var(--read); font-size: .82rem; line-height: 1.5; width: max-content; max-width: 210px; text-align: center; animation: pop .3s ease; z-index: 3; }
.bubble::after { content: ''; position: absolute; top: 100%; left: 50%; border: 7px solid transparent; border-top-color: #3a3a3a; transform: translateX(-50%); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 6px) scale(.9); } }
.bld { width: 74px; height: 70px; } .ent .bld + .plate b { font-size: .78rem; }
/* الورقة الصغيرة القابلة للسحب */
.ptok { position: relative; min-width: 58px; max-width: 120px; padding: 6px 8px 5px; background: #fffdf6; color: #2a2733; border: 1px solid #cdbf98; border-radius: 3px; box-shadow: 0 3px 8px rgba(0,0,0,.15); font-family: var(--ui); font-size: .68rem; line-height: 1.35; text-align: center; background-image: repeating-linear-gradient(0deg, transparent 0 9px, #efe6cc 9px 10px); }
.ptok::after { content: ''; position: absolute; top: 0; left: 0; border-width: 0 0 10px 10px; border-style: solid; border-color: transparent transparent #e8dcb8 var(--paper); }
.ptok b { display: block; font-size: .74rem; }
.ptok .stamp { display: block; margin-top: 3px; font-weight: 700; font-size: .64rem; padding: 1px 4px; border: 1.5px solid currentColor; border-radius: 3px; transform: rotate(-4deg); }
.ptok .stamp.ok { color: var(--ok); } .ptok .stamp.bad { color: var(--bad); } .ptok .stamp.warn { color: var(--warn); }
.ptok .stamp:empty { display: none; }
.ent.paper { z-index: 5; } .ent.paper .plate { display: none; }
.ent.coin .ptok { background: #f3d77a; border-color: #b8892f; background-image: none; border-radius: 16px; min-width: 76px; } .ent.coin .ptok::after { display: none; }
/* ورقة كبيرة على المكتب (وثيقة قابلة للتحرير) */
.sheet { position: absolute; transform: translate(-50%, -50%); width: min(78%, 520px); background: #fffdf6; color: #2a2733; border: 1px solid #cdbf98; border-radius: 4px; box-shadow: 0 10px 24px rgba(0,0,0,.16); padding: 12px 16px; font-family: var(--read); font-size: .84rem; line-height: 1.75; background-image: repeating-linear-gradient(0deg, transparent 0 25px, #f0e7cf 25px 26px); z-index: 3; transition: transform .6s; }
.sheet.flipped { transform: translate(-50%, -50%) rotateY(180deg); }
.sheet h4 { margin: 0 0 4px; text-align: center; font-family: var(--title); font-size: 1.02rem; }
.sheet .row { display: flex; justify-content: space-between; gap: 8px; }
.slot { display: inline-block; min-width: 70px; min-height: 22px; padding: 0 6px; margin: 1px 2px; border-radius: 4px; transition: background .3s, outline-color .3s; vertical-align: middle; }
.slot.empty { outline: 1.5px dashed #bba873; color: #a99a72; font-family: var(--ui); font-size: .72rem; }
.slot.filled { background: color-mix(in srgb, var(--gold) 12%, transparent); }
.slot.gone { text-decoration: line-through; color: #b8433a88; background: none; }
.slot.can { cursor: grab; } .slot.hot { outline: 2px solid var(--gold); }
/* ورقة الموضوع المستمرة: البيان المعيب من صفحة سابقة يبقى مسطَّراً بالأحمر، والبيان الذي تعمل عليه الصفحة مضاء */
.slot.flaw { text-decoration: underline wavy #b8433a; text-underline-offset: 3px; }
.slot.hi, .sheet.bill .slot[data-drop] { outline: 2px solid color-mix(in srgb, var(--gold) 70%, transparent); background: color-mix(in srgb, var(--gold) 18%, transparent); }
.sheet.bill .slot.empty[data-drop] { outline-style: dashed; }
.carry { display: inline-block; font-family: var(--ui); font-size: .74rem; color: var(--violet); line-height: 1.6; }
.slot.picked { outline: 3px dashed var(--gold); }
.sheet .stampbig { position: absolute; top: 8px; left: 12px; font-family: var(--ui); font-weight: 800; font-size: .78rem; padding: 2px 8px; border: 2px solid currentColor; border-radius: 4px; transform: rotate(-8deg); animation: stamp .35s ease; }
.sheet .stampbig.ok { color: var(--ok); } .sheet .stampbig.bad { color: var(--bad); } .sheet .stampbig.warn { color: var(--warn); }
.sheet .stampbig:empty { display: none; }
@keyframes stamp { from { transform: rotate(-8deg) scale(1.8); opacity: 0; } }
.tray { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 6px; border: 1.5px dashed var(--line); border-radius: 10px; min-height: 40px; }
.tray:empty::before { content: 'فارغ'; color: var(--muted); font-family: var(--ui); font-size: .74rem; }
.tile { font-family: var(--read); font-size: .82rem; background: #fffdf6; color: #2a2733; border: 1px solid #cdbf98; border-radius: 6px; padding: 3px 9px; cursor: grab; box-shadow: 0 2px 5px rgba(0,0,0,.08); touch-action: none; }
.tile.picked { outline: 3px dashed var(--gold); } .tile.dragging { opacity: .5; pointer-events: none; }
.drag-ghost { position: fixed; z-index: 99; pointer-events: none; top: 0; left: 0; }
.bin { position: absolute; bottom: 8px; right: 10px; z-index: 4; font-family: var(--ui); font-size: .72rem; color: var(--muted); border: 1.5px dashed var(--line); border-radius: 10px; padding: 6px 10px; background: var(--paper); }
.bin.hot { border-color: var(--bad); color: var(--bad); }

/* ── ترتيب المختبر: المشهد، ثم الراوي (التعليل) والمؤشرات (النتيجة) تحته مباشرة، ثم أدوات التحكم */
#labBody { display: flex; flex-direction: column; gap: 9px; }
#labBody > .how { order: 0; } #labBody > .steps-dots { order: 1; } #labBody > .stage { order: 2; } #labBody > .timeline { order: 3; }
#labBody > .narr { order: 4; } #labBody > .gauges { order: 5; } #labBody > .tray { order: 6; } #labBody > .ctrl { order: 7; } #labBody > .limit { order: 8; }
/* وسوم نوع الكلام في المختبر وسؤال التوقع */
.fic-tag, .src-tag { display: inline-block; font-family: var(--ui); font-size: .66rem; font-weight: 600; padding: 0 8px; border-radius: 999px; white-space: nowrap; vertical-align: middle; line-height: 1.7; }
.fic-tag { color: var(--violet); border: 1.3px dashed color-mix(in srgb, var(--violet) 60%, transparent); background: color-mix(in srgb, var(--violet) 5%, transparent); }
.src-tag { color: #8a6d3b; background: color-mix(in srgb, #8a6d3b 14%, transparent); }
.run-head .tags { display: inline-flex; gap: 5px; flex-wrap: wrap; } .predict h3 .fic-tag, .predict h3 .src-tag { margin-inline-start: 6px; }
.thread { color: var(--ink); font-weight: 600; }
.resets { display: inline-flex; gap: 5px; }
.ent .plate b.fict { display: inline-block; border: 1.3px dashed color-mix(in srgb, var(--violet) 65%, transparent); border-radius: 6px; padding: 0 5px; }

/* ── تعليمات، لوحة التحكم، المؤشرات، الراوي */
.how { font-family: var(--ui); font-size: .8rem; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.ctrl { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-family: var(--ui); font-size: .8rem; }
.cgrp { display: flex; align-items: center; gap: 6px; }
.cgrp > span { color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; background: none; padding: 4px 11px; cursor: pointer; color: var(--muted); font-size: .78rem; }
.seg button[aria-pressed=true] { background: var(--ink); color: var(--paper); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); }
.stepper button { border: 0; background: none; width: 28px; height: 26px; cursor: pointer; font-size: 1rem; }
.stepper output { min-width: 64px; text-align: center; font-weight: 600; font-size: .82rem; }
.tog { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tog input { appearance: none; width: 34px; height: 19px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .2s; margin: 0; }
.tog input::after { content: ''; position: absolute; top: 2px; right: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; transition: right .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.tog input:checked { background: var(--ink); } .tog input:checked::after { right: 17px; }
.act { border: 0; background: var(--ink); color: var(--paper); border-radius: 999px; padding: 5px 14px; cursor: pointer; font-family: var(--ui); font-weight: 600; font-size: .8rem; }
.act.ghost { background: none; color: var(--ink); border: 1px solid var(--line); }
.act:disabled { opacity: .4; cursor: default; }
.gauges { display: flex; flex-wrap: wrap; gap: 8px; }
.gauge { flex: 1 1 150px; display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: color-mix(in srgb, var(--paper2) 50%, transparent); font-family: var(--ui); font-size: .76rem; line-height: 1.5; transition: background .4s; }
.gauge .lamp { flex: none; width: 12px; height: 12px; border-radius: 50%; margin-top: 3px; background: #bbb; box-shadow: inset 0 -2px 3px rgba(0,0,0,.2); transition: background .4s, box-shadow .4s; }
.gauge.ok .lamp { background: #3fa46a; box-shadow: 0 0 9px #3fa46a; } .gauge.bad .lamp { background: #d0533f; box-shadow: 0 0 9px #d0533f; } .gauge.warn .lamp { background: #d9a52c; box-shadow: 0 0 9px #d9a52c; }
.gauge b { display: block; color: var(--muted); font-weight: 600; } .gauge span { color: var(--ink); font-weight: 600; }
.narr { position: sticky; bottom: 0; z-index: 6; font-family: var(--read); line-height: 1.85; font-size: .93rem; padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--blue) 7%, var(--paper)); box-shadow: 0 -6px 12px -8px rgba(0,0,0,.18); border-inline-start: 3px solid var(--blue); min-height: 48px; }
.narr.ok { background: var(--ok-soft); border-color: var(--ok); } .narr.bad { background: var(--bad-soft); border-color: var(--bad); } .narr.warn { background: var(--warn-soft); border-color: var(--warn); }
/* المسرح المصغَّر ليتسع للنتيجة: كل ما فيه يتناسب مع --k */
.stage { --k: 1; }
.ent .fig { width: calc(64px * var(--k)); height: calc(100px * var(--k)); }
.ent.small .fig { width: calc(46px * var(--k)); height: calc(72px * var(--k)); } .ent.mid .fig { width: calc(55px * var(--k)); height: calc(86px * var(--k)); }
.stage .bld { width: calc(74px * var(--k)); height: calc(70px * var(--k)); }
.stage .ent .plate b { font-size: calc(.8rem * max(var(--k), .85)); } .stage .ent .plate i { font-size: calc(.7rem * max(var(--k), .85)); }
.stage .sheet { font-size: calc(.84rem * var(--k)); padding: calc(12px * var(--k)) calc(16px * var(--k)); background-size: 100% calc(26px * var(--k)); }
.stage .sheet h4 { font-size: calc(1.02rem * var(--k)); }
.stage .ptok { font-size: calc(.68rem * max(var(--k), .85)); } .stage .ptok b { font-size: calc(.74rem * max(var(--k), .85)); }
.narr .pref { font-family: var(--ui); font-size: .72rem; color: #8a6d3b; white-space: nowrap; }
.narr.pop { animation: rise .35s ease; } @keyframes rise { from { opacity: 0; transform: translateY(5px); } }
.fig-cap { font-family: var(--ui); font-size: .76rem; color: var(--muted); }
.fig-cap b { color: var(--ink); }
.steps-dots { display: flex; gap: 5px; align-items: center; font-family: var(--ui); font-size: .72rem; color: var(--muted); }
.steps-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background .3s; } .steps-dots i.on { background: var(--ok); }
.timeline { position: relative; height: 92px; margin: 4px 8px 0; }
.tl-axis { position: absolute; top: 46px; left: 0; right: 0; height: 2px; background: var(--muted); }
.tl-tick { position: absolute; top: 40px; width: 1px; height: 14px; background: var(--muted); font-family: var(--ui); font-size: .62rem; color: var(--muted); }
.tl-tick span { position: absolute; top: 16px; transform: translateX(-50%); white-space: nowrap; }
.tl-mark { position: absolute; top: 6px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; font-family: var(--ui); font-size: .68rem; transition: left .5s cubic-bezier(.4,0,.2,1); touch-action: none; }
.tl-mark .pin { width: 14px; height: 14px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); margin: 2px 0; }
.tl-mark b { white-space: nowrap; background: var(--paper); padding: 0 4px; border-radius: 4px; }
.tl-mark.drag { cursor: grab; } .tl-mark.drag .pin { outline: 2px dashed currentColor; outline-offset: 2px; }
.tl-mark.dragging { transition: none; }

/* ── شريط التنقل السفلي */
.dock { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-radius: 999px; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px); border: 1px solid var(--line); box-shadow: 0 8px 26px rgba(0,0,0,.16); font-family: var(--ui); max-width: calc(100vw - 20px); }
.dock button { border: 0; background: none; cursor: pointer; border-radius: 999px; padding: 6px 10px; color: var(--ink); font-size: .85rem; }
.dock button:hover { background: var(--paper2); }
.dock .where { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }
.dock .where small { color: var(--muted); margin-inline-start: 6px; }
.dock .sep { width: 1px; height: 18px; background: var(--line); }
.dock button:disabled { opacity: .35; }
.only-m { display: none; }

/* ── الفهرس، وعارض الأصل */
.drawer { position: fixed; inset: 0; z-index: 60; background: rgba(20, 20, 30, .35); display: flex; justify-content: center; align-items: center; padding: 16px; }
.drawer[hidden], .viewer[hidden] { display: none; }
.drawer-in { width: min(720px, 100%); max-height: 86vh; overflow: auto; background: var(--paper); border-radius: 14px; padding: 20px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.drawer-in h2 { font-family: var(--title); margin: 0 0 8px; }
.toc-part { margin: 12px 0 4px; font-family: var(--ui); font-size: .8rem; color: var(--violet); font-weight: 700; }
.toc a { display: flex; justify-content: space-between; gap: 10px; padding: 5px 8px; border-radius: 8px; color: var(--ink); text-decoration: none; line-height: 1.6; }
.toc a:hover { background: var(--paper2); } .toc a.cur { background: color-mix(in srgb, var(--violet) 12%, transparent); font-weight: 700; }
.toc a small { font-family: var(--ui); color: var(--muted); white-space: nowrap; }
/* الأصل بجانب الشرح: يغطي الصفحة المقابلة فقط، ويبقى الدرس ظاهراً */
.viewer { position: absolute; top: 10px; bottom: 10px; width: calc(50% - 10px); z-index: 25; display: flex; animation: fadein .25s ease; }
.viewer.over-lab { left: 10px; } .viewer.over-text { right: 10px; }
.viewer-in { flex: 1; display: flex; flex-direction: column; background: var(--paper2); border-radius: 8px; overflow: hidden; box-shadow: inset 0 0 0 2px #8a6d3b55; }
.viewer-bar { display: flex; align-items: center; gap: 6px; padding: 7px 10px; font-family: var(--ui); font-size: .8rem; border-bottom: 1px solid var(--line); background: var(--paper); color: #8a6d3b; font-weight: 600; }
.viewer-bar .act { padding: 3px 10px; font-size: .76rem; }
.viewer-bar .grow { flex: 1; }
.viewer-body { flex: 1; overflow: auto; background: #d9d4c8; padding: 8px; }
.viewer-body img { display: block; width: 100%; max-width: 760px; margin: 0 auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.2); }
.viewer-body .vtxt { max-width: 760px; margin: 0 auto; background: var(--paper); padding: 18px 22px; line-height: 2; white-space: pre-wrap; font-family: var(--read); }
.x { border: 0; background: none; cursor: pointer; font-size: 1.1rem; }

/* ── قلب الصفحة */
.sheet-turn { position: absolute; top: 10px; bottom: 10px; width: calc(50% - 10px); z-index: 30; background: var(--paper); transform-origin: left center; border-radius: 0 8px 8px 0; box-shadow: 0 0 30px rgba(0,0,0,.2); pointer-events: none; backface-visibility: hidden; }
.sheet-turn.next { right: 10px; animation: turnNext .75s cubic-bezier(.45,.05,.3,1) forwards; }
.sheet-turn.prev { left: 10px; transform-origin: right center; border-radius: 8px 0 0 8px; animation: turnPrev .75s cubic-bezier(.45,.05,.3,1) forwards; }
@keyframes turnNext { from { transform: rotateY(0); } to { transform: rotateY(-178deg); opacity: .4; } }
@keyframes turnPrev { from { transform: rotateY(0); } to { transform: rotateY(178deg); opacity: .4; } }
.page-in.fade { animation: fadein .5s ease .25s both; } @keyframes fadein { from { opacity: 0; } }

/* ── شاشات أصغر: صفحة واحدة فوق الأخرى */
@media (max-width: 1199px) {
  .book-wrap { padding: 2px 6px 90px; perspective: none; } /* المنظور يجعل اللوح السفلي للأصل يتبع الكتاب بدل الشاشة */
  .book { grid-template-columns: 1fr; height: auto; min-height: 0; padding: 6px; border-radius: 12px; }
  .page.text, .page.lab { border-radius: 6px; box-shadow: none; }
  .page.lab { margin-top: 6px; }
  .page-in { overflow: visible; padding: 20px 18px; }
  .page h1 { font-size: 1.6rem; }
  .tx { grid-template-columns: 1fr; } .tx-margin { display: flex; flex-wrap: wrap; gap: 4px 16px; }
  .mnote { margin: 4px 0 10px; }
  .dock .where { max-width: 110px; }
  /* الأصل على الشاشة الضيقة: لوح سفلي، والدرس فوقه يبقى قابلاً للتمرير */
  .viewer { position: fixed; top: auto; left: 0 !important; right: 0 !important; bottom: 0; width: auto; height: 52vh; z-index: 50; }
  .viewer-in { border-radius: 14px 14px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.25), inset 0 0 0 2px #8a6d3b55; }
  body.src-open { padding-bottom: 52vh; } body.src-open .dock { bottom: calc(52vh + 8px); }
  .narr { position: static; box-shadow: none; }
  .only-m { display: inline-block; font-weight: 600; } .dock button { padding: 6px 7px; }
  .sheet-turn { display: none; }
}
@media (max-width: 640px) {
  .stage, .stage:has(.sheet) { aspect-ratio: 3 / 3.9; min-height: 330px; }
  .stage:not(:has(.sheet)) { aspect-ratio: 4 / 3.6; }
  .gauge { flex: 1 1 120px; padding: 6px 8px; font-size: .72rem; }
  .ent .fig { width: 50px; height: 78px; } .ent.small .fig { width: 38px; height: 60px; } .ent.mid .fig { width: 44px; height: 70px; }
  .stage .ent .plate b { font-size: .72rem; } .stage .ent .plate i { font-size: .64rem; }
  .stage .bld { width: 58px; height: 56px; }
  .stage .sheet { width: 94% !important; font-size: .68rem; line-height: 1.5; padding: 6px 9px; background-image: none; }
  .stage .sheet p { margin: 4px 0; }
  .stage .sheet h4 { font-size: .86rem; }
  .run-head { flex-wrap: wrap; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } .mnote { opacity: 1; } }
/* سطور التظهير المتراكمة على ظهر الورقة عبر صفحات «سلسلة الأيدي» */
.eline { margin: 1px 0; font-family: var(--hw); line-height: 1.6; }
.eline.more { font-family: var(--ui); font-size: .78em; color: var(--muted); }
.eline.bad { text-decoration: line-through; color: #b8433a; }
.eline[data-drop].hot { outline: 2px solid var(--gold); border-radius: 4px; }
.eline .stk { font-family: var(--ui); font-size: .85em; color: var(--ok); }
.stk-prev { margin: 2px 0; font-family: var(--ui); font-size: .82em; color: var(--violet); }
.gauges.seals .gauge { flex: 1 1 110px; padding: 4px 8px; font-size: .7rem; }
/* ── الشاشة العريضة: صفحة المختبر تتسع للمشهد ونتيجته وأدواته معاً */
@media (min-width: 1200px) {
  .book { height: calc(100vh - 124px); }
  .page.lab .page-in { padding: 14px 22px 10px; gap: 6px; }
  .page.lab .run-head { margin-bottom: 2px; }
  #labBody { gap: 7px; }
  .gauge { padding: 4px 9px; font-size: .72rem; line-height: 1.4; }
  .timeline { height: 72px; } .tl-axis { top: 38px; } .tl-tick { top: 32px; }
  .narr { padding: 6px 12px; line-height: 1.75; }
  /* إن بقي ما لا يتسع بعد تصغير المسرح: أدوات التحكم فوق المسرح، والراوي ثابت في الأسفل */
  #labBody.tight > .tray { order: 1; } #labBody.tight > .ctrl { order: 1; }
}
.gauges.seals { gap: 5px; } .gauges.seals .gauge { padding: 2px 7px; } .gauges.seals .gauge .lamp { width: 9px; height: 9px; }
/* الوصلة تُظهر آخر سطرين فقط كي لا تكبر فوق الورقة */
.ptok .eline:nth-last-of-type(n+3) { display: none; }
/* تقدّم التعلّم: زرت / جرّبت / أتممت */
.prog { font-family: var(--ui); font-size: .7rem; padding: 1px 8px; border-radius: 999px; white-space: nowrap; font-style: normal; }
.prog.p0, .prog.p1 { color: var(--muted); border: 1px solid var(--line); } .prog.p2 { color: var(--warn); background: var(--warn-soft); } .prog.p3 { color: var(--ok); background: var(--ok-soft); font-weight: 700; }
.toc a .prog { padding: 0 5px; margin-inline-end: 4px; border: 0; background: none; }
.prog-legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 6px; } .prog-legend small { font-family: var(--ui); color: var(--muted); font-size: .7rem; flex-basis: 100%; }
.toc-part small { color: var(--muted); font-weight: 400; margin-inline-start: 6px; }
.goal { font-family: var(--ui); font-size: .7rem; color: var(--ink); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resets { align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#labBody > .carry-bar { order: 0; font-family: var(--ui); font-size: .74rem; color: var(--violet); line-height: 1.6; }
/* شاشة الحاسوب المحمول (مثلاً ١٣٦٦×٧٦٨): حين لا يتسع المشهد كاملاً، تبقى النتيجة والتعليل معاً ثابتين أسفل الصفحة،
   بمؤشرات مضغوطة في سطر واحد، والأدوات فوق المسرح */
@media (min-width: 1200px) {
  #labBody.tight > .gauges { order: 4; position: sticky; bottom: var(--narrH, 60px); z-index: 6; background: var(--paper); padding-top: 4px; }
  #labBody.tight > .narr { order: 5; }
  #labBody.tight .gauge { flex: 1 1 120px; padding: 2px 8px; font-size: .68rem; line-height: 1.35; }
  #labBody.tight .gauge b { display: inline; } #labBody.tight .gauge b::after { content: ': '; } #labBody.tight .gauge .lamp { width: 9px; height: 9px; margin-top: 2px; }
  #labBody.tight > .how { font-size: .74rem; }
}
/* الشاشات القصيرة العريضة: تُطوى اللافتة العلوية ليتسع الكتاب (الفهرس والتنقل باقيان في الشريط السفلي) */
@media (min-width: 1200px) and (max-height: 820px) {
  .crown { display: none; }
  .book-wrap { padding-top: 10px; }
  .book { height: calc(100vh - 82px); }
  .page.lab .run-head { font-size: .68rem; }
  .page.lab .lab-head { font-size: .72rem; }
}
@media (max-width: 640px) { .stage .stk-prev { margin: 0; font-size: .78em; } .stage .stick-zone { min-height: 18px !important; margin: 2px 0; } }
@media (max-width: 640px) { .stage .sheet.bill { font-size: .64rem; line-height: 1.45; } }
@media (max-width: 640px) { .stage.tall, .stage.tall:has(.sheet) { aspect-ratio: 3 / 4.5; } }
/* بعد أول تفاعل في مشهد لا يتسع: سطر التعليمات يُطوى (يبقى في title)، فيتسع المشهد ونتيجته */
@media (min-width: 1200px) { #labBody.tight.acted > .how { display: none; } }
.ctrl[hidden] { display: none; }
/* الآيباد والشاشات المتوسطة أفقياً: صفحة واحدة بعرض مريح، كي يبقى المشهد وتعليله معاً على الشاشة */
@media (min-width: 641px) and (max-width: 1199px) and (orientation: landscape) { .book { max-width: 660px; } }

/* لوح «القراءة دون اتصال» في الفهرس (نسخة النشر) */
.offline-box { margin: 0 0 12px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; font-family: var(--ui); font-size: .8rem; line-height: 1.6; }
.offline-box p { margin: 4px 0 6px; } .offline-box small { display: block; color: var(--muted); margin-top: 4px; } .offline-box .act[hidden] { display: none; }
