:root {
  --bg: #f6f4f1;
  --card: #ffffff;
  --text: #1c1a22;
  --muted: #6b6775;
  --line: #e2ded8;
  --accent: #d6336c;
  --warm: #c2560c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121019;
    --card: #1d1a27;
    --text: #f1eef7;
    --muted: #a39db3;
    --line: #2e2a3c;
    --accent: #ff6b9d;
    --warm: #ffa94d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  padding: 0 16px 48px;
  max-width: 1200px;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.material-symbols-outlined { font-size: 18px; vertical-align: -4px; }

header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  padding: 32px 0 16px;
}
h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }
.brand img { display: block; width: auto; height: 40px; max-width: 100%; }
h1 { margin: 14px 0 0; font-size: 1.5rem; line-height: 1.25; }
.tagline { max-width: 70ch; }
.topics { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; font-size: 0.875rem; }
.topics a { color: var(--muted); text-decoration: none; }
.topics a:hover { color: var(--accent); }
.topics a[aria-current="page"] { color: var(--text); font-weight: 700; }
.tagline { margin: 4px 0 0; color: var(--muted); }
.status { text-align: right; color: var(--muted); font-size: 0.875rem; }
.status p { margin: 0; }
/* The status column runs the header's full height: the support button sits top right, level
   with the logo, and the live figures stay at the bottom. */
.status { align-self: stretch; display: flex; flex-direction: column; align-items: flex-end; }
.status .top { margin-bottom: auto; padding-bottom: 12px; }
.live { color: var(--accent); font-weight: 600; }
.support { color: var(--accent); font-weight: 600; text-decoration: none; }
.support:hover { text-decoration: underline; }
.support.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--card);   /* white in light mode, near-black in dark: both pass contrast */
  font-size: 0.9375rem;
}
.support.button .material-symbols-outlined { vertical-align: 0; }
.support.button:hover { filter: brightness(1.1); text-decoration: none; }

nav {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.chip {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toggle { margin-left: auto; color: var(--muted); font-size: 0.875rem; cursor: pointer; }

main {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  grid-auto-flow: dense;   /* small cards fill the gaps the wide ones leave */
  gap: 16px;
  padding-top: 16px;
}

.card {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.card[hidden] { display: none; }
.card h2 a { color: inherit; text-decoration: none; }
.card h2 a:hover { color: var(--accent); }
.thumb { display: block; }
.card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.body { padding: 12px 14px 14px; }
.card h2 { margin: 0 0 6px; font-size: 1rem; line-height: 1.35; }
.meta { margin: 0; color: var(--muted); font-size: 0.8125rem; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.pulse {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px 2px 5px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pulse small { font-size: 0.6875rem; font-weight: 600; opacity: 0.8; }
.pulse-normal { color: var(--muted); }
.pulse-svt { color: var(--warm); }
.pulse-tachycardia { color: #fff; background: var(--accent); border-color: var(--accent); }
.card.hero .pulse { font-size: 1rem; }

/* Heart-rate tags beside the pulse. */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  cursor: help;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-svt { color: var(--warm); border: 1px solid var(--warm); }
.badge-flatline { color: var(--muted); border: 1px dashed var(--muted); }
.pulse-flatline { color: var(--muted); border-style: dashed; }

/* Each story's own ECG. */
.tile-ecg { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.tile-ecg svg { flex: 1; min-width: 0; height: 22px; }
.tile-ecg path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.25;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.tile-ecg.flat path { stroke: var(--muted); stroke-dasharray: 3 3; }
.tile-ecg span { color: var(--muted); font-size: 0.6875rem; white-space: nowrap; }
.card.hero .tile-ecg svg { height: 32px; }
.badge-tachycardia { color: #fff; background: var(--accent); }
.growth { color: var(--accent); font-weight: 600; white-space: nowrap; }

.also, .wiki { margin: 8px 0 0; color: var(--muted); font-size: 0.8125rem; }
.wiki a { color: var(--text); text-underline-offset: 3px; text-decoration-color: var(--line); }
.also a {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 8px;
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}

/* Bigger cards for the stories with the most activity. Only on screens with room for them. */
.card.hero h2 { font-size: 1.75rem; line-height: 1.2; letter-spacing: -0.01em; }
.card.wide h2 { font-size: 1.25rem; line-height: 1.25; }
@media (min-width: 600px) {
  .card.hero { grid-column: 1 / -1; }
  .card.wide { grid-column: span 2; }
  /* minmax(0, ...) so a wide tile ECG cannot stretch the text column and squeeze the
     picture's column to nothing (a 24-hour trace is 1,440 units wide). */
  .card.hero:has(.thumb) { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: center; }
  .card.hero img { height: 100%; max-height: 380px; }
  .card.hero .body { padding: 24px; }
  .card.hero h2 { margin-bottom: 12px; }
  .card.wide img { max-height: 260px; }
}

/* A spoiler card is blurred until its button, or the page toggle, reveals it. */
.card.spoiler :is(.thumb, h2, .badge) { filter: blur(14px); pointer-events: none; }
.card.spoiler.revealed :is(.thumb, h2, .badge),
body.show-spoilers .card.spoiler :is(.thumb, h2, .badge) { filter: none; pointer-events: auto; }
.reveal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.card.revealed .reveal, body.show-spoilers .reveal { display: none; }

.empty { color: var(--muted); }

footer {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8125rem;
}

/* The global ECG: always at the bottom of the screen, always dark like a heart monitor. */
body { padding-bottom: 104px; }
.ecg {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 max(16px, calc((100vw - 1200px) / 2));
  background-color: #0d0b13;
  background-image:
    linear-gradient(rgba(255, 107, 157, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 107, 157, 0.07) 1px, transparent 1px);
  background-size: 12px 12px;
  border-top: 1px solid #2e2a3c;
  color: #f1eef7;
}
.ecg-label { display: flex; align-items: center; gap: 4px; margin: 0; color: #a39db3; font-size: 0.75rem; white-space: nowrap; }
.ecg-label small { opacity: 0.8; }
.ecg-trace { flex: 1; min-width: 0; height: 40px; }
.ecg-trace path {
  fill: none;
  stroke: #ff6b9d;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.ecg-now { display: flex; align-items: center; gap: 5px; margin: 0; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ecg-now strong { font-size: 1.25rem; }
.ecg-now small { color: #a39db3; font-size: 0.6875rem; font-weight: 600; }
.ecg .badge-svt { color: #ffa94d; border-color: #ffa94d; }
.ecg-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff6b9d; animation: ecg-beat 1s ease-out infinite; }
@keyframes ecg-beat {
  0% { transform: scale(1); opacity: 1; }
  60% { transform: scale(1.9); opacity: 0.25; }
  100% { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .ecg-dot { animation: none; } }
.ecg-label .ecg-recent, .ecg-trace.ecg-recent { display: none; }
/* On phones the header's support button scrolls away at once, so it moves into the strip,
   which is always on screen. The strip is always dark, hence fixed colours. */
.support.ecg-support {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #ff6b9d;
  color: #0d0b13;
  font-size: 0.8125rem;
  white-space: nowrap;
}
.support.ecg-support .material-symbols-outlined { vertical-align: 0; }
.support.ecg-support:hover { filter: brightness(1.1); text-decoration: none; }
@media (max-width: 600px) {
  .status .top { display: none; }
  .support.ecg-support { display: inline-flex; }
  .ecg { gap: 8px; height: 48px; }
  .ecg-label { flex-direction: column; align-items: flex-start; gap: 0; }
  .ecg-label .material-symbols-outlined, .ecg-label .ecg-day, .ecg-trace.ecg-day { display: none; }
  .ecg-label .ecg-recent { display: inline; }
  .ecg-trace.ecg-recent { display: block; }
}

/* Time before the first reading: nothing to show, so a faint dotted line that can never be
   mistaken for a flatline (which is a dashed or solid flat stretch of the trace itself). */
.ecg-trace .nodata, .tile-ecg .nodata {
  stroke: currentColor;
  stroke-width: 1;
  stroke-dasharray: 1 5;
  stroke-linecap: round;
  opacity: 0.35;
  vector-effect: non-scaling-stroke;
}
.ecg-trace { color: #a39db3; }
.tile-ecg svg { color: var(--muted); }

/* Language picker, beside the spoiler toggle. */
.language-picker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.875rem;
}
.language-picker select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
}
.language-picker + .toggle { margin-left: 12px; }
