:root {
  --navy: #1f4e79;
  --navy-dark: #163A5C;
  --ink: #1b2430;
  --muted: #5b6570;
  --paper: #f7f3ea;
  --card: #fffdf8;
  --line: #e2d9c8;
  --book: #1a7a4c;
  --book-bg: #e7f6ee;
  --gen: #8a5a12;
  --gen-bg: #f8eedc;
  --play: #1f4e79;
  --play-on: #c0392b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(28px + var(--safe-bot));
}
@font-face {
  font-family: Harmattan;
  src: url("fonts/Harmattan-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Harmattan;
  src: url("fonts/Harmattan-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}
.ar {
  font-family: Harmattan, "Noto Naskh Arabic", "SF Arabic", "Geeza Pro", serif;
  font-size: 1.45rem;
  line-height: 1.7;
  direction: rtl;
  unicode-bidi: isolate;
  font-weight: 400;
}
header.hero {
  background: var(--navy);
  color: #fff;
  padding: calc(18px + var(--safe-top)) 16px 20px;
}
header.hero h1 {
  margin: 0 0 4px;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
header.hero .sub { opacity: 0.92; font-size: 0.95rem; }
header.hero .meta { margin-top: 10px; font-size: 0.88rem; opacity: 0.88; }
.wrap { width: min(860px, calc(100% - 24px)); margin: 0 auto; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 16px auto;
}
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; font-size: 0.92rem; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
}
.tag.book { background: var(--book-bg); color: var(--book); }
.tag.gen { background: var(--gen-bg); color: var(--gen); }
.install { margin-top: 10px; color: var(--muted); font-size: 0.9rem; }
nav.toc {
  display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 10px 12px; position: sticky; top: 0; z-index: 20;
  background: rgba(247,243,234,0.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
nav.toc a {
  flex: 0 0 auto; text-decoration: none; color: var(--navy);
  background: #fff; border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 12px; font-size: 0.85rem; font-weight: 600;
  white-space: nowrap;
}
.search {
  width: min(860px, calc(100% - 24px));
  margin: 12px auto 0;
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  background: #fff;
}
section.block { width: min(860px, calc(100% - 24px)); margin: 22px auto; }
section.block h2 {
  color: var(--navy-dark);
  font-size: 1.25rem;
  margin: 0 0 6px;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  flex-wrap: wrap;
}
section.block h2 .ar { font-size: 1.4rem; color: var(--navy); }
section.block .intro { color: var(--muted); margin: 0 0 12px; }
h3.subh {
  margin: 18px 0 8px;
  font-size: 1.05rem;
  color: var(--navy);
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 8px 12px;
  align-items: start;
  background: var(--card);
  border: 1px solid var(--line);
  border-width: 0 1px 1px 1px;
  padding: 10px 12px;
}
.rows { border-radius: var(--radius); overflow: hidden; border-top: 1px solid var(--line); }
.row:nth-child(even) { background: #fbf8f1; }
.en { color: var(--ink); font-size: 0.98rem; padding-top: 6px; }
.ars {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 10px;
  direction: rtl;
}
.item {
  display: inline-flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}
button.play {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--play);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  position: relative;
  box-shadow: 0 1px 0 rgba(0,0,0,0.15);
}
button.play:focus-visible { outline: 3px solid #f0c14b; outline-offset: 2px; }
button.play.playing { background: var(--play-on); }
button.play .mark {
  position: absolute; right: -3px; bottom: -3px;
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 10px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}
button.play.book .mark { background: var(--book); color: #fff; }
button.play.gen .mark { background: #c4842a; color: #fff; }
button.play[disabled] { opacity: 0.4; }
.pair .item { margin-inline: 2px; }
.pair-label { color: var(--muted); font-size: 0.8rem; }
.offline-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.offline-bar button, .hero-btn {
  background: #fff; color: var(--navy); border: 0; border-radius: 10px;
  padding: 8px 12px; font-weight: 700; cursor: pointer; font-size: 0.9rem;
}
#status { font-size: 0.85rem; color: var(--muted); margin-top: 6px; min-height: 1.2em; }
footer {
  width: min(860px, calc(100% - 24px));
  margin: 24px auto 8px;
  color: var(--muted);
  font-size: 0.85rem;
}
.missing { background: #f8d7da !important; }
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; gap: 4px; }
  .en { padding-top: 0; }
  .ars { justify-content: flex-start; }
  .ar { font-size: 1.55rem; }
  button.play { width: 46px; height: 46px; }
}
