:root {
    --bg: #46178f;
    --bg-2: #7c3aed;
    --text: #ffffff;
    --accent: #ffd60a;
    --opt-a: #e21b3c;
    --opt-b: #1368ce;
    --opt-c: #d89e00;
    --opt-d: #26890c;
    --success: #26890c;
    --danger: #e21b3c;
    --radius: 16px;
    --shadow: 0 12px 36px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at 30% 20%, var(--bg-2) 0%, var(--bg) 50%, #2d0e5e 100%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.screen {
    display: none;
    min-height: 100vh;
    padding: 24px 16px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.screen.active { display: flex; }

.card {
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(10px);
    border-radius: var(--radius);
    padding: 32px 28px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255,255,255,0.12);
    width: 100%;
    max-width: 420px;
    text-align: center;
}
.card .logo { font-size: 56px; margin-bottom: 8px; }
.card h1, .card h2 { margin: 0 0 20px 0; }
.card h1 { font-size: 28px; }
.card h2 { font-size: 22px; }
.card p { color: rgba(255,255,255,0.85); margin: 8px 0 16px 0; }

.card input {
    width: 100%;
    background: rgba(255,255,255,0.95);
    color: #1a1a1a;
    border: none;
    padding: 14px 16px;
    border-radius: 10px;
    font-size: 16px;
    margin-bottom: 12px;
    font-family: inherit;
}
.card input:focus { outline: 3px solid var(--accent); }
.card #pin { letter-spacing: 8px; text-align: center; font-weight: 700; font-size: 20px; }

.btn {
    border: none;
    border-radius: 10px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: transform .15s, box-shadow .15s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.25); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
    background: var(--accent);
    color: #1a1a1a;
}
.btn.big { padding: 16px 28px; font-size: 18px; width: 100%; }

/* ---------- Client CAPTCHA ---------- */
.captcha-box {
    background: rgba(255,214,10,0.08);
    border: 2px solid rgba(255,214,10,0.3);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    text-align: center;
    animation: captchaSlideIn 0.3s ease;
}
@keyframes captchaSlideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.captcha-shield {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}
.captcha-question {
    font-size: 26px;
    font-weight: 800;
    font-family: 'Courier New', monospace;
    color: white;
    margin-bottom: 10px;
}
.captcha-box input {
    width: 100%;
    background: rgba(255,255,255,0.95);
    color: #1a1a1a;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 18px;
    text-align: center;
    letter-spacing: 4px;
    font-weight: 700;
}
.captcha-box input:focus { outline: 3px solid var(--accent); }

.error {
    color: #ffb4b4;
    background: rgba(226,27,60,0.25);
    padding: 10px;
    border-radius: 8px;
    margin-top: 12px;
    min-height: 20px;
    font-size: 14px;
}
.error:empty { display: none; }

.spinner {
    width: 56px;
    height: 56px;
    border: 5px solid rgba(255,255,255,0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Question screen ---------- */
#screenQuestion {
    justify-content: flex-start;
    padding-top: 16px;
}

.q-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 760px;
    margin-bottom: 14px;
    font-weight: 700;
}
.q-pos { font-size: 14px; opacity: 0.9; }
.q-timer {
    background: var(--accent);
    color: #1a1a1a;
    padding: 8px 18px;
    border-radius: 999px;
    font-size: 22px;
    min-width: 60px;
    text-align: center;
    transition: background 0.5s ease, color 0.5s ease, transform 0.3s ease;
}
.q-timer.warning {
    background: #ff8c00;
    color: white;
}
.q-timer.danger {
    background: #e63946;
    color: white;
    animation: pulse 0.8s infinite alternate;
}
.q-timer.critical {
    background: #b71c1c;
    color: white;
    animation: pulse 0.4s infinite alternate;
    font-size: 26px;
}
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.15); } }

.q-text {
    background: rgba(0,0,0,0.25);
    padding: 24px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 760px;
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 18px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.q-options {
    width: 100%;
    max-width: 760px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.opt {
    border: none;
    border-radius: var(--radius);
    padding: 22px 18px;
    color: white;
    font-size: 17px;
    font-weight: 600;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    display: grid;
    grid-template-columns: 44px 1fr;
    align-items: center;
    gap: 14px;
    transition: transform .15s;
    min-height: 90px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}
.opt:hover:not(:disabled) { transform: scale(1.02); }
.opt:active:not(:disabled) { transform: scale(0.98); }
.opt:disabled { opacity: 0.55; cursor: not-allowed; }
.opt .letter {
    width: 44px;
    height: 44px;
    background: rgba(0,0,0,0.25);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 22px;
}
.opt-a { background: var(--opt-a); }
.opt-b { background: var(--opt-b); }
.opt-c { background: var(--opt-c); }
.opt-d { background: var(--opt-d); }

.opt.selected {
    outline: 4px solid var(--accent);
    transform: scale(1.02);
}

.q-status {
    width: 100%;
    max-width: 760px;
    text-align: center;
    margin-top: 18px;
    font-size: 15px;
    min-height: 22px;
    opacity: 0.9;
}
.q-status.correct { color: var(--accent); font-weight: 700; }
.q-status.wrong { color: #ffb4b4; font-weight: 700; }

.score-box {
    background: rgba(255,214,10,0.2);
    border: 2px solid var(--accent);
    color: var(--accent);
    padding: 14px;
    border-radius: 10px;
    font-size: 18px;
    margin-top: 16px;
}
.score-box strong { font-size: 28px; }

/* ---------- Leaderboard wait ---------- */
.leaderboard-wait {
    color: rgba(255,255,255,0.6);
    font-size: 14px;
    animation: blink 1.5s ease-in-out infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- Leaderboard Screen ---------- */
#screenLeaderboard { padding: 16px; }

.leaderboard-container {
    width: 100%;
    max-width: 560px;
}

.lb-header {
    text-align: center;
    margin-bottom: 16px;
}
.lb-trophy {
    font-size: 56px;
    animation: trophyBounce 1s ease;
}
@keyframes trophyBounce {
    0% { transform: scale(0) rotate(-20deg); opacity: 0; }
    50% { transform: scale(1.2) rotate(5deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.lb-header h2 { margin: 4px 0 0; font-size: 24px; }
.lb-subtitle { color: rgba(255,255,255,0.7); margin: 4px 0 0; font-size: 14px; }

.lb-your-score {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,214,10,0.15);
    border: 2px solid var(--accent);
    border-radius: 12px;
    padding: 14px 20px;
    margin-bottom: 20px;
}
.lb-score-label { font-size: 16px; font-weight: 600; }
.lb-score-value { font-size: 28px; font-weight: 800; color: var(--accent); }

/* Leaderboard rows */
.lb-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.lb-row {
    display: grid;
    grid-template-columns: 44px 1fr auto auto;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.06);
    border-radius: 10px;
    padding: 12px 14px;
    animation: slideInRow 0.5s ease both;
    border: 2px solid transparent;
}

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

/* Current user's row - special glow animation */
.lb-row-me {
    background: rgba(255,214,10,0.12);
    border: 2px solid var(--accent);
    animation: slideInRow 0.5s ease both, glowPulse 2s ease-in-out infinite 0.8s;
    position: relative;
}
.lb-row-me::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 12px;
    background: linear-gradient(45deg, var(--accent), #ff6b35, var(--accent), #26890c);
    background-size: 300% 300%;
    animation: borderShift 3s ease infinite;
    z-index: -1;
}
.lb-row-me::after {
    content: '← Sen';
    position: absolute;
    right: -52px;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    animation: arrowBounce 1s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes glowPulse {
    0%, 100% { box-shadow: 0 0 8px rgba(255,214,10,0.3); }
    50% { box-shadow: 0 0 20px rgba(255,214,10,0.6); }
}
@keyframes borderShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
@keyframes arrowBounce {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(6px); }
}

/* Medals & Rank */
.lb-medal {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
    color: #1a1a1a;
}
.lb-medal.gold { background: linear-gradient(135deg, #ffd60a, #ffaa00); box-shadow: 0 2px 10px rgba(255,214,10,0.5); }
.lb-medal.silver { background: linear-gradient(135deg, #e0e0e0, #b0b0b0); }
.lb-medal.bronze { background: linear-gradient(135deg, #cd7f32, #a0522d); color: white; }
.lb-rank {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    background: rgba(255,255,255,0.1);
}

.lb-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; font-size: 16px; color: var(--accent); min-width: 50px; text-align: right; }
.lb-time { font-size: 12px; color: rgba(255,255,255,0.5); min-width: 42px; text-align: right; }

/* Separator */
.lb-separator {
    text-align: center;
    padding: 4px 0;
    color: rgba(255,255,255,0.3);
    font-size: 20px;
    letter-spacing: 8px;
}

/* Actions */
.lb-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

@media (max-width: 540px) {
    .q-options { grid-template-columns: 1fr; }
    .q-text { font-size: 18px; padding: 18px; }
    .opt { padding: 16px 14px; min-height: 72px; font-size: 15px; }
    .opt .letter { width: 36px; height: 36px; font-size: 18px; }
    .lb-row-me::after { display: none; }
    .lb-row { grid-template-columns: 36px 1fr auto auto; padding: 10px 12px; gap: 8px; }
    .lb-medal, .lb-rank { width: 30px; height: 30px; font-size: 13px; }
}
