/* ---------- Font ---------- */
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Variable.woff2") format("woff2-variations"),
       url("../fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- Theme tokens ---------- */
:root {
  --bg: #faf7f2;
  --bg-elevated: #ffffff;
  --fg: #2a2420;
  --fg-muted: #6b6055;
  --border: #e4dcd0;
  --accent: #9a3324;
  --accent-fg: #ffffff;
  --link: #9a3324;
  --shadow: 0 1px 3px rgba(40, 30, 20, 0.08);
  --reader-font-size: 1.15rem;
}

:root[data-theme="dark"] {
  --bg: #1b1815;
  --bg-elevated: #242019;
  --fg: #ece5da;
  --fg-muted: #a99f92;
  --border: #3a332b;
  --accent: #e0a458;
  --accent-fg: #1b1815;
  --link: #e0a458;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: "Vazirmatn", "Tahoma", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button, select {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5em 0.9em;
  cursor: pointer;
}

button:hover, select:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Site nav (shared across all pages) ---------- */
.site-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.site-nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  text-decoration: none;
}

.site-nav-links {
  display: flex;
  gap: 1.1rem;
  flex: 1;
}

.site-nav-links a {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.25em 0;
  border-bottom: 2px solid transparent;
}

.site-nav-links a:hover { color: var(--fg); }

.site-nav-links a.active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

/* ---------- Masthead ---------- */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.masthead-title h1 {
  font-size: 1.3rem;
  margin: 0;
  font-weight: 700;
}

.masthead-title .author {
  margin: 0.15em 0 0;
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.chapter-picker select {
  min-width: 12rem;
  max-width: 60vw;
}

.font-size-controls {
  display: flex;
  gap: 0.3rem;
}

.font-size-controls button {
  padding: 0.5em 0.7em;
  font-weight: 600;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5em;
  height: 2.5em;
  padding: 0;
}

.theme-icon::before {
  content: "☾";
  font-size: 1.1rem;
}
:root[data-theme="dark"] .theme-icon::before {
  content: "☀";
}

/* ---------- Main / reader ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chapter-nav-bottom {
  margin-top: 2rem;
  margin-bottom: 0;
}

.chapter-nav button {
  flex: 1;
  max-width: 12rem;
}

.chapter-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.review-note {
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-elevated));
  border: 1px solid var(--accent);
  color: var(--fg);
  border-radius: 8px;
  padding: 0.7em 1em;
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.reader {
  font-size: var(--reader-font-size);
  line-height: 2.05;
}

.reader h2 {
  font-size: 1.4em;
  margin: 0 0 1em;
  text-align: center;
}

.reader p {
  margin: 0 0 1.3em;
  text-align: right;
}

.reader p:last-child { margin-bottom: 0; }

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

.reader .error { color: var(--accent); }

/* ---------- Home / cover page ---------- */
.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.25rem;
  padding: 2.5rem 1.25rem;
  max-width: none;
}

.cover-card {
  width: 100%;
  max-width: 20rem;
  aspect-ratio: 2 / 3;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.5rem;
}

.cover-kicker {
  margin: 0 0 1.5rem;
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  color: var(--fg-muted);
}

.cover-title {
  margin: 0;
  font-size: 2.1rem;
  line-height: 1.35;
  font-weight: 800;
}

.cover-rule {
  width: 3rem;
  height: 2px;
  background: var(--accent);
  margin: 1.5rem 0;
}

.cover-author {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.cover-sub {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.home-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  display: inline-block;
  padding: 0.7em 1.7em;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  color: var(--fg);
  background: var(--bg-elevated);
}

.btn:hover { border-color: var(--accent); }

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

.btn-primary:hover { opacity: 0.9; }

/* ---------- Static content pages (about, etc.) ---------- */
.page-content {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  font-size: 1.05rem;
  line-height: 2;
}

.page-content h1 {
  font-size: 1.6rem;
  margin: 0 0 1em;
}

.page-content p { margin: 0 0 1.3em; text-align: right; }
.page-content p:last-child { margin-bottom: 0; }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  color: var(--fg-muted);
  font-size: 0.85rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 32rem) {
  .masthead {
    flex-direction: column;
    align-items: stretch;
  }
  .controls { justify-content: space-between; }
  .chapter-picker select { max-width: 100%; flex: 1; }
}
