/* css/sections/05-anatomy.css · v2 · the machine-parts render as one large plate, six numbered brass hairline leaders,
   a narrow spotlight that jumps from part to part. Default (phone, reduced motion, no JS): every leader drawn, no dimming.
   Desktop with motion (≥64em, ≥700px tall): a sticky stage over a runway; the scroll walks the six parts in list order. */
@property --an-sx { syntax: "<percentage>"; inherits: true; initial-value: 50%; }
@property --an-sy { syntax: "<percentage>"; inherits: true; initial-value: 40%; }

@layer sections {
  .s-anatomy {
    --an-hair: 2.4;                               /* leader width in photo units (800 wide): about 1 px on screen */
    --an-num-r: 30px;
    --an-num-t: 34px;
    --an-mech: cubic-bezier(.77, 0, .18, 1);
    --an-expo: cubic-bezier(.16, 1, .3, 1);
    position: relative;
    padding-block: var(--gap-b) var(--gap-c);
  }

  .anatomy__stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: var(--space-xl);
    align-content: start;
  }

  /* head: a brass folio over the serif title */
  .anatomy__head { min-width: 0; }
  .anatomy__folio {
    margin-block-end: var(--space-sm);
    font: 400 var(--text-sm)/1 var(--font-body);
    font-variant-numeric: tabular-nums lining-nums;
    color: var(--color-brass);
  }
  .s-anatomy .anatomy__title {
    max-width: 12ch;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: var(--text-section-calm);
    line-height: .94;
    letter-spacing: -0.02em;
    color: var(--color-ink);
  }
  .s-anatomy .anatomy__title em { font-style: italic; color: var(--color-brass-hi); }

  /* the plate */
  .anatomy__plate { margin: 0; min-width: 0; display: grid; gap: var(--space-md); justify-items: center; }
  .anatomy__frame {
    position: relative;
    inline-size: 100%;
    aspect-ratio: 5 / 7;
    container-type: inline-size;
    isolation: isolate;
    overflow: hidden;
  }
  .anatomy__photo, .anatomy__photo img { display: block; inline-size: 100%; block-size: 100%; }
  .anatomy__photo img { object-fit: cover; }
  /* feather the photo into the black: no hard edge (the leaders stay crisp above it) */
  .anatomy__photo, .anatomy__spot {
    -webkit-mask-image: radial-gradient(ellipse 54% 52% at 50% 48%, var(--mask-ink) 70%, transparent 100%);
            mask-image: radial-gradient(ellipse 54% 52% at 50% 48%, var(--mask-ink) 70%, transparent 100%);
  }

  /* the narrow spotlight: everything outside a small circle steps back into the black */
  .anatomy__spot {
    --an-r: 11cqw;
    position: absolute; inset: 0;
    pointer-events: none;
    background:
      radial-gradient(circle at var(--an-sx) var(--an-sy), rgba(var(--beam-rgb), .10) 0, transparent var(--an-r)),
      radial-gradient(circle at var(--an-sx) var(--an-sy), transparent 0, transparent var(--an-r), color-mix(in srgb, var(--color-stage) 82%, transparent) calc(var(--an-r) * 2.1));
    opacity: 0;
    transition: opacity .6s var(--an-expo), --an-sx .7s var(--an-mech), --an-sy .7s var(--an-mech);
  }
  .s-anatomy[data-active] .anatomy__spot { opacity: 1; }

  /* leaders, in the photo's own space */
  .anatomy__leaders { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; overflow: visible; }
  .an-lead__line {
    fill: none; stroke: var(--color-brass); stroke-width: var(--an-hair); stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 1; stroke-dashoffset: 0;
    transition: stroke-dashoffset .9s var(--an-mech), stroke .3s ease, opacity .3s ease;
  }
  .an-lead__dot { fill: var(--color-brass-hi); transform-box: fill-box; transform-origin: center; transition: transform .4s var(--an-expo), opacity .3s ease; }
  .an-lead__ring { fill: none; stroke: var(--color-brass); stroke-width: var(--an-hair); stroke-dasharray: 4 7; opacity: .9;
                   transform-box: fill-box; transform-origin: center; transition: transform .5s var(--an-expo), opacity .3s ease, stroke .3s ease; }
  .an-lead__num { transform-box: fill-box; transform-origin: center; transition: opacity .4s ease, transform .5s var(--an-expo); }
  .an-lead__num circle { r: var(--an-num-r); fill: color-mix(in srgb, var(--color-stage) 82%, transparent); stroke: var(--color-brass); stroke-width: var(--an-hair); transition: fill .3s ease, stroke .3s ease; }
  .an-lead__num text {
    font: italic 400 var(--an-num-t)/1 var(--font-display);
    fill: var(--color-brass-hi); text-anchor: middle; dominant-baseline: central;
    font-variant-numeric: lining-nums;
    transition: fill .3s ease;
  }

  /* before the walk reaches a part (motion only), its leader is undrawn and its numeral waits */
  :where(.anim .s-anatomy.is-motion) .an-lead:not(.is-drawn) .an-lead__line { stroke-dashoffset: 1; }
  :where(.anim .s-anatomy.is-motion) .an-lead:not(.is-drawn) :is(.an-lead__num, .an-lead__dot, .an-lead__ring) { opacity: 0; transform: scale(.6); }

  /* one part in the light: its leader brightens and draws even if the walk has not reached it (hover, focus) */
  .s-anatomy[data-active] .an-lead { opacity: .5; transition: opacity .3s ease; }
  :is([data-active="e61"] .an-lead[data-part="e61"], [data-active="flow"] .an-lead[data-part="flow"],
      [data-active="gauges"] .an-lead[data-part="gauges"], [data-active="boilers"] .an-lead[data-part="boilers"],
      [data-active="pump"] .an-lead[data-part="pump"], [data-active="handle"] .an-lead[data-part="handle"]) {
    &.an-lead { opacity: 1; }
    .an-lead__line { stroke: var(--color-brass-hi); stroke-dashoffset: 0; }
    :is(.an-lead__num, .an-lead__dot, .an-lead__ring) { opacity: 1; transform: none; }
    .an-lead__ring { stroke: var(--color-brass-hi); }
    .an-lead__num circle { fill: var(--color-brass); stroke: var(--color-brass-hi); }
    .an-lead__num text { fill: var(--color-accent-ink); }
  }

  /* the index: six numbered entries on hairlines */
  .anatomy__index { min-width: 0; }
  .anatomy__parts { list-style: none; margin: 0; padding: 0; display: grid; }
  .anatomy__part {
    position: relative;
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr);
    column-gap: var(--space-sm);
    row-gap: var(--space-3xs);
    padding-block: var(--space-sm) var(--space-md);
    border-block-start: 1px solid var(--color-rule);
  }
  .anatomy__part::before {                       /* a brass hairline that runs across the active entry */
    content: ""; position: absolute; inset-inline: 0; inset-block-start: -1px; block-size: 1px;
    background: var(--color-brass);
    transform: scaleX(0); transform-origin: left center;
    transition: transform .7s var(--an-mech);
  }
  .anatomy__n {
    grid-row: 1 / span 2;
    font: italic 400 1.5rem/1.2 var(--font-display);
    font-variant-numeric: lining-nums;
    color: var(--color-brass);
    transition: color .3s ease;
  }
  .s-anatomy .anatomy__label {
    justify-self: start;
    font: 400 clamp(1.375rem, 1.1rem + .8vw, 1.75rem)/1.2 var(--font-display);
    letter-spacing: -0.01em;
    color: var(--color-ink);
    text-decoration: none;
    transition: color .3s ease;
  }
  .s-anatomy a.anatomy__label:focus-visible { outline: var(--focus-w) solid var(--color-focus); outline-offset: 4px; }
  .anatomy__text { font: 400 var(--text-body)/1.5 var(--font-body); color: var(--color-ink-2); max-width: 44ch; }
  .anatomy__more { margin-block-start: var(--space-lg); font: 400 var(--text-body)/1.4 var(--font-body); }

  :is([data-active="e61"] .anatomy__part[data-part="e61"], [data-active="flow"] .anatomy__part[data-part="flow"],
      [data-active="gauges"] .anatomy__part[data-part="gauges"], [data-active="boilers"] .anatomy__part[data-part="boilers"],
      [data-active="pump"] .anatomy__part[data-part="pump"], [data-active="handle"] .anatomy__part[data-part="handle"]) {
    &::before { transform: none; }
    .anatomy__n, .anatomy__label { color: var(--color-brass-hi); }
  }

  /* the footnote: print style, under a short hairline */
  .anatomy__foot {
    justify-self: start;
    max-width: 46ch;
    padding-block-start: var(--space-xs);
    border-block-start: 1px solid var(--color-rule);
    font: 400 var(--text-sm)/1.45 var(--font-body);
    color: var(--color-ink-2);
  }
  .anatomy__mark { margin-inline-end: .2em; font-family: var(--font-display); color: var(--color-brass); }

  @media (min-width: 30em) and (max-width: 63.99em) {
    .s-anatomy { --an-hair: 1.8; --an-num-r: 26px; --an-num-t: 30px; }
    .anatomy__plate { max-inline-size: 34rem; justify-self: center; }
  }

  @media (min-width: 64em) {
    .s-anatomy { --an-hair: 1.5; --an-num-r: 22px; --an-num-t: 26px; }
    .anatomy__stage {
      grid-template-columns: repeat(12, minmax(0, 1fr));
      grid-template-rows: auto 1fr;
      column-gap: var(--gap-columns);
      row-gap: var(--space-lg);
    }
    .anatomy__stage { padding-block: calc(var(--header-h) + var(--space-lg)) var(--space-lg); }
    .anatomy__head { grid-column: 1 / span 6; grid-row: 1; }
    .anatomy__index { grid-column: 1 / span 6; grid-row: 2; align-self: start; }
    .anatomy__part { padding-block: var(--space-xs) var(--space-sm); }
    .anatomy__text { max-width: none; }
    .s-anatomy .anatomy__label { font-size: clamp(1.375rem, .9rem + .7vw, 1.625rem); }
    .anatomy__plate { grid-column: 7 / -1; grid-row: 1 / span 2; align-self: center; }
    .anatomy__frame { inline-size: min(100%, calc((100svh - var(--header-h) - 10.5rem) * 5 / 7)); }
    .anatomy__plate { gap: var(--space-sm); }
  }

  /* desktop with motion, when the whole stage fits the screen (js adds .is-sticky): the stage holds while the runway scrolls */
  @media (min-width: 64em) {
    .s-anatomy.is-sticky { padding-block: var(--gap-c) 0; }
    .s-anatomy.is-sticky .anatomy__runway { block-size: calc(100svh + 170svh); }
    .s-anatomy.is-sticky .anatomy__stage {
      position: sticky; inset-block-start: 0;
      block-size: 100svh;
      align-content: center;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .anatomy__spot, .an-lead__line, .anatomy__part::before { transition: none; }
  }
  @media (forced-colors: active) {
    .an-lead__line, .an-lead__ring, .an-lead__num circle { stroke: CanvasText; }
    .an-lead__num text, .an-lead__dot { fill: CanvasText; }
    .anatomy__spot { display: none; }
  }
}
