/* Theme variables and default (dark) color scheme */
:root {
    color-scheme: dark light;
    --bg: #000000; /* page background */
    --text: #ffffff; /* primary text for dark */
    --muted: #b8b8b8; /* muted text */
    --accent: #3b82f6; /* accent color */
    --accent-2: #60d5ea; /* accent gradient color */
    --panel-bg: #0b1220; /* panel / card backgrounds */
    --panel-surface: #323b45; /* lighter surface */
    --panel-biggest-surface: #323d45;
    --panel-gradient-start: #0f1724;
    --panel-gradient-end: #0b1220;
    --white: #ffffff;
    --scene-info-bg: rgb(60, 157, 154);
    --metadata-item-bg: rgb(60, 157, 154);
    --close-btn-color: #000000; /* close button color for dark */
    --anno-bg: #000000; /* annotation details background */
}

/* Light theme overrides */
html[data-theme="light"] {
    color-scheme: light dark;
    --bg: #ffffff;
    --text: #000000;
    --muted: #000000;
    --accent: #106bff;
    --accent-2: #004e92;
    --panel-bg: #ffffff;
    --panel-surface: #ffffff;
    --panel-biggest-surface: #ffffff;
    --panel-gradient-start: #e5e7eb;
    --panel-gradient-end: #f3f4f6;
    --white: #ffffff;
    --scene-info-bg: #b5d4cc;
    --metadata-item-bg: rgb(208, 217, 219);
    --close-btn-color: #000000;
    --anno-bg: rgb(96, 186, 188);
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    overflow: hidden;
    background-color: var(--bg);
    color: var(--text);
    /* Prevent pull-to-refresh on mobile browsers */
    overscroll-behavior-y: contain;
    touch-action: pan-x pan-y;
}

/* Loading Indicator */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(28, 80, 96, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.5s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-container {
    text-align: center;
    color: var(--white);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 20px;
    color: rgba(255, 255, 255, 0.9);
}

.loading-progress {
    width: 300px;
    margin: 0 auto;
}

.loading-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 10px;
}

.loading-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

.loading-percentage {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

/* Scene Header */
#scene-header {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
}

#scene-title {
    margin: 0;
    font-size: 24px;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.5px;
    pointer-events: none;
}

/* Scene Selector Button */
#scene-selector-button {
    width: 40px;
    height: 40px;
    background: var(--panel-surface);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

#scene-selector-button:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#scene-selector-button svg {
    width: 20px;
    height: 20px;
    fill: var(--muted);
    transition: fill 0.2s;
}

#scene-selector-button:hover svg {
    fill: #4b5563;
}

/* Scene Selector Modal */
#scene-selector-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

#scene-selector-modal.open {
    display: flex;
}

.modal-content {
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    border-radius: 12px;
    padding: 24px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    color: var(--text);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.modal-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
}

#close-modal {
    background: none;
    border: none;
    font-size: 32px;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

#close-modal:hover {
    color: var(--text);
}

.scene-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

.scene-card {
    background: var(--panel-bg);
    border: 2px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    color: var(--text);
}

.scene-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: rgba(59, 131, 246, 0.515);
}

.scene-card.active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
}

.scene-thumbnail {
    width: 100%;
    aspect-ratio: 1;
    background: var(--panel-surface);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    font-size: 48px;
}

.scene-thumbnail img {
    max-width: 60%;
    max-height: 60%;
    object-fit: contain;
    border-radius: 4px;
}

.scene-card h3 {
    margin: 0 0 4px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.scene-card p {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

/* Home Button */
#home-button {
    position: fixed;
    top: 20px;
    right: 140px;
    width: 50px;
    height: 50px;
    background: var(--panel-surface);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-decoration: none;
}

#home-button:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#home-button svg {
    width: 24px;
    height: 24px;
    fill: var(--muted);
    transition: fill 0.2s;
}

#home-button:hover svg {
    fill: #4b5563;
}

/* Info Button */
#info-button {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: var(--panel-surface);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#info-button:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#info-button svg {
    width: 24px;
    height: 24px;
    fill: var(--muted);
    transition: fill 0.2s;
}

#info-button:hover svg {
    fill: #4b5563;
}

/* Reset Button */
#reset-button {
    width: 40px;
    height: 40px;
    background: var(--panel-surface);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

#reset-button:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#reset-button svg {
    width: 20px;
    height: 20px;
    fill: var(--muted);
    transition: fill 0.2s;
}

#reset-button:hover svg {
    fill: #4b5563;
}

/* Fullscreen Button */
#fullscreen-button {
    position: fixed;
    top: 20px;
    right: 80px;
    width: 50px;
    height: 50px;
    background: var(--panel-surface);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#fullscreen-button:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#fullscreen-button svg {
    width: 24px;
    height: 24px;
    fill: var(--muted);
    transition: fill 0.2s;
}

#fullscreen-button:hover svg {
    fill: #4b5563;
}

/* Bounding Box Toggle Button */
#bbox-toggle-button {
    width: 40px;
    height: 40px;
    background: var(--panel-surface);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

#bbox-toggle-button:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#bbox-toggle-button svg {
    width: 20px;
    height: 20px;
    fill: var(--muted);
    transition: fill 0.2s;
}

#bbox-toggle-button:hover svg {
    fill: #4b5563;
}

/* Info Panel */
#info-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: var(--panel-biggest-surface);
    backdrop-filter: blur(20px);
    box-shadow: -2px 0 20px rgba(0, 0, 0, 0.08);
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    color: var(--text);
    /* Fix mobile scrolling issues */
    overscroll-behavior-y: contain;
}

#info-panel.open {
    right: 0;
}

/* Panel Header */
.panel-header {
    padding: 30px 25px 25px;
    background: var(--scene-info-bg);
    border-bottom: 1px solid rgba(7, 206, 228, 0.06);
    color: #374151;
    flex-shrink: 0;
}

.panel-header h2 {
    margin: 0 0 8px 0;
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
}

.panel-header p {
    margin: 0;
    opacity: 0.7;
    font-size: 13px;
    color: var(--muted);
}

/* Close Button */
#close-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--white);
    border: 3px solid rgba(0, 0, 0, 0.06);
    color: var(--close-btn-color);
    font-size: 20px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: none; /* Hidden by default on desktop */
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}

#close-panel:hover {
    background: rgba(255, 255, 255, 0.9);
    color: #374151;
    transform: rotate(90deg);
}

/* Panel Content */
.panel-content {
    padding: 20px 25px;
    flex: 1;
    overflow-y: auto;
    /* Fix mobile scrolling issues */
    overscroll-behavior-y: contain;
}

.info-section {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.info-section:last-child {
    border-bottom: none;
}

.info-section h3 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: var(--text);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
}

.info-section h3 svg {
    width: 20px;
    height: 20px;
    fill: #bebbb3;
}

.info-row {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 8px;
    font-size: 14px;
    gap: 5px;
}

.info-label {
    color: var(--accent-2);
    font-weight: 500;
}

.info-value {
    color: var(--text);
    font-weight: 400;
    text-align: right;
}

.info-description {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
    margin: 8px 0 0 0;
}

/* Annotation Details Section */
#annotation-details {
    display: none;
    background: var(--anno-bg);
    color: var(--accent-2);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

#annotation-details.visible {
    display: block;
}

#annotation-details h3 {
    margin: 0 0 10px 0;
    color: var(--text);
    font-size: 16px;
}

#annotation-details .info-row {
    color: #4b5563;
}

#annotation-details .info-label {
    color: var(--text);
}

#annotation-details .info-value {
    color: var(--text);
    font-weight: 500;
}

/* Scene Metadata */
.metadata-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.metadata-item {
    background: var(--metadata-item-bg);
    padding: 7px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.metadata-item .label {
    font-size: 11px;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.metadata-item .value {
    font-size: 15px;
    color: var(--text);
    font-weight: 600;
}

/* Objects Grid - Compact horizontal layout */
.objects-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.objects-grid .object-tag {
    background: var(--metadata-item-bg);
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.04);
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
}

/* Scrollbar Styling */
.panel-content::-webkit-scrollbar {
    width: 6px;
}

.panel-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.02);
}

.panel-content::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.4);
    border-radius: 3px;
}

.panel-content::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.6);
}

.info-value-mobile {
    display: none;
    color: var(--text);
}

/* Alternative: Show both on all devices with different styling */
@media (hover: none) and (pointer: coarse) {
    /* Touch device detected */
    .info-value-mobile {
        display: inline;
        margin-left: 10px;
    }
    
    /* Only hide desktop values when there's a mobile alternative */
    .info-row:has(.info-value-mobile) .info-value:not(.info-value-mobile) {
        display: none;
    }
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    /* Show close button on mobile */
    #close-panel {
        display: flex;
    }
    /* Make info panel full width on mobile */
    #info-panel {
        width: 100%;
        right: -100%;
    }
    
    /* Hide entire scene header when info panel is open to prevent overlap */
    body:has(#info-panel.open) #scene-header {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    
    /* Move reset and bbox toggle buttons to bottom right on mobile */
    #reset-button,
    #bbox-toggle-button {
        position: fixed;
        z-index: 1000;
    }
    
    #reset-button {
        bottom: 80px;
        right: 15px;
        top: auto;
        left: auto;
    }
    
    #bbox-toggle-button {
        bottom: 20px;
        right: 15px;
        top: auto;
        left: auto;
    }
    
    /* Hide reset and bbox toggle buttons when info panel is open */
    body:has(#info-panel.open) #reset-button,
    body:has(#info-panel.open) #bbox-toggle-button {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .info-value-mobile {
        display: inline;
    }
    
    /* Only hide desktop values when there's a mobile alternative */
    .info-row:has(.info-value-mobile) .info-value:not(.info-value-mobile) {
        display: none;
    }
    
    /* Disable rotation on close button for mobile */
    #close-panel:hover {
        transform: none;
    }
    
    /* Adjust button positions on mobile */
    #info-button {
        top: 15px;
        right: 15px;
        width: 44px;
        height: 44px;
    }
    
    #fullscreen-button {
        top: 15px;
        right: 70px;
        width: 44px;
        height: 44px;
    }
    
    #home-button {
        top: 15px;
        right: 125px;
        width: 44px;
        height: 44px;
    }
    
    /* Button sizing for mobile - reset and bbox are now positioned separately */
    #reset-button,
    #bbox-toggle-button {
        width: 50px;
        height: 50px;
    }
    
    #scene-header {
        top: 15px;
        left: 15px;
    }
    
    #scene-title {
        font-size: 20px;
    }
    
    #scene-selector-button {
        width: 36px;
        height: 36px;
    }
    
    /* Adjust modal for mobile */
    .modal-content {
        width: 95%;
        padding: 20px;
    }
    
    .scene-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    /* Stack title below buttons on very small screens when panel is open */
    #info-panel.open {
        z-index: 1001;
    }
    
    /* Alternative: Move scene header down when panel is open */
    body:has(#info-panel.open) #scene-header {
        top: 75px;
        transition: top 0.4s ease;
    }
    
    /* Adjust loading indicator for mobile */
    .loading-progress {
        width: 250px;
    }
    
    .loading-text {
        font-size: 16px;
    }
}
