:root {
  color-scheme: light dark;
  --bg: #faf8f4;
  --surface: #ffffff;
  --ink: #17170f;
  --muted: #5f5c54;
  --line: #e4e0d6;
  --accent: #1f6f4a;
  --link: #9a3412;
  --radius: 12px;
  --arabic: 30px;
  /* Linked words are coloured per word; only the lightness follows the theme. */
  --word-s: 72%;
  --word-l: 33%;
}
:root[data-theme="dark"], :root:not([data-theme="light"]) {
  --bg: #0e0e0d;
  --surface: #1a1a18;
  --ink: #f0eee8;
  --muted: #a8a49b;
  --line: #2e2e2b;
  --accent: #58b184;
  --link: #f0a97e;
  --word-l: 68%;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #faf8f4;
    --surface: #ffffff;
    --ink: #17170f;
    --muted: #5f5c54;
    --line: #e4e0d6;
    --accent: #1f6f4a;
    --link: #9a3412;
    --word-l: 33%;
  }
}
:root[data-theme="light"] {
  --bg: #faf8f4; --surface: #ffffff; --ink: #17170f;
  --muted: #5f5c54; --line: #e4e0d6; --accent: #1f6f4a; --link: #9a3412;
  --word-l: 33%;
}

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

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.6 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: 48px;
}
main { max-width: 760px; margin: 0 auto; padding: 16px; }

.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.bar h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-right { display: flex; gap: 6px; flex: none; }

button {
  font: inherit; padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.ghost { padding: 6px 10px; font-size: 14px; }
button:focus-visible, a:focus-visible, li:focus-visible, input:focus-visible,
[role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.notice { color: var(--muted); padding: 24px 4px; text-align: center; }

.search { display: block; font-size: 14px; color: var(--muted); margin: 4px 0 6px; }
#search {
  width: 100%; padding: 11px 13px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px; margin-bottom: 14px;
}

.cards { list-style: none; margin: 0; padding: 0; }
.cards li {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; margin-bottom: 9px; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
}
.cards li:hover { border-color: var(--accent); }
.cards .no {
  flex: none; min-width: 2.4em; height: 2.4em; display: grid; place-items: center;
  border-radius: 999px; background: var(--bg); border: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}
.cards .label { flex: 1; min-width: 0; }
.cards .name { font-weight: 600; }
.cards .meta { color: var(--muted); font-size: 14px; margin-top: 1px; }

.verse { border-top: 1px solid var(--line); padding: 20px 0; }
.verse:first-child { border-top: 0; }
.verse-no { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.arabic {
  direction: rtl; text-align: right; font-size: var(--arabic); line-height: 2.15;
  font-family: "Scheherazade New", "Geeza Pro", "Traditional Arabic", "Noto Naskh Arabic", serif;
}
.translation { margin-top: 12px; }
.linked {
  color: hsl(var(--w, 20) var(--word-s) var(--word-l));
  cursor: pointer; font-weight: 600;
  border-bottom: 2px dotted currentColor;
}
.linked:hover { background: color-mix(in srgb, currentColor 14%, transparent); }

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 10;
}
.sheet {
  background: var(--surface); width: min(640px, 100%); max-height: 88vh;
  border-radius: var(--radius) var(--radius) 0 0; display: flex; flex-direction: column;
}
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: var(--radius); } }
.sheet-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.sheet-bar h2 {
  margin: 0; font-size: 26px; font-family: "Scheherazade New", "Geeza Pro", serif;
  color: hsl(var(--w, 20) var(--word-s) var(--word-l));
}
.sheet-body { overflow-y: auto; padding: 16px; }
.summary { margin: 0 0 14px; }
.detail { margin: 14px 0 0; white-space: pre-wrap; color: var(--ink); font-size: 15px; }

.foot {
  position: fixed; bottom: 0; left: 0; right: 0; padding: 7px 14px;
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted); text-align: center;
}

.player { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--radius); margin-bottom: 10px; }
h2 { font-size: 16px; margin: 22px 0 10px; }
