/**
 * @license
 * SPDX-License-Identifier: Apache-2.0
 */

/* --- MODAL CONTAINER --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 9995;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
}

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

.modal-content {
    background: var(--bg-color-light);
    color: var(--text-color);
    padding: 30px;
    border-radius: 15px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 10px 30px var(--shadow-color);
    position: relative;
    animation: slideInUp 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex;
    flex-direction: column;
    max-height: 90vh; /* Default max height for desktop */
}
.modal-content.small {
    max-width: 400px;
}
.modal-content.large {
    max-width: 1100px; /* Wider to fit up to 6 items comfortably on desktop */
    width: 95%;
}

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

.modal-close {
    position: absolute;
    top: 15px;
    left: 15px; /* Adjusted for LTR close button on RTL layout */
    background: var(--surface-color);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 16px;
    color: var(--text-muted-color);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s, transform 0.2s;
    z-index: 10;
}

.modal-close:hover {
    background-color: var(--border-color);
    transform: rotate(90deg);
}

.modal-content h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 25px;
    text-align: center;
    flex-shrink: 0;
}

/* --- MODAL FOOTER & ACTIONS --- */
.modal-footer {
    display: flex;
    justify-content: center; /* Default center */
    align-items: center;
    gap: 15px;
    margin-top: 25px;
    width: 100%;
}

/* Confirm Actions - Side by Side */
.confirm-actions { 
    justify-content: space-between !important; /* Push to edges or space evenly */
    flex-direction: row !important; /* Force row layout */
}

.confirm-actions .btn {
    min-width: 100px;
    justify-content: center;
}
.settings-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 25px;
    flex-shrink: 0;
}

.settings-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: none;
    border: none;
    color: var(--text-muted-color);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    position: relative;
    transition: color 0.3s;
}

.settings-tab:hover {
    color: var(--primary-color);
}

.settings-tab.active {
    color: var(--primary-color);
}

.settings-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary-color);
}


/* --- PANELS & FORM GROUPS --- */
.settings-panel {
    display: none;
    overflow-y: auto; /* Allow panel internal scroll */
}
.settings-panel.active {
    display: block;
    animation: fadeIn 0.5s ease;
}

#settingsForm {
    overflow-y: auto;
    flex-grow: 1;
}

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

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

/* Custom Select */
select {
    width: 100%;
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23a0a0a0' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 15px center; /* Adjusted for RTL */
    padding-right: 20px;
    padding-left: 40px;
}

/* Custom Checkbox */
.checkbox-group {
    display: flex;
    align-items: center;
    background: var(--surface-color);
    padding: 10px 15px;
    border-radius: 8px;
}

.checkbox-group input[type="checkbox"] {
    display: none;
}

.checkbox-group label {
    margin: 0;
    cursor: pointer;
    position: relative;
    padding-right: 35px; /* Space for custom checkbox */
}

.checkbox-group label::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    background: var(--bg-color);
    transition: all 0.2s;
}

.checkbox-group label::after {
    content: '✔';
    position: absolute;
    right: 3px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    font-size: 16px;
    color: white;
    transition: transform 0.2s;
}

.checkbox-group input[type="checkbox"]:checked + label::before {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-group input[type="checkbox"]:checked + label::after {
    transform: translateY(-50%) scale(1);
}


/* --- THEME PREVIEW --- */
.theme-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
}

.theme-preview {
    height: 60px;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    transition: border-color 0.3s, transform 0.3s;
    overflow: hidden;
}

.theme-preview:hover {
    transform: scale(1.05);
}

.theme-preview.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color);
}

.theme-preview-label {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 11px;
    font-weight: 600;
    background: rgba(0,0,0,0.5);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Theme specific backgrounds */
.theme-dark { background: linear-gradient(135deg, #2c2c2c, #121212); }
.theme-light { background: linear-gradient(135deg, #ffffff, #f5f5f5); }
.theme-midnight-blue { background: linear-gradient(135deg, #1e293b, #0f172a); }
.theme-royal-purple { background: linear-gradient(135deg, #3e2c5f, #2c1f43); }
.theme-emerald-green { background: linear-gradient(135deg, #047857, #064e3b); }
.theme-sunset-orange { background: linear-gradient(135deg, #7c2d12, #451a03); }
.theme-dreamy-pink { background: linear-gradient(135deg, #7e22ce, #5b21b6); }
.theme-sky-blue { background: linear-gradient(135deg, #ffffff, #f0f9ff); }
.theme-luxury-gold { background: linear-gradient(135deg, #292524, #1c1917); }
.theme-neon-electric { background: linear-gradient(135deg, #1a1a1a, #000000); }
.theme-dark-cherry { background: linear-gradient(135deg, #4b0000, #2a0000); }

/* --- CURSOR PREVIEW --- */
.cursor-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 15px;
    margin-top: 10px;
}

.cursor-preview {
    height: 70px;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    border: 2px solid var(--border-color);
    background: var(--surface-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.cursor-preview:hover {
    transform: scale(1.05);
    border-color: var(--primary-color);
}

.cursor-preview.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color);
}

.cursor-preview-label {
    font-size: 11px;
    font-weight: 600;
    margin-top: 5px;
}

.cursor-preview-icon {
    width: 32px;
    height: 32px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.cursor-preview:first-child .cursor-preview-icon {
    border-top: 10px solid transparent;
    border-left: 6px solid var(--text-color);
    border-bottom: 2px solid transparent;
    border-right: 2px solid transparent;
    width: 15px;
    height: 15px;
    background: none;
}

.cursor-preview:nth-child(2) .cursor-preview-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><circle cx="16" cy="16" r="8" fill="none" stroke="%23667eea" stroke-width="2"/><line x1="16" y1="0" x2="16" y2="6" stroke="%23667eea" stroke-width="2"/><line x1="16" y1="26" x2="16" y2="32" stroke="%23667eea" stroke-width="2"/><line x1="0" y1="16" x2="6" y2="16" stroke="%23667eea" stroke-width="2"/><line x1="26" y1="16" x2="32" y2="16" stroke="%23667eea" stroke-width="2"/></svg>');
}

.cursor-preview:nth-child(3) .cursor-preview-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path d="M16 2 L28 16 L16 30 L4 16 Z" fill="none" stroke="%23a78bfa" stroke-width="2"/><circle cx="16" cy="16" r="4" fill="%23a78bfa"/></svg>');
}

.cursor-preview:nth-child(4) .cursor-preview-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path d="M4 16 L16 4 L16 12 L28 12 L28 20 L16 20 L16 28 Z" fill="%23f59e0b"/></svg>');
}

.cursor-preview:nth-child(5) .cursor-preview-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path d="M8 28 Q8 16, 16 8 T24 28" fill="none" stroke="%2310b981" stroke-width="2"/><line x1="24" y1="16" x2="28" y2="12" stroke="%2310b981" stroke-width="2"/><line x1="24" y1="16" x2="28" y2="20" stroke="%2310b981" stroke-width="2"/></svg>');
}

/* --- NOTIFICATION MODAL STYLES --- */
.notifications-list-container {
    /* إصلاح حاسم: السماح بالتمرير */
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    max-height: 500px;
    flex-grow: 1;
    padding: 10px 0;
}

.notifications-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.notification-item {
    background: var(--surface-color);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: all 0.3s;
    cursor: pointer;
}

.notification-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-color);
    border-color: var(--primary-color);
}

.notification-item.unread {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.05));
    border-color: var(--primary-color);
}

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

.notification-header strong {
    font-size: 1rem;
    color: var(--primary-color);
}

.timestamp {
    font-size: 0.75rem;
    color: var(--text-muted-color);
}

.notification-content {
    color: var(--text-color);
    line-height: 1.6;
}

.notification-content p {
    margin: 5px 0;
}

.notification-content b {
    color: var(--primary-color);
    font-weight: 700;
}

.notification-content i {
    font-style: italic;
    opacity: 0.8;
}

.notification-content a {
    color: var(--primary-color);
    text-decoration: underline;
}

.notification-content a:hover {
    color: var(--primary-hover);
}

/* Empty Notifications State */
.empty-notifications {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted-color);
    opacity: 0.6;
}

.empty-notifications-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.empty-notifications-text {
    font-size: 16px;
    line-height: 1.6;
}


/* --- PURCHASE MODAL --- */
.purchase-game-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    flex-grow: 1; 
    min-height: 200px;
}

.purchase-game-item {
    background: var(--surface-color);
    border-radius: 12px;
    overflow: hidden;
    text-align: center;
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    height: 100%;
}

.purchase-game-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px var(--shadow-color);
    border-color: var(--primary-color);
}

.purchase-game-item img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.purchase-game-item h4 {
    font-size: 0.95rem; /* Compact font for grid */
    font-weight: 700;
    padding: 10px 8px;
    margin: 0;
    flex-grow: 1; /* Pushes content below */
    display: flex;
    align-items: center;
    justify-content: center;
    /* Limit height and text */
    min-height: 45px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
}

.purchase-game-item .btn {
    width: calc(100% - 16px);
    margin: 5px 8px 10px; /* Top margin ensures separation */
    text-decoration: none;
    padding: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0; /* Prevents button compression */
    justify-content: center;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap; /* Prevent wrapping */
    position: relative;
    z-index: 2;
}

.btn-buy-now {
    background: linear-gradient(135deg, #f5af19 0%, #f12711 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 10px rgba(245, 175, 25, 0.3);
}

.btn-buy-now:hover {
    box-shadow: 0 6px 15px rgba(241, 39, 17, 0.4);
    transform: translateY(-2px);
}

.purchase-game-item .btn.disabled {
    background: var(--border-color);
    color: var(--text-muted-color);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}


/* --- GAME INFO & CONFIRM MODALS --- */
.game-info-content { text-align: center; }
.game-info-logo {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 15px;
    margin-bottom: 20px;
    border: 2px solid var(--border-color);
}
#gameInfoDescription {
    color: var(--text-muted-color);
    line-height: 1.6;
    margin-bottom: 20px;
}
.game-info-details {
    background: var(--surface-color);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
}
.confirm-title { margin-bottom: 10px !important; }
.confirm-message {
    text-align: center;
    color: var(--text-muted-color);
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 25px;
}
/* .confirm-actions { justify-content: space-evenly !important; } - Removed to use new definition */

/* --- BETA REPORTING MODAL STYLES --- */
#reportModal .form-group {
    margin-bottom: 15px;
}
.report-textarea {
    width: 100%;
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    min-height: 100px;
}
.report-file-input {
    width: 100%;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

.report-image-preview {
    margin-top: 10px;
    position: relative;
    width: 100px;
    height: 100px;
}
.report-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.remove-preview-btn {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #d32f2f;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Rating Stars */
.rating-stars {
    display: flex;
    justify-content: center;
    flex-direction: row-reverse; /* To fill from right-to-left */
    font-size: 2.5rem;
}
.rating-stars span {
    cursor: pointer;
    color: var(--text-muted-color);
    transition: color 0.2s;
}
.rating-stars:hover span {
    color: #ffc107;
}
.rating-stars span:hover,
.rating-stars span:hover ~ span {
    color: #ffc107;
}


/* --- PRO UPGRADE MODAL --- */
#proUpgradeModal .btn-secondary {
    flex-grow: 1; /* Make "Learn More" button smaller */
}

#proUpgradeModal .btn-save {
    flex-grow: 2; /* Make "Start Game" button larger */
}


/* --- VERSION CHOICE MODAL --- */
#versionChoiceModal .confirm-actions .btn {
    width: 100%;
}

#versionChoiceModal .btn-secondary {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}


/* ===============================================
   🔧 إصلاحات الموبايل - التمرير الذكي
   =============================================== */
@media (max-width: 768px) {
    /* ✅ الإصلاح الأساسي: السماح بالتمرير داخل النوافذ المنبثقة */
    .modal-content {
        padding: 20px;
        max-height: 95vh;
        /* إزالة overflow-y: hidden وجعله auto */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
    }
    
    /* ✅ التأكد من أن العناصر الداخلية لا تتمدد خارج الحاوية */
    .modal-content > * {
        flex-shrink: 0;
    }
    
    .modal-content h3 {
        font-size: 1.2rem;
    }
    
    .settings-tabs {
        font-size: 0.8rem;
    }

    /* ✅ إصلاح قائمة الإشعارات */
    .notifications-list-container {
        /* السماح بالتمرير الكامل */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        /* ارتفاع ديناميكي بدلاً من max-height: none */
        max-height: 60vh !important;
        flex-grow: 1;
        flex-shrink: 1;
        min-height: 0;
    }
    
    .notification-item { 
        padding: 12px; 
    }
    
    .notification-content p,
    .notification-content b,
    .notification-content i,
    .notification-content a {
        font-size: 0.85rem;
        line-height: 1.4;
    }
    
    .notification-item .timestamp { 
        font-size: 0.7rem; 
    }

    /* ✅ إصلاح نافذة الإعدادات (المظهر) */
    #settingsForm {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        flex-grow: 1;
        flex-shrink: 1;
        min-height: 0;
        max-height: 60vh;
    }
    
    .settings-panel {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* ✅ إصلاح نافذة المتجر */
    #purchaseModal.modal.show { 
        padding: 0; 
    }
    
    #purchaseModal .modal-content {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        padding: 15px;
        padding-bottom: 0;
        overflow: hidden;
    }
    
    .purchase-game-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin: 0;
        padding: 10px 5px 150px;
        flex: 1 1 0;
        display: grid;
        overflow-y: scroll !important;
        -webkit-overflow-scrolling: touch;
        height: 100%;
        min-height: 0;
    }

    .purchase-game-item {
        height: auto; 
        min-height: 180px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        overflow: visible;
        position: relative;
        padding-bottom: 5px;
    }

    .purchase-game-item h4 {
        font-size: 0.75rem;
        padding: 5px;
        margin-bottom: 5px;
        line-height: 1.2;
        flex-grow: 0;
        min-height: auto;
    }

    .purchase-game-item .btn {
        margin-top: auto; 
        width: 90%;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 10px;
        padding: 6px;
        font-size: 0.75rem;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-shrink: 0;
        opacity: 1 !important;
        position: relative;
        z-index: 5;
    }
}