/* #154 the front card's 3D viewer (dist/card3d.js), from the approved #148 prototype (docs/design/card-3d-2026-10-24).
   #321 brings it back for the #273 living card (living-card.css draws the card, unchanged); this adds the card's press,
   the viewer, the QR back's place in it and the light layers. Every frame moves transforms and opacities only. */

/* The card opens on a tap anywhere on it except its own buttons (the empty card's Buy pill). Keyboards and screen
   readers reach a button that stays out of the way until it has focus, then rings the whole card (the card's own text
   stays readable). A quick press-in tells the finger it was heard before the card lifts out. */
.lc-stage > .c3d-open {
  position: absolute; left: 0; top: 0; z-index: 3; display: block; width: 1px; height: 1px; min-width: 0; max-width: none; min-height: 0;
  margin: 0; padding: 0; overflow: hidden; clip-path: inset(50%); border: 0; border-radius: 5.4cqw; background: transparent; box-shadow: none;
  pointer-events: none; -webkit-tap-highlight-color: transparent;
}
.lc-stage > .c3d-open:focus-visible { width: 100%; height: 100%; clip-path: none; outline: 3px solid var(--cc-ink); outline-offset: 3px; }
.lc-stage.c3d-tappable { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.lc-stage.c3d-tappable > .lc-face { transition: transform 160ms var(--gold-ease-out, cubic-bezier(0.23, 1, 0.32, 1)); }
.lc-stage.c3d-tappable:active:not(:has(.mc-buy:active)) > .lc-face { transform: scale(0.97); }
/* While it is out, its place on the page is empty (the viewer holds the card). */
.lc-stage > .c3d-lifted { visibility: hidden; }

html.c3d-lock, html.c3d-lock body { overflow: hidden; }

/* The viewer: a dimmed, blurred page with the card held in the middle. */
.c3d { position: fixed; inset: 0; z-index: 50; perspective: 1000px; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.c3d[hidden] { display: none; }
.c3d-scrim {
  position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(120% 80% at 50% 45%, rgba(44, 28, 16, 0.42), rgba(22, 13, 7, 0.72));
  -webkit-backdrop-filter: blur(12px) saturate(1.1); backdrop-filter: blur(12px) saturate(1.1);
  transition: opacity 200ms cubic-bezier(0.23, 1, 0.32, 1);
}
.c3d.is-open .c3d-scrim { opacity: 1; transition-duration: 320ms; }

.c3d-obj, .c3d-shadow { position: absolute; left: 50%; top: 50%; width: var(--w); height: var(--h); margin: calc(var(--h) / -2) 0 0 calc(var(--w) / -2); }
.c3d-obj { transform-style: preserve-3d; will-change: transform; cursor: grab; outline: none; }
.c3d-obj:active { cursor: grabbing; }
/* The shadow lies on the page under the card: it grows as the card lifts and slides away from the light. */
.c3d-shadow { border-radius: 50%; opacity: 0; will-change: transform, opacity; background: radial-gradient(closest-side, rgba(8, 4, 1, 0.75), rgba(8, 4, 1, 0.35) 55%, transparent); }

/* The board's thickness: a few card-shaped layers between the two faces, darker than the paper like a cut edge. */
.c3d-edge { position: absolute; inset: 0; border-radius: var(--r); background: #bfa57e; }
.c3d[data-kind=gold] .c3d-edge { background: #b48a3e; }

.c3d-face { position: absolute; inset: 0; border-radius: var(--r); overflow: hidden; -webkit-backface-visibility: hidden; backface-visibility: hidden; isolation: isolate; }
.c3d-front { transform: translateZ(var(--half)); }
.c3d-back { transform: rotateY(180deg) translateZ(var(--half)); }
.c3d-host, .c3d-host > .lc-face, .c3d-host .lc, .c3d-host .mc-wrap { height: 100%; }
.c3d-host .mc { height: 100%; transform: none; animation: none; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), inset 0 -1px 0 rgba(60, 38, 20, 0.18); }

/* The light, transform and opacity only:
   - foil: a rainbow holo printed on the drawing alone (masked by the card's own art), sliding as the card turns;
   - sweep: a broad soft band across the whole board (gold: the foil frame flashes);
   - glare: the bright spot of the room light, moving the other way; shade: the face darkens as it turns away. */
.c3d .c3d-foil { /* over the living card's art, under its words */
  position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  -webkit-mask: var(--art) right center / cover no-repeat, linear-gradient(90deg, transparent 36%, #000 50%);
  -webkit-mask-composite: source-in;
  mask: var(--art) right center / cover no-repeat intersect, linear-gradient(90deg, transparent 36%, #000 50%);
}
.c3d-holo, .c3d-sweep, .c3d-glare { position: absolute; left: -50%; top: -50%; width: 200%; height: 200%; z-index: 5; pointer-events: none; opacity: 0; will-change: transform, opacity; }
.c3d-holo {
  z-index: 0;
  background: repeating-linear-gradient(115deg,
    hsl(350 95% 62%) 0%, hsl(35 100% 58%) 3.5%, hsl(80 85% 52%) 7%, hsl(170 85% 48%) 10.5%, hsl(215 95% 62%) 14%, hsl(275 85% 66%) 17.5%, hsl(350 95% 62%) 21%);
  mix-blend-mode: screen;
  /* Only a diagonal band is iridescent at a time; it travels with the light, the rest keeps the art's own ink. */
  -webkit-mask: linear-gradient(115deg, transparent 22%, #000 40%, #000 60%, transparent 78%); mask: linear-gradient(115deg, transparent 22%, #000 40%, #000 60%, transparent 78%);
}
/* Gold: a warm pearl foil (gold, rose, pale mint) rather than a full rainbow. */
.c3d[data-kind=gold] .c3d-holo {
  background: repeating-linear-gradient(115deg, hsl(42 90% 62%) 0%, hsl(18 85% 70%) 4%, hsl(340 60% 76%) 8%, hsl(150 45% 70%) 12%, hsl(48 95% 66%) 16%, hsl(42 90% 62%) 20%);
}
.c3d-sweep {
  background: linear-gradient(115deg, transparent 38%, rgba(255, 250, 235, 0.55) 47%, rgba(255, 255, 255, 0.75) 50%, rgba(255, 250, 235, 0.55) 53%, transparent 62%);
  mix-blend-mode: soft-light;
}
.c3d-glare { background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.28) 14%, rgba(255, 255, 255, 0) 34%); mix-blend-mode: overlay; }
.c3d-shade { position: absolute; inset: 0; z-index: 6; pointer-events: none; opacity: 0; background: #1a0c04; }
/* Gold: the sweep is warm foil light, strong enough to flash the gold frame and labels. */
.c3d[data-kind=gold] .c3d-sweep {
  background: linear-gradient(115deg, transparent 34%, rgba(255, 226, 150, 0.6) 44%, rgba(255, 252, 235, 0.95) 50%, rgba(255, 226, 150, 0.6) 56%, transparent 66%);
  mix-blend-mode: overlay;
}

.c3d-hint { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 34px); margin: 0; text-align: center; font: 500 0.8125rem/1.3 var(--cc-font-body); letter-spacing: 0.02em; color: #fbf1df; opacity: 0; pointer-events: none; }

/* Reduced motion: the card appears in place with a short fade and goes the same way; dragging still turns it
   (the finger drives it), but it settles without a bounce and the phone's tilt is ignored (card3d.js). */
@media (prefers-reduced-motion: reduce) {
  .c3d { transition: opacity 200ms ease-out; }
  .c3d.is-fading { opacity: 0; }
  .lc-stage.c3d-tappable > .lc-face { transition: none; }
  .lc-stage.c3d-tappable:active:not(:has(.mc-buy:active)) > .lc-face { transform: none; }
  .c3d-reduced-back .c3d-front { visibility: hidden; }
  .c3d-reduced-back .c3d-back { visibility: visible; transform: translateZ(var(--half)); }
  .c3d:not(.c3d-reduced-back) .c3d-back { visibility: hidden; }
}
