/* SunnahFinder styles — no framework, light/dark via [data-theme].
   Visual system "Mushaf": warm paper light, candlelight dark, serif
   headings, quiet accents, single-dot grade badges. All class names are
   unchanged so js/app.js needs no edits. */

:root {
  --bg: #faf7f1;
  --bg-card: #fffdf8;
  --surface-alt: #f5efe2;
  --text: #2c2a24;
  --text-muted: #7a7264;
  --text-faint: #a89e88;
  --accent: #37614f;
  --accent-soft: #ecf2ee;
  --on-accent: #fffdf8;
  --border: #e0d8c4;
  --hairline: #efe9da;
  --rule: #cbb98d;
  --mark: #f2e6c4;
  --good: #37614f;
  --ok: #8a6d2f;
  --weak: #a35d3a;
  --bad: #9e3b39;
  --shadow: 0 1px 2px rgba(80, 70, 50, 0.06);
  --arabic-font: "Amiri", "Scheherazade New", "Noto Naskh Arabic", "Traditional Arabic", serif;
  --english-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif-font: "Lora", Georgia, "Times New Roman", serif;
  --reading-scale: 1; /* set from Settings › Text size */
}

[data-theme="dark"] {
  --bg: #1a1814;
  --bg-card: #201d17;
  --surface-alt: #262218;
  --text: #e4ddcf;
  --text-muted: #9b937f;
  --text-faint: #736b57;
  --accent: #c9b078;
  --accent-soft: #2a2519;
  --on-accent: #1a1814;
  --border: #2e2a22;
  --hairline: #262218;
  --rule: #57503f;
  --mark: #4a3f22;
  --good: #8fb89e;
  --ok: #c9b078;
  --weak: #cf9b7a;
  --bad: #d98d8a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--english-font);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}

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

mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

code, kbd {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.9em;
}

::selection { background: rgba(203, 185, 141, 0.4); }

/* ---------- layout ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  color: var(--text);
  font-size: 1.2rem;
  font-family: var(--serif-font);
  font-weight: 600;
  letter-spacing: 0.01em;
  z-index: 1; /* stay above the absolutely-centered Bismillah */
}
.brand:hover { text-decoration: none; }
.brand-name b { color: var(--accent); font-weight: 600; font-style: italic; }

/* Basmala, centered in the header on wide screens. */
.bismillah {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--arabic-font);
  font-size: 1.35rem;
  line-height: 1;
  color: var(--accent);
  opacity: 0.9;
  white-space: nowrap;
  pointer-events: none;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- settings: desktop right-hand drawer ---------- */

.header-actions { position: relative; }

/* Backdrop dimming the page behind the open drawer. */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 8, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s ease;
  z-index: 190;
}
.settings-backdrop.show { opacity: 1; visibility: visible; }

/* The drawer slides in from the right and covers about a third of the screen. */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  width: clamp(320px, 33.333vw, 460px);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 50px rgba(40, 30, 15, 0.18);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.28s ease, visibility 0.28s ease;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.settings-panel.open { transform: none; visibility: visible; }
.settings-panel-inner { display: flex; flex-direction: column; height: 100%; }
.settings-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1.3rem;
  border-bottom: 1px solid var(--hairline);
}
.settings-head h2 { font-size: 1.15rem; margin: 0; font-family: var(--serif-font); font-weight: 600; }
.settings-head .modal-x { margin-left: auto; }

/* ---------- shared settings form (drawer + mobile page) ---------- */

.settings-form { padding: 1.1rem 1.3rem 1.6rem; overflow-y: auto; }
.set-group {
  display: block;
  margin-bottom: 1.1rem;
}
.set-legend {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.settings-form select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.6rem;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.settings-note { font-size: 0.78rem; color: var(--text-muted); margin: 0.3rem 0 0; }

/* Live specimen — mirrors the reading font + size the user picks. */
.settings-preview {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  padding: 0.9rem 1.05rem;
}
.preview-ara {
  font-family: var(--arabic-font);
  font-size: calc(1.55rem * var(--reading-scale));
  line-height: 2;
  direction: rtl;
  text-align: right;
  margin: 0 0 0.5rem;
}
.preview-eng {
  font-family: var(--english-font);
  font-size: calc(1rem * var(--reading-scale));
  line-height: 1.6;
  margin: 0;
  color: var(--text);
}

/* Default collections picker. */
.set-book-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.9rem;
  margin: 0.5rem 0 0.6rem;
}
.set-book {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
}
.set-book input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; cursor: pointer; }
.set-book .muted { font-size: 0.75rem; }

/* Settings as a full page (mobile route). Reuses .settings-form inside. */
.settings-title { font-size: 1.5rem; font-family: var(--serif-font); font-weight: 600; margin: 0 0 1rem; }
.settings-page .settings-form { padding: 0; overflow: visible; }
.settings-page .set-group { margin-bottom: 1.4rem; }

.app { max-width: 860px; margin: 0 auto; padding: 1.2rem; min-height: 70vh; }

.site-footer {
  max-width: 860px;
  margin: 2rem auto 0;
  padding: 1.2rem;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.85rem;
}

/* ---------- search ---------- */

.hero { text-align: center; padding: 2.5rem 0 1.5rem; }
.hero h1 { font-size: 2rem; margin: 0 0 0.4rem; font-family: var(--serif-font); font-weight: 600; letter-spacing: -0.01em; }
.tagline { color: var(--text-muted); margin: 0 0 1.6rem; font-family: var(--serif-font); font-style: italic; }

.search-form {
  display: flex;
  gap: 0.5rem;
  max-width: 640px;
  margin: 0 auto;
}
.search-form input {
  flex: 1;
  font-size: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.search-form input:focus { border-color: var(--accent); }
.search-form-big input { font-size: 1.1rem; padding: 0.9rem 1.15rem; }

.search-btn {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 11px;
  padding: 0 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
}
.search-btn:hover { filter: brightness(1.06); }

.search-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  margin: 0.7rem auto 0;
  max-width: 640px;
}

.examples { margin: 1.1rem 0 1.4rem; color: var(--text-muted); font-size: 0.9rem; }
.examples a {
  display: inline-block;
  margin: 0.2rem 0.3rem;
  padding: 0.4rem 0.85rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
}
.examples a:hover { text-decoration: none; filter: brightness(0.97); }

/* ---------- scope chips ---------- */

.scope {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.9rem 0;
}
.scope-label { color: var(--text-muted); font-size: 0.85rem; }
.scope-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; }

.chip {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--accent); }
.chip-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.chip-check { font-size: 0.75em; }
.chip-ghost { color: var(--text-muted); border-style: dashed; }

/* ---------- filters ---------- */

.filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.4rem 0 0.2rem;
}
.filters input {
  flex: 0 1 320px;
  min-width: 0;
  font-size: 0.88rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text);
  outline: none;
}
.filters input:focus { border-color: var(--accent); }
.grade-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.chip-sm { font-size: 0.78rem; padding: 0.2rem 0.65rem; }

.partial-divider { margin-top: 1.6rem; }

/* ---------- results ---------- */

.search-page .search-form { margin-top: 0.4rem; }

.result-count { color: var(--text-muted); font-size: 0.9rem; margin: 1.2rem 0 0.8rem; font-family: var(--serif-font); }

.result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.95rem 1.15rem;
  margin-bottom: 0.8rem;
  transition: border-color 0.15s;
}
.result:hover { border-color: var(--rule); }
.result-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.result-ref { font-weight: 600; color: var(--accent); font-family: var(--serif-font); }
.result-meta { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.card-copy {
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  border-radius: 7px;
  font-size: 0.72rem;
  padding: 0.15rem 0.55rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.card-copy:hover { color: var(--accent); border-color: var(--accent); }

.match-badge {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.05rem 0.6rem;
  white-space: nowrap;
}
.result-text { margin: 0; font-size: calc(1rem * var(--reading-scale)); }
.result-text-ar {
  font-family: var(--arabic-font);
  font-size: calc(1.25rem * var(--reading-scale));
  line-height: 2;
  text-align: right;
}
.quiet-link { color: inherit; }
.quiet-link:hover { text-decoration: none; }

/* Grades: quiet dot + label instead of a bordered pill. */
.grade {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.74rem;
  padding: 0;
  border: none;
  margin-left: 0.3rem;
  white-space: nowrap;
}
.grade::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.grade small { opacity: 0.7; }
.grade-good { color: var(--good); }
.grade-ok { color: var(--ok); }
.grade-weak { color: var(--weak); }
.grade-bad { color: var(--bad); }
.grade-neutral { color: var(--text-muted); }

.no-results { margin-top: 1.5rem; }
.no-results-tips { color: var(--text-muted); font-size: 0.9rem; }

.error { color: var(--bad); margin-top: 1.5rem; }
.muted { color: var(--text-muted); }

/* ---------- loading ---------- */

.loading-panel {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 0;
  font-size: 0.92rem;
}
.load-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.load-list li.done { color: var(--good); }
.load-list .load-state { font-variant-numeric: tabular-nums; }

.spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 0.6rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- browse ---------- */

.crumbs { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.8rem; }

.books h2 { font-size: 1.2rem; margin: 2rem 0 0.8rem; font-family: var(--serif-font); font-weight: 600; }
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.7rem;
}
.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.95rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  color: var(--text);
  transition: border-color 0.15s;
}
.book-card:hover { border-color: var(--accent); text-decoration: none; }
.book-card-name { font-weight: 600; font-family: var(--serif-font); }
.book-card-sub { color: var(--text-muted); font-size: 0.82rem; }

.section-list { padding-left: 0; list-style: none; }
.section-list li { border-bottom: 1px solid var(--hairline); }
.section-list a {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.65rem 0.4rem;
  color: var(--text);
}
.section-list a:hover { background: var(--accent-soft); text-decoration: none; }
.sec-num { color: var(--text-faint); min-width: 2.2rem; text-align: right; font-variant-numeric: tabular-nums; }
.sec-range { margin-left: auto; color: var(--text-faint); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.section-title { font-size: 1.35rem; font-family: var(--serif-font); font-weight: 600; }

/* ---------- hadith detail ---------- */

.hadith-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.5rem 1.7rem;
}
.hadith-card h1 { font-size: 1.4rem; margin: 0 0 0.2rem; font-family: var(--serif-font); font-weight: 600; }
.hadith-section { margin: 0 0 0.3rem; font-size: 0.9rem; color: var(--accent); }
.hadith-grades { margin: 0 0 0.9rem; }

.hadith-arabic {
  font-family: var(--arabic-font);
  font-size: calc(1.6rem * var(--reading-scale));
  line-height: 2.2;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 1.1rem;
  margin-bottom: 1.1rem;
  overflow-wrap: break-word;
}

.hadith-english { white-space: pre-wrap; font-size: calc(1rem * var(--reading-scale)); }

.hadith-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.3rem;
}
.action-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 9px;
  padding: 0.45rem 0.95rem;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-block;
  transition: filter 0.15s;
}
.action-btn:hover { filter: brightness(0.97); text-decoration: none; }

.pager {
  display: flex;
  justify-content: space-between;
  margin-top: 1.3rem;
  font-variant-numeric: tabular-nums;
}
.pager a {
  padding: 0.4rem 0.95rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 9px;
}
.pager a:hover { text-decoration: none; filter: brightness(0.97); }

/* ---------- related & explanations ---------- */

.related h2, .explanations h2 {
  font-size: 1.1rem;
  margin: 1.9rem 0 0.7rem;
  font-family: var(--serif-font);
  font-weight: 600;
}
.related .how, .explanations .how { font-weight: 400; font-size: 0.8rem; color: var(--text-muted); }
.related-note { font-size: 0.85rem; }

.linklike {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.linklike:disabled { color: var(--text-muted); cursor: default; text-decoration: none; }

.explain-links { list-style: none; padding: 0; margin: 0; }
.explain-links li {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 0.65rem 0.95rem;
  margin-bottom: 0.5rem;
  font-size: 0.92rem;
}

/* ---------- mobile ---------- */

@media (max-width: 560px) {
  .app { padding: 0.8rem; }
  .hero { padding-top: 1.2rem; }
  .hero h1 { font-size: 1.55rem; }
  .search-form { gap: 0.4rem; }
  .search-form input { min-width: 0; font-size: 16px; } /* 16px stops iOS focus-zoom */
  .search-btn { padding: 0 0.9rem; }
  /* comfortable touch targets */
  .chip { padding: 0.55rem 0.95rem; }
  .card-copy { padding: 0.3rem 0.7rem; }
  .icon-btn { padding: 0.4rem 0.7rem; }
  .pager a { padding: 0.55rem 1.1rem; }
  .hadith-card { padding: 1.1rem; }
  .hadith-arabic { font-size: calc(1.35rem * var(--reading-scale)); line-height: 2; }
  .hadith-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .hadith-actions .action-btn { text-align: center; padding: 0.7rem 0.5rem; }
  .result { padding: 0.8rem 0.9rem; }
  .result-head { flex-direction: column; align-items: flex-start; gap: 0.3rem; }
  .site-footer { font-size: 0.8rem; }

  /* Mobile: no gear in the header, no drawer — Settings is its own page. */
  .header-actions { display: none; }
  .settings-panel, .settings-backdrop { display: none; }
  .bismillah { position: static; transform: none; margin-left: auto; font-size: 1.1rem; }
  .settings-form select { font-size: 16px; padding: 0.65rem 0.6rem; }
  .set-book-list { grid-template-columns: 1fr 1fr; }
  .set-book { padding: 0.15rem 0; }

  /* filters: stack, full-width narrator box, bigger grade chips */
  .filters { gap: 0.45rem; }
  .filters input { flex: 1 1 100%; font-size: 16px; padding: 0.55rem 0.9rem; }
  .chip-sm { font-size: 0.82rem; padding: 0.6rem 0.95rem; }
}

/* ---------- collection picker (summary + modal) ---------- */

.scope-summary { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 0.4rem; margin: 0.9rem 0 0.2rem; color: var(--text-muted); font-size: 0.9rem; }
.scope-pick {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s;
}
.scope-pick:hover { border-color: var(--accent); }
.scope-caret { color: var(--text-muted); font-size: 0.75em; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 8, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 440px;
  max-width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}
.modal-head { display: flex; align-items: center; gap: 0.6rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--hairline); }
.modal-title { font-family: var(--serif-font); font-weight: 600; font-size: 1.05rem; }
.modal-sub { color: var(--text-muted); font-size: 0.78rem; margin-top: 1px; }
.modal-x {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  cursor: pointer;
}
.modal-x:hover { border-color: var(--accent); color: var(--accent); }
.modal-body { overflow-y: auto; }
.scope-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--hairline);
  padding: 0.75rem 1.1rem;
  cursor: pointer;
  color: var(--text);
  font: inherit;
}
.scope-row:hover { background: var(--accent-soft); }
.scope-box {
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  color: var(--on-accent);
}
.scope-row.on .scope-box { background: var(--accent); border-color: var(--accent); }
.scope-row-name { flex: 1; font-family: var(--serif-font); }
.scope-row-sub { color: var(--text-faint); font-size: 0.75rem; white-space: nowrap; }
.modal-foot { display: flex; align-items: center; gap: 1rem; padding: 0.85rem 1.1rem; border-top: 1px solid var(--hairline); }
.modal-foot .search-btn { margin-left: auto; padding: 0.5rem 1.3rem; }

/* ---------- bottom tab bar (mobile) ---------- */

.tabbar { display: none; }
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.4rem 0;
  color: var(--text-faint);
  background: none;
  border: none;
  font: inherit;
  font-size: 0.7rem;
  cursor: pointer;
  text-decoration: none;
}
.tab svg { width: 22px; height: 22px; }
.tab-on { color: var(--accent); }
.tab:hover { text-decoration: none; }

/* ---------- hadith detail: two-column with meta rail ---------- */

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 2.5rem; align-items: start; }
.detail-rail { position: sticky; top: 5rem; display: flex; flex-direction: column; gap: 1.5rem; }
.rail-label { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); margin: 0 0 0.6rem; font-weight: 700; }
.rail-facts { margin: 0; }
.rail-facts > div { display: flex; justify-content: space-between; gap: 0.8rem; padding: 0.4rem 0; border-bottom: 1px solid var(--hairline); font-size: 0.85rem; }
.rail-facts > div:last-child { border-bottom: none; }
.rail-facts dt { color: var(--text-faint); margin: 0; }
.rail-facts dd { margin: 0; text-align: right; }
.rail-facts dd .grade { margin: 0; justify-content: flex-end; }
.detail-rail .explain-links li { background: none; border: none; border-radius: 0; padding: 0.3rem 0; margin: 0; font-size: 0.85rem; }

/* ---------- "also narrated in": compact rows ---------- */

.similar-row {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.65rem 0.3rem;
  border-bottom: 1px solid var(--hairline);
  color: var(--text);
}
.similar-row:hover { text-decoration: none; background: var(--accent-soft); }
.similar-ref { color: var(--accent); font-family: var(--serif-font); font-weight: 600; white-space: nowrap; }
.similar-text { flex: 1; color: var(--text-muted); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.similar-pct { color: var(--text-faint); font-size: 0.75rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- mobile: stack rail, bottom sheet modal, tab bar ---------- */

@media (max-width: 560px) {
  .app { padding-bottom: 4.8rem; }
  .detail-grid { grid-template-columns: 1fr; gap: 1.3rem; }
  .detail-rail { position: static; border-top: 1px solid var(--hairline); padding-top: 1rem; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-panel { width: 100%; max-width: 100%; border-radius: 18px 18px 0 0; max-height: 84vh; }
  .tabbar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 0.3rem 0 1.1rem;
    z-index: 90;
  }
  .site-footer { margin-bottom: 3.5rem; }
}
