/* درسي — نظام التصميم «مداد وورق»: حبر عميق، ورق دافئ، لمسة ذهب من المخطوطات. هادئ، بلا زحام. */
:root {
  --paper: #FAF8F3; --surface: #FFFFFF; --surface-2: #F2EFE7; --line: #E6E1D5; --line-2: #D9D2C1;
  --ink: #18223A; --ink-2: #3B4660; --muted: #6B7280;
  --primary: #1D3A6E; --primary-2: #2B5299; --primary-soft: #EAF0FA;
  --gold: #B8892B; --gold-soft: #F8F0DC;
  --ok: #2F7D55; --ok-soft: #E6F4EC; --bad: #B4432F; --bad-soft: #FBEAE6;
  --radius: 16px; --scale: 1; --age: 1;
  --shadow: 0 1px 2px rgba(24,34,58,.04), 0 8px 24px rgba(24,34,58,.06);
  --font: "Noto Naskh Arabic", "Amiri", "Segoe UI", Tahoma, "DejaVu Sans", serif;
  --font-brand: "Reem Kufi", "Noto Naskh Arabic", Tahoma, sans-serif;
  --font-quran: "Amiri Quran", "Amiri", "Noto Naskh Arabic", serif;
}
/* الفئات العمرية */
html[data-age="primary"] { --age: 1.12; --radius: 22px; --primary: #1F5F8B; --primary-2: #2A7AB0; --primary-soft: #E5F2FA; --gold: #E08A2E; --gold-soft: #FDF0E0; }
html[data-age="preparatory"] { --age: .97; --radius: 14px; }

* { box-sizing: border-box; }
html { font-size: calc(17.5px * var(--scale) * var(--age)); }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); line-height: 1.85;
  -webkit-text-size-adjust: 100%; padding-bottom: calc(76px + env(safe-area-inset-bottom)); text-rendering: optimizeLegibility; }
a { color: var(--primary-2); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.skip { position: absolute; right: -999px; } .skip:focus { right: 8px; top: 8px; z-index: 99; background: #fff; padding: 6px 10px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
main { max-width: 760px; margin: 0 auto; padding: 18px 16px 28px; }
main.wide { max-width: 1320px; }
h1 { font-size: 1.45rem; line-height: 1.5; margin: .2em 0 .4em; font-weight: 700; letter-spacing: 0; }
h2 { font-size: 1.12rem; margin: 1.2em 0 .5em; font-weight: 700; }
h3 { font-size: 1rem; margin: .4em 0; }
p { margin: .35em 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .grow { flex: 1; }
.loading { padding: 48px; text-align: center; color: var(--muted); }
.sec { font-size: 1rem; color: var(--ink-2); margin: 28px 0 10px; }

/* الشريط العلوي */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(250,248,243,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .in { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 8px 16px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-brand); font-weight: 700; font-size: 1.3rem; color: var(--primary); text-decoration: none; }
.logo-mark { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-size: 1.1rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: inset 0 -3px 0 var(--gold); }
.back { border: 0; background: none; font: inherit; color: var(--primary-2); cursor: pointer; padding: 6px 2px; }

/* التنقل السفلي */
.bottomnav { position: fixed; bottom: 0; inset-inline: 0; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
.bottomnav a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: .78rem; padding: 4px 0; border-radius: 12px; }
.bottomnav a .ic { display: block; font-size: 1.25rem; line-height: 1.25; }
.bottomnav a.on { color: var(--primary); font-weight: 700; background: var(--primary-soft); }
.bottomnav:empty { display: none; }

/* أزرار وحقول */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; border-radius: 12px;
  border: 1px solid var(--primary); background: var(--primary); color: #fff; padding: 9px 18px; min-height: 46px; cursor: pointer; text-decoration: none; transition: background .15s; }
.btn:hover { background: var(--primary-2); }
.btn.ghost { background: transparent; color: var(--primary); } .btn.ghost:hover { background: var(--primary-soft); }
.btn.quiet { background: var(--surface-2); border-color: transparent; color: var(--ink); font-weight: 500; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; } .btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
label { display: block; font-weight: 700; margin: 12px 0 4px; font-size: .95rem; }
input, select, textarea { width: 100%; font: inherit; padding: 10px 14px; border: 1px solid var(--line-2); border-radius: 12px; background: #fff; color: var(--ink); min-height: 46px; }
.err { color: var(--bad); font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 10px 0; box-shadow: var(--shadow); }
.card.soft { background: var(--primary-soft); border-color: transparent; box-shadow: none; }
.card.warn, .note { background: var(--gold-soft); border: 1px solid #EBD9AE; border-radius: 12px; padding: 10px 14px; box-shadow: none; color: #6A4E12; font-size: .92rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.tag.ok { background: var(--ok-soft); color: var(--ok); } .tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.accent { background: var(--gold-soft); color: #7A5A12; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 5px 14px; font: inherit; font-size: .9rem;
  cursor: pointer; color: var(--ink); min-height: 38px; text-decoration: none; display: inline-flex; align-items: center; }
.chip:hover { border-color: var(--primary-2); }
.chip.strong { border-color: var(--gold); background: var(--gold-soft); }
.list { list-style: none; padding: 0; margin: 0; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary-2); border-radius: 99px; }

/* هوية المدرس */
.ai-avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--gold-soft);
  font-family: var(--font-brand); font-weight: 700; background: radial-gradient(circle at 30% 30%, var(--primary-2), var(--primary)); box-shadow: 0 0 0 2px var(--gold-soft), 0 0 0 3px var(--gold); }
.ai-avatar.lg { width: 64px; height: 64px; font-size: 1.8rem; margin: 0 auto 10px; }

/* الرئيسية */
.hero { text-align: center; padding: 26px 0 6px; }
.hero h1 { font-size: 1.6rem; }
.composer-box { background: var(--surface); border: 1px solid var(--line-2); border-radius: 22px; padding: 10px 12px 8px; box-shadow: var(--shadow); text-align: start; margin-top: 16px; }
.composer-box:focus-within { border-color: var(--primary-2); }
.composer-box textarea { border: 0; min-height: 30px; padding: 6px 4px; resize: none; background: transparent; line-height: 1.7; }
.composer-box textarea:focus { outline: none; }
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer-row .mode { flex: 1; color: #7A5A12; }
.send { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; font-size: 1.2rem; cursor: pointer; margin-inline-start: auto; }
.send:hover { background: var(--primary-2); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.seg label { margin: 0; font-weight: 500; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-block; border: 1px solid var(--line-2); border-radius: 999px; padding: 3px 12px; font-size: .88rem; cursor: pointer; }
.seg input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.seg input:focus-visible + span { outline: 3px solid var(--gold); }
.tasks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.task-card { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .15s, border-color .15s; }
.task-card:hover { transform: translateY(-2px); border-color: var(--primary-2); }
.task-card .ic { font-size: 1.3rem; } .task-card .why { color: var(--muted); font-size: .86rem; }
.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.subject-card { display: flex; gap: 14px; align-items: center; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.subject-card > span:last-child { display: flex; flex-direction: column; }
.ring { --p: 0; flex: none; width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--gold) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring > span { width: 46px; height: 46px; border-radius: 50%; background: var(--primary-soft); display: grid; place-items: center; font-size: 1.25rem; color: var(--primary); font-weight: 700; }

/* صفحة المادة */
.subject-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 6px 0 10px; }
.big-ic { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; font-size: 1.8rem; background: var(--primary-soft); color: var(--primary); }
.subject-head h1 { margin: 0; }
.chapter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px 10px; margin: 14px 0; box-shadow: var(--shadow); }
.chapter h2 { display: flex; align-items: center; gap: 10px; margin: 10px 0 4px; }
.chapter .num { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--gold-soft); color: #7A5A12; font-size: .9rem; }
.lessons { list-style: none; padding: 0; margin: 0; counter-reset: l; }
.lessons li a { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.lessons li a::before { counter-increment: l; content: counter(l); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: .85rem; }
.lessons li a:hover { color: var(--primary-2); } .lessons .go { color: var(--muted); }

/* مساحة الدرس */
.ws-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 14px; margin-bottom: 12px; position: sticky; top: 64px; z-index: 5; }
.ws-tabs button { flex: 1; border: 0; background: none; font: inherit; padding: 7px; border-radius: 10px; cursor: pointer; color: var(--ink-2); }
.ws-tabs button[aria-selected="true"] { background: var(--surface); color: var(--primary); font-weight: 700; box-shadow: var(--shadow); }
.workspace .pane { display: none; }
.workspace[data-active="book"] .pane-book, .workspace[data-active="chat"] .pane-chat, .workspace[data-active="tools"] .pane-tools { display: block; }
.pane-head { display: flex; flex-direction: column; margin-bottom: 8px; }
.page-list { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.pg { border: 1px solid var(--line-2); background: var(--surface); border-radius: 10px; padding: 2px 10px; font: inherit; font-size: .85rem; cursor: pointer; }
.pg.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.tools { display: grid; gap: 10px; }
.tool { display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: start;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; font: inherit; color: var(--ink); text-decoration: none; cursor: pointer; }
.tool:hover { border-color: var(--primary-2); }
.tool span { grid-row: span 2; font-size: 1.4rem; width: 40px; height: 40px; display: grid; place-items: center; background: var(--primary-soft); border-radius: 12px; }
.tool small { color: var(--muted); font-size: .82rem; }
#studyOut { margin-top: 12px; }
@media (min-width: 1000px) {
  .ws-tabs { display: none; }
  .workspace { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(420px, 1.35fr) minmax(260px, .8fr); gap: 16px; align-items: start; }
  .workspace .pane { display: block !important; }
  .pane-book, .pane-tools { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
  .pane-chat { min-height: calc(100vh - 110px); display: flex !important; flex-direction: column; }
  .pane-chat #chatHost { display: flex; flex-direction: column; flex: 1; }
  .pane-chat .chat { flex: 1; }
}

/* المحادثة */
.chat-page { max-width: 760px; margin: 0 auto; }
.chat { display: flex; flex-direction: column; gap: 18px; padding: 6px 0 12px; }
.msg { display: flex; gap: 10px; align-items: flex-start; overflow-wrap: anywhere; }
.msg.user { justify-content: flex-start; }
.msg.user .body { background: var(--primary-soft); color: var(--ink); padding: 8px 14px; border-radius: 18px 18px 18px 6px; max-width: 85%; }
.msg.assistant .body { flex: 1; min-width: 0; padding-top: 3px; }
.msg .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.cite { font: inherit; font-size: .8rem; border: 1px solid #CDD9EE; background: var(--primary-soft); color: var(--primary); border-radius: 8px; padding: 0 9px; cursor: pointer; }
sup.cn { color: var(--gold); font-weight: 700; cursor: pointer; }
.flag-btn { border: 0; background: none; color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer; opacity: .7; }
.general-note { border-inline-start: 3px solid var(--gold); padding-inline-start: 10px; background: var(--gold-soft); border-radius: 6px; }
.ref-card { border: 1px solid #EBD9AE; background: #FFFCF4; border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
.check { border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-top: 10px; background: var(--surface); }
.dots i { display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%; background: var(--primary-2); animation: b 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes b { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--paper) 22%); padding-top: 12px; }
.composer .composer-box { margin-top: 0; }

/* الأسئلة */
.q .stem, .stem { font-weight: 700; margin-bottom: 8px; }
.opt { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line-2); border-radius: 12px; padding: 9px 12px; margin: 6px 0; cursor: pointer; background: #fff; font-weight: 400; }
.opt input { width: auto; min-height: 0; accent-color: var(--primary); }
.opt:has(input:checked) { border-color: var(--primary-2); background: var(--primary-soft); }
.result.ok { border-inline-start: 4px solid var(--ok); } .result.bad { border-inline-start: 4px solid var(--bad); }
.stages { display: flex; gap: 4px; margin: 6px 0 10px; }
.stages i { flex: 1; height: 6px; border-radius: 9px; background: var(--surface-2); }
.stages i.done { background: var(--primary-2); } .stages i.cur { background: var(--gold); }
.task { display: flex; gap: 12px; } .task .n { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; }

/* معالج البداية */
.wizard { max-width: 620px; margin: 0 auto; text-align: center; }
.wizard h1 { margin-top: 10px; } .wizard .card { text-align: start; }
.steps { display: flex; gap: 6px; margin: 4px 0 18px; }
.steps i { flex: 1; height: 6px; border-radius: 9px; background: var(--surface-2); }
.steps i.done { background: var(--primary-2); } .steps i.cur { background: var(--gold); }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.choice-grid.three { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.choice { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 10px; background: var(--surface); border: 1.5px solid var(--line-2);
  border-radius: var(--radius); font: inherit; font-weight: 700; color: var(--ink); cursor: pointer; transition: border-color .15s, transform .15s; }
.choice:hover { border-color: var(--primary-2); transform: translateY(-2px); }
.choice.on { border-color: var(--primary); background: var(--primary-soft); }
.choice .big { font-size: 1.8rem; } .choice small { font-weight: 400; font-size: .8rem; }
.back-link { border: 0; background: none; font: inherit; color: var(--primary-2); cursor: pointer; display: block; margin-inline-start: auto; }
.wizard .btn.block { margin-top: 14px; }
.bank-q { border-top: 1px solid var(--line); padding: 12px 0; }

/* الخريطة والملخص */
.study { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.points { padding-inline-start: 1.2em; margin: 0; } .points li { margin: 6px 0; } .points li p { margin: 0; }
.mm { padding-inline-start: 0; list-style: none; margin: 0; }
.mm ul { list-style: none; padding-inline-start: 16px; border-inline-start: 2px solid var(--line); margin-inline-start: 12px; }
.mm li { margin: 7px 0; }
.mm .node { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line-2); background: #fff; border-radius: 12px; padding: 4px 12px; font: inherit; cursor: pointer; text-align: start; }
.mm .node.root { background: var(--primary); color: #fff; font-weight: 700; border-color: var(--primary); font-size: 1.05rem; }
.mm .node.group { background: var(--gold-soft); border-color: #EBD9AE; font-weight: 700; }
.mm .node[aria-expanded="false"] + ul { display: none; }
.det { margin-top: 10px; }

/* القارئ */
.page { background: #FFFDF8; border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; box-shadow: var(--shadow); }
.page .chunk { position: relative; padding: 6px 8px 6px 34px; border-radius: 8px; margin: 6px 0; }
.page .chunk.hl { background: #FFF3CC; box-shadow: inset 0 0 0 2px #E8C766; }
.page .chunk.k-heading { font-weight: 700; font-size: 1.08rem; color: var(--primary); }
.page .chunk.k-definition { border-inline-start: 3px solid var(--primary-2); }
.page .chunk.k-example { border-inline-start: 3px solid var(--gold); }
.flag { position: absolute; left: 4px; top: 6px; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; opacity: .45; }
.flag:hover, .flag:focus-visible { opacity: 1; }
.page-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: start; vertical-align: top; }
.quran { font-family: var(--font-quran); font-size: 1.3em; line-height: 2.3; }

#toast { position: fixed; bottom: calc(88px + env(safe-area-inset-bottom)); inset-inline: 0; margin: auto; width: max-content; max-width: 90%;
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 12px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
#toast.show { opacity: 1; }
dialog { border: 0; border-radius: 18px; padding: 20px; width: min(460px, 92vw); }
dialog::backdrop { background: rgba(24,34,58,.35); }
.math-block { display: block; text-align: center; margin: 8px 0; overflow-x: auto; }
.math-block .katex { display: inline-block; }
.katex { font-size: 1.05em; direction: ltr; unicode-bidi: isolate; display: inline-block; max-width: 100%; overflow-x: auto; vertical-align: middle; }

/* الفئة الابتدائية: أزرار كبيرة وعمود واحد */
html[data-age="primary"] .btn { min-height: 52px; }
html[data-age="primary"] .grid2, html[data-age="primary"] .tasks { grid-template-columns: 1fr; }

.topnav { display: none; gap: 4px; }
.topnav a { text-decoration: none; color: var(--ink-2); padding: 5px 14px; border-radius: 10px; font-size: .92rem; }
.topnav a .ic { margin-inline-end: 6px; color: var(--muted); }
.topnav a.on { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.back { font-size: 1.3rem; }
@media (max-width: 999px) { .topbar .title:not(:empty) ~ * { } .topbar .back ~ .brand .brand-word { display: none; } }
@media (min-width: 1000px) {
  body { padding-bottom: 0; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .composer { bottom: 0; }
  #toast { bottom: 24px; }
}
@media print { .topbar, .bottomnav, .chips, .composer, .flag, .ws-tabs { display: none !important; } body { background: #fff; } }
/* ---------- نظام الحركة: ناعم وسريع، ويختفي مع «تقليل الحركة» ---------- */
:root { --ease: cubic-bezier(.2,.8,.2,1); --dur: .28s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { opacity: 0; transform: translateY(6px) scale(.98); } 100% { opacity: 1; transform: none; } }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 0 rgba(184,137,43,.0); } 50% { box-shadow: 0 0 0 6px rgba(184,137,43,.18); } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
main { animation: rise var(--dur) var(--ease) both; }
main .card, main .tool, main .subject, main .qcard { animation: rise .32s var(--ease) both; animation-delay: calc(var(--i, 0) * 35ms); }
.msg { animation: pop .26s var(--ease) both; }
.btn, .chip, .tool, .cite, .flag-btn { transition: transform .12s var(--ease), background .15s, border-color .15s, box-shadow .15s; }
.btn:active, .chip:active, .tool:active { transform: scale(.97); }
@media (hover: hover) { .tool:hover, a.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(24,34,58,.05), 0 14px 30px rgba(24,34,58,.09); } }
.result.ok { animation: pop .3s var(--ease) both; }
.card.flash .back:not([hidden]) { animation: rise .22s var(--ease) both; }
/* الصغار: أزرار أكبر ومرحة وتغذية راجعة محببة */
html[data-level="primary_lower"] .btn, html[data-level="primary_upper"] .btn { border-radius: 999px; min-height: 52px; font-size: 1.05em; }
html[data-level="primary_lower"] .tool span, html[data-level="primary_upper"] .tool span { display: inline-block; font-size: 1.6em; }
html[data-level="primary_lower"] .tool:hover span { animation: wiggle .5s var(--ease); }
/* الإعدادي: واجهة وزارية جادة وزر «إجابة نموذجية» بارز */
html[data-level="preparatory"] .chip[data-i="model_answer"] { animation: glow 2.4s ease-in-out 1s 2; }
html[data-level="preparatory"] .tool[data-model] { border-color: var(--gold); background: linear-gradient(180deg, var(--gold-soft), var(--surface)); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.ai-note { margin-top: 6px; font-size: .85em; color: var(--primary); background: var(--primary-soft); border-radius: 8px; padding: 4px 8px; }
.ai-note.bad { color: #9a3b2b; background: #fbeae6; }

/* ===== حسب المستوى ===== */
/* الأول–الثالث الابتدائي: أكبر، أدفأ، أزرار قليلة، بلا أدوات متقدمة */
html[data-level="primary_lower"] { --age: 1.2; --radius: 26px; }
html[data-level="primary_lower"] [data-adv] { display: none !important; }
html[data-level="primary_lower"] .chip { font-size: 1.15em; padding: 12px 18px; }
html[data-level="primary_lower"] .msg:not(.user) .body { font-size: 1.12em; line-height: 2; }
html[data-level="primary_lower"] .hero h1 { font-size: 2em; }
/* الرابع–السادس: كبير وواضح مع الأدوات الأساسية */
html[data-level="primary_upper"] [data-model] { display: none !important; }
/* الإعدادي: أكثف، والإجابة النموذجية بارزة */
html[data-level="preparatory"] .chip[data-i="model_answer"] { background: var(--gold-soft); border-color: var(--gold); font-weight: 700; }
.ai-note .cand { white-space: pre-wrap; max-height: 220px; overflow: auto; background: #fff; color: var(--ink); padding: 6px; border-radius: 6px; margin: 4px 0; }

/* بطاقات المراجعة */
.cards { display: grid; gap: 10px; margin-top: 10px; }
.card.flash { padding: 12px 14px; }
.card.flash .back { margin: 8px 0; padding-top: 8px; border-top: 1px dashed var(--line, #ddd); }
.hintbox .note { margin: 6px 0; }

/* الرئيسية: أرقام تحفيزية وسؤال اليوم */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 4px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 8px; text-align: center;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; font-size: .85rem; color: var(--muted); }
.stat .big { font-family: var(--font-brand); font-size: 1.45rem; color: var(--ink); line-height: 1.2; }
a.card.qday { display: block; text-decoration: none; color: var(--ink); border-inline-start: 4px solid var(--gold); }
a.card.qday .stem { margin: 6px 0; }
html[data-level="primary_lower"] .stat .big, html[data-level="primary_upper"] .stat .big { font-size: 1.7rem; }

/* الدرس صوتيًا */
.podcast .turns { max-height: 420px; overflow: auto; margin-top: 8px; }
.podcast .turn { padding: 6px 10px; border-radius: 12px; margin: 4px 0; cursor: pointer; transition: background .2s; }
.podcast .turn.student { background: var(--surface-2); margin-inline-start: 18%; }
.podcast .turn.now { background: var(--gold-soft); box-shadow: inset 3px 0 0 var(--gold); }

.qctx { background: var(--surface-2); border-radius: 12px; padding: 6px 10px; margin: 4px 0 8px; font-size: .95em; }
.qctx summary { cursor: pointer; color: var(--muted); }

/* مساحة المدرس */
.bank-layout { display: grid; grid-template-columns: 280px 1fr; gap: 14px; align-items: start; }
.bank-outline { position: sticky; top: 70px; max-height: 75vh; overflow: auto; }
.bank-outline label { gap: 6px; padding: 2px 0; }
.qcard.picked { border-color: var(--ok); background: var(--ok-soft); }
.opts { margin: 4px 0; padding-inline-start: 22px; }
@media (max-width: 760px) { .bank-layout { grid-template-columns: 1fr; } .bank-outline { position: static; max-height: none; } }
/* ورقة الامتحان (طباعة A4) */
.paper { background: #fff; color: #000; max-width: 820px; margin: 0 auto; padding: 28px 34px; font-size: 15px; line-height: 1.9; box-shadow: var(--shadow); }
.paper-head { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 8px; border-bottom: 2px solid #000; padding-bottom: 8px; font-size: 14px; }
.paper-head .c { text-align: center; }
.paper-sec h3 { font-size: 16px; margin: 14px 0 4px; }
.paper .ans { color: #0a5a2a; font-weight: 700; margin: 2px 0 6px; }
.paper-note, .paper-foot { text-align: center; color: #333; }
@media print {
  body.print-mode header, body.print-mode nav, body.print-mode .bottom-nav, .no-print { display: none !important; }
  body.print-mode { background: #fff; padding: 0; }
  body.print-mode main { max-width: none; padding: 0; animation: none; }
  .paper { box-shadow: none; padding: 0; max-width: none; }
  .paper-sec { break-inside: avoid-page; }
  @page { size: A4; margin: 14mm; }
}

/* استمع وسمّع */
.quran { font-family: var(--font-quran); font-size: 1.55rem; line-height: 2.4; text-align: justify; margin: 8px 0; }
.quran .ayah { transition: background .25s; border-radius: 8px; padding: 0 2px; }
.quran .ayah.now { background: var(--gold-soft); box-shadow: 0 0 0 2px var(--gold-soft); }
.quran .an { color: var(--gold); font-size: .85em; }
.hidden-text { filter: blur(7px); user-select: none; transition: filter .25s; }
.recite-words { font-family: var(--font-quran); font-size: 1.3rem; line-height: 2.2; }
.recite-words .w.ok { color: var(--ok); }
.recite-words .w.missed { color: var(--bad); text-decoration: underline wavy; background: var(--bad-soft); border-radius: 6px; }
.recite-words .w.wrong { color: #8a5a00; background: #fff1cc; border-radius: 6px; }
.score { font-family: var(--font-brand); font-size: 1.3rem; padding: 0 10px; border-radius: 10px; }
.score.ok { background: var(--ok-soft); color: var(--ok); } .score.mid { background: #fff1cc; color: #8a5a00; } .score.bad { background: var(--bad-soft); color: var(--bad); }
.rec-btn.rec, .mic.rec { background: var(--bad); border-color: var(--bad); color: #fff; animation: glow 1.2s ease-in-out infinite; }
.mic { border: 1px solid var(--line-2); background: var(--surface); border-radius: 50%; width: 40px; height: 40px; cursor: pointer; font-size: 1.1rem; }
.en-target { font-size: 1.35rem; font-weight: 700; margin: 6px 0; }
#ec { max-height: 360px; overflow: auto; margin: 8px 0; }
/* المحادثة مثبتة مثل تطبيقات الذكاء الاصطناعي: الرسائل تتمرر والصندوق ثابت في الأسفل */
body.chat-mode main { max-width: 820px; height: calc(100dvh - 60px - 68px - env(safe-area-inset-bottom)); display: flex; flex-direction: column; padding-bottom: 0; }
body.chat-mode .chat-page, body.chat-mode #chatHost { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; }
body.chat-mode .chat { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding-inline: 4px; }
body.chat-mode .composer { position: static; padding-bottom: 8px; }
@media (min-width: 1000px) { .pane-chat .chat { max-height: calc(100vh - 260px); overflow-y: auto; } }

/* قصة الإنكليزي + المراجعة المتباعدة */
.story h3 { margin: 4px 0 8px; }
.story-text { font-size: 1.12rem; line-height: 2; margin: 10px 0; text-align: left; }
.story-text .sent { cursor: pointer; border-radius: 6px; padding: 1px 2px; transition: background .2s; }
.story-text .sent.now { background: color-mix(in srgb, var(--gold) 35%, transparent); }
.story-words { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.story-words small { color: var(--muted); }
.story-qs .sq { margin: 8px 0; padding: 10px 12px; }
.story-qs .sq p { margin: 0; }
.sq-out .note.correct { border-inline-start: 4px solid #2e9e5b; }
.sq-out .note.wrong { border-inline-start: 4px solid #c0392b; }
a.card.qday.review-due { border-inline-start-color: #2e9e5b; }
.rv .w.missed { background: color-mix(in srgb, #c0392b 15%, transparent); border-radius: 4px; padding: 0 4px; }
ul.plain { list-style: none; padding: 0; } ul.plain li { padding: 4px 0; border-bottom: 1px dashed var(--line); }

/* جداول المقارنة */
.cmp-wrap { overflow-x: auto; margin: 8px 0; }
table.cmp { width: 100%; border-collapse: separate; border-spacing: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: .95rem; }
table.cmp th, table.cmp td { padding: 8px 10px; border-bottom: 1px solid var(--line); border-inline-start: 1px solid var(--line); vertical-align: top; text-align: start; }
table.cmp thead th { background: var(--ink, #1D3A6E); color: #fff; font-weight: 600; }
table.cmp tbody th { background: color-mix(in srgb, var(--gold) 14%, transparent); font-weight: 600; white-space: nowrap; }
table.cmp tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--line) 25%, transparent); }
table.cmp td p, table.cmp th p { margin: 0; }
table.cmp td.shut { color: transparent; background: repeating-linear-gradient(45deg, var(--line), var(--line) 6px, transparent 6px, transparent 12px) !important; cursor: pointer; }
table.cmp td.shut * { visibility: hidden; }
html[data-level^="primary"] table.cmp { font-size: 1.05rem; }
/* نافذة سؤال المدرس */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; padding: 12px; }
.modal-back .modal { width: min(640px, 100%); max-height: 92vh; overflow: auto; }
.modal label { display: block; margin: 8px 0 4px; }
.modal textarea, .modal select, .modal input:not([type=radio]) { width: 100%; }
@media print { table.cmp thead th { background: #eee; color: #000; } }
