:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --error: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Dynamic Background */
#dynamic-bg {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: radial-gradient(circle at 50% 50%, #1e293b 0%, #020617 100%);
    z-index: -1;
}
#dynamic-bg::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: url('data:image/svg+xml;utf8,<svg width="20" height="20" xmlns="http://www.w3.org/2000/svg"><circle cx="2" cy="2" r="1" fill="rgba(255,255,255,0.05)"/></svg>');
    opacity: 0.5;
}

/* App Container */
#app {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 100vh;
    max-height: 800px;
}

/* Screens */
.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    transform: scale(0.95);
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    z-index: 10;
}

/* Glass Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    width: 100%;
    animation: floatUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.game-panel {
    padding: 30px;
    margin-top: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Typography & Elements */
h1 { font-size: 2.5rem; font-weight: 800; margin-bottom: 10px; letter-spacing: 2px; }
h2 { font-size: 1.8rem; font-weight: 600; margin-bottom: 20px; }
p { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 15px; }

.glow-text {
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.6);
    color: #fff;
}
.highlight { color: var(--accent); font-weight: bold; }

.input-field {
    width: 100%;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.3);
    color: white;
    font-size: 1.1rem;
    text-align: center;
    outline: none;
    transition: border 0.3s, box-shadow 0.3s;
}
.input-field:focus {
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

/* Buttons */
.button-group { display: flex; flex-direction: column; gap: 15px; margin-top: 20px; }
button {
    padding: 15px 25px;
    border-radius: 10px;
    border: none;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.primary-btn {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}
.primary-btn:hover { background: var(--accent-hover); transform: translateY(-2px); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { background: #475569; pointer-events: none; opacity: 0.7; }

.secondary-btn {
    background: transparent;
    color: white;
    border: 1px solid var(--glass-border);
}
.secondary-btn:hover { background: rgba(255,255,255,0.1); }

/* Game UI */
.hud {
    width: 100%;
    display: flex;
    justify-content: space-between;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 15px;
    padding: 15px 20px;
    backdrop-filter: blur(10px);
}
.hud-item { display: flex; flex-direction: column; align-items: center; }
.hud-item .label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; letter-spacing: 1px; }
.hud-item .value { font-size: 1.3rem; font-weight: 800; }
.timer-active .value { color: var(--accent); }

.time-warning .value { color: var(--error); animation: pulse 1s infinite alternate; }

.question-container {
    margin-bottom: 30px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.question-container h2 { margin: 0; font-size: 1.6rem; line-height: 1.4; color: white; }

.options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}
.option-btn {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--glass-border);
    color: white;
    text-align: left;
    padding: 18px 20px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 400;
    transition: all 0.2s;
    position: relative;
    padding-left: 50px;
}
.option-btn::before {
    content: attr(data-index);
    position: absolute;
    left: 15px; top: 50%; transform: translateY(-50%);
    background: rgba(255,255,255,0.1);
    width: 25px; height: 25px;
    border-radius: 5px;
    display: flex; justify-content: center; align-items: center;
    font-size: 0.9rem; font-weight: bold; color: var(--accent);
}
.option-btn:hover { background: rgba(59, 130, 246, 0.2); border-color: rgba(59, 130, 246, 0.5); transform: scale(1.02); }
.option-btn.selected { background: var(--accent); border-color: var(--accent); color: white; }
.option-btn.selected::before { background: rgba(0,0,0,0.2); color: white; }
.option-btn.correct { background: var(--success); border-color: var(--success); }
.option-btn.wrong { background: var(--error); border-color: var(--error); }

/* Loader */
.loader {
    border: 4px solid rgba(255,255,255,0.1);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 40px; height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px auto;
}
.loader.sm { width: 30px; height: 30px; border-width: 3px; }

/* Feedback */
#feedback-title { font-size: 3rem; margin-bottom: 5px; text-shadow: 0 0 20px rgba(0,0,0,0.5); }
#feedback-desc { font-size: 1.5rem; font-weight: bold; margin-bottom: 20px;}

.feedback-success #feedback-title { color: var(--success); text-shadow: 0 0 20px var(--success); }
.feedback-success #feedback-desc { color: var(--success); }
.feedback-success .loader { border-top-color: var(--success); }

.feedback-error #feedback-title { color: var(--error); text-shadow: 0 0 20px var(--error); }
.feedback-error #feedback-desc { color: var(--error); }
.feedback-error .loader { border-top-color: var(--error); }

/* Stats & Leaderboard */
.stat-circle {
    width: 150px; height: 150px;
    border-radius: 50%;
    background: conic-gradient(var(--accent) 0%, rgba(255,255,255,0.1) 0%);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    margin: 0 auto 30px auto;
    position: relative;
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.3);
}
.stat-circle::after {
    content: ''; position: absolute;
    width: 130px; height: 130px; border-radius: 50%;
    background: var(--bg-secondary);
    z-index: 1;
}
.stat-circle span { position: relative; z-index: 2; }
.score-num { font-size: 3.5rem; font-weight: 900; line-height: 1; }
.score-label { font-size: 0.9rem; color: var(--text-muted); font-weight: 600; margin-top: 5px;}

/* Leaderboard Tabs */
.tabs { display: flex; background: rgba(0,0,0,0.3); border-radius: 10px; padding: 5px; margin-bottom: 20px; }
.tab-btn { flex: 1; padding: 10px; background: transparent; font-size: 0.9rem; color: var(--text-muted); border-radius: 8px; }
.tab-btn.active { background: rgba(255,255,255,0.1); color: white; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }

.tab-content { display: none; text-align: left; max-height: 300px; overflow-y: auto; padding-right: 10px;}
.tab-content.active { display: block; animation: fadeIn 0.3s; }

/* Scrollbar styling */
.tab-content::-webkit-scrollbar { width: 6px; }
.tab-content::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 10px;}
.tab-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px;}
.tab-content::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

.lb-list { list-style: none; }
.lb-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px; border-bottom: 1px solid var(--glass-border);
}
.lb-item:last-child { border-bottom: none; }
.lb-rank { font-weight: 900; width: 30px; color: var(--text-muted); font-size: 1.2rem;}
.lb-name { flex: 1; font-weight: 600; font-size: 1.1rem; }
.lb-score { font-weight: 800; color: var(--accent); font-size: 1.2rem; }
.lb-item.is-me { background: rgba(59, 130, 246, 0.15); border-radius: 8px; border: 1px solid rgba(59, 130, 246, 0.3); }

/* Personal Records */
.personal-record { background: rgba(0,0,0,0.2); padding: 20px; border-radius: 12px; margin-bottom: 15px; text-align: center; }
.personal-record h3 { font-size: 1rem; color: var(--text-muted); margin-bottom: 10px; }
.personal-record .score { font-size: 2.5rem; font-weight: 800; color: white; line-height:1;}
.personal-record .score .date { font-size: 0.9rem; color: var(--text-muted); font-weight:normal; margin-left:10px; }
.personal-record .category { color: var(--accent); margin-top:5px; font-weight:bold; }

.personal-record.best { border: 1px solid var(--success); }
.personal-record.best .score { color: var(--success); }
.personal-record.worst { border: 1px solid var(--error); }
.personal-record.worst .score { color: var(--error); }


/* Utils */
.hidden { display: none !important; }
.mt-2 { margin-top: 20px; }
.alert-msg { background: rgba(239, 68, 68, 0.2); color: #fca5a5; padding: 10px; border-radius: 8px; border: 1px solid rgba(239, 68, 68, 0.4); font-size: 0.9rem;}

/* Animations */
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes floatUp { 0% { opacity: 0; transform: translateY(20px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { 0% { opacity: 0; } 100% { opacity: 1; } }
@keyframes pulse { 0% { opacity: 1; } 100% { opacity: 0.6; } }

/* Confetti */
#confetti-canvas { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 100; }
