/* =========================================================
   GOOGLE FONTS
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swap');

/* =========================================================
   GLOBAL VARIABLES & THEME
   ========================================================= */
:root {
    /* Color Palette */
    --brand-primary: #6366f1;
    --brand-secondary: #ec4899;
    --brand-accent: #06b6d4;
    --success: #10b981;
    --danger: #f43f5e;
    --warning: #f59e0b;

    /* Gradients */
    --bg-mesh: linear-gradient(135deg, #0f172a 0%, #1e1b4b 40%, #312e81 80%, #083344 100%);
    --gradient-primary: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    --gradient-success: linear-gradient(135deg, #059669, #10b981);
    --gradient-danger: linear-gradient(135deg, #be123c, #f43f5e);
    --gradient-glass: rgba(255, 255, 255, 0.03);
    
    /* UI Elements (Dark Mode / Glassmorphism approach) */
    --card-bg: rgba(15, 23, 42, 0.6);
    --card-border: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(0, 0, 0, 0.25);
    --input-border: rgba(255, 255, 255, 0.15);
    --input-focus: var(--brand-primary);
    
    /* Typography */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dark: #0f172a;
    
    /* Effects */
    --shadow-soft: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.4);
    --blur: blur(16px);
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================================
   RESETS & BASE
   ========================================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg-mesh);
    background-attachment: fixed;
    background-size: 200% 200%;
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    animation: gradientFlow 15s ease infinite;
}

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

/* =========================================================
   LAYOUT & CONTAINERS (GLASSMORPHISM)
   ========================================================= */
#mainApp {
    width: 100%;
    max-width: 540px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: fadeInUp 0.5s ease forwards;
    margin-top: 40px;
}

.container, .auth-card {
    background: var(--card-bg);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 50px 24px 32px 24px;
    position: relative;
    overflow: visible;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   HEADER & TYPOGRAPHY
   ========================================================= */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 28px;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.3;
    margin-bottom: 12px;
    letter-spacing: -0.5px;
}

.header p {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 400;
}

.header strong {
    color: var(--text-main);
    font-weight: 600;
}

/* =========================================================
   USER BAR & PROFILE
   ========================================================= */
.user-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--card-border);
}

.user-avatar-wrap {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

.user-initials, .user-avatar-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    font-size: 32px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 4px rgba(15, 23, 42, 0.8), var(--shadow-glow);
    border: 2px solid rgba(255, 255, 255, 0.2);
    object-fit: cover;
}

.user-details {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 10px;
}

.user-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
}

.user-email-text {
    font-size: 12px;
    color: var(--text-muted);
}

.connection-status {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--success);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(4px);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.5; }
    100% { transform: scale(0.95); opacity: 1; }
}

/* =========================================================
   TOKENS & BUY BUTTONS
   ========================================================= */
.token-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 8px;
}

.token-label {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.token-label::before {
    content: "💎";
    font-size: 18px;
}

#tokenCount {
    font-size: 28px;
    font-weight: 900;
    background: linear-gradient(135deg, #fde047, #f59e0b);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}

.buy-buttons-inline {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    margin-top: 16px;
}

.btn-buy-tokens {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn-buy-tokens:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: var(--shadow-glow);
}

/* Specific Button Accents on Hover */
.btn-buy-tokens:nth-child(1):hover { border-color: #38bdf8; box-shadow: 0 0 15px rgba(56, 189, 248, 0.3); }
.btn-buy-tokens:nth-child(2):hover { border-color: #a855f7; box-shadow: 0 0 15px rgba(168, 85, 247, 0.3); }
.btn-buy-tokens:nth-child(3):hover { border-color: #f43f5e; box-shadow: 0 0 15px rgba(244, 63, 94, 0.3); }
.btn-buy-tokens:nth-child(4):hover { border-color: #f59e0b; box-shadow: 0 0 15px rgba(245, 158, 11, 0.3); }

.btn-logout {
    width: 100%;
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.2);
    color: var(--danger);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 12px;
}

.btn-logout:hover {
    background: var(--danger);
    color: white;
    box-shadow: 0 8px 20px rgba(244, 63, 94, 0.3);
    transform: translateY(-2px);
}

/* =========================================================
   FORMS & INPUTS
   ========================================================= */
.form-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 16px 16px 16px 48px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--input-border);
    font-size: 14px;
    font-family: 'Poppins', sans-serif;
    background-color: var(--input-bg);
    color: var(--text-main);
    transition: var(--transition);
    background-repeat: no-repeat;
    background-position: 16px center;
    background-size: 20px;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

input:focus {
    outline: none;
    border-color: var(--brand-primary);
    background-color: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

/* Input Icons via background SVG */
#galleryTitle { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='8' y1='6' x2='21' y2='6'/%3E%3Cline x1='8' y1='12' x2='21' y2='12'/%3E%3Cline x1='8' y1='18' x2='21' y2='18'/%3E%3Cline x1='3' y1='6' x2='3.01' y2='6'/%3E%3Cline x1='3' y1='12' x2='3.01' y2='12'/%3E%3Cline x1='3' y1='18' x2='3.01' y2='18'/%3E%3C/svg%3E"); }
#galleryPassword { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2' ry='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E"); }
#whatsappNumber { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2310b981' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z'/%3E%3C/svg%3E"); }

/* =========================================================
   UPLOAD ZONE
   ========================================================= */
.upload-zone {
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    padding: 40px 20px;
    text-align: center;
    background-color: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: var(--transition);
}

.upload-zone:hover, .upload-zone.drag-over {
    background-color: rgba(99, 102, 241, 0.05);
    border-color: var(--brand-primary);
    box-shadow: inset 0 0 20px rgba(99, 102, 241, 0.1);
}

.upload-zone .upload-icon { display: none; }
.upload-zone::before {
    content: "";
    display: block;
    width: 100%;
    height: 48px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236366f1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='17 8 12 3 7 8'/%3E%3Cline x1='12' y1='3' x2='12' y2='15'/%3E%3C/svg%3E") center no-repeat;
    margin-bottom: 16px;
}

.upload-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* =========================================================
   BADGES & INFO
   ========================================================= */
.info-badge {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.2);
    color: #22d3ee;
    font-size: 12px;
    font-weight: 500;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
    line-height: 1.5;
}

.info-badge svg {
    flex-shrink: 0;
    margin-top: 2px;
    color: #06b6d4;
}

/* =========================================================
   PREVIEW GRID & PROGRESS
   ========================================================= */
#previewGrid {
    display: none;
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.2);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--card-border);
}

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

.preview-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--brand-accent);
}

.clear-btn {
    font-size: 12px;
    color: var(--danger);
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.2);
    cursor: pointer;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    transition: var(--transition);
}

.clear-btn:hover {
    background: var(--danger);
    color: white;
}

.preview-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 10px;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
}

.preview-thumbs::-webkit-scrollbar {
    width: 6px;
}
.preview-thumbs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.preview-thumb {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--card-border);
}

.preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    color: white;
    font-size: 9px;
    padding: 4px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Progress Bar */
#progressWrap {
    display: none;
    margin-top: 16px;
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.progress-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 8px;
}

.progress-bar-track {
    width: 100%;
    height: 6px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 10px;
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

/* =========================================================
   ACTION BUTTONS
   ========================================================= */
.buttons-wrapper {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 32px;
}

.buttons-wrapper button {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 15px;
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    transition: var(--transition);
    box-shadow: var(--shadow-soft);
}

.buttons-wrapper button:active {
    transform: scale(0.98);
}

.btn-generate {
    background: var(--gradient-primary);
    color: white;
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4);
}

.btn-generate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
}

.btn-download {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-download.active {
    background: var(--gradient-success);
    color: white;
    opacity: 1;
    cursor: pointer;
    border: none;
}

.btn-download.active:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
}

/* =========================================================
   AUTH OVERLAY
   ========================================================= */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: opacity 0.4s ease;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
}

.auth-brand-icon {
    font-size: 28px;
    width: 60px;
    height: 60px;
    background: var(--gradient-primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.auth-brand h2 {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.2;
}

.auth-brand p {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 4px;
}

.btn-google {
    width: 100%;
    padding: 16px;
    background: #ffffff;
    color: var(--text-dark);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: var(--transition);
}

.btn-google:hover {
    background: #f8fafc;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 255, 255, 0.2);
}

.auth-msg {
    margin-bottom: 16px;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    display: none;
}

.auth-msg--error { background: rgba(244, 63, 94, 0.1); color: #fecdd3; border: 1px solid rgba(244, 63, 94, 0.2); }
.auth-msg--success { background: rgba(16, 185, 129, 0.1); color: #a7f3d0; border: 1px solid rgba(16, 185, 129, 0.2); }

/* =========================================================
   TOAST NOTIFICATION
   ========================================================= */
#toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--card-bg);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    padding: 14px 28px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), var(--shadow-glow);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
}

#toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* =========================================================
   MEDIA QUERIES (DESKTOP / WIDE SCREENS)
   ========================================================= */
@media (min-width: 768px) {
    #mainApp {
        max-width: 700px;
        margin-top: 60px;
    }

    .container {
        padding: 60px 40px 40px 40px;
    }

    .form-row {
        flex-direction: row;
    }

    .form-row .form-group {
        flex: 1;
    }

    .buy-buttons-inline {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .buttons-wrapper {
        flex-direction: row;
    }

    .user-avatar-wrap {
        top: -60px;
    }
    
    .user-initials, .user-avatar-img {
        width: 100px;
        height: 100px;
        font-size: 36px;
    }

    .auth-card {
        padding: 48px;
    }
}
