:root {
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --surface-2: #f0eadc;
  --line: #e4dccb;
  --text: #1f2a27;
  --muted: #6b746f;
  --accent: #0f5c4d;
  --accent-2: #13806b;
  --accent-soft: #dcece6;
  --gold: #b8862b;
  --gold-soft: #f6ead0;
  --hl: #fff2c4;
  --shadow: 0 1px 2px rgba(31, 42, 39, .06), 0 4px 14px rgba(31, 42, 39, .05);
  --ar-size: 2rem;
  --radius: 14px;
  --font: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-ar: "Amiri Quran", "KFGQPC Uthmanic Script HAFS", "Traditional Arabic", serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1514;
  --surface: #161e1c;
  --surface-2: #1d2725;
  --line: #2a3633;
  --text: #e6ece9;
  --muted: #93a19c;
  --accent: #5cc6a8;
  --accent-2: #7fd8bd;
  --accent-soft: #1d3a33;
  --gold: #e2b563;
  --gold-soft: #3a3020;
  --hl: #34341f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
main { outline: none; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand img { border-radius: 9px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: .75rem; }
.topbar-mid { flex: 1; min-width: 0; display: flex; justify-content: center; }
.topbar-actions { display: flex; gap: 4px; flex: none; }
.icon-btn {
  display: inline-grid; place-items: center;
  min-width: 40px; height: 40px; padding: 0 8px;
  border: 0; border-radius: 10px; background: transparent;
  font-weight: 600;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:focus-visible, .chip:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.surah-nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.surah-nav select {
  max-width: 230px; min-width: 0;
  padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600;
}

/* ---------- layout ---------- */
.wrap { max-width: 1000px; margin: 0 auto; padding: 20px 16px 120px; }

.hero {
  text-align: center;
  padding: 34px 16px 26px;
}
.hero .bism { font-family: var(--font-ar); font-size: 2.2rem; color: var(--accent); line-height: 1.8; }
.hero h1 { margin: 6px 0 4px; font-size: 1.6rem; }
.hero p { margin: 0 auto; color: var(--muted); max-width: 560px; }

.search {
  display: flex; align-items: center; gap: 8px;
  max-width: 560px; margin: 22px auto 0;
  padding: 4px 6px 4px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow);
}
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font: inherit; padding: 10px 0; color: var(--text);
}
.search svg { color: var(--muted); flex: none; }

.quick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: .9rem; font-weight: 500;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .chip.on { color: #0f1514; }

.tabs { display: flex; gap: 6px; margin: 26px 0 14px; border-bottom: 1px solid var(--line); }
.tabs button {
  border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--accent); border-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.num {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: .95rem;
  transform: rotate(45deg);
}
.num span { transform: rotate(-45deg); }
.card .info { flex: 1; min-width: 0; }
.card .info b { display: block; }
.card .info small { color: var(--muted); font-size: .82rem; }
.card .ar { font-family: var(--font-ar); font-size: 1.45rem; color: var(--accent); line-height: 1.2; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- reader ---------- */
.surah-head {
  text-align: center; padding: 26px 16px 18px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  position: relative; overflow: hidden;
}
.surah-head::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% -40%, var(--gold-soft), transparent 60%);
  pointer-events: none;
}
.surah-head > * { position: relative; }
.surah-head .ar { font-family: var(--font-ar); font-size: 2.4rem; color: var(--accent); line-height: 1.6; }
.surah-head h1 { margin: 0; font-size: 1.5rem; }
.surah-head .meta { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.surah-head .actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.bismillah { text-align: center; font-family: var(--font-ar); font-size: calc(var(--ar-size) * .95); color: var(--text); padding: 12px 0 4px; line-height: 2; }

.verse {
  padding: 18px 4px 20px;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 80px;
  transition: background .3s;
}
.verse.playing { background: var(--hl); border-radius: 12px; }
.verse-top { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.vkey {
  font-size: .8rem; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); padding: 3px 10px; border-radius: 999px;
}
.verse-top .sp { flex: 1; }
.verse-top .icon-btn { min-width: 34px; height: 34px; color: var(--muted); }
.verse-top .icon-btn:hover { color: var(--accent); }
.verse-top .icon-btn.on { color: var(--gold); }

.words {
  display: flex; flex-wrap: wrap; direction: rtl;
  gap: 14px 6px; align-items: flex-start;
}
.w {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 6px 8px 8px; border-radius: 10px; cursor: pointer;
  max-width: 11rem;
  transition: background .15s;
}
.w:hover { background: var(--surface-2); }
.w.playing { background: var(--gold-soft); }
.w .ar { font-family: var(--font-ar); font-size: var(--ar-size); line-height: 2.1; direction: rtl; }
.w .tl { direction: ltr; font-size: .78rem; color: var(--muted); font-style: italic; line-height: 1.3; margin-top: 4px; }
.w .mn { direction: ltr; font-size: .86rem; line-height: 1.3; margin-top: 3px; color: var(--accent); font-weight: 500; }
.w .mn.en { color: var(--muted); font-weight: 400; }
.end-mark {
  align-self: center; font-family: var(--font-ar); font-size: calc(var(--ar-size) * .8);
  color: var(--gold); padding: 0 4px;
}
.ar-line { font-family: var(--font-ar); font-size: var(--ar-size); line-height: 2.2; direction: rtl; text-align: right; }
.ar-line .end-mark { font-size: calc(var(--ar-size) * .8); }

.tr { margin-top: 12px; font-size: 1rem; line-height: 1.7; }
.tr + .tr { margin-top: 10px; }
.tr .by { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }

.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 26px; }
.pager a { flex: 1; }
.pager a.next { text-align: right; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; font-size: .92rem;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .btn.primary { color: #0f1514; }
.btn.primary:hover { background: var(--accent-2); color: #fff; }

.loading { text-align: center; padding: 60px 0; color: var(--muted); }

/* ---------- player ---------- */
.player {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; display: flex; align-items: center; gap: 4px;
  width: min(520px, calc(100% - 20px));
  padding: 8px 10px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .15);
}
.player[hidden] { display: none; }
.player .big { background: var(--accent); color: #fff; border-radius: 50%; width: 44px; height: 44px; }
[data-theme="dark"] .player .big { color: #0f1514; }
.pl-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; padding: 0 6px; }
.pl-info b, .pl-info small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-info small { color: var(--muted); font-size: .78rem; }

/* ---------- settings sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(380px, 100%); overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--line);
  padding: 18px 20px 40px;
}
.sheet[hidden], .sheet-backdrop[hidden] { display: none; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.field { padding: 14px 0; border-bottom: 1px solid var(--line); }
.field > label:not(.toggle), .field > .lbl { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.sheet select, .sheet input[type=range] { width: 100%; }
.sheet select { padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.sheet input[type=range] { accent-color: var(--accent); }
.preview-ar { font-family: var(--font-ar); font-size: var(--ar-size); text-align: center; direction: rtl; margin-top: 4px; }
.note { font-size: .82rem; color: var(--muted); line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem;
}
.toast[hidden] { display: none; }

footer.site { margin-top: 50px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; line-height: 1.6; }
footer.site b { color: var(--text); }

@media (max-width: 640px) {
  .brand-text { display: none; }
  .surah-nav select { max-width: 160px; }
  .wrap { padding: 14px 10px 120px; }
  .w { max-width: 8.5rem; padding: 4px 4px 6px; }
  .w .mn { font-size: .8rem; }
  .hero h1 { font-size: 1.35rem; }
}

/* groups of Arabic words sharing one piece of the verse translation */
.g { display: flex; flex-direction: column; align-items: center; max-width: min(100%, 22rem); }
.gw { display: flex; direction: rtl; align-items: flex-start; }
.g.multi .gw { border-bottom: 2px solid var(--accent-soft); border-radius: 0 0 8px 8px; }
.g .mn { direction: ltr; text-align: center; font-size: .86rem; line-height: 1.35; margin-top: 4px; padding: 0 6px; color: var(--accent); font-weight: 500; }
.g .mn:empty { display: none; }
@media (max-width: 640px) { .g .mn { font-size: .8rem; } }
