:root {
    --primary: #1b4f9c;
    --primary-light: #2f6fca;
    --secondary: #3f83f8;
    --dark: #0f172a;
    --dark-light: #eaf1fb;
    --light: #f4f8ff;
    --text-muted: #4d6283;
    --border: #bfd2ee;
    --surface: #ffffff;
    --surface-soft: #edf4ff;
    --shadow: 0 14px 36px rgba(15, 23, 42, 0.14);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(180deg, #f6f9ff 0%, #eef4ff 100%);
    color: var(--dark);
    line-height: 1.6;
    overflow-x: hidden;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Navigation */
#navbar {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    background: linear-gradient(90deg, #0a2d57 0%, #133c73 100%);
    border-bottom: 1px solid #1f4f90;
    height: 70px;
    display: flex;
    align-items: center;
    box-shadow: 0 8px 22px rgba(10, 45, 87, 0.28);
}

#navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

#navbar .container > span {
    color: #dbe9ff;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: #f5f9ff;
    text-decoration: none;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.logo:hover {
    color: #ffffff;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-links a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    color: #dbe9ff;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-icon {
    width: 0.95rem;
    height: 0.95rem;
    flex-shrink: 0;
}

.nav-links a:hover {
    color: #ffffff;
}

/* Demo Layout */
.demo-container {
    padding-top: 120px;
    padding-bottom: 60px;
    min-height: calc(100vh - 70px - 100px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.demo-title {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    text-align: center;
    color: var(--dark);
}

.demo-subtitle {
    text-align: center;
    color: #334a6b;
    margin-bottom: 2.5rem;
    font-size: 1rem;
    max-width: 58ch;
}

/* Upload Section */
#upload-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Upload Zone */
.upload-zone {
    width: 100%;
    max-width: 600px;
    height: 280px;
    border: 2px solid #a7c2e8;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    background: linear-gradient(180deg, #ffffff 0%, #f5f9ff 100%);
    box-shadow: var(--shadow);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary-light);
    background: linear-gradient(180deg, #f7fbff 0%, #eaf2ff 100%);
    box-shadow: 0 16px 28px rgba(27, 79, 156, 0.20);
}

.upload-content {
    text-align: center;
    pointer-events: none;
}

.upload-icon {
    color: #8aa0c2;
    margin-bottom: 1.5rem;
    transition: color 0.2s;
}

.upload-zone:hover .upload-icon,
.upload-zone.dragover .upload-icon {
    color: var(--primary);
}

.upload-content p {
    font-size: 1.05rem;
    margin-bottom: 0.4rem;
    color: var(--dark);
}

.upload-content strong {
    color: var(--primary);
}

.upload-content span {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Loading Spinner */
.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.spinner {
    width: 52px;
    height: 52px;
    border: 3px solid var(--border);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.status-msg {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.progress-bar-container {
    width: 80%;
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    margin-top: 1rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary-light);
    width: 0%;
    transition: width 0.2s ease;
}

.progress-text {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.4rem;
}

.error-msg {
    width: 100%;
    max-width: 600px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    border-radius: 8px;
    padding: 0.8rem 1.2rem;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.download-progress-container {
    width: 100%;
    max-width: 100%;
    margin: 0 0 1rem 0;
    padding: 0.75rem 1rem;
    background: #f7fbff;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.download-progress-container.hidden {
    display: none;
}

/* Result Section */
.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    width: 100%;
}

.result-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.download-size-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.btn {
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

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

.btn:hover:not(:disabled) {
    opacity: 0.85;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-light);
}

.btn-secondary {
    background: #f0f6ff;
    color: #17365e;
    border-color: #9ebbe3;
}

/* Visibility Helpers */
.hidden {
    display: none !important;
}

.active {
    display: block;
}

/* Re-using and adjusting existing styles */
.section { padding: 4rem 0; }
.shadow { box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12); }

.demo-viewport {
    width: 100vw;
    max-width: 1000px;
    height: 600px;
    position: relative;
    background: var(--surface);
    border: 1px solid #b6cceb;
    border-radius: 10px;
    overflow: hidden;
}

.viewer-overlay {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 120;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.viewer-close-btn {
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 2px solid #000000;
    background: rgba(245, 250, 255, 0.95);
    color: #17365e;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.viewer-overlay #overlay-download-btn {
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 2px solid #000000;
    background: rgba(245, 250, 255, 0.95);
    color: #17365e;
}

.overlay-btn-icon {
    width: 0.85rem;
    height: 0.85rem;
    flex-shrink: 0;
}

.viewer-overlay .btn,
.viewer-close-btn {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

.viewer-close-btn:hover {
    background: #ffffff;
}

.viewer-overlay #overlay-download-btn:hover {
    background: #ffffff;
    opacity: 1;
}

.viewer-overlay-btn {
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 2px solid #000000;
    background: rgba(245, 250, 255, 0.95);
    color: #17365e;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    transition: background 0.2s;
}

.viewer-overlay-btn:hover {
    background: #ffffff;
}

.viewer-overlay-btn.active {
    background: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 1px 4px rgba(27, 79, 156, 0.4);
}

#demo-canvas-container {
    width: 100%;
    height: 100%;
}

.demo-ui {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
}

.legend {
    background: rgba(0,0,0,0.55);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.color {
    width: 12px;
    height: 12px;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;

.chair { background: #ff595e; }
.table { background: #8ac926; }
.floor { background: #1982c4; }
.wall { background: #6a4c93; }

    z-index: 300;
    color: var(--text-muted);
    font-size: 0.8rem;
    background: rgba(0,0,0,0.6);
    padding: 0.35rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(23, 54, 94, 0.2);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.22);
    pointer-events: auto;
    padding: 0.5rem 1rem;
    border-radius: 20px;
}

/* Results */
.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.comparison-item h3 {
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--secondary);
}

.image-pair {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.comparison-item .label {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* BibTeX */
.bibtex-container {
    background: #f4f8ff;
    padding: 1rem;
    border-radius: 12px;
    position: relative;
    border: 1px solid var(--border);
}

#bibtex-code {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.8rem;
    color: #355173;
    overflow-x: auto;
}

.copy-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

.btn-small {
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
}

/* Footer */
.footer {
    padding: 3rem 0;
    text-align: center;
    background: #edf4ff;
    border-top: 1px solid rgba(16, 42, 76, 0.2);
    color: var(--text-muted);
}

.footer .bibtex-container {
    max-width: 900px;
    margin: 1rem auto 0;
    text-align: left;
}

/* Fullscreen viewer mode: keep only top navbar visible */
body.result-mode .demo-container.container {
    max-width: none;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
    padding-top: 70px;
    padding-bottom: 0;
    min-height: 100dvh;
    justify-content: flex-start;
}

body.result-mode #result-section.active {
    width: 100%;
}

body.result-mode .result-header,
body.result-mode .download-progress-container,
body.result-mode .footer {
    display: none !important;
}

body.result-mode .demo-viewport {
    width: 100vw;
    max-width: none;
    height: calc(100dvh - 70px);
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
}

/* Hamburger menu hidden on larger screens (default) */
.hamburger-menu {
    display: none;
}

.mobile-menu {
    display: none;
}

@media (max-width: 768px) {
    .title { font-size: 2.5rem; }
    .comparison-grid { grid-template-columns: 1fr; }
    #navbar .container { padding: 0 1rem; }
    #navbar .container > span { display: none; }
    .logo { font-size: 1.25rem; }
    .nav-links { display: none; }
    .result-header { flex-direction: column; gap: 1rem; align-items: flex-start; }
    
    /* Hamburger menu button - visible on small screens */
    .hamburger-menu {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        background: none;
        border: none;
        cursor: pointer;
        padding: 0.5rem;
        align-items: center;
        justify-content: center;
    }
    
    .hamburger-menu span {
        display: block;
        width: 1.5rem;
        height: 2px;
        background: #dbe9ff;
        border-radius: 1px;
        transition: all 0.3s ease;
    }
    
    .hamburger-menu.active span:nth-child(1) {
        transform: rotate(45deg) translateY(10px);
    }
    
    .hamburger-menu.active span:nth-child(2) {
        opacity: 0;
    }
    
    .hamburger-menu.active span:nth-child(3) {
        transform: rotate(-45deg) translateY(-10px);
    }
    
    /* Mobile menu - dropdown */
    .mobile-menu {
        display: flex;
        position: absolute;
        top: 70px;
        right: 0;
        left: 0;
        background: linear-gradient(90deg, #0a2d57 0%, #133c73 100%);
        border-bottom: 1px solid #1f4f90;
        flex-direction: column;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        z-index: 999;
    }
    
    .mobile-menu.active {
        max-height: 200px;
    }
    
    .mobile-menu a {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        padding: 1rem 1.5rem;
        text-decoration: none;
        color: #dbe9ff;
        font-weight: 500;
        border-bottom: 1px solid rgba(31, 79, 144, 0.5);
        transition: background 0.2s;
    }
    
    .mobile-menu a:last-child {
        border-bottom: none;
    }
    
    .mobile-menu a:hover {
        background: rgba(255, 255, 255, 0.1);
        color: #ffffff;
    }
}
