/* ---------- Joint drawings (src/joints.ts, JointArt.astro) ----------
   Phones: the drawing has its own full-width band between the title and the words. Desktop: whole and centered
   beside the words. Each drawing names its frame (--fx --fy --fw --fh, in its own units); the frame is fitted to
   the box and centered, whatever the drawing's shape. Soft edge fades are inside the SVG, so they never touch the label. */
.masthead.has-joint .col > .joint { position: relative; margin: 0; overflow: hidden; container-type: size; }
.joint-art {
  --u: min(100cqh / var(--fh), 100cqw / var(--fw));
  position: absolute; display: block; overflow: visible; width: auto; height: calc(var(--u) * var(--vh));
  top: calc(50cqh - (var(--fy) + var(--fh) / 2 - var(--vy)) * var(--u));
  left: calc(50cqw - (var(--fx) + var(--fw) / 2 - var(--vx)) * var(--u));
}
@media (width <= 899px) {
  .masthead.has-joint .col > .joint { height: 84vw; margin: 20px calc(-1 * var(--pad)) 22px; }
}
@media (width >= 900px) {
  .masthead.has-joint .col {
    display: grid; width: 100%; grid-template-columns: minmax(0, 1fr) clamp(340px, 34vw, 500px);
    grid-template-rows: 1fr auto auto 1fr; column-gap: clamp(32px, 5vw, 80px);
  }
  .masthead.has-joint .copy-top { grid-column: 1; grid-row: 2; max-width: 44rem; }
  .masthead.has-joint .copy-bottom { grid-column: 1; grid-row: 3; max-width: 44rem; }
  .masthead.has-joint .col > .joint { grid-column: 2; grid-row: 1 / -1; align-self: center; height: clamp(360px, 31vw, 460px); }
  /* Every drawing starts the same distance from the words: its visible left edge (--ix, measured from the render)
     sits just inside the box, instead of the frame being centered (Joel, Nov 6: the hip felt "super far away" from
     the title, about 250px off where the elbow sat about 100px off). */
  .masthead.has-joint .col > .joint .joint-art { left: calc(clamp(0px, 1.5vw, 28px) + (var(--vx) - var(--ix)) * var(--u)); }
}

/* One line style and palette for every joint: soft-dark lines, faint fills, the lit part in sky. A part with one
   paint (a line, a fill) carries its strength as stroke-opacity or fill-opacity, never opacity: the picture is the
   same, but opacity makes the browser paint each part off screen first, and with 60 to 90 such parts a frame of the
   drawing-in cost Safari three to four times as much (Joel, Nov 11: the drawings "feel slightly glitchy"). Only the
   few parts with both a fill and an outline (.lf, .lf2, .bone) and the glow still use opacity. */
.joint-art .ln { fill: none; stroke: var(--soft-dark); stroke-width: var(--sw); stroke-linecap: round; stroke-linejoin: round; stroke-opacity: 0.72; }
.joint-art .bone { fill: rgb(201 217 230 / 0.07); stroke: var(--soft-dark); stroke-width: calc(var(--sw) * 1.3); stroke-linejoin: round; }
.joint-art :is(.lf, .lf2) { fill: var(--soft-dark); stroke: var(--soft-dark); stroke-width: calc(var(--sw) * 0.3); stroke-linejoin: round; }
.joint-art .lf { opacity: 0.85; }
.joint-art .lf2 { opacity: 0.45; }
.joint-art .fb { fill: var(--soft-dark); fill-opacity: 0.3; }
.joint-art .bf { fill: rgb(201 217 230 / 0.08); }
.joint-art .bf2 { fill: rgb(201 217 230 / 0.04); }
.joint-art .tissue { fill: rgb(81 145 196 / 0.14); }
.joint-art .cart { fill: rgb(81 145 196 / 0.22); }
.joint-art .hi-fill { fill: var(--sky); }
.joint-art .hi-ln { stroke: #fff; stroke-opacity: 0.95; }
.joint-art .hi-glow { fill: var(--sky); opacity: 0.85; }
.joint-art .hi-fb { fill: #fff; fill-opacity: 0.5; }
.joint-art .ol { stroke-width: calc(var(--sw) * 1.6); stroke-opacity: 0.8; }
.joint-art .tag-ln { fill: none; stroke: #fff; stroke-width: var(--sw); stroke-opacity: 0.9; }
.joint-art .tag-dot { fill: #fff; }
.joint-art .tag-tx { fill: #fff; font-weight: 700; font-family: inherit; letter-spacing: 0.08em; }

/* The drawing-in. The script adds .play (and .hold until the drawing is on screen). Text and the label never fade:
   the label rises from behind a mask, like the headline words. The part lights at 2.1s and its name is in by 3.8s
   (Joel, Nov 11: "waiting a little too long" for the name, which used to be in at 5.25s). */
.joint.hold * { animation-play-state: paused !important; }
/* Until the script starts it, the drawing waits unseen, so the finished drawing never flashes first. If the script
   never runs, it shows after two seconds. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  .joint:not(.play, .done) .joint-art { animation: j-show 0s 2s both; }
}
@keyframes j-show { from { visibility: hidden; } }
@media (prefers-reduced-motion: no-preference) {
  .joint.play :is(.ln, .bone, .lf, .lf2) { stroke-dasharray: var(--len) var(--len); stroke-dashoffset: var(--len); animation: j-draw 2.6s cubic-bezier(0.33, 0, 0.2, 1) var(--d, 0s) both; }
  .joint.play .bone { animation: j-draw 2.6s cubic-bezier(0.33, 0, 0.2, 1) 0s both, j-ink 1.6s ease 1.3s both; }
  .joint.play :is(.lf, .lf2) { animation: j-draw 2.4s cubic-bezier(0.33, 0, 0.2, 1) var(--d, 0s) both, j-fillo 1s ease calc(var(--d, 0s) + 1.3s) both; }
  .joint.play :is(.fb, .bf, .bf2, .tissue, .cart) { animation: j-fillo 1.6s ease 1.2s both; }
  .joint.play .hi-fill { animation: j-fillo 1.4s ease 1.2s both, j-lit 1.4s cubic-bezier(0.33, 0, 0.2, 1) 2.1s both; }
  .joint.play .hi-ln { animation: j-draw 2.6s cubic-bezier(0.33, 0, 0.2, 1) var(--d, 0s) both, j-litln 1.4s ease 2.1s both; }
  .joint.play .hi-glow { animation: j-fade 1.6s cubic-bezier(0.33, 0, 0.2, 1) 2.1s both; }
  .joint.play .hi-fb { animation: j-fillo 1.4s ease 2.1s both; }
  .joint.play .tag-dot { animation: j-pop 0.6s cubic-bezier(0.33, 0, 0.2, 1) 2.5s both; transform-box: fill-box; transform-origin: center; }
  .joint.play .tag-ln { stroke-dasharray: var(--len) var(--len); stroke-dashoffset: var(--len); animation: j-draw 0.8s cubic-bezier(0.33, 0, 0.2, 1) 2.6s both; }
  .joint.play .tag-tx { animation: j-rise 0.8s var(--ease-reveal) 3s both; }
}
@keyframes j-draw { to { stroke-dashoffset: 0; } }
@keyframes j-fade { from { opacity: 0; } }
@keyframes j-fillo { from { fill-opacity: 0; } }
@keyframes j-ink { from { fill-opacity: 0; stroke-opacity: 0; } }
@keyframes j-lit { from { fill: rgb(81 145 196 / 0.2); } }
@keyframes j-litln { from { stroke: var(--soft-dark); stroke-opacity: 0.72; } }
@keyframes j-pop { from { transform: scale(0); } }
@keyframes j-rise { from { transform: translateY(0.8em); clip-path: inset(0 0 100% 0); } to { clip-path: inset(-20% 0 -20% 0); } }

/* After the drawing-in (Joel, Nov 11: "more interactivity with these visuals", then "you don't really know to click
   it"). Nothing to find or tap: the script swaps .play for .done, and from then on the lit part pulses by itself while
   it's on screen. It brightens and its glow swells, and a ring opens from the label's dot (the script adds the ring).
   On a desktop, pointing at the drawing also quiets everything but the lit part (.focus). The drawing-in is untouched. */
.joint-art .tag-ring { fill: none; stroke: #fff; stroke-width: 1.25px; vector-effect: non-scaling-stroke; opacity: 0; transform-box: fill-box; transform-origin: center; }
@media (prefers-reduced-motion: no-preference) {
  .joint.done .hi-fill { animation: j-pulse 4s ease-in-out infinite; }
  .joint.done .hi-glow { animation: j-breathe 4s ease-in-out infinite; }
  .joint.done .tag-ring { animation: j-ring 4s cubic-bezier(0.2, 0.6, 0.3, 1) infinite; }
  .joint.done.away :is(.hi-fill, .hi-glow, .tag-ring) { animation-play-state: paused; }
  .joint .art :is(.ln, .bone, .lf, .lf2, .fb, .bf, .bf2, .tissue, .cart) { transition: 0.6s cubic-bezier(0.33, 0, 0.2, 1); transition-property: opacity, fill-opacity, stroke-opacity; }
  .joint.done.focus .art .ln:not(.hi-ln) { stroke-opacity: 0.3; }
  .joint.done.focus .art .bone { opacity: 0.42; }
  .joint.done.focus .art :is(.bf, .bf2, .tissue, .cart) { fill-opacity: 0.42; }
  .joint.done.focus .art .lf { opacity: 0.36; }
  .joint.done.focus .art .lf2 { opacity: 0.2; }
  .joint.done.focus .art .fb { fill-opacity: 0.13; }
}
@keyframes j-pulse { 35% { fill: #a3cdf0; } 75% { fill: var(--sky); } }
@keyframes j-breathe { 35% { opacity: 1; } 75% { opacity: 0.4; } }
@keyframes j-ring { from { transform: scale(1); opacity: 0.9; } 60%, to { transform: scale(4.2); opacity: 0; } }

/* Each drawing's frame and label size, from build_svg.py. */
.joint-art.j-elbow-ucl { --sw: 0.625; --fx: 140; --fy: 112; --fw: 215; --fh: 220; --vx: 0; --vy: 0; --vh: 400; --ix: 133.8; }
.j-elbow-ucl .tag-tx { font-size: 10px; }
.joint-art.j-hip-labrum { --sw: 1.091; --fx: 45; --fy: 8; --fw: 300; --fh: 384; --vx: 0; --vy: 0; --vh: 400; --ix: 103.7; }
.j-hip-labrum .tag-tx { font-size: 17.5px; }
.joint-art.j-knee-acl { --sw: 1.7; --fx: 186; --fy: 70; --fw: 492; --fh: 620; --vx: 0; --vy: 0; --vh: 729; --ix: 188; }
.j-knee-acl .tag-tx { font-size: 28.2px; }
.joint-art.j-knee-meniscus { --sw: 1.7; --fx: 186; --fy: 70; --fw: 560; --fh: 620; --vx: 0; --vy: 0; --vh: 729; --ix: 188.7; }
.j-knee-meniscus .tag-tx { font-size: 28.2px; }
.joint-art.j-shoulder-cuff { --sw: 1.051; --fx: 45; --fy: -2; --fw: 320; --fh: 370; --vx: 0; --vy: -2; --vh: 402; --ix: 55.5; }
.j-shoulder-cuff .tag-tx { font-size: 16.8px; }
.joint-art.j-shoulder-labrum { --sw: 1.051; --fx: 45; --fy: -2; --fw: 320; --fh: 370; --vx: 0; --vy: -2; --vh: 402; --ix: 55.5; }
.j-shoulder-labrum .tag-tx { font-size: 16.8px; }


/* Home specialty cards (Joel, Nov 5): the finished drawing fills the navy panel, no label (the card's title names it).
   Hover keeps the panel navy and lifts the drawing a little, with the lit part brighter. This file loads ahead of the
   site's own styles, so the two rules that overrule a plain card panel name it twice (.panel.joint-panel). */
.spec-card .panel.joint-panel { position: relative; padding: 0; container-type: size; }
.joint-panel .joint-art { transition: transform 0.5s cubic-bezier(0.33, 0, 0.2, 1); }
.joint-panel .tag { display: none; }
.spec-card:hover .panel.joint-panel { background: var(--navy); }
.spec-card:hover .joint-panel .joint-art { transform: scale(1.04); }
.joint-panel .hi-glow { transition: opacity 0.5s ease; }
.spec-card:hover .joint-panel .hi-glow { opacity: 1; }
.joint-art.j-prp-syringe { --sw: 1.3; --fx: 0; --fy: 15; --fw: 200; --fh: 170; --vx: 0; --vy: 0; --vh: 200; }
/* On the cards there's no label, so each drawing gets a frame centered on the joint itself (measured from the
   rendered cards: the page-top frames, which leave room for a label, sat 6 to 11% left of center). The shoulder was
   measured again on Nov 6, after its lower edge started fading out. */
:is(.joint-panel, .cb-art) :is(.j-shoulder-cuff, .j-shoulder-labrum) { --fx: 33; --fw: 280; --fy: -30; --fh: 404; }
:is(.joint-panel, .cb-art) .j-elbow-ucl { --fx: 104.5; --fw: 200; }
:is(.joint-panel, .cb-art) :is(.j-knee-acl, .j-knee-meniscus) { --fx: 105; --fw: 560; }
.joint-panel .j-prp-syringe { --fx: -15; --fw: 230; --fy: -5; --fh: 210; }

/* Phones: the title bar that stays in view (the drawing's script moves it to just after the site header and turns it on
   once the title has scrolled under the header). The live build's cleanup keeps any file a stylesheet names, so the
   script's file name stays out of these comments. Sticky like the header; the negative margin keeps it from taking space.
   Frosted like the header bars on Apple's product pages; it slides out from under the site header and back. */
.context-bar { display: none; }
@media (width <= 999px) {
  .context-bar {
    position: sticky; top: 68px; z-index: 25; margin-bottom: -52px; display: flex; align-items: center; justify-content: space-between; gap: 14px;
    height: 52px; padding: 0 var(--pad); background: rgb(246 248 250 / 0.95); -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
    border-bottom: 1px solid var(--rule); transform: translateY(-100%); visibility: hidden;
    transition: transform 0.35s cubic-bezier(0.33, 0, 0.2, 1), visibility 0s linear 0.35s;
  }
  .context-bar.on { transform: none; visibility: visible; transition: transform 0.35s cubic-bezier(0.33, 0, 0.2, 1), visibility 0s; }
  .context-bar .cb-title { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 1.0625rem; font-weight: 650; letter-spacing: -0.01em; color: var(--ink); }
  .context-bar .cb-art { flex: none; position: relative; width: 58px; height: 40px; overflow: hidden; border-radius: 8px; background: var(--navy); container-type: size; }
  .context-bar .cb-art .tag { display: none; }
  body:has(.menu-toggle[open]) .context-bar { display: none; }
}
@media (prefers-reduced-motion: reduce) { .context-bar { transition: none !important; } }
