@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;700&family=Amiri:wght@400;700&display=swap');

:root {
  --bg: #f3efe6;
  --bg-accent: #e7efe8;
  --ink: #1c2b24;
  --muted: #5d6b63;
  --brand: #1f6b4a;
  --brand-deep: #134632;
  --surface: rgba(255, 255, 255, 0.72);
  --line: rgba(28, 43, 36, 0.12);
  --danger: #9b3b3b;
  --radius: 18px;
  --shadow: 0 18px 40px rgba(28, 43, 36, 0.08);
  --sidebar-width: 280px;
  --font: "Vazirmatn", sans-serif;
  --font-ar: "Amiri", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, #dce9df 0%, transparent 55%),
    radial-gradient(900px 500px at -10% 100%, #efe4d2 0%, transparent 50%),
    var(--bg);
  min-height: 100%;
  direction: rtl;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  backdrop-filter: blur(14px);
  background: rgba(243, 239, 230, 0.82);
  border-bottom: 1px solid var(--line);
  direction: ltr; /* back left, menu right — same row */
}

.topbar-start {
  width: 44px; height: 44px;
  display: grid; place-items: center;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  text-align: center;
  direction: rtl;
}

.icon-btn {
  width: 44px; height: 44px;
  border: 1px solid rgba(28, 43, 36, 0.14);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(28, 43, 36, 0.08);
  display: grid; place-items: center;
  cursor: pointer;
  padding: 0;
}

.burger, .burger::before, .burger::after {
  display: block; width: 16px; height: 2px; background: var(--ink); border-radius: 2px;
  content: ""; position: relative;
}
.burger::before { top: -5px; position: absolute; }
.burger::after { top: 5px; position: absolute; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; /* LTR physical: for RTL put on right */
  right: 0; left: auto;
  width: min(var(--sidebar-width), 86vw);
  background: #163528;
  color: #f4f7f5;
  transform: translateX(105%);
  transition: transform .28s ease;
  z-index: 30;
  display: flex; flex-direction: column;
  padding: 1.25rem 0.75rem;
  box-shadow: var(--shadow);
}

.app-shell.sidebar-open .sidebar { transform: translateX(0); }

.backdrop {
  position: fixed; inset: 0; background: rgba(10, 18, 14, 0.35);
  opacity: 0; pointer-events: none; transition: opacity .28s ease; z-index: 25;
}
.app-shell.sidebar-open .backdrop { opacity: 1; pointer-events: auto; }

.side-nav { display: flex; flex-direction: column; height: 100%; gap: 1rem; }
.side-section { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.side-footer { border-top: 1px solid rgba(255,255,255,0.12); padding-top: 0.75rem; }

.side-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  color: inherit;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: right;
  cursor: pointer;
}
.side-item:hover, .side-item.active { background: rgba(255,255,255,0.08); }
.side-item.nested { padding-right: 1.6rem; font-size: 0.95rem; color: #d7e6dd; }
.side-item.danger { color: #ffc9c9; }
.cascade { display: flex; flex-direction: column; gap: 0.15rem; }
.chevron { transition: transform .2s ease; opacity: .8; }
.chevron.open { transform: rotate(180deg); }
.user-chip { padding: 0.5rem 0.9rem; color: #c7d8ce; font-size: 0.9rem; }

.content { padding: 1.25rem 1rem 2.5rem; max-width: 980px; margin: 0 auto; }
.app-shell.has-player-dock .content { padding-bottom: 8.5rem; }

.home { padding-top: 1.5rem; }
.tile-grid { display: grid; gap: 1rem; }
.tafsir-tile {
  display: flex; flex-direction: column; justify-content: flex-end;
  min-height: 220px;
  padding: 1.5rem;
  border-radius: 28px;
  background:
    linear-gradient(160deg, rgba(31,107,74,0.92), rgba(19,70,50,0.95)),
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.18), transparent 40%);
  color: #f7faf8;
  box-shadow: var(--shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}
.tafsir-tile:hover { transform: translateY(-3px); box-shadow: 0 22px 48px rgba(19,70,50,0.22); }
.tile-title { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 700; }
.tile-author { margin-top: 0.35rem; font-size: 0.95rem; opacity: 0.85; }

.page-header h1, .list-page h1, .prose-page h1, .auth-page h1 {
  margin: 0 0 0.35rem; font-size: 1.6rem;
}
.muted { color: var(--muted); }
.error { color: var(--danger); }

.episode-layout {
  display: grid;
  gap: 1rem;
}
@media (min-width: 860px) {
  .episode-layout { grid-template-columns: 1fr 1.1fr; align-items: start; }
}

.episode-list {
  display: flex; flex-direction: column; gap: 0.45rem;
  max-height: 60vh; overflow: auto; padding-left: 0.25rem;
}
.episode-row {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  text-align: right;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 0.2rem;
}
.episode-row.active, .episode-row:hover {
  border-color: rgba(31,107,74,0.45);
  background: #fff;
}
.ep-title { font-weight: 600; }
.ep-meta { color: var(--muted); font-size: 0.85rem; }

.player-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 22px;
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.ayah-block { margin-bottom: 1rem; }
.ayah-ar {
  font-family: var(--font-ar);
  font-size: clamp(1.75rem, 4.2vw, 2.35rem);
  line-height: 2.05;
  margin: 0 0 0.65rem;
  color: #14261e;
  font-weight: 700;
}
.ayah-fa {
  margin: 0;
  font-size: clamp(1.05rem, 2.6vw, 1.28rem);
  line-height: 1.95;
  color: #3a4a42;
}

.audio-player { display: flex; flex-direction: column; gap: 0.85rem; }
.player-title { font-weight: 600; }
.player-actions { display: flex; gap: 0.5rem; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
}
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.player-controls { display: grid; grid-template-columns: auto 1fr auto; gap: 0.75rem; align-items: center; }
.play-btn {
  width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: var(--brand); color: #fff; cursor: pointer;
}
.seek { width: 100%; accent-color: var(--brand); }
.time { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

.simple-list { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: 0.6rem; }
.simple-list li {
  padding: 0.9rem 1rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 0.2rem;
}

.prose-page p, .auth-page p { line-height: 1.9; color: var(--muted); }
.auth-form { display: grid; gap: 0.85rem; max-width: 420px; margin-top: 1rem; }
.auth-form label { display: grid; gap: 0.35rem; font-size: 0.95rem; }
.auth-form input {
  border: 1px solid var(--line); border-radius: 12px; padding: 0.75rem 0.9rem; background: #fff;
}
.primary-btn {
  border: 0; border-radius: 12px; padding: 0.85rem 1rem;
  background: var(--brand); color: #fff; cursor: pointer;
}
.primary-btn:disabled { opacity: 0.6; cursor: default; }
.link-btn {
  margin-top: 0.85rem; border: 0; background: transparent; color: var(--brand-deep); cursor: pointer;
}

.surah-grid { display: grid; gap: 0.55rem; }
.surah-card {
  display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; align-items: center;
  border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 0.35rem;
}
.surah-main {
  border: 0; background: transparent; cursor: pointer; text-align: right;
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.75rem; align-items: center;
  padding: 0.65rem 0.75rem; width: 100%;
}
.surah-num {
  width: 2.2rem; height: 2.2rem; border-radius: 10px; display: grid; place-items: center;
  background: rgba(31,107,74,0.12); color: var(--brand-deep); font-weight: 700; font-size: 0.85rem;
}
.surah-names { display: flex; flex-direction: column; gap: 0.1rem; }
.ayah-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 70vh; overflow: auto; }
.ayah-row {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: 0.75rem 0.9rem; text-align: right; cursor: pointer;
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.7rem; align-items: center;
}
.ayah-row:hover { border-color: rgba(31,107,74,0.45); background: #fff; }
.ayah-num { font-weight: 700; color: var(--brand); }
.ayah-preview { color: var(--muted); font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ayah-flags { display: flex; gap: 0.25rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.fav { background: #c45c26; }
.dot.mark { background: var(--brand); }
.dot.audio { background: #3b6ea5; }
.section-title { margin: 1.25rem 0 0.6rem; font-size: 1.05rem; }
.linkish { border: 0; background: transparent; color: var(--brand-deep); cursor: pointer; padding: 0; }
.ayah-nav { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.content-block {
  margin-top: 1rem; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 0.85rem 1rem;
}
.content-block summary { cursor: pointer; font-weight: 600; margin-bottom: 0.5rem; }
.html-body { line-height: 1.95; color: var(--ink); }
.html-body p { margin: 0 0 0.65rem; }
.video-wrap { position: relative; aspect-ratio: 16 / 9; max-width: 520px; }
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 12px; }
.list-row {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.9rem 1rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
}
.chip:disabled { opacity: 0.45; cursor: default; }

.page-title-inline {
  margin: 0; font-size: clamp(1.15rem, 3.5vw, 1.45rem); font-weight: 700;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem;
  direction: rtl;
  text-align: right;
  justify-content: flex-start;
}
.title-author { font-weight: 500; color: var(--muted); font-size: 0.92em; }
.back-btn,
.sheet-icon-btn,
.icon-chip,
.sheet-action-icon {
  flex-shrink: 0;
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid rgba(28, 43, 36, 0.14);
  background: #fff;
  box-shadow: 0 2px 8px rgba(28, 43, 36, 0.08);
  cursor: pointer;
  color: #1c2b24;
  display: grid; place-items: center;
  font-size: 1.45rem; line-height: 1;
  padding: 0;
}
.icon-chip.on,
.sheet-action.on .sheet-action-icon {
  background: var(--brand); color: #fff; border-color: var(--brand);
  box-shadow: 0 2px 10px rgba(31, 107, 74, 0.28);
}
.ayah-page-title {
  margin: 0 0 0.85rem; font-size: 1.1rem; font-weight: 700; color: var(--brand-deep);
}

.skeleton-stack { display: grid; gap: 0.65rem; margin: 0.5rem 0 1rem; }
.skeleton-line, .skeleton-card, .skeleton-block {
  background: linear-gradient(90deg, rgba(28,43,36,0.07), rgba(28,43,36,0.14), rgba(28,43,36,0.07));
  background-size: 200% 100%;
  animation: skeleton-shine 1.2s ease-in-out infinite;
  border-radius: 10px;
}
.skeleton-line { height: 14px; }
.skeleton-card { height: 64px; border-radius: 14px; }
.skeleton-block { height: 120px; }
@keyframes skeleton-shine {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.player-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 28px rgba(28, 43, 36, 0.08);
}
.dock-player {
  max-width: none; margin: 0; width: 100%;
  border: 0; border-radius: 0;
  background: #fff;
  padding: 0.85rem 1rem 0.95rem;
  direction: rtl;
  text-align: right;
  box-sizing: border-box;
}
.dock-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem;
  margin-bottom: 0.65rem;
}
.dock-title {
  border: 0; background: transparent; padding: 0; cursor: pointer;
  font-weight: 700; font-size: 1.05rem; color: var(--ink); text-align: right;
}
.dock-actions { display: flex; gap: 0.45rem; flex-shrink: 0; }
.ltr-controls {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.7rem; align-items: center;
  direction: ltr;
}
.ltr-controls .seek { direction: ltr; }
.ltr-controls .time {
  font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--muted); white-space: nowrap;
  min-width: 5.5rem; text-align: left;
}
.dock-empty { margin: 0; font-size: 0.9rem; }

.resume-btn {
  width: 100%; margin: 0 0 1rem; padding: 1rem 1.1rem;
  border: 1px solid rgba(31,107,74,0.35); border-radius: 18px;
  background: linear-gradient(135deg, rgba(31,107,74,0.12), rgba(31,107,74,0.04));
  cursor: pointer; text-align: right;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.resume-label { font-weight: 700; color: var(--brand-deep); }
.resume-meta { color: var(--muted); font-size: 0.9rem; }

/* Expanded player sheet */
.player-expanded-host {
  position: fixed; inset: 0; z-index: 60;
  background: #f7f5f0;
}
.player-sheet {
  height: 100%;
  width: 100%;
  max-width: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #f7f5f0;
  padding: calc(0.65rem + env(safe-area-inset-top)) 1.15rem calc(1.1rem + env(safe-area-inset-bottom));
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  direction: rtl;
  text-align: right;
  overflow: auto;
}
.sheet-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  direction: ltr; /* spacer left, menu right */
}
.sheet-header-spacer { width: 44px; height: 44px; }
.sheet-header-title {
  direction: rtl;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
}
.player-hero {
  width: min(100%, 360px);
  aspect-ratio: 1;
  margin: 0.25rem auto 1rem;
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(19, 70, 50, 0.92), rgba(31, 107, 74, 0.78)),
    url('/background.png') center/cover;
  box-shadow: 0 18px 40px rgba(28, 43, 36, 0.18);
  display: grid;
  place-items: center;
  color: #fff;
}
.player-hero-inner {
  display: grid; gap: 0.45rem; text-align: center; padding: 1.25rem;
}
.player-hero-kicker {
  font-size: 0.9rem; opacity: 0.85;
}
.player-hero-inner strong {
  font-size: 1.45rem; font-weight: 800; line-height: 1.5;
}
.sheet-track-meta {
  text-align: center;
  margin-bottom: 1rem;
}
.sheet-track-name {
  font-size: 1.15rem; font-weight: 700; color: var(--ink);
}
.sheet-track-index {
  margin-top: 0.25rem; color: var(--muted); font-size: 0.95rem;
}
.sheet-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.sheet-action {
  border: 0; background: transparent; cursor: pointer;
  display: grid; gap: 0.3rem; justify-items: center;
  color: var(--ink); font-size: 0.85rem; padding: 0.35rem;
}
.sheet-action.on { color: var(--brand); font-weight: 700; }
.sheet-action-icon { font-size: 1.25rem; }
.sheet-seek-block { margin-top: auto; padding-top: 0.5rem; }
.sheet-seek { width: 100%; accent-color: var(--brand); }
.sheet-times {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  margin-top: 0.45rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--muted);
}
.sheet-times > span:first-child { text-align: left; }
.sheet-times > span:last-child { text-align: right; }
.sheet-remain { text-align: center; color: var(--brand-deep); }
.player-main-controls {
  display: flex; align-items: center; justify-content: center;
  gap: 1.4rem; margin: 1.35rem 0 0.4rem;
}
.play-btn-lg {
  width: 72px; height: 72px; font-size: 1.35rem;
  background: #1c2b24;
}
.skip-btn {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid rgba(28, 43, 36, 0.14); background: #fff;
  box-shadow: 0 2px 8px rgba(28, 43, 36, 0.08);
  cursor: pointer; font-weight: 700; color: var(--brand-deep);
}

/* TOC sheet */
.toc-sheet {
  position: fixed; inset: 0; z-index: 70;
  background: #fff;
  padding: calc(0.65rem + env(safe-area-inset-top)) 0 calc(0.5rem + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  overflow: hidden;
}
.toc-header {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 0.65rem;
  padding: 0 1rem 0.85rem;
  border-bottom: 1px solid var(--line);
  direction: ltr; /* back button physical left */
}
.toc-header-text {
  display: grid; gap: 0.15rem;
  direction: rtl;
  text-align: right;
}
.toc-header-text strong { font-size: 1.15rem; color: var(--ink); }
.toc-skeleton { padding: 1rem; }
.toc-list {
  list-style: none; margin: 0; padding: 0;
  overflow: auto; flex: 1;
}
.toc-row {
  border-bottom: 1px solid rgba(28, 43, 36, 0.08);
}
.toc-row.active { background: rgba(28, 43, 36, 0.06); }
.toc-row-btn {
  width: 100%; border: 0; background: transparent; cursor: pointer;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 1rem;
  text-align: right;
  color: inherit;
}
.toc-play-slot {
  width: 36px; height: 36px;
  display: grid; place-items: center;
}
.toc-play-dot {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 0.85rem;
}
.toc-row-main { display: grid; gap: 0.2rem; min-width: 0; }
.toc-row-title { font-weight: 700; color: var(--ink); }
.toc-row-preview {
  color: var(--muted); font-size: 0.88rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc-row-flags {
  display: flex; gap: 0.4rem; font-size: 0.85rem; color: var(--brand-deep);
}
.toc-row-num {
  font-weight: 700; color: var(--muted); min-width: 1.5rem; text-align: center;
}
