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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
    color: #e0e0e0;
    overflow: hidden;
}

#app-container {
    display: grid;
    grid-template-areas: 
        "header header header"
        "left-sidebar scene right-sidebar"
        "bottom-controls bottom-controls bottom-controls"
        "footer footer footer";
    grid-template-rows: 100px 1fr 60px 40px;
    grid-template-columns: 320px 1fr 320px;
    height: 100vh;
    gap: 10px;
    padding: 10px;
}

/* Header */
.header {
    grid-area: header;
    background: rgba(26, 26, 46, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 15px;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.app-title {
    font-size: 2rem;
    font-weight: bold;
    background: linear-gradient(135deg, #00d4ff, #ff6b35);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
}

.version-badge {
    position: absolute;
    top: 10px;
    left: 20px;
    background: rgba(255, 107, 53, 0.8);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
}

.generation-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.control-input {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(0, 212, 255, 0.5);
    border-radius: 8px;
    padding: 8px 12px;
    color: #e0e0e0;
    font-size: 14px;
    transition: all 0.3s ease;
}

.control-input:focus {
    outline: none;
    border-color: #00d4ff;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

.generate-btn {
    background: linear-gradient(135deg, #00d4ff, #0099cc);
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 212, 255, 0.4);
}

.regen-textures-btn {
    background: linear-gradient(135deg, #ff6b35, #e55a2b);
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 13px;
}

.regen-textures-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 107, 53, 0.4);
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Sidebars */
.left-sidebar, .right-sidebar {
    background: rgba(26, 26, 46, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 15px;
    padding: 20px;
    overflow-y: auto;
}

.left-sidebar {
    grid-area: left-sidebar;
}

.right-sidebar {
    grid-area: right-sidebar;
}

.panel {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
}

.panel h3 {
    color: #00d4ff;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.panel h4 {
    color: #ff6b35;
    margin: 15px 0 10px 0;
    font-size: 1rem;
}

.panel label {
    display: block;
    margin: 10px 0 5px 0;
    font-size: 14px;
    color: #cccccc;
}

/* NEW: Collapsible panels */
.collapsible-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: color 0.3s ease;
}

.collapsible-header:hover {
    color: #ff6b35;
}

.collapse-indicator {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.collapsible-content {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.collapsible-content.collapsed {
    max-height: 0;
}

/* NEW: Template inputs */
.template-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 6px;
    padding: 8px;
    color: #e0e0e0;
    font-size: 12px;
    font-family: monospace;
    resize: vertical;
    min-height: 50px;
}

.template-input:focus {
    outline: none;
    border-color: #00d4ff;
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.2);
}

.template-controls {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.small-btn {
    background: rgba(0, 212, 255, 0.2);
    border: 1px solid rgba(0, 212, 255, 0.5);
    border-radius: 4px;
    padding: 4px 8px;
    color: #00d4ff;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.3s ease;
}

.small-btn:hover {
    background: rgba(0, 212, 255, 0.3);
}

.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #00d4ff;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #00d4ff;
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

/* Scene Container */
.scene-container {
    grid-area: scene;
    position: relative;
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 15px;
    overflow: hidden;
    background: radial-gradient(circle, rgba(26, 26, 46, 0.8) 0%, rgba(10, 10, 10, 0.9) 100%);
}

.scene-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(0, 212, 255, 0.3);
    border-top: 4px solid #00d4ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.progress-bar {
    width: 300px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    margin: 20px auto;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #00d4ff, #0099cc);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.fps-counter {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: #00d4ff;
    padding: 5px 10px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 12px;
    z-index: 100;
}

/* NEW: Texture Debug Overlay */
.texture-debug-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(0, 212, 255, 0.5);
    border-radius: 8px;
    padding: 10px;
    max-width: 300px;
    z-index: 100;
    font-size: 12px;
}

.texture-debug-overlay h4 {
    color: #00d4ff;
    margin-bottom: 8px;
}

.texture-debug-overlay p {
    margin: 4px 0;
    color: #cccccc;
}

/* Bottom Controls */
.bottom-controls {
    grid-area: bottom-controls;
    background: rgba(26, 26, 46, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 15px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.view-controls, .export-controls {
    display: flex;
    gap: 10px;
}

.control-btn {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(0, 212, 255, 0.5);
    border-radius: 6px;
    padding: 8px 12px;
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 12px;
}

.control-btn:hover {
    background: rgba(0, 212, 255, 0.2);
    border-color: #00d4ff;
    transform: translateY(-1px);
}

/* Enhanced Texture Gallery */
.texture-gallery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-height: 250px;
    overflow-y: auto;
}

.texture-thumbnail {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px;
    text-align: center;
    transition: all 0.3s ease;
}

.texture-thumbnail.success {
    border-color: rgba(0, 255, 136, 0.3);
}

.texture-thumbnail.failed {
    border-color: rgba(255, 107, 53, 0.5);
}

.texture-thumbnail img {
    width: 100%;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 5px;
}

.failed-texture {
    width: 100%;
    height: 50px;
    background: rgba(255, 107, 53, 0.2);
    border: 1px dashed rgba(255, 107, 53, 0.5);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ff6b35;
    font-size: 10px;
    margin-bottom: 5px;
}

.texture-info {
    font-size: 10px;
}

.texture-info p {
    color: #aaa;
    margin-bottom: 5px;
    line-height: 1.2;
}

.texture-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.quality-indicator {
    font-size: 12px;
}

.regen-btn {
    background: rgba(255, 107, 53, 0.3);
    border: 1px solid #ff6b35;
    border-radius: 4px;
    color: #ff6b35;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.3s ease;
}

.regen-btn:hover {
    background: rgba(255, 107, 53, 0.5);
}

.regen-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.texture-controls {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.generation-log {
    max-height: 150px;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.4;
}

.generation-log p {
    margin-bottom: 5px;
    padding: 3px 0;
}

.timestamp {
    color: #666;
    font-family: monospace;
}

/* Footer */
.footer {
    grid-area: footer;
    background: rgba(26, 26, 46, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 15px;
    padding: 10px 20px;
    text-align: center;
    font-size: 12px;
}

.footer a {
    color: #00d4ff;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Mobile Responsiveness */
@media (max-width: 1400px) {
    #app-container {
        grid-template-columns: 280px 1fr 280px;
    }
}

@media (max-width: 1200px) {
    #app-container {
        grid-template-areas: 
            "header"
            "scene"
            "bottom-controls"
            "footer";
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto auto;
    }
    
    .left-sidebar, .right-sidebar {
        display: none;
    }
    
    .generation-controls {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .control-input {
        font-size: 12px;
        padding: 6px 8px;
    }
    
    .app-title {
        font-size: 1.5rem;
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    
    .bottom-controls {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    
    .view-controls, .export-controls {
        justify-content: center;
    }
    
    .control-btn {
        font-size: 11px;
        padding: 6px 8px;
    }
    
    .version-badge {
        position: static;
        margin-bottom: 5px;
    }
}

/* Custom scrollbars */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.7);
}

/* Enhanced animations */
@keyframes glow {
    0%, 100% { 
        box-shadow: 0 0 5px rgba(0, 212, 255, 0.3); 
    }
    50% { 
        box-shadow: 0 0 20px rgba(0, 212, 255, 0.6); 
    }
}

.texture-thumbnail.success {
    animation: glow 2s ease-in-out;
}

/* Improved focus states */
.control-input:focus,
.template-input:focus {
    outline: none;
    border-color: #00d4ff;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

/* Better button hover effects */
.generate-btn:hover,
.regen-textures-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.small-btn:hover,
.regen-btn:hover {
    transform: translateY(-1px);
}