:root {
  --bg: #faf8f3;
  --surface: #ffffff;
  --surface-2: #f1eee6;
  --text: #22261f;
  --muted: #6b6f66;
  --line: #e2ddd0;
  --accent: #1f4d3a;
  --accent-soft: #e3eee7;
  --verse-bg: #f3efe2;
  --verse-border: #c9a85a;
  --hl: #fff1b8;
  --hl-speak: #d9eadf;
  --shadow: 0 6px 24px rgba(30, 40, 30, .12);
  --font-size: 18px;
  --line-height: 1.7;
  --reader-font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #f4ecd8; --surface: #fbf5e6; --surface-2: #ebe1c8; --text: #3b2f22; --muted: #7a6a55;
  --line: #ddd0b2; --accent: #7a4b1c; --accent-soft: #efe0c2; --verse-bg: #ece0c2; --verse-border: #b08a4a;
  --hl: #f7dc8a; --hl-speak: #e3d6b0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="sepia"]) {
    --bg: #121512; --surface: #1b1f1b; --surface-2: #242924; --text: #e4e6df; --muted: #9aa094;
    --line: #2f352f; --accent: #8fcfaa; --accent-soft: #1f3328; --verse-bg: #1f231d; --verse-border: #8c7640;
    --hl: #5a4c12; --hl-speak: #234232; --shadow: 0 6px 24px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121512; --surface: #1b1f1b; --surface-2: #242924; --text: #e4e6df; --muted: #9aa094;
  --line: #2f352f; --accent: #8fcfaa; --accent-soft: #1f3328; --verse-bg: #1f231d; --verse-border: #8c7640;
  --hl: #5a4c12; --hl-speak: #234232; --shadow: 0 6px 24px rgba(0,0,0,.5); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--ui-font);
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.title-wrap { flex: 1; min-width: 0; padding: 0 6px; }
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; flex: none; }
.icon-btn:active { background: var(--surface-2); }

main { max-width: 760px; margin: 0 auto; padding: 0 16px 140px; }

/* Home */
.continue {
  display: block; width: 100%; text-align: left; margin: 16px 0 6px; padding: 14px 16px;
  background: var(--accent); color: #fff; border-radius: 16px; box-shadow: var(--shadow);
}
:root[data-theme="dark"] .continue, :root:not([data-theme]) .continue { }
.continue small { display: block; opacity: .8; font-size: 12.5px; margin-bottom: 2px; }
.continue strong { font-size: 16px; }
.seg { display: flex; gap: 6px; margin: 14px 0 8px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.filter {
  width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--text); font-size: 16px; margin: 6px 0 4px;
}
.group-h { font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 18px 4px 6px; }
.slist { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 14px; border: 1px solid var(--line); overflow: hidden; }
.slist li + li { border-top: 1px solid var(--line); }
.srow { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 11px 14px; }
.srow:active { background: var(--surface-2); }
.snum {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13.5px;
}
.sname { font-weight: 600; font-size: 15.5px; }
.smeta { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.srow .grow { flex: 1; min-width: 0; }

/* Reader */
.reader { font-family: var(--reader-font); font-size: var(--font-size); line-height: var(--line-height); }
.reader .pg { content-visibility: auto; contain-intrinsic-size: auto 900px; }
.pgmark {
  font-family: var(--ui-font); font-size: 11.5px; color: var(--muted); text-align: center; margin: 22px 0 10px;
  display: flex; align-items: center; gap: 10px;
}
.pgmark::before, .pgmark::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.reader p { margin: 0 0 .85em; padding: 2px 6px; margin-left: -6px; margin-right: -6px; border-radius: 6px; transition: background .2s; }
.reader p.tr {
  background: var(--verse-bg); border-left: 3px solid var(--verse-border); padding: 10px 14px; margin: 8px 0 14px; border-radius: 4px 10px 10px 4px;
  font-style: italic;
}
.reader p.tr .an { font-style: normal; font-family: var(--ui-font); font-weight: 700; font-size: .72em; color: var(--verse-border); margin-right: 6px; }
.reader h2.topic { font-family: var(--ui-font); font-size: 1.05em; font-weight: 700; margin: 1.6em 0 .7em; color: var(--accent); padding: 0 6px; margin-left: -6px; border-radius: 6px; }
.reader .speaking { background: var(--hl-speak) !important; }
.reader .flash { background: var(--hl) !important; }
.reader mark { background: var(--hl); color: inherit; border-radius: 3px; }
.reader .bm::after { content: "★"; color: var(--verse-border); font-size: .7em; margin-left: 6px; font-style: normal; }
.surah-head { text-align: center; padding: 26px 0 10px; font-family: var(--ui-font); }
.surah-head .big { font-family: var(--reader-font); font-size: 30px; font-weight: 600; }
.surah-head .meta { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.surah-foot { display: flex; gap: 10px; margin: 30px 0; font-family: var(--ui-font); }
.surah-foot button { flex: 1; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 14px; }
.surah-foot button span { display: block; color: var(--muted); font-size: 12px; }

/* Search */
.search-box { position: sticky; top: calc(env(safe-area-inset-top) + 55px); background: var(--bg); padding: 12px 0 8px; z-index: 5; }
.search-status { font-size: 13px; color: var(--muted); margin: 6px 4px; min-height: 18px; }
.hit { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; margin: 8px 0; }
.hit .where { font-size: 12.5px; color: var(--accent); font-weight: 650; margin-bottom: 3px; }
.hit .snip { font-family: var(--reader-font); font-size: 15px; line-height: 1.5; }
.hit mark { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 1px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 14.5px; line-height: 1.6; }

/* Player */
.player {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 12px); z-index: 30;
  width: min(560px, calc(100% - 24px)); background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 8px 10px 8px 14px;
}
.player-info { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 0 4px; }
.player-controls { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.play-btn { width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--bg); display: grid; place-items: center; }
.play-btn svg { fill: currentColor; stroke: none; width: 24px; height: 24px; }
.rate-btn { min-width: 52px; height: 36px; border-radius: 10px; background: var(--surface-2); font-size: 13.5px; font-weight: 650; }
.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 18px); z-index: 25; width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: var(--bg); box-shadow: var(--shadow); display: grid; place-items: center;
}
.fab svg { fill: currentColor; stroke: none; width: 26px; height: 26px; }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 82vh; overflow: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 6px 16px calc(env(safe-area-inset-bottom) + 20px); max-width: 760px; margin: 0 auto;
  box-shadow: var(--shadow); overscroll-behavior: contain;
}
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 10px; }
.sheet h3 { font-size: 16px; margin: 10px 0 10px; }
.sheet .tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 12px; position: sticky; top: -6px; z-index: 2; }
.sheet .tabs button { flex: 1; padding: 8px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.sheet .tabs button.on { background: var(--surface); color: var(--text); font-weight: 600; }
.ayat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.ayat-grid button { padding: 10px 0; border-radius: 10px; background: var(--surface-2); font-size: 14px; font-weight: 600; }
.ayat-grid button.approx { color: var(--muted); font-weight: 400; }
.tlist { list-style: none; padding: 0; margin: 0; }
.tlist button { display: block; width: 100%; text-align: left; padding: 11px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.tlist small { color: var(--muted); }
.menu button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 13px 4px; font-size: 15.5px; border-bottom: 1px solid var(--line); text-align: left; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.setrow .ctl { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { padding: 7px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.chip.on { background: var(--accent); color: var(--bg); font-weight: 600; }
select.chip { border: 0; color: var(--text); max-width: 200px; }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 10px 0; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 110px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
}
[hidden] { display: none !important; }
