/* CSS Variables */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a26;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-glass: rgba(255, 255, 255, 0.05);

    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;

    --accent-primary: #7c3aed;
    --accent-secondary: #a855f7;
    --accent-gradient: linear-gradient(135deg, #7c3aed 0%, #a855f7 50%, #ec4899 100%);

    --success: #22c55e;
    --warning: #eab308;
    --error: #ef4444;

    --border-color: rgba(255, 255, 255, 0.08);
    --shadow-glow: 0 0 60px -15px rgba(124, 58, 237, 0.5);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* Reset & Base */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Background Animation */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(124, 58, 237, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(236, 72, 153, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(168, 85, 247, 0.08) 0%, transparent 60%);
    pointer-events: none;
    z-index: -1;
}

/* App Container */
/* App Layout - Fit to Screen */
body {
    overflow: hidden;
    /* Disable body scroll */
}

.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1rem 2rem;
    overflow: hidden;
}

.header {
    flex-shrink: 0;
    /* Header doesn't shrink */
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.section {
    margin-bottom: 0;
}

.editor-section {
    flex: 1;
    /* Takes remaining height */
    min-height: 0;
    /* Critical for scrolling inside flex */
    width: 100%;
}

.editor-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    height: 100%;
}

/* Video Side */
.video-container {
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    height: 100%;
    /* Fill the grid height */
    display: flex;
    align-items: center;
    /* Vertical Center */
    justify-content: center;
    /* Horizontal Center */
}

.video-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    /* Allow width to shrink */
    height: auto;
    /* Allow height to shrink */
    object-fit: contain;
}

#caption-overlay {
    /* Overlay must match video size ideally, but for now absolute is okay */
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 5px solid red;
    /* DEBUG FRAME */
    z-index: 999;
}

/* Controls Side */
.style-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    height: 100%;
    overflow-y: auto;
}

/* Mobile responsive */
@media (max-width: 1000px) {
    body {
        overflow: auto;
    }

    .app-container {
        height: auto;
        overflow: visible;
    }

    .editor-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .video-container {
        height: 60vh;
    }
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.logo-icon {
    font-size: 2.5rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

.logo-text {
    font-size: 2.5rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 400;
}

/* Sections */
.section {
    margin-bottom: 3rem;
}

/* Upload Section */
.upload-section {
    max-width: 600px;
    margin: 0 auto;
}

.upload-zone {
    background: var(--bg-card);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-xl);
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.upload-zone:hover {
    border-color: var(--accent-primary);
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
}

.upload-zone:hover::before {
    opacity: 0.05;
}

.upload-zone.dragover {
    border-color: var(--accent-secondary);
    background: rgba(124, 58, 237, 0.1);
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    position: relative;
    z-index: 1;
}

.upload-zone h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    position: relative;
    z-index: 1;
}

.upload-zone p {
    color: var(--text-secondary);
    position: relative;
    z-index: 1;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted) !important;
    margin-top: 1rem;
}

/* Progress */
.upload-progress {
    margin-top: 2rem;
    text-align: center;
}

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    width: 0%;
    transition: width var(--transition-fast);
    border-radius: 4px;
}

.progress-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Editor Section */
.editor-section {
    max-width: 100%;
}

.editor-layout {
    display: grid;
    grid-template-columns: 1fr 350px;
    /* Fixed width for controls */
    gap: 20px;
    align-items: start;
    height: calc(100vh - 120px);
    /* Fit within viewport */
    overflow: hidden;
    /* Prevent scrolling main page */
}

@media (max-width: 1024px) {
    .editor-layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }
}

/* Duplicates removed - using top definitions */

.video-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

.time-display {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

/* Control Groups */
.control-group {
    margin-bottom: 1.25rem;
}

.control-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* Inputs */
.select-input,
.text-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all var(--transition-fast);
    cursor: pointer;
}

.select-input:hover,
.text-input:hover {
    border-color: var(--accent-primary);
}

.select-input:focus,
.text-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

/* Range Input */
.range-input {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    -webkit-appearance: none;
    cursor: pointer;
}

.range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: grab;
    transition: transform var(--transition-fast);
}

.range-input::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.range-input.small {
    width: 80px;
}

.range-value {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

/* Color Picker */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-input {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    overflow: hidden;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.color-value {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: 'SF Mono', Monaco, monospace;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px -5px rgba(124, 58, 237, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-glass);
    border-color: var(--accent-primary);
}

.btn-success {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px -5px rgba(34, 197, 94, 0.4);
}

.btn-full {
    width: 100%;
    margin-top: 1rem;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

/* Download Section */
.download-section {
    max-width: 500px;
    margin: 0 auto;
}

.download-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    padding: 3rem;
    text-align: center;
}

.success-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    animation: celebrate 0.6s ease;
}

@keyframes celebrate {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.download-content h2 {
    font-size: 1.75rem;
    margin-bottom: 2rem;
}

.download-content .btn {
    margin: 0.5rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Utility */
[hidden] {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        padding: 1rem;
    }

    .header {
        margin-bottom: 2rem;
    }

    .logo-text {
        font-size: 2rem;
    }

    .upload-zone {
        padding: 3rem 1.5rem;
    }

    .style-panel {
        position: static;
        max-height: none;
    }
}