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

:root {
  color-scheme: light;
  --paper: #f8f3e6;
  --surface: #fffdf6;
  --surface-strong: #ffffff;
  --ink: #211d14;
  --ink-soft: #6e6654;
  --gold: #a5854b;
  --gold-text: #806735;
  --gold-soft: color-mix(in srgb, var(--gold) 13%, transparent);
  --green: #2f6b4f;
  --green-soft: #dcebe2;
  --amber: #c98a2d;
  --amber-soft: #f5e5c9;
  --red: #b4533a;
  --red-soft: #f1ddd7;
  --line: #e4dcc8;
  --control-line: #8f866f;
  --on-green: #fffdf6;
  --scrim: rgb(20 25 38 / 44%);
  --nav-height: 58px;
  --mini-height: 62px;
  --radius-card: 10px;
  --radius-button: 8px;
  --quran-size: 32px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-quran: "Uthmanic Hafs", "Noto Naskh Arabic", serif;
  --ease-out: cubic-bezier(.2, .75, .25, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="paper"]) {
    color-scheme: dark;
    --paper: #141926;
    --surface: #1c2333;
    --surface-strong: #222b3d;
    --ink: #ede7d6;
    --ink-soft: #aeb2bc;
    --gold: #c9a961;
    --gold-text: #c9a961;
    --green: #58a47c;
    --green-soft: #233e35;
    --amber: #d9a144;
    --amber-soft: #493a24;
    --red: #cd7b62;
    --red-soft: #49302e;
    --line: #2f394e;
    --control-line: #687792;
    --on-green: #141926;
    --scrim: rgb(0 0 0 / 58%);
  }
}

:root[data-theme="night"] {
  color-scheme: dark;
  --paper: #141926;
  --surface: #1c2333;
  --surface-strong: #222b3d;
  --ink: #ede7d6;
  --ink-soft: #aeb2bc;
  --gold: #c9a961;
  --gold-text: #c9a961;
  --green: #58a47c;
  --green-soft: #233e35;
  --amber: #d9a144;
  --amber-soft: #493a24;
  --red: #cd7b62;
  --red-soft: #49302e;
  --line: #2f394e;
  --control-line: #687792;
  --on-green: #141926;
  --scrim: rgb(0 0 0 / 58%);
}

:root[data-theme="paper"] { color-scheme: light; }

*, *::before, *::after { box-sizing: border-box; }

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
}

button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button, input, select { -webkit-appearance: none; appearance: none; }
button:disabled { cursor: not-allowed; opacity: .5; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.app-shell {
  position: relative;
  width: min(100%, 640px);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  border-inline: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}

.view-stack { height: 100%; }

.view {
  position: absolute;
  inset: 0;
  display: none;
  background: var(--paper);
  contain: layout paint;
}

.view.is-active { display: block; }

.view-scroll {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  padding: 0 16px calc(var(--nav-height) + env(safe-area-inset-bottom) + 24px);
}

.view.has-mini-player .view-scroll {
  padding-bottom: calc(var(--nav-height) + var(--mini-height) + env(safe-area-inset-bottom) + 20px);
}

.page-header {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-inline: -16px;
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  backdrop-filter: blur(14px);
}

.page-header__copy { min-width: 0; }
.page-header__eyebrow {
  display: block;
  margin-bottom: 2px;
  color: var(--gold-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.page-title {
  margin: 0;
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 650;
  letter-spacing: -.025em;
  line-height: 1.1;
}
.page-subtitle { margin: 4px 0 0; color: var(--ink-soft); font-size: 13px; }

.back-button, .icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: 50%;
  background: var(--surface);
}

.icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.section-block { margin-top: 24px; }
.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}
.section-title { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.section-note { color: var(--ink-soft); font-size: 12px; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.continue-card, .review-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 16px;
  overflow: hidden;
}
.continue-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  content: "";
  background: var(--gold);
}
.continue-card strong, .review-card h2 { display: block; margin: 0 0 4px; font-size: 16px; }
.continue-card small, .review-card p { display: block; margin: 0; color: var(--ink-soft); font-size: 13px; }
.review-count {
  display: grid;
  min-width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  background: var(--amber-soft);
  color: var(--ink);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.button {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-button);
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
}
.button--primary { border-color: var(--green); background: var(--green); color: var(--on-green); }
.button--gold { border-color: var(--gold); background: var(--gold); color: #17140e; }
.button--danger { border-color: var(--red); color: var(--red); }
.button--quiet { border-color: transparent; background: transparent; color: var(--ink-soft); }
.button--wide { width: 100%; }
.text-button { min-height: 44px; padding: 8px 0; border: 0; background: none; color: var(--gold-text); font-weight: 650; }

.search-field { position: relative; margin-top: 16px; }
.search-field svg {
  position: absolute;
  top: 50%;
  left: 14px;
  width: 20px;
  height: 20px;
  translate: 0 -50%;
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 2;
}
.search-input {
  width: 100%;
  height: 48px;
  padding: 0 44px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-button);
  background: var(--surface);
  outline: none;
}
.search-input:focus { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-soft); }
.search-input::placeholder { color: var(--ink-soft); opacity: 1; }
.search-clear { position: absolute; top: 2px; right: 2px; width: 44px; height: 44px; border: 0; background: none; color: var(--ink-soft); }

.surah-list { margin: 0 -16px; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.surah-item { position: relative; }
.surah-item .surah-row { padding-right: 60px; }
.fav-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 1;
  translate: 0 -50%;
}
.fav-toggle.is-active { color: var(--gold); }
.surah-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  grid-template-areas: "number meta arabic" "number bar status";
  gap: 4px 12px;
  width: 100%;
  min-height: 78px;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}
.surah-number {
  grid-area: number;
  display: grid;
  width: 38px;
  height: 38px;
  align-self: center;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--gold-text);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.surah-meta { grid-area: meta; min-width: 0; align-self: end; }
.surah-meta strong { display: block; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.surah-meta small { color: var(--ink-soft); font-size: 12px; }
.surah-arabic { grid-area: arabic; align-self: end; font-family: var(--font-quran); font-size: 22px; line-height: 1; direction: rtl; }
.surah-progress { grid-area: bar; align-self: center; height: 3px; overflow: hidden; border-radius: 3px; background: var(--line); }
.surah-progress > i { display: block; width: var(--progress, 0%); height: 100%; background: var(--green); }
.status-chip { grid-area: status; align-self: center; justify-self: end; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink-soft); font-size: 10px; white-space: nowrap; }
.status-chip[data-status="memorized"] { border-color: var(--green); background: var(--green-soft); color: var(--ink); }
.status-chip[data-status="mastered"] { border-color: var(--gold); background: var(--gold-soft); color: var(--ink); }

.quick-presets { display: flex; gap: 8px; margin-inline: -16px; padding: 4px 16px 8px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
.quick-presets::-webkit-scrollbar { display: none; }
.pill { flex: 0 0 auto; min-height: 44px; padding: 8px 13px; scroll-snap-align: start; border: 1px solid var(--control-line); border-radius: 999px; background: var(--surface); font-size: 13px; }
.pill.is-active { border-color: var(--gold); background: var(--gold-soft); }

.selector-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0 12px; }
.mode-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 10px; border: 1px solid var(--control-line); border-radius: var(--radius-button); background: var(--surface); font-size: 13px; }
.switch-track { position: relative; width: 34px; height: 20px; border-radius: 999px; background: var(--control-line); }
.switch-track::after { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; content: ""; background: var(--surface-strong); transition: transform 180ms var(--ease-out); }
[aria-pressed="true"] .switch-track { background: var(--green); }
[aria-pressed="true"] .switch-track::after { transform: translateX(14px); }

.ayah-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 10px; padding-bottom: 120px; }
.ayah-chip {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 44px;
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.ayah-chip[data-confidence="1"] { border-color: var(--red); border-style: dashed; background: var(--red-soft); }
.ayah-chip[data-confidence="2"] { border-width: 3px; border-color: var(--amber); border-style: double; background: var(--amber-soft); }
.ayah-chip[data-confidence="3"] { border-width: 2px; border-color: var(--green); background: var(--green-soft); }
.ayah-chip.is-selected { border-width: 1px; border-color: var(--gold); border-style: solid; background: var(--gold); color: #17140e; box-shadow: inset 0 0 0 2px var(--surface); }
.ayah-chip.is-multi-selected::after { position: absolute; inset: 2px; border: 2px solid var(--gold); border-radius: 50%; content: ""; }

.selection-footer {
  position: absolute;
  z-index: 8;
  right: 0;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
  left: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(12px);
}
.selection-summary strong { display: block; font-size: 15px; }
.selection-summary small { color: var(--ink-soft); }
.bulk-rating-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 16px; }

/* The player never scrolls as a whole: the transport controls stay on screen
   and only the Quran text pane scrolls internally. This fixes phones where the
   controls used to sit below the fold and were unreachable. */
.player-view .view-scroll { padding: 0; overflow: hidden; }
.player-empty { height: 100%; padding: 0 16px calc(var(--nav-height) + env(safe-area-inset-bottom) + 24px); overflow-y: auto; }
.player-shell {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
}
.player-header { padding: max(14px, env(safe-area-inset-top)) 16px 12px; }
.cartouche {
  position: relative;
  padding: 10px 36px 8px;
  border-block: 1px solid var(--gold);
  text-align: center;
}
.cartouche::before, .cartouche::after { position: absolute; top: -4px; bottom: -4px; width: 8px; content: ""; border-block: 1px solid var(--gold); }
.cartouche::before { left: 14px; border-left: 1px solid var(--gold); }
.cartouche::after { right: 14px; border-right: 1px solid var(--gold); }
.cartouche h1 { margin: 0; font-family: var(--font-quran); font-size: 26px; font-weight: 400; line-height: 1.25; }
.cartouche button { min-height: 44px; padding: 3px 6px; border: 0; background: none; color: var(--ink-soft); font-size: 12px; }
.player-mode-line { display: flex; justify-content: center; gap: 8px; margin-top: 10px; color: var(--ink-soft); font-size: 11px; }
.mode-badge { padding: 3px 8px; border-radius: 999px; background: var(--gold-soft); color: var(--ink); }

.quran-pane { position: relative; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; border-block: 1px solid var(--line); scroll-behavior: smooth; }
.text-toggle { min-height: 36px; padding: 6px 14px; font-size: 12px; font-weight: 650; color: var(--ink); }
.player-mode-line { align-items: center; }
.mode-help { width: 34px; height: 34px; font-size: 14px; font-weight: 700; color: var(--gold-text); }
.quran-toolbar { position: sticky; z-index: 3; top: 0; display: flex; justify-content: flex-end; padding: 8px 12px; pointer-events: none; }
.quran-toolbar button { pointer-events: auto; background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(8px); }
.ayah-text {
  position: relative;
  margin: 0;
  padding: 18px 20px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  font-family: var(--font-quran);
  font-size: var(--quran-size);
  line-height: 2.1;
  text-align: right;
  direction: rtl;
  scroll-margin-block: 88px;
}
.ayah-text.is-current { background: var(--gold-soft); }
.ayah-text.is-hidden { min-height: 112px; color: transparent; text-shadow: none; cursor: pointer; }
.ayah-text.is-hidden::after { position: absolute; inset: 0; display: grid; place-items: center; content: "Tap to reveal"; color: var(--ink-soft); font-family: var(--font-ui); font-size: 13px; direction: ltr; }
.ayah-marker { display: inline-block; margin-inline-start: .2em; color: var(--gold); white-space: nowrap; }

.rating-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 16px; }
.rating-button { min-height: 48px; padding: 6px 4px; border: 1px solid var(--control-line); border-radius: var(--radius-button); background: var(--surface); font-size: 12px; font-weight: 650; }
.rating-button::before { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; content: ""; }
.rating-button[data-rating="1"]::before { background: var(--red); }
.rating-button[data-rating="2"]::before { background: var(--amber); }
.rating-button[data-rating="3"]::before { background: var(--green); }
.rating-button.is-selected[data-rating="1"] { border-color: var(--red); background: var(--red-soft); }
.rating-button.is-selected[data-rating="2"] { border-color: var(--amber); background: var(--amber-soft); }
.rating-button.is-selected[data-rating="3"] { border-color: var(--green); background: var(--green-soft); }

.repeat-panel { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; border-block: 1px solid var(--line); background: var(--line); }
.repeat-control:last-child { grid-column: 1 / -1; }
.repeat-control { min-width: 0; padding: 10px 5px; background: var(--surface); text-align: center; }
.repeat-control__label { display: block; overflow: hidden; color: var(--ink-soft); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.stepper { display: grid; grid-template-columns: 44px minmax(28px, 1fr) 44px; align-items: center; margin-top: 3px; }
.stepper button { width: 44px; height: 44px; padding: 0; border: 0; background: none; color: var(--gold-text); font-size: 20px; }
.stepper output, .repeat-value { font-size: 17px; font-variant-numeric: tabular-nums; font-weight: 700; }
.repeat-control > button { width: 100%; min-height: 44px; padding: 2px; border: 0; background: none; }

.transport { padding: 12px 16px 16px; }
.bead-counter { margin-bottom: 8px; text-align: center; }
.bead-strand { position: relative; display: flex; min-height: 22px; align-items: center; justify-content: center; gap: clamp(3px, 1.5vw, 8px); overflow: hidden; }
.bead-strand::before { position: absolute; right: 5%; left: 5%; height: 1px; content: ""; background: var(--line); }
.bead { position: relative; z-index: 1; width: clamp(9px, 2.8vw, 14px); height: clamp(9px, 2.8vw, 14px); border: 1px solid var(--gold); border-radius: 50%; background: var(--surface); }
.bead.is-complete { background: var(--gold); transform: translateX(1px); }
.bead-label { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 10px; font-variant-numeric: tabular-nums; }
.transport-buttons { display: flex; align-items: center; justify-content: center; gap: clamp(2px, 1.5vw, 8px); }
.transport-buttons button { border: 0; background: none; }
.transport-buttons .icon-button { width: clamp(38px, 11vw, 48px); height: clamp(38px, 11vw, 48px); }
.shift-button { font-size: 13px; font-weight: 700; color: var(--gold-text); }
.play-button { display: grid; width: clamp(56px, 17vw, 72px); height: clamp(56px, 17vw, 72px); flex: 0 0 auto; place-items: center; border-radius: 50% !important; background: var(--green) !important; color: var(--on-green); }
.play-button .icon { width: 30px; height: 30px; }
.play-button .icon-pause, .is-playing .play-button .icon-play, .mini-player.is-playing .icon-play { display: none; }
.is-playing .play-button .icon-pause, .mini-player.is-playing .icon-pause { display: block; }
.speed-button { width: 44px; height: 44px; font-size: 12px; font-weight: 700; }

.mini-player {
  position: absolute;
  z-index: 20;
  right: 0;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
  left: 0;
  height: var(--mini-height);
  align-items: center;
  gap: 6px;
  padding: 7px 10px 7px 16px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(14px);
}
.mini-player:not([hidden]) { display: flex; }
.mini-player__open { display: grid; min-width: 0; flex: 1; grid-template-columns: 54px minmax(0, 1fr); align-items: center; gap: 10px; padding: 0; border: 0; background: none; text-align: left; }
.mini-player__copy { min-width: 0; }
.mini-player__copy strong, .mini-player__copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-player__copy strong { font-size: 13px; }
.mini-player__copy small { color: var(--ink-soft); font-size: 11px; }
.mini-player__toggle { border: 0; background: transparent; }
.mini-player__toggle .icon-pause { display: none; }
.mini-beads { position: relative; display: flex; align-items: center; gap: 3px; }
.mini-beads::before { position: absolute; right: 0; left: 0; height: 1px; content: ""; background: var(--line); }
.mini-beads i { position: relative; width: 8px; height: 8px; border: 1px solid var(--gold); border-radius: 50%; background: var(--surface); }
.mini-beads i:first-child, .mini-player.is-playing .mini-beads i:nth-child(-n+3) { background: var(--gold); }

.bottom-nav {
  position: absolute;
  z-index: 21;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 98%, transparent);
  backdrop-filter: blur(16px);
}
.nav-item { position: relative; display: grid; min-width: 0; place-content: center; justify-items: center; gap: 2px; padding: 4px 2px; border: 0; background: none; color: var(--ink-soft); font-size: 10px; }
.nav-item::before { position: absolute; top: 0; width: 24px; height: 2px; border-radius: 0 0 2px 2px; content: ""; background: transparent; }
.nav-item.is-active { color: var(--gold-text); }
.nav-item.is-active::before { background: var(--gold); }
.nav-icon { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-tile { min-height: 112px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); }
.stat-tile--wide { grid-column: 1 / -1; min-height: 96px; }
.stat-value { display: block; font-size: clamp(26px, 8vw, 38px); font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: -.04em; }
.stat-label { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 12px; }
.stat-key { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; }
.stat-key.practice { background: var(--red); }.stat-key.review { background: var(--amber); }.stat-key.confident { background: var(--green); }

.stacked-bar { display: flex; width: 100%; height: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 999px; background: var(--line); }
.stacked-bar > i { display: block; min-width: 0; height: 100%; }
.stacked-bar .untracked { background: var(--line); }
.stacked-bar .practice { background: repeating-linear-gradient(135deg, var(--red) 0 4px, color-mix(in srgb, var(--red) 65%, var(--surface)) 4px 7px); }
.stacked-bar .review { background: repeating-linear-gradient(90deg, var(--amber) 0 6px, color-mix(in srgb, var(--amber) 68%, var(--surface)) 6px 8px); }
.stacked-bar .confident { background: var(--green); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; color: var(--ink-soft); font-size: 11px; }
.chart-legend i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 2px; }
.progress-list { margin: 0; padding: 0; list-style: none; }
.progress-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; width: 100%; padding: 13px 0; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.progress-row strong { font-size: 14px; }.progress-row small { color: var(--ink-soft); }.progress-row .stacked-bar { grid-column: 1 / -1; height: 7px; }

.settings-group { margin-top: 24px; border: 1px solid var(--line); border-radius: var(--radius-card); overflow: hidden; background: var(--surface); }
.settings-group__title { margin: 0; padding: 12px 14px 8px; color: var(--gold-text); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.setting-row { display: grid; min-height: 58px; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.setting-row:first-of-type { border-top: 0; }
.setting-label strong, .setting-label small { display: block; }.setting-label strong { font-size: 14px; }.setting-label small { color: var(--ink-soft); font-size: 11px; }
.setting-row select, .select-control { min-width: 124px; max-width: 190px; height: 44px; padding: 0 34px 0 10px; border: 1px solid var(--control-line); border-radius: var(--radius-button); background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23877758' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 9px center; font-size: 13px; }
.setting-row input[type="range"] { width: min(44vw, 220px); accent-color: var(--gold); }
.theme-options { display: flex; gap: 4px; padding: 3px; border: 1px solid var(--control-line); border-radius: var(--radius-button); background: var(--paper); }
.theme-options button { min-height: 44px; padding: 5px 8px; border: 0; border-radius: 5px; background: transparent; font-size: 11px; }.theme-options button.is-active { background: var(--surface); color: var(--gold-text); }
.font-preview { padding: 18px; border-top: 1px solid var(--line); font-family: var(--font-quran); font-size: var(--quran-size); line-height: 1.8; text-align: right; direction: rtl; }
.download-progress { width: 100%; height: 6px; overflow: hidden; border-radius: 99px; background: var(--line); }.download-progress i { display: block; width: var(--download-progress, 0%); height: 100%; background: var(--green); }
.downloaded-list { margin: 0; padding: 0; list-style: none; }.downloaded-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }.downloaded-row small { display: block; color: var(--ink-soft); }

.settings-header { align-items: flex-start; }
.settings-header > .page-subtitle { max-width: 250px; margin: 2px 0 0; text-align: right; }
.settings-stack { padding-bottom: 24px; }
.settings-section { margin-top: 20px; }
.settings-section > .section-heading { align-items: flex-start; margin: 0; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.settings-section > .section-heading h2 { padding: 0; }
.settings-section > .section-heading p { max-width: 320px; margin: 0; color: var(--ink-soft); font-size: 11px; text-align: right; }
.settings-grid { display: grid; }
.settings-grid-two { grid-template-columns: minmax(0, 1fr); }
.settings-field { min-width: 0; }
.settings-label { font-size: 13px; font-weight: 650; }
.settings-hint { grid-column: 1 / -1; color: var(--ink-soft); font-size: 11px; }
.settings-label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-slider-field { display: block; padding: 14px; border-top: 0; }
.settings-slider-field input[type="range"] { width: 100%; margin: 12px 0; accent-color: var(--gold); }
.quran-preview { margin: 4px -14px -14px; }
.theme-picker { margin: 0; padding: 14px; border: 0; border-top: 1px solid var(--line); }
.theme-picker legend { float: left; margin-right: 16px; padding: 8px 0; }
.theme-picker::after { display: block; clear: both; content: ""; }
.segmented-control { float: right; }
.segmented-control label { position: relative; cursor: pointer; }
.segmented-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.segmented-control label span { display: grid; min-height: 44px; place-items: center; padding: 4px 9px; border-radius: 5px; color: var(--ink-soft); font-size: 11px; }
.segmented-control input:checked + span { background: var(--surface); color: var(--gold-text); }
.segmented-control input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }
.offline-pickers { border-bottom: 1px solid var(--line); }
.settings-download { width: calc(100% - 28px); margin: 14px; }
.offline-progress-panel { margin: 0 14px 14px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-button); background: var(--paper); }
.offline-progress-panel progress { width: 100%; height: 8px; margin-top: 9px; overflow: hidden; border: 0; border-radius: 99px; background: var(--line); accent-color: var(--green); }
.offline-progress-panel progress::-webkit-progress-bar { background: var(--line); }.offline-progress-panel progress::-webkit-progress-value { background: var(--green); }
.settings-status { min-height: 0; margin: 0 14px 12px; color: var(--ink-soft); font-size: 12px; }
.offline-library { padding: 0 14px 12px; border-top: 1px solid var(--line); }
.offline-library h3 { margin: 13px 0 7px; font-size: 13px; }
.offline-download-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.offline-download-row:first-child { border-top: 0; }
.offline-download-details strong, .offline-download-details small { display: block; }.offline-download-details small { color: var(--ink-soft); font-size: 11px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; }
.settings-about > p { margin: 0; padding: 14px; color: var(--ink-soft); font-size: 12px; }
.settings-about a { color: var(--gold-text); }

.empty-state { padding: 32px 20px; color: var(--ink-soft); text-align: center; }
.empty-state strong { display: block; margin-bottom: 4px; color: var(--ink); }
.loading-state { display: grid; min-height: 220px; place-content: center; justify-items: center; gap: 12px; color: var(--ink-soft); font-size: 13px; }
.spinner { width: 28px; height: 28px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }

.sheet-layer { position: fixed; z-index: 100; inset: 0; display: none; align-items: flex-end; justify-content: center; background: var(--scrim); }
.sheet-layer.is-open { display: flex; }
.bottom-sheet { width: min(100%, 640px); max-height: min(82dvh, 720px); overflow-y: auto; padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); border-radius: 16px 16px 0 0; background: var(--surface); }
.sheet-handle { width: 40px; height: 4px; margin: 2px auto 14px; border-radius: 99px; background: var(--line); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }.sheet-header h2 { margin: 0; font-size: 19px; }
.sheet-options { margin: 0; padding: 0; list-style: none; }.sheet-options button { display: grid; width: 100%; min-height: 54px; grid-template-columns: 1fr auto; align-items: center; padding: 8px 4px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }.sheet-options small { color: var(--ink-soft); }.sheet-options button[aria-checked="true"]::after { content: "✓"; color: var(--green); font-weight: 800; }

.info-sheet-list { margin: 0 0 16px; }
.info-sheet-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.info-sheet-item dt { margin-bottom: 4px; font-size: 14px; font-weight: 700; }
.info-sheet-item dd { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }

.week-strip { display: flex; gap: 6px; justify-content: space-between; margin-top: 12px; }
.week-day { display: grid; flex: 1; justify-items: center; gap: 4px; color: var(--ink-soft); font-size: 10px; }
.week-day i { width: 24px; height: 24px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); }
.week-day.is-active i { border-color: var(--green); background: var(--green); }
.week-day.is-today span { color: var(--ink); font-weight: 700; }

.toast-region { position: fixed; z-index: 110; right: 16px; bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px); left: 16px; display: grid; justify-items: center; pointer-events: none; }
.toast { max-width: 520px; padding: 11px 14px; border: 1px solid var(--line); border-radius: var(--radius-button); background: var(--ink); color: var(--paper); font-size: 13px; animation: toast-in 180ms var(--ease-out); }

dialog { width: min(calc(100% - 32px), 440px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); } dialog::backdrop { background: var(--scrim); }.dialog-body { padding: 20px; }.dialog-body h2 { margin: 0 0 8px; }.dialog-body p { color: var(--ink-soft); }.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }

@keyframes spin { to { transform: rotate(1turn); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: no-preference) {
  button, .ayah-chip, .rating-button, .bead { transition: transform 100ms ease, background-color 200ms ease, border-color 200ms ease, color 200ms ease, opacity 180ms ease; }
  button:active { transform: scale(.97); }
  .rating-button.is-pulsing { animation: pulse-rating 260ms var(--ease-out); }
  .view.is-entering { animation: view-in 180ms var(--ease-out); }
  .bottom-sheet { animation: sheet-in 200ms var(--ease-out); }
  .ayah-text { transition: background-color 250ms ease, color 180ms ease; }
  @keyframes pulse-rating { 50% { transform: scale(1.04); } }
  @keyframes view-in { from { opacity: 0; transform: translateY(8px); } }
  @keyframes sheet-in { from { transform: translateY(100%); } }
}

@media (prefers-reduced-motion: reduce) {
  .quran-pane { scroll-behavior: auto; }
  .spinner { animation: none; }
  .switch-track::after { transition: none; }
}

@media (min-width: 480px) {
  .repeat-panel { grid-template-columns: repeat(3, 1fr); }
  .repeat-control:last-child { grid-column: auto; }
}

@media (min-width: 700px) {
  body { background: color-mix(in srgb, var(--paper) 88%, var(--ink)); }
  .app-shell { box-shadow: 0 0 0 1px var(--line); }
}

@media (max-width: 370px) {
  .view-scroll { padding-inline: 12px; }
  .player-view .view-scroll { padding-inline: 0; }
  .page-header { margin-inline: -12px; padding-inline: 12px; }
  .ayah-grid { gap: 7px; }
  .rating-row { padding-inline: 10px; gap: 5px; }
  .transport-buttons { gap: 2px; }
}

/* Keep every player control on screen even on short phone viewports. */
@media (max-height: 720px) {
  .player-header { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; }
  .cartouche { padding-top: 6px; padding-bottom: 5px; }
  .cartouche h1 { font-size: 21px; }
  .player-mode-line { margin-top: 6px; }
  .rating-row { padding: 8px 16px; }
  .rating-button { min-height: 42px; }
  .repeat-control { padding: 6px 5px; }
  .transport { padding: 8px 12px 10px; }
  .bead-counter { margin-bottom: 4px; }
  .bead-strand { min-height: 16px; }
}

@media (max-width: 420px) {
  .settings-header { display: block; }
  .settings-header > .page-subtitle { max-width: none; margin-top: 6px; text-align: left; }
}

@media print {
  .bottom-nav, .mini-player, .selection-footer, .quran-toolbar, .transport, .rating-row, .repeat-panel { display: none !important; }
  body, .app-shell, .view, .view-scroll { position: static; height: auto; overflow: visible; background: white; color: black; }
}
