:root {
  /* Core theme tokens */
  --bg0: #07131b;
  --bg1: #0c1d26;
  --ink: #eef7f8;
  --muted: #9db8bc;
  --glass: rgba(16, 42, 50, 0.55);
  --glass-2: rgba(255, 255, 255, 0.06);
  --stroke: rgba(210, 236, 228, 0.16);
  --gold: #d7b56d;
  --gold-2: #f3ddad;
  --emerald: #46d7b2;
  --shadow: 0 22px 50px rgba(0, 0, 0, 0.32);
  --radius: 24px;
  /* Semantic aliases */
  --background: var(--bg0);
  --surface: var(--glass);
  --text-primary: var(--ink);
  --text-secondary: var(--muted);
  --border: var(--stroke);
  --accent: var(--gold);
  --reader-background: transparent;
  --reader-text: var(--ink);
  /* Local/system fonts only — no CDN required for core reading */
  --sans: "Segoe UI", "Tahoma", "IBM Plex Sans", sans-serif;
  --naskh: "Noto Naskh Arabic", "Traditional Arabic", "Arabic Typesetting", "Amiri", "Scheherazade New", serif;
  --traditional: "Traditional Arabic", "Arabic Typesetting", "Noto Naskh Arabic", serif;
  --amiri: "Amiri", "Scheherazade New", "Noto Naskh Arabic", serif;
  --nastaliq: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Urdu Typesetting", "Segoe UI", serif;
  --segoe-ur: "Segoe UI", "Tahoma", "Noto Nastaliq Urdu", sans-serif;
  --font-arabic: var(--naskh);
  --font-urdu: var(--nastaliq);
  /* Reader sizing (defaults = current approved look) */
  --reader-arabic-size: clamp(24px, 2.8vw, 34px);
  --reader-kanz-size: clamp(17px, 1.8vw, 22px);
  --reader-line-height: 2.15;
  --reader-kanz-line-height: 2.2;
  --reader-max-width: 46rem;
}

[data-theme="light"] {
  --bg0: #f6f1e6;
  --bg1: #ece4d3;
  --ink: #14241f;
  --muted: #5a6e69;
  --glass: rgba(255, 252, 246, 0.72);
  --glass-2: rgba(255, 255, 255, 0.5);
  --stroke: rgba(40, 80, 70, 0.14);
  --gold: #8f6c22;
  --gold-2: #b68a32;
  --emerald: #0f7a5c;
  --shadow: 0 16px 36px rgba(40, 50, 40, 0.12);
  --background: var(--bg0);
  --surface: var(--glass);
  --text-primary: var(--ink);
  --text-secondary: var(--muted);
  --border: var(--stroke);
  --accent: var(--gold);
}

/* System theme: follow OS when data-theme=system (resolved on html by JS) */
@media (prefers-color-scheme: light) {
  html[data-theme="system"] {
    --bg0: #f6f1e6;
    --bg1: #ece4d3;
    --ink: #14241f;
    --muted: #5a6e69;
    --glass: rgba(255, 252, 246, 0.72);
    --glass-2: rgba(255, 255, 255, 0.5);
    --stroke: rgba(40, 80, 70, 0.14);
    --gold: #8f6c22;
    --gold-2: #b68a32;
    --emerald: #0f7a5c;
    --shadow: 0 16px 36px rgba(40, 50, 40, 0.12);
  }
}
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg0: #07131b;
    --bg1: #0c1d26;
    --ink: #e8f2f3;
    --muted: #9db8bc;
    --glass: rgba(16, 42, 50, 0.55);
    --glass-2: rgba(255, 255, 255, 0.06);
    --stroke: rgba(210, 236, 228, 0.16);
    --gold: #d7b56d;
    --gold-2: #f3ddad;
    --emerald: #46d7b2;
    --shadow: 0 22px 50px rgba(0, 0, 0, 0.32);
  }
}

/* Softer night reading when dark (avoid pure white on pure black) */
html[data-theme="dark"],
html[data-theme="system"] {
  --reader-text: color-mix(in srgb, var(--ink) 92%, var(--gold-2));
}

html[data-contrast="high"] {
  --ink: #ffffff;
  --muted: #d5e6e8;
  --stroke: rgba(255, 255, 255, 0.35);
  --gold-2: #ffe9b0;
}
html[data-theme="light"][data-contrast="high"] {
  --ink: #0a1210;
  --muted: #2a3a36;
  --stroke: rgba(0, 0, 0, 0.35);
}

/* Size / spacing / width tokens driven by data-* on html */
html[data-arabic-size="sm"] { --reader-arabic-size: clamp(18px, 2vw, 24px); }
html[data-arabic-size="md"] { --reader-arabic-size: clamp(24px, 2.8vw, 34px); }
html[data-arabic-size="lg"] { --reader-arabic-size: clamp(28px, 3.2vw, 40px); }
html[data-arabic-size="xl"] { --reader-arabic-size: clamp(32px, 3.6vw, 46px); }
html[data-arabic-size="xxl"] { --reader-arabic-size: clamp(36px, 4.2vw, 54px); }

html[data-translation-size="sm"] { --reader-kanz-size: clamp(14px, 1.4vw, 18px); }
html[data-translation-size="md"] { --reader-kanz-size: clamp(17px, 1.8vw, 22px); }
html[data-translation-size="lg"] { --reader-kanz-size: clamp(19px, 2.1vw, 26px); }
html[data-translation-size="xl"] { --reader-kanz-size: clamp(21px, 2.4vw, 30px); }
html[data-translation-size="xxl"] { --reader-kanz-size: clamp(24px, 2.8vw, 34px); }

html[data-line-spacing="compact"] { --reader-line-height: 1.85; --reader-kanz-line-height: 1.9; }
html[data-line-spacing="normal"] { --reader-line-height: 2.15; --reader-kanz-line-height: 2.2; }
html[data-line-spacing="comfortable"] { --reader-line-height: 2.45; --reader-kanz-line-height: 2.5; }
html[data-line-spacing="wide"] { --reader-line-height: 2.75; --reader-kanz-line-height: 2.8; }

html[data-reading-width="narrow"] { --reader-max-width: 34rem; }
html[data-reading-width="comfortable"] { --reader-max-width: 46rem; }
html[data-reading-width="wide"] { --reader-max-width: 58rem; }
html[data-reading-width="full"] { --reader-max-width: 100%; }

html[data-arabic-font="naskh"] { --font-arabic: var(--naskh); }
html[data-arabic-font="traditional"] { --font-arabic: var(--traditional); }
html[data-arabic-font="amiri"] { --font-arabic: var(--amiri); }
html[data-urdu-font="nastaliq"] { --font-urdu: var(--nastaliq); }
html[data-urdu-font="segoe"] { --font-urdu: var(--segoe-ur); }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-urdu);
  color: var(--text-primary);
  background:
    radial-gradient(900px 520px at 8% -8%, rgba(70, 215, 178, 0.14), transparent 55%),
    radial-gradient(700px 420px at 100% 0%, rgba(215, 181, 109, 0.14), transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 52%, #08141b);
  padding-bottom: 84px;
}

html[data-theme="light"] body,
html[data-theme="system"] body {
  /* light body override when tokens are light — system uses media tokens */
}

html[data-theme="light"] body {
  background:
    radial-gradient(900px 500px at 6% -10%, rgba(20, 154, 120, 0.12), transparent 52%),
    linear-gradient(180deg, #f8f3e8, #ebe3d1);
}

@media (prefers-color-scheme: light) {
  html[data-theme="system"] body {
    background:
      radial-gradient(900px 500px at 6% -10%, rgba(20, 154, 120, 0.12), transparent 52%),
      linear-gradient(180deg, #f8f3e8, #ebe3d1);
  }
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(70, 215, 178, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(70, 215, 178, 0.035) 1px, transparent 1px);
  background-size: 78px 78px;
  mask-image: radial-gradient(circle at 50% 18%, black, transparent 78%);
  opacity: 0.5;
}

.wrap { width: min(1180px, calc(100% - 28px)); margin: 0 auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(18px);
  background: color-mix(in srgb, var(--bg0) 86%, transparent);
  border-bottom: 1px solid var(--stroke);
}
.topbar-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 14px 0 16px;
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand b { font-size: clamp(18px, 2.4vw, 26px); color: var(--gold-2); line-height: 1.45; }
.brand span { color: var(--muted); font-size: 13px; }

/* Phase 11C: desktop two-row top nav — never replaced by مزید on wide screens */
.nav.nav-desktop {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
}
.nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
  width: 100%;
}
.nav a,
.nav .icon-btn,
.icon-btn {
  border: 1px solid color-mix(in srgb, var(--stroke) 80%, var(--gold) 20%);
  background: var(--glass);
  border-radius: 14px;
  padding: 12px 16px;
  min-height: 48px;
  min-width: 44px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--ink);
  text-decoration: none;
  box-sizing: border-box;
}
.nav a.active {
  border-color: color-mix(in srgb, var(--gold) 70%, var(--stroke));
  background: color-mix(in srgb, var(--gold) 22%, var(--glass));
  color: var(--gold-2);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--gold) 35%, transparent);
  font-weight: 700;
}
.nav a:hover,
.icon-btn:hover {
  border-color: color-mix(in srgb, var(--gold) 55%, var(--stroke));
  color: var(--gold-2);
}
.nav a:focus-visible,
.icon-btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--emerald) 70%, transparent);
  outline-offset: 2px;
}
.icon-btn { cursor: pointer; font-family: inherit; }
.nav-update-btn { position: relative; }
.nav-update-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--bg0) 70%, transparent);
}
.nav-update-dot[hidden] { display: none !important; }
[data-theme="light"] .nav a.active {
  background: color-mix(in srgb, var(--gold) 28%, var(--glass));
  color: var(--gold-2);
}
@media (prefers-color-scheme: light) {
  html[data-theme="system"] .nav a.active {
    background: color-mix(in srgb, var(--gold) 28%, var(--glass));
    color: var(--gold-2);
  }
}
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .nav a.active {
    background: color-mix(in srgb, var(--gold) 22%, var(--glass));
    color: var(--gold-2);
  }
}

.hero, .panel, .card, .ayah, .book, .pkg {
  background:
    linear-gradient(180deg, var(--glass-2), transparent 42%),
    var(--glass);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.hero {
  margin: 28px 0 22px;
  padding: 34px 28px;
  border-radius: 32px;
}
.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 5vw, 48px);
  color: var(--gold-2);
}
.hero p { margin: 0; color: var(--muted); line-height: 2.1; max-width: 46rem; }

.grid-core, .grid-books, .grid-pkgs {
  display: grid;
  gap: 16px;
}
.grid-core { grid-template-columns: repeat(5, 1fr); margin-bottom: 48px; }
.grid-books { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid-pkgs { grid-template-columns: repeat(2, 1fr); }

.card, .book, .pkg, .surah-chip {
  border-radius: var(--radius);
  padding: 22px 20px;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.lift:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--emerald) 45%, var(--stroke));
}
.card h2, .book h2, .pkg h2 { margin: 0 0 8px; font-size: 21px; }
.kicker {
  display: inline-block;
  color: var(--emerald);
  font-size: 12px;
  margin-bottom: 8px;
  font-family: var(--sans);
}
.muted { color: var(--muted); line-height: 2; }
.group-title {
  margin: 28px 0 12px;
  color: var(--gold-2);
  font-size: 26px;
}
.is-off { opacity: 0.45; pointer-events: none; }
.surah-chip { display: block; margin-bottom: 8px; padding: 12px 14px; }
.surah-chip.active { border-color: color-mix(in srgb, var(--gold) 55%, var(--stroke)); }

.reader {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  margin: 22px 0 48px;
}
.side {
  border-radius: var(--radius);
  padding: 16px;
  max-height: calc(100vh - 120px);
  overflow: auto;
  position: sticky;
  top: 82px;
}
.main { min-width: 0; }
.ayah { border-radius: 20px; padding: 20px 22px 16px; margin-bottom: 14px; }
.ayah-no { color: var(--gold); font-family: var(--sans); font-size: 12px; }
.arabic {
  font-family: var(--font-arabic);
  font-size: var(--reader-arabic-size);
  line-height: var(--reader-line-height);
  margin: 8px 0 10px;
  color: var(--reader-text);
  max-width: var(--reader-max-width);
}
.kanz {
  font-family: var(--font-urdu);
  font-size: var(--reader-kanz-size);
  line-height: var(--reader-kanz-line-height);
  color: color-mix(in srgb, var(--ink) 88%, var(--gold));
  max-width: var(--reader-max-width);
}
.main .ayah {
  max-width: var(--reader-max-width);
}
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 18px;
  position: sticky;
  top: 8px;
  z-index: 6;
  padding: 8px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--bg0) 72%, transparent);
  backdrop-filter: blur(12px);
}
.nav-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.nav-btn.is-off,
.nav-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  pointer-events: none;
}
.btn {
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, color-mix(in srgb, var(--emerald) 16%, var(--glass)), var(--glass));
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-gold { background: linear-gradient(180deg, color-mix(in srgb, var(--gold) 26%, var(--glass)), var(--glass)); }
.btn-takhrij {
  background: linear-gradient(180deg, color-mix(in srgb, var(--emerald) 32%, var(--glass)), var(--glass));
}
.btn-shawahid {
  background: linear-gradient(180deg, color-mix(in srgb, var(--gold) 18%, var(--glass)), var(--glass));
  border-color: color-mix(in srgb, var(--gold) 45%, var(--stroke));
}
.link-panel {
  display: none;
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--glass) 70%, transparent);
  line-height: 2;
}
.link-panel.open { display: block; }
.btn:focus-visible, .nav a:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.orb-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  margin-top: 22px;
  align-items: center;
}
.orb-form input, .search-row input, .search-row select {
  width: 100%;
  background: color-mix(in srgb, var(--glass) 80%, transparent);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 14px 16px;
}
.orb {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--emerald) 45%, var(--stroke));
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.28), transparent 36%),
              radial-gradient(circle at 50% 55%, color-mix(in srgb, var(--emerald) 35%, transparent), var(--glass));
  cursor: pointer;
  display: grid;
  place-items: center;
}
.orb-core {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold-2);
  box-shadow: 0 0 18px color-mix(in srgb, var(--emerald) 55%, transparent);
}
.orb.listening { animation: pulse 1.6s ease-in-out infinite; }
.orb .wave {
  display: none;
  position: absolute;
  inset: auto 10px 8px;
  height: 10px;
  gap: 3px;
}
.orb { position: relative; }
.orb.listening .wave {
  display: none;
}
.orb .wave i {
  width: 3px;
  height: 4px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--gold) 70%, white);
  animation: wave 0.7s ease-in-out infinite;
}
.orb .wave i:nth-child(2) { animation-delay: 0.12s; height: 7px; }
.orb .wave i:nth-child(3) { animation-delay: 0.24s; height: 9px; }
.orb .wave i:nth-child(4) { animation-delay: 0.36s; }
@keyframes wave { 50% { transform: scaleY(1.8); } }

.search-box, .voice-box { border-radius: 28px; padding: 18px; margin-bottom: 16px; }
.voice-box {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 10px;
  align-items: center;
}
.voice-box .live { grid-column: 1 / -1; }
.diag-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}
.diag-table th, .diag-table td {
  border: 1px solid var(--stroke);
  padding: 8px 10px;
  text-align: start;
}
.diag-table th { width: 42%; color: var(--muted); font-weight: 600; }
.search-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; }
.composer-panel { padding: 16px; }
.composer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: end;
}
.composer-row textarea {
  width: 100%;
  min-height: 56px;
  max-height: 160px;
  resize: none;
  background: color-mix(in srgb, var(--glass) 80%, transparent);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 14px 16px;
  font: inherit;
  line-height: 1.7;
}
.composer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}
.composer-meta select {
  background: transparent;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 4px 8px;
  color: inherit;
}
.btn-send {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--gold) 50%, var(--stroke));
  background: color-mix(in srgb, var(--gold) 22%, var(--glass));
  color: var(--gold-2);
  cursor: pointer;
  font-size: 20px;
}
.orb.listening {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--emerald) 28%, transparent),
    0 0 22px color-mix(in srgb, var(--gold) 35%, transparent);
  animation: none;
}
.wave-strip {
  margin-top: 8px;
  height: 44px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--emerald) 28%, var(--stroke));
  background: color-mix(in srgb, var(--glass) 70%, transparent);
}
.voice-partial {
  margin: 8px 0 0;
  font-size: 0.95rem;
  line-height: 1.8;
  min-height: 1.4em;
}
.voice-partial .unstable {
  opacity: 0.55;
  font-weight: 400;
}
.mic-level {
  margin: 6px 0 0;
  font-size: 13px;
}
.voice-settings {
  font-size: 13px;
  color: var(--muted);
}
.voice-settings summary {
  cursor: pointer;
}
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 10px 0 22px;
}
mark.search-hit {
  color: #c62828;
  background: color-mix(in srgb, #ff8a80 32%, transparent);
  border-radius: 4px;
  padding: 0 3px;
  box-decoration-break: clone;
}
.concept-note {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 2;
}
.chat-turns { margin: 0 0 16px; padding: 0 18px; color: var(--muted); font-size: 0.85rem; }
.chat-turns li { margin: 4px 0; }
.evidence-summary { color: var(--text); }
.research-role { font-size: 0.8rem; margin-top: -8px; }
.result-actions { margin-top: 8px; }
.match-label { font-size: 0.82rem; color: var(--muted); margin: 0 0 8px; }
.src-badge {
  display: inline-block;
  font-size: 11px;
  color: var(--gold-2);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 1px 8px;
  margin-inline-end: 6px;
}
.kanz-badge { color: color-mix(in srgb, var(--ink) 70%, var(--gold)); }
.ai-badge { color: color-mix(in srgb, var(--muted) 80%, var(--gold)); }
.mt-badge { color: color-mix(in srgb, #b45309 70%, var(--gold)); }
.related-qs, .facets p { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip { border: 1px solid var(--stroke); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--muted); }
.research-plan { margin: 0 0 14px; color: var(--muted); }
.arabic.snippet { font-size: calc(var(--reader-arabic-size) * 0.92); }
[data-theme="light"] mark.search-hit {
  color: #8b0000;
  background: #ffd6d6;
}
.modes { display: flex; gap: 8px; margin-bottom: 12px; }
.live {
  min-height: 52px;
  width: 100%;
  border: 1px dashed var(--stroke);
  border-radius: 16px;
  padding: 12px 14px;
  margin-top: 12px;
  background: transparent;
  resize: vertical;
}
.mic {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: radial-gradient(circle at 40% 30%, color-mix(in srgb, var(--emerald) 40%, transparent), var(--glass));
  cursor: pointer;
}
.mic.listening { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }

.notice {
  border-radius: 16px;
  padding: 12px 14px;
  border: 1px solid var(--stroke);
  color: var(--muted);
  margin: 12px 0 18px;
  line-height: 2;
}
.sirat {
  display: none;
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  color: var(--muted);
  line-height: 2;
}
.sirat.open { display: block; }
.hidden { display: none !important; }
mark {
  background: color-mix(in srgb, var(--gold) 35%, transparent);
  color: inherit;
  border-radius: 4px;
  padding: 0 2px;
}
.footer { color: var(--muted); text-align: center; padding: 28px 0 20px; font-size: 13px; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  display: none; /* desktop default: never show */
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg0) 82%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--stroke);
  z-index: 40;
}
.bottom-nav a,
.bottom-nav .nav-more > summary,
.bottom-nav .nav-more-panel button {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 4px;
  min-height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background: transparent;
  border: 0;
  color: inherit;
  font-family: inherit;
  width: 100%;
  cursor: pointer;
}
.bottom-nav a.active { background: var(--glass); color: var(--gold-2); }

/* Desktop / wide tablet: FORCE top two-row nav; NEVER bottom/More */
@media (min-width: 1024px) {
  .nav.nav-desktop { display: flex !important; }
  .bottom-nav,
  html[data-display-mode="standalone"] .bottom-nav {
    display: none !important;
  }
  body { padding-bottom: 0 !important; }
  .nav a, .nav .icon-btn, .icon-btn { font-size: 18px; min-height: 48px; }
}
@media (max-width: 1100px) {
  .grid-core { grid-template-columns: repeat(2, 1fr); }
}
/* Mobile / narrow: bottom nav only — hide desktop rows */
@media (max-width: 1023px) {
  .grid-pkgs, .reader { grid-template-columns: 1fr; }
  .side { position: static; max-height: 240px; }
  .search-row, .orb-form, .voice-box { grid-template-columns: 1fr; }
  .nav.nav-desktop { display: none !important; }
  .bottom-nav { display: grid !important; }
  body { padding-bottom: 72px; }
}
@media (max-width: 720px) {
  .composer-row { grid-template-columns: 1fr auto auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .lift:hover { transform: none; }
}

.icon-subtle {
  padding: 7px 12px;
  opacity: 0.92;
  font-size: 0.92em;
}
.note-dialog {
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 0;
  background: color-mix(in srgb, var(--bg0) 88%, transparent);
  color: inherit;
  max-width: min(480px, 92vw);
}
.note-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.note-editor {
  margin: 0;
  padding: 18px;
}
.note-editor textarea {
  width: 100%;
  min-height: 120px;
  margin: 12px 0;
  background: color-mix(in srgb, var(--glass) 80%, transparent);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 12px;
  color: inherit;
  font: inherit;
}
.lib-toast {
  position: fixed;
  inset-inline-start: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--glass) 90%, transparent);
  backdrop-filter: blur(12px);
  font-size: 14px;
}
.empty-state { opacity: 0.85; }
.collection-items { list-style: none; padding: 0; display: grid; gap: 12px; }
.notes-list { display: grid; gap: 12px; }

.storage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.storage-grid > div {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--glass) 70%, transparent);
}
.storage-grid b { display: block; margin-top: 4px; }
.pkg-status {
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--gold-2);
}
.pkg-progress {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--glass) 80%, transparent);
  border: 1px solid var(--stroke);
  overflow: hidden;
  margin: 8px 0;
}
.pkg-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, color-mix(in srgb, var(--emerald) 55%, transparent), var(--gold-2));
  width: 0;
}
.offline-banner { margin-bottom: 16px; }
.grid-pkgs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.pkg {
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--glass) 75%, transparent);
}


/* ---- Phase 4: reading mode + toolbar + settings ---- */
html[data-motion="reduced"] *,
html[data-motion="reduced"] *::before,
html[data-motion="reduced"] *::after {
  animation: none !important;
  transition: none !important;
}
html[data-motion="reduced"] .sky { opacity: 0.18; }
html[data-motion="reduced"] .lift:hover { transform: none; }

body.reading-mode .sky { opacity: 0.12; }
body.reading-mode .topbar .nav a:not([data-keep-nav]),
body.reading-mode .topbar .brand span,
body.reading-mode .hero,
body.reading-mode .side,
body.reading-mode .bottom-nav,
body.reading-mode .footer,
body.reading-mode .grid-core {
  display: none !important;
}
body.reading-mode .topbar-inner { justify-content: flex-start; }
body.reading-mode .reader { grid-template-columns: 1fr; }
body.reading-mode .wrap { width: min(var(--reader-max-width), calc(100% - 20px)); }
body.reading-mode .ayah {
  box-shadow: none;
  background: color-mix(in srgb, var(--glass) 55%, transparent);
}

.reader-toolbar {
  position: sticky;
  top: 64px;
  z-index: 25;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--bg0) 78%, transparent);
  backdrop-filter: blur(14px);
}
.reader-toolbar .btn {
  min-height: 44px;
  min-width: 44px;
}
body.reading-mode .reader-toolbar { top: 8px; }

.settings-grid {
  display: grid;
  gap: 16px;
}
.settings-card label {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}
.settings-card select,
.settings-card input[type="range"] {
  width: 100%;
  max-width: 28rem;
  background: color-mix(in srgb, var(--glass) 80%, transparent);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 10px 12px;
}
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.reading-exit {
  position: fixed;
  inset-inline-end: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 50;
  display: none;
}
body.reading-mode .reading-exit { display: inline-flex; }

@media (max-width: 980px) {
  .reader-toolbar { top: 0; }
  body.reading-mode .wrap { width: calc(100% - 16px); }
}

/* ---- Phase 5/11C: PWA update toast (top, non-blocking) — never bottom overlay ---- */
.pwa-banner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  inset-inline: 12px;
  bottom: auto;
  z-index: 90;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--bg0) 92%, transparent);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  max-width: min(520px, calc(100% - 24px));
  margin-inline: auto;
  left: 0;
  right: 0;
}
.pwa-banner[hidden] { display: none !important; }
.pwa-install-btn { font-size: 13px; }
.net-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  color: var(--muted);
  background: var(--glass);
  align-self: flex-start;
}
.net-chip[data-online="0"] { color: var(--gold-2); }
.bottom-nav { grid-template-columns: repeat(6, minmax(0, 1fr)); }
/* REMOVED: standalone must not force bottom nav on desktop */
html[data-display-mode="standalone"] .footer { padding-bottom: 12px; }

.nav-more { position: relative; }
.nav-more > summary {
  list-style: none;
  cursor: pointer;
  text-align: center;
  padding: 8px 4px;
  color: inherit;
}
.nav-more > summary::-webkit-details-marker { display: none; }
.nav-more-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  inset-inline: 0;
  display: grid;
  gap: 4px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--bg0) 92%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  min-width: 140px;
  z-index: 40;
}
.nav-more-panel a {
  display: block;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
}
.nav-more-panel a.active,
.nav-more-panel a:hover { background: var(--glass); color: var(--gold-2); }

.app-lock-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg0) 88%, transparent);
  backdrop-filter: blur(10px);
}
.app-lock-gate[hidden] { display: none !important; }
.app-lock-card { width: min(360px, 92vw); display: grid; gap: 10px; }
.app-lock-card input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--glass);
  color: inherit;
}
body.is-app-locked main,
body.is-app-locked .bottom-nav,
body.is-app-locked .topbar { visibility: hidden; }

.share-preview {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--glass);
  font-size: 13px;
}
.settings-card .toolbar { flex-wrap: wrap; gap: 8px; }

/* Phase 8 onboarding + errors + help */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 16px;
  background: color-mix(in srgb, var(--bg0) 82%, transparent);
  backdrop-filter: blur(8px);
}
.onboarding-card {
  width: min(420px, 94vw);
  display: grid;
  gap: 12px;
}
body.onboarding-open main { pointer-events: none; }
.error-host {
  position: fixed;
  inset-inline: 0;
  bottom: 72px;
  z-index: 950;
  display: grid;
  place-items: center;
  padding: 12px;
}
.error-card { width: min(440px, 94vw); }
.help-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.help-toc a {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  text-decoration: none;
  color: inherit;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.help-list { padding-inline-start: 1.2rem; line-height: 1.75; }
.empty-state .toolbar { margin-top: 10px; }
html[data-safe-mode="1"] .sky,
html[data-safe-mode="1"] .lift,
html[data-safe-mode="1"] .orb-core {
  animation: none !important;
  transition: none !important;
}
@media (prefers-reduced-motion: reduce) {
  .onboarding-overlay, .error-host { transition: none; }
}
