/* ==========================================================================
   Something Big Already Happened — Component Library
   Premium dark-theme components for book chapters
   ========================================================================== */

/* ==========================================================================
   HERO — Chapter Opener
   ========================================================================== */

.hero {
  position: relative;
  padding: 120px 40px 80px;
  text-align: center;
  background: linear-gradient(180deg, #0D0D1A 0%, #1A1A2E 50%, #0D0D1A 100%);
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(99, 102, 241, 0.15) 0%, transparent 70%),
    radial-gradient(ellipse at 70% 80%, rgba(255, 107, 53, 0.08) 0%, transparent 50%);
  pointer-events: none;
}

.hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(to top, var(--bg-primary), transparent);
  pointer-events: none;
}

.hero > * {
  position: relative;
  z-index: 1;
}

.hero-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--space-5);
  display: block;
}

.hero h1 {
  font-family: var(--font-heading);
  font-size: var(--text-4xl);
  font-weight: 900;
  line-height: 1.05;
  margin-bottom: var(--space-6);
  border: none;
  padding: 0;
  display: block;
  background: linear-gradient(135deg, #fff 0%, var(--accent2-light) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
  font-weight: 300;
  line-height: var(--leading-normal);
}

.hero-meta {
  margin-top: var(--space-10);
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.hero-meta span {
  margin: 0 12px;
}

.hero-meta span::before {
  content: '';
}

/* ==========================================================================
   LEAD PARAGRAPH
   ========================================================================== */

p.lead,
.lead {
  font-size: var(--text-lg);
  font-weight: 300;
  color: var(--text-secondary);
  border-left: 3px solid var(--accent);
  padding-left: var(--space-5);
  margin: var(--space-8) 0;
  line-height: var(--leading-relaxed);
}

/* ==========================================================================
   STAT GRID & STAT CARDS
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
  margin: var(--space-12) 0;
}

.stat-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, #1A1A2E 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}

.stat-number {
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-2);
  line-height: 1.4;
}

.stat-date {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-2);
  font-family: var(--font-mono);
}

/* ==========================================================================
   TIMELINE
   ========================================================================== */

.timeline {
  position: relative;
  margin: var(--space-12) 0;
  padding-left: 40px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 16px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent2), transparent);
}

.timeline-item {
  position: relative;
  margin-bottom: var(--space-8);
  padding: var(--space-5) var(--space-6);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.timeline-item:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-sm);
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -32px;
  top: 24px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--shadow-glow-accent);
}

.timeline-item:last-child::before {
  background: var(--accent2);
  box-shadow: var(--shadow-glow-accent2);
}

.timeline-item.highlight {
  border-color: var(--accent);
}

.timeline-item.highlight::before {
  width: 16px;
  height: 16px;
  left: -34px;
  top: 22px;
}

.timeline-year {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--accent);
  font-weight: 600;
}

.timeline-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: #fff;
  margin: var(--space-1) 0;
}

.timeline-desc {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

/* ==========================================================================
   BLOCKQUOTE
   ========================================================================== */

blockquote {
  background: var(--bg-card);
  border-left: 4px solid var(--accent);
  padding: var(--space-6) 28px;
  margin: var(--space-8) 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  position: relative;
}

blockquote::before {
  content: '\201C';
  position: absolute;
  top: -8px;
  left: 16px;
  font-family: var(--font-heading);
  font-size: 64px;
  color: rgba(255, 107, 53, 0.15);
  line-height: 1;
  pointer-events: none;
}

blockquote p {
  color: var(--text-secondary);
  font-style: italic;
}

blockquote p:last-of-type {
  margin-bottom: 0;
}

blockquote .source,
blockquote cite,
blockquote footer {
  display: block;
  margin-top: var(--space-3);
  font-style: normal;
  font-weight: 600;
  color: var(--accent);
  font-size: var(--text-sm);
}

blockquote .source::before,
blockquote cite::before {
  content: '\2014\00a0';
}

/* ==========================================================================
   CALLOUT / ADMONITION
   ========================================================================== */

.callout {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(255, 107, 53, 0.05));
  border: 1px solid var(--accent2);
  border-radius: var(--radius-md);
  padding: var(--space-6) 28px;
  margin: var(--space-8) 0;
}

.callout-title {
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: var(--space-2);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.callout p {
  margin-bottom: 0;
  font-size: 15px;
  color: var(--text-secondary);
}

.callout p + p {
  margin-top: var(--space-3);
}

/* Callout Variants */
.callout-warning,
.callout.callout-warning {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(255, 107, 53, 0.05));
  border-color: var(--warning);
}

.callout-warning .callout-title {
  color: var(--warning);
}

.callout-info,
.callout.callout-info {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(99, 102, 241, 0.03));
  border-color: var(--accent2);
}

.callout-info .callout-title {
  color: var(--accent2-light);
}

.callout-key-insight,
.callout.callout-key-insight {
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.12), rgba(99, 102, 241, 0.05));
  border-color: var(--accent);
}

.callout-key-insight .callout-title {
  color: var(--accent);
}

.callout-success,
.callout.callout-success {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(16, 185, 129, 0.03));
  border-color: var(--success);
}

.callout-success .callout-title {
  color: var(--success);
}

/* Quarto-standard callout variants */
.callout-note,
.callout.callout-note {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(99, 102, 241, 0.03));
  border-color: var(--accent2);
}

.callout-note .callout-title,
.callout-note .callout-header {
  color: var(--accent2-light);
}

.callout-tip,
.callout.callout-tip {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(16, 185, 129, 0.03));
  border-color: var(--success);
}

.callout-tip .callout-title,
.callout-tip .callout-header {
  color: var(--success);
}

.callout-important,
.callout.callout-important {
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.12), rgba(99, 102, 241, 0.05));
  border-color: var(--accent);
}

.callout-important .callout-title,
.callout-important .callout-header {
  color: var(--accent);
}

.callout-caution,
.callout.callout-caution {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(255, 107, 53, 0.05));
  border-color: var(--warning);
}

.callout-caution .callout-title,
.callout-caution .callout-header {
  color: var(--warning);
}

/* Quarto callout integration */
.callout.callout-style-default {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(255, 107, 53, 0.05));
  border: 1px solid var(--accent2);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}

.callout.callout-style-default .callout-header {
  background: transparent;
  font-weight: 700;
  border-bottom: none;
}

.callout.callout-style-default .callout-body {
  color: var(--text-secondary);
  font-size: 15px;
}

.callout.callout-style-default .callout-icon {
  color: inherit;
}

/* ==========================================================================
   CHART CONTAINER
   ========================================================================== */

.chart-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin: var(--space-10) 0;
  box-shadow: var(--shadow-lg);
}

.chart-container .chart-label,
.chart-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--space-2);
}

.chart-container .chart-caption,
.chart-caption {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-3);
  text-align: right;
  font-style: italic;
}

/* Plotly charts: force dark theme */
.chart-container .plotly-graph-div,
.chart-container .js-plotly-plot {
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   DIAGRAM CONTAINER
   ========================================================================== */

.diagram-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  margin: var(--space-12) 0;
  text-align: center;
}

.diagram-container .chart-label {
  color: var(--accent2);
  margin-bottom: var(--space-4);
  text-align: left;
}

.diagram-container svg {
  margin: 0 auto;
}

/* ==========================================================================
   SCORECARD TABLE
   ========================================================================== */

.scorecard {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-10) 0;
  font-size: 15px;
}

.scorecard th {
  background: var(--bg-card);
  padding: 14px var(--space-4);
  text-align: left;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.scorecard td {
  padding: 14px var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.scorecard tr:hover td {
  background: rgba(99, 102, 241, 0.05);
}

.scorecard tbody tr:last-child td {
  border-bottom: 1px solid var(--border);
}

/* Status badges */
.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.status.confirmed {
  background: var(--success-bg);
  color: var(--success);
}

.status.ahead {
  background: rgba(255, 107, 53, 0.15);
  color: var(--accent);
}

.status.pending {
  background: rgba(99, 102, 241, 0.15);
  color: #818CF8;
}

.status.missed {
  background: var(--error-bg);
  color: var(--error);
}

.status.partial {
  background: var(--warning-bg);
  color: var(--warning);
}

/* ==========================================================================
   CODE BLOCK
   ========================================================================== */

.code-block {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5) var(--space-6);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--accent2-light);
  overflow-x: auto;
  margin: var(--space-6) 0;
  position: relative;
}

.code-block::before {
  content: attr(data-lang);
  position: absolute;
  top: var(--space-2);
  right: var(--space-3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.6;
}

.code-comment { color: var(--text-muted); }
.code-string { color: var(--accent); }
.code-keyword { color: #818CF8; }
.code-function { color: var(--accent2-light); }
.code-number { color: var(--accent-light); }
.code-type { color: var(--success); }
.code-operator { color: var(--text-secondary); }

/* Quarto code block overrides */
div.sourceCode {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin: var(--space-6) 0;
}

div.sourceCode pre {
  background: transparent;
  border: none;
  margin: 0;
}

/* ==========================================================================
   CHAPTER NAVIGATION
   ========================================================================== */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-10) 0;
  border-top: 1px solid var(--border);
  margin-top: var(--space-20);
  gap: var(--space-4);
}

.chapter-nav a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  transition: color var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chapter-nav a:hover {
  color: var(--accent-light);
  text-decoration: none;
}

.chapter-nav .nav-prev::before {
  content: '\2190';
}

.chapter-nav .nav-next::after {
  content: '\2192';
}

/* Quarto pagination override */
.page-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  margin-top: var(--space-20);
  padding-top: var(--space-10);
  gap: var(--space-4);
}

.page-navigation .nav-page-previous,
.page-navigation .nav-page-next {
  flex: 1;
}

.page-navigation .nav-page-next {
  text-align: right;
}

.page-navigation a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: color var(--transition-fast);
}

.page-navigation a:hover {
  color: var(--accent-light);
  text-decoration: none;
}

.page-navigation .nav-page-previous a::before {
  content: '\2190';
}

.page-navigation .nav-page-next a::after {
  content: '\2192';
}

.page-navigation .chapter-title {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  display: block;
}

.page-navigation .chapter-number {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
}

/* ==========================================================================
   SIDEBAR NOTE (Premium Edition)
   ========================================================================== */

.sidebar-note {
  background: var(--bg-card);
  border-left: 3px solid var(--accent2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: var(--space-4) var(--space-5);
  margin: var(--space-6) 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

.sidebar-note strong {
  color: var(--accent2-light);
  font-weight: 600;
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* On wider screens, float sidebar notes */
@media (min-width: 1100px) {
  .sidebar-note {
    float: right;
    width: 240px;
    margin-left: var(--space-6);
    margin-right: calc(-260px - var(--space-6));
    clear: right;
  }
}

/* ==========================================================================
   FIGURE CAPTION
   ========================================================================== */

.figure-caption,
figcaption,
.quarto-figure figcaption {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  margin-top: var(--space-3);
  padding: 0 var(--space-4);
}

.figure-caption::before,
figcaption::before {
  content: '';
  display: block;
  width: 40px;
  height: 1px;
  background: var(--border);
  margin: 0 auto var(--space-2);
}

/* ==========================================================================
   DROP CAP (Chapter Opener)
   ========================================================================== */

.drop-cap::first-letter,
.chapter-content > p:first-of-type::first-letter {
  font-family: var(--font-heading);
  font-size: 3.5em;
  float: left;
  line-height: 0.8;
  padding-right: 8px;
  padding-top: 4px;
  color: var(--accent);
  font-weight: 900;
}

/* ==========================================================================
   KEY FIGURE (Highlighted Number)
   ========================================================================== */

.key-figure {
  text-align: center;
  padding: var(--space-10) var(--space-6);
  margin: var(--space-10) 0;
}

.key-figure .number {
  font-size: clamp(48px, 8vw, 80px);
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.key-figure .label {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  margin-top: var(--space-3);
}

.key-figure .sublabel {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: var(--space-1);
}

/* ==========================================================================
   COMPARISON CARDS (Side-by-Side)
   ========================================================================== */

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  margin: var(--space-10) 0;
}

.comparison-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  position: relative;
}

.comparison-card.left {
  border-top: 3px solid var(--accent);
}

.comparison-card.right {
  border-top: 3px solid var(--accent2);
}

.comparison-card h4 {
  margin-top: 0;
  margin-bottom: var(--space-3);
}

.comparison-card.left h4 { color: var(--accent); }
.comparison-card.right h4 { color: var(--accent2-light); }

/* ==========================================================================
   PREDICTION TRACKER
   ========================================================================== */

.prediction-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin: var(--space-6) 0;
  position: relative;
  overflow: hidden;
}

.prediction-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}

.prediction-card.confirmed::before {
  background: var(--success);
}

.prediction-card.ahead::before {
  background: var(--accent);
}

.prediction-card.pending::before {
  background: var(--accent2);
}

.prediction-card .prediction-who {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.prediction-card .prediction-text {
  font-size: var(--text-lg);
  font-weight: 600;
  color: #fff;
  margin: var(--space-2) 0;
}

.prediction-card .prediction-analysis {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-3);
}

/* ==========================================================================
   SECTION DIVIDER
   ========================================================================== */

.section-divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-16) 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
}

.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* ==========================================================================
   RESPONSIVE OVERRIDES
   ========================================================================== */

@media (max-width: 1024px) and (min-width: 769px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-grid .stat-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    max-width: 50%;
    margin: 0 auto;
  }

  .comparison-grid {
    gap: var(--space-4);
  }

  .page-navigation {
    gap: var(--space-3);
  }
}

@media (max-width: 768px) {
  .hero {
    padding: 80px 20px 60px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

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

  .timeline {
    padding-left: 32px;
  }

  .timeline::before {
    left: 12px;
  }

  .timeline-item::before {
    left: -28px;
    width: 10px;
    height: 10px;
  }

  .scorecard {
    font-size: var(--text-sm);
  }

  .scorecard th,
  .scorecard td {
    padding: 10px 8px;
  }

  .chapter-nav {
    flex-direction: column;
    gap: var(--space-4);
    text-align: center;
  }

  .page-navigation {
    flex-direction: column;
    gap: var(--space-4);
    text-align: center;
  }

  .page-navigation .nav-page-previous,
  .page-navigation .nav-page-next {
    text-align: center;
  }

  .sidebar-note {
    float: none;
    width: auto;
    margin-right: 0;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: clamp(28px, 8vw, 36px);
  }

  .stat-number {
    font-size: 36px;
  }

  .hero-meta span {
    display: block;
    margin: 4px 0;
  }

  .scorecard {
    display: block;
    overflow-x: auto;
  }
}

/* ==========================================================================
   ANIMATION (Reduced Motion Safe)
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  .stat-card {
    transition: transform var(--transition-base), box-shadow var(--transition-base);
  }

  .timeline-item {
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
  }

  a {
    transition: color var(--transition-fast);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
