/* ==========================================================================
   VibeFlix – motion.css
   All the animation for the site. Load after styles.css.
   ========================================================================== */

/* ---------- Mood colors melt instead of snapping ----------
   Registering these as real colors lets the browser fade between them. Older
   browsers ignore this and simply switch colors, which still works. */
@property --mood      { syntax: "<color>"; inherits: true; initial-value: #ff7043; }
@property --mood-ink  { syntax: "<color>"; inherits: true; initial-value: #121212; }
@property --mood-glow { syntax: "<color>"; inherits: true; initial-value: rgba(255, 112, 67, 0.35); }

html {
  overflow-x: clip;
}

body {
  background-color: transparent; /* the html background shows behind the glow */
  transition: --mood 700ms var(--ease), --mood-ink 700ms var(--ease), --mood-glow 700ms var(--ease);
}

/* These followed the mood with their own delay; the melt above now drives them */
.brand-logo,
.eyebrow,
.pill-match,
.progress-fill {
  transition-property: width;
}

.cta {
  position: relative;
  overflow: hidden;
  transition: transform var(--fast) var(--ease);
}

/* ---------- Ambient glow drifting behind the page ----------
   Two soft shapes; app.js speeds them up or slows them down per mood. */
body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  background: radial-gradient(circle, var(--mood-glow), transparent 62%);
  pointer-events: none;
}

body::before {
  top: -30vmax;
  left: -20vmax;
  animation: drift-a 18s ease-in-out infinite alternate;
}

body::after {
  right: -25vmax;
  bottom: -35vmax;
  opacity: 0.7;
  animation: drift-b 24s ease-in-out infinite alternate;
}

@keyframes drift-a {
  to { transform: translate(38vw, 22vh) scale(1.2); }
}

@keyframes drift-b {
  to { transform: translate(-42vw, -30vh) scale(0.85); }
}

/* Color wash spreading out from the mood you tapped */
.mood-wash {
  position: fixed;
  z-index: 40;
  border-radius: 50%;
  pointer-events: none;
}

/* ---------- Page load ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.site-header {
  animation: rise 500ms var(--ease) backwards;
}

.hero > *,
.mood-button {
  animation: rise 600ms var(--ease) backwards;
}

.hero > :nth-child(1) { animation-delay: 60ms; }
.hero > :nth-child(2) { animation-delay: 120ms; }
.hero > :nth-child(3) { animation-delay: 180ms; }
.hero > :nth-child(4) { animation-delay: 240ms; }
.hero > :nth-child(5) { animation-delay: 300ms; }
.hero > :nth-child(6) { animation-delay: 620ms; }

.mood-button:nth-child(1) { animation-delay: 300ms; }
.mood-button:nth-child(2) { animation-delay: 350ms; }
.mood-button:nth-child(3) { animation-delay: 400ms; }
.mood-button:nth-child(4) { animation-delay: 450ms; }
.mood-button:nth-child(5) { animation-delay: 500ms; }
.mood-button:nth-child(6) { animation-delay: 550ms; }

/* Things that fade up as you scroll to them */
.reveal {
  opacity: 0;
}

.reveal.is-in {
  opacity: 1;
  animation: rise 620ms var(--ease) backwards;
}

/* ---------- Main button: a band of light passes over it ---------- */
.cta::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.35) 50%, transparent 65%);
  transform: translateX(-120%);
  animation: sheen 5s ease-in-out 1.4s infinite;
  pointer-events: none;
}

@keyframes sheen {
  0% { transform: translateX(-120%); }
  22%, 100% { transform: translateX(120%); }
}

.cta:disabled {
  cursor: default;
  transform: none;
}

.cta[aria-busy="true"] {
  animation: breathe 1.1s ease-in-out infinite alternate;
}

@keyframes breathe {
  to { box-shadow: 0 8px 44px var(--mood-glow), 0 0 0 6px var(--mood-glow); }
}

/* Selected mood gently pulses its glow */
.mood-button[aria-pressed="true"] .mood-emoji {
  animation: float 2.6s ease-in-out infinite alternate;
}

@keyframes float {
  to { transform: translateY(-4px) scale(1.08); }
}

/* ---------- Particles and flying posters ---------- */
.burst-bit {
  position: fixed;
  z-index: 60;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
}

.burst-emoji {
  width: auto;
  height: auto;
  background: none;
  font-size: 22px;
  line-height: 1;
}

.flyer {
  position: fixed;
  z-index: 60;
  transform-origin: top left;
  pointer-events: none;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.55));
}

.flyer .poster {
  height: 100%;
  border-radius: 6px;
}

/* ---------- Results: loading placeholders ----------
   Every piece of the real card turns into a shimmering block of its own
   size, so nothing jumps when the real content appears. */
.results[data-state="loading"] :is(.poster, .eyebrow, .top-pick-title, .movie-meta, .ai-reason, .pill, .rate-button, .card-title, .card-meta, .icon-button) {
  color: transparent !important;
  border-color: transparent;
  box-shadow: none;
  background: linear-gradient(100deg, var(--surface-raised) 30%, var(--surface-hover) 50%, var(--surface-raised) 70%) !important;
  background-size: 220% 100% !important;
  border-radius: var(--radius-sm);
  pointer-events: none;
  animation: shimmer 1.2s linear infinite;
}

.results[data-state="loading"] .poster {
  border-radius: var(--radius-md);
}

.results[data-state="loading"] :is(.poster > *, .icon-button > *, .rate-button > *) {
  visibility: hidden;
}

.results[data-state="loading"] .section-meta {
  visibility: hidden;
}

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

/* ---------- Results: the reveal ---------- */
.movie-card.arrive {
  animation: deal 640ms var(--ease) backwards;
  animation-delay: calc(var(--i) * 80ms);
}

@keyframes deal {
  from { opacity: 0; transform: perspective(900px) translateY(36px) rotateX(-28deg) scale(0.92); }
  to { opacity: 1; transform: perspective(900px); }
}

.top-pick.land {
  animation: land 760ms cubic-bezier(0.34, 1.4, 0.64, 1) 320ms backwards;
}

@keyframes land {
  from { opacity: 0; transform: translateY(26px) scale(0.9); }
  to { opacity: 1; transform: none; }
}

/* Glow ring that fades after the top pick lands */
.top-pick {
  position: relative;
}

.top-pick.land::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  animation: ring 1.5s var(--ease) 700ms backwards;
  opacity: 0;
}

@keyframes ring {
  from { opacity: 1; box-shadow: 0 0 0 2px var(--mood), 0 0 60px var(--mood-glow); }
  to { opacity: 0; box-shadow: 0 0 0 2px transparent, 0 0 120px transparent; }
}

.type-rest {
  visibility: hidden;
}

.type-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-inline: 1px -3px;
  vertical-align: -0.12em;
  background: var(--mood);
  animation: blink 700ms steps(2) infinite;
}

body[data-mood="dark"] .type-caret {
  background: var(--text-muted);
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- Cards: 3D tilt and light ---------- */
.movie-card {
  --lift: 1;
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(var(--lift));
  transition: transform 140ms ease-out, background-color var(--fast), box-shadow var(--fast);
}

.movie-card:hover {
  --lift: 1.03;
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(var(--lift));
}

.top-pick .poster,
.favorite-item .poster,
.pick-tile .poster {
  transform: perspective(700px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform 140ms ease-out, outline-color var(--fast);
}

@media (hover: hover) {
  .poster::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at var(--sx, 50%) var(--sy, 0%), rgba(255, 255, 255, 0.3), transparent 58%);
    opacity: 0;
    transition: opacity var(--fast);
    pointer-events: none;
  }

  .movie-card:hover .poster::after,
  .poster:hover::after {
    opacity: 1;
  }
}

/* Room for three buttons beside the score, and equal column widths */
.card-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.card-foot .pill {
  flex: none;
  white-space: nowrap;
}

.card-foot .icon-actions {
  gap: 0;
}

.card-foot .icon-button {
  width: 30px;
  height: 30px;
}

/* The play badge is now a real button */
button.poster-badge {
  z-index: 1;
  border: 0;
  padding: 0;
}

button.poster-badge:hover {
  transform: scale(1.12);
}

button.poster-badge:focus-visible {
  opacity: 1;
  transform: none;
}

@media (hover: none) {
  .poster-badge {
    opacity: 1;
    transform: none;
  }
}

/* Phones: "more for this mood" becomes a row you swipe through */
@media (max-width: 760px) {
  .card-grid {
    display: flex;
    gap: 14px;
    margin-inline: -16px;
    padding: 6px 16px 16px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 16px;
    scrollbar-width: none;
  }

  .card-grid::-webkit-scrollbar {
    display: none;
  }

  .movie-card {
    flex: 0 0 min(68%, 260px);
    scroll-snap-align: start;
  }
}

/* ---------- Share button: turns into a confirmation ---------- */
.action-button {
  overflow: hidden;
  white-space: nowrap;
}

.action-button svg {
  flex: none;
}

.share-button .icon-check {
  display: none;
}

.share-button[data-shared] .icon-share {
  display: none;
}

.share-button[data-shared] .icon-check {
  display: block;
  animation: check-in 340ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes check-in {
  from { transform: scale(0) rotate(-40deg); }
  to { transform: none; }
}

.rate-button.share-button[data-shared] {
  background: var(--mood);
  border-color: var(--mood);
  color: var(--mood-ink);
}

.icon-button.share-button {
  position: relative;
}

.icon-button.share-button[data-shared] {
  color: var(--mood);
}

body[data-mood="dark"] .icon-button.share-button[data-shared] {
  color: var(--text);
}

/* The small icon has no room for words, so they float above it */
.icon-button.share-button[data-shared]::after {
  content: attr(data-shared);
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--bg);
  animation: rise 240ms var(--ease) backwards;
}

/* ---------- Trailer player: grows out of the poster ---------- */
.trailer-modal {
  position: fixed;
  inset: auto;
  margin: 0;
  padding: 0;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
}

.trailer-modal[open] {
  display: flex;
  flex-direction: column;
}

.trailer-modal::backdrop {
  background: rgba(0, 0, 0, 0.85);
  transition: opacity 280ms;
  animation: fade-in 320ms ease-out;
}

.trailer-modal.is-closing::backdrop {
  opacity: 0;
}

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

.trailer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

.trailer-cover,
.trailer-stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.trailer-cover {
  z-index: 1;
  object-fit: cover;
  transition: opacity 400ms;
  pointer-events: none;
}

.trailer-cover.is-gone {
  opacity: 0;
}

.trailer-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding-inline: 18px 10px;
  background: var(--surface);
}

.trailer-title {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trailer-link {
  flex: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.trailer-link:hover {
  color: var(--text);
}

.trailer-bar .icon-button {
  flex: none;
  font-size: 22px;
}

/* ---------- Survey ---------- */
.progress-fill {
  box-shadow: 0 0 14px var(--mood);
}

.step.step-in > * {
  animation: step-in 480ms var(--ease) backwards;
  animation-delay: calc(var(--i) * 55ms);
}

@keyframes step-in {
  from { opacity: 0; transform: translateX(calc(var(--dir, 1) * 36px)); }
  to { opacity: 1; transform: none; }
}

.service-tile[aria-pressed="true"]::after {
  animation: check-in 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

#genre-grid .chip[data-state="love"],
#genre-grid .chip[data-state="skip"] {
  animation: chip-pop 280ms var(--ease);
}

@keyframes chip-pop {
  40% { transform: scale(1.14); }
}

.summary-list .pill {
  animation: rise 460ms var(--ease) backwards;
  animation-delay: calc(var(--i) * 90ms + 300ms);
}

/* ---------- Profile ---------- */
.genre-fill {
  display: block; /* it's a span, and width does nothing on an inline element */
  transition: width 1000ms var(--ease);
}

.modal[open]:not(.trailer-modal) {
  animation: dialog-in 300ms var(--ease);
}

.modal[open]::backdrop {
  animation: fade-in 260ms ease-out;
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
}

/* ---------- Reduced motion: stop everything that moves on its own ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  *::backdrop {
    animation: none !important;
    transition: none !important;
  }

  .cta::after {
    display: none;
  }
}
