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

/* ========================================= */
/* 🛑 THEME VARIABLES & DESIGN TOKENS        */
/* ========================================= */
:root {
    /* Brand Theme Colors */
    --theme-primary: #0D47A1;
    --theme-secondary: #6f42c1;
    --theme-success: #28a745;
    --theme-danger: #dc3545;
    --theme-warning: #ffc107;
    --theme-info: #17a2b8;
    --theme-grey: #777777;

    /* Theme Layout Tokens */
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-panel: rgba(255, 255, 255, 0.08);
    --bg-input: #ffffff;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    --border-color: rgba(255, 255, 255, 0.15);
    --border-light: rgba(255, 255, 255, 0.1);

    /* Basic Colors */
    --basic-white: #ffffff;
    --basic-black: #000000;
    --basic-red: #ff0000;
    --basic-darkred: #D44638;
    --basic-green: #25D366;
    --basic-darkgreen: #28a745;
    --basic-darkgreen-2: #1e7e34;
    --basic-orange: #ffc107;
    --basic-darkorange: #f97316;
    --basic-blue: #007bff;
    --basic-darkblue: #0000ff;
    --basic-yellow: #ffff00;
    --basic-pink: #f8d7da;
    --basic-purple: #9c27b0;
    --basic-amber: #ff9800;
    --basic-lightblue: #2196f3;
    --basic-hotpink: #e83e8c;
    --basic-grey-alt: #6c757d;

    /* UI Neutral Scale */
    --basic-grey-w: #fff;
    --basic-grey-0: #ccc;
    --basic-grey-1: #aaa;
    --basic-grey-2: #999;
    --basic-grey-3: #888;
    --basic-grey-4: #777;
    --basic-grey-5: #666;
    --basic-grey-6: #555;
    --basic-grey-7: #444;
    --basic-grey-8: #333;
    --basic-grey-9: #222;
    --basic-grey-10: #111;
    --basic-grey-b: #000;

    /* Z-index Scale */
    --z-base: 1;
    --z-base1: 5;
    --z-base2: 10;
    --z-base3: 20;
    --z-base4: 100;
    --z-low1: 1000;
    --z-low2: 2000;
    --z-low2-5: 2500;
    --z-low3: 3000;
    --z-low3-5: 3500;
    --z-low3-6: 3600;
    --z-mid4: 4000;
    --z-mid4-5: 4500;
    --z-mid5: 5000;
    --z-mid5-5: 5500;
    --z-mid6: 6000;
    --z-mid6-5: 6500;
    --z-high7: 7000;
    --z-high8: 8000;
    --z-high9: 9000;
    --z-max: 9999;
    --z-top: 10000;

    /* Feedback & Box Colors */
    --text-success-dark: #155724;
    --text-warning-dark: #856404;
    --text-danger-dark: #721c24;
    --bg-info-light: rgba(23, 162, 184, 0.15);
    --border-info-light: rgba(23, 162, 184, 0.3);
    --bg-warning-light: rgba(255, 193, 7, 0.15);
    --border-warning-light: rgba(255, 193, 7, 0.3);
    --bg-light-hover: #f1f5f9;
}

/* ========================================= */
/* 🌐 RESET & GLOBAL STYLES                  */
/* ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Cairo', 'Tajawal', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: radial-gradient(circle at 50% 15%, #1e1b4b 0%, #0f172a 60%, #020617 100%);
    color: var(--text-main);
    min-height: 100vh;
    padding: 20px 15px;
    opacity: 0;
    transition: opacity 0.25s ease-in-out;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.app-ready {
    opacity: 1;
}

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

[dir="ltr"] {
    direction: ltr;
    text-align: left;
}

/* ========================================= */
/* 📱 MAIN CONTAINER & SCREENS               */
/* ========================================= */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    min-height: 90vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
}

.screen {
    display: none;
    width: 100%;
    animation: fadeInScreen 0.3s ease-out;
}

.screen.active {
    display: block;
}

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

/* ========================================= */
/* 🧭 TOP NAV & HEADERS                      */
/* ========================================= */
.top-nav-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
}

[dir="rtl"] .top-nav-bar {
    justify-content: flex-start;
}

.welcome-subtitle {
    text-align: center;
    margin-bottom: 5px;
    color: var(--text-muted);
    font-size: 1.4rem;
    font-weight: 700;
}

.main-title {
    font-size: 2.2rem;
    font-weight: 900;
    text-align: center;
    color: var(--basic-white);
    margin-bottom: 25px;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

/* ========================================= */
/* 📦 CARDS & INPUTS                         */
/* ========================================= */
.card {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 24px;
    padding: 32px 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.2);
    margin-bottom: 20px;
    box-sizing: border-box;
}

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

.input-field {
    width: 100%;
    padding: 14px 18px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
    font-size: 1.15rem;
    font-weight: 600;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
    text-align: center;
    box-sizing: border-box;
}

.input-field:focus {
    border-color: #3b82f6;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.35);
}

.code-box {
    margin: 20px 0;
    background: rgba(23, 162, 184, 0.15);
    padding: 20px 15px;
    border-radius: 16px;
    border: 1px solid rgba(23, 162, 184, 0.35);
    text-align: center;
}

.code-label {
    display: block;
    font-weight: 800;
    margin-bottom: 10px;
    color: #38bdf8;
    font-size: 1.15rem;
}

.code-input {
    letter-spacing: 5px;
    font-size: 1.6rem;
    font-weight: 900;
    font-family: 'Inter', monospace, sans-serif;
    color: var(--theme-primary);
}

.pin-box {
    margin: 20px 0;
    background: rgba(255, 193, 7, 0.15);
    padding: 20px 15px;
    border-radius: 16px;
    border: 1px solid rgba(255, 193, 7, 0.35);
    text-align: center;
}

.pin-label {
    display: block;
    font-weight: 800;
    margin-bottom: 10px;
    color: #fbbf24;
    font-size: 1.15rem;
}

.pin-input {
    letter-spacing: 6px;
    font-size: 1.6rem;
    font-weight: 900;
    font-family: 'Inter', monospace, sans-serif;
}

/* ========================================= */
/* 🔘 BUTTONS & INTERACTIONS                 */
/* ========================================= */
.btn-action {
    width: 100%;
    padding: 15px 24px;
    border-radius: 14px;
    border: none;
    font-size: 1.2rem;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-decoration: none;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35);
}

.btn-action:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.45);
}

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

.btn-green {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    color: var(--basic-white);
}

.btn-blue {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: var(--basic-white);
}

.btn-yellow {
    background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
    color: #ffffff;
}

.btn-red {
    background: linear-gradient(135deg, #b91c1c 0%, #ef4444 100%);
    color: #ffffff;
}

.btn-nav {
    background: rgba(255, 255, 255, 0.12);
    color: var(--basic-white);
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 10px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 700;
    font-family: inherit;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

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

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

/* ========================================= */
/* 🎮 GAMES LIST & SELECTION                 */
/* ========================================= */
.games-list-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
}

.game-select-btn {
    width: 100%;
    padding: 18px 22px;
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    font-size: 1.25rem;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
    box-sizing: border-box;
}

.game-select-btn:hover {
    transform: translateY(-3px) scale(1.01);
    background: #ffffff;
    border-color: #3b82f6;
    box-shadow: 0 12px 25px rgba(59, 130, 246, 0.3);
}

.lobby-game-logo, .welcome-game-logo, .ingame-logo {
    height: 48px;
    width: auto;
    object-fit: contain;
}

.welcome-game-logo {
    height: 80px;
    margin: 0 auto 20px auto;
    display: block;
}

.rules-box {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 22px;
    margin-bottom: 20px;
    font-size: 1.15rem;
    line-height: 1.7;
    color: #e2e8f0;
    text-align: start;
}

.welcome-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ========================================= */
/* ⏱️ GAME HUD & PROGRESS                    */
/* ========================================= */
.overall-timer-pill {
    background: rgba(220, 53, 69, 0.2);
    border: 1px solid rgba(220, 53, 69, 0.4);
    color: #f87171;
    padding: 8px 20px;
    border-radius: 30px;
    text-align: center;
    font-size: 1.15rem;
    font-weight: 800;
    margin-bottom: 15px;
    backdrop-filter: blur(8px);
}

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    margin-bottom: 15px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    width: 0%;
    transition: width 0.3s ease-out;
    border-radius: 10px;
}

.hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.hud-item {
    font-size: 1.25rem;
    font-weight: 800;
    color: #94a3b8;
}

.hud-timer {
    color: #fbbf24;
}

.hud-score {
    color: #38bdf8;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.question-text {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--basic-white);
    margin-bottom: 15px;
    line-height: 1.4;
    text-align: center;
}

.question-attached-image {
    max-width: 100%;
    max-height: 250px;
    object-fit: contain;
    border-radius: 14px;
    margin: 0 auto 20px auto;
    display: block;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.multi-select-hint {
    text-align: center;
    color: #fbbf24;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 15px;
}

/* ========================================= */
/* 🧩 OPTIONS & INPUTS                       */
/* ========================================= */
.v1-options-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.option-btn {
    width: 100%;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
    border: 3px solid transparent;
    border-radius: 16px;
    font-size: 1.2rem;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
    text-align: start;
    box-sizing: border-box;
}

.option-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    background: #ffffff;
    border-color: #3b82f6;
}

.option-btn.selected {
    background: #1e40af !important;
    color: #ffffff !important;
    border-color: #60a5fa !important;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.4);
}

.option-btn.correct {
    background: #059669 !important;
    color: #ffffff !important;
    border-color: #34d399 !important;
}

.option-btn.wrong {
    background: #dc2626 !important;
    color: #ffffff !important;
    border-color: #f87171 !important;
}

.tf-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.tf-btn {
    text-align: center;
    padding: 24px 15px;
    font-size: 1.4rem;
}

.fib-container {
    margin: 20px 0;
}

.fib-input {
    width: 100%;
    padding: 16px 20px;
    border-radius: 14px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    background: #ffffff;
    color: #0f172a;
    font-size: 1.3rem;
    font-weight: 800;
    text-align: center;
    box-sizing: border-box;
}

.fib-input.correct-input {
    border-color: #10b981;
    background: #ecfdf5;
    color: #065f46;
}

.fib-input.wrong-input {
    border-color: #ef4444;
    background: #fef2f2;
    color: #991b1b;
}

/* ========================================= */
/* 💬 FEEDBACK & ACTION ROWS                 */
/* ========================================= */
.feedback-box {
    border-radius: 16px;
    padding: 18px 22px;
    margin-bottom: 20px;
    font-size: 1.15rem;
    line-height: 1.6;
    animation: fadeInScreen 0.25s ease;
}

.feedback-box.show-correct {
    background: #d4edda;
    border: 2px solid #c3e6cb;
    color: #155724;
}

.feedback-box.show-wrong {
    background: #f8d7da;
    border: 2px solid #f5c6cb;
    color: #721c24;
}

.game-action-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nav-btn-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.nav-btn-row > * {
    flex: 1;
}

/* ========================================= */
/* 🏁 RESULT & STATS SCREEN                  */
/* ========================================= */
.final-player-name {
    font-size: 2rem;
    font-weight: 900;
    color: #ffffff;
    margin-bottom: 20px;
    text-align: center;
}

.trivia-stats-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    margin: 20px 0;
}

.final-score-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 15px 35px rgba(37, 99, 235, 0.4);
    border: 4px solid rgba(255, 255, 255, 0.3);
}

#final-score-display {
    font-size: 3rem;
    font-weight: 900;
    line-height: 1;
    color: #ffffff;
}

.final-score-unit {
    font-size: 1rem;
    font-weight: 800;
    color: #bfdbfe;
    letter-spacing: 2px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    width: 100%;
}

.stat-box {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 16px 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-num {
    font-size: 1.8rem;
    font-weight: 900;
}

.stat-label {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 700;
}

.stat-correct-color { color: #34d399; }
.stat-wrong-color { color: #f87171; }
.stat-skipped-color { color: #fbbf24; }
.stat-time-color { color: #38bdf8; }

.review-highlight {
    font-size: 1.8rem;
    font-weight: 900;
    color: #fbbf24;
    text-align: center;
    margin-bottom: 10px;
}

.review-submessage {
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 25px;
}

.review-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ========================================= */
/* 📱 RESPONSIVE ADJUSTMENTS                 */
/* ========================================= */
@media (max-width: 480px) {
    .card {
        padding: 24px 18px;
    }

    .main-title {
        font-size: 1.8rem;
    }

    .question-text {
        font-size: 1.35rem;
    }

    .option-btn {
        font-size: 1.1rem;
        padding: 14px 16px;
    }
}

/* ========================================= */
/* 🌟 APP PRELOADER & SEAMLESS TRANSITIONS   */
/* ========================================= */
.app-preloader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.app-preloader.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.preloader-spinner {
    width: 44px;
    height: 44px;
    border: 3.5px solid rgba(255, 255, 255, 0.15);
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: preloaderSpin 0.75s linear infinite;
}

.preloader-text {
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    opacity: 0.85;
}

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

