/* Fonts are self-hosted: no requests to third parties (see README, Fonts). */
@font-face {
  font-family: 'Amiri Quran';
  src: url('../fonts/amiri-quran-arabic-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Amiri';
  src: url('../fonts/amiri-arabic-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Amiri';
  src: url('../fonts/amiri-arabic-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
/* Brackets. The Arabic subsets above have none, so ( ) fell back to a
   system font that WebKit draws the wrong way round in right-to-left text:
   "المزيد )٢٣٥(". These come from Amiri's Latin subset instead. */
@font-face {
  font-family: 'Amiri';
  src: url('../fonts/amiri-latin-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0028-0029, U+005B, U+005D, U+007B, U+007D;
}
@font-face {
  font-family: 'Amiri';
  src: url('../fonts/amiri-latin-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0028-0029, U+005B, U+005D, U+007B, U+007D;
}

:root {
  --bg: #fbf8f1;
  --surface: #ffffff;
  --text: #1f1b16;
  --muted: #6b6257;
  --line: #e6dfd1;
  --accent: #8a5a1c;
  --accent-soft: #f3e8d6;
  --quran: 'Amiri Quran', 'Amiri', serif;
  --ui: 'Amiri', 'Noto Naskh Arabic', 'Geeza Pro', serif;
  --quran-size: 1.75rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f;
    --surface: #1e1b16;
    --text: #ece5d8;
    --muted: #a39887;
    --line: #34302a;
    --accent: #d9a85b;
    --accent-soft: #2e2618;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15130f;
  --surface: #1e1b16;
  --text: #ece5d8;
  --muted: #a39887;
  --line: #34302a;
  --accent: #d9a85b;
  --accent-soft: #2e2618;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 1.125rem;
  line-height: 1.8;
}
a { color: var(--accent); }
.wrap { max-width: 46rem; margin: 0 auto; padding: 0 16px; }

.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: baseline; gap: 1rem; padding-block: 0.75rem; }
.site-name { font-size: 1.75rem; font-weight: 700; color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 0.4rem; }
/* The mark (img/mark.svg) as a mask, so it takes the accent and its roots show the header behind. */
.site-name::before { content: ""; flex: none; width: 1.2em; height: 1.2em; background: var(--accent); -webkit-mask: url(../img/mark.svg) center / contain no-repeat; mask: url(../img/mark.svg) center / contain no-repeat; }
.site-header nav { margin-inline-start: auto; display: flex; gap: 1rem; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover, .site-header nav a[aria-current] { color: var(--accent); }

main.wrap { padding-block: 1.5rem 3rem; }
h1 { font-size: 2rem; line-height: 1.4; margin: 0 0 1rem; }
.muted { color: var(--muted); }

.quran { font-family: var(--quran); font-size: var(--quran-size); line-height: 2.4; }

.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.95rem; }
.site-footer .wrap { padding-block: 1rem 2rem; }

/* Surah index */
.surah-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.5rem;
}
.surah-list a {
  display: grid; grid-template-columns: 2.5rem 1fr; align-items: center;
  padding: 0.5rem 0.75rem; border: 1px solid var(--line); border-radius: 0.5rem;
  background: var(--surface); color: var(--text); text-decoration: none;
}
.surah-list a:hover, .surah-list a:focus-visible { border-color: var(--accent); }
.surah-number { grid-row: span 2; color: var(--accent); font-size: 1.1rem; }
.surah-name { font-size: 1.3rem; font-weight: 700; line-height: 1.5; }
.surah-meta { color: var(--muted); font-size: 0.95rem; line-height: 1.4; }

/* Reading page */
.surah-title { text-align: center; }
.basmala { text-align: center; margin: 0 0 1rem; }
.verses { margin: 0; }
.word {
  font: inherit; color: inherit; background: none; border: 0; padding: 0 0.05em; margin: 0;
  border-radius: 0.3em; cursor: pointer; line-height: inherit;
}
.word:hover { background: var(--accent-soft); }
.word:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.word.selected { background: var(--accent-soft); color: var(--accent); }
.mark { color: var(--accent); }
.w { white-space: nowrap; }
.verse-end {
  font: inherit; color: var(--accent); background: none; border: 0; padding: 0; margin: 0;
  border-radius: 0.3em; cursor: pointer; line-height: inherit;
}
.verse-end:hover, .verse-end[aria-expanded="true"] { background: var(--accent-soft); }
.verse-end:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tafsir {
  display: block; margin: 0.5rem 0 1rem; padding: 0.75rem 1rem;
  border-inline-start: 3px solid var(--accent); background: var(--surface); border-radius: 0.25rem;
  font-family: var(--ui); font-size: 1.15rem; line-height: 1.9;
}
.tafsir .q { color: var(--accent); }
.tafsir-text, .tafsir-source { display: block; margin: 0; }
.tafsir-source { margin-top: 0.4rem; font-size: 0.9rem; color: var(--muted); }
.verse.target { background: var(--accent-soft); }
.surah-nav { display: flex; justify-content: space-between; margin-top: 2rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.surah-nav a { text-decoration: none; }

/* Word panel: a sheet at the bottom on narrow screens, a side panel on wide ones */
.panel {
  position: fixed; inset-inline: 0; bottom: 0; max-height: 70vh; overflow-y: auto;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 1rem 1rem 0 0; box-shadow: 0 -0.5rem 2rem rgb(0 0 0 / 0.15);
  padding: 0.5rem 16px 1.5rem; z-index: 10;
}
.panel[hidden] { display: none; }
@media (min-width: 60rem) {
  .panel {
    inset-inline: auto 0; inset-block: 0; max-height: none; width: 24rem;
    border-top: 0; border-inline-start: 1px solid var(--line); border-radius: 0;
  }
  body:has(.panel:not([hidden])) main { margin-inline-end: 24rem; }
}
.panel-close {
  float: inline-end; font-size: 1.75rem; line-height: 1; padding: 0.25rem 0.5rem;
  background: none; border: 0; color: var(--muted); cursor: pointer;
}
.panel-word { font-size: 2.25rem; margin: 0.25rem 0 0.5rem; }
.layer h2 { font-size: 1.05rem; color: var(--muted); margin: 1.25rem 0 0.5rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts .quran, .lemmas .quran { font-size: 1.4rem; line-height: 1.6; }
.root-letters { font-size: 1.5rem; font-weight: 700; color: var(--accent); word-spacing: 0.3em; }
.lemmas { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.lemmas li { border: 1px solid var(--line); border-radius: 2rem; padding: 0 0.75rem; }
.lemmas li[aria-current] { border-color: var(--accent); background: var(--accent-soft); }
.other-verses { list-style: none; padding: 0; margin: 0; }
.other-verses li { border-bottom: 1px solid var(--line); padding-block: 0.5rem; }
.other-verses .quran { font-size: 1.35rem; line-height: 2.1; margin: 0; }
.other-verses mark { background: var(--accent-soft); color: var(--accent); border-radius: 0.3em; }
.other-verses a { font-size: 0.95rem; text-decoration: none; }

/* Font size control */
.font-size { display: flex; gap: 0.25rem; }
.font-size button {
  min-width: 2.75rem; min-height: 2.75rem; font: inherit; font-size: 1rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 0.5rem; cursor: pointer;
}
.font-size button:disabled { opacity: 0.4; cursor: default; }
.panel-close { min-width: 2.75rem; min-height: 2.75rem; }
/* Room to scroll the last lines above the bottom sheet */
@media (max-width: 59.99rem) { body:has(.panel:not([hidden])) main { padding-bottom: 70vh; } }

/* Sources page */
.about section { margin-top: 2rem; }
.about h2 { font-size: 1.4rem; margin: 0 0 0.75rem; }
.about pre {
  background: var(--surface); border: 1px solid var(--line); border-radius: 0.5rem;
  padding: 0.75rem 1rem; font-size: 0.8rem; line-height: 1.5; overflow-x: auto; text-align: left;
}
.citation { text-align: left; font-family: Georgia, serif; font-size: 0.95rem; line-height: 1.6; }
/* The Amiri files are an Arabic subset: give Latin text its own font. */
:lang(en) { font-family: Georgia, 'Times New Roman', serif; }
pre:lang(en) { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* Search */
.site-search { flex-basis: 100%; order: 3; }
.site-search input { width: 100%; font: inherit; padding: 0.4rem 0.75rem; border: 1px solid var(--line); border-radius: 0.5rem; background: var(--bg); color: var(--text); }
.site-search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (min-width: 40rem) { .site-search { flex-basis: 14rem; order: 0; } }
.site-header .wrap { flex-wrap: wrap; }
.results { list-style: none; padding: 0; }
.results li { padding-block: 0.75rem; border-bottom: 1px solid var(--line); }
.results .quran { font-family: var(--quran); font-size: 1.4rem; }
.result-root { margin-inline-end: 0.75rem; text-decoration: none; }

/* Root page */
.lemma { border-bottom: 1px solid var(--line); padding-block: 0.5rem; }
.lemma summary { cursor: pointer; padding-block: 0.25rem; }
.lemma summary .quran { font-family: var(--quran); font-size: 1.6rem; }
.lemma .forms { list-style: none; padding: 0; margin: 0.5rem 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.lemma .forms li { border: 1px solid var(--line); border-radius: 2rem; padding: 0 0.75rem; }
.lemma .forms .quran { font-family: var(--quran); font-size: 1.25rem; }
.lemma .more { font: inherit; margin-block: 0.75rem; padding: 0.3rem 1rem; border: 1px solid var(--line); border-radius: 0.5rem; background: var(--bg); color: var(--accent); cursor: pointer; }

/* Meaning and Study layers */
.meaning summary, .study summary { cursor: pointer; }
.meaning summary h2, .study summary h2 { display: inline; }
.meaning .tafsir { margin-block: 0.5rem; }
.meaning details { margin-block: 0.5rem; }
.gloss .tafsir-text { white-space: pre-line; }
.study { margin-top: 1rem; border-top: 1px solid var(--line); }
.segments { list-style: none; padding: 0; margin: 0; }
.segments li { padding-block: 0.3rem; border-bottom: 1px solid var(--line); }
.segments .quran { font-size: 1.4rem; line-height: 1.6; margin-inline-end: 0.5rem; }
.small { font-size: 0.9rem; }
.reader-hint { text-align: center; font-size: 0.95rem; margin: -0.5rem 0 1rem; }

/* Back to top */
.to-top {
  position: fixed; z-index: 5;
  inset-inline-end: max(1rem, env(safe-area-inset-left));
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: 2.75rem; height: 2.75rem; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--accent);
  font: 700 1.3rem/1 var(--ui); cursor: pointer;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
}
.to-top[hidden] { display: none; }
.to-top:hover { background: var(--accent-soft); }
.to-top:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
body:has(.panel:not([hidden])) .to-top { display: none; }
