:root {
    --bg: #0b1021;
    --surface: #11172b;
    --surface-alt: #1a2138;
    --border: #1f2a48;
    --accent: #7c5dff;
    --accent-2: #47c9ff;
    --text: #e6e8f0;
    --muted: #8e98b7;
    --success: #3cd188;
    --warning: #f5c542;
    --danger: #ff6b6b;
    --shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
    --radius: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 32px;
    font-family: "Inter", system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at 20% 20%, rgba(124,93,255,0.12), transparent 25%),
                radial-gradient(circle at 80% 10%, rgba(71,201,255,0.1), transparent 20%),
                var(--bg);
    color: var(--text);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
}

.page-header h1 {
    margin: 0;
    font-size: 28px;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    gap: 10px;
}

main.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.card {
    background: linear-gradient(145deg, var(--surface), var(--surface-alt));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.card.wide {
    grid-column: span 2;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.card-header h2 {
    margin: 0;
    letter-spacing: -0.01em;
}

.eyebrow {
    color: var(--accent-2);
    margin: 0 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    font-size: 12px;
}

.muted { color: var(--muted); margin: 0; }

.badge {
    background: rgba(124, 93, 255, 0.14);
    color: var(--accent);
    border: 1px solid rgba(124,93,255,0.3);
    padding: 6px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 12px;
}

input, select, textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 14px;
    transition: border-color 0.2s ease;
}

textarea { min-height: 90px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

button, a.button, .toolbar .ghost, .toolbar .primary, .header-actions a {
    appearance: none;
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
    color: var(--text);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

button:disabled { opacity: 0.6; cursor: not-allowed; }

.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 10px 30px rgba(124,93,255,0.3);
}

.ghost {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
}

.full { width: 100%; justify-content: center; }

.stack { display: flex; flex-direction: column; gap: 12px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.checkbox { display: flex; align-items: center; gap: 8px; }

.list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.list .item {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    background: rgba(255,255,255,0.02);
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.list .item:hover { border-color: var(--accent); }

.list .item.active { border-color: var(--accent); background: rgba(124,93,255,0.08); }

.chip {
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 12px;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.summary {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.progress-block {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: rgba(124,93,255,0.04);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-weight: 700;
}

.progress-bar {
    height: 10px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 8px;
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    transition: width 0.3s ease;
}

.progress-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    font-size: 14px;
}

.generation-focus {
    margin-top: 12px;
    border: 1px solid rgba(71,201,255,0.32);
    border-radius: 14px;
    padding: 14px;
    background: linear-gradient(135deg, rgba(71,201,255,0.1), rgba(124,93,255,0.08));
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr);
    gap: 14px;
    align-items: center;
}

.generation-focus[hidden] { display: none; }

.generation-focus h3 {
    margin: 0 0 6px;
}

.generation-focus-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.generation-focus-stats div {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    background: rgba(11,16,33,0.34);
    text-align: center;
}

.generation-focus-stats strong {
    display: block;
    font-size: 22px;
    color: var(--accent-2);
}

.generation-focus-stats span {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.scene-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

.scene-card {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255,255,255,0.02);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.scene-card .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.scene-card .title h4 { margin: 0; }

.scene-card .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.activity-log {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

.activity-entry {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: rgba(255,255,255,0.02);
}

.activity-entry .meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.status-indicator {
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    font-weight: 700;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: min(900px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    padding: 16px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.modal-header h3 { margin: 0; }

.modal .icon {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px;
    border-radius: 8px;
}

.versions {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.version-entry {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: rgba(255,255,255,0.02);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.version-entry.success { border-color: rgba(60,209,136,0.4); }
.version-entry.failed { border-color: rgba(255,107,107,0.4); }

.version-meta { font-size: 12px; color: var(--muted); }

.status-pill {
    padding: 4px 8px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    border: 1px solid var(--border);
}

.status-pill.success { color: var(--success); border-color: rgba(60,209,136,0.4); }
.status-pill.failed { color: var(--danger); border-color: rgba(255,107,107,0.4); }
.status-pill.generating { color: var(--accent); border-color: rgba(124,93,255,0.4); }

/* Audio Section */
.audio-section {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    background: rgba(71, 201, 255, 0.04);
}

.audio-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.audio-header h4 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.audio-info {
    margin-bottom: 12px;
    padding: 10px;
    background: rgba(255,255,255,0.02);
    border-radius: 8px;
}

.audio-info p { margin: 4px 0; }

.audio-player-container {
    margin: 10px 0;
}

.audio-player-container audio {
    width: 100%;
    border-radius: 8px;
}

.transcript-details {
    margin-top: 10px;
}

.transcript-details summary {
    cursor: pointer;
    padding: 8px;
    background: var(--surface);
    border-radius: 6px;
}

.transcript-details summary:hover {
    background: var(--surface-alt);
}

.transcript-text {
    max-height: 200px;
    overflow-y: auto;
    padding: 12px;
    background: var(--surface);
    border-radius: 6px;
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.audio-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.file-input {
    position: relative;
    cursor: pointer;
}

.file-input input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    background: rgba(255,255,255,0.02);
    transition: border-color 0.2s ease, background 0.2s ease;
}

.file-input:hover .file-label {
    border-color: var(--accent);
    background: rgba(124,93,255,0.04);
}

.file-input.has-file .file-label {
    border-color: var(--success);
    background: rgba(60,209,136,0.08);
}

.lyrics-section textarea {
    min-height: 80px;
}

.audio-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.audio-section .badge.has-audio {
    background: rgba(60,209,136,0.14);
    color: var(--success);
    border-color: rgba(60,209,136,0.3);
}

.image-section {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    background: rgba(124, 93, 255, 0.04);
}

.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.image-thumb {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: rgba(255,255,255,0.03);
}

.image-thumb img {
    width: 100%;
    height: 76px;
    object-fit: cover;
    display: block;
}

.image-thumb span {
    display: block;
    padding: 6px;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-plan {
    border: 1px solid rgba(71,201,255,0.28);
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(71,201,255,0.06);
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
}

.scene-source-image {
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #000;
    margin-bottom: 12px;
}

/* Video Preview */
.video-preview-container {
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

.video-preview-container video {
    width: 100%;
    max-height: 400px;
    display: block;
}

/* Scene Card Video Preview */
.scene-video-preview {
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    margin-bottom: 8px;
}

.scene-video-preview video {
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.scene-video-preview img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.scene-video-preview.no-video {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
}

/* Scene Card Enhanced */
.scene-card {
    position: relative;
}

.scene-card.generating {
    animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% { border-color: var(--border); }
    50% { border-color: var(--accent); box-shadow: 0 0 15px rgba(124,93,255,0.3); }
}

.scene-card .reorder-buttons {
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: absolute;
    top: 8px;
    right: 8px;
}

.scene-card .reorder-buttons button {
    padding: 4px 6px;
    font-size: 10px;
    background: var(--surface);
}

.scene-version-chip {
    font-size: 10px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(124,93,255,0.12);
    border-color: rgba(124,93,255,0.3);
}

.scene-error {
    margin: 8px 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,107,107,0.4);
    background: rgba(255,107,107,0.08);
    color: #ff8f8f;
    font-size: 12px;
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

/* Three column layout */
.three-col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

/* Modal Video Preview */
.modal-video-preview {
    border-radius: 10px;
    overflow: hidden;
    background: #000;
    margin-bottom: 16px;
}

.modal-video-preview video {
    width: 100%;
    max-height: 300px;
}

/* Modal Small */
.modal-small {
    width: min(500px, 100%);
}

/* Version Selection */
.version-selection {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: rgba(124,93,255,0.04);
}

.version-selection select {
    margin-top: 4px;
}

.clip-upload-section {
    border: 1px solid rgba(71,201,255,0.28);
    border-radius: 10px;
    padding: 12px;
    background: rgba(71,201,255,0.04);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.clip-upload-section strong {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clip-upload-section strong i {
    color: var(--accent-2);
}

/* Version Entry Enhanced */
.version-entry {
    cursor: pointer;
    transition: background 0.2s ease;
}

.version-entry:hover {
    background: rgba(255,255,255,0.04);
}

.version-entry.selected {
    border-color: var(--accent);
    background: rgba(124,93,255,0.1);
}

.version-entry .version-video {
    margin-top: 8px;
}

.version-entry .version-video video {
    width: 100%;
    max-height: 150px;
    border-radius: 6px;
}

/* Error Display */
.error-display {
    border: 1px solid rgba(255,107,107,0.4);
    border-radius: 10px;
    padding: 12px;
    background: rgba(255,107,107,0.08);
}

.error-message {
    color: var(--danger);
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

/* Danger Button */
button.danger {
    color: var(--danger);
    border-color: rgba(255,107,107,0.4);
}

button.danger:hover {
    background: rgba(255,107,107,0.1);
}

/* Scene Transcript Info */
.scene-transcript-info {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: rgba(71,201,255,0.04);
}

.scene-transcript-info p { margin: 4px 0; }

/* Scenes Header Actions */
.scenes-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Status Pills Enhanced */
.status-pill.ready { color: var(--success); border-color: rgba(60,209,136,0.4); }
.status-pill.pending { color: var(--muted); }
.status-pill.queued { color: var(--accent-2); border-color: rgba(71,201,255,0.4); }
.status-pill.skipped { color: var(--warning); border-color: rgba(245,197,66,0.4); }

/* Phase Stepper */
.phase-stepper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 12px;
    margin-bottom: 12px;
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    border-radius: 12px;
    gap: 0;
}

.phase-stepper .step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 70px;
}

.phase-stepper .step-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    transition: all 0.3s ease;
}

.phase-stepper .step-label {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    transition: color 0.3s ease;
}

.phase-stepper .step-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    min-width: 20px;
    max-width: 60px;
    transition: background 0.3s ease;
}

.phase-stepper .step.completed .step-circle {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.phase-stepper .step.completed .step-label {
    color: var(--success);
}

.phase-stepper .step.completed + .step-connector {
    background: var(--success);
}

.phase-stepper .step.active .step-circle {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.phase-stepper .step.active .step-label {
    color: var(--accent);
    font-weight: 600;
}

.phase-stepper .step.active.running .step-circle {
    animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(124,93,255,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(124,93,255,0); }
}

.phase-stepper .step.failed .step-circle {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.phase-stepper .step.failed .step-label {
    color: var(--danger);
}

/* Guidance Panel */
.guidance-panel {
    padding: 12px 16px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, rgba(124,93,255,0.08), rgba(71,201,255,0.08));
    border: 1px solid rgba(124,93,255,0.2);
    border-radius: 12px;
}

.guidance-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 16px;
}

.guidance-status i {
    color: var(--accent);
}

.guidance-text {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.guidance-text p {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
}

.guidance-text strong {
    color: var(--text);
}

/* Suggested button highlight */
button.suggested {
    background: linear-gradient(135deg, rgba(124,93,255,0.2), rgba(71,201,255,0.2));
    border-color: var(--accent);
    animation: suggest-pulse 2s ease-in-out infinite;
}

@keyframes suggest-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(124,93,255,0.3); }
    50% { box-shadow: 0 0 0 4px rgba(124,93,255,0); }
}

/* Toast notifications */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    font-size: 14px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-info { border-left: 3px solid var(--accent); }
.toast-success { border-left: 3px solid var(--success); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-error { border-left: 3px solid var(--danger); }

/* Activity Log Improvements */
.activity-entry {
    padding: 10px 12px;
}

.activity-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.activity-main i {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.activity-message {
    flex: 1;
    font-size: 13px;
}

.activity-time {
    font-size: 11px;
    color: var(--muted);
    flex-shrink: 0;
}

.activity-details {
    margin-top: 6px;
    font-size: 12px;
}

.activity-details summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 11px;
}

.activity-details pre {
    margin: 6px 0 0;
    padding: 8px;
    background: var(--surface);
    border-radius: 6px;
    font-size: 10px;
    max-height: 120px;
    overflow: auto;
}

.activity-info i { color: var(--accent-2); }
.activity-success i { color: var(--success); }
.activity-warning i { color: var(--warning); }
.activity-error i { color: var(--danger); }

.activity-success { border-left: 2px solid var(--success); }
.activity-error { border-left: 2px solid var(--danger); }
.activity-warning { border-left: 2px solid var(--warning); }

@media (max-width: 1024px) {
    main.grid { grid-template-columns: 1fr; }
    .card.wide { grid-column: span 1; }
    .layout { grid-template-columns: 1fr; }
    .summary { grid-template-columns: 1fr; }
    .progress-grid { grid-template-columns: repeat(2, 1fr); }
    .generation-focus { grid-template-columns: 1fr; }
    .generation-focus-stats { grid-template-columns: repeat(2, 1fr); }
    .guidance-text { grid-template-columns: 1fr; }
    .phase-stepper { flex-wrap: wrap; gap: 8px; }
    .phase-stepper .step-connector { display: none; }
    body { padding: 18px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .two-col, .three-col { grid-template-columns: 1fr; }
    .scenes-header-actions { flex-wrap: wrap; justify-content: flex-start; }
}
