/* Grimdark XP Hub — analogiczny do souls-display-independent */
.xp-bar-container {
    --frame-color: #3a2a28;
    --frame-inner: #2a1a18;
    --corner-color: #4a3a35;
    --diamond-color: #5a4a45;
    --moss-dark: #008c00;
    --moss-mid: #00ff00;
    --moss-light: #40ff40;
    --bar-base: #0e0a06;
    --texture: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

    position: fixed;
    bottom: 2.2vh;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    pointer-events: none;
    display: flex;
    justify-content: center;
}

.xp-bar-hub {
    display: flex;
    align-items: center;
    gap: 0.4vw;
}

/* Side ornament lines */
.xp-hub-line {
    width: 1.6vw;
    height: 2px;
    background: var(--frame-color);
}

.xp-hub-diamond-small {
    width: 0.8vh;
    height: 0.8vh;
    border: 1px solid var(--corner-color);
    transform: rotate(45deg);
    background:
        var(--texture),
        linear-gradient(135deg, #0e060a 0%, #0a0406 100%);
    background-blend-mode: soft-light, normal;
}

/* Wrap that hosts both the bar frame and the overlapping level medallion */
.xp-bar-frame-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

/* Level medallion - centered over the bar (horizontally and vertically) */
.xp-level-group {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 4.5vh;
    height: 4.5vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    pointer-events: none;
}

.xp-level-side {
    position: absolute;
    width: 2.8vh;
    height: 2.8vh;
    border: 2px solid var(--corner-color);
    transform: rotate(45deg);
    background:
        var(--texture),
        linear-gradient(135deg, #0e060a 0%, #0a0406 100%);
    background-blend-mode: soft-light, normal;
    z-index: 1;
}

.xp-level-side.left { left: 0; }
.xp-level-side.right { right: 0; }

.xp-level-center {
    position: absolute;
    width: 4.2vh;
    height: 4.2vh;
    border: 2px solid var(--frame-color);
    transform: rotate(45deg);
    background:
        var(--texture),
        radial-gradient(ellipse 60% 60% at 50% 50%, rgba(0, 255, 0, 0.15) 0%, transparent 70%),
        linear-gradient(135deg, #0e060a 0%, #0a0406 100%);
    background-blend-mode: soft-light, normal, normal;
    box-shadow: inset 0 0 0 3px var(--frame-inner);
    z-index: 2;
}

.xp-level-content {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.xp-level-content #xpBarLevel {
    font-family: 'SFPixelate', 'Courier New', monospace;
    font-size: 2vh;
    font-weight: bold;
    color: var(--moss-light);
    text-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
        0 0 8px rgba(64, 255, 64, 0.7),
        0 0 14px rgba(0, 255, 0, 0.5);
}

/* The bar frame */
.xp-bar-frame {
    position: relative;
    width: 32vw;
    min-width: 280px;
    max-width: 560px;
    height: 2.4vh;
    min-height: 16px;
    max-height: 26px;
    border: 2px solid var(--frame-color);
    box-shadow:
        inset 0 0 0 1px var(--frame-inner),
        0 0 6px rgba(0, 0, 0, 0.7);
    overflow: hidden;
}

.xp-bar-background {
    position: relative;
    width: 100%;
    height: 100%;
    background:
        var(--texture),
        linear-gradient(to top,
            rgba(0, 0, 0, 0.9) 0%,
            rgba(4, 22, 4, 0.8) 50%,
            rgba(0, 140, 0, 0.5) 100%
        );
    background-blend-mode: soft-light, normal;
    overflow: hidden;
}

/* Main XP fill bar — player 0 green scheme */
.xp-bar-fill {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg,
        rgba(0, 140, 0, 0.9) 0%,
        rgba(0, 255, 0, 0.95) 35%,
        rgba(64, 255, 64, 0.92) 50%,
        rgba(0, 255, 0, 0.95) 65%,
        rgba(0, 140, 0, 0.9) 100%
    );
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        inset 0 0 12px rgba(0, 255, 0, 0.35),
        0 0 8px rgba(0, 255, 0, 0.22);
}

/* Animated ghostly glow overlay */
.xp-bar-glow {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(140, 255, 140, 0.04) 45%,
        rgba(64, 255, 64, 0.18) 50%,
        rgba(140, 255, 140, 0.04) 55%,
        transparent 100%
    );
    animation: spectralGlow 3s linear infinite;
    pointer-events: none;
}

@keyframes spectralGlow {
    0% { transform: translate3d(-100%, 0, 0); }
    100% { transform: translate3d(100%, 0, 0); }
}

/* Floating spirit particles */
.xp-bar-spirits {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    pointer-events: none;
}

.xp-bar-spirits::before,
.xp-bar-spirits::after {
    content: '';
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(64, 255, 64, 0.6);
    border-radius: 50%;
    box-shadow:
        10px 8px 0 rgba(0, 255, 0, 0.45),
        30px 4px 0 rgba(64, 255, 64, 0.5),
        50px 10px 0 rgba(0, 255, 0, 0.45),
        70px 6px 0 rgba(0, 140, 0, 0.55),
        90px 12px 0 rgba(0, 255, 0, 0.45),
        110px 2px 0 rgba(64, 255, 64, 0.45),
        130px 8px 0 rgba(0, 255, 0, 0.45),
        150px 4px 0 rgba(64, 255, 64, 0.5),
        170px 10px 0 rgba(0, 255, 0, 0.45),
        190px 6px 0 rgba(0, 140, 0, 0.55);
    animation: floatingSpirits 15s linear infinite;
}

.xp-bar-spirits::after {
    animation-delay: -7.5s;
    animation-direction: reverse;
}

@keyframes floatingSpirits {
    0% { transform: translate3d(-200px, 0, 0); }
    50% { transform: translate3d(50vw, 0, 0); }
    100% { transform: translate3d(calc(60vw + 200px), 0, 0); }
}

/* Text overlay — XP numbers anchored to right half of bar; level is in medallion */
.xp-bar-text {
    position: absolute;
    top: 50%;
    right: 1.2vh;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    font-family: 'SFPixelate', 'Courier New', monospace;
    color: #d8e0c0;
    font-size: max(14px, 1.4vh);
    font-weight: bold;
    letter-spacing: 0.03vw;
    z-index: 10;
    text-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
        0 0 6px rgba(0, 255, 0, 0.6);
    pointer-events: none;
    white-space: nowrap;
}

.xp-progress {
    color: #d8e0c0;
}

/* Level up animation — gold flash on whole frame */
@keyframes levelUpFlash {
    0%, 100% { background-color: rgba(138, 43, 226, 0); }
    50% { background-color: rgba(255, 215, 0, 0.5); }
}

.xp-bar-container.level-up .xp-bar-background {
    animation: levelUpFlash 0.5s ease-out 3;
}

/* Elevated z-index for multiplayer level-up (without color change) */
.xp-bar-container.xp-bar-elevated {
    z-index: 10001 !important;
}

/* Permanent level-up state that lasts until menu is closed */
.xp-bar-container.level-up-active {
    z-index: 10001 !important;
}

.xp-bar-container.level-up-active .xp-bar-background {
    background: linear-gradient(to top,
        rgba(255, 215, 0, 0.9) 0%,
        rgba(255, 140, 0, 0.7) 50%,
        rgba(255, 215, 0, 0.5) 100%
    ) !important;
    box-shadow:
        0 0 20px rgba(255, 215, 0, 0.8),
        inset 0 0 15px rgba(255, 215, 0, 0.3) !important;
}

.xp-bar-container.level-up-active .xp-bar-frame {
    border-color: #ffd700 !important;
}

.xp-bar-container.level-up-active .xp-bar-fill {
    background: linear-gradient(90deg,
        rgba(255, 215, 0, 0.9) 0%,
        rgba(255, 255, 255, 0.95) 25%,
        rgba(255, 215, 0, 0.9) 50%,
        rgba(255, 255, 255, 0.95) 75%,
        rgba(255, 215, 0, 0.9) 100%
    ) !important;
    box-shadow:
        inset 0 0 20px rgba(255, 215, 0, 0.7),
        0 0 30px rgba(255, 215, 0, 0.8) !important;
}

.xp-bar-container.level-up-active .xp-level-center {
    background:
        var(--texture),
        radial-gradient(ellipse 60% 60% at 50% 50%, rgba(255, 215, 0, 0.35) 0%, transparent 70%),
        linear-gradient(135deg, #1a1208 0%, #0a0406 100%) !important;
    border-color: #ffd700 !important;
}

.xp-bar-container.level-up-active .xp-level-content #xpBarLevel {
    color: #ffd700;
    text-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
        0 0 10px rgba(255, 215, 0, 0.9),
        0 0 18px rgba(255, 140, 0, 0.6);
}

.xp-bar-container.level-up-active .xp-progress {
    font-size: 0;
}

.xp-bar-container.level-up-active .xp-progress::after {
    content: "LVL UP!";
    font-size: max(14px, 1.4vh);
    color: #ffffff;
    font-weight: bold;
    text-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
        0 0 10px rgba(255, 255, 255, 0.8),
        0 0 20px rgba(255, 215, 0, 0.6);
    animation: levelUpTextPulse 1.5s ease-in-out infinite;
}

@keyframes levelUpTextPulse {
    0%, 100% {
        opacity: 1;
        text-shadow:
            1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
            0 0 10px rgba(255, 255, 255, 0.8),
            0 0 20px rgba(255, 215, 0, 0.6);
    }
    50% {
        opacity: 0.85;
        text-shadow:
            1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
            0 0 15px rgba(255, 255, 255, 1),
            0 0 30px rgba(255, 215, 0, 0.8);
    }
}

/* Spirit burst effect on XP gain */
@keyframes spiritBurst {
    0% { transform: scale3d(0, 0, 1) rotate(0deg); opacity: 1; }
    100% { transform: scale3d(3, 3, 1) rotate(360deg); opacity: 0; }
}

.spirit-burst {
    position: absolute;
    width: 30px;
    height: 30px;
    background: radial-gradient(circle,
        rgba(64, 255, 64, 0.7) 0%,
        rgba(0, 255, 0, 0.35) 50%,
        transparent 100%
    );
    border-radius: 50%;
    pointer-events: none;
    animation: spiritBurst 1s ease-out forwards;
}

/* Multiplayer: per-player island hub positioned in its screen segment */
.xp-bar-container.xp-bar-player-hub {
    /* left set inline per-player; centered via translateX(-50%) */
    justify-content: center;
}

/* Shrink the bar frame so the hub fits the player's segment.
   --player-count is set inline; the bar takes roughly half a segment, capped. */
.xp-bar-container.xp-bar-player-hub .xp-bar-frame {
    width: calc((90vw / var(--player-count, 1)) - 8vh);
    min-width: 140px;
    max-width: 360px;
}

/* Slightly smaller medallion in coop so it doesn't dominate the small bar */
.xp-bar-container.xp-bar-player-hub .xp-level-group {
    width: 3.8vh;
    height: 3.8vh;
}
.xp-bar-container.xp-bar-player-hub .xp-level-side {
    width: 2.4vh;
    height: 2.4vh;
}
.xp-bar-container.xp-bar-player-hub .xp-level-center {
    width: 3.5vh;
    height: 3.5vh;
}
.xp-bar-container.xp-bar-player-hub .xp-level-content #xpBarLevel,
.xp-bar-container.xp-bar-player-hub .xp-level-content .xp-level {
    font-size: 1.7vh;
}

/* Shrink bar frame height + text for coop hubs */
.xp-bar-container.xp-bar-player-hub .xp-bar-frame {
    height: 2vh;
    min-height: 14px;
    max-height: 22px;
}
.xp-bar-container.xp-bar-player-hub .xp-bar-text {
    font-size: max(14px, 1.15vh);
}
.xp-bar-container.xp-bar-player-hub .xp-hub-line {
    width: 1vw;
}

/* Per-player color schemes on fill + level text (frame/medallion shell stays grimdark) */
.xp-bar-container.xp-bar-player-hub .xp-bar-background {
    background:
        var(--texture),
        linear-gradient(to top,
            rgba(0, 0, 0, 0.9) 0%,
            color-mix(in srgb, var(--player-color-dark) 35%, rgba(10, 10, 10, 0.85)) 50%,
            color-mix(in srgb, var(--player-color-dark) 55%, rgba(10, 10, 10, 0.7)) 100%
        );
    background-blend-mode: soft-light, normal;
}

.xp-bar-container.xp-bar-player-hub .xp-bar-fill {
    background: linear-gradient(90deg,
        var(--player-color-dark) 0%,
        var(--player-color) 50%,
        var(--player-color-dark) 100%
    );
    box-shadow:
        inset 0 0 10px color-mix(in srgb, var(--player-color) 35%, transparent),
        0 0 8px color-mix(in srgb, var(--player-color) 25%, transparent);
}

.xp-bar-container.xp-bar-player-hub .xp-level-content .xp-level,
.xp-bar-container.xp-bar-player-hub .xp-level-content #xpBarLevel {
    color: var(--player-color-light);
    text-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
        0 0 8px color-mix(in srgb, var(--player-color) 60%, transparent),
        0 0 14px color-mix(in srgb, var(--player-color) 40%, transparent);
}

/* Tint medallion center subtly with player color */
.xp-bar-container.xp-bar-player-hub .xp-level-center {
    background:
        var(--texture),
        radial-gradient(ellipse 60% 60% at 50% 50%, color-mix(in srgb, var(--player-color) 18%, transparent) 0%, transparent 70%),
        linear-gradient(135deg, #0e060a 0%, #0a0406 100%);
    background-blend-mode: soft-light, normal, normal;
}

/* Match glow + spirits to player color */
.xp-bar-container.xp-bar-player-hub .xp-bar-glow {
    background: linear-gradient(90deg,
        transparent 0%,
        color-mix(in srgb, var(--player-color-light) 8%, transparent) 45%,
        color-mix(in srgb, var(--player-color) 25%, transparent) 50%,
        color-mix(in srgb, var(--player-color-light) 8%, transparent) 55%,
        transparent 100%
    );
}

.xp-bar-container.xp-bar-player-hub .xp-bar-text {
    text-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
        0 0 6px color-mix(in srgb, var(--player-color) 50%, transparent);
}

/* Legacy: in-bar segments (no longer used for island hubs, kept for compat) */
.xp-bar-segments {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 100%;
    z-index: 5;
}

.xp-segment {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 0%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-top: 1px solid rgba(0, 0, 0, 0.3);
    box-shadow:
        inset 0 0 10px rgba(255, 255, 255, 0.1),
        0 0 10px rgba(255, 255, 255, 0.15);
    z-index: 10;
    opacity: 0.8;
}

.xp-segment:last-child {
    border-right: none;
}

.xp-segment-bg {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 0%;
    border-right: 1px solid rgba(0, 0, 0, 0.5);
}

.xp-segment-bg:last-child {
    border-right: none;
}

.xp-segment-text {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: 'SFPixelate', 'Courier New', monospace;
    color: #d8e0c0;
    font-size: 1.1vh;
    font-weight: bold;
    z-index: 15;
    pointer-events: none;
    text-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000,
        0 0 6px rgba(0, 255, 0, 0.55);
}

.segment-level {
    background: none;
    padding: 0;
    border: none;
    box-shadow: none;
    font-size: 1.1vh;
}

.segment-progress {
    color: #d8e0c0;
    font-size: 1.1vh;
}

/* Player segment level-up effect */
.xp-segment-levelup {
    background: linear-gradient(90deg,
        rgba(255, 215, 0, 0.9) 0%,
        rgba(255, 255, 255, 0.95) 25%,
        rgba(255, 215, 0, 0.9) 50%,
        rgba(255, 255, 255, 0.95) 75%,
        rgba(255, 215, 0, 0.9) 100%
    ) !important;
    box-shadow:
        inset 0 0 20px rgba(255, 215, 0, 0.7),
        0 0 30px rgba(255, 215, 0, 0.8) !important;
    animation: segmentLevelUpPulse 1s ease-in-out 3;
}

.xp-segment-levelup + .xp-segment-text .segment-progress::after {
    content: " - LVL UP!";
    color: #ffd700;
    font-weight: bold;
    text-shadow:
        0 0 10px rgba(255, 215, 0, 0.8),
        0 0 20px rgba(255, 215, 0, 0.6);
    animation: levelUpTextPulse 1.5s ease-in-out infinite;
}

@keyframes segmentLevelUpPulse {
    0%, 100% { opacity: 0.8; filter: brightness(1); }
    50% { opacity: 1; filter: brightness(1.5); }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .xp-bar-frame {
        border-color: #00ff00;
    }
    .xp-bar-fill {
        background: linear-gradient(90deg, #008c00 0%, #00ff00 50%, #008c00 100%);
    }
    .xp-bar-text {
        text-shadow: 0 0 5px #000, 0 0 10px #00ff00;
    }
}
