:root {
  --paper: #f7f2e7;
  --page: #fffdf7;
  --ink: #1b2620;
  --muted: #6b7268;
  --faint: #a9ab9f;
  --line: #e6dcc6;
  --accent: #1f5c45;
  --accent-ink: #fffdf7;
  --gold: #a8833a;
  --hl: rgba(168, 131, 58, 0.2);
  --heat0: #ebe3d1;
  --heat1: #9cc4ae;
  --heat2: #4f9273;
  --heat3: #1f5c45;
  --shadow: 0 1px 2px rgba(60, 45, 10, 0.06), 0 8px 30px rgba(60, 45, 10, 0.07);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Figtree", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111513; --page: #181d1a; --ink: #ebe5d5; --muted: #9aa096; --faint: #636a63;
    --line: #2a312d; --accent: #86c7a6; --accent-ink: #0f1a14; --gold: #d2b06a;
    --hl: rgba(210, 176, 106, 0.18); --heat0: #222925; --heat1: #2f5a46; --heat2: #4f9273; --heat3: #86c7a6;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 30px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #111513; --page: #181d1a; --ink: #ebe5d5; --muted: #9aa096; --faint: #636a63;
  --line: #2a312d; --accent: #86c7a6; --accent-ink: #0f1a14; --gold: #d2b06a;
  --hl: rgba(210, 176, 106, 0.18); --heat0: #222925; --heat1: #2f5a46; --heat2: #4f9273; --heat3: #86c7a6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 30px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

@font-face { font-family: "SuraNames"; src: url("/fonts/sura_names.woff2") format("woff2"); font-display: block; }
@font-face { font-family: "UthmanicHafs"; src: url("/fonts/UthmanicHafs.woff2") format("woff2"); font-display: swap; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* ---------- shared ---------- */
.wrap { max-width: 640px; margin: 0 auto; padding: 0 20px; }
.eyebrow { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 0 26px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 16px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 999px; color: var(--ink);
}
.icon-btn:hover { background: var(--hl); }
.icon-btn svg { width: 22px; height: 22px; }
.sn { font-family: "SuraNames"; direction: rtl; unicode-bidi: bidi-override; font-weight: normal; }

#toast {
  position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translate(-50%, -16px);
  background: var(--ink); color: var(--paper); padding: 12px 20px; border-radius: 999px;
  font-size: 15px; font-weight: 500; opacity: 0; pointer-events: none; transition: 0.25s ease; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center; white-space: nowrap;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 32px 20px; }
.login-inner { width: 100%; max-width: 360px; }
.mark { width: 56px; height: 56px; display: block; margin-bottom: 40px; }
.login h1 { font: 600 44px/1.05 var(--serif); margin: 0 0 12px; letter-spacing: -0.02em; }
.login p { color: var(--muted); margin: 0 0 36px; font-size: 17px; }
.field {
  width: 100%; height: 56px; padding: 0 18px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--page); font-size: 17px; outline: none; transition: border-color 0.15s;
}
.field:focus { border-color: var(--accent); }
.code-field { font: 600 32px var(--sans); letter-spacing: 0.6em; text-align: center; padding-left: 0.6em; height: 68px; }
.login .btn { width: 100%; margin-top: 14px; }
.login .err { color: #b4442f; min-height: 24px; margin-top: 12px; font-size: 15px; }
.login .link { margin-top: 20px; color: var(--muted); font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- home ---------- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 0; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand svg { width: 26px; height: 26px; }

.hero { padding: 48px 0 40px; }
.hero h1 { font: 600 clamp(34px, 9vw, 48px)/1.08 var(--serif); margin: 10px 0 28px; letter-spacing: -0.02em; text-wrap: balance; }
.hero h1 em { font-style: normal; color: var(--accent); }
.continue { width: 100%; justify-content: space-between; min-height: 68px; padding: 0 12px 0 26px; font-size: 17px; }
.continue .pg { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; text-align: left; }
.continue .pg small { font-weight: 500; opacity: 0.75; font-size: 13px; }
.continue .arrow { width: 46px; height: 46px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); display: grid; place-items: center; }

.numbers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 0 36px; }
.num b { display: block; font: 600 clamp(36px, 10vw, 52px)/1 var(--serif); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.num span { display: block; color: var(--muted); font-size: 14px; margin-top: 8px; }

.progress { padding: 0 0 28px; }
.pgrid { display: grid; gap: 5px; margin-top: 14px; }
.pg-row { display: grid; grid-template-columns: repeat(100, 1fr); gap: 1px; }
.pg-row i { height: 16px; border-radius: 1px; background: var(--heat0); }
.pg-row i.r { background: var(--accent); }
.pg-row i.nx { box-shadow: inset 0 0 0 1px var(--gold); }
.khatam-date b { display: block; font: 600 clamp(30px, 8vw, 40px)/1.1 var(--serif); letter-spacing: -0.02em; margin: 8px 0 6px; }
.khatam-date p { margin: 0; color: var(--muted); font-size: 15px; }
.section { padding: 32px 0; border-top: 1px solid var(--line); }
.section h2 { font: 600 22px var(--serif); margin: 0 0 18px; letter-spacing: -0.01em; }
.heat { display: grid; grid-template-columns: 52px repeat(7, 1fr); gap: 4px; align-items: center; }
.heat .hx { font-size: 12px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.heat .hy { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.heat i { height: 18px; border-radius: 4px; background: var(--heat0); }
.heat i.l1 { background: var(--heat1); } .heat i.l3 { background: var(--heat3); }
.heat i.today { outline: 1.5px solid var(--gold); outline-offset: 1px; }
.heat i.future { background: transparent; box-shadow: inset 0 0 0 1px var(--heat0); }
.heat-legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 10px; }

.browse summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; }
.browse summary::-webkit-details-marker { display: none; }
.browse summary h2 { margin: 0; }
.browse .chev { width: 22px; height: 22px; color: var(--muted); transform: rotate(-90deg); transition: transform 0.2s ease; }
.browse .chev svg { width: 22px; height: 22px; }
.browse[open] .chev { transform: rotate(90deg); }
.browse[open] summary { margin-bottom: 18px; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab { padding: 8px 16px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 15px; }
.tab.on { background: var(--ink); color: var(--paper); }
.jump { display: flex; gap: 8px; margin: 16px 0 8px; }
.jump .field { height: 48px; font-size: 16px; }
.jump .btn { min-height: 48px; padding: 0 20px; }

.list { list-style: none; margin: 0; padding: 0; }
.list a { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; padding: 13px 0; text-decoration: none; border-bottom: 1px solid var(--line); }
.list li:last-child a { border-bottom: 0; }
.list .n { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.list .t b { font-weight: 600; display: block; }
.list .t small { color: var(--muted); font-size: 13px; }
.list .ar { font-size: 30px; line-height: 1; color: var(--ink); }
.list .pgs { color: var(--muted); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.list .doneDot { display: inline-block; width: 7px; height: 7px; border-radius: 9px; background: var(--accent); margin-left: 6px; vertical-align: middle; }

.recent { list-style: none; padding: 0; margin: 0; }
.recent li:last-child { border-bottom: 0; }
.recent li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.recent li span:last-child { color: var(--muted); }
.recent a:hover, .list a:hover b { color: var(--accent); }
.top .icon-btn { margin-right: -10px; }
.empty { color: var(--muted); margin: 0; }

.settings { display: grid; gap: 22px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.setting label { font-weight: 500; }
.setting small { display: block; color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; background: var(--heat0); border-radius: 999px; padding: 3px; }
.seg button { padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--page); color: var(--ink); box-shadow: var(--shadow); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper .icon-btn { box-shadow: inset 0 0 0 1.5px var(--line); font-size: 20px; }
.stepper output { min-width: 32px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.foot { padding: 32px 0 calc(48px + env(safe-area-inset-bottom)); color: var(--faint); font-size: 13px; }
.foot a { color: var(--muted); }

/* ---------- reader ---------- */
.reader { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.rbar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px; max-width: 760px; width: 100%; margin: 0 auto;
}
.rside { display: flex; width: 92px; flex: none; }
.rside:last-child { justify-content: flex-end; }
.rtitle { text-align: center; line-height: 1.2; min-width: 0; }
.rtitle b { display: block; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtitle small { color: var(--muted); font-size: 12px; }
.stage { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
.stage-inner { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100%; padding: 4px 6px 16px; }
.stage-inner:has(.trans:not(.hidden)) { justify-content: flex-start; }

.mushaf {
  --w: 360px; --lh: calc(var(--w) / 9.2); --pad: calc(var(--w) * 0.03);
  width: var(--w); background: var(--page); border-radius: 6px; box-shadow: var(--shadow);
  padding: calc(var(--w) * 0.045) var(--pad) calc(var(--w) * 0.033);
  position: relative; transition: opacity 0.18s ease;
}
.mushaf.loading .lines { opacity: 0; }
.lines { direction: rtl; transition: opacity 0.2s ease; }
.ln { height: var(--lh); display: flex; align-items: center; justify-content: space-between; white-space: nowrap; color: var(--ink); }
.ln.x { justify-content: center; gap: 0.18em; }
.compact:not(.flow) .lines { padding: calc(var(--lh) * 2.2) 8% calc(var(--lh) * 2.6); }
.compact .ln { justify-content: center; gap: 0.18em; }
/* wrapped layout: words flow as justified text, headers and basmala stay as blocks */
.flow { --pad: 14px; }
.flow .lines { text-align: justify; text-align-last: center; line-height: var(--lh); padding: 4px 0; }
.flow .ln, .flow .ln.x { display: inline; height: auto; white-space: normal; }
.flow .hd, .flow .bs { height: calc(var(--lh) * 1.1); margin: 6px 0; }
.flow .hd .sn { font-size: min(calc(var(--lh) * 0.7), 44px); }
.w { cursor: pointer; transition: color 0.15s; border-radius: 4px; }
.w.e { color: var(--gold); }
.w.on { color: var(--accent); }
.w.on.e { color: var(--accent); }

.hd { height: var(--lh); display: flex; align-items: center; justify-content: center; position: relative; color: var(--gold); }
.hd svg { position: absolute; inset: 8% 0; width: 100%; height: 84%; }
.hd .sn { position: relative; color: var(--ink); font-size: calc(var(--lh) * 0.72); line-height: 1; }
.bs { height: var(--lh); display: flex; align-items: center; justify-content: center; }
.bs i {
  display: block; height: 80%; aspect-ratio: 176 / 36; background: var(--ink);
  -webkit-mask: url("/bismillah.svg") center / contain no-repeat; mask: url("/bismillah.svg") center / contain no-repeat;
}
.pfoot { text-align: center; color: var(--muted); font-size: 13px; padding-top: calc(var(--lh) * 0.1); font-variant-numeric: tabular-nums; }
.read-badge {
  position: absolute; top: 10px; left: 10px; width: 22px; height: 22px; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.read-badge svg { width: 13px; height: 13px; }

.trans { width: var(--w); padding: 28px 4px 0; }
.trans .v { padding: 14px 0; border-bottom: 1px solid var(--line); scroll-margin-top: 20px; }
.trans .v:last-child { border-bottom: 0; }
.trans .v.on { background: var(--hl); margin: 0 -10px; padding: 14px 10px; border-radius: 8px; }
.trans .k { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; color: var(--gold); text-transform: uppercase; }
.trans p { margin: 4px 0 0; font-size: 16px; line-height: 1.55; }
.trans p.en { color: var(--muted); font-size: 15px; }

.dock {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); max-width: 560px; width: 100%; margin: 0 auto;
}
.dock .btn { flex: 1; max-width: 280px; }
.continue.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.continue.ghost .arrow { background: var(--heat0); }
.dock .btn.done { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.dock .icon-btn { width: 52px; height: 52px; box-shadow: inset 0 0 0 1.5px var(--line); }
.dock .icon-btn[disabled] { opacity: 0.3; cursor: default; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--page); box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  border-radius: 20px 20px 0 0; padding: 10px 22px calc(26px + env(safe-area-inset-bottom)); max-height: 62dvh; overflow-y: auto;
  transform: translateY(105%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); max-width: 640px; margin: 0 auto;
}
.sheet.on { transform: none; }
.sheet .grab { width: 40px; height: 4px; border-radius: 9px; background: var(--line); margin: 0 auto 16px; }
.sheet .k { font-size: 13px; font-weight: 600; letter-spacing: 0.06em; color: var(--gold); text-transform: uppercase; display: flex; justify-content: space-between; align-items: center; }
.sheet .arab { font-family: "UthmanicHafs"; direction: rtl; font-size: 26px; line-height: 1.9; margin: 12px 0 8px; }
.sheet p { margin: 10px 0 0; font-size: 17px; line-height: 1.55; }
.sheet p.en { color: var(--muted); font-size: 15px; }
.sheet small { color: var(--faint); font-size: 12px; display: block; margin-top: 14px; }

@media (min-width: 900px) {
  .hero { padding-top: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
