/* ==========================================================================
   The clothes-rack demo in /writing/clothes-rack-hover-animation-ecommerce.html.
   Loads after article.css. A shop's light stage inside the post: a straight
   rail, and on it tees hanging side-on that turn to face you on hover. The
   rail scrolls sideways; rack-demo.js swings each tee from its hook as the
   rail speeds up and slows down.

   Every tee is the same three cut-outs of one white mockup (front, side,
   back), tinted per colourway: a solid --cloth masked to the shirt's shape,
   with the white photo multiplied over it for the folds. The front and back
   sit on one plane, the two sides on a second plane crossing it at the
   axis; --fw and --sw crossfade them as the tee turns, overlapping so the
   shirt is never see-through. Without JS, or with reduced
   motion, the CSS turn below is the whole effect.
   ========================================================================== */

/* Registered so the CSS-only turn can transition the crossfade too.
   --fw: front/back opacity; --sw: side opacity. */
@property --fw { syntax: "<number>"; inherits: true; initial-value: 0; }
@property --sw { syntax: "<number>"; inherits: true; initial-value: 1; }

.prose .rack { --w: clamp(124px, 32vw, 150px); --pad: 18px; position: relative; margin-top: 2em; padding: var(--space-xl) 0 var(--space-lg); border: 1px solid; border-color: var(--edge-glass); border-radius: var(--radius-card); background: linear-gradient(180deg, #FFFFFF 0%, #F6F7F9 70%, #EEF0F3 100%); box-shadow: var(--glow-inset); overflow: hidden; }
.rack__defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* The shop's own header, so the stage reads as a storefront, not a widget */
.rack__head { display: grid; justify-items: center; gap: var(--space-xs); padding-inline: var(--space-lg); text-align: center; }
.prose .rack__eyebrow { margin: 0; font-size: var(--text-xs); font-weight: 600; line-height: 1.4; color: #5B6470; }
.rack__eyebrow span { margin-inline: 0.6em; color: #C2C7CE; }
.prose .rack__title { margin: 0; font-size: clamp(30px, 5vw, 46px); font-weight: 600; line-height: 1.04; letter-spacing: -0.04em; color: #15181D; }
.rack__title span { color: #8C939C; }

/* The rail stays put; the row of tees scrolls along it. The hook's bend
   sits 6/120 of a tee's width below its top, so the rail does too. */
.rack__floor { position: relative; margin-top: var(--space-lg); }
.rack__rail { position: absolute; left: 0; right: 0; top: calc(var(--pad) + var(--w) * 6 / 120 - 2.5px); z-index: 0; height: 5px; border-radius: 3px; background: linear-gradient(180deg, #B6BBC2, #8E949C); box-shadow: 0 2px 2px rgba(20, 24, 30, 0.16); }
/* With the script running, the rail becomes a shallow arch (rack-demo.js
   draws it to the floor's size) and each hook is lowered to meet it. */
.rack__arch { position: absolute; top: 0; left: 0; z-index: 0; width: 100%; overflow: visible; pointer-events: none; }
.rack__arch path { fill: none; stroke: #9AA0A8; stroke-width: 5px; stroke-linecap: round; filter: drop-shadow(0 2px 1px rgba(20, 24, 30, 0.18)); }
.rack.is-arched .rack__rail { visibility: hidden; }
.prose .rack__scroll { position: relative; z-index: 1; margin: 0; padding: var(--pad) 0 var(--space-lg); overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
.rack__scroll::-webkit-scrollbar { display: none; }
.rack__scroll:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; }
.rack.is-dragging .rack__scroll { cursor: grabbing; }
.prose .rack__list { display: flex; gap: 0; width: max-content; margin: 0; padding: 0 calc(var(--w) * 0.5); list-style: none; }
/* Side-on, a tee is two fifths of its card wide, so the cards overlap; the
   one turned towards you comes forward. */
.prose .rack .rack__item { position: relative; flex: none; width: var(--w); margin: 0 calc(var(--w) * -0.2); color: var(--cloth); }
.rack__item:hover, .rack__item:focus-within, .rack__item.is-pinned { z-index: 2; }
.rack__item::marker { content: none; }

/* One tee. The card ignores the pointer; only .hanger__hit, the width of
   the tee as it hangs, picks it up, and it widens to the whole shirt once
   the tee has turned, so a sleeve does not drop the hover. */
.hanger { position: relative; display: block; width: 100%; aspect-ratio: 120 / 160; margin: 0; padding: 0; border: 0; border-radius: var(--radius-sm); background: none; color: inherit; cursor: inherit; pointer-events: none; -webkit-tap-highlight-color: transparent; }
.hanger:focus { outline: none; }
.hanger:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 4px; }
.hanger__hit { position: absolute; z-index: 3; top: 4%; bottom: 6%; left: 30%; width: 40%; pointer-events: auto; }
.rack__item:hover .hanger__hit, .rack__item.is-pinned .hanger__hit { left: 3%; width: 94%; }

/* The swing hangs from the top of the hook's bend and carries the hook, the
   tee and the tag; inside it, the tee alone turns about a vertical axis
   through the neck. */
.hanger__swing { position: absolute; inset: 0; transform-origin: 50% 2%; perspective: 640px; perspective-origin: 50% 25%; }
.hanger__hook, .hanger__tag { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
/* No filter, opacity, overflow or mask on the spin: any of them flattens the
   3D context. The swing stays flat on purpose, so the tag paints over the
   tee instead of cutting through it. */
.hanger__spin { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 50% 14%; transform: rotateY(var(--rest)); }
.face { position: absolute; left: 2.5%; top: 12.5%; width: 95%; height: 80.25%; isolation: isolate; backface-visibility: hidden; -webkit-backface-visibility: hidden; filter: drop-shadow(0 12px 10px rgba(20, 24, 30, 0.12)); }
.face > * { position: absolute; inset: 0; width: 100%; height: 100%; }
.face__tint { background: var(--cloth); -webkit-mask: var(--shot) center / contain no-repeat; mask: var(--shot) center / contain no-repeat; }
/* .prose figure img frames images as glass cards; these are cut-outs. */
.prose .rack .face img { padding: 0; border: 0; border-radius: 0; background: none; mix-blend-mode: multiply; }
.face--front { --shot: url(/assets/tee-front.webp); opacity: var(--fw); }
.face--back { --shot: url(/assets/tee-back.webp); opacity: var(--fw); transform: rotateY(180deg); }
/* The side plane crosses the front at the axis. At rest (+90°) the near
   side shows, mirrored so the shirt's front points the way it turns. */
.face--side { --shot: url(/assets/tee-side.webp); opacity: var(--sw); transform: rotateY(-90deg); }
.face--side > * { transform: scaleX(-1); }
.face--far { --shot: url(/assets/tee-side.webp); opacity: var(--sw); transform: rotateY(90deg); }
.hanger__tag text { fill: #1B1F25; font: 700 8.2px/1 var(--font-body); text-anchor: middle; font-variant-numeric: tabular-nums; }

/* Without the spring (no JS, reduced motion, or the toggle): a plain CSS turn */
/* The photo arriving fades in first and the one leaving fades out after it,
   so the two overlap instead of going see-through halfway. */
.rack[data-mode="css"] .hanger__spin { transition: transform 180ms var(--ease-out), --sw 80ms var(--ease-out), --fw 80ms var(--ease-out) 60ms; }
.rack[data-mode="css"] .rack__item:hover .hanger__spin,
.rack[data-mode="css"] .hanger:focus-visible .hanger__spin { transform: rotateY(0deg); --fw: 1; --sw: 0; transition: transform 180ms var(--ease-out), --fw 80ms var(--ease-out), --sw 80ms var(--ease-out) 60ms; }

/* Arrows either side of the toggle between the two versions */
.rack__ctl { display: flex; align-items: center; justify-content: center; gap: var(--space-sm); margin: var(--space-xs) var(--space-md) 0; }
.rack__ctl [hidden] { display: none; }
.rack__modes { display: flex; gap: var(--space-2xs); padding: var(--space-3xs); border: 1px solid; border-color: var(--edge-glass); border-radius: var(--radius-pill); background: var(--grad-glass); }
.rack__mode { min-height: 36px; padding: 0 var(--space-md); border: 0; border-radius: var(--radius-pill); background: none; color: var(--color-ink-2); font: 600 var(--text-xs)/1 var(--font-body); white-space: nowrap; cursor: pointer; transition: background-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out); }
.rack__mode:hover { color: var(--color-accent-deep); }
.rack__mode[aria-pressed="true"] { background: var(--color-paper); color: var(--color-accent-deep); box-shadow: 0 1px 2px rgba(10, 44, 92, 0.12); }
.rack__mode:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.prose .rack figcaption { margin: var(--space-md) var(--space-lg) 0; text-align: center; }

@media (max-width: 30rem) {
  .rack__mode { padding: 0 var(--space-sm); }
}
@media (prefers-reduced-motion: reduce) {
  .rack[data-mode="css"] .hanger__spin { transition: none; }
  .rack__mode { transition: none; }
}
