/* Theme case studies: the industry interaction of type "swatch" (CARVÉ's "Choose your colour"): a colour studio. Markup:
   src/_includes/e2/theme/sig-swatch.njk; behaviour: e2-theme-swatch.js. Nothing is brand-specific: the wrapper's inline style carries the
   theme (--th-from / --th-to / --th-ink / --th-accent from stage, --th-f-head / ui / prod from tokens.fonts) and the stage's --th-tint is the
   chosen colour (the script sets it; it eases, so the paper warms or cools rather than flips).
   Layout: wide, the studio (the bag on its plinth, ~7 parts) beside the buy box (~5 parts); under 960px the buy box goes under the studio;
   phones get a square studio and the swatches as large chips. The token strip after it is e2-theme-sig.css's.
   Every control is at least 44px tall and wide. Reduced motion: no crossfade, no lift, no easing of the tint; the loupe still works. */

@property --th-tint { syntax: '<color>'; inherits: true; initial-value: #8a8a8a; }

.th-cs {
  --cs-spring: cubic-bezier(.34, 1.56, .64, 1);
  --cs-out: cubic-bezier(.2, .8, .2, 1);
  --cs-line: color-mix(in srgb, var(--th-ink) 13%, transparent);
  --cs-muted: color-mix(in srgb, var(--th-ink) 68%, transparent);
  --cs-gap: 10px;   /* between the swatches (the sliding ring needs it too) */
  display: flex; flex-direction: column; gap: clamp(40px, 5vw, 64px);
}
.th-cs :focus-visible { outline: 2px solid var(--th-ink); outline-offset: 3px; }
:where(.th-cs) button { font: inherit; color: inherit; }

/* ---------- The stage: the theme's warm paper, with the chosen colour as a soft glow behind the bag ---------- */
.th-cs__stage {
  position: relative; isolation: isolate; overflow: hidden; border-radius: 32px; padding: clamp(18px, 3vw, 40px);
  display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: clamp(20px, 3.4vw, 56px); align-items: center;
  background: linear-gradient(135deg, var(--th-from), var(--th-to)); color: var(--th-ink); font-family: var(--th-f-ui); font-size: 15px; line-height: 1.4;
  transition: --th-tint .7s ease;
}
.th-cs__stage::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 80% at 16% 0%, rgba(255,255,255,.62), transparent 62%),
    radial-gradient(55% 70% at 100% 100%, rgba(255,255,255,.4), transparent 70%);
}

/* ---------- 1. The studio ---------- */
/* as tall as the screen allows (a 1280 x 720 laptop sees the whole stage), never shorter than 440px or taller than 640px */
.th-cs__studio { position: relative; align-self: stretch; min-height: clamp(440px, min(46vw, 100svh - 220px), 640px); }
/* the chosen colour as a soft glow behind the bag (the stage clips it) */
.th-cs__studio::before {
  content: ""; position: absolute; z-index: -1; left: 50%; top: 54%; width: 92%; aspect-ratio: 1 / .9; translate: -50% -50%; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--th-tint) 24%, transparent), transparent);
}

/* the readout (colour name + hex) in the studio's top-left corner, the hint (how to use the loupe) in its bottom-left one */
.th-cs__read, .th-cs__hint { position: absolute; z-index: 2; display: inline-flex; align-items: center; margin: 0; white-space: nowrap; pointer-events: none; }
.th-cs__read { left: 0; top: 0; gap: 8px; padding: 9px 0; font: 500 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.th-cs__chip { width: 12px; height: 12px; border-radius: 3px; background: var(--th-tint); box-shadow: inset 0 0 0 1px rgba(0,0,0,.14); }
.th-cs__rhex { color: var(--cs-muted); letter-spacing: .04em; }
.th-cs__hint {
  left: 0; bottom: 0; gap: 7px; padding: 6px 6px 6px 11px; border-radius: 99px; letter-spacing: .01em; font: 500 12px/1 var(--th-f-ui);
  color: var(--th-ink); background: rgba(255,255,255,.62); box-shadow: inset 0 0 0 1px var(--cs-line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.th-cs__hint svg { flex: none; }
.th-cs__hk { padding: 4px 7px; border-radius: 99px; background: var(--th-ink); color: #fff; font: 500 10.5px/1 var(--mono); letter-spacing: .02em; }
.th-cs__ht--touch, .th-cs__ht--key { display: none; }
@media (hover: none) { .th-cs__ht--hover { display: none; } .th-cs__ht--touch { display: inline; } }
.th-cs__studio:has(.th-cs__inspect:focus-visible) .th-cs__ht { display: none; }
.th-cs__studio:has(.th-cs__inspect:focus-visible) .th-cs__ht--key { display: inline; }
.th-cs__hint.is-nudge { animation: th-cs-nudge .5s var(--cs-out); }
@keyframes th-cs-nudge { 30% { scale: 1.06; background: #fff; } }

/* The bag: a box of the close-up's shape, its foot on the plinth's top face. The picture is contained in it, feet on the bottom edge. */
.th-cs__bag {
  position: absolute; left: 50%; bottom: 20%; height: 63%; aspect-ratio: 712 / 827; translate: -50% 0; isolation: isolate;
}
.th-cs__img {
  position: absolute; inset: 0; z-index: 1; display: block; width: 100%; height: 100%; max-width: none; object-fit: contain; object-position: 50% 100%;
  user-select: none; -webkit-user-select: none; -webkit-user-drag: none; transform-origin: 50% 100%;
}
.th-cs__ghost { z-index: 2; pointer-events: none; }
/* a soft plinth: the top face is a pale ellipse, its edge the offset shadow below it, then a wide soft shadow on the paper */
.th-cs__plinth {
  position: absolute; z-index: -1; left: 50%; top: 100%; width: 142%; aspect-ratio: 5.6; translate: -50% -50%; border-radius: 50%;
  background: radial-gradient(90% 120% at 50% 18%, rgba(255,255,255,.84), color-mix(in srgb, var(--th-to) 82%, #fff) 64%, color-mix(in srgb, var(--th-from) 78%, var(--th-to)));
  box-shadow:
    0 13px 0 -1px color-mix(in srgb, var(--th-from) 86%, var(--th-ink) 9%),
    0 13px 0 0 color-mix(in srgb, var(--th-from) 70%, var(--th-ink) 14%),
    0 44px 46px -20px color-mix(in srgb, var(--th-ink) 30%, transparent);
}
/* the contact shadow under the bag's feet */
.th-cs__shadow {
  position: absolute; z-index: 0; left: 8%; right: 8%; bottom: -2.4%; height: 6%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--th-ink) 40%, transparent), transparent);
  filter: blur(3px); transform-origin: 50% 50%;
}
/* viewfinder corners round the bag; they close in while the loupe is on. The lower pair stops above the plinth's top face (it rises
   ~11% of the bag's height above the bag's foot), so they never land on the disc. */
.th-cs__marks { position: absolute; z-index: 0; inset: -7% -12% 12%; pointer-events: none; transition: inset .4s var(--cs-out), opacity .3s ease; opacity: .4; }
.th-cs__marks i { position: absolute; width: 16px; height: 16px; border: 0 solid color-mix(in srgb, var(--th-ink) 45%, transparent); }
.th-cs__marks i:nth-child(1) { left: 0; top: 0; border-width: 1.5px 0 0 1.5px; }
.th-cs__marks i:nth-child(2) { right: 0; top: 0; border-width: 1.5px 1.5px 0 0; }
.th-cs__marks i:nth-child(3) { left: 0; bottom: 0; border-width: 0 0 1.5px 1.5px; }
.th-cs__marks i:nth-child(4) { right: 0; bottom: 0; border-width: 0 1.5px 1.5px 0; }
.th-cs__stage.is-loupe .th-cs__marks { inset: -3% -6% 14%; opacity: 1; }

/* the size, drawn as a dimension rule under the plinth */
.th-cs__dim {
  position: absolute; left: 0; right: 0; top: calc(100% + 17%); display: flex; align-items: center; gap: 10px; pointer-events: none;
  font: 500 11px/1 var(--mono); letter-spacing: .06em; color: var(--cs-muted); white-space: nowrap;
}
.th-cs__dim::before, .th-cs__dim::after {
  content: ""; flex: 1; height: 9px;
  background: linear-gradient(currentColor, currentColor) 0 50% / 100% 1px no-repeat;
  border: 0 solid currentColor; opacity: .7;
}
.th-cs__dim::before { border-left-width: 1px; }
.th-cs__dim::after { border-right-width: 1px; }

/* The loupe: a round lens with the close-up at 2.2x (the script sets its position and the background's size and offset) */
.th-cs__loupe {
  --d: 208px;
  position: absolute; z-index: 3; left: 0; top: 0; width: var(--d); height: var(--d); border-radius: 50%; pointer-events: none;
  background-color: color-mix(in srgb, var(--th-to) 70%, #fff); background-repeat: no-repeat;
  box-shadow: 0 0 0 3px #fff, 0 0 0 4px color-mix(in srgb, var(--th-ink) 16%, transparent), 0 26px 44px -16px rgba(10,12,16,.5), inset 0 0 0 1px rgba(0,0,0,.06);
  opacity: 0; scale: .55; transition: opacity .14s ease, scale .26s var(--cs-spring); will-change: transform;
}
.th-cs__loupe.is-on { opacity: 1; scale: 1; }
.th-cs__cross { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; translate: -50% -50%; opacity: .55;
  background: linear-gradient(#fff, #fff) 50% 50% / 1px 100% no-repeat, linear-gradient(#fff, #fff) 50% 50% / 100% 1px no-repeat;
  filter: drop-shadow(0 0 1px rgba(0,0,0,.6)); }
.th-cs__zk {
  position: absolute; left: 50%; bottom: -11px; translate: -50% 0; padding: 5px 8px; border-radius: 99px;
  background: var(--th-ink); color: #fff; font: 500 10.5px/1 var(--mono); letter-spacing: .02em; box-shadow: 0 0 0 2px #fff;
}

/* The inspect area: a transparent button over the bag (keyboard: Enter, then the arrow keys). */
.th-cs__inspect {
  position: absolute; z-index: 4; inset: -2%; padding: 0; border: 0; border-radius: 16px; background: none; cursor: zoom-in;
  -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}
.th-cs__stage.is-loupe .th-cs__inspect { cursor: none; }
.th-cs .th-cs__inspect:focus-visible { outline-offset: 10px; }

/* ---------- 2. The buy box ---------- */
.th-cs__panel { display: flex; flex-direction: column; gap: 0; min-width: 0; max-width: 460px; padding: 8px 0; }
.th-cs__brand { margin: 0 0 14px; font: 600 12px/1 var(--th-f-ui); letter-spacing: .32em; text-transform: uppercase; color: var(--cs-muted); }
.th-cs__name { margin: 0; font: 600 clamp(28px, 2.6vw, 38px)/1.08 var(--th-f-head); letter-spacing: -.015em; text-wrap: balance; }
.th-cs__cw { display: inline-block; }
.th-cs__price { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin: 14px 0 0; font-family: var(--th-f-prod); }
.th-cs__now { font-size: 24px; font-weight: 500; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.th-cs__was { font-size: 17px; color: var(--cs-muted); text-decoration-thickness: 1.2px; font-variant-numeric: tabular-nums; }

.th-cs__opt { display: flex; flex-direction: column; gap: 12px; margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--cs-line); }
.th-cs__lbl { margin: 0; font-size: 14px; color: var(--cs-muted); }
.th-cs__lbl b { font-weight: 600; color: var(--th-ink); }

/* the swatches: equal cells; the ring that marks the chosen one slides between them */
.th-cs__swatches { position: relative; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: var(--cs-gap); container: cs-sw / inline-size; }
.th-cs__sw {
  position: relative; display: flex; align-items: center; gap: 12px; min-width: 0; min-height: 64px; padding: 10px 12px; text-align: left; cursor: pointer;
  border: 0; border-radius: 14px; background: rgba(255,255,255,.5); box-shadow: inset 0 0 0 1px var(--cs-line);
  transition: background-color .18s ease, box-shadow .18s ease, transform .2s var(--cs-spring);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
@media (hover: hover) { .th-cs__sw:hover { background: rgba(255,255,255,.85); } .th-cs__sw:hover .th-cs__dot { scale: 1.08; } }
.th-cs__sw:active { transform: scale(.97); transition-duration: .1s; }
.th-cs__sw[aria-pressed="true"] { background: #fff; box-shadow: inset 0 0 0 1px transparent; }
.th-cs__dot {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, color-mix(in srgb, var(--c) 62%, #fff) 0, var(--c) 48%, color-mix(in srgb, var(--c) 76%, #000) 100%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 6px 10px -6px rgba(0,0,0,.5);
  transition: scale .25s var(--cs-spring);
}
.th-cs__swt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.th-cs__swn { font-size: 14px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.th-cs__swh { font: 500 11px/1.2 var(--mono); letter-spacing: .02em; color: var(--cs-muted); }
.th-cs__ring {
  position: absolute; z-index: 1; left: 0; top: 0; bottom: 0; pointer-events: none; border-radius: 14px;
  width: calc((100% - (var(--n) - 1) * var(--cs-gap)) / var(--n));
  box-shadow: inset 0 0 0 1.5px var(--th-ink), 0 10px 18px -12px color-mix(in srgb, var(--th-ink) 60%, transparent);
  translate: calc(var(--i) * (100% + var(--cs-gap))) 0; transition: translate .42s var(--cs-spring);
}

/* A narrow swatch group (the buy box is only ~330-390px wide between ~960px and ~1160px of viewport, where the studio and the buy box sit
   side by side): a cell is then ~100-125px, too narrow for the dot beside the name + hex, so the dot goes above the text, exactly as on
   phones (the phone rules below are the same three declarations, for the one-column widths where the group is wide but the chips are
   kept). The cell widens again past 392px (3 x 124px of cell + 2 gaps): there the row layout has >= 8px to spare on the right. */
@container cs-sw (max-width: 391px) {
  .th-cs__sw { flex-direction: column; align-items: flex-start; gap: 10px; min-height: 96px; padding: 12px; }
  .th-cs__dot { width: 36px; height: 36px; }
  .th-cs__swn { font-size: 15px; }
}

/* the spec chips */
.th-cs__specs { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 22px 0 0; padding: 0; }
.th-cs__specs li {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px 7px 10px; border-radius: 99px; font-size: 13px; line-height: 1.2;
  background: rgba(255,255,255,.42); box-shadow: inset 0 0 0 1px var(--cs-line);
}
.th-cs__specs li::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--th-accent); }

/* the one filled button: square-cornered like the theme's own */
.th-cs__cta {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 56px; margin-top: 28px; padding: 0 24px; cursor: pointer;
  border: 0; border-radius: 6px; background: var(--th-ink); color: #fff; font: 600 15px/1.2 var(--th-f-ui); letter-spacing: .02em;
  box-shadow: 0 16px 24px -16px color-mix(in srgb, var(--th-ink) 85%, transparent);
  transition: background-color .2s ease, transform .2s var(--cs-spring), box-shadow .2s ease;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
@media (hover: hover) { .th-cs__cta:hover { background: color-mix(in srgb, var(--th-ink) 80%, var(--th-accent)); transform: translateY(-1px); } }
.th-cs__cta:active { transform: scale(.985); transition-duration: .1s; }
.th-cs__check { display: none; }
.th-cs__cta.is-done { background: var(--th-accent); }
.th-cs__cta.is-done .th-cs__check { display: block; animation: th-cs-pop .45s var(--cs-spring); }
@keyframes th-cs-pop { from { scale: .3; opacity: 0; } to { scale: 1; opacity: 1; } }

/* ---------- Narrower: the buy box goes under the studio ---------- */
@media (max-width: 959px) {
  .th-cs__stage { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .th-cs__studio { min-height: 0; aspect-ratio: 16 / 11; }
  .th-cs__hint { left: 50%; translate: -50% 0; }
  .th-cs__panel { max-width: none; padding: 0 clamp(0px, 2vw, 16px) 8px; }
}

/* ---------- Phones: a squarer studio; the swatches become large chips, three across ---------- */
@media (max-width: 699px) {
  .th-cs { --cs-gap: 8px; }
  .th-cs__stage { border-radius: 24px; padding: 16px; gap: 8px; }
  .th-cs__studio { aspect-ratio: 1 / 1.08; }
  .th-cs__bag { bottom: 22%; height: 59%; }
  .th-cs__read { padding: 8px 0; font-size: 10.5px; }
  .th-cs__dim { top: calc(100% + 14%); }
  .th-cs__loupe { --d: 140px; }
  .th-cs__panel { padding: 8px 0 0; }
  .th-cs__brand { margin-bottom: 10px; font-size: 11px; }
  .th-cs__name { font-size: 26px; }
  .th-cs__now { font-size: 21px; }
  .th-cs__was { font-size: 15px; }
  .th-cs__opt { margin-top: 20px; padding-top: 18px; }
  .th-cs__sw { flex-direction: column; align-items: flex-start; gap: 10px; min-height: 96px; padding: 12px; }
  .th-cs__dot { width: 36px; height: 36px; }
  .th-cs__swn { font-size: 15px; }
  .th-cs__specs { margin-top: 18px; gap: 6px; }
  .th-cs__specs li { font-size: 12.5px; }
  .th-cs__cta { margin-top: 22px; }
}

/* ---------- Reduced motion: the swap is a cut, the tint jumps, the ring jumps; the loupe still works (it shows at once) ---------- */
@media (prefers-reduced-motion: reduce) {
  .th-cs__stage, .th-cs__ring, .th-cs__marks, .th-cs__loupe, .th-cs__sw, .th-cs__dot, .th-cs__cta { transition: none; }
  .th-cs__hint.is-nudge, .th-cs__cta.is-done .th-cs__check { animation: none; }
  .th-cs__sw:hover .th-cs__dot { scale: 1; }
}
