:root {
  --bg-primary: #faf7f2;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f4ede4;
  --bg-subtle: #eee6db;
  --border-subtle: #e2d7c9;
  --border-strong: #cfbeab;
  --text-primary: #1e1315;
  --text-secondary: #5c4a4c;
  --text-muted: #8c7678;
  --arterial: #d92638;
  --arterial-glow: rgba(217, 38, 56, 0.15);
  --venous: #2b4acb;
  --venous-glow: rgba(43, 74, 203, 0.15);
  --accent: #c92a2a;
  --accent-light: #ffe3e3;
  --capillary: #b02550;
  --success: #2b8a3e;
  --warning: #e67700;
  --font-serif: "Newsreader", "Charter", "Bitstream Charter", "Sitka Text", Cambria, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Roboto Mono", Menlo, Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(30, 19, 21, 0.04);
  --shadow-md: 0 8px 24px rgba(30, 19, 21, 0.08);
  --shadow-lg: 0 16px 40px rgba(30, 19, 21, 0.12);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #120b0d;
    --bg-surface: #1a1013;
    --bg-surface-elevated: #24171b;
    --bg-subtle: #2d1e23;
    --border-subtle: #38252b;
    --border-strong: #4d333c;
    --text-primary: #fcf4f1;
    --text-secondary: #c9b4b7;
    --text-muted: #8f797d;
    --arterial: #ff4d61;
    --arterial-glow: rgba(255, 77, 97, 0.2);
    --venous: #4d70ff;
    --venous-glow: rgba(77, 112, 255, 0.2);
    --accent: #ff6b7d;
    --accent-light: #38151c;
    --capillary: #e64980;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.7);
  }
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.75;
  letter-spacing: -0.01em;
  padding: 0;
  margin: 0;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.container {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.wide-container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Header & Language Nav */
.site-header {
  padding: 2rem 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 3.5rem;
}

.site-brand {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--arterial);
  box-shadow: 0 0 8px var(--arterial);
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.4); opacity: 1; }
}

.lang-switch {
  display: inline-flex;
  background: var(--bg-surface-elevated);
  padding: 0.25rem;
  border-radius: 9999px;
  border: 1px solid var(--border-subtle);
}

.lang-switch a {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  text-decoration: none;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.lang-switch a.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Hero Section */
.hero {
  margin-bottom: 4rem;
  text-align: left;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  background: var(--arterial-glow);
  color: var(--arterial);
  border: 1px solid rgba(217, 38, 56, 0.25);
  border-radius: 9999px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-size: 2.75rem;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

@media (max-width: 640px) {
  .hero h1 {
    font-size: 2.125rem;
  }
}

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

/* Hero Metric Cards */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin: 3rem 0;
}

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

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.metric-label {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

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

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

.metric-value.ratio {
  color: var(--venous);
}

.metric-sub {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Prose Typography */
.prose {
  margin: 3rem 0;
}

.prose p {
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.prose h2 {
  font-size: 1.875rem;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 3.5rem 0 1.25rem;
  color: var(--text-primary);
}

.prose h3 {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  line-height: 1.4;
  font-weight: 700;
  margin: 2.25rem 0 0.85rem;
  color: var(--text-primary);
}

.prose blockquote {
  border-left: 3px solid var(--arterial);
  padding: 1rem 0 1rem 1.5rem;
  margin: 2rem 0;
  background: var(--bg-surface-elevated);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--text-secondary);
}

.prose ul, .prose ol {
  margin: 1.5rem 0 1.5rem 1.75rem;
  color: var(--text-primary);
}

.prose li {
  margin-bottom: 0.5rem;
}

/* Interactive Simulators & Widgets */
.interactive-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin: 3.5rem 0;
  box-shadow: var(--shadow-md);
}

@media (max-width: 640px) {
  .interactive-section {
    padding: 1.25rem;
    border-radius: var(--radius-md);
  }
}

.interactive-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.interactive-title {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.interactive-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-secondary);
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  margin-bottom: 1.5rem;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* Simulator Controls */
.controls-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  background: var(--bg-surface-elevated);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

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

.control-label {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

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

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

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--arterial);
  cursor: pointer;
  box-shadow: 0 0 6px var(--arterial-glow);
  transition: transform var(--transition-fast);
}

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

.button-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-option {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-option:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-option.active {
  background: var(--arterial);
  color: #ffffff;
  border-color: var(--arterial);
  box-shadow: 0 2px 6px var(--arterial-glow);
}

/* CRT Tactile Stopwatch Tool */
.crt-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem 1rem;
}

.crt-press-button {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b7d, #d92638);
  color: white;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 700;
  border: 4px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 30px rgba(217, 38, 56, 0.35);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  margin: 1.5rem 0;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.3s ease;
}

.crt-press-button:active, .crt-press-button.blanched {
  background: #f8f0ea;
  color: #8c7678;
  border-color: #e2d7c9;
  transform: scale(0.95);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.crt-timer-display {
  font-family: var(--font-mono);
  font-size: 2.75rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0.5rem 0;
}

.crt-feedback {
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  margin-top: 1rem;
  max-width: 480px;
}

/* Personal Microcirculation Calculator */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

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

.calc-input-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.calc-output-panel {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.calc-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.calc-stat-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.calc-stat-name {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.calc-stat-num {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text-primary);
}

/* Anatomical Data Table */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: 2.5rem 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  text-align: left;
}

thead {
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

th {
  padding: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

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

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

tr.highlight-row {
  background: var(--arterial-glow);
  font-weight: 600;
}

tr.highlight-row td {
  color: var(--text-primary);
}

td.mono {
  font-family: var(--font-mono);
}

/* Scientific Bibliography & Method Notes */
.scientific-meta {
  margin: 4rem 0 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.scientific-meta h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.biblio-list li {
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.biblio-list strong {
  color: var(--text-secondary);
}

/* Footer */
.site-footer {
  padding: 3rem 0;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.footer-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-nav a:hover {
  color: var(--arterial);
}

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