:root {
  /* Light theme (aged medical paper) */
  --bg-page: #f5f0e8;
  --bg-surface: #faf7f0;
  --bg-card: #ffffff;
  --bg-deep: #ebe5d8;
  --bg-altitude-bar: rgba(235,229,216,0.95);
  --text-primary: #1a1a18;
  --text-secondary: #4a4640;
  --text-tertiary: #7a756c;
  --accent-temp: #b84233;
  --accent-alt: #3a6b8a;
  --accent-legend: #8b7355;
  --accent-interp: #5a7a5a;
  --border: #d4cfc4;
  --border-light: #e8e3d9;
  --ink: #1a1a18;
  --paper: #f5f0e8;
  --paper-deep: #ebe5d8;
  --grid-line: rgba(180,170,155,0.3);

  /* Typography */
  --font-display: 'Spectral', Georgia, serif;
  --font-ui: 'IBM Plex Sans', system-ui, sans-serif;
  --font-data: 'IBM Plex Mono', 'Courier New', monospace;
}

[data-theme='dark'] {
  --bg-page: #141312;
  --bg-surface: #1e1d1b;
  --bg-card: #262523;
  --bg-deep: #0e0d0c;
  --bg-altitude-bar: rgba(30,29,27,0.95);
  --text-primary: #e8e4dc;
  --text-secondary: #a8a49c;
  --text-tertiary: #706c64;
  --accent-temp: #d4735f;
  --accent-alt: #5a9bc4;
  --accent-legend: #c4a87a;
  --accent-interp: #7aaa7a;
  --border: #3a3834;
  --border-light: #2e2c28;
  --ink: #e8e4dc;
  --paper: #141312;
  --paper-deep: #0e0d0c;
  --grid-line: rgba(100,96,88,0.3);
}

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

html {
  font-size: 18px;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-display);
  line-height: 1.65;
}

/* Utilities */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Layout Structure */
.topbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 1.5rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1.25rem;
  min-height: 52px;
}

.topbar .brand {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 1rem;
  text-decoration: none;
  color: var(--text-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar .langsw {
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.topbar .theme-toggle {
  font-family: var(--font-ui);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  color: var(--text-secondary);
}

/* Altitude bar in unified topbar */
.altitude-bar {
  flex: 1;
  max-width: 680px;
  height: 38px;
  position: relative;
  background: transparent;
  margin: 0 auto;
}

.alt-scale {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.alt-depth-label,
.alt-height-label {
  font-family: var(--font-data);
  font-size: 0.68rem;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.alt-track {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
}

.alt-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 1px;
  background-color: var(--border);
}

.alt-marker {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background-color: var(--bg-card);
  cursor: pointer;
  transition: transform 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
  padding: 0;
  font: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}

.alt-marker:hover {
  border-color: var(--accent-alt);
  transform: translateY(-50%) scale(1.2);
}

.alt-marker.active {
  background-color: var(--accent-alt);
  border-color: var(--accent-alt);
  transform: translateY(-50%) scale(1.3);
}

.alt-dot {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.alt-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 3px;
  font-family: var(--font-data);
  font-size: 0.65rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  pointer-events: none;
  transition: color 0.2s ease, font-weight 0.2s ease;
}

/* Stagger & edge-align labels to prevent crowding and overlap */
.alt-marker[data-target="targu-ocna"] .alt-label {
  left: 0;
  transform: none;
}

.alt-marker[data-target="deleni"] .alt-label {
  left: 50%;
  transform: translateX(-50%);
}

.alt-marker[data-target="bisericani"] .alt-label {
  left: 50%;
  transform: translateX(-80%);
}

.alt-marker[data-target="marila"] .alt-label {
  left: 50%;
  transform: translateX(-20%);
}

.alt-marker[data-target="moroeni"] .alt-label {
  left: 100%;
  transform: translateX(-100%);
}

.alt-marker.active .alt-label {
  color: var(--text-primary);
  font-weight: 600;
}

/* Hero Section */
.hero {
  padding: 4rem 1.5rem;
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
}

.hero .kicker {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
}

.hero .standfirst {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 640px;
  margin: 0 auto;
}

/* Shell and Content */
.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.chapter {
  padding: 3.5rem 0;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.chapter.visible {
  opacity: 1;
  transform: translateY(0);
}

.chapter:nth-child(odd) {
  background-color: var(--bg-page);
}

.chapter:nth-child(even) {
  background-color: var(--bg-deep);
}

/* Prose */
.prose h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.prose h2 .ch-num {
  font-family: var(--font-data);
  color: var(--text-tertiary);
  font-size: 0.8em;
  margin-right: 0.5rem;
}

.prose p {
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
}

.prose .lead {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* Medical Card */
.medical-card {
  position: relative;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1.5rem;
  margin: 2rem 0;
  background-image: 
    repeating-linear-gradient(var(--grid-line) 0 1px, transparent 1px 24px), 
    repeating-linear-gradient(90deg, var(--grid-line) 0 1px, transparent 1px 24px);
  background-position: top left;
}

.medical-card .card-header {
  font-family: var(--font-data);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed var(--border);
}

.medical-card .card-row {
  display: flex;
  flex-direction: row;
  gap: 2rem;
  padding: 0.75rem 0;
  border-bottom: 1px dotted var(--border-light);
}

.medical-card .card-label {
  font-family: var(--font-data);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  min-width: 120px;
}

.medical-card .card-value {
  font-family: var(--font-data);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.medical-card .card-chart {
  width: 100%;
  max-height: 120px;
  margin: 1rem 0;
  color: var(--text-primary);
}

/* Markers */
.legend-mark, .interp-mark {
  display: inline;
  font-family: var(--font-data);
  font-size: 0.7rem;
  vertical-align: super;
  cursor: help;
  position: relative;
}

.legend-mark {
  color: var(--accent-legend);
}

.interp-mark {
  color: var(--accent-interp);
}

/* Glossary terms with tooltip */
.glossary-term {
  text-decoration: underline dotted var(--accent-alt);
  text-underline-offset: 3px;
  cursor: help;
  color: inherit;
  font-weight: 500;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.glossary-term:hover,
.glossary-term:focus {
  color: var(--accent-alt);
  text-decoration-color: var(--accent-alt);
  outline: none;
}

/* Floating Tooltip Container */
.floating-tooltip {
  position: absolute;
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
  padding: 0.55rem 0.75rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  line-height: 1.45;
  border-radius: 4px;
  z-index: 300;
  max-width: min(290px, calc(100vw - 28px));
  pointer-events: none;
  animation: tooltipFadeIn 0.12s ease-out;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Soundscape */
.soundscape {
  display: flex;
  align-items: center;
  gap: 1rem;
  background-color: var(--bg-deep);
  border-radius: 4px;
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
}

.sound-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background-color: var(--bg-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.sound-btn svg {
  fill: var(--text-secondary);
  transition: fill 0.2s;
}

.sound-btn.playing {
  border-color: var(--accent-alt);
}

.sound-btn.playing svg {
  fill: var(--accent-alt);
}

.sound-label {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sound-note {
  font-family: var(--font-data);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  font-style: italic;
}

.sound-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 16px;
  opacity: 0;
  transition: opacity 0.2s;
}

.sound-wave.active {
  opacity: 1;
}

.sound-wave span {
  width: 3px;
  background-color: var(--accent-alt);
  height: 4px;
  border-radius: 1px;
  display: inline-block;
}

.sound-wave.active span {
  animation: wave 1.2s infinite ease-in-out;
}

.sound-wave.active span:nth-child(2) { animation-delay: 0.2s; }
.sound-wave.active span:nth-child(3) { animation-delay: 0.4s; }
.sound-wave.active span:nth-child(4) { animation-delay: 0.6s; }

@keyframes wave {
  0%, 100% { height: 4px; }
  50% { height: 16px; }
}

/* Sources Section */
.sources-section {
  padding: 3rem 0;
  background-color: var(--bg-deep);
}

.sources-section h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--ink);
}

.sources-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sources-list li {
  font-family: var(--font-display);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.sources-list li a {
  color: var(--accent-alt);
  text-decoration: underline;
}

/* Footer */
footer {
  padding: 2rem 0;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-light);
  background-color: var(--bg-page);
}

footer a {
  color: var(--text-secondary);
}

/* Back to Top */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 1.25rem;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.back-to-top:hover {
  background-color: var(--bg-card);
  border-color: var(--accent-alt);
  color: var(--accent-alt);
  transform: translateY(0) scale(1.08);
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

@media (max-width: 960px) {
  .alt-label {
    display: none;
  }
}

/* Responsive */
@media (max-width: 640px) {
  html {
    font-size: 16px;
  }
  
  .hero {
    padding: 3rem 1rem;
  }
  
  .shell {
    padding: 0 1rem;
  }
  
  .medical-card {
    padding: 1rem;
  }
  
  .medical-card .card-row {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .alt-label {
    display: none;
  }

  .topbar {
    flex-wrap: wrap;
    padding: 0.45rem 1rem;
    gap: 0.35rem;
    min-height: auto;
  }

  .topbar .brand {
    order: 1;
  }

  .topbar-right {
    order: 2;
  }

  .altitude-bar {
    order: 3;
    width: 100%;
    max-width: 100%;
    height: 28px;
    margin: 0;
  }

  .alt-scale {
    gap: 0.5rem;
  }

  .alt-depth-label,
  .alt-height-label {
    font-size: 0.62rem;
  }

  .bipolar-nav {
    flex-direction: column;
    gap: 0.5rem;
  }

  .back-to-top {
    bottom: 1.25rem;
    right: 1.25rem;
    width: 42px;
    height: 42px;
    font-size: 1.1rem;
  }
}

/* ─── Archival Figures & Captions ─── */
.archival-figure {
  margin: 2.5rem 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.archival-figure img {
  width: 100%;
  height: auto;
  display: block;
  background-color: var(--bg-deep);
}

.archival-figure figcaption {
  padding: 0.85rem 1.25rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-light);
  background-color: var(--bg-surface);
}

.archival-figure .figure-meta {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--font-data);
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.archival-figure .figure-meta a {
  color: var(--accent-alt);
  text-decoration: underline;
}

/* ─── Bipolar Comparator (Hero Interaction) ─── */
.bipolar-box {
  margin: 2rem 0 1rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1.25rem;
  text-align: left;
}

.bipolar-header {
  font-family: var(--font-data);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bipolar-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.bipolar-btn {
  flex: 1;
  padding: 0.6rem 0.85rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.bipolar-btn:hover {
  border-color: var(--accent-alt);
  color: var(--text-primary);
}

.bipolar-btn.active {
  background-color: var(--accent-alt);
  color: #ffffff;
  border-color: var(--accent-alt);
}

.bipolar-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-light);
}

.bipolar-panel[hidden] {
  display: none !important;
}

@media (max-width: 600px) {
  .bipolar-panel {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

.bipolar-item-label {
  font-family: var(--font-data);
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 0.2rem;
}

.bipolar-item-val {
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.4;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  
  .chapter {
    opacity: 1;
    transform: none;
  }
  
  .sound-wave.active span {
    height: 10px;
  }
}

/* Print Styles */
@media print {
  body {
    background-color: white !important;
    color: black !important;
  }
  
  .altitude-bar, 
  .soundscape, 
  .theme-toggle, 
  .back-to-top {
    display: none !important;
  }
  
  .chapter {
    background-color: white !important;
    opacity: 1 !important;
    transform: none !important;
  }
  
  .medical-card {
    background-image: none !important;
    border: 1px solid #ccc !important;
  }
}

/* ─── Missing Styles ─── */

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.langsw a {
  color: var(--text-secondary);
  text-decoration: none;
}
.langsw a[aria-current="page"] {
  color: var(--text-primary);
  font-weight: 600;
}

.note-box {
  background-color: var(--bg-deep);
  border-left: 3px solid var(--accent-legend);
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0 2px 2px 0;
}
.note-label {
  font-family: var(--font-data);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-legend);
  margin-bottom: 0.5rem;
  font-weight: 600;
}
.note-box p {
  font-size: 0.95rem;
  line-height: 1.55;
  margin-bottom: 0.5rem;
}
.note-box p:last-child { margin-bottom: 0; }

.sound-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.sources-intro {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.55;
}

.interp-mark-inline {
  font-family: var(--font-data);
  color: var(--accent-interp);
  font-size: 0.85rem;
}
.legend-mark-inline {
  font-family: var(--font-data);
  color: var(--accent-legend);
  font-size: 0.85rem;
}

/* Altitude Diagram SVG */
.altitude-section {
  margin: 2.5rem 0 0;
}
.altitude-diagram {
  width: 100%;
  max-width: 600px;
  height: auto;
  margin: 0 auto;
  display: block;
  color: var(--text-primary);
}
.diagram-label {
  font-family: var(--font-data);
  font-size: 10px;
  fill: var(--text-tertiary);
}
.diagram-value {
  font-family: var(--font-data);
  font-size: 9px;
  fill: var(--accent-alt);
  font-weight: 600;
}
.diagram-name {
  font-family: var(--font-ui);
  font-size: 9px;
  fill: var(--text-secondary);
}
.diagram-dot {
  fill: var(--accent-alt);
}
.diagram-dot-depth {
  fill: var(--accent-temp);
}
.diagram-depth-line {
  stroke: var(--accent-temp);
  stroke-width: 1;
  stroke-dasharray: 3,3;
}

/* SVG Chart styles */
.chart-label {
  font-family: var(--font-data);
  font-size: 9px;
  fill: var(--text-tertiary);
}
.chart-grid {
  stroke: var(--grid-line);
  stroke-width: 1;
}
.chart-tick {
  font-family: var(--font-data);
  font-size: 8px;
  fill: var(--text-tertiary);
}
.chart-line-temp {
  stroke: var(--accent-temp);
}
.chart-annotation {
  font-family: var(--font-data);
  font-size: 8px;
  fill: var(--accent-temp);
}

