/* --- CSS VARIABLES & THEMES --- */
:root {
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Light Theme (Teal-Ivory) */
.theme-light {
  --bg-color: #f7fafc;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --border-color: #e2e8f0;
  --accent-color: #0d9488;
  --accent-glow: #008fa3;
  --accent-green: #10b981;
  --wash-bg: #f0fdfa;
  --timeline-line: #cbd5e1;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --node-glow: rgba(13, 148, 136, 0.2);
  --badge-nomic: #e0f2fe;
  --badge-nomic-text: #0369a1;
  --badge-os: #fdf2f8;
  --badge-os-text: #be185d;
  --badge-infra: #f0fdf4;
  --badge-infra-text: #15803d;
  --badge-meta: #fff7ed;
  --badge-meta-text: #c2410c;
}

/* Dark Theme (Cyber Mirror - Deep Slate & Glowing Neon Cyan) */
.theme-dark {
  --bg-color: #0b131a;
  --card-bg: #111e29;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border-color: #1e2d3d;
  --accent-color: #00f3ff;
  --accent-glow: #00f3ff;
  --accent-green: #00ffaa;
  --wash-bg: #152535;
  --timeline-line: #1e2d3d;
  --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --node-glow: rgba(0, 243, 255, 0.3);
  --badge-nomic: #172c3d;
  --badge-nomic-text: #38bdf8;
  --badge-os: #3c1e2f;
  --badge-os-text: #f472b6;
  --badge-infra: #1b3527;
  --badge-infra-text: #4ade80;
  --badge-meta: #382415;
  --badge-meta-text: #fb923c;
}

/* --- SYSTEM DEFAULTS & ACCESSIBILITY --- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link:focus {
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  top: 20px;
  left: 20px;
  background: var(--accent-color);
  color: #000;
  padding: 8px 16px;
  z-index: 100;
  font-weight: bold;
  border-radius: 4px;
}

/* Clear Focus Rings */
*:focus-visible {
  outline: 3px solid var(--accent-color);
  outline-offset: 2px;
}

/* --- LAYOUT CONTAINERS --- */
.header-container, .section-container, .main-container, .footer-container {
  max-width: 950px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- APP HEADER --- */
.app-header {
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(180deg, var(--wash-bg) 0%, transparent 100%);
  padding: 2.5rem 0 1.5rem 0;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--accent-color);
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.03em;
}

.lede {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 700px;
  margin: 0.75rem 0 1.5rem 0;
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
}

.header-nav a {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  position: relative;
  padding-bottom: 2px;
}
.header-nav a::after {
  content: '';
  position: absolute;
  width: 100%;
  transform: scaleX(0);
  height: 2px;
  bottom: 0;
  left: 0;
  background-color: var(--accent-color);
  transform-origin: bottom right;
  transition: transform 0.25s ease-out;
}
.header-nav a:hover::after {
  transform: scaleX(1);
  transform-origin: bottom left;
}

/* --- THEME TOGGLE BUTTON --- */
.theme-toggle-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.6rem;
  border-radius: 99px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
}
.theme-toggle-btn:hover {
  border-color: var(--accent-color);
  transform: scale(1.05);
}

.theme-toggle-btn svg {
  width: 20px;
  height: 20px;
}

.theme-light .moon-icon { display: block; }
.theme-light .sun-icon { display: none; }
.theme-dark .moon-icon { display: none; }
.theme-dark .sun-icon { display: block; }

/* --- MILESTONE ROADMAP (SVG MAP) --- */
.milestone-map-section {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 2rem 0;
}

.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
}

.section-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin: 0 0 1.5rem 0;
}

.svg-scroll-container {
  overflow-x: auto;
  border-radius: 8px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  padding: 1rem;
}

#interactive-svg-map {
  min-width: 1000px;
  height: 150px;
  display: block;
}

.bg-path {
  stroke: var(--border-color);
}

.animated-path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  transition: stroke-dashoffset 2s cubic-bezier(0.4, 0, 0.2, 1);
  filter: url(#glow);
}

.svg-node {
  cursor: pointer;
  outline: none;
}

.node-glow {
  fill: var(--accent-color);
  opacity: 0.2;
  transition: all 0.3s ease;
}

.node-core {
  fill: var(--accent-color);
  stroke: var(--card-bg);
  stroke-width: 2;
  transition: all 0.3s ease;
}

.node-date {
  font-size: 11px;
  font-weight: 700;
  fill: var(--text-secondary);
  text-anchor: middle;
}

.node-label {
  font-size: 12px;
  font-weight: 600;
  fill: var(--text-primary);
  text-anchor: middle;
}

/* SVG Node interactions */
.svg-node:hover .node-glow, .svg-node:focus-visible .node-glow {
  r: 16px;
  opacity: 0.5;
}
.svg-node:hover .node-core, .svg-node:focus-visible .node-core {
  r: 9px;
  fill: var(--accent-green);
}

/* --- INTERACTIVE FILTER & SEARCH HUB --- */
.interactive-hub {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  margin-top: 2rem;
  box-shadow: var(--shadow);
}

.search-input-container {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  width: 1.2rem;
  height: 1.2rem;
  color: var(--text-secondary);
  pointer-events: none;
}

#timeline-search {
  width: 100%;
  padding: 0.8rem 1rem 0.8rem 2.8rem;
  font-size: 1rem;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}
#timeline-search:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--node-glow);
}

.filter-tabs-wrapper {
  margin-top: 1.25rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.filter-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-btn {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
}
.filter-btn:hover {
  border-color: var(--accent-color);
  background: var(--wash-bg);
}
.filter-btn.active {
  background: var(--accent-color);
  color: #000;
  border-color: var(--accent-color);
  font-weight: 750;
  box-shadow: 0 0 8px var(--node-glow);
}

.results-meta {
  margin-top: 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
  padding-top: 0.75rem;
}

/* --- INFO NOTES --- */
.info-note {
  background: var(--wash-bg);
  border-left: 4px solid var(--accent-color);
  border-radius: 0 8px 8px 0;
  padding: 1.25rem;
  margin: 1.5rem 0;
}

.note-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.info-icon {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--accent-color);
}

#method-title {
  font-size: 1.1rem;
  font-weight: 750;
  margin: 0;
}

.info-note p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.status-pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  margin: 0 0.25rem;
}
.established-sample {
  background-color: var(--badge-infra);
  color: var(--badge-infra-text);
}
.current-sample {
  background-color: var(--badge-meta);
  color: var(--badge-meta-text);
}

/* --- TIMELINE LIST & CARDS --- */
ol#timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.entry-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  position: relative;
}
.entry-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-color);
  box-shadow: 0 6px 20px rgba(0, 243, 255, 0.08);
}

.card-date-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-date {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--accent-color);
}

.category-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
}
.category-badge.nomic { background: var(--badge-nomic); color: var(--badge-nomic-text); }
.category-badge.object-show { background: var(--badge-os); color: var(--badge-os-text); }
.category-badge.infra { background: var(--badge-infra); color: var(--badge-infra-text); }
.category-badge.meta { background: var(--badge-meta); color: var(--badge-meta-text); }

.status-badge {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  border: 1px solid transparent;
}
.status-badge.established {
  border-color: var(--badge-infra-text);
  color: var(--badge-infra-text);
}
.status-badge.current-record {
  border-color: var(--badge-meta-text);
  color: var(--badge-meta-text);
}

.card-title {
  font-size: 1.35rem;
  font-weight: 800;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.01em;
}

.card-summary {
  color: var(--text-secondary);
  font-size: 1rem;
  margin: 0 0 1.25rem 0;
}

/* Sources & Evidence Section inside cards */
.card-sources {
  border-top: 1px dashed var(--border-color);
  padding-top: 1rem;
}

.sources-title {
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 0 0 0.5rem 0;
}

.sources-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.source-item {
  font-size: 0.9rem;
}

.source-link {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 650;
}
.source-link:hover {
  text-decoration: underline;
}

.source-quote {
  margin: 0.4rem 0 0 0;
  padding: 0.4rem 0.8rem;
  border-left: 3px solid var(--accent-color);
  background: var(--wash-bg);
  font-style: italic;
  font-size: 0.85rem;
  border-radius: 0 4px 4px 0;
  color: var(--text-secondary);
}

/* Highlight Flash Animation for Node Scrolling */
@keyframes flash {
  0% { box-shadow: 0 0 0 0 var(--accent-color); }
  50% { box-shadow: 0 0 20px 5px var(--accent-color); border-color: var(--accent-color); }
  100% { box-shadow: none; }
}

.highlight-flash {
  animation: flash 1.5s ease-out;
}

/* Loading, Error, Empty states */
.loading-state, .error-state, .empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- CONTRIBUTING AND FOOTER --- */
.contribute-note {
  margin-top: 3rem;
  border-top: 1px solid var(--border-color);
  padding-top: 2rem;
}
.contribute-note h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
}
.contribute-note p {
  color: var(--text-secondary);
  margin: 0;
}
.contribute-note a {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 600;
}
.contribute-note a:hover {
  text-decoration: underline;
}

.app-footer {
  border-top: 1px solid var(--border-color);
  padding: 2rem 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: var(--wash-bg);
  margin-top: 4rem;
}
.app-footer a {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 600;
}
.app-footer a:hover {
  text-decoration: underline;
}

/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 600px) {
  .title-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .theme-toggle-btn {
    align-self: flex-end;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .animated-path {
    stroke-dasharray: none !important;
    stroke-dashoffset: 0 !important;
    transition: none !important;
  }
}
