/* ============================================================================
   VIDEO GENERATOR PRO - Professional Light Theme
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --success: #10b981;
    --success-light: #34d399;
    --warning: #f59e0b;
    --error: #ef4444;
    --gold: #FECE22;

    --bg: #f8fafc;
    --bg-white: #ffffff;
    --bg-hover: #f1f5f9;

    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --border: #e2e8f0;
    --border-focus: #2563eb;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================================================
   LAYOUT
   ============================================================================ */

.app {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2rem;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.pro-badge {
    background: linear-gradient(135deg, var(--gold), #e5b800);
    color: #000;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 0.25rem;
}

/* ============================================================================
   SECTIONS
   ============================================================================ */

.section {
    background: var(--bg-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: var(--transition);
}

.section:hover {
    box-shadow: var(--shadow-lg);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.section-header:hover {
    background: var(--bg-hover);
}

.step-number {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.upload-area {
    min-height: 300px;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    transition: all 0.2s;
    position: relative;
    /* Removed cursor pointer and dashed border as requested */
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1;
}

.section-toggle {
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.section.collapsed .section-content {
    display: none;
}

.section.collapsed .section-toggle {
    transform: rotate(-90deg);
}

.section-content {
    padding: 0 1.5rem 1.5rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   FORMS
   ============================================================================ */

.form-group {
    margin-bottom: 1.25rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.input,
.input-large,
.select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text);
    transition: var(--transition);
}

.input-large {
    padding: 1rem 1.25rem;
    font-size: 1.1rem;
}

.input:focus,
.input-large:focus,
.select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.gold-border {
    border-color: var(--gold);
}

.gold-border:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(254, 206, 34, 0.2);
}

.select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

.logo-inputs {
    display: flex;
    gap: 0.75rem;
}

.logo-inputs .input {
    flex: 1;
}

/* Toggle Group */
.toggle-group {
    display: flex;
    gap: 0.5rem;
}

.toggle-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.toggle-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.toggle-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-full {
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

.btn-icon-only {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

/* ============================================================================
   TEXT BLOCK (for each varTEXT)
   ============================================================================ */

.text-block {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    transition: var(--transition);
}

.text-block:hover {
    border-color: var(--primary);
}

.text-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.text-block-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
}

.text-block-actions {
    display: flex;
    gap: 0.5rem;
}

.text-block textarea {
    min-height: 80px;
    resize: vertical;
}

.text-block-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.char-count.over {
    color: var(--error);
    font-weight: 600;
}

.char-count.warning {
    color: var(--warning);
    /* Orange */
    font-weight: 600;
}

.audio-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.audio-status.ready {
    color: var(--success);
}

.audio-status.pending {
    color: var(--text-muted);
}

audio {
    height: 32px;
    border-radius: 16px;
}

/* ============================================================================
   SECTION CARD (for each content section)
   ============================================================================ */

.content-section {
    background: var(--bg-white);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.content-section-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.section-number-badge {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
}

.content-section-body {
    padding: 1.25rem;
}

/* ============================================================================
   UPLOAD AREA
   ============================================================================ */

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.02);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

#imagePreview {
    /* Enforce strict aspect ratio matching the canvas */
    aspect-ratio: 749 / 1118;
    max-height: 600px;
    /* Allow it to be taller */
    width: auto;
    max-width: 100%;

    /* Remove rounded corners to match editor canvas exactly */
    border-radius: 0;

    /* Add a subtle border/shadow to look like a paper/canvas */
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    border: 1px solid #e2e8f0;

    cursor: pointer;
    transition: transform 0.2s;
    background-color: white;
    /* Ensure background is white like canvas */
    object-fit: contain;
    /* Ensure image fits if sizes differ, though they shouldn't */
}

#imagePreview:hover {
    transform: scale(1.01);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* ============================================================================
   EXPORT STATS
   ============================================================================ */

.export-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.exp.logo-inputs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.intro-audio-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.stat {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ============================================================================
   LOADING OVERLAY
   ============================================================================ */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1001;
}

.toast {
    background: var(--bg-white);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 1rem 1.5rem;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.3s ease;
    border-left: 4px solid var(--primary);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--error);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 640px) {
    .app {
        padding: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .export-stats {
        grid-template-columns: 1fr;
    }

    .logo-inputs {
        flex-direction: column;
    }
}

/* ============================================================================
   IMAGE EDITOR MODAL
   ============================================================================ */

.editor-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.editor-container {
    background: var(--bg-white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 1200px;
    height: 90vh;
    display: flex;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* Sidebar */
.editor-sidebar {
    width: 200px;
    /* Fixed width sidebar */
    background: #f8fafc;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    flex-shrink: 0;
}

.editor-sidebar-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.editor-sidebar-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.editor-tools {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    width: 100%;
}

.tool-btn:hover {
    background: rgba(37, 99, 235, 0.05);
    color: var(--primary);
}

.tool-btn.active {
    background: var(--primary);
    color: white;
}

.tool-btn.active .tool-icon {
    /* filter: brightness(0) invert(1); */
    /* Standard emoji don't tint well, rely on bg */
    transform: scale(1.1);
}

.editor-modal-content {
    background: white;
    width: 95vw;
    height: 90vh;
    border-radius: var(--radius-lg);
    display: flex;
    overflow: hidden;
    position: relative;
}

.editor-sidebar {
    width: 260px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    z-index: 10;
    flex-shrink: 0;
}

.editor-main {
    flex: 2;
    /* Give more space to the editor */
    background: #e2e8f0;
    /* Solid grey background as requested */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    border-right: 1px solid #cbd5e1;
    min-width: 0;
    /* Allow flex shrinking if needed */
}

.editor-preview-panel {
    flex: 1;
    min-width: 350px;
    /* Prevent being crushed */
    max-width: 500px;
    /* Don't get too wide */
    background: #f1f5f9;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-left: 1px solid #e2e8f0;
}

.video-preview-container {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: black;
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.video-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('bg-preview.png');
    background-size: cover;
    background-position: center;
    opacity: 0.8;
    /* Dim slightly to let overlay pop? Or keep full? Let's keep full for accuracy */
    opacity: 1;
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    /* Match height of container (1080 equivalent) based on red-area finding */
    width: auto;
    /* Maintain aspect ratio */
    object-fit: contain;
    /* Transformation origin top-left usually works for this layout */
    /* Hide if source is empty to prevent broken icon */
    display: block;
}

.video-overlay[src=""],
.video-overlay:not([src]) {
    display: none;
}

.editor-canvas-wrapper {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Prevent scrollbars */
    padding: 2rem;
}

.editor-hint {
    background: rgba(255, 255, 255, 0.9);
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    border-top: 1px solid var(--border);
    backdrop-filter: blur(4px);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

/* Fabric Canvas Override */
.canvas-container {
    background: white;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}