/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3b82f6;
    --background: #0a0a0a;
    --surface: #151515;
    --surface-light: #1f1f1f;
    --text: #e5e5e5;
    --text-secondary: #888;
    --border: #2a2a2a;
    --accent: #60a5fa;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    font-size: 14px;
}

/* Header */
header {
    background: var(--surface);
    padding: 1.5rem 2rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text);
    font-weight: 600;
}

header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Sections */
.section {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.hidden {
    display: none !important;
}

/* Upload Section */
.upload-container {
    max-width: 600px;
    margin: 0 auto;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease;
    background: var(--surface);
}

.drop-zone:hover {
    border-color: var(--primary);
}

.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--surface-light);
}

.drop-zone svg {
    color: var(--primary);
    margin-bottom: 1rem;
}

.drop-zone p {
    margin: 0.5rem 0;
}

/* Context Section */
.context-section {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.context-grid {
    display: grid;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group select,
.form-group textarea {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.15s ease;
}

.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group select {
    cursor: pointer;
}

/* Context Section */
.context-section {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.context-grid {
    display: grid;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group select,
.form-group textarea {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.15s ease;
}

form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Grey out disabled options in dropdown */
.form-group select option[disabled] {
    color: var(--text-secondary);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group select {
    cursor: pointer;
}

/* Demo Videos Section */
.demo-section {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.demo-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.demo-header h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.demo-videos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.demo-video-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.demo-video-card:hover {
    border-color: var(--primary);
}

.demo-video-thumbnail {
    width: 100%;
    height: 140px;
    background: linear-gradient(135deg, var(--surface-light), var(--primary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    position: relative;
}

.demo-video-thumbnail::after {
    content: '▶';
    position: absolute;
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.demo-video-info {
    padding: 1rem;
}

.demo-video-info h4 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.demo-video-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.drop-zone .small {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.file-info {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: 8px;
    text-align: center;
    overflow: visible;
}

.file-info p {
    margin-bottom: 1rem;
    word-break: break-word;
}

.file-info .btn {
    margin: 0.5rem;
    min-width: 120px;
}

/* Processing Section */
.processing-container {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 30px;
    background: var(--surface);
    border-radius: 15px;
    overflow: hidden;
    margin: 2rem 0 1rem;
    border: 2px solid var(--border);
}

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

#progress-message {
    color: var(--text-secondary);
    margin-top: 1rem;
}

#progress-percent {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
    margin-top: 0.5rem;
}

/* Results Section */
.results-container {
    width: 100%;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.results-actions {
    display: flex;
    gap: 1rem;
}

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: minmax(680px, 2fr) minmax(360px, 1fr);
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 1200px) {
    .main-content { grid-template-columns: 1fr; }
}

/* Panel Styles */
.viewer-panel {
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    padding: 0;
}

.analysis-panel {
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 600px;
}

.panel-header {
    background: var(--surface-light);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* 3D Canvas */
#canvas-container {
    position: relative;
    width: 100%;
    height: clamp(420px, 56vw, 720px);
    background: var(--background);
    overflow: hidden;
}

#canvas3d, canvas.glcanvas {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    z-index: 0 !important;
}

#overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 1;
}

#overlay-container.hidden {
    display: none;
    z-index: -1;
}

/* Overlay controls on canvas */
.overlay-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 5;
}
.ov-group {
    display: flex;
    gap: 6px;
}
.ov-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ov-btn:hover:not(:disabled) { background: rgba(0,0,0,0.65); border-color: rgba(255,255,255,0.3); }
.ov-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.overlay-stats {
    position: absolute;
    top: 8px;
    left: 8px;
    display: none;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 12px;
    color: #e5e5e5;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.12);
    z-index: 5;
}

.overlay-timeline {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    display: none;
    gap: 10px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.12);
    z-index: 5;
}
#canvas-container[data-overlay="on"] .overlay-stats { display: flex; }
#canvas-container[data-overlay="on"] .overlay-timeline { display: flex; }
.overlay-timeline input[type="range"] { flex: 1; }
.overlay-timeline .speed { display: flex; gap: 6px; align-items: center; }

/* Old controls (hidden) */
.controls { display: none !important; }
.controls-secondary { display: none !important; }

.controls input[type="range"] {
    flex: 1;
    min-width: 100px;
    accent-color: var(--primary);
    cursor: pointer;
}

#timeline {
    flex: 2;
}

/* Info Panel (no longer displayed; kept for reference) */
.info-panel {
    display: none;
}

/* Analysis Content */
.analysis-content {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.analysis-content .placeholder {
    text-align: center;
    color: var(--text-secondary);
    padding: 3rem 1rem;
}

/* Markdown styling in analysis */
.analysis-content h1,
.analysis-content h2,
.analysis-content h3 {
    color: var(--primary);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.analysis-content h1 {
    font-size: 1.8rem;
}

.analysis-content h2 {
    font-size: 1.4rem;
}

.analysis-content h3 {
    font-size: 1.2rem;
}

.analysis-content p {
    margin-bottom: 1rem;
}

.analysis-content ul,
.analysis-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.analysis-content li {
    margin-bottom: 0.5rem;
}

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

.analysis-content code {
    background: var(--surface-light);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: opacity 0.15s ease;
}

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

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
}

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

.btn-icon {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: border-color 0.15s ease;
}

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

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--surface);
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    border: 1px solid var(--border);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
}

.close-btn:hover {
    color: var(--primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body label {
    display: block;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--surface-light);
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.modal-body label:hover {
    border-color: var(--primary);
}

.modal-body input[type="radio"] {
    margin-right: 0.5rem;
    accent-color: var(--primary);
}

.api-key-input {
    width: 100%;
    padding: 0.75rem;
    background: var(--surface-light);
    border: 2px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
    margin: 1rem 0;
}

.api-key-input:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.modal-actions .btn {
    flex: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Loading spinner */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    .section {
        padding: 1rem;
    }
    
    .upload-container {
        max-width: 100%;
    }
    
    .file-info {
        padding: 1rem;
    }
    
    .file-info .btn {
        display: block;
        width: 100%;
        margin: 0.5rem 0;
    }
    
    .demo-videos-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .results-actions {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .results-actions .btn {
        width: 100%;
        margin: 0;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .viewer-panel {
        width: 100%;
    }
    
    .analysis-panel {
        width: 100%;
        min-height: 400px;
    }
    
    #canvas-container {
        height: 350px;
    }
    .overlay-controls { top: 6px; right: 6px; }
    .ov-btn { width: 32px; height: 32px; font-size: 14px; }
    .overlay-stats { top: 6px; left: 6px; font-size: 11px; }
    .overlay-timeline { left: 6px; right: 6px; bottom: 6px; }
}
