:root {
    --bg: #0c0c0f;
    --bg-surface: #16161a;
    --bg-card: #1e1e24;
    --bg-card-hover: #28282f;
    --primary: #d4a017;
    --primary-light: #f0c040;
    --primary-lighter: #ffd966;
    --primary-pale: #fff5d6;
    --accent: #ffd700;
    --accent-glow: rgba(255, 215, 0, 0.3);
    --text: #f5f0e8;
    --text-secondary: #b8b0a0;
    --text-muted: #706858;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.15);
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.15);
    --border: rgba(212, 160, 23, 0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ─── BACKGROUND PARTICLES ─── */
#bg-particles {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

#app { position: relative; z-index: 1; }

.view { display: none; min-height: 100vh; }
.view.active { display: flex; }

/* ─── BUTTONS ─── */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #0c0c0f;
    box-shadow: 0 2px 12px rgba(212, 160, 23, 0.4);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(212, 160, 23, 0.6);
}
.btn-primary:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
    box-shadow: none;
}
.btn-secondary {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); }
.btn-large { padding: 16px 40px; font-size: 1.1rem; }
.btn-full { width: 100%; }

/* ─── INPUTS ─── */
input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-lighter);
}
input[type="text"]::placeholder { color: var(--text-muted); }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ─── CARDS ─── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.card h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    background: var(--primary);
    color: #0c0c0f;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 99px;
    font-weight: 700;
}

/* ─── ONBOARDING ─── */
.onboarding-container {
    max-width: 560px;
    margin: 0 auto;
    padding: 80px 20px 40px;
    width: 100%;
    animation: fadeInUp 0.4s ease-out;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.logo-section { text-align: center; margin-bottom: 48px; }
.logo {
    font-size: 2.8rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: white;
}
.logo-icon { display: flex; align-items: center; }
.accent { color: var(--accent); }
.tagline {
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.name-card { max-width: 400px; margin: 0 auto; }

.welcome-back {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1rem;
    color: var(--text-secondary);
}
.welcome-back span {
    color: var(--accent);
    font-weight: 700;
}

.choose-title {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 24px;
}

.choose-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.choose-card {
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 32px 20px;
}
.choose-card:hover {
    border-color: var(--primary-lighter);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(212, 160, 23, 0.2);
}
.choose-card h3 { font-size: 1.1rem; margin-bottom: 8px; }
.choose-card p { font-size: 0.85rem; color: var(--text-secondary); }
.choose-icon {
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-left: auto;
    margin-right: auto;
    border-radius: 50%;
    background: rgba(255, 215, 0, 0.1);
    border: 2px solid rgba(255, 215, 0, 0.2);
}

.btn-back {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    margin-bottom: 24px;
    padding: 4px 0;
}
.btn-back:hover { color: var(--text); }

/* ─── JOIN SECTION ─── */
.join-section { max-width: 480px; margin: 0 auto; }

.code-input-row {
    display: flex;
    gap: 12px;
}
.code-input {
    font-size: 1.4rem !important;
    font-weight: 800 !important;
    text-align: center;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    max-width: 160px;
}

.divider-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.divider-row::before, .divider-row::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Room list */
.room-list {
    max-height: 260px;
    overflow-y: auto;
    margin-bottom: 16px;
}
.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}
.room-item:hover {
    border-color: var(--primary-lighter);
    background: var(--bg-card-hover);
}
.room-item-name { font-weight: 600; }
.room-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.room-item-code {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    background: rgba(255, 215, 0, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.1em;
}
.room-item-players {
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
    font-size: 0.9rem;
}

/* ─── WAITING ROOM ─── */
.waiting-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 60px 20px;
    text-align: center;
    width: 100%;
    animation: fadeInUp 0.4s ease-out;
}
.waiting-container h2 {
    font-size: 1.6rem;
    margin-bottom: 24px;
}

.room-share-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}
.room-code-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.room-code-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.room-code-value {
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--accent);
    letter-spacing: 0.25em;
    text-shadow: 0 0 20px var(--accent-glow);
}
.btn-copy {
    font-size: 0.85rem;
    padding: 8px 16px;
}

.players-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-bottom: 32px;
}
.player-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-radius: 99px;
    font-weight: 600;
    background: var(--bg-card);
    border: 1px solid var(--border);
}
.player-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    color: #0c0c0f;
    flex-shrink: 0;
}
.player-chip.host { border-color: var(--accent); }
.player-chip.host::after { content: ' (Host)'; font-size: 0.75rem; color: var(--accent); }
.host-controls { margin-bottom: 16px; }
.waiting-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ─── GAME VIEW ─── */
.game-layout {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.game-header {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
.round-info {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    min-width: 50px;
}
.timer-bar-container {
    flex: 1;
    height: 8px;
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
}
.timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--accent), var(--primary-lighter));
    border-radius: 4px;
    transition: width 0.25s linear;
}
.timer-bar.warning { background: linear-gradient(90deg, #f59e0b, var(--error)); }
.timer-bar.danger { background: var(--error); }

.streak-display {
    font-weight: 800;
    font-size: 0.9rem;
    white-space: nowrap;
    color: #ff6b35;
    text-shadow: 0 0 10px rgba(255, 107, 53, 0.5);
    animation: streakGlow 1s ease-in-out infinite alternate;
}
@keyframes streakGlow {
    from { text-shadow: 0 0 10px rgba(255, 107, 53, 0.3); }
    to { text-shadow: 0 0 20px rgba(255, 107, 53, 0.8); }
}

.category-badge {
    background: var(--primary);
    color: #0c0c0f;
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 16px;
    overflow-y: auto;
}

.question-panel {
    width: 100%;
    max-width: 680px;
    display: flex;
    flex-direction: column;
}

.question-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    min-height: 80px;
}
.question-image {
    max-height: 80px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}
.question-image.flag {
    border: 1px solid var(--border);
    border-radius: 6px;
    height: 64px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.question-image.logo {
    height: 64px;
    border-radius: var(--radius-sm);
    background: white;
    padding: 8px 16px;
}
.question-icon {
    width: 56px;
    height: 56px;
    color: var(--accent);
    opacity: 0.7;
    display: none;
    align-items: center;
    justify-content: center;
}
.question-icon svg {
    width: 100%;
    height: 100%;
}

.question-text {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 20px;
    line-height: 1.4;
}

.answer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.answer-btn {
    padding: 14px 16px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
}
.answer-btn:hover:not(.disabled) {
    border-color: var(--primary-lighter);
    background: var(--bg-card-hover);
    transform: translateY(-1px);
}
.answer-btn .answer-letter {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary);
    color: #0c0c0f;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.answer-btn.selected {
    border-color: var(--accent);
    background: rgba(255, 215, 0, 0.12);
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.15);
}
.answer-btn.selected .answer-letter {
    background: var(--accent);
}
.answer-btn.correct {
    border-color: var(--success) !important;
    background: var(--success-bg) !important;
}
.answer-btn.correct .answer-letter { background: var(--success); color: white; }
.answer-btn.wrong {
    border-color: var(--error) !important;
    background: var(--error-bg) !important;
}
.answer-btn.wrong .answer-letter { background: var(--error); color: white; }
.answer-btn.disabled { cursor: default; opacity: 0.7; }

.btn-confirm {
    margin-top: 12px;
    width: 100%;
    animation: fadeInUp 0.3s ease-out;
}

/* ─── MINI LEADERBOARD ─── */
.mini-leaderboard {
    width: 100%;
    max-width: 680px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
}
.mini-leaderboard-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.mini-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.8rem;
}
.mini-player-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.6rem;
    color: #0c0c0f;
    flex-shrink: 0;
}
.mini-player-rank {
    font-weight: 800;
    color: var(--accent);
    width: 18px;
}
.mini-player-name { flex: 1; font-weight: 600; }
.mini-player-score {
    color: var(--text-secondary);
    font-weight: 600;
}
.mini-player.answered .mini-player-name::after {
    content: ' \2713';
    color: var(--success);
    font-weight: 800;
}

/* ─── XP BAR ─── */
.xp-bar-container {
    padding: 8px 20px 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
}
.xp-bar-track {
    height: 6px;
    background: var(--bg-card);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}
.xp-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.xp-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
}
.xp-rank {
    color: var(--accent);
    font-weight: 700;
}
.xp-score { color: var(--text-secondary); font-weight: 600; }

/* ─── POINTS POPUP ─── */
.points-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 900;
    z-index: 200;
    pointer-events: none;
    text-shadow: 0 0 30px currentColor;
}
.points-popup.positive { color: var(--success); }
.points-popup.negative { color: var(--error); }
.points-popup.animate {
    animation: pointsFly 1.2s ease-out forwards;
}
@keyframes pointsFly {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -70%) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -120%) scale(0.8); }
}

/* ─── CONFETTI ─── */
#confetti-canvas {
    position: fixed;
    inset: 0;
    z-index: 150;
    pointer-events: none;
}

/* ─── SCREEN SHAKE ─── */
.screen-shake {
    animation: shake 0.4s ease-out;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* ─── OVERLAYS ─── */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(12, 12, 15, 0.88);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.results-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    max-width: 560px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.6);
    animation: fadeInUp 0.3s ease-out;
}
.results-card h2 {
    font-size: 1.3rem;
    margin-bottom: 12px;
}
.explanation {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 16px;
    padding: 10px 12px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.results-players { margin-bottom: 14px; }
.result-player-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 0.9rem;
}
.result-player-row.correct { background: var(--success-bg); }
.result-player-row.wrong { background: var(--error-bg); }
.result-player-name { font-weight: 600; }
.result-player-points { font-weight: 700; font-size: 0.85rem; }
.result-player-points.positive { color: var(--success); }
.result-player-time { font-size: 0.75rem; color: var(--text-muted); }

.results-leaderboard {
    border-top: 1px solid var(--border);
    padding-top: 12px;
}
.results-leaderboard h3 {
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: var(--text-secondary);
}
.lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    font-size: 0.85rem;
}
.lb-rank { font-weight: 800; width: 22px; color: var(--accent); }
.lb-name { flex: 1; font-weight: 600; }
.lb-score { font-weight: 700; color: var(--primary-pale); }

.countdown-number {
    font-size: 8rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 40px var(--accent-glow);
    animation: countdownPulse 1s ease-in-out;
}
@keyframes countdownPulse {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* ─── FINAL RESULTS ─── */
.final-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 60px 20px;
    text-align: center;
    width: 100%;
    animation: fadeInUp 0.5s ease-out;
}
.final-title {
    font-size: 2.4rem;
    font-weight: 900;
    margin-bottom: 24px;
    background: linear-gradient(135deg, var(--accent), white);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.winner-showcase { margin-bottom: 32px; }
.winner-name {
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent);
    margin-bottom: 4px;
}
.winner-score { font-size: 1.2rem; color: var(--text-secondary); }
.winner-crown { font-size: 4rem; margin-bottom: 12px; }

.final-leaderboard { text-align: left; margin-bottom: 32px; }
.final-lb-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}
.final-lb-row:first-child {
    border-color: var(--accent);
    background: rgba(255, 215, 0, 0.1);
}
.final-lb-rank {
    font-size: 1.4rem;
    font-weight: 900;
    width: 40px;
    text-align: center;
}
.final-lb-rank.gold { color: #ffd700; }
.final-lb-rank.silver { color: #c0c0c0; }
.final-lb-rank.bronze { color: #cd7f32; }
.final-lb-name { flex: 1; font-weight: 700; font-size: 1.1rem; }
.final-lb-score { font-weight: 800; font-size: 1.1rem; color: var(--accent); }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
    .answer-grid { grid-template-columns: 1fr; }
    .choose-grid { grid-template-columns: 1fr; }
    .logo { font-size: 2rem; }
    .question-text { font-size: 1.1rem; }
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }
