/* ============================================================
   AISBT Bible Reader — styles
   ============================================================ */

:root {
  --bg: #FAF8F5;
  --bg-elev: #FFFFFF;
  --text: #2C2416;
  --text-muted: #6B5E47;
  --accent: #B8944A;
  --accent-soft: rgba(184, 148, 74, 0.10);
  --sidebar-bg: #F2EDE6;
  --border: rgba(44, 36, 22, 0.08);
  --divider: rgba(44, 36, 22, 0.05);
  --shadow-sm: 0 1px 2px rgba(44, 36, 22, 0.04);
  --shadow-md: 0 4px 16px rgba(44, 36, 22, 0.08);
  --shadow-lg: 0 12px 32px rgba(44, 36, 22, 0.12);

  --font-serif: 'EB Garamond', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --font-ui: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --sidebar-w: 280px;
  --header-h: 56px;
  --content-max: 700px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

[data-theme="dark"] {
  --bg: #1A1A1E;
  --bg-elev: #222228;
  --text: #E8E0D4;
  --text-muted: #9E9282;
  --accent: #C9A84C;
  --accent-soft: rgba(201, 168, 76, 0.12);
  --sidebar-bg: #222228;
  --border: rgba(232, 224, 212, 0.08);
  --divider: rgba(232, 224, 212, 0.05);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 11px;
  background: var(--border);
  border-radius: 3px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* ---------- Top bar ---------- */

.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--divider);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}

.brand {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--accent);
}

.topbar-spacer { flex: 1; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background 120ms, color 120ms;
}

.icon-btn:hover { background: var(--accent-soft); color: var(--text); }

#btnTheme .theme-icon-light { display: none; }
#btnTheme .theme-icon-dark  { display: inline; }
[data-theme="dark"] #btnTheme .theme-icon-light { display: inline; }
[data-theme="dark"] #btnTheme .theme-icon-dark  { display: none; }

/* ---------- Layout ---------- */

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--divider);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 0 24px;
}

.ref-input-wrap {
  position: relative;
  margin: 0 16px 14px;
}

#refInput {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}

#refInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ref-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  z-index: 15;
}

.ref-suggestions:empty { display: none; }

.ref-suggestions li {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
}

.ref-suggestions li.active,
.ref-suggestions li:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 8px;
}

.tab {
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-bottom: 2px solid transparent;
  transition: color 120ms, border-color 120ms;
}

.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sidebar-nav {
  flex: 1;
  padding: 4px 8px 0;
  overflow-y: auto;
  font-size: 14px;
}

.testament-group { margin-top: 6px; }

.testament-label {
  display: block;
  width: 100%;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-align: left;
}

.testament-label:hover { background: var(--accent-soft); color: var(--text); }

.book-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 6px;
}

.book-list.collapsed { display: none; }

.book-item { margin: 0; }

.book-toggle {
  display: block;
  width: 100%;
  padding: 5px 10px;
  font-size: 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-align: left;
}

.book-toggle:hover { background: var(--accent-soft); }

.book-toggle.active { color: var(--accent); font-weight: 500; }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 3px;
  padding: 6px 10px 10px 20px;
}

.chapter-grid.collapsed { display: none; }

.chapter-btn {
  padding: 3px 4px;
  font-size: 12px;
  text-align: center;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}

.chapter-btn:hover { background: var(--accent-soft); color: var(--text); }

.chapter-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 500;
}

.pericope-list {
  list-style: none;
  margin: 0;
  padding: 0 0 4px 18px;
  font-size: 13px;
}

.pericope-list.collapsed { display: none; }

.pericope-item {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  line-height: 1.35;
}

.pericope-item:hover { background: var(--accent-soft); }

.pericope-item .pericope-ref {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Main ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  min-height: 0;
}

/* ---------- Reader ---------- */

.reader {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px 120px;
  outline: none;
  scroll-behavior: smooth;
}

.reader-placeholder {
  max-width: var(--content-max);
  margin: 80px auto;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 18px;
}

.book-title {
  max-width: var(--content-max);
  margin: 0 auto 16px;
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 34px;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--accent);
}

.chapter-heading {
  max-width: var(--content-max);
  margin: 56px auto 24px;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 24px;
  text-align: center;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  scroll-margin-top: 24px;
}

.pericope-heading {
  max-width: var(--content-max);
  margin: 28px auto 14px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
}

.verse-block {
  max-width: var(--content-max);
  margin: 0 auto;
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.75;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  transition: background 180ms;
  scroll-margin-top: 35vh;
  position: relative;
}

/* Left-margin gutter for note/xref indicators */
.verse-gutter {
  position: absolute;
  left: -34px;
  top: 2px;
  display: inline-flex;
  gap: 3px;
  align-items: center;
  height: 1.75em;
}

.gutter-dot {
  width: 16px;
  height: 16px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: var(--font-ui);
  color: var(--accent);
  opacity: 0.45;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 120ms, background 120ms, transform 120ms;
  line-height: 1;
}

.gutter-dot:hover {
  opacity: 1;
  background: var(--accent-soft);
  transform: scale(1.15);
}

.gutter-note { font-weight: 600; }
.gutter-xref { font-weight: 400; }

@media (max-width: 767px) {
  /* On mobile, put markers at the right edge instead (less crowded) */
  .verse-gutter {
    left: auto;
    right: -4px;
    top: -2px;
  }
}

.verse-block.active {
  background: var(--accent-soft);
}

.verse-number {
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  vertical-align: super;
  margin-right: 3px;
  padding-left: 2px;
  font-variant-numeric: tabular-nums;
}

.verse-number:first-child { padding-left: 0; }

.verse-text { display: inline; }

.verse-text .poetry-line {
  display: block;
}

.verse-text .poetry-line.indent {
  padding-left: 2em;
  text-indent: -0.5em;
}

.verse-text .poetry-break {
  display: block;
  height: 0.5em;
}

.fn-marker {
  display: inline-block;
  color: var(--accent);
  font-size: 11px;
  vertical-align: super;
  font-weight: 600;
  cursor: pointer;
  padding: 0 1px;
  margin: 0 1px;
  border-radius: 2px;
  font-family: var(--font-ui);
}

.fn-marker:hover { background: var(--accent-soft); }

/* ---------- Action bar ---------- */

.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg);
  border-top: 1px solid var(--divider);
  z-index: 5;
}

.action-btn {
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  transition: all 120ms;
}

.action-btn:hover { color: var(--text); border-color: var(--accent); }

.action-btn[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.action-spacer { flex: 1; }

.search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#searchInput {
  width: 280px;
  padding: 6px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}

#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.phrase-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.phrase-toggle:hover { color: var(--text); }
.phrase-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}
.phrase-toggle input:checked + span {
  color: var(--accent);
  font-weight: 500;
}

/* ---------- Side panels (Notes/Compare/Search) ---------- */

.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(440px, 100%);
  height: 100%;
  background: var(--bg-elev);
  border-left: 1px solid var(--divider);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 10;
  animation: slideIn 200ms ease-out;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.side-panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.panel-header h2 {
  flex: 1;
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 18px;
  margin: 0;
}

.panel-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  font-size: 13px;
}

.panel-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
  color: var(--text-muted);
}

.panel-toolbar input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 40px;
  font-size: 15px;
  line-height: 1.55;
}

.panel-body .empty-state {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  margin-top: 40px;
}

/* notes */
.note-card {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--divider);
}
.note-card:last-child { border-bottom: none; margin-bottom: 0; }
.note-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin: 0 0 2px 0;
}
.note-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.note-category {
  display: inline-block;
  padding: 1px 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.note-greek { font-style: italic; font-family: var(--font-serif); color: var(--text); }
.note-body { margin-top: 4px; }

/* compare */
.compare-entry {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--divider);
}
.compare-entry:last-child { border-bottom: none; }
.compare-abbr {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.1em;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.compare-text {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.7;
}
.compare-missing { color: var(--text-muted); font-style: italic; }

/* search */
.search-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  transition: background 120ms;
}
.search-result:hover { background: var(--accent-soft); }
.search-ref {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 2px;
}
.search-snippet {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}
.search-snippet mark {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 600;
}

.search-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ---------- Popup (footnote) ---------- */

.popup {
  position: fixed;
  z-index: 30;
  max-width: 360px;
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  line-height: 1.5;
  animation: fadeIn 150ms ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.popup.hidden { display: none; }

.popup h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.popup .xref {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--divider);
}
.popup .xref:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }

.popup .xref-ref {
  display: inline-block;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 13px;
}
.popup .xref-ref:hover { text-decoration: underline; }

.popup .xref-text {
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text);
}

.popup .note-only {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.6;
}

/* ---------- Mobile ---------- */

.mobile-only { display: none; }
.sidebar-scrim { display: none; }

@media (max-width: 767px) {
  .mobile-only { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 200ms ease-out;
    z-index: 25;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim.visible {
    display: block;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 24;
  }

  .reader { padding: 20px 18px 120px; }
  .book-title { font-size: 26px; }
  .chapter-heading { font-size: 20px; margin: 36px auto 16px; }
  .verse-block { font-size: 18px; line-height: 1.7; }

  .action-bar { padding: 8px 12px; }
  #searchInput { width: 0; padding: 0; border: 0; background: transparent; }
  #searchInput.visible { width: 100%; padding: 6px 12px; border: 1px solid var(--border); background: var(--bg-elev); }

  .side-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 70vh;
    border-left: none;
    border-top: 1px solid var(--divider);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    animation: slideUp 200ms ease-out;
  }
  @keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  .icon-btn, .action-btn { min-height: 44px; min-width: 44px; }
}
