/* ===================== Badges & levels ===================== */
/* Self-contained: everything is scoped to .bdg-* so it can't fight the rest of the app. */

.bdg-scope, .bdg-sheet, .bdg-celebrate, .bdg-chips {
  --bdg-ink: #101628; --bdg-muted: #697187; --bdg-card: #ffffff; --bdg-card-2: #f3f5fb;
  --bdg-line: #e1e5f0; --bdg-track: #e6e9f3; --bdg-accent: #7649f7;
  --r-common-a: #98a2b8; --r-common-b: #c7cedd;
  --r-rare-a: #2f7bff; --r-rare-b: #5cc8ff;
  --r-epic-a: #8b5cf6; --r-epic-b: #e04bd0;
  --r-legendary-a: #f0a020; --r-legendary-b: #ffe27a;
  --r-mythic-a: #22d3ee; --r-mythic-b: #f472b6; --r-mythic-c: #a78bfa;
}
body[data-theme="dark"] .bdg-scope, body[data-theme="dark"] .bdg-sheet, body[data-theme="dark"] .bdg-celebrate, body[data-theme="dark"] .bdg-chips {
  --bdg-ink: #e6edf3; --bdg-muted: #8b949e; --bdg-card: #161b22; --bdg-card-2: #181818;
  --bdg-line: rgba(255,255,255,.14); --bdg-track: #262d38; --bdg-accent: #a78bfa;
}

/* ---------- the hexagon itself ---------- */
.bdg-hex {
  --a: var(--r-common-a); --b: var(--r-common-b);
  --size: 64px;
  align-items: center; background: linear-gradient(145deg, var(--a), var(--b)); clip-path: polygon(50% 0, 94% 25%, 94% 75%, 50% 100%, 6% 75%, 6% 25%);
  display: inline-flex; flex: 0 0 auto; height: var(--size); justify-content: center; position: relative; width: var(--size);
}
.bdg-hex::before {
  background: var(--bdg-card); clip-path: polygon(50% 0, 94% 25%, 94% 75%, 50% 100%, 6% 75%, 6% 25%);
  content: ""; inset: 3px; position: absolute;
}
.bdg-hex::after { /* soft tint of the rarity colour inside the face */
  background: linear-gradient(160deg, color-mix(in srgb, var(--a) 22%, transparent), color-mix(in srgb, var(--b) 6%, transparent));
  clip-path: polygon(50% 0, 94% 25%, 94% 75%, 50% 100%, 6% 75%, 6% 25%); content: ""; inset: 3px; position: absolute;
}
.bdg-hex > span { font-size: calc(var(--size) * .44); line-height: 1; position: relative; z-index: 1; }
.bdg-hex.r-rare { --a: var(--r-rare-a); --b: var(--r-rare-b); }
.bdg-hex.r-epic { --a: var(--r-epic-a); --b: var(--r-epic-b); }
.bdg-hex.r-legendary { --a: var(--r-legendary-a); --b: var(--r-legendary-b); }
.bdg-hex.r-mythic { --a: var(--r-mythic-a); --b: var(--r-mythic-b); background: linear-gradient(120deg, var(--r-mythic-a), var(--r-mythic-c), var(--r-mythic-b), #fde047, var(--r-mythic-a)); background-size: 320% 320%; animation: bdg-flow 5s ease-in-out infinite; }
/* soft rarity glow around earned badges — pro-game-style medals, not flat stickers */
.bdg-hex.r-rare:not(.is-locked) { filter: drop-shadow(0 2px 7px color-mix(in srgb, var(--r-rare-a) 55%, transparent)); }
.bdg-hex.r-epic:not(.is-locked) { filter: drop-shadow(0 2px 9px color-mix(in srgb, var(--r-epic-a) 62%, transparent)); }
.bdg-hex.r-legendary:not(.is-locked) { filter: drop-shadow(0 2px 11px color-mix(in srgb, var(--r-legendary-a) 70%, transparent)); }
.bdg-hex.r-mythic:not(.is-locked) { filter: drop-shadow(0 0 12px color-mix(in srgb, var(--r-mythic-a) 70%, transparent)) drop-shadow(0 0 18px color-mix(in srgb, var(--r-mythic-b) 45%, transparent)); }
.bdg-hex.size-sm { filter: none !important; }
@keyframes bdg-flow { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.bdg-hex.is-locked { --a: var(--bdg-track); --b: var(--bdg-line); }
.bdg-hex.is-locked > span { filter: grayscale(1); opacity: .38; }
.bdg-hex.is-locked::after { display: none; }
.bdg-hex.size-sm { --size: 26px; }
.bdg-hex.size-sm::before, .bdg-hex.size-sm::after { inset: 2px; }
.bdg-hex.size-lg { --size: 120px; }
.bdg-hex.size-lg::before, .bdg-hex.size-lg::after { inset: 5px; }
/* the single "memorable" motion: a light sweep across Legendary badges */
.bdg-hex.r-epic:not(.is-locked) > i, .bdg-hex.r-mythic:not(.is-locked) > i, .bdg-hex.r-legendary:not(.is-locked) > i {
  animation: bdg-sweep 3.6s ease-in-out infinite; background: linear-gradient(110deg, transparent 38%, rgba(255,255,255,.7) 50%, transparent 62%);
  clip-path: polygon(50% 0, 94% 25%, 94% 75%, 50% 100%, 6% 75%, 6% 25%); inset: 0; position: absolute; transform: translateX(-130%); z-index: 2;
}
@keyframes bdg-sweep { 0%, 55% { transform: translateX(-130%); } 100% { transform: translateX(130%); } }

/* ---------- page layout ---------- */
.bdg-scope { color: var(--bdg-ink); display: grid; gap: 14px; padding-bottom: 96px; }
.bdg-card { background: var(--bdg-card); border: 1px solid var(--bdg-line); border-radius: 18px; padding: 16px; }
.bdg-muted { color: var(--bdg-muted); }
.bdg-empty { color: var(--bdg-muted); font-size: 13px; padding: 24px 8px; text-align: center; }

/* hero: level + totals */
.bdg-hero { display: grid; gap: 14px; }
.bdg-hero-top { align-items: center; display: flex; gap: 14px; }
.bdg-level-medal {
  align-items: center; background: conic-gradient(var(--bdg-accent) var(--pct, 0%), var(--bdg-track) 0); border-radius: 50%;
  display: inline-flex; flex: 0 0 auto; height: 68px; justify-content: center; position: relative; width: 68px;
}
.bdg-level-medal::before { background: var(--bdg-card); border-radius: 50%; content: ""; inset: 5px; position: absolute; }
.bdg-level-medal span { font-size: 28px; position: relative; z-index: 1; }
.bdg-hero h2 { font-size: 22px; letter-spacing: -.03em; line-height: 1.1; margin: 0; }
.bdg-hero-sub { color: var(--bdg-muted); font-size: 12px; font-weight: 700; margin: 3px 0 0; }
.bdg-level-link { background: none; color: var(--bdg-accent); cursor: pointer; font-size: 12px; font-weight: 800; padding: 0; text-align: left; }
.bdg-stats { display: grid; gap: 8px; grid-template-columns: repeat(3, 1fr); }
.bdg-stat { background: var(--bdg-card-2); border-radius: 14px; padding: 10px 12px; }
.bdg-stat strong { display: block; font-size: 19px; letter-spacing: -.02em; line-height: 1.15; }
.bdg-stat small { color: var(--bdg-muted); font-size: 11px; font-weight: 700; }
.bdg-next { display: grid; gap: 7px; }
.bdg-bar-row label { color: var(--bdg-muted); display: block; font-size: 11.5px; font-weight: 700; margin-bottom: 4px; }
.bdg-bar { background: var(--bdg-track); border-radius: 99px; height: 7px; overflow: hidden; }
.bdg-bar span { background: linear-gradient(90deg, #7649f7, #3975f4); border-radius: 99px; display: block; height: 100%; min-width: 4px; }

/* pinned shelf */
.bdg-shelf-title { font-size: 13px; font-weight: 800; margin: 0 0 10px; }
.bdg-shelf { display: grid; gap: 8px; grid-template-columns: repeat(3, 1fr); }
.bdg-slot { align-items: center; background: none; border: 0; color: inherit; display: grid; gap: 6px; justify-items: center; padding: 4px 0; text-align: center; }
.bdg-slot b { font-size: 11.5px; line-height: 1.2; }
.bdg-slot.is-empty .bdg-hex { opacity: .5; }
.bdg-slot.is-empty b { color: var(--bdg-muted); font-weight: 700; }

/* category tabs */
.bdg-tabs { display: flex; gap: 8px; margin: 0 -16px; overflow-x: auto; padding: 2px 16px; scrollbar-width: none; }
.bdg-tabs::-webkit-scrollbar { display: none; }
.bdg-tab { background: var(--bdg-card); border: 1px solid var(--bdg-line); border-radius: 99px; color: var(--bdg-muted); flex: 0 0 auto; font-size: 12.5px; font-weight: 800; padding: 8px 13px; }
.bdg-tab[aria-pressed="true"] { background: var(--bdg-ink); border-color: var(--bdg-ink); color: var(--bdg-card); }
.bdg-tab em { font-style: normal; font-weight: 700; margin-left: 5px; opacity: .7; }

/* grid of badge tiles */
.bdg-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 340px) { .bdg-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 700px) { .bdg-grid { grid-template-columns: repeat(4, 1fr); } .bdg-hero { grid-template-columns: 1.2fr 1fr; align-items: center; } }
.bdg-tile { align-content: start; background: var(--bdg-card); border: 1px solid var(--bdg-line); border-radius: 16px; color: inherit; display: grid; gap: 7px; justify-items: center; min-height: 148px; padding: 14px 8px 12px; text-align: center; }
.bdg-tile b { font-size: 12.5px; line-height: 1.2; }
.bdg-tile small { color: var(--bdg-muted); font-size: 11px; font-weight: 700; line-height: 1.25; }
.bdg-tile .bdg-bar { width: 78%; }
.bdg-tile.is-earned small { color: var(--bdg-accent); }

/* custom / admin awarded badge tile note */
.bdg-tag { background: var(--bdg-card-2); border-radius: 6px; color: var(--bdg-muted); font-size: 10px; font-weight: 800; padding: 2px 6px; }

/* ---------- detail sheet ---------- */
.bdg-sheet-wrap { background: rgba(5,8,18,.55); inset: 0; position: fixed; z-index: 1400; display: flex; align-items: flex-end; justify-content: center; }
.bdg-sheet { background: var(--bdg-card); border-radius: 24px 24px 0 0; color: var(--bdg-ink); display: grid; gap: 12px; justify-items: center; max-height: 88vh; max-width: 520px; overflow-y: auto; padding: 22px 20px calc(24px + env(safe-area-inset-bottom, 0px)); text-align: center; width: 100%; animation: bdg-rise .22s ease-out; }
@keyframes bdg-rise { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.bdg-sheet h3 { font-size: 22px; letter-spacing: -.03em; margin: 2px 0 0; }
.bdg-pill { border-radius: 99px; color: #fff; font-size: 11px; font-weight: 800; padding: 4px 10px; background: linear-gradient(120deg, var(--r-common-a), var(--r-common-b)); }
.bdg-pill.r-rare { background: linear-gradient(120deg, var(--r-rare-a), var(--r-rare-b)); }
.bdg-pill.r-epic { background: linear-gradient(120deg, var(--r-epic-a), var(--r-epic-b)); }
.bdg-pill.r-mythic { background: linear-gradient(120deg, var(--r-mythic-a), var(--r-mythic-c), var(--r-mythic-b)); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.bdg-pill.r-legendary { background: linear-gradient(120deg, var(--r-legendary-a), #e8a900); color: #3a2600; }
.bdg-sheet p { color: var(--bdg-muted); font-size: 14px; line-height: 1.5; margin: 0; max-width: 36ch; }
.bdg-sheet .bdg-bar { width: min(260px, 80%); }
.bdg-btn { background: var(--bdg-accent); border-radius: 14px; color: #fff; font-size: 14px; font-weight: 800; padding: 12px 18px; width: 100%; }
.bdg-btn.is-ghost { background: var(--bdg-card-2); color: var(--bdg-ink); }
.bdg-btn[disabled] { opacity: .55; }

/* ---------- unlock celebration ---------- */
.bdg-celebrate { align-items: center; background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--glow, #7649f7) 40%, #181818) 0%, #181818 68%); color: #fff; display: grid; inset: 0; justify-items: center; padding: 28px; position: fixed; text-align: center; z-index: 1500; animation: bdg-fade .25s ease-out; }
@keyframes bdg-fade { from { opacity: 0; } to { opacity: 1; } }
.bdg-celebrate-inner { display: grid; gap: 12px; justify-items: center; max-width: 340px; }
.bdg-celebrate h2 { font-size: 30px; letter-spacing: -.04em; line-height: 1.1; margin: 4px 0 0; }
.bdg-celebrate p { color: rgba(255,255,255,.74); font-size: 14.5px; line-height: 1.5; margin: 0; }
.bdg-celebrate .bdg-kicker { color: rgba(255,255,255,.7); font-size: 13px; font-weight: 800; letter-spacing: .02em; }
.bdg-celebrate .bdg-hex { --size: 150px; animation: bdg-pop .6s cubic-bezier(.2,1.4,.4,1) both; filter: drop-shadow(0 0 28px color-mix(in srgb, var(--glow, #7649f7) 70%, transparent)); }
.bdg-celebrate .bdg-hex::before { background: #202020; }
.bdg-celebrate .bdg-hex > span { font-size: 66px; }
@keyframes bdg-pop { from { transform: scale(.4) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
.bdg-ring { animation: bdg-ripple 1.6s ease-out .15s both; border: 2px solid var(--glow, #7649f7); border-radius: 50%; height: 150px; opacity: 0; position: absolute; width: 150px; }
@keyframes bdg-ripple { from { transform: scale(.7); opacity: .8; } to { transform: scale(2.6); opacity: 0; } }
.bdg-celebrate .bdg-btn { margin-top: 8px; }
.bdg-celebrate .bdg-btn.is-ghost { background: rgba(255,255,255,.1); color: #fff; margin-top: 0; }
.bdg-celebrate-hex-wrap { align-items: center; display: grid; justify-items: center; position: relative; }

/* ---------- little chips on profiles ---------- */
.bdg-chips { align-items: center; background: var(--bdg-card-2); border: 1px solid var(--bdg-line); border-radius: 99px; color: var(--bdg-ink); cursor: pointer; display: inline-flex; gap: 3px; padding: 3px 9px 3px 5px; }
.bdg-chips .bdg-hex { margin-right: -3px; }
.bdg-chips small { color: var(--bdg-muted); font-size: 10.5px; font-weight: 800; margin-left: 7px; }

/* ---------- admin panel ---------- */
.bdg-admin summary { cursor: pointer; font-size: 14px; font-weight: 800; list-style: none; }
.bdg-admin summary::-webkit-details-marker { display: none; }
.bdg-admin-body { display: grid; gap: 14px; margin-top: 14px; }
.bdg-admin h4 { font-size: 13px; margin: 0 0 8px; }
.bdg-form { display: grid; gap: 8px; }
.bdg-form input, .bdg-form select, .bdg-form textarea { background: var(--bdg-card-2); border: 1px solid var(--bdg-line); border-radius: 12px; color: var(--bdg-ink); font-size: 16px; padding: 11px 12px; width: 100%; }
.bdg-form .bdg-row { display: grid; gap: 8px; grid-template-columns: 84px 1fr; }
.bdg-rarity-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.bdg-rarity-pick button { background: var(--bdg-card-2); border: 1px solid var(--bdg-line); border-radius: 99px; color: var(--bdg-ink); font-size: 12px; font-weight: 800; padding: 7px 12px; }
.bdg-rarity-pick button[aria-pressed="true"] { background: var(--bdg-ink); border-color: var(--bdg-ink); color: var(--bdg-card); }
.bdg-admin-list { display: grid; gap: 6px; }
.bdg-admin-item { align-items: center; background: var(--bdg-card-2); border-radius: 12px; display: flex; gap: 10px; padding: 8px 10px; }
.bdg-admin-item span { flex: 1; font-size: 13px; font-weight: 700; min-width: 0; }
.bdg-admin-item small { color: var(--bdg-muted); display: block; font-size: 11px; font-weight: 600; }
.bdg-admin-item button { background: none; color: #e5484d; font-size: 12px; font-weight: 800; padding: 6px 8px; }
.bdg-row-btns { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }

@media (prefers-reduced-motion: reduce) {
  .bdg-hex.r-mythic { animation: none; }
  .bdg-hex.r-legendary:not(.is-locked) > i, .bdg-celebrate .bdg-hex, .bdg-ring, .bdg-sheet, .bdg-celebrate { animation: none; }
}
