/* Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Ensure hidden attribute works */
[hidden] {
    display: none !important;
}

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg-dark: #0f0f0f;
    --bg-card: #1a1a1a;
    --bg-input: #252525;
    --bg-hover: #2a2a2a;
    --border: #333;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* App Container */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

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

/* Main Content Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
}

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

/* Preview Section */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.preview-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

/* Upload Zone */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    height: 100%;
    min-height: 400px;
}

.upload-zone:hover {
    background: var(--bg-hover);
}

.upload-zone.drag-over {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
}

.upload-icon {
    color: var(--text-muted);
    margin-bottom: 16px;
}

.upload-text {
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.upload-subtext {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

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

/* Video Preview */
.video-preview {
    width: 100%;
    padding: 16px;
}

.video-preview video {
    width: 100%;
    max-height: 500px;
    border-radius: var(--radius-sm);
    background: #000;
}

/* GIF Preview */
.gif-preview {
    width: 100%;
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gif-preview[hidden] {
    display: none !important;
}

.canvas-wrapper {
    position: relative;
    display: inline-block;
    background: repeating-conic-gradient(#333 0% 25%, #222 0% 50%) 50% / 20px 20px;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

#gifCanvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.captions-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Caption Element on Canvas */
.caption-element {
    position: absolute;
    cursor: move;
    pointer-events: all;
    user-select: none;
    text-align: center;
    white-space: nowrap;
    font-weight: bold;
    text-transform: uppercase;
    -webkit-text-stroke: 2px black;
    paint-order: stroke fill;
}

.caption-element:hover {
    outline: 2px dashed var(--primary);
    outline-offset: 4px;
}

.caption-element.selected {
    outline: 2px solid var(--primary);
    outline-offset: 4px;
}

.caption-element .resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border: 2px solid white;
    border-radius: 50%;
    cursor: se-resize;
    bottom: -6px;
    right: -6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.caption-element:hover .resize-handle,
.caption-element.selected .resize-handle {
    opacity: 1;
}

/* Timeline */
.timeline-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
}

.timeline-labels {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-family: monospace;
}

.timeline-slider {
    position: relative;
    height: 40px;
    margin-bottom: 8px;
}

.timeline-slider input[type="range"] {
    position: absolute;
    width: 100%;
    height: 8px;
    background: transparent;
    -webkit-appearance: none;
    pointer-events: none;
    top: 50%;
    transform: translateY(-50%);
}

.timeline-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.timeline-slider input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.timeline-track {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    width: 100%;
    z-index: 0;
}

.timeline-track::after {
    content: '';
    position: absolute;
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    left: var(--start, 0%);
    width: var(--width, 100%);
}

.timeline-duration {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

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

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

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

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
}

.btn-success {
    background: var(--success);
    color: white;
}

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

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #d97706;
}

.btn-add-caption {
    width: 100%;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px dashed var(--border);
    justify-content: center;
    margin-bottom: 16px;
}

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

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-icon:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Progress */
.progress-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
}

.progress-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #a855f7);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* File Info */
.file-info {
    text-align: center;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Settings Section */
.settings-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

/* Setting Groups */
.setting-group {
    margin-bottom: 16px;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.setting-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.setting-row {
    display: flex;
    gap: 12px;
}

.setting-group.half {
    flex: 1;
}

/* Input Styles */
input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

select {
    cursor: pointer;
}

input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 4px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
    border-radius: 4px;
    border: none;
}

/* Range Input */
.input-with-value {
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-with-value input[type="range"] {
    flex: 1;
}

.input-with-value span {
    min-width: 40px;
    text-align: right;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-family: monospace;
}

input[type="range"] {
    -webkit-appearance: none;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Captions List */
.captions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.caption-item {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.caption-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.caption-number {
    font-size: 0.875rem;
    font-weight: 500;
}

.caption-body {
    padding: 12px;
}

.caption-body .setting-group {
    margin-bottom: 12px;
}

.caption-body .setting-group:last-child {
    margin-bottom: 0;
}

.caption-body input[type="text"],
.caption-body input[type="number"],
.caption-body select {
    padding: 8px 10px;
}

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

::-webkit-scrollbar-track {
    background: var(--bg-input);
    border-radius: 4px;
}

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

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

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

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

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.caption-item {
    animation: fadeIn 0.3s ease;
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        padding: 16px;
    }

    .header h1 {
        font-size: 2rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }

    .setting-row {
        flex-direction: column;
    }
}
