/* Functional CSS only (PLAN §4.4): show/hide, positioning, theme tokens, highlights, RTL. */

/* Theme tokens: Auto / Light / Sepia / Dark */
:root,
[data-theme="light"] {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #555555;
  --border: #999999;
  --highlight: #ffe58a;
  --selected: #cfe3ff;
}
[data-theme="sepia"] {
  --bg: #f4ecd8;
  --fg: #3b2f1e;
  --muted: #6b5a43;
  --border: #a8977a;
  --highlight: #f0cd6e;
  --selected: #e3d3a8;
}
[data-theme="dark"] {
  --bg: #141414;
  --fg: #eeeeee;
  --muted: #aaaaaa;
  --border: #666666;
  --highlight: #6b5800;
  --selected: #23446e;
}
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #141414;
    --fg: #eeeeee;
    --muted: #aaaaaa;
    --border: #666666;
    --highlight: #6b5800;
    --selected: #23446e;
  }
}

html { background: var(--bg); color: var(--fg); }
body { background: var(--bg); color: var(--fg); margin: 0 8px; }
a { color: inherit; }

[hidden] { display: none !important; }
/* Read by assistive technology, not shown (the login panels' headings once they are tabs). */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 8px; top: 8px; z-index: 100; background: var(--bg); }

/* Overlays */
.drawer {
  position: fixed; top: 0; bottom: 0; right: 0; z-index: 20;
  width: min(420px, 100%); overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--border);
}
[dir="rtl"] .drawer { right: auto; left: 0; border-left: 0; border-right: 1px solid var(--border); }
.modal {
  position: fixed; top: 5vh; left: 50%; transform: translateX(-50%); z-index: 30;
  width: min(720px, 96vw); max-height: 90vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border);
}
.popover {
  position: absolute; z-index: 35; max-width: 360px;
  background: var(--bg); border: 1px solid var(--border);
}

#toasts { position: fixed; bottom: 8px; left: 8px; z-index: 40; }
.toast { background: var(--bg); border: 1px solid var(--border); }

/* Functional visuals */
.is-selected, [aria-selected="true"] { background: var(--selected); }
.is-highlighted { background: var(--highlight); }

/* Quran fonts, through the asset mirror: /m/{key} is our copy or a 302 to the font source (D-029, D-041) */
@font-face {
  font-family: "IndoPak";
  src: url("/m/font:script:indopak") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "UthmanicHafs";
  src: url("/m/font:script:uthmanic-hafs") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "surahnames";
  src: url("/m/font:script:surah-names") format("woff2");
  font-display: block;
}
.surah-name { font-family: "surahnames"; font-size: 3em; margin: 0; }
.verse-arabic[data-font="text_indopak"] { font-family: "IndoPak"; }
.verse-arabic[data-font="qpc_uthmani_hafs"], .bismillah { font-family: "UthmanicHafs"; }
/* Quran font size: quranReaderStyles.quranTextFontScale 1–10, default 4 = 1.8em (SPEC §4.3, D-044) */
.verse-arabic, .bismillah, .mushaf-line { font-size: calc(0.9em + var(--quran-scale, 4) * 0.225em); }
/* Translation font size: quranReaderStyles.translationFontScale 1–10, default 3 = 1em (D-045) */
.translation-text { font-size: calc(0.625em + var(--translation-scale, 3) * 0.125em); }

/* Words are buttons for word actions, but read as running text. */
.word { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
/* The IndoPak font draws the verse-end digits with zero width: the number uses UthmanicHafs, as in the client (D-051) */
[data-font="text_indopak"] .word[data-word-type="end"] { font-family: "UthmanicHafs"; }

/* The ayah embed measures its root for the auto-resize: margins stay inside it (D-088) */
[data-embed] { display: flow-root; }

/* Word by word (SPEC §4.3, D-046): below-word content per html[data-wbw-inline], the hover tooltip, and
   readingPreferences' wordByWordFontScale 1–6 (default 3 = 1rem). The page font, not the Quran font. */
.verse-arabic .word { display: inline-flex; flex-direction: column; align-items: center; vertical-align: top; }
.wbw-inline { display: none; }
[data-wbw-inline~="translation"] .wbw-inline[data-wbw="translation"],
[data-wbw-inline~="transliteration"] .wbw-inline[data-wbw="transliteration"] { display: block; }
.wbw-inline, #wbw-tooltip { font-family: initial; font-size: calc(0.625rem + var(--wbw-scale, 3) * 0.125rem); }
#wbw-tooltip { position: fixed; z-index: 30; background: var(--bg); color: var(--fg); border: 1px solid var(--border); }
#wbw-tooltip[hidden] { display: none; }

/* Reader header strip: sticky, with a progress bar whose width is the reading progress (SPEC §4.1) */
.reader-header { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--border); }
.reading-progress-bar { width: 0; height: 3px; background: var(--fg); }

/* Reading → Arabic: one row per mushaf line, justified (SPEC §4.1) */
.mushaf-line { text-align: justify; text-align-last: justify; }
.mushaf-page[data-font="text_indopak"] { font-family: "IndoPak"; }
.mushaf-page[data-font="qpc_uthmani_hafs"] { font-family: "UthmanicHafs"; }

/* Surah info (D-042): the text size follows quranReaderStyles.surahInfoFontScale (1–10) */
.surah-info-text { font-size: calc(0.75rem + var(--info-scale, 3) * 0.125rem); }

/* Audio player (SPEC §4.4, D-048): the bar is fixed at the bottom; the current verse and word are highlighted. */
.audio-player { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--bg); border-top: 1px solid var(--border); }
.audio-player[hidden] { display: none; }
body:has(.audio-player:not([hidden])) { padding-bottom: 8rem; }
.audio-verse { background: var(--selected); }
.audio-word { background: var(--highlight); }
/* The player's ⋯ menu opens above the fixed bar, not below its button (P4.2). */
.audio-menu.popover { position: fixed; top: auto; left: auto; right: 0; bottom: 6rem; max-height: 60vh; overflow: auto; }
.audio-menu [role^="menuitem"] { display: block; }
.audio-menu [aria-checked="true"]::before { content: "✓ "; }

/* Verse card actions (SPEC §4.5, D-052): the More menu lists one item per row */
#verse-menu [role="menuitem"] { display: block; }
#pins-menu [role="menuitem"] { display: block; }
/* Study view (D-054): the tab body follows the tab's font scale (1–10, default 3) */
.study-body { font-size: calc(0.75rem + var(--study-scale, 3) * 0.125rem); }
[data-study-pins][hidden], [data-study-scale][hidden] { display: none; }
.qr-body { white-space: pre-line; }
.qiraat-readers table { border-collapse: collapse; }
.qiraat-readers th, .qiraat-readers td { border: 1px solid; padding: 0.25rem; text-align: start; }
