/* ============================================================================================
   MOTION — how UNO PLAY moves.  Loaded last, so it layers on top of style.css and royal.css.

   Rules of thumb used here:
   • Only opacity and the individual transform properties (translate / scale / rotate) are animated.
     They are cheap for the phone's GPU and add on top of each element's own `transform`, so an
     entrance never fights the layout (seats, the fanned hand, the scenery hotspots).
   • Things arrive with a soft overshoot (--spring) and leave quickly (--ease-in): the eye follows
     what comes in, and nothing makes the player wait on the way out.
   • Every entrance has `backwards` fill so it can be staggered with a delay without a flash.
   • Closing animations use `transition-behavior: allow-discrete` (Chrome 117+, Safari 17.4+).
     Older phones simply close instantly, exactly as before.
   • Reduce animations (Settings, or the phone's own setting) switches all of it off.
   ============================================================================================ */
:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --spring-soft: cubic-bezier(0.25, 1.35, 0.5, 1);
}

/* ---------- 1. Touch feedback: every button squeezes a little when pressed ---------- */
button:not(:disabled):active, [role="button"]:active { scale: 0.95; }
button, [role="button"] { transition: scale 0.22s var(--spring); }
button:not(:disabled):active, [role="button"]:active { transition-duration: 0.06s; }
/* Elements that already move on their own keep their own transitions. */
/* Cards already in the hand glide to their new place when the hand re-fans (a card played or drawn). */
.hand .card { transition: left 0.34s var(--ease-out), transform 0.34s var(--ease-out), filter 0.15s, translate 0.22s var(--ease-out), scale 0.22s var(--spring); }
@media (hover: hover) { .hand .card.playable:hover { translate: 0 -10px; } }
.hand .card.playable:active { scale: 0.94; }

/* ---------- 2. Screen changes ---------- */
/* The whole screen fades in; its pieces then arrive in order (top bar, main cards, bottom bar). */
.screen.screen-in { animation: screenFade 0.32s var(--ease-out) both; }
@keyframes screenFade { from { opacity: 0; } }
@keyframes dropIn { from { opacity: 0; translate: 0 -22px; } }
@keyframes riseIn { from { opacity: 0; translate: 0 26px; } }
@keyframes slideInLeft { from { opacity: 0; translate: -36px 0; } }
@keyframes slideInRight { from { opacity: 0; translate: 36px 0; } }
@keyframes popIn2 { 0% { opacity: 0; scale: 0.55; } 70% { opacity: 1; } }
@keyframes cardDeal {
  0% { opacity: 0; scale: 0.4; rotate: -14deg; translate: 0 40px; }
  65% { opacity: 1; scale: 1.06; rotate: 2deg; translate: 0 -4px; }
  100% { opacity: 1; scale: 1; rotate: 0deg; translate: 0 0; }
}

/* Home: top bar drops, the three mode cards are dealt onto the table, the bottom bar rises. */
.screen-in .home-scene #profileChip,
.screen-in .home-scene #wallet,
.screen-in .home-scene #dailyBtn,
.screen-in .home-scene #settingsBtn { animation: dropIn 0.5s var(--ease-out) backwards; }
.screen-in .home-scene #wallet { animation-delay: 0.05s; }
.screen-in .home-scene #dailyBtn { animation-delay: 0.1s; }
.screen-in .home-scene #settingsBtn { animation-delay: 0.15s; }
.screen-in .home-scene #liveBtn { animation: slideInRight 0.5s var(--ease-out) 0.25s backwards; }
.screen-in .home-scene .mode-card { animation: cardBob 4.2s ease-in-out infinite, cardDeal 0.7s var(--spring-soft) backwards; }
.screen-in .home-scene #quickPlayBtn { animation-delay: -0s, 0.12s; }
.screen-in .home-scene #wildBtn { animation-delay: -1.4s, 0.22s; }
.screen-in .home-scene #friendsPlayBtn { animation-delay: -2.8s, 0.32s; }
.screen-in .home-scene #shopBtn,
.screen-in .home-scene #homeFriendsBtn,
.screen-in .home-scene #rulesBtn,
.screen-in .home-scene #historyBtn { animation: riseIn 0.5s var(--ease-out) 0.3s backwards; }
.screen-in .home-scene #homeFriendsBtn { animation-delay: 0.36s; }
.screen-in .home-scene #rulesBtn { animation-delay: 0.42s; }
.screen-in .home-scene #historyBtn { animation-delay: 0.48s; }

/* Play with Friends: the two doors swing in from their sides. */
.screen-in .friends-scene #pwfBack,
.screen-in .friends-scene .pwf-wallet,
.screen-in .friends-scene #pwfLiveBtn { animation: dropIn 0.45s var(--ease-out) backwards; }
.screen-in .friends-scene #joinHouse,
.screen-in .friends-scene .code-boxes,
.screen-in .friends-scene #joinBtn { animation: slideInLeft 0.55s var(--ease-out) 0.08s backwards; }
.screen-in .friends-scene #createHouse,
.screen-in .friends-scene .skin-caption,
.screen-in .friends-scene #createBtn { animation: slideInRight 0.55s var(--ease-out) 0.14s backwards; }
.screen-in .friends-scene .code-boxes, .screen-in .friends-scene #joinBtn { animation-delay: 0.18s; }
.screen-in .friends-scene .skin-caption, .screen-in .friends-scene #createBtn { animation-delay: 0.24s; }

/* Lobby: header slides down, seats pop in one after another, the side panel slides in. */
.screen-in .lb-top, .screen-in .lb-info { animation: dropIn 0.45s var(--ease-out) backwards; }
.screen-in .lb-info { animation-delay: 0.06s; }
.screen-in .side-panel { animation: slideInRight 0.5s var(--ease-out) 0.12s backwards; }
.screen-in .lb-foot { animation: riseIn 0.5s var(--ease-out) 0.18s backwards; }
.screen-in .seat-tile { animation: popIn2 0.5s var(--spring) backwards; animation-delay: calc(0.12s + var(--i, 0) * 0.06s); }

/* ---------- 3. Lobby life ---------- */
/* Someone just sat down: their seat bounces and a ring of light spreads out. */
.seat-tile.seat-pop { animation: seatPop 0.6s var(--spring) both; }
.seat-tile.seat-pop .st-av::after {
  content: ''; position: absolute; inset: -4px; border-radius: inherit; pointer-events: none;
  border: 3px solid #ffe27a; animation: ringOut 0.8s var(--ease-out) forwards;
}
@keyframes seatPop { 0% { scale: 0.6; } 60% { scale: 1.12; } 100% { scale: 1; } }
@keyframes ringOut { from { opacity: 1; scale: 0.9; } to { opacity: 0; scale: 1.5; } }
.seat-tile .st-av { position: relative; }
/* Empty seats breathe gently so they read as "tap me". */
.seat-tile.empty .st-av { animation: seatBreathe 2.4s ease-in-out infinite; }
@keyframes seatBreathe { 50% { border-color: rgba(255, 255, 255, 0.6); background-color: rgba(255, 255, 255, 0.12); } }
.seat-tile.ready-now .ready-badge { animation: readyPop 0.55s var(--spring) both; }
@keyframes readyPop { 0% { scale: 0; rotate: -90deg; } 70% { scale: 1.35; rotate: 8deg; } 100% { scale: 1; rotate: 0deg; } }
/* The ready/start button wakes up when it becomes usable. */
#startBtn:not(:disabled):not(.hidden) { animation: startGlow 1.8s ease-in-out infinite; }
@keyframes startGlow { 50% { box-shadow: 0 0 0 4px rgba(255, 214, 120, 0.35), 0 0 22px rgba(255, 200, 61, 0.7); } }
.seat-menu:not(.hidden) { animation: popIn2 0.22s var(--spring) both; transform-origin: left center; }
.match-status:not(.hidden) { animation: dropIn 0.4s var(--ease-out) backwards; }

/* ---------- 4. Popups, sheets and messages: in and out ---------- */
/* Popups: the dark backdrop fades, the box springs up; on close the box sinks back quickly. */
.modal { transition: opacity 0.2s var(--ease-out), display 0.2s allow-discrete; }
.modal.hidden { opacity: 0; }
@starting-style { .modal:not(.hidden) { opacity: 0; } }
.modal-box { animation: boxIn 0.34s var(--spring-soft) both; transition: scale 0.18s var(--ease-in), translate 0.18s var(--ease-in); }
@keyframes boxIn { from { opacity: 0; scale: 0.88; translate: 0 18px; } }
.modal.hidden .modal-box { scale: 0.92; translate: 0 10px; }
/* Side sheets (settings, friends, chat, stats, store) slide back out the way they came. */
.drawer { transition: opacity 0.2s var(--ease-out), translate 0.24s var(--ease-in), display 0.24s allow-discrete; }
.drawer.hidden { opacity: 0; translate: 48px 0; }
@media (orientation: portrait) and (max-width: 700px) { .drawer.hidden { translate: 0 48px; } }
/* Message toasts float up, and bump when the text changes while one is showing. */
.toast { transition: opacity 0.22s var(--ease-out), translate 0.3s var(--spring), display 0.3s allow-discrete; }
.toast.hidden { opacity: 0; translate: 0 14px; }
@starting-style { .toast:not(.hidden) { opacity: 0; translate: 0 18px; } }
.toast.bump { animation: toastBump 0.3s var(--spring); }
@keyframes toastBump { 40% { scale: 1.06; } }
.conn:not(.hidden) { animation: dropIn 0.35s var(--ease-out) backwards; }

/* ---------- 5. Coins, gems and levels ---------- */
.pill.bump, .skin-chip .level.bump { animation: pillBump 0.45s var(--spring); }
@keyframes pillBump { 30% { scale: 1.18; filter: brightness(1.35); } }
.coin-flyer {
  position: fixed; z-index: 60; left: 0; top: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px; pointer-events: none;
  display: grid; place-items: center; border-radius: 50%; font: 900 14px/1 system-ui, sans-serif; color: #a86b00;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #ffc83d 60%, #b8860b);
  box-shadow: inset 0 0 0 2px #e0a100, 0 3px 8px rgba(0, 0, 0, 0.45); will-change: transform, opacity;
}
.level-up {
  position: fixed; z-index: 60; left: 50%; top: 38%; translate: -50% -50%; pointer-events: none; text-align: center;
  font: 900 italic clamp(28px, 7vw, 54px)/1 'Arial Black', system-ui, sans-serif; color: #ffe27a; letter-spacing: 0.04em;
  -webkit-text-stroke: 2px #6b3a00; text-shadow: 0 4px 0 #b8580b, 0 10px 24px rgba(0, 0, 0, 0.5);
  animation: levelUp 2.2s var(--ease-out) forwards;
}
.level-up small { display: block; margin-top: 6px; font: 800 clamp(13px, 2.4vw, 18px)/1.2 system-ui, sans-serif; -webkit-text-stroke: 0; color: #fff; letter-spacing: 0.08em; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }
@keyframes levelUp { 0% { opacity: 0; scale: 0.3; } 18% { opacity: 1; scale: 1.15; } 30% { scale: 1; } 80% { opacity: 1; } 100% { opacity: 0; translate: -50% -80%; } }

/* ---------- 6. The table ---------- */
/* A new game: the players' seats pop in around the table, the deck drops onto the felt. */
.game.deal-in .seat.opp { animation: popIn2 0.5s var(--spring) backwards; animation-delay: calc(0.08s + var(--i, 0) * 0.08s); }
.game.deal-in .deck-wrap { animation: deckDrop 0.6s var(--spring-soft) backwards; }
.game.deal-in .discard { animation: popIn2 0.45s var(--spring) 0.5s backwards; }
.game.deal-in #meSeat { animation: riseIn 0.5s var(--ease-out) 0.3s backwards; }
.game.deal-in .game-bar { animation: dropIn 0.45s var(--ease-out) backwards; }
@keyframes deckDrop { 0% { opacity: 0; translate: 0 -60px; scale: 1.25; } 70% { opacity: 1; } }
/* Card counts bump when they change: red when a player picks up, green when they get closer to winning. */
.seat .count.up { animation: countUp 0.7s var(--spring); }
.seat .count.down { animation: countDown 0.5s var(--spring); }
@keyframes countUp { 30% { scale: 1.6; background: #ff5a5a; color: #fff; } }
@keyframes countDown { 30% { scale: 1.35; background: #4ade80; color: #06300f; } }
/* The UNO button arrives with a bounce. */
.uno-btn:not(.hidden) { animation: unoArrive 0.5s var(--spring) backwards; }
@keyframes unoArrive { from { opacity: 0; scale: 0.3; rotate: -20deg; } }
.drawn-panel:not(.hidden) { animation: riseIn 0.35s var(--spring-soft) backwards; }

/* ---------- 7. Results ---------- */
#winner:not(.hidden) #resultsList li { animation: riseIn 0.45s var(--ease-out) backwards; animation-delay: calc(0.3s + var(--i, 0) * 0.09s); }
#winner:not(.hidden) #winnerText { animation: titleBounce 0.7s var(--spring) 0.1s backwards; }
@keyframes titleBounce { 0% { opacity: 0; scale: 0.4; } 60% { opacity: 1; scale: 1.12; } 100% { scale: 1; } }
#winner.victory:not(.hidden) .modal-box { animation: boxIn 0.4s var(--spring-soft) both, victoryGlow 2.4s ease-in-out 0.4s infinite; }
@keyframes victoryGlow { 50% { box-shadow: 0 0 60px rgba(255, 200, 61, 0.55), 0 24px 60px rgba(0, 0, 0, 0.7); } }

/* ---------- 8. Daily reward ---------- */
#dailyModal:not(.hidden) #dailyDays li { animation: popIn2 0.4s var(--spring) backwards; animation-delay: calc(0.08s + var(--i, 0) * 0.05s); }
#dailyModal #dailyDays li.today:not(.done) { animation: popIn2 0.4s var(--spring) backwards, todayPulse 1.4s ease-in-out 0.6s infinite; animation-delay: calc(0.08s + var(--i, 0) * 0.05s), 0.6s; }
@keyframes todayPulse { 50% { scale: 1.07; filter: brightness(1.12); } }
#dailyModal #dailyDays.settled li { animation: none; }
#dailyModal #dailyDays li.claimed-now { animation: claimFlip 0.6s var(--spring) both; }
@keyframes claimFlip { 0% { rotate: y 0deg; } 50% { rotate: y 90deg; scale: 1.1; } 100% { rotate: y 0deg; scale: 1; } }

/* ---------- 9. In-game confirm popup ---------- */
.confirm-box { width: min(360px, 100%); gap: 12px; }
.confirm-box h3 { font-size: 1.15rem; font-weight: 900; }
.confirm-box p { margin: 0; line-height: 1.4; }
.confirm-box .confirm-actions { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.confirm-box .confirm-actions .btn { flex: 1; max-width: 160px; }
.confirm-box .btn.danger { background: linear-gradient(180deg, #ff6b5e, #d22d23); color: #fff; border-color: transparent; }

/* ---------- 10. Reduce animations ---------- */
/* Turned on in Settings, or automatically when the phone asks for less motion. Movement stops;
   quick fades remain so nothing appears or disappears with a jarring jump. */
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation-duration: 0.01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important;
}
html.reduce-motion .scene-fx, html.reduce-motion .game-sky, html.reduce-motion .rim-fx { display: none; }

/* Drawn coin (the 🪙 emoji is missing on Android 10 and older) */
.coin-face.inline.big { font-size: 1.6em; }
.switch-note { display: block; font-size: 0.74rem; font-weight: 500; margin-top: 2px; }

/* ---------- 11. Lists that slide in row by row (stats, badges, rules) ---------- */
.stagger > * { animation: riseIn 0.4s var(--ease-out) backwards; }
.stagger > :nth-child(2) { animation-delay: 0.04s; }
.stagger > :nth-child(3) { animation-delay: 0.08s; }
.stagger > :nth-child(4) { animation-delay: 0.12s; }
.stagger > :nth-child(5) { animation-delay: 0.16s; }
.stagger > :nth-child(6) { animation-delay: 0.2s; }
.stagger > :nth-child(7) { animation-delay: 0.24s; }
.stagger > :nth-child(8) { animation-delay: 0.28s; }
.stagger > :nth-child(9) { animation-delay: 0.32s; }
.stagger > :nth-child(n+10) { animation-delay: 0.36s; }
