/* Avatar Tab Styles */
/* Extracted from index.html lines 134-519 */

#avatar-display-container {
    position: relative;
    width: 300px;
    height: 400px;
    margin: 0 auto;
    border: 3px solid #333;
    border-radius: 10px;
    overflow: hidden;
    background-color: #f0f0f0;
}

.avatar-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Ensures images respect aspect ratio */
    object-position: bottom center;
    /* Aligns all layers to the bottom */
    z-index: 1;
}

/* Layer specific z-indices (Front to Back) */
/* Order: glasses, hair, jacket, t-shirt, head, trainers, trousers, arms, background */
.avatar-layer.glasses {
    z-index: 10;
}

.avatar-layer.hat {
    z-index: 11;
}

.avatar-layer.pet {
    z-index: 12;
}

.avatar-layer.hair {
    z-index: 9;
}

.avatar-layer.jacket {
    z-index: 8;
}

.avatar-layer.t-shirt {
    z-index: 7;
}

.avatar-layer.head {
    z-index: 6;
}

.avatar-layer.trainers {
    z-index: 4;
}

.avatar-layer.trousers {
    z-index: 3;
}

.avatar-layer.arms {
    z-index: 2;
}

.avatar-layer.background {
    object-fit: cover;
    /* Background should fill the container */
    object-position: center;
    z-index: 1;
}

/* Helper to raise trainers above trousers (z-index 4) */
.avatar-layer.trainers.layer-over-trousers {
    z-index: 5 !important;
}

/* Avatar Builder Styles */
.avatar-builder-container {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    height: 100%;
}

.category-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.category-btn {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    color: #555;
}

.category-btn.active {
    background: #4a90e2;
    color: white;
    border-color: #4a90e2;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.3);
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
}

.option-card {
    background: white;
    border-radius: 10px;
    padding: 0;
    /* REMOVED padding to maximize icon size */
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.option-card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 5px;
    /* Add slight internal padding to prevent edge touching if needed, or keeping it 0 for max size */
}

.option-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.option-card.active {
    border-color: #4a90e2;
    background-color: #f0f7ff;
    transform: scale(1.05);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
}

/* 3D Pop Animation */
@keyframes popIn {
    0% {
        transform: scale(0.9);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.pop-anim {
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* --- Avatar App Collections Mode --- */
.avatar-mode-container {
    animation: fadeInUp 0.5s ease-out;
}

#avatar-collections-carousel {
    display: flex;
    overflow-x: auto;
    gap: 1.5rem;
    padding: 1rem 0.5rem;
    scroll-behavior: smooth;
}

.collection-card {
    min-width: 140px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.collection-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.1);
}

.collection-card img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 0.5rem;
}

.collection-card h6 {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.collection-card p {
    font-size: 0.75rem;
    color: #aaa;
    margin-bottom: 0.75rem;
    line-height: 1.2;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spinHighlight {
    0% {
        transform: rotate(0deg) scale(1);
        filter: brightness(1);
    }

    50% {
        transform: rotate(180deg) scale(1.1);
        filter: brightness(1.2);
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.6);
    }

    100% {
        transform: rotate(360deg) scale(1);
        filter: brightness(1);
    }
}

/* --- Avatar Shop Category Grid --- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 20px;
    margin-bottom: 1.5rem;
}

.category-icon-btn {
    width: 100%;
    aspect-ratio: 1;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    z-index: 1;
}

.category-icon-btn i {
    font-size: 1.2rem;
    color: #6c757d;
    transition: all 0.2s ease;
}

.category-icon-btn:hover {
    background: #e9ecef;
    transform: scale(1.05);
    border-color: #adb5bd;
    z-index: 10;
}

.category-icon-btn:hover i {
    color: #495057;
}

.category-icon-btn.active {
    background: var(--primary-color, #0d6efd);
    border-color: var(--primary-color, #0d6efd);
    box-shadow: 0 0 15px rgba(13, 110, 253, 0.4);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.category-icon-btn.active i {
    color: #fff;
    transform: scale(1.1);
}

/* Collection icon grid (Collections mode) */
.avatar-collections-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
    align-items: start;
}

.collection-icon-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease;
    padding: 4px;
}

.collection-icon-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.collection-lock-badge {
    position: absolute;
    right: 6px;
    bottom: 6px;
    color: #FFD700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.85);
    font-size: 1.25rem;
    z-index: 2;
    pointer-events: none;
}

/* Tooltip on hover */
.category-icon-btn::after,
.collection-icon-container::after {
    content: attr(data-label);
    position: absolute;
    top: 100%;
    margin-top: -5px;
    /* Pull it slightly up closer to the icon */
    left: 50%;
    transform: translateX(-50%);
    /* Move it below the element */
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
}

.category-icon-btn:hover::after,
.collection-icon-container:hover::after {
    opacity: 1;
}

@media (max-width: 576px) {
    .category-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
}

@media (max-width: 768px) {
    #tab-avatar .container-fluid {
        padding-left: 0;
        padding-right: 0;
    }

    .avatar-collections-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
    }

    .collection-icon-container {
        padding: 2px;
    }

    .collection-icon-container img {
        width: 92%;
        height: 92%;
    }

    .collection-lock-badge {
        right: 6px;
        bottom: 4px;
        font-size: 1.1rem;
    }
}

/* --- Avatar Mode Switch (Segmented Control) --- */
.avatar-mode-switch-container {
    display: flex;
    background-color: #e9ecef;
    /* Light grey track */
    border: 1px solid #dee2e6;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    /* Inner shadow for depth */
    border-radius: 50px;
    /* Pill shape */
    padding: 4px;
    margin-bottom: 20px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    cursor: pointer;
    width: 100%;
    max-width: 300px;
}

.mode-switch-item {
    flex: 1;
    text-align: center;
    padding: 8px 16px;
    border-radius: 50px;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #6c757d;
    /* Inactive grey */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    user-select: none;
}

.mode-switch-item.active {
    background-color: #fff;
    color: #0d6efd;
    /* Active Blue */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    /* Pop out shadow */
    transform: scale(1.02);
    /* Slight scale up */
}

/* --- Economy Header Card (Phase 5) --- */
#avatar-economy-header {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 14px;
    padding: 14px 8px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: stretch;
    gap: 0;
    animation: fadeInDown 0.5s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Each panel inside the header */
.economy-panel {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-align: center;
    padding: 4px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Subtle vertical separator between panels */
.economy-panel+.economy-panel {
    border-left: 1px solid #e9ecef;
}

/* Section title */
.economy-panel-title {
    font-size: 1.0rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #555;
    margin-bottom: 8px;
}

/* Growable content area pushes footer to bottom */
.economy-panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* Row of icon+value pairs inside Balance panel */
.economy-items-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

/* Footer row for Balance panel (X Drops / X Keys side by side) */
.economy-footer-row {
    display: flex;
    width: 100%;
    margin-top: auto;
    padding-top: 8px;
}

.economy-footer-row .economy-item-value {
    flex: 1;
    text-align: center;
}

/* Single icon + label unit */
.economy-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.economy-item img {
    width: 56px;
    height: 56px;
    max-width: 56px;
    max-height: 56px;
    object-fit: contain;
}

.economy-item-value,
.economy-panel>.economy-item-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    margin-top: auto;
    padding-top: 8px;
}

/* --- Panel 2: Weekly Progress --- */
.weekly-progress-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 6px;
}

.progress-dots {
    display: flex;
    align-items: center;
    gap: 6px;
}

.progress-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.progress-dot.dot-green {
    background: #2fbf5b;
}

.progress-dot.dot-blue {
    background: #2d8fd5;
}

.progress-dot.dot-black {
    background: #2f3a4a;
}

.progress-dot.dot-amber {
    background: #f2b63d;
}

.progress-dot.dot-grey {
    background: #d1d5db;
}

/* --- Panel 3: Keys Grid --- */
.keys-grid {
    display: grid;
    grid-template-columns: repeat(4, 28px);
    gap: 4px;
    justify-content: center;
    margin-bottom: 6px;
}

/* Locked Item Styling - no grayscale, let user see the item */
.option-card.locked {
    cursor: pointer;
}

/* Card + price wrapper */
.option-card-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Lock badge (top-right corner) */
.lock-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 1.1rem;
    z-index: 10;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
    line-height: 1;
}

.option-card.locked:hover .lock-badge {
    transform: scale(1.2);
    transition: transform 0.2s;
}

/* Price row below the card */
.card-price-below {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 1.1rem;
    font-weight: 700;
    color: #555;
}

/* Collection Lock */
.collection-card.locked {
    position: relative;
    opacity: 0.8;
}

.collection-card.locked::after {
    content: '\f023';
    /* FontAwesome Lock */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.8);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 5;
}

/* Purchase Modal / Confirm Styles */
.purchase-confirm-dialog {
    text-align: center;
}

/* Fix for page jump/layout shift */
#avatar-options-grid,
#avatar-collections-carousel {
    min-height: 320px;
    /* Reduced to avoid excessive whitespace */
    transition: min-height 0.3s ease;
}

/* --- Avatar Celebration Modals --- */
.avatar-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.avatar-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.avatar-modal {
    background: white;
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    transform: scale(0.8);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    position: relative;
    border: 4px solid #f0f0f0;
}

.avatar-modal-overlay.active .avatar-modal {
    transform: scale(1);
    opacity: 1;
}

.avatar-modal-image-container {
    width: 160px;
    height: 160px;
    background: #f8f9fa;
    border-radius: 50%;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid #FFD700;
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.2);
    animation: float 3s ease-in-out infinite;
}

.avatar-modal-image {
    width: 80%;
    height: 80%;
    object-fit: contain;
}

.avatar-modal h3 {
    margin-bottom: 10px;
    color: #333;
    font-weight: 800;
    font-size: 1.5rem;
}

.avatar-modal p {
    color: #666;
    margin-bottom: 25px;
    font-size: 1.1rem;
    line-height: 1.4;
}

.avatar-modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.avatar-modal-btn {
    padding: 12px 30px;
    border-radius: 25px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    font-size: 1rem;
}

.avatar-modal-btn:hover {
    transform: scale(1.05);
}

.avatar-modal-btn.primary {
    background: #FFD700;
    color: #333;
    box-shadow: 0 4px 10px rgba(255, 215, 0, 0.4);
}

.avatar-modal-btn.secondary {
    background: #f0f0f0;
    color: #666;
}

.avatar-modal-btn.secondary:hover {
    background: #e0e0e0;
}

.avatar-modal-confetti {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    pointer-events: none;
    z-index: -1;
    background-image:
        radial-gradient(circle, #FFD700 10px, transparent 10px),
        radial-gradient(circle, #ff6b6b 10px, transparent 10px),
        radial-gradient(circle, #4ecdc4 10px, transparent 10px);
    background-size: 20% 20%;
    background-position: 0 0, 50% 50%, 100% 100%;
    opacity: 0;
}

.avatar-modal-overlay.detect-celebration .avatar-modal-confetti {
    animation: confettiBurst 1s ease-out forwards;
}

@keyframes confettiBurst {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0;
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* --- Dashboard Mini Avatar Widget --- */
.dashboard-mini-avatar-container {
    background: white;
    border-radius: 16px;
    padding: 6px;
    margin: 15px auto 25px;
    width: 120px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.dashboard-mini-avatar-container:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    border-color: #FFD700;
}

.dashboard-mini-avatar-preview {
    position: relative;
    width: 100%;
    height: 120px;
    margin: 0 auto 0;
    background: transparent;
    border-radius: 12px;
    overflow: hidden;
}

.dashboard-mini-avatar-preview .avatar-layer {
    width: 150%;
    height: 150%;
    left: -25%;
    top: -10%;
    object-position: top center;
}



.dashboard-mini-avatar-stats {
    display: flex;
    justify-content: center;
    gap: 12px;
    background: #f8f9fa;
    border-radius: 20px;
    padding: 6px 10px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #444;
}

.stat-item img {
    width: 18px;
    height: 18px;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
}

/* Final mobile overrides for economy header visibility/readability */
@media (max-width: 768px) {
    #avatar-economy-header {
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        padding: 10px 12px !important;
        animation: none !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    #avatar-economy-header .economy-panel {
        width: 100% !important;
        min-height: auto !important;
        padding: 14px 8px !important;
        overflow: visible !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
    }

    #avatar-economy-header .economy-panel + .economy-panel {
        border-left: 0 !important;
        border-top: 1px solid #e9ecef !important;
    }

    #avatar-economy-header .economy-panel-title {
        color: #555 !important;
        font-size: 0.9rem !important;
        line-height: 1.15 !important;
        margin: 0 0 6px 0 !important;
    }

    #avatar-economy-header .economy-panel-content {
        width: 100%;
        flex: 0 0 auto !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }

    #avatar-economy-header .economy-items-row {
        gap: 10px;
    }

    #avatar-economy-header .economy-items-row img:first-child {
        width: 72px !important;
        height: 72px !important;
        max-width: 72px !important;
        max-height: 72px !important;
    }

    #avatar-economy-header .economy-items-row img:last-child {
        width: 40px !important;
        height: 40px !important;
        max-width: 40px !important;
        max-height: 40px !important;
    }

    #avatar-economy-header .weekly-progress-row {
        margin-bottom: 0 !important;
        gap: 8px;
    }

    #avatar-economy-header .weekly-progress-row img {
        width: 38px !important;
        height: 38px !important;
        max-width: 38px !important;
        max-height: 38px !important;
    }

    #avatar-economy-header .economy-footer-row {
        width: 100%;
        margin-top: 6px !important;
        padding-top: 0 !important;
        display: flex;
        gap: 0;
    }

    #avatar-economy-header .economy-footer-row .economy-item-value {
        flex: 1;
        text-align: center !important;
    }

    #avatar-economy-header .keys-grid {
        margin-bottom: 0 !important;
    }

    #avatar-economy-header .economy-item-value,
    #avatar-economy-header .economy-panel > .economy-item-value {
        display: block !important;
        color: #333 !important;
        font-size: 0.85rem !important;
        white-space: normal !important;
        line-height: 1.2 !important;
        text-align: center !important;
        margin-top: 0 !important;
        padding-top: 0 !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    #avatar-economy-header .economy-panel > .economy-item-value {
        margin-top: 4px !important;
    }

    #avatar-economy-header img {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
}
