/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  /* Palette */
  --bg:           #F4EEDD;
  --bg-soft:      #FAF5E6;
  --surface:      #FFFBF1;
  --surface-elev: #FFFFFF;
  --ink:          #1F1A12;
  --ink-soft:     #4A3F2E;
  --ink-mute:     #8A7A5F;
  --rule:         #DCCFB1;
  --rule-soft:    #ECE2C8;

  /* Scripture accents */
  --accent:       #00574B;
  --accent-hover: #007362;
  --accent-soft:  #D7E8E3;
  --gold:         #B8902F;
  --gold-hover:   #A07828;
  --gold-soft:    #F0E2BD;
  --bible:        #1E3A5F;
  --bible-soft:   #DCE5F0;
  --danger:       #B23A2E;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(31,26,18,0.06), 0 1px 2px rgba(31,26,18,0.04);
  --shadow-md: 0 4px 16px rgba(31,26,18,0.09), 0 1px 4px rgba(31,26,18,0.05);
  --shadow-lg: 0 12px 36px rgba(31,26,18,0.12), 0 2px 8px rgba(31,26,18,0.06);

  /* Radii */
  --r-sm:   6px;
  --r-md:   12px;
  --r-lg:   18px;
  --r-pill: 999px;

  /* Typography */
  --font-display: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --font-body:    "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ar:      Georgia, "Times New Roman", serif;
  --font-ar-q:    Georgia, "Times New Roman", serif;
  --font-he:      "Frank Ruhl Libre", "SBL Hebrew", "Ezra SIL", serif;
  --font-mono:    ui-monospace, "SFMono-Regular", Menlo, monospace;
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--ink);
  font-feature-settings: "kern", "liga", "calt";
  -webkit-font-smoothing: antialiased;
}

/* Subtle paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

/* ── Container ───────────────────────────────────────────────────────────── */
.container {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  animation: fadeUp 0.22s ease-out both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Panel / Card ────────────────────────────────────────────────────────── */
.panel {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 1fr;
  background: var(--surface);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-lg);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-md);
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-md);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-sm);
}

/* ── Form controls ───────────────────────────────────────────────────────── */
input,
select,
textarea {
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface-elev);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

input:hover, select:hover, textarea:hover { border-color: var(--ink-mute); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Custom select chevron */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A7A5F' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.2rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.62rem 1.4rem;
  border: none;
  border-radius: var(--r-pill);
  cursor: pointer;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: #fff;
  letter-spacing: 0.015em;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

button:disabled {
  background: var(--rule);
  color: var(--ink-mute);
  cursor: default;
  transform: none;
  box-shadow: none;
}

/* ── Stack ───────────────────────────────────────────────────────────────── */
.stack { display: grid; gap: 0.75rem; }

/* ── Misc typography ─────────────────────────────────────────────────────── */
h1, h2, h3 { font-family: var(--font-display); }

.ar {
  font-family: var(--font-ar-q);
  font-size: 1.5rem;
  direction: rtl;
  text-align: right;
  line-height: 2;
}

.orig {
  font-size: 1.2rem;
  unicode-bidi: plaintext;
  line-height: 1.7;
}

.link { display: inline-block; margin-top: 2rem; }

/* ── Top nav ─────────────────────────────────────────────────────────────── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(255,251,241,0.82);
  backdrop-filter: blur(14px) saturate(150%);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  border: 1px solid var(--rule-soft);
  border-top: 2px solid var(--gold);
  border-radius: var(--r-lg);
  padding: 0.45rem 0.65rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow-md);
}

.topnav-wordmark {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.01em;
  margin-right: 0.4rem;
  padding: 0.25rem 0.5rem;
  text-decoration: none;
  flex-shrink: 0;
}

.topnav-wordmark span {
  font-family: var(--font-ar);
  font-style: italic;
  font-weight: 400;
  font-size: 1rem;
  color: var(--gold);
  opacity: 0.85;
  margin-left: 0.35rem;
}

.topnav-divider {
  width: 1px;
  height: 1.1rem;
  background: var(--rule);
  margin: 0 0.3rem;
  flex-shrink: 0;
}

.topnav-link {
  position: relative;
  padding: 0.38rem 0.8rem;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  background: transparent;
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.77rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-color: rgba(31, 26, 18, 0.08);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.topnav-link::after {
  content: "";
  position: absolute;
  bottom: 2px; left: 0.8rem; right: 0.8rem;
  height: 2px;
  background: var(--gold);
  border-radius: 1px;
  transform: scaleX(0);
  transition: transform 0.2s ease;
}

.topnav-link:hover {
  color: var(--accent);
  background: rgba(0,87,75,0.06);
  border-color: rgba(0,87,75,0.18);
}

.topnav-link:hover::after {
  transform: scaleX(0.6);
}

.topnav-link.active {
  color: var(--accent);
  font-weight: 700;
  background: var(--accent-soft);
  border-color: rgba(0,87,75,0.22);
}

.topnav-link.active::after {
  transform: scaleX(1);
}

/* ── Hero section ────────────────────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 2.75rem 1rem 2rem;
}

.hero-eyebrow {
  font-family: var(--font-ar);
  font-size: 0.95rem;
  color: var(--gold);
  letter-spacing: 0.04em;
  margin-bottom: 0.6rem;
  opacity: 0.9;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 400;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 0.75rem;
}

.hero-title em {
  font-style: italic;
  color: var(--accent);
}

.hero-tagline {
  font-size: 1rem;
  color: var(--ink-soft);
  max-width: 500px;
  margin: 0 auto 0;
  line-height: 1.6;
}

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

.hero-divider::before,
.hero-divider::after {
  content: "";
  height: 1px;
  flex: 1;
}

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

.hero-divider span { font-size: 0.9rem; opacity: 0.75; }

/* Compact hero variant for inner pages */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header-name {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  color: var(--ink);
  margin: 0 0 0.15rem;
}

.page-header-desc {
  font-size: 0.9rem;
  color: var(--ink-mute);
  line-height: 1.55;
  margin: 0;
}

/* ── Scripture toggle ────────────────────────────────────────────────────── */
.scripture-toggle {
  display: inline-flex;
  gap: 0;
  margin-bottom: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--rule-soft);
}

.scripture-toggle__btn {
  padding: 0.42rem 1.15rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-mute);
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  border-radius: 0;
}

.scripture-toggle__btn:first-child { border-radius: var(--r-md) 0 0 var(--r-md); }
.scripture-toggle__btn:last-child  { border-radius: 0 var(--r-md) var(--r-md) 0; border-left: none; }

.scripture-toggle__btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.controls-stack { display: flex; flex-direction: column; gap: 0.5rem; }
.controls-stack[hidden] { display: none; }

.translator-info {
  font-size: 0.82rem;
  color: var(--ink-mute);
  font-style: italic;
  min-height: 1.1rem;
}

.translation-note {
  margin-top: 0.6rem;
  padding: 0.55rem 0.8rem;
  border-left: 3px solid var(--gold);
  background: var(--gold-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ── Inline word (Quran quick-view) ─────────────────────────────────────── */
.word-line { display: flex; flex-wrap: wrap; gap: 0.5rem; direction: rtl; }

.word {
  position: relative;
  padding: 0.45rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-sm);
  font-size: 1.5rem;
  transition: box-shadow 0.15s;
}

.word:hover { box-shadow: var(--shadow-sm); }

.word::after {
  content: attr(data-translation);
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.45rem 0.6rem;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 200px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.12s;
}

.word:hover::after { opacity: 1; }

.word-ayah-label {
  font-weight: bold;
  color: var(--accent);
  margin: 0.5rem 0 0.25rem;
}

.word-row { margin-bottom: 0.5rem; }

.token-info {
  font-size: 0.8rem;
  color: var(--ink-mute);
  margin-bottom: 0.5rem;
  font-family: var(--font-mono);
}

/* ── Loading skeleton ────────────────────────────────────────────────────── */
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--rule-soft);
  border-radius: var(--r-md);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.65) 50%, transparent 100%);
  animation: shimmer 1.5s ease-in-out infinite;
}

.loading-skeletons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 0;
}

.loading-skeletons .skel-card {
  height: 120px;
}

/* ── Error ───────────────────────────────────────────────────────────────── */
.error { color: var(--danger); }
.loading { color: var(--ink-mute); padding: 1rem 0; }

/* ── Dot-pulse "Thinking" animation ──────────────────────────────────────── */
@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40%           { opacity: 1;    transform: scale(1);   }
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
}

.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-pulse 1.4s ease-in-out infinite both;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── Turn fade-in ────────────────────────────────────────────────────────── */
@keyframes turnIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.qa-turn-new { animation: turnIn 0.25s ease-out both; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hero-title { font-size: clamp(1.65rem, 6vw, 2.2rem); }
  .hero { padding: 2rem 1rem 1.5rem; }
  .panel { padding: 1rem; border-radius: var(--r-md); }
}

@media (max-width: 640px) {
  .container { padding: 0.75rem 0.75rem 2rem; }
  .topnav { border-radius: var(--r-md); gap: 0.15rem; overflow-x: auto; flex-wrap: nowrap; }
  .topnav-wordmark span { display: none; }
  .topnav-divider { display: none; }
  .topnav-link { padding: 0.35rem 0.55rem; font-size: 0.7rem; letter-spacing: 0.03em; white-space: nowrap; }
  .ar, .word { font-size: 1.25rem; }
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--ink-mute);
  font-style: italic;
  font-family: var(--font-display);
}
.empty-state::before {
  content: "✦";
  display: block;
  color: var(--gold);
  font-size: 1.4rem;
  margin-bottom: 0.4rem;
  font-style: normal;
}
