* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--background) 0%, #1e1b4b 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    padding: 40px 20px;
    background: var(--surface);
    border-radius: 16px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px var(--shadow);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 12px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    color: var(--primary-color);
}

.header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.input-section,
.output-section {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 6px var(--shadow);
}

/* Text Input */
.text-input-wrapper {
    margin-bottom: 24px;
}

.text-input-wrapper label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

#narrative-text {
    width: 100%;
    padding: 16px;
    background: var(--background);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.3s;
}

#narrative-text:focus {
    outline: none;
    border-color: var(--primary-color);
}

.char-count {
    text-align: right;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Controls Grid */
.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-group label {
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

select,
input[type="range"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--background);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9375rem;
    cursor: pointer;
    transition: border-color 0.3s;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.button-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn {
    flex: 1;
    min-width: 150px;
    padding: 14px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
}

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

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

.btn-tertiary:hover:not(:disabled) {
    background: #059669;
    transform: translateY(-2px);
}

.btn-image {
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
    color: white;
}

.btn-image:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(236, 72, 153, 0.3);
}

.btn-video {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
}

.btn-video:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(245, 158, 11, 0.3);
}

.btn-video-full {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    width: 100%;
    margin-top: 16px;
}

.btn-video-full:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(245, 158, 11, 0.3);
}

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

.btn-icon {
    font-size: 1.2rem;
}

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--background);
    border-radius: 10px;
}

.stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.stat-value {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1rem;
}

/* Saved Narratives */
.saved-narratives h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.narratives-list {
    max-height: 400px;
    overflow-y: auto;
}

.narrative-item {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 12px;
    transition: border-color 0.3s;
}

.narrative-item:hover {
    border-color: var(--primary-color);
}

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

.narrative-title {
    font-weight: 600;
    color: var(--text-primary);
}

.narrative-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.narrative-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

.btn-sm {
    padding: 6px 12px;
    font-size: 0.875rem;
    border-radius: 6px;
}

.btn-play {
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
}

.btn-delete {
    background: var(--danger-color);
    color: white;
    border: none;
    cursor: pointer;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-style: italic;
}

/* Examples Section */
.examples-section {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 6px var(--shadow);
}

.examples-section h3 {
    margin-bottom: 20px;
    color: var(--text-primary);
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.example-card {
    background: var(--background);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s;
}

.example-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-4px);
    box-shadow: 0 8px 20px var(--shadow);
}

.example-card h4 {
    color: var(--primary-color);
    margin-bottom: 8px;
}

.example-card p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

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

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

@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    .header {
        padding: 24px 16px;
    }

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

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

    .logo-icon {
        width: 40px;
        height: 40px;
    }

    .tagline {
        font-size: 1rem;
    }

    .input-section,
    .output-section {
        padding: 16px;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .examples-grid {
        grid-template-columns: 1fr;
    }

    .stats-bar {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .tagline {
        font-size: 0.875rem;
    }

    #narrative-text {
        font-size: 0.9375rem;
    }

    .control-group label {
        font-size: 0.8125rem;
    }
}

/* Loading Animation */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Scrollbar Styling */
.narratives-list::-webkit-scrollbar {
    width: 8px;
}

.narratives-list::-webkit-scrollbar-track {
    background: var(--background);
    border-radius: 4px;
}

.narratives-list::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}

.narratives-list::-webkit-scrollbar-thumb:hover {
    background: var(--border);
}

/* Image Preview Section */
.image-preview {
    margin-top: 24px;
    padding: 20px;
    background: var(--background);
    border-radius: 12px;
    border: 2px solid var(--border);
    animation: fadeIn 0.3s ease-in;
}

.image-preview h4 {
    color: var(--text-primary);
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.image-container {
    position: relative;
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    margin-bottom: 16px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#generated-image {
    width: 100%;
    height: auto;
    max-height: 500px;
    object-fit: contain;
    display: block;
}

.image-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
    pointer-events: none;
    z-index: 1;
}

.image-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-download,
.btn-share {
    flex: 1;
    min-width: 140px;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
}

.btn-download {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.btn-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.3);
}

.btn-share {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.btn-share:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.btn-sm {
    padding: 10px 16px;
    font-size: 0.875rem;
}

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

/* Loading Animation for Image Generation */
.image-container.loading::after {
    content: 'Generating image...';
    position: absolute;
    color: var(--text-secondary);
    font-size: 1.1rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.image-container.loading img {
    opacity: 0.3;
}

/* Mobile-specific image styles */
@media (max-width: 768px) {
    .image-preview {
        padding: 16px;
        margin-top: 20px;
    }

    .image-container {
        min-height: 250px;
    }

    #generated-image {
        max-height: 400px;
    }

    .image-actions {
        flex-direction: column;
    }

    .btn-download,
    .btn-share {
        width: 100%;
        min-width: auto;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

/* Video Generation Styles */
.video-options {
    margin-top: 24px;
    padding: 20px;
    background: var(--background);
    border-radius: 12px;
    border: 2px solid #f59e0b;
    animation: fadeIn 0.3s ease-in;
}

.video-options h4 {
    color: #f59e0b;
    margin-bottom: 16px;
}

.video-controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.video-controls-grid small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* Video Progress Styles */
.video-progress {
    margin-top: 24px;
    padding: 24px;
    background: var(--background);
    border-radius: 12px;
    border: 2px solid var(--primary-color);
}

.video-progress h4 {
    color: var(--primary-color);
    margin-bottom: 20px;
}

.progress-bar-container {
    margin-bottom: 16px;
}

.progress-bar {
    width: 100%;
    height: 30px;
    background: var(--surface-light);
    border-radius: 15px;
    overflow: hidden;
    position: relative;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #ec4899);
    background-size: 200% 100%;
    animation: gradientMove 2s ease infinite;
    transition: width 0.3s ease;
    border-radius: 15px;
}

@keyframes gradientMove {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.progress-text {
    display: block;
    text-align: center;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9rem;
}

.progress-details {
    padding: 16px;
    background: var(--surface);
    border-radius: 8px;
}

.progress-details p {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.9rem;
}

/* Video Preview Styles */
.video-preview {
    margin-top: 24px;
    padding: 24px;
    background: var(--background);
    border-radius: 12px;
    border: 2px solid #10b981;
    animation: fadeIn 0.5s ease-in;
}

.video-preview h4 {
    color: #10b981;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.video-container {
    position: relative;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

#generated-video {
    width: 100%;
    height: auto;
    display: block;
    max-height: 600px;
}

.video-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--surface);
    border-radius: 10px;
}

.info-item {
    text-align: center;
}

.info-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.info-value {
    display: block;
    color: var(--primary-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.video-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-video-download,
.btn-video-share {
    flex: 1;
    min-width: 160px;
    padding: 14px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
}

.btn-video-download {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.btn-video-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

.btn-video-share {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.btn-video-share:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
}

/* Mobile-specific video styles */
@media (max-width: 768px) {
    .video-options,
    .video-progress,
    .video-preview {
        padding: 16px;
    }

    .video-controls-grid {
        grid-template-columns: 1fr;
    }

    .video-info {
        grid-template-columns: 1fr;
    }

    .video-actions {
        flex-direction: column;
    }

    .btn-video-download,
    .btn-video-share {
        width: 100%;
        min-width: auto;
    }

    #generated-video {
        max-height: 400px;
    }
}
