/* ==========================================================================
   The Biophysics Atlas Project — shared stylesheet
   Structure:
     1. Design tokens (colours, type, spacing)
     2. Base elements
     3. Site header and footer
     4. Homepage
     5. Plates (the simulation layout used on module pages)
     6. Controls: sliders, buttons, readouts
     7. Model badges and notes
     8. Accessibility and motion
   ========================================================================== */

/* 1. Design tokens ------------------------------------------------------- */
:root {
  --ivory: #F7F5EE;        /* page background */
  --paper: #FCFBF7;        /* figure background, slightly lighter than the page */
  --forest: #264D42;       /* primary text and lines */
  --forest-soft: #4F6F64;  /* secondary text */
  --sage: #E5EDE5;         /* educational panel */
  --sage-line: #A8C4B1;    /* panel borders and hairlines */
  --vessel: #B85B61;       /* vessel wall */
  --lumen: #F5E6E3;        /* inside of a vessel */
  --blood: #7D2735;        /* blood particles, warnings */
  --amber: #8A5A12;        /* "transitional" status text */

  --font-display: "Spectral", Georgia, "Times New Roman", serif;
  --font-ui: "Public Sans", "Segoe UI", system-ui, sans-serif;

  /* Type scale (ratio about 1.25) */
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.5625rem;
  --step-3: 1.953rem;
  --step-4: 2.441rem;
  --step-5: clamp(2.2rem, 4.6vw, 3.6rem);

  --page-width: 1160px;
  --gutter: clamp(1.25rem, 4vw, 2.5rem);
  --radius-panel: 14px;
  --radius-control: 8px;
}

/* 2. Base elements ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ivory);
  color: var(--forest);
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.15;
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
}
h1 { font-size: var(--step-5); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-1); font-weight: 600; }

p { margin: 0 0 1em; max-width: 68ch; }

a { color: var(--forest); text-decoration-color: var(--sage-line); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--forest); }

.wrap {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.lede {
  font-family: var(--font-display);
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--forest-soft);
  max-width: 60ch;
}

/* 3. Site header and footer --------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--sage-line);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  text-decoration: none;
}
.brand svg { flex: none; }
.site-nav { display: flex; gap: 1.5rem; font-size: var(--step--1); }
.site-nav a { text-decoration: none; padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.site-nav a[aria-current="page"], .site-nav a:hover { border-bottom-color: var(--vessel); }

.site-footer {
  margin-top: 5rem;
  padding: 2.5rem 0 3rem;
  border-top: 1px solid var(--sage-line);
  font-size: var(--step--1);
  color: var(--forest-soft);
}
.site-footer .wrap { display: grid; gap: 1.5rem; grid-template-columns: 1.4fr 1fr; }
.site-footer p { margin: 0 0 0.5em; }
@media (max-width: 720px) { .site-footer .wrap { grid-template-columns: 1fr; } }

/* 4. Homepage ----------------------------------------------------------- */
.hero { padding-top: clamp(2rem, 5vw, 4rem); padding-bottom: 2rem; }

.hero-sentence {
  font-size: var(--step-5);
  font-weight: 400;
  max-width: 19ch;
  margin-bottom: 0.4em;
}
/* The live numbers inside the headline. They change as the slider moves. */
.hero-sentence output {
  font-variant-numeric: tabular-nums lining-nums;
  font-weight: 600;
  white-space: nowrap;
}

.hero-figure {
  margin: 2rem 0 0;
  background: var(--paper);
  border: 1px solid var(--sage-line);
  border-radius: var(--radius-panel);
  padding: 1rem 1rem 1.25rem;
}
.hero-figure canvas { display: block; width: 100%; height: clamp(180px, 26vw, 280px); }

.hero-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem 2rem;
  align-items: end;
  padding: 0.75rem 0.5rem 0;
}
.hero-controls .control { margin: 0; }
.flow-meter { min-width: 220px; }
.flow-meter-track {
  height: 10px;
  border-radius: 5px;
  background: var(--sage);
  border: 1px solid var(--sage-line);
  overflow: hidden;
}
.flow-meter-fill {
  height: 100%;
  width: 100%;
  background: var(--blood);
  transform-origin: left center;
  transition: transform 0.25s ease-out;
}
.flow-meter-label { font-size: var(--step--1); color: var(--forest-soft); margin-top: 0.35rem; }
@media (max-width: 720px) { .hero-controls { grid-template-columns: 1fr; } }

.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; margin-top: 1.75rem; }

.principles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
  padding-top: 3.5rem;
  padding-bottom: 1rem;
}
.principles h3 { margin-bottom: 0.35em; }
.principles p { color: var(--forest-soft); margin: 0; }
@media (max-width: 860px) { .principles { grid-template-columns: 1fr; gap: 1.25rem; } }

/* Contents: the four modules, listed like the contents page of an atlas */
.contents { padding-top: 3rem; }
.contents-list { list-style: none; margin: 1.5rem 0 0; padding: 0; border-top: 1px solid var(--sage-line); }
.module-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr 150px;
  gap: 1.5rem;
  align-items: center;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--sage-line);
}
.module-number {
  font-family: var(--font-display);
  font-size: var(--step-4);
  line-height: 1;
  color: var(--sage-line);
}
.module-row h3 { font-size: var(--step-2); font-weight: 500; margin-bottom: 0.2em; }
.module-row h3 a { text-decoration: none; }
.module-row h3 a:hover { text-decoration: underline; text-decoration-color: var(--vessel); }
.module-row p { margin: 0; color: var(--forest-soft); }
.module-status { font-size: var(--step--1); margin-top: 0.4rem; color: var(--forest-soft); }
.module-status strong { color: var(--forest); font-weight: 600; }
.module-art { width: 150px; height: 90px; justify-self: end; }
.module-row.is-open .module-number { color: var(--vessel); }
@media (max-width: 640px) {
  .module-row { grid-template-columns: 3rem 1fr; }
  .module-art { display: none; }
}

/* 5. Plates ------------------------------------------------------------- */
.page-intro { padding: clamp(2rem, 5vw, 3.5rem) 0 1rem; }
.page-intro h1 { font-size: var(--step-4); }

.module-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-size: var(--step--1);
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}

.plate {
  padding-top: 4rem;
  scroll-margin-top: 1rem;
}
.plate-heading { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.plate-heading h2 { margin: 0; }
.plate-number {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--step-1);
  color: var(--vessel);
}
.plate-intro { margin-top: 0.75rem; }

.plate-body {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr);
  gap: 1.5rem;
  margin-top: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) { .plate-body { grid-template-columns: 1fr; } }

.figure {
  margin: 0;
  background: var(--paper);
  border: 1px solid var(--sage-line);
  border-radius: var(--radius-panel);
  padding: 1rem;
}
.figure canvas { display: block; width: 100%; }
.figure .vessel-canvas { height: 300px; }
.figure .plot-canvas { height: 280px; }
.figcaption {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  align-items: baseline;
  margin-top: 0.75rem;
  font-size: var(--step--1);
  color: var(--forest-soft);
}
.figcaption p { margin: 0; flex: 1 1 260px; }

.panel {
  background: var(--sage);
  border: 1px solid var(--sage-line);
  border-radius: var(--radius-panel);
  padding: 1.25rem;
}
.panel + .panel { margin-top: 1rem; }
.panel h3 { margin-bottom: 0.75rem; }

.equation {
  font-size: 1.15rem;
  margin: 1rem 0 1.25rem;
  overflow-x: auto;
}

.where-list { margin: 0; padding: 0; list-style: none; font-size: var(--step--1); }
.where-list li { padding: 0.15rem 0; }

/* 6. Controls ----------------------------------------------------------- */
.control { margin-bottom: 1.1rem; }
.control:last-child { margin-bottom: 0; }
.control-label {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: var(--step--1);
  font-weight: 500;
  margin-bottom: 0.35rem;
}
.control-label output { font-weight: 600; }
.control-hint { font-size: 0.8rem; color: var(--forest-soft); margin-top: 0.2rem; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--forest) var(--fill, 50%), var(--sage-line) var(--fill, 50%));
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--sage-line); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--forest); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--forest);
  box-shadow: 0 1px 2px rgba(38, 77, 66, 0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--forest);
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font: inherit;
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1.2;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-control);
  border: 1.5px solid var(--forest);
  background: var(--forest);
  color: var(--ivory);
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: #1C3A31; }
.button-quiet { background: transparent; color: var(--forest); }
.button-quiet:hover { background: var(--sage); }
.button-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Readouts: the calculated results */
.readouts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--sage-line);
  border: 1px solid var(--sage-line);
  border-radius: var(--radius-control);
  overflow: hidden;
  margin-top: 1rem;
}
.readout { background: var(--paper); padding: 0.75rem 0.9rem; }
.readout-label { font-size: 0.8rem; color: var(--forest-soft); }
.readout-value { font-size: var(--step-1); font-weight: 600; line-height: 1.3; }
.readout-value small { font-size: 0.8rem; font-weight: 500; color: var(--forest-soft); }
.readout.is-primary { grid-column: 1 / -1; }
.readout.is-primary .readout-value { font-family: var(--font-display); font-size: var(--step-3); font-weight: 500; }

/* Reynolds number status */
.flow-status { font-weight: 600; }
.flow-status[data-regime="laminar"] { color: var(--forest); }
.flow-status[data-regime="transitional"] { color: var(--amber); }
.flow-status[data-regime="turbulent"] { color: var(--blood); }

.alert {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-control);
  border-left: 4px solid var(--blood);
  background: #F7E9E7;
  font-size: var(--step--1);
}
.alert p { margin: 0; }
.alert[hidden] { display: none; }

/* Tabs above the graph */
.tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; }
.tab {
  font: inherit;
  font-size: var(--step--1);
  font-weight: 500;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  background: transparent;
  color: var(--forest-soft);
  cursor: pointer;
}
.tab[aria-selected="true"] { border-color: var(--sage-line); background: var(--sage); color: var(--forest); }

/* Predict, then reveal */
.predict-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin: 0.75rem 0; }
.predict-option {
  font-family: var(--font-display);
  font-size: var(--step-2);
  padding: 0.6rem 0;
  border-radius: var(--radius-control);
  border: 1.5px solid var(--sage-line);
  background: var(--paper);
  color: var(--forest);
  cursor: pointer;
}
.predict-option:hover:not(:disabled) { border-color: var(--forest); }
.predict-option:disabled { cursor: default; }
.predict-option.is-correct { border-color: var(--forest); background: var(--forest); color: var(--ivory); }
.predict-option.is-wrong { border-color: var(--blood); color: var(--blood); text-decoration: line-through; }
.predict-result { font-size: var(--step--1); }
.predict-result[hidden] { display: none; }

/* Clinical scenarios */
.scenario-list { display: grid; gap: 0.5rem; }
.scenario {
  text-align: left;
  font: inherit;
  font-size: var(--step--1);
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--sage-line);
  background: var(--paper);
  color: var(--forest);
  cursor: pointer;
}
.scenario strong { display: block; font-weight: 600; }
.scenario span { color: var(--forest-soft); }
.scenario:hover { border-color: var(--forest); }
.scenario[aria-pressed="true"] { border-color: var(--forest); box-shadow: inset 3px 0 0 var(--vessel); }
.scenario-result { margin-top: 0.75rem; font-size: var(--step--1); min-height: 1.6em; }

/* Assumptions table */
.assumptions { width: 100%; border-collapse: collapse; font-size: var(--step--1); margin-top: 1.5rem; }
.assumptions th, .assumptions td { text-align: left; vertical-align: top; padding: 0.75rem 1rem 0.75rem 0; border-bottom: 1px solid var(--sage-line); }
.assumptions th { font-weight: 600; width: 22%; }
.assumptions thead th { font-weight: 500; color: var(--forest-soft); }

.coming-list { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.coming-list li { border-left: 2px solid var(--sage-line); padding-left: 1rem; }
.coming-list strong { font-family: var(--font-display); font-weight: 500; font-size: var(--step-1); display: block; }
.coming-list span { font-size: var(--step--1); color: var(--forest-soft); }

/* 7. Model badges ---------------------------------------------------------
   Every figure says what kind of picture it is. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.badge-model { color: var(--forest); }
.badge-model::before { background: var(--forest); }
.badge-schematic { color: var(--vessel); }
.badge-schematic::before { border: 1.5px solid var(--vessel); width: 7px; height: 7px; }
.badge-data { color: #2F5A86; }
.badge-data::before { background: #2F5A86; border-radius: 1px; }

.legend { display: grid; gap: 0.75rem; }
.legend div { display: grid; grid-template-columns: 9.5rem 1fr; gap: 0.75rem; align-items: baseline; }
.legend .badge { justify-self: start; }
.legend p { margin: 0; }

.margin-note {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--forest-soft);
  border-left: 2px solid var(--vessel);
  padding-left: 0.9rem;
  margin: 1.25rem 0 0;
}

/* 8. Accessibility and motion ------------------------------------------ */
:focus-visible {
  outline: 3px solid var(--vessel);
  outline-offset: 2px;
  border-radius: 4px;
}
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.skip-link { position: absolute; left: -999px; top: 0.5rem; }
.skip-link:focus { left: 0.5rem; background: var(--paper); padding: 0.5rem 0.75rem; z-index: 10; }

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

/* Small screens: keep the header on one tidy line */
@media (max-width: 560px) {
  .brand { font-size: var(--step-0); }
  .site-nav { gap: 1rem; }
  .site-nav .nav-optional { display: none; }
}

/* Plate 1.0: the 3D heart ------------------------------------------------ */
.heart-stage {
  position: relative;
  height: clamp(380px, 52vw, 520px);
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 45%, #FFFFFF 0%, var(--paper) 70%);
  overflow: hidden;
  touch-action: none;
}
.heart-stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.heart-stage canvas:active { cursor: grabbing; }
.heart-labels { position: absolute; inset: 0; pointer-events: none; }
.heart-labels[hidden] { display: none; }
.heart-label {
  position: absolute;
  left: 0; top: 0;
  pointer-events: auto;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--sage-line);
  background: rgba(252, 251, 247, 0.92);
  color: var(--forest);
  cursor: pointer;
  transition: opacity 0.2s ease;
}
.heart-label:hover { border-color: var(--forest); }
.heart-label[aria-pressed="true"] { background: var(--forest); border-color: var(--forest); color: var(--ivory); }
.heart-label.is-behind { opacity: 0.4; }
.heart-leaders { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.heart-leaders line { stroke: var(--forest); stroke-width: 1; opacity: 0.7; }
.heart-leaders circle { fill: var(--forest); }
.heart-leaders .is-behind { opacity: 0.25; }
.heart-fallback[hidden] { display: none; }
.heart-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 2rem; text-align: center; margin: 0; max-width: none; }

.cycle { margin-top: 0.9rem; }
.cycle-bar { position: relative; display: flex; height: 10px; border-radius: 5px; overflow: hidden; }
.cycle-seg { display: block; height: 100%; }
.cycle-atrial { background: #E3B3B6; }
.cycle-systole { background: var(--vessel); }
.cycle-diastole { background: var(--sage-line); }
.cycle-marker {
  position: absolute; top: -3px; bottom: -3px; width: 3px; margin-left: -1.5px;
  background: var(--forest); border-radius: 2px;
}
.cycle-key { display: flex; flex-wrap: wrap; gap: 0.3rem 1.1rem; margin-top: 0.45rem; font-size: 0.78rem; color: var(--forest-soft); }
.cycle-key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 0.35rem; vertical-align: -1px; }
.cycle-key span:last-child { margin-left: auto; }
.heart-phase { font-family: var(--font-display); font-style: italic; margin: 0.5rem 0 0; min-height: 1.6em; }

.heart-info h3 { margin-bottom: 0.4rem; }
.heart-info p { font-size: var(--step--1); }
.heart-info-physics { background: var(--paper); border-radius: var(--radius-control); padding: 0.7rem 0.85rem; }
.heart-info a { font-size: var(--step--1); font-weight: 600; }

.check { display: inline-flex; align-items: center; gap: 0.4rem; font-size: var(--step--1); cursor: pointer; }
.check input { width: 1rem; height: 1rem; accent-color: var(--forest); }
