@font-face {
  font-family: "Scheherazade";
  src: url("Scheherazade.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #FAFAF5;
  --bg-surface: #FFFFFF;
  --text-primary: #1A1A1A;
  --text-secondary: #555555;
  --text-arabic: #1A3A2A;
  --text-translit: #6B7280;
  --accent: #1B6B4A;
  --accent-hover: #155A3E;
  --border: #E8E5DD;
  --nav-bg: #1B6B4A;
  --nav-text: #FFFFFF;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius: 8px;
}
[data-theme="dark"] {
  --bg: #121714;
  --bg-surface: #1C2420;
  --text-primary: #E0E0D8;
  --text-secondary: #9A9A90;
  --text-arabic: #D4E8DC;
  --text-translit: #8B9580;
  --accent: #4CAF7C;
  --accent-hover: #5CC98E;
  --border: #2A3530;
  --nav-bg: #0D2E1F;
  --nav-text: #E0E0D8;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---- Top nav ---- */
nav.topbar {
  background: var(--nav-bg);
  color: var(--nav-text);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
nav.topbar a, nav.topbar a:hover { color: var(--nav-text); }
nav.topbar .crumbs { font-size: 0.95rem; display: flex; gap: 8px; align-items: center; }
nav.topbar .crumbs span { opacity: 0.6; }
nav.topbar .controls { display: flex; gap: 8px; }
nav.topbar button {
  background: rgba(255,255,255,0.1);
  color: var(--nav-text);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
nav.topbar button:hover { background: rgba(255,255,255,0.2); }
@media (max-width: 600px) {
  nav.topbar { padding: 10px 12px; gap: 8px; }
  nav.topbar .crumbs { font-size: 0.85rem; gap: 4px; min-width: 0; flex-shrink: 1; }
  nav.topbar .crumbs a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  nav.topbar .controls { gap: 4px; flex-shrink: 0; }
  nav.topbar button { padding: 6px 8px; font-size: 0.8rem; }
}

/* ---- Settings popover ---- */
.settings {
  position: fixed;
  top: 60px;
  right: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 60;
  min-width: 240px;
  display: none;
}
.settings.open { display: block; }
.settings h3 { margin: 0 0 12px; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); }
.settings label { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.settings label input { accent-color: var(--accent); }
.settings .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.settings .row button {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
}
.settings .row button:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* ---- TOC (section list) view ---- */
.toc {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.toc-header { text-align: center; margin-bottom: 32px; }
.toc-header .arabic { font-family: "Scheherazade", serif; font-size: 2.2rem; color: var(--text-arabic); direction: rtl; }
.toc-header h1 { font-size: 1.5rem; margin: 8px 0 4px; }
.toc-header .author { color: var(--text-secondary); font-size: 0.95rem; }
.toc-list { display: flex; flex-direction: column; gap: 8px; }
.toc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  transition: border-color 0.15s, transform 0.1s;
}
.toc-item:hover { border-color: var(--accent); transform: translateX(2px); color: var(--text-primary); }
.toc-item .title { font-weight: 500; }
.toc-item .badge {
  background: var(--accent);
  color: white;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.8rem;
}

/* ---- Reading mode ---- */
.reader { max-width: 760px; margin: 0 auto; padding: 32px 20px 80px; }
.reader .section-title { text-align: center; margin: 0 0 32px; }
.reader .section-title .arabic { font-family: "Scheherazade", serif; font-size: 2rem; color: var(--text-arabic); direction: rtl; }
.reader .section-title h1 { font-size: 1.4rem; margin: 4px 0 0; color: var(--text-secondary); font-weight: 500; }
.verse {
  margin-bottom: 36px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}
.verse:last-child { border-bottom: none; }
.verse .num {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.verse .arabic {
  font-family: "Scheherazade", serif;
  font-size: var(--ar-size, 2rem);
  line-height: 1.9;
  text-align: right;
  direction: rtl;
  color: var(--text-arabic);
  margin: 8px 0 16px;
}
.verse .translit {
  font-style: italic;
  color: var(--text-translit);
  font-size: var(--tl-size, 1.05rem);
  margin: 8px 0;
  white-space: pre-line;
}
.verse .english {
  color: var(--text-primary);
  font-size: var(--en-size, 1.05rem);
  margin: 8px 0;
}
.verse .meta { font-size: 0.85rem; color: var(--accent); margin-top: 8px; }
body.hide-translit .verse .translit { display: none; }
body.hide-en .verse .english { display: none; }

/* ---- Reader bottom nav ---- */
.section-nav {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 60px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.section-nav a {
  flex: 1;
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-primary);
}
.section-nav a:hover { border-color: var(--accent); color: var(--accent); }
.section-nav a.disabled { opacity: 0.3; pointer-events: none; }

/* ---- Presentation mode ---- */
body.presenting { background: var(--bg); color: var(--text-primary); overflow: hidden; }
body.presenting nav.topbar { display: none; }
.present-stage {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text-primary);
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 8vh 6vw 10vh;
  overflow-y: auto;
}
body.presenting .present-stage { display: flex; }
.present-stage .arabic {
  font-family: "Scheherazade", serif;
  font-size: calc(clamp(2.2rem, 5.5vw, 6rem) * var(--p-scale, 1));
  line-height: 1.7;
  direction: rtl;
  color: var(--text-arabic);
  margin-bottom: 4vh;
  max-width: 92vw;
}
.present-stage .translit {
  font-style: italic;
  font-size: calc(clamp(1.2rem, 2vw, 2rem) * var(--p-scale, 1));
  color: var(--text-translit);
  margin-bottom: 3vh;
  white-space: pre-line;
  max-width: 85vw;
}
.present-stage .english {
  font-size: calc(clamp(1.2rem, 2.4vw, 2.4rem) * var(--p-scale, 1));
  line-height: 1.5;
  color: var(--text-primary);
  max-width: 85vw;
  margin-bottom: 2vh;
}
.present-stage .meta {
  font-size: clamp(0.9rem, 1.2vw, 1.1rem);
  color: var(--accent);
  margin-top: 1vh;
}
.present-stage .present-section-label {
  font-size: clamp(0.9rem, 1.4vw, 1.3rem);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 3vh;
  opacity: 0.85;
}
body.presenting.hide-translit .present-stage .translit { display: none; }
body.presenting.hide-en .present-stage .english { display: none; }

/* presentation top bar (auto-hide) */
.present-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  display: none;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  transition: opacity 0.3s;
}
body.presenting .present-bar { display: flex; }
body.presenting.controls-hidden .present-bar { opacity: 0; pointer-events: none; }
.present-bar .section-name { font-weight: 500; }
.present-bar .counter { font-size: 0.9rem; opacity: 0.85; }
.present-bar button {
  background: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  margin-left: 8px;
}
.present-bar button:hover { background: var(--accent); color: white; border-color: var(--accent); }

.present-progress {
  position: fixed;
  bottom: 0; left: 0;
  height: 3px;
  background: var(--accent);
  z-index: 100;
  transition: width 0.2s;
}
body:not(.presenting) .present-progress { display: none; }

/* tap zones for mobile/touch */
.present-tap {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 30%;
  z-index: 90;
  cursor: pointer;
  display: none;
}
body.presenting .present-tap { display: block; }
.present-tap.left { left: 0; }
.present-tap.right { right: 0; }

/* section jumper modal */
.jumper {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 200;
  padding: 20px;
}
.jumper.open { display: flex; }
.jumper-inner {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.jumper h2 { margin: 0 0 16px; font-size: 1.2rem; }
.jumper .jumper-list { display: flex; flex-direction: column; gap: 6px; }
.jumper .jumper-list a {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  color: var(--text-primary);
}
.jumper .jumper-list a:hover { border-color: var(--accent); color: var(--accent); }

/* small-screen warning in present mode */
.present-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,235,59,0.15);
  color: #ffeb3b;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  display: none;
  z-index: 100;
}
@media (max-width: 700px) {
  body.presenting .present-hint { display: block; }
}
