:root {
  --bg: #090d12;
  --bg-card: rgba(255, 255, 255, 0.035);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(56, 189, 248, 0.5);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-cyan: #38bdf8;
  --accent-cyan-glow: rgba(56, 189, 248, 0.25);
  --accent-blue: #0284c7;
  --accent-water: #22d3ee;
  --accent-amber: #fbbf24;
  --accent-amber-glow: rgba(251, 191, 36, 0.2);
  --accent-rose: #f43f5e;
  --card-radius: 16px;
  --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  --font-serif: "Charter", "Bitstream Charter", "Sitka Text", "Cambria", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --border: #e2e8f0;
    --border-focus: rgba(2, 132, 199, 0.5);
    --text-main: #0f172a;
    --text-muted: #475569;
    --text-dim: #94a3b8;
    --accent-cyan: #0284c7;
    --accent-cyan-glow: rgba(2, 132, 199, 0.15);
    --accent-blue: #0369a1;
    --accent-water: #0891b2;
    --accent-amber: #d97706;
    --accent-amber-glow: rgba(217, 119, 6, 0.15);
    --accent-rose: #e11d48;
  }
}

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

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

body {
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.site-header .brand {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-header .brand:hover {
  color: var(--accent-cyan);
}

.lang-switch {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.25rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 500;
}

.lang-switch a {
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  text-decoration: none;
  color: var(--text-muted);
  transition: var(--transition);
}

.lang-switch a.active {
  background: var(--accent-cyan);
  color: #ffffff;
  font-weight: 600;
}

main {
  flex: 1;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

.lead-kicker {
  font-family: var(--font-mono);
  font-size: 0.825rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-cyan);
  margin-bottom: 1rem;
  font-weight: 600;
}

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

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

.stat-hero-card {
  background: linear-gradient(145deg, var(--bg-card) 0%, rgba(56, 189, 248, 0.04) 100%);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 2rem;
  margin-bottom: 3rem;
  position: relative;
  overflow: hidden;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 1.5rem;
}

@media (max-width: 640px) {
  .stat-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

.stat-col {
  padding: 1.5rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
}

@media (prefers-color-scheme: light) {
  .stat-col {
    background: #f1f5f9;
  }
}

.stat-col.gas {
  border-top: 4px solid var(--accent-cyan);
}

.stat-col.liquid {
  border-top: 4px solid var(--accent-water);
}

.stat-num {
  font-family: var(--font-sans);
  font-size: clamp(2.2rem, 4vw, 3.2rem);
  font-weight: 800;
  line-height: 1;
  margin-bottom: 0.5rem;
}

.stat-col.gas .stat-num {
  color: var(--accent-cyan);
}

.stat-col.liquid .stat-num {
  color: var(--accent-water);
}

.stat-label {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

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

/* Interactive Laboratory Section */
.laboratory {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 2.25rem 2rem;
  margin: 3rem 0;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.lab-header {
  margin-bottom: 2rem;
}

.lab-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

/* Control Panel */
.control-group {
  margin-bottom: 2rem;
}

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

.control-label {
  font-size: 0.95rem;
  font-weight: 600;
}

.control-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-amber);
}

.slider-wrapper {
  position: relative;
  width: 100%;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  outline: none;
  transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-amber);
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-amber-glow);
  border: 2px solid #ffffff;
  transition: transform 0.1s ease;
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-amber);
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-amber-glow);
  border: 2px solid #ffffff;
}

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

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

.preset-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.preset-btn:hover,
.preset-btn.active {
  border-color: var(--accent-amber);
  color: var(--text-main);
  background: var(--accent-amber-glow);
}

/* Visualization Split Bar */
.split-bar-container {
  margin: 2rem 0;
  background: rgba(0, 0, 0, 0.2);
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
}

@media (prefers-color-scheme: light) {
  .split-bar-container {
    background: #f8fafc;
  }
}

.split-track {
  height: 38px;
  width: 100%;
  border-radius: 8px;
  display: flex;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.split-seg {
  height: 100%;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  color: #ffffff;
  overflow: hidden;
  white-space: nowrap;
}

.split-seg.gas {
  background: linear-gradient(90deg, #0284c7 0%, #38bdf8 100%);
}

.split-seg.water {
  background: linear-gradient(90deg, #0891b2 0%, #22d3ee 100%);
}

.split-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
}

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

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

/* Detailed Results Card */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.result-card {
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  padding: 1.25rem;
  border-radius: 10px;
}

.result-card .kicker {
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.result-card .val {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.result-card .sub {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* Pulse / Realtime Spirometer section */
.spiro-box {
  margin-top: 2rem;
  padding: 1.5rem;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.05) 0%, transparent 100%);
  border: 1px dashed var(--accent-cyan);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.spiro-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.spiro-indicator-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.breath-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-cyan-glow);
  border: 2px solid var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-cyan);
  transition: transform 2.5s ease-in-out;
  transform: scale(1);
  flex-shrink: 0;
}

.breath-circle.inhale {
  transform: scale(1.35);
  background: rgba(56, 189, 248, 0.4);
}

.breath-circle.exhale {
  transform: scale(0.9);
  background: rgba(56, 189, 248, 0.1);
}

.spiro-ticker {
  font-family: var(--font-mono);
  font-size: 1.1rem;
}

.spiro-ticker span {
  color: var(--accent-cyan);
  font-weight: 700;
}

/* Activity Comparison Table */
.activity-section {
  margin: 3rem 0;
}

.activity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.activity-card {
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--card-radius);
  transition: var(--transition);
}

.activity-card:hover {
  border-color: var(--border-focus);
  background: var(--bg-card-hover);
}

.activity-card h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.activity-val {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-amber);
  margin-bottom: 0.35rem;
}

.activity-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Editorial Essay Content */
.prose {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.75;
  color: var(--text-main);
  margin: 3rem 0;
}

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

.prose h2 {
  font-family: var(--font-sans);
  font-size: 1.6rem;
  font-weight: 700;
  margin: 2.5rem 0 1rem;
  color: var(--text-main);
}

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

.prose blockquote {
  border-left: 3px solid var(--accent-cyan);
  padding-left: 1.25rem;
  font-style: italic;
  color: var(--text-muted);
  margin: 1.75rem 0;
}

/* Formula Box */
.formula-box {
  font-family: var(--font-mono);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 2rem 0;
  text-align: center;
  font-size: 1rem;
  color: var(--text-main);
  overflow-x: auto;
}

.formula-box .highlight {
  color: var(--accent-cyan);
  font-weight: 700;
}

/* Method Note */
.method-note {
  border-top: 1px solid var(--border);
  padding-top: 2rem;
  margin-top: 4rem;
  font-size: 0.925rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.method-note h3 {
  font-family: var(--font-sans);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

.method-note p {
  margin-bottom: 1rem;
}

.method-note a {
  color: var(--accent-cyan);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 2.5rem 1.5rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-dim);
}

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

footer a:hover {
  color: var(--accent-cyan);
}

/* Back to top */
.btt-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 1.5rem;
  transition: var(--transition);
}

.btt-button:hover {
  border-color: var(--text-main);
  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;
    scroll-behavior: auto !important;
  }

  .breath-circle {
    transform: none !important;
    transition: none !important;
  }
}
