@font-face {
  font-family: 'Amiri Quran';
  src: url('/static/fonts/AmiriQuran-Regular.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Amiri';
  src: url('/static/fonts/Amiri-Regular.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Amiri';
  src: url('/static/fonts/Amiri-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}

:root {
  --bg:        #05070b;
  --line:      #1e2734;
  --line-soft: #161d27;

  --ink:       #eef2f8;
  --ink-dim:   #94a3b8;
  --ink-faint: #5a6879;

  --gold:      #e0b878;
  --gold-soft: #f0d9ae;
  --gold-dim:  #7d6640;
  --teal:      #56ccb4;
  --rose:      #e8807a;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-xl: 30px;

  --shadow-2: 0 8px 30px rgba(0,0,0,.45);
  --shadow-3: 0 30px 80px rgba(0,0,0,.65), 0 2px 6px rgba(0,0,0,.4);

  --glass: rgba(13,19,28,.72);
  --glass-line: rgba(255,255,255,.075);
  --glass-hi: rgba(255,255,255,.045);

  --ease: cubic-bezier(.22,.61,.36,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px; overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;   /* stop iOS inflating Arabic text */
  overscroll-behavior: none;
}
/* nothing should create a horizontal scrollbar on a phone */
body { overflow-x: hidden; }
img, svg, table { max-width: 100%; }

/* ------------------------------------------------------ ambient bg */
.ambient { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.glow { position: absolute; border-radius: 50%; filter: blur(110px); opacity: .5; }
.g1 {
  width: 62vw; height: 62vw; top: -22vw; left: -12vw;
  background: radial-gradient(circle, rgba(224,184,120,.30), transparent 68%);
  animation: drift1 46s var(--ease) infinite alternate;
}
.g2 {
  width: 54vw; height: 54vw; bottom: -20vw; right: -10vw;
  background: radial-gradient(circle, rgba(86,204,180,.20), transparent 68%);
  animation: drift2 58s var(--ease) infinite alternate;
}
.g3 {
  width: 44vw; height: 44vw; top: 32%; left: 42%;
  background: radial-gradient(circle, rgba(165,140,240,.16), transparent 70%);
  animation: drift3 68s var(--ease) infinite alternate;
}
@keyframes drift1 { to { transform: translate3d(9vw,7vw,0) scale(1.16); } }
@keyframes drift2 { to { transform: translate3d(-8vw,-6vw,0) scale(1.12); } }
@keyframes drift3 { to { transform: translate3d(-6vw,8vw,0) scale(1.2); } }
.grain {
  position: absolute; inset: -50%; opacity: .16; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

#app { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100vh; }
/* 100vh on mobile Safari includes the collapsing toolbar, so prefer dvh */
@supports (height: 100dvh) {
  #app { height: 100dvh; }
  .mushaf-stage, .reader { max-height: 100dvh; }
}

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
  backdrop-filter: blur(26px) saturate(160%);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow-3), inset 0 1px 0 var(--glass-hi);
}

/* -------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 18px; height: 62px; flex: 0 0 62px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(10,14,20,.92), rgba(5,7,11,.72));
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  flex: 0 0 auto; display: block;
  filter: drop-shadow(0 0 12px rgba(224,184,120,.42));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-ar { font-family: 'Amiri Quran', serif; font-size: 17px; color: var(--gold-soft); }
.brand-en { font-size: 9px; letter-spacing: .28em; text-transform: uppercase;
            color: var(--ink-faint); margin-top: 2px; }

.modes {
  position: relative; display: flex; gap: 2px; padding: 4px;
  background: rgba(255,255,255,.028); border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
}
.modes button {
  position: relative; z-index: 2; background: none; border: 0; cursor: pointer;
  color: var(--ink-dim); font: inherit; font-size: 13.5px; font-weight: 500;
  padding: 7px 15px; border-radius: 10px; transition: color .22s var(--ease);
}
.modes button:hover { color: var(--ink); }
.modes button.active { color: #0a0d12; font-weight: 600; }
.modes-glider {
  position: absolute; z-index: 1; top: 4px; bottom: 4px; left: 4px; width: 0;
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  border-radius: 10px; box-shadow: 0 4px 18px rgba(224,184,120,.28);
  transition: transform .34s var(--ease-out), width .34s var(--ease-out);
  pointer-events: none;
}

.cmd-trigger {
  margin-inline-start: auto; display: flex; align-items: center; gap: 9px;
  background: rgba(255,255,255,.032); border: 1px solid var(--line);
  color: var(--ink-dim); font: inherit; font-size: 13px;
  padding: 8px 11px 8px 13px; border-radius: var(--r-md); cursor: pointer;
  transition: .2s var(--ease);
}
.cmd-trigger:hover { color: var(--ink); border-color: var(--gold-dim); background: rgba(224,184,120,.07); }
.cmd-trigger kbd {
  font-family: inherit; font-size: 10.5px; color: var(--ink-faint);
  background: rgba(255,255,255,.05); border: 1px solid var(--line-soft);
  border-radius: 5px; padding: 2px 5px;
}
.stats { display: flex; gap: 13px; font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.stats b { color: var(--ink-dim); font-weight: 600; }
@media (max-width: 1560px) { .stats { display: none; } }

/* ---------------------------------------------------------- stage */
.stage { flex: 1; position: relative; overflow: hidden; }
.view { display: none; height: 100%; }
.view.active { display: flex; animation: fade .3s var(--ease-out); }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } }

.rail {
  width: 276px; flex: 0 0 276px; height: 100%; overflow-y: auto;
  padding: 16px 14px 40px;
  background: linear-gradient(180deg, rgba(10,15,22,.6), rgba(5,7,11,.3));
  border-inline-end: 1px solid var(--line-soft);
}
.rail.narrow { width: 176px; flex: 0 0 176px; }
.rail-head { position: sticky; top: -16px; z-index: 3; padding: 12px 0 10px;
             background: linear-gradient(180deg, #090d13 70%, transparent); }
.rail-title {
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 9px; font-weight: 600;
}
.filter {
  width: 100%; background: rgba(255,255,255,.035); border: 1px solid var(--line);
  color: var(--ink); border-radius: var(--r-sm); padding: 8px 11px; font: inherit;
  font-size: 13px; margin-bottom: 10px; transition: .2s var(--ease);
}
.filter:focus { outline: none; border-color: var(--gold-dim); background: rgba(224,184,120,.06); }
.filter::placeholder { color: var(--ink-faint); }

.surah-list { display: flex; flex-direction: column; gap: 2px; }
.surah-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 9px;
  border-radius: var(--r-sm); cursor: pointer; border: 1px solid transparent;
  transition: .16s var(--ease);
}
.surah-item:hover { background: rgba(255,255,255,.04); }
.surah-item.active {
  background: linear-gradient(90deg, rgba(224,184,120,.14), rgba(224,184,120,.03));
  border-color: rgba(224,184,120,.26);
}
.surah-num {
  width: 27px; height: 27px; flex: 0 0 27px; display: grid; place-items: center;
  background: rgba(255,255,255,.05); border-radius: 8px;
  font-size: 11.5px; color: var(--gold); font-variant-numeric: tabular-nums;
}
.surah-item.active .surah-num { background: var(--gold); color: #0a0d12; font-weight: 700; }
.surah-meta { display: flex; flex-direction: column; min-width: 0; }
.surah-en { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.surah-sub { font-size: 10.5px; color: var(--ink-faint); }
.surah-ar { margin-inline-start: auto; font-family: 'Amiri', serif; font-size: 17px; color: var(--ink-dim); }

.juz-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.juz-list button {
  background: rgba(255,255,255,.035); border: 1px solid var(--line-soft);
  color: var(--ink-dim); border-radius: var(--r-sm); padding: 12px 4px; cursor: pointer;
  font: inherit; font-size: 14px; font-variant-numeric: tabular-nums; transition: .18s var(--ease);
}
.juz-list button:hover { border-color: var(--gold-dim); color: var(--gold); transform: translateY(-1px); }
.juz-list button.active {
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  color: #0a0d12; font-weight: 700; border-color: transparent;
}

.root-list { display: flex; flex-wrap: wrap; gap: 6px; }
.root-list button {
  background: rgba(255,255,255,.035); border: 1px solid var(--line-soft);
  color: var(--ink-dim); border-radius: 30px; padding: 5px 12px; cursor: pointer;
  font-family: 'Amiri', serif; font-size: 16px; transition: .18s var(--ease);
}
.root-list button:hover { border-color: var(--teal); color: var(--teal); transform: translateY(-1px); }
.root-list button.active { background: var(--teal); color: #05070b; border-color: transparent; }

/* --------------------------------------------------------- mushaf */
/* The mushaf view stacks: floating pager, the page itself, then the inline
 * statistics strip and the hint. Without an explicit column these became row
 * flex items and squeezed the page to a few dozen pixels on a short viewport. */
#view-mushaf { flex-direction: column; }
#view-mushaf .mushaf-stage { flex: 1 1 auto; min-height: 0; }
.pagestats, .hint { flex: 0 0 auto; }

.pager {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 6; display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--r-lg);
  background: var(--glass); border: 1px solid var(--glass-line);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: var(--shadow-2);
}
.pager-read { display: flex; align-items: baseline; gap: 5px; }
.pager-read input {
  width: 54px; background: rgba(255,255,255,.05); border: 1px solid var(--line);
  color: var(--ink); border-radius: 8px; padding: 5px 6px; font: inherit; font-size: 14px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.pager-read input:focus { outline: none; border-color: var(--gold-dim); }
.pager-of { font-size: 11.5px; color: var(--ink-faint); }
.iconbtn {
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  color: var(--ink-dim); width: 31px; height: 31px; border-radius: 9px;
  cursor: pointer; font-size: 17px; line-height: 1; transition: .18s var(--ease);
}
.iconbtn:hover { color: var(--gold); border-color: var(--gold-dim); background: rgba(224,184,120,.1); }
.ghostbtn {
  background: none; border: 1px solid var(--line); color: var(--ink-dim);
  border-radius: 9px; padding: 6px 12px; font: inherit; font-size: 12.5px; cursor: pointer;
  transition: .18s var(--ease);
}
.ghostbtn:hover { color: var(--gold); border-color: var(--gold-dim); }

.mushaf-stage {
  flex: 1 1 auto; min-width: 0; min-height: 0;
  overflow-y: auto; padding: 78px 30px 26px;
  display: flex; justify-content: center; align-items: flex-start;
}
.mushaf-frame {
  width: min(780px, 100%); height: fit-content;
  background: radial-gradient(120% 90% at 50% 0%, #fdfaf3 0%, #f7f2e7 55%, #efe8d8 100%);
  border-radius: var(--r-md); padding: 38px 34px 30px;
  direction: rtl;
  box-shadow: 0 40px 90px rgba(0,0,0,.6), 0 0 0 1px rgba(0,0,0,.25),
              0 0 90px rgba(224,184,120,.08);
  border-inline: 13px solid #ece2cd;
  align-self: flex-start; position: relative;
}
.mushaf-frame::before {
  content: ''; position: absolute; inset: 7px; border: 1px solid rgba(160,140,100,.3);
  border-radius: 6px; pointer-events: none;
}
.mushaf-line {
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 11px; min-height: 31px;
}
.mushaf-line.center { justify-content: center; }
.mushaf-line.justify .ayah-line-text { text-align: justify; text-align-last: center; }
.surah-header {
  text-align: center; font-family: 'Amiri Quran', serif; font-size: 20px;
  color: #7c6432; background: linear-gradient(180deg, #f7efdd, #f1e6cf);
  border: 1px solid #d9cdb2; border-radius: 7px; padding: 4px 0; margin: 12px 0;
}
.basmala { text-align: center; font-family: 'Amiri Quran', serif; font-size: 22px; color: #48402c; margin: 7px 0 13px; }
.ayah-line-text {
  font-family: 'Amiri Quran', 'Amiri', serif; font-size: 26px; line-height: 1.95;
  color: #1c1913; width: 100%;
}
.mword { cursor: pointer; border-radius: 4px; padding: 0 2px; transition: background .14s var(--ease), box-shadow .14s var(--ease); }
.mword:hover { background: rgba(160,130,70,.2); box-shadow: 0 0 0 1px rgba(160,130,70,.3); }
.mword.sel { background: var(--gold); color: #0a0d12; box-shadow: 0 3px 12px rgba(140,110,50,.5); }

.ltr { position: relative; cursor: pointer; transition: background .12s; }
.ltr:hover { background: rgba(86,204,180,.32); border-radius: 2px; }
.ltr.tj { border-bottom: 2px solid currentColor; }
.ltr.sel { background: var(--gold); color: #0a0d12 !important; border-radius: 2px; }
.ltr.tj-ghunnah  { color: #c0347f; }
.ltr.tj-ikhfa    { color: #7a52d8; }
.ltr.tj-iqlab    { color: #1f7fc4; }
.ltr.tj-idghaam  { color: #158a72; }
.ltr.tj-madd     { color: #9a6b00; }
.ltr.tj-qalqalah { color: #b4491f; }
.ltr.tj-hamzat   { color: #5f6b7c; }
.ltr.tj-lam      { color: #5f6b7c; }
.ltr.tj-silent   { color: #8b93a0; }
.tjc-ghunnah  { color: #c0347f; }
.tjc-ikhfa    { color: #7a52d8; }
.tjc-iqlab    { color: #1f7fc4; }
.tjc-idghaam  { color: #158a72; }
.tjc-madd     { color: #9a6b00; }
.tjc-qalqalah { color: #b4491f; }
.tjc-hamzat   { color: #5f6b7c; }
.tjc-lam      { color: #5f6b7c; }
.tjc-silent   { color: #8b93a0; }

.hint { flex: 0 0 auto; text-align: center; font-size: 12px; color: var(--ink-faint); padding: 6px 0 16px; }
.hint b { color: var(--ink-dim); font-weight: 600; }

/* -------------------------------------------------------- reader */
.reader { flex: 1; overflow-y: auto; padding: 26px 34px 80px; }
.reader-head { margin-bottom: 24px; }
.reader-head h1 { margin: 0 0 8px; font-size: 27px; font-weight: 650; letter-spacing: -.02em; }
.reader-head h1 .ar { font-family: 'Amiri Quran', serif; color: var(--gold); font-size: 32px;
                      margin-inline-start: 12px; font-weight: 400; }
.reader-sub { color: var(--ink-faint); font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  background: rgba(255,255,255,.04); border: 1px solid var(--line-soft);
  border-radius: 30px; padding: 4px 12px; font-size: 12px; color: var(--ink-dim);
}
.chip b { color: var(--gold); font-weight: 650; }

.ayah {
  border-top: 1px solid var(--line-soft); padding: 20px 16px 20px 0;
  display: grid; grid-template-columns: 62px 1fr; gap: 20px;
  border-radius: var(--r-md); transition: background .2s var(--ease);
}
.ayah:hover { background: rgba(255,255,255,.022); }
.ayah-no { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums;
           padding-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.ayah-no .n { color: var(--gold); font-size: 16px; font-weight: 700; }
.ayah-body { min-width: 0; }
.ayah-ar {
  font-family: 'Amiri Quran', 'Amiri', serif; font-size: 30px; line-height: 2.2;
  direction: rtl; text-align: right; margin-bottom: 12px;
}
.ayah-ar .w { cursor: pointer; border-radius: 5px; padding: 0 2px; transition: .14s var(--ease); }
.ayah-ar .w:hover { background: rgba(224,184,120,.16); }
.ayah-ar .w.sel { background: var(--gold); color: #0a0d12; }
.ayah-tr { font-size: 15px; color: var(--ink-dim); line-height: 1.7; margin-bottom: 6px; }
.ayah-tr.de { color: var(--ink-faint); font-size: 14px; }
.ayah-tf { font-size: 14.5px; color: var(--ink-dim); line-height: 1.85; direction: rtl;
           text-align: right; font-family: 'Amiri', serif; }
.ayah-tools { display: flex; gap: 8px; margin-top: 13px; align-items: center; flex-wrap: wrap; }
.tool {
  background: rgba(255,255,255,.045); border: 1px solid var(--line-soft);
  color: var(--ink-dim); border-radius: 9px; padding: 6px 12px; font: inherit;
  font-size: 12px; cursor: pointer; transition: .18s var(--ease);
}
.tool:hover { color: var(--gold); border-color: var(--gold-dim); background: rgba(224,184,120,.08); }
.tool.rec { color: var(--teal); }
.tool.rec:hover { border-color: var(--teal); background: rgba(86,204,180,.09); }

.empty { color: var(--ink-faint); font-size: 13.5px; padding: 40px 0; text-align: center; }

/* ---------------------------------------------- sheet (page index) */
.sheet { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; }
.sheet-panel {
  width: min(880px, 92vw); max-height: 82vh; border-radius: var(--r-xl);
  padding: 22px 24px; display: flex; flex-direction: column;
  animation: pop .3s var(--ease-out);
}
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(10px); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
             gap: 6px; overflow-y: auto; }
.page-grid button {
  aspect-ratio: 1; background: rgba(255,255,255,.04); border: 1px solid var(--line-soft);
  color: var(--ink-dim); border-radius: 9px; cursor: pointer; font: inherit;
  font-size: 11.5px; font-variant-numeric: tabular-nums; transition: .15s var(--ease);
}
.page-grid button:hover { border-color: var(--gold-dim); color: var(--gold); transform: translateY(-1px); }
.page-grid button.active { background: var(--gold); color: #0a0d12; font-weight: 700; border-color: transparent; }

/* --------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; }
.modal-scrim {
  position: absolute; inset: 0; background: rgba(3,5,9,.72);
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
  animation: fadein .26s var(--ease-out);
}
@keyframes fadein { from { opacity: 0; } }
.modal-card {
  position: relative; width: min(1080px, 94vw); max-height: 88vh;
  border-radius: var(--r-xl); display: flex; flex-direction: column;
  animation: rise .38s var(--ease-out); overflow: hidden;
}
@keyframes rise { from { opacity: 0; transform: translateY(26px) scale(.975); } }

.modal-head {
  display: flex; align-items: flex-start; gap: 20px;
  padding: 24px 26px 18px; border-bottom: 1px solid var(--glass-line);
  background: linear-gradient(180deg, rgba(224,184,120,.07), transparent);
}
.modal-id { min-width: 0; }
.modal-kicker {
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--gold-dim); font-weight: 700; margin-bottom: 7px;
}
.modal-title {
  margin: 0; font-family: 'Amiri Quran', serif; font-size: 42px; line-height: 1.25;
  direction: rtl; text-align: right; color: var(--gold-soft); font-weight: 400;
}
.modal-title.ltr { font-family: inherit; font-size: 22px; font-weight: 650;
                   direction: ltr; text-align: left; color: var(--ink); }
.modal-sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 7px; }
.xbtn {
  margin-inline-start: auto; flex: 0 0 auto; width: 36px; height: 36px;
  border-radius: 11px; background: rgba(255,255,255,.05); border: 1px solid var(--line);
  color: var(--ink-dim); font-size: 20px; line-height: 1; cursor: pointer;
  transition: .18s var(--ease);
}
.xbtn:hover { color: var(--rose); border-color: rgba(232,128,122,.4); background: rgba(232,128,122,.1); }

.mtabs {
  position: relative; display: flex; gap: 2px; padding: 0 22px;
  border-bottom: 1px solid var(--glass-line); background: rgba(0,0,0,.14); flex: 0 0 auto;
}
.mtabs button {
  position: relative; z-index: 2; background: none; border: 0; cursor: pointer;
  color: var(--ink-faint); font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 14px 16px; display: flex; align-items: center; gap: 7px;
  transition: color .2s var(--ease);
}
.mtabs button:hover { color: var(--ink-dim); }
.mtabs button.active { color: var(--gold); }
.mtabs-glider {
  position: absolute; z-index: 1; bottom: -1px; height: 2px; left: 22px; width: 0;
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
  box-shadow: 0 0 14px rgba(224,184,120,.55);
  transition: transform .32s var(--ease-out), width .32s var(--ease-out);
}
.badge {
  font-size: 10px; background: rgba(255,255,255,.08); border-radius: 20px;
  padding: 1px 7px; color: var(--ink-faint); font-variant-numeric: tabular-nums;
}
.badge.hot { background: rgba(86,204,180,.18); color: var(--teal); }

.modal-body { padding: 24px 26px 32px; overflow-y: auto; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: 20px; }
.card {
  background: rgba(255,255,255,.028); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 16px 18px;
}
.card h4 {
  margin: 0 0 12px; font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700;
}
.kv { display: grid; grid-template-columns: 104px 1fr; gap: 9px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--ink-faint); }
.kv dd { margin: 0; color: var(--ink); }
.kv dd.ar { font-family: 'Amiri', serif; font-size: 18px; direction: rtl; text-align: right; }

.seg-row {
  display: flex; align-items: center; gap: 11px; padding: 9px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.seg-row:last-child { border-bottom: 0; }
.seg-ar { font-family: 'Amiri', serif; font-size: 20px; color: var(--ink); }
.seg-pos { font-size: 10.5px; color: var(--gold); background: rgba(224,184,120,.1);
           border-radius: 6px; padding: 2px 8px; }
.seg-feats { color: var(--ink-faint); font-size: 11.5px; margin-inline-start: auto; text-align: right; }

.tag {
  display: inline-block; background: rgba(255,255,255,.05); border: 1px solid var(--line-soft);
  border-radius: 7px; padding: 3px 9px; font-size: 12px; color: var(--ink-dim);
  margin: 0 5px 5px 0;
}
.tag.ar { font-family: 'Amiri', serif; font-size: 15px; }

.ayah-show {
  font-family: 'Amiri Quran', serif; font-size: 25px; direction: rtl; text-align: right;
  line-height: 2.15; background: rgba(0,0,0,.22); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 18px 20px; margin-bottom: 16px;
}
.ayah-show .w { cursor: pointer; border-radius: 5px; padding: 0 2px; transition: .14s var(--ease); }
.ayah-show .w:hover { background: rgba(224,184,120,.18); }
.ayah-show .w.sel { background: var(--gold); color: #0a0d12; }

.occ-wrap { display: flex; flex-wrap: wrap; gap: 7px; }
.occ {
  background: rgba(255,255,255,.04); border: 1px solid var(--line-soft); border-radius: 9px;
  padding: 5px 10px; cursor: pointer; font-family: 'Amiri', serif; font-size: 16px;
  color: var(--ink-dim); transition: .16s var(--ease);
}
.occ:hover { border-color: var(--teal); color: var(--teal); transform: translateY(-1px); }
.occ .r { font-family: inherit; font-size: 10.5px; color: var(--ink-faint); margin-inline-start: 6px; }

/* patterns inside the modal */
.rel {
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
  padding: 14px 16px; margin-bottom: 10px; background: rgba(255,255,255,.022);
  transition: .2s var(--ease);
}
.rel:hover { background: rgba(255,255,255,.038); }
.rel-survive { border-inline-start: 3px solid var(--teal); background: rgba(86,204,180,.05); }
.rel-chance  { border-inline-start: 3px solid var(--line); }
.rel-degen   { border-inline-start: 3px solid #3a2f1a; opacity: .6; }
.rel-head { display: flex; justify-content: space-between; gap: 14px; align-items: baseline; }
.rel-label { font-size: 13.5px; color: var(--ink); font-family: ui-monospace, 'SF Mono', monospace; }
.rel-q { font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rel-survive .rel-q { color: var(--teal); font-weight: 600; }
.rel-stats { display: flex; gap: 20px; margin-top: 9px; font-size: 12.5px; color: var(--ink-faint); }
.rel-stats b { color: var(--ink-dim); font-weight: 650; }
.rel-verdict { margin-top: 9px; font-size: 12.5px; color: var(--ink-dim); }
.rel-survive .rel-verdict { color: var(--teal); }
.strata { margin-top: 11px; display: flex; flex-wrap: wrap; gap: 8px; font-size: 11.5px; align-items: center; }
.stratum { color: var(--ink-dim); background: rgba(255,255,255,.05); border-radius: 7px;
           padding: 4px 9px; font-variant-numeric: tabular-nums; }
.stratum b { color: var(--ink); }

.method {
  background: rgba(224,184,120,.045); border: 1px solid rgba(224,184,120,.16);
  border-radius: var(--r-md); padding: 15px 18px; margin-bottom: 18px;
}
.method p { margin: 0 0 10px; font-size: 13px; line-height: 1.72; color: var(--ink-dim); }
.method p:last-child { margin-bottom: 0; }
.method b { color: var(--ink); }
.dim { color: var(--ink-faint); font-size: 12.5px; }

.pmatch { font-size: 12.5px; color: var(--ink-dim); padding: 5px 0; border-bottom: 1px solid var(--line-soft); }
.pmatch:last-child { border-bottom: 0; }
.pmatch b { color: var(--gold); }
.pmatch.strong { color: var(--teal); }
.pmatch.strong b { color: var(--teal); }

.claims-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 11px 14px; border-radius: var(--r-sm); margin-bottom: 7px;
  background: rgba(255,255,255,.022); border: 1px solid var(--line-soft);
}
.claims-row.ok { border-inline-start: 3px solid var(--teal); background: rgba(86,204,180,.05); }
.claims-row .cl { font-size: 13px; color: var(--ink-dim); }
.claims-row .cn { font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.claims-row .cn b { color: var(--ink); }
.claims-row .ok-tag { color: var(--teal); font-weight: 650; }
.claims-row .no-tag { color: var(--ink-faint); }

/* ------------------------------------------------------- command */
.cmdk { position: fixed; inset: 0; z-index: 100; display: flex; justify-content: center; padding-top: 13vh; }
.cmdk-scrim {
  position: absolute; inset: 0; background: rgba(3,5,9,.7);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  animation: fadein .22s var(--ease-out);
}
.cmdk-card {
  position: relative; width: min(760px, 92vw); max-height: 70vh;
  border-radius: var(--r-xl); display: flex; flex-direction: column; overflow: hidden;
  animation: rise .32s var(--ease-out);
}
.cmdk-input {
  display: flex; align-items: center; gap: 13px; padding: 17px 20px;
  border-bottom: 1px solid var(--glass-line); color: var(--ink-faint);
}
.cmdk-input input {
  flex: 1; background: none; border: 0; color: var(--ink); font: inherit;
  font-size: 17px; outline: none;
}
.cmdk-input input::placeholder { color: var(--ink-faint); }
.cmdk-input kbd {
  font-family: inherit; font-size: 10.5px; color: var(--ink-faint);
  background: rgba(255,255,255,.05); border: 1px solid var(--line-soft);
  border-radius: 5px; padding: 3px 7px;
}
.results { overflow-y: auto; padding: 7px; }
.result {
  padding: 13px 15px; border-radius: var(--r-sm); cursor: pointer;
  border: 1px solid transparent; transition: .15s var(--ease);
}
.result:hover, .result.hot { background: rgba(224,184,120,.09); border-color: rgba(224,184,120,.2); }
.result-ref { font-size: 11.5px; color: var(--gold); margin-bottom: 7px; font-variant-numeric: tabular-nums; }
.result-ar { font-family: 'Amiri Quran', serif; font-size: 22px; direction: rtl;
             text-align: right; color: var(--ink); margin-bottom: 6px; }
.result-tr { font-size: 13.5px; color: var(--ink-dim); }

/* -------------------------------------------------------- tooltip */
.tooltip {
  position: fixed; pointer-events: none; z-index: 200; display: none;
  background: rgba(6,9,14,.94); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-radius: var(--r-md); padding: 12px 15px; font-size: 12.5px;
  color: var(--ink); max-width: 420px; box-shadow: var(--shadow-3);
}
.tooltip .tt-ar { font-family: 'Amiri', serif; font-size: 21px; direction: rtl;
                  text-align: right; color: var(--gold); margin-bottom: 6px; }
.tooltip .tt-line { color: var(--ink-dim); margin-top: 4px; }
.tooltip .tt-line b { color: var(--ink); }

audio { width: 100%; margin-top: 10px; height: 36px; }

/* ------------------------------------------------------- settings */
.settings-card {
  position: relative; width: min(820px, 94vw); max-height: 84vh;
  border-radius: var(--r-xl); display: flex; flex-direction: column; overflow: hidden;
  animation: rise .32s var(--ease-out);
}
.settings-head {
  display: flex; align-items: flex-start; gap: 18px;
  padding: 22px 24px 16px; border-bottom: 1px solid var(--glass-line);
  background: linear-gradient(180deg, rgba(224,184,120,.07), transparent);
}
.settings-title { margin: 0; font-size: 23px; font-weight: 650; letter-spacing: -.02em; }
.settings-body { padding: 20px 24px 8px; overflow-y: auto; }
.settings-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 24px 18px; border-top: 1px solid var(--glass-line);
}
.sgroup { margin-bottom: 26px; }
.sgroup > h4 {
  margin: 0 0 4px; font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--gold-dim); font-weight: 700;
}
.sgroup > .sdesc { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 14px; line-height: 1.6; }

.srow {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 12px 0; border-bottom: 1px solid var(--line-soft);
}
.srow:last-child { border-bottom: 0; }
.srow-info { min-width: 0; }
.srow-label { font-size: 14px; color: var(--ink); }
.srow-help { font-size: 12px; color: var(--ink-faint); margin-top: 3px; line-height: 1.55; }
.srow-control { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }

/* segmented control */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 11px;
       background: rgba(255,255,255,.04); border: 1px solid var(--line-soft); }
.seg button {
  background: none; border: 0; color: var(--ink-dim); font: inherit; font-size: 12.5px;
  padding: 6px 13px; border-radius: 8px; cursor: pointer; transition: .18s var(--ease);
  white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--gold); color: #0a0d12; font-weight: 650; }

/* switch */
.sw { position: relative; width: 46px; height: 26px; flex: 0 0 46px; cursor: pointer; display: block; }
.sw input {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%;
  margin: 0; cursor: pointer; z-index: 2;
}
.sw span {
  position: absolute; inset: 0; border-radius: 30px; background: rgba(255,255,255,.09);
  border: 1px solid var(--line); transition: .22s var(--ease);
  pointer-events: none;   /* the decorative track must not swallow the click */
}
.sw span::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--ink-faint); transition: .22s var(--ease-out);
}
.sw input:checked + span { background: rgba(224,184,120,.3); border-color: var(--gold-dim); }
.sw input:checked + span::after { transform: translateX(20px); background: var(--gold); }
.sw input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

/* range */
.srange { display: flex; align-items: center; gap: 12px; }
.srange input[type=range] {
  width: 168px; accent-color: var(--gold); cursor: pointer;
}
.srange .val { font-size: 12.5px; color: var(--ink-dim); font-variant-numeric: tabular-nums;
               min-width: 42px; text-align: right; }

/* reciter grid */
.reciter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(226px, 1fr)); gap: 9px; }
.reciter {
  display: flex; align-items: center; gap: 11px; text-align: left;
  background: rgba(255,255,255,.028); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 11px 13px; cursor: pointer;
  color: inherit; font: inherit; transition: .18s var(--ease);
}
.reciter:hover { background: rgba(255,255,255,.06); transform: translateY(-1px); }
.reciter.on {
  border-color: rgba(224,184,120,.5); background: rgba(224,184,120,.1);
  box-shadow: 0 4px 18px rgba(224,184,120,.1);
}
.reciter-radio {
  width: 17px; height: 17px; flex: 0 0 17px; border-radius: 50%;
  border: 1.5px solid var(--line); display: grid; place-items: center;
}
.reciter.on .reciter-radio { border-color: var(--gold); }
.reciter.on .reciter-radio::after {
  content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--gold);
}
.reciter-meta { display: flex; flex-direction: column; min-width: 0; }
.reciter-ar { font-family: 'Amiri', serif; font-size: 17px; color: var(--ink); }
.reciter-en { font-size: 11px; color: var(--ink-faint); margin-top: 1px; }
.reciter-style {
  margin-inline-start: auto; font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--gold-dim); border: 1px solid var(--gold-dim); border-radius: 20px;
  padding: 2px 7px; flex: 0 0 auto;
}
.reciter-preview {
  flex: 0 0 auto; background: none; border: 1px solid var(--line); color: var(--teal);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 12px;
  display: grid; place-items: center; transition: .18s var(--ease);
}
.reciter-preview:hover { border-color: var(--teal); background: rgba(86,204,180,.1); }

/* mushaf theme swatches */
.themes { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-sw {
  width: 74px; border-radius: 10px; border: 1px solid var(--line-soft); cursor: pointer;
  padding: 8px 6px 7px; text-align: center; transition: .18s var(--ease); background: none;
  font: inherit;
}
.theme-sw:hover { transform: translateY(-2px); }
.theme-sw.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.theme-chip { display: block; height: 34px; border-radius: 6px; margin-bottom: 7px;
              border: 1px solid rgba(0,0,0,.3); }
.theme-name { font-size: 10.5px; color: var(--ink-dim); }

/* ------------------------------------------------- charts (hand-rolled SVG) */
.chart { width: 100%; max-width: 760px; }
.chart h4 { margin: 0 0 4px; }
.chart-note { font-size: 11.5px; color: var(--ink-faint); margin-bottom: 12px; line-height: 1.6; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 6px 0;
            min-width: 0; }
.bar-label { flex: 0 0 128px; font-size: 12.5px; color: var(--ink-dim);
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 21px; background: rgba(255,255,255,.045);
             border-radius: 6px; overflow: hidden; position: relative; }
.bar-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  transition: width .6s var(--ease-out);
}
.bar-fill.teal { background: linear-gradient(90deg, #2c6f61, var(--teal)); }
.bar-fill.violet { background: linear-gradient(90deg, #5b4a8c, #a58cf0); }
.bar-value { flex: 0 0 54px; text-align: right; font-size: 12.5px;
             color: var(--ink); font-variant-numeric: tabular-nums; }
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-legend { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.donut-legend span { color: var(--ink-dim); display: flex; align-items: center; gap: 8px; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }
.donut-legend b { color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; }
.kpi {
  background: rgba(255,255,255,.03); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 13px 14px;
}
.kpi .v { font-size: 23px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
          color: var(--ink-faint); margin-top: 4px; }
.kpi.gold .v { color: var(--gold); }
.kpi.teal .v { color: var(--teal); }

/* ---------------------------------------------------------- chat panel */
.chat-wrap { display: flex; flex-direction: column; height: min(62vh, 620px); }
.chat-log { flex: 1; overflow-y: auto; padding-right: 6px; margin-bottom: 14px; }
.msg { margin-bottom: 16px; display: flex; gap: 12px; }
.msg-user { justify-content: flex-end; }
.bubble {
  max-width: 84%; padding: 12px 15px; border-radius: var(--r-md);
  font-size: 13.5px; line-height: 1.68; white-space: pre-wrap; word-break: break-word;
}
.msg-user .bubble {
  background: linear-gradient(135deg, rgba(224,184,120,.2), rgba(224,184,120,.1));
  border: 1px solid rgba(224,184,120,.28); color: var(--ink);
}
.msg-ai .bubble {
  background: rgba(255,255,255,.035); border: 1px solid var(--line-soft);
  color: var(--ink-dim);
}
.msg-ai .bubble b { color: var(--ink); }
.avatar {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 9px; display: grid;
  place-items: center; font-size: 11px; font-weight: 700;
  background: rgba(255,255,255,.05); border: 1px solid var(--line-soft);
  color: var(--ink-faint);
}
.msg-ai .avatar { color: var(--gold); border-color: var(--gold-dim); background: rgba(224,184,120,.09); }
.trace {
  margin-top: 10px; border-top: 1px solid var(--line-soft); padding-top: 9px;
  font-size: 11.5px; color: var(--ink-faint);
}
.trace summary { cursor: pointer; color: var(--ink-faint); }
.trace summary:hover { color: var(--ink-dim); }
.trace-row { padding: 5px 0; font-family: ui-monospace, monospace; font-size: 11px;
             color: var(--ink-dim); word-break: break-all; }
.trace-row .tname { color: var(--teal); }
.suggest { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.suggest button {
  background: rgba(255,255,255,.04); border: 1px solid var(--line-soft);
  color: var(--ink-dim); border-radius: 30px; padding: 7px 13px; font: inherit;
  font-size: 12.5px; cursor: pointer; transition: .16s var(--ease);
}
.suggest button:hover { border-color: var(--gold-dim); color: var(--gold); }
.chat-input { display: flex; gap: 10px; align-items: flex-end; }
.chat-input textarea {
  flex: 1; resize: none; min-height: 46px; max-height: 130px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  color: var(--ink); border-radius: var(--r-md); padding: 13px 15px;
  font: inherit; font-size: 14px; line-height: 1.5;
}
.chat-input textarea:focus { outline: none; border-color: var(--gold-dim); }
.chat-input button {
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  border: 0; color: #0a0d12; border-radius: var(--r-md); padding: 0 20px;
  height: 46px; font: inherit; font-size: 14px; font-weight: 650; cursor: pointer;
}
.chat-input button:disabled { opacity: .45; cursor: default; }
.thinking { color: var(--ink-faint); font-size: 12.5px; padding: 8px 0; }
.thinking i {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--gold); margin-right: 4px; animation: blip 1.1s infinite;
}
.thinking i:nth-child(2) { animation-delay: .16s; }
.thinking i:nth-child(3) { animation-delay: .32s; }
@keyframes blip { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }
.ai-off {
  background: rgba(232,128,122,.08); border: 1px solid rgba(232,128,122,.28);
  border-radius: var(--r-md); padding: 13px 16px; font-size: 13px; color: var(--ink-dim);
}
.tab-ai { color: var(--violet) !important; }
.tab-ai.active { color: var(--violet) !important; }

/* ask button */
.ask-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  color: #0a0d12; border: 0; border-radius: 30px; padding: 12px 19px 12px 16px;
  font: inherit; font-size: 13.5px; font-weight: 650; cursor: pointer;
  box-shadow: 0 12px 34px rgba(224,184,120,.3);
  transition: .2s var(--ease);
}
.ask-fab:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(224,184,120,.42); }
.ask-fab.hidden { display: none; }

/* letter strip inside the Word tab: one chip per glyph */
.lstrip { display: flex; flex-wrap: wrap; gap: 6px; direction: rtl; }
.lchip {
  font-family: 'Amiri Quran', 'Amiri', serif; font-size: 24px; line-height: 1.4;
  min-width: 38px; padding: 3px 8px; border-radius: 9px; cursor: pointer;
  background: rgba(255,255,255,.05); border: 1px solid var(--line-soft);
  color: var(--ink); transition: .16s var(--ease);
}
.lchip:hover { border-color: var(--gold-dim); background: rgba(224,184,120,.12); transform: translateY(-1px); }
.lchip.tj { border-bottom-width: 3px; border-bottom-style: solid; }

/* ------------------------------------------- settings-driven overrides */

/* mushaf text colour/size come from the active theme */
.ayah-line-text { color: var(--mushaf-ink, #1c1913); font-size: var(--mushaf-textsize, 26px); }
.mushaf-frame::before { border-color: var(--mushaf-rule, rgba(160,140,100,.3)); }
.surah-header { color: var(--mushaf-header, #7c6432); }
.ayah-ar { font-size: var(--ayah-textsize, 30px); }

/* tajweed colouring off -> fall back to plain ink */
.no-tajweed-colour .ltr.tj { color: inherit !important; border-bottom: 0; }

/* per-letter interaction off -> letters stop looking/behaving interactive */
.no-letter-spans .ltr { cursor: inherit; }
.no-letter-spans .ltr:hover { background: none; }

/* content toggles */
.no-translations .ayah-tr { display: none; }
.no-tafsir .ayah-tf { display: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1e2734; border-radius: 6px;
                           border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #2f3d4f; background-clip: content-box; }

/* ============================================================== responsive
 *
 * Breakpoints follow the content, not device presets: the rail stops fitting
 * beside the reader around 1000px, the five-tab modal needs 720px of labels,
 * and the mushaf page needs 520px to hold 15 justified lines without breaking.
 * Touch targets get larger, not smaller, as the viewport shrinks.
 */

/* =========================================================== āyah cards
 *
 * A 3D card deck as an alternative to the āyah list. The list stays available:
 * some tasks (scanning a whole surah) are genuinely better as a list, and the
 * card metaphor is for reading one āyah closely.
 *
 * Interaction model:
 *   - swipe left/right slides to the previous/next āyah (carousel)
 *   - tap the card flips it in 3D to its back
 *   - buttons/links on the card do NOT flip it (the tap handler ignores them)
 *
 * The deck is transform-based, so it does not need a scroll container or a
 * gesture library. Only the active card holds real content; the rest are
 * shallow (index + ref) until visited, which is what keeps a 286-āyah surah
 * from loading 286 full cards at once.
 */

.cards-wrap { margin-top: 6px; max-width: 760px; margin-inline: auto; }

/* with the deck on screen the āyah is the subject, so the surah-wide trend
 * compacts instead of pushing the deck and its controls below the fold */
/* In cards mode the deck is the subject, so the surah-wide trend yields its
 * vertical space: a taller card is worth more than a small chart above it. The
 * numbers stay, the chart goes. */
#view-surah.cards-mode .inline-trend { padding: 10px 14px; margin-bottom: 10px; }
#view-surah.cards-mode .inline-trend h4 { margin-bottom: 4px; }
#view-surah.cards-mode .inline-trend .chart { display: none; }
#view-surah.cards-mode .inline-trend .chart-note { margin-top: 0; font-size: 11.5px; }
#view-surah.cards-mode .reader-head { margin-bottom: 10px; }
#view-surah.cards-mode .reader-head h1 { font-size: 22px; }
.cards-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 0 0 16px;
}
.acard-pos { font-size: 12.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.acard-pos b { color: var(--gold); }
.cards-legend { font-size: 11.5px; color: var(--ink-faint); margin-left: auto; }

/* The deck sets its own readable width. A full-bleed card is 1000px+ on a
 * desktop, which is an uncomfortable measure for a single āyah and also squashes
 * the stacked neighbours almost entirely behind it. */
.deck {
  position: relative;
  width: min(100%, 660px); margin: 0 auto 14px;
  height: clamp(380px, 54vh, 560px);
  perspective: 1800px; perspective-origin: 50% 42%;
  touch-action: pan-y;   /* let vertical scroll through */
}
.deck-hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--ink-faint); font-size: 13px; pointer-events: none;
}

.acard {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.22,.8,.24,1), opacity .4s var(--ease);
  will-change: transform;
  cursor: pointer;
}
/* Depth. Offsets are fractions of the CARD (percentages of its own width in a
 * translate3d), not of the container, so a neighbour peeks out by a third of a
 * card at every size and stays clickable. */
/* z-index is explicit because cards are appended in āyah order: without it a
 * later āyah that is only a hidden "far" card would paint above the active one
 * and intercept its clicks. */
.acard[data-pos="0"]   { transform: translate3d(0,0,0) rotateY(var(--flip,0deg)); z-index: 3; }
.acard[data-pos="1"]   { transform: translate3d(15%,-3%,-80px) rotateY(var(--flip,0deg)); opacity: .5; z-index: 2; }
.acard[data-pos="-1"]  { transform: translate3d(-15%,-3%,-80px) rotateY(var(--flip,0deg)); opacity: .5; z-index: 2; }
.acard[data-pos="2"]   { transform: translate3d(26%,-6%,-170px) rotateY(var(--flip,0deg)); opacity: .26; z-index: 1; }
.acard[data-pos="-2"]  { transform: translate3d(-26%,-6%,-170px) rotateY(var(--flip,0deg)); opacity: .26; z-index: 1; }
/* invisible depth: not painted, not interactive */
.acard[data-pos="far"] { transform: translate3d(0,-9%,-260px) rotateY(var(--flip,0deg));
                         opacity: 0; z-index: 0; pointer-events: none; }
.acard.flipped { --flip: 180deg; }

/* during a drag the card follows the finger, no transition */
.acard.dragging { transition: none; }
.acard.leaving-left  { transform: translate3d(-120%,0,-60px) rotateZ(-8deg) !important; opacity: 0; }
.acard.leaving-right { transform: translate3d(120%,0,-60px) rotateZ(8deg) !important; opacity: 0; }

.acard-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--r-xl);
  border: 1px solid var(--line);
  padding: 30px 32px;
  display: flex; flex-direction: column;
  background:
    radial-gradient(120% 80% at 80% 0%, rgba(224,184,120,.10), transparent 60%),
    linear-gradient(160deg, rgba(255,255,255,.055), rgba(255,255,255,.012));
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: 0 26px 60px -20px rgba(0,0,0,.7), 0 2px 0 rgba(255,255,255,.04) inset;
  overflow: hidden;
}
.acard-face.back { transform: rotateY(180deg); }
/* the face turned away must not accept taps (backface-visibility hides it, but
 * it still receives pointer events in some engines) */
.acard:not(.flipped) .acard-face.back,
.acard.flipped .acard-face.front { pointer-events: none; }

/* the āyah reference, top of both faces */
.acard-ref {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px;
  font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums;
}
.acard-ref .n { color: var(--gold); font-size: 15px; font-weight: 700; }
.acard-ref .spacer { margin-left: auto; }
.acard-ref .sajda { color: var(--gold); }

/* ---- front: the Arabic ---- */
.acard-ar {
  flex: 1 1 auto; min-height: 0; min-width: 0;
  /* Vertical flex so the text block can be centred, but with exactly ONE child
   * (the .ar-line wrapper). A flex container holding all the word spans would
   * make each word a flex item, which is what broke the wrapping: words broke
   * individually instead of the āyah reflowing as running text. */
  display: flex; flex-direction: column; justify-content: center;
  font-family: 'Amiri Quran', 'Amiri', serif;
  font-size: calc(var(--ayah-textsize, 30px) * 1.12);
  line-height: 2.15; direction: rtl; text-align: center;
  padding: 6px 4px; overflow-y: auto; overflow-x: hidden;
}

/* The āyah as running text: a single block, so the inline word spans wrap
 * together across lines the way Arabic is meant to. */
.acard-ar .ar-line {
  display: block; width: 100%;
  /* `balance` gives ragged lines on a long āyah; `pretty` reflows better */
  text-wrap: pretty;
  word-break: normal;      /* never split a word across lines */
  hyphens: none;
  overflow-wrap: break-word;
}

.acard-ar .w {
  display: inline;         /* running text, not a box */
  cursor: pointer; border-radius: 6px; padding: 0 3px;
  transition: .14s var(--ease);
  white-space: nowrap;     /* a clickable word stays whole */
}
.acard-ar .w { cursor: pointer; border-radius: 6px; padding: 0 3px; transition: .14s var(--ease); }
.acard-ar .w:hover { background: rgba(224,184,120,.18); }
.acard-ar .w.sel { background: var(--gold); color: #0a0d12; }

/* ---- back: translation + real counts ---- */
.acard-back-body {
  flex: 1 1 auto; min-height: 0; min-width: 0;
  overflow-y: auto; overflow-x: hidden; padding-right: 6px;
  overflow-wrap: anywhere; word-break: break-word;
  /* long translations and tafsir must wrap inside the card */
  hyphens: auto;
  scrollbar-width: thin;
}
.acard-back-body .bt {
  font-size: 15px; color: var(--ink-dim); line-height: 1.7; margin-bottom: 8px;
  max-width: 100%; overflow-wrap: anywhere;
}
.acard-back-body .bt.de { color: var(--ink-faint); font-size: 14px; }
.acard-back-body .btf {
  font-size: 14px; color: var(--ink-dim); line-height: 1.9; direction: rtl;
  text-align: right; font-family: 'Amiri', serif; margin-top: 8px;
  overflow-wrap: anywhere;
}
.acard-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 8px; margin: 0 0 4px;
}
.acard-stat {
  background: rgba(255,255,255,.035); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 10px 12px;
}
.acard-stat b { display: block; font-size: 19px; color: var(--ink); font-variant-numeric: tabular-nums; }
.acard-stat span { font-size: 10.5px; color: var(--ink-faint); letter-spacing: .05em; text-transform: uppercase; }
.acard-roots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.acard-roots .r {
  font-family: 'Amiri', serif; font-size: 16px; cursor: pointer;
  background: rgba(255,255,255,.05); border: 1px solid var(--line-soft);
  border-radius: 16px; padding: 3px 11px; transition: .15s var(--ease);
}
.acard-roots .r:hover { background: rgba(224,184,120,.16); color: #fff; }
.acard-roots .r b { font-family: inherit; font-size: 11px; opacity: .75; margin-left: 4px; }

/* ---- corpus ML figures in the Insights view ---- */
.ml-figs {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px; margin-top: 12px;
}
.ml-fig { margin: 0; }
.ml-fig.wide { grid-column: 1 / -1; max-width: 760px; }
.ml-fig img {
  width: 100%; height: auto; display: block;
  border-radius: var(--r-md); border: 1px solid var(--line-soft);
  background: #0b0e13;
}
.ml-fig figcaption {
  font-size: 11px; color: var(--ink-faint); margin-top: 6px; letter-spacing: .02em;
}
.ml-interactive { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }

/* ================================================== card-back tables
 *
 * The back face presents everything as HTML tables: one row per fact, so the
 * reader scans a column instead of hunting through prose, and the layout cannot
 * break when a value is long. Charts stay as figures — a graph is not tabular
 * data — and are the only non-table elements.
 */
.acard-back-body .t {
  width: 100%; border-collapse: collapse; margin: 0 0 14px;
  font-size: 12px; table-layout: auto;
}
.acard-back-body .t caption {
  caption-side: top; text-align: left;
  font-size: 10px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700;
  padding: 0 0 6px;
}
.acard-back-body .t thead th {
  text-align: left; font-weight: 600; font-size: 10.5px;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-faint); padding: 5px 8px 5px 0;
  border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
.acard-back-body .t td {
  padding: 6px 8px 6px 0; vertical-align: top;
  border-bottom: 1px solid rgba(255,255,255,.045);
  color: var(--ink-dim); line-height: 1.6;
}
.acard-back-body .t tbody tr:last-child td { border-bottom: 0; }
.acard-back-body .t td.hi { color: var(--gold); font-weight: 650;
                            font-variant-numeric: tabular-nums; }
.acard-back-body .t td.num, .acard-back-body .t th.num {
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.acard-back-body .t td.ar { font-family: 'Amiri', serif; font-size: 15px; }
.acard-back-body .t td.ar-hi {
  font-family: 'Amiri Quran', 'Amiri', serif; font-size: 17px; color: var(--ink);
}
.acard-back-body .t td.note { font-size: 11.5px; color: var(--ink-faint); }
.acard-back-body .t td.src {
  font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint); white-space: nowrap; padding-right: 12px;
}
.acard-back-body .t .of { color: var(--ink-faint); font-size: 10px; }
.acard-back-body .t tr.degen { opacity: .62; }
/* long prose cells must wrap inside the column, never widen the table */
.acard-back-body .t td.note, .acard-back-body .t td.ar {
  overflow-wrap: anywhere; word-break: break-word;
}
.acard-back-body .t td:first-child { white-space: nowrap; }
.acard-back-body .t td.note:first-child,
.acard-back-body .t td.ar:first-child { white-space: normal; }

.acard-back-body .lnk {
  font: inherit; font-size: 11.5px; color: var(--gold); background: none;
  border: 1px solid var(--line-soft); border-radius: 11px;
  padding: 2px 9px; cursor: pointer; white-space: nowrap;
  transition: .15s var(--ease);
}
.acard-back-body .lnk:hover { background: rgba(224,184,120,.15); }
.acard-back-body h5.chart-h {
  margin: 16px 0 8px; font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-faint); font-weight: 700;
}

/* On a phone the six-column morphology table cannot fit: drop to the columns
   that answer "what is this word and where is it from". */
@media (max-width: 720px) {
  .acard-back-body .t { font-size: 11.5px; }
  .acard-back-body .t td, .acard-back-body .t thead th { padding-right: 6px; }
  .acard-back-body .words-t td:nth-child(5),
  .acard-back-body .words-t td:nth-child(6),
  .acard-back-body .words-t th:nth-child(5),
  .acard-back-body .words-t th:nth-child(6) { display: none; }
}

/* ---- ML read-out on the card back ---- */
.ml-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 8px; margin-bottom: 10px;
}
.ml-cell {
  background: rgba(124,108,240,.10); border: 1px solid rgba(124,108,240,.28);
  border-radius: var(--r-md); padding: 8px 9px; text-align: center;
}
.ml-cell b { display: block; font-size: 16px; color: #cfc7ff;
             font-variant-numeric: tabular-nums; }
.ml-cell span {
  font-size: 9.5px; color: var(--ink-faint); letter-spacing: .04em;
  text-transform: uppercase; white-space: nowrap;
}
.ml-chart { margin: 10px 0 4px; min-height: 150px; }
.ml-chart .js-plotly-plot { border-radius: var(--r-md); overflow: hidden; }
.ml-sim { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.ml-sim-row {
  display: grid; grid-template-columns: 62px 1fr 40px auto; gap: 8px;
  align-items: center; font-size: 11.5px;
}
.ml-ref {
  font: inherit; font-size: 11.5px; color: var(--gold); background: none;
  border: 1px solid var(--line-soft); border-radius: 11px; padding: 3px 7px;
  cursor: pointer; font-variant-numeric: tabular-nums; transition: .15s var(--ease);
}
.ml-ref:hover { background: rgba(224,184,120,.14); }
.ml-bar { height: 6px; background: rgba(255,255,255,.07); border-radius: 3px; overflow: hidden; }
.ml-bar i { display: block; height: 100%; background: #5fd0c0; border-radius: 3px; }
.ml-num { font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.ml-shared { font-family: 'Amiri', serif; font-size: 13px; color: var(--ink-faint);
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- pattern relations: shown WITH their significance ---- */
.pat-row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 12px;
}
.pat-row:last-child { border-bottom: 0; }
.pat-row.degen { opacity: .62; }
.pat-label { color: var(--ink-dim); }
.pat-q { color: var(--gold); font-variant-numeric: tabular-nums; font-size: 11px; }
.pat-verdict { grid-column: 1 / -1; font-size: 11px; color: var(--ink-faint); line-height: 1.5; }

/* ---- every word: morphology table (was the Word tab) ---- */
.wtable { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.wrow {
  display: grid; grid-template-columns: 1.2fr .8fr .7fr 1fr 1.2fr;
  gap: 6px; align-items: baseline; padding: 5px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 11.5px;
}
.wrow:last-child { border-bottom: 0; }
.wcell-ar { font-family: 'Amiri', serif; font-size: 16px; color: var(--ink); }
.wcell-root { font-family: 'Amiri', serif; font-size: 14px; color: var(--gold); }
.wcell-pos { font-family: 'Amiri', serif; font-size: 13px; color: var(--ink-dim); }
.wcell-lem { font-family: 'Amiri', serif; font-size: 13px; color: var(--ink-faint); }
.wcell-feats { font-size: 10px; color: var(--ink-faint); letter-spacing: .02em; }
@media (max-width: 720px) {
  .wrow { grid-template-columns: 1fr 1fr 1fr; }
  .wcell-lem, .wcell-feats { display: none; }
  .ml-sim-row { grid-template-columns: 54px 1fr 36px; }
  .ml-shared { display: none; }
}

/* collapsible long lists on the back face */
.acard-more { margin-top: 8px; }
.acard-more summary {
  cursor: pointer; font-size: 11.5px; color: var(--gold);
  padding: 4px 0; list-style: none;
}
.acard-more summary::-webkit-details-marker { display: none; }
.acard-more summary::before { content: '▸ '; }
.acard-more[open] summary::before { content: '▾ '; }
.taj-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.taj-item { display: grid; grid-template-columns: 34px 1fr; gap: 6px; font-size: 11.5px; }
.taj-slice { font-family: 'Amiri Quran', serif; font-size: 18px; color: var(--gold); }
.taj-rule { font-family: 'Amiri', serif; font-size: 14px; color: var(--ink-dim); }
.taj-info { grid-column: 2; font-size: 11px; color: var(--ink-faint); line-height: 1.5; }
.chart-note.muted { opacity: .75; font-style: italic; }

/* back-face statistics: headings, chips, position grid, percentile line */
.acard-back-body h5 {
  margin: 16px 0 8px; font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-faint); font-weight: 700;
}
.acard-back-body h5 .dim { letter-spacing: 0; text-transform: none; font-weight: 400; }
.acard-pct {
  margin: 12px 0 2px; padding: 10px 13px; font-size: 12.5px; line-height: 1.6;
  color: var(--ink-dim); background: rgba(224,184,120,.07);
  border: 1px solid rgba(224,184,120,.18); border-radius: var(--r-md);
}
.acard-pct b { color: var(--gold); }

.acard-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.acard-chips .tchip, .acard-chips .pchip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--ink-dim);
  background: rgba(255,255,255,.045); border: 1px solid var(--line-soft);
  border-radius: 14px; padding: 4px 10px; white-space: nowrap;
}
.acard-chips .pchip { font-family: 'Amiri', serif; font-size: 14px; }
.acard-chips .tchip b, .acard-chips .pchip b {
  font-family: inherit; color: var(--gold); font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.posgrid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(74px, 1fr)); gap: 8px;
}
.poscell {
  background: rgba(255,255,255,.035); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 8px 9px; text-align: center;
}
.poscell b { font-size: 16px; font-variant-numeric: tabular-nums; }
.poscell .of { font-size: 10.5px; color: var(--ink-faint); }
.poscell .lbl {
  display: block; font-size: 9.5px; color: var(--ink-faint);
  letter-spacing: .04em; text-transform: uppercase; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* the chart on the back face is a context shape, not a reading surface */
.acard-back-body .chart { margin: 0; }
.acard-back-body .chart svg { max-height: 96px; }

.acard-foot {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line-soft);
}
.acard-foot .dim { font-size: 11.5px; }

/* ---- deck controls ---- */
.deck-nav {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  flex-wrap: wrap;
  /* Sticky, because a taller card would otherwise push the controls below the
   * fold. They stay reachable at any card height without shrinking the card. */
  position: sticky; bottom: 0; z-index: 6;
  padding: 10px 8px 12px; margin-top: 4px;
  background: linear-gradient(180deg, rgba(8,11,16,0), rgba(6,8,12,.92) 42%);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.deck-nav .dnav {
  min-height: 44px; min-width: 44px; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; padding: 8px 16px;
  background: rgba(255,255,255,.045); border: 1px solid var(--line-soft);
  color: var(--ink-dim); border-radius: 22px; font: inherit; font-size: 13px;
  cursor: pointer; transition: .16s var(--ease);
}
.deck-nav .dnav:hover:not(:disabled) { background: rgba(224,184,120,.14); color: #fff; }
.deck-nav .dnav:disabled { opacity: .35; cursor: default; }
.deck-scrub { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-faint); }
.deck-scrub input[type=range] { width: 168px; accent-color: var(--gold); }

/* ---- list | cards toggle in the reader head ---- */
.viewtoggle {
  display: inline-flex; background: rgba(255,255,255,.04);
  border: 1px solid var(--line-soft); border-radius: 20px; padding: 3px; gap: 2px;
}
.viewtoggle button {
  font: inherit; font-size: 12.5px; padding: 6px 14px; min-height: 32px;
  background: none; border: 0; color: var(--ink-faint); border-radius: 16px;
  cursor: pointer; transition: .16s var(--ease);
}
.viewtoggle button.on { background: rgba(224,184,120,.16); color: var(--gold); }

@media (max-width: 720px) {
  .deck { height: clamp(400px, 56vh, 520px); }
  .acard-face { padding: 20px 18px; border-radius: var(--r-lg); }
  .acard-ar { font-size: calc(var(--ayah-textsize, 30px) * .88); line-height: 2; }
  .deck { width: 100%; }
  /* on a phone the neighbours peek only slightly, so the active card keeps its
   * full width for the Arabic */
  .acard[data-pos="1"]   { transform: translate3d(9%,-3%,-60px) rotateY(var(--flip,0deg)); opacity: .4; }
  .acard[data-pos="-1"]  { transform: translate3d(-9%,-3%,-60px) rotateY(var(--flip,0deg)); opacity: .4; }
  .acard[data-pos="2"]   { transform: translate3d(15%,-6%,-130px) rotateY(var(--flip,0deg)); opacity: .18; }
  .acard[data-pos="-2"]  { transform: translate3d(-15%,-6%,-130px) rotateY(var(--flip,0deg)); opacity: .18; }
  .acard-stat b { font-size: 17px; }
  .deck-scrub input[type=range] { width: 108px; }
  .cards-legend { display: none; }
  .deck-nav .dnav { padding: 8px 13px; }
  /* clear the fixed bottom tab bar on a phone */
  .deck-nav { bottom: calc(58px + env(safe-area-inset-bottom)); padding-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .acard { transition: none; }
}

/* page-level stats strip under the mushaf */
.pagestats {
  display: flex; flex-wrap: wrap; gap: 7px; justify-content: center;
  align-items: center; padding: 10px 16px 4px; max-width: 900px; margin: 0 auto;
}
.ps-item {
  font-size: 11.5px; color: var(--ink-faint); background: rgba(255,255,255,.035);
  border: 1px solid var(--line-soft); border-radius: 20px; padding: 4px 11px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ps-item b { color: var(--ink-dim); font-weight: 650; }
.ps-more {
  font: inherit; font-size: 11.5px; color: var(--gold); background: none;
  border: 1px solid var(--gold-dim); border-radius: 20px; padding: 4px 12px;
  cursor: pointer; transition: .16s var(--ease);
}
.ps-more:hover { background: rgba(224,184,120,.1); }

/* inline trend card inside the surah reader */
.inline-trend { margin-bottom: 22px; }
.inline-trend .chart svg { max-height: 150px; }
.linkish { color: var(--gold); text-decoration: none; border-bottom: 1px dotted var(--gold-dim); }

/* bottom tab bar: hidden on desktop, the primary nav on touch */
.tabbar { display: none; }

/* ---- tablet: the rail stops fitting beside the reader ---- */
@media (max-width: 1000px) {
  .rail { width: 208px; flex: 0 0 208px; }
  .rail.narrow { width: 150px; flex: 0 0 150px; }
  .reader { padding: 22px 20px 70px; }
  .mushaf-stage { padding: 72px 16px 20px; }
  .mushaf-frame { padding: 26px 22px 22px; border-inline-width: 9px; }
  .modal-card { width: 96vw; }
  .grid2 { grid-template-columns: 1fr; }
  .chart { max-width: 100%; }
}

/* ---- phone: single column, bottom nav, sheet-style modal ---- */
@media (max-width: 720px) {
  html, body { font-size: 15px; }

  /* chrome: compress the top bar, the tab bar takes over navigation */
  .topbar { height: 54px; flex: 0 0 54px; padding: 0 12px; gap: 10px; }
  .brand-text { display: none; }
  .brand-mark { width: 27px; height: 27px; }
  .modes { display: none; }
  .stats { display: none; }
  .cmd-trigger { margin-inline-start: auto; }
  .cmd-trigger span { display: none; }          /* icon only */
  .cmd-trigger kbd { display: none; }
  .cmd-trigger { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; }
  #settings-open { width: 44px; height: 44px; }

  /* the tab bar is the navigation now */
  .tabbar {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 55;
    background: linear-gradient(180deg, rgba(8,11,16,.86), rgba(5,7,11,.97));
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    border-top: 1px solid var(--line-soft);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: 0; color: var(--ink-faint); font: inherit;
    font-size: 10px; letter-spacing: .02em; padding: 7px 2px 5px;
    border-radius: 12px; cursor: pointer; min-height: 48px;   /* touch target */
    transition: color .18s var(--ease);
  }
  .tabbar button span { line-height: 1; }
  .tabbar button.on { color: var(--gold); background: rgba(224,184,120,.09); }
  .tabbar svg { flex: 0 0 auto; }

  /* keep room for the bar and the floating ask button */
  .stage { padding-bottom: 0; }
  .reader { padding: 18px 14px calc(84px + env(safe-area-inset-bottom)); }
  .mushaf-stage { padding: 64px 10px 12px; }
  .hint { padding: 4px 12px calc(70px + env(safe-area-inset-bottom)); font-size: 11px; }
  .pagestats { padding: 8px 10px 2px; gap: 5px; }

  /* pager becomes a compact floating bar */
  .pager { top: 10px; gap: 6px; padding: 5px 6px; border-radius: 16px; max-width: calc(100vw - 20px); }
  .pager-read input { width: 46px; font-size: 13px; padding: 4px; }
  .ghostbtn { font-size: 11.5px; padding: 5px 9px; }
  .iconbtn { width: 34px; height: 34px; }

  /* mushaf page: fit the width, keep the frame readable */
  .mushaf-frame {
    padding: 18px 14px 16px; border-inline-width: 6px; border-radius: 10px;
    width: 100%;
  }
  .mushaf-frame::before { inset: 5px; }
  .ayah-line-text { font-size: calc(var(--mushaf-textsize, 26px) * 0.72); line-height: 2.05; }
  .surah-header { font-size: 16px; padding: 3px 0; margin: 9px 0; }
  .basmala { font-size: 18px; margin: 5px 0 10px; }
  .mushaf-line { margin-bottom: 7px; min-height: 24px; }

  /* rails become horizontal scrollers instead of stealing column width */
  .view.active { flex-direction: column; }
  .rail {
    width: 100%; flex: 0 0 auto; max-height: 42vh; height: auto;
    border-inline-end: 0; border-bottom: 1px solid var(--line-soft);
    padding: 12px 12px 14px;
  }
  .rail.narrow { width: 100%; flex: 0 0 auto; }
  .rail-head { position: static; background: none; padding: 0 0 8px; }
  /* In cards mode the āyah is the focus, so the surah rail collapses to just its
   * filter: at 42vh it pushed the deck and its controls below the fold. This
   * must come AFTER the .rail rules above to win on source order. */
  #view-surah.cards-mode .rail { max-height: none; padding: 8px 12px; }
  #view-surah.cards-mode .rail #surah-list { display: none; }
  /* In cards mode the āyah is the subject. The surah chip wall and the trend
   * chart belong to the list experience and cost ~400px of a phone viewport,
   * which pushed the deck's controls off screen. Collapse both, keeping the
   * trend's numbers because they are still worth reading. */
  #view-surah.cards-mode .reader-head .reader-sub { display: none; }
  #view-surah.cards-mode .reader-head { padding-bottom: 4px; }
  #view-surah.cards-mode .reader-head h1 { font-size: 19px; }
  #view-surah.cards-mode .inline-trend .chart { display: none; }
  #view-surah.cards-mode .inline-trend { padding: 10px 12px; }
  #view-surah.cards-mode .inline-trend .chart-note { margin-top: 0; }
  #view-surah.cards-mode .cards-toolbar { margin-bottom: 8px; }
  #view-surah.cards-mode .cards-legend { display: none !important; }
  .juz-list { grid-template-columns: repeat(6, 1fr); }
  .juz-list button { padding: 10px 2px; font-size: 13px; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }

  /* reader typography */
  .reader-head h1 { font-size: 21px; }
  .reader-head h1 .ar { font-size: 24px; margin-inline-start: 8px; }
  .ayah { grid-template-columns: 1fr; gap: 8px; padding: 16px 6px; }
  .ayah-no { flex-direction: row; gap: 10px; align-items: center; padding-top: 0; }
  .ayah-ar { font-size: calc(var(--ayah-textsize, 30px) * 0.74); line-height: 2; }
  .ayah-tr { font-size: 14px; }
  .ayah-tools { gap: 6px; }
  .tool { padding: 7px 11px; font-size: 12px; }   /* bigger tap area */

  /* modal becomes a bottom sheet filling most of the screen */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card {
    width: 100vw; max-width: 100vw; height: 94vh; max-height: 94vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-head { padding: 16px 16px 12px; gap: 12px; }
  .modal-title { font-size: 28px; }
  .modal-title.ltr { font-size: 18px; }
  .modal-sub { font-size: 11.5px; }
  .xbtn { width: 40px; height: 40px; }             /* easier to hit */

  /* Tab strip scrolls horizontally rather than squashing five labels. The
   * right-edge fade marks that there is more to scroll — without it a cut-off
   * tab just looks broken. */
  .mtabs {
    padding: 0 8px; overflow-x: auto; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 34px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 34px), transparent 100%);
  }
  /* once the last tab is reached the fade would obscure it, so drop it */
  .mtabs.at-end {
    -webkit-mask-image: none; mask-image: none;
  }
  .mtabs::-webkit-scrollbar { display: none; }
  .mtabs button { padding: 13px 12px; font-size: 13px; white-space: nowrap; }
  .mtabs-glider { display: none; }                 /* offset is unreliable when scrolling */
  .mtabs button.active { border-bottom: 2px solid var(--gold); }
  .modal-body { padding: 16px 16px 26px; }

  /* content inside the modal */
  .kv { grid-template-columns: 1fr; gap: 3px 0; }
  .kv dt { font-size: 11.5px; margin-top: 8px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .kpi .v { font-size: 20px; }
  .bar-label { flex: 0 0 88px; font-size: 12px; }
  .bar-value { flex: 0 0 46px; font-size: 12px; }
  .donut-wrap { gap: 14px; }
  .donut-wrap svg { width: 128px; height: 128px; }
  .occ-wrap { gap: 6px; }
  .lstrip { gap: 5px; }
  .lchip { font-size: 21px; min-width: 34px; padding: 3px 7px; }
  .chart svg { max-height: 220px; }
  .rel-stats { flex-wrap: wrap; gap: 10px; }
  .rel-label { font-size: 12px; }
  .claims-row { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* chat fills the sheet */
  .chat-wrap { height: calc(94vh - 210px); }
  .bubble { max-width: 92%; font-size: 13px; padding: 11px 13px; }
  .chat-input textarea { min-height: 44px; font-size: 16px; }  /* 16px stops iOS zoom */
  .chat-input button { height: 44px; padding: 0 16px; }
  .suggest button { font-size: 12px; padding: 8px 12px; }

  /* settings + command palette */
  .cmdk { padding-top: 6vh; }
  .cmdk-card, .settings-card {
    width: 100vw; max-width: 100vw; max-height: 88vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  .cmdk { align-items: flex-end; padding: 0; }
  .settings-body { padding: 16px 16px 8px; }
  .settings-head, .settings-foot { padding-inline: 16px; }
  .reciter-grid { grid-template-columns: 1fr; }
  .seg button { padding: 8px 12px; }               /* tap targets */
  .srow { flex-direction: column; align-items: flex-start; gap: 10px; }
  .srow-control { width: 100%; }
  .srange { width: 100%; }
  .srange input[type=range] { flex: 1; width: auto; }
  .sw { align-self: flex-start; }

  /* tooltip is useless on touch, and the ask button moves into the bar */
  .tooltip { display: none !important; }
  .ask-fab {
    right: 14px; bottom: calc(70px + env(safe-area-inset-bottom));
    padding: 12px 18px 12px 16px; font-size: 13px; min-height: 48px;
  }
  .sheet-panel { width: 96vw; padding: 16px; border-radius: var(--r-lg); }
}

/* ---- very small phones ---- */
@media (max-width: 400px) {
  .tabbar button { font-size: 9px; }
  .kpi-row { grid-template-columns: 1fr; }
  .modal-title { font-size: 24px; }
  .ayah-ar { font-size: calc(var(--ayah-textsize, 30px) * 0.66); }
  .ayah-line-text { font-size: calc(var(--mushaf-textsize, 26px) * 0.62); }
  .ask-fab span { display: none; }
  .ask-fab { padding: 0; width: 48px; height: 48px; border-radius: 50%;
             display: grid; place-items: center; }
}

/* ---- landscape phones: don't waste vertical space ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .tabbar { padding-block: 3px; }
  .tabbar button { min-height: 38px; font-size: 9px; gap: 1px; }
  .modal-card { height: 96vh; max-height: 96vh; }
  .chat-wrap { height: calc(96vh - 190px); }
  .topbar { height: 48px; flex: 0 0 48px; }
  .mushaf-stage { padding: 54px 14px 10px; }
  /* on a short landscape phone the statistics strip costs more than it gives */
  .pagestats { display: none; }
  .hint { padding: 2px 12px calc(60px + env(safe-area-inset-bottom)); font-size: 10.5px; }
}

/* touch devices: no hover affordances, and real tap targets.
 * 44px is the practical minimum for a comfortable thumb hit; the smallest
 * offenders measured were 24px (the inline stats link) and 30px (nav tabs). */
@media (hover: none), (pointer: coarse) {
  .ltr:hover, .mword:hover, .ayah-ar .w:hover { background: none; box-shadow: none; }
  .lchip:hover, .occ:hover, .surah-item:hover, .reciter:hover { transform: none; }
  .tool, .ghostbtn, .iconbtn, .seg button, .juz-list button,
  .ps-more, .ps-item, .tabbar button, .modes button, .mtabs button,
  .page-grid button, .occ, .lchip, .suggest button, .reciter, .theme-sw,
  .chat-input button, .xbtn, .filter, .pager-read input,
  .cmd-trigger, .ask-fab, #settings-open { min-height: 44px; }
  .iconbtn, .cmd-trigger, #settings-open { min-width: 44px; }
  .cmd-trigger { display: inline-flex; align-items: center; justify-content: center; }
  .ps-item, .ps-more { display: inline-flex; align-items: center; }
  .mtabs button { padding-block: 14px; }
  /* keep the inline stats link tappable without making the strip bulky */
  .ps-item, .ps-more { padding-block: 0; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .glow { animation: none; }
  .view.active, .modal-card, .cmdk-card, .settings-card, .sheet-panel { animation: none; }
  .modes-glider, .mtabs-glider, .bar-fill { transition: none; }
}
