:root {
  --font-scale: 1;
  --bg: #f6f0e2;
  --surface: #fffaf0;
  --text: #2a2017;
  --muted: #76664f;
  --accent: #8a5a2b;
  --accent-text: #fffaf0;
  --border: #e2d4b8;
  --shadow: 0 1px 3px rgba(60, 40, 10, 0.12);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15120e;
  --surface: #1e1914;
  --text: #ece2cf;
  --muted: #a8977e;
  --accent: #d9a766;
  --accent-text: #1a140d;
  --border: #3a3127;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Amiri", "Times New Roman", serif;
  font-size: 1.15rem;
  line-height: 1.8;
  transition: background-color 0.2s, color 0.2s;
}

a { color: var(--accent); }

button, select {
  font: inherit;
  color: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 44px;
  padding: 0.3em 1em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 1rem;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.icon-btn {
  width: 44px;
  padding: 0;
}

.icon { width: 20px; height: 20px; flex: none; }

/* Theme toggle shows the icon for the mode you'll switch to */
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* Mirror directional arrows in RTL */
[dir="rtl"] .icon-dir { transform: scaleX(-1); }

/* ---------- Index ---------- */

.home {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.home-top {
  display: flex;
  justify-content: flex-end;
}

.hero {
  text-align: center;
  margin: 8px 0 32px;
}

.hero h1 {
  font-size: clamp(1.9rem, 6vw, 2.8rem);
  line-height: 1.4;
  margin: 0 0 4px;
  font-weight: 700;
}

.hero .subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 1.25rem;
}

.hero .en-title {
  margin-top: 12px;
  font-size: 1.2rem;
  color: var(--muted);
}

.ornament {
  color: var(--accent);
  font-size: 1.5rem;
  margin: 16px 0;
  letter-spacing: 0.5em;
}

.summaries {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  color: var(--accent);
}

.card h3 {
  margin: 16px 0 4px;
  font-size: 1.1rem;
}

.card p { margin: 0 0 8px; }

.card[lang="ar"] { font-size: 1.25rem; line-height: 2; }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 32px 0 12px;
}

.actions .btn { min-width: 220px; font-size: 1.1rem; }

.continue {
  text-align: center;
  margin-bottom: 24px;
}

.disclaimer {
  max-width: 640px;
  margin: 24px auto 0;
  padding: 12px 16px;
  border-inline-start: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}
.disclaimer p { margin: 0; }
.disclaimer p + p { margin-top: 6px; }

@media (max-width: 700px) {
  .summaries { grid-template-columns: 1fr; }
  .actions .btn { width: 100%; }
}

/* ---------- Reader ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.topbar .spacer { flex: 1; }

.page-select {
  min-height: 44px;
  max-width: 11em;
  padding: 0 0.8em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: 1rem;
}

.reader {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 120px;
  min-height: 70vh;
  touch-action: pan-y;
}

.reader article {
  transition: opacity 0.18s ease;
}
.reader.loading article { opacity: 0.25; }

.reader p {
  margin: 0 0 0.9em;
  text-align: justify;
  hyphens: auto;
}

:root[lang="ar"] .reader {
  font-size: calc(1.4rem * var(--font-scale));
  line-height: 2.15;
}

:root[lang="en"] .reader {
  font-size: calc(1.2rem * var(--font-scale));
  line-height: 1.8;
}

.reader hr.fn-sep {
  width: 30%;
  margin: 1.5em 0 0.8em;
  margin-inline-end: auto;
  border: 0;
  border-top: 1px solid var(--muted);
}

.reader p.footnote {
  font-size: 0.8em;
  line-height: 1.7;
  color: var(--muted);
  margin-bottom: 0.3em;
  text-align: start;
}

.reader .error {
  text-align: center;
  color: var(--muted);
}

.en-note {
  margin-top: 2em;
  padding-top: 0.8em;
  border-top: 1px dashed var(--border);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

.bottombar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-top: 1px solid var(--border);
}

.bottombar .counter {
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

.font-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* − and + joined into one pill */
.font-size {
  display: inline-flex;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.font-size .btn {
  width: 44px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  box-shadow: none;
}

.font-size .btn:first-child {
  border-radius: 999px 0 0 999px;
  border-right-width: 0;
}

.font-size .btn:last-child {
  border-radius: 0 999px 999px 0;
}

.font-size .btn + .btn {
  border-left-color: var(--border);
}

@media (max-width: 480px) {
  .topbar { padding: 8px 12px; gap: 6px; }
  .page-select { max-width: 8.5em; }
  .bottombar { padding-inline: 12px; }
  .bottombar #prev, .bottombar #next { width: 44px; padding: 0; }
  .bottombar .label { display: none; }
  .bottombar .counter { font-size: 0.85rem; }
}
