/* ليل: dark-only Quran reader.
   Shape rule: sheets 24px top corners, every control is a pill or a circle. One accent: illumination gold. */

:root {
  --gold: #d6b77a;
  --ui: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --qfont: "Amiri Quran", "Scheherazade New", serif;
  --qsize: 26px;
  --qlh: 2.15;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --bright: 100%;
}
[data-theme="midnight"] { --bg:#0e0e10; --ink:#e9e3d5; --muted:#8d887e; --surface:#17171a; --surface2:#202024; --line:rgba(233,227,213,.10); }
[data-theme="oled"]     { --bg:#000000; --ink:#ddd7c9; --muted:#7e796f; --surface:#0f0f10; --surface2:#19191b; --line:rgba(221,215,201,.10); }
[data-theme="ink"]      { --bg:#0b1120; --ink:#e3e7f0; --muted:#8a93a8; --surface:#121a2c; --surface2:#1a2338; --line:rgba(227,231,240,.10); }
[data-theme="forest"]   { --bg:#0a120f; --ink:#e3e8de; --muted:#8a9689; --surface:#111c17; --surface2:#18251f; --line:rgba(227,232,222,.10); }
[data-theme="dusk"]     { --bg:#15100b; --ink:#ecdec6; --muted:#9c8e79; --surface:#1e1710; --surface2:#281f16; --line:rgba(236,222,198,.10); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: var(--ui); font-weight: 400;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; display: block; fill: currentColor; }
[hidden] { display: none !important; }

/* ---------- Reader ---------- */
#app { position: fixed; inset: 0; }
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.track {
  position: absolute; top: 0; right: 0;
  font-family: var(--qfont); font-size: var(--qsize); line-height: var(--qlh);
  color: color-mix(in srgb, var(--ink) var(--bright, 100%), var(--bg));
  text-align: justify; text-justify: inter-word;
  column-fill: auto; will-change: transform;
  font-feature-settings: "calt", "liga";
  opacity: 0; transition: opacity .5s ease;
}
.track.ready { opacity: 1; }
.track.align-right { text-align: right; }
.chunk + .chunk { break-before: column; -webkit-column-break-before: always; }
.a { border-radius: .35em; transition: color .35s ease, background-color .35s ease; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.a.on { color: var(--gold); background: color-mix(in srgb, var(--gold) 9%, transparent); }
.a.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%,40% { background: color-mix(in srgb, var(--gold) 22%, transparent); } 100% { background: transparent; } }
.n { color: color-mix(in srgb, var(--gold) 80%, var(--ink)); white-space: nowrap; }
.rh { color: var(--gold); }
.sj { color: var(--gold); }

.sh { break-inside: avoid; -webkit-column-break-inside: avoid; break-after: avoid; text-align: center; padding: .35em 0 .15em; }
.sh-frame {
  position: relative; display: block; padding: .18em .9em .28em; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  outline: 1px solid color-mix(in srgb, var(--gold) 16%, transparent); outline-offset: 4px;
}
.sh-name { display: block; font-size: 1.18em; color: var(--gold); line-height: 1.9; }
.sh-meta { display: block; font-family: var(--ui); font-size: max(11px, .42em); color: var(--muted); letter-spacing: .02em; line-height: 1.4; margin-top: -.2em; }
.bs { break-inside: avoid; break-after: avoid; text-align: center; padding: .1em 0 .2em; font-size: 1.02em; }
.bs.on { color: var(--gold); }
.jz { break-after: avoid; display: flex; align-items: center; gap: .8em; justify-content: center; font-family: var(--ui); font-size: max(11px, .42em); color: var(--muted); line-height: 2.4; }
.jz::before, .jz::after { content: ""; flex: 0 1 3.5em; height: 1px; background: var(--line); }

.folio {
  position: fixed; left: 0; right: 0; bottom: calc(var(--safe-b) + 10px); text-align: center;
  font-size: 12px; color: var(--muted); opacity: .55; pointer-events: none; font-variant-numeric: tabular-nums;
}
/* two facing pages: a soft fold down the middle */
.spine { position: fixed; top: 0; bottom: 0; left: 50%; width: 90px; transform: translateX(-50%); pointer-events: none; display: none;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.28) 47%, rgba(255,255,255,.025) 50%, rgba(0,0,0,.28) 53%, transparent); }
.spread .spine { display: block; }
.warm { position: fixed; inset: 0; pointer-events: none; background: #ff8a2a; mix-blend-mode: multiply; opacity: 0; transition: opacity .4s; z-index: 5; }

/* ---------- Chrome (hidden while reading) ---------- */
.chrome {
  position: fixed; left: 0; right: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(140%); backdrop-filter: blur(18px) saturate(140%);
  transition: transform .38s var(--ease), opacity .3s ease; opacity: 0; pointer-events: none;
}
.chrome.top { top: 0; padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 16px) 12px calc(var(--safe-l) + 12px); display: flex; align-items: center; justify-content: space-between; transform: translateY(-100%); border-bottom: 1px solid var(--line); }
.chrome.bottom { bottom: 0; padding: 12px calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px); transform: translateY(100%); border-top: 1px solid var(--line); }
.show-chrome .chrome { transform: none; opacity: 1; pointer-events: auto; }
.where-surah { font-family: var(--qfont); font-size: 22px; color: var(--ink); line-height: 1.5; }
.where-meta { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 4px; }
.icon-btn { width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center; color: var(--ink); position: relative; transition: background .2s, transform .15s; }
.icon-btn:active { transform: scale(.94); background: var(--surface2); }
.icon-btn.on { color: var(--gold); }
.badge { position: absolute; top: 4px; left: 2px; font-size: 10px; color: var(--gold); }

.scrub { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.scrub-label { font-size: 12px; color: var(--muted); min-width: 86px; text-align: left; font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; height: 28px; background: transparent; margin: 0; direction: rtl; }
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: var(--line); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 2px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -8px; border-radius: 50%; background: var(--gold); border: 4px solid var(--bg); box-shadow: 0 0 0 1px color-mix(in srgb, var(--gold) 60%, transparent); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 3px solid var(--bg); }

.player { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.reciter-btn { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 16px; border-radius: 999px; background: var(--surface); color: var(--ink); font-size: 13px; max-width: 42%; }
.reciter-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reciter-btn svg { width: 18px; height: 18px; color: var(--gold); flex: none; }
.transport { display: flex; align-items: center; gap: 6px; }
.play-btn { width: 56px; height: 56px; border-radius: 999px; display: grid; place-items: center; background: var(--gold); color: #17130b; transition: transform .15s; }
.play-btn svg { width: 24px; height: 24px; }
.play-btn:active { transform: scale(.95); }

.pill { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 18px; border-radius: 999px; background: var(--surface2); color: var(--ink); font-size: 14px; white-space: nowrap; transition: transform .15s, background .2s; }
.pill svg { width: 18px; height: 18px; }
.pill:active { transform: scale(.97); }
.pill.solid { background: var(--gold); color: #17130b; font-weight: 500; }
.pill.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.follow-pill { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 24px); z-index: 9; color: var(--gold); box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.show-chrome .follow-pill { bottom: calc(var(--safe-b) + 150px); }

/* ---------- Sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 20; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; margin: 0 auto; max-width: 640px;
  max-height: calc(100dvh - var(--safe-t) - 24px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 24px 24px 0 0; border-top: 1px solid var(--line);
  transform: translateY(105%); transition: transform .42s var(--ease);
  box-shadow: 0 -20px 60px rgba(0,0,0,.45);
}
.sheet.open { transform: none; }
.sheet.tall { height: calc(100dvh - var(--safe-t) - 24px); }
.grab { display: grid; place-items: center; height: 26px; flex: none; touch-action: none; }
.grab span { width: 38px; height: 4px; border-radius: 4px; background: var(--line); background: color-mix(in srgb, var(--ink) 22%, transparent); }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: 0 20px calc(var(--safe-b) + 24px); flex: 1; -webkit-overflow-scrolling: touch; }
.sheet h2 { font-size: 20px; font-weight: 500; margin: 6px 0 14px; }
.sheet h3 { font-size: 13px; font-weight: 500; color: var(--muted); margin: 26px 0 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; background: var(--surface); z-index: 2; padding: 4px 0 10px; }
.sheet-head h2 { margin: 0; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { height: 34px; padding: 0 14px; border-radius: 999px; font-size: 13px; color: var(--muted); background: transparent; box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; }
.tab.on { background: var(--ink); color: var(--bg); box-shadow: none; }

.search { display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 16px; border-radius: 999px; background: var(--surface2); margin: 4px 0 12px; }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--ink); font: inherit; font-size: 16px; -webkit-user-select: text; user-select: text; }
.search input::placeholder { color: var(--muted); }

.list { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px; min-height: 58px; padding: 6px 4px; border-radius: 16px; text-align: right; width: 100%; }
.row:active { background: var(--surface2); }
.row .num { width: 34px; height: 34px; display: grid; place-items: center; font-size: 13px; color: var(--muted); position: relative; }
.row .num::before { content: ""; position: absolute; inset: 3px; border: 1px solid var(--line); transform: rotate(45deg); border-radius: 6px; }
.row .num.done { color: var(--gold); }
.row .num.done::before { border-color: color-mix(in srgb, var(--gold) 50%, transparent); }
.row .title { font-family: var(--qfont); font-size: 21px; line-height: 1.5; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .side { font-size: 12px; color: var(--muted); text-align: left; font-variant-numeric: tabular-nums; }
.row.current .title { color: var(--gold); }
.hit { padding: 12px 4px; border-radius: 14px; width: 100%; text-align: right; display: block; }
.hit:active { background: var(--surface2); }
.hit .ref { font-size: 12px; color: var(--gold); margin-bottom: 2px; }
.hit .txt { font-family: var(--qfont); font-size: 19px; line-height: 1.9; color: var(--ink); }
.hit mark { background: color-mix(in srgb, var(--gold) 25%, transparent); color: inherit; border-radius: 4px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 16px; line-height: 1.8; }

/* settings */
.set { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; }
.set label, .set .lbl { font-size: 15px; }
.set .val { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: left; }
.set input[type=range] { max-width: 58%; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { height: 36px; padding: 0 14px; border-radius: 999px; font-size: 13px; box-shadow: inset 0 0 0 1px var(--line); color: var(--ink); }
.seg button.on { background: var(--gold); color: #17130b; box-shadow: none; }
.toggle { width: 50px; height: 30px; border-radius: 999px; background: var(--surface2); position: relative; flex: none; box-shadow: inset 0 0 0 1px var(--line); transition: background .25s; }
.toggle::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--muted); transition: transform .25s var(--ease), background .25s; }
.toggle.on { background: color-mix(in srgb, var(--gold) 35%, var(--surface2)); }
.toggle.on::after { transform: translateX(-20px); background: var(--gold); }
.fonts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fonts button { border-radius: 18px; padding: 10px 6px 8px; box-shadow: inset 0 0 0 1px var(--line); text-align: center; }
.fonts button.on { box-shadow: inset 0 0 0 1.5px var(--gold); }
.fonts .sample { font-size: 22px; line-height: 1.8; display: block; }
.fonts .fname { font-size: 11px; color: var(--muted); }
.themes { display: flex; gap: 12px; }
.themes button { width: 44px; height: 44px; border-radius: 999px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); position: relative; }
.themes button.on::after { content: ""; position: absolute; inset: -5px; border-radius: 999px; border: 1.5px solid var(--gold); }
.preview { font-family: var(--qfont); background: var(--bg); border-radius: 18px; padding: 14px 18px; line-height: var(--qlh); font-size: var(--qsize); text-align: center; color: var(--ink); max-height: 200px; overflow: hidden; }
.note { font-size: 12px; color: var(--muted); line-height: 1.8; }
.about { font-size: 12px; color: var(--muted); line-height: 1.9; }
.about a { color: var(--gold); }

/* ayah sheet */
.ayah-text { font-family: var(--qfont); font-size: 23px; line-height: 2; text-align: center; padding: 4px 4px 12px; }
.ayah-ref { text-align: center; font-size: 13px; color: var(--gold); margin-bottom: 14px; }
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.action { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 4px; border-radius: 20px; background: var(--surface2); font-size: 12px; }
.action svg { width: 22px; height: 22px; color: var(--gold); }
.action:active { transform: scale(.97); }
.tafsir { font-size: 17px; line-height: 2.05; text-align: justify; padding-top: 8px; color: color-mix(in srgb, var(--ink) 92%, var(--bg)); }
.tafsir .t4 { color: var(--gold); font-family: var(--qfont); }
.tafsir .t1 { font-weight: 600; }
.tafsir .t2 { color: var(--muted); }
.tafsir .t3 { color: color-mix(in srgb, var(--ink) 75%, var(--gold)); }
.tafsir-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.skeleton { height: 14px; border-radius: 8px; background: linear-gradient(90deg, var(--surface2), color-mix(in srgb, var(--surface2) 60%, var(--ink) 6%), var(--surface2)); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; margin: 12px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* khatma sky */
.sky { position: relative; width: 100%; aspect-ratio: 1; max-width: 420px; margin: 0 auto; }
.sky svg { width: 100%; height: 100%; }
.sky circle { transition: opacity .6s; cursor: pointer; }
.sky-stat { text-align: center; margin: 4px 0 6px; }
.sky-stat b { display: block; font-size: 40px; font-weight: 300; color: var(--gold); font-variant-numeric: tabular-nums; }
.sky-stat span { font-size: 13px; color: var(--muted); }

/* ---------- Drive ---------- */
.drive {
  position: fixed; inset: 0; z-index: 30; background: #050505; color: #e8e2d4;
  display: flex; flex-direction: column; align-items: stretch; justify-content: space-between;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 24px) calc(var(--safe-l) + 20px);
  animation: fadein .35s ease;
}
@keyframes fadein { from { opacity: 0; } }
.drive-close { position: absolute; top: calc(var(--safe-t) + 14px); left: calc(var(--safe-l) + 14px); color: #8d887e; width: 52px; height: 52px; }
.drive-close svg { width: 26px; height: 26px; }
.drive-trip { position: absolute; top: calc(var(--safe-t) + 18px); right: calc(var(--safe-r) + 18px); background: #141414; color: var(--gold); height: 46px; font-size: 15px; }
.drive-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding-top: 40px; touch-action: none; }
.drive-surah { font-family: "Amiri Quran", serif; font-size: clamp(54px, 16vw, 132px); line-height: 1.6; color: #efe9dc; }
.drive-reciter { font-size: 17px; color: #8d887e; }
.drive-ayah { font-size: 15px; color: var(--gold); min-height: 22px; font-variant-numeric: tabular-nums; }
.drive-progress { width: min(560px, 80vw); height: 3px; border-radius: 3px; background: #1c1c1c; margin-top: 18px; overflow: hidden; }
.drive-progress span { display: block; height: 100%; width: 0; background: var(--gold); margin-right: 0; transition: width .5s linear; }
.drive-time { font-size: 14px; color: #6d695f; font-variant-numeric: tabular-nums; }
.drive-controls { display: flex; align-items: center; justify-content: center; gap: clamp(20px, 8vw, 64px); }
.drive-btn { width: 88px; height: 88px; border-radius: 999px; display: grid; place-items: center; background: #141414; color: #e8e2d4; transition: transform .15s; }
.drive-btn svg { width: 34px; height: 34px; }
.drive-btn.big { width: 124px; height: 124px; background: var(--gold); color: #17130b; }
.drive-btn.big svg { width: 46px; height: 46px; }
.drive-btn:active { transform: scale(.95); }
@media (orientation: landscape) and (max-height: 500px) {
  .drive { flex-direction: row; align-items: center; }
  .drive-center { padding-top: 0; }
  .drive-controls { flex-direction: column; gap: 14px; }
  .drive-btn { width: 72px; height: 72px; } .drive-btn.big { width: 100px; height: 100px; }
  .drive-surah { font-size: clamp(48px, 11vw, 110px); }
}

.driving .scrim { z-index: 31; }
.driving .sheet { z-index: 32; }

/* ---------- Toast, hint, zoom ---------- */
.toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 18px); transform: translate(-50%, -20px); z-index: 40; background: var(--surface2); color: var(--ink); padding: 10px 18px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s var(--ease); box-shadow: 0 10px 30px rgba(0,0,0,.35); max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.zoom-badge { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9); z-index: 15; background: var(--surface2); color: var(--gold); width: 86px; height: 86px; border-radius: 999px; display: grid; place-items: center; font-size: 26px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-variant-numeric: tabular-nums; }
.zoom-badge.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.hint { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.72); display: grid; place-items: center; padding: 24px; animation: fadein .5s ease; }
.hint-card { background: var(--surface); border-radius: 28px; padding: 26px 24px 22px; max-width: 360px; width: 100%; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.hint-title { font-family: var(--qfont); font-size: 30px; color: var(--gold); text-align: center; margin-bottom: 6px; }
.hint ul { list-style: none; padding: 0; margin: 0 0 20px; }
.hint li { padding: 11px 0; font-size: 15px; color: var(--ink); border-bottom: 1px solid var(--line); line-height: 1.6; }
.hint li:last-child { border-bottom: 0; }
.hint .pill { width: 100%; justify-content: center; height: 48px; font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
