/* ==========================================================================
   Quranic Reels Generator — Premium Dark Theme
   ========================================================================== */

:root {
    --bg-main: #0a0f1a;
    --bg-card: rgba(15, 20, 35, 0.85);
    --gold: #c5a059;
    --gold-light: #e8d5a3;
    --gold-dark: #8b6914;
    --emerald: #2ecc71;
    --text-primary: #f0ece4;
    --text-secondary: #a8a29e;
    --glass-border: rgba(197, 160, 89, 0.15);
    --radius: 16px;
    --shadow-gold: 0 4px 30px rgba(197, 160, 89, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Tajawal', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    direction: rtl;
    min-height: 100vh;
    line-height: 1.7;
}

/* ── Header ── */
.app-header {
    text-align: center;
    padding: 50px 20px 30px;
    background: linear-gradient(180deg, rgba(197, 160, 89, 0.08) 0%, transparent 100%);
}

.app-header h1 {
    font-size: 3rem;
    color: var(--gold);
    margin-bottom: 10px;
    text-shadow: 0 2px 20px rgba(197, 160, 89, 0.3);
}

.app-header .subtitle {
    font-size: 1.4rem;
    color: var(--gold-light);
    font-weight: 500;
    opacity: 0.85;
}

/* ── Container ── */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px 40px;
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-gold);
    animation: fadeIn 0.5s ease-out;
}

.card h2 {
    color: var(--gold);
    font-size: 1.25rem;
    margin-bottom: 22px;
    padding-right: 14px;
    border-right: 3px solid var(--gold);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--gold-dark), var(--gold));
    color: #0a0f1a;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 800;
}

/* ── Grid ── */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

@media (max-width: 600px) {
    .grid-2 { grid-template-columns: 1fr; }
}

/* ── Form Controls ── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

select, input[type="number"] {
    font-family: 'Tajawal', sans-serif;
    background: rgba(10, 15, 26, 0.8);
    color: var(--text-primary);
    border: 1.5px solid rgba(197, 160, 89, 0.25);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 1rem;
    direction: rtl;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    appearance: none;
    -webkit-appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23c5a059' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 14px center;
    padding-left: 36px;
}

select:focus, input[type="number"]:focus {
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(197, 160, 89, 0.2);
}

select option {
    background: #1a1f30;
    color: var(--text-primary);
}

/* ── Background Selection ── */
.bg-types {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.bg-type-btn {
    font-family: 'Tajawal', sans-serif;
    padding: 10px 22px;
    border: 1.5px solid rgba(197, 160, 89, 0.25);
    border-radius: 10px;
    background: rgba(10, 15, 26, 0.6);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.bg-type-btn:hover {
    border-color: var(--gold);
    background: rgba(197, 160, 89, 0.08);
}

.bg-type-btn.active {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold));
    color: #0a0f1a;
    border-color: var(--gold);
    font-weight: 700;
}

/* ── Upload Settings ── */
.upload-group {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.upload-btn {
    display: inline-block;
    padding: 8px 16px;
    background: rgba(197, 160, 89, 0.1);
    border: 1px dashed var(--gold);
    border-radius: 8px;
    color: var(--gold-light);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-btn:hover {
    background: rgba(197, 160, 89, 0.2);
}

.upload-status {
    font-size: 0.85rem;
    color: var(--emerald);
}

.bg-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.bg-card {
    border: 2px solid transparent;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    background: #111827;
}

.bg-card:hover {
    border-color: var(--gold);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(197, 160, 89, 0.2);
}

.bg-card.selected {
    border-color: var(--emerald);
    box-shadow: 0 0 15px rgba(46, 204, 113, 0.3);
}

.bg-card img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
}

.bg-card .bg-label {
    padding: 6px 8px;
    font-size: 0.75rem;
    text-align: center;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bg-card .bg-type-icon {
    position: absolute;
    top: 6px;
    left: 6px;
    font-size: 0.7rem;
    background: rgba(0,0,0,0.7);
    padding: 2px 6px;
    border-radius: 4px;
}

.selected-info {
    margin-top: 12px;
    padding: 10px 16px;
    border-radius: 10px;
    background: rgba(46, 204, 113, 0.08);
    border: 1px solid rgba(46, 204, 113, 0.2);
    color: var(--emerald);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── AI Background Generation ── */
.ai-prompt-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
}

.ai-prompt-group label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.ai-prompt-group input[type="text"] {
    font-family: 'Tajawal', sans-serif;
    background: rgba(10, 15, 26, 0.8);
    color: var(--text-primary);
    border: 1.5px solid rgba(197, 160, 89, 0.25);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 1rem;
    direction: rtl;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.ai-prompt-group input[type="text"]:focus {
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(197, 160, 89, 0.2);
}

.ai-generate-btn {
    font-family: 'Tajawal', sans-serif;
    padding: 12px 28px;
    background: linear-gradient(135deg, #6b21a8, #9333ea);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(147, 51, 234, 0.3);
}

.ai-generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(147, 51, 234, 0.45);
}

.ai-generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-generate-btn.loading {
    animation: pulse 1.5s infinite;
}

#ai-preview-area {
    margin-top: 18px;
    text-align: center;
}

.ai-preview-label {
    color: var(--gold-light);
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 12px;
}

#ai-preview-img {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 12px;
    border: 2px solid rgba(197, 160, 89, 0.3);
    margin-bottom: 16px;
}

.ai-confirm-buttons {
    display: flex;
    gap: 14px;
    justify-content: center;
}

.ai-confirm-yes {
    font-family: 'Tajawal', sans-serif;
    padding: 10px 28px;
    background: linear-gradient(135deg, #1a6b3a, var(--emerald));
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ai-confirm-yes:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.4);
}

.ai-confirm-no {
    font-family: 'Tajawal', sans-serif;
    padding: 10px 28px;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    font-size: 1rem;
    font-weight: 700;
    border: 1.5px solid rgba(239, 68, 68, 0.3);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ai-confirm-no:hover {
    background: rgba(239, 68, 68, 0.25);
    transform: translateY(-2px);
}

.ai-error-msg {
    color: #ef4444;
    text-align: center;
    padding: 10px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    font-size: 0.9rem;
    margin-top: 12px;
}

/* ── Font Gallery ── */
.font-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.font-card {
    border: 2px solid rgba(68, 68, 68, 0.5);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #1a1f2b;
    text-align: center;
}

.font-card:hover {
    border-color: var(--gold);
    transform: translateY(-2px);
}

.font-card.selected {
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(197, 160, 89, 0.25);
}

.font-card img {
    width: 100%;
    height: 60px;
    object-fit: contain;
    padding: 5px;
}

.font-card .font-name {
    padding: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.font-badge {
    background: rgba(197, 160, 89, 0.1);
    border: 1px solid rgba(197, 160, 89, 0.3);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--gold-light);
    font-size: 0.9rem;
}

/* ── Live Preview ── */
.preview-container {
    width: 100%;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(197, 160, 89, 0.2);
}

#live-preview {
    width: 100%;
    max-height: 500px;
    height: auto;
    display: block;
    object-fit: contain;
    transition: opacity 0.3s ease;
}

.preview-loading {
    position: absolute;
    color: var(--gold-light);
    font-size: 1rem;
    animation: pulse 1.5s infinite;
}

/* ── Generate Button ── */
.generate-btn {
    font-family: 'Tajawal', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 18px 32px;
    background: linear-gradient(135deg, var(--gold-dark), var(--gold), var(--gold-dark));
    background-size: 200% 100%;
    color: #0a0f1a;
    font-size: 1.2rem;
    font-weight: 700;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    margin-bottom: 24px;
    transition: transform 0.25s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 20px rgba(197, 160, 89, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.generate-btn:hover {
    transform: scale(1.03) translateY(-2px);
    box-shadow: 0 8px 32px rgba(197, 160, 89, 0.45);
    animation: shimmer 1.8s linear infinite;
}

.generate-btn:active {
    transform: scale(0.98);
}

.generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    animation: none;
}

.btn-icon {
    font-size: 1.4rem;
}

/* ── Progress ── */
.progress-bar-container {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 14px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold), var(--emerald));
    background-size: 300% 100%;
    border-radius: 10px;
    transition: width 0.4s ease;
    animation: progressShimmer 2s linear infinite;
}

.progress-text {
    text-align: center;
    color: var(--gold-light);
    font-size: 0.95rem;
    font-weight: 500;
}

/* ── Result ── */
.result-video {
    width: 100%;
    max-height: 500px;
    border-radius: 12px;
    margin-bottom: 16px;
    background: #000;
}

.download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #1a6b3a, var(--emerald));
    color: #fff;
    font-family: 'Tajawal', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(46, 204, 113, 0.35);
}

/* ── Idle ── */
.idle-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.idle-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.6;
}

/* ── Error ── */
.error-text {
    color: #ef4444;
    text-align: center;
    padding: 16px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 10px;
    font-size: 0.95rem;
}

/* ── Footer ── */
.app-footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.6;
}

/* ── Animations ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes progressShimmer {
    0% { background-position: 300% 0; }
    100% { background-position: -300% 0; }
}

@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* ── Generation Panel ── */
.generation-panel {
    box-shadow: 0 4px 30px rgba(197, 160, 89, 0.12);
    border-color: rgba(197, 160, 89, 0.25);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gold-dark); border-radius: 3px; }

/* ── Accessibility & Responsive ── */
@media (prefers-reduced-motion: reduce) {
    *, ::before, ::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media (max-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
    .app-header h1 {
        font-size: 2.2rem;
    }
    .card {
        padding: 20px;
    }
    .bg-gallery {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
    .font-gallery {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}
