:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-faint: #64748b;
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --primary-light: #e0f2fe;
  --accent-thermal: #d97706;
  --accent-thermal-light: #fef3c7;
  --accent-stokes: #2563eb;
  --accent-stokes-light: #dbeafe;
  --accent-rain: #4f46e5;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #dc2626;
  --font-serif: "Newsreader", "Charter", "Bitstream Charter", "Sitka Text", "Cambria", serif;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.07), 0 4px 6px -4px rgb(0 0 0 / 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --bg-card: #131d33;
    --bg-card-alt: #1e293b;
    --border: #334155;
    --border-strong: #475569;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --text-faint: #94a3b8;
    --primary: #38bdf8;
    --primary-dark: #7dd3fc;
    --primary-light: #0c4a6e;
    --accent-thermal: #fbbf24;
    --accent-thermal-light: #451a03;
    --accent-stokes: #60a5fa;
    --accent-stokes-light: #1e3a8a;
    --accent-rain: #818cf8;
    --success: #34d399;
    --success-light: #064e3b;
    --warning: #f87171;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4);
  }
}

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

html {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

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

/* Header */
.site-header {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.15s ease;
}

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

.lang-switch {
  display: flex;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.lang-switch a {
  color: var(--text-faint);
  text-decoration: none;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.lang-switch a:hover {
  color: var(--text-main);
  background: var(--bg-card-alt);
}

.lang-switch a.active {
  color: var(--text-main);
  background: var(--bg-card);
  border-color: var(--border);
}

/* Main Container */
main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem 4rem;
}

/* Typography & Titles */
.lead-kicker {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text-main);
  margin-bottom: 1.25rem;
}

.deck {
  font-family: var(--font-serif);
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  line-height: 1.5;
  color: var(--text-muted);
  margin-bottom: 2.5rem;
}

/* Hero Stat Grid */
.stat-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  margin-bottom: 3rem;
}

.stat-hero-header {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.stat-col {
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-size: clamp(1.8rem, 3.5vw, 2.5rem);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 0.35rem;
  font-feature-settings: "tnum";
}

.stat-col.primary .stat-num { color: var(--primary); }
.stat-col.stokes .stat-num { color: var(--accent-stokes); }
.stat-col.thermal .stat-num { color: var(--accent-thermal); }
.stat-col.dispersal .stat-num { color: var(--success); }

.stat-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

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

/* Prose Sections */
.prose {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  line-height: 1.75;
  color: var(--text-main);
  margin-bottom: 3rem;
}

.prose h2 {
  font-family: var(--font-sans);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 2.5rem 0 1rem;
  letter-spacing: -0.01em;
}

.prose p {
  margin-bottom: 1.25rem;
}

.prose strong {
  font-weight: 700;
  color: var(--text-main);
}

/* Interactive Laboratory */
.laboratory {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  margin: 3.5rem 0;
  overflow: hidden;
}

.lab-header {
  padding: 1.75rem 1.75rem 1.25rem;
  background: var(--bg-card-alt);
  border-bottom: 1px solid var(--border);
}

.lab-kicker {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.lab-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.lab-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.lab-body {
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Presets Bar */
.presets-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.presets-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preset-btn {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: var(--border);
  color: var(--text-main);
}

.preset-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* Controls Grid */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  background: var(--bg-card-alt);
  padding: 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

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

.control-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.85rem;
}

.control-name {
  font-weight: 600;
  color: var(--text-main);
}

.control-value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--primary);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border-strong);
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg-card);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg-card);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
}

/* Simulator Canvas Area */
.sim-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: stretch;
}

@media (max-width: 768px) {
  .sim-container {
    grid-template-columns: 1fr;
  }
}

.sim-canvas-box {
  background: #07111e;
  border-radius: 8px;
  border: 1px solid #1e293b;
  position: relative;
  overflow: hidden;
  height: 320px;
  display: flex;
  flex-direction: column;
}

#sim-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-overlay-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-state-float {
  background: rgba(5, 150, 105, 0.85);
  color: #ffffff;
}

.badge-state-rain {
  background: rgba(220, 38, 38, 0.85);
  color: #ffffff;
}

.badge-state-rise {
  background: rgba(2, 132, 199, 0.85);
  color: #ffffff;
}

/* Readout Box */
.readout-box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-card-alt);
  padding: 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.readout-narrative {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--text-main);
}

.readout-narrative mark {
  background: transparent;
  font-weight: 700;
  color: var(--primary);
}

.metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.metrics-table tr {
  border-bottom: 1px solid var(--border);
}

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

.metrics-table td {
  padding: 0.5rem 0;
}

.metric-label {
  color: var(--text-muted);
}

.metric-val {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
}

/* Comparison Bar */
.forces-balance-card {
  background: var(--bg-card-alt);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 1.25rem;
}

.forces-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

.balance-bar-track {
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  display: flex;
  margin-bottom: 0.5rem;
}

.balance-fill-thermal {
  background: var(--accent-thermal);
  height: 100%;
  transition: width 0.2s ease;
}

.balance-fill-stokes {
  background: var(--accent-stokes);
  height: 100%;
  transition: width 0.2s ease;
}

.balance-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
}

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

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-thermal { background: var(--accent-thermal); }
.dot-stokes { background: var(--accent-stokes); }

/* Method and References Note */
.method-note {
  margin-top: 3.5rem;
  padding: 1.5rem;
  background: var(--bg-card);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.method-note h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-main);
}

.method-note p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.method-note p:last-child {
  margin-bottom: 0;
}

/* Footer */
.site-footer {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-faint);
}

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

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

/* Back to Top */
.back-to-top {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-faint);
}

.back-to-top:hover {
  color: var(--text-main);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
