/* =============================================
   Z-Image-to-Video — Styles
   Mobile-first, dark cyberpunk theme
   ============================================= */

/* --- CSS Variables --- */
:root {
    --bg-color: #0a0a0f;
    --bg-card: #111118;
    --bg-input: #1a1a25;
    --border-color: #2a2a3a;
    --text-color: #e0e0e0;
    --text-secondary: #888;
    --primary-color: #00f2ff;
    --primary-glow: rgba(0, 242, 255, 0.2);
    --error-color: #ff4466;
    --success-color: #00ff88;
    --radius: 12px;
    --radius-sm: 8px;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* --- Reset --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    min-height: 100vh;
    padding: 12px;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 520px;
    margin: 0 auto;
}

/* --- Headings --- */
h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    background: linear-gradient(135deg, var(--primary-color), #7b2fff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --- Form --- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.label-hint {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.75rem;
    color: #666;
}

/* --- API Select --- */
.api-select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 0.8rem;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.2s;
}

.api-select:focus {
    border-color: var(--primary-color);
}

/* --- Image Upload --- */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-input);
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(0, 242, 255, 0.05);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.upload-icon {
    font-size: 2rem;
    opacity: 0.6;
}

.upload-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.upload-hint {
    font-size: 0.7rem;
    color: #555;
}

.upload-preview {
    position: relative;
    width: 100%;
    max-width: 300px;
}

.upload-preview img {
    width: 100%;
    border-radius: var(--radius-sm);
    display: block;
}

.upload-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--error-color);
    color: white;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}

.upload-remove:hover {
    transform: scale(1.1);
}

/* --- Textarea --- */
textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 0.9rem;
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

textarea:focus {
    border-color: var(--primary-color);
}

textarea::placeholder {
    color: #555;
}

/* --- Paste button --- */
.btn-paste {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.15s;
}

.btn-paste:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* --- Aspect Ratio / Megapixels Grid --- */
.ratio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
}

.ratio-btn {
    padding: 10px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    white-space: nowrap;
}

.ratio-btn:hover {
    border-color: var(--primary-color);
    color: var(--text-color);
}

.ratio-btn.active {
    background: rgba(0, 242, 255, 0.12);
    border-color: var(--primary-color);
    color: var(--primary-color);
    box-shadow: 0 0 12px var(--primary-glow);
}

/* --- Duration Slider --- */
.duration-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
    border: 1px solid var(--border-color);
}

.duration-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 0 10px var(--primary-glow);
    border: 2px solid var(--bg-color);
}

.duration-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: 2px solid var(--bg-color);
}

/* --- Seed --- */
.seed-container {
    display: flex;
    gap: 8px;
}

#seed {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 0.85rem;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.2s;
}

#seed:focus {
    border-color: var(--primary-color);
}

.btn-random-seed {
    padding: 10px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}

.btn-random-seed:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* --- Buttons --- */
.button-group {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.btn-generate {
    flex: 1;
    padding: 14px;
    background: linear-gradient(135deg, #00c8e8, #7b2fff);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-generate:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(0, 200, 232, 0.3);
}

.btn-generate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-cancel {
    flex: 1;
    padding: 14px;
    background: rgba(255, 68, 102, 0.15);
    border: 1px solid var(--error-color);
    border-radius: var(--radius-sm);
    color: var(--error-color);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.save-history-btn {
    flex: 1;
    padding: 12px;
    background: rgba(0, 255, 136, 0.1);
    border: 1px solid var(--success-color);
    border-radius: var(--radius-sm);
    color: var(--success-color);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.save-history-btn:hover {
    background: rgba(0, 255, 136, 0.2);
}

.save-history-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* --- History button --- */
.btn-history {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}

.btn-history:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* --- Loading --- */
.loading {
    display: none;
    text-align: center;
    padding: 30px;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 16px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* --- Error --- */
.error {
    display: none;
    padding: 14px;
    background: rgba(255, 68, 102, 0.1);
    border: 1px solid var(--error-color);
    border-radius: var(--radius-sm);
    color: var(--error-color);
    font-size: 0.85rem;
    margin-top: 12px;
    word-break: break-word;
}

/* --- Result --- */
.result {
    display: none;
    margin-top: 20px;
}

.result-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.video-container {
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    border: 1px solid var(--border-color);
}

.result-video {
    width: 100%;
    display: block;
    border-radius: var(--radius);
}

/* --- Recent Gallery --- */
.recent-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.recent-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.recent-title-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-color);
    box-shadow: 0 0 6px var(--primary-color);
}

.recent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.recent-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}

.recent-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.recent-thumb {
    position: relative;
    aspect-ratio: 1;
    background: #000;
    overflow: hidden;
}

.recent-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recent-badge {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.3px;
}

.recent-info {
    padding: 8px 10px;
}

.recent-prompt {
    font-size: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.recent-meta {
    font-size: 0.6rem;
    color: #555;
    margin-top: 4px;
}

/* --- Modal (History) --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--error-color);
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.history-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.history-actions {
    margin-bottom: 14px;
}

.btn-clear-history {
    padding: 8px 16px;
    background: rgba(255, 68, 102, 0.1);
    border: 1px solid var(--error-color);
    border-radius: 6px;
    color: var(--error-color);
    cursor: pointer;
    font-size: 0.75rem;
}

.btn-clear-history:hover {
    background: rgba(255, 68, 102, 0.2);
}

.history-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px;
    align-items: flex-start;
}

.history-thumb {
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    background: #000;
    flex-shrink: 0;
    position: relative;
}

.history-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-prompt {
    font-size: 0.75rem;
    color: var(--text-color);
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.history-meta {
    font-size: 0.65rem;
    color: #555;
    margin-top: 3px;
}

.history-actions-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.history-btn {
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.65rem;
    cursor: pointer;
    white-space: nowrap;
}

.history-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.history-btn-delete:hover {
    border-color: var(--error-color);
    color: var(--error-color);
}

.empty-history {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    gap: 12px;
}

.empty-history-icon {
    font-size: 2.5rem;
    opacity: 0.4;
}

.empty-history-text {
    color: #555;
    font-size: 0.85rem;
}

/* --- Image Preview Overlay --- */
.image-preview-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 200;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.image-preview-header {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 12px;
    z-index: 10;
}

.image-preview-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.8rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.image-preview-newtab {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.image-preview-newtab:hover {
    background: rgba(255, 255, 255, 0.2);
}

.image-preview-body {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 20px;
}

/* --- Responsive --- */
@media (max-width: 480px) {
    .container {
        padding: 0;
    }

    h1 {
        font-size: 1.3rem;
    }

    .ratio-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .recent-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .history-item {
        flex-wrap: wrap;
    }

    .history-thumb {
        width: 60px;
        height: 60px;
    }
}