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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 15px 30px rgba(0,0,0,0.1);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
    padding: 5px;
    text-align: center;
}

header h1 {
    font-size: 2.2em;
    margin-bottom: 4px;
}

header p {
    font-size: 1em;
    opacity: 0.9;
}

.screen {
    display: none;
    padding: 10px;
}

.screen.active {
    display: block;
}

/* Lobby Styles */
.join-form {
    text-align: center;
    margin: 20px 0;
}

#username {
    padding: 12px;
    font-size: 1em;
    border: 2px solid #ddd;
    border-radius: 6px;
    width: 280px;
    max-width: 100%;
    margin-right: 8px;
}

button {
    padding: 10px 20px;
    font-size: 1em;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
}

button:hover {
    background: #219a52;
    transform: translateY(-2px);
}

button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

.participants {
    text-align: center;
    font-size: 1.1em;
    margin: 15px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
}

.admin-panel {
    text-align: center;
    margin: 20px 0;
    padding: 15px;
    background: #e8f4fd;
    border-radius: 8px;
    border: 2px solid #3498db;
}

.admin-panel button {
    background: #e74c3c;
    padding: 12px 30px;
    font-size: 1.1em;
}

.admin-panel button:hover {
    background: #c0392b;
}

.quiz-info {
    margin-top: 5px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.quiz-info h3 {
    margin-bottom: 5px;
    color: #2c3e50;
}

.quiz-info ul {
    list-style: none;
    text-align: left;
    max-width: 600px;
    margin: 0 auto;
}

.quiz-info li {
    padding: 8px 0;
    font-size: 1em;
    border-bottom: 1px solid #e9ecef;
}

.quiz-info li:last-child {
    border-bottom: none;
}

/* Waiting Message Styles */
.waiting-message {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 12px;
    margin: 20px 0;
    border: 3px dashed #3498db;
}

.waiting-content {
    max-width: 500px;
    margin: 0 auto;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.waiting-message h3 {
    font-size: 1.6em;
    color: #2c3e50;
    margin-bottom: 15px;
}

.waiting-message p {
    font-size: 1em;
    color: #7f8c8d;
    margin-bottom: 12px;
    line-height: 1.5;
}

.waiting-info {
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
    text-align: left;
}

.waiting-info p {
    padding: 6px 0;
    border-bottom: 1px solid #f1f1f1;
    margin-bottom: 0;
    font-size: 0.9em;
}

.waiting-info p:last-child {
    border-bottom: none;
}

/* Quiz Styles - COMPACT LAYOUT */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.question-info, .score {
    font-size: 1.1em;
    font-weight: bold;
    color: #2c3e50;
}

.timer-container {
    text-align: center;
}

.timer {
    font-size: 2em;
    font-weight: bold;
    color: #27ae60;
    line-height: 1;
}

.timer.warning {
    color: #e74c3c;
    animation: pulse 1s infinite;
}

.timer-label {
    font-size: 0.8em;
    color: #7f8c8d;
    margin-top: 3px;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.question-container {
    text-align: center;
    margin-bottom: 25px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.08);
}

#questionText {
    font-size: 1.5em;
    margin-bottom: 20px;
    color: #2c3e50;
    line-height: 1.3;
    font-weight: 600;
}

.options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    max-width: 700px;
    margin: 0 auto;
}

.option {
    padding: 15px;
    font-size: 1em;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    min-height: 65px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.option:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.option.selected {
    transform: scale(0.98);
}

.option.correct {
    background: #27ae60;
}

.option.incorrect {
    background: #e74c3c;
}

.option:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

/* Performance Section - COMPACT HEIGHT */
.performance-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.leaderboard, .current-performance {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
}

.leaderboard h3, .current-performance h3 {
    text-align: center;
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.1em;
}

.leaderboard-header {
    display: grid;
    grid-template-columns: 50px 1fr 70px 70px;
    gap: 10px;
    padding: 8px 10px;
    background: #2c3e50;
    color: white;
    border-radius: 4px;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 0.85em;
}

/* FIX: Reduced height to show top 5 without scrolling */
.leaderboard-list {
    max-height: 220px; /* Reduced from 400px to show ~5 participants */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #3498db #f1f1f1;
}

.leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

.leaderboard-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
    background: #3498db;
    border-radius: 3px;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 50px 1fr 70px 70px;
    gap: 10px;
    padding: 8px 10px;
    margin: 3px 0;
    background: white;
    border-radius: 4px;
    border-left: 3px solid #3498db;
    transition: all 0.3s;
    font-size: 0.85em;
}

.leaderboard-item.you {
    background: #e8f4fd;
    border-left-color: #e74c3c;
    font-weight: bold;
}

.leaderboard-item:hover {
    transform: translateX(3px);
}

.leaderboard-item.you:hover {
    transform: translateX(3px);
}

.leaderboard-rank {
    font-weight: bold;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Rank change indicators */
.rank-up {
    color: #27ae60;
    font-weight: bold;
    font-size: 0.7em;
    background: #d4edda;
    padding: 1px 4px;
    border-radius: 2px;
    animation: slideUp 0.5s ease-in-out;
}

.rank-down {
    color: #e74c3c;
    font-weight: bold;
    font-size: 0.7em;
    background: #f8d7da;
    padding: 1px 4px;
    border-radius: 2px;
    animation: slideDown 0.5s ease-in-out;
}

@keyframes slideUp {
    0% { transform: translateY(5px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

@keyframes slideDown {
    0% { transform: translateY(-5px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

.leaderboard-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-score {
    color: #27ae60;
    font-weight: bold;
}

.leaderboard-correct {
    color: #3498db;
    font-weight: 500;
}

/* Performance Stats */
.performance-stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.stat {
    text-align: center;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.stat-value {
    display: block;
    font-size: 2em;
    font-weight: bold;
    color: #3498db;
    margin-bottom: 3px;
}

.stat-label {
    font-size: 0.85em;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Results Screen */
.final-leaderboard {
    margin-bottom: 30px;
}

.final-leaderboard .leaderboard-header {
    grid-template-columns: 50px 1fr 70px 70px 70px;
}

.final-leaderboard .leaderboard-item {
    grid-template-columns: 50px 1fr 70px 70px 70px;
}

.questions-review {
    margin: 30px 0;
}

.review-list {
    max-height: 400px;
    overflow-y: auto;
}

.review-item {
    background: #f8f9fa;
    padding: 15px;
    margin: 10px 0;
    border-radius: 8px;
    border-left: 3px solid #3498db;
}

.review-question {
    font-weight: bold;
    margin-bottom: 8px;
    color: #2c3e50;
    font-size: 1em;
}

.review-answer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    margin: 4px 0;
    padding: 6px 10px;
    background: white;
    border-radius: 4px;
    font-size: 0.9em;
}

.review-answer.correct {
    background: #d4edda;
    border-left: 2px solid #28a745;
}

.review-answer.incorrect {
    background: #f8d7da;
    border-left: 2px solid #dc3545;
}

.answer-status {
    font-weight: bold;
    padding: 3px 6px;
    border-radius: 2px;
    font-size: 0.8em;
}

.answer-status.correct {
    background: #28a745;
    color: white;
}

.answer-status.incorrect {
    background: #dc3545;
    color: white;
}

.action-buttons {
    text-align: center;
    margin-top: 20px;
}

.action-buttons button {
    margin: 0 8px;
}

.action-buttons button:last-child {
    background: #3498db;
}

.action-buttons button:last-child:hover {
    background: #2980b9;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .performance-section {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .container {
        margin: 5px;
        border-radius: 8px;
    }
    
    header h1 {
        font-size: 1.8em;
    }
    
    .quiz-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .options {
        grid-template-columns: 1fr;
    }
    
    #username {
        margin-bottom: 8px;
        margin-right: 0;
        width: 100%;
    }
    
    .join-form button {
        width: 100%;
    }
    
    .performance-stats {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .stat-value {
        font-size: 1.6em;
    }
    
    .waiting-message {
        padding: 30px 15px;
    }
    
    .waiting-message h3 {
        font-size: 1.4em;
    }
}

@media (max-width: 480px) {
    .screen {
        padding: 15px;
    }
    
    #questionText {
        font-size: 1.3em;
    }
    
    .option {
        padding: 12px;
        font-size: 0.9em;
        min-height: 55px;
    }
    
    .performance-stats {
        grid-template-columns: 1fr;
    }
    
    .leaderboard-header,
    .leaderboard-item {
        grid-template-columns: 40px 1fr 60px 60px;
        gap: 6px;
        font-size: 0.8em;
        padding: 6px 8px;
    }
    
    .waiting-message {
        padding: 20px 10px;
    }
    
    .spinner {
        width: 35px;
        height: 35px;
    }
}

/* ================= Additions for the new features (original design kept above) ================= */
.hidden { display: none !important; }
.center { text-align: center; }
.error { color: #e74c3c; text-align: center; min-height: 1.3em; margin-top: 6px; }
.conn { position: fixed; top: 0; left: 0; right: 0; z-index: 50; padding: 8px; text-align: center; background: #e74c3c; color: white; }
.badge { display: inline-block; margin-top: 4px; padding: 2px 12px; border-radius: 12px; background: rgba(255,255,255,0.18); font-size: 0.85em; }

.option { flex-direction: column; gap: 4px; font-family: inherit; }
.option.selected { outline: 4px solid #f1c40f; }
.option.dim { opacity: 0.45; }
.option.static { cursor: default; }
.option.static:hover { background: #3498db; transform: none; }
.option.static.correct:hover { background: #27ae60; }
.opt-count { font-size: 0.85em; opacity: 0.95; }

.feedback { margin: 18px auto 0; max-width: 700px; padding: 12px; border-radius: 8px; font-weight: bold; font-size: 1.2em; }
.feedback.good { background: #d4edda; color: #1e7e34; }
.feedback.bad { background: #f8d7da; color: #b02a37; }
.feedback.none { background: #eef1f3; color: #566573; }
.explain { margin: 12px auto 0; max-width: 700px; padding: 12px; border-left: 4px solid #3498db; background: #e8f4fd; border-radius: 6px; text-align: left; }
.status-line { margin-top: 14px; color: #7f8c8d; min-height: 1.2em; }

.overlay { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; text-align: center; background: rgba(44,62,80,0.9); color: white; padding: 20px; }
.overlay h2 { font-size: 2.2em; margin-bottom: 8px; }

/* Host */
.login-box { max-width: 360px; margin: 30px auto; }
.login-box input { width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 6px; font-size: 1em; margin-bottom: 10px; }
.login-box button { width: 100%; }
.admin-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 10px; }
.admin-panel button { background: #27ae60; padding: 10px 18px; font-size: 1em; }
.admin-panel button:hover { background: #219a52; }
.admin-panel button.secondary { background: #3498db; }
.admin-panel button.secondary:hover { background: #2980b9; }
.admin-panel button.danger { background: #e74c3c; }
.admin-panel button.danger:hover { background: #c0392b; }
.admin-panel button:disabled { background: #bdc3c7; }
.admin-panel label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.95em; color: #2c3e50; cursor: pointer; }
.seg { display: inline-flex; border: 2px solid #3498db; border-radius: 8px; overflow: hidden; }
.seg button { background: white !important; color: #3498db; border-radius: 0; padding: 8px 14px; transform: none !important; }
.seg button.on { background: #3498db !important; color: white; }
.seg button:disabled:not(.on) { opacity: 0.5; color: #7f8c8d; }
.join-banner { text-align: center; margin: 15px 0; padding: 16px; background: #fff8e1; border: 2px dashed #f1c40f; border-radius: 8px; }
.join-banner strong { display: block; font-size: 1.8em; color: #2c3e50; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.chip { padding: 5px 12px; border-radius: 14px; background: #e8f4fd; border: 1px solid #b6dcf5; font-size: 0.95em; }
.chip.off { opacity: 0.45; }
details.players { margin: 0 10px 10px; padding: 8px 12px; background: #f8f9fa; border-radius: 8px; }
details.players summary { cursor: pointer; font-weight: bold; color: #2c3e50; }
.prow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid #eee; font-size: 0.95em; }
.prow button { padding: 3px 10px; font-size: 0.8em; background: #e74c3c; }
.paused-banner { margin: 0 0 12px; padding: 8px; text-align: center; font-weight: bold; font-size: 1.3em; background: #fff3cd; color: #856404; border-radius: 8px; }
.counter { font-size: 3em; font-weight: bold; color: #2c3e50; }

/* Big screen mode (host): text scales with the screen height, controls are hidden, and the
   leaderboard sits beside the question so the top players are always visible (no scrolling). */
body.present { font-size: clamp(15px, 2.3vh, 32px); padding: 6px; }
body.present .container { max-width: none; }
body.present .admin-panel, body.present details.players { display: none; }
body.present header h1 { font-size: 1.6em; margin-bottom: 0; }
body.present header p { font-size: 0.9em; }
body.present #quiz.active {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
    grid-template-areas: "paused paused" "head head" "question board";
    gap: 12px 18px;
    align-items: start;
}
body.present #pausedBanner { grid-area: paused; margin: 0; }
body.present #quiz .quiz-header { grid-area: head; margin-bottom: 0; }
body.present #quiz .question-container { grid-area: question; margin-bottom: 0; }
body.present #quiz .performance-section { grid-area: board; display: block; margin-top: 0; }
body.present #quiz .current-performance { display: none; }
body.present .leaderboard-list { max-height: none; overflow: visible; }
.login-title { margin-bottom: 12px; }
.clear-row { margin-top: 8px; }
.small-danger { background: #e74c3c; padding: 6px 12px; font-size: 0.85em; }
.muted-note { color: #7f8c8d; margin: 14px 0; }
