:root {
    --achievement-green: #159447;
    --achievement-green-light: #22b45b;
    --achievement-gold: #fbbf24;
    --achievement-ink: #172033;
    --achievement-muted: #697386;
}

/* Levelbar integration */
.level-bar-wrapper {
    isolation: isolate;
    overflow: visible !important;
    z-index: 1000 !important;
}

.level-bar-wrapper #levelBar { z-index: 1; }
.level-bar-wrapper #myXP,
.level-bar-wrapper #myXPbar { z-index: 2; }
.level-bar-wrapper #achievementButton,
.level-bar-wrapper #cardIcon { z-index: 4; }

#achievementButton {
    position: absolute;
    top: 15px;
    left: 10px;
    z-index: 4;
    width: 49px;
    height: 49px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: #fff !important;
    background: transparent !important;
    box-shadow: none;
    cursor: pointer;
    perspective: 700px;
    -webkit-tap-highlight-color: transparent;
}

#achievementButton:focus-visible {
    outline: 3px solid rgba(26, 115, 232, .3);
    outline-offset: 3px;
}

.level-achievement-flip {
    position: absolute;
    inset: 0;
    display: block;
    transform-style: preserve-3d;
    transition: transform .58s cubic-bezier(.2, .75, .25, 1);
}

.level-achievement-face {
    position: absolute;
    inset: 0;
    display: block;
    overflow: hidden;
    border: 5px solid #fff;
    border-radius: 50%;
    color: #fff !important;
    background: #1a73e8;
    box-shadow: 0 4px 10px rgba(26, 115, 232, .24);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.level-achievement-front {
    transform: rotateY(0deg);
}

.level-achievement-back {
    display: grid;
    place-items: center;
    transform: rotateY(180deg);
    background: linear-gradient(145deg, #3b82f6, #1a73e8);
}

#achievementButton #myLvl {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    padding: 1px 0 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    color: #fff !important;
    background: #1a73e8;
    font: 700 16px/24px Arial, sans-serif !important;
    text-align: center;
}

#achievementButton #myLvlLabel {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 5px !important;
    width: auto !important;
    height: auto !important;
    padding: 0 !important;
    border: 0 !important;
    color: #fff !important;
    background: transparent !important;
    font: 700 9px/10px Arial, sans-serif !important;
    text-align: center;
}

.level-achievement-back .material-icons {
    color: #fff !important;
    font-size: 25px;
    line-height: 1;
}

@media (hover: hover) and (pointer: fine) {
    #achievementButton:hover .level-achievement-flip {
        transform: rotateY(180deg);
    }
}

#achievementButton.is-flipped .level-achievement-flip {
    transform: rotateY(180deg);
}

#achievementButton.has-new::after {
    content: "";
    position: absolute;
    top: -3px;
    right: -3px;
    z-index: 3;
    width: 11px;
    height: 11px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #ef4444;
}

/* Personal overview */
.achievement-modal {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: grid;
    place-items: center;
    padding: 28px;
    background: rgba(13, 20, 32, .66);
    backdrop-filter: blur(5px);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    animation: achievementFadeIn .2s ease-out;
}

.achievement-modal,
.achievement-modal * {
    box-sizing: border-box;
}

.achievement-modal__panel {
    width: min(1120px, 100%);
    min-width: 0;
    max-width: 100%;
    max-height: min(880px, calc(100vh - 56px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(148, 163, 184, .34);
    border-radius: 24px;
    color: var(--achievement-ink);
    background: #f8fafc;
    box-shadow: 0 28px 90px rgba(0, 0, 0, .32);
    animation: achievementPanelIn .26s cubic-bezier(.2, .8, .2, 1);
}

.achievement-modal__header {
    min-height: 70px;
    padding: 0 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, .94);
}

.achievement-modal__header > .material-icons {
    color: #e8a600;
    font-size: 30px;
}

.achievement-modal__title {
    margin: 0;
    font-size: 22px;
    font-weight: 750;
    letter-spacing: -.02em;
}

.achievement-modal__close {
    width: 40px;
    height: 40px;
    margin-left: auto;
    border: 1px solid #dbe1e8;
    border-radius: 50%;
    background: #fff !important;
    color: #4b5563 !important;
    cursor: pointer;
    display: grid;
    place-items: center;
    box-shadow: 0 3px 10px rgba(15, 23, 42, .08);
}

.achievement-modal__close:hover,
.achievement-modal__close:focus-visible {
    color: #111827 !important;
    background: #f1f5f9 !important;
    outline: 2px solid rgba(37, 99, 235, .25);
}

.achievement-modal__body {
    min-width: 0;
    overflow-y: auto;
    padding: 24px;
    scrollbar-color: #b8c0cc transparent;
}

.achievement-intro h2 {
    margin: 0 0 4px;
    font-size: clamp(22px, 3vw, 30px);
    letter-spacing: -.025em;
}

.achievement-intro p {
    margin: 0;
    color: var(--achievement-muted);
}

.achievement-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 22px 0;
}

.achievement-summary__card {
    min-height: 108px;
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    border: 1px solid #e1e6ed;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .055);
}

.achievement-summary__icon {
    flex: 0 0 auto;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(145deg, #15a854, #087f3b);
    display: grid;
    place-items: center;
    box-shadow: 0 7px 18px rgba(21, 148, 71, .24);
}

.achievement-summary__card:nth-child(2) .achievement-summary__icon {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    box-shadow: 0 7px 18px rgba(37, 99, 235, .24);
}

.achievement-summary__card:nth-child(3) .achievement-summary__icon {
    background: linear-gradient(145deg, #8b5cf6, #6d28d9);
    box-shadow: 0 7px 18px rgba(109, 40, 217, .24);
}

.achievement-summary__label {
    display: block;
    color: var(--achievement-muted);
    font-size: 12px;
    font-weight: 650;
}

.achievement-summary__value {
    display: block;
    margin-top: 2px;
    font-size: 26px;
    line-height: 1.1;
    font-weight: 800;
}

.achievement-summary__detail {
    display: block;
    margin-top: 4px;
    color: var(--achievement-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.achievement-featured {
    position: relative;
    min-height: 132px;
    margin-bottom: 20px;
    padding: 22px 26px;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 20px;
    border-radius: 20px;
    color: #502b00;
    background: linear-gradient(115deg, #ffd43b, #fbbf24 52%, #ffdf68);
    box-shadow: 0 12px 30px rgba(217, 151, 0, .22);
}

.achievement-featured::after {
    content: "emoji_events";
    position: absolute;
    right: 24px;
    bottom: -34px;
    opacity: .09;
    font: 150px/1 "Material Icons";
}

.achievement-medal {
    --medal-color: #eab308;
    position: relative;
    isolation: isolate;
    flex: 0 0 auto;
    width: 82px;
    height: 82px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    filter: drop-shadow(0 6px 10px rgba(67, 45, 0, .17));
}

.achievement-medal__art {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.achievement-medal__scallop {
    fill: #fff;
    stroke: rgba(255, 255, 255, .98);
    stroke-width: 9;
    stroke-dasharray: .5 4.2;
    stroke-linecap: round;
}

.achievement-medal__face {
    fill: #fff;
    stroke: var(--medal-color);
    stroke-width: 2.4;
}

.achievement-medal__branch {
    fill: none;
    stroke: var(--medal-color);
    stroke-width: 2.1;
    stroke-linecap: round;
}

.achievement-medal__leaves,
.achievement-medal__star {
    fill: var(--medal-color);
}

.achievement-medal__icon {
    position: relative;
    z-index: 1;
    width: 54%;
    height: 54%;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    display: flex !important;
    align-items: center;
    justify-content: center;
    color: var(--medal-color);
    font-family: "Material Icons";
    font-feature-settings: "liga";
    font-size: 33px !important;
    line-height: 1 !important;
    text-align: center;
    white-space: nowrap;
}

.achievement-medal--featured {
    width: 96px;
    height: 96px;
}

.achievement-medal--featured .achievement-medal__icon {
    font-size: 40px !important;
}

.achievement-featured__content { position: relative; z-index: 1; min-width: 0; }
.achievement-featured__eyebrow { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.achievement-featured h3 { margin: 5px 0 4px; font-size: 25px; }
.achievement-featured p { margin: 0; font-size: 15px; }

.achievement-toolbar {
    margin: 0 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.achievement-filter {
    min-height: 36px;
    padding: 0 16px;
    border: 1px solid #dce2ea;
    border-radius: 999px;
    color: #536071;
    background: #fff;
    font-weight: 650;
    cursor: pointer;
}

.achievement-filter.is-active {
    border-color: #e7ae08;
    color: #785000;
    background: #fff9df;
}

.achievement-sort {
    width: auto;
    min-width: 165px;
    height: 38px;
    margin-left: auto;
    padding: 0 34px 0 14px;
    border: 1px solid #dce2ea;
    border-radius: 999px;
    background-color: #fff;
    color: #536071;
    display: block;
}

.achievement-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.achievement-card {
    position: relative;
    min-height: 158px;
    padding: 16px;
    overflow: hidden;
    display: grid;
    grid-template-columns: 66px minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    border: 1px solid color-mix(in srgb, var(--card-color) 55%, #d8dee8);
    border-radius: 17px;
    background: #fff;
    box-shadow: 0 5px 15px rgba(15, 23, 42, .045);
    transition: transform .18s ease, box-shadow .18s ease;
}

.achievement-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 9px 22px rgba(15, 23, 42, .09);
}

.achievement-medal--card {
    width: 64px;
    height: 64px;
    filter: none;
}

.achievement-medal--card .achievement-medal__icon {
    font-size: 27px !important;
}
.achievement-card__main { min-width: 0; }
.achievement-card h3 { margin: 2px 0 4px; font-size: 15px; line-height: 1.25; }
.achievement-card p { margin: 0; color: #657184; font-size: 12px; line-height: 1.35; }

.achievement-card__state {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    margin-top: 10px;
    padding: 0 8px;
    border-radius: 6px;
    color: #08763a;
    background: #dcfce7;
    font-size: 10px;
    font-weight: 800;
}

.achievement-card__context {
    margin-top: 6px;
    color: #778295;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.achievement-card__progress {
    grid-column: 1 / -1;
    align-self: end;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 5px 8px;
    color: #64748b;
    font-size: 10px;
    font-weight: 700;
}

.achievement-card__track {
    grid-column: 1 / -1;
    height: 5px;
    overflow: hidden;
    border-radius: 999px;
    background: #e7ebf0;
}

.achievement-card__fill {
    height: 100%;
    border-radius: inherit;
    background: var(--card-color);
}

.achievement-card[data-status="progress"] .achievement-card__state {
    color: #155bb5;
    background: #dbeafe;
}

.achievement-card[data-status="locked"] {
    --card-color: #a1a8b3 !important;
    border-color: #e1e5ea;
    background: #f8fafc;
    box-shadow: none;
}

.achievement-card[data-status="locked"] .achievement-medal,
.achievement-card[data-status="locked"] .achievement-card__main {
    filter: grayscale(1);
    opacity: .62;
}

.achievement-card[data-status="locked"] .achievement-card__state {
    color: #687281;
    background: #e8ebef;
}

.achievement-empty,
.achievement-loading,
.achievement-error {
    padding: 50px 20px;
    text-align: center;
    color: var(--achievement-muted);
}

.achievement-loading .material-icons {
    display: block;
    margin-bottom: 8px;
    font-size: 40px;
    animation: achievementSpin 1s linear infinite;
}

/* Unlock animation: timing and movement follow the supplied Xbox CodePen. */
.achievement-unlock {
    --unlock-width: min(355px, calc(100vw - 16px));
    position: fixed;
    left: 0;
    bottom: 16px;
    z-index: 2147483646;
    width: 100%;
    pointer-events: none;
}

.achievement-unlock *,
.achievement-unlock *::before,
.achievement-unlock *::after {
    box-sizing: border-box;
}

.achievement-unlock__animation {
    width: var(--unlock-width);
    height: 110px;
    padding: 5px 0;
    position: relative;
    margin: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.achievement-unlock__circle {
    width: 75px;
    height: 75px;
    top: 0;
    opacity: 0;
    margin: 0 auto;
    border-radius: 50%;
    background: #39960c;
    position: relative;
    overflow: hidden;
    z-index: 4;
    transform-origin: center;
    animation: achievementCodepenCircle 10.5s both;
}

.achievement-unlock__circle::before,
.achievement-unlock__circle::after {
    content: "";
    opacity: 0;
    width: 75px;
    height: 75px;
    position: absolute;
    inset: 0;
    border-radius: 50%;
    display: block;
    transform-origin: center;
    animation: achievementCodepenPulse 10.5s both;
}

.achievement-unlock__circle::before {
    background: #40a90e;
    animation-iteration-count: 2;
}

.achievement-unlock__circle::after {
    background: #32830a;
    animation-delay: .1s;
}

.achievement-unlock__intro-logo {
    position: absolute;
    inset: 0;
    z-index: 102;
    display: grid;
    place-items: center;
}

.achievement-unlock__intro-logo {
    color: #fff;
    animation: achievementCodepenIntro 10.5s both;
}

.achievement-unlock__intro-logo::before {
    content: "";
    position: absolute;
    inset: 13px;
    border: 4px solid #fff;
    border-radius: 50%;
}

.achievement-unlock__intro-logo .material-icons {
    position: relative;
    z-index: 1;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    color: #fff !important;
    font-size: 34px;
    line-height: 1 !important;
    text-align: center;
}

.achievement-unlock__brilliance {
    position: absolute;
    inset: 0;
    z-index: 101;
    width: 75px;
    height: 75px;
    opacity: 0;
    background-image: url('/assets/achievements/rare-brilliance.png');
    background-repeat: no-repeat;
    background-size: 11025px 75px;
    background-position: right center;
    animation:
        achievementRareSprite 7.4s steps(147) 2s both,
        achievementRareVisibility 10s ease-in-out both;
}

.achievement-unlock__banner-outer {
    display: flex;
    align-items: center;
    align-content: center;
    width: 100%;
    top: -75px;
    position: relative;
}

.achievement-unlock__banner {
    width: var(--unlock-width);
    height: 75px;
    position: relative;
    opacity: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    color: #fff;
    background: #39960c;
    overflow: hidden;
    border-radius: 100px;
    box-shadow: 0 10px 30px rgba(27, 91, 8, .28);
    animation: achievementCodepenBanner 10.5s both;
}

.achievement-unlock__text {
    display: flex;
    flex-direction: column;
    width: calc(100% - 105px);
    position: absolute;
    justify-content: center;
    margin-left: 95px;
    left: 0;
    height: 100%;
    top: 0;
    overflow: hidden;
    animation: achievementCodepenText 10.5s both;
}

.achievement-unlock__label {
    display: block;
    margin-bottom: 2px;
    width: 100%;
    font-size: 14px;
    font-weight: 400;
    color: #fff !important;
}

.achievement-unlock__title {
    display: block;
    overflow: hidden;
    font-size: 17px;
    line-height: 24px;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #fff !important;
}

@keyframes achievementFadeIn { from { opacity: 0; } }
@keyframes achievementPanelIn { from { opacity: 0; transform: translateY(16px) scale(.98); } }
@keyframes achievementSpin { to { transform: rotate(360deg); } }
@keyframes achievementCodepenPulse {
    0% { transform: scale3d(0, 0, 0); }
    2% { opacity: 1; }
    5% { transform: scale3d(1, 1, 1); opacity: .8; }
    6%, 9% { opacity: 0; }
    10% { transform: scale3d(1, 1, 1); opacity: 0; }
    90% { transform: scale3d(0, 0, 0); }
    92% { opacity: 1; }
    95% { transform: scale3d(1, 1, 1); opacity: .8; }
    96%, 99% { opacity: 0; }
    100% { transform: scale3d(1, 1, 1); opacity: 0; }
}

@keyframes achievementCodepenCircle {
    1% { opacity: 0; transform: scale(.1); }
    4% { transform: scale(1.1); }
    5% { transform: scale(1); opacity: 1; }
    11% { transform: translate(0); background-color: #39960c; }
    24%, 85% { transform: translateX(calc((var(--unlock-width) - 75px) / -2)); background-color: #42ae0e; }
    89% { transform: translateX(0); background-color: #39960c; }
    94% { transform: scale(1); }
    96% { transform: scale(1.1); }
    98% { transform: scale(.1); opacity: 1; }
    99% { opacity: 0; }
    100% { transform: scale(.1); opacity: 0; }
}

@keyframes achievementCodepenIntro {
    0%, 19% { opacity: 1; transform: scale3d(1, 1, 1); }
    23%, 90% { opacity: 0; }
    95%, 100% { opacity: 1; }
}

@keyframes achievementCodepenBanner {
    0% { width: 75px; opacity: 0; }
    2% { opacity: 0; }
    4% { opacity: 1; }
    11% { width: 75px; }
    24%, 85% { width: var(--unlock-width); }
    89% { width: 75px; opacity: 1; }
    90%, 100% { width: 75px; opacity: 0; }
}

@keyframes achievementCodepenText {
    0%, 20% { transform: translateY(85px); opacity: 0; }
    25%, 79% { transform: translateY(0); opacity: 1; }
    84% { transform: translateY(-115px); opacity: 0; }
    100% { opacity: 0; }
}

@keyframes achievementRareSprite {
    from { background-position: 0 center; }
    to { background-position: -11025px center; }
}

@keyframes achievementRareVisibility {
    0%, 20% { opacity: 0; }
    20.00001%, 90% { opacity: 1; }
    95%, 100% { opacity: 0; }
}

@media (max-width: 820px) {
    .achievement-modal { padding: 12px; }
    .achievement-modal__panel { max-height: calc(100vh - 24px); border-radius: 18px; }
    .achievement-modal__body { padding: 18px; }
    .achievement-summary { grid-template-columns: 1fr; }
    .achievement-summary__card { min-height: 86px; }
    .achievement-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
    .achievement-modal__header {
        min-width: 0;
        padding: 0 16px;
    }
    .achievement-modal__title {
        min-width: 0;
        overflow: hidden;
        font-size: 22px;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .achievement-modal__close { flex: 0 0 40px; }
    .achievement-grid { grid-template-columns: 1fr; }
    .achievement-featured { padding: 18px; }
    .achievement-medal--featured { width: 76px; height: 76px; }
    .achievement-medal--featured .achievement-medal__icon { font-size: 32px !important; }
    .achievement-sort { width: 100%; margin-left: 0; }
    .achievement-unlock { bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    .achievement-modal,
    .achievement-modal__panel,
    .achievement-unlock__banner,
    .achievement-unlock__circle,
    .achievement-unlock__circle::before,
    .achievement-unlock__circle::after,
    .achievement-unlock__intro-logo,
    .achievement-unlock__brilliance,
    .achievement-unlock__text {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}
