/* Readability and accessibility refinements (audit phase 2).
   Loaded last so it can adjust the shared material without rewriting it.
   The visual language stays the same: dark, neutral, light type, thin borders,
   rounded corners. Doubled :root raises specificity above the shared
   `:root :is(...)` material rules without resorting to !important. */

/* 1. One selected state everywhere: full-strength text, area border, ~12% area fill.
      Previously some selected items used the accent as text colour, which is
      dimmer than the default text and made them look disabled. */
:root:root .portfolio-area-nav > a[aria-current="page"] {
  color: var(--text);
  background-color: rgba(var(--ph-area-rgb), .12);
  border-color: var(--ph-area-color);
}
:root:root .navigation-dropdown-panel > a[aria-current="page"] {
  color: var(--text);
  background: rgba(var(--accent-rgb), .12);
  border-radius: 8px;
}
:root:root .path-filter-row > .path-filter[aria-pressed="true"] {
  color: var(--text);
  background: rgba(var(--accent-rgb), .12);
  border-color: rgba(var(--accent-rgb), .7);
}
:root:root .path-option[aria-pressed="true"] .path-option-name { color: var(--text); }
:root:root .compare-actions > button[aria-pressed="true"] {
  color: var(--text);
  background: rgba(var(--accent-rgb), .12);
  border-color: var(--accent);
}
:root:root .mw-steps button[aria-pressed="true"] { color: var(--text); }
:root:root .ad-demo .ad-config-button[aria-pressed="true"] strong { color: var(--text); }
:root:root .academic-result-highlight th[scope="row"] { color: var(--text); }

/* 2. One primary action per view: a light area-tinted fill and a firmer border,
      still glass, still rounded. Secondary buttons keep the neutral material. */
:root:root .button.primary {
  background: linear-gradient(145deg, rgba(var(--harmonized-rgb), .22), rgba(var(--harmonized-rgb), .1)), rgba(29, 36, 40, .5);
  border-color: rgba(var(--harmonized-rgb), .7);
  font-weight: 400;
}
:root:root .button.primary:is(:hover, :focus-visible) {
  background-color: rgba(var(--harmonized-rgb), .16);
  border-color: var(--harmonized-accent);
}

/* 3. Form fields: the 1px border now reaches at least 3:1 against the panel
      (WCAG 1.4.11). Hover, focus and invalid states keep their own colours. */
.contact-form :is(input:not([type="hidden"]), textarea):not(:hover):not(:focus-visible):not(:user-invalid) {
  border-color: rgba(202, 211, 215, .55);
}
.contact-form :is(input:not([type="hidden"]), textarea):hover { border-color: rgba(var(--accent-rgb), .8); }
@media (prefers-contrast: more) {
  .contact-form :is(input:not([type="hidden"]), textarea):not(:hover):not(:focus-visible):not(:user-invalid) {
    border-color: rgba(202, 211, 215, .85);
  }
}

/* 4. Light type stays for text of 15px and above. Below that, thin strokes on a
      dark ground read worse than their contrast ratio suggests, so small UI and
      metadata text uses the regular weight (Helvetica Neue / bundled Open Sans 400). */
:root:root :is(
  .button, .project-try, .text-link, .tag, kbd, figcaption, dt, dd, td,
  .footer-bottom, .footer-bottom a, .footer-bottom span, .motion-status,
  .contact-form-required, .contact-form-note, .contact-form-note a, .contact-form label,
  .contact-section-social > a, .portfolio-area-nav a, .pan-label,
  .navigation-dropdown-panel > a,
  .case-story aside a, .academic-story aside a,
  .project-meta span, .project-bottom span, .art-label, .lab-card-label, .case-demo-label,
  .portfolio-activity-meta, .publication-year, .publication-venue,
  .path-links a, .path-chronology-date, .path-option-name, .path-option-kind,
  .path-filter, .path-year, .path-bar-date, .path-milestone-label, .path-timeline-return,
  .academic-stack li, .academic-step-number, .academic-study-label, .academic-next-label,
  .mw-steps button, .mw-tile-name, .aw-steps button, .aw-legend span, .rw-steps button,
  .ad-topline span, .ad-metric-variation, .ad-stage-number, .ad-stage-button span, .ad-config-button span,
  .ph-area-action span, .demo-note, .compare-titlebar span, .compare-label, .drag-prompt,
  .compare-control, .compare-actions > button, [data-compare-boxes],
  /* page furniture */
  .ph-location span, .ph-lab-action span, .publication-award, .portfolio-area-note, .about-chips span, .about-intro,
  .path-slider-label label, .path-chart-note, .path-mobile-hint, .path-selection-header span,
  .path-detail-category, .path-detail-meta span, .process-list span, summary, summary span, caption,
  .academic-context, .academic-study-grid p, .workflow-demo-note, .guidance-demo label,
  /* demo controls and notes (all under 15px) */
  .aw-kicker, .aw-heading p, .aw-metadata-note, .aw-decision span, .aw-controls button, .aw-controls p,
  .mw-topline span, .mw-heading p, .mw-actions button, .mw-inspect-heading span, .mw-inspect p,
  .mw-stage p, .mw-stage-visual span, .mw-stage-actions button, .mw-stage-actions span, .mw-disclosure,
  .rw-topline span, .rw-panel-top span, .rw-empty span, .rw-panel-actions button, .rw-footer p, .rw-footer button, .rw-disclosure,
  .ad-source-note, .ad-example-control label, .ad-reference-note, .ad-selected-marker, .ad-disclosure,
  .ad-signal-legend span, .ad-range-heading label, .ad-range-heading output, .ad-control-note, .ad-stage-detail
):not(.simulation-reset) { font-weight: 400; }

/* 5. No text below 12px. */
:root:root :is(
  .about-chips span, .case-facts dt, .tag, .compare-titlebar, .compare-titlebar span,
  .compare-label, .drag-prompt, .compare-control output, .compare-secondary > .demo-note,
  [data-compare-boxes] span
) { font-size: .75rem; }
:root:root .compare-actions > button,
:root:root .compare-actions > button span { font-size: .8125rem; }

/* 6. Comfortable reading measure for long paragraphs (under 80 characters). */
:root:root :is(.case-story article > p, .story-copy > p, .academic-story-content p, .academic-insight > p, .academic-result-note,
  .publication-row p, .talk-row p, .research-highlight p, .portfolio-activity p, main li > p, .path-chronology-content > p,
  .ad-example-reading, .ad-stage-panel p) {
  max-width: 60ch; /* about 75–78 characters per line with this typeface */
}
:root .page-lead { max-width: 60ch; }

/* 7. Touch targets of at least 44 × 44px. */
:root:root .search-trigger { min-width: 44px; min-height: 44px; justify-content: center; }
:root:root .icon-button.close-dialog { width: 44px; height: 44px; }
:root:root .compare-actions > button { min-height: 44px; }
:root:root [data-compare-boxes] { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding-inline: 4px; }
:root:root .profile-actions .text-link { display: inline-flex; align-items: center; min-height: 44px; }
:root:root .site-header .brand { min-height: 44px; }
:root:root :is(.contact-section-social > a, .project-try, .footer-bottom a,
  .publication-links a, .research-highlight a.text-link, .portfolio-contribution-card a.text-link,
  .path-links a, .path-timeline-return) {
  display: inline-flex; align-items: center; min-height: 44px;
}
:root:root .project-try { display: flex; justify-content: center; }
/* Case-study side navigation: 44px by default (touch), a tighter 32px rhythm
   with a precise pointer (still above the 24px WCAG minimum). Kept in its own
   rules so both have the same specificity and the media query wins. */
:root:root :is(.case-story aside nav a, .academic-story aside nav a) {
  display: inline-flex; align-items: center; min-height: 44px;
}
@media (hover: hover) and (pointer: fine) {
  :root:root :is(.case-story aside nav a, .academic-story aside nav a) { min-height: 32px; }
}
:root:root :is(.aw-steps button, .aw-controls button, .workflow-transcript summary, .mw-reset, .mw-details summary,
  .mw-steps button, .mw-stage-actions button, .rw-steps button, .rw-reset, .path-year-range) { min-height: 44px; }

/* 9. Governance: the section heading now comes first in reading order;
      the project card keeps its place on the left. */
.portfolio-governance-card { order: -1; }

/* 10. About path: the selected year's list is no longer clipped in its own
       scroll box, and bar names stay visible when the chart scrolls sideways. */
:root:root .path-entry-options { max-height: none; overflow-y: visible; }
:root:root :is(.path-bar-name, .path-bar-date) { position: sticky; left: 10px; width: auto; max-width: 100%; }

/* 11. Reported-results tables on small screens: each configuration becomes a
       small card with labelled values, so no metric is hidden off-screen.
       Values, ± and notes are unchanged; ARIA roles in the markup keep the
       table semantics when the display changes. */
@media (max-width: 680px) {
  :is(.academic-results-table, .ad-table-scroll table) :is(thead) {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  :root:root :is(.academic-results-table, .ad-demo .ad-table-scroll table),
  :is(.academic-results-table, .ad-table-scroll table) :is(caption, tbody, tr, th, td) { display: block; width: 100%; min-width: 0; }
  :is(.academic-results-table, .ad-table-scroll table) tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; padding: 16px 14px; }
  :is(.academic-results-table, .ad-table-scroll table) th[scope="row"] { grid-column: 1 / -1; min-width: 0; padding: 0; }
  :is(.academic-results-table, .ad-table-scroll table) td { padding: 0; white-space: normal; }
  :is(.academic-results-table, .ad-table-scroll table) td::before {
    content: attr(data-label); display: block; color: var(--muted); font-size: .75rem; line-height: 1.5;
  }
  /* The help text is the table's accessible description: on small screens it
     describes the card layout instead of suggesting a scroll that is no longer needed.
     The hidden alternative is display:none, so it is left out of the description. */
  :root .academic-table-help .table-help-wide { display: none; }
  :root :is(.academic-table-wrap, .ad-table-scroll) { overflow-x: visible; }
}
.academic-table-help .table-help-narrow { display: none; }
@media (max-width: 680px) {
  :root .academic-table-help .table-help-narrow { display: inline; }
}

/* 12. Responsive images: <picture> wrappers do not add a layout box, so the
       images keep their existing sizing (the one direct-child rule,
       `.ph-portrait-stage > img`, also matches `> picture > img`). */
.responsive-picture { display: contents; }

/* 13. Personal contribution (phase 4).
       Cards: a small "My role" label above the role sentence.
       Case studies: "My contribution." as the first section, a short labelled list. */
.project-card .project-role { margin: 0; }
.project-card .project-role-label {
  display: block; margin-bottom: 4px;
  color: var(--accent); font-size: .75rem; font-weight: 400; line-height: 1.5;
}
.case-contribution .contribution-list { display: grid; gap: 18px; margin: 22px 0 0; max-width: 60ch; }
.case-contribution .contribution-list > div { padding-top: 16px; border-top: 1px solid var(--line); }
.case-contribution .contribution-list dt { margin: 0 0 4px; color: var(--accent); font-size: .8125rem; font-weight: 400; line-height: 1.5; }
:root:root .case-contribution .contribution-list dd { margin: 0; color: var(--text); font-size: 1rem; font-weight: 300; line-height: 1.75; } /* 16px body text keeps the light weight */

/* 14. Mammography demo on small screens: the tile label (and, once organised,
       the result) sit in a header row above the schematic instead of on top of it. */
@media (max-width: 680px) {
  :root:root .mw-tile { display: grid; grid-template-rows: 28px minmax(0, 1fr); height: 118px; }
  :root:root .mw-tile-name { position: static; padding: 6px 8px 0; }
  :root:root .mw-tile-result { top: 4px; bottom: auto; right: 6px; padding: 1px 6px; }
  :root:root .mw-tile svg { height: 100%; min-height: 0; }
}

/* 15. Comparison slider: the image handles pointer drags (interactions.js);
       the transparent native range stays for keyboard and screen readers only. */
:root:root .compare-image input.compare-range { pointer-events: none; }
:root:root .comparison-v2 .compare-image { cursor: ew-resize; touch-action: pan-y; }

/* 16. Fewer nested frames. Inside an already framed demo, purely decorative
       inner boxes become open groups separated by thin rules; the grouping
       (context fields, the four metrics, the signal snapshot) is kept. */
:root:root .rw-context { padding-block: 10px; border-block: 1px solid var(--line); }
:root:root .rw-context > div { padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
:root:root .ad-demo .ad-metric { padding: 10px 0 0; border: 0; border-top: 1px solid rgba(var(--accent-rgb), .3); border-radius: 0; background: none; box-shadow: none; }
:root:root .ad-demo .ad-snapshot { padding: 16px 0 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: none; box-shadow: none; }

/* Final review: accessible links, comfortable form focus and native image detail. */
:root:root .academic-source-figure a.text-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
@media (hover: none), (pointer: coarse), (max-width: 680px) {
  :root:root .academic-case button { min-height: 44px; }
}
.contact-form textarea { scroll-margin-block: 120px; }
.case-cover img[src$="/ultrasound-kidney.jpg"] {
  max-width: 748px;
  height: auto;
  margin-inline: auto;
}

/* The original rounded corner controls share one compact surface. */
.atmosphere {
  position: fixed;
  inset-inline-end: max(28px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 4px 12px;
  border: 1px solid rgba(var(--accent-rgb), .28);
  border-radius: 30px;
  background: rgba(29, 36, 40, .94);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 8px 30px #0004;
}
.atmosphere-title { margin-inline-end: 4px; color: var(--muted); font-size: .8125rem; }
.atmosphere :is(.dock-tour, .motion-toggle) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--text);
  font: 400 .8125rem/1.5 var(--sans);
  white-space: nowrap;
}
.atmosphere :is(.dock-tour, .motion-toggle):hover { background: rgba(var(--accent-rgb), .08); }
.atmosphere :is(.dock-tour, .motion-toggle):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.atmosphere .icon { width: 17px; height: 17px; color: var(--accent); }
.dock-divider { align-self: center; width: 1px; height: 22px; background: var(--line); }
.dock-motion { min-width: 0; }
.dock-motion .motion-status:not(.sr-only) { max-width: 190px; margin: 0; color: var(--muted); font: 400 .75rem/1.4 var(--sans); }
html { scroll-padding-bottom: 88px; }
@media (max-width: 680px) {
  .atmosphere { inset-inline-end: 16px; bottom: max(16px, env(safe-area-inset-bottom)); gap: 6px; padding-inline: 10px; }
  .atmosphere-title { display: none; }
  .dock-motion .motion-status:not(.sr-only) { max-width: 170px; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .atmosphere { background: var(--panel-solid); backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* Reset actions share a darker fill and bold label across project simulations. */
:root:root button.simulation-reset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid rgba(var(--accent-rgb), .28);
  border-radius: 13px;
  background: #151b1e;
  color: var(--text);
  font: 700 .875rem/1.5 var(--sans);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
:root:root button.simulation-reset:is(:hover, :active, :focus-visible) {
  background: #202a2f;
  border-color: rgba(var(--accent-rgb), .6);
  color: var(--text);
}
:root:root button.simulation-reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
@media (forced-colors: active) {
  :root:root button.simulation-reset,
  :root:root button.simulation-reset:is(:hover, :active, :focus-visible) { background: ButtonFace; color: ButtonText; border-color: ButtonText; }
}
