/* ===== Fonts ===== */
@font-face {
  font-family: 'Faruma';
  src: local('Faruma'), url('../fonts/Faruma.woff2') format('woff2'), url('../fonts/Faruma.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Book Naskh';
  src: local('KFGQPC Uthman Taha Naskh'), local('KFGQPCUthmanTahaNaskh'), url('../fonts/UthmanTahaNaskh.woff2') format('woff2'), url('../fonts/UthmanTahaNaskh.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'MV Waheed';
  src: local('MV A Waheed'), local('MVAWaheed'), local('MV Waheed'), local('MVWaheed'), url('../fonts/MVWaheed.woff2') format('woff2'), url('../fonts/MVWaheed.ttf') format('truetype');
  font-weight: 100 900; /* already a heavy face: never add fake bold on top */
  font-display: swap;
}

:root {
  --ink: #2a2119;
  --muted: #7a6c5d;
  --bg: #fbf7f0;
  --card: #ffffff;
  --line: #eadfcd;
  --brown: #7b4a22;
  --brown-2: #9a6434;
  --gold: #c9a26b;
  --gold-soft: #f4e9d6;
  --teal: #0d7680;
  --teal-soft: #e3f4f4;
  --red: #b3261e;
  --green: #1d7a3e;
  --green-soft: #e5f4ea;
  --red-soft: #fbe9e7;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .06);
  --thaana: 'Faruma', 'MV Faseyha', 'Noto Sans Thaana', 'FreeSerif', sans-serif;
  --thaana-head: 'MV Waheed', 'Faruma', 'Noto Sans Thaana', 'FreeSerif', sans-serif;
  --arabic: 'Book Naskh', 'Amiri', 'Noto Naskh Arabic', 'Traditional Arabic', 'FreeSerif', serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; font-size: calc(16px * var(--fs, 1)); }
body {
  margin: 0;
  font-family: var(--thaana);
  color: var(--ink);
  background: var(--bg);
  font-size: 1.0625rem;
  line-height: 1.9;
}
a { color: var(--teal); }
img { max-width: 100%; }
.ar, [lang="ar"] { font-family: var(--arabic); font-size: 1.15em; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ===== Header ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(251, 247, 240, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .in {
  max-width: 1040px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--brown); min-width: 0; }
.brand img { width: 38px; height: 38px; object-fit: contain; }
.brand .t1 { font-family: var(--thaana-head); font-size: 1.05rem; line-height: 1.2; white-space: nowrap; }
.brand .t2 { font-family: var(--arabic); font-size: .9rem; color: var(--muted); line-height: 1.2; }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.user-chip .name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn { background: none; border: 0; color: var(--teal); cursor: pointer; padding: 4px 6px; font-size: .9rem; }

main { max-width: 1040px; margin: 0 auto; padding: 18px 16px 80px; }
.crumbs { font-size: .9rem; color: var(--muted); margin: 4px 0 14px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--teal); }

.demo-banner {
  background: #fff6db; color: #6b5200; border-bottom: 1px solid #f0dc9a;
  font-size: .85rem; text-align: center; padding: 4px 12px;
}

/* ===== Buttons & cards ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--brown); color: #fff; border: 0; border-radius: 999px;
  padding: 10px 22px; text-decoration: none; cursor: pointer; font-size: 1rem; line-height: 1.6;
  transition: transform .08s ease, background .15s;
}
.btn:hover { background: var(--brown-2); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--brown); border: 1.5px solid var(--gold); }
.btn.ghost:hover { background: var(--gold-soft); }
.btn.teal { background: var(--teal); }
.btn.small { padding: 6px 14px; font-size: .9rem; }
.btn[disabled] { opacity: .45; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.page-title { font-family: var(--thaana-head); color: var(--brown); font-size: 1.7rem; margin: 6px 0 4px; line-height: 1.5; }
.page-sub { color: var(--muted); margin: 0 0 22px; }

/* ===== Home: levels ===== */
.hero { text-align: center; padding: 18px 0 8px; }
.hero img { width: 92px; }
.hero h1 { font-family: var(--thaana-head); color: var(--brown); font-size: 2rem; margin: 8px 0 0; line-height: 1.5; }
.hero .ar-title { font-family: var(--arabic); font-size: 1.5rem; color: var(--brown-2); }
.hero p { color: var(--muted); margin: 6px 0 0; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-top: 26px; }
.level {
  position: relative; display: block; text-decoration: none; color: inherit;
  padding: 22px 18px 18px; text-align: center; overflow: hidden;
}
.level .num {
  width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 50%;
  display: grid; place-items: center; font-family: system-ui, sans-serif; font-weight: 700; font-size: 1.7rem;
  background: var(--gold-soft); color: var(--brown); border: 2px solid var(--gold);
}
.level .lt { font-family: var(--thaana-head); font-size: 1.15rem; color: var(--brown); }
.level .ls { font-size: .85rem; color: var(--muted); }
.level.open:hover { border-color: var(--gold); transform: translateY(-2px); }
.level { transition: transform .15s, border-color .15s; }
.level.soon { opacity: .55; cursor: not-allowed; }
.level .tag { position: absolute; top: 10px; left: 10px; font-size: .7rem; background: var(--line); color: var(--muted); border-radius: 999px; padding: 0 8px; }

/* ===== Level: choice ===== */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 10px; }
.choice { display: flex; gap: 16px; align-items: center; padding: 22px; text-decoration: none; color: inherit; transition: transform .15s, border-color .15s; }
.choice:hover { transform: translateY(-2px); border-color: var(--gold); }
.choice .ic { width: 64px; height: 64px; flex: none; border-radius: 18px; display: grid; place-items: center; }
.choice .ic svg { width: 34px; height: 34px; }
.choice.study .ic { background: var(--gold-soft); color: var(--brown); }
.choice.practice .ic { background: var(--teal-soft); color: var(--teal); }
.choice h3 { margin: 0; font-family: var(--thaana-head); font-size: 1.3rem; color: var(--brown); line-height: 1.5; }
.choice.practice h3 { color: var(--teal); }
.choice p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; line-height: 1.7; }

/* ===== Lesson list ===== */
.lesson-list { display: grid; gap: 10px; }
.lesson-item { display: flex; gap: 14px; align-items: center; padding: 14px 16px; text-decoration: none; color: inherit; }
.lesson-item:hover { border-color: var(--gold); }
.lesson-item .n { width: 44px; height: 44px; flex: none; border-radius: 12px; background: var(--gold-soft); color: var(--brown); display: grid; place-items: center; font-weight: 700; font-family: system-ui, sans-serif; }
.lesson-item .lt { font-family: var(--thaana-head); color: var(--brown); line-height: 1.5; }
.lesson-item .lt .ar { font-size: 1.2em; }
.lesson-item .ls { color: var(--muted); font-size: .85rem; line-height: 1.6; }
.lesson-item .done { margin-inline-start: auto; color: var(--green); font-size: .8rem; white-space: nowrap; }

/* ===== Lesson page ===== */
.lesson-head { text-align: center; margin: 4px 0 18px; }
.lesson-head .k { color: var(--muted); font-size: .95rem; }
.lesson-head .k .ar { font-size: 1.1em; }
.lesson-head h1 { margin: 2px 0; color: var(--brown); font-size: 2rem; line-height: 1.6; font-weight: 700; }
.lesson-head h1 .ar { font-size: 1.25em; }
.toc { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0 0; padding: 0; list-style: none; }
.toc a { display: inline-block; font-size: .85rem; text-decoration: none; color: var(--brown); background: var(--gold-soft); border-radius: 999px; padding: 2px 12px; line-height: 1.9; }
.toc a .ar { font-size: 1.05em; }
.toc a.ex { background: var(--teal-soft); color: var(--teal); }

.lesson { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px clamp(14px, 4vw, 40px) 30px; }
.lesson p.p { margin: 0 0 .75em; text-align: justify; line-height: 2.15; font-size: 1.08rem; }
.lesson p.p.indent { text-indent: 1.4em; }
.lesson p.p .ar { font-size: 1.2em; }
.lesson p.num { padding-inline-start: 2.2em; text-indent: -2.2em !important; }
.lesson .np { display: inline-block; min-width: 2.2em; text-indent: 0; }
.lesson h2 {
  font-family: var(--thaana-head); color: var(--red); font-size: 1.3rem; line-height: 1.7;
  margin: 1.6em 0 .5em; padding-bottom: 4px; border-bottom: 2px solid var(--red-soft); scroll-margin-top: 70px;
}
.lesson h2 .ar { font-size: 1.25em; font-weight: 700; }
.lesson .tab { display: inline-block; width: 2.2em; }
.lesson .frame { border: 2px solid var(--fc, #4472c4); border-radius: 14px; padding: 14px 16px 4px; margin: 1em 0 1.2em; }

/* figures rebuilt from the book's diagrams */
.fig { margin: 1.1em auto 1.3em; width: 100%; max-width: calc(var(--w) * 1px); }
.fig .stage { position: relative; width: 100%; height: 0; container-type: inline-size; }
.fig.scene { max-width: 640px; }
.shp { position: absolute; display: flex; flex-direction: column; overflow: visible; margin: 0; }
img.shp { object-fit: fill; display: block; }
.shp-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.sp { white-space: pre-wrap; line-height: 1.32; font-family: var(--thaana); }
.sp .ar, .stp .ar { font-size: 1.12em; line-height: 1.3; }
.stp { position: absolute; left: 0; right: 0; white-space: pre-wrap; margin: 0; }
.fig-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.fig-wrap.zoom .fig { width: 640px; max-width: none; }
@media (max-width: 700px) { .fig-wrap .fig { cursor: zoom-in; } .fig-wrap.zoom .fig { cursor: zoom-out; } }

.pic { text-align: center; margin: 1em 0; }

/* exercise call-outs inside lessons */
.ex-card {
  margin: 1.4em 0; padding: 14px 16px; border-radius: 14px;
  background: var(--teal-soft); border: 1.5px solid #9fd4d6;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; scroll-margin-top: 70px;
}
.ex-label { font-weight: 700; color: var(--teal); }
.ex-label .ar { font-size: 1.15em; }
.ex-body { flex: 1 1 100%; color: var(--ink); font-size: .95rem; line-height: 1.9; }
.ex-body:empty { display: none; }
.ex-go { margin-inline-start: auto; background: var(--teal); }
.ex-go:hover { background: #0b636b; }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 1em 0; }
.tbl { border-collapse: collapse; width: 100%; background: #fff; }
.tbl td { border: 1px solid var(--line); padding: 6px 10px; vertical-align: middle; }
.tbl td p.p { margin: 0; text-align: inherit; line-height: 1.8; }
.tbl tr:first-child td { background: var(--gold-soft); font-weight: 700; }

.vocab h2 { color: var(--brown); border-color: var(--gold-soft); }

.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; }

/* ===== Forms / auth ===== */
.auth-wrap { max-width: 440px; margin: 20px auto; padding: 26px 24px; }
.auth-wrap h1 { font-family: var(--thaana-head); color: var(--brown); margin: 0 0 4px; font-size: 1.6rem; text-align: center; }
.auth-wrap .sub { text-align: center; color: var(--muted); margin: 0 0 16px; font-size: .95rem; }
.field { margin: 0 0 14px; }
.field label { display: block; font-size: .92rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.field input.ltr { direction: ltr; text-align: left; font-family: system-ui, sans-serif; }
.field .hint { font-size: .8rem; color: var(--muted); }
.msg { border-radius: 12px; padding: 8px 12px; font-size: .92rem; margin: 0 0 12px; }
.msg.err { background: var(--red-soft); color: var(--red); }
.msg.ok { background: var(--green-soft); color: var(--green); }
.auth-alt { text-align: center; margin-top: 14px; font-size: .92rem; }

/* ===== Practice ===== */
.set-group { margin: 0 0 18px; }
.set-group h2 { font-size: 1.1rem; color: var(--brown); margin: 0 0 8px; font-family: var(--thaana-head); line-height: 1.6; }
.set-group h2 .ar { font-size: 1.15em; }
.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.set { display: block; padding: 12px 14px; text-decoration: none; color: inherit; }
.set:hover { border-color: #9fd4d6; }
.set .st { color: var(--teal); font-weight: 700; line-height: 1.6; }
.set .st .ar { font-size: 1.1em; }
.set .sm { font-size: .82rem; color: var(--muted); }
.set .best { font-size: .8rem; color: var(--green); }
.set.new-set { border-style: dashed; }
.pill { display: inline-block; font-size: .72rem; border-radius: 999px; padding: 0 8px; background: var(--gold-soft); color: var(--brown); margin-inline-start: 4px; }

.quiz-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.quiz-head h1 { font-size: 1.25rem; margin: 0; color: var(--teal); line-height: 1.6; }
.quiz-head h1 .ar { font-size: 1.15em; }
.progress { flex: 1 1 100%; height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--teal); width: 0; transition: width .3s; }
.q-card { padding: 20px clamp(14px, 4vw, 28px); }
.q-meta { font-size: .82rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.q-instr { margin: 4px 0 10px; color: var(--muted); font-size: .98rem; line-height: 1.9; }
.q-instr .ar { font-size: 1.1em; }
.q-prompt { font-size: 1.15rem; line-height: 2.2; margin: 6px 0 14px; }
.q-prompt .ar { font-size: 1.45em; }
.q-prompt .blank { display: inline-block; min-width: 4.5em; border-bottom: 2px dashed var(--teal); margin: 0 .2em; text-align: center; color: var(--teal); }
.q-prompt u { text-decoration-color: var(--red); text-decoration-thickness: 2px; text-underline-offset: 6px; }
.opts { display: grid; gap: 8px; }
.opts.cols { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.opt {
  display: flex; align-items: center; gap: 10px; text-align: start; width: 100%;
  padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; line-height: 1.7;
}
.opt .ar { font-size: 1.3em; }
.opt:hover { border-color: #9fd4d6; }
.opt.sel { border-color: var(--teal); background: var(--teal-soft); }
.opt.right { border-color: var(--green); background: var(--green-soft); }
.opt.wrong { border-color: var(--red); background: var(--red-soft); }
.opt .mark { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 2px solid var(--line); }
.opt.sel .mark { border-color: var(--teal); background: radial-gradient(var(--teal) 45%, transparent 50%); }
.opt.multi .mark { border-radius: 6px; }
.opt.multi.sel .mark { background: var(--teal); }
.q-input { width: 100%; padding: 10px 14px; font-size: 1.2rem; border: 1.5px solid var(--line); border-radius: 12px; }
.q-input.ar-in { font-family: var(--arabic); font-size: 1.5rem; }
.q-input.right { border-color: var(--green); background: var(--green-soft); }
.q-input.wrong { border-color: var(--red); background: var(--red-soft); }
textarea.q-input { min-height: 110px; line-height: 1.8; }
.tokens { display: flex; flex-wrap: wrap; gap: 8px; direction: rtl; margin: 8px 0 4px; }
.token { font-family: var(--arabic); font-size: 1.45rem; padding: 2px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; line-height: 1.9; position: relative; }
.token:hover { border-color: #9fd4d6; }
.token .lab { position: absolute; top: -12px; inset-inline-start: 8px; font-family: var(--arabic); font-size: .72rem; line-height: 1.4; padding: 0 6px; border-radius: 999px; color: #fff; }
.token.right { border-color: var(--green); background: var(--green-soft); }
.token.wrong { border-color: var(--red); background: var(--red-soft); }
.token.should { outline: 2px dashed var(--green); outline-offset: 2px; }
.labels { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.labelbtn { border: 2px solid var(--c); color: var(--c); background: #fff; border-radius: 999px; padding: 2px 14px; cursor: pointer; font-family: var(--arabic); font-size: 1.1rem; line-height: 1.8; }
.labelbtn.on { background: var(--c); color: #fff; }
.labelbtn small { font-family: var(--thaana); font-size: .75rem; }
.match-row { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; flex-wrap: wrap; }
.match-row .left { flex: 1 1 160px; padding: 8px 12px; background: var(--gold-soft); border-radius: 12px; }
.match-row select { flex: 1 1 160px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; }
.match-row select.right { border-color: var(--green); background: var(--green-soft); }
.match-row select.wrong { border-color: var(--red); background: var(--red-soft); }
.feedback { margin-top: 14px; border-radius: 12px; padding: 10px 14px; line-height: 1.9; }
.feedback.ok { background: var(--green-soft); color: var(--green); }
.feedback.no { background: var(--red-soft); color: var(--red); }
.feedback.info { background: var(--gold-soft); color: var(--brown); }
.feedback .ans { color: var(--ink); }
.feedback .ans .ar { font-size: 1.3em; }
.feedback .why { color: var(--ink); font-size: .92rem; margin-top: 4px; }
.q-actions { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; flex-wrap: wrap; }
.result { text-align: center; padding: 26px 18px; }
.result .score { font-family: system-ui, sans-serif; font-size: 3rem; font-weight: 800; color: var(--teal); line-height: 1.2; }
.result .stars { font-size: 1.4rem; letter-spacing: 4px; color: var(--gold); }
.review-list { margin-top: 18px; text-align: start; display: grid; gap: 8px; }
.review-item { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: .95rem; }
.review-item.ok { border-color: #b8dfc4; }
.review-item.no { border-color: #f1c0bb; }
.review-item.pending { border-color: #ecd9b0; }
.review-item .ar { font-size: 1.2em; }

/* ===== Teacher ===== */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 14px; }
.tabs button { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 16px; cursor: pointer; }
.tabs button.on { background: var(--brown); border-color: var(--brown); color: #fff; }
.panel { padding: 16px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { padding: 12px 14px; }
.stat .v { font-family: system-ui, sans-serif; font-size: 1.6rem; font-weight: 800; color: var(--brown); line-height: 1.3; }
.stat .k { font-size: .85rem; color: var(--muted); }
.dt { width: 100%; border-collapse: collapse; font-size: .92rem; }
.dt th, .dt td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: start; vertical-align: top; }
.dt th { color: var(--muted); font-weight: 400; font-size: .82rem; }
.dt td.num, .dt th.num { font-family: system-ui, sans-serif; direction: ltr; text-align: center; }
.dt tr.click { cursor: pointer; }
.dt tr.click:hover td { background: var(--gold-soft); }
.badge { display: inline-block; font-size: .75rem; border-radius: 999px; padding: 0 8px; }
.badge.g { background: var(--green-soft); color: var(--green); }
.badge.r { background: var(--red-soft); color: var(--red); }
.badge.y { background: #fff3d6; color: #8a6200; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar input, .toolbar select { padding: 6px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; }
.code { font-family: ui-monospace, monospace; direction: ltr; unicode-bidi: isolate; background: var(--gold-soft); border-radius: 8px; padding: 0 8px; }
.editor-q { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fffdf9; }
.editor-q .row { display: flex; gap: 8px; flex-wrap: wrap; }
.editor-q .row > * { flex: 1 1 160px; }
.muted { color: var(--muted); }
.hide { display: none !important; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

@media (max-width: 560px) {
  body { font-size: 1rem; }
  .brand .t2 { display: none; }
  .lesson-head h1 { font-size: 1.6rem; }
  .lesson { padding: 16px 12px 22px; border-radius: 12px; }
  .lesson p.p { font-size: 1.02rem; text-align: right; }
  .fig { min-width: 0; }
}
@media print {
  .topbar, .ex-go, .pager, .demo-banner { display: none; }
  .lesson { box-shadow: none; border: 0; }
}

/* ===== header tools ===== */
.hdr-tools { display: inline-flex; gap: 2px; align-items: center; }
.iconbtn { display: inline-grid; place-items: center; min-width: 32px; height: 32px; border-radius: 10px; border: 1px solid transparent; background: none; color: var(--brown); cursor: pointer; text-decoration: none; padding: 0 6px; }
.iconbtn:hover { background: var(--gold-soft); }
.user-chip a.name { color: var(--muted); text-decoration: none; }
.user-chip a.name:hover { color: var(--teal); }
@media (max-width: 560px) { .user-chip .name { max-width: 70px; } .user-chip { gap: 2px; } }

/* ===== announcements & homework ===== */
.announce { background: #fff6db; border: 1px solid #f0dc9a; color: #5c4700; border-radius: 12px; padding: 8px 14px; margin: 0 0 10px; }
.hw-card { padding: 12px 14px; margin-bottom: 8px; }
.hw-card.done { opacity: .75; }
.hw-top { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.hw-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill-link { font-size: .85rem; text-decoration: none; background: var(--teal-soft); color: var(--teal); border-radius: 999px; padding: 2px 12px; }
.pill-link.ok { background: var(--green-soft); color: var(--green); }
.hw-pick { display: grid; gap: 6px; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; padding: 8px; background: #fff; }
.chip { display: inline-flex; align-items: center; gap: 4px; margin: 2px 4px; font-size: .85rem; background: var(--gold-soft); border-radius: 999px; padding: 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ===== practice tools ===== */
.tools, .mini-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 6px 0 10px; }
.mini-choices { margin-top: 16px; }
.tool { display: flex; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; color: inherit; text-align: start; font: inherit; cursor: pointer; }
.tool:hover { border-color: var(--gold); }
.tool .ti { font-size: 1.6rem; }
.tool b { display: block; color: var(--brown); line-height: 1.5; }
.tool small { color: var(--muted); font-size: .8rem; line-height: 1.5; }
.linklike { color: var(--teal); text-decoration: underline; }
.set { position: relative; padding: 0; }
.set-main { display: block; padding: 12px 14px; text-decoration: none; color: inherit; }
.set-print { position: absolute; top: 8px; left: 10px; text-decoration: none; opacity: .5; font-size: .95rem; }
.set-print:hover { opacity: 1; }
.timer { font-family: system-ui, sans-serif; font-weight: 700; color: var(--teal); background: var(--teal-soft); border-radius: 999px; padding: 2px 12px; direction: ltr; }
.timer.low { color: var(--red); background: var(--red-soft); }
.say { border: 0; background: var(--gold-soft); border-radius: 999px; cursor: pointer; padding: 0 8px; margin-inline-start: 8px; font-size: .9rem; vertical-align: middle; }

/* build (i'rab) */
.build-line { min-height: 56px; border: 2px dashed #9fd4d6; border-radius: 12px; padding: 6px; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px; direction: rtl; background: #fff; }
.build-line.right { border-color: var(--green); border-style: solid; background: var(--green-soft); }
.build-line.wrong { border-color: var(--red); border-style: solid; background: var(--red-soft); }
.build-pool { display: flex; flex-wrap: wrap; gap: 6px; direction: rtl; }
.piece { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 2px 12px; cursor: pointer; line-height: 1.9; }
.piece .ar { font-size: 1.25em; }
.piece.in { background: var(--teal-soft); border-color: #9fd4d6; }
.piece.used { visibility: hidden; }

/* ===== flashcards ===== */
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 4px 14px; cursor: pointer; }
.seg button.on { background: var(--brown); color: #fff; }
.boxes { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 14px; }
.lbox { flex: 1 1 60px; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px; line-height: 1.4; }
.lbox b { display: block; font-family: system-ui, sans-serif; font-size: 1.2rem; color: var(--brown); }
.lbox small { font-size: .72rem; color: var(--muted); }
.lbox.b5 b { color: var(--green); }
.fc-meta { text-align: center; color: var(--muted); font-size: .85rem; }
.flashcard { margin: 8px auto 4px; max-width: 520px; min-height: 230px; background: #fff; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); display: grid; place-items: center; text-align: center; padding: 24px; cursor: pointer; transition: transform .25s; }
.flashcard.flipped { background: #fffdf7; border-color: var(--gold); }
.flashcard hr { border: 0; border-top: 1px dashed var(--gold); width: 60%; margin: 12px auto; }
.fc-ar { font-family: var(--arabic); font-size: 2.6rem; line-height: 1.6; color: var(--brown); }
.fc-dv { font-size: 1.35rem; line-height: 1.8; }
.fc-hint { color: var(--muted); font-size: .8rem; margin-top: 10px; }
.flashcard + .q-actions { max-width: 520px; margin: 12px auto 0; }

/* ===== progress & certificate ===== */
.sub-h { font-family: var(--thaana-head); color: var(--brown); font-size: 1.15rem; margin: 20px 0 8px; line-height: 1.6; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.badge-card { text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; filter: grayscale(1); opacity: .45; line-height: 1.5; }
.badge-card span { font-size: 1.8rem; display: block; }
.badge-card small { font-size: .78rem; }
.badge-card.on { filter: none; opacity: 1; border-color: var(--gold); background: #fffaf0; }
.bar { display: inline-block; width: 110px; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-inline-end: 6px; }
.bar > i { display: block; height: 100%; background: var(--teal); }
.certificate { max-width: 820px; margin: 16px auto; background: #fffdf7; border: 10px double var(--gold); padding: 10px; }
.cert-in { border: 2px solid var(--brown); padding: 36px 30px; text-align: center; }
.cert-logo { width: 90px; }
.cert-ar { font-family: var(--arabic); font-size: 2.4rem; color: var(--brown); line-height: 1.6; }
.cert-dv { font-family: var(--thaana-head); font-size: 1.3rem; color: var(--brown-2); }
.cert-name { font-family: var(--thaana-head); font-size: 2rem; color: var(--teal); border-bottom: 2px solid var(--gold); display: inline-block; padding: 0 30px; margin: 6px 0 12px; }
.cert-foot { display: flex; justify-content: space-between; margin-top: 30px; color: var(--muted); }

/* ===== lesson extras ===== */
.listen-fab { position: fixed; bottom: 18px; left: 18px; z-index: 30; border: 0; border-radius: 999px; background: var(--brown); color: #fff; box-shadow: var(--shadow); padding: 10px 16px; font-size: 1.05rem; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.listen-fab span { font-size: .85rem; }
.listen-fab.on { background: var(--teal); }
body.listen .sayable { cursor: pointer; border-radius: 6px; box-shadow: 0 0 0 2px rgba(13, 118, 128, .18); }
body.listen .sayable:hover { background: var(--teal-soft); }
.sayable.saying { background: #c9eef0 !important; }
.toast { position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%); background: #2a2119; color: #fff; padding: 8px 16px; border-radius: 12px; z-index: 40; font-size: .9rem; max-width: 90vw; }
.ask-btn { border: 0; background: none; cursor: pointer; font-size: .85rem; opacity: .45; margin-inline-start: 6px; vertical-align: middle; }
.ask-btn:hover { opacity: 1; }
.qa { margin-top: 30px; border-top: 2px solid var(--gold-soft); padding-top: 6px; }
.qa h2 { color: var(--brown); border-color: var(--gold-soft); }
.qa-item { background: #fffdf7; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; line-height: 1.9; }
.qa-ans { color: var(--teal); }
.qa-form { display: grid; gap: 8px; margin-top: 10px; }
.qa-form select, .qa-form textarea { border: 1.5px solid var(--line); border-radius: 12px; padding: 8px 12px; background: #fff; }

/* ===== search ===== */
.search-results { display: grid; gap: 8px; }
.search-hit { display: block; padding: 10px 14px; text-decoration: none; color: inherit; }
.search-hit .snip { color: var(--muted); font-size: .92rem; line-height: 1.9; }
.search-hit mark, .snip mark { background: #ffe9a8; color: inherit; border-radius: 4px; }
.gloss td { vertical-align: middle; }
.ar-cell { font-family: var(--arabic); font-size: 1.25rem; white-space: nowrap; }

/* ===== teacher extras ===== */
.rec-row { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.rec-row .rec-t { flex: 1; }
.rec-row.has { background: var(--green-soft); }
.rec-row.busy { opacity: .5; }
.iconbtn.rec { color: var(--red); }
.iconbtn.rec.on { background: var(--red); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

/* ===== printable worksheet ===== */
.worksheet { background: #fff; max-width: 820px; margin: 10px auto; padding: 28px 32px; border: 1px solid var(--line); }
.ws-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--brown); padding-bottom: 8px; margin-bottom: 12px; }
.ws-name { white-space: nowrap; }
.ws-blank { display: inline-block; min-width: 160px; border-bottom: 1px dotted #555; }
.ws-blank.short { min-width: 100px; }
.ws-main-instr { background: var(--gold-soft); padding: 6px 12px; border-radius: 8px; margin-bottom: 10px; }
.ws-q { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #eee; break-inside: avoid; }
.ws-n { font-weight: 700; min-width: 26px; }
.ws-b { flex: 1; }
.ws-prompt { font-size: 1.1rem; line-height: 2.2; }
.ws-prompt .ar { font-size: 1.35em; }
.ws-instr { color: var(--muted); font-size: .9rem; }
.ws-opts { display: flex; flex-wrap: wrap; gap: 6px 24px; margin-top: 4px; }
.ws-opts .ar { font-size: 1.2em; }
.ws-piece { border: 1px solid #bbb; border-radius: 6px; padding: 0 8px; }
.ws-line { border-bottom: 1px dotted #555; height: 2.2em; }
.ws-fill { margin-top: 4px; }
.ws-match td { padding: 4px 10px; }
.ws-key { margin-top: 20px; border-top: 2px dashed var(--brown); padding-top: 8px; break-before: page; }
@media print {
  body { background: #fff; }
  .no-print, .listen-fab, .toast, .topbar, .crumbs { display: none !important; }
  main { padding: 0; max-width: none; }
  .worksheet { border: 0; padding: 0; max-width: none; }
  .certificate { margin: 0 auto; }
}
