/* ============================================================================
   wa-legend.css — Legendary visual identity layer
   Per-category hues, living ambient background, 3D card tilt + shine,
   staggered reveals, category sort toolbar, season card, challenge banner,
   sound toggle and achievement seals. Loaded after page styles so it wins.
   ============================================================================ */

:root {
  --wa-hue: #f5c451;
  --wa-hue-soft: rgba(245, 196, 81, 0.16);
  --wa-hue-glow: rgba(245, 196, 81, 0.45);
}

/* ------------------------------------------------------------ ambient bg */
#wa-legend-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
}
#wa-legend-bg .wa-aurora {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(38% 46% at 18% 22%, var(--wa-hue-soft), transparent 70%),
    radial-gradient(42% 50% at 82% 18%, rgba(139, 92, 246, 0.14), transparent 70%),
    radial-gradient(46% 54% at 64% 86%, rgba(34, 211, 238, 0.10), transparent 72%),
    radial-gradient(30% 36% at 36% 64%, rgba(255, 79, 216, 0.07), transparent 70%);
  animation: waAuroraDrift 46s ease-in-out infinite alternate;
  will-change: transform;
}
#wa-legend-bg .wa-aurora--b {
  background:
    radial-gradient(34% 40% at 74% 70%, var(--wa-hue-soft), transparent 70%),
    radial-gradient(40% 44% at 12% 80%, rgba(61, 123, 255, 0.10), transparent 72%);
  animation: waAuroraDriftB 61s ease-in-out infinite alternate;
  opacity: 0.85;
}
#wa-legend-bg .wa-grain {
  position: absolute;
  inset: 0;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}
#wa-legend-bg .wa-rune {
  position: absolute;
  bottom: -8vh;
  color: var(--wa-hue);
  opacity: 0;
  font-size: 18px;
  text-shadow: 0 0 12px var(--wa-hue-glow);
  animation: waRuneFloat linear infinite;
  will-change: transform, opacity;
  user-select: none;
}
@keyframes waAuroraDrift {
  0% { transform: translate3d(-2%, -1%, 0) rotate(-1.5deg) scale(1); }
  50% { transform: translate3d(2%, 2%, 0) rotate(1deg) scale(1.06); }
  100% { transform: translate3d(-1%, 3%, 0) rotate(-0.5deg) scale(1.02); }
}
@keyframes waAuroraDriftB {
  0% { transform: translate3d(2%, 1%, 0) rotate(1deg); }
  100% { transform: translate3d(-2%, -2%, 0) rotate(-1.5deg) scale(1.05); }
}
@keyframes waRuneFloat {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 0; }
  8% { opacity: 0.16; }
  85% { opacity: 0.10; }
  100% { transform: translate3d(4vw, -118vh, 0) rotate(28deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #wa-legend-bg .wa-aurora { animation: none; }
  #wa-legend-bg .wa-rune { display: none; }
  .wa-enter { animation: none !important; }
}

/* ------------------------------------------------- category page re-hue */
body.wa-cat .badge {
  color: var(--wa-hue);
  border-color: var(--wa-hue-glow);
  background: var(--wa-hue-soft);
}
body.wa-cat .play {
  background: linear-gradient(135deg, var(--wa-hue-soft), rgba(29, 78, 216, 0.55));
  border: 1px solid var(--wa-hue-glow);
  box-shadow: 0 12px 28px -12px var(--wa-hue-glow);
}
body.wa-cat .hero {
  border-color: var(--wa-hue-soft);
  background: radial-gradient(120% 140% at 10% 0%, var(--wa-hue-soft), transparent 60%), #0b1220;
}
body.wa-cat .card:hover,
body.wa-cat .card:focus-visible {
  border-color: var(--wa-hue-glow);
  box-shadow: 0 0 22px -4px var(--wa-hue-glow), inset 0 0 12px var(--wa-hue-soft);
}
body.wa-cat .card-cat { color: var(--wa-hue); }
body.wa-cat .pager-current { background: var(--wa-hue-soft); border-color: var(--wa-hue); color: #fff; }
body.wa-cat .pager-link:hover { border-color: var(--wa-hue-glow); }
body.wa-cat a.play:hover { color: #fff; }

/* ------------------------------------------- shelf hue (index/all-games) */
.wa-hued .wa-shelf-title,
.wa-hued h2 .wa-shelf-accent { color: var(--wa-hue); }
.wa-hued .game-card:hover,
.wa-hued .game-card:focus-within {
  border-color: var(--wa-hue-glow) !important;
  box-shadow: 0 0 20px -4px var(--wa-hue-glow), 0 10px 26px -14px rgba(0, 0, 0, 0.8) !important;
}

/* ----------------------------------------------------- 3D tilt + shine */
a.card, .game-card { position: relative; }
a.card.wa-tilting, .game-card.wa-tilting {
  transform: perspective(720px) rotateX(var(--wa-rx, 0deg)) rotateY(var(--wa-ry, 0deg)) translateY(-4px) scale(1.02);
  transition: transform 0.06s linear;
  z-index: 2;
}
.wa-shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: radial-gradient(240px circle at var(--wa-mx, 50%) var(--wa-my, 50%), rgba(255, 255, 255, 0.16), transparent 62%);
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 3;
}
.wa-tilting .wa-shine { opacity: 1; }

/* ---------------------------------------------------- staggered reveal */
@keyframes waCardEnter {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.wa-enter { animation: waCardEnter 0.45s cubic-bezier(0.22, 0.9, 0.3, 1) both; }

/* ------------------------------------------------- category sort toolbar */
.cat-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 10px 14px;
  border: 1px solid var(--wa-hue-soft);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.85), rgba(11, 18, 32, 0.9));
}
.cat-tools label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  color: #94a3b8;
}
.cat-tools select {
  appearance: none;
  background: #0f172a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2367e8f9' stroke-width='1.6' fill='none'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #e2e8f0;
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 10px;
  padding: 7px 30px 7px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
[dir="rtl"] .cat-tools select { background-position: left 10px center; padding: 7px 12px 7px 30px; }
.cat-tools select:hover, .cat-tools select:focus-visible {
  border-color: var(--wa-hue-glow);
  box-shadow: 0 0 0 3px var(--wa-hue-soft);
  outline: none;
}
.cat-tools-count { font-size: 11.5px; color: #64748b; margin-inline-start: auto; }
.cat-tools-reset {
  background: none;
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #94a3b8;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.cat-tools-reset:hover { color: var(--wa-hue); border-color: var(--wa-hue-glow); }
.cat-empty {
  padding: 34px 16px;
  text-align: center;
  color: #94a3b8;
  font-size: 13.5px;
  border: 1px dashed rgba(148, 163, 184, 0.3);
  border-radius: 14px;
  grid-column: 1 / -1;
}

/* ------------------------------------------------------- sound toggle */
.wa-sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 38px;
  min-height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.7);
  color: #e2e8f0;
  font-size: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.wa-sound-btn:hover { border-color: rgba(34, 211, 238, 0.55); box-shadow: 0 0 14px -2px rgba(34, 211, 238, 0.4); }
.wa-sound-btn:active { transform: scale(0.94); }
.wa-sound-btn[aria-pressed="true"] { color: #64748b; border-color: rgba(148, 163, 184, 0.2); }
.wa-sound-btn .wa-sound-label { font-size: 11px; font-weight: 800; }

/* -------------------------------------------------------- season card */
@media (min-width: 1024px) {
  .wa-retention-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.wa-season-card {
  border-radius: 18px;
  border: 1px solid rgba(139, 92, 246, 0.35);
  background:
    radial-gradient(120% 130% at 85% 0%, rgba(139, 92, 246, 0.16), transparent 55%),
    radial-gradient(100% 120% at 0% 100%, rgba(245, 196, 81, 0.10), transparent 55%),
    linear-gradient(150deg, rgba(17, 24, 39, 0.95), rgba(10, 14, 25, 0.97));
  padding: 16px;
  color: #e2e8f0;
  position: relative;
  overflow: hidden;
}
.wa-season-card h3 { margin: 0 0 2px; font-size: 14px; font-weight: 900; color: #fff; display: flex; align-items: center; gap: 8px; }
.wa-season-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.wa-season-head > div { flex: 1; min-width: 0; }
.wa-season-ico { font-size: 22px; filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.6)); }
.wa-season-title { font-size: 14px; font-weight: 900; color: #fff; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wa-season-mins { font-size: 12px; font-weight: 900; color: #fde68a; white-space: nowrap; font-variant-numeric: tabular-nums; }
.wa-season-card .wa-season-sub { font-size: 11px; color: #94a3b8; margin: 2px 0 0; }
.wa-season-month {
  font-size: 9.5px; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase;
  color: #c4b5fd; background: rgba(139, 92, 246, 0.14); border: 1px solid rgba(139, 92, 246, 0.4);
  padding: 2px 8px; border-radius: 999px;
}
.wa-season-bar { height: 8px; border-radius: 999px; background: rgba(148, 163, 184, 0.15); overflow: hidden; margin: 8px 0 10px; }
.wa-season-bar i, .wa-season-bar span {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #8b5cf6, #f5c451);
  box-shadow: 0 0 10px rgba(245, 196, 81, 0.5);
  transition: width 0.6s cubic-bezier(0.22, 0.9, 0.3, 1);
}
.wa-season-next { font-size: 10.5px; color: #94a3b8; margin-bottom: 10px; }
.wa-season-tiers { display: flex; flex-direction: column; gap: 6px; }
.wa-season-tier {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid rgba(148, 163, 184, 0.16); border-radius: 12px;
  padding: 7px 10px; background: rgba(15, 23, 42, 0.55); font-size: 11.5px;
}
.wa-season-tier .wa-tier-ico { font-size: 16px; }
.wa-season-tier .wa-tier-name { font-weight: 800; color: #e2e8f0; flex: 1; min-width: 0; }
.wa-season-tier .wa-tier-req { color: #64748b; font-size: 10px; white-space: nowrap; }
.wa-season-tier .wa-tier-prize { color: #a5b4fc; font-size: 10px; font-weight: 800; white-space: nowrap; }
.wa-season-tier .wa-tier-state { font-size: 10px; font-weight: 800; color: #6ee7b7; white-space: nowrap; }
.wa-season-tier .wa-tier-locked { color: #64748b; }
.wa-season-tier.wa-tier-ready { border-color: rgba(245, 196, 81, 0.5); box-shadow: 0 0 14px -6px rgba(245, 196, 81, 0.5); }
.wa-season-tier button {
  border: none; border-radius: 9px; padding: 5px 12px; font-size: 10.5px; font-weight: 900;
  cursor: pointer; background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #fff;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.wa-season-tier button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px -6px rgba(139, 92, 246, 0.8); }
.wa-season-tier button:disabled { background: rgba(148, 163, 184, 0.15); color: #64748b; cursor: default; }
.wa-season-tier.wa-tier-done { border-color: rgba(52, 211, 153, 0.4); }
.wa-season-tier.wa-tier-done .wa-tier-name { color: #6ee7b7; }
.wa-season-pass {
  margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 11px; border-top: 1px dashed rgba(148, 163, 184, 0.2); padding-top: 10px;
}
.wa-season-pass a { color: #f5c451; font-weight: 800; text-decoration: none; }
.wa-season-pass a:hover { text-decoration: underline; }
a.wa-season-pass { text-decoration: none; transition: background 0.15s ease; border-radius: 10px; }
a.wa-season-pass:hover { background: rgba(245, 196, 81, 0.06); text-decoration: none; }
.wa-pass-days { color: #6ee7b7; font-weight: 800; font-size: 10.5px; }
.wa-pass-arrow { color: #f5c451; font-weight: 900; margin-inline-start: auto; }
.wa-pass-on .wa-pass-chip { color: #6ee7b7; background: rgba(52, 211, 153, 0.12); border-color: rgba(52, 211, 153, 0.45); }
.wa-pass-chip {
  font-size: 9.5px; font-weight: 900; color: #fde68a; background: rgba(245, 196, 81, 0.12);
  border: 1px solid rgba(245, 196, 81, 0.45); border-radius: 999px; padding: 2px 9px;
}

/* ---------------------------------------------------- challenge banner */
.wa-challenge-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 10px auto 0; max-width: 1100px;
  border: 1px solid rgba(255, 106, 61, 0.5); border-radius: 16px;
  background:
    radial-gradient(120% 160% at 0% 0%, rgba(255, 106, 61, 0.16), transparent 55%),
    linear-gradient(135deg, rgba(23, 16, 12, 0.95), rgba(12, 10, 18, 0.97));
  padding: 12px 16px; color: #e2e8f0; font-size: 13px;
  box-shadow: 0 10px 30px -14px rgba(255, 106, 61, 0.6);
}
.wa-challenge-banner .wa-ch-ico { font-size: 24px; filter: drop-shadow(0 0 8px rgba(255, 106, 61, 0.6)); }
.wa-challenge-banner b { color: #ffb020; }
.wa-challenge-banner .wa-ch-score { margin-inline-start: auto; font-weight: 900; font-variant-numeric: tabular-nums; color: #fff; font-size: 12.5px; }
.wa-challenge-banner.wa-ch-won { border-color: rgba(52, 211, 153, 0.6); background: radial-gradient(120% 160% at 0% 0%, rgba(52, 211, 153, 0.16), transparent 55%), linear-gradient(135deg, rgba(10, 22, 16, 0.95), rgba(10, 14, 20, 0.97)); }
.wa-challenge-banner .wa-ch-close {
  background: none; border: none; color: #64748b; font-size: 15px; cursor: pointer; padding: 4px;
}
.wa-challenge-banner .wa-ch-close:hover { color: #fff; }

/* ---------------------------------------------------- achievement seals */
.wa-ach-overlay {
  position: fixed; inset: 0; z-index: 100000;
  background: rgba(2, 6, 23, 0.78); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.wa-ach-modal {
  width: min(560px, 100%); max-height: 86vh; overflow-y: auto;
  border-radius: 22px; border: 1px solid rgba(245, 196, 81, 0.4);
  background:
    radial-gradient(130% 120% at 50% 0%, rgba(245, 196, 81, 0.12), transparent 55%),
    linear-gradient(160deg, #131a2b, #0a0e19);
  padding: 22px; color: #e2e8f0;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.9), 0 0 40px -12px rgba(245, 196, 81, 0.35);
}
.wa-ach-modal h2 { margin: 0 0 4px; font-size: 19px; font-weight: 900; color: #fff; display: flex; align-items: center; gap: 10px; }
.wa-ach-modal .wa-ach-sub { font-size: 12px; color: #94a3b8; margin: 0 0 16px; }
.wa-ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.wa-seal {
  border-radius: 16px; padding: 14px 12px; text-align: center;
  border: 1px solid rgba(148, 163, 184, 0.18); background: rgba(15, 23, 42, 0.6);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
}
.wa-seal .wa-seal-ico { font-size: 30px; display: block; margin-bottom: 6px; filter: grayscale(1) opacity(0.4); }
.wa-seal b { display: block; font-size: 12px; color: #94a3b8; margin-bottom: 3px; }
.wa-seal small { font-size: 10px; color: #64748b; line-height: 1.4; display: block; }
.wa-seal.wa-seal-on {
  border-color: rgba(245, 196, 81, 0.55);
  background: radial-gradient(100% 100% at 50% 0%, rgba(245, 196, 81, 0.14), transparent 70%), rgba(15, 23, 42, 0.7);
  box-shadow: 0 0 18px -6px rgba(245, 196, 81, 0.5);
}
.wa-seal.wa-seal-on .wa-seal-ico { filter: none; }
.wa-seal.wa-seal-on b { color: #fde68a; }
.wa-seal.wa-seal-on:hover { transform: translateY(-3px); }
.wa-ach-close {
  margin-top: 16px; width: 100%; border: none; border-radius: 12px; padding: 10px;
  background: linear-gradient(135deg, #f5c451, #d97706); color: #1c1204; font-weight: 900;
  font-size: 13px; cursor: pointer;
}
.wa-ach-count { font-size: 11px; font-weight: 800; color: #f5c451; }

/* --------------------------------------------------- related categories */
.wa-related-cats .wa-rel-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.25); background: #0f172a;
  border-radius: 999px; padding: 6px 14px; text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.wa-related-cats .wa-rel-link:hover {
  color: #fff; border-color: var(--wa-rel-hue, #22d3ee);
  box-shadow: 0 0 14px -4px var(--wa-rel-hue, #22d3ee);
}

/* ------------------------------------------------- cross-doc transitions */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: waVtOut 0.18s ease both; }
::view-transition-new(root) { animation: waVtIn 0.24s ease both; }
@keyframes waVtOut { to { opacity: 0; transform: translateY(-6px); } }
@keyframes waVtIn { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}