/* ═══ rig — a live prototype on a plate ════════════════════════════════════
   Replaces a screen recording with the real prototype in an iframe, plus a
   scripted cursor. rig.js drives it.

   Three nested layers, and the nesting is the point:

     .rig          the field (background, padding) — untransformed
     .rig__screen  reserves the box the screen occupies on the card
     .rig__plate   scale(var(--s)), sized in PROTOTYPE pixels

   The plate carries one transform and only one: the scale that fits the
   prototype's intrinsic pixels into the slot. There is deliberately no
   pointer-driven tilt. A 3D transform changing on an ancestor of an iframe
   makes the browser throw away that document's :hover for a frame, so a
   parallax that followed the pointer destroyed the prototype's own hover
   sixty times a second. The effect was not worth the cost.

   --pw / --ph are the prototype's intrinsic size, set per rig in the markup.
   rig.js keeps --s in sync with the rendered width.

   The prototype draws a rounded card inside a white margin of its own, and
   reserves a strip at the foot for the comparison picker that ?clean hides.
   The rig wants the card alone, so that it — not the prototype — decides the
   field and the padding around it. So the frame is given its true size
   (--fw/--fh), shifted up and left by --ox/--oy, and the plate clips to the
   card (--pw/--ph). Nothing in the prototype's source has to change.
---------------------------------------------------------------------------- */

/* By default the rig is nothing but the artwork: no field, no padding, no
   box of its own. The prototype already composes a rounded card on its own
   gradient, and that card IS the media — so the rounding and the crop belong
   to it, not to a second frame around it.

   A rig that wants a page-side field opts in with data-bg, which brings back
   the padding and the rounded container. */
.rig {
  position: relative;
  /* The gradient card, cropped. This box never moves: it is the surface the
     screen sits on, drawn by the page so the page can restyle it. */
  aspect-ratio: var(--cw) / var(--ch);
  background: var(--rig-field,
    linear-gradient(118.22deg, rgba(139, 102, 193, .3) 7.5%,
                               rgba(228, 130, 202, .47) 108.89%), #fff);
  border-radius: var(--radius);      /* the standing rule: media is rounded */
  overflow: hidden;                  /* the screen is cropped by the card */
  isolation: isolate;
}

/* The screen's box on the card. --wx/--wy place it; left resolves against
   the card's width and top against its height, so each is divided by the
   matching dimension. Its own height comes from the aspect ratio, which is
   taller than the cropped card — that is the bleed off the foot.

   No transform of its own, which is the whole point: nothing between the
   card and the iframe ever changes, so the prototype's :hover is never
   invalidated from the outside. */
/* -- arriving ------------------------------------------------------
   The card itself does not arrive. It is part of the page the way a rule
   or a heading is: fixed, already there, drawn before you reach it. What
   arrives is the prototype inside it, rising into a frame that is standing
   still - which is the point. A frame that moves is a slide; a frame that
   holds while its contents fill it is a window.

   The move lives on .rig__plate, folded into the scale() that rule already
   carries (see --rin further down), rather than on .rig__screen, which is
   carrying the scroll drift - two animated transforms on one element would
   fight every frame.

   It is 2D for the same reason the drift is: a 3D transform on an ancestor
   of an iframe costs that document its :hover. */
.rig__plate {
  /* Travel does the work; the fade only takes the edge off the start. A
     reveal that goes 0 -> 1 reads as something switching on, where a half
     opaque thing already on its way up reads as arriving. */
  opacity: .5;
  transition: opacity 420ms ease-out,
              transform 760ms cubic-bezier(.19, 1, .3, 1);
}
.rig.is-in .rig__plate { opacity: 1; --rin: 0px; }

/* Nothing to reveal if the page is not allowed to move, and nothing to
   reveal if scripting never runs - both show everything at once. */
@media (prefers-reduced-motion: reduce) {
  .rig__plate { opacity: 1; --rin: 0px; transition: none; }
}

.rig__screen {
  position: absolute;
  left: calc(var(--wx) / var(--cw) * 100%);
  top:  calc(var(--wy) / var(--ch) * 100%);
  width: calc(var(--pw) / var(--cw) * 100%);
  aspect-ratio: var(--pw) / var(--ph);
  /* A few pixels of drift against the scroll, set by rig.js, so the screen
     sits on the field rather than being printed on it. Deliberately 2D:
     a 3D transform on an ancestor of an iframe makes Chrome drop that
     document's :hover for a frame, which would break the walkthrough
     every time the page moved. The plate below keeps its own scale(). */
  transform: translateY(var(--drift, 0px));
  will-change: transform;
}

.rig__plate {
  position: absolute;
  inset: 0 auto auto 0;
  width:  calc(var(--pw) * 1px);
  height: calc(var(--ph) * 1px);
  /* The prototype's intrinsic pixels scaled into the slot, plus the
     reveal's starting offset — composed here rather than in a separate
     rule, because a second `transform` further up the file would simply
     be overwritten by this one. --rin goes to 0 when the card comes
     into view, and is the only travel in the reveal now. */
  transform: translateY(var(--rin, 34px)) scale(var(--s, 1));
  transform-origin: 0 0;
  /* The screen's own corner, as the prototype draws it. The page's --radius
     belongs to the card around it, not to the screen. */
  border-radius: calc(var(--srad, 20) * 1px);
  overflow: hidden;
  background: var(--plate-bg, #fff);
  /* Lifted off the card, so the screen reads as an object standing on the
     field rather than a picture printed on it. */
  box-shadow: var(--plate-shadow,
    0 calc(18px / var(--s, 1)) calc(44px / var(--s, 1)) rgba(40, 20, 60, .18));
  /* The plate is scaled, so without its own compositing layer every repaint
     inside the prototype re-rasterises the whole thing at a fractional
     scale. This is the difference between a smooth view switch and a
     visible hitch. */
  will-change: transform;
}

.rig__frame {
  display: block;
  position: absolute;
  top:  calc(var(--oy, 0) * -1px);
  left: calc(var(--ox, 0) * -1px);
  width:  calc(var(--fw, var(--pw)) * 1px);
  height: calc(var(--fh, var(--ph)) * 1px);
  border: 0;
  /* The frame takes real pointer events from the start, not only once the
     viewer has taken control. That is what lets their own hover light
     things up while the walkthrough is still playing — and a control that
     responds to the pointer is a far better invitation to take over than a
     badge in the corner. The first press hands control over AND does what
     it was aimed at, so nothing is spent on a throwaway click. */
  pointer-events: auto;
}

/* ?bare gives the frame a transparent background, so the page's own card
   shows through wherever the UI is not painting. The plate must not fill
   white behind it or that transparency is wasted.

   Needed in two different situations, which is why the chrome is a separate
   switch: a UI that changes size inside the frame (the profile panel), and
   a UI that is itself translucent and wants the card to show through it
   (the calendar window). */
.rig[data-bare] .rig__plate { --plate-bg: transparent; }

/* And where the plate is larger than the UI standing on it, its shadow
   would draw a phantom panel around empty space. The corner is a separate
   matter — a transparent plate still clips what is inside it — so that stays
   with --srad, which a rig sets to 0 when it wants none. */
.rig[data-chromeless] .rig__plate { --plate-shadow: none; }

/* ── poster ──────────────────────────────────────────────────────────────
   Shown until the frame has loaded, and instead of it under reduced motion.
   Sits on the plate so it carries the same scale and rounding. */
.rig__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 260ms linear;
  pointer-events: none;
}
.rig:not(.is-ready) .rig__poster { opacity: 1; }

/* ── the cursor ──────────────────────────────────────────────────────────
   A sibling of the plate, not a child, and positioned in the rig's own
   unscaled pixels — rig.js maps the plate-space point out here. That buys
   what a real cursor has: it is rasterised at full device resolution rather
   than resampled along with the scaled plate. */
.rig__cursor {
  position: absolute;
  top: 0;
  left: 0;
  /* Sized to sit alongside the real macOS pointer rather than under it —
     the system one is noticeably larger than the 19px this used to be. */
  width: var(--cursor-size, 26px);
  height: var(--cursor-size, 26px);
  margin: 0;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  /* translate, not translate3d. This moves every frame while a scene plays,
     and a 3D transform changing on a sibling of the frame is enough to cost
     the prototype its hover. 2D needs no compositing layer here and does
     not disturb it. */
  /* Position only. The press scale lives on the glyph below, because this
     transform is rewritten on every frame of a move and a transition here
     would smear the motion itself. */
  transform: translate(calc(var(--cx, 0) * 1px), calc(var(--cy, 0) * 1px));
  transform-origin: 0 0;
  transition: opacity 200ms linear;
  will-change: transform;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .3));
}
.rig.is-playing .rig__cursor { opacity: 1; }

/* Each glyph is offset so its business end — the arrow's tip, the hand's
   fingertip — sits exactly on --x/--y, whichever is showing. */
/* --hotx/--hoty are in the glyph's own 24-unit viewBox, scaled here by the
   rendered size — so changing --cursor-size keeps the business end of each
   glyph on the point. */
.rig__cursor svg {
  display: block;
  position: absolute;
  top:  calc(var(--hoty, 0) * var(--cursor-size, 26px) / 24 * -1);
  left: calc(var(--hotx, 0) * var(--cursor-size, 26px) / 24 * -1);
  width: 100%;
  height: 100%;
  /* The press. Eased rather than snapped, and pivoted on the glyph's own
     hotspot so the tip stays exactly where it is pointing while the rest
     of the shape dips. */
  transform: scale(var(--press, 1));
  transform-origin: calc(var(--hotx, 0) / 24 * 100%) calc(var(--hoty, 0) / 24 * 100%);
  transition: transform 190ms cubic-bezier(.33, .72, .3, 1);
}
.rig__cursor[data-k="arrow"] { --hotx: 2.5; --hoty: 1.5; }
.rig__cursor[data-k="hand"]  { --hotx: 9.8; --hoty: 1.5; }

/* The click ripple: one element, animated by rig.js adding .is-tap. */
.rig__cursor::after {
  content: "";
  position: absolute;
  top: -5px;
  left: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(20, 20, 24, .4);
  opacity: 0;
  transform: scale(1);
  /* Behind the glyph, so the pointer is never veiled by its own feedback. */
  z-index: -1;
}
.rig__cursor.is-tap::after { animation: rig-tap 980ms cubic-bezier(.22, .78, .3, 1); }

/* A ring opening, not a flicker. The timing is the middle of the two that
   were tried: the first was a 820ms snap that read as a flinch, the second
   a 1250ms drift that read as slow. The opacities and the final size come
   from the calmer one, so it is gentler without being sluggish. */
@keyframes rig-tap {
  0%   { opacity: .4;  transform: scale(.78); }
  22%  { opacity: .32; transform: scale(1.45); }
  100% { opacity: 0;   transform: scale(3); }
}

/* ── pause / play ────────────────────────────────────────────────────────
   One control, two states. While the walkthrough runs it offers a pause,
   which drops the viewer straight into using the thing themselves; once
   paused it offers a play, which restarts the walkthrough. Clicking the
   prototype directly has the same effect as pausing, so the button follows
   that too — it reports the state rather than driving it. */
.rig__hint {
  position: absolute;
  right: clamp(16px, 2.6vw, 36px);
  bottom: clamp(16px, 2.6vw, 36px);
  z-index: 4;
  display: grid;
  place-items: center;
  /* One token for both axes, and an aspect-ratio behind it, so this can
     only ever be a circle. It was a text badge once, and the narrow-width
     rule that shortened that badge was still setting a height without a
     width — which quietly turned the button into a 42x24 ellipse on any
     screen under 760px, the Claude side panel included. */
  width: var(--hint-size, 42px);
  height: var(--hint-size, 42px);
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(14, 14, 18, .62);
  color: #fff;
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 240ms linear, background-color 150ms ease-out;
}
.rig.is-ready .rig__hint { opacity: 1; }
.rig__hint:hover { background: rgba(14, 14, 18, .82); }

.rig__hint svg { display: block; width: calc(var(--hint-size, 42px) * 0.405); height: auto; aspect-ratio: 1; }
.rig__hint .rig__ico--play { display: none; }
.rig.is-live .rig__hint .rig__ico--pause { display: none; }
.rig.is-live .rig__hint .rig__ico--play { display: block; }

/* ── field presets ───────────────────────────────────────────────────────  */
/* Lifted from the prototype's own presentation field, so the page and the
   prototype agree on the palette instead of approximating each other. */
.rig[data-bg="violet"] { --rig-field: linear-gradient(118.22deg, rgba(139,102,193,.3) 7.5%, rgba(228,130,202,.47) 108.89%), #fff; }
.rig[data-bg="grey"]   { --rig-field: #f1f1f2; }
.rig[data-bg="ink"]    { --rig-field: radial-gradient(120% 120% at 20% 10%, #2a2a31 0%, #191920 100%); }
.rig[data-bg="none"]   { --rig-field: transparent; }

/* ── narrow screens ───────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .rig[data-bg]:not([data-bg="none"]) { --rig-pad: 12px; }
  /* Sized in absolute units, so it has to come down with everything else
     or it reads as a disc stuck on the artwork. Width, height and glyph all
     follow --hint-size, so there is one number to change. */
  .rig { --hint-size: 32px; }
  .rig__hint { right: 10px; bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .rig__cursor { display: none; }
}
