/* Multiplayer quiz (quizzes/multiplayer/index.php). The question,
   answer and feedback look comes from quizzes/includes/quiz-player.css;
   surfaces, buttons, alerts and pills from includes/styles.css. This
   file lays out the join / lobby / reveal / leaderboard screens. */

/* ---------- Cards (join, lobby, finished) ---------- */
.mp-card {
    max-width: 520px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
    text-align: center;
}

.mp-icon {
    margin-bottom: 1rem;
}

.mp-title {
    margin: 0 0 0.35rem;
    color: var(--text-primary);
    font-size: var(--fs-section-title);
    font-weight: 700;
}

.mp-lead {
    margin: 0 0 1.5rem;
    color: var(--text-secondary);
}

/* When a screen change would strand keyboard focus, the page script
   moves it to the new screen's heading (tabindex=-1). It is a reading
   position, not a control, so it takes no ring (the site's focus ring
   skips tabindex=-1 too). */
h2[tabindex="-1"]:focus {
    outline: none;
}

/* Player name badge (white label on the fill token). */
.my-name-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1rem;
    padding: 0.3rem 0.8rem;
    border-radius: var(--r-pill);
    background: var(--primary-fill);
    color: #fff;
    font-size: var(--fs-sm);
    font-weight: 600;
}

/* ---------- Join ---------- */
.join-section {
    max-width: 320px;
    margin: 0 auto;
}

.code-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.code-input-group .btn {
    width: 100%;
}

/* The game code field: big, centred, monospaced capitals. */
.form-control.code-input {
    padding: 0.6rem;
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 6px;
    text-align: center;
    text-transform: uppercase;
}

/* The example code reads lighter than a typed one. */
.code-input::placeholder {
    font-weight: 400;
    letter-spacing: 4px;
}

.mp-error {
    margin: 0.75rem 0 0;
    padding: 0.6rem 0.9rem;
    font-size: var(--fs-sm);
    font-weight: 600;
    text-align: left;
}

.divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0;
    color: var(--text-muted);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-soft);
}

/* ---------- Lobby ---------- */
.join-code-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 1rem 0;
}

.join-code-value {
    color: var(--primary-text);
    font-family: var(--font-mono);
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 8px;
}

.mp-qr {
    margin: 1rem 0;
}

.mp-qr-label {
    margin-top: 0.4rem;
    color: var(--text-muted);
    font-size: var(--fs-xs);
}

.player-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin: 1.5rem 0;
}

.player-chip {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 6px 14px;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-pill);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: var(--fs-sm);
    font-weight: 500;
}

.player-rank {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-fill);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
}

.load-progress-label {
    margin-bottom: 0.4rem;
}

.waiting-dots {
    color: var(--text-muted);
    font-style: italic;
}

.waiting-dots .dots::after {
    content: '';
    animation: waitDots 1.5s steps(4, end) infinite;
}

@keyframes waitDots {
    0%  { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* Start button's loading glyph. */
.spin {
    display: inline-block;
}

@media (prefers-reduced-motion: no-preference) {
    .spin {
        animation: mp-spin 1s linear infinite;
    }
}

@keyframes mp-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Question: count-down bar and seconds ----------
   The page script swaps .green / .yellow / .red on the bar. The
   role=timer wrapper holds a visually hidden 'Time remaining' and the
   seconds the script writes into #timerText. */
.timer-text-wrap {
    display: inline-flex;
    align-items: center;
}

.timer-text {
    min-width: 2.5rem;
    color: var(--text-primary);
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.timer-bar-container {
    height: 8px;
    margin-bottom: 1.25rem;
    overflow: hidden;
    border-radius: var(--r-pill);
    background: var(--neutral-bg);
    box-shadow: inset 0 0 0 1px var(--border-soft);
}

.timer-bar {
    height: 100%;
    border-radius: inherit;
    transition: width 0.1s linear;
}

.timer-bar.green  { background: var(--success-fill); }
.timer-bar.yellow { background: var(--warning-text); }
.timer-bar.red    { background: var(--danger-text); }

/* Host view of a fill-in-the-blank question. */
.mp-waiting-note {
    margin: 1rem 0;
    color: var(--text-muted);
    text-align: center;
}

@keyframes fitb-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.fitb-shake {
    animation: fitb-shake 0.4s ease;
}

/* ---------- Reveal ---------- */
.reveal-card {
    margin-bottom: 2rem;
}

.reveal-answers {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* An answer row with the share of players who picked it drawn behind
   the text. Correct: the success tint and a 2px success frame, with a
   ti-check. The player's own pick adds ti-user (and ti-x when wrong). */
.reveal-answer {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    overflow: hidden;
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.reveal-answer.correct {
    border-color: var(--success-text);
    background: var(--success-tint);
    box-shadow: inset 0 0 0 1px var(--success-text);
}

.reveal-answer.my-pick.incorrect {
    border-color: var(--danger-text);
    background: var(--danger-tint);
    box-shadow: inset 0 0 0 1px var(--danger-text);
}

.reveal-answer-bar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.05);
    transition: width 0.6s ease;
}

[data-theme="dark"] .reveal-answer-bar {
    background: rgba(255, 255, 255, 0.06);
}

.reveal-answer-text {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-primary);
    font-weight: 500;
}

.reveal-answer.correct .reveal-answer-text {
    font-weight: 700;
}

.reveal-answer.correct .reveal-answer-text > .ti-check {
    color: var(--success-text);
}

.reveal-answer.my-pick.incorrect .reveal-answer-text > .ti-x {
    color: var(--danger-text);
}

.reveal-answer-count {
    position: relative;
    z-index: 1;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    font-weight: 600;
    white-space: nowrap;
}

.reveal-explanation {
    margin: 1rem 0 0;
}

/* The shared .callout sets no link colour: a link in the explanation
   takes the readable primary text token and an underline, as in the
   results review (results.css .question-result-explanation a). */
.reveal-explanation a {
    color: var(--primary-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ---------- Leaderboard ----------
   On the reveal screen the title, rows and the host / player controls
   share one panel, so the controls and the waiting note read on the
   card colour rather than the page background. */
.leaderboard-title {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0 0 0.75rem;
}

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.lb-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 10px 14px;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.lb-row.top-three {
    border-color: var(--primary-soft);
}

.lb-rank {
    min-width: 32px;
    color: var(--text-muted);
    font-weight: 700;
    text-align: center;
}

.lb-name {
    flex: 1;
    color: var(--text-primary);
    font-weight: 500;
    text-align: left;
}

.lb-score {
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Medals carry the rank as text ('1st'); the colour is decoration. */
.medal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-pill);
    background: var(--neutral-tint);
    color: var(--text-primary);
    font-size: var(--fs-2xs);
    font-weight: 800;
}

.medal.gold {
    border-color: var(--brand-gold);
    background: var(--ce-tint);
    color: var(--ce-text);
}

.medal.silver {
    border-color: var(--border-strong);
    background: var(--neutral-tint);
    color: var(--text-secondary);
}

.medal.bronze {
    border-color: var(--warning-border);
    background: var(--warning-tint);
    color: var(--warning-text);
}

/* ---------- Host late-join card ----------
   Sits under the active question / reveal screen. */
.host-code-card {
    max-width: 520px;
    margin: 2.5rem auto 0;
    padding: 0.85rem 1.5rem;
}

.host-code-card-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
}

.host-code-card-label {
    color: var(--text-secondary);
    font-size: 1.25rem;
    font-weight: 700;
}

.host-code-card-code {
    padding: 0.3rem 0.85rem;
    border-radius: var(--r-sm);
    background: var(--primary-tint);
    color: var(--primary-text);
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.25em;
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
    .mp-card {
        padding: 2rem 1.25rem;
    }

    .join-code-value {
        font-size: 2.2rem;
        letter-spacing: 5px;
    }

    .form-control.code-input {
        font-size: 1.3rem;
        letter-spacing: 4px;
    }

    .host-code-card {
        padding: 0.75rem 1rem;
    }

    .host-code-card-code {
        font-size: 1.25rem;
        letter-spacing: 0.2em;
    }
}
