/* ============================================================
   Mufradaat Al Quran — design tokens
   ============================================================ */
:root {
  --bg:        #f5f1e8; --bg-tint:   #ebe4d5; --surface:   #fffdf8; --surface-2: #f8f4eb;
  --line:      #d9cfbc; --ink:       #17231e; --ink-2:     #5f6d62; --ink-3:     #8b9489;
  --brand:     #0d5b45; --brand-2:   #073a2d; --brand-soft:#dce9df; --gold:      #b28a3b;
  --gold-soft: #f2e7c9; --good:      #157F52; --good-soft: #DFF3E8; --bad:       #B4342C;
  --bad-soft:  #FBE6E3; --shadow:    0 16px 40px -26px rgba(33, 40, 31, .42);
  --shadow-lg: 0 28px 70px -34px rgba(24, 41, 31, .48); --r-sm: 10px; --r: 18px; --r-lg: 26px;
  --r-xl: 34px; --maxw: 1080px; --btn-fg: #fff;
  --ui: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ar: "Scheherazade New", "Amiri Quran", "SF Arabic", "Geeza Pro", serif;
}
:root[data-theme="dark"] {
  --bg:        #0b1210; --bg-tint:   #14201a; --surface:   #111c17; --surface-2: #17251e;
  --line:      #2b4034; --ink:       #f0eadb; --ink-2:     #a7b5aa; --ink-3:     #76897b;
  --brand:     #4eaa80; --brand-2:   #2b7658; --brand-soft:#17392b; --gold:      #d6ae5b;
  --gold-soft: #382d17; --good:      #43C48A; --good-soft: #123326; --bad:       #F08A80;
  --bad-soft:  #351916; --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  --shadow-lg: 0 2px 4px rgba(0,0,0,.4), 0 24px 48px -20px rgba(0,0,0,.7);
  --btn-fg: #06201A;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); font-family: var(--ui); font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column; min-height: 100vh;
  background: radial-gradient(circle at 50% -10%, rgba(178,138,59,.12), transparent 34rem), var(--bg);
}
h1,h2,h3,h4 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.02em; font-weight: 700; }
h1 { font-size: clamp(1.9rem, 1.2rem + 2.6vw, 3rem); font-weight: 800; }
h2 { font-size: clamp(1.3rem, 1.05rem + 1vw, 1.75rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
a {
  color: var(--brand); text-decoration-color: color-mix(in srgb, var(--brand) 35%, transparent);
  text-underline-offset: 3px;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--ink-2); }
.tiny { font-size: .8rem; }
.skip { position: absolute; left: -9999px; }
.skip:focus {
  left: 12px; top: 12px; background: var(--surface); padding: 10px 16px; border-radius: var(--r-sm);
  z-index: 99;
}
:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ============================================================ topbar */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, calc((100vw - var(--maxw)) / 2));
  backdrop-filter: saturate(1.6) blur(12px); background: rgba(11, 25, 19, .96);
  border-bottom: 1px solid rgba(214,174,91,.28); color: #f8f2e5;
}
.brand {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit;
  margin-right: auto;
}
.brand-mark {
  /* The mark is a transparent PNG, so it sits directly on the header and needs
     no plate of its own — nothing to keep in sync with the bar's colour. */
  width: 46px; height: 46px; flex: none; display: block; object-fit: contain;
}
.brand-text { display: flex; flex-direction: column; }
.brand-text b { font-size: .98rem; letter-spacing: -.01em; line-height: 1.2; }
.brand-ar { display: block; width: 152px; height: auto; margin-top: 1px; }
.topnav { display: flex; gap: 2px; }
.topnav a {
  padding: 7px 13px; border-radius: 999px; text-decoration: none; color: var(--ink-2);
  font-size: .9rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
}
.topnav a:hover { background: rgba(255,255,255,.09); color: #fff; }
.topnav a[aria-current="page"] { background: rgba(214,174,91,.18); color: #f1cc79; }
.pill {
  background: var(--gold); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: .7rem;
  font-weight: 700;
}
:root[data-theme="dark"] .pill { color: #1a1405; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; flex: none;
  border: 1px solid var(--line); border-radius: 11px; cursor: pointer; transition: .18s;
  background: rgba(255,255,255,.08); color: #f1cc79; border-color: rgba(214,174,91,.3);
}
.icon-btn:hover { color: var(--brand); border-color: var(--brand); }

/* ============================================================ layout */
main { flex: 1; padding: 28px max(16px, calc((100vw - var(--maxw)) / 2)) 72px; padding-top: 42px; }
.foot {
  padding: 28px max(16px, calc((100vw - var(--maxw)) / 2)) 40px; border-top: 1px solid var(--line);
  font-size: .82rem; background: #0b2018; color: #afc5b3; border-top-color: rgba(214,174,91,.3);
}
.foot p { margin: 0 0 .5em; max-width: 74ch; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between {
  display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.stack { display: grid; gap: 14px; }
.grid { display: grid; gap: 16px; }
.crumb {
  display: flex; gap: 8px; align-items: center; font-size: .85rem; color: var(--ink-2);
  margin-bottom: 14px;
}
.crumb a { text-decoration: none; font-weight: 600; }
.crumb span { opacity: .5; }

/* ============================================================ hero */
.hero {
  position: relative; overflow: hidden; border-radius: var(--r-xl); color: #EAF6F2;
  margin-bottom: 34px; box-shadow: var(--shadow-lg); isolation: isolate;
  border: 1px solid rgba(214,174,91,.4);
  background: radial-gradient(circle at 84% 12%, rgba(214,174,91,.28), transparent 20%), linear-gradient(135deg, #071f17, #0d5b45 62%, #104b39);
  padding: clamp(34px, 6vw, 72px);
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23ffffff' stroke-width='1.1'%3E%3Cpath d='M40 0 80 40 40 80 0 40Z'/%3E%3Cpath d='M40 14 66 40 40 66 14 40Z'/%3E%3Cpath d='M0 0h80v80H0z'/%3E%3C/g%3E%3C/svg%3E");
  opacity: .22;
}
.hero > * { position: relative; z-index: 1; }
.hero h1 {
  color: #fff; font-family: var(--ar); font-weight: 600;
  font-size: clamp(2.5rem, 1.7rem + 3vw, 4.35rem); letter-spacing: 0; line-height: 1.15;
  max-width: 12ch;
}
.hero p { font-size: 1rem; max-width: 48ch; color: #d4e5d7; }
.hero-ar {
  position: absolute; top: clamp(22px, 4vw, 48px); right: clamp(22px, 5vw, 58px);
  font-family: var(--ar); direction: rtl; opacity: .96; font-size: clamp(2rem, 1rem + 3vw, 3.4rem);
  color: #e5bf6b;
}
.hero-actions { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: 26px; }
.btn.hero-primary {
  box-shadow: 0 8px 20px rgba(0,0,0,.14); background: #e1bd68; color: #12291f; border-radius: 10px;
  padding-inline: 22px;
}
.btn.hero-primary:hover { background: #f0d389; color: #12291f; }
.hero-link { color: #F4E5BE; font-weight: 700; text-underline-offset: 5px; }
.hero-stats {
  display: flex; gap: 28px; flex-wrap: wrap; padding-top: 22px;
  border-top: 1px solid rgba(255,255,255,.18); margin-top: 38px;
}
.hero-stats div b {
  display: block; color: #e6c576; font-family: var(--ar); font-size: 2rem; font-weight: 600;
}
.hero-stats div span {
  font-size: .8rem; color: #B9DDD4; text-transform: uppercase; letter-spacing: .07em;
}

/* ============================================================ cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 22px; box-shadow: var(--shadow); border-color: rgba(177,155,111,.45);
}
.card-link {
  text-decoration: none; color: inherit; display: block;
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.card-link:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
}
.surah-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.surah-card {
  display: grid; gap: 14px; position: relative; overflow: hidden; padding: 26px;
  background: linear-gradient(145deg, var(--surface), color-mix(in srgb, var(--gold-soft) 28%, var(--surface)));
}
.surah-card .top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  min-height: 102px;
}
.surah-num {
  flex: none; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem;
  border: 1px solid color-mix(in srgb, var(--gold) 25%, transparent);
  border-color: rgba(178,138,59,.5); width: 50px; height: 50px; border-radius: 50%;
  background: var(--brand); color: var(--gold-soft);
  box-shadow: inset 0 0 0 5px color-mix(in srgb, var(--gold) 20%, transparent);
}
.surah-card h3 { margin: 0; font-size: 1.18rem; margin-top: 2px; }
.ar-name {
  font-family: var(--ar); font-size: 1.7rem; direction: rtl; color: var(--brand); line-height: 1.6;
}
.meta { display: flex; gap: 8px; flex-wrap: wrap; }
.tag {
  font-size: .72rem; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-tint); color: var(--ink-2); border: 1px solid var(--line);
}
.tag.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.tag.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; }

/* ============================================================ progress */
.bar { height: 8px; border-radius: 999px; background: var(--bg-tint); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--gold));
  transition: width .5s cubic-bezier(.2,.8,.2,1);
}
.ring {
  --p: 0; width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid;
  place-items: center;
  background: conic-gradient(var(--brand) calc(var(--p) * 1%), var(--bg-tint) 0); font-size: .72rem;
  font-weight: 700; color: var(--ink-2);
}
.ring::before {
  content: ""; position: absolute; width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface);
}
.ring > span { position: relative; }
.ring-wrap { position: relative; display: grid; place-items: center; }

/* ============================================================ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px;
  border: 1px solid transparent; font-weight: 700; font-size: .93rem; cursor: pointer;
  text-decoration: none; background: var(--brand); color: var(--btn-fg); transition: .18s;
  white-space: nowrap; border-radius: 10px;
}
.btn:hover { background: var(--brand-2); transform: translateY(-1px); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg-tint); border-color: var(--brand); color: var(--brand); }
.btn.gold { background: var(--gold); color: #22190a; }
.btn.sm { padding: 7px 14px; font-size: .82rem; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ============================================================ surah overview */
.surah-hero {
  display: flex; justify-content: space-between; gap: 28px; align-items: center;
  padding: clamp(24px, 4vw, 42px); margin-bottom: 14px; border-radius: var(--r-xl);
  background: linear-gradient(135deg, var(--surface) 0%, var(--gold-soft) 100%);
  border: 1px solid color-mix(in srgb, var(--gold) 22%, var(--line)); box-shadow: var(--shadow);
}
.surah-hero-copy { min-width: 0; }
.surah-hero .eyebrow { color: var(--gold); }
.surah-hero .ar-name {
  font-size: clamp(2rem, 1.2rem + 3vw, 3.5rem); color: var(--brand-2); line-height: 1.5;
}
.surah-hero h1 { margin: 0 0 8px; }
.surah-subtitle { color: var(--ink-2); margin: 0; }
.surah-facts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.surah-facts span {
  padding: 6px 11px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 72%, transparent); color: var(--ink-2);
  font-size: .78rem; font-weight: 600;
}
.surah-progress {
  display: grid; justify-items: center; gap: 8px; flex: none; color: var(--ink-2);
  font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
}
.surah-progress .ring { width: 82px; height: 82px; font-size: .9rem; }
.surah-progress .ring::before { width: 66px; height: 66px; }
.surah-progress-line { margin: 0 2px 28px; }
.surah-progress-line .between { margin-top: 7px; }
.surah-tabs { margin-bottom: 18px; }

/* ============================================================ section list */
.sec-list { display: grid; gap: 10px; }
.sec {
  display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center;
  padding: 14px 18px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); text-decoration: none; color: inherit; transition: .18s;
}
.sec:hover { border-color: var(--brand); transform: translateX(3px); }
.sec .idx {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px;
  background: var(--bg-tint); font-weight: 700; font-size: .9rem; color: var(--ink-2);
}
.sec.done .idx { background: var(--good-soft); color: var(--good); }
.sec b { display: block; font-size: .98rem; }
.sec .sub { font-size: .8rem; color: var(--ink-2); }
.tabs {
  display: flex; gap: 6px; margin-bottom: 20px; width: fit-content; padding: 6px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
}
.tabs button, .tabs a {
  padding: 8px 18px; border: 0; background: transparent; font-weight: 600; font-size: .88rem;
  cursor: pointer; color: var(--ink-2); text-decoration: none; border-radius: 9px;
}
.tabs [aria-selected="true"] {
  background: var(--surface); color: var(--brand); box-shadow: var(--shadow);
}

/* ============================================================ study cards */
.study-deck { display: grid; gap: 18px; justify-items: center; }
.flip {
  width: min(520px, 100%); height: 300px; perspective: 1400px; cursor: pointer; background: none;
  border: 0; padding: 0;
}
.flip-in {
  position: relative; width: 100%; height: 100%;
  transition: transform .55s cubic-bezier(.3,.8,.3,1); transform-style: preserve-3d;
}
.flip[aria-pressed="true"] .flip-in { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--r-lg);
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-content: center; gap: 10px; text-align: center; padding: 28px;
}
.face.back { transform: rotateY(180deg); background: var(--brand-soft); border-color: transparent; }
.face .ar {
  font-family: var(--ar); font-size: clamp(2.4rem, 1.5rem + 4vw, 3.6rem); direction: rtl;
  line-height: 1.9; color: var(--ink);
}
.face .tl { color: var(--ink-2); font-style: italic; }
.face .en { font-size: 1.5rem; font-weight: 700; color: var(--brand-2); }
:root[data-theme="dark"] .face .en { color: var(--brand-2); }

/* ============================================================ quiz */
.q-shell { max-width: 720px; margin: 0 auto; }
.q-head { display: grid; gap: 10px; margin-bottom: 22px; }
.q-meter { display: flex; align-items: center; gap: 12px; }
.q-meter .bar { flex: 1; }
.streak {
  display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: .85rem;
  color: var(--gold);
}
.q-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: clamp(20px, 4vw, 34px); box-shadow: var(--shadow);
}
.q-kind {
  font-size: .74rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 14px;
}
.q-prompt { text-align: center; margin-bottom: 26px; }
.q-prompt .ar {
  font-family: var(--ar); font-size: clamp(2.2rem, 1.4rem + 3.6vw, 3.4rem); direction: rtl;
  line-height: 2;
}
.q-prompt .en { font-size: clamp(1.3rem, 1.1rem + 1vw, 1.8rem); font-weight: 700; }
.q-prompt .hint { color: var(--ink-2); font-size: .9rem; margin-top: 6px; }
.opts { display: grid; gap: 10px; }
.opts.two { grid-template-columns: 1fr 1fr; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  border: 1.5px solid var(--line); cursor: pointer; transition: .15s; font-weight: 600;
  border-radius: 14px; padding: 17px 20px; background: var(--surface);
  border-color: rgba(177,155,111,.65);
}
.opt:hover:not(:disabled) {
  transform: translateY(-2px); border-color: var(--gold); background: var(--gold-soft);
  box-shadow: var(--shadow);
}
.opt .key {
  width: 26px; height: 26px; flex: none; display: grid; place-items: center; font-size: .75rem;
  font-weight: 700; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
}
.opt .ar { font-family: var(--ar); font-size: 1.9rem; direction: rtl; line-height: 1.9; }
.opt.correct { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.opt.wrong {
  border-color: var(--bad); background: var(--bad-soft); color: var(--bad); animation: shake .4s;
}
.opt:disabled { cursor: default; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-7px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(3px)} }
.feedback {
  margin-top: 18px; padding: 15px 18px; border-radius: var(--r); display: none; gap: 12px;
  align-items: flex-start;
}
.feedback.show { display: flex; animation: rise .28s ease-out; }
.feedback.ok { background: var(--good-soft); color: var(--good); }
.feedback.no { background: var(--bad-soft); color: var(--bad); }
.feedback b { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.cloze {
  font-family: var(--ar); direction: rtl; font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2.2rem);
  line-height: 2.4; text-align: center;
}
.cloze .blank {
  display: inline-block; min-width: 3.2em; border-bottom: 3px dashed var(--gold);
  color: transparent;
}
.cloze .blank.filled { color: var(--good); border-bottom-color: var(--good); }
.ayah-en {
  font-size: .92rem; color: var(--ink-2); font-style: italic; max-width: 60ch; margin: 14px auto 0;
  text-align: center;
}
.speaker {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 14px 26px; display: inline-flex; gap: 10px; align-items: center; cursor: pointer;
  font-weight: 700; color: var(--brand);
}
.speaker:hover { background: var(--brand-soft); }

/* ============================================================ match game */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.match-col { display: grid; gap: 10px; align-content: start; }
.tile {
  padding: 14px 16px; border-radius: var(--r); border: 1.5px solid var(--line);
  background: var(--surface); cursor: pointer; transition: .15s; text-align: center;
  font-weight: 600; min-height: 62px; display: grid; place-content: center;
}
.tile:hover:not(:disabled) { border-color: var(--brand); }
.tile.ar { font-family: var(--ar); font-size: 1.8rem; direction: rtl; line-height: 1.8; }
.tile.sel {
  border-color: var(--gold); background: var(--gold-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 22%, transparent);
}
.tile.hit {
  border-color: var(--good); background: var(--good-soft); color: var(--good); animation: pop .3s;
}
.tile.miss { border-color: var(--bad); background: var(--bad-soft); animation: shake .4s; }
.tile.gone { opacity: 0; pointer-events: none; transition: opacity .35s; }
@keyframes pop { 50% { transform: scale(1.05); } }

/* ============================================================ memory game */
.mem-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.mem {
  aspect-ratio: 1/1.05; perspective: 900px; background: none; border: 0; padding: 0;
  cursor: pointer;
}
.mem-in {
  position: relative; width: 100%; height: 100%; transition: transform .45s;
  transform-style: preserve-3d;
}
.mem[aria-pressed="true"] .mem-in, .mem.matched .mem-in { transform: rotateY(180deg); }
.mem-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--r); display: grid;
  place-content: center; padding: 8px; text-align: center; border: 1.5px solid var(--line);
}
.mem-front {
  /* The monogram itself as the card back, rather than a bare م. Decorative, so
     it rides on the background rather than sitting in the DOM. */
  /* Fixed dark ground rather than var(--brand), which the dark palette flips to
     a light green — the gold mark fell to 1.21:1 against it. The monogram is
     drawn for a dark field, the same one it sits on in the header. */
  background: url('logo.png') center / 46% no-repeat,
              linear-gradient(145deg, #0d5b45, #073a2d);
  border-color: transparent;
}
.mem-back {
  transform: rotateY(180deg); background: var(--surface); font-weight: 600; font-size: .85rem;
}
.mem-back.ar { font-family: var(--ar); font-size: 1.5rem; direction: rtl; font-weight: 400; }
.mem.matched .mem-back { background: var(--good-soft); border-color: var(--good); color: var(--good); }

/* ============================================================ builder game */
.builder-target {
  min-height: 84px; border: 2px dashed var(--line); border-radius: var(--r); padding: 12px;
  display: flex; flex-wrap: wrap-reverse; gap: 8px; direction: rtl; justify-content: flex-start;
  align-content: flex-start;
}
.builder-pool {
  display: flex; flex-wrap: wrap; gap: 8px; direction: rtl; margin-top: 16px;
  justify-content: center;
}
.chip {
  font-family: var(--ar); font-size: 1.6rem; line-height: 1.7; padding: 4px 14px;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer;
  transition: .15s;
}
.chip:hover { border-color: var(--brand); background: var(--brand-soft); }
.chip.ok { border-color: var(--good); background: var(--good-soft); }
.chip.err { border-color: var(--bad); background: var(--bad-soft); animation: shake .4s; }
.chip:disabled { opacity: .3; pointer-events: none; }

/* ============================================================ results */
.result { max-width: 620px; margin: 0 auto; text-align: center; }
.score-ring {
  --p: 0; width: 168px; height: 168px; margin: 0 auto 20px; border-radius: 50%;
  background: conic-gradient(var(--brand) calc(var(--p) * 1%), var(--bg-tint) 0); display: grid;
  place-items: center; position: relative;
}
.score-ring::before {
  content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--surface);
}
.score-ring > div { position: relative; }
.score-ring b { font-size: 2.6rem; font-weight: 800; display: block; line-height: 1; }
.score-ring span {
  font-size: .78rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .08em;
}
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); margin: 22px 0;
  gap: 14px;
}
.stat {
  border: 1px solid var(--line); border-radius: var(--r); padding: 20px;
  background: linear-gradient(145deg, var(--surface), var(--surface-2));
  border-color: rgba(177,155,111,.45);
}
.stat b {
  display: block; color: var(--brand); font-family: var(--ar); font-size: 2rem; font-weight: 600;
}
.stat span { font-size: .75rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .12em; }
.review-list { display: grid; gap: 8px; text-align: left; margin-top: 12px; }
.review-item {
  display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.review-item .ar { font-family: var(--ar); font-size: 1.5rem; direction: rtl; }

/* ============================================================ word table */
.wordlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.wcard {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
  /* It is a button now — picking a word moves the study card to it. */
  font: inherit; color: inherit; text-align: start; width: 100%; cursor: pointer; transition: .15s;
}
.wcard:hover { border-color: var(--brand); transform: translateY(-1px); }
.wcard[aria-pressed="true"] {
  border-color: var(--gold); background: var(--gold-soft);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 25%, transparent);
}
.wcard-body { flex: 1; min-width: 0; display: block; }
.wcard .ar, .wcard .en, .wcard .tl { display: block; }
.wcard .ar { font-family: var(--ar); font-size: 1.7rem; direction: rtl; line-height: 1.8; }
.wcard .en { font-weight: 600; font-size: .9rem; }
.wcard .tl { font-size: .75rem; color: var(--ink-3); font-style: italic; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--line); }
.dot.b1 { background: #E0B563; }
.dot.b2 { background: #C9A227; }
.dot.b3 { background: #6FBF8A; }
.dot.b4 { background: var(--good); }
.dot.b5 { background: var(--brand); }

/* ============================================================ misc */
.review-banner { display: flex; gap: 16px; align-items: center; margin-bottom: 26px; }
.review-icon {
  width: 42px; height: 42px; display: grid; place-items: center; flex: none; border-radius: 13px;
  background: var(--gold-soft); color: var(--gold); font-size: 1.5rem; font-weight: 700;
}
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 90px);
  background: var(--ink); color: var(--bg); padding: 11px 20px; border-radius: 999px;
  font-size: .88rem; font-weight: 600; box-shadow: var(--shadow-lg); transition: transform .3s;
  z-index: 60;
}
.toast.show { transform: translate(-50%, 0); }
.empty { text-align: center; padding: 56px 20px; color: var(--ink-2); }
.empty .big { font-family: var(--ar); font-size: 3rem; color: var(--brand); opacity: .5; }
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 14px; }
.mode {
  display: grid; gap: 6px; border-radius: var(--r-lg); border: 1px solid var(--line);
  text-decoration: none; color: inherit; transition: .18s; padding: 24px;
  background: linear-gradient(145deg, var(--surface), var(--surface-2));
}
.mode:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--brand); }
.mode .ico {
  display: grid; place-items: center; font-size: .7rem; font-weight: 800; letter-spacing: .04em;
  line-height: 1; margin-bottom: 4px; border-radius: 50%; background: var(--gold-soft);
  color: var(--gold); width: 40px; height: 40px;
}
.mode b { font-size: 1rem; }
.mode span { font-size: .84rem; color: var(--ink-2); }
.loader { display: grid; place-items: center; padding: 80px 0; color: var(--ink-2); gap: 14px; }
.spin {
  width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: sp .8s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

@media (max-width: 620px) {
  /* The wordmark alone fills a phone header, so navigation moves to a bottom
     bar: nothing is pushed off-screen, the targets land under the thumb, and
     the Arabic name can stay visible. */
  /* backdrop-filter makes an element the containing block for fixed-position
     descendants, which would pin the bar below to the header instead of the
     viewport. The header's own background is already opaque, so dropping the
     blur costs nothing. */
  .topbar {
    gap: 10px; padding-top: 8px; padding-bottom: 8px;
    backdrop-filter: none;
  }
  .brand { min-width: 0; }
  .brand-text { min-width: 0; }
  .brand-text b { font-size: 1rem; white-space: nowrap; }

  .topnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    justify-content: space-around; gap: 4px;
    background: rgba(11, 25, 19, .97);
    border-top: 1px solid rgba(214, 174, 91, .28);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .topnav a { flex: 1; justify-content: center; padding: 11px 6px; font-size: .82rem; border-radius: 12px; }
  main { padding-bottom: 92px; }
  .toast { bottom: 88px; }

  /* Keep only the last couple of crumbs; the rest fragments into single words. */
  .crumb { flex-wrap: nowrap; }
  .crumb > *:not(:nth-last-child(-n+3)) { display: none; }
  .crumb a, .crumb b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* A memory board you have to scroll is unplayable — fit all twelve cards. */
  .mem-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .mem { aspect-ratio: 1 / 1.1; }
  .mem-front { background-size: 52%; }
  .mem-back { font-size: .7rem; }
  .mem-back.ar { font-size: 1.15rem; }

  .tile { min-height: 56px; padding: 11px 10px; font-size: .88rem; }
  .tile.ar { font-size: 1.5rem; }

  .btn.sm { padding: 10px 16px; }   /* comfortable tap target */
  .opts.two { grid-template-columns: 1fr; }
  .hero-ar { position: static; margin-bottom: 12px; text-align: right; }
  .hero-stats { gap: 18px; }
  .hero-actions { align-items: flex-start; flex-direction: column; gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---- conjunction prefix + particle annotations ---- */
.prefix-note {
  display: block; margin-top: 8px; font-size: .76rem; color: var(--ink-2); padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.prefix-note .pre-ar { font-family: var(--ar); font-size: 1.25rem; color: var(--gold); }
.face.back .prefix-note { border-top-color: color-mix(in srgb, var(--brand) 25%, transparent); }
.chip-x {
  font-size: .62rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 999px; background: var(--bg-tint); color: var(--ink-3);
  vertical-align: middle;
}

.q-kind .carried { color: var(--ink-3); font-weight: 600; letter-spacing: 0; text-transform: none; }

/* ============================================================ premium editorial refresh */

.topnav a { color: #c6d0c3; }

.card, .sec, .mode, .stat, .wcard, .face, .q-card { box-shadow: var(--shadow); }

.card-link:hover, .mode:hover, .sec:hover { border-color: var(--gold); }

.surah-card .ar-name { font-size: 2rem; color: var(--brand-2); }

.opt .ar, .face .ar, .q-prompt .ar, .tile.ar, .chip { font-family: var(--ar); }

.foot a { color: #e1bd68; }
  @media (max-width: 620px) {
  main { padding-top: 24px; }
  .hero { border-radius: 24px; padding: 28px 22px; }
  .hero h1 { font-size: 2.8rem; }
  .surah-card { padding: 22px; }
  .stat { padding: 15px 12px; }
  }

/* focused home + lesson refresh */
.section-heading {
  display: flex; align-items: end; justify-content: space-between; gap: 28px; margin: 42px 0 18px;
}
.section-heading h2 { margin: 4px 0 0; }
.section-heading p { max-width: 38ch; margin: 0 0 2px; font-size: .92rem; }
.eyebrow {
  color: var(--gold); font-size: .72rem; font-weight: 800; letter-spacing: .16em;
  text-transform: uppercase;
}
.surah-heading { margin-top: 46px; }

.surah-card::after {
  content: ""; position: absolute; width: 150px; height: 150px; right: -50px; bottom: -60px;
  border: 1px solid color-mix(in srgb, var(--gold) 28%, transparent); border-radius: 50%;
  box-shadow: 0 0 0 18px color-mix(in srgb, var(--gold) 7%, transparent), 0 0 0 36px color-mix(in srgb, var(--gold) 5%, transparent);
  pointer-events: none;
}
.surah-card > * { position: relative; z-index: 1; }

.lesson-heading { margin-top: 58px; }
.lesson-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
.lesson-grid .mode { min-height: 170px; padding: 22px; border-radius: 20px; background: var(--surface); }
.lesson-grid .mode:nth-child(2) { background: var(--brand-soft); }
.lesson-grid .mode:nth-child(3) { background: var(--gold-soft); }
.lesson-grid .mode:nth-child(4) {
  background: color-mix(in srgb, var(--brand-soft) 55%, var(--surface));
}
.lesson-grid .mode .ico {
  width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: var(--gold-soft);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--gold) 16%, transparent);
}
.lesson-grid .mode:nth-child(3) .ico { background: var(--gold); color: #fffaf0; }
.lesson-grid .mode b { font-size: 1.04rem; }
.lesson-grid .mode span { line-height: 1.55; }

@media (max-width: 780px) {
  .lesson-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 620px) {
  .surah-hero { align-items: flex-start; padding: 24px 20px; }
  .surah-progress .ring { width: 64px; height: 64px; }
  .surah-progress .ring::before { width: 50px; height: 50px; }
  .surah-facts { gap: 6px; }
  .surah-facts span { font-size: .7rem; }
  .section-heading { display: grid; gap: 8px; margin-top: 34px; }
  .section-heading p { max-width: 32ch; }
  .surah-heading { margin-top: 38px; }
  .surah-card { padding: 22px; }
  .lesson-grid { grid-template-columns: 1fr; }
  .lesson-grid .mode { min-height: 0; }
}


/* ---- progress page: static rows reuse the section-list look ---- */
.sec.static { cursor: default; }
.sec.static:hover { transform: none; border-color: var(--line); }
.sec-count {
  font-family: var(--ar); font-size: 1.6rem; font-weight: 600; color: var(--brand);
  font-variant-numeric: tabular-nums; line-height: 1;
}
/* A count, not a surah name: .ar-name is direction:rtl, which right-aligns a
   numeral and leaves it stranded under the progress ring. */
.hero-figure {
  font-family: var(--ar); font-weight: 600; line-height: 1.05; color: var(--brand-2);
  font-size: clamp(2.4rem, 1.4rem + 3vw, 3.8rem); font-variant-numeric: tabular-nums;
}

/* ---- study card: meaning in context, grammar, and the explore layer ---- */
.f-gram {
  font-family: var(--mono, var(--ui)); font-size: .74rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--brand-2); margin-top: 6px;
}
:root[data-theme="dark"] .f-gram { color: var(--brand); }
.face.back .tiny.muted { margin-top: 10px; }

.explore {
  width: min(520px, 100%); border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); overflow: hidden;
}
.explore summary {
  cursor: pointer; padding: 12px 16px; font-weight: 700; font-size: .88rem;
  color: var(--ink-2); list-style: none;
}
.explore summary::-webkit-details-marker { display: none; }
.explore summary::after { content: " ▾"; color: var(--ink-3); }
.explore[open] summary { border-bottom: 1px solid var(--line); color: var(--ink); }
.explore[open] summary::after { content: " ▴"; }
.explore-body { padding: 14px 16px; display: grid; gap: 11px; }
.explore-row { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px; align-items: baseline; }
.explore-row .k {
  font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
}
.explore-row .v { font-size: .92rem; }

.seg {
  display: inline-grid; justify-items: center; gap: 1px; padding: 4px 10px; border-radius: 9px;
  background: var(--bg-tint); font-family: var(--ar); font-size: 1.35rem; line-height: 1.7;
}
.seg.p, .seg.x { background: var(--gold-soft); color: var(--gold); }
.seg i {
  font-family: var(--ui); font-style: normal; font-size: .6rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-3);
}
.seg-plus { color: var(--ink-3); margin: 0 5px; }
/* The breakdown reads the way the word is written: بِ is the rightmost piece of
   بِٱلْيَوْمِ, not the leftmost. The Latin tags inside each chip stay LTR. */
.segments {
  display: inline-flex; flex-wrap: wrap; align-items: center;
  direction: rtl; unicode-bidi: isolate;
}
.seg i { direction: ltr; unicode-bidi: isolate; }
.root {
  font-family: var(--ar); font-size: 1.5rem; letter-spacing: .18em; color: var(--brand);
  direction: rtl; unicode-bidi: isolate;
}
.ar-inline { font-family: var(--ar); font-size: 1.25rem; direction: rtl; unicode-bidi: isolate; }
.rel { display: inline-flex; align-items: baseline; gap: 6px; margin-inline-end: 14px; }

/* ---- transliteration is optional ---- */
:root[data-translit="off"] .face .tl,
:root[data-translit="off"] .wcard .tl-text,
:root[data-translit="off"] .hint.translit { display: none; }

/* ---- resume card: the first thing a returning learner should see ---- */
.resume {
  display: flex; align-items: center; gap: 20px; margin-bottom: 14px;
  border-color: color-mix(in srgb, var(--gold) 40%, var(--line));
  background: linear-gradient(135deg, var(--surface), var(--gold-soft));
}
.resume-copy { flex: 1; min-width: 0; display: grid; gap: 7px; }
.resume-copy b { font-size: 1.05rem; }
.resume .bar { max-width: 360px; }
@media (max-width: 620px) {
  .resume { flex-direction: column; align-items: stretch; gap: 14px; }
  .resume .btn { justify-content: center; }
}

/* ---- surah index ---- */
[hidden] { display: none !important; }
.finder { display: flex; align-items: center; gap: 14px; margin: 18px 0 8px; }
.finder input {
  flex: 1; min-width: 0; padding: 12px 16px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: .95rem;
}
.finder input::placeholder { color: var(--ink-3); }
.finder input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.row-ar { font-family: var(--ar); font-size: 1.25rem; direction: rtl; unicode-bidi: isolate; margin-inline-end: 6px; }

/* ---- backup panel ---- */
.backup { display: grid; gap: 0; padding: 0; }
.backup-row {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.backup-row:last-child { border-bottom: 0; }
.backup-row b { display: block; font-size: .96rem; }
@media (max-width: 620px) {
  .backup-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .backup-row .btn { justify-content: center; }
}
