:root {
  --bg: #eef0f3; --surface: #fff; --surface-2: #f6f7f9; --text: #23262d; --muted: #6b7180; --border: #dfe2e8;
  --brand: #c49a6c; --brand-dark: #a87d52; --brand-soft: #f5ece2; --slate: #4b4f5a; --slate-dark: #3c4049;
  --page: #fffdf8; --page-border: #e9dcc8; --ink: #1f1d1a;
  --ok: #2f8f5b; --ok-soft: #e3f3ea; --bad: #c2453d; --bad-soft: #fbe7e5; --warn: #b7791f;
  --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 8px 24px -14px rgb(0 0 0 / .25);
  color-scheme: light;
}
:root.dark {
  --bg: #1b1d22; --surface: #24272e; --surface-2: #2b2e36; --text: #eceef2; --muted: #a2a8b5; --border: #393d47;
  --brand-soft: #3a2f24; --page: #22252b; --page-border: #3b3f48; --ink: #f2efe8; --ok-soft: #1f3a2b; --bad-soft: #42221f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "IBM Plex Sans Arabic", system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand-dark); }
:root.dark a { color: var(--brand); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 1rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.top { background: var(--slate); color: #fff; position: sticky; top: 0; z-index: 20; }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 64px; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff !important; text-decoration: none; }
.brand img { border-radius: 10px; background: #fff; object-fit: contain; }
.brand b { display: block; font-size: 1.05rem; line-height: 1.2; }
.brand small { color: #e3c7a4; font-size: .75rem; }
.top-nav { display: flex; gap: .5rem; align-items: center; }
.icon-btn { width: 2.4rem; height: 2.4rem; border-radius: 10px; border: 1px solid rgb(255 255 255 / .25); background: transparent; color: #fff; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 1.1rem; height: 1.1rem; }
.link-btn { color: #fff !important; text-decoration: none; border: 1px solid rgb(255 255 255 / .25); border-radius: 10px; padding: .4rem .85rem; font-size: .9rem; }

main { padding-top: 1.25rem; padding-bottom: 3rem; }
.loading { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }

/* حساب الطالب */
.account { border-inline-start: 4px solid var(--brand); }
.acc-guest summary { cursor: pointer; line-height: 1.7; }
.acc-guest summary .muted { font-size: .88rem; }
.acc-guest[open] summary { margin-bottom: .7rem; }
.acc-guest .acc-note { display: block; margin-top: .5rem; }
.acc-text { display: grid; gap: .1rem; min-width: 0; }
.acc-text b { font-size: 1.05rem; }
.acc-text .muted { font-size: .88rem; }
.acc-form { display: flex; gap: .5rem; }
.acc-form input { width: 11rem; text-align: center; letter-spacing: .12em; font-weight: 700; text-transform: uppercase; }
.acc-note { font-size: .8rem; }
.acc-user { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.acc-user .acc-text { flex: 1; }
.avatar { width: 2.6rem; height: 2.6rem; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; flex: none; }
.sync { font-size: .8rem; font-weight: 600; color: var(--ok); background: var(--ok-soft); border-radius: 99px; padding: .2rem .7rem; }
.sync.off { color: var(--warn); background: var(--surface-2); }

/* الإحصاءات */
.stats-title { font-size: 1.05rem; margin: 1.75rem 0 .6rem; }
.stats { display: grid; gap: 1rem; }
.stats-top { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 640px) { .stats-top { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface-2); border-radius: 12px; padding: .6rem .8rem; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.25; }
.stat span { font-size: .8rem; color: var(--muted); }
.juz-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; direction: rtl; }
@media (max-width: 480px) { .juz-grid { grid-template-columns: repeat(6, 1fr); } }
.juz-cell { position: relative; aspect-ratio: 1.6; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: .72rem; display: grid; place-items: center; overflow: hidden; cursor: pointer; padding: 0; }
.juz-cell i { position: absolute; inset: auto 0 0 0; background: color-mix(in srgb, var(--brand) 70%, transparent); }
.juz-cell span { position: relative; font-weight: 600; }
.juz-legend { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }

/* الاختيار */
.tabs { display: flex; gap: .35rem; margin-bottom: .85rem; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 99px; padding: .35rem .95rem; cursor: pointer; font-weight: 600; font-size: .9rem; }
.tabs button[aria-selected="true"] { background: var(--slate); color: #fff; border-color: var(--slate); }
.badge { display: inline-block; min-width: 1.4rem; padding: 0 .35rem; border-radius: 99px; background: var(--bad); color: #fff; font-size: .75rem; }
.pick { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .pick { grid-template-columns: 2fr 1fr 1fr; } }
label { display: grid; gap: .25rem; }
label > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
select, input { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: .5rem .7rem; min-height: 2.6rem; }
select:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); border-color: var(--brand); }

/* الأوضاع */
.modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: 1rem; }
@media (min-width: 720px) { .modes { grid-template-columns: repeat(4, 1fr); } }
.modes button { text-align: start; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: .7rem .9rem; cursor: pointer; box-shadow: var(--shadow); }
.modes button b { display: block; }
.modes button small { color: var(--muted); font-size: .8rem; }
.modes button[aria-selected="true"] { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; border-color: transparent; }
.modes button[aria-selected="true"] small { color: rgb(255 255 255 / .85); }

.audio-bar { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; align-items: end; }
@media (min-width: 720px) { .audio-bar { grid-template-columns: 2fr 1fr auto; } }
.audio-actions { display: flex; gap: .5rem; grid-column: 1 / -1; }
@media (min-width: 720px) { .audio-actions { grid-column: auto; } }
.btn { border: 1px solid transparent; border-radius: 10px; padding: .55rem 1rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.tools { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }

/* المصحف */
.mushaf { background: var(--page); border: 1px solid var(--page-border); border-radius: 18px; padding: 1.5rem 1.25rem; box-shadow: var(--shadow); position: relative; }
.mushaf::before { content: ""; position: absolute; inset: 8px; border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent); border-radius: 12px; pointer-events: none; }
.sura-head { text-align: center; margin: .25rem 0 1rem; }
.sura-title { display: inline-block; padding: .35rem 2.2rem; border-radius: 99px; background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 45%, transparent); color: var(--brand-dark); font-weight: 700; font-size: 1.05rem; }
:root.dark .sura-title { color: var(--brand); }
.basmala { font-family: "Amiri Quran", "Amiri", serif; font-size: 1.7rem; text-align: center; margin: .6rem 0 .2rem; color: var(--ink); }
.ayat { font-family: "Amiri Quran", "Amiri", serif; font-size: clamp(1.45rem, 3.6vw, 2rem); line-height: 2.35; color: var(--ink); text-align: justify; text-align-last: center; word-spacing: .05em; }
.ayah { border-radius: 8px; padding: 0 .1em; transition: background .2s; cursor: pointer; }
.ayah:hover { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.ayah.playing { background: color-mix(in srgb, var(--brand) 22%, transparent); }
.ayah.err { text-decoration: underline wavy color-mix(in srgb, var(--bad) 60%, transparent); text-underline-offset: .45em; }
.w { border-radius: 6px; transition: background .2s, color .2s; }
.w.hid { color: transparent; cursor: pointer; user-select: none;
  background: linear-gradient(transparent 30%, color-mix(in srgb, var(--muted) 24%, transparent) 30%, color-mix(in srgb, var(--muted) 24%, transparent) 72%, transparent 72%); }
.w.hid:hover { background: linear-gradient(transparent 30%, color-mix(in srgb, var(--brand) 40%, transparent) 30%, color-mix(in srgb, var(--brand) 40%, transparent) 72%, transparent 72%); }
.w.hint { color: transparent; position: relative; }
.w.hint::before { content: attr(data-h) "…"; position: absolute; inset-inline-start: 0; color: var(--brand-dark); }
:root.dark .w.hint::before { color: var(--brand); }
.num { display: inline-grid; place-items: center; min-width: 1.9em; height: 1.9em; margin: 0 .15em; font-family: "IBM Plex Sans Arabic", sans-serif; font-size: .5em; font-weight: 700; color: var(--brand-dark); border: 1.5px solid var(--brand); border-radius: 50%; vertical-align: middle; line-height: 1; }
:root.dark .num { color: var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; font-family: "IBM Plex Sans Arabic", sans-serif; font-size: 1rem; }

/* الاختبار */
.test { text-align: center; }
.test .q-meta { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.test .q-progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-bottom: 1rem; }
.test .q-progress i { display: block; height: 100%; background: var(--brand); transition: width .3s; }
.test .q-text { font-family: "Amiri Quran", "Amiri", serif; font-size: clamp(1.5rem, 4vw, 2.1rem); line-height: 2.3; min-height: 5rem; margin: .5rem 0 1rem; }
.test .q-text .rest { color: transparent; background: color-mix(in srgb, var(--muted) 18%, transparent); border-radius: 8px; }
.test .q-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.test .q-actions .btn { min-width: 8rem; padding: .7rem 1.2rem; }
.result-big { font-size: 2.6rem; font-weight: 700; color: var(--brand-dark); }
.result-list { text-align: start; margin: 1rem 0; display: grid; gap: .35rem; }
.result-list span { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: .2rem .6rem; font-size: .9rem; display: inline-block; }

.credit { font-size: .8rem; color: var(--muted); text-align: center; margin-top: 1.5rem; }
.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translate(-50%, 150%); background: var(--slate-dark); color: #fff; padding: .65rem 1.1rem; border-radius: 12px; opacity: 0; transition: .25s; z-index: 50; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
