:root {
  --bg-primary: #0e0c0b;
  --bg-surface: #171412;
  --bg-card: #1f1b18;
  --bg-card-hover: #28221e;
  --border-subtle: #332b26;
  --border-accent: rgba(217, 107, 67, 0.4);
  
  --clay-terracotta: #d96b43;
  --clay-warm: #e89138;
  --clay-hot: #ff4a22;
  --clay-dark: #6e331c;
  --iron-grey: #8a837c;
  --cool-cyan: #38bdf8;
  --chalk-pale: #e0dcd5;
  
  --text-main: #f5eee8;
  --text-muted: #aca39a;
  --text-dim: #756d66;
  
  --font-serif: "Iowan Old Style", "Apple Garamond", "Baskerville", "Times New Roman", "Droid Serif", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
  
  --max-w: 880px;
}

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

html {
  font-size: 16px;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 0%, #241a15 0%, #0e0c0b 60%);
  background-attachment: fixed;
  overflow-x: hidden;
}

a {
  color: var(--clay-warm);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover, a:focus-visible {
  color: #ffa858;
  text-decoration: underline;
}

/* Site Header */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
}

.brand {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand:hover {
  color: var(--text-main);
  text-decoration: none;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--clay-terracotta);
  box-shadow: 0 0 8px var(--clay-terracotta);
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 2px;
}

.lang-btn {
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 600;
  border-radius: 16px;
  color: var(--text-muted);
  text-decoration: none;
}

.lang-btn.active {
  background: var(--clay-terracotta);
  color: #fff;
}

.lang-btn:not(.active):hover {
  color: var(--text-main);
  text-decoration: none;
}

/* Container */
.container {
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
  flex: 1;
}

/* Hero */
.hero {
  margin-top: 1rem;
  margin-bottom: 2.5rem;
}

.kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--clay-terracotta);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.kicker::after {
  content: "";
  flex: 1;
  max-width: 60px;
  height: 1px;
  background: var(--border-accent);
}

.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #fff;
  margin-bottom: 1.25rem;
}

.hero-deck {
  font-size: clamp(1.05rem, 2.2vw, 1.25rem);
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 48ch;
}

/* Stat Strip */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 3rem;
}

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

.stat-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--clay-terracotta), var(--clay-warm));
}

.stat-value {
  font-family: var(--font-mono);
  font-size: clamp(1.8rem, 3.5vw, 2.4rem);
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
  margin-bottom: 0.5rem;
  font-feature-settings: "tnum";
}

.stat-value.cool {
  color: var(--cool-cyan);
}

.stat-value.hot {
  color: var(--clay-hot);
}

.stat-value.amber {
  color: var(--clay-warm);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Tool Sections */
.tool-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 1.75rem;
  margin-bottom: 3rem;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
}

.tool-header {
  margin-bottom: 1.5rem;
}

.tool-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.5rem;
}

.tool-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Interactive Cross-section Canvas Area */
.tunnel-visual-wrapper {
  background: #090807;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.canvas-container {
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16 / 10;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#tunnelCanvas {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: block;
}

.canvas-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-color.c-14 { background: #2b4c6f; }
.legend-color.c-20 { background: #8a733e; }
.legend-color.c-26 { background: #c85a2d; }
.legend-color.c-32 { background: #e6391a; }
.legend-color.c-iron { background: #96908a; border: 1px solid #fff; }

/* Scrubber / Slider Controls */
.control-group {
  margin-bottom: 1.25rem;
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.control-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.control-badge {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--clay-warm);
}

.timeline-scrubber {
  position: relative;
  margin-bottom: 1.5rem;
}

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: #2a231f;
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--clay-terracotta);
  border: 2px solid #fff;
  box-shadow: 0 0 10px rgba(217, 107, 67, 0.8);
  cursor: grab;
  transition: transform 0.1s, background 0.2s;
}

.range-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
  background: var(--clay-hot);
}

.range-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--clay-terracotta);
  border: 2px solid #fff;
  box-shadow: 0 0 10px rgba(217, 107, 67, 0.8);
  cursor: grab;
}

.timeline-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.timeline-ticks span.active {
  color: var(--clay-warm);
  font-weight: 700;
}

/* Station Presets */
.preset-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.pill-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.825rem;
  font-weight: 500;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.pill-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-accent);
}

.pill-btn.active {
  background: var(--clay-terracotta);
  border-color: var(--clay-terracotta);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(217, 107, 67, 0.35);
}

.pill-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

/* Readout Grid */
.readout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.readout-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1rem;
  text-align: left;
}

.readout-sub {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.readout-val {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.readout-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  line-height: 1.35;
}

/* Historical Context Box */
.milestone-callout {
  background: rgba(217, 107, 67, 0.08);
  border-left: 3px solid var(--clay-terracotta);
  border-radius: 0 8px 8px 0;
  padding: 0.9rem 1.1rem;
  margin-top: 1.25rem;
  font-size: 0.875rem;
  color: var(--text-main);
  line-height: 1.5;
}

.milestone-callout strong {
  color: var(--clay-warm);
  font-family: var(--font-mono);
}

/* Prose Narrative Sections */
.prose-section {
  margin-bottom: 3.5rem;
}

.section-title {
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 3.5vw, 2.1rem);
  font-weight: 700;
  color: #fff;
  margin-bottom: 1.25rem;
  letter-spacing: -0.01em;
}

.prose-block p {
  font-size: 1.05rem;
  line-height: 1.7;
  color: #ded7ce;
  margin-bottom: 1.25rem;
}

.prose-block strong {
  color: #fff;
  font-weight: 600;
}

/* Comparison Table / Matrix */
.matrix-container {
  overflow-x: auto;
  margin: 2rem 0;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

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

.matrix-table th, .matrix-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.matrix-table th {
  background: var(--bg-card);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.matrix-table td {
  color: var(--text-main);
}

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

.matrix-table tr:hover td {
  background: var(--bg-card-hover);
}

.matrix-table .num-cell {
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
}

.tag-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 600;
}

.tag-red { background: rgba(255, 74, 34, 0.15); color: #ff6e4a; }
.tag-amber { background: rgba(232, 145, 56, 0.15); color: #f5a623; }
.tag-green { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }

/* Interactive Balancer Section */
.intervention-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.intervention-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.intervention-card:hover {
  border-color: var(--border-accent);
}

.intervention-card.selected {
  border-color: var(--clay-terracotta);
  background: #241d19;
  box-shadow: 0 0 12px rgba(217, 107, 67, 0.2);
}

.intervention-card.selected::before {
  content: "✓";
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: bold;
  color: var(--clay-terracotta);
}

.intervention-title {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 0.35rem;
}

.intervention-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Method Note & Sources */
.method-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.5rem;
  margin-top: 3.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.method-box h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

.method-box ul {
  list-style: square;
  padding-left: 1.25rem;
  margin-top: 0.75rem;
}

.method-box li {
  margin-bottom: 0.4rem;
}

/* Site Footer */
.site-footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.site-footer a {
  color: var(--text-muted);
}

.site-footer a:hover {
  color: var(--text-main);
}

.back-to-top {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
}

.back-to-top:hover {
  color: #fff;
  border-color: var(--clay-terracotta);
  text-decoration: none;
}

/* Error page styles */
.error-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  text-align: center;
}

.error-container {
  max-width: 500px;
}

.error-container h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  margin-bottom: 1rem;
}

.btn-action {
  display: inline-block;
  margin-top: 1.5rem;
  background: var(--clay-terracotta);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}

.btn-action:hover {
  background: var(--clay-warm);
  color: #fff;
  text-decoration: none;
}

/* Responsive Overrides */
@media (max-width: 640px) {
  .stat-strip {
    grid-template-columns: 1fr;
  }
  
  .tool-section {
    padding: 1.25rem 1rem;
  }
  
  .readout-grid {
    grid-template-columns: 1fr 1fr;
  }
  
  .site-header {
    padding: 1rem;
  }
  
  .container {
    padding: 1rem 0.85rem 3rem;
  }
}

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