/* ---------- Living cabinet portraits and the flipping prize sign ----------

   The owner's 2026-10-17 request, with a recording of Heart of Vegas's
   lobby beside one of ours: the frames had the motion and the paintings
   none, so the art no longer stood out. As in that lobby, the painting
   itself now moves and the prize signs give it room.

   The portrait (js/lobby.js cabinetStage) sits in a box of the source's own
   1:2 shape and 28% crop (`.game-card-portrait`, laid out in the stage's
   container units exactly as `object-fit: cover` would place the picture),
   so a layer given in the source's pixels lands on the same spot of the
   painting at every phone height. The box drifts and zooms slowly
   (always at least the window's size, so no edge shows), staggered card to
   card. A machine's `artLayers` ride along inside it: discs of the same
   painting that spin or swell in place, masked soft at their rims, and
   sideways-drifting curtains and gold glints. Everything is a transform
   or an opacity of a box of its own, so WebKit composites it without
   repainting, except a living subject's stepped frames (`artHero`, below).
   It runs on playable
   cards in view while the floor is uncovered and shows (the same gates as
   the bulbs), never on a card coming soon, and stops under reduced motion.

   The two prize signs share one place over the portrait: GRAND, then MAJOR
   (or the machine's own two prizes), crossfading every few seconds like
   the reference's header, where a sign alone would take a second row. */

.game-list > .game-card { will-change: transform; }

.game-card-stage {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  border-radius: inherit;
  container-type: size;
  background-color: var(--cabinet-glass);
  background-image: radial-gradient(ellipse at 50% 28%, var(--c-dark), var(--cabinet-glass) 85%);
  pointer-events: none;
}

.game-card-portrait {
  --portrait-w: max(100cqw, 50cqh);
  --drift-period: 18s;
  --drift-delay: -4s;
  position: absolute;
  display: block;
  left: calc((100cqw - var(--portrait-w)) / 2);
  top: calc((100cqh - var(--portrait-w) * 2) * .28);
  width: var(--portrait-w);
  height: calc(var(--portrait-w) * 2);
  opacity: 0;
  transition: opacity 150ms ease-out;
  transform-origin: 50% 30%;
  animation: cabinet-drift var(--drift-period) linear var(--drift-delay) infinite alternate;
  animation-play-state: paused;
}
.card-portrait-ready .game-card-portrait { opacity: 1; }
.game-card-portrait > .game-card-picture { position: absolute; inset: 0; }

.game-list > .game-card:nth-child(4n + 2) .game-card-portrait { --drift-period: 21s; --drift-delay: -11s; }
.game-list > .game-card:nth-child(4n + 3) .game-card-portrait { --drift-period: 16s; --drift-delay: -7s; }
.game-list > .game-card:nth-child(4n) .game-card-portrait { --drift-period: 23s; --drift-delay: -15s; }

@keyframes cabinet-drift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-3%, 2.2%) scale(1.08); }
  100% { transform: translate(3%, -3%) scale(1.06); }
}

@property --cabinet-parallax {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .game-card-brand { will-change: transform; }
  .lobby-motion-active .game-card:not(.soon) .game-card-portrait {
    translate: calc(var(--cabinet-parallax, 0) * 1%);
    scale: calc(1 + max(var(--cabinet-parallax, 0), -1 * var(--cabinet-parallax, 0)) * .02);
  }
  .lobby-motion-active .game-card:not(.soon) .game-card-breakout > img {
    translate: calc(var(--cabinet-parallax, 0) * -.3px);
  }
  .lobby-motion-active .game-card:not(.soon) :is(.game-card-portrait, .game-card-breakout > img):not(.cabinet-parallax) {
    transition: opacity 150ms ease-out, translate 140ms ease-out, scale 140ms ease-out;
  }
}

.game-card-layer {
  position: absolute;
  display: block;
  pointer-events: none;
  animation-play-state: paused;
}

.game-card-layer:is(.spin, .pulse) {
  background-repeat: no-repeat;
  border-radius: 50%;
  -webkit-mask-image: radial-gradient(closest-side, #000 56%, transparent);
  mask-image: radial-gradient(closest-side, #000 56%, transparent);
}
.game-card-layer.spin {
  -webkit-mask-image: radial-gradient(closest-side, #000 22%, #0000 100%);
  mask-image: radial-gradient(closest-side, #000 22%, #0000 100%);
}

.game-card-layer.spin { animation: cabinet-layer-spin var(--layer-period, 30s) linear infinite; }

.game-card-layer.pulse { animation: cabinet-layer-pulse var(--layer-period, 2.8s) ease-in-out infinite alternate; }
.game-card-layer.pulse::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(closest-side, #fff6d0aa, #ffd47a44 50%, transparent);
  opacity: .05;
  animation: cabinet-layer-bloom var(--layer-period, 2.8s) ease-in-out infinite alternate;
  animation-play-state: paused;
}

.game-card-layer.drift {
  --curtain-sway: calc(var(--portrait-w) / 64);
  background-repeat: no-repeat;
  -webkit-mask-image: radial-gradient(ellipse, #000 24%, #000b 48%, transparent 72%);
  mask-image: radial-gradient(ellipse, #000 24%, #000b 48%, transparent 72%);
  animation: cabinet-layer-curtain var(--layer-period, 12s) ease-in-out infinite alternate;
}

@keyframes cabinet-layer-curtain {
  from { transform: translateX(calc(-1 * var(--curtain-sway))); }
  to { transform: translateX(var(--curtain-sway)); }
}

.game-card-layer.glint {
  width: 9%;
  aspect-ratio: 1;
  margin: -4.5% 0 0 -4.5%;
  background: radial-gradient(circle, #fff 0 12%, var(--gold-light) 26%, var(--gold) 50%);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  transform: scale(.001);
  animation: cabinet-layer-glint var(--layer-period, 6.4s) ease-in-out infinite;
  animation-delay: calc(var(--layer-index) * 1.3s);
}

@keyframes cabinet-layer-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(-360deg); }
}
@keyframes cabinet-layer-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}
@keyframes cabinet-layer-bloom {
  from { opacity: .05; }
  to { opacity: .9; }
}
@keyframes cabinet-layer-glint {
  0% { transform: scale(.001) rotate(-45deg); }
  6% { transform: scale(1) rotate(0deg); }
  12%, 100% { transform: scale(.001) rotate(45deg); }
}

@property --hero-progress {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

.game-card-hero {
  --hero-pose: min(var(--hero-progress), calc(14 - var(--hero-progress)));
  --hero-lower: round(down, var(--hero-pose), 1);
  --hero-upper: min(7, calc(var(--hero-lower) + 1));
  --hero-blend: calc(var(--hero-pose) - var(--hero-lower));
  position: absolute;
  display: block;
  pointer-events: none;
  isolation: isolate;
}
.game-card-hero::before,
.game-card-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--hero-strip, none);
  background-repeat: no-repeat;
  background-size: 800% 100%;
}
.game-card-hero::before {
  background-position: calc(var(--hero-lower) * 100% / 7) 0;
  opacity: calc(1 - var(--hero-blend));
}
.game-card-hero::after {
  background-position: calc(var(--hero-upper) * 100% / 7) 0;
  opacity: var(--hero-blend);
  mix-blend-mode: plus-lighter;
}
.game-card-hero.hero-loop {
  --hero-cadence: linear;
  --hero-pose: calc(var(--hero-progress) * 8 / 14);
  --hero-lower: mod(round(down, var(--hero-pose), 1), 8);
  --hero-upper: mod(calc(var(--hero-lower) + 1), 8);
  --hero-blend: calc(var(--hero-pose) - round(down, var(--hero-pose), 1));
}
@media (prefers-reduced-motion: no-preference) {
  body:not(.scene-motion-paused) .lobby.lobby-motion-active .game-card.card-motion-in-view:not(.soon) .game-card-hero {
    animation: cabinet-hero var(--hero-duration, 7s) var(--hero-cadence, linear(0, 0 10%, 1 90%, 1)) infinite;
  }
}
@keyframes cabinet-hero {
  to { --hero-progress: 14; }
}

.game-card.has-breakout { overflow: visible; }
.game-card-breakout {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  clip-path: polygon(0 -44px, 100% -44px, 100% calc(100% + 44px),
    0 calc(100% + 44px), 0 100%, calc(100% - 3px) 100%,
    calc(100% - 3px) 10px, calc(100% - 14px) 0, 0 0);
}
.game-card-breakout > img {
  position: absolute;
  display: block;
  right: 0;
  top: calc(-1 * clamp(13px, 6cqh, 23px) - 16px);
  width: 40cqw;
  max-width: 68px;
  height: auto;
  pointer-events: none;
  animation: cabinet-cutout-float 6s ease-in-out infinite alternate;
  animation-play-state: paused;
}
@media (max-height: 700px) {
  .game-card-breakout > img { top: calc(-1 * clamp(13px, 6cqh, 23px) - 13px); }
}
@container (max-height: 280px) {
  .game-card-breakout > img { top: -26px; }
}
.game-list > .game-card:nth-child(2n) .game-card-breakout > img { animation-delay: -3s; }
@keyframes cabinet-cutout-float {
  from { transform: translateY(0); }
  to { transform: translateY(-2px); }
}

.game-card-portrait .game-card-layer,
.game-card-portrait .game-card-layer::after { animation-play-state: paused; }
.lobby.lobby-motion-active .game-card.card-motion-in-view:not(.soon) :is(.game-card-portrait, .game-card-layer, .game-card-breakout > img),
.lobby.lobby-motion-active .game-card.card-motion-in-view:not(.soon) .game-card-layer::after {
  animation-play-state: running;
}
.game-card.soon :is(.game-card-portrait, .game-card-layer) { animation: none; }
body.scene-motion-paused .lobby :is(.game-card-portrait, .game-card-layer, .game-card-breakout > img),
body.scene-motion-paused .lobby .game-card-layer::after {
  animation-play-state: paused !important;
}

/* One sign's place, two signs taking turns. Opacity holds near, never
   exactly at, a value (no two keyframes in a row alike: WebKit repaints a
   layer leaving a flat stretch while another animation runs). A sign that
   flares (css/lobby.css "Live jackpots") keeps its turn: its flip is the
   same animation, so it carries on with the flare beside it. */
.game-card-prizes {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
@media (prefers-reduced-motion: no-preference) {
  .lobby.lobby-motion-active .game-card.card-in-view .game-card-prizes {
    perspective: 540px;
  }
  .lobby.lobby-motion-active .game-card.card-in-view .game-card-prizes > .game-card-jackpot {
    backface-visibility: hidden;
  }
}
.game-card-prizes > .game-card-jackpot {
  --sign-flip: 8s linear var(--sign-delay, -0.3s) infinite;
  grid-area: 1 / 1;
  transform-origin: 50% 50%;
}
.game-card-prizes > .game-card-jackpot.major { margin: 0; }
.game-card-prizes > .game-card-jackpot.grand { animation: cabinet-sign-first var(--sign-flip); }
.game-card-prizes > .game-card-jackpot.major { opacity: 0; animation: cabinet-sign-second var(--sign-flip); }
.game-card-prizes > .game-card-jackpot.grand.flare { animation: cabinet-sign-first var(--sign-flip), lobby-plaque-flare 1.2s ease-out; }
.game-card-prizes > .game-card-jackpot.major.flare { animation: cabinet-sign-second var(--sign-flip), lobby-plaque-flare 1.2s ease-out; }
.game-list > .game-card:nth-child(5n + 2) .game-card-jackpot { --sign-delay: -1.9s; }
.game-list > .game-card:nth-child(5n + 3) .game-card-jackpot { --sign-delay: -3.5s; }
.game-list > .game-card:nth-child(5n + 4) .game-card-jackpot { --sign-delay: -1.1s; }
.game-list > .game-card:nth-child(5n) .game-card-jackpot { --sign-delay: -2.7s; }

@keyframes cabinet-sign-first {
  0% { opacity: 1; rotate: x 0deg; filter: brightness(1.18); }
  1.5% { filter: brightness(1.28); }
  6% { filter: brightness(1); }
  45% { opacity: .995; rotate: x 0deg; animation-timing-function: ease-in; }
  47.1% { opacity: .95; }
  47.5% { opacity: 0; rotate: x 90deg; animation-timing-function: step-end; }
  50% { opacity: .005; rotate: x 0deg; }
  95% { opacity: .002; rotate: x 0deg; animation-timing-function: step-end; }
  97.5% { opacity: 0; rotate: x -90deg; animation-timing-function: ease-out; filter: brightness(1.003); }
  97.9% { opacity: .95; }
  100% { opacity: 1; rotate: x 0deg; filter: brightness(1.18); }
}
@keyframes cabinet-sign-second {
  0% { opacity: .005; rotate: x 0deg; filter: brightness(1.0015); }
  45% { opacity: .002; rotate: x 0deg; animation-timing-function: step-end; }
  47.5% { opacity: 0; rotate: x -90deg; animation-timing-function: ease-out; filter: brightness(1.003); }
  47.9% { opacity: .95; }
  50% { opacity: 1; rotate: x 0deg; filter: brightness(1.18); }
  51.5% { filter: brightness(1.28); }
  56% { filter: brightness(1); }
  95% { opacity: .995; rotate: x 0deg; animation-timing-function: ease-in; }
  97.1% { opacity: .95; }
  97.5% { opacity: 0; rotate: x 90deg; animation-timing-function: step-end; }
  100% { opacity: .005; rotate: x 0deg; filter: brightness(1.0015); }
}

.lobby .game-card:not(.card-motion-in-view) .game-card-prizes > .game-card-jackpot,
.lobby .game-card:not(.card-motion-in-view) .game-card-prizes > .game-card-jackpot.flare::after { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .game-card-breakout > img,
  .game-card-portrait,
  .game-card-portrait .game-card-layer,
  .game-card-portrait .game-card-layer::after { animation: none; }
  .game-card-portrait { transition: none; }
  .game-card-portrait .game-card-layer.glint { opacity: 0; }
  .game-card-prizes > .game-card-jackpot { --sign-flip: 8s step-end var(--sign-delay, -0.3s) infinite; }
  .game-card-prizes > .game-card-jackpot.grand.flare { animation: cabinet-sign-first var(--sign-flip); }
  .game-card-prizes > .game-card-jackpot.major.flare { animation: cabinet-sign-second var(--sign-flip); }
  @keyframes cabinet-sign-first {
    0% { opacity: 1; }
    50% { opacity: 0; }
    100% { opacity: 1; }
  }
  @keyframes cabinet-sign-second {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
  }
}

.lobby:not(.lobby-motion-active) .game-card .game-card-prizes > .game-card-jackpot,
.lobby:not(.lobby-motion-active) .game-card .game-card-prizes > .game-card-jackpot.flare::after { animation: none; }
