@font-face { font-family: "QuranText"; src: url("fonts/quran-text.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "SurahNames"; src: url("fonts/sura_names.woff2") format("woff2"); font-display: swap; }
/* ─── the Tajweed Muṣḥaf ───
   beige manuscript world; color belongs to the tajweed alone. */

:root {
  --page: #ece3cd;
  --page-deep: #e3d7ba;
  --leaf: #faf5e7;
  --ink: #241c0e;
  --muted: #82755a;
  --line: #dcd0b2;
  --frame: #8a6d3b;
  --gold: #a8832f;
  --goldink: #7d5f1c; /* weave line-work: darker than --gold for contrast */
  --wbg8: color-mix(in srgb, var(--gold) 16%, var(--leaf)); /* beige ground behind the page-frame ribbons */
  --wbg5: #2e6349; /* green ground behind the surah-band ribbons */
  --accent: #175f58;
  --card: #fffdf4;
  --shadow: rgba(60, 42, 12, 0.22);
  --hover: rgba(138, 109, 59, 0.16);
}
/* night: deep navy world, gold accents */
[data-scheme="night"] {
  --page: #0b1220;
  --page-deep: #060b15;
  --leaf: #101b2c;
  --ink: #dfe7f2;
  --muted: #8ba0bc;
  --line: #24354e;
  --frame: #9aa9c4;
  --gold: #b9964a;
  --goldink: #d8b264;
  --wbg8: color-mix(in srgb, #3b598a 30%, var(--leaf));
  --wbg5: #1d4359;
  --accent: #5aa7d6;
  --card: #0d1626;
  --shadow: rgba(0, 0, 0, 0.6);
  --hover: rgba(122, 162, 210, 0.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, var(--page) 55%, var(--page-deep) 100%);
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: 14px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr) 300px;
  grid-template-rows: 100vh;
  height: 100vh;
}
@media (max-width: 1100px) {
  body { grid-template-columns: 190px minmax(0, 1fr) 260px; }
}
/* Arabic: rails swap sides — controls right, info panel left */
body.lang-ar { grid-template-columns: 300px minmax(0, 1fr) 224px; }
body.lang-ar #panel { grid-column: 1; grid-row: 1; border-left: none; border-right: 1px solid var(--line); }
body.lang-ar #stage { grid-column: 2; grid-row: 1; }
body.lang-ar #left { grid-column: 3; grid-row: 1; border-right: none; border-left: 1px solid var(--line); }
@media (max-width: 1100px) {
  body.lang-ar { grid-template-columns: 260px minmax(0, 1fr) 190px; }
}
.arf { font-family: "QuranText", "Scheherazade New", "Noto Naskh Arabic", serif; }
.snf { font-family: "SurahNames"; }

/* ── left rail ── */
#left {
  min-height: 0;
  display: flex; flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 16px 14px 12px;
  overflow-y: auto;
  gap: 14px;
}
#left .brand { display: flex; flex-direction: column; gap: 1px; }
#left .brand .arf { font-size: 24px; color: var(--accent); line-height: 1.5; }
#left .brand .en { font-size: 12px; color: var(--muted); letter-spacing: 0.05em; }
.langsw { display: flex; gap: 4px; margin-top: 8px; }
.langsw button {
  flex: 1; font-size: 11px; padding: 3px 0; cursor: pointer;
  background: var(--leaf); border: 1px solid var(--line); border-radius: 5px; color: var(--muted);
}
.langsw button.on { background: var(--accent); border-color: var(--accent); color: var(--leaf); }
#left .controls { display: flex; flex-direction: column; gap: 10px; }
.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.ctl select, .ctl input, .ctl button {
  font-family: Georgia, serif; font-size: 13px; color: var(--ink);
  background: var(--leaf); border: 1px solid var(--line); border-radius: 5px;
  padding: 5px 8px; text-transform: none; letter-spacing: normal;
}
.ctl button { cursor: pointer; }
#pageno { width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.pagenav { display: inline-flex; align-items: center; gap: 4px; }
.mode { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; width: max-content; }
.mode button { border: 0 !important; border-radius: 0 !important; }
.mode button.on { background: var(--accent); color: #fbf6e8; }
#left .spacer { flex: 1; }

#legend { border-top: 1px solid var(--line); padding-top: 10px; }
#legend .ltitle { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 6px; }
#legend-body { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
#legend-body .li { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
#legend-body .sw { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

#credits { font-size: 10px; color: var(--muted); line-height: 1.5; border-top: 1px solid var(--line); padding-top: 8px; }
#credits strong { color: var(--accent); font-weight: 600; }

/* ── stage & spread ── */
#stage {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  gap: 0; padding: 0;
  min-width: 0; min-height: 0; overflow: hidden;
}
#spread { display: flex; flex-direction: row; gap: 0; align-items: center; }
/* the fold between the two pages */
.leaf.pos-left::after, .leaf.pos-right::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 7%;
  pointer-events: none; z-index: 5;
}
.leaf.pos-left::after { right: 0; background: linear-gradient(to left, rgba(60, 42, 12, 0.16), transparent 85%); }
.leaf.pos-right::after { left: 0; background: linear-gradient(to right, rgba(60, 42, 12, 0.16), transparent 85%); }
.leaf.pos-left { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.leaf.pos-right { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.edge-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 25; width: 38px; height: 84px;
  font-size: 30px; line-height: 1; color: var(--muted);
  background: color-mix(in srgb, var(--leaf) 70%, transparent);
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.edge-nav:hover { color: var(--accent); background: var(--leaf); }
#nav-left { left: 6px; }
#nav-right { right: 6px; }

/* ── the leaf ── */
.leaf {
  position: relative;
  background: var(--leaf);
  border-radius: 6px;
  box-shadow: 0 6px 26px var(--shadow);
}
.leaf .border-art { position: absolute; inset: 0; pointer-events: none; }
.leaf .border-art svg { opacity: 0.95; overflow: hidden; }
.brule { position: absolute; border: 1px solid var(--gold); pointer-events: none; }
.brule.in { border-color: color-mix(in srgb, var(--gold) 88%, transparent); }
.leaf .content {
  position: absolute;
  display: flex; flex-direction: column;
}
.leaf .pghead {
  display: flex; justify-content: space-between; align-items: baseline;
  direction: rtl; color: var(--frame);
}
.leaf .pgfoot {
  position: absolute; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--frame); z-index: 6; pointer-events: none; line-height: 1;
}
.leaf .pgfoot svg { position: absolute; }
.leaf .pgfoot span {
  position: relative;
  /* lining figures — Georgia's old-style digits each sit at a different
     height (7 descends, 8 ascends), so no single nudge centers them */
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  font-variant-numeric: lining-nums;
}
.leaf .textblock { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; }

.gline { display: flex; justify-content: flex-start; gap: 0.2em; direction: rtl; align-items: baseline; margin-inline: 2%; }
.gline.just { justify-content: space-between; gap: 0; }
.gline.basline { gap: 0.02em; }
/* extra breathing room after waqf-letter marks, as the print does */
.gword.gspace { margin-left: 0.3em; }
.gline.gcenter { justify-content: center; }
.leaf.ornate .gline { justify-content: center; width: 66%; margin: 0 auto; }
.leaf.ornate .basmalah { width: 66%; margin: 0 auto; }
.leaf.ornate .textblock { justify-content: flex-start; }
.ornate-center { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-top: 4%; }
.gword { white-space: nowrap; border-radius: 3px; }
.gword.ghit { cursor: pointer; }
.gword.ghit:hover { background: var(--hover); }
.gword.sel { background: var(--hover); box-shadow: 0 2px 0 var(--accent); }

.surah-band {
  position: relative; overflow: hidden;
  direction: rtl; display: flex; justify-content: center; align-items: center;
  font-family: "SurahNames"; font-weight: normal;
  color: var(--frame);
  border-block: 1px solid var(--gold);
  margin-top: 0.32em;
}
/* the band text is glyph codes in the SurahNames font — hide the raw
   fallback ("surah 001") until the font is actually loaded */
.surah-band .cartouche span { visibility: hidden; }
html.sn-ready .surah-band .cartouche span { visibility: visible; }
.surah-band .cartouche {
  position: relative; display: inline-flex; align-items: center; gap: 0.16em;
  background: var(--leaf); border: 1px solid var(--gold); border-radius: 999px;
  padding: 0.04em 0.75em 0.1em;
}
.basmalah { text-align: center; direction: rtl; margin-inline: 2%; }

/* engine-colored text view */
.tline { direction: rtl; text-align: justify; margin-inline: 2%; }
.word { cursor: pointer; border-radius: 3px; }
.word:hover { background: var(--hover); }
.word.sel { background: var(--hover); box-shadow: 0 2px 0 var(--accent); }
.ayah-num {
  position: relative; display: inline-block; direction: rtl;
  font-size: 0.9em; line-height: 1; margin: 0 0.12em; color: var(--gold); user-select: none;
}
.ayah-num .n {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.34em; color: var(--frame); padding-bottom: 0.35em;
}
.wmark { color: var(--accent); font-size: 0.6em; vertical-align: super; margin: 0 0.1em; }

/* engine-view rule family colors */
.f-ghunnah { color: #177a43; }
.f-gray { color: #948b76; }
.f-tafkhim { color: #2b52a8; }
.f-qalq { color: #0e9db5; }
.f-madd2 { color: #d07f10; }
.f-madd45 { color: #c3273c; }
.f-madd6 { color: #7c1322; }
.f-perf { color: #7d4a9e; }
[data-scheme="night"] .f-ghunnah { color: #43bd78; }
[data-scheme="night"] .f-gray { color: #9d947e; }
[data-scheme="night"] .f-tafkhim { color: #85a9f2; }
[data-scheme="night"] .f-qalq { color: #5fd3e8; }
[data-scheme="night"] .f-madd2 { color: #eda63e; }
[data-scheme="night"] .f-madd45 { color: #ef7386; }
[data-scheme="night"] .f-madd6 { color: #d84d62; }
[data-scheme="night"] .f-perf { color: #bb8dd9; }
.flg { text-decoration: underline dotted; text-underline-offset: 6px; }

/* ── panel ── */
#panel {
  min-height: 0;
  background: var(--card);
  border-left: 1px solid var(--line);
  overflow-y: auto; padding: 16px 18px 20px;
}
#panel .empty { color: var(--muted); font-size: 13px; line-height: 1.6; margin-top: 10px; }
#panel .pword {
  direction: rtl; text-align: center; font-size: 34px; line-height: 1.7;
  margin: 2px 0 0;
}
#panel .pref { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
#panel h3 {
  font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted); margin: 14px 0 6px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
#panel h3 .lchar { font-size: 21px; color: var(--ink); text-transform: none; letter-spacing: 0; }
#panel h3 .lname { text-transform: none; letter-spacing: 0; font-weight: 400; }
.rulecard {
  border: 1px solid var(--line); border-inline-start: 3px solid var(--rc, var(--accent));
  border-radius: 6px; padding: 8px 11px; margin-bottom: 8px; background: var(--leaf);
}
.rulecard .rn { font-weight: 600; font-size: 13.5px; }
.rulecard .rn .arf { font-size: 16px; }
.rulecard .tr { color: var(--muted); font-size: 12px; font-style: italic; }
.rulecard .why { font-size: 12.5px; margin: 5px 0 0; }
.rulecard .cite { font-size: 11.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 5px; margin-top: 6px; }
.rulecard .cite .poem { display: block; direction: rtl; text-align: right; font-size: 14.5px; color: var(--ink); margin-top: 2px; line-height: 1.85; }
.rulecard .badge {
  font-size: 9.5px; letter-spacing: 0.05em; text-transform: uppercase;
  border: 1px solid var(--line); border-radius: 3px; padding: 1px 4px;
  margin-inline-start: 6px; color: var(--muted); vertical-align: 1px;
}
.noRule { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
details.pron { margin: 2px 0 10px; }
details.pron summary {
  cursor: pointer; font-size: 11.5px; color: var(--accent);
  letter-spacing: 0.03em;
}
details.pron .makhraj { font-size: 12.5px; margin-top: 5px; }
details.pron .makhraj .arf { display: block; direction: rtl; font-size: 15px; }
.sifa {
  display: inline-block; background: var(--leaf); border: 1px solid var(--line);
  border-radius: 999px; padding: 1px 8px; margin: 2px 3px 0 0; font-size: 11px;
}
.sifa .arf { font-size: 13px; }

/* ── mobile chrome (hidden on desktop) ── */
#mtopbar, #mbackdrop { display: none; }
#mtopbar {
  align-items: center; gap: 6px; padding: 0 8px; height: 48px;
  background: var(--card); border-bottom: 1px solid var(--line); z-index: 30;
}
#mtopbar .mtitle { flex: 1; text-align: center; font-size: 20px; color: var(--frame); }
#mtopbar button {
  width: 40px; height: 38px; font-size: 22px; line-height: 1; cursor: pointer;
  background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
#mbackdrop { position: fixed; inset: 0; background: rgba(20,14,4,0.42); z-index: 35; }

/* ── phone / small tablet ── */
@media (max-width: 820px) {
  body, body.lang-ar { grid-template-columns: 1fr; grid-template-rows: 48px minmax(0, 1fr); }
  #mtopbar { display: flex; grid-row: 1; grid-column: 1; }
  #stage, body.lang-ar #stage { grid-row: 2; grid-column: 1; }
  .edge-nav { display: none; }

  /* left rail becomes an off-canvas drawer */
  #left, body.lang-ar #left {
    position: fixed; top: 0; bottom: 0; left: 0; grid-column: auto;
    width: min(86vw, 330px); z-index: 40; border: 0; border-right: 1px solid var(--line);
    transform: translateX(-100%); transition: transform 0.24s ease; overflow-y: auto;
  }
  body.nav-open #left { transform: none; }
  body.lang-ar #left { left: auto; right: 0; border-right: 0; border-left: 1px solid var(--line);
    transform: translateX(100%); }
  body.lang-ar.nav-open #left { transform: none; }

  /* info panel becomes a bottom sheet, raised on word tap */
  #panel, body.lang-ar #panel {
    position: fixed; left: 0; right: 0; bottom: 0; grid-column: auto;
    max-height: 72vh; z-index: 40; border: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px var(--shadow);
    transform: translateY(100%); transition: transform 0.26s ease;
    padding-top: 22px;
  }
  #panel::before {
    content: ""; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
    width: 38px; height: 4px; border-radius: 2px; background: var(--line);
  }
  body.panel-open #panel { transform: none; }
  body.panel-open #mbackdrop, body.nav-open #mbackdrop { display: block; }
}
