/* --- Variables --- */
:root {
    --bg-dark: #121212;
    --surface-glass: rgba(18, 18, 18, 0.85);
    /* Darker, more legible glass */
    --surface-hover: rgba(40, 40, 40, 0.9);
    --primary-color: #3b82f6;
    /* Modern Blue */
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border-radius: 12px;
    --border-color: rgba(255, 255, 255, 0.08);
    --blur-amount: 12px;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-size: 14px;
}

#canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    outline: none;
}

/* --- UI Containers --- */
#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass to canvas */
}

/* Panel Containers */
.panel-container {
    position: absolute;
    z-index: 20;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.panel-container.top-right {
    top: 20px;
    right: 20px;
    align-items: flex-end;
}

.panel-container.bottom-left {
    bottom: 20px;
    left: 20px;
    align-items: flex-start;
}

/* --- Components --- */

/* Header */
header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    gap: 12px;
}

h1 {
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 12px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

/* New Upload Button Placement? keeping it simple for now, maybe floats top left */
/* --- Unified Menu --- */
#main-menu-container {
    position: relative;
    pointer-events: auto;
    margin-left: auto;
}

.menu-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 260px;
    background: var(--surface-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow-md);

    /* Animation */
    transform-origin: top right;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    opacity: 1;
    transform: scale(1) translateY(0);

    /* Scroll support */
    max-height: calc(100vh - 80px);
    /* Prevent going off screen */
    overflow-y: auto;
}

.menu-dropdown.hidden {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
    pointer-events: none;
    display: flex;
    /* Keep layout for transition */
    visibility: hidden;
}

/* Sections */
.menu-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-header h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 6px;
    font-weight: 600;
}

.full-width {
    width: 100%;
    justify-content: center;
}

.hidden-empty:empty {
    display: none;
}

/* Explicitly hide if no children in scene list */
#scenes-section.hidden {
    display: none;
}

/* Buttons */
.btn {
    background: var(--surface-glass);
    backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    font-size: 0.9rem;
}

.btn:hover {
    background: var(--surface-hover);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn.primary {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
    color: #60a5fa;
}

.btn.primary:hover {
    background: rgba(59, 130, 246, 0.3);
}

/* Icon Buttons (Circular) */
.btn-icon {
    width: 44px;
    /* Touch target */
    height: 44px;
    border-radius: 50%;
    background: var(--surface-glass);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.25rem;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.2s ease;
    backdrop-filter: blur(var(--blur-amount));
    box-shadow: var(--shadow-md);
}

.btn-icon:hover {
    background: var(--surface-hover);
    transform: scale(1.05);
}

.btn-mini {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
}

.btn-mini:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

/* Panels */
.panel {
    background: var(--surface-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    /* Safari support */
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: var(--border-radius);
    pointer-events: auto;
    box-shadow: var(--shadow-md);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);

    opacity: 1;
    transform: scale(1);
    max-width: 100%;
}

.panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95);
    display: none;
    /* simple hide for layout shifts */
}

/* Panel Header */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.panel h3 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
}

/* Controls Scoped Styles */
#controls-help {
    width: 280px;
}

.panel-content p {
    margin-bottom: 8px;
    line-height: 1.5;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type="range"] {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
    margin: 10px 0;
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 12px 0;
}

/* Scene List Specifics */
#scene-list {
    /* Reset absolute positioning from previous version */
    position: static;
    width: 100%;
    max-height: none;
    display: flex;
    flex-direction: column;
}

#scene-items {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    /* Custom scrollbar later if needed */
}

.scene-item {
    background: rgba(255, 255, 255, 0.03);
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    border: 1px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scene-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.scene-item.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: #93c5fd;
    font-weight: 500;
}

/* Loading Overlay */
#loading-overlay {
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#loading-overlay p {
    margin-top: 16px;
    letter-spacing: 1px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.hidden {
    display: none !important;
}

/* --- Mobile Ops --- */
/* --- Mobile Ops --- */
@media (max-width: 768px) {

    /* Header adjustments */
    header {
        top: 10px;
        left: 10px;
        right: 10px;
        justify-content: space-between;
        /* H1 left, Menu right */
    }

    /* Ensure title doesn't crowd menu */
    h1 {
        font-size: 0.9rem;
        max-width: 60%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Adjust menu width for mobile */
    .menu-dropdown {
        width: 220px;
    }

    /* Button sizing for touch */
    .btn-icon,
    .btn {
        min-height: 48px;
        min-width: 48px;
    }

    .btn {
        min-width: auto;
    }
}