:root {
  --bg-deep: #0e0c0b;
  --bg-surface: #171311;
  --bg-surface-elevated: #221b18;
  --bg-surface-translucent: rgba(23, 19, 17, 0.85);
  
  --border-subtle: rgba(245, 158, 11, 0.15);
  --border-medium: rgba(245, 158, 11, 0.3);
  --border-focus: #f59e0b;
  
  --text-primary: #f5ede6;
  --text-secondary: #c4b5a5;
  --text-muted: #8c7d70;
  
  --acid-amber: #f59e0b;
  --acid-glow: #fbbf24;
  --acid-intense: #fef08a;
  
  --bicarbonate-teal: #2dd4bf;
  --bicarbonate-glow: rgba(45, 212, 191, 0.25);
  --neutral-blue: #38bdf8;
  
  --danger-crimson: #ef4444;
  --atp-energy: #a855f7;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Roboto Mono", Menlo, Consolas, Monaco, monospace;
  --font-serif: "Newsreader", "Georgia", Cambria, serif;
  
  --max-w-content: 860px;
  --max-w-wide: 1040px;
}

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

html {
  font-size: 16px;
  line-height: 1.65;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-sans);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Accessibility: FM-001 prevention */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Header & Nav */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface-translucent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.75rem 1.5rem;
}

.header-container {
  max-width: var(--max-w-wide);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-link {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: color 0.2s ease;
}

.brand-link:hover {
  color: var(--acid-amber);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s ease;
}

.lang-switch:hover {
  border-color: var(--acid-amber);
  color: var(--acid-amber);
}

/* Main Container */
main {
  flex: 1;
  max-width: var(--max-w-content);
  width: 100%;
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

/* Hero Section */
.hero {
  margin-bottom: 3.5rem;
}

.badge-topic {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--acid-amber);
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  margin-bottom: 1.25rem;
}

h1.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(2.25rem, 5vw, 3.25rem);
  line-height: 1.15;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 1.25rem;
}

h1.hero-title span.highlight {
  color: var(--acid-amber);
  background: linear-gradient(135deg, var(--acid-amber) 0%, var(--acid-glow) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-lead {
  font-size: 1.1875rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

/* Stat Grid (The Big Contrasting Figures) */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin: 2.5rem 0 3.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--border-medium);
}

.stat-card.featured::before {
  background: linear-gradient(90deg, var(--acid-amber), var(--acid-glow));
}

.stat-card.teal::before {
  background: var(--bicarbonate-teal);
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.stat-card.featured .stat-val {
  color: var(--acid-amber);
}

.stat-card.teal .stat-val {
  color: var(--bicarbonate-teal);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Prose & Sections */
.article-section {
  margin: 3.5rem 0;
}

h2.section-title {
  font-family: var(--font-serif);
  font-size: 1.85rem;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  line-height: 1.25;
}

h3.subsection-title {
  font-size: 1.25rem;
  color: var(--text-primary);
  margin: 1.75rem 0 0.75rem;
}

p {
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
  font-size: 1.0625rem;
}

p strong {
  color: var(--text-primary);
  font-weight: 600;
}

p em {
  font-style: italic;
  color: var(--text-primary);
}

/* Interactive Component Containers */
.interactive-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 12px;
  padding: 1.75rem;
  margin: 2.5rem 0;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
}

.panel-header {
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 1rem;
}

.panel-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--acid-amber);
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.panel-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: var(--text-primary);
}

.panel-description {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  margin-bottom: 0;
}

/* Canvas Display */
.canvas-wrapper {
  position: relative;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #080706;
  border: 1px solid rgba(245, 158, 11, 0.2);
  margin-bottom: 1.5rem;
}

canvas.display-canvas {
  display: block;
  width: 100%;
  height: 280px;
}

/* Controls Grid */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 640px) {
  .controls-grid.two-col {
    grid-template-columns: 1fr 1fr;
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.875rem;
}

.control-label {
  font-weight: 500;
  color: var(--text-primary);
}

.control-output {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  color: var(--acid-amber);
  font-weight: 600;
}

/* Custom Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-surface-elevated);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--acid-amber);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
  border: 2px solid #fff;
  transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--acid-amber);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
  border: 2px solid #fff;
}

/* Live Computation Results in Panel */
.metric-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1.25rem;
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.metric-key {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-value.highlight {
  color: var(--acid-amber);
}

.metric-value.teal {
  color: var(--bicarbonate-teal);
}

.metric-value.energy {
  color: var(--atp-energy);
}

/* Preset Buttons */
.preset-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn-preset {
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-preset:hover, .btn-preset[aria-pressed="true"] {
  border-color: var(--acid-amber);
  color: var(--acid-amber);
  background: rgba(245, 158, 11, 0.1);
}

/* Formula & Scientific Callout Box */
.scientific-callout {
  background: rgba(245, 158, 11, 0.05);
  border-left: 3px solid var(--acid-amber);
  padding: 1.25rem 1.5rem;
  margin: 1.75rem 0;
  border-radius: 0 8px 8px 0;
}

.scientific-callout h4 {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  text-transform: uppercase;
  color: var(--acid-amber);
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

.scientific-callout p {
  font-size: 0.9375rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.scientific-callout p:last-child {
  margin-bottom: 0;
}

/* Comparative Table */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: 2rem 0;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

table.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  text-align: left;
}

table.comparison-table th {
  background: var(--bg-surface-elevated);
  padding: 0.875rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

table.comparison-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

table.comparison-table tr:last-child td {
  border-bottom: none;
}

table.comparison-table tr.highlight-row {
  background: rgba(245, 158, 11, 0.08);
}

table.comparison-table tr.highlight-row td {
  color: var(--text-primary);
  font-weight: 500;
}

/* References / Sources List */
.source-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.source-item {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding-left: 1rem;
  border-left: 2px solid var(--border-subtle);
}

.source-item cite {
  color: var(--text-secondary);
  font-style: italic;
}

/* Footer */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 2.5rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-container {
  max-width: var(--max-w-content);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (min-width: 640px) {
  .footer-container {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-link {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-link:hover {
  color: var(--acid-amber);
}

/* Reduced Motion Optimization */
@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;
  }
}
