:root {
  --tw-motion-out: cubic-bezier(0.22, 1, 0.36, 1);
  --tw-motion-soft: cubic-bezier(0.2, 0.72, 0.22, 1);
}

/* Entrance: one calm sequence, preserving the published composition. */
body.motion-polish-enabled.home-landing-state .home-topbar {
  animation: tw-polish-fade-down 400ms var(--tw-motion-out) both;
}

body.motion-polish-enabled.home-landing-state .home-heading {
  animation: tw-polish-title-in 540ms var(--tw-motion-out) 60ms both;
}

body.motion-polish-enabled.home-landing-state .home-subcopy {
  animation: tw-polish-fade-up 440ms var(--tw-motion-out) 120ms both;
}

body.motion-polish-enabled.home-landing-state .home-card-shell img {
  --tw-polish-card-x: 0px;
  --tw-polish-card-y: 0px;
  animation: tw-polish-card-reveal 680ms var(--tw-motion-out) 150ms both;
  transform: translate3d(var(--tw-polish-card-x), var(--tw-polish-card-y), 0);
  will-change: transform;
}

body.motion-polish-enabled.home-landing-state .home-start-button {
  animation: tw-polish-button-in 500ms var(--tw-motion-out) 250ms both !important;
  transition:
    transform 150ms var(--tw-motion-out),
    filter 180ms ease,
    box-shadow 180ms ease !important;
}

@media (hover: hover) and (pointer: fine) {
  body.motion-polish-enabled.home-landing-state .home-start-button:hover {
    transform: translateX(-50%) translateY(-2px) scale(1.012) !important;
  }

  body.motion-polish-enabled .meaning-entry-button:hover .meaning-entry-image img {
    transform: scale(1.018);
  }
}

body.motion-polish-enabled.home-landing-state .home-start-button:active {
  transform: translateX(-50%) scale(0.97) !important;
  transition-duration: 100ms !important;
}

body.motion-polish-enabled .primary-button:active,
body.motion-polish-enabled .ghost-button:active,
body.motion-polish-enabled .mode-button:active,
body.motion-polish-enabled .filter-button:active,
body.motion-polish-enabled .draw-mode-tab:active,
body.motion-polish-enabled .spread-picker-option:active,
body.motion-polish-enabled .meaning-entry-button:active {
  transform: translateY(0) scale(0.97) !important;
  transition-duration: 100ms !important;
}

/* A short light veil turns the homepage-to-table hard cut into one scene change. */
body.motion-polish-enabled.is-entering-desk .app-shell::after {
  animation: tw-polish-desk-veil 490ms var(--tw-motion-out) both !important;
}

/* Keep the published long-form deal; only refine the chosen-card response. */
@media (min-width: 900px) {
  body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.tw-eleven-grid.is-reveal-pending .tw-eleven-layer .deck-card.is-picked {
    animation: tw-polish-picked-reveal 480ms var(--tw-motion-out) both !important;
  }

  body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.is-reveal-pending .deck-card.is-picked img:not(.deck-card-back):not(.deck-card-face),
  body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.is-reveal-pending .deck-card.is-picked::after {
    animation: none !important;
  }
}

/* Result hierarchy: status, card, then copy. Opacity always settles at 1. */
body.motion-polish-enabled .completed-reading-head {
  animation: tw-polish-fade-down 320ms var(--tw-motion-out) both !important;
}

body.motion-polish-enabled .completed-reading-card {
  opacity: 1;
  animation: tw-polish-result-in 480ms var(--tw-motion-out) both !important;
  animation-delay: calc(min(var(--i, 0), 4) * 48ms) !important;
}

body.motion-polish-enabled .completed-reading-copy,
body.motion-polish-enabled .reading-panel-content {
  opacity: 1;
  animation: tw-polish-fade-up 380ms var(--tw-motion-out) 70ms both;
}

/* Dialogs are spatial but fast. */
body.motion-polish-enabled dialog[open] {
  animation: tw-polish-dialog-in 230ms var(--tw-motion-out) both !important;
}

body.motion-polish-enabled dialog[open]::backdrop {
  animation: tw-polish-backdrop-in 170ms ease both;
}

body.motion-polish-enabled[data-page="meanings"] .meaning-entry-image img {
  transition: transform 260ms var(--tw-motion-out), filter 220ms ease !important;
}

body.motion-polish-enabled.motion-paused *,
body.motion-polish-enabled.motion-paused *::before,
body.motion-polish-enabled.motion-paused *::after {
  animation-play-state: paused !important;
}

@keyframes tw-polish-fade-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes tw-polish-fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes tw-polish-title-in {
  from { opacity: 0; filter: blur(5px); transform: translateY(12px) scale(0.985); }
  to { opacity: 1; filter: blur(0); transform: translateY(0) scale(1); }
}

@keyframes tw-polish-card-reveal {
  from { opacity: 0; filter: brightness(0.72) blur(5px); clip-path: inset(8% 5% 8% 5% round 12px); }
  to { opacity: 1; filter: brightness(1) blur(0); clip-path: inset(0 0 0 0 round 12px); }
}

@keyframes tw-polish-button-in {
  from { opacity: 0; filter: blur(3px); transform: translateX(-50%) translateY(12px) scale(0.97); }
  to { opacity: 1; filter: blur(0); transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes tw-polish-desk-veil {
  0% { opacity: 0; }
  38% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes tw-polish-picked-reveal {
  0% {
    filter: brightness(1) saturate(1);
    transform:
      translate(calc(-50% + var(--tw-x, 0px)), var(--tw-y, 0px))
      rotate(var(--tw-tilt, 0deg))
      scale(var(--tw-scale, 1));
  }
  56% {
    filter: brightness(1.1) saturate(1.08);
    transform:
      translate(calc(-50% + var(--tw-x, 0px)), calc(var(--tw-y, 0px) - 30px))
      rotate(var(--tw-tilt, 0deg))
      scale(1.1);
    box-shadow:
      0 30px 52px rgba(0, 0, 0, 0.56),
      0 0 36px rgba(255, 216, 98, 0.58),
      0 0 74px rgba(255, 211, 84, 0.2);
  }
  100% {
    filter: brightness(1.08) saturate(1.06);
    transform:
      translate(calc(-50% + var(--tw-x, 0px)), calc(var(--tw-y, 0px) - 24px))
      rotate(var(--tw-tilt, 0deg))
      scale(1.08);
  }
}

@keyframes tw-polish-result-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes tw-polish-dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes tw-polish-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (hover: none), (pointer: coarse) {
  body.motion-polish-enabled .home-start-button:hover,
  body.motion-polish-enabled .deck-card:hover:not(:disabled),
  body.motion-polish-enabled .meaning-entry:hover {
    filter: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.motion-polish-enabled *,
  body.motion-polish-enabled *::before,
  body.motion-polish-enabled *::after {
    scroll-behavior: auto !important;
  }

  body.motion-polish-enabled.motion-reduced .home-topbar,
  body.motion-polish-enabled.motion-reduced .home-heading,
  body.motion-polish-enabled.motion-reduced .home-subcopy,
  body.motion-polish-enabled.motion-reduced .home-card-shell,
  body.motion-polish-enabled.motion-reduced .home-card-shell img,
  body.motion-polish-enabled.motion-reduced .home-start-button,
  body.motion-polish-enabled.motion-reduced .completed-reading-head,
  body.motion-polish-enabled.motion-reduced .completed-reading-card,
  body.motion-polish-enabled.motion-reduced .completed-reading-copy,
  body.motion-polish-enabled.motion-reduced .reading-panel-content,
  body.motion-polish-enabled.motion-reduced dialog[open],
  body.motion-polish-enabled.motion-reduced dialog[open]::backdrop {
    animation: none !important;
    opacity: 1 !important;
    filter: none !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

}

/* Reveal ritual: selected backs turn away, the real faces arrive in chosen order. */
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .deck-card {
  perspective: 760px;
  transform-style: preserve-3d;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .deck-card .deck-card-back {
  position: relative;
  z-index: 2;
  backface-visibility: hidden;
  transform-origin: 50% 50%;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .deck-card .deck-card-face {
  position: absolute !important;
  inset: 4px !important;
  z-index: 3;
  width: calc(100% - 8px) !important;
  height: calc(100% - 8px) !important;
  aspect-ratio: 463 / 760;
  border-radius: 4px !important;
  object-fit: cover !important;
  opacity: 0;
  backface-visibility: hidden;
  transform: rotateY(78deg) scale(0.96);
  transform-origin: 50% 50%;
  filter: brightness(0.76) saturate(0.88);
}

/* The original deal runs only once. After selection starts, keep the deck still
   so each click belongs only to the newly chosen card. */
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.tw-eleven-grid.has-selection .tw-eleven-layer .deck-card,
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.tw-eleven-grid.has-selection.is-reveal-pending .tw-eleven-layer .deck-card.is-picked,
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.mobile-four-row-grid.has-selection .deck-card,
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.mobile-four-row-grid.has-selection.is-reveal-pending .deck-card.is-picked {
  animation: none !important;
  animation-delay: 0ms !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid .deck-card.is-face-entering .deck-card-back {
  animation: tw-polish-card-back-away 420ms cubic-bezier(0.77, 0, 0.175, 1) both !important;
  animation-delay: 0ms !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid .deck-card.is-face-entering .deck-card-face {
  animation: tw-polish-card-face-arrive 460ms var(--tw-motion-out) both !important;
  animation-delay: 35ms !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid .deck-card.is-face-settled .deck-card-back {
  opacity: 0 !important;
  transform: rotateY(-88deg) scale(0.95) !important;
  animation: none !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid .deck-card.is-face-settled .deck-card-face {
  opacity: 1 !important;
  transform: rotateY(0deg) scale(1) !important;
  filter: none !important;
  animation: none !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.is-reveal-pending .deck-card:not(.is-picked) {
  opacity: 0.34 !important;
  filter: brightness(0.64) saturate(0.74) !important;
  transition: opacity 260ms ease, filter 260ms ease !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .selection-grid.is-reveal-pending .deck-card:not(.is-picked):disabled {
  opacity: 0.32 !important;
  filter: brightness(0.62) saturate(0.72) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .deck-card.is-face-entering .deck-card-number {
  animation: tw-polish-seal-confirm 420ms var(--tw-motion-out) both;
  animation-delay: 0ms;
}

/* One card: image establishes the focus, meaning follows as a separate layer. */
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-board.is-single-reading .completed-reading-card {
  opacity: 1;
  animation: none !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-board.is-single-reading .completed-reading-art {
  animation: tw-polish-single-art-arrive 660ms var(--tw-motion-out) 20ms both !important;
  transform-origin: 50% 72%;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-board.is-single-reading .completed-reading-copy {
  animation: tw-polish-single-meaning-arrive 560ms var(--tw-motion-out) 150ms both !important;
}

/* Three cards: preserve reading order and keep the stagger short enough not to block. */
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-grid.is-multi .completed-reading-card {
  opacity: 1;
  animation: tw-polish-three-card-arrive 520ms var(--tw-motion-out) both !important;
  animation-delay: calc(var(--i, 0) * 82ms) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-grid.is-multi .completed-reading-art {
  animation: tw-polish-three-art-unveil 560ms var(--tw-motion-out) both !important;
  animation-delay: calc(40ms + var(--i, 0) * 82ms) !important;
  transform-origin: 50% 78%;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-grid.is-multi .completed-reading-copy {
  animation: tw-polish-three-meaning-arrive 480ms var(--tw-motion-out) both !important;
  animation-delay: calc(170ms + var(--i, 0) * 82ms) !important;
}

@keyframes tw-polish-card-back-away {
  0%, 18% {
    opacity: 1;
    transform: rotateY(0deg) scale(1);
    filter: brightness(1) saturate(1);
  }
  64% {
    opacity: 0.36;
    transform: rotateY(-68deg) scale(0.97);
    filter: brightness(1.16) saturate(1.08);
  }
  100% {
    opacity: 0;
    transform: rotateY(-88deg) scale(0.95);
    filter: brightness(0.8) saturate(0.88);
  }
}

/* Reading contrast: keep the celestial texture around the cards, not through
   the copy. The surface stays green-black instead of becoming a flat black box. */
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-grid.is-multi .completed-reading-card {
  background-color: rgba(4, 13, 10, 0.94) !important;
  border-color: rgba(224, 180, 78, 0.38) !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 174, 0.05),
    inset 0 0 52px rgba(0, 0, 0, 0.18),
    0 20px 54px rgba(0, 0, 0, 0.32) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-grid.is-multi .completed-reading-card:hover,
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-grid.is-multi .completed-reading-card:focus-within {
  background:
    radial-gradient(ellipse at 50% 14%, rgba(255, 213, 91, 0.1), transparent 42%),
    linear-gradient(180deg, rgba(255, 232, 154, 0.05), transparent 46%),
    rgba(5, 14, 10, 0.95) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-board.is-single-reading .completed-reading-copy {
  background-color: rgba(4, 13, 10, 0.94) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-copy .slot-label {
  color: rgba(109, 205, 183, 0.98) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-copy h3 {
  color: #fff0c8 !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-copy .meta {
  color: rgba(255, 215, 124, 0.98) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-copy p:not(.meta):not(.completed-reading-keywords),
body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-guidance p {
  color: rgba(247, 238, 215, 0.9) !important;
}

body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .completed-reading-keywords span {
  background-color: rgba(7, 15, 11, 0.9) !important;
}

@keyframes tw-polish-card-face-arrive {
  0%, 18% {
    opacity: 0;
    transform: rotateY(78deg) scale(0.96);
    filter: brightness(0.76) saturate(0.88);
  }
  58% {
    opacity: 1;
    transform: rotateY(-5deg) scale(1.035);
    filter: brightness(1.16) saturate(1.08);
  }
  100% {
    opacity: 1;
    transform: rotateY(0deg) scale(1);
    filter: brightness(1) saturate(1);
  }
}

@keyframes tw-polish-seal-confirm {
  0% { opacity: 0.4; transform: translate(34%, -38%) rotate(var(--badge-counter-tilt, 0deg)) scale(0.88); }
  58% { opacity: 1; transform: translate(34%, -38%) rotate(var(--badge-counter-tilt, 0deg)) scale(1.08); }
  100% { opacity: 1; transform: translate(34%, -38%) rotate(var(--badge-counter-tilt, 0deg)) scale(1); }
}

@keyframes tw-polish-single-art-arrive {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.955) rotateY(7deg);
    filter: blur(3px) brightness(0.74) saturate(0.86);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotateY(0deg);
    filter: blur(0) brightness(1) saturate(1);
  }
}

@keyframes tw-polish-single-meaning-arrive {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.988);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes tw-polish-three-card-arrive {
  from { opacity: 0; transform: translateY(14px) scale(0.988); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes tw-polish-three-art-unveil {
  from {
    opacity: 0;
    clip-path: inset(8% 5% 8% 5% round 8px);
    transform: translateY(10px) scale(0.965) rotateY(6deg);
    filter: blur(2px) brightness(0.78) saturate(0.9);
  }
  to {
    opacity: 1;
    clip-path: inset(0 0 0 0 round 8px);
    transform: translateY(0) scale(1) rotateY(0deg);
    filter: blur(0) brightness(1) saturate(1);
  }
}

@keyframes tw-polish-three-meaning-arrive {
  from { opacity: 0; transform: translateY(10px); filter: blur(3px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

@media (max-width: 899px) {
  body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .deck-card .deck-card-face {
    inset: 2px !important;
    width: calc(100% - 4px) !important;
    height: calc(100% - 4px) !important;
    border-radius: 5px !important;
  }

  body.motion-polish-enabled[data-page="draw"]:not(.home-landing-state) .deck-card.is-face-entering .deck-card-number {
    animation-name: tw-polish-seal-confirm-mobile;
  }
}

@keyframes tw-polish-seal-confirm-mobile {
  0% { opacity: 0.4; transform: translate(24%, -30%) scale(0.88); }
  58% { opacity: 1; transform: translate(24%, -30%) scale(1.08); }
  100% { opacity: 1; transform: translate(24%, -30%) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .selection-grid.is-reveal-pending .deck-card,
  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .selection-grid.mobile-four-row-grid.is-reveal-pending .deck-card.is-picked,
  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .selection-grid.tw-eleven-grid.is-reveal-pending .tw-eleven-layer .deck-card.is-picked,
  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .selection-grid .deck-card:nth-child(13),
  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .selection-grid .deck-card:nth-child(18) {
    animation: none !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .selection-grid.has-selection .deck-card {
    animation: none !important;
    transition: none !important;
  }

  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .deck-card.is-face-revealed .deck-card-back {
    opacity: 0 !important;
    transform: none !important;
    filter: none !important;
    animation: none !important;
  }

  body.motion-polish-enabled.motion-reduced[data-page="draw"]:not(.home-landing-state) .deck-card.is-face-revealed .deck-card-face {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    animation: none !important;
  }

  body.motion-polish-enabled.motion-reduced .completed-reading-art,
  body.motion-polish-enabled.motion-reduced .completed-reading-copy,
  body.motion-polish-enabled.motion-reduced .completed-reading-grid.is-multi .completed-reading-card {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    animation: none !important;
  }
}
