/* ============================================
   ISLAMIFY — Dark Theme with Gold/Emerald
   ============================================ */

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

:root {
    --bg-dark: #0a0a1a;
    --bg-card: #12122a;
    --bg-card-hover: #1a1a3a;
    --gold-50: #FFF8E1;
    --gold-100: #FFECB3;
    --gold-200: #FFE082;
    --gold-300: #FFD54F;
    --gold-400: #FFCA28;
    --gold-500: #FFC107;
    --gold-600: #D4A017;
    --gold-700: #B8860B;
    --emerald: #00C853;
    --emerald-dark: #00953e;
    --text-primary: #F5F0E8;
    --text-secondary: #B0A89C;
    --text-muted: #7A7268;
    --glass-bg: rgba(18, 18, 42, 0.85);
    --glass-border: rgba(212, 160, 23, 0.2);
    --gold-glow: rgba(212, 160, 23, 0.15);
    --danger: #EF5350;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Background pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('bg.jpg') center/cover no-repeat fixed;
    opacity: 0.25;
    /* Keeps the UI readable */
    pointer-events: none;
    z-index: 0;
}

/* Geometric pattern overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.015;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 40px, rgba(212, 160, 23, 0.5) 40px, rgba(212, 160, 23, 0.5) 41px),
        repeating-linear-gradient(90deg, transparent, transparent 40px, rgba(212, 160, 23, 0.5) 40px, rgba(212, 160, 23, 0.5) 41px);
    pointer-events: none;
    z-index: 0;
}

/* --- Page Wrapper --- */
.page-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 640px;
    padding: 80px 24px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
}

/* --- Header --- */
.header {
    text-align: center;
}

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

.logo-icon {
    font-size: 2.5rem;
    color: var(--gold-500);
    filter: drop-shadow(0 0 20px var(--gold-glow));
    animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {

    0%,
    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 20px var(--gold-glow));
    }

    50% {
        transform: scale(1.05);
        filter: drop-shadow(0 0 30px rgba(212, 160, 23, 0.3));
    }
}

.logo-text {
    font-family: 'Playfair Display', serif;
    font-size: 3.2rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--gold-300) 0%, var(--gold-600) 50%, var(--gold-300) 100%);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: goldShimmer 4s ease-in-out infinite;
    letter-spacing: 6px;
}

@keyframes goldShimmer {

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

    50% {
        background-position: 100% 50%;
    }
}

.tagline {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.5px;
}

/* --- Upload Section --- */
.upload-section {
    width: 100%;
}

.upload-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.upload-area {
    border: 2px dashed rgba(212, 160, 23, 0.3);
    border-radius: 16px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.upload-area:hover {
    border-color: var(--gold-500);
    background: rgba(212, 160, 23, 0.05);
}

.upload-area.dragging {
    border-color: var(--gold-400);
    background: rgba(212, 160, 23, 0.1);
    transform: scale(1.01);
}

.upload-icon {
    color: var(--gold-500);
    margin-bottom: 16px;
    opacity: 0.8;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

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

/* --- Divider --- */
.divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--glass-border), transparent);
}

.divider span {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 2px;
}

/* --- X Input --- */
.x-input-group {
    display: flex;
    gap: 10px;
}

.x-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0 14px;
    transition: all 0.3s ease;
}

.x-input-wrapper:focus-within {
    border-color: var(--gold-500);
    box-shadow: 0 0 0 3px var(--gold-glow);
}

.x-prefix {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 1rem;
    margin-right: 4px;
}

.x-input {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: 'Inter', sans-serif;
    padding: 14px 0;
    width: 100%;
    outline: none;
}

.x-input::placeholder {
    color: var(--text-muted);
}

.x-fetch-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.x-fetch-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--gold-500);
}

/* --- Preview Section --- */
.preview-section {
    width: 100%;
}

.preview-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 28px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

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

.preview-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
    color: var(--gold-400);
}

.reset-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
}

.preview-image-container {
    width: 100%;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 24px;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
}

.preview-image-container img {
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
    display: block;
}

.islamify-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px 32px;
    background: linear-gradient(135deg, var(--gold-700) 0%, var(--gold-500) 50%, var(--gold-700) 100%);
    background-size: 200% 200%;
    border: none;
    border-radius: 14px;
    color: #0a0a1a;
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 24px rgba(212, 160, 23, 0.3);
    animation: btnShimmer 3s ease-in-out infinite;
}

@keyframes btnShimmer {

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

    50% {
        background-position: 100% 50%;
    }
}

.islamify-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(212, 160, 23, 0.5);
}

.islamify-btn:active {
    transform: translateY(0);
}

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

/* --- Loading Section --- */
.loading-section {
    width: 100%;
}

.loading-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 48px 32px;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.loading-spinner {
    width: 56px;
    height: 56px;
    border: 3px solid rgba(212, 160, 23, 0.15);
    border-top-color: var(--gold-500);
    border-radius: 50%;
    margin: 0 auto 24px;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    font-family: 'Playfair Display', serif;
    font-size: 1.2rem;
    color: var(--gold-400);
    margin-bottom: 8px;
}

.loading-subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* --- Result Section --- */
.result-section {
    width: 100%;
}

.result-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 32px;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.result-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.8rem;
    color: var(--gold-400);
    margin-bottom: 24px;
}

.result-comparison {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.result-before,
.result-after {
    flex: 1;
    position: relative;
}

.result-label {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-primary);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    z-index: 2;
}

.result-before img,
.result-after img {
    width: 100%;
    border-radius: 12px;
    display: block;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.result-after img {
    border-color: var(--gold-600);
    box-shadow: 0 0 20px var(--gold-glow);
}

.result-arrow {
    font-size: 1.5rem;
    color: var(--gold-500);
    flex-shrink: 0;
}

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

.download-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--gold-700), var(--gold-500));
    border: none;
    border-radius: 12px;
    color: #0a0a1a;
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(212, 160, 23, 0.3);
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(212, 160, 23, 0.4);
}

.copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.try-again-btn {
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
}

.try-again-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--gold-500);
}

/* --- Error Section --- */
.error-section {
    width: 100%;
}

.error-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(239, 83, 80, 0.3);
    border-radius: 20px;
    padding: 32px;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.error-text {
    color: var(--danger);
    font-size: 1rem;
    margin-bottom: 16px;
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.footer-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.footer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    transition: all 0.2s ease;
}

.footer-link:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--gold-500);
    color: var(--gold-400);
}

.footer-divider {
    color: var(--text-muted);
}

.footer-ca {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: monospace;
    padding: 6px 6px 6px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.footer-ca:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--gold-500);
}

.ca-text {
    opacity: 0.9;
}

.copy-badge {
    background: var(--gold-600);
    color: #000;
    padding: 4px 12px;
    border-radius: 14px;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    transition: all 0.2s ease;
}

.footer-ca:hover .copy-badge {
    background: var(--gold-500);
}

.footer p {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* --- Navigation Toggle --- */
.nav-container {
    position: absolute;
    top: 32px;
    left: 0;
    width: 100%;
    text-align: center;
    z-index: 100;
}

.nav-link {
    color: var(--gold-500);
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 6px;
    font-family: 'Playfair Display', serif;
    letter-spacing: 1px;
    transition: color 0.2s ease;
    cursor: pointer;
}

.nav-link:hover {
    color: var(--gold-300);
}

/* --- Public Gallery View --- */
#galleryView {
    width: 100%;
}

.gallery-header {
    text-align: center;
    margin-bottom: 32px;
}

.gallery-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    color: var(--gold-400);
    margin-bottom: 8px;
}

.gallery-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    width: 100%;
}

.gallery-item {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    position: relative;
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    border-color: var(--gold-500);
}

.gallery-img-container {
    position: relative;
    width: 100%;
    padding-top: 50%;
    /* standard 2:1 aspect ratio assumed for stitched images */
    background: #000;
}

.gallery-img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: rgba(0, 0, 0, 0.5);
}

.gallery-loading,
.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-style: italic;
}

/* --- Modal Overlay --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(10, 10, 26, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--gold-500);
    border-radius: 20px;
    padding: 40px 32px;
    width: 90%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px var(--gold-glow);
    transform: scale(0.9);
    animation: scaleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes scaleIn {
    to {
        transform: scale(1);
    }
}

.modal-card h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.8rem;
    color: var(--gold-400);
    margin-bottom: 12px;
}

.modal-card p {
    color: var(--text-primary);
    font-size: 1.05rem;
    line-height: 1.5;
    margin-bottom: 24px;
}

.modal-preview-container {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 24px;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    display: none;
    /* Hidden by default until image loads */
}

.modal-preview-container img {
    width: 100%;
    height: auto;
    display: block;
}

.modal-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.modal-btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-no {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-muted);
}

.modal-no:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.4);
}

.modal-yes {
    background: linear-gradient(135deg, var(--gold-700), var(--gold-500));
    border: none;
    color: #000;
    box-shadow: 0 4px 15px rgba(212, 160, 23, 0.3);
}

.modal-yes:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 160, 23, 0.4);
}

/* Gallery View Modal Specifics */
.gallery-view-card {
    max-width: 800px;
    /* Wider to show the landscape before/after image better */
    padding: 32px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.gallery-close-btn {
    position: absolute;
    top: -16px;
    right: -16px;
    background: var(--bg-card);
    border: 1px solid var(--gold-600);
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.gallery-close-btn:hover {
    background: var(--gold-500);
    color: #000;
    transform: rotate(90deg) scale(1.1);
}

.gallery-large-preview {
    display: block;
    /* Override default hidden state */
    margin-bottom: 0;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .page-wrapper {
        padding: 28px 16px;
        gap: 24px;
    }

    .logo-text {
        font-size: 2.4rem;
        letter-spacing: 4px;
    }

    .logo-icon {
        font-size: 2rem;
    }

    .upload-card,
    .preview-card,
    .result-card,
    .loading-card {
        padding: 24px 18px;
        border-radius: 16px;
    }

    .upload-area {
        padding: 36px 16px;
    }

    .x-input-group {
        flex-direction: column;
    }

    .x-fetch-btn {
        justify-content: center;
    }

    .result-comparison {
        flex-direction: column;
    }

    .result-arrow {
        transform: rotate(90deg);
    }

    .islamify-btn {
        font-size: 1.1rem;
        padding: 16px 24px;
    }

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