/* =============================================================================
   RANK BAR — Reusable era-aware level/rank progress component

   <div class="rank-bar" data-era="pioneers">
       <div class="rank-bar-head">
           <div class="rank-bar-watermark">The Pioneers</div>
           <div class="rank-bar-title">The Beautiful Game</div>
       </div>
       <div class="rank-bar-track">
           <div class="rank-bar-fill" style="width:35%"></div>
           <span class="rank-bar-text"><span class="rank-bar-badge">5</span> 420 / 1200</span>
       </div>
   </div>
   ============================================================================= */

/* ---- Era Palettes ---- */
.rank-bar[data-era="pioneers"]   { --rb-color: #CD7F32; --rb-color-dim: #a0622a; --rb-glow: rgba(205,127,50,0.4); --rb-bg: rgba(205,127,50,0.06); }
.rank-bar[data-era="golden"]     { --rb-color: #c4956a; --rb-color-dim: #8b6d4a; --rb-glow: rgba(196,149,106,0.4); --rb-bg: rgba(196,149,106,0.06); }
.rank-bar[data-era="modern"]     { --rb-color: #FFD700; --rb-color-dim: #c9a800; --rb-glow: rgba(255,215,0,0.4); --rb-bg: rgba(255,215,0,0.05); }
.rank-bar[data-era="millennium"] { --rb-color: #E5E4E2; --rb-color-dim: #b0afad; --rb-glow: rgba(229,228,226,0.3); --rb-bg: rgba(229,228,226,0.04); }
.rank-bar[data-era="new_era"]    { --rb-color: #2a9d8f; --rb-color-dim: #1a7a6e; --rb-glow: rgba(42,157,143,0.45); --rb-bg: rgba(42,157,143,0.06); }

/* ---- Era Signature Fonts ---- */
.rank-bar[data-era="pioneers"]   .rank-bar-watermark { font-family: 'Georgia', 'Times New Roman', serif; font-style: italic; letter-spacing: 2px; }
.rank-bar[data-era="golden"]     .rank-bar-watermark { font-family: 'Brush Script MT', 'Segoe Script', cursive; font-style: normal; letter-spacing: 1px; font-size: 1.1rem; }
.rank-bar[data-era="modern"]     .rank-bar-watermark { font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-style: italic; letter-spacing: 3px; }
.rank-bar[data-era="millennium"] .rank-bar-watermark { font-family: 'Trebuchet MS', 'Lucida Sans', Arial, sans-serif; font-style: normal; letter-spacing: 4px; font-weight: 300; }
.rank-bar[data-era="new_era"]    .rank-bar-watermark { font-family: 'Courier New', 'Lucida Console', monospace; font-style: normal; letter-spacing: 5px; text-transform: uppercase; font-size: 0.75rem; }

/* ---- Container ---- */
.rank-bar {
    position: relative;
    display: flex; flex-direction: column;
    gap: 0;
    font-family: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
    padding: 0.6rem 0.5rem 0.35rem;
    background: var(--rb-bg);
    border: 1px solid color-mix(in srgb, var(--rb-color) 12%, transparent);
    border-radius: 4px;
}

/* ---- Head area: watermark behind, title in front ---- */
.rank-bar-head {
    position: relative;
    margin-bottom: 0.3rem;
    min-height: 1.2rem;
    display: flex; align-items: center; justify-content: center;
}

/* Era watermark — behind the title, centered in head area */
.rank-bar-watermark {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.9rem;
    color: var(--rb-color);
    opacity: 0.08;
    white-space: nowrap;
    pointer-events: none;
    z-index: 0;
    user-select: none;
    transition: color 0.4s ease, opacity 0.4s ease;
}

/* Rank title — centered over watermark */
.rank-bar-title {
    position: relative; z-index: 1;
    text-align: center;
    font-size: 0.52rem; font-weight: 700;
    color: var(--rb-color);
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: color 0.4s ease;
}

/* ---- Track (soft rounded edges) ---- */
.rank-bar-track {
    position: relative; z-index: 1;
    width: 100%; height: 16px;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
    transition: opacity 0.4s ease;
}
/* Track hidden during rank-up celebration */
.rank-bar-track.rank-bar-track-hidden {
    opacity: 0;
}

/* ---- Fill bar ---- */
.rank-bar-fill {
    position: absolute; top: 0; left: 0; bottom: 0;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--rb-color-dim), var(--rb-color));
    box-shadow: 0 0 8px var(--rb-glow);
    width: 0%;
    transition: width 1.2s cubic-bezier(.22,.68,.31,1.01);
    min-width: 0;
}
.rank-bar-fill[style*="width:0%"],
.rank-bar-fill[style*="width: 0%"] { display: none; }
/* Top shine on fill */
.rank-bar-fill::after {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 45%;
    background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, transparent 100%);
    pointer-events: none;
}

/* ---- Inline text (centered in track) ---- */
.rank-bar-text {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    gap: 0.3rem;
    font-size: 0.5rem; font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8), 0 0 4px rgba(0,0,0,0.4);
    letter-spacing: 0.5px;
    z-index: 1;
    pointer-events: none;
}

/* ---- Rank badge (shield/crest inside the bar) ---- */
.rank-bar-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 16px; height: 12px;
    padding: 1px 3px 0;
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 2px;
    font-size: 0.45rem; font-weight: 900;
    color: var(--rb-color);
    text-shadow: none;
    letter-spacing: 0;
    line-height: 0;
    flex-shrink: 0;
    box-sizing: border-box;
}

/* ---- Caps icon (era-tinted C badge) ---- */
.rb-cap-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 10px; height: 10px; border-radius: 2px;
    background: var(--rb-color, #aaa);
    opacity: 0.7;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
    vertical-align: middle; margin-left: 2px;
}
.rb-cap-c {
    font-size: 0.35rem; font-weight: 900; line-height: 1;
    color: rgba(0,0,0,0.6); font-family: 'Georgia', 'Times New Roman', serif;
}

/* ---- Rank-up flash (same era) ---- */
.rank-bar.rank-bar-flash .rank-bar-fill {
    animation: rbFlash 1.8s ease;
}
@keyframes rbFlash {
    0%   { filter: brightness(1); }
    15%  { filter: brightness(1.6); }
    40%  { filter: brightness(1.2); }
    100% { filter: brightness(1); }
}
/* Title: JS adds rank-bar-title-celebrate for the big centered state */
.rank-bar-title {
    transform-origin: center center;
    position: relative;
    transition: transform 0.5s cubic-bezier(.25,.1,.25,1),
                font-size 0.5s cubic-bezier(.25,.1,.25,1),
                color 0.4s ease,
                opacity 0.3s ease;
}
/* Slide out right — normal title exits */
.rank-bar-title.rank-bar-title-out {
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
/* Celebrate state — big title centered in the full .rank-bar card */
.rank-bar.rank-bar-celebrating .rank-bar-head {
    position: static;
}
.rank-bar-title.rank-bar-title-celebrate {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: fit-content;
    font-size: 0.85rem;
    letter-spacing: 2px;
    color: #fff;
    z-index: 2;
    animation: rbTitleSlideIn 0.5s cubic-bezier(.22,.68,.35,1) both;
}
@keyframes rbTitleSlideIn {
    0%   { opacity: 0; transform: translate(-50%, -50%) translateX(-30px); }
    100% { opacity: 1; transform: translate(-50%, -50%); }
}
/* Celebrate exit — big title slides out to right */
.rank-bar-title.rank-bar-title-celebrate-out {
    animation: rbTitleSlideOut 0.35s ease forwards;
}
@keyframes rbTitleSlideOut {
    0%   { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; transform: translate(-50%, -50%) translateX(30px); }
}
/* Normal title slides back in from left */
.rank-bar-title.rank-bar-title-back {
    animation: rbTitleSlideBack 0.4s cubic-bezier(.22,.68,.35,1) both;
}
@keyframes rbTitleSlideBack {
    0%   { opacity: 0; transform: translateX(-25px); }
    100% { opacity: 1; transform: translateX(0); }
}
/* Watermark celebration — simple fade out / fade in */
.rank-bar-watermark {
    transition: color 0.4s ease, opacity 0.4s ease, font-size 0.4s ease;
}
.rank-bar-watermark.rank-bar-wm-out {
    opacity: 0 !important;
}
.rank-bar-watermark.rank-bar-wm-big {
    opacity: 0.14 !important;
    font-size: 1.3rem;
}
/* Shine sweep — metallic shimmer masked to the letters */
.rank-bar-title.rank-bar-title-shine {
    background: linear-gradient(
        110deg,
        #fff 0%, #fff 25%,
        rgba(255,255,255,0.35) 42%, #fff 50%, rgba(255,255,255,0.35) 58%,
        #fff 75%, #fff 100%
    );
    background-size: 300% 100%;
    background-position: 100% 0;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: rbTitleShine 0.9s cubic-bezier(0.25,0.8,0.25,1) forwards;
}
@keyframes rbTitleShine {
    0%   { background-position: 100% 0; }
    100% { background-position: 0% 0; }
}
.rank-bar.rank-bar-flash .rank-bar-badge {
    animation: rbBadgePop 1.8s ease;
}
@keyframes rbBadgePop {
    0%   { transform: scale(1); border-color: rgba(255,255,255,0.2); }
    10%  { transform: scale(1.3); border-color: var(--rb-color); background: rgba(0,0,0,0.6); }
    50%  { transform: scale(1.3); border-color: var(--rb-color); }
    100% { transform: scale(1); border-color: rgba(255,255,255,0.2); }
}

/* ---- Era unlock celebration ---- */
/* New era watermark — centered in the FULL .rank-bar, large, full opacity.
   Reveal animation: text-shaped lightning (white text → era color) + scale-up.
   JS sets top/left inline to center of .rank-bar. */
.rank-bar-watermark.rank-bar-era-reveal {
    position: fixed;
    top: auto; left: auto;
    transform: none;
    opacity: 1 !important;
    font-size: 1.4rem;
    z-index: 2;
    animation: rbEraReveal 0.9s cubic-bezier(.22,.68,.35,1) both;
}
@keyframes rbEraReveal {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4);
           color: #fff; text-shadow: 0 0 24px rgba(255,255,255,0.9), 0 0 8px rgba(255,255,255,0.6); }
    20%  { opacity: 1; transform: translate(-50%, -50%) scale(0.85);
           color: #fff; text-shadow: 0 0 18px rgba(255,255,255,0.7), 0 0 6px rgba(255,255,255,0.4); }
    45%  { opacity: 1; transform: translate(-50%, -50%) scale(1);
           color: var(--rb-color); text-shadow: 0 0 6px var(--rb-glow); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1);
           color: var(--rb-color); text-shadow: none; }
}
/* Shake/rotation — layered ON TOP of reveal (no class swap, no jump).
   Defined after reveal so its animation property wins by source order.
   Starts strong, eases to stillness. */
.rank-bar-watermark.rank-bar-era-shake {
    animation: rbEraShake 1.2s ease-out both;
}
@keyframes rbEraShake {
    0%   { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
    6%   { transform: translate(-50%, -50%) rotate(-4deg) scale(1.04); }
    12%  { transform: translate(-50%, -50%) rotate(3.5deg) scale(1.03); }
    20%  { transform: translate(-50%, -50%) rotate(-2.8deg) scale(1.02); }
    28%  { transform: translate(-50%, -50%) rotate(2.2deg) scale(1.01); }
    38%  { transform: translate(-50%, -50%) rotate(-1.5deg); }
    48%  { transform: translate(-50%, -50%) rotate(1deg); }
    60%  { transform: translate(-50%, -50%) rotate(-0.5deg); }
    72%  { transform: translate(-50%, -50%) rotate(0.2deg); }
    84%  { transform: translate(-50%, -50%) rotate(-0.08deg); }
    100% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
}
/* Slow fade-out + subtle scale-down when reverting */
.rank-bar-watermark.rank-bar-era-exit {
    position: fixed;
    font-size: 1.4rem;
    z-index: 2;
    transition: opacity 0.8s ease-in, transform 0.8s ease-in;
    opacity: 0 !important;
    transform: translate(-50%, -50%) scale(0.88);
}

/* ---- Floating "+caps" indicator ---- */
/* JS appends to document.body, positioned via JS near the bar's right edge */
.rank-bar-plus {
    position: fixed;
    font-size: 0.65rem; font-weight: 800;
    color: var(--rb-color, #e9c46a);
    text-shadow: 0 0 8px rgba(0,0,0,0.8), 0 2px 4px rgba(0,0,0,0.5);
    white-space: nowrap;
    pointer-events: none;
    z-index: 10001;
    opacity: 0;
    animation: rbPlusFloat 1.6s ease forwards;
}
@keyframes rbPlusFloat {
    0%   { opacity: 0; transform: translate(0, 0); }
    12%  { opacity: 1; transform: translate(0, 0); }
    35%  { opacity: 1; transform: translate(1px, -2px); }
    55%  { opacity: 0.9; transform: translate(-1px, -3px); }
    75%  { opacity: 0.4; transform: translate(1px, -4px); }
    100% { opacity: 0; transform: translate(0px, -5px); }
}
