/* ============================================================
   Ishraq al-Ma'ani — Tafsir of the Noble Qur'an
   Static website stylesheet
   Palette: deep green/teal + gold, Islamic-inspired
   ============================================================ */

:root {
  /* Light theme */
  --bg: #f7f4ec;
  --bg-alt: #efe9db;
  --surface: #ffffff;
  --surface-alt: #f3eee2;
  --text: #232a26;
  --text-muted: #5f6d66;
  --primary: #0e5c4a;
  --primary-dark: #0a4638;
  --primary-soft: #e1efe9;
  --gold: #b98a1f;
  --gold-strong: #9c7415;
  --gold-soft: #f6edd3;
  --border: #ddd5c1;
  --shadow: 0 2px 10px rgba(30, 40, 34, 0.08);
  --shadow-lg: 0 8px 30px rgba(30, 40, 34, 0.14);
  --header-bg: rgba(247, 244, 236, 0.92);
  --verse-arabic: #0a4638;
  --highlight: #fdf3d0;
  --scrollbar: #c9bfa4;
}

[data-theme="dark"] {
  --bg: #0d1512;
  --bg-alt: #101b17;
  --surface: #15211c;
  --surface-alt: #1a2a23;
  --text: #e9e4d6;
  --text-muted: #9aa89f;
  --primary: #35a98b;
  --primary-dark: #4fc0a2;
  --primary-soft: #1b3a30;
  --gold: #d4af37;
  --gold-strong: #e0c25c;
  --gold-soft: #3a3015;
  --border: #2a3a32;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --header-bg: rgba(13, 21, 18, 0.92);
  --verse-arabic: #f0ead8;
  --highlight: #3a3015;
  --scrollbar: #3a4a41;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Lora", Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

/* Subtle geometric pattern overlay for hero areas */
.pattern-bg {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23b98a1f' stroke-opacity='0.14' stroke-width='1'%3E%3Cpath d='M40 4 L52 28 L76 40 L52 52 L40 76 L28 52 L4 40 L28 28 Z'/%3E%3Cpath d='M40 20 L48 32 L60 40 L48 48 L40 60 L32 48 L20 40 L32 32 Z'/%3E%3Ccircle cx='40' cy='40' r='6'/%3E%3C/g%3E%3C/svg%3E");
}

[data-theme="dark"] .pattern-bg {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23d4af37' stroke-opacity='0.10' stroke-width='1'%3E%3Cpath d='M40 4 L52 28 L76 40 L52 52 L40 76 L28 52 L4 40 L28 28 Z'/%3E%3Cpath d='M40 20 L48 32 L60 40 L48 48 L40 60 L32 48 L20 40 L32 32 Z'/%3E%3Ccircle cx='40' cy='40' r='6'/%3E%3C/g%3E%3C/svg%3E");
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg-alt);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

/* ---------- Top header bar ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.7rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.brand .star {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.brand small {
  display: block;
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-search {
  flex: 1;
  min-width: 200px;
  max-width: 420px;
  margin-left: auto;
  display: flex;
  position: relative;
}

.header-search input {
  width: 100%;
  padding: 0.55rem 2.4rem 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.header-search input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.header-search button {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: var(--primary);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.header-search button:hover {
  background: var(--gold);
}

.header-search button svg {
  width: 15px;
  height: 15px;
}

/* Theme toggle */
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: border-color 0.2s, transform 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--gold);
  transform: rotate(15deg);
}

/* ---------- Hero (index) ---------- */
.hero {
  text-align: center;
  padding: 3.2rem 1.2rem 2.6rem;
  background: linear-gradient(180deg, var(--primary-soft), transparent 85%);
  border-bottom: 1px solid var(--border);
}

.hero .ornament {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  color: var(--gold);
}

.hero h1 {
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  color: var(--primary-dark);
  font-weight: 700;
  letter-spacing: 0.01em;
}

[data-theme="dark"] .hero h1 {
  color: var(--gold-strong);
}

.hero .arabic-title {
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: clamp(1.5rem, 3.5vw, 2.1rem);
  color: var(--gold-strong);
  margin-top: 0.4rem;
  direction: rtl;
}

.hero p.subtitle {
  margin-top: 0.7rem;
  color: var(--text-muted);
  font-size: 1.02rem;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

.hero .divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin: 1.4rem auto 0;
  max-width: 420px;
  color: var(--gold);
}

.hero .divider::before,
.hero .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold));
}

.hero .divider::after {
  background: linear-gradient(90deg, var(--gold), transparent);
}

/* ---------- Layout containers ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.6rem 1.2rem 4rem;
}

.container-narrow {
  max-width: 860px;
}

/* ---------- Surah list page ---------- */
.list-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.4rem;
}

.list-toolbar h2 {
  font-size: 1.25rem;
  color: var(--primary-dark);
}

[data-theme="dark"] .list-toolbar h2 {
  color: var(--gold-strong);
}

.list-toolbar .filter-input {
  margin-left: auto;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  min-width: 220px;
}

.list-toolbar .filter-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.surah-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.1rem;
}

.surah-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}

.surah-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--gold);
}

.surah-card .num-badge {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gold-strong);
  background: var(--gold-soft);
  border-radius: 12px;
  border: 1px solid var(--gold);
  font-variant-numeric: tabular-nums;
}

.surah-card .card-body {
  flex: 1;
  min-width: 0;
}

.surah-card .card-arabic {
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: 1.5rem;
  color: var(--primary-dark);
  direction: rtl;
  line-height: 1.3;
}

[data-theme="dark"] .surah-card .card-arabic {
  color: var(--gold-strong);
}

.surah-card .card-english {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text);
}

.surah-card .card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.surah-card .card-meta span {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
}

.surah-card .progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--surface-alt);
}

.surah-card .progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  transition: width 0.4s ease;
}

/* ---------- Surah reader page ---------- */
.reader-header {
  background: linear-gradient(180deg, var(--primary-soft), transparent 90%);
  border-bottom: 1px solid var(--border);
  padding: 1.8rem 1.2rem 1.4rem;
  text-align: center;
}

.reader-header .back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  margin-bottom: 1rem;
  transition: color 0.2s;
}

.reader-header .back-link:hover {
  color: var(--gold-strong);
}

.reader-header .surah-arabic {
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: clamp(2rem, 5vw, 2.8rem);
  color: var(--primary-dark);
  direction: rtl;
  line-height: 1.4;
}

[data-theme="dark"] .reader-header .surah-arabic {
  color: var(--gold-strong);
}

.reader-header .surah-english {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.2rem;
}

.reader-header .surah-meta {
  margin-top: 0.6rem;
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.reader-header .surah-meta span {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.15rem 0.7rem;
  border-radius: 999px;
}

.reader-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin: 1.4rem 0;
  flex-wrap: wrap;
}

.reader-nav .nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  transition: border-color 0.2s, background 0.2s;
}

.reader-nav .nav-btn:hover:not(.disabled) {
  border-color: var(--gold);
  background: var(--gold-soft);
}

.reader-nav .nav-btn.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.reader-nav .verse-jump {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.reader-nav select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  max-width: 180px;
}

/* Reading progress bar (fixed top) */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  z-index: 200;
  transition: width 0.1s linear;
}

/* Verse blocks */
.verse-list {
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

.verse-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow);
  scroll-margin-top: 90px;
  transition: box-shadow 0.3s, border-color 0.3s;
}

.verse-block.flash {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px var(--gold-soft), var(--shadow-lg);
  animation: flashPulse 2.2s ease;
}

@keyframes flashPulse {
  0%, 60% { box-shadow: 0 0 0 4px var(--gold-soft), var(--shadow-lg); }
  100% { box-shadow: var(--shadow); }
}

.verse-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.verse-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 0.5rem;
  background: var(--primary);
  color: #fff;
  border-radius: 9px;
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.verse-head .verse-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.verse-arabic {
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  line-height: 2.1;
  color: var(--verse-arabic);
  direction: rtl;
  text-align: right;
  margin-bottom: 0.9rem;
  word-spacing: 0.05em;
}

.verse-translation {
  font-size: 1.02rem;
  color: var(--text);
  border-left: 3px solid var(--gold);
  padding-left: 0.9rem;
  margin-bottom: 0.9rem;
}

[dir="rtl"] .verse-translation {
  border-left: none;
  border-right: 3px solid var(--gold);
  padding-left: 0;
  padding-right: 0.9rem;
}

.verse-commentary {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  font-size: 0.94rem;
  color: var(--text);
  line-height: 1.75;
}

.verse-commentary .commentary-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold-strong);
  margin-bottom: 0.4rem;
  font-weight: 700;
}

.verse-commentary p {
  margin-bottom: 0.6rem;
}

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

/* Resume banner */
.resume-banner {
  display: none;
  align-items: center;
  gap: 0.8rem;
  background: var(--gold-soft);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 0.8rem 1.1rem;
  margin-bottom: 1.2rem;
  font-size: 0.92rem;
}

.resume-banner.visible {
  display: flex;
}

.resume-banner button {
  margin-left: auto;
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  transition: background 0.2s;
}

.resume-banner button:hover {
  background: var(--gold-strong);
}

/* ---------- Search page ---------- */
.search-hero {
  text-align: center;
  padding: 2.4rem 1.2rem 1.6rem;
}

.search-hero h1 {
  font-size: clamp(1.5rem, 3.5vw, 2.1rem);
  color: var(--primary-dark);
}

[data-theme="dark"] .search-hero h1 {
  color: var(--gold-strong);
}

.search-hero .search-form {
  max-width: 620px;
  margin: 1.2rem auto 0;
  display: flex;
  gap: 0.5rem;
}

.search-hero .search-form input {
  flex: 1;
  padding: 0.7rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}

.search-hero .search-form input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.search-hero .search-form button {
  padding: 0.7rem 1.6rem;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.search-hero .search-form button:hover {
  background: var(--gold-strong);
}

.search-status {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 1rem 0;
}

.search-status .spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.search-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
  display: block;
}

.search-result:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.search-result .result-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.search-result .result-surah {
  font-weight: 700;
  color: var(--primary-dark);
}

[data-theme="dark"] .search-result .result-surah {
  color: var(--gold-strong);
}

.search-result .result-verse {
  font-size: 0.78rem;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
}

[data-theme="dark"] .search-result .result-verse {
  color: var(--gold-strong);
  background: var(--gold-soft);
}

.search-result .result-type {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.search-result .result-snippet {
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.65;
}

.search-result .result-snippet mark {
  background: var(--gold-soft);
  color: var(--gold-strong);
  border-radius: 3px;
  padding: 0 0.15em;
}

.search-result.surah-match {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search-result.surah-match .num-badge {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--gold-strong);
  background: var(--gold-soft);
  border-radius: 10px;
  border: 1px solid var(--gold);
}

.search-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.search-empty .empty-icon {
  font-size: 2.4rem;
  margin-bottom: 0.6rem;
}

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

.site-footer .footer-arabic {
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: 1.1rem;
  color: var(--gold-strong);
  direction: rtl;
  margin-bottom: 0.4rem;
}

/* ---------- Loading & error states ---------- */
.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.loading .spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0.8rem;
}

.error-box {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
  max-width: 560px;
  margin: 2rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.error-box h2 {
  color: var(--primary-dark);
  margin-bottom: 0.6rem;
}

[data-theme="dark"] .error-box h2 {
  color: var(--gold-strong);
}

.error-box code {
  background: var(--surface-alt);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .header-inner {
    gap: 0.6rem;
  }
  .header-search {
    order: 3;
    max-width: 100%;
    flex-basis: 100%;
  }
  .surah-grid {
    grid-template-columns: 1fr;
  }
  .verse-block {
    padding: 1.1rem 1rem;
  }
  .reader-nav {
    justify-content: center;
  }
  .list-toolbar .filter-input {
    margin-left: 0;
    width: 100%;
  }
}

/* ---------- Print ---------- */
@media print {
  .site-header, .reader-nav, .progress-bar, .resume-banner, .site-footer, .theme-toggle {
    display: none !important;
  }
  .verse-block {
    box-shadow: none;
    break-inside: avoid;
  }
  body {
    background: #fff;
    color: #000;
  }
}
