/*
*  Copyright (C) 2026 Erik Ferguson
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU Affero General Public License as
*  published by the Free Software Foundation, either version 3 of the
*  License, or (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU Affero General Public License for more details.
*
*  You should have received a copy of the GNU Affero General Public License
*  along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/* ── Base Typography & Layout ───────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Georgia', 'Times New Roman', serif;
  color: #333;
  background: #fff;
  line-height: 1.75;
  font-size: 18px;
}

.article-container {
  max-width: 740px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

h1 {
  font-size: 2.4em;
  line-height: 1.2;
  margin-bottom: 0.3em;
  font-weight: 700;
  color: #1a1a1a;
}

h2 {
  font-size: 1.6em;
  line-height: 1.3;
  margin-top: 2.5em;
  margin-bottom: 0.6em;
  font-weight: 600;
  color: #1a1a1a;
}

h3 {
  font-size: 1.2em;
  margin-top: 1.5em;
  margin-bottom: 0.4em;
  font-weight: 600;
  color: #333;
}

p {
  margin: 0 0 1.2em;
}

.subtitle {
  font-size: 1.15em;
  color: #666;
  margin-bottom: 2em;
  line-height: 1.6;
}

.section-epigraph {
  font-style: italic;
  color: #666;
  border-left: 3px solid #ddd;
  padding-left: 16px;
  margin: 1.5em 0;
}

.author-note {
  font-size: 0.88em;
  color: #666;
  border-left: 3px solid #ddd;
  padding-left: 16px;
  margin: 1.5em 0;
  line-height: 1.65;
}

blockquote {
  border-left: 4px solid #4A7BF7;
  background: #F0F4FE;
  margin: 1.2em 0;
  padding: 12px 20px;
  border-radius: 0 4px 4px 0;
  font-style: italic;
  color: #333;
}

sup {
  font-size: 0.7em;
}

a {
  color: #4A7BF7;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.home-banner {
  display: inline-block;
  margin-top: 2rem;
  font-size: 1.05em;
}

.footnote {
  font-size: 0.85em;
  color: #666;
  margin-top: 0.5em;
}

.footnotes {
  margin-top: 3em;
}

.footnotes h3 {
  font-size: 1em;
  color: #666;
  margin-bottom: 0.8em;
}

.footnotes ol {
  padding-left: 1.5em;
}

.footnotes li {
  font-size: 0.88em;
  color: #555;
  line-height: 1.65;
  margin-bottom: 1em;
}

.footnotes li p {
  margin: 0 0 0.8em;
}

/* ── Widget Containers ─────────────────────────────────────────────── */

.widget-container {
  width: 100%;
  background: #F7F7F8;
  border: 1px solid #E0E0E0;
  border-radius: 6px;
  padding: 20px;
  margin: 40px 0;
  position: relative;
  overflow: hidden;
}

.widget-container h3 {
  margin-top: 0;
  font-size: 1.05em;
  color: #1a1a1a;
}

.widget-disclaimer {
  font-size: 0.8em;
  color: #888;
  font-style: italic;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}

/* ── Prior Toggle ──────────────────────────────────────────────────── */

.prior-toggle {
  display: flex;
  gap: 0;
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
}

.prior-toggle-btn {
  padding: 5px 14px;
  font-size: 0.8em;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 500;
  border: 1px solid #ccc;
  background: #fff;
  color: #666;
  cursor: pointer;
  transition: all 0.15s ease;
}

.prior-toggle-btn:first-child {
  border-radius: 20px 0 0 20px;
  border-right: none;
}

.prior-toggle-btn:last-child {
  border-radius: 0 20px 20px 0;
}

.prior-toggle-btn.active {
  background: #4A7BF7;
  border-color: #4A7BF7;
  color: #fff;
}

.prior-toggle-btn:hover:not(.active) {
  background: #f0f0f0;
}

.prior-description {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.78em;
  color: #888;
  margin: 0 0 4px;
  white-space: nowrap;
}

/* ── Sliders & Controls ────────────────────────────────────────────── */

.widget-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 16px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85em;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 180px;
}

.control-group label {
  font-weight: 500;
  color: #555;
  font-size: 0.9em;
}

.control-group input[type="range"] {
  width: 100%;
  accent-color: #4A7BF7;
}

.control-value {
  font-size: 0.85em;
  color: #888;
  text-align: right;
}

.read-only-label {
  font-size: 0.85em;
  color: #999;
  padding: 4px 0;
}

/* ── Output Displays ───────────────────────────────────────────────── */

.widget-output {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin: 16px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.output-stat {
  text-align: center;
}

.output-stat .big-number {
  font-size: 2em;
  font-weight: 700;
  color: #1a1a1a;
  line-height: 1.1;
}

.output-stat .stat-label {
  font-size: 0.8em;
  color: #888;
  margin-top: 2px;
}

/* ── Buttons ───────────────────────────────────────────────────────── */

.widget-btn {
  padding: 8px 18px;
  font-size: 0.85em;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 500;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #333;
  cursor: pointer;
  transition: all 0.15s ease;
}

.widget-btn:hover {
  background: #f5f5f5;
  border-color: #aaa;
}

.widget-btn.primary {
  background: #4A7BF7;
  border-color: #4A7BF7;
  color: #fff;
}

.widget-btn.primary:hover {
  background: #3A6BE7;
}

.widget-btn.active {
  background: #4A7BF7;
  border-color: #4A7BF7;
  color: #fff;
}

/* ── Playback Controls ─────────────────────────────────────────────── */

.playback-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85em;
}

/* ── Tooltip ───────────────────────────────────────────────────────── */

.widget-tooltip {
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.78em;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  max-width: 220px;
  line-height: 1.4;
  z-index: 100;
}

/* ── SVG Common ────────────────────────────────────────────────────── */

.axis text {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 11px;
  fill: #666;
}

.axis line,
.axis path {
  stroke: #ccc;
}

.grid line {
  stroke: #E8E8E8;
  stroke-dasharray: 2,2;
}

.grid path {
  stroke: none;
}

.threshold-line {
  stroke: #E05252;
  stroke-width: 1.5;
  stroke-dasharray: 6,4;
}

.posterior-line {
  fill: none;
  stroke-width: 2;
}

/* ── Widget-Specific ───────────────────────────────────────────────── */

/* Widget 2 — view toggle */
.view-toggle {
  display: flex;
  gap: 0;
  margin: 12px 0;
}

.view-toggle .widget-btn:first-child {
  border-radius: 4px 0 0 4px;
}

.view-toggle .widget-btn:last-child {
  border-radius: 0 4px 4px 0;
  border-left: none;
}

/* Widget 3 — two-panel layout */
.two-panel {
  display: flex;
  gap: 16px;
  margin: 12px 0;
}

.two-panel .panel {
  flex: 1;
  min-width: 0;
}

.panel-label {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85em;
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
}

/* Widget 4 — coverage counter */
.coverage-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.9em;
}

/* Widget 5 — camera feed */
.camera-feed {
  width: 100%;
  height: 200px;
  background: #222;
  border-radius: 4px;
  margin: 12px 0;
  position: relative;
  overflow: hidden;
}

.confidence-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 4px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.8em;
  font-weight: 600;
}

.confidence-badge.high {
  background: rgba(76, 175, 80, 0.9);
  color: #fff;
}

.confidence-badge.medium {
  background: rgba(255, 193, 7, 0.9);
  color: #333;
}

.confidence-badge.low {
  background: rgba(224, 82, 82, 0.9);
  color: #fff;
}

.model-status {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85em;
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 4px;
}

.model-status.correct {
  background: #E8F5E9;
  color: #2E7D32;
}

.model-status.wrong {
  background: #FFEBEE;
  color: #C62828;
}

/* Widget 5 — condition grid */
.condition-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  margin: 12px 0;
}

.condition-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.condition-cell:hover {
  border-color: #4A7BF7;
}

.condition-cell.selected {
  border-color: #4A7BF7;
  border-width: 3px;
}

/* Widget 6 — timeline */
.timeline-container {
  display: flex;
  gap: 20px;
  margin: 12px 0;
}

.timeline-events {
  flex: 0 0 280px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}

.timeline-event {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.82em;
  margin-bottom: 4px;
  transition: background 0.15s;
}

.timeline-event:hover {
  background: rgba(0,0,0,0.04);
}

.timeline-event.active {
  background: rgba(74, 123, 247, 0.08);
}

.timeline-event .event-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

.timeline-event .event-dot.incident { background: #E05252; }
.timeline-event .event-dot.fix_claimed { background: #4CAF50; }
.timeline-event .event-dot.aggregate_report { background: #4A7BF7; }

.timeline-event .event-date {
  color: #888;
  font-size: 0.9em;
}

.timeline-chart {
  flex: 1;
  min-width: 0;
}

/* ── Bayesian Panel (inline posterior display) ─────────────────────── */

.bayes-panel {
  background: #fff;
  border: 1px solid #E0E0E0;
  border-radius: 4px;
  padding: 12px 16px;
  margin: 12px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85em;
}

.bayes-panel .posterior-value {
  font-size: 1.6em;
  font-weight: 700;
  color: #4A7BF7;
}

.bayes-panel .posterior-label {
  color: #888;
  font-size: 0.85em;
}

.bayes-panel .posterior-gloss {
  color: #666;
  margin-top: 4px;
  font-size: 0.9em;
  line-height: 1.4;
}

/* ── Detail Panel ──────────────────────────────────────────────────── */

.detail-panel {
  background: #fff;
  border: 1px solid #E0E0E0;
  border-radius: 4px;
  padding: 12px 16px;
  margin: 12px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85em;
  color: #555;
  min-height: 48px;
}

/* ── Callout Box ───────────────────────────────────────────────────── */

.callout {
  background: #FFF8E1;
  border-left: 4px solid #FFC107;
  padding: 12px 16px;
  margin: 16px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.88em;
  line-height: 1.5;
  border-radius: 0 4px 4px 0;
}

/* ── Bayesian Intro Animation ─────────────────────────────────────── */

.bi-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 8px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#bi-dots {
  display: flex;
  gap: 8px;
}

.bi-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ddd;
  cursor: pointer;
  transition: background 0.3s, transform 0.15s;
}

.bi-dot:hover {
  transform: scale(1.3);
}

.bi-dot.active {
  background: #4A7BF7;
}

.bi-dot.done {
  background: #93B4FF;
}

#bi-phase-label {
  font-weight: 600;
  font-size: 0.9em;
  color: #333;
  flex: 1;
}

#bi-caption {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.88em;
  color: #555;
  line-height: 1.55;
  min-height: 42px;
}

/* ── AI Disclosure ────────────────────────────────────────────────── */

.ai-disclosure {
  margin-top: 2em;
  font-size: 0.85em;
  color: #888;
  border-top: 1px solid #eee;
  padding-top: 1em;
}

.ai-disclosure summary {
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 500;
  color: #999;
}

.ai-disclosure summary:hover {
  color: #666;
}

.ai-disclosure p {
  margin: 0.6em 0 0;
  line-height: 1.6;
}

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  body {
    font-size: 20px;
  }

  .article-container {
    padding: 20px 16px 60px;
  }

  .two-panel {
    flex-direction: column;
  }

  .timeline-container {
    flex-direction: column;
  }

  .timeline-events {
    flex: none;
    max-height: 200px;
  }

  .widget-controls {
    flex-direction: column;
  }

  .prior-toggle {
    position: relative;
    top: 0;
    right: 0;
    margin-bottom: 10px;
  }
}
