:root {
    /* Violet-tinted palette — mirrors cards.css structure but hue-rotated
       toward purple so the multiplayer arena is instantly distinguishable
       from the blue single-player study app. */
    --primary-color: #6b42a6; /* cards' #4a6fa5 rotated to violet */
    --secondary-color: #46178f; /* cards' #166088 rotated to deep violet */
    --accent-color: #ff3366; /* magenta-leaning red for high-energy CTA */
    --light-color: var(--surface-secondary);
    --dark-color: #343a40;
    --correct-color: #28a745; /* green stays universal for correct */
    --wrong-color: #dc3545; /* red stays universal for wrong */
    --warning-color: #ffc107;

    --quiz-surface: #f2e9ff; /* cards' #e9f2ff rotated */
    --quiz-surface-alt: #f5f0ff; /* cards' #f0f5ff rotated */
    --quiz-hover: #ece0ff;
    --success-bg: #d4edda;
    --success-border: #c3e6cb;
    --cards-highlight-bg: #f2e9ff; /* cards' #e9f2ff rotated */
    --cards-highlight-border: #b592e3; /* cards' #92b5e3 rotated */
    --progress-track: #e9ecef;
    --primary-rgb: 107, 66, 166;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--surface-secondary);
    color: var(--text-color);
    font-size: 18px;
    line-height: 1.5;
}

/* Links — themed so the join-link and footer stay readable in both modes
   (browser default dark-blue is nearly invisible on dark surfaces). */
a {
    color: var(--primary-color);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    font-weight: 500;
}

a:hover,
a:focus-visible {
    color: var(--secondary-color);
}

#join-link,
#join-link-modal {
    color: var(--primary-color);
    word-break: break-all;
}

h1 {
    font-size: 1.8rem;
}
h2 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}
h3 {
    font-size: 1.25rem;
    color: var(--primary-color);
    margin: 0.5rem 0;
}
h4 {
    font-size: 1.15rem;
    color: var(--primary-color);
    margin: 0.25rem 0;
}

.container {
    width: 95%;
    max-width: 1400px;
    margin: 0.5rem auto;
    padding: 0.5rem;
}

header {
    background-color: var(--surface-color);
    color: var(--primary-color);
    padding: 0.5rem 1rem;
    text-align: center;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    box-shadow: 0 2px 4px var(--shadow-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

header h1 {
    color: var(--primary-color);
    margin: 0;
    flex: 1;
}

.back-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.back-link:hover {
    background-color: rgba(128, 128, 128, 0.15);
}

.view {
    display: none;
}

.active {
    display: block;
}

.btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 500;
    transition: background-color 0.2s;
    margin: 0.3rem 0.3rem 0.3rem 0;
}

.btn:hover {
    background-color: var(--secondary-color);
}

.btn-accent {
    background-color: var(--accent-color);
}

.btn-accent:hover {
    background-color: #e02858;
}

.btn-reconnect {
    background-color: transparent;
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
    font-size: 0.95em;
    margin-top: 5px;
}

.btn-reconnect:hover {
    background-color: var(--secondary-color);
    color: white;
}

.card {
    background-color: var(--surface-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    box-shadow: 0 2px 4px var(--shadow-color);
    margin-bottom: 0.75rem;
}

input,
select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    margin: 0.3rem 0;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 1em;
    background-color: var(--input-bg);
    color: var(--text-color);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.15rem rgba(var(--primary-rgb), 0.25);
}

.duration-setting {
    margin-top: 0.5rem;
}

.duration-range-row {
    display: flex;
    gap: 1rem;
    margin-top: 0.3rem;
}

.duration-input-group {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.duration-input-group label {
    white-space: nowrap;
    font-weight: 500;
}

.duration-input {
    width: 80px;
}

/* Drop Zone (aligned with cards.html) */
.upload-section {
    margin: 0.75rem 0;
}

.drop-zone {
    margin-top: 0.5rem;
    border: 2px dashed var(--text-muted, #aaa);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: var(--surface-color);
}

.drop-zone:hover {
    border-color: var(--primary-color);
    background-color: var(--quiz-hover);
}

.drop-zone.drag-over {
    border-color: var(--primary-color);
    background-color: var(--cards-highlight-bg);
    border-style: solid;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    pointer-events: none;
}

.drop-zone-icon {
    font-size: 1.75rem;
    line-height: 1;
}

.drop-zone-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--dark-color);
}

.drop-zone-hint {
    font-size: 0.9rem;
    color: var(--text-muted, #888);
}

#file-status {
    margin-top: 0.4rem;
    font-size: 0.95rem;
    color: var(--text-muted, #888);
    text-align: center;
}

/* Host form styles */
#question-form {
    margin-top: 0.75rem;
}

.option-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 0.4rem;
}

.option-group input[type='text'] {
    flex-grow: 1;
    margin-right: 0.5rem;
    min-width: 150px;
}

.option-group input[type='checkbox'] {
    width: auto;
    margin-left: 0.5rem;
}

.option-group label {
    margin-left: 0.3rem;
}

#questions-list {
    margin-top: 0.75rem;
}

.question-item {
    background-color: var(--quiz-surface);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.4rem;
    border-left: 3px solid var(--primary-color);
}

/* Player option buttons */
.option-btn {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border: 2px solid var(--input-border);
    border-radius: 8px;
    background-color: var(--quiz-surface-alt);
    color: var(--text-color);
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.1em;
}

.option-btn:hover:not(:disabled) {
    background-color: var(--quiz-hover);
    border-color: var(--primary-color);
}

.option-btn.selected {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.option-btn.correct-answer,
.option-btn.correct {
    background-color: var(--correct-color);
    color: white;
    border-color: var(--correct-color);
    font-weight: bold;
}

.option-btn.incorrect-answer.selected,
.option-btn.incorrect {
    background-color: var(--wrong-color);
    color: white;
    border-color: var(--wrong-color);
    font-weight: bold;
}

/* Host options list (big screen — compact spacing, large fonts) */
.host-options-list {
    margin-top: 0.75rem;
    padding: 0;
    list-style: none;
}

.host-options-list li {
    background-color: var(--quiz-surface-alt);
    border: 1px solid var(--input-border);
    border-left: 4px solid var(--primary-color);
    padding: 0.6rem 0.9rem;
    margin-bottom: 0.4rem;
    border-radius: 6px;
    font-size: 1.25em;
}

.host-options-list li.correct {
    background-color: var(--success-bg);
    border-color: var(--success-border);
    border-left-color: var(--correct-color);
    font-weight: bold;
}

/* Player result display */
#result-display {
    text-align: center;
    font-size: 1.4rem;
    margin: 0.75rem 0;
    padding: 0.75rem;
    border-radius: 8px;
}

#result-display.correct {
    background-color: rgba(40, 167, 69, 0.15);
    color: var(--correct-color);
}

#result-display.incorrect {
    background-color: rgba(220, 53, 69, 0.15);
    color: var(--wrong-color);
}

#result-display .correct {
    color: var(--correct-color);
    font-weight: bold;
}

#result-display .incorrect {
    color: var(--wrong-color);
    font-weight: bold;
}

#result-display .player-selected {
    text-decoration: underline;
    font-weight: bold;
}

#result-display .correct-not-selected {
    font-weight: bold;
    font-style: italic;
    color: var(--correct-color);
}

.score-gained {
    color: var(--correct-color);
    font-weight: bold;
    margin: 0 4px;
}

/* Scoreboard */
.scoreboard {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.scoreboard h4 {
    margin-bottom: 0.5rem;
    font-size: 1.3em;
}

.scoreboard ol {
    padding-left: 1.5rem;
}

.scoreboard li {
    margin-bottom: 0.3rem;
    font-size: 1.15em;
}

.scoreboard-item {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px dashed var(--border-color);
}

.scoreboard-item:last-child {
    border-bottom: none;
}

/* QR modal */
.qr-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.qr-modal-content {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 12px;
    position: relative;
    text-align: center;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    max-width: 90%;
}

.qr-modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: var(--text-color);
    line-height: 1;
}

.qr-modal-close:hover {
    color: #000;
}

#large-qrcode {
    margin: 1rem auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#large-qrcode img {
    width: 300px;
    max-width: 100%;
    height: auto;
}

#qrcode {
    margin: 0.75rem auto;
    text-align: center;
}

/* Leaderboard / scoreboard rank highlights */
.leaderboard-item.rank-1,
.scoreboard-item.rank-1 {
    background-color: #ffeb3b;
    font-weight: bold;
    border-color: #fbc02d;
}
.leaderboard-item.rank-2,
.scoreboard-item.rank-2 {
    background-color: #e0e0e0;
    font-weight: bold;
    border-color: #bdbdbd;
}
.leaderboard-item.rank-3,
.scoreboard-item.rank-3 {
    background-color: #ffccbc;
    font-weight: bold;
    border-color: #e64a19;
}

.hidden {
    display: none !important;
}

/* Confetti */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 999;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: var(--confetti-color);
    opacity: 0;
    animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100px) rotateZ(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotateZ(720deg);
        opacity: 0;
    }
}

#leaderboard {
    margin-top: 0.75rem;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.loader {
    border: 5px solid var(--border-color);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 1rem auto;
}

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

/* Timer bar */
.timer-bar-container {
    width: 100%;
    height: 10px;
    background-color: var(--progress-track);
    border-radius: 5px;
    margin-top: 0.4rem;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    background-color: var(--accent-color);
    width: 100%;
    border-radius: 5px;
    transition: width 1s linear;
}

.players-list {
    margin: 0.75rem 0;
}

.player-item {
    background-color: var(--quiz-surface);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    margin-bottom: 0.25rem;
    border-left: 3px solid var(--primary-color);
}

.flex-row {
    display: flex;
    gap: 0.5rem;
}

.correct-answers {
    margin-top: 0.5rem;
    color: var(--correct-color);
    font-weight: bold;
}

.score-display {
    font-size: 1.25rem;
    font-weight: bold;
    text-align: center;
    margin: 0.75rem 0;
    color: var(--primary-color);
}

.question-counter {
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
    font-weight: 500;
}

/* Big screen: make question text pop */
#current-question-text {
    font-size: 1.75em;
    color: var(--primary-color);
    margin: 0.5rem 0;
    text-align: center;
    line-height: 1.3;
}

#player-question-text {
    font-size: 1.4em;
    color: var(--primary-color);
    margin: 0.5rem 0;
    line-height: 1.3;
}

.player-item.disconnected {
    opacity: 0.5;
    font-style: italic;
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    z-index: 10001;
    opacity: 0;
    transition:
        opacity 0.3s ease,
        transform 0.3s ease;
    max-width: 90%;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-info {
    background-color: var(--primary-color);
}

.toast-error {
    background-color: var(--wrong-color);
}

.footer-link {
    color: var(--text-muted);
    text-decoration: none;
}

.footer-link:hover {
    text-decoration: underline;
}

.qr-error {
    color: var(--wrong-color);
}

/* Mobile */
@media (max-width: 600px) {
    body {
        font-size: 16px;
    }
    h1 {
        font-size: 1.5rem;
    }
    h2 {
        font-size: 1.3rem;
    }
    h3 {
        font-size: 1.15rem;
    }

    .container {
        padding: 0.4rem;
    }

    .card {
        padding: 0.75rem;
    }

    #current-question-text {
        font-size: 1.4em;
    }

    #player-question-text {
        font-size: 1.2em;
    }

    #large-qrcode img {
        width: 250px;
        height: 250px;
    }
}

/* Dark mode overrides — violet-leaning, with boosted contrast.
   We locally override --text-color / --text-muted so quiz-page text
   reads cleanly against both the deep-violet surfaces and the default
   dark body; this is scoped to quiz.css and does not affect cards. */
[data-theme='dark'] {
    --primary-color: #c4a6ea; /* lighter violet — higher contrast on dark */
    --secondary-color: #a78bd1; /* used for link-hover / secondary buttons */
    --accent-color: #ff7a96;
    --dark-color: #f5f5f5;
    --correct-color: #5cd66f;
    --wrong-color: #ff8560;

    --text-color: #f5f5f5; /* was #e0e0e0 — brighter body text */
    --text-muted: #c0bed0; /* was #a0a0b0 — readable hints */

    --quiz-surface: #2a2040; /* slightly darker to raise text contrast */
    --quiz-surface-alt: #352a52;
    --quiz-hover: #443666;
    --cards-highlight-bg: #352a52;
    --cards-highlight-border: #a78bd1;
    --success-bg: rgba(76, 175, 80, 0.22);
    --success-border: rgba(92, 214, 111, 0.45);
    --primary-rgb: 196, 166, 234;
}

[data-theme='dark'] a:hover,
[data-theme='dark'] a:focus-visible {
    color: #e0cdf5; /* brighter than primary — pops on hover */
}

[data-theme='dark'] .question-item,
[data-theme='dark'] .player-item,
[data-theme='dark'] .host-options-list li {
    color: var(--text-color);
}

[data-theme='dark'] #current-question-text,
[data-theme='dark'] #player-question-text {
    color: var(--primary-color);
}

[data-theme='dark'] .qr-modal-close:hover {
    color: #fff;
}

[data-theme='dark'] .btn-accent:hover {
    background-color: #e04a6d;
}

[data-theme='dark'] .leaderboard-item.rank-1,
[data-theme='dark'] .scoreboard-item.rank-1 {
    background-color: rgba(255, 235, 59, 0.25);
    border-color: rgba(251, 192, 45, 0.4);
    color: #ffeb3b;
}

[data-theme='dark'] .leaderboard-item.rank-2,
[data-theme='dark'] .scoreboard-item.rank-2 {
    background-color: rgba(224, 224, 224, 0.15);
    border-color: rgba(189, 189, 189, 0.3);
    color: #e0e0e0;
}

[data-theme='dark'] .leaderboard-item.rank-3,
[data-theme='dark'] .scoreboard-item.rank-3 {
    background-color: rgba(255, 204, 188, 0.2);
    border-color: rgba(230, 74, 25, 0.3);
    color: #ffccbc;
}
