/* بنك تمارين الباكالوريا — Layout: one column (max 720px). Sticky top bar (back · title · language).
   Home: hero with section chip + progress, actions row, search, chapter list. Chapter: exercise cards.
   Exercise: meta chips, statement (LTR, French), question blocks with hint/correction toggles, footer actions. */
@font-face { font-family: "Readex Pro"; font-weight: 400; font-display: swap; src: url("../fonts/readex-pro-arabic-400-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Readex Pro"; font-weight: 700; font-display: swap; src: url("../fonts/readex-pro-arabic-700-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Readex Pro"; font-weight: 400; font-display: swap; src: url("../fonts/readex-pro-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Readex Pro"; font-weight: 700; font-display: swap; src: url("../fonts/readex-pro-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --bg: #F4F5F9; --surface: #FFFFFF; --surface-2: #ECEEF5; --ink: #161B2E; --muted: #5A6178; --line: #DCE0EA;
  --brand: #24408E; --brand-ink: #FFFFFF; --brand-soft: #E3E9F8; --gold: #C98A0B; --gold-soft: #FBF1DC;
  --ok: #1F8A55; --ok-soft: #DDF3E7; --rev: #C2410C; --rev-soft: #FDE8DC;
  --shadow: 0 1px 2px rgba(22,27,46,.06), 0 3px 10px rgba(22,27,46,.05);
  --f: "Readex Pro", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1220; --surface: #171C2E; --surface-2: #1F2539; --ink: #E8EBF5; --muted: #A1A8C0; --line: #2B3250;
    --brand: #8FA8F5; --brand-ink: #0E1220; --brand-soft: #1E2950; --gold: #F1B93C; --gold-soft: #3A2E12;
    --ok: #4CC98B; --ok-soft: #12321F; --rev: #FB8C5A; --rev-soft: #3B2114; --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1220; --surface: #171C2E; --surface-2: #1F2539; --ink: #E8EBF5; --muted: #A1A8C0; --line: #2B3250;
  --brand: #8FA8F5; --brand-ink: #0E1220; --brand-soft: #1E2950; --gold: #F1B93C; --gold-soft: #3A2E12;
  --ok: #4CC98B; --ok-soft: #12321F; --rev: #FB8C5A; --rev-soft: #3B2114; --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.6 var(--f); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.app { max-width: 720px; margin-inline: auto; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr);
  padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top, 0px)) 0 8px; }
.top .title { flex: 1; min-width: 0; font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; flex: none; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .flip svg { transform: scaleX(-1); }
.pill { height: 42px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; background: var(--surface); font-weight: 700; font-size: .85rem; }
.view { min-width: 0; display: grid; gap: 14px; align-content: start; padding-top: 4px; animation: in .2s ease; }

/* ---------- الرئيسية ---------- */
.hero { background: var(--brand); color: var(--brand-ink); border-radius: 20px; padding: 18px; display: grid; gap: 10px; position: relative; overflow: hidden; }
.hero h1 { margin: 0; font-size: 1.35rem; line-height: 1.3; }
.hero p { margin: 0; opacity: .88; font-size: .9rem; }
.hero .deco { position: absolute; inset-inline-end: 10px; top: -6px; font-size: 5rem; opacity: .1; font-weight: 700; direction: ltr; pointer-events: none; }
.secchip { justify-self: start; display: inline-flex; gap: 8px; align-items: center; background: rgba(255,255,255,.16); color: inherit; border: 0; border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: .85rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: rgba(255,255,255,.12); border-radius: 12px; padding: 8px; text-align: center; }
.stats b { display: block; font-size: 1.35rem; line-height: 1.2; }
.stats span { font-size: .75rem; opacity: .9; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: inherit; }
.hero .bar { background: rgba(255,255,255,.2); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { min-height: 48px; border: 0; border-radius: 14px; background: var(--brand); color: var(--brand-ink); font-weight: 700; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.soft { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.rev { background: var(--rev); color: #fff; }
.btn.ghost-ok { background: var(--ok-soft); color: var(--ok); }
.btn.ghost-rev { background: var(--rev-soft); color: var(--rev); }
.btn .n { background: var(--rev); color: #fff; border-radius: 99px; min-width: 22px; height: 22px; display: inline-grid; place-items: center; font-size: .75rem; padding: 0 6px; }
.searchbox { position: relative; }
.searchbox input { width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding-inline: 44px 14px; }
.searchbox svg { position: absolute; inset-inline-start: 14px; top: 13px; width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
h2.sec-title { margin: 6px 0 -4px; font-size: 1rem; }
.list { display: grid; gap: 8px; }
.row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; text-align: start; box-shadow: var(--shadow); width: 100%; }
.row .ic { width: 44px; height: 44px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 1rem; direction: ltr; font-family: "Times New Roman", serif; font-style: italic; }
.row b { display: block; font-size: .98rem; line-height: 1.35; }
.row small { color: var(--muted); font-size: .8rem; }
.row .bar { margin-top: 6px; }
.row .chev { color: var(--muted); }
[dir="rtl"] .row .chev { transform: scaleX(-1); }

/* ---------- قائمة التمارين ---------- */
.ex { display: grid; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; text-align: start; box-shadow: var(--shadow); width: 100%; position: relative; }
.ex .t { font-weight: 700; direction: ltr; text-align: left; line-height: 1.4; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { font-size: .75rem; border-radius: 99px; padding: 2px 9px; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.tag.l1 { background: var(--ok-soft); color: var(--ok); } .tag.l2 { background: var(--gold-soft); color: var(--gold); } .tag.l3 { background: var(--rev-soft); color: var(--rev); }
.tag.st-ok { background: var(--ok); color: #fff; } .tag.st-rev { background: var(--rev); color: #fff; }

/* ---------- التمرين ---------- */
.ex-head { display: grid; gap: 8px; }
.ex-head h1 { margin: 0; font-size: 1.2rem; line-height: 1.4; direction: ltr; text-align: left; }
.note { background: var(--gold-soft); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: .86rem; }
.content { direction: ltr; text-align: left; font-family: var(--f); min-width: 0; max-width: 100%; overflow-wrap: break-word; overflow-x: clip; overflow-clip-margin: 4px; }
.content .katex { white-space: normal; position: relative; }
.content td .katex, .content th .katex { white-space: nowrap; }
.q, .intro, .qt, .solbox, .hintbox { min-width: 0; }
.content p { margin: 0 0 .6em; }
.content p:last-child { margin-bottom: 0; }
.content ul { margin: 0 0 .6em; padding-left: 20px; }
.content .dm { overflow-x: auto; overflow-y: hidden; padding: 4px 0; margin: 4px 0 8px; }
.content .katex-display { margin: .4em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.content .katex { font-size: 1.06em; }
.content .tw { overflow-x: auto; margin: 6px 0 10px; }
.content table { border-collapse: collapse; min-width: 100%; font-size: .92rem; }
.content th, .content td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; vertical-align: middle; white-space: nowrap; }
.content th { background: var(--surface-2); }
.intro { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.q { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: grid; gap: 10px; box-shadow: var(--shadow); }
.q .qt { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.q .num { background: var(--brand); color: var(--brand-ink); border-radius: 10px; min-width: 34px; height: 30px; padding: 0 8px; display: grid; place-items: center; font-weight: 700; font-size: .85rem; direction: ltr; }
.q .tools { display: flex; gap: 8px; flex-wrap: wrap; }
.q .tools button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 6px 12px; font-weight: 700; font-size: .85rem; }
.q .tools button[aria-expanded="true"] { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.hintbox { background: var(--gold-soft); border-radius: 12px; padding: 10px 12px; font-size: .95rem; }
.solbox { border-inline-start: 4px solid var(--ok); background: var(--ok-soft); border-radius: 4px 12px 12px 4px; padding: 10px 12px; }
.mark { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; display: grid; gap: 6px; }
.foot a, .foot button { color: inherit; background: none; border: 0; text-decoration: underline; font-size: .8rem; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); inset-inline: 0; margin-inline: auto; width: max-content; max-width: 90%; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 40; }

/* اختيار الشعبة */
.picker { display: grid; gap: 10px; }
.picker button { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; text-align: start; border: 1.5px solid var(--line); background: var(--surface); border-radius: 16px; padding: 14px; font-weight: 700; }
.picker button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.picker .ic { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: .9rem; }
.picker small { display: block; color: var(--muted); font-weight: 400; direction: ltr; text-align: start; }

@keyframes in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
