/* ============================================
   THE BIBLE PROJECT — Style System
   Three Themes: Parchment, Constellation, Candlelight
   ============================================ */

/* --- Type Scale --- */
:root {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-theme: 400ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Font families */
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'DM Sans', 'Helvetica Neue', sans-serif;
}

/* ============================================
   THEME: PARCHMENT (Light / Warm Manuscript)
   ============================================ */
:root, [data-theme="parchment"] {
  --color-bg: #F5F0E6;
  --color-surface: #FAF6EE;
  --color-surface-2: #FFFFFF;
  --color-surface-offset: #EDE7D9;
  --color-border: #D4C9B5;
  --color-divider: #E0D6C5;

  --color-text: #2C2416;
  --color-text-muted: #7A6F5F;
  --color-text-faint: #B5A996;

  --color-primary: #8B1A1A;
  --color-primary-hover: #6B1010;
  --color-primary-highlight: rgba(139, 26, 26, 0.1);

  --color-gold: #B8860B;
  --color-gold-light: rgba(184, 134, 11, 0.15);

  --color-accent-1: #8B1A1A;
  --color-accent-2: #1B5E20;
  --color-accent-3: #4A148C;

  /* Graph colors */
  --graph-bg: transparent;
  --graph-node-verse: #8B1A1A;
  --graph-node-verse-stroke: #6B1010;
  --graph-node-xref: #B5A996;
  --graph-node-xref-stroke: #D4C9B5;
  --graph-edge: rgba(139, 26, 26, 0.12);
  --graph-edge-hover: rgba(139, 26, 26, 0.4);
  --graph-glow: rgba(184, 134, 11, 0.3);
  --graph-label: #2C2416;

  /* Section group colors */
  --group-0: #8B1A1A;
  --group-1: #1B5E20;
  --group-2: #1A237E;
  --group-3: #B8860B;
  --group-4: #4A148C;
  --group-5: #BF360C;
  --group-6: #00695C;

  --shadow-sm: 0 1px 2px rgba(44, 36, 22, 0.06);
  --shadow-md: 0 4px 12px rgba(44, 36, 22, 0.08);
  --shadow-lg: 0 12px 32px rgba(44, 36, 22, 0.12);
}

/* ============================================
   THEME: CONSTELLATION (Dark / Night Sky)
   ============================================ */
[data-theme="constellation"] {
  --color-bg: #0C0E1A;
  --color-surface: #13152A;
  --color-surface-2: #1A1D36;
  --color-surface-offset: #101228;
  --color-border: #2A2D4A;
  --color-divider: #1E2040;

  --color-text: #D4D1E0;
  --color-text-muted: #8A87A3;
  --color-text-faint: #55536E;

  --color-primary: #E8C56D;
  --color-primary-hover: #D4A843;
  --color-primary-highlight: rgba(232, 197, 109, 0.12);

  --color-gold: #E8C56D;
  --color-gold-light: rgba(232, 197, 109, 0.12);

  --color-accent-1: #E8C56D;
  --color-accent-2: #6DBFE8;
  --color-accent-3: #E86D9F;

  /* Graph colors */
  --graph-bg: transparent;
  --graph-node-verse: #E8C56D;
  --graph-node-verse-stroke: #D4A843;
  --graph-node-xref: #3A3D5E;
  --graph-node-xref-stroke: #2A2D4A;
  --graph-edge: rgba(232, 197, 109, 0.08);
  --graph-edge-hover: rgba(232, 197, 109, 0.35);
  --graph-glow: rgba(232, 197, 109, 0.4);
  --graph-label: #D4D1E0;

  /* Section group colors */
  --group-0: #E8C56D;
  --group-1: #6DBFE8;
  --group-2: #E86D9F;
  --group-3: #6DE8A1;
  --group-4: #C56DE8;
  --group-5: #E8976D;
  --group-6: #6DE8D4;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* ============================================
   THEME: CANDLELIGHT (Warm / Amber / Intimate)
   ============================================ */
[data-theme="candlelight"] {
  --color-bg: #1A1408;
  --color-surface: #231C0E;
  --color-surface-2: #2C2314;
  --color-surface-offset: #1E1709;
  --color-border: #3D3220;
  --color-divider: #2F2618;

  --color-text: #E8D5B5;
  --color-text-muted: #A89575;
  --color-text-faint: #6B5D45;

  --color-primary: #D4A843;
  --color-primary-hover: #BF9030;
  --color-primary-highlight: rgba(212, 168, 67, 0.15);

  --color-gold: #D4A843;
  --color-gold-light: rgba(212, 168, 67, 0.12);

  --color-accent-1: #D4A843;
  --color-accent-2: #C47A4A;
  --color-accent-3: #8B6B3A;

  /* Graph colors */
  --graph-bg: transparent;
  --graph-node-verse: #D4A843;
  --graph-node-verse-stroke: #BF9030;
  --graph-node-xref: #3D3220;
  --graph-node-xref-stroke: #2F2618;
  --graph-edge: rgba(212, 168, 67, 0.08);
  --graph-edge-hover: rgba(212, 168, 67, 0.35);
  --graph-glow: rgba(212, 168, 67, 0.4);
  --graph-label: #E8D5B5;

  /* Section group colors */
  --group-0: #D4A843;
  --group-1: #C47A4A;
  --group-2: #8B6B3A;
  --group-3: #D4C843;
  --group-4: #C44A4A;
  --group-5: #7A9943;
  --group-6: #43A8D4;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* ============================================
   GLOBAL LAYOUT
   ============================================ */

body {
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-theme),
              color var(--transition-theme);
}

/* --- Header --- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
  z-index: 100;
  flex-shrink: 0;
  transition: background-color var(--transition-theme),
              border-color var(--transition-theme);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text);
}

.logo svg { flex-shrink: 0; }

.logo-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
}

.header-chapter {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding-left: var(--space-4);
  border-left: 1px solid var(--color-divider);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Theme Switcher */
.theme-switcher {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  padding: var(--space-1);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  transition: all var(--transition-interactive);
}

.theme-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.theme-btn.active {
  color: var(--color-primary);
  background: var(--color-surface-2);
  box-shadow: var(--shadow-sm);
}

.mobile-panel-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}

.mobile-panel-toggle:hover {
  color: var(--color-text);
  background: var(--color-surface-offset);
}

/* --- Main Layout --- */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* --- Graph Area --- */
.graph-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

#graph-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.graph-controls {
  position: absolute;
  bottom: var(--space-6);
  left: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  z-index: 10;
}

.graph-control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-interactive);
}

.graph-control-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
  border-color: var(--color-text-faint);
}

.graph-legend {
  position: absolute;
  top: var(--space-4);
  left: var(--space-6);
  display: flex;
  gap: var(--space-6);
  z-index: 10;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
}

.verse-dot {
  background: var(--graph-node-verse);
  box-shadow: 0 0 6px var(--graph-glow);
}

.xref-dot {
  background: var(--graph-node-xref);
  border: 1px solid var(--graph-node-xref-stroke);
}

/* Graph Tooltip */
.graph-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  max-width: 320px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 150ms ease;
  z-index: 50;
  line-height: 1.5;
}

.graph-tooltip.visible {
  opacity: 1;
}

.graph-tooltip .tooltip-ref {
  font-family: var(--font-display);
  font-size: var(--text-base);
  color: var(--color-primary);
  margin-bottom: var(--space-1);
}

.graph-tooltip .tooltip-text {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.graph-tooltip .tooltip-rabbit-hole {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-style: italic;
}

/* --- Side Panel --- */
.side-panel {
  width: 420px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--color-divider);
  background: var(--color-surface);
  overflow: hidden;
  transition: background-color var(--transition-theme),
              border-color var(--transition-theme);
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}

.panel-tab {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  transition: all var(--transition-interactive);
}

.panel-tab:hover {
  color: var(--color-text);
  background: var(--color-surface-offset);
}

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

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  overscroll-behavior: contain;
}

/* --- Section Navigation --- */
.section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.section-nav-btn {
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: all var(--transition-interactive);
}

.section-nav-btn:hover {
  background: var(--color-primary-highlight);
  color: var(--color-text);
}

.section-nav-btn.active {
  background: var(--color-primary);
  color: #fff;
}

/* --- Reading Content --- */
.reading-section-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  margin-bottom: var(--space-4);
  color: var(--color-text);
}

.reading-verse {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-interactive);
  margin-bottom: var(--space-1);
}

.reading-verse:hover {
  background: var(--color-primary-highlight);
}

.reading-verse.active {
  background: var(--color-primary-highlight);
}

.verse-number {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  color: var(--color-primary);
  font-weight: 500;
  min-width: 24px;
  flex-shrink: 0;
  padding-top: 2px;
}

.verse-text {
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--color-text);
}

.verse-voices-indicator {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.voice-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
}

.voice-dot.kirk { background: #B8860B; }
.voice-dot.mlk { background: #8B4513; }
.voice-dot.fisher { background: #2F4F4F; }

/* --- Voices Panel --- */
.voice-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--color-text-muted);
}

.voice-empty-state h3 {
  color: var(--color-text);
  margin: var(--space-4) 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.voice-empty-state p {
  font-size: var(--text-sm);
  max-width: 28ch;
}

/* Selected Verse Header */
.selected-verse-header {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.selected-verse-ref {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.selected-verse-text {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.7;
  font-style: italic;
}

/* Voice Cards */
.voice-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.voice-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  transition: border-color var(--transition-interactive),
              box-shadow var(--transition-interactive);
}

.voice-card:hover {
  border-color: var(--color-text-faint);
  box-shadow: var(--shadow-md);
}

.voice-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.voice-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.voice-avatar.kirk { background: #B8860B; }
.voice-avatar.mlk { background: #8B4513; }
.voice-avatar.fisher { background: #2F4F4F; }

.voice-card-name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.voice-card-role {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.voice-card-quote {
  font-family: var(--font-display);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  margin-bottom: var(--space-3);
  padding-left: var(--space-3);
  border-left: 2px solid var(--color-primary);
}

.voice-card-summary {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: var(--space-3);
}

.voice-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.voice-source-link {
  font-size: var(--text-xs);
  color: var(--color-primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.voice-source-link:hover {
  text-decoration: underline;
}

.voice-audio-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  transition: all var(--transition-interactive);
}

.voice-audio-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.voice-xrefs {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-divider);
}

.voice-xrefs-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.voice-xref-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.voice-xref-tag {
  font-size: var(--text-xs);
  padding: 2px var(--space-2);
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  white-space: normal;
  word-break: break-word;
}

.no-commentary {
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
  font-style: italic;
}

/* --- Footer --- */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-6);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
  flex-shrink: 0;
  transition: background-color var(--transition-theme),
              border-color var(--transition-theme);
}

.site-footer a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* ============================================
   D3 GRAPH STYLES
   ============================================ */

.graph-node-verse {
  cursor: pointer;
  transition: r 200ms ease;
}

.graph-node-xref {
  cursor: pointer;
  transition: r 200ms ease;
}

.graph-edge {
  stroke: var(--graph-edge);
  stroke-width: 0.5;
  transition: stroke var(--transition-interactive);
}

.graph-label {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--graph-label);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.graph-label-xref {
  font-family: var(--font-body);
  font-size: 8px;
  fill: var(--color-text-faint);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transition: opacity 200ms ease;
}

/* ============================================
   SCROLL BAR STYLING
   ============================================ */

.panel-content::-webkit-scrollbar {
  width: 6px;
}

.panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.panel-content::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-faint);
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@keyframes nodeGlow {
  0%, 100% { filter: url(#glow) drop-shadow(0 0 2px var(--graph-glow)); }
  50% { filter: url(#glow) drop-shadow(0 0 6px var(--graph-glow)); }
}

/* Subtle graph background texture */
.graph-area::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.03;
  background-image: radial-gradient(circle at 1px 1px, var(--color-text) 1px, transparent 0);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .header-chapter {
    display: none;
  }

  .mobile-panel-toggle {
    display: flex;
  }

  .app-layout {
    flex-direction: column;
    position: relative;
  }

  .graph-area {
    flex: 1;
    min-height: 0;
  }

  .side-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 55%;
    border-left: none;
    border-top: 1px solid var(--color-divider);
    transform: translateY(100%);
    transition: transform 350ms cubic-bezier(0.16, 1, 0.3, 1),
                background-color var(--transition-theme);
    z-index: 50;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-lg);
  }

  .side-panel.open {
    transform: translateY(0);
  }

  .side-panel::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    margin: var(--space-2) auto var(--space-1);
  }

  .graph-legend {
    flex-direction: column;
    gap: var(--space-2);
  }

  .graph-controls {
    bottom: var(--space-4);
    left: var(--space-4);
  }

  .site-footer {
    flex-direction: column;
    gap: var(--space-1);
    text-align: center;
    padding: var(--space-2) var(--space-4);
  }
}

@media (max-width: 480px) {
  .logo-text {
    font-size: var(--text-base);
  }

  .theme-switcher {
    gap: 0;
  }

  .theme-btn {
    width: 32px;
    height: 32px;
  }
}
