/* Quran Hifz — calm, warm, mobile-first. Logical properties throughout for RTL. */

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

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f6f0e2;
  --bg-2: #efe6d2;
  --surface: #fffbf2;
  --surface-2: #f8f1e1;
  --ink: #2a241c;
  --ink-2: #5e5446;
  --muted: #847865;
  --line: #e3d7bd;
  --line-2: #d6c7a6;
  --accent: #2f6b5c;          /* the one accent: deep sage green */
  --accent-ink: #fffbf2;
  --accent-soft: #dfeae3;
  --accent-line: #b8d0c4;
  --good: #2f8a63;
  --good-glow: rgba(47, 138, 99, .28);
  --amber: #b9791a;
  --amber-soft: #f6e5c2;
  --amber-ink: #fffaf0;
  --warn-soft: #f7e3d6;
  --hidden-ink: #8d7f68;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 6px 24px -8px rgba(60, 45, 20, .16);
  --shadow-up: 0 -10px 30px -12px rgba(60, 45, 20, .22);
  --focus: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent);

  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --ar-ui: "Noto Naskh Arabic", "Geeza Pro", "Segoe UI", "Arial", sans-serif;
  --quran: "UthmanicHafs", "KFGQPC HAFS Uthmanic Script", "Amiri Quran", serif;

  --qscale: 1;
  --q-size: calc(clamp(28px, 5vw, 44px) * var(--qscale));
  --radius: 18px;
  --radius-s: 12px;
  --gutter: 16px;
  --col: 760px;
  --kb: 0px;
  --dock-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #191612; --bg-2: #211d18; --surface: #221e19; --surface-2: #2a251f;
    --ink: #ede5d6; --ink-2: #c9bfad; --muted: #9a8f7d;
    --line: #36302a; --line-2: #463e35;
    --accent: #86c0aa; --accent-ink: #14211c; --accent-soft: #23352e; --accent-line: #34574b;
    --good: #6cc59a; --good-glow: rgba(108, 197, 154, .3);
    --amber: #e3a948; --amber-ink: #241a0c; --amber-soft: #3d2f18; --warn-soft: #3a261d; --hidden-ink: #a4977f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px -10px rgba(0,0,0,.6);
    --shadow-up: 0 -10px 30px -12px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #191612; --bg-2: #211d18; --surface: #221e19; --surface-2: #2a251f;
  --ink: #ede5d6; --ink-2: #c9bfad; --muted: #9a8f7d;
  --line: #36302a; --line-2: #463e35;
  --accent: #86c0aa; --accent-ink: #14211c; --accent-soft: #23352e; --accent-line: #34574b;
  --good: #6cc59a; --good-glow: rgba(108, 197, 154, .3);
  --amber: #e3a948; --amber-ink: #241a0c; --amber-soft: #3d2f18; --warn-soft: #3a261d; --hidden-ink: #a4977f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px -10px rgba(0,0,0,.6);
  --shadow-up: 0 -10px 30px -12px rgba(0,0,0,.6);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  background-image: radial-gradient(120% 60% at 50% -10%, var(--surface) 0%, transparent 60%);
  background-attachment: fixed;
  color: var(--ink);
  font: 400 17px/1.55 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; inset-inline-start: 8px; inset-block-start: -60px; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 10px; text-decoration: none; }
.skip:focus { inset-block-start: 8px; }
.ic { width: 24px; height: 24px; flex: none; }
.muted { color: var(--muted); }
.lead { font-size: 1.08rem; color: var(--ink-2); margin: .25rem 0 1rem; }
.eyebrow { margin: 0 0 .35rem; font-size: .78rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.h1, .h2, .hero { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; color: var(--ink); }
.h1 { font-size: 1.6rem; margin: 0 0 .3rem; line-height: 1.2; }
.h2 { font-size: 1.35rem; margin: 0 0 .5rem; line-height: 1.25; }
.hero { font-size: clamp(1.75rem, 6.2vw, 2.4rem); line-height: 1.15; margin: 1.6rem 0 1.2rem; text-wrap: balance; }

.hide-touch { display: inline; }
.show-touch { display: none; }
@media (hover: none), (pointer: coarse) { .hide-touch { display: none; } .show-touch { display: inline; } }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; inset-block-start: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-block-end: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  padding-block-start: env(safe-area-inset-top, 0px);
}
.topbar__in {
  max-width: var(--col); margin-inline: auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left, 0px)) max(var(--gutter), env(safe-area-inset-right, 0px));
  height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; background: none; border: 0; padding: 6px 8px 6px 0; min-height: 48px; border-radius: 12px; }
.brand__mark {
  width: 26px; height: 26px; flex: none; border-radius: 7px; background: var(--accent);
  transform: rotate(45deg) scale(.82);
  box-shadow: inset 0 0 0 5px color-mix(in srgb, var(--accent) 60%, var(--surface)), inset 0 0 0 7px var(--accent);
}
.brand__name { font-family: var(--serif); font-size: 1.2rem; letter-spacing: .005em; }
.topbar__tools { display: flex; gap: 4px; }
.iconbtn {
  min-width: 48px; height: 48px; padding: 0 10px; border-radius: 14px; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2);
}
.iconbtn:hover:not(:disabled) { background: var(--bg-2); color: var(--ink); }
.iconbtn:disabled { opacity: .38; }
.iconbtn--text { font-family: var(--serif); font-size: 1rem; font-weight: 600; }
.iconbtn--big { font-size: 1.22rem; }

.col {
  max-width: var(--col); margin-inline: auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left, 0px)) max(var(--gutter), env(safe-area-inset-right, 0px));
  padding-block: 8px calc(24px + var(--safe-b));
  outline: none;
}
body.has-dock .col { padding-block-end: calc(var(--dock-h) + var(--kb) + 32px); }
.screen { animation: rise .35s var(--ease) both; }
.screen--center { display: grid; place-items: center; min-height: 50vh; text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.boot { padding: 40px 0; color: var(--muted); }

/* ---------- Cards / buttons ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-block: 16px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 22px; border-radius: 16px; border: 1px solid transparent;
  font-weight: 600; font-size: 1.02rem; letter-spacing: .005em; text-decoration: none;
  background: var(--surface-2); color: var(--ink);
  transition: transform .12s var(--ease), background-color .2s, box-shadow .2s, opacity .2s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--accent) 80%, transparent); }
.btn--primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn--soft { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
:root[data-theme="dark"] .btn--soft { color: var(--accent); }
.btn--ghost { background: transparent; border-color: var(--line-2); color: var(--ink-2); }
.btn--ghost:hover { background: var(--bg-2); }
.btn--amber { background: var(--amber); color: var(--amber-ink); }
.btn--small { min-height: 48px; padding: 0 14px; font-size: .95rem; border-radius: 14px; }
.btn--icon { width: 56px; padding: 0; flex: none; }
.btn--block { width: 100%; }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.btnrow--end { justify-content: flex-end; }
.btnrow--fill > .btn:not(.btn--icon) { flex: 1; }
.btnrow--end .btn { flex: 1 1 140px; }
@media (min-width: 560px) { .btnrow--end .btn { flex: 0 0 auto; } }
.btnstack { display: grid; gap: 10px; margin-block: 20px 8px; }
.kbd { font-size: .75rem; font-weight: 600; border: 1px solid color-mix(in srgb, currentColor 40%, transparent); border-radius: 6px; padding: 0 6px; opacity: .75; }
.note { padding: 12px 14px; border-radius: 12px; background: var(--bg-2); color: var(--ink-2); font-size: .95rem; margin: 12px 0; }
.note--warn { background: var(--warn-soft); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.note--warn p { margin: 0; }
.note--soft { background: transparent; border: 1px dashed var(--line-2); }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ---------- Home ---------- */
.resume { border-color: var(--accent-line); background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--accent-soft) 45%, var(--surface))); }
.resume__title { font-family: var(--serif); font-size: 1.3rem; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.resume__stage { font-family: var(--ui); font-size: .92rem; color: var(--accent); font-weight: 600; }
.resume .btnrow .btn { flex: 1 1 160px; }

.modes { display: grid; gap: 12px; }
@media (min-width: 640px) { .modes { grid-template-columns: repeat(3, 1fr); } }
.mode {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; align-items: center;
  text-align: start; padding: 18px; min-height: 84px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: border-color .2s, background-color .2s, transform .12s var(--ease);
}
.mode:active { transform: scale(.985); }
.mode:hover { border-color: var(--line-2); }
.mode[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.mode__ic { grid-row: span 2; width: 34px; height: 34px; color: var(--accent); }
.mode__t { font-family: var(--serif); font-size: 1.22rem; line-height: 1.2; }
.mode__d { color: var(--muted); font-size: .9rem; }
@media (min-width: 640px) {
  .mode { grid-template-columns: 1fr; grid-template-rows: auto; row-gap: 4px; padding: 20px; }
  .mode__ic { grid-row: auto; margin-bottom: 6px; }
}

.panel { margin-block: 18px; scroll-margin-top: 76px; }
.search input, .field input, .field select, .select {
  width: 100%; min-height: 52px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-size: 1rem; appearance: none; -webkit-appearance: none;
}
.field select, .select {
  padding-inline-end: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
}
.search input:focus-visible, .field input:focus-visible, .field select:focus-visible, .select:focus-visible { border-color: var(--accent); }
.search { display: block; position: sticky; inset-block-start: 68px; z-index: 5; padding-block: 4px 10px; background: linear-gradient(var(--bg) 70%, transparent); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: start;
  min-height: 64px; padding: 10px 16px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, background-color .15s;
}
.row:hover:not(:disabled) { border-color: var(--accent-line); background: color-mix(in srgb, var(--accent-soft) 30%, var(--surface)); }
.row:disabled { opacity: .5; }
.row__num {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center; font-size: .85rem; font-weight: 600; color: var(--accent);
  border-radius: 11px; background: var(--accent-soft);
  font-variant-numeric: tabular-nums;
}
.row__main { display: grid; flex: 1; min-width: 0; }
.row__t { font-weight: 600; }
.row__s { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__ar { font-family: var(--quran); font-size: 1.55rem; line-height: 1; color: var(--ink-2); }
.row__count { color: var(--muted); font-size: .85rem; white-space: nowrap; }

.range { display: grid; gap: 14px; }
.range__row { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: flex; gap: 10px; }
.range__row legend { padding: 0 6px; font-size: .78rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.field { display: grid; gap: 4px; }
.field__l { font-size: .82rem; color: var(--muted); }
.field--grow { flex: 1; min-width: 0; }
.field--num { width: 96px; flex: none; }
.field--num input { text-align: center; font-variant-numeric: tabular-nums; }
.range__info { margin: 0; color: var(--ink-2); min-height: 1.5em; }
.range__info.is-error { color: var(--amber); }

/* ---------- Confirm ---------- */
.confirm { padding: 22px; }
.confirm__title { font-family: var(--serif); font-weight: 500; font-size: clamp(1.6rem, 6vw, 2.1rem); margin: 0; line-height: 1.15; }
.confirm__ar { font-family: var(--quran); font-size: 2rem; margin: .2rem 0 0; color: var(--ink-2); line-height: 1.6; }
.confirm__meta { color: var(--accent); font-weight: 600; margin: .4rem 0 0; }
.parts { margin-block: 18px 6px; }
.parts__lead { color: var(--ink-2); margin: 0 0 10px; }
.parts__grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.part {
  display: grid; text-align: start; gap: 1px; padding: 12px 14px; min-height: 56px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.part[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.part__t { font-weight: 600; }
.part__s { font-size: .9rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.part__c { font-size: .8rem; color: var(--muted); }

.settings { margin-block: 18px 4px; border-block: 1px solid var(--line); }
.disclosure {
  width: 100%; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; text-align: start;
  background: none; border: 0; padding: 12px 0; min-height: 56px;
}
.disclosure__chev { width: 20px; height: 20px; color: var(--muted); transition: transform .2s var(--ease); grid-row: span 2; }
.disclosure[aria-expanded="true"] .disclosure__chev { transform: rotate(90deg); }
.disclosure__t { font-weight: 600; }
.disclosure__s { grid-column: 2; color: var(--muted); font-size: .88rem; }
.settings__body { padding-block: 4px 16px; display: grid; gap: 14px; }
.setting { display: grid; gap: 6px; border: 0; }
.setting__l { font-size: .88rem; color: var(--ink-2); font-weight: 600; }
.setting__h { font-size: .84rem; color: var(--muted); margin-top: -2px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg__o { position: relative; flex: 1 1 auto; }
.seg__o input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg__o span {
  display: grid; place-items: center; min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--surface); font-size: .95rem; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.seg__o input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.seg__o input:focus-visible + span { box-shadow: var(--focus); }

/* ---------- Loader ---------- */
.loader { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.loader span { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); transform: rotate(45deg); animation: dot 1.2s ease-in-out infinite; }
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 100% { opacity: .25; transform: rotate(45deg) scale(.8); } 50% { opacity: 1; transform: rotate(45deg) scale(1.1); } }

/* ---------- Quran text ---------- */
.quran {
  font-family: var(--quran);
  font-size: var(--q-size);
  line-height: 2.2;
  text-align: right;  /* within dir=rtl this is the start edge */
  text-align: start;
  margin: 0;
  color: var(--ink);
  word-spacing: .05em;
  font-feature-settings: normal;
  overflow-wrap: break-word;
}
.w {
  /* --hit widens the tap box on touch; the equal negative margin keeps the
     visual spacing of the line unchanged (QA B2). */
  --hit: 0px;
  display: inline-block; border-radius: 10px; text-align: center;
  padding-inline: calc(.06em + var(--hit));
  margin-inline: calc(-1 * var(--hit));
  transition: background-color .2s, color .2s, box-shadow .3s, filter .35s;
}
.w + .w { margin-inline-start: calc(.18em - var(--hit)); }
@media (pointer: coarse) {
  .w { --hit: 9px; min-inline-size: 44px; }
  .w--end, .w--blank { --hit: 0px; min-inline-size: 0; }
}
.w--end { color: var(--accent); white-space: nowrap; }
.w--live { cursor: pointer; }
@media (hover: hover) { .w--live:hover { background: var(--accent-soft); } }
.w--live:focus-visible { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }
.w.is-tip { background: var(--accent-soft); }

/* Hidden words (placeholders) */
.w--hidden { position: relative; cursor: pointer; }
.w--blur > span { filter: blur(.19em); opacity: .75; user-select: none; -webkit-user-select: none; color: var(--hidden-ink); }
.w--blank {
  display: inline-block; vertical-align: middle;
  width: 3.4em; height: 1.35em; margin-block: .1em;
  border: 2px dotted var(--line-2); border-radius: .45em; background: var(--surface-2);
  line-height: 1;
}
.w--blank > span { display: none; }
.w--active.w--blur { background: color-mix(in srgb, var(--accent-soft) 85%, transparent); box-shadow: 0 0 0 2px var(--accent); }
.w--active.w--blank { border-color: var(--accent); border-style: solid; background: var(--accent-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.w--hinted::after {
  content: ""; position: absolute; inset-inline-end: -2px; inset-block-start: .25em; width: 8px; height: 8px; border-radius: 50%; background: var(--amber);
}
.w--solved { color: var(--good); animation: glow 1.4s var(--ease) both; }
.w--missed { color: var(--amber); }
/* Underline on the glyph span, not the word box, so the touch hit padding (--hit) never widens it. */
.w--missed > span { box-shadow: inset 0 -.12em 0 color-mix(in srgb, var(--amber) 45%, transparent); }
.w--revealed { animation: fadein .45s var(--ease) both; }
.w--markable { cursor: pointer; background: color-mix(in srgb, var(--accent-soft) 70%, transparent); box-shadow: inset 0 -2px 0 var(--accent-line); }
@media (hover: hover) { .w--markable:hover { background: var(--amber-soft); } }
.w--marked { background: var(--amber-soft); color: var(--amber); box-shadow: 0 0 0 2px color-mix(in srgb, var(--amber) 55%, transparent); }
.w--slot-next.w--blank { border-color: var(--accent); border-style: solid; }
.w--slot-next.w--blur { box-shadow: 0 0 0 2px var(--accent); }
.w--placed { animation: land .38s var(--ease) both; color: var(--good); }
.w--placed.is-settled { color: inherit; }
@keyframes glow {
  0% { filter: blur(6px); opacity: .3; text-shadow: none; }
  40% { filter: none; opacity: 1; text-shadow: 0 0 18px var(--good-glow); background: color-mix(in srgb, var(--good) 14%, transparent); }
  100% { text-shadow: none; background: transparent; }
}
@keyframes fadein { from { opacity: 0; filter: blur(4px); } to { opacity: 1; filter: none; } }
@keyframes land { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.trans {
  font-family: var(--serif); color: var(--ink-2); font-size: calc(1.02rem * (0.85 + 0.15 * var(--qscale)));
  line-height: 1.6; margin: .35rem 0 0; text-align: start;
}
.trans--cue {
  background: var(--surface-2); border-inline-start: 3px solid var(--accent-line); padding: 10px 14px; border-radius: 0 12px 12px 0;
  margin-block: .25rem .5rem; font-size: 1rem;
}
.trans--moment { animation: fadein .5s var(--ease) both; border-inline-start: 3px solid var(--good); padding-inline-start: 12px; }
.cue__lbl { font-family: var(--ui); font-size: .72rem; letter-spacing: .09em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin-inline-end: 6px; }

/* ---------- READ ---------- */
.readhead { padding-block: 14px 6px; }
.readhead__tip { margin: .2rem 0 .6rem; font-size: .95rem; }
.readhead__tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 48px; cursor: pointer; font-weight: 500; color: var(--ink-2); position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__ui { width: 44px; height: 26px; border-radius: 99px; background: var(--line-2); position: relative; transition: background-color .2s; flex: none; }
.switch__ui::after { content: ""; position: absolute; inset-block-start: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s var(--ease); }
.switch input:checked + .switch__ui { background: var(--accent); }
.switch input:checked + .switch__ui::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__ui { box-shadow: var(--focus); }

.ayahs { display: grid; }
.ayahs > *, .focus > * { min-width: 0; }
.ayah {
  position: relative; padding: 14px 4px 12px; border-block-end: 1px solid var(--line);
  scroll-margin-top: 80px; scroll-margin-bottom: calc(var(--dock-h) + 20px);
  transition: background-color .3s;
}
.ayah:last-child { border-block-end: 0; }
.ayah.is-playing { background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent-soft) 70%, transparent) 12%, color-mix(in srgb, var(--accent-soft) 70%, transparent) 88%, transparent); }
.ayah__meta { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.ayah__key { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.ayah__key--corner { position: absolute; inset-inline-start: 4px; inset-block-start: 8px; }
.playbtn {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--surface);
  display: grid; place-items: center; color: var(--accent);
}
.playbtn .ic { width: 20px; height: 20px; }
.playbtn:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.playbtn--accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.surahhead {
  text-align: center; margin: 10px 0 4px; font-family: var(--serif); font-size: 1.15rem; color: var(--accent);
  display: flex; align-items: center; gap: 12px;
}
.surahhead::before, .surahhead::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.readfoot { margin-block: 18px 6px; }
.readfoot__in { display: grid; gap: 10px; text-align: center; }
.readfoot__in p { margin: 0; }

/* ---------- Stage ---------- */
.stagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-block: 14px 6px; }
.stagehead__t { font-family: var(--serif); font-weight: 500; font-size: clamp(1.25rem, 5vw, 1.5rem); margin: 6px 0 0; line-height: 1.2; }
.stagehead__s { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }
.stagehead .btn .ic { width: 20px; height: 20px; }
.steps { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.steps__s { width: 26px; height: 6px; border-radius: 6px; background: var(--line-2); transition: background-color .3s, width .3s var(--ease); }
.steps__s.is-done { background: var(--accent-line); }
.steps__s.is-skipped { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-2); background-image: repeating-linear-gradient(90deg, var(--line-2) 0 3px, transparent 3px 6px); background-size: 100% 1.5px; background-repeat: no-repeat; background-position: center; }
.steps__s.is-on { background: var(--accent); width: 40px; }
.ayahs--test .ayah { padding-block-start: 26px; }

.focus { display: grid; gap: 6px; }
.ctx { opacity: .55; padding: 4px 4px; }
.quran--ctx { font-size: calc(var(--q-size) * .72); line-height: 2; }
.ayah--target {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; box-shadow: var(--shadow);
}
.target__label { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 4px; font-size: .88rem; font-weight: 600; color: var(--ink-2); }
.quran--target { min-height: 2.2em; }
.cue { border-radius: var(--radius); padding: 12px 14px; background: color-mix(in srgb, var(--accent-soft) 45%, transparent); border: 1px solid var(--accent-line); transition: box-shadow .3s; }
.cue.is-playing { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.cue__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cue__head .eyebrow { margin: 0; }
.quran--cue { font-size: calc(var(--q-size) * .85); }
.cue__surah { text-align: center; padding: 6px 0 4px; }
.cue__name { font-family: var(--serif); font-size: 1.3rem; margin: 0; }
.cue__ar { font-family: var(--quran); font-size: 2.2rem; margin: 0; line-height: 1.7; color: var(--accent); }
.cue__surah .muted { margin: 0; font-size: .92rem; }

.is-shake { animation: shake .42s var(--ease); }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }

.roundend { text-align: center; padding: 26px 22px; margin-top: 22px; }
.roundend__badge { width: 62px; height: 62px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-2); color: var(--muted); }
.roundend__badge.is-pass { background: var(--accent); color: var(--accent-ink); animation: pop .5s var(--ease) both; }
.roundend__badge .ic { width: 30px; height: 30px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Dock (bottom-pinned) ---------- */
.dock {
  position: fixed; inset-inline: 0; inset-block-end: var(--kb); z-index: 30;
  padding-block-end: max(10px, var(--safe-b));
  pointer-events: none;
}
/* Soft fade so text scrolling under the dock recedes instead of clashing with it. */
.dock::before {
  content: ""; position: absolute; inset-inline: 0; inset-block: -18px 0; z-index: -1;
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
}
.dock__in {
  max-width: var(--col); margin-inline: auto; padding-inline: max(var(--gutter), env(safe-area-inset-left, 0px)) max(var(--gutter), env(safe-area-inset-right, 0px));
  display: grid; gap: 8px; pointer-events: none;
}
.dock__in > * { pointer-events: auto; min-width: 0; }

.player {
  display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--line); box-shadow: var(--shadow-up), var(--shadow);
}
.pbtn {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: transparent; color: var(--ink-2);
  display: grid; place-items: center; flex: none; position: relative;
}
.pbtn:hover { background: var(--bg-2); }
.pbtn .ic { width: 22px; height: 22px; }
.pbtn--main { width: 56px; height: 56px; background: var(--accent); color: var(--accent-ink); }
.pbtn--main:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.pbtn--main .ic { width: 26px; height: 26px; }
.pbtn--toggle[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.pbtn__badge { position: absolute; inset-block-end: 5px; inset-inline-end: 4px; font-size: .62rem; font-weight: 700; line-height: 1; padding: 2px 3px; border-radius: 5px; background: var(--accent); color: var(--accent-ink); }
.pbtn--select { overflow: hidden; }
.pbtn--select select { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; font-size: 16px; }
.pbtn--select:focus-within { box-shadow: var(--focus); }
.player__now { flex: 1; min-width: 0; display: grid; padding-inline: 6px; line-height: 1.2; }
.player__key { font-weight: 600; font-variant-numeric: tabular-nums; font-size: .95rem; }
.player__rec { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.answer {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 22px; padding: 12px; box-shadow: var(--shadow-up), var(--shadow);
}
.typebox__row { display: flex; gap: 8px; align-items: center; }
.typebox__in {
  flex: 1; min-width: 0; min-height: 56px; padding: 0 16px; border-radius: 16px;
  border: 1.5px solid var(--line-2); background: var(--bg); color: var(--ink);
  font-family: var(--ar-ui); font-size: 1.35rem; text-align: right;
}
.typebox__in:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.typebox__in::placeholder { color: var(--muted); opacity: .7; font-size: 1.05rem; }
.typebox__row--fb { justify-content: space-between; }
.typebox__yours { margin: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; min-width: 0; }
.typed { font-family: var(--ar-ui); font-size: 1.2rem; text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--amber) 70%, transparent); color: var(--ink-2); }

.tray-wrap { display: grid; gap: 8px; }
.tray__lbl { margin: 0 4px; font-size: .85rem; color: var(--muted); }
.tray {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start;
  max-height: 34vh; overflow-y: auto; padding: 2px; overscroll-behavior: contain;
  background: repeating-linear-gradient(45deg, transparent 0 10px, color-mix(in srgb, var(--line) 25%, transparent) 10px 11px);
  border-radius: 14px;
}
.tile {
  font-family: var(--quran); font-size: calc(clamp(22px, 4.6vw, 30px) * var(--qscale)); line-height: 1.6;
  min-height: 52px; min-width: 52px; padding: 0 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line-2); border-block-end-width: 3px; color: var(--ink);
  transition: transform .12s var(--ease), border-color .15s;
}
.tile:hover { border-color: var(--accent-line); }
.tile:active { transform: translateY(1px) scale(.98); }
.tile.is-wrong { animation: shake .42s var(--ease); border-color: var(--amber); }

.selfcheck { display: grid; gap: 8px; }
.selfcheck__lead { margin: 0 4px 8px; font-size: .95rem; color: var(--ink-2); }
.reveal { position: relative; overflow: hidden; }
.reveal.is-waiting::after {
  content: ""; position: absolute; inset-block-end: 0; inset-inline-start: 0; height: 3px; background: currentColor; opacity: .5;
  animation: wait var(--wait, 2s) linear both;
}
@keyframes wait { from { width: 0; } to { width: 100%; } }

.moment {
  display: flex; align-items: center; gap: 12px; padding: 4px 12px; margin-block-end: 10px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  animation: rise .3s var(--ease) both; min-height: 48px;
}
.moment--good { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.moment--miss { border-color: color-mix(in srgb, var(--amber) 55%, var(--line)); background: color-mix(in srgb, var(--amber-soft) 55%, var(--surface)); }
.moment__ar { font-family: var(--quran); font-size: 1.55rem; line-height: 1.6; flex: none; }
.moment--good .moment__ar { color: var(--good); }
.moment--miss .moment__ar { color: var(--amber); }
.moment__t { display: grid; min-width: 0; font-family: var(--serif); font-size: .98rem; line-height: 1.3; }
.moment__txt { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.moment__lbl { font-family: var(--ui); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }

/* ---------- Tooltip ---------- */
.tip {
  position: fixed; z-index: 40; inset-inline-start: 0; inset-block-start: 0;
  transform: translate(var(--x), var(--y));
  width: max-content; max-width: min(300px, calc(100vw - 24px));
  display: grid; grid-template-columns: 1fr auto; column-gap: 10px; align-items: center;
  padding: 10px 10px 10px 14px; border-radius: 16px;
  background: var(--ink); color: var(--bg); box-shadow: 0 12px 34px -10px rgba(0,0,0,.45);
  animation: tipin .16s var(--ease) both;
}
html[dir="rtl"] .tip { inset-inline-start: auto; }
.tip::after {
  content: ""; position: absolute; inset-block-end: -6px; left: var(--ax); width: 12px; height: 12px; margin-left: -6px;
  background: var(--ink); transform: rotate(45deg); border-radius: 2px;
}
.tip--below::after { inset-block-end: auto; inset-block-start: -6px; }
.tip__ar { grid-column: 1; font-family: var(--quran); font-size: 1.5rem; line-height: 1.5; text-align: start; direction: rtl; }
.tip__m { grid-column: 1; font-family: var(--serif); font-size: 1.05rem; line-height: 1.3; }
.tip__tr { grid-column: 1; font-size: .85rem; font-style: italic; opacity: .72; }
.tip__play {
  grid-column: 2; grid-row: 1 / span 3; width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: color-mix(in srgb, var(--bg) 16%, transparent); color: var(--bg); display: grid; place-items: center;
}
.tip__play:hover { background: color-mix(in srgb, var(--bg) 26%, transparent); }
.tip__play .ic { width: 22px; height: 22px; }
@keyframes tipin { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Done ---------- */
.done { text-align: center; padding-block: 26px 8px; }
.done__orn {
  width: 72px; height: 72px; margin: 4px auto 14px; border-radius: 16px; rotate: 45deg;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  box-shadow: inset 0 0 0 10px var(--surface), inset 0 0 0 11px var(--accent-line);
  animation: pop .6s var(--ease) both;
}
.hero--done { margin: .2rem 0 .2rem; }
.done .lead { margin-bottom: .2rem; }
.review { margin-top: 20px; }
.ayah--review { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 4px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
}
.chip__ar { font-family: var(--quran); font-size: 1.5rem; line-height: 1.5; }
.chip__m { font-family: var(--serif); color: var(--ink-2); font-size: .95rem; }

/* ---------- Footer ---------- */
.foot { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; text-align: center; }
.foot p { margin: 2px 0; }

/* ---------- Desktop refinements ---------- */
@media (min-width: 900px) {
  body { font-size: 17.5px; }
  .card { padding: 26px 28px; }
  .ayah { padding-inline: 10px; }
  .answer { padding: 14px; }
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .w--solved { animation: none; }
}

/* Forced colours */
@media (forced-colors: active) {
  .w--blank { border-color: CanvasText; }
  .seg__o input:checked + span { outline: 2px solid Highlight; }
}

/* Small inline actions */
.hintbtn { justify-self: start; }
.hintbtn .ic, .linkbtn .ic { width: 18px; height: 18px; }
.linkbtn {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 12px; margin-inline-end: 8px;
  border-radius: 10px; border: 1px solid var(--accent-line); background: var(--accent-soft); color: var(--accent); font-size: .85rem; font-weight: 600;
}
.linkbtn:disabled { opacity: .45; }
.tray__lbl { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.tray__hint { flex: 1; min-width: 0; }
.linkbtn--end { margin-inline: auto 0; }

/* Stage 1 Self check, ayah by ayah: the ayah being recited is lifted, later ones rest. */
.ayahs--test .ayah.is-current { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); border-radius: 14px; border-block-end-color: transparent; }
.ayahs--test .ayah.is-later { opacity: .55; }

/* Touch: the hit box is wider than the word (--hit). Keep fills and rings at the
   word's visual size so they don't run into the neighbouring words. */
@media (pointer: coarse) {
  .w.w--active, .w.w--marked, .w.w--slot-next, .w.w--live:focus-visible { background: none; }
  .w.is-tip { background: none; color: var(--accent); }
  .w.w--markable:not(.w--marked) { background: none; box-shadow: none; text-decoration: underline dotted var(--accent-line); text-underline-offset: .35em; }
  .w--active.w--blur, .w--slot-next.w--blur, .w--marked, .w--live:focus-visible {
    box-shadow: none;
    outline: 2px solid var(--accent); outline-offset: calc(-1 * var(--hit));
  }
  .w--marked { outline-color: color-mix(in srgb, var(--amber) 60%, transparent); }
}
