@import url("/static/css/fonts.css");

/* ============ tokens ============ */
:root {
  --brand: #0b6b4f; --brand-dark: #085340; --brand-soft: #e6f4ee; --brand-ring: rgba(11, 107, 79, .22);
  --ink: #1a1d21; --muted: #5b6470; --line: #e2e6ea; --page: #f4f6f8; --card: #fff;
  --paper-line: #333; --soft: #e8e8e8; --danger: #a12727; --danger-soft: #fde8e8;
  --radius: 14px; --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
  /* kept for the exam/quiz renderers */
  --accent: var(--brand); --accent-soft: var(--brand-soft);
  --font-scale: 1;   /* set by static/js/prefs.js */
  --font-body: "Simplified Arabic", "Noto Naskh Arabic", "Traditional Arabic", serif;
}
html { font-size: calc(18px * var(--font-scale)); -webkit-text-size-adjust: 100%; }
@media (max-width: 480px) { html { font-size: calc(16.5px * var(--font-scale)); } }
@page { size: A4; margin: 15mm; }
* { box-sizing: border-box; }
body { font-family: var(--font-body); font-size: 1.125rem; line-height: 1.7; color: var(--ink); background: var(--page); margin: 0; }
.n, .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.n { font-family: var(--font-body); }
.ltr-row { direction: ltr; }
.center { text-align: center; margin: 4px 0; }
.hint { color: var(--muted); font-size: .95rem; }
[hidden] { display: none !important; }

/* ============ buttons ============ */
button, .btn { font: inherit; font-size: 1rem; border: 1.5px solid transparent; border-radius: 10px; padding: .4rem 1.1rem; min-height: 44px;
  cursor: pointer; background: var(--brand); color: #fff; text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; gap: .4rem; transition: background .15s, border-color .15s, box-shadow .15s; }
button:hover, .btn:hover { background: var(--brand-dark); }
button:focus-visible, .btn:focus-visible, input:focus-visible { outline: 3px solid var(--brand-ring); outline-offset: 2px; }
button.secondary, .btn.secondary, .btn.ghost, button.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
button.secondary:hover, .btn.secondary:hover, .btn.ghost:hover, button.ghost:hover { background: var(--page); border-color: #cbd2d9; }
button:disabled { opacity: .5; cursor: not-allowed; }
.notice { max-width: 210mm; margin: 12px auto; padding: 10px 16px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); }
.notice:empty { display: none; }

/* ============ top bar (all pages) ============ */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .75rem; padding: .5rem max(1rem, calc((100% - 1180px) / 2)); }
.brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; font-weight: bold; font-size: 1.15rem; margin-inline-end: auto; }
.brand:hover { background: none; }
.brand svg { width: 34px; height: 34px; flex: none; }
.actions { display: flex; gap: .5rem; align-items: center; }
.sizer { display: inline-flex; align-items: stretch; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; direction: rtl; }
.sizer button { min-height: 40px; min-width: 40px; padding: 0 .5rem; border: 0; border-radius: 0; background: #fff; color: var(--muted); line-height: 1; font-weight: bold; }
.sizer button + button { border-inline-start: 1px solid var(--line); }
.sizer button:hover { background: var(--page); }
.sizer button.on { background: var(--brand-soft); color: var(--brand); }

/* ============ home ============ */
.home { max-width: 1180px; margin: 0 auto; padding: 1rem; }
.hero { padding: 1.4rem 0 1rem; }
.hero h1 { font-size: 2rem; line-height: 1.35; margin: 0 0 .3rem; }
.hero p { color: var(--muted); margin: 0 0 .8rem; max-width: 46rem; }
.pills { display: flex; flex-wrap: wrap; gap: .5rem; }
.pill { background: var(--brand-soft); color: var(--brand-dark); border-radius: 999px; padding: .1rem .9rem; font-size: .95rem; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1.25rem; align-items: start; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin: 0 0 1rem; box-shadow: var(--shadow); }
.step-head { display: flex; align-items: center; gap: .7rem; margin: 0 0 .9rem; }
.step-num { flex: none; width: 2rem; height: 2rem; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: bold; font-size: 1rem; }
.step-head h2 { font-size: 1.25rem; margin: 0; line-height: 1.4; }
.step-head .hint { margin-inline-start: auto; }
.group-label { font-size: .95rem; color: var(--muted); margin: .9rem 0 .4rem; }
.group-label:first-of-type { margin-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { min-height: 42px; border: 1.5px solid var(--line); border-radius: 999px; padding: .15rem 1.1rem; background: #fff; color: var(--ink); font-size: 1.02rem; }
.chip:hover { background: var(--page); border-color: #cbd2d9; }
.chip.on, .chip.on:hover { background: var(--brand); border-color: var(--brand); color: #fff; }

/* subject + option cards */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: .7rem; }
.tile { display: flex; align-items: center; gap: .7rem; text-align: start; min-height: 64px; padding: .6rem .8rem; background: #fff; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 12px; line-height: 1.35; }
.tile:hover { background: #fff; border-color: var(--brand); }
.tile.on, .tile.on:hover { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-ring); }
.tile .icon { flex: none; width: 42px; height: 42px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.tile.on .icon { background: var(--brand); color: #fff; }
.tile .icon svg { width: 24px; height: 24px; }
.tile b { display: block; font-size: 1.05rem; }
.tile small { color: var(--muted); font-size: .85rem; }
.tiles.wide { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.tiles.wide .tile { align-items: flex-start; padding: .8rem .9rem; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tiles.three .tile { justify-content: center; text-align: center; min-height: 58px; }

/* units accordion */
.bulk { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.bulk button { min-height: 38px; font-size: .92rem; padding: .1rem .9rem; }
.unit { border: 1.5px solid var(--line); border-radius: 12px; margin: .5rem 0; overflow: hidden; background: #fff; }
.unit.has-selection { border-color: var(--brand); }
.unit-head { display: flex; align-items: center; gap: .2rem; background: #fafbfc; }
.unit-head .check { display: grid; place-items: center; width: 48px; min-height: 52px; flex: none; cursor: pointer; }
.unit-toggle { flex: 1; min-width: 0; min-height: 52px; background: none; color: var(--ink); border: 0; border-radius: 0; padding: .3rem 0 .3rem .8rem;
  display: flex; align-items: center; gap: .6rem; text-align: start; font-weight: bold; font-size: 1.05rem; line-height: 1.45; justify-content: flex-start; }
.unit-toggle:hover { background: none; color: var(--brand); }
.unit-toggle .name { flex: 1; min-width: 0; }
.count { flex: none; font-weight: normal; font-size: .85rem; color: var(--muted); background: #eef1f4; border-radius: 999px; padding: 0 .6rem; direction: ltr; }
.unit.has-selection .count { background: var(--brand-soft); color: var(--brand-dark); }
.chev { flex: none; width: 20px; height: 20px; color: var(--muted); transition: transform .2s; }
.unit.open .chev { transform: rotate(180deg); }
.lessons { display: none; border-top: 1px solid var(--line); padding: .3rem 0; }
.unit.open .lessons { display: block; }
label.lesson { display: flex; gap: .2rem; align-items: flex-start; cursor: pointer; line-height: 1.55; padding: .15rem .8rem .15rem .2rem; }
label.lesson:hover { background: var(--page); }
label.lesson .check { display: grid; place-items: center; width: 48px; min-height: 40px; flex: none; }
label.lesson .text { padding-top: .35rem; }
label.lesson.off { color: #9aa3ad; cursor: not-allowed; }
.lesson.oral { display: flex; gap: .2rem; align-items: flex-start; line-height: 1.55; padding: .15rem .8rem .15rem .2rem; color: #9aa3ad; }
.lesson.oral .check { width: 48px; min-height: 40px; flex: none; }
.lesson.oral .text { padding-top: .35rem; }
.lesson.oral em { font-style: normal; font-size: .82rem; background: #eef1f4; color: var(--muted); border-radius: 999px; padding: 0 .6rem; white-space: nowrap; }
label.lesson.off:hover { background: none; }
input[type=checkbox] { width: 20px; height: 20px; flex: none; margin: 0; accent-color: var(--brand); cursor: inherit; }

/* summary: a sticky side card on wide screens, a bottom bar on narrow ones */
.summary { position: sticky; top: 76px; }
.summary h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
.summary dl { margin: 0 0 .9rem; display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: .98rem; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: bold; text-align: start; }
.summary .cta { width: 100%; font-size: 1.15rem; min-height: 52px; font-weight: bold; }
.summary .hint { margin: .5rem 0 0; text-align: center; }
.summary .notice { margin: .6rem 0 0; font-size: .95rem; }
.summary-line { display: none; }

.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; flex-wrap: wrap; gap: .1rem .9rem; align-items: baseline; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history a { color: var(--brand); font-weight: bold; text-decoration: none; }
.history a:hover { text-decoration: underline; }
.history .hint { flex: 1; min-width: 12rem; }
/* Site footer: who made it, why, and that it is free. On screen only — printed papers stay clean. */
.site-footer {
  max-width: 44rem; margin: 2.5rem auto 1.5rem; padding: 1.6rem 1.4rem 1.3rem;
  text-align: center; background: var(--card); border: 1px solid var(--line);
  border-top: 4px solid var(--brand); border-radius: var(--radius); box-shadow: var(--shadow);
}
.site-footer p { margin: 0; }
.site-footer__badge {
  display: inline-block; padding: .25rem 1rem; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: bold; font-size: .95rem;
}
.site-footer__mission { margin-top: .85rem !important; color: var(--ink); font-size: 1rem; line-height: 1.9; }
.site-footer__credit {
  margin-top: .9rem !important; padding-top: .9rem; border-top: 1px dashed var(--line);
  color: var(--muted); font-size: .95rem;
  display: flex; align-items: center; justify-content: center; gap: .4rem; flex-wrap: wrap;
}
.site-footer__credit strong { color: var(--brand-dark); font-size: 1.1rem; }
.site-footer__credit svg { width: 1.05rem; height: 1.05rem; fill: #c0392b; flex: none; }
.site-footer__note { margin-top: .5rem !important; color: var(--muted); font-size: .8rem; }
@media (max-width: 600px) {
  .site-footer { margin: 2rem 1rem 1rem; padding: 1.3rem 1rem 1.1rem; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .home { padding: .8rem .8rem 7rem; }
  .hero { padding: .8rem 0 .6rem; }
  .hero h1 { font-size: 1.6rem; }
  .summary { position: fixed; inset-inline: 0; bottom: 0; top: auto; z-index: 15; margin: 0; border-radius: 16px 16px 0 0; border-bottom: 0;
    padding: .6rem .9rem calc(.6rem + env(safe-area-inset-bottom)); box-shadow: 0 -6px 24px rgba(16, 24, 40, .12);
    display: grid; grid-template-columns: 1fr auto; gap: .2rem .8rem; align-items: center; }
  .summary h2, .summary dl, .summary .hint { display: none; }
  .summary-line { display: block; font-size: .92rem; color: var(--muted); line-height: 1.45; min-width: 0; }
  .summary-line b { color: var(--ink); }
  .summary .cta { width: auto; padding-inline: 1.4rem; }
  .summary .notice { grid-column: 1 / -1; margin: .3rem 0 0; }
}
@media (max-width: 560px) {
  .card { padding: .9rem .8rem; border-radius: 12px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tiles.wide { grid-template-columns: 1fr; }
  .tile { padding: .5rem .6rem; gap: .5rem; }
  .tile .icon { width: 36px; height: 36px; }
  .step-head .hint { display: none; }
  .brand span { font-size: 1rem; }
}

/* ============ exam sheet ============ */
.sheet { background: #fff; max-width: 210mm; margin: 16px auto; padding: 15mm; box-shadow: var(--shadow); border-radius: 4px; }
.exam-head { border-bottom: 2.5px solid #222; padding-bottom: .4rem; margin-bottom: .7rem; }
.exam-head h1 { font-size: 1.5rem; margin: 0; text-align: center; }
.scope { font-size: 1rem; color: #333; text-align: center; margin-top: .15rem; }

.q { margin: 14px 0; break-inside: avoid; }
.q h2 { font-size: 1.25rem; margin: 0 0 6px; background: var(--soft); padding: 2px 10px; border-radius: 6px; display: flex; justify-content: space-between; gap: 12px; }
.q h2 small { font-weight: normal; font-size: 1rem; white-space: nowrap; }
.prompt { margin: 4px 0; }
ol.mcq { margin: 0; padding-inline-start: 24px; }
ol.mcq > li { margin-bottom: 8px; break-inside: avoid; }
/* options flow to their natural width: four short numbers sit in a row, long phrases take the space they need */
.opts { display: flex; flex-wrap: wrap; gap: 2px 1.6rem; }
.opts > span { flex: 0 1 auto; max-width: 100%; }
ol.items { list-style: none; margin: 4px 0; padding: 0; }
ol.items > li { margin: 8px 0; break-inside: avoid; }
ol.items .lbl { margin-inline-end: 4px; }
.box { display: inline-block; min-width: 70px; height: 30px; border: 1.5px solid var(--paper-line); border-radius: 6px; vertical-align: middle; margin: 2px 3px; }
.box.s { min-width: 36px; }
.box.filled { height: auto; min-height: 30px; padding: 0 8px; color: var(--brand); font-weight: bold; background: var(--brand-soft); border-color: var(--brand); text-align: center; direction: ltr; unicode-bidi: isolate; }
.lines { display: block; border-bottom: 1px dotted var(--paper-line); height: 32px; }
.tf { white-space: nowrap; }
.scramble { list-style: none; margin: 6px auto; padding: 0; display: grid; gap: 4px; max-width: 620px; }
.scramble li { border: 1.5px solid var(--paper-line); border-radius: 8px; padding: 2px 12px; }
.passage { border: 1.5px solid var(--paper-line); border-radius: 10px; padding: .5rem 1rem; margin: .5rem 0 .7rem; background: #fcfcfa; break-inside: avoid; }
.passage h3 { margin: 0 0 .2rem; text-align: center; font-size: 1.15rem; }
.passage p { margin: 0; line-height: 2.05; text-align: justify; }
.figure { text-align: center; margin: 6px 0; direction: ltr; }
.figure svg { max-width: 100%; height: auto; }
.table-wrap { overflow-x: auto; max-width: 100%; }
table.grid { border-collapse: collapse; margin: 6px auto; }
table.grid td, table.grid th { border: 1.5px solid var(--paper-line); padding: 4px 14px; text-align: center; min-width: 96px; height: 36px; }
table.grid th { background: #eee; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 0 90px; max-width: 560px; margin: 6px auto; }
.match .cell { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1.5px solid var(--paper-line); border-radius: 8px; padding: 2px 12px; margin: 6px 0; }
.match .dot { width: 9px; height: 9px; border-radius: 50%; background: #222; flex: none; }
.ans { color: var(--brand); font-weight: bold; }
td.ans, .opts .ans { background: var(--brand-soft); border-radius: 6px; }
.ansrow { font-size: 1rem; }
.solution { font-size: .95rem; color: #444; border-inline-start: 3px solid var(--brand); padding-inline-start: 8px; margin-top: 4px; }
.solution .from, .solution.from { color: #666; }
.solution.from { border: 0; padding: 0; }
.parents { background: var(--brand-soft); border-radius: 8px; padding: 6px 14px; margin: 10px 0; font-size: 1rem; }
.end { text-align: center; font-weight: bold; margin-top: 18px; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: .4rem .7rem; gap: .4rem; }
  .topbar .actions { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .topbar .actions > * { flex: 1 0 auto; min-height: 40px; font-size: .92rem; padding: .2rem .7rem; }
  .sheet { padding: 14px 12px; margin: 0; border-radius: 0; box-shadow: none; }
  .opts { gap: 2px 1rem; }
  .match { gap: 0 22px; }
  .match .cell { padding: 2px 8px; }
  table.grid td, table.grid th { min-width: 64px; padding: 4px 8px; }
  .q h2 { font-size: 1.12rem; }
}

/* ============ interactive quiz ============ */
.quiz { max-width: 760px; margin: 0 auto; padding: 1rem; }
.quiz-head { margin-bottom: .8rem; }
.quiz-title { font-size: 1.3rem; font-weight: bold; }
.progress { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin: .5rem 0 .4rem; }
.progress span { display: block; height: 100%; min-width: 8px; background: var(--brand); border-radius: 999px; transition: width .25s ease; }
.quiz-meta { display: flex; justify-content: space-between; gap: .2rem 1rem; flex-wrap: wrap; color: var(--muted); font-size: .95rem; }
.question-card { min-height: 200px; }
.instruction { color: var(--muted); margin: 0 0 6px; font-size: 1rem; }
.question { font-size: 1.3rem; line-height: 1.8; margin-bottom: 14px; }
.question .figure { margin: 10px 0; }
.choices { display: grid; gap: 10px; }
button.choice { display: flex; align-items: center; justify-content: flex-start; gap: 12px; width: 100%; min-height: 56px; text-align: start; font-size: 1.15rem;
  background: #fff; color: var(--ink); border: 2px solid #d5dae0; border-radius: 12px; padding: 8px 14px; line-height: 1.5; }
button.choice:hover { background: #fff; border-color: var(--brand); }
button.choice.on, button.choice.on:hover { border-color: var(--brand); background: var(--brand-soft); }
.choice .letter, .choices.review .letter { flex: none; width: 34px; height: 34px; border-radius: 50%; background: #eef0f3; display: grid; place-items: center; font-weight: bold; font-size: 1rem; }
button.choice.on .letter { background: var(--brand); color: #fff; }
.choice .text { flex: 1; min-width: 0; }
.quiz-actions { display: flex; gap: 10px; margin: 14px 0 4px; }
.quiz-actions button, .quiz-actions .btn { font-size: 1.1rem; min-height: 50px; padding: .4rem 1.6rem; }
#next { flex: 1; font-weight: bold; }

.score-card { text-align: center; }
.score-ring { --percent: 0; width: 150px; height: 150px; margin: 4px auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring-color, var(--brand)) calc(var(--percent) * 1%), #e5e7eb 0); }
.score-ring[data-band=high] { --ring-color: #0ca30c; }
.score-ring[data-band=mid]  { --ring-color: #eda100; }
.score-ring[data-band=low]  { --ring-color: #d03b3b; }
.score-ring span { width: 112px; height: 112px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 1.8rem; font-weight: bold; direction: ltr; }
.score-card h2 { margin: 0 0 4px; font-size: 1.4rem; }
.score-card .quiz-actions { justify-content: center; flex-wrap: wrap; }
.review-title { margin: 18px 0 8px; font-size: 1.2rem; }
.review-item { border-inline-start: 5px solid #d1d5db; }
.review-item.ok { border-inline-start-color: #0ca30c; }
.review-item.bad { border-inline-start-color: #d03b3b; }
.review-head { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); margin-bottom: 6px; }
.review-item.ok .review-head span { color: #0a7d0a; font-weight: bold; }
.review-item.bad .review-head span { color: var(--danger); font-weight: bold; }
.choices.review { list-style: none; margin: 8px 0; padding: 0; }
.choices.review li { display: flex; align-items: center; gap: 12px; border: 2px solid #e5e7eb; border-radius: 10px; padding: 6px 12px; font-size: 1.08rem; }
.choices.review li.right { border-color: #0ca30c; background: #eaf7ea; }
.choices.review li.wrong { border-color: #d03b3b; background: #fdeeee; }
.choices.review .text { flex: 1; min-width: 0; }
.choices.review .mark { font-weight: bold; font-size: 1.2rem; }
.choices.review li.right .mark { color: #0a7d0a; }
.choices.review li.wrong .mark { color: var(--danger); }
@media (max-width: 640px) {
  .quiz { padding: .7rem; }
  .question { font-size: 1.18rem; }
  .quiz-actions button, .quiz-actions .btn { padding: .4rem 1rem; }
}

/* ============ print ============ */
@media print {
  html { font-size: calc(18px * var(--font-scale)); }
  body { background: #fff; }
  .topbar, .notice, .no-print, .summary, .site-footer { display: none !important; }
  .sheet { box-shadow: none; margin: 0; padding: 0; max-width: none; border-radius: 0; }
  .table-wrap { overflow: visible; }
}
