/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:           #faf7f2;
  --surface:      #ffffff;
  --border:       #e4ddd0;
  --text:         #2a1f14;
  --text-muted:   #7a6a55;
  --accent:       #8b3252;
  --accent-hover: #6d2540;
  --accent-light: #f5eaef;
  --radius:       6px;
  --shadow:       0 1px 4px rgba(0,0,0,.08);
}

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Vazirmatn', 'Tahoma', 'Arial', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  direction: rtl;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.site-header .container {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.site-title:hover { text-decoration: none; color: var(--accent-hover); }

/* ── Search bar (header) ───────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  flex: 1;
  gap: 0.5rem;
}

.search-bar input {
  flex: 1;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-bar button {
  padding: 0.4rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  white-space: nowrap;
}
.search-bar button:hover { background: var(--accent-hover); }

.search-bar .adv-link {
  align-self: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.search-bar .adv-link:hover { color: var(--accent); }

/* ── Main ──────────────────────────────────────────────────────────────────── */
main.container { padding-top: 2rem; padding-bottom: 3rem; }

/* ── Footer ────────────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Breadcrumb ────────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }

.breadcrumb > * + *::before {
  content: '›';
  margin-left: 0.25rem;
  color: var(--border);
}

/* ── Page title ────────────────────────────────────────────────────────────── */
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text);
}

/* ── Poet grid ─────────────────────────────────────────────────────────────── */
.poet-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.poet-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.poet-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(139,50,82,.12);
  text-decoration: none;
}

.poet-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
}

.poet-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Poet bio ──────────────────────────────────────────────────────────────── */
.poet-bio {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.9;
}

/* ── Item list (categories, poems) ────────────────────────────────────────── */
.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.item-link {
  display: block;
  padding: 0.55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
}
.item-link:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  text-decoration: none;
  color: var(--accent);
}
.item-link.poem-link::before {
  content: '◆ ';
  font-size: 0.65em;
  color: var(--text-muted);
  vertical-align: middle;
}

/* ── Poem ──────────────────────────────────────────────────────────────────── */
.poem-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 2rem;
  color: var(--text);
}

.poem-body {
  max-width: 700px;
  margin: 0 auto 2.5rem;
}

/* Couplet: two hemistichs side by side */
.verse {
  margin: 0.1rem 0;
}

.couplet {
  display: flex;
  direction: rtl;
  border-bottom: 1px solid transparent;
  padding: 0.3rem 0;
}
.couplet:nth-child(odd) { background: rgba(0,0,0,.018); }

.hemistich {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  line-height: 2;
  padding: 0 0.5rem;
}

.hemistich-right {
}

/* Centered verse (tarji/tarkib band) */
.centered-verse {
  text-align: center;
  font-size: 1.1rem;
  line-height: 2;
  padding: 0.3rem 0;
  font-weight: 500;
  color: var(--accent);
}

/* Single line (Nima / free verse) */
.single-verse {
  font-size: 1.05rem;
  line-height: 2;
  padding: 0.2rem 1rem;
}

/* Prose */
.prose {
  font-size: 1.1rem;
  line-height: 2;
  padding: 0.4rem 0;
  color: var(--text);
}

/* ── Settings ──────────────────────────────────────────────────────────────── */
.settings-wrap {
  position: relative;
}

.settings-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.settings-btn:hover { color: var(--accent); border-color: var(--border); }

.settings-panel {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 0.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6rem 0.75rem;
  min-width: 180px;
  z-index: 100;
  gap: 0.5rem;
  flex-direction: column;
}
.settings-panel.open { display: flex; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
}

.settings-toggle {
  padding: 0.2rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.settings-toggle:hover { border-color: var(--accent); color: var(--accent); }

.settings-select {
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  direction: rtl;
}

/* Poem font — set via --poem-font CSS variable from JS */
.hemistich,
.centered-verse,
.single-verse,
.prose {
  font-family: var(--poem-font, 'Vazirmatn'), 'Tahoma', sans-serif;
}

/* Gulzar (Nastaliq) needs extra breathing room */
.poem-font-nastaliq .hemistich,
.poem-font-nastaliq .centered-verse,
.poem-font-nastaliq .single-verse,
.poem-font-nastaliq .prose {
  font-size: 1.3rem;
  line-height: 3;
}

/* ── Dark mode ─────────────────────────────────────────────────────────────── */
:root.dark {
  --bg:           #1c1510;
  --surface:      #261d14;
  --border:       #3d3025;
  --text:         #e8ddd0;
  --text-muted:   #9a8a75;
  --accent:       #c4728a;
  --accent-hover: #d4879c;
  --accent-light: #3d2030;
  --shadow:       0 1px 4px rgba(0,0,0,.4);
}

/* ── Poem navigation ───────────────────────────────────────────────────────── */
.poem-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
  font-size: 0.9rem;
}

.nav-link {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.nav-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.nav-up { color: var(--accent); border-color: var(--accent); }

/* ── Search page ───────────────────────────────────────────────────────────── */
.search-form { margin-bottom: 1.5rem; }

.search-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  direction: rtl;
}
.search-input:focus { outline: none; border-color: var(--accent); }

.poet-select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  direction: rtl;
}

.search-btn {
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
}
.search-btn:hover { background: var(--accent-hover); }

.result-count {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.search-results { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }

.result-item {
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.result-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  display: block;
  margin-bottom: 0.2rem;
}

.result-poet {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.4rem;
}

.result-sample {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.8;
}

mark {
  background: #fde68a;
  color: #2a1f14;
  padding: 0 2px;
  border-radius: 2px;
}

:root.dark mark {
  background: #d97706;
  color: #1c1510;
}

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.page-link {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-muted);
}
.page-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.page-link.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.page-gap {
  padding: 0.35rem 0.4rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ── Advanced search ────────────────────────────────────────────────────────── */
.adv-switch-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  align-self: center;
}

.adv-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.adv-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.adv-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.adv-input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
}
.adv-input:focus { outline: none; border-color: var(--accent); }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty { color: var(--text-muted); font-style: italic; margin-top: 1rem; }

/* ── Error pages ───────────────────────────────────────────────────────────── */
.error-page {
  text-align: center;
  padding: 3rem 1rem 2rem;
}
.error-code {
  font-size: 5rem;
  font-weight: 300;
  line-height: 1;
  color: var(--border);
  margin-bottom: 0.5rem;
}
.error-title { margin-bottom: 1rem; }
.error-message {
  color: var(--text-muted);
  max-width: 32rem;
  margin: 0 auto 2rem;
  line-height: 1.8;
}
.error-actions { margin-top: 1.5rem; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .couplet { flex-direction: column; }
  .hemistich-right { border-left: none; border-bottom: 1px solid var(--border); }
  .hemistich { text-align: right; }
  .poet-grid { grid-template-columns: 1fr 1fr; }
  .poem-nav { flex-wrap: wrap; font-size: 0.85rem; }
  .nav-link { max-width: 160px; }
}
