@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&family=Nunito:wght@400;600;700&display=swap');

:root {
    --primary-color: #FF6B6B;
    --secondary-color: #4ECDC4;
    --accent-color: #FFD93D;
    --dark-color: #2D3436;
    --light-color: #F7F1E3;
    --white: #FFFFFF;
    --shadow: 0 8px 16px rgba(0,0,0,0.1);
}

body {
    font-family: 'Nunito', 'Cairo', sans-serif;
    direction: rtl;
    text-align: center;
    background: linear-gradient(135deg, var(--light-color) 0%, var(--secondary-color) 100%);
    margin: 0;
    padding: 20px;
    min-height: 100vh;
}

.container {
    max-width: 900px;
    margin: auto;
    background: var(--white);
    padding: 30px;
    border-radius: 20px;
    box-shadow: var(--shadow);
}

h1, h2, h3 { font-family: 'Cairo', sans-serif; color: var(--dark-color); }
h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; color: var(--primary-color); }

.btn {
    background: var(--primary-color);
    color: var(--white);
    border: none;
    padding: 12px 25px;
    border-radius: 50px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    margin: 5px;
}
.btn:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
.btn-secondary { background: var(--secondary-color); }
.btn-accent { background: var(--accent-color); color: var(--dark-color); }

.form-group { margin-bottom: 20px; text-align: right; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; }
.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 10px;
    box-sizing: border-box;
    font-size: 1rem;
}
.form-group input:focus { border-color: var(--secondary-color); outline: none; }

.card {
    background: var(--white);
    border-radius: 15px;
    padding: 20px;
    margin: 20px 0;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    border-left: 5px solid var(--accent-color);
}

.lesson-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.quiz-container {
    position: relative;
}
.question-panel {
    border: 2px solid var(--secondary-color);
    background: #F0FFFF;
    padding: 25px;
    border-radius: 15px;
    margin: 20px 0;
    display: none;
}
.question-panel.active { display: block; }
.question-options label {
    display: block;
    background: var(--light-color);
    border: 2px solid transparent;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: right;
}
.question-options label:hover { border-color: var(--accent-color); transform: scale(1.02); }
.question-options input[type="radio"] { margin-left: 10px; }

/* Feedback */
.feedback-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: var(--white);
    padding: 30px 50px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 2000;
    font-size: 2rem;
    font-weight: 700;
    transition: transform 0.3s ease;
}
.feedback-popup.show { transform: translate(-50%, -50%) scale(1); }
.feedback-popup.correct { color: var(--secondary-color); border: 5px solid var(--secondary-color); }
.feedback-popup.wrong { color: var(--primary-color); border: 5px solid var(--primary-color); }

/* Leaderboard */
.leaderboard {
    position: fixed;
    top: 120px;
    left: 20px;
    width: 320px;
    background: var(--white);
    border-radius: 15px;
    box-shadow: var(--shadow);
    z-index: 1500;
    padding: 20px;
    cursor: move;
    border: 3px solid var(--accent-color);
}
.leaderboard h3 { margin-top: 0; color: var(--dark-color); }
.leaderboard-list { list-style: none; padding: 0; }
.leaderboard-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: var(--light-color);
    margin-bottom: 5px;
    border-radius: 8px;
    font-weight: 600;
}
.leaderboard-list .rank { font-weight: 700; color: var(--primary-color); }

/* Admin Table */
.admin-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.admin-table th, .admin-table td {
    padding: 12px;
    border: 1px solid #ddd;
    text-align: center;
}
.admin-table th { background: var(--secondary-color); color: var(--white); }

/* --- Tab System Styles --- */
.tab-navigation {
    display: flex;
    justify-content: center;
    border-bottom: 3px solid var(--secondary-color);
    margin-bottom: 0;
    background: var(--white);
    border-radius: 15px 15px 0 0;
    padding-top: 10px;
}
.tab-button {
    background: var(--light-color);
    border: none;
    padding: 12px 25px;
    margin: 0 5px;
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    color: var(--dark-color);
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}
.tab-button:hover {
    background: var(--secondary-color);
    color: var(--white);
}
.tab-button.active {
    background: var(--secondary-color);
    color: var(--white);
    border-bottom: 3px solid var(--accent-color);
}
.tab-content {
    background: var(--white);
    border-radius: 0 0 15px 15px;
    padding: 0;
    border: 3px solid var(--secondary-color);
    border-top: none;
}
.tab-panel {
    display: none;
    padding: 20px;
}
.tab-panel.active {
    display: block;
}
.tab-panel p {
    text-align: right;
    line-height: 1.8;
}


/* =================================================================== */
/* ==                       Responsive Design                        == */
/* =================================================================== */

/* --- For Tablets and smaller screens --- */
@media (max-width: 768px) {
    body {
        padding: 15px;
    }
    .container {
        padding: 20px;
        border-radius: 15px;
    }
    h1 { font-size: 2.2rem; }
    h2 { font-size: 1.8rem; }

    .lesson-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 15px;
    }

    /* Make leaderboard take full width and not fixed */
    .leaderboard {
        position: static;
        width: 100%;
        margin-top: 20px;
    }

    /* Allow tabs to wrap if needed */
    .tab-navigation {
        flex-wrap: wrap;
    }
}

/* --- For Mobile phones --- */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    .container {
        padding: 15px;
        border-radius: 10px;
    }
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.5rem; }

    .btn {
        font-size: 0.9rem;
        padding: 10px 20px;
        display: block; /* Make buttons full width on small screens */
        width: 100%;
        margin: 10px 0;
    }
    .btn:hover {
        transform: none; /* Remove hover effect for touch devices */
    }

    .form-group input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .card {
        padding: 15px;
    }

    .lesson-grid {
        grid-template-columns: 1fr; /* Force single column layout */
        gap: 15px;
    }

    /* Stack tabs vertically */
    .tab-navigation {
        flex-direction: column;
        border-bottom: none;
        border-right: 3px solid var(--secondary-color);
        border-radius: 0 15px 15px 0;
        padding-top: 0;
        padding-right: 0;
    }
    .tab-button {
        margin: 5px 0;
        border-radius: 0 10px 10px 0;
        border-bottom: none;
        border-right: 3px solid transparent;
    }
    .tab-button.active {
        border-right: 3px solid var(--accent-color);
    }
    .tab-content {
        border-radius: 15px;
        border: 3px solid var(--secondary-color);
    }

    /* Feedback popup adjustments */
    .feedback-popup {
        font-size: 1.5rem;
        padding: 20px 30px;
        width: 90%;
    }
}


/* =================================================================== */
/* ==                       Table Responsiveness                      == */
/* ==  (You need to wrap your tables in a div with class="table-wrapper") == */
/* =================================================================== */

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* for smooth scrolling on iOS */
}

@media (max-width: 600px) {
    /* On small screens, make table cells stack */
    .admin-table,
    .admin-table thead,
    .admin-table tbody,
    .admin-table th,
    .admin-table td,
    .admin-table tr {
        display: block;
    }

    .admin-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .admin-table tr {
        border: 1px solid #ccc;
        margin-bottom: 10px;
        border-radius: 8px;
    }

    .admin-table td {
        border: none;
        border-bottom: 1px solid #eee;
        position: relative;
        padding-left: 50%;
        text-align: right;
    }

    .admin-table td:before {
        position: absolute;
        top: 12px;
        right: 12px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: bold;
        content: attr(data-label); /* Use data-label to show column name */
    }
}