/* ==========================================================================
   SF Badge System v2 — shared 10-tier level badge + avatar pip + level-up toast
   ==========================================================================
   Used by: themes/default/sf/php/helpers.php (sf_render_badge / _for_user /
            sf_render_avatar_level_badge)
            themes/default/sf/js/badge-levelup.js (corner toast only — never
            a full-screen overlay)

   Tier escalation:
     1-3  muted / thin border / (almost) no glow
     4-6  full accent gradient (#e91e8c -> #8b2fc9) + own tint, medium glow
     7-8  metallic / crystal tones, stronger glow
     9    tri-color gradient, strong glow
     10   white-glow core + thin extra outer ring, strongest glow
   ========================================================================== */

.sf-badge-lvl {
    --badge-size: 48px;
    --badge-icon-size: 22px;
    --badge-border: 2px;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--badge-size);
    height: var(--badge-size);
    border-radius: 50%;
    flex-shrink: 0;
    vertical-align: middle;
    box-sizing: border-box;
    isolation: isolate;
}

.sf-badge-lvl__icon {
    width: var(--badge-icon-size);
    height: var(--badge-icon-size);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    color: #fff;
}

.sf-badge-lvl__icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.sf-badge-lvl__label {
    margin-left: 6px;
    font-weight: 700;
    font-size: 13px;
    vertical-align: middle;
    color: var(--sa-text, #f5eef6);
}

/* ---- sizes ---- */
.sf-badge-lvl--xs { --badge-size: 18px; --badge-icon-size: 10px; --badge-border: 1.25px; }
.sf-badge-lvl--sm { --badge-size: 26px; --badge-icon-size: 13px; --badge-border: 1.5px; }
.sf-badge-lvl--md { --badge-size: 44px; --badge-icon-size: 20px; }
.sf-badge-lvl--lg { --badge-size: 72px; --badge-icon-size: 32px; }
.sf-badge-lvl--xl { --badge-size: 108px; --badge-icon-size: 46px; }

/* ---- tier 1-3: muted, thin border, little/no glow ---- */
.sf-badge-lvl--t1 {
    background: linear-gradient(145deg, #4c4656, #2b2732);
    border: var(--badge-border) solid rgba(255, 255, 255, 0.14);
}
.sf-badge-lvl--t2 {
    background: linear-gradient(145deg, #504362, #2a2338);
    border: var(--badge-border) solid rgba(255, 255, 255, 0.16);
}
.sf-badge-lvl--t3 {
    background: linear-gradient(145deg, #4c3f74, #292140);
    border: var(--badge-border) solid rgba(202, 190, 255, 0.24);
    box-shadow: 0 0 8px rgba(139, 47, 201, 0.16);
}

/* ---- tier 4-6: full accent gradient, medium glow, per-tier tint ---- */
.sf-badge-lvl--t4 {
    background: linear-gradient(145deg, #f15fab, #e91e8c 45%, #8b2fc9);
    border: var(--badge-border) solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 0 16px rgba(233, 30, 140, 0.45);
}
.sf-badge-lvl--t5 {
    background: linear-gradient(145deg, #b955e8, #8b2fc9 45%, #5a2fd6);
    border: var(--badge-border) solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 0 16px rgba(139, 47, 201, 0.5);
}
.sf-badge-lvl--t6 {
    background: linear-gradient(145deg, #f3d488, #e6b84a 42%, #c9427e 90%);
    border: var(--badge-border) solid rgba(255, 241, 200, 0.55);
    box-shadow: 0 0 18px rgba(230, 184, 74, 0.5);
}

/* ---- tier 7-8: metallic / crystal, stronger glow ---- */
.sf-badge-lvl--t7 {
    background: linear-gradient(145deg, #ffffff, #ded1ff 40%, #8b5cf6);
    border: var(--badge-border) solid rgba(255, 255, 255, 0.75);
    box-shadow: 0 0 22px rgba(196, 168, 255, 0.65);
}
.sf-badge-lvl--t7 .sf-badge-lvl__icon { color: #4c2f8a; }

.sf-badge-lvl--t8 {
    background: linear-gradient(145deg, #eafeff, #67e8f9 40%, #0891b2);
    border: var(--badge-border) solid rgba(255, 255, 255, 0.75);
    box-shadow: 0 0 24px rgba(103, 232, 249, 0.6);
}
.sf-badge-lvl--t8 .sf-badge-lvl__icon { color: #053b47; }

/* ---- tier 9: tri-color gradient, strong glow ---- */
.sf-badge-lvl--t9 {
    background: linear-gradient(135deg, #ff9a3d, #e91e8c 50%, #8b2fc9);
    border: var(--badge-border) solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 26px rgba(233, 30, 140, 0.55), 0 0 42px rgba(255, 154, 61, 0.32);
}

/* ---- tier 10: white-glow core + thin extra outer ring, strongest glow ---- */
.sf-badge-lvl--t10 {
    background: radial-gradient(circle at 35% 30%, #ffffff, #f3e9ff 35%, #c9427e 72%, #8b2fc9);
    border: var(--badge-border) solid #ffffff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.85), 0 0 32px rgba(233, 30, 140, 0.6), 0 0 52px rgba(139, 47, 201, 0.45);
}
.sf-badge-lvl--t10 .sf-badge-lvl__icon { color: #6a1b6e; }
.sf-badge-lvl--t10::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.6);
    pointer-events: none;
}

/* Legacy inline-next-to-name placement (kept for any leftover call sites). */
.i_inline_lvl_badge {
    margin-left: 5px;
    transform: translateY(3px);
}

/* ==========================================================================
   Avatar-corner level badge (permanent, status-dot style)
   ==========================================================================
   Always-visible tier icon on the profile picture — top-right, ~1/3 of the
   avatar size, with a thin ring in the page/card background so it reads as a
   status pip. Never a full-screen overlay; never covers post media. */

.sf-avatar-with-lvl {
    position: relative !important;
    overflow: visible !important;
}

.sf-avatar-with-lvl > img,
.sf-avatar-with-lvl .i_message_avatar > img {
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* Chat list wraps the <img> one level deeper. */
.sf-avatar-with-lvl .i_message_avatar {
    position: relative;
    overflow: visible !important;
    border-radius: 50%;
}

.sf-avatar-with-lvl > .sf-badge-lvl.i_avatar_lvl_badge,
.sf-avatar-with-lvl > a.sf-avatar-lvl-link,
.sf-avatar-with-lvl .i_message_avatar > .sf-badge-lvl.i_avatar_lvl_badge {
    position: absolute;
    top: -1px;
    right: -1px;
    z-index: 3;
    width: 34%;
    height: 34%;
    min-width: 14px;
    min-height: 14px;
    max-width: 40px;
    max-height: 40px;
    margin: 0;
    transform: none;
    pointer-events: none;
}

.sf-avatar-with-lvl > a.sf-avatar-lvl-link {
    display: block;
    pointer-events: auto;
    line-height: 0;
    text-decoration: none;
}

.sf-avatar-with-lvl > .sf-badge-lvl.i_avatar_lvl_badge,
.sf-avatar-with-lvl > a.sf-avatar-lvl-link .sf-badge-lvl.i_avatar_lvl_badge,
.sf-avatar-with-lvl .i_message_avatar > .sf-badge-lvl.i_avatar_lvl_badge {
    --badge-size: 100%;
    --badge-icon-size: 58%;
    --badge-border: 0;
    box-shadow: none !important;
    /* Thin ring matching the dark feed/card surface (status-dot separation). */
    outline: 2px solid var(--sf-avatar-badge-ring, #15101c);
    outline-offset: 0;
}

.sf-avatar-with-lvl > a.sf-avatar-lvl-link .sf-badge-lvl.i_avatar_lvl_badge {
    position: relative;
    top: auto;
    right: auto;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
}

/* Soften heavy tier glows so the tiny pip doesn't look like an overlay. */
.sf-avatar-with-lvl .sf-badge-lvl.i_avatar_lvl_badge.sf-badge-lvl--t4,
.sf-avatar-with-lvl .sf-badge-lvl.i_avatar_lvl_badge.sf-badge-lvl--t5,
.sf-avatar-with-lvl .sf-badge-lvl.i_avatar_lvl_badge.sf-badge-lvl--t6 {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18) !important;
}

.sf-avatar-with-lvl .sf-badge-lvl.i_avatar_lvl_badge.sf-badge-lvl--t10::after {
    display: none;
}

.sf-avatar-with-lvl .sf-badge-lvl.i_avatar_lvl_badge.sf-badge-lvl--glow {
    animation: none;
}

/* Profile hero avatar wrappers often clip; force the pip to show. */
.i_profile_avatar_wrp.sf-avatar-with-lvl,
.i_profile_avatar_container .sf-avatar-with-lvl {
    overflow: visible !important;
}

/* Feed / comment / chat surfaces use the dark card tone as the ring. */
body.sf-ui-consistency-v2 .sf-avatar-with-lvl,
body.sf-app-body .sf-avatar-with-lvl,
.i_post_body .sf-avatar-with-lvl,
.i_u_comment_body .sf-avatar-with-lvl,
.i_message_wrapper .sf-avatar-with-lvl {
    --sf-avatar-badge-ring: #1a1224;
}

.sf-badge-lvl--locked {
    filter: grayscale(0.65) brightness(0.65);
    opacity: 0.55;
}

/* ---- permanent glow modifier (own profile/dashboard badge ONLY) ---- */
@keyframes sf-badge-breathe {
    0%, 100% { filter: brightness(1); box-shadow: 0 0 10px var(--sf-badge-glow-a, rgba(233, 30, 140, 0.35)); }
    50% { filter: brightness(1.12); box-shadow: 0 0 26px var(--sf-badge-glow-b, rgba(233, 30, 140, 0.65)); }
}
.sf-badge-lvl--glow {
    animation: sf-badge-breathe 3s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
    .sf-badge-lvl--glow { animation: none; }
}

/* ==========================================================================
   Level-up toast (built dynamically by badge-levelup.js)
   ==========================================================================
   Replaces the old full-screen celebration modal/overlay. A level-up is now
   confirmed with a small, unobtrusive corner toast only — never a full-screen
   takeover, never anything post-sized. This is intentionally separate from
   the ALWAYS-VISIBLE inline badge next to a username (sf_render_badge_for_user(),
   .i_inline_lvl_badge below), which never animates and is the permanent
   record of a user's tier; this toast is only the one-off "you just leveled
   up" confirmation and disappears on its own. Same 10-tier icon/tint set as
   the rest of the badge system — only WHERE/HOW LARGE it renders changed. */

.sf-lvlup-toast {
    position: fixed;
    top: calc(var(--sf-header-height, 60px) + 14px);
    right: 16px;
    z-index: 9500;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: min(300px, calc(100vw - 32px));
    background: linear-gradient(165deg, #241627 0%, #170f1c 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left: 3px solid #e91e8c;
    border-radius: 14px;
    padding: 12px 12px 12px 14px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translateX(24px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}
.sf-lvlup-toast.is-open {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}
.sf-lvlup-toast.is-leaving {
    opacity: 0;
    transform: translateX(24px) scale(0.97);
}

.sf-lvlup-toast .sf-badge-lvl {
    position: relative;
    margin-top: 1px;
}

/* One brief, contained pulse ring around the small badge — the only
   "supporting effect" this toast gets. Fires once and stops; it never loops
   or grows beyond the toast's own footprint. */
.sf-lvlup-toast-ring {
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid rgba(233, 30, 140, 0.55);
    opacity: 0;
    pointer-events: none;
    animation: sf-lvlup-toast-pulse 0.9s ease-out 0.15s 1 both;
}
@keyframes sf-lvlup-toast-pulse {
    0% { transform: scale(0.75); opacity: 0.85; }
    100% { transform: scale(1.6); opacity: 0; }
}

.sf-lvlup-toast-text {
    flex: 1 1 auto;
    min-width: 0;
}
.sf-lvlup-toast-title {
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: #c9a3d6;
    margin: 1px 0 2px;
}
.sf-lvlup-toast-level {
    font-size: 14.5px;
    font-weight: 800;
    color: #fff;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sf-lvlup-toast-xp {
    font-size: 11px;
    color: #a993ab;
    margin: 3px 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sf-lvlup-toast-close {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #f5eef6;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sf-lvlup-toast-close:hover { background: rgba(255, 255, 255, 0.16); }

@media (max-width: 460px) {
    .sf-lvlup-toast {
        left: 12px;
        right: 12px;
        width: auto;
        transform: translateY(-12px);
    }
    .sf-lvlup-toast.is-open { transform: translateY(0); }
    .sf-lvlup-toast.is-leaving { transform: translateY(-12px) scale(0.98); }
}

@media (prefers-reduced-motion: reduce) {
    .sf-lvlup-toast { transition: none; }
    .sf-lvlup-toast-ring { animation: none; }
}
