* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Space Grotesk', sans-serif;
    background: #1a1a1a;
    color: #fff;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-columns: 250px 1fr 200px;
    grid-template-rows: 60px 1fr 60px;
    height: 100vh;
    width: 100vw;
}

/* Toolbar */
#toolbar {
    grid-column: 1 / -1;
    grid-row: 1;
    background: linear-gradient(180deg, #3a3a3a 0%, #2a2a2a 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 2px solid #FFD700;
    z-index: 100;
}

.toolbar-left, .toolbar-center, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-btn, .action-btn {
    background: #444;
    border: 2px solid #555;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #fff;
}

.tool-btn:hover, .action-btn:hover {
    background: #555;
    transform: translateY(-2px);
}

.tool-btn.active {
    background: #FFD700;
    border-color: #FFD700;
    color: #1a1a1a;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.5);
}

.action-btn.test-drive {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff8e53 100%);
    border-color: #ff6b6b;
}

.action-btn.test-drive:hover {
    transform: translateY(-2px) scale(1.05);
}

.action-btn.test-drive.active {
    animation: pulse 0.5s ease infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.divider {
    width: 2px;
    height: 30px;
    background: #555;
    margin: 0 8px;
}

.snap-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #aaa;
}

.switch {
    position: relative;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #555;
    border-radius: 24px;
    transition: 0.3s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}

input:checked + .slider {
    background: #FFD700;
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.layer-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #aaa;
}

.layer-display button {
    background: #555;
    border: none;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.layer-display button:hover {
    background: #FFD700;
    color: #1a1a1a;
}

/* Left Sidebar */
#leftSidebar {
    grid-column: 1;
    grid-row: 2;
    background: #2a2a2a;
    overflow-y: auto;
    border-right: 1px solid #444;
}

.sidebar-header {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-header h2 {
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    color: #1a1a1a;
}

.category-section {
    border-bottom: 1px solid #333;
}

.category-header {
    padding: 12px 16px;
    background: #333;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 13px;
    transition: background 0.2s;
}

.category-header:hover {
    background: #444;
}

.category-section.collapsed .category-content {
    display: none;
}

.category-section.collapsed .toggle {
    transform: rotate(-90deg);
}

.toggle {
    transition: transform 0.2s;
    font-size: 10px;
}

.category-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
}

.brick-item {
    background: #3a3a3a;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}

.brick-item:hover {
    background: #444;
    transform: scale(1.05);
}

.brick-item.selected {
    border-color: #00aaff;
    box-shadow: 0 0 12px rgba(0, 170, 255, 0.4);
}

.brick-preview {
    height: 40px;
    background: linear-gradient(135deg, #666 0%, #444 100%);
    border-radius: 4px;
    margin-bottom: 6px;
}

.brick-name {
    font-size: 10px;
    color: #aaa;
    display: block;
}

/* Color Picker */
.color-picker {
    padding: 16px;
    border-top: 1px solid #444;
}

.color-picker h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: #FFD700;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.color-swatch {
    aspect-ratio: 1;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid #333;
    transition: all 0.2s ease;
    min-width: 28px;
    min-height: 28px;
}

.color-swatch:hover {
    transform: scale(1.15);
    z-index: 10;
}

.color-swatch.selected {
    border-color: #FFD700;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
}

/* Main Canvas */
#scene-container {
    grid-column: 2;
    grid-row: 2;
    background: linear-gradient(180deg, #1a1a1a 0%, #0d0d0d 100%);
    position: relative;
}

#scene-container canvas {
    display: block;
}

/* Camera Controls */
#cameraControls {
    position: absolute;
    bottom: 80px;
    right: 220px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 50;
}

.cam-btn {
    background: rgba(42, 42, 42, 0.9);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 11px;
    cursor: pointer;
    color: #fff;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

.cam-btn:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: #FFD700;
}

.cam-btn.active {
    background: #FFD700;
    color: #1a1a1a;
}

/* Right Sidebar */
#rightSidebar {
    grid-column: 3;
    grid-row: 2;
    background: #2a2a2a;
    border-left: 1px solid #444;
    overflow-y: auto;
    transition: width 0.3s ease;
}

#rightSidebar.collapsed {
    width: 40px;
}

#rightSidebar.collapsed .templates-list,
#rightSidebar.collapsed .sidebar-header h2 {
    display: none;
}

#toggleSidebar {
    background: none;
    border: none;
    color: #1a1a1a;
    cursor: pointer;
    font-size: 14px;
}

.templates-list {
    padding: 12px;
}

.template-item {
    background: #3a3a3a;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
}

.template-item:hover {
    background: #444;
    border-color: #FFD700;
    transform: translateX(-4px);
}

.template-emoji {
    font-size: 28px;
}

.template-info {
    display: flex;
    flex-direction: column;
}

.template-name {
    font-weight: 700;
    font-size: 13px;
    color: #fff;
}

.template-desc {
    font-size: 10px;
    color: #888;
    margin-top: 2px;
}

/* Stats Panel */
#statsPanel {
    grid-column: 1 / -1;
    grid-row: 3;
    background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    padding: 0 24px;
    border-top: 2px solid #FFD700;
    z-index: 100;
    flex-wrap: wrap;
}

.stat {
    font-size: 14px;
    color: #aaa;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.stat span {
    color: #fff;
    font-weight: 700;
}

.berrry-link {
    font-size: 12px;
    color: #666;
    text-decoration: none;
    transition: color 0.2s;
    white-space: nowrap;
}

.berrry-link:hover {
    color: #FFD700;
}

/* Responsive - Tablet */
@media (max-width: 1024px) {
    #app {
        grid-template-columns: 200px 1fr 0;
    }
    
    #rightSidebar {
        display: none;
    }
    
    #cameraControls {
        right: 20px;
    }
    
    .category-content {
        grid-template-columns: 1fr;
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: 50px 1fr auto 50px;
    }
    
    #leftSidebar {
        grid-column: 1;
        grid-row: 3;
        max-height: 200px;
        overflow-y: auto;
    }
    
    #scene-container {
        grid-column: 1;
        grid-row: 2;
    }
    
    #toolbar {
        padding: 0 8px;
        overflow-x: auto;
    }
    
    .toolbar-center {
        display: none;
    }
    
    .toolbar-left, .toolbar-right {
        gap: 4px;
    }
    
    .tool-btn, .action-btn {
        padding: 6px 8px;
        font-size: 14px;
        min-width: 36px;
        min-height: 36px;
    }
    
    .divider {
        margin: 0 4px;
    }
    
    #cameraControls {
        bottom: 260px;
        right: 10px;
    }
    
    .cam-btn {
        padding: 6px 8px;
        font-size: 10px;
    }
    
    #statsPanel {
        gap: 8px;
        padding: 8px 12px;
        justify-content: space-around;
    }
    
    .stat {
        font-size: 11px;
    }
    
    .berrry-link {
        width: 100%;
        text-align: center;
        order: 10;
    }
    
    .category-content {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
        padding: 8px;
    }
    
    .brick-item {
        padding: 6px;
    }
    
    .brick-preview {
        height: 30px;
    }
    
    .brick-name {
        font-size: 9px;
    }
    
    .color-grid {
        grid-template-columns: repeat(10, 1fr);
        gap: 4px;
    }
    
    .color-swatch {
        min-width: 24px;
        min-height: 24px;
    }
    
    .sidebar-header {
        padding: 8px 12px;
    }
    
    .sidebar-header h2 {
        font-size: 14px;
    }
    
    .color-picker {
        padding: 10px;
    }
    
    .color-picker h3 {
        font-size: 12px;
        margin-bottom: 8px;
    }
}

/* Very small mobile */
@media (max-width: 400px) {
    .tool-btn, .action-btn {
        padding: 4px 6px;
        font-size: 12px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .stat {
        font-size: 10px;
    }
    
    #statsPanel {
        gap: 6px;
    }
    
    .category-content {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #FFD700;
}