/* === Reset & Base === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3498db;
    --primary-dark: #2980b9;
    --secondary: #2c3e50;
    --bg-dark: #1a1a2e;
    --bg-panel: #16213e;
    --text: #ecf0f1;
    --text-muted: #95a5a6;
    --success: #27ae60;
    --border: #34495e;
    --panel-height: 45vh;
    --fab-size: 56px;

    /* Transparent UI - no blur, high transparency */
    --glass-bg: rgba(22, 33, 62, 0.35);
    --glass-bg-light: rgba(44, 62, 80, 0.25);
    --glass-border: rgba(255, 255, 255, 0.15);
    --text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8), 0 0 8px rgba(0, 0, 0, 0.5);
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    touch-action: none;
}

/* === Viewer Container === */
#viewer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #0f0f23 100%);
}

#three-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* === Loading Overlay === */
#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text);
    font-size: 18px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* === Drop Zone === */
#drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(52, 152, 219, 0.2);
    border: 4px dashed var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-size: 24px;
}

.drop-icon {
    font-size: 64px;
    font-weight: 300;
}

/* === FAB Buttons === */
.fab {
    position: fixed;
    width: var(--fab-size);
    height: var(--fab-size);
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: rgba(52, 152, 219, 0.4);
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 200;
    transition: transform 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: var(--text-shadow);
}

.fab:hover {
    background: rgba(52, 152, 219, 0.6);
}

.fab:active {
    transform: scale(0.95);
}

#toggle-panel {
    bottom: calc(var(--panel-height) + 16px);
    right: 16px;
}

#toggle-panel.panel-open {
    bottom: calc(var(--panel-height) + 16px);
}

#toggle-panel.panel-closed {
    bottom: 16px;
}

.fab-secondary {
    background: rgba(44, 62, 80, 0.4);
}

.fab-secondary:hover {
    background: rgba(44, 62, 80, 0.6);
}

#fullscreen-btn {
    top: 16px;
    right: 16px;
}

.fab-icon {
    font-family: monospace;
    font-weight: bold;
}

/* === Control Panel === */
.panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--panel-height);
    background: var(--glass-bg);
    border-radius: 24px 24px 0 0;
    border-top: 1px solid var(--glass-border);
    box-shadow: 0 -2px 15px rgba(0,0,0,0.2);
    z-index: 150;
    transition: transform 0.3s ease-out;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel.hidden {
    transform: translateY(100%);
}

.panel-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto;
    cursor: grab;
}

/* === Tabs === */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--glass-border);
    padding: 0 16px;
    background: rgba(0, 0, 0, 0.1);
}

.tab {
    flex: 1;
    padding: 14px 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
    text-shadow: var(--text-shadow);
}

.tab:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(52, 152, 219, 0.1);
}

/* === Tab Content === */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-content.active {
    display: block;
}

/* === Gallery Grid === */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.gallery-item {
    background: var(--glass-bg-light);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, border-color 0.2s;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-shadow: var(--text-shadow);
}

.gallery-item:active {
    transform: scale(0.97);
}

.gallery-item:hover {
    background: rgba(52, 152, 219, 0.3);
    border-color: rgba(52, 152, 219, 0.5);
}

.gallery-item .icon {
    font-size: 32px;
}

.gallery-item .name {
    font-size: 14px;
    word-break: break-word;
}

/* === Upload Area === */
.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 24px;
}

.upload-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 32px 48px;
    background: var(--glass-bg-light);
    border: 2px dashed rgba(255, 255, 255, 0.25);
    border-radius: 16px;
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    width: 100%;
    max-width: 300px;
    text-shadow: var(--text-shadow);
}

.upload-btn:hover {
    border-color: var(--primary);
    background: rgba(52, 152, 219, 0.2);
}

.upload-btn:active {
    background: rgba(52, 152, 219, 0.3);
}

.upload-icon {
    font-size: 48px;
    font-weight: 300;
    color: var(--primary);
}

.upload-hint {
    color: var(--text-muted);
    font-size: 14px;
}

/* === Additional Files (MTL, Textures) === */
.additional-files {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 300px;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-row .file-name {
    font-size: 12px;
    color: var(--success);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}

.btn-small {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 36px;
}

/* === Orientation Controls === */
.orientation-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}

.control-label {
    font-size: 13px;
    color: var(--text-muted);
}

.orientation-controls .btn-small {
    padding: 6px 10px;
    min-height: 32px;
    min-width: 36px;
}

.btn-accent {
    background: var(--primary);
    color: white;
}

.btn-accent:hover {
    background: var(--primary-dark);
}

/* === Slice Controls === */
.slice-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.slice-group {
    background: var(--glass-bg-light);
    border: 1px solid var(--glass-border);
    padding: 16px;
    border-radius: 12px;
}

.slice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.slice-header label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    cursor: pointer;
}

.slice-header input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

.flip-btn {
    background: rgba(52, 73, 94, 0.35);
    border: 1px solid var(--glass-border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.2s;
    text-shadow: var(--text-shadow);
}

.flip-btn:hover {
    background: rgba(52, 152, 219, 0.5);
}

/* === Slider === */
.slider {
    width: 100%;
    height: 44px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(52, 73, 94, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.slider:disabled {
    opacity: 0.4;
}

/* === Buttons === */
.btn {
    padding: 14px 24px;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, border-color 0.2s;
    min-height: 48px;
    text-shadow: var(--text-shadow);
}

.btn:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: rgba(44, 62, 80, 0.35);
    color: var(--text);
}

.btn-secondary:hover {
    background: rgba(52, 152, 219, 0.4);
    border-color: rgba(52, 152, 219, 0.5);
}

/* === View Controls === */
.view-controls {
    padding: 16px;
    border-top: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 12px;
}

.view-controls .btn {
    flex: 1;
}

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

.info-text {
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
}

/* === Desktop Styles === */
@media (min-width: 768px) {
    :root {
        --panel-height: 35vh;
    }

    .panel {
        width: 400px;
        right: 0;
        left: auto;
        border-radius: 24px 0 0 0;
    }

    #toggle-panel {
        right: 416px;
    }

    #toggle-panel.panel-closed {
        right: 16px;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* === Landscape Mode (Mobile) === */
@media (max-width: 900px) and (orientation: landscape) {
    body {
        display: flex;
        flex-direction: row;
    }

    #viewer-container {
        width: 60%;
        height: 100vh;
        position: relative;
    }

    .panel {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        left: auto;
        width: 40%;
        height: 100vh;
        border-radius: 0;
        transform: none !important;
        display: flex;
        flex-direction: column;
    }

    .panel.hidden {
        transform: translateX(100%) !important;
    }

    .panel-handle {
        display: none;
    }

    #toggle-panel {
        position: fixed;
        bottom: auto;
        top: 50%;
        right: calc(40% + 8px);
        transform: translateY(-50%);
        z-index: 300;
    }

    #toggle-panel.panel-open {
        right: calc(40% + 8px);
        bottom: auto;
    }

    #toggle-panel.panel-closed {
        right: 8px;
    }

    #fullscreen-btn {
        top: 8px;
        right: calc(40% + 8px);
    }

    .viewcube-wrapper {
        top: 8px;
        left: 8px;
        gap: 4px;
    }

    .viewcube-container {
        padding: 4px;
    }

    .viewcube-face {
        width: 50px;
        height: 24px;
        font-size: 9px;
    }

    .lighting-control {
        top: 115px;
        left: 8px;
        width: 100px;
        padding: 8px;
    }

    .sun-dial {
        width: 76px;
        height: 76px;
    }

    .sun-indicator {
        width: 16px;
        height: 16px;
    }

    .tabs {
        padding: 0 8px;
    }

    .tab {
        padding: 10px 6px;
        font-size: 14px;
    }

    .tab-content {
        padding: 12px;
        flex: 1;
        overflow-y: auto;
    }

    .slice-group {
        padding: 12px;
    }

    .slice-header label {
        font-size: 14px;
    }

    .view-controls {
        padding: 12px;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .gallery-item {
        padding: 12px;
        min-height: 70px;
    }

    /* Landscape indicator */
    body::after {
        content: '';
        display: none;
    }
}

/* === ViewCube === */
.viewcube-wrapper {
    position: fixed;
    top: 16px;
    left: 16px;
    display: flex;
    gap: 8px;
    z-index: 100;
}

.viewcube-container {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 6px;
}

.viewcube {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.viewcube-face {
    width: 60px;
    height: 28px;
    background: rgba(44, 62, 80, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.1s;
    user-select: none;
    text-shadow: var(--text-shadow);
}

.viewcube-face:hover {
    background: rgba(52, 152, 219, 0.5);
    border-color: rgba(52, 152, 219, 0.5);
}

.viewcube-face:active {
    transform: scale(0.95);
}

/* === Lighting Control === */
.lighting-control {
    position: fixed;
    top: 125px;
    left: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px;
    z-index: 100;
    width: 120px;
}

.lighting-control h4 {
    font-size: 11px;
    margin-bottom: 10px;
    color: var(--text-muted);
    text-align: center;
    text-shadow: var(--text-shadow);
}

.sun-dial {
    position: relative;
    width: 96px;
    height: 96px;
    margin: 0 auto;
    border-radius: 50%;
    background: linear-gradient(to bottom, rgba(26, 26, 46, 0.7) 0%, rgba(44, 62, 80, 0.7) 50%, rgba(26, 26, 46, 0.7) 100%);
    border: 1px solid var(--glass-border);
    cursor: pointer;
}

.sun-dial::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border);
}

.sun-indicator {
    position: absolute;
    width: 20px;
    height: 20px;
    background: #f39c12;
    border-radius: 50%;
    box-shadow: 0 0 10px #f39c12;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: left 0.1s, top 0.1s;
}

.time-display {
    text-align: center;
    font-size: 12px;
    margin-top: 8px;
    color: var(--text);
}

.intensity-slider {
    margin-top: 10px;
}

.intensity-slider label {
    font-size: 10px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

.intensity-slider input {
    width: 100%;
    height: 24px;
}
