/**
 * Level Up: badge, translucent band, reward chips. Load order is significant: keep this file's <link> position in index.html.
 */

.modal-panel--levelup {
    text-align: center;
    max-width: min(560px, 92vw);
}

.levelup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    /* Anchors the confetti, which is positioned against this box. */
    position: relative;
}

/*
 * Purely decorative confetti: no pointer events, hidden from assistive
 * technology; the panel clips the overshoot.
 */
.levelup__confetti {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.levelup__confetti i {
    position: absolute;
    top: -18px;
    width: 9px;
    height: 14px;
    border-radius: 2px;
    opacity: 0;
    animation-name: confetti-fall;
    animation-timing-function: cubic-bezier(0.18, 0.8, 0.2, 1);
    animation-iteration-count: 1;
    animation-fill-mode: forwards;
}

@keyframes confetti-fall {
    0% {
        opacity: 0;
        transform: translate3d(0, 0, 0) scale(0.75) rotate(0deg);
    }
    12% {
        opacity: 1;
        transform: translate3d(calc(var(--drift, 0) * 0.35), 24px, 0) scale(1) rotate(42deg);
    }
    70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate3d(var(--drift, 0), 440px, 0) rotate(var(--spin, 360deg)) scale(0.8);
    }
}

.levelup__badge:empty {
    display: none;
}

.levelup__badge {
    display: grid;
    place-items: center;
    animation: badge-bloom 0.58s cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.levelup__badge img {
    width: 120px;
    height: 120px;
    object-fit: contain;
    filter: drop-shadow(0 12px 20px rgba(255, 172, 72, 0.45));
}

@keyframes badge-bloom {
    0% {
        opacity: 0;
        transform: scale(0.7) translateY(12px);
    }
    60% {
        opacity: 1;
        transform: scale(1.08) translateY(-4px);
    }
}

/*
 * Staged reveal. The panel lands first, then the badge, the headline, the era
 * and finally the unlocks — each waits for the one before it, so the moment
 * reads as an announcement instead of everything arriving at once. Delays are
 * cumulative with the 260ms `panel-in` above.
 */
@keyframes levelup-rise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
}

@keyframes levelup-stamp {
    0%   { opacity: 0; transform: scale(0.4) rotate(-8deg); }
    70%  { opacity: 1; transform: scale(1.08) rotate(2deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.levelup__badge,
.levelup__heading,
.levelup__era,
.levelup__message,
.levelup__chip {
    animation: levelup-rise 320ms ease-out both;
}

.levelup__badge  { animation: levelup-stamp 520ms cubic-bezier(0.34, 1.42, 0.64, 1) both; animation-delay: 120ms; }
.levelup__heading { animation-delay: 300ms; }
.levelup__era     { animation-delay: 430ms; }
.levelup__message { animation-delay: 540ms; }

.levelup__chip:nth-child(1) { animation-delay: 660ms; }
.levelup__chip:nth-child(2) { animation-delay: 740ms; }
.levelup__chip:nth-child(3) { animation-delay: 820ms; }
.levelup__chip:nth-child(4) { animation-delay: 900ms; }
.levelup__chip:nth-child(5) { animation-delay: 980ms; }
.levelup__chip:nth-child(n + 6) { animation-delay: 1060ms; }

.levelup__heading {
    font-size: 40px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #fff;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 18px rgba(255, 204, 98, 0.35);
    animation: heading-pop 0.6s cubic-bezier(0.18, 0.9, 0.18, 1) both;
}

@keyframes heading-pop {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    65% {
        opacity: 1;
        transform: translateY(-2px) scale(1.03);
    }
}

.levelup__era {
    font-size: 26px;
    font-weight: 700;
    color: var(--era);
    animation: text-rise 0.52s ease-out both;
}

.levelup__message {
    font-size: 16px;
    color: var(--text);
    max-width: 42ch;
    animation: text-rise 0.58s ease-out 0.06s both;
}

@keyframes text-rise {
    0% {
        opacity: 0;
        transform: translateY(8px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.levelup__era.is-empty,
.levelup__message.is-empty {
    display: none;
}

.levelup__unlocks {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 6px;
    animation: unlocks-pop 0.52s cubic-bezier(0.18, 0.9, 0.14, 1.1) both;
}

@keyframes unlocks-pop {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.88);
    }
    70% {
        opacity: 1;
        transform: translateY(-2px) scale(1.02);
    }
}

.levelup__chip {
    padding: 8px 18px;
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.08));
    border: 2px solid var(--edge);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    font-size: 15px;
    font-weight: 700;
    animation: chip-rise 0.42s cubic-bezier(0.18, 0.78, 0.16, 1.25) both;
    animation-delay: var(--chip-delay, 0ms);
}

@keyframes chip-rise {
    0% {
        opacity: 0;
        transform: translateY(12px) scale(0.88);
    }
    70% {
        opacity: 1;
        transform: translateY(-3px) scale(1.04);
    }
}

/*
 * New LevelUp DOM introduced for the pixel-perfect band: badge-frame,
 * resource chips with count balloon, and confetti-art layer.
 * Generic (theme-agnostic) fallback keeps the old pill look so a theme
 * without --levelup-* tokens (futuristic) is unchanged.
 */
.levelup__badge-frame {
    display: grid;
    place-items: center;
    width: 120px;
    height: 120px;
}

.levelup__badge-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 12px 20px rgba(255, 172, 72, 0.45));
}

.levelup__chip--resource {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Fallback pill when --levelup-chip-art is not defined */
    min-width: 58px;
    padding-right: 8px;
}

.levelup__chip-icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
}

.levelup__chip-icon-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.levelup__chip-fallback {
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
}

.levelup__chip-count {
    position: absolute;
    right: -6px;
    bottom: -6px;
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: #2ecc71;
    border: 1.5px solid #fff;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.levelup__chip--unlock .levelup__chip-label {
    font-size: 13px;
    font-weight: 700;
    max-width: 10ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Earned land: same pill as an unlock chip, so the row stays uniform. */
.levelup__chip--expand .levelup__chip-label {
    font-size: 13px;
    font-weight: 700;
    max-width: 16ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.levelup__confetti-art {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    /* Wood supplies --confetti-art; other themes keep it none */
    background-image: var(--confetti-art, none);
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
    opacity: 0;
}
