/* Release 174 — badge medallion v2 (.nb-medal.nb-v2 from badge-icons-runtime.js).
   Loaded after components.css / profile.css on the dashboard, the public profile and the leaderboard.
   Layers: the medal box is the rim (tier colours), ::before is the face, .nb-fx is the motion layer,
   the glyph <svg> sits on top, ::after is the light sweep. Frames: data-shape circle | hex | shield
   (default squircle). Motion: data-fx shine | glow | float | pulse | sparkle | rotate — only transform and
   opacity are animated, everything is inside prefers-reduced-motion: no-preference, and data-off (set by
   NovaBadges.watch for off-screen medals) pauses it. Locked (not owned) medals never move.
   r181: medals are the moment, but a grid or a row of them never moves all at once at rest. The motion
   loops on the public profile (div#badges in profile-frame.html: the owner chose it) and inside a preview
   that opts in with .nb-live (the badges page preview, the badge creator, a badge's own dialog); anywhere
   else it plays on hover or keyboard focus of the medal or of the control that holds it.
   The medal rules live in @layer components (next to components.css), so surface sheets keep their
   contextual sizes; the dashboard pieces for credits / packs / the creator are in @layer surfaces.
   profile-frame.html loads no tokens, so every --nv-* used in @layer components carries a fallback. */
@layer components {
.nb-medal.nb-v2 {
  --nb-rim-a: color-mix(in srgb, var(--nb-light) 45%, #fff);
  --nb-rim-b: color-mix(in srgb, var(--nb-deep) 70%, #000);
  --nb-amp: 1;
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--nb-size, 28px);
  height: var(--nb-size, 28px);
  border-radius: 32%;
  color: #fff;
  background: linear-gradient(150deg, var(--nb-rim-a) 0%, var(--nb-deep) 52%, var(--nb-rim-b) 100%);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--nb-deep) 50%, transparent),
    0 3px 10px -3px color-mix(in srgb, var(--nb-glow) 70%, transparent);
  overflow: hidden;
  isolation: isolate;
}
.nb-medal.nb-v2::before,
.nb-medal.nb-v2::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.nb-medal.nb-v2::before {
  inset: 9%;
  z-index: -1;
  border-radius: 28%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .38) 0%, rgba(255, 255, 255, 0) 46%),
    radial-gradient(130% 105% at 28% 12%, color-mix(in srgb, var(--nb-light) 62%, #fff) 0%, var(--nb-light) 34%, var(--nb-deep) 100%);
  box-shadow: inset 0 -2px 3px color-mix(in srgb, var(--nb-deep) 80%, #000 20%);
}
.nb-medal.nb-v2::after {
  inset: -30%;
  z-index: 2;
  background: linear-gradient(115deg, transparent 40%, rgba(255, 255, 255, .5) 50%, transparent 60%);
  transform: translateX(-80%);
  animation: none;
  opacity: .9;
}
.nb-medal.nb-v2 svg {
  position: relative;
  z-index: 1;
  width: 56%;
  height: 56%;
  overflow: visible;
  filter: drop-shadow(0 1px 0 color-mix(in srgb, var(--nb-deep) 85%, #000));
  animation: none;
}
.nb-v2 .nb-fx {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  pointer-events: none;
}

/* ---- Tiers (rim) ---- */
.nb-medal.nb-v2[data-tier="rare"] {
  --nb-rim-a: #ffffff;
  --nb-rim-b: color-mix(in srgb, var(--nb-deep) 55%, #1b2233);
}
.nb-medal.nb-v2[data-tier="epic"] {
  --nb-rim-a: color-mix(in srgb, var(--nb-light) 30%, #fff);
  background: linear-gradient(150deg, var(--nb-rim-a) 0%, var(--nb-light) 30%, var(--nb-deep) 62%, var(--nb-rim-b) 100%);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--nb-deep) 55%, transparent),
    0 0 0 2.5px color-mix(in srgb, var(--nb-light) 35%, transparent),
    0 4px 12px -3px color-mix(in srgb, var(--nb-glow) 80%, transparent);
}
.nb-medal.nb-v2[data-tier="legendary"] {
  background: conic-gradient(from 200deg, #fff8d6, var(--nb-light) 18%, #ffd36b 34%, var(--nb-deep) 52%, #ffffff 66%, var(--nb-light) 80%, #fff8d6);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--nb-deep) 60%, transparent),
    0 0 0 2.5px color-mix(in srgb, #ffd36b 45%, transparent),
    0 4px 14px -3px color-mix(in srgb, var(--nb-glow) 85%, transparent);
}
.nb-v2[data-tier="legendary"] .nb-fx {
  inset: -30%;
  border-radius: 0;
  background: conic-gradient(from 0deg, transparent 0 14%, rgba(255, 255, 255, .55) 21%, transparent 28% 60%, rgba(255, 255, 255, .38) 68%, transparent 76%);
  opacity: .75;
}

/* ---- Frames ---- */
.nb-medal.nb-v2[data-shape="circle"],
.nb-medal.nb-v2[data-shape="circle"]::before { border-radius: 50%; }
.nb-medal.nb-v2[data-shape="hex"],
.nb-medal.nb-v2[data-shape="hex"]::before {
  border-radius: 0;
  clip-path: polygon(50% 0, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%);
}
.nb-medal.nb-v2[data-shape="shield"],
.nb-medal.nb-v2[data-shape="shield"]::before {
  border-radius: 0;
  clip-path: polygon(50% 0, 100% 13%, 100% 50%, 93% 70%, 78% 86%, 50% 100%, 22% 86%, 7% 70%, 0 50%, 0 13%);
}
.nb-medal.nb-v2[data-shape="hex"]::before { inset: 10%; }
.nb-medal.nb-v2[data-shape="shield"]::before { inset: 9% 9% 10%; }
.nb-medal.nb-v2[data-shape="hex"] svg,
.nb-medal.nb-v2[data-shape="shield"] svg { width: 52%; height: 52%; }
.nb-medal.nb-v2[data-shape="shield"] svg { transform: translateY(-4%); }
/* A clipped frame loses its box-shadow ring; a drop glow on the parent row keeps it readable on light pages. */
.nb-medal.nb-v2[data-shape="hex"],
.nb-medal.nb-v2[data-shape="shield"] { box-shadow: none; }

/* Uploaded picture sits on the face, inside the rim. */
.nb-medal.nb-v2 .nb-medal-img {
  inset: 9%;
  width: 82%;
  height: 82%;
  z-index: 1;
  border-radius: 28%;
}
.nb-medal.nb-v2[data-shape="circle"] .nb-medal-img { border-radius: 50%; }
.nb-medal.nb-v2[data-shape="hex"] .nb-medal-img { border-radius: 0; clip-path: polygon(50% 0, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%); }
.nb-medal.nb-v2[data-shape="shield"] .nb-medal-img { border-radius: 0; clip-path: polygon(50% 0, 100% 13%, 100% 50%, 93% 70%, 78% 86%, 50% 100%, 22% 86%, 7% 70%, 0 50%, 0 13%); }

/* ---- Motion layers (static parts) ---- */
.nb-v2[data-fx="glow"] .nb-fx {
  background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--nb-light) 55%, #fff) 0%, transparent 62%);
  opacity: .25;
}
.nb-v2[data-fx="sparkle"] .nb-fx::before,
.nb-v2[data-fx="sparkle"] .nb-fx::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  background: #fff;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: .9;
}
.nb-v2[data-fx="sparkle"] .nb-fx::before { top: 9%; right: 10%; }
.nb-v2[data-fx="sparkle"] .nb-fx::after { bottom: 12%; left: 11%; width: 18%; height: 18%; opacity: .7; }
.nb-medal.nb-v2.is-locked,
.is-locked .nb-medal.nb-v2 { filter: saturate(.55); opacity: .72; }

/* Small sizes (profile row 18–24 px): thinner rim, no sparkles that would turn to noise. */
#badges .nb-medal.nb-v2::before,
.bp-pv-medals .nb-medal.nb-v2::before { inset: 8%; }
#badges .nb-v2[data-fx="sparkle"] .nb-fx::after { display: none; }

@media (prefers-reduced-motion: no-preference) {
  /* Every rule below is (0,2,1) or more: the context sits in :where(), so the order decides — hover, then the
     live loop (a hovered live medal keeps looping), then the medals that never move. */
  .nb-medal.nb-v2 { transition: transform var(--nv-dur-2, .2s) var(--nv-ease, cubic-bezier(.2, .8, .2, 1)); }
  .badge:hover .nb-medal.nb-v2 { transform: translateY(-1px) scale(1.07); }

  /* Hover / keyboard focus: the light sweeps once and the medal's own motion runs while the pointer stays. */
  :where(a, button, label, .bp-tile, .bp-chip, .badge):where(:hover, :focus-visible) .nb-medal.nb-v2::after,
  .nb-medal.nb-v2:where(:hover, :focus-visible)::after { animation: nbV2SweepOnce .9s var(--nv-ease, cubic-bezier(.22, 1, .36, 1)) both; }

  /* Live: the public profile and the previews that opt in. */
  :where(div#badges, .nb-live) .nb-medal.nb-v2::after,
  .nb-medal.nb-v2:where(.nb-live)::after { animation: nbV2Sweep 7s ease-in-out infinite; animation-delay: calc(var(--nb-i, 0) * .6s); }
  :where(div#badges, .nb-live) .nb-medal.nb-v2[data-fx="shine"]::after,
  .nb-medal.nb-v2:where(.nb-live)[data-fx="shine"]::after { animation-duration: 4.2s; }

  :where(div#badges, .nb-live, :is(a, button, label, .bp-tile, .bp-chip, .badge):is(:hover, :focus-visible)) .nb-v2[data-fx="float"] svg,
  .nb-v2:where(.nb-live, :hover, :focus-visible)[data-fx="float"] svg { animation: nbV2Float 3.2s ease-in-out infinite; }
  :where(div#badges, .nb-live, :is(a, button, label, .bp-tile, .bp-chip, .badge):is(:hover, :focus-visible)) .nb-v2[data-fx="pulse"] svg,
  .nb-v2:where(.nb-live, :hover, :focus-visible)[data-fx="pulse"] svg { animation: nbV2Pulse 2.6s ease-in-out infinite; }
  :where(div#badges, .nb-live, :is(a, button, label, .bp-tile, .bp-chip, .badge):is(:hover, :focus-visible)) .nb-v2[data-fx="glow"] .nb-fx,
  .nb-v2:where(.nb-live, :hover, :focus-visible)[data-fx="glow"] .nb-fx { animation: nbV2Glow 2.8s ease-in-out infinite; }
  :where(div#badges, .nb-live, :is(a, button, label, .bp-tile, .bp-chip, .badge):is(:hover, :focus-visible)) .nb-v2[data-fx="sparkle"] .nb-fx::before,
  .nb-v2:where(.nb-live, :hover, :focus-visible)[data-fx="sparkle"] .nb-fx::before { animation: nbV2Twinkle 2.4s ease-in-out infinite; }
  :where(div#badges, .nb-live, :is(a, button, label, .bp-tile, .bp-chip, .badge):is(:hover, :focus-visible)) .nb-v2[data-fx="sparkle"] .nb-fx::after,
  .nb-v2:where(.nb-live, :hover, :focus-visible)[data-fx="sparkle"] .nb-fx::after { animation: nbV2Twinkle 2.4s ease-in-out 1.2s infinite; }
  :where(div#badges, .nb-live, :is(a, button, label, .bp-tile, .bp-chip, .badge):is(:hover, :focus-visible)) .nb-v2[data-tier="legendary"] .nb-fx,
  .nb-v2:where(.nb-live, :hover, :focus-visible)[data-tier="legendary"] .nb-fx { animation: nbV2Spin 7s linear infinite; }
  .nb-v2[data-fx="rotate"][data-tier="legendary"] .nb-fx { animation-duration: 5s; }

  /* Public profile: the same motion, calmer — slower and with a smaller travel. */
  div#badges .nb-medal.nb-v2 { --nb-amp: .6; }
  div#badges .nb-medal.nb-v2::after { animation-duration: 9s; }
  div#badges .nb-v2[data-fx="float"] svg { animation-duration: 4.4s; }
  div#badges .nb-v2[data-fx="pulse"] svg { animation-duration: 3.6s; }
  div#badges .nb-v2[data-tier="legendary"] .nb-fx { animation-duration: 10s; }

  /* Off-screen (NovaBadges.watch), motion-free and locked medals stay still. */
  .nb-medal.nb-v2[data-fx="none"]::after { animation: none; }
  .nb-v2[data-off],
  .nb-v2[data-off]::after,
  .nb-v2[data-off] *,
  .nb-v2[data-off] *::before,
  .nb-v2[data-off] *::after { animation-play-state: paused; }
  .nb-medal.nb-v2.is-locked::after,
  .is-locked .nb-medal.nb-v2::after,
  .is-locked .nb-v2 svg,
  .is-locked .nb-v2 .nb-fx,
  .is-locked .nb-v2 .nb-fx::before,
  .is-locked .nb-v2 .nb-fx::after { animation: none; }
}
@media (prefers-reduced-motion: reduce) {
  .nb-medal.nb-v2,
  .nb-medal.nb-v2::after,
  .nb-medal.nb-v2 svg,
  .nb-v2 .nb-fx,
  .nb-v2 .nb-fx::before,
  .nb-v2 .nb-fx::after { animation: none; transition: none; }
}
@keyframes nbV2Sweep { 0%, 72% { transform: translateX(-80%); } 88%, 100% { transform: translateX(80%); } }
@keyframes nbV2SweepOnce { from { transform: translateX(-80%); } to { transform: translateX(80%); } }
@keyframes nbV2Float { 50% { transform: translateY(calc(-9% * var(--nb-amp, 1))); } }
@keyframes nbV2Pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(calc(1 + .1 * var(--nb-amp, 1))); } }
@keyframes nbV2Glow { 0%, 100% { opacity: .15; } 50% { opacity: .85; } }
@keyframes nbV2Twinkle { 0%, 100% { transform: scale(.2) rotate(0deg); opacity: 0; } 45% { transform: scale(1) rotate(45deg); opacity: .95; } 70% { transform: scale(.6) rotate(70deg); opacity: .4; } }
@keyframes nbV2Spin { to { transform: rotate(360deg); } }
}

@layer surfaces {
  /* Collection tile: the rarity is a quiet word above the name; the medal's rim already shows the tier. */
  .bp-tier {
    justify-self: start;
    margin-bottom: 2px;
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    font-weight: var(--nv-fw-regular);
  }

  /* Own badge card: the credits are quiet meta (figure in mono), the packs are plain choices. */
  .bp-credits {
    display: inline-flex;
    align-items: baseline;
    gap: var(--nv-space-1);
    margin-top: var(--nv-space-1);
    color: var(--nv-text-2);
    font-size: var(--nv-fs-13);
  }
  .bp-credits b {
    color: var(--nv-text);
    font-family: var(--nv-font-figure);
    font-size: var(--nv-fs-14);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
  }
  .bp-create-actions { display: grid; justify-items: stretch; gap: var(--nv-space-2); }
  .bp-create-packs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--nv-space-2);
    width: 100%;
    margin-top: var(--nv-space-3);
  }
  .bp-create-pack,
  .bp-pack {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 2px;
    min-height: 64px;
    padding: var(--nv-space-2);
    border: 1px solid var(--nv-line-strong);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
    color: var(--nv-text);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }
  .bp-create-pack b,
  .bp-pack b { font-size: var(--nv-fs-13); font-weight: var(--nv-fw-medium); }
  .bp-create-pack span,
  .bp-pack strong {
    font-family: var(--nv-font-figure);
    font-size: var(--nv-fs-16);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
  }
  .bp-create-pack small,
  .bp-pack small { color: var(--nv-text-3); font-size: var(--nv-fs-12); }
  /* The saving is the one good change on a pack: quiet green text. */
  .bp-create-pack small { color: var(--nv-success); }
  .bp-create-pack:hover,
  .bp-pack:hover { border-color: var(--nv-field-line-hover); background: var(--nv-surface-3); }
  .bp-pack[aria-checked="true"] { border-color: var(--nv-accent-line); background: var(--nv-surface-3); }
  .bp-packs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--nv-space-2); }
  .bp-pack-art { display: flex; align-items: center; justify-content: center; gap: var(--nv-space-3); padding: var(--nv-space-1) 0 0; }
  .bp-pack-hint { margin: 0; }
  .bp-create-gift { justify-self: end; }

  /* Creator: ready-made designs, frame and motion chips. The choice is a surface step with an accent hairline. */
  .bp-own-presets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
    gap: var(--nv-space-2);
  }
  .bp-own-preset {
    display: grid;
    justify-items: center;
    gap: var(--nv-space-1);
    padding: var(--nv-space-2) var(--nv-space-1);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--nv-surface-2);
    color: var(--nv-text-2);
    cursor: pointer;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }
  .bp-own-preset small { font-size: var(--nv-fs-12); }
  .bp-own-preset:hover { border-color: var(--nv-line-strong); background: var(--nv-surface-3); }
  .bp-own-preset[aria-pressed="true"] { border-color: var(--nv-accent-line); background: var(--nv-surface-3); color: var(--nv-text); }
  .bp-own-preset-art { display: grid; pointer-events: none; }
  .bp-own-chips { display: flex; flex-wrap: wrap; gap: var(--nv-space-2); }
  .bp-own-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-2);
    min-height: var(--nv-h-md);
    padding: var(--nv-space-1) var(--nv-space-3) var(--nv-space-1) var(--nv-space-2);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-control);
    background: var(--nv-surface-2);
    font-size: var(--nv-fs-13);
    cursor: pointer;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }
  .bp-own-chip.is-text { padding-left: var(--nv-space-3); }
  .bp-own-chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
  .bp-own-chip:hover { border-color: var(--nv-line-strong); }
  .bp-own-chip:has(input:checked) { border-color: var(--nv-accent-line); background: var(--nv-surface-3); }
  .bp-own-chip:has(input:focus-visible),
  .bp-own-preset:focus-visible { box-shadow: var(--nv-focus-ring); }
  .bp-own-chip-art { display: grid; pointer-events: none; }

  @media (max-width: 640px) {
    .bp-create-pack { min-height: 56px; padding: var(--nv-space-2) var(--nv-space-1); }
    .bp-create-actions { grid-column: 1 / -1; }
    .bp-create-gift { grid-column: 1 / -1; justify-self: stretch; }
    .bp-own-presets { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  }
}
