@font-face {
  font-family: "Hafs";
  src: url("fonts/UthmanicHafs.woff2") format("woff2");
  font-display: block;
}

:root {
  --bg: #F4EFE4;
  --card: #FFFCF6;
  --card-2: #F8F3E9;
  --ink: #1C2320;
  --muted: #69716C;
  --faint: #9AA19C;
  --line: #E3DBCC;
  --accent: #0D6B5B;
  --accent-2: #0A5649;
  --accent-soft: #DCEDE7;
  --on-accent: #FFFFFF;
  --gold: #B07F24;
  --gold-soft: #F6E8C8;
  --me: #C8621E;
  --me-soft: #FBE3D2;
  --warn: #B4471F;
  --warn-soft: #FAE1D6;
  --ok: #2F7D4F;
  --shadow: 0 1px 2px rgba(40, 32, 18, .06), 0 6px 20px rgba(40, 32, 18, .06);
  --radius: 20px;
  --tabbar: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1412;
    --card: #161E1B;
    --card-2: #1B2521;
    --ink: #ECE7DC;
    --muted: #9BA39E;
    --faint: #6E7772;
    --line: #26312D;
    --accent: #3BB79B;
    --accent-2: #5CCBB1;
    --accent-soft: #173A32;
    --on-accent: #06221C;
    --gold: #E2B458;
    --gold-soft: #3A2F18;
    --me: #F09A5A;
    --me-soft: #3D2616;
    --warn: #F0875F;
    --warn-soft: #3C2018;
    --ok: #62C48C;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0E1412;
  --card: #161E1B;
  --card-2: #1B2521;
  --ink: #ECE7DC;
  --muted: #9BA39E;
  --faint: #6E7772;
  --line: #26312D;
  --accent: #3BB79B;
  --accent-2: #5CCBB1;
  --accent-soft: #173A32;
  --on-accent: #06221C;
  --gold: #E2B458;
  --gold-soft: #3A2F18;
  --me: #F09A5A;
  --me-soft: #3D2616;
  --warn: #F0875F;
  --warn-soft: #3C2018;
  --ok: #62C48C;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 28px);
}

/* ---------- type */
h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 4px; font-weight: 750; }
h2 { font-size: 19px; line-height: 1.25; letter-spacing: -.01em; margin: 0 0 10px; font-weight: 700; }
h3 { font-size: 16px; margin: 0 0 6px; font-weight: 650; }
p { margin: 0 0 10px; }
.sub { color: var(--muted); font-size: 15px; margin-bottom: 18px; }
.small { font-size: 13.5px; color: var(--muted); }
.tiny { font-size: 12px; color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.head .sub { margin: 0; }

/* ---------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card.flat { box-shadow: none; background: var(--card-2); }
.card.accent { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.card.accent .small { color: inherit; opacity: .85; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 650; font-size: 16px;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--card-2); color: var(--ink); border: 1px solid var(--line); }
.btn.soft { background: var(--accent-soft); color: var(--accent-2); }
.btn.wide { width: 100%; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14.5px; }
.btn svg { width: 20px; height: 20px; fill: currentColor; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }
.btns > .btn { flex: 1 1 0; min-width: 0; padding: 0 12px; white-space: nowrap; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  font-size: 14.5px; font-weight: 550; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); background: var(--card); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- today */
.plan { display: grid; gap: 10px; }
.plan-row {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px;
  padding: 12px; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line);
  cursor: pointer; text-align: left; width: 100%;
}
.plan-row .dot {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-2); font-weight: 750;
}
.plan-row.done .dot { background: var(--accent); color: var(--on-accent); }
.plan-row b { display: block; font-size: 16px; }
.plan-row .small { display: block; margin-top: 1px; }
.plan-row .go { color: var(--faint); font-size: 22px; }
.week { display: flex; justify-content: space-between; gap: 6px; margin-top: 6px; }
.week div { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.week i {
  display: block; margin: 0 auto 6px; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent;
}
.week .yes i { background: var(--accent); border-color: var(--accent); }
.week .today i { border-color: var(--gold); }
.focus-card { border-left: 4px solid var(--gold); }
.focus-card .label { font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--gold); }
.focus-card .what { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* ---------- ayah */
.ayah-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ayah-bar .where {
  flex: 1; min-width: 0; text-align: center; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; min-height: 44px; padding: 0 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 650;
}
.ayah-bar .where .ar { font-family: "Hafs", serif; font-size: 20px; font-weight: 400; }
.ayah {
  direction: rtl; text-align: center;
  font-family: "Hafs", "Amiri Quran", "Noto Naskh Arabic", serif;
  font-size: clamp(28px, 8.4vw, 38px); line-height: 1.9;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 10px;
  padding: 6px 2px 2px;
}
.w {
  display: inline-flex; flex-direction: column; align-items: center;
  border-radius: 12px; padding: 0 4px; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.w .tr {
  direction: ltr; font-family: -apple-system, system-ui, sans-serif; font-size: 12px; line-height: 1.2;
  color: var(--faint); margin-top: -4px; padding-bottom: 4px; white-space: nowrap;
}
.w.now { background: var(--gold-soft); }
.w.flag { color: var(--warn); }
.w.flag .tr { color: var(--warn); }
.w.tap { background: var(--accent-soft); }
.hl { color: var(--me); }
.end-mark { font-family: "Hafs", serif; color: var(--gold); }
.no-translit .w .tr { display: none; }

/* ---------- steps */
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0; }
.steps button {
  border: 1px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 8px 4px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.steps button b { font-size: 15px; color: var(--ink); }
.steps button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps button.on b { color: var(--on-accent); }
.steps button.did:not(.on) { border-color: var(--accent); }

.stage { text-align: center; padding: 22px 18px; }
.stage .say { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.stage .small { margin-bottom: 16px; }
.big {
  width: 96px; height: 96px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  display: inline-grid; place-items: center; margin: 6px auto 12px;
  box-shadow: 0 10px 24px rgba(13, 107, 91, .28);
  transition: transform .12s ease;
}
.big:active { transform: scale(.95); }
.big svg { width: 36px; height: 36px; fill: currentColor; }
.big.rec { background: var(--warn); box-shadow: 0 10px 24px rgba(180, 71, 31, .3); }
.big.rec.live { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(180, 71, 31, .12); } }
@media (prefers-reduced-motion: reduce) { .big.rec.live { animation: none; } }
.count { display: flex; justify-content: center; gap: 8px; margin: 2px 0 14px; }
.count i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.count i.on { background: var(--accent); }
.speed { display: flex; justify-content: center; gap: 8px; }

.live-wrap { position: relative; margin: 4px 0 12px; }
canvas.live { width: 100%; height: 150px; display: block; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line); }
.live-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.timer { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.level { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin: 8px auto 0; max-width: 220px; }
.level i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .06s linear; }

/* ---------- compare */
.play-row { display: grid; grid-template-columns: 1fr 1fr 1.75fr; gap: 8px; margin-bottom: 14px; }
.play-row .btn { padding: 0 8px; min-height: 46px; font-size: 14.5px; white-space: nowrap; gap: 6px; }
.who-him { color: var(--accent); }
.who-me { color: var(--me); }
.finds { display: grid; gap: 10px; margin-bottom: 14px; }
.find {
  display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start;
  padding: 14px; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line);
}
.find .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.find.warn .ic { background: var(--warn-soft); color: var(--warn); }
.find.good .ic { background: var(--accent-soft); color: var(--accent-2); }
.find.info .ic { background: var(--gold-soft); color: var(--gold); }
.find b { display: block; margin-bottom: 2px; }
.find .small { margin: 0; }
.find .ar { font-family: "Hafs", serif; font-size: 22px; line-height: 1.5; }
.find button.link { border: 0; background: none; color: var(--accent); font-weight: 650; padding: 6px 0 0; cursor: pointer; font-size: 14.5px; }

.chart-scroll { overflow-x: auto; direction: rtl; margin: 0 -4px; padding: 0 4px; scrollbar-width: none; }
.chart-scroll::-webkit-scrollbar { display: none; }
.chart { display: block; }
.chart .l-ref { stroke: var(--accent); fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.chart .l-me { stroke: var(--me); fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .sep { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .flagbg { fill: var(--warn-soft); }
.chart .stopmark { fill: var(--warn); }
.chart text { font-family: "Hafs", serif; font-size: 17px; fill: var(--ink); direction: rtl; }
.chart text.flag { fill: var(--warn); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.legend i { display: inline-block; width: 18px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

.pick-one .chips { margin-top: 10px; }
.note { font-size: 13.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }

/* ---------- letters */
.letter-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lt {
  aspect-ratio: 1; border-radius: 16px; border: 1px solid var(--line); background: var(--card);
  font-family: "Hafs", serif; font-size: 30px; cursor: pointer; display: grid; place-items: center; line-height: 1;
}
.lt.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.letter-card .big-letter { font-family: "Hafs", serif; font-size: 64px; line-height: 1.1; color: var(--accent); }
.letter-card .top { display: flex; gap: 16px; align-items: center; margin-bottom: 10px; }
.letter-card .top h2 { margin: 0; }
.letter-card dl { margin: 0 0 12px; }
.letter-card dt { font-size: 12.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-top: 10px; }
.letter-card dd { margin: 2px 0 0; }
.word-chips { display: flex; flex-wrap: wrap; gap: 8px; direction: rtl; }
.word-chip {
  font-family: "Hafs", serif; font-size: 26px; line-height: 1.6; padding: 0 14px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--card-2); cursor: pointer;
}
.word-chip.now { border-color: var(--accent); background: var(--accent-soft); }
.heavy-tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--gold-soft); color: var(--gold); margin-left: 6px; vertical-align: middle; }

/* ---------- progress */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; position: relative; }
.bars .b { flex: 1; background: var(--accent-soft); border-radius: 6px 6px 3px 3px; position: relative; min-height: 3px; }
.bars .b.hit { background: var(--accent); }
.bars .goal { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--gold); }
.bars-x { display: flex; gap: 6px; font-size: 11px; color: var(--faint); margin-top: 4px; }
.bars-x span { flex: 1; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal i { aspect-ratio: 1; border-radius: 8px; background: var(--card-2); border: 1px solid var(--line); }
.cal i.yes { background: var(--accent); border-color: var(--accent); }
.cal i.today { outline: 2px solid var(--gold); outline-offset: 1px; }
.cal i.future { visibility: hidden; }
.takes { display: grid; gap: 10px; }
.take-row { padding: 14px; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line); }
.take-row .t { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.take-row .btns .btn { min-height: 40px; font-size: 14.5px; }

/* ---------- picker / sheet */
#sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-back { position: absolute; inset: 0; background: rgba(8, 12, 10, .45); animation: fade .2s ease; }
.sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 90vh; overflow: auto;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .28s cubic-bezier(.2, .8, .2, 1);
  max-width: 560px; margin: 0 auto;
}
.sheet-card .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet-card .sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-card .sheet-head h2 { margin: 0; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet-card, .sheet-back { animation: none; } }
.search {
  width: 100%; min-height: 46px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 0 14px; font-size: 16px; margin-bottom: 10px;
}
.surah-list { display: grid; gap: 2px; }
.surah-item {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  padding: 10px 8px; border: 0; background: none; text-align: left; border-radius: 12px; cursor: pointer; width: 100%;
}
.surah-item:active, .surah-item.on { background: var(--card-2); }
.surah-item .n { color: var(--faint); font-size: 14px; text-align: center; }
.surah-item .ar { font-family: "Hafs", serif; font-size: 22px; }
.surah-item .small { display: block; }
.ayah-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.ayah-grid button {
  min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums;
}
.ayah-grid button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.ayah-grid button.did { border-color: var(--accent); }

.breath-num { font-size: 64px; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1; }
.breath-ring { width: 180px; height: 180px; margin: 8px auto 14px; position: relative; }
.breath-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.breath-ring .track { stroke: var(--line); }
.breath-ring .fill { stroke: var(--accent); transition: stroke-dashoffset .1s linear; }
.breath-ring .mid { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.rounds { display: flex; justify-content: center; gap: 10px; margin: 6px 0 14px; }
.rounds span { min-width: 64px; padding: 6px 10px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); font-variant-numeric: tabular-nums; font-weight: 650; }

/* ---------- tabs */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(18px); backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
#tabs button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11.5px; font-weight: 600; color: var(--faint); cursor: pointer; min-height: 50px; justify-content: center;
}
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.on { color: var(--accent); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 18px); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14.5px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; font-weight: 650; cursor: pointer; }
.lt { position: relative; }
.lt.mine::after { content: "★"; position: absolute; top: 4px; right: 6px; font: 11px/1 system-ui, sans-serif; color: var(--gold); }
.lt.on.mine::after { color: var(--on-accent); }
.chip .ar, .focus-card .what .ar { font-family: "Hafs", serif; font-size: 21px; line-height: 1; }
.focus-card .btn { margin-top: 4px; }

.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mb0 { margin-bottom: 0; }
.err { color: var(--warn); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
