/* Motion (P4): screen changes (View Transitions), the fanned hand, the wheel, coins and
   confetti, and table mode. Transform and opacity only. With reduced motion the screens
   simply swap (fx/screens.js skips the transitions) and nothing here moves. */

/* ---------------------------------------------------------------------------------------
   Screen changes. Taps go straight to the new screen while it settles. */
::view-transition {
  pointer-events: none;
}

::view-transition-group(*) {
  animation-duration: var(--dur-screen);
  animation-timing-function: var(--ease-out);
}

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
}

/* Default: a quick cross-fade with a slight settle. */
::view-transition-old(screen) {
  animation: vt-fade-out 160ms var(--ease) both;
}

::view-transition-new(screen) {
  animation: vt-settle-in var(--dur-screen) var(--spring-soft) both;
}

/* Forward through a turn (card to reactions, mirror): the next screen comes from the right,
   the way a dealer slides the next card across. */
html[data-vt='forward']::view-transition-old(screen) {
  animation: vt-left-out 220ms var(--ease-in) both;
}

html[data-vt='forward']::view-transition-new(screen) {
  animation: vt-right-in 420ms var(--spring-soft) both;
}

/* A sheet over the game (shop, truth, dare, wildcard, mini-game): rises from below. */
html[data-vt='sheet']::view-transition-old(screen) {
  animation: vt-dim 260ms var(--ease) both;
}

html[data-vt='sheet']::view-transition-new(screen) {
  animation: vt-rise-in 460ms var(--spring-soft) both;
}

/* Back to the game from a sheet: the sheet drops away. */
html[data-vt='sheet-close']::view-transition-old(screen) {
  animation: vt-drop-out 260ms var(--ease-in) both;
}

html[data-vt='sheet-close']::view-transition-new(screen) {
  animation: vt-fade-in 260ms var(--ease) 60ms both;
}

/* A new turn: the old table clears, the new turn arrives from the picker's side. */
html[data-vt='turn']::view-transition-old(screen) {
  animation: vt-clear-out 220ms var(--ease-in) both;
}

html[data-vt='turn']::view-transition-new(screen) {
  animation: vt-turn-in 520ms var(--spring-soft) both;
}

/* The tapped topic card becomes the question card. */
::view-transition-group(deal-card) {
  animation-duration: 460ms;
  animation-timing-function: var(--ease-out);
}

@keyframes vt-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-fade-in {
  from {
    opacity: 0;
  }
}

@keyframes vt-settle-in {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
}

@keyframes vt-left-out {
  to {
    opacity: 0;
    transform: translateX(-14%);
  }
}

@keyframes vt-right-in {
  from {
    opacity: 0;
    transform: translateX(18%);
  }
}

@keyframes vt-dim {
  to {
    opacity: 0;
    transform: scale(0.96);
  }
}

@keyframes vt-rise-in {
  from {
    opacity: 0;
    transform: translateY(12%);
  }
}

@keyframes vt-drop-out {
  to {
    opacity: 0;
    transform: translateY(14%);
  }
}

@keyframes vt-clear-out {
  to {
    opacity: 0;
    transform: scale(0.94);
  }
}

@keyframes vt-turn-in {
  from {
    opacity: 0;
    transform: translateX(-16%) rotate(-1.5deg);
  }
}

/* ---------------------------------------------------------------------------------------
   The hand fans as it scrolls: cards tilt away from the middle (scroll-driven, so the
   compositor runs it). Without support the cards simply sit in a row. */
@supports (animation-timeline: view()) {
  .hand .topic {
    animation: hand-fan linear both;
    animation-timeline: view(inline);
  }
}

@keyframes hand-fan {
  0% {
    transform: translateY(26px) rotate(17deg);
  }
  50% {
    transform: translateY(-8px) rotate(0deg);
  }
  100% {
    transform: translateY(26px) rotate(-17deg);
  }
}

/* ---------------------------------------------------------------------------------------
   The wheel (fx/wheel.js) */
.wheel-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px var(--pad) calc(24px + env(safe-area-inset-bottom));
  /* solid, so the question cannot be read before the wheel lands */
  background:
    radial-gradient(80% 42% at 50% 46%, rgb(255 170 90 / 0.2) 0%, rgb(0 0 0 / 0) 70%),
    #0d0f24;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.wheel-lead {
  margin: 0 0 30px;
  font-size: 17px;
  color: var(--text-soft);
}

.wheel {
  position: relative;
  width: 300px;
  height: 300px;
  flex: 0 0 auto;
}

.wheel-halo {
  position: absolute;
  inset: -22px;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(0 0 0 / 0) 60%, rgb(255 180 90 / 0.22) 68%, rgb(0 0 0 / 0) 76%);
}

.wheel-disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 2px var(--gold), 0 0 0 9px var(--card), 0 0 0 10px var(--line), 0 30px 70px rgb(0 0 0 / 0.6);
  will-change: transform;
}

.wheel-line {
  position: absolute;
  left: 149px;
  top: 0;
  width: 2px;
  height: 150px;
  background: rgb(244 199 123 / 0.55);
  transform-origin: 1px 150px;
}

.wheel-label {
  position: absolute;
  left: 128px;
  top: 128px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 25px;
  line-height: 1;
}

.wheel-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
}

.wheel-flap {
  position: absolute;
  left: 133px;
  top: -26px;
  width: 34px;
  height: 44px;
  color: var(--gold);
  transform-origin: 17px 14px;
  filter: drop-shadow(0 4px 10px rgb(255 170 80 / 0.7));
}

.wheel-hub {
  position: absolute;
  left: 108px;
  top: 108px;
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 36%, var(--gold-hi) 0%, var(--gold) 48%, var(--gold-deep) 100%);
  box-shadow: 0 0 0 6px var(--card), var(--glow-gold);
  color: var(--gold-ink);
}

.wheel-hub svg {
  width: 22px;
  height: 30px;
}

.wheel-name {
  min-height: 2.3em;
  margin: 40px 0 0;
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.1;
  text-align: center;
  font-variation-settings: 'SOFT' 100, 'opsz' 144;
  opacity: 0;
}

.wheel-hint {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--muted);
}

/* ---------------------------------------------------------------------------------------
   Coins, confetti and score rolls (fx/coins.js, fx/confetti.js) */
#fx {
  position: fixed;
  inset: 0;
  z-index: 35;
  overflow: hidden;
  pointer-events: none;
}

.fx-coin {
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--gold-hi), #e0a04e);
  box-shadow: inset 0 0 0 1.5px #8a5a22, 0 0 14px rgb(255 190 90 / 0.65);
  will-change: transform;
}

.fx-coin.is-spent {
  filter: saturate(0.6);
}

.fx-bit {
  position: absolute;
  left: 0;
  top: 0;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  will-change: transform, opacity;
}

.score-roll {
  position: relative;
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
}

.score-roll > span {
  display: block;
}

.score-roll > .roll-old {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}

/* ---------------------------------------------------------------------------------------
   Table mode: the phone lies flat between the players. Player 2 sits across the table:
   their score strip is turned to face them, and each screen turns to face whoever acts. */
html.table-mode,
html.table-mode body {
  height: 100%;
  overflow: hidden;
}

.table-mode #app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-bottom: 0;
}

.table-mode .scorebar {
  position: relative;
  flex: 0 0 auto;
  background: rgb(13 16 36 / 0.7);
}

.table-mode .strip-far {
  order: 0;
  padding: 10px var(--pad);
  transform: rotate(180deg);
  view-transition-name: strip-far;
}

.table-mode .strip-near {
  order: 2;
  padding: 10px var(--pad) calc(10px + env(safe-area-inset-bottom));
  view-transition-name: scorebar;
}

.table-mode #app > main.screen {
  order: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-top: var(--space-4);
  transition: none;
}

.table-mode #app > main.screen.faces-far {
  transform: rotate(180deg);
}

.table-mode .screen-pick {
  min-height: 0;
}

.table-mode .strip-far .meter,
.table-mode .strip-far .icon-btn {
  display: none;
}

.table-mode .shop-player.faces-far {
  transform: rotate(180deg);
}

/* ---------------------------------------------------------------------------------------
   Reduced motion: nothing moves. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }

  .hand .topic {
    animation: none;
  }
}
