/* cosmetics.css — profile CARD decorations + the NX cosmetics shop UI.
   Avatar decorations live in dashboard.css (.avatar-decoration[data-decoration]).

   Card decorations are applied by setting data-card-decoration="<id>" on a
   card container: #profile-popout, #user-profile-popout, or a
   .card-deco-preview swatch in the shop. They're pure CSS overlays drawn with
   ::before / ::after, so the container only needs position (fixed/relative)
   and overflow:hidden, which the popouts already have. Ids must match
   server/config/cosmetics_catalog.json. */

[data-card-decoration]::before,
[data-card-decoration]::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  border-radius: inherit;
  display: none;
}
[data-card-decoration="aurora"]::before,
[data-card-decoration="aurora"]::after,
[data-card-decoration="neon"]::before,
[data-card-decoration="neon"]::after,
[data-card-decoration="sakura"]::before,
[data-card-decoration="sakura"]::after,
[data-card-decoration="starfield"]::before,
[data-card-decoration="starfield"]::after { display: block; }

/* Aurora: drifting colour wash + gradient frame */
[data-card-decoration="aurora"]::before {
  background:
    radial-gradient(120% 60% at 20% 0%, rgba(80,255,190,.28), transparent 60%),
    radial-gradient(100% 60% at 85% 10%, rgba(150,110,255,.30), transparent 60%),
    radial-gradient(90% 50% at 50% 100%, rgba(80,170,255,.20), transparent 65%);
  background-size: 160% 160%;
  mix-blend-mode: screen;
  animation: card-deco-aurora 9s ease-in-out infinite alternate;
}
[data-card-decoration="aurora"]::after {
  padding: 2px;
  background: linear-gradient(135deg, #5dffc2, #8e6bff, #4fb3ff, #5dffc2);
  background-size: 300% 300%;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  animation: card-deco-shift 6s linear infinite;
}

/* Neon edge: pulsing outline + inner glow */
[data-card-decoration="neon"]::before {
  box-shadow: inset 0 0 0 2px #ff4fd8, inset 0 0 18px rgba(255,79,216,.55), inset 0 0 40px rgba(90,200,255,.25);
  animation: card-deco-neon 2.4s ease-in-out infinite;
}
[data-card-decoration="neon"]::after {
  box-shadow: 0 0 14px rgba(255,79,216,.6), 0 0 30px rgba(90,200,255,.35);
  animation: card-deco-neon 2.4s ease-in-out infinite;
}

/* Sakura: petals drifting down (tiled radial petals, two parallax layers) */
[data-card-decoration="sakura"]::before {
  background-image:
    radial-gradient(ellipse 5px 3px at 20px 14px, #ffb7d5 60%, transparent 62%),
    radial-gradient(ellipse 4px 2.5px at 90px 60px, #ffd0e4 60%, transparent 62%),
    radial-gradient(ellipse 5px 3px at 150px 30px, #ff9cc6 60%, transparent 62%),
    radial-gradient(ellipse 4px 2.5px at 230px 80px, #ffc2dc 60%, transparent 62%);
  background-size: 260px 120px;
  animation: card-deco-fall 7s linear infinite;
}
[data-card-decoration="sakura"]::after {
  background-image:
    radial-gradient(ellipse 4px 2.5px at 60px 20px, #ffc8e0 60%, transparent 62%),
    radial-gradient(ellipse 5px 3px at 180px 70px, #ff9cc6 60%, transparent 62%),
    radial-gradient(ellipse 3.5px 2px at 120px 100px, #ffd8ea 60%, transparent 62%);
  background-size: 220px 140px;
  animation: card-deco-fall 11s linear infinite;
  opacity: .8;
}

/* Starfield: twinkling stars + faint nebula tint */
[data-card-decoration="starfield"]::before {
  background:
    radial-gradient(1.5px 1.5px at 18px 22px, #fff, transparent),
    radial-gradient(1px 1px at 70px 90px, #cfe3ff, transparent),
    radial-gradient(1.5px 1.5px at 130px 40px, #fff, transparent),
    radial-gradient(1px 1px at 200px 120px, #ffe9b8, transparent),
    radial-gradient(1.5px 1.5px at 250px 60px, #fff, transparent),
    radial-gradient(1px 1px at 40px 150px, #cfe3ff, transparent);
  background-size: 280px 180px;
  animation: card-deco-twinkle 3.2s ease-in-out infinite;
}
[data-card-decoration="starfield"]::after {
  background: radial-gradient(80% 60% at 70% 20%, rgba(120,90,255,.22), transparent 70%),
              radial-gradient(70% 50% at 20% 90%, rgba(60,120,255,.18), transparent 70%);
  box-shadow: inset 0 0 0 1px rgba(170,180,255,.35);
  animation: card-deco-twinkle 5s ease-in-out infinite reverse;
}

@keyframes card-deco-aurora { 0% { background-position: 0% 0%; opacity:.75; } 100% { background-position: 100% 100%; opacity:1; } }
@keyframes card-deco-shift  { 0% { background-position: 0% 50%; } 100% { background-position: 300% 50%; } }
@keyframes card-deco-neon   { 0%,100% { opacity:.65; } 50% { opacity:1; } }
@keyframes card-deco-fall   { from { background-position: 0 0; } to { background-position: -30px 140px; } }
@keyframes card-deco-twinkle{ 0%,100% { opacity:.55; } 50% { opacity:1; } }

@media (prefers-reduced-motion: reduce) {
  [data-card-decoration]::before,
  [data-card-decoration]::after { animation: none !important; }
}

/* ── Settings: cosmetics shop ─────────────────────────────── */
#view-settings .cosmetics-shop-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 6px; flex-wrap: wrap;
}
#view-settings .shop-balance {
  font-size: .8rem; padding: 4px 10px; border-radius: 999px;
  background: var(--bg-secondary); border: 1px solid var(--border-color); color: var(--text-primary);
}
#view-settings .shop-balance strong { color: var(--accent); }
#view-settings .shop-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 10px; margin-top: 10px;
}
#view-settings .shop-tile {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 10px 7px 8px; border: 1px solid var(--border-color); border-radius: 10px;
  background: var(--bg-secondary); color: var(--text-primary); font-size: .75rem; text-align: center;
  transition: border-color .15s ease, background .15s ease;
}
#view-settings .shop-tile.selectable { cursor: pointer; }
#view-settings .shop-tile.selectable:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-color)); }
#view-settings .shop-tile.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-secondary));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}
#view-settings .shop-tile .shop-name { font-weight: 600; }
#view-settings .shop-tile .shop-state { font-size: .7rem; color: var(--text-muted); }
#view-settings .shop-buy-btn {
  width: 100%; padding: 5px 8px; border: none; border-radius: 7px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: .72rem; font-weight: 600;
}
#view-settings .shop-buy-btn:hover { background: var(--accent-hover); }
#view-settings .shop-buy-btn:disabled { opacity: .55; cursor: default; }
#view-settings .shop-buy-btn.cant { background: var(--bg-tertiary, #444); color: var(--text-muted); }
#view-settings .card-deco-preview {
  position: relative; overflow: hidden; width: 100%; height: 58px; border-radius: 8px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 55%, #000), var(--bg-modal-card, var(--bg-secondary)));
  border: 1px solid var(--border-color);
}
#view-settings .shop-error { color: #ff6b6b; font-size: .78rem; margin-top: 8px; }

/* ── Profile effect (ring + sparks) is bought in the shop ───────────────
   The markup exists on every card, but it's only drawn when the owner has
   bought and equipped the effect (users.profile_effect). dashboard.js toggles
   .has-profile-effect on the .profile-effect-host. */
.profile-effect-host:not(.has-profile-effect) .profile-effect,
.profile-effect-host:not(.has-profile-effect) .profile-effect-ring { display: none !important; }

/* ── Compact profile effect for small avatars ─────────────────────────
   Same look as the big card effect (spinning ring + sparkles) but sized
   from the avatar it wraps, for: the bottom-left user panel, DM list,
   member list and the Settings avatar preview. The element only exists in
   the DOM for users who equipped the effect (dashboard.js: setAvatarFx), so there's
   nothing to gate here. The wrapper must be position:relative. */
.avatar-fx {
  --fx-inset: 5px;
  position: absolute;
  inset: calc(var(--fx-inset) * -1);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
.avatar-fx-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: .9;
  background: conic-gradient(from 0deg,
    transparent 0deg, rgba(253,102,113,.08) 35deg, rgba(253,102,113,.85) 85deg,
    rgba(255,190,196,.98) 125deg, transparent 175deg, transparent 235deg,
    rgba(253,102,113,.6) 290deg, transparent 330deg);
  -webkit-mask: radial-gradient(circle, transparent 63%, #000 65%, #000 71%, transparent 73%);
  mask: radial-gradient(circle, transparent 63%, #000 65%, #000 71%, transparent 73%);
  animation: profile-effect-spin 4.8s linear infinite;
}
.avatar-fx::after {
  content: "";
  position: absolute;
  inset: calc(var(--fx-inset) * .6);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(253,102,113,.45);
  animation: profile-effect-pulse 2.2s ease-in-out infinite;
}
.avatar-fx-spark {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 5px rgba(255,255,255,.95), 0 0 9px rgba(253,102,113,.85);
  opacity: 0;
  animation: profile-effect-float 2.8s ease-in-out infinite;
}
.avatar-fx-spark.s1 { left: 6%;  top: 16%;    animation-delay: -.2s; }
.avatar-fx-spark.s2 { right: 4%; top: 6%;     animation-delay: -1.1s; }
.avatar-fx-spark.s3 { right: 12%; bottom: 4%; animation-delay: -2s; }
/* The Settings avatar preview is 80px, so give it a roomier ring + bigger sparks. */
.avatar-fx.avatar-fx-lg { --fx-inset: 8px; }
.avatar-fx.avatar-fx-lg .avatar-fx-spark { width: 5px; height: 5px; }

/* wrappers */
.avatar-fx-host { position: relative; flex-shrink: 0; }
#view-app .ml-avatar-wrap { position: relative; flex-shrink: 0; width: 32px; height: 32px; }
#view-app .ml-avatar-wrap .avatar-fx { --fx-inset: 4px; }
#view-app #up-avatar-wrap .avatar-fx { --fx-inset: 4px; }
#view-app .ml-row.offline .avatar-fx { opacity: .55; }

@media (prefers-reduced-motion: reduce) {
  .avatar-fx-ring, .avatar-fx::after, .avatar-fx-spark { animation: none !important; }
  .avatar-fx-spark { opacity: .7; }
}

/* ── Compact avatar decorations ───────────────────────────────────────
   The decoration art (.avatar-decoration in dashboard.css) is drawn for the
   84px profile-card avatar inside a 108px box. On smaller avatars that box is
   centred on the avatar wrapper and scaled by --deco-scale (= avatar px / 84).
   Wrappers are position:relative and isolated so the art can't leak over
   neighbouring UI. */
.avatar-decoration.avatar-decoration-compact {
  --deco-scale: .5;
  --deco-fit: .9;    /* 1 = art at full profile-card proportions; lower = smaller */
  inset: auto;
  left: 50%;
  top: 50%;
  width: 108px;
  height: 108px;
  /* translate (not negative margins) so reset rules like
     "#view-settings * { margin: 0 }" can't knock it off-centre */
  transform: translate(-50%, -50%) scale(calc(var(--deco-scale) * var(--deco-fit)));
  transform-origin: 50% 50%;
}
#view-app .dm-avatar-wrap, #view-app .fr-avatar-wrap,
#view-app .ml-avatar-wrap, #view-app #up-avatar-wrap,
#view-settings .avatar-fx-host { isolation: isolate; }
#view-app .dm-avatar-wrap > .avatar-decoration-compact,
#view-app .fr-avatar-wrap > .avatar-decoration-compact { --deco-scale: .5; }      /* 42px */
#view-app .ml-avatar-wrap > .avatar-decoration-compact { --deco-scale: .381; }    /* 32px */
#view-app #up-avatar-wrap > .avatar-decoration-compact { --deco-scale: .429; }    /* 36px */
#view-settings .avatar-fx-host > .avatar-decoration-compact { --deco-scale: .952; } /* 80px */
#view-app .ml-row.offline .avatar-decoration { opacity: .55; }

/* Profile Effect tile in the Settings shop */
#view-settings .effect-preview {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: block;
  margin: 4px 0;
}
#view-settings .effect-preview .avatar-fx { --fx-inset: 4px; }

/* Presence dots stay on top of avatar decorations and the profile-effect ring,
   so the status looks exactly as it did before they were added. */
#view-app .dm-avatar-wrap .status-pip,
#view-app .fr-avatar-wrap .status-pip,
#view-app #up-status-pip,
#view-app .ml-status-dot { z-index: 6; }


/* In-app "Buy item?" confirmation (settings shop) */
#view-settings .buy-cosmetic-modal { max-width: 380px; }
#view-settings .buy-cosmetic-rows {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-input); border: 1px solid var(--border-color);
  border-radius: 8px; padding: 12px 14px;
}
#view-settings .buy-cosmetic-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .88rem; color: var(--text-muted);
}
#view-settings .buy-cosmetic-row strong { color: var(--text-primary); font-weight: 700; }
#view-settings .buy-cosmetic-row:first-child strong { color: var(--accent); }
#view-settings .buy-cosmetic-error { min-height: 1.1em; margin-top: 10px; font-size: .8rem; color: var(--danger); }
#view-settings .buy-cosmetic-modal .modal-actions { margin-top: 12px; }
#view-settings .buy-cosmetic-modal .btn-primary:disabled { opacity: .5; cursor: not-allowed; }
