.demo {
  --ecg-grid: #f6d2d2;
  --ecg-grid-major: #e59a9a;
  --ecg-trace: #1b1b1f;
  --wiggers-lv: #b3122e;
  --wiggers-aorta: #1f5fbf;
  --wiggers-la: #2a7d4f;
  --wiggers-volume: #7a3fb0;
  --wiggers-systole: rgb(179 18 46 / 7%);

  display: grid;
  gap: 1rem;
}

@media (prefers-color-scheme: dark) {
  .demo {
    --ecg-grid: #3a2326;
    --ecg-grid-major: #6e3a40;
    --ecg-trace: #f2f2f5;
    --wiggers-lv: #ff7a8a;
    --wiggers-aorta: #7fb2ff;
    --wiggers-la: #6fd39b;
    --wiggers-volume: #c79bff;
    --wiggers-systole: rgb(255 122 138 / 10%);
  }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: center;
}

/* Play: an accent pill; sound: the same pill outlined. Both keep their width when the label switches. */
.play,
.sound {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  min-inline-size: 8.5rem;
  padding-block: 0.5rem;
  padding-inline: 1rem 1.25rem;
  border: 1px solid var(--color-accent);
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
}

.play {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.sound {
  min-inline-size: 11rem;
  background: var(--color-bg);
  color: var(--color-text);
}

.play:focus-visible,
.sound:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.icon {
  flex: none;
  inline-size: 1rem;
  block-size: 1rem;
  fill: currentcolor;
}

/* The speaker faces the reading direction. */
.sound .icon:dir(rtl) {
  transform: scaleX(-1);
}

.wave {
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

/* The label above, the slider and its value on one line, so the value never wraps alone. */
.rate {
  display: grid;
  grid-template-columns: minmax(0, 12rem) auto;
  gap: 0.25rem 0.5rem;
  align-items: center;
}

.rate label,
.rate-label {
  grid-column: 1 / -1;
}

.rate input {
  accent-color: var(--color-accent);
}

.rate output {
  min-inline-size: 3ch;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* Fieldsets without a frame: the legend sits above a segmented switch. */
.speed,
.presets {
  display: grid;
  gap: 0.375rem;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.speed legend,
.presets legend {
  padding: 0;
  margin-block-end: 0.375rem;
}

.segments {
  display: inline-flex;
  flex-wrap: wrap;
  justify-self: start;
  max-inline-size: 100%;

  /* Muted, not the border colour: a control outline needs 3:1 against the page. */
  border: 1px solid var(--color-muted);

  /* Half a row: a second row on a narrow screen keeps its corners instead of being clipped. */
  border-radius: 1.125rem;
  overflow: hidden;
}

.segments label {
  position: relative;
  flex: 1 1 auto;
  padding-block: 0.375rem;
  padding-inline: clamp(0.625rem, 3vw, 1rem);
  text-align: center;
  cursor: pointer;
}

.segments label:has(:checked) {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

/* Inside the label: the rounded switch clips anything drawn outside it. */
.segments label:has(:focus-visible) {
  outline: 2px solid currentcolor;
  outline-offset: -4px;
}

.segments input {
  position: absolute;
  opacity: 0;
}

/* Forced colours drop the background, so the chosen item gets an outline instead. */
@media (forced-colors: active) {
  .segments label:has(:checked) {
    outline: 2px solid Highlight;
    outline-offset: -4px;
  }

  /* The focused radio is the checked one, so focus needs its own, heavier outline. */
  .segments label:has(:focus-visible) {
    outline: 4px double Highlight;
    outline-offset: -6px;
  }
}

/* The long list of states: a native select, grouped, full width on a phone. */
.picker {
  display: grid;
  gap: 0.375rem;
  justify-items: start;
}

.picker select {
  inline-size: min(100%, 28rem);
  padding-block: 0.5rem;
  padding-inline: 0.75rem;
  border: 1px solid var(--color-muted);
  border-radius: 0.5rem;
  background: var(--color-bg);
  color: var(--color-text);
  font: inherit;
}

.picker select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.summary,
.phase,
.description {
  margin: 0;
}

.strip {
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.description,
.note {
  color: var(--color-muted);
}

/* In place of the Wiggers diagram when there are no cycles to draw. */
.no-cycles {
  margin: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
}

.ecg,
.wiggers {
  display: block;
}

.wiggers-title {
  margin-block: 1rem 0;
  font-size: 1.25rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
}

.legend li::before {
  content: '';
  display: inline-block;
  inline-size: 1.25rem;
  block-size: 0.25rem;
  margin-inline-end: 0.5rem;
  vertical-align: middle;
  background: var(--swatch);
}

.legend [data-series='lv'] {
  --swatch: var(--wiggers-lv);
}

.legend [data-series='aorta'] {
  --swatch: var(--wiggers-aorta);
}

.legend [data-series='la'] {
  --swatch: var(--wiggers-la);
}

.legend [data-series='volume'] {
  --swatch: var(--wiggers-volume);
}

/* Dashed like their curves. */
.legend [data-series='la']::before,
.legend [data-series='volume']::before {
  background: repeating-linear-gradient(
    to right,
    var(--swatch) 0 0.375rem,
    transparent 0.375rem 0.625rem
  );
}

.legend [data-series='volume']::before {
  background: repeating-linear-gradient(
    to right,
    var(--swatch) 0 0.125rem,
    transparent 0.125rem 0.3125rem
  );
}

.legend [data-series='systole']::before {
  block-size: 0.75rem;
  background: var(--wiggers-systole);
  outline: 1px solid var(--color-border);
}
