/* ---------- 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;
}

[hidden] { display: none !important; }

.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 .book-link {
  color: inherit;
  text-decoration: none;
}

.masthead-title .book-link:hover { color: var(--accent); }

.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; }

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

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

/* ---------- Cover card (library grid + book page) ---------- */
.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;
  text-wrap: balance;
}

.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);
}

.cover-card-small {
  max-width: none;
  padding: 1.5rem 1rem;
}

.cover-card-small .cover-kicker { margin-bottom: 1rem; }
.cover-card-small .cover-title { font-size: 1.5rem; }
.cover-card-small .cover-rule { margin: 1.1rem 0; }
.cover-card-small .cover-author { font-size: 0.95rem; }

/* ---------- Library (home) ---------- */
.library-main { max-width: 60rem; }

.library-title {
  font-size: 1.5rem;
  margin: 0.5rem 0 1.5rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 1.75rem;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  color: var(--fg);
  text-decoration: none;
}

.book-card .cover-card { transition: transform 0.15s ease, border-color 0.15s ease; }
.book-card:hover .cover-card,
.book-card:focus-visible .cover-card {
  border-color: var(--accent);
  transform: translateY(-3px);
}

.book-card:focus-visible { outline: none; }

.book-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.status-badge {
  display: inline-block;
  font-size: 0.8rem;
  padding: 0.15em 0.7em;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

.status-in-progress {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Book page ---------- */
.book-main { max-width: 52rem; }

.book-hero {
  display: grid;
  grid-template-columns: 15rem 1fr;
  gap: 2rem;
  align-items: center;
  margin: 1rem 0 2.5rem;
}

.book-hero .cover-card { max-width: none; }
.book-hero .cover-title { font-size: 1.8rem; }

.book-info h1 {
  font-size: 1.8rem;
  margin: 0 0 0.3rem;
}

.book-info p { margin: 0 0 0.6rem; }

.book-info-author {
  font-size: 1.1rem;
  font-weight: 600;
}

.book-info-original {
  color: var(--fg-muted);
  font-size: 0.9rem;
  text-align: right;
}

.book-info-desc { line-height: 2; }

.home-actions.book-actions {
  justify-content: flex-start;
  margin-top: 1.25rem;
}

.toc h2 {
  font-size: 1.2rem;
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.4rem 1rem;
}

.toc-list a {
  display: block;
  padding: 0.4em 0.6em;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
}

.toc-list a:hover { background: var(--bg-elevated); color: var(--accent); }

.toc-list a.toc-current {
  color: var(--accent);
  font-weight: 600;
}

.empty-note {
  color: var(--fg-muted);
  text-align: center;
  padding: 1.5rem 0;
}

.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; }
  .book-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .cover-card-small .cover-title { font-size: 1.2rem; }
}

@media (max-width: 40rem) {
  .book-hero {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .book-hero .cover-card { max-width: 14rem; }
  .book-info-original { text-align: center; }
  .home-actions.book-actions { justify-content: center; }
}
