/* Animations: ember canvas, XP sheen, the LEVEL UP curtain, confetti.
   Everything here is switched off by prefers-reduced-motion at the bottom:
   then the curtain simply appears, still and readable, and fades out. */

.fx-embers {
  position: fixed;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.75;
}

.fx-confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@keyframes xp-sheen {
  from {
    transform: translateX(-60px);
  }
  to {
    transform: translateX(100%);
  }
}

/* A row that just gained a level flashes gold and lifts for a moment. */
.row-dinged {
  animation: row-ding 2.4s ease-out;
}

@keyframes row-ding {
  0% {
    background: linear-gradient(90deg, rgba(247, 231, 172, 0.5), rgba(212, 175, 55, 0.12));
    border-color: var(--gold-bright);
    transform: scale(1.015);
    box-shadow: 0 0 36px rgba(212, 175, 55, 0.5);
  }
  100% {
    transform: scale(1);
  }
}

.feed-new {
  animation: feed-in 700ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes feed-in {
  from {
    opacity: 0;
    transform: translateX(14px);
    background: rgba(212, 175, 55, 0.25);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --- the LEVEL UP curtain -------------------------------------------------- */

.levelup {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
  background: radial-gradient(60% 50% at 50% 50%, rgba(40, 27, 6, 0.88), rgba(3, 2, 6, 0.94));
  animation: curtain-in 240ms ease-out;
}

.levelup[hidden] {
  display: none;
}

.levelup-closing {
  animation: curtain-out 420ms ease-in forwards;
}

@keyframes curtain-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes curtain-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.levelup-rays {
  position: absolute;
  width: max(150vw, 150vh);
  height: max(150vw, 150vh);
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 222, 140, 0.2) 0deg 5deg,
    transparent 5deg 18deg,
    rgba(255, 222, 140, 0.12) 18deg 21deg,
    transparent 21deg 30deg
  );
  mask-image: radial-gradient(circle, rgba(0, 0, 0, 0.95) 8%, transparent 52%);
  animation: rays-spin 14s linear infinite;
}

.levelup-grand .levelup-rays {
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 236, 170, 0.42) 0deg 6deg,
    transparent 6deg 16deg,
    rgba(255, 236, 170, 0.28) 16deg 20deg,
    transparent 20deg 30deg
  );
}

@keyframes rays-spin {
  to {
    rotate: 360deg;
  }
}

/* A golden shockwave ring that rolls out once. */
.levelup-shock {
  position: absolute;
  width: 18rem;
  height: 18rem;
  border-radius: 50%;
  border: 10px solid rgba(255, 214, 120, 0.85);
  box-shadow: 0 0 40px rgba(255, 200, 90, 0.8), inset 0 0 40px rgba(255, 200, 90, 0.6);
  opacity: 0;
  animation: shock 1.1s cubic-bezier(0.2, 0.8, 0.3, 1) 0.18s;
}

@keyframes shock {
  0% {
    opacity: 1;
    scale: 0.15;
    border-width: 18px;
  }
  100% {
    opacity: 0;
    scale: 3.2;
    border-width: 2px;
  }
}

.levelup-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(92vw, 44rem);
  padding: clamp(1rem, 4vw, 2.4rem) clamp(1rem, 6vw, 4rem);
  text-align: center;
  animation: card-pop 620ms cubic-bezier(0.18, 1.5, 0.4, 1);
}

/* A warm dark core right behind the text (so it reads over the rays),
   fading out into a class-coloured glow. */
.levelup-card::before {
  content: "";
  position: absolute;
  inset: 2% -6%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side,
      rgba(16, 10, 4, 0.86) 0%,
      rgba(16, 10, 4, 0.7) 50%,
      color-mix(in srgb, var(--class-color) 26%, transparent) 76%,
      transparent 100%);
  filter: blur(14px);
}

@keyframes card-pop {
  0% {
    opacity: 0;
    transform: scale(0.72) translateY(18px);
  }
  60% {
    opacity: 1;
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

/* The class portrait, spun in like a coin. */
.levelup-medal {
  display: grid;
  place-items: center;
  margin-bottom: 0.4rem;
  animation: medal-in 900ms cubic-bezier(0.2, 1.4, 0.4, 1) 80ms both;
}

.levelup-medal .medal {
  width: clamp(5.5rem, 14vw, 8rem);
  height: clamp(5.5rem, 14vw, 8rem);
  border-width: 5px;
  box-shadow:
    0 0 0 2.5px var(--ink-line),
    inset 0 0 0 2px rgba(0, 0, 0, 0.6),
    inset 0 -10px 20px rgba(0, 0, 0, 0.45),
    0 0 36px color-mix(in srgb, var(--class-color) 70%, transparent),
    0 0 70px rgba(255, 200, 90, 0.45);
}

@keyframes medal-in {
  0% {
    opacity: 0;
    transform: perspective(600px) rotateY(-540deg) scale(0.3);
  }
  70% {
    opacity: 1;
    transform: perspective(600px) rotateY(20deg) scale(1.12);
  }
  100% {
    transform: perspective(600px) rotateY(0) scale(1);
  }
}

/* LEVEL UP! in chunky beveled gold, slammed down, then a shine runs across. */
.levelup-kicker {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2.6rem, 1rem + 8vw, 6.4rem);
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  background:
    linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.95) 50%, transparent 60%) -200% 0 / 200% 100% no-repeat,
    linear-gradient(180deg, var(--gold-text-top) 0%, #fff0b8 24%, var(--gold-text-mid) 47%, #eebc50 51%, var(--gold-text-low) 74%, #f6cf68 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter:
    drop-shadow(0 2px 0 var(--ink-line))
    drop-shadow(0 -2px 0 var(--ink-line))
    drop-shadow(2px 0 0 var(--ink-line))
    drop-shadow(-2px 0 0 var(--ink-line))
    drop-shadow(0 5px 0 #6a420b)
    drop-shadow(0 3px 0 #2a1704)
    drop-shadow(0 0 30px rgba(255, 190, 80, 0.65));
  animation:
    kicker-slam 700ms cubic-bezier(0.2, 1.6, 0.4, 1) 120ms both,
    kicker-shine 1.4s ease-in-out 800ms;
}

@keyframes kicker-slam {
  0% {
    opacity: 0;
    transform: scale(2.6);
  }
  55% {
    opacity: 1;
    transform: scale(0.92);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes kicker-shine {
  from {
    background-position: -200% 0, 0 0;
  }
  to {
    background-position: 300% 0, 0 0;
  }
}

/* The name on a dark ribbon plate with gold edges and notched tails. */
.levelup-name {
  position: relative;
  margin-top: 0.7rem;
  max-width: 100%;
  padding: 0.35rem 2.2rem 0.4rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 1rem + 2.4vw, 2.3rem);
  line-height: 1.2;
  color: var(--class-text);
  text-shadow: 0 2px 0 var(--ink-line), 0 0 22px color-mix(in srgb, var(--class-color) 50%, transparent);
  overflow-wrap: anywhere;
  background: linear-gradient(180deg, var(--surface-panel), #0c0910);
  clip-path: polygon(0 0, 100% 0, calc(100% - 1rem) 50%, 100% 100%, 0 100%, 1rem 50%);
  box-shadow:
    inset 0 2px 0 #f0c75a,
    inset 0 3px 0 rgba(0, 0, 0, 0.5),
    inset 0 -2px 0 #c8952e,
    inset 0 -3px 0 rgba(0, 0, 0, 0.5);
  animation: rise-in 600ms cubic-bezier(0.2, 1.3, 0.4, 1) 300ms both;
}

.levelup-level {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 0.6rem;
  animation: rise-in 600ms cubic-bezier(0.2, 1.3, 0.4, 1) 420ms both;
}

.levelup-level-word {
  font-family: var(--font-display);
  font-size: clamp(0.9375rem, 0.8rem + 0.6vw, 1.25rem);
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-transform: uppercase;
  color: var(--text-gold);
  text-shadow: 0 2px 0 var(--ink-line);
}

.levelup-level-num {
  display: block;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(3.4rem, 1.6rem + 9vw, 7.5rem);
  line-height: 0.95;
  background: linear-gradient(180deg, var(--text-strong) 0%, var(--text) 50%, var(--gold-text-mid) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter:
    drop-shadow(0 2px 0 var(--ink-line))
    drop-shadow(0 -2px 0 var(--ink-line))
    drop-shadow(2px 0 0 var(--ink-line))
    drop-shadow(-2px 0 0 var(--ink-line))
    drop-shadow(0 5px 0 #4a3208)
    drop-shadow(0 0 36px rgba(255, 220, 140, 0.7));
  animation: num-pop 700ms cubic-bezier(0.2, 1.8, 0.4, 1) 480ms both;
}

@keyframes num-pop {
  0% {
    opacity: 0;
    transform: scale(0.2) rotate(-12deg);
  }
  60% {
    opacity: 1;
    transform: scale(1.18) rotate(3deg);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes rise-in {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

.levelup-flavour {
  margin-top: 0.8rem;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(9, 7, 13, 0.82);
  font-size: var(--fs-lead);
  font-style: italic;
  color: var(--text);
  animation: rise-in 600ms ease-out 650ms both;
}

/* Twinkling stars around the card. */
.levelup-sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.levelup-spark {
  position: absolute;
  width: 1.6rem;
  height: 1.6rem;
  background: radial-gradient(circle, #ffffff 0%, #ffe9a6 35%, #f0b43c 70%);
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
  filter: drop-shadow(0 0 6px rgba(255, 230, 150, 0.9));
  opacity: 0;
  animation: twinkle 1.6s ease-in-out infinite;
}

.levelup-spark:nth-child(1) { top: 6%; left: 8%; animation-delay: 0.2s; }
.levelup-spark:nth-child(2) { top: 12%; right: 6%; width: 1.1rem; height: 1.1rem; animation-delay: 0.7s; }
.levelup-spark:nth-child(3) { top: 46%; left: -2%; width: 1.2rem; height: 1.2rem; animation-delay: 1.1s; }
.levelup-spark:nth-child(4) { top: 40%; right: -3%; animation-delay: 0.45s; }
.levelup-spark:nth-child(5) { bottom: 14%; left: 10%; width: 1rem; height: 1rem; animation-delay: 0.9s; }
.levelup-spark:nth-child(6) { bottom: 8%; right: 12%; width: 1.4rem; height: 1.4rem; animation-delay: 0.3s; }

@keyframes twinkle {
  0%,
  100% {
    opacity: 0;
    scale: 0.2;
    rotate: 0deg;
  }
  50% {
    opacity: 1;
    scale: 1;
    rotate: 45deg;
  }
}

/* The contender's cartoon figure, cheering on a class-coloured glow. */
.levelup-figure {
  position: relative;
  display: block;
  width: clamp(6.5rem, 16vw, 9.5rem);
  aspect-ratio: 200 / 260;
}

.levelup-figure::before {
  content: "";
  position: absolute;
  inset: 10% -18% -4%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--class-color) 55%, transparent), transparent);
  filter: blur(6px);
}

.levelup-figure > .fig {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.45)) drop-shadow(0 0 24px rgba(255, 220, 140, 0.45));
}

/* Loot: the item in its quality colour, in [brackets], big. */
.levelup-item {
  margin-top: 0.7rem;
  max-width: 100%;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.5rem, 1rem + 2.4vw, 2.6rem);
  line-height: 1.15;
  color: var(--quality-color);
  overflow-wrap: anywhere;
  text-shadow:
    0 2px 0 var(--ink-line),
    0 -2px 0 var(--ink-line),
    2px 0 0 var(--ink-line),
    -2px 0 0 var(--ink-line),
    0 0 28px color-mix(in srgb, var(--quality-color) 70%, transparent);
  animation: num-pop 700ms cubic-bezier(0.2, 1.8, 0.4, 1) 420ms both;
}

/* The loot curtain's rays and shockwave take the item's quality colour. */
.levelup-loot .levelup-rays {
  background: repeating-conic-gradient(
    from 0deg,
    color-mix(in srgb, var(--quality-color) 30%, transparent) 0deg 5deg,
    transparent 5deg 18deg,
    color-mix(in srgb, var(--quality-color) 18%, transparent) 18deg 21deg,
    transparent 21deg 30deg
  );
}

.levelup-loot .levelup-shock {
  border-color: color-mix(in srgb, var(--quality-color) 85%, transparent);
  box-shadow: 0 0 40px var(--quality-color), inset 0 0 40px color-mix(in srgb, var(--quality-color) 60%, transparent);
}

.levelup-legendary .levelup-rays {
  animation-duration: 7s;
}

/* --- reduced motion -------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  :root {
    --t-fast: 0ms;
    --t-mid: 0ms;
    --t-slow: 0ms;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .fx-embers,
  .levelup-rays,
  .levelup-shock,
  .levelup-spark,
  .xpbar-spark,
  .board-row.rank-1::after {
    display: none;
  }

  .levelup {
    background: rgba(3, 2, 6, 0.94);
  }
}
