/* =========================================================================
   Qur'an Reader — frontend styles
   ========================================================================= */
:root {
  --brand: #0b5d4b;
  --brand-2: #13836a;
  --brand-soft: #e7f2ee;
  --gold: #c9a24a;
  --gold-soft: #f7efdc;
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --border: #e2e8e5;
  --text: #15211d;
  --muted: #66746f;
  --arabic-color: #10241e;
  --highlight: #fff6df;
  --shadow-sm: 0 1px 2px rgba(15, 30, 25, .06);
  --shadow: 0 1px 2px rgba(15, 30, 25, .04), 0 8px 24px rgba(15, 30, 25, .07);
  --shadow-lg: 0 24px 64px rgba(10, 25, 20, .25);
  --radius: 16px;
  --radius-sm: 12px;
  --appbar-h: 64px;
  --panel-w: 300px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --arabic: "Amiri Quran", "Amiri", "Scheherazade New", "Traditional Arabic", serif;
  --ar-size: 32px;
  --tr-size: 16px;
  color-scheme: light;
}

:root[data-theme="sepia"] {
  --bg: #f4ecd8;
  --surface: #fbf6ea;
  --surface-2: #f1e8d3;
  --border: #e3d6b8;
  --text: #3b2f1e;
  --muted: #7d6c51;
  --arabic-color: #2e2212;
  --brand-soft: #ece3cb;
  --highlight: #f3e2b5;
}

:root[data-theme="dark"] {
  --brand: #3fbf98;
  --brand-2: #2a9b7a;
  --brand-soft: #16302a;
  --gold: #d9b45f;
  --gold-soft: #2c2616;
  --bg: #0c1513;
  --surface: #121d1a;
  --surface-2: #17241f;
  --border: #233430;
  --text: #e5eeeb;
  --muted: #8fa29c;
  --arabic-color: #f1f6f4;
  --highlight: #1d2f24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --brand: #3fbf98;
    --brand-2: #2a9b7a;
    --brand-soft: #16302a;
    --gold: #d9b45f;
    --gold-soft: #2c2616;
    --bg: #0c1513;
    --surface: #121d1a;
    --surface-2: #17241f;
    --border: #233430;
    --text: #e5eeeb;
    --muted: #8fa29c;
    --arabic-color: #f1f6f4;
    --highlight: #1d2f24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--appbar-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.6; -webkit-font-smoothing: antialiased;
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  transition: background .25s, color .25s;
}
a { color: var(--brand); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px; }

.skip-link { position: absolute; left: -999px; top: 8px; z-index: 999; background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 12px; border: 0; background: transparent; color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn .dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px var(--surface); }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.5) blur(14px); -webkit-backdrop-filter: saturate(1.5) blur(14px);
  border-bottom: 1px solid var(--border);
}
.appbar-inner { height: var(--appbar-h); display: flex; align-items: center; gap: 10px; padding: 0 16px; max-width: 1480px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #0b5d4b, #13836a); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .14);
}
.brand-mark img { width: 28px; height: 28px; object-fit: contain; }
.brand-text strong { display: block; font-size: 1rem; line-height: 1.15; letter-spacing: -.01em; }
.brand-text small { display: block; font-size: .72rem; color: var(--muted); font-weight: 500; }
.appbar-center { flex: 1; min-width: 0; display: flex; justify-content: center; }
.appbar-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.support-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; margin-right: 6px; border-radius: 999px;
  background: linear-gradient(135deg, #d4ae55, #b8872f); color: #fff; font-weight: 700; font-size: .85rem; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(184, 135, 47, .35); transition: transform .15s, box-shadow .15s, filter .15s;
}
.support-btn:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 6px 18px rgba(184, 135, 47, .45); }
.support-btn i { animation: beat 2.4s ease-in-out infinite; }
@keyframes beat { 0%, 20%, 40%, 100% { transform: scale(1); } 10%, 30% { transform: scale(1.18); } }
.footer-support { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--gold); }
.footer-support:hover { text-decoration: underline; }
.appbar-surah {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; font-size: .9rem;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s;
}
.appbar-surah.show { opacity: 1; transform: none; }
.appbar-surah .ar { font-family: var(--arabic); font-size: 1.1rem; font-weight: 400; color: var(--brand); }
.read-progress { height: 2px; background: transparent; }
.read-progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--gold)); transition: width .1s linear; }

body:not(.is-reader) .reader-only { display: none !important; }
body.is-reader .brand-text { display: none; }

/* ---------- Shell ---------- */
.shell { flex: 1; display: flex; width: 100%; max-width: 1480px; margin: 0 auto; }
.main { flex: 1; min-width: 0; outline: none; }

.surah-panel { display: none; }
body.is-reader .surah-panel {
  display: flex; flex-direction: column; width: var(--panel-w); flex: none;
  position: sticky; top: calc(var(--appbar-h) + 2px); height: calc(100vh - var(--appbar-h) - 2px);
  border-right: 1px solid var(--border); background: var(--surface);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 4px; }
.search-box { position: relative; margin: 14px 14px 8px; }
.search-box i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .85rem; }
.search-box input {
  width: 100%; padding: 10px 12px 10px 36px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.panel-list { flex: 1; overflow-y: auto; padding: 4px 8px 20px; overscroll-behavior: contain; }
.panel-item {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 12px; background: none; text-align: left; color: var(--text);
}
.panel-item:hover { background: var(--surface-2); }
.panel-item.active { background: var(--brand-soft); }
.panel-item .num { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; font-size: .78rem; font-weight: 700; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); }
.panel-item.active .num { background: var(--brand); color: #fff; border-color: var(--brand); }
.panel-item .nm { font-weight: 600; font-size: .9rem; line-height: 1.2; }
.panel-item .sub { display: block; font-size: .74rem; color: var(--muted); }
.panel-item .ar { font-family: var(--arabic); font-size: 1.15rem; color: var(--brand); }

/* ---------- Home ---------- */
.hero {
  position: relative; overflow: hidden; color: #fff;
  background: radial-gradient(1000px 400px at 85% 0%, rgba(201, 162, 74, .35), transparent 60%),
              linear-gradient(140deg, #08473a 0%, #0b5d4b 45%, #13836a 100%);
}
.hero-pattern {
  position: absolute; inset: 0; opacity: .12;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23fff' stroke-width='1'%3E%3Cpath d='M40 4l10 26 26 10-26 10-10 26-10-26L4 40l26-10z'/%3E%3Crect x='22' y='22' width='36' height='36' transform='rotate(45 40 40)'/%3E%3Ccircle cx='40' cy='40' r='8'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 80px 80px;
  mask-image: linear-gradient(to bottom, #000 30%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent);
}
.hero-inner { position: relative; max-width: 820px; margin: 0 auto; padding: 56px 20px 64px; text-align: center; }
.hero-greet { display: inline-block; margin: 0 0 14px; padding: 5px 14px; border-radius: 999px; background: rgba(255, 255, 255, .12); font-size: .82rem; font-weight: 600; letter-spacing: .02em; border: 1px solid rgba(255, 255, 255, .18); }
.hero h1 { margin: 0; font-size: clamp(1.7rem, 4.2vw, 2.7rem); line-height: 1.2; letter-spacing: -.02em; font-weight: 800; }
.hero-bismillah { font-family: var(--arabic); font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 18px 0 26px; color: #f6e7bf; line-height: 1.8; }
.hero-search { position: relative; max-width: 620px; margin: 0 auto; }
.hero-search i { position: absolute; left: 20px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.hero-search input {
  width: 100%; padding: 17px 56px 17px 50px; border: 0; border-radius: 16px; font-size: 1rem;
  background: var(--surface); color: var(--text); box-shadow: 0 16px 40px rgba(0, 0, 0, .2); outline: none;
}
.hero-search input:focus { box-shadow: 0 0 0 4px rgba(201, 162, 74, .5), 0 16px 40px rgba(0, 0, 0, .2); }
.hero-search kbd { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font: 600 .75rem var(--font); color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; background: var(--surface-2); }

.quick-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: -32px; position: relative; z-index: 2; }
.quick-card {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.quick-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--brand) 35%, var(--border)); }
.quick-card .qi { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-size: 1.1rem; flex: none; }
.quick-card.gold .qi { background: var(--gold-soft); color: var(--gold); }
.quick-card .qt { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.quick-card .qv { font-weight: 700; line-height: 1.25; }
.quick-card .qs { font-size: .82rem; color: var(--muted); }
.quick-card .go { margin-left: auto; color: var(--muted); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 36px 0 16px; }
.section-head h2 { margin: 0; font-size: 1.3rem; letter-spacing: -.01em; }

.seg { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); gap: 2px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg-full { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; }
.seg-full button { padding: 9px 4px; font-size: .8rem; display: flex; flex-direction: column; align-items: center; gap: 4px; }

.surah-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; padding-bottom: 48px; }
.surah-card {
  display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
  color: var(--text); transition: border-color .15s, box-shadow .15s, transform .15s;
}
.surah-card:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--border)); box-shadow: var(--shadow); transform: translateY(-1px); }
.star {
  position: relative; isolation: isolate; width: 44px; height: 44px; display: grid; place-items: center; font-weight: 700; font-size: .85rem; color: var(--brand);
}
.star::before, .star::after {
  content: ""; position: absolute; inset: 6px; border: 1.5px solid color-mix(in srgb, var(--brand) 45%, transparent); border-radius: 8px; z-index: -1; transition: background .15s;
}
.star::after { transform: rotate(45deg); }
.surah-card:hover .star::before, .surah-card:hover .star::after { background: var(--brand-soft); }
.surah-card .nm { font-weight: 700; line-height: 1.25; }
.surah-card .sub { font-size: .8rem; color: var(--muted); }
.surah-card .ar { font-family: var(--arabic); font-size: 1.45rem; color: var(--brand); text-align: right; line-height: 1.3; }
.surah-card .ar small { display: block; font-family: var(--font); font-size: .72rem; color: var(--muted); }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state i { font-size: 2rem; display: block; margin-bottom: 10px; opacity: .5; }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
.card-skel { height: 76px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Reader ---------- */
.reader { max-width: 900px; margin: 0 auto; padding: 24px 20px 40px; }
.surah-header {
  position: relative; overflow: hidden; border-radius: 22px; padding: 30px 24px 26px; text-align: center; color: #fff;
  background: radial-gradient(600px 240px at 90% -10%, rgba(201, 162, 74, .45), transparent 60%),
              linear-gradient(140deg, #08473a, #0b5d4b 50%, #13836a);
  box-shadow: var(--shadow);
}
.surah-header::before {
  content: ""; position: absolute; inset: 0; opacity: .1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23fff' stroke-width='1.2'%3E%3Cpath d='M40 4l10 26 26 10-26 10-10 26-10-26L4 40l26-10z'/%3E%3C/g%3E%3C/svg%3E");
}
.surah-header > * { position: relative; }
.surah-header .sh-ar { font-family: var(--arabic); font-size: clamp(2.2rem, 7vw, 3.2rem); line-height: 1.5; color: #f6e7bf; }
.surah-header h1 { margin: 2px 0 2px; font-size: clamp(1.35rem, 3.5vw, 1.75rem); letter-spacing: -.01em; }
.surah-header .sh-meaning { opacity: .9; }
.sh-meta { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.sh-meta span { font-size: .78rem; font-weight: 600; padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, .13); border: 1px solid rgba(255, 255, 255, .18); }
.sh-tafsir {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; padding: 10px 20px; border-radius: 999px;
  border: 0; cursor: pointer; font-weight: 700; font-size: .9rem; color: #3a2a06;
  background: linear-gradient(135deg, #f6e7bf, #d9b45f); box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  transition: transform .15s, box-shadow .15s;
}
.sh-tafsir:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0, 0, 0, .22); }
.sh-tafsir:focus-visible { outline: 3px solid #f6e7bf; outline-offset: 3px; }
.sh-tafsir[hidden] { display: none; }
.tafsir-tag { font-size: .72em; color: var(--gold); vertical-align: .1em; margin-left: 2px; }
.bismillah { font-family: var(--arabic); text-align: center; font-size: calc(var(--ar-size) * 1.05); color: var(--arabic-color); margin: 26px 0 6px; line-height: 2; }

.reader-toolbar {
  position: sticky; top: calc(var(--appbar-h) + 10px); z-index: 20;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
  margin: 18px auto 8px; padding: 8px; width: fit-content; max-width: 100%;
  border-radius: 16px; background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(12px);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: .86rem; color: var(--text);
}
.pill i { color: var(--muted); }
.pill-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.pill-primary i { color: inherit; }
.pill-primary:hover { filter: brightness(1.07); }
.pill[hidden] { display: none; }
.pill-gold { background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold) 55%, transparent); color: var(--text); cursor: pointer; }
.pill-gold i { color: var(--gold); }
.pill-gold:hover { border-color: var(--gold); }
.pill-select { padding-right: 6px; }
.pill-select select { border: 0; background: transparent; font-weight: 600; outline: none; max-width: 190px; padding: 6px 0; }
.jump { padding-right: 4px; }
.jump input { width: 64px; border: 0; background: transparent; outline: none; font-weight: 600; -moz-appearance: textfield; }
.jump input::-webkit-outer-spin-button, .jump input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.jump button { width: 32px; height: 32px; border-radius: 8px; border: 0; background: var(--surface-2); color: var(--muted); }
.jump button:hover { color: var(--brand); }

.ayah-list { margin-top: 10px; }
.ayah {
  position: relative; padding: 26px 4px 22px; border-bottom: 1px solid var(--border);
  transition: background .3s;
}
.ayah.playing, .ayah.flash { background: var(--highlight); border-radius: var(--radius); border-bottom-color: transparent; }
.ayah.flash { animation: flash 2s ease forwards; }
@keyframes flash { 0%, 50% { background: var(--highlight); } 100% { background: transparent; } }
.ayah.playing { padding-left: 16px; padding-right: 16px; }
.ayah-top { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ayah-ref { font-size: .78rem; font-weight: 700; color: var(--brand); padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); white-space: nowrap; }
.ayah-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.ayah-tags span { font-size: .72rem; color: var(--muted); padding: 3px 8px; border: 1px solid var(--border); border-radius: 999px; }
.ayah-tags .sajda { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 50%, transparent); }
.ayah-actions { margin-left: auto; display: flex; gap: 2px; opacity: .85; }
.ayah-actions .icon-btn { width: 36px; height: 36px; border-radius: 10px; font-size: .92rem; }
.ayah-actions .icon-btn.on { color: var(--gold); }
.ayah-actions .icon-btn.playing-btn { color: var(--brand); }
.arabic {
  font-family: var(--arabic); font-size: var(--ar-size); line-height: 2.15; color: var(--arabic-color);
  direction: rtl; text-align: right; margin: 0; word-spacing: .06em;
}
.ayah-end {
  display: inline-grid; place-items: center; min-width: 1.55em; height: 1.55em; padding: 0 .2em; margin: 0 .2em;
  font-size: .62em; line-height: 1; vertical-align: .18em; color: var(--brand);
  border: 1.5px solid color-mix(in srgb, var(--gold) 70%, transparent); border-radius: 50%;
  font-family: "Amiri", serif; font-weight: 700;
}
.translation { font-size: var(--tr-size); color: var(--text); opacity: .86; margin: 14px 0 0; line-height: 1.75; }
.translation sup { font-size: .65em; color: var(--muted); }
body.hide-tr .ayah .translation { display: none; }

.surah-nav { display: flex; gap: 12px; margin-top: 32px; }
.surah-nav a {
  flex: 1; display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.surah-nav a:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.surah-nav a.next { justify-content: flex-end; text-align: right; }
.surah-nav small { display: block; color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.surah-nav strong { display: block; }
.surah-nav i { color: var(--brand); }

.state-box { text-align: center; padding: 60px 16px; color: var(--muted); }
.state-box i { font-size: 2rem; margin-bottom: 12px; display: block; opacity: .55; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; margin-top: 14px; }
.btn:hover { border-color: var(--brand); color: var(--brand); }

.ayah-skel { padding: 26px 0; border-bottom: 1px solid var(--border); }
.ayah-skel .l1 { height: 22px; width: 90px; margin-bottom: 18px; }
.ayah-skel .l2 { height: 42px; width: 85%; margin-left: auto; margin-bottom: 12px; }
.ayah-skel .l3 { height: 16px; width: 70%; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 18px 0; font-size: .82rem; color: var(--muted); background: var(--surface); }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
body.player-open .site-footer { padding-bottom: 96px; }

/* ---------- Player ---------- */
.player {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 45;
  width: min(640px, calc(100% - 24px));
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg);
  animation: rise .25s ease;
}
@keyframes rise { from { transform: translate(-50%, 20px); opacity: 0; } }
.player-inner { display: flex; align-items: center; gap: 4px; padding: 8px 10px; }
.play-btn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 40%, transparent); }
.player-info { flex: 1; min-width: 0; padding: 0 10px; }
.player-info strong { display: block; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-info small { display: block; color: var(--muted); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-bar { height: 3px; background: var(--border); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.player-bar span { display: block; height: 100%; width: 0; background: var(--brand); }
#pl-repeat.on { color: var(--gold); background: var(--gold-soft); }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  width: 46px; height: 46px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); display: grid; place-items: center;
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s, bottom .2s;
}
.fab.show { opacity: 1; transform: none; pointer-events: auto; }
body.player-open .fab { bottom: calc(100px + env(safe-area-inset-bottom)); }

/* ---------- Drawers ---------- */
.scrim { position: fixed; inset: 0; background: rgba(5, 15, 12, .45); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100%); z-index: 70;
  background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 14px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; font-size: 1.05rem; display: flex; gap: 10px; align-items: center; }
.drawer-head h3 i { color: var(--brand); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 32px; overscroll-behavior: contain; }

.settings .setting { margin-bottom: 20px; }
.settings label { display: flex; justify-content: space-between; font-weight: 600; font-size: .88rem; margin-bottom: 8px; }
.settings output { color: var(--brand); font-weight: 700; }
.settings select {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); outline: none;
}
.settings select:focus { border-color: var(--brand); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting-row > label:first-child { margin: 0; }
input[type="range"] { width: 100%; accent-color: var(--brand); }

.switch { position: relative; display: inline-block !important; width: 46px; height: 26px; flex: none; margin: 0 !important; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 26px; background: var(--border); transition: background .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--brand-soft); }

.preview-card { padding: 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border); }
.preview-card .translation { margin-top: 8px; }

.bm-item {
  display: block; width: 100%; text-align: left; padding: 14px 16px; margin-bottom: 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); position: relative;
  transition: border-color .15s;
}
.bm-item:hover { border-color: var(--brand); }
.bm-item .bm-head { display: flex; align-items: center; gap: 8px; padding-right: 36px; }
.bm-item .bm-head strong { font-size: .9rem; }
.bm-item .bm-head small { color: var(--muted); font-size: .78rem; }
.bm-item .arabic { font-size: 1.35rem; line-height: 2; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bm-item .bm-tr { font-size: .84rem; color: var(--muted); margin: 4px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bm-item .bm-del { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; }
.bm-item .bm-del:hover { color: #c2413b; }

/* ---------- Palette ---------- */
.palette { position: fixed; inset: 0; z-index: 80; background: rgba(5, 15, 12, .5); display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } }
.palette-box { width: min(620px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--border); }
.palette-input { display: flex; align-items: center; gap: 12px; padding: 0 14px 0 18px; border-bottom: 1px solid var(--border); }
.palette-input i { color: var(--muted); }
.palette-input input { flex: 1; border: 0; outline: none; background: transparent; padding: 18px 0; font-size: 1.02rem; }
.palette-input .esc { border: 1px solid var(--border); background: var(--surface-2); border-radius: 7px; font-size: .72rem; font-weight: 600; padding: 3px 8px; color: var(--muted); }
.palette-list { overflow-y: auto; padding: 8px; }
.palette-list .panel-item[aria-selected="true"] { background: var(--brand-soft); }
.palette-hint { padding: 10px 12px; font-size: .8rem; color: var(--muted); }

/* ---------- Tafsir popup ---------- */
html.modal-open, html.modal-open body { overflow: hidden; }
.tafsir-modal {
  position: fixed; inset: 0; z-index: 85; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(5, 15, 12, .6); animation: fade .18s;
}
.tafsir-modal[hidden] { display: none; }
.tafsir-box {
  width: min(1040px, 100%); height: 100%; max-height: 100%; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; overflow: hidden;
  box-shadow: var(--shadow-lg); animation: pop .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
.tafsir-head {
  display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 14px; flex: none;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.tafsir-icon {
  width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center; margin-right: 8px;
  background: var(--gold-soft); color: var(--gold);
}
.tafsir-heading { flex: 1; min-width: 0; line-height: 1.25; }
.tafsir-heading small { display: block; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); }
.tafsir-heading strong { display: block; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tafsir-body { position: relative; flex: 1; min-height: 0; background: var(--surface-2); }
.tafsir-body iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block;
  background: #fff; opacity: 0; transition: opacity .25s;
}
.tafsir-body.loaded iframe { opacity: 1; }
.tafsir-loader { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.tafsir-body.loaded .tafsir-loader { display: none; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tafsir-slow { margin: 0; font-size: .88rem; color: var(--muted); opacity: 0; transition: opacity .3s; }
.tafsir-slow a { color: var(--brand); font-weight: 600; white-space: nowrap; }
.tafsir-body.slow .tafsir-slow { opacity: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px); z-index: 90;
  background: #11201b; color: #fff; padding: 11px 18px; border-radius: 12px; font-size: .9rem; font-weight: 500;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.player-open .toast { bottom: calc(104px + env(safe-area-inset-bottom)); }

/* ---------- Responsive ---------- */
@media (min-width: 1100px) {
  .lg-hide { display: none !important; }
}
@media (max-width: 1099px) {
  .quick-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.is-reader .surah-panel {
    position: fixed; top: 0; left: 0; bottom: 0; height: auto; z-index: 70; width: min(var(--panel-w), 88vw);
    transform: translateX(-105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); box-shadow: var(--shadow-lg); visibility: hidden;
  }
  body.is-reader .surah-panel.open { transform: none; visibility: visible; }
}
@media (max-width: 700px) {
  :root { --appbar-h: 58px; }
  .container { padding: 0 16px; }
  .appbar-inner { padding: 0 8px 0 10px; gap: 4px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .brand-mark img { width: 24px; height: 24px; }
  .icon-btn { width: 40px; height: 40px; }
  .hide-sm { display: none !important; }
  .support-btn { width: 38px; padding: 0; justify-content: center; margin-right: 2px; }
  .support-btn span { display: none; }
  .hero-inner { padding: 40px 16px 56px; }
  .hero-search input { padding: 15px 16px 15px 46px; font-size: .95rem; }
  .quick-row { grid-template-columns: 1fr; gap: 10px; margin-top: -28px; }
  .section-head { margin-top: 28px; }
  .section-head .seg { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  .surah-grid { grid-template-columns: 1fr; gap: 8px; }
  .surah-card { padding: 12px 14px; gap: 12px; }
  .reader { padding: 14px 16px 32px; }
  .surah-header { padding: 24px 16px 20px; border-radius: 18px; }
  .reader-toolbar { width: 100%; gap: 6px; padding: 6px; top: calc(var(--appbar-h) + 6px); flex-wrap: nowrap; }
  .reader-toolbar .pill { padding: 0 10px; height: 38px; font-size: .8rem; }
  #btn-play-surah span { display: none; }
  .pill-select { flex: 1; min-width: 0; }
  .pill-select select { max-width: none; width: 100%; min-width: 0; text-overflow: ellipsis; }
  .jump input { width: 44px; }
  .ayah { padding: 20px 0 18px; }
  .ayah.playing { padding-left: 10px; padding-right: 10px; margin: 0 -6px; }
  .ayah-actions .icon-btn { width: 34px; height: 34px; }
  .arabic { line-height: 2.05; }
  .surah-nav { flex-direction: column; }
  .drawer { width: 100%; }
  .player { border-radius: 16px; }
  .player-inner { padding: 6px; }
  .player .icon-btn { width: 36px; height: 36px; }
  .play-btn { width: 42px; height: 42px; }
  #pl-repeat { display: none; }
  .fab { right: 14px; }
  .palette { padding-top: 12px; }
  .palette-box { max-height: 82vh; }
  #btn-tafsir span { display: none; }
  .sh-tafsir { margin-top: 14px; padding: 9px 18px; font-size: .86rem; }
  /* Tafsir popup goes full-screen on phones */
  .tafsir-modal { padding: 0; background: var(--surface); animation: none; }
  .tafsir-box { width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none; animation: slide-up .25s cubic-bezier(.2, .8, .2, 1); }
  .tafsir-head { padding: calc(6px + env(safe-area-inset-top)) 4px 6px calc(10px + env(safe-area-inset-left)); }
  .tafsir-icon { width: 34px; height: 34px; margin-right: 6px; }
  .tafsir-body { margin-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 380px) {
  .ayah-tags { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .appbar, .reader-toolbar, .ayah-actions, .player, .fab, .site-footer, .surah-panel, .surah-nav, .sh-tafsir, .tafsir-modal { display: none !important; }
  .surah-header { color: #000; background: none; box-shadow: none; border: 1px solid #ccc; }
}
