:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-2: #f0ede4;
  --text: #1d2420;
  --muted: #5d665f;
  --border: #e2ddd0;
  --accent: #0f5132;
  --accent-soft: #e3efe8;
  --gold: #9a6b12;
  --sahih: #1e7a46;
  --hasan: #2b6cb0;
  --daif: #b4441f;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --ur: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", serif;
  --ar: "Amiri", "Traditional Arabic", serif;
  --en: "Inter", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111613; --surface: #181f1b; --surface-2: #1f2823; --text: #e6ebe7; --muted: #9aa69e;
    --border: #2b362f; --accent: #5cc08b; --accent-soft: #1d3327; --gold: #d9ad55;
    --sahih: #5cc08b; --hasan: #7fb2ec; --daif: #f08a64; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #111613; --surface: #181f1b; --surface-2: #1f2823; --text: #e6ebe7; --muted: #9aa69e;
  --border: #2b362f; --accent: #5cc08b; --accent-soft: #1d3327; --gold: #d9ad55;
  --sahih: #5cc08b; --hasan: #7fb2ec; --daif: #f08a64; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--ur); font-size: 17px; line-height: 2.1;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus, main:focus-visible { outline: none; }

/* Header */

main { max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; outline: none; }
.loading, .muted { color: var(--muted); }
.foot { max-width: 980px; margin: 0 auto; padding: 16px; border-top: 1px solid var(--border); font-size: 14px; }

/* Typography */
h1 { font-size: 30px; line-height: 1.9; margin: 0 0 4px; }
h2 { font-size: 22px; line-height: 1.9; margin: 32px 0 8px; }
h3 { font-size: 18px; line-height: 1.9; margin: 0; }
.lede { color: var(--muted); margin: 0 0 20px; max-width: 70ch; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.en { font-family: var(--en); direction: ltr; unicode-bidi: isolate; }

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--accent-soft), var(--surface));
  border: 1px solid var(--border); border-radius: 16px; padding: 28px; margin-bottom: 24px;
}
.hero .ayah { font-family: var(--ar); font-size: 26px; line-height: 1.9; color: var(--accent); margin: 0; }
.searchbar { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.searchbar input, .searchbar select, .filter {
  flex: 1 1 220px; min-width: 0; padding: 6px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
.searchbar select { flex: 0 1 200px; line-height: 1.8; padding-block: 8px; }
.btn {
  padding: 4px 18px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--surface); cursor: pointer; font-size: 15px; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }

/* Cards / grids */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 18px; color: var(--text); box-shadow: var(--shadow);
}
a.card:hover { border-color: var(--accent); text-decoration: none; }
.card .ar-title { font-family: var(--ar); font-size: 20px; color: var(--gold); }
.card .meta { font-size: 13px; color: var(--muted); }
.stat { font-family: var(--en); font-weight: 600; }
.tag { display: inline-block; font-size: 12px; padding: 0 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); line-height: 2; }

/* Chapter list */
.chapters { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.chapters a {
  display: flex; gap: 12px; align-items: center; padding: 6px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text);
}
.chapters a:hover { border-color: var(--accent); text-decoration: none; }
.chapters .num { font-family: var(--en); color: var(--muted); min-width: 2.5em; font-size: 14px; }
.chapters .t-en { font-family: var(--en); font-size: 15px; direction: ltr; unicode-bidi: isolate; flex: 1; text-align: left; }
.chapters .count { font-family: var(--en); font-size: 12px; color: var(--muted); }

/* Hadith card */
.hadith {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.hadith-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; font-size: 14px; color: var(--muted); }
.hadith-head .ref { font-weight: 600; color: var(--accent); }
.arabic {
  font-family: var(--ar); font-size: 23px; line-height: 2; direction: rtl; text-align: right;
  margin: 10px 0; padding: 10px 14px; background: var(--surface-2); border-radius: 10px;
}
.urdu { font-size: 18px; line-height: 2.3; margin: 8px 0; }
.grades { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.grade { font-family: var(--en); font-size: 12px; line-height: 1.9; padding: 0 8px; border-radius: 6px; border: 1px solid currentColor; direction: ltr; }
.grade.sahih { color: var(--sahih); }
.grade.hasan { color: var(--hasan); }
.grade.daif { color: var(--daif); }
.grade.other { color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.actions button, .actions a {
  font-size: 13px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; cursor: pointer; color: var(--muted); line-height: 2.2;
}
.actions button:hover, .actions a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
mark { background: #f5d97a; color: #1d2420; border-radius: 3px; }

/* Duas / wazaif */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 20px; }
.tabs a { padding: 2px 14px; border: 1px solid var(--border); border-radius: 999px; color: var(--text); font-size: 15px; background: var(--surface); }
.tabs a.active, .tabs a:hover { background: var(--accent); color: var(--surface); border-color: var(--accent); text-decoration: none; }
.zikr-title { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.count-badge { font-family: var(--en); font-size: 13px; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 0 10px; white-space: nowrap; }
.counter { font-family: var(--en); min-width: 7em; }
details.src { margin-top: 8px; }
details.src summary { cursor: pointer; color: var(--accent); font-size: 15px; }
.notice { border: 1px solid var(--border); border-inline-start: 4px solid var(--gold); background: var(--surface); border-radius: 10px; padding: 10px 16px; margin: 16px 0; font-size: 15px; }
table.src-table { width: 100%; border-collapse: collapse; font-size: 15px; background: var(--surface); }
.src-table th, .src-table td { border: 1px solid var(--border); padding: 4px 10px; text-align: right; vertical-align: top; }
.src-table th { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.pager { display: flex; justify-content: center; gap: 8px; margin: 16px 0; }

@media (max-width: 720px) {
  body { font-size: 16px; }
  h1 { font-size: 24px; }
  .hero { padding: 18px; }
  .hero .ayah { font-size: 21px; }
  .arabic { font-size: 20px; padding: 8px 10px; }
  .hadith { padding: 12px 14px; }
}

/* ---------- Kids corner ---------- */
:root { --k1: #ffe9a8; --k2: #c9f0dc; --k3: #d6e6ff; --k4: #ffd9e4; --kink: #3b2f12; --star: #e8a400; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --k1: #4a3d14; --k2: #1d4532; --k3: #22385c; --k4: #522536; --kink: #fff4d6; --star: #ffd24a; } }
:root[data-theme="dark"] { --k1: #4a3d14; --k2: #1d4532; --k3: #22385c; --k4: #522536; --kink: #fff4d6; --star: #ffd24a; }

.kids-banner { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; background: linear-gradient(135deg, var(--k1), var(--k2)); color: var(--kink); }
.kids-banner .meta { color: var(--kink); opacity: .85; margin: 0; }
.kids-emoji { font-size: 40px; line-height: 1; }

.kids-hero { background: linear-gradient(135deg, var(--k1), var(--k3)); color: var(--kink); border-radius: 22px; padding: 24px; margin-bottom: 20px; }
.kids-hero .lede { color: var(--kink); }
.kids-progress { background: var(--surface); color: var(--text); border-radius: 16px; padding: 10px 16px; margin: 12px 0 18px; border: 2px solid var(--border); }
.kids-stars .big { font-family: var(--en); font-size: 22px; font-weight: 700; color: var(--star); }
.bar { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 4px 0 8px; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--star), #4cc38a); border-radius: 999px; transition: width .4s; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 14px; padding: 0 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); filter: grayscale(1); opacity: .6; }
.badge.on { filter: none; opacity: 1; background: var(--k1); color: var(--kink); }

.kids-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kids-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 12px; border-radius: 22px; font-size: 21px; font-weight: 600; color: var(--kink); text-align: center; border: 3px solid transparent; transition: transform .15s; }
.kids-tile span { font-size: 54px; line-height: 1.3; }
.kids-tile:hover, .kids-tile:focus-visible { transform: translateY(-3px) scale(1.02); text-decoration: none; border-color: var(--star); }
.t1 { background: var(--k1); } .t2 { background: var(--k2); } .t3 { background: var(--k3); } .t4 { background: var(--k4); }
.notice.parents { font-size: 15px; }

.kid-card { background: var(--surface); border: 3px solid var(--border); border-radius: 22px; padding: 16px 20px; margin-bottom: 16px; transition: border-color .2s; }
.kid-card.done { border-color: var(--star); }
.kid-head { display: flex; align-items: center; gap: 12px; }
.kid-head h2 { margin: 0; font-size: 22px; }
.kid-emoji { font-size: 40px; line-height: 1.2; }
.kid-arabic { font-family: var(--ar); font-size: 30px; line-height: 2; text-align: center; direction: rtl; margin: 12px 0; padding: 12px 16px; background: var(--k2); color: var(--kink); border-radius: 16px; }
.kid-meaning { font-size: 19px; line-height: 2.3; margin: 8px 0; }
.kid-meaning .lbl { font-weight: 600; color: var(--accent); }
.kid-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 10px 0; }
.star-btn { font-size: 18px; padding: 4px 20px; border-radius: 999px; border: 2px solid var(--star); background: var(--surface); color: var(--text); cursor: pointer; min-height: 48px; }
.star-btn[aria-pressed="true"] { background: var(--star); color: #2a2000; font-weight: 600; }

.quiz-card { background: var(--surface); border: 3px solid var(--border); border-radius: 22px; padding: 20px; text-align: center; }
.quiz-meta { font-size: 15px; color: var(--muted); }
.quiz-q { font-size: 22px; font-weight: 600; margin: 8px 0; }
.quiz-opts { display: grid; gap: 10px; margin: 14px 0; }
.quiz-opt { font-size: 20px; padding: 8px 16px; min-height: 56px; border-radius: 16px; border: 2px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.quiz-opt[lang="ar"] { font-family: var(--ar); font-size: 22px; }
.quiz-opt:hover:not([disabled]) { border-color: var(--accent); }
.quiz-opt.right { background: #c9f0dc; border-color: #1e7a46; color: #12331f; }
.quiz-opt.wrong { background: #ffe0d6; border-color: #b4441f; color: #3b1206; }
.feedback { font-size: 19px; font-weight: 600; }
.feedback.ok { color: var(--sahih); } .feedback.no { color: var(--daif); }
.big-score { font-family: var(--en); font-size: 64px; font-weight: 700; color: var(--star); }

.tasbih-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 16px 0; }
.tasbih-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 190px; border-radius: 50%; aspect-ratio: 1; max-width: 240px; width: 100%; margin: 0 auto; border: 4px solid var(--accent); background: var(--k2); color: var(--kink); cursor: pointer; touch-action: manipulation; user-select: none; transition: transform .08s; }
.tasbih-btn:active { transform: scale(.96); }
.tasbih-btn.full { border-color: var(--star); background: var(--k1); }
.t-label { font-size: 22px; font-weight: 600; }
.t-count { font-family: var(--en); font-size: 48px; font-weight: 700; line-height: 1.2; }
.t-target { font-size: 16px; }

.spark { position: absolute; z-index: 50; pointer-events: none; font-size: 22px; animation: spark .9s ease-out forwards; }
@keyframes spark { from { transform: translate(0, 0) scale(.6); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(1.2); opacity: 0; } }

body.kids-mode .top { background: linear-gradient(90deg, var(--k1), var(--k3)); }
@media (max-width: 720px) {
  .kid-arabic { font-size: 25px; }
  .kids-tile { font-size: 18px; padding: 16px 8px; }
  .kids-tile span { font-size: 44px; }
  .kids-grid { grid-template-columns: 1fr 1fr; }
  .tasbih-btn { min-height: 150px; max-width: 200px; }
}
@media (prefers-reduced-motion: reduce) { .kids-tile, .tasbih-btn, .bar span { transition: none; } }

/* ---------- Seerah stories ---------- */
.story-tile { display: flex; flex-direction: column; align-items: center; background: linear-gradient(135deg, var(--k3), var(--k4)); margin-bottom: 14px; }
.story-tile small { font-size: 15px; font-weight: 400; opacity: .85; }
.story-list { display: grid; gap: 16px; margin-bottom: 20px; }
.story-card { display: grid; grid-template-columns: 220px 1fr; gap: 0; background: var(--surface); border: 3px solid var(--border); border-radius: 22px; overflow: hidden; color: var(--text); }
a.story-card:hover { border-color: var(--star); text-decoration: none; }
.story-thumb svg, .scene-art svg, .story-hero svg { display: block; width: 100%; height: 100%; }
.story-thumb { min-height: 150px; }
.story-meta { padding: 12px 18px; }
.story-meta h2 { margin: 2px 0; font-size: 21px; }
.story-meta p { margin: 0; color: var(--muted); }
.story-no { display: inline-block; font-size: 13px; background: var(--k1); color: var(--kink); border-radius: 999px; padding: 0 12px; }
.read-tag { font-size: 13px; color: var(--sahih); margin-inline-start: 8px; font-weight: 600; }
.story-card.soon { opacity: .75; }
.soon-thumb { filter: grayscale(.6); }

.story-progress { position: fixed; top: 0; inset-inline: 0; height: 5px; z-index: 20; background: transparent; }
.story-progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--star), #4cc38a); }
.story-hero { position: relative; border-radius: 24px; overflow: hidden; height: clamp(200px, 45vw, 380px); width: 100%; }
.story-hero-text { position: absolute; inset: auto 0 0 0; padding: 14px 18px; background: linear-gradient(transparent, rgba(0,0,0,.72)); color: #fff; }
.story-hero-text h1 { color: #fff; margin: 4px 0 0; font-size: 26px; text-shadow: 0 2px 6px rgba(0,0,0,.5); }
.story-hero-text p { margin: 0; font-size: 15px; opacity: .95; }
.story-tools { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; }
.font-ctl button { font-size: 18px; min-width: 48px; min-height: 40px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; margin-inline-start: 6px; }
.story-intro { font-size: 20px; line-height: 2.4; background: var(--k1); color: var(--kink); border-radius: 18px; padding: 12px 18px; }
.legend { background: var(--surface); border: 2px dashed var(--border); border-radius: 14px; padding: 4px 14px; margin: 12px 0 20px; font-size: 15px; }
.legend summary { cursor: pointer; color: var(--accent); }

.story-scene { background: var(--surface); border: 3px solid var(--border); border-radius: 24px; overflow: hidden; margin-bottom: 22px; }
.scene-art { height: clamp(170px, 42vw, 340px); overflow: hidden; }
.scene-body { padding: 8px 22px 16px; }
.scene-no { display: inline-block; font-size: 13px; background: var(--accent); color: var(--surface); border-radius: 999px; padding: 0 12px; margin-top: 10px; }
.scene-body h2 { margin: 4px 0 6px; font-size: 24px; color: var(--accent); }
.story p, .story li { font-size: 19px; line-height: 2.45; }
.story.font-0 p, .story.font-0 li { font-size: 17px; }
.story.font-2 p, .story.font-2 li { font-size: 22px; line-height: 2.6; }
.story.font-3 p, .story.font-3 li { font-size: 25px; line-height: 2.7; }
.story-ul { padding-inline-start: 22px; margin: 0; }
.story-ul li::marker { content: "✨ "; }
.did-you-know { background: var(--k1); color: var(--kink); border-radius: 16px; padding: 8px 16px; margin: 12px 0; border-inline-start: 6px solid var(--star); }
.did-you-know p { margin: 0; }
.ayah-quote { margin: 14px 0; background: linear-gradient(135deg, var(--k2), var(--surface)); border: 2px solid var(--accent); border-radius: 18px; padding: 6px 14px; }
.ayah-quote .kid-arabic { background: transparent; margin: 4px 0; }
.sources { display: grid; gap: 6px; margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.badge-src { border-radius: 12px; padding: 2px 12px; font-size: 15px; }
.badge-src summary { cursor: pointer; font-weight: 600; }
.badge-src p { font-size: 16px !important; line-height: 2.2 !important; }
.badge-src.quran { background: var(--k2); color: var(--kink); }
.badge-src.hadith { background: var(--accent-soft); color: var(--text); }
.badge-src.sirah { background: var(--surface-2); color: var(--text); }
.badge-src .quote { font-weight: 600; color: var(--accent); }
.badge-src .hadith { box-shadow: none; }

.story-end { background: var(--surface); border: 3px solid var(--star); border-radius: 24px; padding: 6px 20px 16px; }
.lessons { display: grid; gap: 10px; }
.lesson { display: flex; gap: 12px; align-items: flex-start; background: var(--surface-2); border-radius: 16px; padding: 8px 14px; }
.lesson p { margin: 0; font-size: 18px !important; }
.l-emoji { font-size: 34px; line-height: 1.4; }
.glossary { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin: 0; }
.glossary div { background: var(--k3); color: var(--kink); border-radius: 14px; padding: 6px 12px; }
.glossary dt { font-weight: 700; font-size: 19px; }
.glossary dd { margin: 0; font-size: 16px; }
.sq { background: var(--surface-2); border-radius: 16px; padding: 4px 14px; margin-bottom: 10px; }
.sq .quiz-opts { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 6px 0 10px; }
.sq .quiz-opt { min-height: 48px; font-size: 18px; }
.next-story { text-align: center; font-size: 18px; color: var(--accent); font-weight: 600; }

@media (max-width: 720px) {
  .story-card { grid-template-columns: 1fr; }
  .story-thumb { aspect-ratio: 400 / 220; min-height: 0; }
  .scene-body { padding: 6px 14px 12px; }
  .story-hero-text h1 { font-size: 20px; }
  .story-hero-text p { display: none; }
  .story p, .story li { font-size: 18px; }
}

.saw { font-family: var(--ar); font-size: .95em; line-height: 1; display: inline-block; vertical-align: baseline; }

/* ---------- installable app ---------- */
.install-card { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; border: 2px solid var(--accent); }
.install-card .btn { margin-top: 4px; }
@media (display-mode: standalone) { .install-btn, .install-card { display: none !important; } }

/* =====================================================================
   Readability and mobile layer
   Nastaliq script stacks letters vertically and joins words tightly, so it needs
   more line height and word spacing than Latin text to stay readable on phones.
   ===================================================================== */
:root { --ur-words: .14em; --ar-words: .12em; --tabbar-h: 64px; --gap: 16px; }

body { line-height: 2.3; word-spacing: var(--ur-words); }
p { margin: 0 0 .85em; }
p:last-child { margin-bottom: 0; }
h1, h2, h3 { word-spacing: .06em; }
h1 { line-height: 1.75; margin: 0 0 14px; }
h2 { line-height: 1.75; margin: 36px 0 12px; }
h3 { line-height: 1.75; }
.lede { line-height: 2.35; margin-bottom: 24px; }
.crumbs { line-height: 2; margin-bottom: 10px; word-spacing: .08em; }
.urdu, .kid-meaning, .story p, .story li, .story-intro, .notice, .card .meta, .lesson p { word-spacing: var(--ur-words); }
.urdu { line-height: 2.45; }
/* Arabic (Amiri) reads best a little tighter than Urdu but with clear gaps between words. */
.arabic, .kid-arabic, [lang="ar"] { word-spacing: var(--ar-words); }
.arabic { line-height: 2.15; padding: 14px 16px; }
.kid-arabic { line-height: 2.1; }
/* English and numbers inside Urdu text keep normal Latin spacing. */
.en, .stat, .grade, .chapters .num, .chapters .count, .counter, .t-count { word-spacing: normal; }

/* Comfortable, consistent rhythm between blocks */
.card, .hadith, .kid-card, .story-scene, .quiz-card { margin-bottom: var(--gap); }
.grid, .kids-grid, .story-list, .lessons { gap: var(--gap); }
.hadith-head { line-height: 1.9; margin-bottom: 6px; }
.grades { gap: 8px; margin-top: 10px; }

/* Inputs: tall enough for Nastaliq so nothing is clipped; 16px+ stops iOS from zooming in. */
.searchbar input, .filter, .searchbar select { min-height: 50px; font-size: 17px; line-height: 1.6; padding: 8px 14px; }
.searchbar select { padding-block: 0; line-height: 50px; height: 50px; }
.btn { min-height: 46px; padding: 4px 20px; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.filter { width: 100%; }

/* Bigger tap targets (at least ~44px) */
.actions button, .actions a { min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; }
.chapters a { min-height: 54px; padding: 8px 16px; }
.tabs a { min-height: 44px; display: inline-flex; align-items: center; padding: 0 16px; }
details summary { min-height: 44px; display: flex; align-items: center; gap: 6px; padding-block: 4px; }
.badge-src summary { min-height: 44px; }

/* Bottom tab bar (phones) */
.tabbar { display: none; }
.to-top { position: fixed; inset-inline-start: 16px; bottom: 24px; z-index: 15; width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.15); font-family: var(--en); cursor: pointer; }

@media (max-width: 720px) {
  :root { --gap: 14px; }
  body { font-size: 17px; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  main { padding: 18px 16px 32px; }

  .tabbar {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(0,0,0,.06);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
    color: var(--muted); font-size: 13px; line-height: 1.5; text-decoration: none; word-spacing: normal; position: relative; }
  .tabbar .tab-ico { font-size: 22px; line-height: 1.2; filter: grayscale(.5); opacity: .8; }
  .tabbar a.active { color: var(--accent); font-weight: 600; }
  .tabbar a.active .tab-ico { filter: none; opacity: 1; }
  .tabbar a.active::before { content: ""; position: absolute; top: 0; inset-inline: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  body.kids-mode .tabbar { background: linear-gradient(90deg, var(--k1), var(--k3)); }
  body.kids-mode .tabbar a { color: var(--kink); }
  .to-top { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); }
  .foot { padding: 18px 16px 24px; line-height: 2.2; }

  h1 { font-size: 25px; }
  h2 { font-size: 21px; margin-top: 30px; }
  .lede { font-size: 16.5px; }
  .hero { padding: 20px 16px; border-radius: 18px; }
  .searchbar { flex-direction: column; gap: 10px; }
  .searchbar input, .searchbar select, .searchbar .btn { flex: none; width: 100%; }
  .card, .hadith { padding: 14px 16px; border-radius: 16px; }
  .urdu { font-size: 17.5px; line-height: 2.5; }
  .arabic { font-size: 21px; line-height: 2.2; padding: 12px 14px; }
  .hadith-head { flex-direction: column; align-items: flex-start; gap: 0; }
  .actions { gap: 8px; }
  .actions button, .actions a { flex: 1 1 auto; justify-content: center; }

  /* Category pills scroll sideways in one row instead of stacking into several. */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; margin-inline: -16px; padding: 4px 16px 10px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch; mask-image: linear-gradient(to left, #000 88%, transparent); }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; scroll-snap-align: start; white-space: nowrap; }

  .chapters .t-en { font-size: 14.5px; line-height: 1.5; }
  .kids-progress { padding: 10px 14px; }
  .kid-card, .story-scene, .quiz-card { border-radius: 20px; }
  .kid-meaning, .story p, .story li { line-height: 2.5; }
  .story-intro { line-height: 2.5; padding: 14px 16px; }
  .scene-body h2 { font-size: 22px; }
  .lesson { padding: 10px 14px; }
  .src-table th, .src-table td { padding: 6px 10px; line-height: 2; }
}
@media (max-width: 380px) {
  body { font-size: 16.5px; }
  .tabbar a { font-size: 12px; }
  .kids-tile { font-size: 17px; }
}
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "◂"; font-family: var(--en); font-size: .85em; color: var(--accent); transition: transform .2s; flex: none; }
details[open] > summary::before { transform: rotate(-90deg); }
.hadith-head .ref, .crumbs a { display: inline-flex; align-items: center; min-height: 40px; }
/* Chrome draws <select> text in a fixed box that clips tall Nastaliq letters; Naskh-style Amiri fits. */
.searchbar select, .searchbar select option { font-family: var(--ar); font-size: 18px; }
.searchbar { margin-bottom: 18px; }
.h1-en { display: block; font-size: .62em; line-height: 1.5; font-weight: 600; color: var(--muted); margin-top: 2px; text-align: right; }

/* =====================================================================
   Header: one row at every width. Logo at the start (right in RTL), links in the
   middle, actions grouped at the end; every control the same height.
   ===================================================================== */
[hidden] { display: none !important; }
.top {
  position: sticky; top: 0; z-index: 25;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: 16px;
  height: calc(64px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 24px 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-size: 21px; font-weight: 600; line-height: 1; white-space: nowrap; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; flex: none; display: block; }
.brand-name { line-height: 1.7; padding-top: 6px; } /* Nastaliq sits low; nudge it onto the logo's centre line */
.nav { display: flex; align-items: center; justify-content: center; gap: 2px; flex-wrap: nowrap; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex: none; padding: 2px 12px; border-radius: 10px; color: var(--text); font-size: 15.5px; line-height: 2.1; white-space: nowrap; }
.nav a:hover, .nav a.active { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions button {
  height: 40px; min-width: 40px; padding: 0 12px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1;
}
.theme-btn, .menu-btn { width: 40px; padding: 0; font-family: var(--en); font-size: 17px; background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.theme-btn:hover, .menu-btn:hover { border-color: var(--accent); color: var(--accent); }
.install-btn { font-size: 14.5px; white-space: nowrap; background: var(--accent); color: var(--surface); border: 1px solid var(--accent); }
.install-label { line-height: 1.9; padding-top: 3px; }
.menu-btn { display: none; }
body.kids-mode .top { background: linear-gradient(90deg, var(--k1), var(--k3)); }

@media (max-width: 1180px) { .nav a { padding: 2px 9px; font-size: 15px; } .top { column-gap: 12px; } }
/* Below this width the links no longer fit on one line: move them into the ☰ menu. */
@media (max-width: 1000px) {
  .nav { display: none; }
  .menu-btn { display: inline-flex; }
  .install-btn { width: 40px; padding: 0; }
  .install-label { display: none; }
  .nav.open {
    display: flex; position: absolute; top: 100%; inset-inline: 0; flex-direction: column; align-items: stretch; justify-content: flex-start;
    gap: 2px; padding: 8px 12px 12px; max-height: 70vh; overflow-y: auto;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 10px 24px rgba(0,0,0,.08);
  }
  .nav.open a { padding: 8px 14px; font-size: 17px; line-height: 2.2; }
}
@media (max-width: 720px) {
  .top { height: calc(58px + env(safe-area-inset-top)); padding-inline: 12px; column-gap: 8px; }
  .top-actions { gap: 6px; }
  .top-actions button, .theme-btn, .menu-btn, .install-btn { height: 44px; width: 44px; min-width: 44px; }
  .brand { font-size: 19px; gap: 8px; }
  .brand-logo { width: 30px; height: 30px; border-radius: 8px; }
}
@media (display-mode: standalone) { .install-btn { display: none !important; } }
.top > .brand { grid-column: 1; }
.top > .nav { grid-column: 2; }
.top > .top-actions { grid-column: 3; justify-self: end; }
.top-actions .menu-btn { display: none; }
@media (max-width: 1000px) { .top-actions .menu-btn { display: inline-flex; } }
@media (max-width: 1000px) { .top > .nav.open { grid-column: 1 / -1; width: auto; } }
@media (max-width: 1000px) { .top > .nav.open { border: 1px solid var(--border); border-top: 0; border-radius: 0 0 16px 16px; } }

/* Dua Ghar brand: Urdu name with the Latin web address underneath, so kids learn what to type. */
.brand-text { display: inline-flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.brand-text .brand-name { line-height: 1.55; padding-top: 4px; }
.brand-en { font-family: var(--en); font-size: 11.5px; font-weight: 600; letter-spacing: .04em; color: var(--accent); direction: ltr; line-height: 1.2; margin-top: -2px; }
.hero-brand { margin: 0 0 4px; font-size: 16px; color: var(--accent); font-weight: 600; }
.hero-brand .en { font-size: 14px; font-weight: 600; letter-spacing: .02em; }
@media (max-width: 720px) { .brand-en { font-size: 10.5px; } }
.brand-text .brand-name { line-height: 1.35; padding-top: 0; }
.brand-en { margin-top: 5px; }
@media (max-width: 720px) { .brand-text .brand-name { font-size: 18px; } .brand-en { margin-top: 4px; } }
