:root {
  --accent: #00796b;
  --accent-ink: #fff;
  --bg: #fafafa;
  --row: #fff;
  --juz: #e8eaea;
  --ink: #1d1d1d;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --bar-h: 52px;
  --page-bg: #fdfdf6;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; }
.icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon:active { background: rgba(255, 255, 255, .18); }

/* ---------- главная ---------- */
#home { min-height: 100%; }
.appbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: env(safe-area-inset-top) 8px 0 16px;
  height: calc(56px + env(safe-area-inset-top));
  background: var(--accent); color: var(--accent-ink);
}
.appbar h1 { margin: 0; font-size: 21px; font-weight: 500; }
.tabs {
  position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 2;
  display: flex; background: var(--accent);
}
.tabs button {
  flex: 1; height: 46px; color: rgba(255, 255, 255, .7);
  font-size: 15px; letter-spacing: .04em; text-transform: uppercase;
  border-bottom: 3px solid transparent;
}
.tabs button.on { color: #fff; border-bottom-color: #ff4081; }

.list { padding-bottom: env(safe-area-inset-bottom); }
.row {
  display: flex; align-items: center; gap: 14px;
  min-height: 64px; padding: 8px 16px;
  background: var(--row); border-bottom: 1px solid var(--line);
}
.row:active { background: #f0f0f0; }
.row .num { width: 34px; flex: none; text-align: center; font-size: 22px; color: #333; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 18px; }
.row .title .ar { margin-left: 10px; color: var(--muted); font-size: 17px; }
.row .sub { margin-top: 2px; color: var(--muted); font-size: 14px; }
.row .pg { flex: none; color: #333; font-size: 17px; font-variant-numeric: tabular-nums; }
.row.juz { min-height: 44px; background: var(--juz); font-size: 16px; }
.row.juz .main { color: #333; }
.row .del { flex: none; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); font-size: 22px; line-height: 1; }
.row .del:active { background: #e6e6e6; }
.section { padding: 14px 16px 8px; background: var(--juz); color: #333; font-size: 16px; }
.empty { padding: 14px 16px; color: var(--muted); font-size: 15px; }

/* ---------- читалка ---------- */
#reader { position: fixed; inset: 0; background: var(--page-bg); overflow: hidden; }
.bar {
  position: absolute; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center;
  background: var(--accent); color: var(--accent-ink);
  transition: transform .22s ease;
}
.bar.top {
  top: 0; height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  justify-content: space-between; gap: 12px;
  font-size: 17px;
}
.bar.top #r-sura { flex: 1; text-align: center; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar.top #r-juz, .bar.top #r-page { flex: none; min-width: 64px; }
.bar.top #r-page { text-align: right; font-variant-numeric: tabular-nums; }
.bar.bottom {
  bottom: 0; height: calc(var(--bar-h) + env(safe-area-inset-bottom));
  padding: 0 12px env(safe-area-inset-bottom);
  justify-content: space-between;
}
#reader.bare .bar.top { transform: translateY(-100%); }
#reader.bare .bar.bottom { transform: translateY(100%); }

#stage {
  position: absolute; inset: 0;
  padding: calc(var(--bar-h) + env(safe-area-inset-top)) 0 calc(var(--bar-h) + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: center;
  transition: padding .22s ease;
  touch-action: pan-y pinch-zoom;
  user-select: none; -webkit-user-select: none;
}
#reader.bare #stage { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
#pg {
  display: block;
  width: auto; height: auto;
  max-width: 100%; max-height: 100%;
  -webkit-user-drag: none;
  will-change: transform;
  transition: opacity .15s;
}
#pg.loading { opacity: .12; transition-delay: .25s; }

/* альбомная: страница во всю ширину, листаем вертикально */
@media (orientation: landscape) {
  #stage { display: block; overflow-y: auto; overscroll-behavior: contain; }
  #pg { width: 100%; max-width: 1000px; max-height: none; margin: 0 auto; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 10;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 20px;
  background: rgba(30, 30, 30, .88); color: #fff; font-size: 15px;
}
