:root {
    --bg-light: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.75);
    --border-color: rgba(0, 0, 0, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent-primary: #059669; /* Emerald */
    --accent-secondary: #2563eb; /* Blue */
    --font-main: 'Outfit', 'Tajawal', sans-serif;
    --glow: 0 5px 15px rgba(5, 150, 105, 0.2);
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-light);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(16, 185, 129, 0.1), transparent 25%),
        radial-gradient(circle at 90% 80%, rgba(59, 130, 246, 0.1), transparent 25%);
    transition: all 0.3s ease;
}

[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .alert-box {
    border-left: none;
    border-right: 4px solid var(--accent-secondary);
    border-radius: 8px 0 0 8px;
    text-align: right;
}

[dir="rtl"] .input-group input {
    text-align: right;
}

[dir="rtl"] .dash-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .module-input input {
    text-align: left; /* Keep numbers LTR even in RTL usually, but left align looks ok */
}

.lang-switcher {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

[dir="rtl"] .lang-switcher {
    right: auto;
    left: 1rem;
}

.lang-switcher select {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-weight: 600;
    cursor: pointer;
    outline: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.hidden {
    display: none !important;
}

/* --- Screens & Transitions --- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    min-height: 100vh;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    position: relative;
    z-index: 10;
}

/* --- Welcome Screen --- */
#welcome-screen {
    cursor: pointer;
}

.welcome-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.logos {
    display: flex;
    gap: 3rem;
    margin-bottom: 2rem;
    animation: fadeInDown 1s ease-out;
}

.logo {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.iav-logo {
    background: linear-gradient(to right, #2563eb, #7c3aed);
    -webkit-background-clip: text;
}

.welcome-text {
    font-size: 4rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: float 6s ease-in-out infinite;
    text-shadow: 0 5px 15px rgba(0,0,0,0.1);
    color: var(--text-primary);
}

.click-prompt {
    font-size: 1.2rem;
    color: var(--text-secondary);
    animation: pulse 2s infinite;
    margin-top: 2rem;
}

/* --- Glassmorphism Utils --- */
.glass-card, .glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 3rem;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
}

/* --- Auth Screen --- */
#auth-screen .glass-card {
    width: 100%;
    max-width: 450px;
    animation: slideUp 0.8s ease-out forwards;
}

#auth-title {
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
    font-weight: 600;
}

.input-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input {
    width: 100%;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
    background: #fff;
}

.btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s ease;
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent-primary), #047857);
    color: white;
    margin-top: 1rem;
    box-shadow: 0 4px 6px rgba(5, 150, 105, 0.2);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow);
}

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

.toggle-auth {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.toggle-auth a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s;
}

.toggle-auth a:hover {
    color: #047857;
}

/* --- Dashboard --- */
.dashboard-container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.dash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    animation: fadeIn 1s ease-out;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.text-btn {
    background: transparent;
    color: var(--accent-primary);
    padding: 0.5rem 1rem;
    width: auto;
    border: 1px solid var(--accent-primary);
}

.text-btn:hover {
    background: var(--accent-primary);
    color: white;
}

.glass-panel {
    padding: 2rem;
    animation: slideUp 0.8s ease-out both;
}

h3 {
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent-primary);
}

/* File Upload */
.file-drop-area {
    border: 2px dashed rgba(0, 0, 0, 0.15);
    border-radius: 16px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    background: rgba(255, 255, 255, 0.4);
}

.file-drop-area:hover, .file-drop-area.dragover {
    border-color: var(--accent-primary);
    background: rgba(16, 185, 129, 0.05);
}

.drop-text {
    font-size: 1.1rem;
    color: var(--text-secondary);
    pointer-events: none;
}

#screenshot-upload {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

#upload-status {
    margin-top: 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--accent-primary);
}

/* Modules Grid */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.module-input {
    background: rgba(255, 255, 255, 0.6);
    padding: 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.module-input:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

.module-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
}

.mod-name {
    font-weight: 600;
    color: var(--text-primary);
}

.mod-coeff {
    color: var(--accent-secondary);
    font-size: 0.85rem;
    background: rgba(37, 99, 235, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-weight: 500;
}

.module-input input {
    padding: 0.8rem;
    font-size: 1.15rem;
    font-weight: 600;
    text-align: right;
    background: #fff;
}

[dir="rtl"] .module-input input {
    text-align: left;
}

.calculate-btn {
    max-width: 300px;
    margin: 0 auto;
    display: block;
}

/* Results Section */
.results-section {
    text-align: center;
    background: linear-gradient(180deg, var(--bg-card) 0%, rgba(16, 185, 129, 0.05) 100%);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.moyenne-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 2rem 0;
}

.moyenne-label {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.moyenne-value {
    font-size: 4.5rem;
    font-weight: 800;
    color: var(--accent-primary);
    text-shadow: 0 4px 10px rgba(5, 150, 105, 0.1);
    animation: scaleIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.alert-box {
    background: rgba(37, 99, 235, 0.05);
    border-left: 4px solid var(--accent-secondary);
    padding: 1.2rem;
    border-radius: 0 8px 8px 0;
    text-align: left;
    margin-top: 1rem;
}

.alert-box.info-alert {
    color: #1e3a8a; /* darker blue for light theme alert text */
}

/* --- Footer --- */
footer {
    margin-top: auto;
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(5px);
}

footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
}

footer a:hover {
    text-decoration: underline;
}

/* --- AI Spinner --- */
.ai-spinner {
    width: 64px;
    height: 64px;
    border: 6px solid rgba(16, 185, 129, 0.2);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin: 0 auto;
}

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

/* --- Form Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-overlay.active.hidden {
    display: flex !important; /* Override standard hidden if toggled via JS securely */
    visibility: visible;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    max-width: 500px;
    width: 90%;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: var(--bg-light);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

[dir="rtl"] .modal-content {
    text-align: right;
}

[dir="rtl"] .modal-actions {
    flex-direction: row-reverse;
}

/* --- Animated Cute Bot --- */
.bot-container {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    pointer-events: none;
}

[dir="rtl"] .bot-container {
    left: auto;
    right: 2rem;
    flex-direction: row-reverse;
}

.cute-bot {
    cursor: pointer;
    pointer-events: auto;
    animation: botFloat 4s ease-in-out infinite;
    filter: drop-shadow(0 10px 15px rgba(5, 150, 105, 0.3));
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cute-bot:hover {
    transform: scale(1.1) translateY(-5px);
}

.bot-bubble {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 2px solid var(--accent-primary);
    padding: 1rem 1.5rem 1rem 1.2rem;
    border-radius: 20px 20px 20px 0;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    max-width: 280px;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary);
    pointer-events: auto;
    position: relative;
    animation: bubblePop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-bottom: 20px;
}

[dir="rtl"] .bot-bubble {
    border-radius: 20px 20px 0 20px;
}

#bot-close-btn {
    position: absolute;
    top: 5px;
    right: 8px;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s;
}

[dir="rtl"] #bot-close-btn {
    right: auto;
    left: 8px;
}

#bot-close-btn:hover {
    color: var(--accent-primary);
}

.antenna-bulb {
    animation: pulseBulb 2s infinite;
}

.bot-eye {
    animation: botBlink 4s infinite;
    transform-origin: center;
}

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

@keyframes botBlink {
    0%, 96%, 98%, 100% { transform: scaleY(1); }
    97%, 99% { transform: scaleY(0.1); }
}

@keyframes pulseBulb {
    0% { fill: var(--accent-secondary); opacity: 1; }
    50% { fill: #fff; opacity: 0.5; }
    100% { fill: var(--accent-secondary); opacity: 1; }
}

@keyframes bubblePop {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* --- Animations --- */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-30px); }
    to { opacity: 1; transform: translateY(0); }
}

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

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

@keyframes pulse {
    0% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}

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

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
    .welcome-text { font-size: 2.2rem; }
    .glass-card, .glass-panel { padding: 2rem; }
    .dash-header { flex-direction: column; gap: 1rem; text-align: center; }
}

/* Admin Dashboard */
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.admin-actions {
    display: flex;
    gap: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-item span {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
}

.stat-item label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.admin-table-container {
    overflow-x: auto;
    margin-top: 1rem;
}

#admin-ranking-table {
    width: 100%;
    border-collapse: collapse;
}

#admin-ranking-table th, 
#admin-ranking-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#admin-ranking-table th {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    font-size: 0.8rem;
    font-weight: 700;
}

.rank-1 .rank-badge { background: #FFD700; color: #000; }
.rank-2 .rank-badge { background: #C0C0C0; color: #000; }
.rank-3 .rank-badge { background: #CD7F32; color: #000; }

.view-details-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 6px;
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--accent-primary);
    border: 1px solid rgba(var(--primary-rgb), 0.2);
    cursor: pointer;
    transition: all 0.2s;
}

.view-details-btn:hover {
    background: var(--accent-primary);
    color: #fff;
}

/* Wide Modal for Details */
.modal-content.wide {
    max-width: 800px;
    width: 95%;
}

.detail-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    padding: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-row.header {
    color: var(--text-secondary);
    font-weight: 600;
}

