:root {
  --bg: #f6f3ec;
  --card: #fffdf8;
  --ink: #1d2420;
  --muted: #6b726d;
  --line: #e4ded1;
  --accent: #1f5f4a;
  --accent-soft: #e3efe9;
  --gold: #b8862b;
  --danger: #b3412f;
  --good: #2e7d4f;
  --radius: 14px;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ar: "Noto Naskh Arabic", "Amiri", "Geeza Pro", "Traditional Arabic", "Scheherazade New", "Noto Sans Arabic", serif;
  --content-size: 19px;
  --top: calc(56px + env(safe-area-inset-top));
  --bottom: calc(60px + env(safe-area-inset-bottom));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --card: #1b201d; --ink: #e9ece9; --muted: #9aa39d; --line: #2c332f;
    --accent: #5fb592; --accent-soft: #1f2e27; --gold: #d9a94a; --danger: #e0715f; --good: #6cc38f;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 16px; }
body { padding-top: var(--top); padding-bottom: var(--bottom); min-height: 100vh; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- bars ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 10; height: var(--top);
  padding: env(safe-area-inset-top) 8px 0; display: flex; align-items: center; gap: 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; font-size: 18px; margin: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border: 0; background: none; border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: var(--accent); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--accent-soft); }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin: 0 8px; }
.sync-dot.ok { background: var(--good); }
.sync-dot.busy { background: var(--gold); animation: pulse 1s infinite; }
.sync-dot.err { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10; height: var(--bottom); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; position: relative; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }
.badge { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--danger); color: #fff; font-size: 10px;
  min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }

main { max-width: 820px; margin: 0 auto; padding: 16px; }

/* ---------- generic ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.list { display: grid; gap: 10px; }
.row-link { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.row-link:active { transform: scale(.99); }
.row-link .grow { flex: 1; min-width: 0; }
.row-link .t { font-weight: 600; font-size: 17px; }
.row-link .s { color: var(--muted); font-size: 13px; margin-top: 3px; }
.chev { color: var(--muted); width: 18px; height: 18px; flex: none; }
.swatch { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-family: var(--ar); font-size: 22px; flex: none; }
.num { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: none; color: var(--accent); }
.btn.danger { background: none; color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 3px 9px; border-radius: 99px; }
input[type=text], input[type=url], input[type=password], input[type=search], input[type=date], input[type=number], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 11px 12px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
textarea { min-height: 160px; resize: vertical; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; background: var(--accent-soft); padding: 10px; border-radius: 8px; }

/* ---------- Arabic / lesson content ---------- */
.content { font-size: var(--content-size); line-height: 1.85; }
.content, .ar { font-family: var(--ar), var(--ui); }
.content h1, .content h2, .content h3 { font-family: var(--ar), var(--ui); line-height: 1.4; margin: 1.2em 0 .4em; color: var(--accent); }
.content h1 { font-size: 1.35em; } .content h2 { font-size: 1.2em; } .content h3 { font-size: 1.07em; }
.content p { margin: .5em 0; }
.content ul, .content ol { padding-inline-start: 1.4em; margin: .4em 0; }
.content blockquote { margin: .6em 0; padding: .4em 1em; border-inline-start: 4px solid var(--gold); background: color-mix(in srgb, var(--gold) 10%, transparent); border-radius: 6px; }
.content code { background: var(--accent-soft); padding: 0 4px; border-radius: 4px; }
.content mark { background: color-mix(in srgb, var(--gold) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.content table, table.data { border-collapse: collapse; width: 100%; margin: .6em 0; font-size: .9em; }
.content th, .content td, table.data th, table.data td { border: 1px solid var(--line); padding: 6px 10px; text-align: start; }
.content th, table.data th { background: var(--accent-soft); }
.table-wrap { overflow-x: auto; }
.transcript { white-space: pre-wrap; }

/* lesson tabs */
.seg { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px 6px; padding-inline: 16px; scrollbar-width: none; position: sticky; top: var(--top); background: var(--bg); z-index: 5; }
.seg::-webkit-scrollbar { display: none; }
.seg a { flex: none; padding: 8px 14px; border-radius: 99px; text-decoration: none; color: var(--muted); background: var(--card); border: 1px solid var(--line); font-size: 14px; }
.seg a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.seg a i { font-style: normal; opacity: .7; font-size: 12px; margin-inline-start: 3px; }
.lesson-head .t { font-size: 22px; font-weight: 700; font-family: var(--ar), var(--ui); }
.toolbar { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-bottom: 8px; }
.toolbar .btn { padding: 7px 12px; font-size: 14px; }

.points li { margin: .35em 0; }
.diagram { padding: 10px; }
.diagram img { width: 100%; height: auto; display: block; background: #fff; border-radius: 10px; cursor: zoom-in; }
.diagram .cap { margin-top: 8px; }
.verse { border-inline-start: 4px solid var(--gold); }
.verse .text { font-size: 1.25em; line-height: 2.1; }
.verse .src { color: var(--gold); font-size: 14px; margin-top: 4px; font-family: var(--ui); }
.hide-words .w { color: transparent; border-bottom: 2px dotted var(--muted); cursor: pointer; }
.hide-words .w.shown { color: inherit; border-bottom-color: transparent; }
.first-letters .w .rest { color: transparent; }
.first-letters .w.shown .rest { color: inherit; }
.vocab dt { font-weight: 700; color: var(--accent); font-size: 1.1em; }
.vocab dd { margin: 0 0 12px; }
.vocab .ex { color: var(--muted); font-size: .9em; }

/* flashcards */
.flash { min-height: 260px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  cursor: pointer; user-select: none; padding: 28px 20px; position: relative; }
.flash .front { font-size: 1.25em; font-weight: 600; }
.flash .back { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); width: 100%; }
.flash .hint { position: absolute; bottom: 10px; font-size: 12px; color: var(--muted); font-family: var(--ui); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.progress > div { height: 100%; background: var(--accent); transition: width .25s; }
.grade { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grade .again { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.grade .good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.mini-cards .card { padding: 12px 14px; }
.mini-cards .q { font-weight: 600; }

/* quiz */
.opt { display: block; width: 100%; text-align: start; padding: 12px 14px; margin: 8px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-family: var(--ar), var(--ui); font-size: 17px; }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.opt.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.explain { margin-top: 8px; font-size: .92em; color: var(--muted); }

/* search */
.hit .snip { font-family: var(--ar), var(--ui); font-size: 15px; color: var(--muted); margin-top: 6px; }

/* dialog, toast, lightbox */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 460px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { padding: 20px; }
dialog h2 { margin: 0 0 6px; font-size: 19px; }
dialog .btns { justify-content: flex-end; margin-top: 18px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 14px); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; transition: .25s; z-index: 30; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.88); display: grid; place-items: center; padding: 12px; overflow: auto; }
#lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 8px; touch-action: pinch-zoom; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats .card { text-align: center; margin: 0; padding: 12px 6px; }
.stats b { display: block; font-size: 24px; color: var(--accent); }
.stats span { font-size: 12px; color: var(--muted); }
.fab-row { display: flex; gap: 8px; margin: 4px 0 14px; }
.fab-row .btn { flex: 1; }

/* video import */
.chip.warn { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }
.banner { border-inline-start: 4px solid var(--gold); }
.banner.err { border-inline-start-color: var(--danger); }
.banner.ok { border-inline-start-color: var(--good); }
.banner b { display: block; margin-bottom: 2px; }
.ts { font-family: var(--ui); font-size: .72em; color: var(--accent); text-decoration: none; unicode-bidi: isolate;
  background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; margin-inline-end: 6px; vertical-align: middle; }
