.ecg-lesson {
  --ecg-gold: #765a23;
  --ecg-gold-light: #f7efd9;
  --ecg-monitor: #212624;
}

.ecg-intro { max-width: 740px; margin-bottom: 32px; }
.ecg-intro h1 { margin: 0 0 8px; }
.ecg-intro nav { display: flex; flex-wrap: wrap; gap: 0 20px; margin-top: 12px; font-size: 14px; }
.ecg-intro nav a { display: inline-flex; align-items: center; min-height: 44px; }
.ecg-lab-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; column-gap: 16px; margin-bottom: 12px; }
.ecg-lab-heading h2 { margin: 0; }
.ecg-lab-heading > a { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; }

.ecg-lab, .ecg-case { background: var(--paper); border: 1px solid var(--line); border-radius: 4px; }
.ecg-lab { padding: clamp(12px, 2vw, 22px); }
.ecg-selectors { display: flex; flex-wrap: wrap; gap: 12px 24px; margin-bottom: 16px; }
.ecg-lesson fieldset { min-inline-size: 0; margin: 0; padding: 0; border: 0; }
.ecg-lesson legend { padding: 0; margin-bottom: 6px; font-size: 14px; font-weight: 700; }
.ecg-options { display: flex; flex-wrap: wrap; gap: 6px; }
.ecg-options button {
  background: var(--paper); color: var(--ink); border: 1px solid #c9c9c9; border-radius: 3px;
  min-height: 44px; padding: 5px 13px; font-size: 14px; line-height: 1.25;
}
.ecg-options button:hover { border-color: #777; }
.ecg-options button[aria-pressed="true"] { background: var(--ecg-gold-light); border-color: #a98a43; color: #4e3910; font-weight: 700; }
.ecg-workspace { display: grid; grid-template: "diagram notes" auto "recordings recordings" auto / minmax(0, 1.35fr) minmax(0, 1fr); align-items: start; gap: 22px; }
.ecg-chart { grid-area: diagram; }
.ecg-notes { grid-area: notes; }
.ecg-notes > div + div { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
#ecg-comparison { grid-area: recordings; min-width: 0; }
#ecg-comparison h3 { margin-bottom: 5px; }
.ecg-comparison-instructions { margin-bottom: 12px; }
.ecg-comparison-key { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 4px; }
.ecg-comparison-key span::before { content: ""; display: inline-block; width: .85em; height: .65em; border: 2px solid; border-radius: 2px; margin-right: .4em; }
.ecg-key-electrical::before { color: #a47a22; background: #f8d46c40; }
.ecg-key-flow::before { color: #287854; background: #9ff1cd40; }
.ecg-recordings { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.ecg-recording .ecg-monitor-head { min-height: 42px; align-items: center; }
.ecg-recording [data-ecg-diagram-match] { color: #f8d46c; }
.ecg-monitor { background: var(--ecg-monitor); border-radius: 4px; color: #f4f4f4; }
.ecg-monitor-head, .ecg-monitor-foot { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 12px; padding: 7px 12px; font-size: 14px; }
.ecg-monitor-head { border-bottom: 1px solid #414943; }
.ecg-monitor-foot { border-top: 1px solid #414943; }
.ecg-recording .ecg-monitor-foot { justify-content: flex-end; }
.ecg-monitor-head span, .ecg-monitor-foot span { font-size: 13px; color: #d3d8d1; }
#ecg-plot { display: block; width: 100%; height: auto; cursor: crosshair; }
#ecg-grid path { stroke: #3a453e; stroke-width: 1; }
.ecg-trace { fill: none; stroke: #9ed8c5; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.ecg-electrical { stroke: #f2e1a9; }
.ecg-artery { stroke: #e9aa8a; stroke-dasharray: 5 4; }
.ecg-divider { stroke: #526057; stroke-width: 1; }
.ecg-zero { stroke: #8d9a91; stroke-width: 1.4; stroke-dasharray: 5 4; }
#ecg-landmark-band { fill: #e1c777; opacity: .13; }
#ecg-cursor { stroke: #e1c777; stroke-width: 1.6; }
/* A halo in the monitor colour keeps labels readable where the cursor line or a trace passes behind them. */
.ecg-plot-label { font-family: var(--font); font-size: 21px; font-weight: 700; fill: #f4f4f4; paint-order: stroke; stroke: var(--ecg-monitor); stroke-width: 6px; stroke-linejoin: round; }
#ecg-plot[data-ecg-anchor="A"] [data-wave="A"],
#ecg-plot[data-ecg-anchor="S"] [data-wave="S"],
#ecg-plot[data-ecg-anchor="S"] [data-wave="No forward S"],
#ecg-plot[data-ecg-anchor="V"] [data-wave="V"],
#ecg-plot[data-ecg-anchor="D"] [data-wave="D"] { fill: #f8d46c; }
.ecg-zero-label, .ecg-artery-label { font-size: 20px; }
.ecg-artery-label { fill: #f8c4a9; }
.ecg-scrub { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.ecg-scrub .button { min-width: 122px; min-height: 44px; padding: 6px 10px; }
.ecg-scrub label { display: flex; align-items: center; flex: 1; min-height: 44px; }
.ecg-scrub input { accent-color: var(--ecg-gold); width: 100%; min-height: 32px; margin: 0; cursor: pointer; }

.ecg-lesson .ecg-timing { margin: 0 0 14px; }
.ecg-phases button { padding: 4px 10px; }
#ecg-phase-details h3, .ecg-reference h3 { font-size: 19px; margin-bottom: 4px; }
#ecg-phase-details p, .ecg-reference p { margin-bottom: 0; }
@media (min-width: 801px) {
  #ecg-phase-details { min-height: 8.75rem; }
  .ecg-recording-caption { min-height: 6.25rem; }
}
.ecg-chart-note { margin: 12px 0 0; }
.ecg-reference .small, .ecg-reference .ecg-formula { margin-top: 8px; }
.ecg-recording-strip { display: block; width: 100%; height: auto; overflow: hidden; background: #090d0b; }
.ecg-recording-zero { stroke: #e5ebea; stroke-width: 1; stroke-dasharray: 4 5; vector-effect: non-scaling-stroke; }
.ecg-recording-zero-label { font: 700 15px var(--font); fill: #fff; paint-order: stroke; stroke: #111; stroke-width: 5px; stroke-linejoin: round; }
.ecg-mark { --marker: #f8d46c; }
.ecg-mark-flow { --marker: #9ff1cd; }
.ecg-mark-box { fill: var(--marker); fill-opacity: .13; stroke: var(--marker); stroke-width: 2; vector-effect: non-scaling-stroke; }
.ecg-mark-label { fill: var(--marker); }
.ecg-mark text { fill: #101812; font: 700 15px var(--font); }
.ecg-monitor-foot a { display: inline-flex; gap: 6px; min-height: 44px; align-items: center; color: #f4f4f4; font-size: 13px; }
.ecg-monitor-foot a .icon, .ecg-scan-link span .icon { width: 16px; height: 16px; }
.ecg-monitor-foot a:focus-visible { outline-color: #f8d46c; }
.ecg-recording-caption strong { display: block; color: var(--ink); font-size: 16px; }
.ecg-recording-caption p { margin: 3px 0 0; }
.ecg-formula { background: var(--ecg-gold-light); border-radius: 3px; padding: 7px 10px; font-size: 14px; font-weight: 700; }
.ecg-lesson figure { min-width: 0; margin: 0; }
.ecg-scan-link { display: grid; place-items: center; background: #151816; border-radius: 3px; color: #f4f4f4; cursor: zoom-in; }
.ecg-scan-link:hover { color: #fff; }
.ecg-scan-link span { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px; font-size: 13px; }
.ecg-scan-link img { display: block; max-width: 100%; max-height: 350px; width: auto; height: auto; }
.ecg-lesson figcaption { font-size: 14px; line-height: 1.45; color: var(--muted); margin-top: 8px; }
.ecg-ivc-note { margin: 14px 0 0; font-size: 15px; }
/* Reading width for running text on desktop. */
.ecg-ivc-note, .ecg-chart-note, .ecg-comparison-instructions, .ecg-basics p, .ecg-glossary, .ecg-sources ul, .ecg-sources p { max-width: 72ch; }

#lead-ii, #practice, .ecg-sources { margin-top: 34px; }
.ecg-basics { display: grid; grid-template-columns: minmax(200px, .75fr) minmax(0, 2fr); gap: 24px; align-items: start; }
.ecg-axis { background: #f3f3f3; border: 1px solid #dfdfdf; border-radius: 4px; padding: 12px; text-align: center; }
.ecg-axis svg { display: block; width: 100%; max-width: 245px; margin: 0 auto; font: 700 15px var(--font); fill: #5d4619; }
.ecg-basics p, .ecg-glossary { margin: 0 0 12px; }
.ecg-glossary > div { display: grid; grid-template-columns: 75px 1fr; border-top: 1px solid var(--line); padding: 6px 0; gap: 8px; }
.ecg-glossary dt { font-weight: 700; }
.ecg-glossary dd { margin: 0; }

.ecg-case { margin-bottom: 8px; }
.ecg-case summary { min-height: 48px; padding: 10px 14px; font-weight: 700; cursor: pointer; }
.ecg-case-body { border-top: 1px solid var(--line); padding: clamp(12px, 2vw, 20px); }
.ecg-case-body:has(figure) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.ecg-question { margin: 0; }
.ecg-question legend { font-size: 16px; }
.ecg-question label { display: flex; align-items: baseline; gap: 9px; min-height: 44px; padding: 9px 3px; cursor: pointer; }
.ecg-question input { flex: none; margin: 0; accent-color: var(--ecg-gold); }
.ecg-question button { min-height: 44px; padding: 7px 13px; margin-top: 6px; }
.ecg-answer { margin: 0; }
.ecg-answer:not(:empty) { border: 1px solid #e5d6aa; border-radius: 6px; background: var(--accent-soft); padding: 9px 12px; margin-top: 10px; }
.ecg-answer[data-correct="true"] { border-color: #bddbc7; background: #eff7f1; }
.ecg-sources h2 { margin-bottom: 8px; }

@media (max-width: 800px) {
  .ecg-workspace { grid-template: "diagram" "notes" "recordings" / minmax(0, 1fr); gap: 18px; }
  .ecg-recordings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .ecg-intro { margin-bottom: 20px; }
  .ecg-intro h1 { font-size: clamp(25px, 8vw, 32px); }
  .ecg-intro nav { margin-top: 6px; }
  .ecg-selectors { display: grid; gap: 8px; }
  .ecg-selectors .ecg-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ecg-selectors .ecg-options button { padding-inline: 4px; }
  .ecg-phases { display: flex; flex-wrap: wrap; gap: 6px; }
  .ecg-phases button { flex: 0 1 calc((100% - 12px) / 3); padding: 6px 8px; font-size: 13px; }
  .ecg-recordings { grid-template-columns: minmax(0, 1fr); }
  .ecg-basics, .ecg-case-body:has(figure) { grid-template-columns: 1fr; gap: 12px; }
  .ecg-plot-label { font-size: 26px; }
  /* At this size the hepatic D label would sit on the trough of the trace. */
  #ecg-plot [data-ecg-trace^="hepatic"] [data-wave="D"] { transform: translateY(10px); }
  .ecg-zero-label, .ecg-artery-label { font-size: 24px; }
}
