/* Motion layer: page transitions, popups, toasts, entrances, micro-interactions.
   Native CSS first (View Transitions, @starting-style). Everything is switched off under prefers-reduced-motion. */

:root { --ease-out: cubic-bezier(0.22, 1, 0.36, 1); --gold: #f7c548; }

/* ---------- 1. Page-to-page transitions (Chrome/Edge/Safari 18.2+; others navigate normally) ---------- */
@view-transition { navigation: auto; }
.site-header { view-transition-name: site-header; }
::view-transition-old(root) { animation: vt-out 0.22s cubic-bezier(0.4, 0, 1, 1) both; }
::view-transition-new(root) { animation: vt-in 0.5s var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-10px); filter: blur(6px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(18px); filter: blur(8px); } }

/* ---------- 2. Every popup animates in and out ---------- */
.contact-dlg, .terms-dialog, .confirm-dlg, .celebrate-dlg {
  opacity: 0;
  transform: translateY(18px) scale(0.94);
  transition: opacity 0.3s ease, transform 0.45s var(--ease-out),
              overlay 0.45s allow-discrete, display 0.45s allow-discrete;
}
.contact-dlg[open], .terms-dialog[open], .confirm-dlg[open], .celebrate-dlg[open] { opacity: 1; transform: none; }
@starting-style {
  .contact-dlg[open], .terms-dialog[open], .confirm-dlg[open], .celebrate-dlg[open] { opacity: 0; transform: translateY(18px) scale(0.94); }
}
.contact-dlg::backdrop, .terms-dialog::backdrop, .confirm-dlg::backdrop, .celebrate-dlg::backdrop {
  background: rgba(4, 8, 16, 0.78);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.35s ease, overlay 0.45s allow-discrete, display 0.45s allow-discrete;
}
.contact-dlg[open]::backdrop, .terms-dialog[open]::backdrop, .confirm-dlg[open]::backdrop, .celebrate-dlg[open]::backdrop { opacity: 1; }
@starting-style {
  .contact-dlg[open]::backdrop, .terms-dialog[open]::backdrop, .confirm-dlg[open]::backdrop, .celebrate-dlg[open]::backdrop { opacity: 0; }
}

/* Styled confirm popup (replaces the browser's confirm()) */
.confirm-dlg, .celebrate-dlg {
  margin: auto; width: min(92vw, 400px); padding: 28px 24px 22px; border-radius: 20px; color: #fff; text-align: center;
  background: linear-gradient(180deg, rgba(22, 30, 46, 0.98), rgba(10, 14, 24, 0.98));
  border: 1px solid rgba(247, 197, 72, 0.35);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7), 0 0 40px rgba(247, 197, 72, 0.12);
}
.confirm-dlg p { margin: 0 0 22px; font-size: 16px; line-height: 1.55; }
.confirm-dlg .modal-actions, .celebrate-dlg .modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Celebration popup: gold burst + check */
.celebrate-dlg { overflow: hidden; }
.celebrate-dlg h3 { margin: 6px 0 8px; font-size: 22px; letter-spacing: 0.02em; color: var(--gold); }
.celebrate-dlg p { margin: 0 0 22px; font-size: 15px; line-height: 1.55; color: #dfe7f3; }
.cel-badge { position: relative; width: 84px; height: 84px; margin: 4px auto 6px; display: grid; place-items: center; }
.cel-badge svg { width: 84px; height: 84px; }
.cel-ring { fill: none; stroke: var(--gold); stroke-width: 4; stroke-dasharray: 240; stroke-dashoffset: 240; animation: cel-draw 0.7s var(--ease-out) 0.15s forwards; }
.cel-check { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 60; stroke-dashoffset: 60; animation: cel-draw 0.45s var(--ease-out) 0.7s forwards; }
.cel-burst i { position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; border-radius: 2px; background: var(--gold); opacity: 0;
  animation: cel-fly 0.9s var(--ease-out) 0.55s forwards; transform: rotate(calc(var(--a) * 1deg)) translateY(0); }
.cel-burst i:nth-child(even) { background: #fff3c4; width: 5px; height: 5px; }
@keyframes cel-draw { to { stroke-dashoffset: 0; } }
@keyframes cel-fly {
  0% { opacity: 1; transform: rotate(calc(var(--a) * 1deg)) translateY(0) scale(1); }
  100% { opacity: 0; transform: rotate(calc(var(--a) * 1deg)) translateY(-78px) scale(0.4); }
}

/* ---------- 3. Toasts ---------- */
.toast { position: relative; overflow: hidden; display: flex; align-items: flex-start; gap: 10px; animation: toast-in 0.5s var(--ease-out) both; }
.toast.is-leaving { animation: toast-out 0.35s ease forwards; }
.toast-x { margin-left: auto; background: none; border: 0; color: inherit; opacity: 0.6; font-size: 16px; cursor: pointer; padding: 0 2px; line-height: 1; }
.toast-x:hover { opacity: 1; }
.toast-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--gold); transform-origin: left; animation: toast-bar 5s linear forwards; }
.flash-error .toast-bar { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px) scale(0.97); } }
@keyframes toast-bar { to { transform: scaleX(0); } }

/* ---------- 4. Entrances ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.app-wrap > *, .login-panel { animation: rise 0.6s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 70ms); }
.lb-row { flex-shrink: 0; animation: rise 0.55s var(--ease-out) backwards; animation-delay: calc(0.25s + var(--i, 0) * 45ms); }
.prize-major-card { animation: rise 0.7s var(--ease-out) backwards; }
.prize-major-card:nth-child(2) { animation-delay: 0.1s; }
.prize-major-card:nth-child(3) { animation-delay: 0.2s; }
.dash-tile, .slot-btn, .day-chip { transition: transform 0.25s var(--ease-out), box-shadow 0.25s ease, border-color 0.25s ease, background-color 0.25s ease; }
.dash-tile:hover, .slot-btn:hover, .day-chip:hover { transform: translateY(-3px); }

/* Top-3 leaderboard shimmer */
.lb-row.rank-1, .lb-row.rank-2, .lb-row.rank-3 { position: relative; overflow: hidden; }
.lb-row.rank-1::after, .lb-row.rank-2::after, .lb-row.rank-3::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 236, 170, 0.16) 50%, transparent 65%);
  transform: translateX(-100%); animation: shimmer 4.5s ease-in-out 1.2s infinite;
}
.lb-row.rank-2::after { animation-delay: 1.5s; }
.lb-row.rank-3::after { animation-delay: 1.8s; }
@keyframes shimmer { 0% { transform: translateX(-100%); } 35%, 100% { transform: translateX(100%); } }

/* "(Team)" tag next to legacy teams */
.tag-team { font-size: 0.78em; font-weight: 600; color: #9fb2cc; letter-spacing: 0.02em; }

/* ---------- 5. Buttons: lift, press, busy spinner ---------- */
.btn-continue-review, .btn-ghost, .btn-header-cta, .btn-hero-register {
  transition: transform 0.2s var(--ease-out), box-shadow 0.25s ease, filter 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
}
.btn-continue-review:hover, .btn-ghost:hover, .btn-header-cta:hover, .btn-hero-register:hover { transform: translateY(-2px); }
.btn-continue-review:active, .btn-ghost:active, .btn-header-cta:active, .btn-hero-register:active { transform: scale(0.97); transition-duration: 0.08s; }
.is-busy { position: relative; pointer-events: none; }
.is-busy > * { opacity: 0; }
.is-busy::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Smooth in-page scrolling */
html { scroll-behavior: smooth; }

/* ---------- Reduced motion: everything off ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  .cel-ring, .cel-check { stroke-dashoffset: 0; }
}
