/* Theme tokens */
:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #66716b;
  --line: #e2e7e3;
  --track: #e6ebe7;
  --brand: #0F4C3A;
  --gold: #C9A227;
  --logo-track: #DCE6E0;
  --s1: #f0a830;
  --s2: #1f9d6b;
  --s3: #7c4dbd;
  --s1-bg: #fff4dc;
  --s2-bg: #dcf3e8;
  --s3-bg: #efe7fa;
  --gold-bg: #f8ecc9;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513;
    --card: #19201d;
    --text: #e7ece9;
    --muted: #93a09a;
    --line: #2a332f;
    --track: #2a332f;
    --brand: #3fc293;
    --logo-track: #2C3A34;
    --s1-bg: #3a2e14;
    --s2-bg: #123527;
    --s3: #a682e0;
    --s3-bg: #2d2342;
    --gold-bg: #3a3014;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", "Noto Sans Bengali", system-ui, sans-serif;
}
html[lang="bn"] body { font-family: "Noto Sans Bengali", "Inter", system-ui, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; color: var(--brand); }
.logo { width: 30px; height: 30px; }
.lg-track { fill: none; stroke: var(--logo-track); }
.lg-gold { fill: none; stroke: var(--gold); }
.lg-book { fill: var(--brand); }
.lg-stand { fill: none; stroke: var(--brand); }
.login-mark { display: block; width: 104px; height: 104px; margin: 0 auto 12px; }
.bar-actions { display: flex; gap: 8px; }
main { max-width: 1040px; margin: 0 auto; padding: 16px; }

/* Buttons */
.chip {
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 6px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
}
.chip.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn {
  border: 1px solid var(--line); background: var(--card);
  padding: 10px 14px; border-radius: 10px; font-weight: 600;
}
.btn:disabled { opacity: .5; cursor: wait; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; width: 100%; }
.btn.s2btn { background: var(--s2); border-color: var(--s2); color: #fff; }
.btn.s3btn { background: var(--s3); border-color: var(--s3); color: #fff; }
.btn.ghost { background: transparent; }
.back { margin-bottom: 12px; }

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

/* Login */
.login { max-width: 380px; margin: 8vh auto 0; padding: 28px 24px; }
.login h1 { text-align: center; margin-bottom: 20px; color: var(--brand); font-weight: 800; letter-spacing: -0.5px; }
.login label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
input {
  display: block; width: 100%; margin-top: 6px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit;
}
input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.error { color: #d0453a; font-size: 14px; }

/* Rings */
.ring { transform: rotate(-90deg); flex-shrink: 0; }
.ring text { transform: rotate(90deg); transform-origin: 60px 60px; text-anchor: middle; fill: var(--text); }
.ring circle { fill: none; stroke-width: 10; }
.ring .track { stroke: var(--track); }
.ring .arc { stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring .mem { stroke: var(--s2); }
.ring .ver { stroke: var(--s3); }
.ring.lg { width: 168px; height: 168px; }
.ring.sm { width: 72px; height: 72px; }
.ring.xs { width: 58px; height: 58px; }
.ring.xs circle { stroke-width: 12; }
.ring-big { font-size: 26px; font-weight: 700; }
.ring-sub { font-size: 10px; fill: var(--muted) !important; }
.ring-txt { font-size: 22px; font-weight: 700; }
.ring-num { font-size: 32px; font-weight: 700; }

/* Hero */
.hero { display: flex; gap: 24px; align-items: center; padding: 20px; margin-bottom: 16px; }
.hero-info { flex: 1; min-width: 0; }
.hero-info h2 { font-size: 22px; margin: 2px 0 12px; }
.stats { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 12px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 22px; }
.stats span { color: var(--muted); font-size: 13px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 4px; }
.sw.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); } .sw.s3 { background: var(--s3); }

/* Juz grid */
.juz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.juz {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
  padding: 12px 6px 10px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line);
  transition: transform .1s ease, border-color .15s;
}
.juz:hover { transform: translateY(-2px); border-color: var(--s2); }
.juz.done { background: var(--s2-bg); border-color: var(--s2); }
.juz.verified { background: var(--s3-bg); border-color: var(--s3); }
.juz-label { font-weight: 600; font-size: 14px; margin-top: 4px; }
.badge {
  position: absolute; top: 6px; right: 8px;
  font-size: 13px; font-weight: 700; color: var(--s2);
}
.juz.verified .badge { color: var(--s3); }

/* Teacher list */
.row-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.search { max-width: 260px; margin: 0; }
.student-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.student-card { display: flex; gap: 14px; align-items: center; padding: 14px; text-align: left; }
.student-card:hover { border-color: var(--s2); }
.sc-body { display: flex; flex-direction: column; min-width: 0; }
.sc-body strong { font-size: 16px; }

/* Juz sheet */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  background: var(--card); border-radius: 18px; padding: 18px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; margin: 14px 0; }
.pg {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 64px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg);
  user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, background .15s;
}
.pg:active { transform: scale(.94); }
.pg-num { font-weight: 600; font-size: 15px; }
.pg-mark { font-size: 15px; font-weight: 700; height: 18px; line-height: 18px; }
.pg.s1 { background: var(--s1-bg); border-color: var(--s1); }
.pg.s1 .pg-mark { color: var(--s1); }
.pg.s2 { background: var(--s2-bg); border-color: var(--s2); }
.pg.s2 .pg-mark { color: var(--s2); }
.pg.s3 { background: var(--s3-bg); border-color: var(--s3); }
.pg.s3 .pg-mark { color: var(--s3); }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-actions .btn { flex: 1 1 auto; }

/* Toast */
.toast {
  /* Centered without transform so the x-transition scale can't shift it */
  position: fixed; bottom: 20px; left: 0; right: 0; margin: 0 auto; width: fit-content; z-index: 30; text-align: center;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px);
}

/* Phones */
@media (max-width: 560px) {
  .hero { flex-direction: column; text-align: center; gap: 12px; }
  .stats, .legend { justify-content: center; }
  .juz-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .overlay { align-items: flex-end; padding: 0; }
  .sheet { border-radius: 18px 18px 0 0; max-height: 85vh; }
  .page-grid { grid-template-columns: repeat(5, 1fr); }
  .pg { height: 56px; }
  .search { max-width: none; flex: 1; }
}

/* Juz / surah tabs */
.tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
.tabs button { border: 0; background: transparent; padding: 6px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--muted); }
.tabs button.on { background: var(--brand); color: #fff; }
.juz-sub { font-size: 11.5px; color: var(--muted); max-width: 100%; padding: 0 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Surah grid */
.surah-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.surah {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.surah:hover { border-color: var(--s2); }
.surah.done { background: var(--s2-bg); border-color: var(--s2); }
.surah.verified { background: var(--s3-bg); border-color: var(--s3); }
.ring.xxs { width: 42px; height: 42px; }
.ring.xxs circle { stroke-width: 13; }
.surah-names { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.surah-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.surah-ar { font-family: "Amiri", "Noto Naskh Arabic", "Geeza Pro", serif; font-size: 19px; direction: rtl; color: var(--brand); }
.sheet-head .surah-ar { margin: 0 6px; font-weight: 400; }

/* Surah chips in juz sheet */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.schip { display: inline-flex; align-items: center; gap: 8px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: 13px; }
.schip .surah-ar { font-size: 15px; }
.schip.done { border-color: var(--s2); background: var(--s2-bg); }
.surah-ar { unicode-bidi: isolate; }
.pg { height: auto; min-height: 64px; padding: 4px 2px; }
.pg-sur { font-size: 10.5px; color: var(--brand); max-width: 100%; padding: 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.schip.on { border-color: var(--brand); background: var(--brand); color: #fff; }
.schip.on .surah-ar { color: #fff; }
.juzchip { font-weight: 600; }

/* Profile */
.profile-btn { display: inline-flex; align-items: center; gap: 8px; padding: 3px 12px 3px 3px; border: 1px solid var(--line); border-radius: 999px; background: transparent; }
.profile-btn:hover { border-color: var(--brand); }
.pb-name { font-weight: 600; font-size: 13.5px; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--s2); color: #fff; font-weight: 700; font-size: 12.5px; flex-shrink: 0; }
.avatar.teacher { background: var(--gold); }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.profile { max-width: 420px; }
.who { display: flex; gap: 14px; align-items: center; margin: 14px 0 6px; }
.who strong { font-size: 17px; }
.role-tag { display: inline-block; margin: 4px 0; padding: 1px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--s2-bg); color: var(--s2); }
.role-tag.teacher { background: var(--gold-bg); color: #9a7a14; }
.pf-form { margin-top: 14px; }
.pf-form label { display: block; margin-bottom: 10px; font-weight: 600; font-size: 14px; }
.ok { color: var(--s2); font-size: 14px; }
@media (max-width: 560px) { .pb-name { display: none; } .profile-btn { padding: 3px; } }
[hidden] { display: none !important; }

/* Profile dropdown */
.menu-wrap { position: relative; }
.caret { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 15; width: 280px; padding: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.14); }
.menu .who { margin: 6px 6px 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.menu .who strong { font-size: 15px; }
.menu .avatar.lg { width: 44px; height: 44px; font-size: 16px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; font-size: 14.5px; }
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); outline: none; }
.menu-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.menu-item.danger, .menu-item.danger svg { color: #c2412f; }
.pf-form .btn.primary { margin-top: 4px; }
/* Keep white text readable on the verify button in dark mode */
@media (prefers-color-scheme: dark) { .btn.s3btn { background: #6a3fae; border-color: #6a3fae; } }
.avatar.visitor { background: #3d6fa8; }
.role-tag.visitor { background: #e3edf8; color: #2f5d91; }
@media (prefers-color-scheme: dark) { .role-tag.visitor { background: #1d2c3d; color: #8cb4e3; } }
.gender { border: 0; padding: 0; margin: 0 0 12px; display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.gender legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 6px; width: 100%; }
.pf-form .gender label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; }
.gender input { display: inline; width: auto; margin: 0; accent-color: var(--brand); }

/* Authentik sign-in */
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.btn.sso { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn.sso svg.mug { width: 22px; height: 26px; }
.mug-body { fill: #6F4529; }
.mug-key { fill: #FFFFFF; }
.mug-accent { stroke: #C6874C; }
@media (prefers-color-scheme: dark) {
  .mug-body { fill: #E3B78A; }
  .mug-key { fill: #15100A; }
  .mug-accent { stroke: #B97A42; }
}
.btn.sso:hover { border-color: var(--brand); }

/* Sign-out: Authentik prompt */
.sso-prompt { max-width: 440px; }
.sso-prompt h3 { margin-bottom: 8px; }
.sso-prompt .sheet-actions { margin-top: 16px; flex-direction: column; }

/* Read & practice */
.read-btn { display: inline-flex; align-items: center; gap: 8px; margin: 2px 0 12px; }
.read-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.small-btn { padding: 7px 12px; font-size: 14px; margin: 10px 0 0; }
.reader { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; }
.reader-inner { display: flex; flex-direction: column; width: 100%; max-width: 860px; margin: 0 auto; min-height: 0; height: 100%; }
.reader-bar { display: flex; gap: 8px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
.reader-search { flex: 1; min-width: 0; }
.reader-search input { margin: 0; width: 100%; min-width: 0; }
.zoom { display: flex; gap: 4px; }
.reader-err { padding: 0 16px; }
.reader-body { flex: 1; overflow-y: auto; padding: 14px 16px 24px; -webkit-overflow-scrolling: touch; }
.reader-context { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.surah-ar.big { font-family: "Amiri Quran", "Amiri", serif; font-size: 28px; line-height: 1.4; }
.pstatus { flex-shrink: 0; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); }
.pstatus.s1 { background: var(--s1-bg); border-color: var(--s1); }
.pstatus.s2 { background: var(--s2-bg); border-color: var(--s2); }
.pstatus.s3 { background: var(--s3-bg); border-color: var(--s3); }
.tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.tr-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.tr-toggle input { display: inline; width: auto; margin: 0; accent-color: var(--brand); }
.mushaf { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px clamp(14px, 4vw, 34px); margin-top: 8px; }
.bismillah { font-family: "Amiri Quran", "Amiri", serif; text-align: center; color: var(--brand); font-size: calc(26px * var(--rscale)); line-height: 2; }
.ayat { font-family: "Amiri Quran", "Amiri", serif; font-size: calc(30px * var(--rscale)); line-height: 2.3; text-align: justify; text-align-last: center; }
.ayah.tappable { cursor: pointer; }
.ayah.hidden > span:not(.ayah-no) { color: transparent; background: var(--bg); border-radius: 6px; box-shadow: inset 0 -2px 0 var(--line); }
.ayat { touch-action: pan-y; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.w { border-radius: 6px; cursor: pointer; transition: background .12s; }
.w.on { background: var(--s2-bg); box-shadow: 0 0 0 1.5px var(--brand); }
@media (hover: hover) and (pointer: fine) { .w:not(.veil):hover { background: var(--s2-bg); box-shadow: 0 0 0 1.5px var(--brand); } }
.w.veil { color: transparent; border-bottom: 2px dotted var(--muted); border-radius: 0; }
.gloss-tip { position: fixed; z-index: 45; transform: translate(calc(-50% + var(--shift, 0px)), calc(-100% - 8px)); background: var(--brand); color: #fff; font-family: "Noto Sans Bengali", system-ui, sans-serif; font-size: calc(17px * (0.85 + var(--rscale) * .15)); line-height: 1.4; white-space: nowrap; padding: 6px 12px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.2); pointer-events: none; }
.gloss-tip::after { content: ""; position: absolute; top: 100%; left: calc(50% - var(--shift, 0px)); transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--brand); }
.tr-note { font-style: italic; margin-top: 4px; }
.ayah-no { color: var(--brand); margin: 0 4px; white-space: nowrap; }
.translation { margin-top: 12px; padding: 14px 4px 0; border-top: 1px dashed var(--line); font-family: "Noto Sans Bengali", system-ui, sans-serif; font-size: calc(16px * (0.85 + var(--rscale) * .15)); line-height: 1.8; }
.translation p { margin: 0 0 8px; }
.tr-pending { font-style: italic; }
.reader-marks { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.reader-marks .btn { padding: 7px 12px; font-size: 14px; }
.reader-marks .btn.on { background: var(--s1-bg); border-color: var(--s1); }
.reader-nav { display: flex; justify-content: space-between; gap: 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); }
.reader-nav .btn { flex: 1; max-width: 220px; }
@media (max-width: 560px) {
  .ayat { font-size: calc(26px * var(--rscale)); line-height: 2.2; }
  .surah-ar.big { font-size: 24px; }
}
@media (prefers-color-scheme: dark) { .gloss-tip { background: #1d6b52; } .gloss-tip::after { border-top-color: #1d6b52; } }

.admin-row { display:flex; flex-wrap:wrap; align-items:center; gap:.6rem; padding:.7rem 0; border-bottom:1px solid var(--border, #ddd); }
.admin-row input { max-width:100%; }
