:root {
    --bg-dark: #121217;
    --panel-bg: #1a1a21;
    --border-color: #2c2c35;
    --accent: #0088ff;
    --accent-hover: #0077ee;
    --text-primary: #ffffff;
    --text-secondary: #8d8d99;
    --icon-size: 24px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, sans-serif;
    overflow: hidden;
}

/* Layout */
.layout-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

/* 1. Left Panel (Colors) */
.left-panel {
    width: 60px;
    background: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    gap: 15px;
    z-index: 20;
    overflow-y: auto;
}

.left-panel::-webkit-scrollbar {
    width: 0;
}

.color-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
    background-size: cover;
}

.color-dot:hover {
    transform: scale(1.1);
}

.color-dot.active {
    border-color: white;
    transform: scale(1.2);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* 2. Main 3D View */
.main-stage {
    flex: 1;
    position: relative;
    background: radial-gradient(circle at center, #1a1f2c 0%, #050505 100%);
    overflow: hidden;
}

#bgCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

#avatarViewerContainer {
    width: 100%;
    height: 100%;
    z-index: 10;
    position: relative;
}

/* Background Control Panel */
#bg-control-panel {
    position: absolute;
    top: 200px;
    left: 20px;
    background: rgba(30, 30, 30, 0.85);
    backdrop-filter: blur(10px);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 200px;
    z-index: 50;
}

#bg-control-panel h2 {
    margin: 0 0 5px 0;
    font-size: 14px;
    color: #a0cfff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#bg-control-panel label {
    font-size: 11px;
    color: #aaa;
    margin-bottom: 2px;
    display: block;
}

#bg-control-panel select {
    width: 100%;
    padding: 6px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #444;
    border-radius: 6px;
    color: white;
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

#bg-control-panel select:hover {
    border-color: #666;
}

#bg-control-panel select:focus {
    border-color: #00a8ff;
}

.status-dot {
    width: 6px;
    height: 6px;
    background-color: #00ff88;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    box-shadow: 0 0 5px #00ff88;
}

.panel-header {
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
    margin-bottom: 5px;
}

/* 3. Right Sidebar */
.right-section {
    display: flex;
    height: 100%;
    z-index: 30;
    background: var(--panel-bg);
    border-left: 1px solid var(--border-color);
}

.asset-drawer {
    width: 320px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background: var(--panel-bg);
}

.drawer-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.search-bar {
    background: #25252d;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 10px 15px;
    color: white;
    width: 100%;
    font-size: 14px;
    outline: none;
}

.search-bar:focus {
    border-color: var(--accent);
}

/* NEW: Filter Scroll Bar */
.filter-scroll {
    display: flex;
    overflow-x: auto;
    padding: 10px 15px;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    background: var(--panel-bg);
    flex-shrink: 0;
}

.filter-scroll::-webkit-scrollbar {
    height: 4px;
}

.filter-scroll::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 2px;
}

.filter-chip {
    padding: 6px 14px;
    border-radius: 16px;
    background: #252528;
    color: #888;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    user-select: none;
}

.filter-chip:hover {
    color: white;
    background: #333;
}

.filter-chip.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(0, 136, 255, 0.3);
}

.asset-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    grid-auto-rows: min-content;
    /* Fix for row height */
    gap: 12px;
    padding-bottom: 20px;
    align-content: start;
}

.asset-grid::-webkit-scrollbar {
    width: 6px;
}

.asset-grid::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

.asset-item {
    aspect-ratio: 1;
    background: #25252d;
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.asset-item:hover {
    background: #2f2f38;
}

.asset-item.active {
    border-color: var(--accent);
    background: rgba(0, 136, 255, 0.1);
}

.asset-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 5px;
}

/* Animation Card */
.anim-card {
    aspect-ratio: 1;
    min-height: 90px;
    /* Ensure visibility even if empty */
    background: #252528;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.anim-card:hover {
    background: #333;
    transform: translateY(-2px);
}

.anim-card.selected {
    border-color: #0088ff;
    background: #1a2a3a;
}

.anim-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.8;
    transition: opacity 0.2s;
    background-color: #000;
    /* Fallback bg */
}

.anim-card:hover img {
    opacity: 1;
}

.anim-card .anim-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 10px;
    padding: 4px 2px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* Nav Sidebar */
.nav-sidebar {
    width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    gap: 15px;
    background: #15151a;
}

.nav-item {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 24px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.nav-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: var(--accent);
    background: rgba(0, 136, 255, 0.1);
}

/* Buttons & Overlay */
.top-bar {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    z-index: 40;
}

.btn {
    padding: 10px 24px;
    border-radius: 24px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.1s;
}

.btn:active {
    transform: scale(0.95);
}

.btn-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.btn-circle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 136, 255, 0.3);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* Loader */
.loader {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s;
}

.loader.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Gender Selection */
.gender-select {
    display: flex;
    gap: 20px;
    margin-top: 30px;
}

.g-card {
    width: 120px;
    height: 160px;
    background: #222;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 2px solid transparent;
    gap: 10px;
}

.g-card:hover {
    border-color: #444;
}

.g-card.selected {
    border-color: var(--accent);
    background: #1a2530;
}

.g-icon {
    font-size: 40px;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Mobile */
@media (max-width: 900px) {
    .asset-drawer {
        width: 240px;
    }

    .asset-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .layout-container {
        flex-direction: column;
    }

    .left-panel {
        display: none;
    }

    .right-section {
        height: 40%;
        width: 100%;
    }

    .main-stage {
        height: 60%;
    }

    .asset-drawer {
        width: 100%;
        border-right: none;
    }

    .nav-sidebar {
        width: 60px;
    }
}