/* ============================================================
   Bible Study Website — Global Styles
   ============================================================ */

/* Dancing Script — self-hosted for canvas draw reliability (OFL license) */
@font-face {
  font-family: 'Dancing Script';
  src: url('../fonts/DancingScript-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Ensure [hidden] is always respected even when CSS sets display */
[hidden] { display: none !important; }

:root {
  /* Colors */
  --color-bg:        #faf8f4;
  --color-surface:   #ffffff;
  --color-primary:   #5c3d1e;
  --color-on-primary: #fff;     /* text color for elements with background: var(--color-primary); dark mode overrides this */
  --color-accent:    #8c6a00;   /* darkened from #b8860b — old value failed WCAG AA 4.5:1 on light bg */
  --color-text:      #2c2416;
  --color-heading:   var(--color-text); /* inherits text color so dark mode adapts automatically */
  --color-muted:     #7a6a55;
  --color-border:    #e0d5c4;

  /* Sidebar */
  --sb-bg:           #32200e;
  --sb-text:         #e8d9bb;
  --sb-muted:        #a08a68;   /* darkened from #9a8060 — old value was 4.18:1, below WCAG AA 4.5:1 */
  --sb-hover:        rgba(255,255,255,0.07);
  --sb-active-bg:    rgba(255,255,255,0.12);
  --sb-active-fg:    #e8c87a;
  --sb-accent:       #b8860b;
  --sidebar-w:       240px;
  --topbar-h:        48px;

  /* Typography */
  --font-body:    Georgia, 'Times New Roman', serif;
  --font-ui:      system-ui, sans-serif;
  --font-mono:    'Courier New', monospace;

  /* Spacing */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  2rem;
  --space-xl:  4rem;

  /* Layout */
  --max-width: 860px;
  --header-h:  0px;   /* desktop: no top bar; updated for mobile via media query */

  /* Reader font size — toggled by F3 controls */
  --reader-font-size: 1rem;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Ensure [hidden] always wins over element-level display rules (e.g. flex/block) */
[hidden] { display: none !important; }

/* ── Body — sidebar pushes content on desktop ── */
body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.75;
  padding-left: var(--sidebar-w);
  transition: padding-left 0.22s ease;
}

/* AUD-27: skip-to-content link — off-screen until keyboard focus, then pinned top-left. */
.skip-link {
  position: fixed;
  top: 0;
  left: 0;
  transform: translateY(-120%);
  z-index: 2000;
  margin: 8px;
  padding: 0.5rem 0.9rem;
  background: var(--color-primary, #5c3d1e);
  color: var(--color-on-primary, #fff);
  border-radius: 6px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.95rem;
  text-decoration: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.skip-link:focus { transform: translateY(0); outline: 2px solid var(--color-accent, #c8a84b); outline-offset: 2px; }
/* The focused <main> shouldn't show a persistent outline (it's a programmatic focus target). */
main:focus { outline: none; }

/* Collapsed: sidebar off-screen, content fills full width */
body.sidebar-collapsed { padding-left: 0; }

/* Embedded as a hub "tab" (set by main.js, or by the inline frame check on pages
   that don't load main.js): hide the global site footer so it never appears mid-iframe.
   The sidebar/topbar are already suppressed by buildSidebar() returning early. */
body.is-embedded .site-footer { display: none; }

/* Overlay mode: sidebar is a drawer, never pushes content (topic pages + mobile) */
body.sidebar-overlay { padding-left: 0 !important; }

/* ── Sidebar ──────────────────────────────────────────────── */
.site-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sb-bg);
  z-index: 900;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(0);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  border-right: 1px solid rgba(0,0,0,0.4);
}

body.sidebar-collapsed .site-sidebar,
body.sidebar-overlay .site-sidebar {
  transform: translateX(calc(-1 * var(--sidebar-w)));
}

body.sb-open .site-sidebar {
  transform: translateX(0) !important;
}

/* Sidebar header row */
.sb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 0.9rem 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.sb-logo {
  color: #f0e6d0;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: bold;
  font-family: var(--font-ui);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-logo:hover { color: #fff; }

.sb-collapse-btn {
  background: none;
  border: none;
  color: var(--sb-muted);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}
.sb-collapse-btn:hover { color: var(--sb-text); background: var(--sb-hover); }
.sb-collapse-btn:focus-visible { outline: 2px solid var(--sb-accent); outline-offset: 2px; }

/* Scrollable nav area */
.sb-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.sb-nav::-webkit-scrollbar { width: 4px; }
.sb-nav::-webkit-scrollbar-track { background: transparent; }
.sb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* ── Sidebar links ── */
.sb-link {
  display: block;
  padding: 0.45rem 1rem;
  color: var(--sb-text);
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-link:hover {
  background: var(--sb-hover);
  color: #fff;
}
.sb-link[aria-current="page"] {
  color: var(--sb-active-fg);
  background: var(--sb-active-bg);
  border-left-color: var(--sb-accent);
  font-weight: 600;
}

/* ── Collapsible group ── */
.sb-group { /* wrapper */ }

.sb-group-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.45rem 0.85rem 0.45rem 1rem;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--sb-text);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  gap: 0.4rem;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  white-space: nowrap;
}
.sb-group-btn:hover { background: var(--sb-hover); color: #fff; }
.sb-group-btn.is-active {
  color: var(--sb-active-fg);
  border-left-color: var(--sb-accent);
}
.sb-group-btn[aria-current="page"] {
  color: var(--sb-active-fg);
  background: var(--sb-active-bg);
  border-left-color: var(--sb-accent);
  font-weight: 600;
}
.sb-group-btn:focus-visible { outline: 2px solid var(--sb-accent); outline-offset: -2px; }

.sb-group-label { flex: 1; }

.sb-group-arrow {
  font-size: 0.6rem;
  color: var(--sb-muted);
  transition: transform 0.18s ease;
  flex-shrink: 0;
}
.sb-group-btn[aria-expanded="true"] .sb-group-arrow { transform: rotate(90deg); }

.sb-group-items { /* hidden/shown via [hidden] */ }
.sb-group-items[hidden] { display: none; }

/* Sub-group label (Library sections) */
.sb-sublabel {
  display: block;
  padding: 0.6rem 1rem 0.15rem 1.5rem;
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #9a7a50;   /* lightened from #6a5540 — old value was 2.21:1, below WCAG AA 3.0:1 minimum */
}

/* Child links */
.sb-child {
  display: block;
  padding: 0.35rem 1rem 0.35rem 1.5rem;
  color: #c4b490;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-child:hover { background: var(--sb-hover); color: #f0e6d0; }
.sb-child[aria-current="page"] {
  color: var(--sb-active-fg);
  background: var(--sb-active-bg);
  border-left-color: var(--sb-accent);
  font-weight: 600;
}

/* ── Collapsible sub-groups (nested within a group) ── */
.sb-subgroup-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.3rem 0.85rem 0.3rem 1.5rem;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: #b8a880;
  font-family: var(--font-ui);
  font-size: 0.79rem;
  cursor: pointer;
  text-align: left;
  gap: 0.35rem;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}
.sb-subgroup-btn:hover { background: var(--sb-hover); color: #f0e6d0; }
.sb-subgroup-btn.is-active { color: var(--sb-active-fg); border-left-color: var(--sb-accent); }
.sb-subgroup-btn:focus-visible { outline: 2px solid var(--sb-accent); outline-offset: -2px; }

.sb-subgroup-label { flex: 1; }

.sb-subgroup-arrow {
  font-size: 0.5rem;
  color: var(--sb-muted);
  transition: transform 0.18s ease;
  flex-shrink: 0;
}
.sb-subgroup-btn[aria-expanded="true"] .sb-subgroup-arrow { transform: rotate(90deg); }

.sb-subgroup-items[hidden] { display: none; }

/* Sub-child links (leaves inside a sub-group) */
.sb-subchild {
  display: block;
  padding: 0.28rem 1rem 0.28rem 2.4rem;
  color: #9e8f6e;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.79rem;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-subchild:hover { background: var(--sb-hover); color: #f0e6d0; }
.sb-subchild[aria-current="page"] {
  color: var(--sb-active-fg);
  background: var(--sb-active-bg);
  border-left-color: var(--sb-accent);
  font-weight: 600;
}

/* Divider */
.sb-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 0.5rem 0;
}

/* Version picker */
.sb-version {
  padding: 0.5rem 0.75rem 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--sb-muted);
}
.sb-version label { white-space: nowrap; flex-shrink: 0; }
.sb-version select {
  background: #1c0e05;
  color: var(--sb-text);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 0.78rem;
  cursor: pointer;
  min-width: 0;
  flex: 1;
}

/* ── Collapse tab (desktop, pinned to sidebar edge) ────────── */
.sidebar-tab {
  position: fixed;
  top: 50%;
  left: var(--sidebar-w);
  transform: translateY(-50%);
  width: 14px;
  height: 36px;
  background: var(--sb-bg);
  border: 1px solid rgba(255,255,255,0.12);
  border-left: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sb-muted);
  font-size: 0.65rem;
  z-index: 901;
  transition: left 0.22s cubic-bezier(0.4, 0, 0.2, 1), color 0.12s;
}
.sidebar-tab:hover { color: var(--sb-text); }
.sidebar-tab:focus-visible { outline: 2px solid var(--sb-accent); }

body.sidebar-collapsed .sidebar-tab { left: 0; }
/* Overlay mode: no tab visible on desktop for topic pages */
body.sidebar-overlay .sidebar-tab { left: 0; }
body.sb-open .sidebar-tab { left: var(--sidebar-w) !important; }

/* ── Mobile topbar ─────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--sb-bg);
  z-index: 800;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(0,0,0,0.35);
}

.mobile-topbar__hamburger {
  background: none;
  border: none;
  color: var(--sb-text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.3rem;
  line-height: 1;
  border-radius: 4px;
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  transition: background 0.12s;
}
.mobile-topbar__hamburger:hover { background: var(--sb-hover); }
.mobile-topbar__hamburger:focus-visible { outline: 2px solid var(--sb-accent); }

.mobile-topbar__logo {
  color: #f0e6d0;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: bold;
  font-family: var(--font-ui);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Sidebar backdrop ──────────────────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 899;
  -webkit-tap-highlight-color: transparent;
}
body.sb-open .sidebar-backdrop { display: block; }

/* ── Mobile overrides (<1024px) ────────────────────────────── */
@media (max-width: 1023px) {
  :root { --header-h: var(--topbar-h); }

  body {
    padding-left: 0 !important;
    padding-top: var(--topbar-h);
  }

  /* Sidebar always operates as overlay on mobile */
  .site-sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w))) !important;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  body.sb-open .site-sidebar {
    transform: translateX(0) !important;
  }

  .sidebar-tab { display: none !important; }
  .mobile-topbar { display: flex; }

  /* Larger touch targets for mobile nav links */
  .sb-link {
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
  }

  /* Section headers more readable on mobile */
  .sb-section-head {
    padding: 0.6rem 1rem 0.25rem;
  }

  /* WCAG 2.5.5: "Today's Reading" passage chips are the primary homepage CTA;
     default padding gives ~19px height — raise to ~44px on mobile. */
  .plans-widget__passage { padding: 0.6rem 0.75rem; }
}

/* ── Layout ── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* ── Main Content ── */
main {
  padding: var(--space-xl) 0;
}

h1, h2, h3, h4 {
  font-family: var(--font-body);
  color: var(--color-primary);
  line-height: 1.3;
  margin-bottom: var(--space-sm);
  margin-top: var(--space-lg);
}
h1 { font-size: 2rem; margin-top: 0; }
h2 { font-size: 1.5rem; border-bottom: 1px solid var(--color-border); padding-bottom: var(--space-xs); }
h3 { font-size: 1.2rem; }

p { margin-bottom: var(--space-md); }

a { color: var(--color-accent); }
a:hover { color: var(--color-primary); }

/* ── Scripture blocks ── */
blockquote.scripture {
  border-left: 4px solid var(--color-accent);
  background: var(--color-surface);
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  font-style: italic;
  color: var(--color-primary);
  border-radius: 0 6px 6px 0;
}
blockquote.scripture cite {
  display: block;
  margin-top: var(--space-sm);
  font-style: normal;
  font-size: 0.9rem;
  color: var(--color-muted);
}

/* ── Bible reference links ── */
a.ref {
  color: var(--color-accent);
  text-decoration: underline dotted;
  cursor: pointer;
}
a.ref:hover { text-decoration: underline; }
a.ref:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: 2px; }

/* ── Key terms ── */
span.term { font-weight: bold; color: var(--color-primary); }

/* ── Topic cards ── */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-lg);
  margin-top: var(--space-lg);
}
.topic-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-lg);
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.2s, transform 0.2s;
}
.topic-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  transform: translateY(-2px);
  color: inherit;
}
.topic-card h3 { margin-top: 0; color: var(--color-primary); }
.topic-card p  { font-size: 0.95rem; color: var(--color-muted); margin: 0; }

/* ── Footer ── */
.site-footer {
  background: var(--color-primary);
  color: #e8d9bb;
  padding: var(--space-lg) 0;
  margin-top: var(--space-xl);
  font-family: var(--font-ui);
  font-size: 0.9rem;
}
.site-footer a { color: #f5e6c8; }
.small { font-size: 0.8rem; opacity: 0.75; margin-top: var(--space-xs); }

/* ── Today's Reading home widget ── */
.plans-widget {
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-radius: 8px;
  padding: 1rem 1.2rem 0.9rem;
  margin-bottom: 1.5rem;
}
.plans-widget__heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0 0 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-ui);
}
.plans-widget__item {
  padding: 0.5rem 0;
  border-top: 1px solid var(--color-border);
}
.plans-widget__item:first-of-type { border-top: none; padding-top: 0; }
.plans-widget__item--done { opacity: 0.65; }
.plans-widget__title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text);
}
.plans-widget__meta {
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-left: 0.35rem;
}
.plans-widget__passages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.4rem 0 0.35rem;
}
.plans-widget__passage {
  font-size: 0.82rem;
  color: var(--color-primary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.18rem 0.5rem;
  text-decoration: none;
  background: var(--color-bg);
}
.plans-widget__passage:hover { border-color: var(--color-primary); }
.plans-widget__check {
  font-size: 0.8rem;
  color: #4caf50;
  font-weight: 600;
}
.plans-widget__goto {
  font-size: 0.78rem;
  color: var(--color-accent);
  text-decoration: none;
}
.plans-widget__goto:hover { text-decoration: underline; }
.plans-widget__done {
  font-size: 0.82rem;
  color: #4caf50;
  font-weight: 600;
}

/* ── Dark mode ──────────────────────────────────────────────────────────────── */
/* Manual override: <html data-theme="dark"> set by the toggle button            */
/* System default:  prefers-color-scheme:dark applies when no manual override    */

[data-theme="dark"] {
  --color-bg:        #1a1208;
  --color-surface:   #231a0d;
  --color-primary:   #e8c87a;
  --color-on-primary: #1a1208;  /* dark text on golden primary bg — white (#fff) fails at ~1.5:1 in dark mode */
  --color-accent:    #d4a017;
  --color-text:      #e8dfc8;
  --color-muted:     #9a8870;
  --color-border:    #3a2e1e;
  --color-bg-alt:    #2a1f0f;
  /* Subtle surfaces / soft text used across feature CSS (chips, badges, blurbs) via
     var(--name, light-fallback). These were never defined, so dark mode silently fell
     back to the LIGHT values (#f5f5f5 etc.) — light chip bg + light --color-text = unreadable
     (e.g. the ?cat=motifs page). Defining them here switches those surfaces to the dark palette;
     light mode is unaffected since it keeps using the fallbacks. */
  --color-surface-subtle: #2a1f0f;
  --color-surface-alt:    #382a16;
  --color-text-soft:      #ab9a7e;
  --sb-bg:           #120d05;
  --sb-text:         #e8d9bb;
  --sb-muted:        #9e8a6e;   /* lightened from #7a6a55 — old value was 3.70:1, below WCAG AA 4.5:1 */
  --sb-hover:        rgba(255,255,255,0.06);
  --sb-active-bg:    rgba(255,255,255,0.1);
  --sb-active-fg:    #e8c87a;
  /* Filled button surfaces — dark bg + golden text avoids white-on-yellow */
  --color-btn-bg:       #3a2d18;
  --color-btn-text:     #e8c87a;
  --color-btn-bg-hover: #4a3a22;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg:        #1a1208;
    --color-surface:   #231a0d;
    --color-primary:   #e8c87a;
    --color-on-primary: #1a1208;  /* matches [data-theme="dark"] */
    --color-accent:    #d4a017;
    --color-text:      #e8dfc8;
    --color-muted:     #9a8870;
    --color-border:    #3a2e1e;
    --color-bg-alt:    #2a1f0f;
    --color-surface-subtle: #2a1f0f;  /* matches [data-theme="dark"] — see note there */
    --color-surface-alt:    #382a16;
    --color-text-soft:      #ab9a7e;
    --sb-bg:           #120d05;
    --sb-text:         #e8d9bb;
    --sb-muted:        #9e8a6e;   /* matches [data-theme="dark"] fix */
    --sb-hover:        rgba(255,255,255,0.06);
    --sb-active-bg:    rgba(255,255,255,0.1);
    --sb-active-fg:    #e8c87a;
    --color-btn-bg:       #3a2d18;
    --color-btn-text:     #e8c87a;
    --color-btn-bg-hover: #4a3a22;
    color-scheme: dark;
  }
}

/* Footer: swap yellow bg for dark surface in dark mode */
[data-theme="dark"] .site-footer {
  background: #231a0d;
  border-top: 1px solid #3a2e1e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .site-footer {
    background: #231a0d;
    border-top: 1px solid #3a2e1e;
  }
}

/* Translation Workshop — pinned footer inside sidebar */
.sb-footer {
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.07);
  padding: 0.35rem 0;
}
.sb-workshop-link {
  display: block;
  width: 100%;
  padding: 0.45rem 1rem;
  font-size: 0.78rem;
  font-family: var(--font-ui, system-ui, sans-serif);
  color: var(--sb-muted, #9a8060);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.15s, color 0.15s;
  box-sizing: border-box;
}
.sb-workshop-link:hover { opacity: 1; color: var(--sb-text, #e8d9bb); }
.sb-workshop-link[aria-current="page"] { color: var(--color-primary, #c8a96e); opacity: 1; }

/* Dark mode toggle button (injected into sidebar footer by main.js) */
#bsw-theme-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: none;
  border: none;
  padding: 0.45rem 1rem;
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.83rem;
  color: var(--sb-text, #e8d9bb);
  cursor: pointer;
  text-align: left;
  opacity: 0.75;
  transition: opacity 0.15s;
}
#bsw-theme-btn:hover { opacity: 1; }

/* Modal scroll lock — overflow:hidden on html+body prevents scroll on Chrome/Android.
   iOS scroll-through is blocked by a touchmove.preventDefault on the backdrop (see modal.js). */
html.bsw-modal-open,
body.bsw-modal-open {
  overflow: hidden;
}

/* ── Minimal-embed back-link (shown when ?minimal=1 inside History hub iframes) ── */
.hist-back-link {
  display: inline-flex;
  align-items: center;
  font-size: .78rem;
  font-family: var(--font-ui);
  color: var(--color-muted);
  text-decoration: none;
  padding: .18rem .5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  white-space: nowrap;
}
.hist-back-link:hover { color: var(--color-primary); border-color: var(--color-primary); }

/* ── Provenance / source attribution badges ── */
/* Inline chip shown next to section headers to identify data origin */
.src-badge {
  display: inline-block;
  font: 0.68rem/1.4 var(--font-ui);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 1px 6px;
  vertical-align: middle;
  white-space: nowrap;
  margin-left: 0.4em;
}
.src-badge a { color: inherit; text-decoration: underline dotted; }
.src-badge a:hover { color: var(--color-accent); }
/* AI-assisted content gets a warm gold tint to distinguish from verbatim external sources */
.src-badge--ai {
  border-color: #b8860b;
  color: #8c6a00;
  background: #fffbf0;
}
[data-theme="dark"] .src-badge { color: var(--color-muted); border-color: var(--color-border); background: transparent; }
[data-theme="dark"] .src-badge--ai { background: rgba(184,134,11,0.12); color: #c9a030; border-color: #b8860b; }

/* ── Patristic chain commentary — collapsible Father voices ─────────────────── */
/* INTENT: The Catena-derived 'catena' source stacks many Father voices per pericope.
   decorateCatena() (core.js) wraps each voice in <details class="catena-voice"> with
   a name + tradition + period badge row. Solid-fill pills keep badges legible on both
   light and dark surfaces with no per-theme overrides. Loaded globally via style.css
   so it applies in the reader panel/grid, verse modal, and verse-study alike. */
.catena-voice {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  margin: 0 0 var(--space-sm);
  background: var(--color-surface);
  overflow: hidden;
}
.catena-voice > .cv-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-family: var(--font-ui);
  list-style: none;                 /* suppress default disclosure triangle */
}
.catena-voice > .cv-head::-webkit-details-marker { display: none; }
.catena-voice > .cv-head::before {
  content: '\25B8';                 /* ▸ custom disclosure marker */
  color: var(--color-muted);
  font-size: 0.85em;
  transition: transform 0.15s ease;
}
.catena-voice[open] > .cv-head::before { transform: rotate(90deg); }
.cv-name {
  font-weight: 600;
  color: var(--color-heading);
  margin-right: auto;               /* push tradition/period badges to the right */
}
/* CSS-39: the Father name is an <a> to their Biblepedia article — give it a link
   affordance so it's discoverable (it otherwise looks identical to plain text). */
a.cv-name { text-decoration: none; cursor: pointer; border-bottom: 1px dotted var(--color-border); }
a.cv-name:hover { color: var(--color-accent); border-bottom-color: var(--color-accent); }
a.cv-name:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: 2px; }
.cv-badge {
  font-size: 0.7rem;
  font-family: var(--font-ui);
  line-height: 1.2;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
  color: #fff;
}
.cv-greek      { background: #1d6b6b; }   /* Eastern / Greek fathers */
.cv-latin      { background: #9a5a00; }   /* Western / Latin fathers */
.cv-medieval   { background: #6b4a9a; }   /* Western medieval compilers */
/* Post-Reformation traditions — same hues as lib-badge equivalents in library.css */
.cv-ecumenical { background: var(--color-accent); }
.cv-reformed   { background: #a0522d; }
.cv-lutheran   { background: #4a7a56; }
.cv-methodist  { background: #1a6b8a; }
.cv-anglican   { background: #4a5f7a; }
.cv-baptist    { background: #5c2d87; }
.cv-other      { background: var(--color-muted); }
/* Dark mode: lighten solid fills so white text stays readable */
[data-theme="dark"] .cv-reformed   { background: #c47c4a; }
[data-theme="dark"] .cv-lutheran   { background: #6aaa76; }
[data-theme="dark"] .cv-methodist  { background: #3a9bba; }
[data-theme="dark"] .cv-anglican   { background: #6a8fa8; }
[data-theme="dark"] .cv-baptist    { background: #8b5fc7; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cv-reformed   { background: #c47c4a; }
  :root:not([data-theme="light"]) .cv-lutheran   { background: #6aaa76; }
  :root:not([data-theme="light"]) .cv-methodist  { background: #3a9bba; }
  :root:not([data-theme="light"]) .cv-anglican   { background: #6a8fa8; }
  :root:not([data-theme="light"]) .cv-baptist    { background: #8b5fc7; }
}
.cv-period {                            /* secondary: outlined, muted */
  color: var(--color-muted);
  background: transparent;
  border: 1px solid var(--color-border);
}
.cv-body {
  padding: 0.5rem 0.7rem 0.6rem;
  border-top: 1px solid var(--color-border);
  max-height: 12em;
  overflow-y: auto;
}
.cv-body > p { margin: 0; }
.catena-voice--hidden { display: none; }

/* ── Catena voice filter — chips appear above voices when ≥2 voices are present ── */
/* INTENT: buildCatenaFilter() (core.js) inserts this bar before the first voice; chips
   toggle individual Father/commentator voices on/off for focused reading. Hidden state
   persists across verse navigation within a session (module-level Set in core.js).
   Consistent with .cv-badge sizing so the bar feels like part of the same system. */
.catena-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.catena-filter__chip {
  font-size: 0.72rem;
  font-family: var(--font-ui);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}
.catena-filter__chip:hover { background: var(--color-bg-alt); }
.catena-filter__chip--off {
  opacity: 0.45;
  text-decoration: line-through;
  background: transparent;
}
.catena-filter__toggle {
  font-size: 0.72rem;
  font-family: var(--font-ui);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--color-accent);
  background: transparent;
  color: var(--color-accent);
  cursor: pointer;
  margin-left: auto;          /* push to the right end of the bar */
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.catena-filter__toggle:hover { background: var(--color-accent); color: #fff; }

/* ── MKT Commentary cards — three expandable tracks per verse ─────────────── */
/* INTENT: decorateMkt() (core.js) wraps the three MKT tracks in <details class="mkt-card">;
   first card is open by default, others collapsed. Mirrors catena-voice aesthetics but uses
   a teal-gold accent instead of tradition colours since tracks are topical not authorial.
   Loaded globally so it applies in the reader panel/grid, verse modal, and verse-study. */
.mkt-card {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  margin: 0 0 var(--space-sm);
  background: var(--color-surface);
  overflow: hidden;
}
.mkt-card > .mkt-card__head {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 600;
  color: var(--color-heading);
  list-style: none;
}
.mkt-card > .mkt-card__head::-webkit-details-marker { display: none; }
.mkt-card > .mkt-card__head::before {
  content: '\25B8';
  color: var(--color-muted);
  font-size: 0.85em;
  transition: transform 0.15s ease;
}
.mkt-card[open] > .mkt-card__head::before { transform: rotate(90deg); }
.mkt-card__title {
  font-size: 0.88rem;
}
.mkt-card__body {
  padding: 0.5rem 0.7rem 0.6rem;
  border-top: 1px solid var(--color-border);
}
.mkt-card__body--empty { color: var(--color-muted); font-style: italic; font-size: 0.9rem; }
