@font-face {
  font-family: Kitab;
  src: url("https://cdn.alquran.cloud/public/fonts/Kitab-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --edition-color: #0aae6b;
  --edition-color-hover: #088a55;
  --bg: #f6f3ec;
  --text: #1c1916;
  --muted: #6b645c;
  --bar: #fffcf7;
  --border: #e4ddd2;
  --ayah-hover: rgba(10, 174, 107, 0.08);
  --ayah-active: rgba(10, 174, 107, 0.16);
  --shadow: 0 8px 24px rgba(28, 25, 22, 0.08);
}

html[data-theme="light"] { color-scheme: light; }

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121416;
  --text: #f0ebe3;
  --muted: #b3aaa0;
  --bar: #1b1e22;
  --border: #2c3138;
  --ayah-hover: rgba(10, 174, 107, 0.14);
  --ayah-active: rgba(10, 174, 107, 0.24);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.digital-reader-body {
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
}

.reader {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
}

.topbar, .playerbar {
  background: var(--bar);
  border-color: var(--border);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(10px + env(safe-area-inset-top)) 12px 12px;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
  max-height: 120px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 0.22s ease, opacity 0.22s ease, margin 0.22s ease;
}

.topbar-row-main {
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  margin-bottom: 10px;
  max-height: none;
  overflow: visible;
}

.reader.chrome-hidden .topbar-row:not(.topbar-row-main),
.reader.chrome-hidden .field-full {
  max-height: 0;
  opacity: 0;
  margin: 0;
  pointer-events: none;
}

.topbar-title {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-full {
  display: flex;
  max-height: 120px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 0.22s ease, opacity 0.22s ease, margin 0.22s ease;
}

.field span {
  color: var(--muted);
  font-size: 0.75rem;
}

.field select, .icon-btn, .play-btn {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.field select {
  width: 100%;
  padding: 0 12px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 13px) calc(50% - 3px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

html[dir="rtl"] .field select {
  background-position: 18px calc(50% - 3px), 13px calc(50% - 3px);
}

.field select option:disabled {
  color: var(--muted);
}

.icon-btn, .play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  padding: 0;
  text-decoration: none;
}

.icon-btn:focus-visible,
.play-btn:focus-visible,
.ayah:focus-visible,
.field select:focus-visible {
  outline: 2px solid var(--edition-color);
  outline-offset: 2px;
}

.icon-btn:active, .play-btn:active, .ayah:active {
  transform: scale(0.98);
}

.back-link { font-size: 1.2rem; }

.ayah-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(108px + env(safe-area-inset-bottom));
}

.ayah {
  display: flex;
  gap: 12px;
  width: 100%;
  margin: 0 0 8px;
  padding: 14px 12px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: inherit;
  text-align: start;
  cursor: pointer;
  position: relative;
}

.ayah:hover { background: var(--ayah-hover); }

.ayah.is-active {
  background: var(--ayah-active);
}

.ayah.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 3px;
  background: var(--edition-color);
}

.ayah-num {
  flex: 0 0 auto;
  min-width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bar);
  border: 1px solid var(--border);
  color: var(--edition-color);
  font-size: 0.85rem;
  font-weight: 700;
}

.ayah.is-active .ayah-num {
  background: var(--edition-color);
  border-color: var(--edition-color);
  color: #fff;
}

.ayah-text {
  flex: 1;
  font-family: Kitab, "Noto Naskh Arabic", "Traditional Arabic", serif;
  font-size: clamp(1.35rem, 5.4vw, 1.85rem);
  line-height: 2.05;
}

.playerbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.play-btn {
  width: 52px;
  min-height: 52px;
  border-radius: 999px;
  background: var(--edition-color);
  color: #fff;
  border-color: var(--edition-color);
  font-size: 1.1rem;
}

.play-btn:hover { background: var(--edition-color-hover); }

.now-playing {
  flex: 1;
  min-width: 0;
}

.now-ref {
  font-weight: 700;
  font-size: 0.95rem;
}

.now-hint {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-msg {
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
}

@media (prefers-reduced-motion: reduce) {
  .topbar-row,
  .field-full,
  .icon-btn,
  .play-btn,
  .ayah {
    transition: none;
  }
  .icon-btn:active, .play-btn:active, .ayah:active {
    transform: none;
  }
}

/* Each riwayah stays paired with its own unmodified KFGQPC font. */
@font-face { font-family: QPCWarsh; src: url('../fonts/digital-qiraat/warsh.woff2') format('woff2'); font-display: block; }
@font-face { font-family: QPCQalun; src: url('../fonts/digital-qiraat/qalun.woff2') format('woff2'); font-display: block; }
@font-face { font-family: QPCShubah; src: url('../fonts/digital-qiraat/shubah.woff2') format('woff2'); font-display: block; }
@font-face { font-family: QPCDouri; src: url('../fonts/digital-qiraat/douri.woff2') format('woff2'); font-display: block; }
html[data-book="warsh"] .ayah-text { font-family: QPCWarsh, serif; }
html[data-book="qalun"] .ayah-text { font-family: QPCQalun, serif; }
html[data-book="shubah"] .ayah-text { font-family: QPCShubah, serif; }
html[data-book="douri"] .ayah-text { font-family: QPCDouri, serif; }
.reader-basmala { text-align: center; margin: 12px 0 20px; color: var(--text); }
.ayah-audio-range { display: block; font: 0.72rem/1.5 system-ui, sans-serif; color: var(--muted); margin-top: 6px; }
.reader-source { font-size: 0.75rem; color: var(--muted); max-height: 240px; }
.reader-source summary { cursor: pointer; padding: 6px 0; min-height: 28px; }
.reader-source[open] { overflow-y: auto; }
.reader-source p { margin: 6px 0; line-height: 1.6; }
.reader-source a { color: var(--text); margin-inline-end: 12px; }
.now-hint { white-space: normal; line-height: 1.45; max-height: 4.4em; overflow-y: auto; }
.playerbar { min-height: 86px; }
.ayah-list { padding-bottom: calc(126px + env(safe-area-inset-bottom)); }
button:disabled { opacity: 0.55; cursor: default; }

.reader-retry { display: block; margin: 0 auto; padding: 12px 24px; border-radius: 12px; border: 1px solid var(--border); color: var(--text); background: var(--bar); min-height: 44px; }


/* Contextual return + juz field (mobile-first) */
.field-grow { flex: 1 1 140px; min-width: 120px; }
.reader-return-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bar);
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
}
.reader-return-btn:hover,
.reader-return-btn:focus-visible {
  border-color: var(--edition-color);
  color: var(--edition-color);
  outline: none;
}
#juz-select { min-width: 7.5rem; }
@media (max-width: 420px) {
  .topbar-row .field { flex: 1 1 calc(50% - 8px); }
  .field-grow { flex: 1 1 100%; }
}