:root {
  --bg: #0f1319;
  --bg-2: #141b24;
  --panel: #1b2430;
  --panel-2: #202b38;
  --panel-3: #273445;
  --line: rgba(200, 169, 107, 0.24);
  --line-strong: rgba(200, 169, 107, 0.42);
  --text: #f5f1e8;
  --muted: #c9c1b4;
  --gold: #c8a96b;
  --gold-2: #9f7b45;
  --blue: #4a6078;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(200, 169, 107, 0.08), transparent 26%),
    radial-gradient(circle at bottom right, rgba(74, 96, 120, 0.10), transparent 20%),
    linear-gradient(180deg, #0d1117 0%, #111821 100%);
  padding: 18px;
}

a {
  color: inherit;
}

.top-shell {
  display: grid;
  gap: 18px;
}

.page-shell {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel {
  background: linear-gradient(180deg, rgba(33, 43, 56, 0.96), rgba(23, 31, 42, 0.96));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(10px);
  min-width: 0;
}

.topbar {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.brand-inline {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-inline-kicker {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
}

.brand-inline-title {
  font-family: Cinzel, serif;
  font-size: 1.25rem;
  color: var(--gold);
}

.top-nav {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.top-nav a {
  text-decoration: none;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
}

.top-nav a:hover {
  border-color: var(--line-strong);
  background: linear-gradient(180deg, rgba(200, 169, 107, 0.10), rgba(200, 169, 107, 0.03));
}

.page-header {
  padding: 24px;
}

.eyebrow,
.section-kicker,
.stat-label,
.sidebar-title,
.card-label {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.76rem;
  font-weight: 700;
}

.page-header h1,
.section-card h2 {
  margin: 10px 0 12px;
  font-family: Cinzel, serif;
  line-height: 1.15;
}

.page-header h1 {
  font-size: clamp(1.9rem, 2.8vw, 2.6rem);
}

.lead,
.muted,
.empty-state,
.simple-list li {
  color: var(--muted);
  line-height: 1.65;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 20px;
}

.stat-value {
  margin-top: 12px;
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  font-weight: 800;
  color: var(--gold);
}

.content-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 16px;
  min-width: 0;
}

.content-card,
.table-panel,
.sidebar-card,
.section-card {
  padding: 20px;
  min-width: 0;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.mini-link,
.table-link,
.inline-link {
  color: #f6e6c3;
  text-decoration: none;
}

.mini-link:hover,
.table-link:hover,
.inline-link:hover {
  text-decoration: underline;
}

.list-stack {
  display: grid;
  gap: 12px;
}

.list-card {
  display: block;
  text-decoration: none;
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.list-card:hover {
  border-color: var(--line-strong);
}

.list-card-title {
  font-weight: 700;
  margin-bottom: 10px;
}

.chip-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(200, 169, 107, 0.12);
  border: 1px solid rgba(200, 169, 107, 0.28);
  color: #f6e6c3;
  font-size: 0.84rem;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.tag-pill span {
  color: var(--gold);
  font-weight: 700;
}

.tag-pill.static {
  cursor: default;
}

.tag-pill:hover {
  border-color: var(--line-strong);
}

.detail-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
}

.sidebar-group + .sidebar-group {
  margin-top: 20px;
}

.simple-list {
  margin: 10px 0 0;
  padding-left: 18px;
}

.main-detail-column {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.section-body p {
  margin: 0 0 14px;
  line-height: 1.75;
  color: var(--muted);
}

.section-body p:last-child {
  margin-bottom: 0;
}

.wiki-link {
  color: #d5ebff;
}

.strongs-link {
  color: #f7d794;
}

.passage-link {
  color: #d6f5d6;
}

.data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.data-table thead {
  display: table-header-group;
}

.data-table tbody {
  display: table-row-group;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  vertical-align: top;
  white-space: nowrap;
}

.data-table th {
  color: var(--gold);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.data-table.compact th,
.data-table.compact td {
  padding: 10px 12px;
}

.data-table th:first-child,
.data-table td:first-child {
  white-space: normal;
  min-width: 220px;
}

.data-table th:nth-child(2),
.data-table td:nth-child(2) {
  min-width: 160px;
}

.data-table th:nth-child(3),
.data-table td:nth-child(3) {
  min-width: 140px;
}

.data-table th:nth-child(4),
.data-table td:nth-child(4),
.data-table th:nth-child(5),
.data-table td:nth-child(5) {
  min-width: 110px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.search-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  outline: none;
}

.search-form button {
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(200, 169, 107, 0.16), rgba(200, 169, 107, 0.06));
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.empty-state {
  padding: 18px 4px;
}

/* Study listing groups */
.study-groups {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.study-group {
  overflow: hidden;
  min-width: 0;
}

.study-group-summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 18px;
  user-select: none;
}

.study-group-summary::-webkit-details-marker {
  display: none;
}

.study-group-title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.study-group-title {
  font-size: 1.05rem;
  font-weight: 700;
  min-width: 0;
}

.study-group-count {
  font-size: 0.9rem;
  opacity: 0.75;
  white-space: nowrap;
}

.study-group-body {
  padding: 0 16px 16px;
  min-width: 0;
}

.study-group[open] .study-group-summary {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}

/* Study detail visual upgrades */
.visual-block.table_or_timeline .section-body {
  overflow-x: auto;
}

.visual-block.hero_summary {
  border-color: rgba(200, 169, 107, 0.35);
  background: linear-gradient(180deg, rgba(200, 169, 107, 0.08), rgba(255, 255, 255, 0.03));
}

.study-detail-page {
  width: 100%;
  min-width: 0;
}

.study-hero {
  margin-bottom: 18px;
}

.study-title {
  margin: 0 0 10px;
  font-size: 2rem;
  line-height: 1.15;
}

.study-subtitle {
  margin: 0 0 12px;
  opacity: 0.9;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.85rem;
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.study-main,
.study-sidebar {
  min-width: 0;
}

.study-section-card,
.sidebar-card {
  margin-bottom: 18px;
}

.section-title {
  margin-top: 0;
  margin-bottom: 14px;
}

.study-section-body p {
  margin: 0 0 14px;
  line-height: 1.6;
}

.study-section-body p:last-child {
  margin-bottom: 0;
}

.simple-list,
.reason-list,
.pill-list {
  margin: 0;
  padding-left: 20px;
}

.pill-list {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-list li {
  margin: 0;
}

.pill,
.link-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.link-pill:hover,
.related-study-link:hover,
.wiki-link:hover,
.strongs-link:hover {
  text-decoration: underline;
}

.related-study-list {
  display: grid;
  gap: 14px;
}

.related-study-block {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.related-study-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.related-study-link {
  font-weight: 700;
  text-decoration: none;
}

.related-study-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-panel {
  width: 100%;
  overflow: hidden;
}

.markdown-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin: 14px 0 18px;
  border-radius: var(--radius-md);
}

.markdown-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.markdown-table th,
.markdown-table td {
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.markdown-table th {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
}

.markdown-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.025);
}

.confidence-chip.confidence-confirmed {
  background: rgba(85, 107, 47, 0.35);
}

.confidence-chip.confidence-strongly-implied {
  background: rgba(176, 141, 87, 0.35);
}

.confidence-chip.confidence-inferred {
  background: rgba(76, 90, 106, 0.35);
}

.confidence-chip.confidence-speculative {
  background: rgba(107, 47, 58, 0.35);
}

/* Verse popup */
#verse-popup,
.verse-popup {
  position: fixed;
  display: none;
  max-width: 520px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 12px 14px;
  background: #111;
  color: #eee;
  border: 1px solid #444;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.65);
  font-size: 14px;
  line-height: 1.5;
  z-index: 9999;
  pointer-events: none;
  white-space: normal;
}

/* Admin */
.admin-pre {
  white-space: pre-wrap;
  word-break: break-word;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(0, 0, 0, 0.22);
  color: var(--muted);
  max-height: 360px;
  overflow: auto;
}

.danger-btn {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(180, 70, 70, 0.6);
  background: linear-gradient(180deg, rgba(180, 70, 70, 0.22), rgba(120, 30, 30, 0.18));
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.danger-btn:hover {
  filter: brightness(1.08);
}

@media (max-width: 1200px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .study-layout {
    grid-template-columns: 1fr;
  }

  .markdown-table {
    min-width: 560px;
  }
}

@media (max-width: 780px) {
  body {
    padding: 12px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-nav {
    justify-content: flex-start;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .markdown-table {
    min-width: 640px;
  }
}

@media (max-width: 768px) {
  .study-group-summary {
    padding: 14px 16px;
  }

  .study-group-title-wrap {
    gap: 10px;
  }

  .study-group-title {
    font-size: 0.98rem;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .study-group-count {
    font-size: 0.82rem;
  }

  .study-group-body {
    padding: 0 12px 12px;
  }

  .data-table {
    min-width: 600px;
  }

  .data-table th,
  .data-table td {
    font-size: 12px;
    padding: 8px 10px;
  }

  .meta-chip {
    font-size: 0.75rem;
    padding: 5px 8px;
  }
}

@media (max-width: 640px) {
  .study-title {
    font-size: 1.55rem;
  }

  .markdown-table {
    min-width: 520px;
  }

  .meta-chip,
  .pill,
  .link-pill {
    font-size: 0.8rem;
  }

  .page-header {
    padding: 18px;
  }

  .page-header h1 {
    font-size: 2rem;
  }

  .lead {
    font-size: 0.98rem;
  }

  .study-group-summary {
    padding: 12px 14px;
  }

  .study-group-title-wrap {
    align-items: flex-start;
    flex-direction: column;
  }

  .study-group-count {
    white-space: normal;
  }

  .study-group-body {
    padding: 0 10px 10px;
  }

  .data-table {
    min-width: 560px;
  }

  .data-table th,
  .data-table td {
    font-size: 11px;
    padding: 8px 9px;
  }
}