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

:root {
    --controls-width: 280px;
    --mobile-drawer-peek: 88px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #eee;
    overflow: hidden;
    overscroll-behavior: none;
}

.container {
    display: flex;
    position: relative;
    width: 100vw;
    height: 100vh;
    min-width: 0;
    min-height: 0;
    padding-right: var(--controls-width);
    transition: padding-right 0.3s ease;
}

body.controls-collapsed .container {
    padding-right: 0;
}

#canvas {
    flex: 1;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
}

.recording-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 10;
}

#canvas:active {
    cursor: grabbing;
}

.controls {
    position: fixed;
    right: 0;
    top: 0;
    width: var(--controls-width);
    height: 100vh;
    background: rgba(26, 26, 46, 0.98);
    border-left: 1px solid #333;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    z-index: 50;
    transition: transform 0.3s ease;
}

body.controls-collapsed .controls,
.controls.hidden {
    transform: translateX(100%);
}

.drawer-handle {
    display: none;
}

.controls-header {
    flex: 0 0 auto;
    border-bottom: 1px solid #333;
    background: rgba(26, 26, 46, 0.98);
}

.controls-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0 20px 20px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.controls h2 {
    font-size: 1.4em;
    margin: 0;
    color: #7f8fff;
    padding: 20px;
}

.controls h3 {
    font-size: 0.9em;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 15px 0 10px;
}

.controls,
.controls h2,
.controls h3,
.controls label,
.controls span,
.controls p,
.controls button,
.toggle-controls,
.toggle-controls span,
.drawer-handle {
    -webkit-user-select: none;
    user-select: none;
}

.section {
    margin-bottom: 20px;
}

.recenter-section {
    margin-top: 10px;
}

#regenerate-depth-btn {
    margin-bottom: 12px;
}

.upload-group {
    margin-bottom: 10px;
}

.upload-group label {
    display: block;
    font-size: 0.85em;
    margin-bottom: 5px;
    color: #aaa;
}

.upload-group input[type="file"] {
    width: 100%;
    padding: 8px;
    background: #2a2a4e;
    border: 1px solid #444;
    border-radius: 4px;
    color: #eee;
    font-size: 0.85em;
}

.slider-group {
    margin-bottom: 12px;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85em;
    margin-bottom: 4px;
    color: #ccc;
}

.slider-group label span {
    color: #7f8fff;
    font-family: monospace;
}

.slider-group input[type="range"] {
    width: 100%;
    height: 4px;
    background: #333;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #7f8fff;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.slider-group input[type="range"]::-webkit-slider-thumb:hover {
    background: #9faeff;
}

.slider-group input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #7f8fff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.select-group {
    margin-bottom: 12px;
}

.select-group label {
    display: block;
    font-size: 0.85em;
    margin-bottom: 5px;
    color: #aaa;
}

.select-group select {
    width: 100%;
    padding: 8px;
    background: #2a2a4e;
    border: 1px solid #444;
    border-radius: 4px;
    color: #eee;
    font-size: 0.9em;
    cursor: pointer;
}

.select-group select:hover {
    border-color: #7f8fff;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #7f8fff;
}

button {
    background: #7f8fff;
    color: #1a1a2e;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}

button:hover {
    background: #9faeff;
}

.export-duration {
    margin-top: 2px;
    margin-bottom: 8px;
    font-size: 0.82em;
    color: #9aa0bf;
}

.export-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.export-buttons button {
    flex: 1;
}

.btn-secondary {
    background: #2a2a4e;
    color: #7f8fff;
    border: 1px solid #7f8fff;
}

.btn-secondary:hover {
    background: #3a3a5e;
}

.btn-secondary.active {
    background: #7f8fff;
    color: #1a1a2e;
}

.btn-primary {
    background: #7f8fff;
    color: #1a1a2e;
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.82em;
}

.instructions {
    font-size: 0.85em;
    color: #888;
    text-align: center;
    padding: 10px;
    background: #2a2a4e;
    border-radius: 4px;
}

.about {
    font-size: 0.8em;
    color: #9aa0bf;
    text-align: left;
    padding: 10px;
    background: #202441;
    border: 1px solid #323a63;
    border-radius: 4px;
}

.about p + p {
    margin-top: 6px;
}

.about a {
    color: #aeb8ff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.about a:hover {
    color: #c5cdff;
}

.toggle-controls {
    position: fixed;
    top: 10px;
    right: calc(var(--controls-width) + 10px);
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(127, 143, 255, 0.9);
    border-radius: 4px;
    z-index: 100;
    transition: right 0.3s ease;
}

.toggle-controls.shifted,
body.controls-collapsed .toggle-controls {
    right: 10px;
}

.toggle-controls span {
    font-size: 1.2em;
}

.progress-container {
    margin: 10px 0;
    padding: 10px;
    background: #2a2a4e;
    border-radius: 4px;
}

.progress-bar {
    height: 4px;
    background: #7f8fff;
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    display: block;
    margin-top: 8px;
    font-size: 0.85em;
    color: #888;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    pointer-events: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(127, 143, 255, 0.3);
    border-top-color: #7f8fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 16px;
    color: #fff;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#depth-upload-group.disabled {
    opacity: 0.5;
    pointer-events: none;
}

@media (max-width: 768px) {
    body.mobile-layout .container {
        padding-right: 0;
    }

    body.mobile-layout .controls {
        left: 0;
        right: 0;
        top: var(--drawer-top, calc(100dvh - var(--mobile-drawer-peek)));
        bottom: 0;
        width: 100%;
        height: auto;
        max-height: none;
        border-left: none;
        border-top: 1px solid #333;
        border-radius: 16px 16px 0 0;
        padding: 0;
        transform: none;
        transition: top 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
        will-change: top;
        z-index: 120;
    }

    body.mobile-layout .controls.dragging {
        transition: none;
    }

    body.mobile-layout .controls.dragging .controls-header {
        cursor: grabbing;
    }

    body.mobile-layout .controls-header {
        padding: 8px 16px 10px;
        border-bottom: 1px solid #2f3556;
        border-radius: 16px 16px 0 0;
        touch-action: none;
        cursor: grab;
    }

    body.mobile-layout .controls h2 {
        padding: 0;
    }

    body.mobile-layout .controls-scroll {
        padding: 0 16px calc(24px + env(safe-area-inset-bottom));
    }

    body.mobile-layout .drawer-handle {
        display: flex;
        width: 100%;
        height: 26px;
        margin: 0 0 8px;
        align-items: center;
        justify-content: center;
        touch-action: none;
        cursor: grab;
    }

    body.mobile-layout .drawer-handle::before {
        content: '';
        width: 44px;
        height: 5px;
        border-radius: 999px;
        background: rgba(127, 143, 255, 0.9);
    }

    body.mobile-layout .toggle-controls {
        top: auto;
        bottom: calc(12px + env(safe-area-inset-bottom));
        right: 12px;
        width: 44px;
        height: 44px;
        border-radius: 999px;
        z-index: 140;
    }

    body.mobile-layout .toggle-controls.shifted,
    body.mobile-layout.controls-collapsed .toggle-controls {
        right: 12px;
    }
}
