/* The game HUD's 15px label on a 36px crest sets the scale everywhere. */
:root {
  --crest-label-size: 41.6667cqmin;
  /* At 35 degrees below horizontal, both badge centres sit on the portrait rim. */
  --crest-anchor-side: 9.0424%;
  --crest-anchor-bottom: 21.3212%;
}

:is(.profile-badge, .avatar-medal, .crestimg, .crs > .crest, .progression-crest, .rbadge) {
  container-type: size;
  --crest-label-scale: 1;
  --crest-label-centre: 50%;
}
:is(.profile-badge, .avatar-medal, .crestimg, .crs > .crest, .progression-crest, .rbadge)[data-digits="3"] {
  --crest-label-scale: .86;
}
:is(.profile-badge, .avatar-medal, .crestimg, .crs > .crest, .progression-crest, .rbadge)[data-digits="4"] {
  --crest-label-scale: .7;
}
:is(.profile-badge, .avatar-medal, .crestimg, .crs > .crest, .progression-crest, .rbadge):is(.elo, [data-kind="elo"]) {
  --crest-label-centre: 44.4444%;
}

/* Override the legacy per-screen label sizing and offset rules. */
:is(.profile-badge, .progression-crest, .rbadge) > b,
:is(.avatar-medal, .crestimg, .crs > .crest) > span {
  position: absolute !important;
  inset: var(--crest-label-centre) 0 auto !important;
  display: block !important;
  margin: 0 !important;
  padding: 0 !important;
  font: 700 calc(var(--crest-label-size) * var(--crest-label-scale))/1 'Barlow Condensed', 'Arial Narrow', sans-serif !important;
  letter-spacing: -.025em !important;
  text-align: center;
  white-space: nowrap;
  transform: translateY(-50%) !important;
  scale: none !important;
  color: #fff !important;
  text-shadow: 0 1px 2px #000, 0 0 3px #0009;
}

/* Image-based result crests need a definite square when using size containment. */
.crs > .crest { aspect-ratio: 1; }
.crestimg > img, .crs > .crest > img { width: 100%; height: 100%; object-fit: contain; }
.rbadge { background-size: contain; }

#snooker-preview #matchbar .hud-avatar > .hud-level-wrap {
  inset: 0 !important;
  display: block;
  width: 100%;
  height: 100%;
}
#snooker-preview #matchbar .hud-avatar .profile-badge,
#profileOpen .menu-profile-badges .profile-badge,
#profileDialog #profileBadges .profile-badge,
:is(#communityHub, #playerProfilePopup) .hub-avatar-anchor .avatar-medal,
.rim > .crs > .crest,
.avatar > .rbadge {
  position: absolute;
  inset: auto auto var(--crest-anchor-bottom) var(--crest-anchor-side) !important;
  transform: translate(-50%, 50%);
}
#snooker-preview #matchbar .hud-avatar .profile-badge[data-kind="elo"],
#profileOpen .menu-profile-badges .profile-badge[data-kind="elo"],
#profileDialog #profileBadges .profile-badge[data-kind="elo"],
:is(#communityHub, #playerProfilePopup) .hub-avatar-anchor .avatar-medal.elo,
.rim > .crs > .crest.elo,
.avatar > .rbadge.elo {
  inset: auto auto var(--crest-anchor-bottom) calc(100% - var(--crest-anchor-side)) !important;
}

#snooker-preview #matchbar .hud-avatar {
  --crest-anchor-side: 14.64466%;
  --crest-anchor-bottom: 14.64466%;
}
#snooker-preview #matchbar .hud-avatar .profile-badge {
  width: clamp(21px, 2.4vw, 29px);
  height: clamp(21px, 2.4vw, 29px);
}
body #profileOpen .menu-profile-badges .profile-badge {
  width: 25px;
  height: 25px;
}
.rim > .crs > .crest { height: 44px; }
.oimg > .crs > .crest { height: 28px; }
.stage .matchcard .avatar > .rbadge {
  width: 19px;
  height: 19px;
}
