/* brandonlehmanshow.com — product turntable (PDPs that carry a GLB: mug, cap).
   Layout for the .turntable block written by scripts/build-shop.mjs and driven
   by product-3d.js. Tokens from experience.css only; hairlines, radius 0, no
   glow; gold is spent on the one control's focus ring and hover underline. */

/* 1. The block is the gallery's hero frame (it replaces the flat packshot
   frame, so the packshot appears once). A 1:1 frame on --bg-deep with a 1px
   image outline, the same size the square packshot frame takes (shop.css keeps
   1:1 packshots uncropped). On phones it is the first frame of the scroll-snap
   gallery; on desktop the gallery is a grid and it stacks like any frame. */
.turntable {
  position: relative;
  flex: 0 0 88vw;
  align-self: flex-start; /* the phone gallery is a flex row: do not stretch to the 4:5 frames */
  scroll-snap-align: start;
  aspect-ratio: 1;
  background: var(--bg-deep);
  outline: 1px solid var(--outline-img);
  outline-offset: -1px;
  overflow: hidden;
}
@media (min-width: 900px) { .turntable { flex: none; } }
@media (max-width: 899px) { .turntable--tile { aspect-ratio: 4 / 5; } }
.turntable picture { display: contents; }

/* 2. Poster first. It stays until the first 3D frame has rendered, then
   crosses to the transparent canvas over --bg-deep. */
.turntable__poster {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 50%;
  background: var(--bg-deep);
}
.turntable.is-3d .turntable__poster { opacity: 0; visibility: hidden; }

.turntable__canvas {
  position: absolute; inset: 0;
  display: block; width: 100%; height: 100%;
  opacity: 0;
  touch-action: pan-y; /* a vertical finger drag still scrolls the page; horizontal turns (yaw only on touch) */
  cursor: grab;
  user-select: none; -webkit-user-select: none;
}
.turntable.is-3d .turntable__canvas { opacity: 1; }
.turntable__canvas.is-dragging { cursor: grabbing; }
.turntable__canvas:focus-visible { outline: 2px solid var(--gold); outline-offset: -3px; }

/* 3. Progress: one hairline along the bottom edge, scaled by --progress. */
.turntable__progress {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 1px;
  background: var(--ink);
  transform-origin: left center;
  transform: scaleX(var(--progress, 0));
  transition: transform var(--t-state) linear;
}

/* 4. The controls: quiet 44px text buttons with a hairline. "View in 3D" sits
   bottom-left over the poster; "Close" top-right over the canvas. */
.turntable__open, .turntable__close {
  position: absolute;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 44px; padding: 0 var(--s-4);
  border: 1px solid var(--line-strong); border-radius: var(--r-0);
  background: transparent; color: var(--ink);
  font: 500 13px/1.4 var(--font-body); letter-spacing: 0.02em;
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 5px; text-decoration-thickness: 1px;
  transition: text-decoration-color var(--t-state) var(--ease-out), border-color var(--t-state) var(--ease-out), scale var(--t-press) var(--ease-out);
}
.turntable__open { left: var(--s-4); bottom: var(--s-4); }
.turntable__close { right: var(--s-4); top: var(--s-4); }
.turntable__open:active, .turntable__close:active { scale: 0.97; text-decoration-color: var(--gold); }
/* After a failed load the control is retired, not removed: the photo stands. */
.turntable__open:disabled { color: var(--muted); border-color: var(--line); cursor: default; text-decoration-color: transparent; scale: 1; }
.motion-paused .turntable__open:active, .motion-paused .turntable__close:active { scale: 1; }

/* 5. Movement is opt-in: the poster/canvas crossfade (450 ms, --ease-out) only
   when the device and the footer toggle allow it; otherwise the swap is instant. */
@media (prefers-reduced-motion: no-preference) {
  html:not(.motion-paused) .turntable__poster { transition: opacity var(--t-crossfade) var(--ease-out), visibility 0s; }
  html:not(.motion-paused) .turntable.is-3d .turntable__poster { transition: opacity var(--t-crossfade) var(--ease-out), visibility 0s linear var(--t-crossfade); }
  html:not(.motion-paused) .turntable__canvas { transition: opacity var(--t-crossfade) var(--ease-out); }
}

/* 6. Hover only where a pointer can hover (rubric 16). */
@media (hover: hover) {
  .turntable__open:hover:not(:disabled), .turntable__close:hover { text-decoration-color: var(--gold); border-color: var(--ink); }
}
