@layer reset, base, components, utilities;

/* Shared calculator components. Page-specific sheets add only controls that are not common to every calculator. */

@layer components {
  :where(.sec-label, .current-time-jump, .ro .label, .drink .lbl, .drinks-cols span, .assumption-k) {
    font-family: var(--mono);
    text-transform: uppercase;
    color: var(--ink-3);
  }
  :where(.sec-label) {
    font-size: var(--fs-eyebrow);
    letter-spacing: var(--tracking-eyebrow);
  }
  :where(.ro .label, .drink .lbl, .assumption-k) {
    font-size: var(--fs-eyebrow-sm);
    letter-spacing: var(--tracking-eyebrow-sm);
  }
  :where(.dt-input, .drink input[type=number], .drink-preset) {
    width: 100%;
    font-family: var(--mono);
    color: var(--ink);
    outline: none;
  }
  :where(.dt-input, .drink) {
    border-radius: var(--control-radius);
    background: var(--paper-light);
  }
  :where(.drinks-count, .th-cell .cite, .ref-link) {
    font-family: var(--mono);
    color: var(--ink-3);
  }
  :where(.field .note, .ro .sub, .inline-note) {
    font-style: italic;
    color: var(--ink-3);
  }
  :where(.foot-link, .tabs button, .share-link, .mini-action, .drink button.del, .add-drink, .reset-drinks) {
    background: transparent;
    cursor: pointer;
  }

  /* Calculator pages widen the shared article container; the smallcaps title stays on one line. */
  .page { max-width: 1320px; }
  .mast h1 { white-space: nowrap; }

  .dek {
    font-size: var(--fs-lead);
    line-height: 1.45;
    color: var(--ink-2);
    max-width: 68ch;
    margin: var(--space-2xl) 0 0;
    font-weight: 300;
  }
  .dek em { color: var(--ink); font-style: italic; }

  /* ————— Primary grid ————— */
  .main {
    display: grid;
    grid-template-columns: minmax(0,1fr) 360px;
    gap: var(--space-3xl);
    padding: var(--space-2xl) 0 0;
  }
  @media (max-width: 980px) {
    .main { grid-template-columns: 1fr; }
  }

  @media (max-width: 720px) {
    body {
      overflow-x: clip;
    }
    .page {
      width: 100%;
      max-width: 100%;
      overflow-x: clip;
      padding-top: 22px;
    }
    .main {
      width: 100%;
      max-width: 100%;
      padding-top: 0px;
    }
  }

  /* ————— Chart column ————— */
  .chart-card {
    position: relative;
    container: chart-card / inline-size;
  }
  .chart-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-xl);
    margin-bottom: var(--space-sm);
  }
  .chart-title {
    font-family: var(--serif);
    font-size: var(--fs-title);
    line-height: 1.08;
    font-style: italic;
    font-weight: 400;
    margin: 0;
  }
  .chart-sub {
    font-family: var(--mono);
    font-size: var(--fs-eyebrow);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-3);
  }
  .chart-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9.5;
    min-height: 380px;
  }
  @container chart-card (max-width: 760px) {
    .chart-head {
      align-items: start;
      gap: 14px;
    }
    .chart-title {
      font-size: var(--fs-subhead);
      line-height: 1.08;
      max-width: 9em;
    }
    .chart-sub {
      font-size: var(--fs-eyebrow-sm);
      letter-spacing: 0.1em;
      line-height: 1.55;
      max-width: 18ch;
    }
    .chart-wrap {
      aspect-ratio: 16 / 5.6;
      min-height: 210px;
    }
    .legend {
      display: flex;
      flex-wrap: nowrap;
      gap: 12px;
      font-size: var(--fs-eyebrow-sm);
      letter-spacing: 0.04em;
      margin-top: 6px;
    }
    .legend .k {
      gap: 6px;
      min-width: 0;
    }
    .legend .k .sw {
      width: 16px;
      flex: 0 0 16px;
    }
    .legend-detail {
      display: none;
    }
    .chart .annotation--small {
      display: none;
    }
  }
  @container chart-card (max-width: 560px) {
    /* Below this width the chart drops the axis-naming subtitle. */
    .chart-sub {
      display: none;
    }
  }
  @container chart-card (max-width: 460px) {
    .chart-wrap {
      min-height: 190px;
    }
  }
  svg.chart {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
  }
  svg.chart:focus { outline: none; }
  svg.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

  /* ————— Readouts under chart ————— */
  .readouts {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    margin-top: var(--space-2xs);
    border-top: var(--hairline-ink);
    border-bottom: var(--hairline-rule);
  }
  .ro {
    padding: var(--space-md) var(--space-lg) var(--space-xs);
    border-right: var(--hairline-rule);
  }
  .ro:last-child { border-right: 0; }
  .ro .label {
    margin-bottom: 6px;
  }
  .ro .value {
    font-family: var(--serif);
    font-size: var(--fs-stat);
    line-height: 1;
    font-weight: 400;
    font-variation-settings: "opsz" 40;
  }
  .ro .value .u {
    font-family: var(--mono);
    font-size: var(--fs-eyebrow);
    color: var(--ink-3);
    margin-left: 4px;
    letter-spacing: 0.04em;
    font-weight: 400;
  }
  .ro .value .readout-jump {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--accent);
    text-underline-offset: 4px;
  }
  .ro .value .readout-jump:hover,
  .ro .value .readout-jump:focus-visible {
    color: var(--accent);
    outline: none;
  }
  .ro .sub {
    font-family: var(--serif);
    font-size: var(--fs-body-sm);
    margin-top: 4px;
    line-height: 1;
  }
  .sub-mobile {
    display: none;
  }

  /* ————— Controls ————— */
  aside.controls {
    border-left: var(--hairline-rule);
    padding-left: var(--space-2xl);
  }
  @media (max-width: 980px) {
    aside.controls { border-left: 0; padding-left: 0; border-top: var(--hairline-rule); padding-top: 0px; }
  }

  .sec-label {
    margin: 0 0 var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
  }
  .sec-label--flush { margin: 0; }
  .sec-label--biblio { margin-bottom: 8px; }
  .sec-label::before {
    content: "";
    display: inline-block;
    width: 18px;
    height: 1px;
    background: var(--ink-2);
  }
  .controls-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
  }
  .controls-head .sec-label {
    margin: 0;
  }
  .current-time-jump {
    display: inline-flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 7px;
    min-width: 0;
    font-size: var(--fs-eyebrow-sm);
    letter-spacing: var(--tracking-eyebrow-sm);
    line-height: 1;
    text-align: right;
    white-space: nowrap;
  }
  .current-time-button {
    appearance: none;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font-family: var(--mono);
    font-size: var(--fs-meta);
    font-weight: 520;
    letter-spacing: 0.02em;
    line-height: 1;
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
  }
  .current-time-button:hover,
  .current-time-button:focus-visible {
    color: var(--accent);
    outline: none;
  }

  .field {
    display: grid;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
  }
  .field--flush {
    margin-top: 0;
    gap: 2px;
  }
  .field .row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
  }
  .row--with-actions {
    align-items: center;
  }
  .field-actions {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
    margin-left: auto;
  }
  .field .name {
    font-family: var(--serif);
    font-style: italic;
    font-size: var(--fs-body);
  }
  .field .val {
    font-family: var(--mono);
    font-size: var(--fs-meta);
    color: var(--ink-2);
    letter-spacing: 0.03em;
  }
  .field .note {
    font-family: var(--serif);
    font-size: var(--fs-body-sm);
    line-height: 1.1;
  }
  .field--seg-left .row {
    display: grid;
    justify-content: start;
    align-items: start;
    gap: 0;
  }
  .range-frame {
    width: 75%;
    margin-inline: auto;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    font-family: var(--mono);
    font-size: var(--fs-meta);
    line-height: 1;
    color: var(--ink-3);
  }
  .range-frame::before,
  .range-frame::after {
    content: "|";
  }
  .range-frame input[type=range] {
    width: 100%;
  }

  /* Segmented control — radio group styled as segments */
  .seg {
    display: inline-flex;
    border: var(--field-border);
    border-radius: var(--radius);
    overflow: hidden;
    font-family: var(--mono);
    font-size: var(--fs-meta);
  }
  .seg label {
    position: relative;
    padding: 5px 11px;
    cursor: pointer;
    color: var(--ink-2);
    letter-spacing: 0.04em;
  }
  .seg label span {
    display: block;
    font-size: var(--fs-eyebrow-sm);
    letter-spacing: 0.06em;
    opacity: 0.72;
    margin-top: 1px;
  }
  .seg:not(.seg--inline-meta) {
    min-width: 144px;
  }
  .seg:not(.seg--inline-meta) label {
    flex: 1 1 0;
    text-align: center;
  }
  .seg--inline-meta label {
    white-space: nowrap;
  }
  .seg--inline-meta label span {
    display: inline;
    margin-top: 0;
    margin-left: 3px;
  }
  .seg label + label { border-left: var(--hairline-rule); }
  .seg label:has(input:checked) { background: var(--ink); color: var(--paper); }
  .seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
  .seg input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .dt-input {
    font-size: var(--fs-body-sm);
    padding: 7px 9px;
    border: var(--field-border);
    margin-bottom: 2px;
  }
  .dt-input:focus { border-color: var(--accent); }

  /* ————— Lower spreads ————— */
  .spread {
    padding: var(--space-5xl) 0 0;
  }
  .spread h2 {
    font-family: var(--serif);
    font-size: var(--fs-h2);
    line-height: 1.04;
    letter-spacing: 0;
    font-weight: 400;
    margin: 0 0 4px;
  }
  .spread h2 em { font-style: italic; color: var(--ink-2); font-weight: 300; }
  .spread .dek2 {
    font-size: var(--fs-body);
    color: var(--ink-2);
    max-width: 60ch;
    margin: 6px 0 20px;
    font-style: italic;
    line-height: 1.3;
  }
  .spread .dek2--support {
    max-width: 72ch;
    margin-top: -8px;
    font-style: normal;
  }
  @media (max-width: 720px) {
    .spread { padding-top: 38px; }
    .spread h2 { line-height: 1.06; }
    .spread .dek2 { font-size: var(--fs-body); margin-bottom: 16px; }
    .spread .dek2--support { margin-top: -4px; }
  }

  /* Threshold table */
  .thresholds {
    display: grid;
    grid-template-columns: repeat(var(--threshold-count, 4), minmax(0, 1fr));
    border-top: var(--hairline-ink);
  }
  @media (max-width: 820px) {
    .thresholds { grid-template-columns: repeat(2, 1fr); }
    .th-cell:nth-child(2n),
    .th-cell:last-child { border-right: 0; }
  }
  @media (max-width: 560px) {
    /* Two-up cells get too narrow on phones — prose wraps one word per line. */
    .thresholds { grid-template-columns: 1fr; }
    .th-cell { border-right: 0; }
  }
  .th-cell {
    padding: var(--space-lg) var(--space-lg) var(--space-xl);
    border-right: var(--hairline-rule);
    border-bottom: var(--hairline-rule);
    position: relative;
  }
  .th-cell:last-child { border-right: 0; }
  .th-cell .cut {
    font-family: var(--serif);
    font-size: var(--fs-stat-lg);
    font-weight: 400;
    font-variation-settings: "opsz" 60;
    line-height: 1;
  }
  .th-cell .cut .u {
    font-family: var(--mono);
    font-size: var(--fs-meta);
    letter-spacing: 0.05em;
    color: var(--ink-3);
    margin-left: 4px;
  }
  .th-cell .who {
    font-family: var(--serif);
    font-style: italic;
    font-size: var(--fs-body);
    margin-top: 8px;
    color: var(--ink);
    line-height: 1.35;
  }
  .th-cell .desc {
    font-size: var(--fs-body-sm);
    color: var(--ink-2);
    line-height: 1.3;
    margin-top: 4px;
  }
  .th-cell .cite {
    font-size: var(--fs-eyebrow);
    letter-spacing: 0.06em;
    margin-top: 8px;
  }
  .th-cell .swatch {
    position: absolute;
    top: 20px; right: 18px;
    width: 22px; height: 3px;
    background: var(--accent);
  }

  /* Field notes / reference */
  .notes-grid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: var(--space-4xl);
  }
  .notes-grid--spaced { margin-top: var(--space-lg); }
  @media (max-width: 820px) { .notes-grid { grid-template-columns: 1fr; } }
  .notes-grid h3 {
    font-family: var(--serif);
    font-style: italic;
    font-size: var(--fs-subhead);
    font-weight: 400;
    margin: 22px 0 8px;
    line-height: 1.18;
  }
  .notes-grid h3:first-child, .notes-grid > div > h3:first-of-type { margin-top: 0; }
  .notes-heading--flush { margin-top: 0; }
  .notes-grid p { margin: 0 0 var(--space-md); color: var(--ink-2); font-size: var(--fs-body); line-height: 1.56; }
  @media (max-width: 720px) {
    .notes-grid p { font-size: var(--fs-body); line-height: 1.1; }
  }
  .notes-grid p sup { color: var(--accent); font-family: var(--mono); font-size: var(--fs-eyebrow); padding: 0 1px; cursor: help; }

  .assumptions {
    display: grid;
    gap: 0;
    border-top: var(--hairline-ink);
    margin: var(--space-md) 0 var(--space-xl);
  }
  .assumption {
    border-bottom: var(--hairline-rule);
    padding: var(--space-md) var(--space-lg) var(--space-md) 0;
  }
  .assumption-v {
    font-size: var(--fs-body-lg);
    line-height: 1.1;
    margin-top: 5px;
    color: var(--ink);
  }
  .assumption-v sup {
    color: var(--accent);
    font-family: var(--mono);
    font-size: var(--fs-eyebrow);
    padding-left: 2px;
    cursor: help;
  }
  .assumption-d {
    color: var(--ink-2);
    font-size: var(--fs-body-sm);
    line-height: 1.48;
    margin-top: 7px;
  }

  /* tooltip */
  .tt {
    position: fixed;
    pointer-events: none;
    background: var(--ink);
    color: var(--paper);
    font-family: var(--mono);
    font-size: var(--fs-meta);
    line-height: 1.45;
    letter-spacing: 0.02em;
    padding: 10px 12px;
    border-radius: 3px;
    max-width: 280px;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .12s, transform .12s;
    z-index: 1000;
  }
  .tt.on { opacity: 1; transform: translateY(0); }
  .tt b { color: var(--accent-soft); font-weight: 500; }
  .tt-ref-title {
    color: var(--ink-tooltip-sub);
    font-size: var(--fs-eyebrow);
    margin-top: 6px;
  }

  /* Footer — core chrome (.foot / .dis / .foot-meta / .foot-copy) lives in
     base.css and is shared by every page. Calculators add the share links. */
  .share-link {
    border: 0;
    padding: 0;
    color: var(--ink);
    font: inherit;
    letter-spacing: inherit;
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-underline-offset: 3px;
  }
  .share-link:hover,
  .share-link:focus-visible {
    color: var(--accent);
  }
  footer.foot .share-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-sm) var(--space-md);
    max-width: 330px;
  }
  .share-glyph {
    display: none;
  }
  @media (max-width: 720px) {
    footer.foot { grid-template-columns: 1fr; }
    footer.foot .foot-meta {
      gap: 12px;
      justify-items: start;
      text-align: left;
    }
    footer.foot .share-links {
      justify-content: flex-start;
      gap: 8px;
      max-width: none;
      padding-top:6px;
    }
    .share-link {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 34px;
      height: 34px;
      border: var(--hairline-rule);
      border-radius: 8px;
      color: var(--ink);
      text-decoration: none;
      background: var(--paper-light);
      line-height: 1;
    }
    .share-link:hover,
    .share-link:focus-visible {
      border-color: var(--accent);
      background: var(--paper);
    }
    .share-glyph {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 18px;
      height: 18px;
      font-family: var(--mono);
      font-size: var(--fs-meta);
      font-weight: 650;
      letter-spacing: 0;
      color: currentColor;
    }
    svg.share-glyph {
      display: block;
      fill: none;
      stroke: currentColor;
      stroke-width: 1.8;
      stroke-linecap: round;
      stroke-linejoin: round;
    }
    .share-glyph--wide {
      font-size: var(--fs-eyebrow);
    }
    .share-text {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }
  }

  /* SVG chart specifics */
  .chart .grid-line { stroke: var(--rule-soft); stroke-width: 1; }
  .chart .axis-line { stroke: var(--ink); stroke-width: 1; }
  .chart .tick { font-family: var(--mono); font-size: var(--fs-eyebrow); fill: var(--ink-3); }
  .chart .tick--minor { fill: var(--ink-4); font-size: var(--fs-eyebrow-sm); }
  .chart .axis-label { font-family: var(--mono); font-size: var(--fs-eyebrow-sm); letter-spacing: 0.12em; text-transform: uppercase; fill: var(--ink-3); }
  .chart .curve { fill: none; stroke: var(--ink); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
  .chart .curve-fill { fill: var(--accent); opacity: 0.08; }
  .chart .bac-curve { fill: none; stroke: var(--accent); stroke-width: 1.55; stroke-dasharray: 4 3; opacity: 0.95; }
  .chart .comparison-curve {
    fill: none;
    stroke: var(--ink-3);
    stroke-width: 1.35;
    stroke-dasharray: 7 4;
    opacity: 0.9;
  }
  .chart .bac-axis-line,
  .chart .bac-axis-tick {
    stroke: var(--accent);
    stroke-width: 1;
    opacity: 0.72;
  }
  .chart .bac-tick,
  .chart .bac-axis-label {
    fill: var(--accent);
  }
  .chart .now-handle-group {
    cursor: ew-resize;
    touch-action: none;
  }
  .chart .now-label {
    fill: var(--paper);
    font-family: var(--mono);
    font-size: var(--fs-meta);
    letter-spacing: 0.04em;
  }
  .chart .now-crosshair {
    fill: none;
    stroke-width: 1.1;
    stroke-dasharray: 3 4;
    opacity: 0.58;
  }
  .chart .now-crosshair--etg,
  .chart .now-crosshair--ets,
  .chart .now-crosshair--cotinine { stroke: var(--ink); }
  .chart .now-crosshair--bac { stroke: var(--accent); }
  .chart .now-line { stroke: var(--accent); stroke-width: 1.65; }
  .chart .now-handle { cursor: ew-resize; }
  .chart .now-handle-plate { fill: var(--paper); stroke: var(--accent); stroke-width: 5; stroke-opacity: 0.18; }
  .chart .now-handle-pill { fill: var(--paper); stroke: var(--accent); stroke-width: 1.4; }
  .chart .now-handle-arrow { fill: none; stroke: var(--accent); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  @media (pointer: coarse) and (prefers-reduced-motion: no-preference) {
    .chart-card:not(.has-scrubbed) .chart .now-handle-plate {
      animation: scrubber-pulse 1.45s ease-in-out infinite;
    }
    .chart-card:not(.has-scrubbed) .chart .now-line {
      animation: scrubber-line-pulse 1.45s ease-in-out infinite;
    }
  }
  @keyframes scrubber-pulse {
    0%, 100% {
      stroke-opacity: 0.18;
      stroke-width: 5;
    }
    45% {
      stroke-opacity: 0.46;
      stroke-width: 8;
    }
  }
  @keyframes scrubber-line-pulse {
    0%, 100% {
      stroke-opacity: 1;
      stroke-width: 1.65;
    }
    45% {
      stroke-opacity: 0.72;
      stroke-width: 2.4;
    }
  }
  .chart .drink-mark { fill: var(--ink); }
  .chart .annotation {
    font-family: var(--serif);
    font-size: var(--fs-body-sm);
    font-style: italic;
    fill: var(--ink-2);
  }
  .chart .annotation--small {
    fill: var(--ink-2);
    font-size: var(--fs-meta);
  }
  .chart .annotation-num {
    font-family: var(--mono);
    font-size: var(--fs-eyebrow);
    fill: var(--accent);
    letter-spacing: 0.04em;
  }
  .chart .peak-dot { fill: var(--ink); }
  .chart .peak-ring { fill: none; stroke: var(--ink); stroke-width: 1; opacity: 0.35; }

  /* Legend */
  .legend {
    display: flex;
    gap: var(--space-lg);
    font-family: var(--mono);
    font-size: var(--fs-eyebrow);
    letter-spacing: 0.06em;
    color: var(--ink-2);
    margin-top: 2px;
    flex-wrap: wrap;
  }
  .legend .k { display: inline-flex; align-items: center; gap: 8px; }
  .legend .k .sw {
    display: inline-block; width: 22px; height: 2px; background: var(--ink);
  }
  .legend .k .sw.dash { background: transparent; border-top: 1.5px dashed var(--accent); height: 0; }
  .legend .k .sw.compare { background: transparent; border-top: 1.5px dashed var(--ink-3); height: 0; opacity: 0.8; }

  .related-tests {
    margin-top: var(--space-xl);
    padding-top: var(--space-md);
  }
  .spread:has(.related-tests) + footer.foot {
    margin-top: 0;
  }
  .related-test-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0;
    margin-top: var(--space-sm);
    border-top: var(--hairline-rule);
    border-left: var(--hairline-rule);
    min-width: 0;
  }
  .related-test {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1px var(--space-sm);
    align-items: baseline;
    min-width: 0;
    min-height: 74px;
    padding: 8px 10px;
    border-right: var(--hairline-rule);
    border-bottom: var(--hairline-rule);
    background: transparent;
    color: var(--ink);
    text-decoration: none;
  }
  .related-test:hover .related-test-label,
  .related-test:focus-visible .related-test-label {
    color: var(--accent);
  }
  .related-test-group {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    font-family: var(--mono);
    font-size: var(--fs-micro);
    letter-spacing: var(--tracking-eyebrow-sm);
    text-transform: uppercase;
    color: var(--ink-4);
    white-space: nowrap;
  }
  .related-test-label {
    grid-column: 1;
    grid-row: 1;
    font-family: var(--mono);
    font-size: var(--fs-micro);
    letter-spacing: var(--tracking-eyebrow-sm);
    text-transform: uppercase;
    color: var(--accent);
    white-space: nowrap;
  }
  .related-test-name {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    font-family: var(--serif);
    font-style: italic;
    font-size: var(--fs-body-lg);
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .related-test-desc {
    grid-column: 1 / -1;
    grid-row: 3;
    color: var(--ink-3);
    font-size: var(--fs-body-sm);
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .related-test--current {
    background: color-mix(in srgb, var(--paper-light) 58%, transparent);
  }
  .related-test--current .related-test-label {
    color: var(--ink-3);
  }

  .inline-note {
    font-family: var(--serif); font-size: var(--fs-body-sm);
    margin-top: var(--space-sm); margin-bottom: 0px; line-height: 1.4;
  }

  /* Phone chart mode: keep the chart visible while inputs scroll underneath.
     Desktop/tablet keep the fuller chart title, legend, readouts, and hints. */
  @media (max-width: 720px) {
    .page {
      --phone-gap-tight: 2px;
      --phone-gap: 5px;
      --phone-label-size: 9px;
      --phone-control-size: 13px;
      --phone-field-size: 14px;
      --phone-input-size: 16px;
      --phone-editor-height: 38px;
      --phone-datetime-height: 30px;
    }

    /* Chart header and legend */
    .legend {
      flex-wrap: wrap;
      gap: 0 18px;
      font-size: var(--fs-meta);
      margin-top: 0px;
    }
    .legend .k {
      gap: 6px;
    }
    .legend .k .sw {
      width: 16px;
      flex: 0 0 16px;
    }
    /* Phones get the chart without its title (the masthead names the page)
       and one dense 5-cell readout row. */
    .chart-head {
      display: none;
    }

    /* Dense 5-cell readout row */
    .readouts {
      margin-top: 5px;
      margin-bottom: 0;
      border-bottom: 0;
      align-items: stretch;
      grid-template-columns: repeat(5, minmax(0, 1fr));
    }
    .ro,
    .ro:nth-child(2n) {
      border-right: 1px solid var(--rule);
      border-bottom: 0;
      padding: 2px 5px;
      min-height: 100%;
    }
    .ro:last-child {
      border-right: 0;
    }
    .ro .label {
      font-size: var(--fs-micro);
      letter-spacing: 0;
      margin-bottom: 1px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .ro .value {
      font-size: var(--phone-input-size);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .ro .sub {
      display: block;
      margin-top: 0px;
      font-family: var(--mono);
      font-style: normal;
      font-size: var(--phone-label-size);
      line-height: 1.1;
      color: var(--ink-3);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .sub-desktop {
      display: none;
    }
    .sub-mobile {
      display: inline;
    }
    /* Units would wrap the narrow cells, and the chart axis still names ng/ml. */
    .ro .value .u,
    .ro .label .label-detail {
      display: none;
    }
    .ro:nth-child(4) .label::after,
    .ro:nth-child(5) .label::after {
      content: "ng/ml";
      text-transform: none;
    }
    .inline-note {
      display: none;
    }

    /* Compact controls */
    aside.controls {
      width: 100%;
      max-width: 100%;
      margin-top: 0;
      padding-top: 5px;
      border-top: var(--hairline-rule);
    }
    aside.controls > .controls-head {
      margin-bottom: 5px;
    }
    .controls-head .sec-label {
      font-size: var(--fs-eyebrow);
    }
    .current-time-jump {
      gap: 5px;
      font-size: var(--phone-label-size);
      letter-spacing: 0.1em;
    }
    .current-time-button {
      font-size: var(--phone-control-size);
    }
    .field .note {
      display: none;
    }
    .field {
      gap: 2px;
      margin-top: var(--phone-gap);
    }
    .field .name {
      font-size: var(--phone-field-size);
    }
    .dt-input {
      width: min(304px, calc(100% - 24px));
      height: var(--phone-datetime-height);
      min-height: 0;
      min-width: 0;
      max-width: 100%;
      justify-self: center;
      padding: 1px 7px;
      font-size: var(--fs-body-sm);
      line-height: 1;
    }

    /* Sticky needs travel room: as a grid item the card is contained by its
       own grid row, so the single-column phone layout uses block flow.
       .main containment unpins the card once the controls scroll past. */
    .main {
      display: block;
    }
    aside.controls {
      margin-top: 0px;
    }
    .chart-shell {
      width: 100%;
      max-width: 100%;
      position: sticky;
      top: 0;
      z-index: 10;
      background: var(--paper);
      padding-top: 2px;
      padding-bottom: 0px;
      border-bottom: var(--hairline-ink);
      box-shadow: 0 6px 14px rgb(26 22 18 / 0.08);
    }
    .chart-card {
      width: calc(100%);
    }
    .chart-wrap {
      aspect-ratio: auto;
      min-height: 0;
      height: clamp(170px, 29vh, 250px);
    }
  }

  /* noscript warning banner */
  .noscript-banner {
    background: var(--paper-light);
    border: 1.5px solid var(--accent);
    border-radius: var(--radius);
    padding: var(--space-xl) var(--space-2xl);
    margin-bottom: var(--space-2xl);
    font-family: var(--serif);
    font-size: var(--fs-body);
    color: var(--ink);
    line-height: 1.5;
  }
  .noscript-banner strong {
    color: var(--accent);
    font-weight: 500;
  }

}

/* ————— Utilities ————— */
@layer utilities {
  .smallcaps { font-variant-caps: small-caps; }
}

/* ————— Print Styles ————— */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .page {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  /* Hide interactive form elements, tab bars, handles, and CTA buttons */
  form#controls-form,
  .tabs,
  .controls-head,
  .add-drink,
  .reset-drinks,
  .drink button.del,
  .drink input,
  .chart .now-handle-group,
  .chart .now-line,
  .chart .now-crosshair {
    display: none !important;
  }
  .main {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }
  /* Layout chart and readouts full width */
  .chart-card {
    width: 100% !important;
    break-inside: avoid;
  }
  .chart-wrap {
    aspect-ratio: 16 / 9.5 !important;
    height: auto !important;
    break-inside: avoid;
  }
  .readouts {
    grid-template-columns: repeat(5, 1fr) !important;
    break-inside: avoid;
  }
  .spread {
    padding-top: 24px !important;
    break-inside: avoid;
  }
  .notes-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .biblio ol {
    column-count: 2 !important;
    break-inside: avoid;
  }
}
