/* ============================================================
   FS25 Portal — Motion layer
   Depends on: 01-tokens.css, 02-base.css, 03-layout.css,
               04-components.css, 05-content.css,
               06-forum-tickets.css, 07-admin.css,
               08-profile-auth.css
   ------------------------------------------------------------
   Loads last. Every other file draws the machine; this one is
   the idle running — the needle twitch, the panel settling on
   its hinge, the amber lamp catching before it holds steady.

   Rules:
   - Only tokens from 01-tokens.css. No hardcoded colour/size.
   - transform + opacity only. No width/height/top/left/shadow
     loops.
   - 02-base.css already zeroes every animation/transition
     duration under prefers-reduced-motion: reduce. Nothing here
     fights that — but nothing here may rely on an animation to
     *become visible* either, so every entrance keeps a static
     fallback of opacity:1 / no transform baked into the base
     (non-animation) state or an animation-fill-mode that lands
     there and stays.
   ============================================================ */

/* ============================================================
   1. Page-load entrance — .stagger-in / .stagger-item
   ------------------------------------------------------------
   Children fade up and settle. Works whether the container is
   marked up with .stagger-in ahead of time or a JS agent adds
   it after render. Capped at 10 explicit steps; anything past
   that shares the last delay so a long list doesn't crawl in.
   ============================================================ */

@keyframes fs-rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.stagger-item,
.stagger-in > * {
  animation: fs-rise-in var(--t-slow) var(--ease) both;
}

/* Also usable stand-alone on a single element. */
.rise-in {
  animation: fs-rise-in var(--t-slow) var(--ease) both;
}

.stagger-item:nth-child(1),  .stagger-in > *:nth-child(1)  { animation-delay: calc(var(--t-fast) * 0); }
.stagger-item:nth-child(2),  .stagger-in > *:nth-child(2)  { animation-delay: calc(var(--t-fast) * 1); }
.stagger-item:nth-child(3),  .stagger-in > *:nth-child(3)  { animation-delay: calc(var(--t-fast) * 2); }
.stagger-item:nth-child(4),  .stagger-in > *:nth-child(4)  { animation-delay: calc(var(--t-fast) * 3); }
.stagger-item:nth-child(5),  .stagger-in > *:nth-child(5)  { animation-delay: calc(var(--t-fast) * 4); }
.stagger-item:nth-child(6),  .stagger-in > *:nth-child(6)  { animation-delay: calc(var(--t-fast) * 5); }
.stagger-item:nth-child(7),  .stagger-in > *:nth-child(7)  { animation-delay: calc(var(--t-fast) * 6); }
.stagger-item:nth-child(8),  .stagger-in > *:nth-child(8)  { animation-delay: calc(var(--t-fast) * 7); }
.stagger-item:nth-child(9),  .stagger-in > *:nth-child(9)  { animation-delay: calc(var(--t-fast) * 8); }
.stagger-item:nth-child(n+10), .stagger-in > *:nth-child(n+10) { animation-delay: calc(var(--t-fast) * 9); }

/* ============================================================
   2. Hover life — lift + pointer-tracked tilt
   ------------------------------------------------------------
   A JS agent sets --mx / --my (0-1) on the hovered element for
   the tilt. Both custom properties default here so the same
   rule degrades to a plain lift when JS hasn't touched them.
   Re-declares the full `transition` list on each selector so
   the transform easing joins the colour/border transitions
   those components already define, rather than replacing them.
   ============================================================ */

.post-card,
.ticket-row,
.kanban-card,
.stat-card,
.comment-item {
  --mx: 0.5;
  --my: 0.5;
  --tilt-x: calc((var(--my) - 0.5) * -8deg);
  --tilt-y: calc((var(--mx) - 0.5) * 8deg);
  transform: translateZ(0);
  will-change: transform;
}

.post-card {
  transition: border-color var(--t) var(--ease), transform var(--t) var(--ease);
}
.post-card:hover {
  transform: translateY(-3px) perspective(600px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
}

.ticket-row {
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease), transform var(--t) var(--ease);
}
.ticket-row:hover {
  transform: translateY(-2px);
}

.kanban-card {
  transition: border-color var(--t) var(--ease), opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.kanban-card:hover {
  transform: translateY(-3px) perspective(600px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
}
.kanban-card.dragging:hover { transform: none; }

.stat-card {
  transition: transform var(--t) var(--ease), border-color var(--t) var(--ease);
}
.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-3px) perspective(600px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
}

.comment-item {
  transition: transform var(--t) var(--ease), border-color var(--t) var(--ease);
}
.comment-item:hover { transform: translateY(-1px); }

/* Buttons and small chips get a lift without the tilt — they're
   too small for parallax to read as anything but jitter. */
.reaction-btn,
.btn-comment-toggle,
.bookmark-btn {
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease), color var(--t) var(--ease), transform var(--t-fast) var(--ease);
}
.reaction-btn:hover,
.btn-comment-toggle:hover,
.bookmark-btn:hover {
  transform: translateY(-1px);
}
.reaction-btn:active,
.btn-comment-toggle:active,
.bookmark-btn:active {
  transform: translateY(0);
}

/* ============================================================
   3. Ambient background drift
   ------------------------------------------------------------
   One cheap layer riding on top of the tramline field already
   painted on body in 02-base.css. A radial wash creeps slowly
   left-right-left; opacity stays near-nothing throughout so it
   reads as light shifting on enamel, never as a visible sweep.
   ============================================================ */

@keyframes fs-ambient-drift {
  0%   { transform: translate3d(-4%, -2%, 0) scale(1); }
  50%  { transform: translate3d(4%, 2%, 0) scale(1.04); }
  100% { transform: translate3d(-4%, -2%, 0) scale(1); }
}

body {
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: -10%;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse at 30% 20%, var(--amber-soft), transparent 55%);
  opacity: 0.5;
  animation: fs-ambient-drift 48s var(--ease) infinite;
}

@media (prefers-reduced-motion: reduce) {
  body::before { display: none; }
}

/* ============================================================
   4. Feedback micro-interactions
   ============================================================ */

/* ---- reaction pop ---- */
@keyframes fs-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(0.88); }
  65%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.reaction-btn.pop { animation: fs-pop var(--t-slow) var(--ease); }

/* ---- rolling counters ---- */
@keyframes fs-count-roll {
  0%   { transform: translateY(40%); opacity: 0; }
  100% { transform: translateY(0);   opacity: 1; }
}

.count-roll {
  display: inline-block;
  animation: fs-count-roll var(--t) var(--ease);
}

/* ---- button press feedback (enriches the existing :active) ---- */
.btn {
  transition: background var(--t) var(--ease),
              border-color var(--t) var(--ease),
              color var(--t) var(--ease),
              transform var(--t-fast) var(--ease);
}
.btn:active { transform: translateY(1px) scale(0.97); }

/* ---- copy confirmation flash ---- */
@keyframes fs-copied-flash {
  0%   { background-color: var(--amber-soft); }
  100% { background-color: transparent; }
}

.copied {
  animation: fs-copied-flash var(--t-slow) var(--ease);
  color: var(--amber);
}

/* ---- validation shake ---- */
@keyframes fs-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(5px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(2px); }
}

.shake {
  animation: fs-shake var(--t-slow) var(--ease);
  border-color: var(--red) !important;
}

/* ============================================================
   5. Toasts — full appearance + motion
   ============================================================ */

.toast-stack {
  position: fixed;
  bottom: var(--s5);
  right: var(--s5);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  width: min(340px, calc(100vw - var(--s5) * 2));
  pointer-events: none;
}

@keyframes fs-toast-in {
  from { opacity: 0; transform: translateX(24px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes fs-toast-out {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to   { opacity: 0; transform: translateX(24px) scale(0.97); }
}

.toast {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s3) var(--s4);
  background: var(--surface-3);
  border: var(--hairline) solid var(--border-strong);
  border-left: var(--plate-edge) solid var(--steel);
  border-radius: 0 var(--r) var(--r) 0;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  pointer-events: auto;
  animation: fs-toast-in var(--t-slow) var(--ease) both;
}

.toast-success { border-left-color: var(--green); }
.toast-error   { border-left-color: var(--red); }
.toast-warning { border-left-color: var(--amber); }
.toast-info    { border-left-color: var(--steel); }

.toast-title {
  font-family: var(--font-display);
  font-size: var(--fs-base);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--text);
}

.toast-message {
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.toast-close {
  position: absolute;
  top: var(--s2);
  right: var(--s2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: var(--text-faint);
  border-radius: var(--r-sm);
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.toast-close:hover { background: var(--surface-2); color: var(--text); }

@keyframes fs-toast-progress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

.toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: currentColor;
  color: var(--steel);
  transform-origin: left center;
  animation: fs-toast-progress linear forwards;
  animation-duration: var(--toast-life, 4s);
}

.toast-success .toast-progress { color: var(--green); }
.toast-error   .toast-progress { color: var(--red); }
.toast-warning .toast-progress { color: var(--amber); }
.toast-info    .toast-progress { color: var(--steel); }

.toast.toast-leaving {
  animation: fs-toast-out var(--t) var(--ease) both;
}

@media (prefers-reduced-motion: reduce) {
  .toast-progress { animation-name: none; transform: scaleX(0); }
}

/* ============================================================
   6. Dialogs
   ============================================================ */

@keyframes fs-backdrop-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fs-backdrop-out { from { opacity: 1; } to { opacity: 0; } }

@keyframes fs-dialog-in {
  from { opacity: 0; transform: translateY(var(--s4)) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fs-dialog-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(var(--s3)) scale(0.96); }
}

.roadmap-modal-backdrop,
.modal-backdrop {
  animation: fs-backdrop-in var(--t) var(--ease) both;
}

.roadmap-modal-dialog,
.modal-dialog {
  animation: fs-dialog-in var(--t-slow) var(--ease) both;
}

.roadmap-modal.modal-leaving .roadmap-modal-backdrop,
.modal.modal-leaving .modal-backdrop {
  animation: fs-backdrop-out var(--t) var(--ease) both;
}

.roadmap-modal.modal-leaving .roadmap-modal-dialog,
.modal.modal-leaving .modal-dialog {
  animation: fs-dialog-out var(--t) var(--ease) both;
}

/* ============================================================
   7. Skeleton loaders
   ============================================================ */

@keyframes fs-shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-sunk);
  border: var(--hairline) solid var(--border-faint);
  border-radius: var(--r-sm);
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--surface-3), transparent);
  animation: fs-shimmer 1.6s var(--ease) infinite;
}

.skeleton-text {
  height: 0.9em;
  margin-bottom: var(--s2);
  border-radius: var(--r-sm);
}
.skeleton-text:last-child { margin-bottom: 0; width: 70%; }

.skeleton-title {
  height: 1.4em;
  width: 45%;
  margin-bottom: var(--s3);
  border-radius: var(--r-sm);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--r-round);
  flex-shrink: 0;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after { display: none; }
  .skeleton { background: var(--surface-2); }
}

/* ============================================================
   8. Accordion — .collapsible / .collapsible.open
   ------------------------------------------------------------
   grid-template-rows 0fr -> 1fr so height animates without a
   hardcoded max-height. The inner wrapper needs min-height: 0
   on the grid item (default overflow: hidden) — provided here
   via a required child; if markup nests one level deeper the
   grid trick still holds since only row 1 is what's collapsing.
   ============================================================ */

.collapsible {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--t-slow) var(--ease);
}

.collapsible > * {
  overflow: hidden;
  min-height: 0;
}

.collapsible.open {
  grid-template-rows: 1fr;
}

/* ============================================================
   9. Progress + counters
   ============================================================ */

@keyframes fs-xp-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.xp-fill {
  transform-origin: left center;
  animation: fs-xp-fill var(--t-slow) var(--ease) both;
  transition: width var(--t-slow) var(--ease);
}

.count-up {
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   10. Level-up celebration — .level-up-burst
   ------------------------------------------------------------
   CSS-only: a ring expanding outward plus a soft flash, additive
   over whatever badge/avatar it's placed on (absolutely position
   it centred over the target; markup/JS decides placement).
   Under a second, fires once.
   ============================================================ */

@keyframes fs-burst-ring {
  0%   { transform: scale(0.4); opacity: 0.9; }
  100% { transform: scale(1.9); opacity: 0; }
}

@keyframes fs-burst-flash {
  0%   { opacity: 0; }
  30%  { opacity: 1; }
  100% { opacity: 0; }
}

.level-up-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.level-up-burst::before,
.level-up-burst::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r-round);
}

.level-up-burst::before {
  border: var(--hairline) solid var(--amber);
  box-shadow: 0 0 0 1px var(--amber-line);
  animation: fs-burst-ring 0.7s var(--ease) forwards;
}

.level-up-burst::after {
  background: radial-gradient(circle, var(--amber-soft), transparent 70%);
  animation: fs-burst-flash 0.7s var(--ease) forwards;
}

@media (prefers-reduced-motion: reduce) {
  .level-up-burst::before,
  .level-up-burst::after { display: none; }
}

/* ============================================================
   11. Page transitions — .page-enter on <main>
   ============================================================ */

@keyframes fs-page-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-enter {
  animation: fs-page-enter var(--t-slow) var(--ease) both;
}

/* ============================================================
   12. Nav — hover slide + dropdown entrance
   ------------------------------------------------------------
   The active-link amber underscore is drawn by .active::after
   in 03-layout.css. This adds a matching bar for the *hover*
   state on non-active links, sliding in from centre via
   transform (never animating left/right/width).
   ============================================================ */

.nav-links > a::before {
  content: '';
  position: absolute;
  left: var(--s3);
  right: var(--s3);
  bottom: -1px;
  height: 2px;
  background: var(--amber-line);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform var(--t) var(--ease);
}

.nav-links > a:hover::before { transform: scaleX(1); }
.nav-links > a.active::before { display: none; }

/* Dropdown menus: replace the plain fade/translate with a touch
   of overshoot so they read as swinging open, not appearing. */
@keyframes fs-dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  60%  { transform: translateY(1px) scale(1.005); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-menu,
.lang-dropdown {
  transform-origin: top right;
}

.nav-user-dropdown:hover .dropdown-menu,
.nav-user-dropdown:focus-within .dropdown-menu,
.lang-selector.open .lang-dropdown {
  animation: fs-dropdown-in var(--t-slow) var(--ease) both;
}

.dropdown-item {
  transition: background var(--t) var(--ease), color var(--t) var(--ease), transform var(--t-fast) var(--ease);
}
.dropdown-item:hover { transform: translateX(2px); }
