:root {
  --bg: #12100b;
  --bg2: #1a1710;
  --card: #1c1913;
  --gold: #c9a227;
  --gold-hi: #e6c86a;
  --gold-dim: rgba(201, 162, 39, .45);
  --ink: #f2ead8;
  --ink-dim: #a89e8a;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(201,162,39,.08), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: "Cairo", system-ui, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
#app-header {
  position: sticky; top: 0; z-index: 40;
  background: linear-gradient(180deg, rgba(18,16,11,.97), rgba(18,16,11,.88));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--gold-dim);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; max-width: 640px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--gold); }
.brand-mark { width: 38px; height: 38px; }
.brand-name { font-family: "Aref Ruqaa", serif; font-size: 1.5rem; line-height: 1; color: var(--gold-hi); }
.brand-sub { font-size: .68rem; color: var(--ink-dim); margin-top: 2px; }
.hijri { font-size: .78rem; color: var(--gold-hi); text-align: left; line-height: 1.5; }

/* ---------- layout ---------- */
main { max-width: 640px; margin: 0 auto; padding: 14px 14px 0; }
.screen { display: none; animation: fadein .25s ease; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }
.hidden { display: none !important; }

/* ---------- cards ---------- */
.card {
  background: linear-gradient(160deg, var(--bg2), var(--card));
  border: 1.5px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 14px rgba(0,0,0,.35), inset 0 0 0 1px rgba(201,162,39,.06);
}
.card-title { font-weight: 800; color: var(--gold-hi); font-size: 1.05rem; }
.card-sub { font-size: .78rem; color: var(--ink-dim); margin: 2px 0 10px; }

/* ---------- home ---------- */
.next-card { text-align: center; padding: 22px 16px; }
.next-label { font-size: .8rem; color: var(--ink-dim); letter-spacing: .5px; }
.next-name { font-family: "Aref Ruqaa", serif; font-size: 2.2rem; color: var(--gold-hi); margin: 4px 0 0; }
.next-time { font-size: 1.3rem; font-weight: 700; }
.next-count { font-size: .95rem; color: var(--ink-dim); margin-top: 6px; }
.next-count b { color: var(--gold-hi); font-variant-numeric: tabular-nums; }

.loc-row {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 4px 12px; color: var(--ink-dim); font-size: .85rem;
}
.ic { width: 18px; height: 18px; color: var(--gold); flex: none; }

.prayer-list { display: flex; flex-direction: column; gap: 8px; }
.prayer-row {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(160deg, var(--bg2), var(--card));
  border: 1.5px solid rgba(201,162,39,.25);
  border-radius: 14px; padding: 12px 16px;
}
.prayer-row .p-name { font-weight: 700; font-size: 1.02rem; }
.prayer-row .p-time { font-variant-numeric: tabular-nums; color: var(--ink-dim); font-weight: 600; }
.prayer-row.next { border-color: var(--gold); box-shadow: 0 0 18px rgba(201,162,39,.22); }
.prayer-row.next .p-name, .prayer-row.next .p-time { color: var(--gold-hi); }
.prayer-row.passed { opacity: .55; }
.src-note { text-align: center; color: var(--ink-dim); font-size: .72rem; margin: 12px 0 20px; opacity: .8; }

/* ---------- quran list ---------- */
.search-wrap { position: sticky; top: calc(64px + env(safe-area-inset-top)); z-index: 20; padding: 4px 0 10px; background: linear-gradient(180deg, var(--bg) 80%, transparent); }
#surah-search, .select, #page-input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--gold-dim); background: var(--card); color: var(--ink);
  font-family: inherit; font-size: .95rem; outline: none;
}
#surah-search:focus, .select:focus { border-color: var(--gold); }
.surah-item {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(160deg, var(--bg2), var(--card));
  border: 1.5px solid rgba(201,162,39,.25);
  border-radius: 14px; padding: 11px 14px; margin-bottom: 8px;
  cursor: pointer; transition: border-color .15s;
}
.surah-item:active { border-color: var(--gold); }
.surah-num {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border: 1.5px solid var(--gold-dim); border-radius: 50%;
  color: var(--gold-hi); font-size: .8rem; font-weight: 700;
  transform: rotate(45deg); border-radius: 8px;
}
.surah-num span { transform: rotate(-45deg); }
.surah-info { flex: 1; min-width: 0; }
.surah-name { font-family: "Amiri Quran", serif; font-size: 1.25rem; color: var(--ink); }
.surah-meta { font-size: .72rem; color: var(--ink-dim); }
.surah-type { font-size: .68rem; color: var(--gold-hi); border: 1px solid var(--gold-dim); padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.last-read { cursor: pointer; color: var(--gold-hi); font-size: .9rem; }

/* ---------- reader ---------- */
.reader-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.reader-title { flex: 1; font-family: "Amiri Quran", serif; font-size: 1.3rem; color: var(--gold-hi); text-align: center; }
.seg { display: flex; border: 1.5px solid var(--gold-dim); border-radius: 12px; overflow: hidden; }
.seg-btn { background: transparent; color: var(--ink-dim); border: 0; padding: 8px 14px; font-family: inherit; font-size: .85rem; font-weight: 700; cursor: pointer; }
.seg-btn.active { background: var(--gold); color: #17140c; }
.seg.wide { margin-bottom: 12px; }
.seg.wide .seg-btn { flex: 1; padding: 11px; font-size: .95rem; }

.mushaf-frame {
  border: 2px solid var(--gold-dim); border-radius: 14px;
  background: #c2dcc7; overflow: hidden; position: relative;
  min-height: 300px; display: grid; place-items: center;
}
#mushaf-img { width: 100%; display: block; user-select: none; }
.mushaf-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--gold); font-size: 2rem; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }
.mushaf-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.nav-btn {
  background: linear-gradient(160deg, var(--bg2), var(--card));
  border: 1.5px solid var(--gold-dim); color: var(--gold-hi);
  border-radius: 12px; padding: 10px 18px; font-family: inherit; font-weight: 700; font-size: .9rem; cursor: pointer;
}
.nav-btn:active { border-color: var(--gold); }
.page-jump { display: flex; align-items: center; gap: 6px; color: var(--ink-dim); font-size: .85rem; }
#page-input { width: 64px; padding: 8px; text-align: center; }

.surah-head { text-align: center; }
.surah-head-name { font-family: "Amiri Quran", serif; font-size: 1.8rem; color: var(--gold-hi); }
.surah-head-meta { font-size: .78rem; color: var(--ink-dim); }
.bismillah { font-family: "Amiri Quran", serif; text-align: center; font-size: 1.7rem; color: var(--ink); margin: 14px 0; }
.ayahs { font-family: "Amiri Quran", serif; font-size: 1.55rem; line-height: 2.3; text-align: justify; }
.ayah { cursor: pointer; border-radius: 8px; transition: background .15s; padding: 0 2px; }
.ayah:active, .ayah.tapped { background: rgba(201,162,39,.18); }
.ayah-num {
  display: inline-grid; place-items: center;
  min-width: 1.9em; height: 1.9em; margin: 0 .2em;
  border: 1px solid var(--gold-dim); border-radius: 50%;
  font-size: .62em; color: var(--gold-hi); vertical-align: middle;
  font-family: "Cairo", sans-serif; font-weight: 700;
}

/* ---------- azkar ---------- */
.progress-wrap { height: 6px; border-radius: 99px; background: rgba(201,162,39,.15); overflow: hidden; margin-bottom: 12px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold-hi)); border-radius: 99px; transition: width .3s; }
.zekr-card {
  background: linear-gradient(160deg, var(--bg2), var(--card));
  border: 1.5px solid rgba(201,162,39,.25);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  cursor: pointer; position: relative; transition: opacity .2s;
}
.zekr-card.done { opacity: .45; }
.zekr-text { font-family: "Amiri Quran", serif; font-size: 1.18rem; line-height: 2; }
.zekr-bless { font-size: .74rem; color: var(--ink-dim); margin-top: 8px; border-top: 1px dashed rgba(201,162,39,.25); padding-top: 8px; }
.zekr-count {
  position: absolute; top: 12px; left: 12px;
  min-width: 34px; height: 34px; display: grid; place-items: center;
  border: 1.5px solid var(--gold); border-radius: 50%;
  color: var(--gold-hi); font-weight: 800; font-size: .9rem;
  background: var(--bg);
}
.reset-btn {
  display: block; width: 100%; margin: 6px 0 18px;
  background: transparent; border: 1.5px solid var(--gold-dim); color: var(--gold-hi);
  border-radius: 12px; padding: 11px; font-family: inherit; font-weight: 700; cursor: pointer;
}
.reset-btn.small { width: auto; padding: 8px 18px; font-size: .85rem; margin: 0; }

/* ---------- tasbih ---------- */
.tasbih-card { text-align: center; padding: 24px 16px; }
.tasbih-dhikr { font-family: "Amiri Quran", serif; font-size: 1.6rem; color: var(--gold-hi); margin-bottom: 10px; min-height: 2em; }
.tasbih-presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }
.chip {
  border: 1.5px solid var(--gold-dim); background: transparent; color: var(--ink-dim);
  border-radius: 99px; padding: 7px 14px; font-family: inherit; font-size: .82rem; font-weight: 700; cursor: pointer;
}
.chip.active { background: var(--gold); color: #17140c; border-color: var(--gold); }
.tasbih-btn {
  width: 210px; height: 210px; border-radius: 50%;
  border: 3px solid var(--gold); margin: 0 auto 18px;
  background: radial-gradient(circle at 35% 30%, #2a2517, #17140c 70%);
  color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; box-shadow: 0 0 40px rgba(201,162,39,.18), inset 0 0 30px rgba(201,162,39,.08);
  transition: transform .07s;
}
.tasbih-btn:active { transform: scale(.96); }
.tasbih-count { font-size: 3.4rem; font-weight: 800; color: var(--gold-hi); font-variant-numeric: tabular-nums; line-height: 1; }
.tasbih-target { font-size: .85rem; color: var(--ink-dim); }
.tasbih-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; }
.tasbih-total { font-size: .85rem; color: var(--ink-dim); }

/* ---------- tafsir ---------- */
.video-frame { position: relative; padding-top: 56.25%; border-radius: 12px; overflow: hidden; border: 1.5px solid var(--gold-dim); }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.select { margin: 6px 0 10px; appearance: none; }
.sheikh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheikh-btn {
  background: linear-gradient(160deg, var(--bg2), var(--card));
  border: 1.5px solid var(--gold-dim); color: var(--ink);
  border-radius: 12px; padding: 12px 8px; font-family: inherit; font-weight: 700; font-size: .85rem;
  cursor: pointer; text-decoration: none; text-align: center; display: block;
}
.sheikh-btn:active { border-color: var(--gold); }
.asbab-entry { border-top: 1px dashed rgba(201,162,39,.25); padding: 12px 0; }
.asbab-ref { color: var(--gold-hi); font-weight: 800; font-size: .9rem; margin-bottom: 4px; }
.asbab-text { font-family: "Amiri Quran", serif; font-size: 1.1rem; line-height: 1.9; white-space: pre-line; }
.asbab-empty { color: var(--ink-dim); font-size: .85rem; text-align: center; padding: 14px 0; }

/* ---------- sheets ---------- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 82vh; overflow-y: auto;
  background: linear-gradient(180deg, #221e15, var(--bg2));
  border: 1.5px solid var(--gold-dim); border-bottom: 0;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: slideup .25s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-title { font-weight: 800; color: var(--gold-hi); margin-bottom: 12px; }
.sheet-sub { color: var(--ink-dim); font-size: .8rem; margin: 14px 0 8px; }
.sheet-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: linear-gradient(160deg, var(--bg2), var(--card));
  border: 1.5px solid var(--gold-dim); color: var(--ink);
  border-radius: 12px; padding: 13px; font-family: inherit; font-weight: 700; font-size: .92rem; cursor: pointer;
}
.city-list { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.city-btn {
  background: transparent; border: 1.5px solid rgba(201,162,39,.25); color: var(--ink-dim);
  border-radius: 10px; padding: 10px 4px; font-family: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
}
.city-btn.active { border-color: var(--gold); color: var(--gold-hi); }
.ayah-sheet-text { font-family: "Amiri Quran", serif; font-size: 1.2rem; line-height: 2; margin-bottom: 12px; }
.ayah-actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

.link-btn { background: none; border: 0; color: var(--gold-hi); font-family: inherit; font-weight: 700; font-size: .85rem; cursor: pointer; padding: 4px; white-space: nowrap; }

/* ---------- bottom nav ---------- */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; justify-content: space-around;
  background: linear-gradient(0deg, rgba(18,16,11,.99), rgba(18,16,11,.92));
  border-top: 1px solid var(--gold-dim);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  background: none; border: 0; color: var(--ink-dim);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: inherit; font-size: .66rem; font-weight: 700; cursor: pointer;
  padding: 4px 8px; border-radius: 12px; flex: 1; max-width: 84px;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--gold-hi); }
