/*
 * battle.css — Battle Mode (multiplayer quiz race).
 *
 * Sections:
 *   - Battle Mode v1 (folder tab list, lobby, playing, finished)
 *   - Battle Mode v2 (empty-state hero + picking phase)
 *   - Battle Mode Phase 1 effects (input flash, +pts floater, screen flash)
 *
 * Loaded on every page (folder detail still references the active-battle
 * resume card), so it isn't worth gating to /battle/ pages only.
 */

/* ==========================================================
   Battle Mode
   ========================================================== */

/* --- Folder tab: active battles list --- */
.battle-tab {
    padding: 8px 0;
}
.battle-tab-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.battle-tab-title {
    font-size: var(--fs-lg);
    margin: 0;
    font-weight: var(--fw-semibold);
}
.battle-tab-subtitle {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    margin: 0 0 1.2rem 0;
}
.battle-tab-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.battle-active-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}
.battle-empty {
    grid-column: 1 / -1;
    color: var(--text-muted);
    font-style: italic;
    padding: 28px 0;
    text-align: center;
}
.battle-active-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    text-decoration: none;
    color: var(--text);
    transition: transform var(--transition), border-color var(--transition);
}
.battle-active-card:hover {
    transform: translateY(-1px);
    border-color: var(--primary);
}
.battle-active-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.battle-active-deck {
    font-weight: var(--fw-semibold);
    font-size: var(--fs-md);
}
.battle-active-state {
    font-size: var(--fs-xs);
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: var(--fw-medium);
}
.battle-state-lobby {
    background: var(--primary-light);
    color: var(--primary);
}
.battle-state-playing {
    background: rgba(14, 124, 90, 0.12);
    color: var(--green);
}
.battle-active-card-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.battle-active-avatars {
    display: flex;
    align-items: center;
}
.battle-active-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--surface);
    margin-left: -6px;
    background: var(--bg);
}
.battle-active-avatar:first-child {
    margin-left: 0;
}
.battle-active-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: var(--fw-bold);
    font-size: var(--fs-xs);
}
.battle-active-more {
    margin-left: 6px;
    font-size: var(--fs-xs);
    color: var(--text-muted);
}
.battle-active-meta {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

/* --- Battle page --- */
.battle-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}
.battle-head {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}
.battle-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background var(--transition);
}
.battle-back:hover {
    background: var(--bg);
}
.battle-title {
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    margin: 0;
    flex: 1;
}
.battle-meta {
    color: var(--text-muted);
    font-size: var(--fs-sm);
}

.battle-state-panel {
    animation: battlePanelIn 280ms ease;
}
@keyframes battlePanelIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* --- Lobby --- */
.battle-lobby-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 600px;
    margin: 24px auto;
}
.battle-lobby-head {
    text-align: center;
    margin-bottom: 24px;
}
.battle-lobby-title {
    font-size: var(--fs-xl);
    margin: 0 0 6px 0;
}
.battle-lobby-sub {
    color: var(--text-muted);
    margin: 0;
    font-size: var(--fs-sm);
}
.battle-share {
    background: var(--bg);
    padding: 14px 16px;
    border-radius: var(--radius);
    margin-bottom: 24px;
}
.battle-share-label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.battle-share-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.battle-share-input {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.85rem;
    color: var(--text);
    text-overflow: ellipsis;
}
.battle-share-input:focus {
    outline: none;
    border-color: var(--ink, var(--primary));
    box-shadow: 0 0 0 3px rgba(30, 64, 232, 0.12);
}
.battle-share-copy {
    flex-shrink: 0;
    padding: 0 18px;
    font-weight: 600;
}
.battle-players-section {
    margin-bottom: 24px;
}
.battle-players-title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    margin: 0 0 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.battle-players-count {
    background: var(--primary-light);
    color: var(--primary);
    padding: 1px 8px;
    border-radius: 999px;
    font-size: var(--fs-xs);
}
.battle-players-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.battle-player-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color var(--transition), background var(--transition);
}
.battle-player-row.battle-player-ready {
    border-color: var(--green);
    background: rgba(14, 124, 90, 0.05);
}
.battle-player-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg);
    flex-shrink: 0;
}
.battle-player-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: var(--fw-bold);
}
.battle-player-name {
    font-weight: var(--fw-semibold);
    flex: 1;
}
.battle-player-host {
    font-size: 10px;
    background: var(--primary);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    font-weight: var(--fw-bold);
}
.battle-player-ready-tag {
    color: var(--green);
    font-weight: var(--fw-medium);
    font-size: var(--fs-sm);
}
.battle-player-waiting {
    color: var(--text-muted);
    font-size: var(--fs-sm);
}
.battle-lobby-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
}
.battle-lobby-hint {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    margin: 0;
    flex: 1;
    min-width: 200px;
}
.battle-start-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.battle-start-arrow {
    transition: transform 180ms ease;
}
.battle-start-btn:hover:not(:disabled) .battle-start-arrow {
    transform: translateX(3px);
}

/* --- Playing --- */
/* --- Playing screen: progress bar + scoreboard strip + centered question --- */
.battle-progress {
    position: relative;
    height: 6px;
    width: 100%;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin: 4px 0 18px;
}
.battle-progress-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background: linear-gradient(
        90deg,
        var(--ink, var(--primary)),
        var(--primary)
    );
    border-radius: 999px;
    transition: width 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Top scoreboard strip — horizontal player cards, scrollable on overflow. */
.battle-scorestrip {
    list-style: none;
    margin: 0 0 24px;
    padding: 0;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: visible;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}
.battle-scorestrip::-webkit-scrollbar { height: 6px; }
.battle-scorestrip::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}
.battle-scorestrip-card {
    position: relative;
    flex: 0 0 auto;
    min-width: 168px;
    display: grid;
    grid-template-columns: 38px 1fr auto;
    column-gap: 10px;
    align-items: center;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    scroll-snap-align: start;
    transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}
.battle-scorestrip-card-self {
    border-color: var(--ink, var(--primary));
    background: var(--primary-light, rgba(30, 64, 232, 0.06));
}
.battle-scorestrip-card-leader {
    border-color: var(--ink, var(--primary));
    box-shadow: 0 0 0 4px rgba(30, 64, 232, 0.10);
}
.battle-scorestrip-card-leader.battle-scorestrip-card-self {
    box-shadow: 0 0 0 4px rgba(30, 64, 232, 0.18);
}
.battle-scorestrip-card-answered::after {
    content: "";
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 0 var(--green);
    animation: battle-answered-pulse 1.6s ease-out 2;
}
.battle-scorestrip-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg);
    grid-row: span 2;
}
.battle-scorestrip-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 700;
    background: var(--primary-light, rgba(30, 64, 232, 0.08));
    color: var(--ink, var(--primary));
}
.battle-scorestrip-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}
.battle-scorestrip-score {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.battle-scorestrip-rank {
    grid-row: span 2;
    align-self: center;
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
.battle-scorestrip-card-leader .battle-scorestrip-rank {
    color: var(--ink, var(--primary));
}
.battle-rank-arrow {
    width: 10px;
    height: 10px;
}
.battle-rank-arrow-up {
    color: var(--green);
    animation: battle-rank-bounce 0.55s ease;
}
.battle-rank-arrow-down {
    color: var(--red);
    animation: battle-rank-bounce 0.55s ease;
}
@keyframes battle-rank-bounce {
    0%   { transform: translateY(0); }
    40%  { transform: translateY(-3px); }
    100% { transform: translateY(0); }
}

/* Centered question column. */
.battle-play-main {
    max-width: 720px;
    margin: 0 auto;
}
.battle-round-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--primary-light, rgba(30, 64, 232, 0.08));
    color: var(--ink, var(--primary));
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-variant-numeric: tabular-nums;
}
.battle-round-chip-sep {
    opacity: 0.5;
}
.battle-question-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    min-height: 240px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.battle-question {
    font-size: 1.65rem;
    line-height: 1.45;
    margin-bottom: 28px;
    text-align: center;
    color: var(--text);
    font-weight: 500;
}
.battle-input-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.battle-input-row {
    display: flex;
    gap: 8px;
}
.battle-text-input {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--fs-md);
    transition: border-color var(--transition);
}
.battle-text-input:focus {
    outline: none;
    border-color: var(--primary);
}
.battle-text-input:disabled {
    background: var(--bg);
    color: var(--text-muted);
}
.battle-submit-btn {
    padding: 14px 24px;
}
.battle-choice-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition);
    font-size: var(--fs-md);
    color: var(--text);
}
.battle-choice-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
}
.battle-choice-btn.battle-choice-selected {
    border-color: var(--primary);
    background: var(--primary-light);
}
.battle-choice-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}
.battle-choice-label {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-bold);
    font-size: var(--fs-sm);
    flex-shrink: 0;
}
.battle-choice-text {
    flex: 1;
}
.battle-feedback {
    margin-top: 12px;
    text-align: center;
    min-height: 24px;
}
.battle-feedback-correct {
    color: var(--green);
    font-weight: var(--fw-bold);
}
.battle-feedback-wrong {
    color: var(--red);
    font-weight: var(--fw-bold);
}

.battle-round-result {
    margin-top: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 16px 20px;
    border-left: 4px solid var(--primary);
}
.battle-round-result-head {
    font-size: var(--fs-md);
    margin-bottom: 8px;
}
.battle-round-result-answer {
    color: var(--text-soft);
    font-size: var(--fs-sm);
}
.battle-round-result-answer-text {
    color: var(--text);
    font-weight: var(--fw-semibold);
}

/* "Your opponent answered" pulse — used by the scoreboard strip cards. */
@keyframes battle-answered-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(14,124,90,0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(14,124,90,0); }
    100% { box-shadow: 0 0 0 0 rgba(14,124,90,0); }
}
@media (prefers-reduced-motion: reduce) {
    .battle-scorestrip-card-answered::after { animation: none; }
    .battle-rank-arrow-up,
    .battle-rank-arrow-down { animation: none; }
}

/* --- Finished --- */
.battle-finished-card {
    max-width: 720px;
    margin: 24px auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
}
.battle-finished-title {
    text-align: center;
    font-size: var(--fs-xl);
    margin: 0 0 28px 0;
}

.battle-podium {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 32px;
    min-height: 200px;
}
.battle-podium-spot {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 22px;
    border-radius: var(--radius);
    text-align: center;
}
.battle-podium-spot-1 {
    background: linear-gradient(180deg, #FFD700, #FFA500);
    color: #1a1a1a;
    height: 200px;
    width: 160px;
    transform: translateY(-12px);
    box-shadow: 0 8px 24px rgba(255, 165, 0, 0.3);
}
.battle-podium-spot-2 {
    background: linear-gradient(180deg, #C0C0C0, #909090);
    color: #1a1a1a;
    height: 170px;
    width: 140px;
}
.battle-podium-spot-3 {
    background: linear-gradient(180deg, #CD7F32, #8B5A2B);
    color: white;
    height: 150px;
    width: 130px;
}
.battle-podium-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid white;
    margin-bottom: 8px;
}
.battle-podium-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: white;
    color: var(--primary);
    font-weight: var(--fw-bold);
    font-size: 1.2rem;
}
.battle-podium-name {
    font-weight: var(--fw-bold);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
}
.battle-podium-score {
    font-size: 1.5rem;
    font-weight: var(--fw-bold);
}
.battle-podium-rank {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.8;
}

.battle-leaderboard {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}
.battle-leaderboard th,
.battle-leaderboard td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-sm);
}
.battle-leaderboard th {
    font-weight: var(--fw-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: var(--fs-xs);
}
.battle-finished-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* --- Mobile --- */
@media (max-width: 720px) {
    .battle-question-card {
        padding: 28px 20px;
    }
    .battle-question {
        font-size: 1.25rem;
        margin-bottom: 22px;
    }
    .battle-scorestrip-card {
        min-width: 148px;
        padding: 8px 12px;
    }
    .battle-podium {
        gap: 8px;
    }
    .battle-podium-spot {
        padding: 12px;
    }
    .battle-podium-spot-1 { width: 120px; height: 170px; }
    .battle-podium-spot-2 { width: 100px; height: 140px; }
    .battle-podium-spot-3 { width: 96px; height: 120px; }
}

/* ============================================================
   Battle Mode v2 — empty-state hero + picking phase
   ============================================================ */

/* --- Folder Battle tab: empty-state hero ---
   Compact horizontal intro (icon + title/sub side-by-side) so the
   Create-Room form lands close to the tab bar instead of pushing
   below the fold. */
.battle-empty-hero {
    max-width: 560px;
    margin: 16px auto 24px;
    padding: 0 16px;
}
.battle-empty-intro {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
    padding: 0 4px;
}
.battle-empty-intro-text {
    min-width: 0;
}
.battle-empty-icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--tint, rgba(30, 64, 232, 0.08));
    color: var(--ink, var(--primary));
    display: flex;
    align-items: center;
    justify-content: center;
}
.battle-empty-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    line-height: 1.2;
}
.battle-empty-sub {
    margin: 2px 0 0;
    font-size: 0.95rem;
    color: var(--text-muted);
}
.battle-empty-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    text-align: left;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
/* Empty-state Create-a-Battle form fields (deck dropdown + cards slider). */
.battle-create-field {
    margin-bottom: 16px;
}
.battle-create-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}
.battle-cards-value {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--ink, var(--primary));
    font-variant-numeric: tabular-nums;
    line-height: 1;
    padding: 4px 12px;
    border-radius: 8px;
    background: var(--tint, rgba(30, 64, 232, 0.08));
}

/* Deck dropdown — clean, accent-aware, custom chevron. */
.battle-deck-select-wrap {
    position: relative;
}
.battle-deck-select {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    padding: 12px 40px 12px 14px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.battle-deck-select:hover:not(:disabled) {
    border-color: var(--ink, var(--primary));
}
.battle-deck-select:focus {
    outline: none;
    border-color: var(--ink, var(--primary));
    box-shadow: 0 0 0 3px rgba(30, 64, 232, 0.12);
}
.battle-deck-select:disabled {
    background: var(--bg);
    color: var(--text-muted);
    cursor: not-allowed;
}
.battle-deck-select-chev {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* Cards slider — custom-styled track with accent fill. */
.battle-empty-slider {
    --fill: 0%;
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(
        to right,
        var(--ink, var(--primary)) 0%,
        var(--ink, var(--primary)) var(--fill, 0%),
        var(--border) var(--fill, 0%),
        var(--border) 100%
    );
    outline: none;
    cursor: pointer;
    margin: 4px 0 2px;
}
.battle-empty-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--ink, var(--primary));
    border: 3px solid var(--surface);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    cursor: grab;
    transition: transform 120ms ease;
}
.battle-empty-slider::-webkit-slider-thumb:hover {
    transform: scale(1.08);
}
.battle-empty-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.12);
}
.battle-empty-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--ink, var(--primary));
    border: 3px solid var(--surface);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    cursor: grab;
}
.battle-empty-slider-hint {
    margin: 8px 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.battle-empty-create-btn.btn-block {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
}
.btn-block { width: 100%; display: block; }
.battle-empty-error {
    min-height: 1.2em;
    margin: 8px 0 0;
    color: var(--red);
    font-size: 0.85rem;
    text-align: center;
}

/* --- Folder Battle tab: resume card --- */
.battle-resume {
    max-width: 720px;
    margin: 32px auto 0;
}
.battle-resume-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 24px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.battle-resume-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.battle-resume-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}
.battle-resume-state {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--tint, rgba(30, 64, 232, 0.1));
    color: var(--ink, var(--primary));
}
.battle-resume-state.battle-state-playing {
    background: rgba(14, 124, 90, 0.1);
    color: var(--green);
}
.battle-resume-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.battle-resume-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.92rem;
    color: var(--text-muted);
}
.battle-resume-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--tint, #eef);
}
.battle-resume-avatar-initial {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--ink, var(--primary));
}
.battle-resume-host {
    font-weight: 600;
    color: var(--text);
}
.battle-resume-dot {
    color: var(--text-muted);
}
.battle-resume-cta {
    padding: 8px 18px;
    font-weight: 600;
}

/* --- Battle page: lobby additions (room code, info text) --- */
.battle-lobby-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    border-radius: 14px;
    background: var(--tint, rgba(30, 64, 232, 0.08));
    color: var(--ink, var(--primary));
    display: flex;
    align-items: center;
    justify-content: center;
}
.battle-lobby-info {
    margin: 16px 0;
    padding: 14px 18px;
    background: var(--tint, rgba(30, 64, 232, 0.06));
    border-radius: 12px;
    color: var(--ink, var(--primary));
    font-size: 0.9rem;
    text-align: center;
    line-height: 1.5;
}
.battle-lobby-info strong {
    font-weight: 700;
}
/* Mobile adjustments */
@media (max-width: 720px) {
    .battle-empty-hero {
        margin: 12px 12px 20px;
        padding: 0 4px;
    }
    .battle-empty-intro {
        gap: 12px;
    }
    .battle-empty-card {
        padding: 18px;
    }
    .battle-resume {
        margin: 16px;
    }
}


/* ==========================================================
   Battle Mode — Phase 1 effects layer
   Per-question dopamine: input flash, +pts floater, screen flash,
   question-card shake, streak chip with tier escalation, hype
   banners, round-win banner. All effects are event-driven; UI is
   fully still between events (per the "no idle motion" rule).
   ========================================================== */

/* --- Input flash (green = correct, red = wrong) --- */
.battle-input-flash-green {
    animation: battle-flash-green 500ms ease-out;
    border-radius: 12px;
}
.battle-input-flash-red {
    animation: battle-flash-red 500ms ease-out;
    border-radius: 12px;
}
@keyframes battle-flash-green {
    0%   { box-shadow: 0 0 0 0 rgba(14,124,90,0);    background-color: rgba(14,124,90,0); }
    25%  { box-shadow: 0 0 0 6px rgba(14,124,90,0.55); background-color: rgba(14,124,90,0.10); }
    100% { box-shadow: 0 0 0 16px rgba(14,124,90,0);   background-color: rgba(14,124,90,0); }
}
@keyframes battle-flash-red {
    0%   { box-shadow: 0 0 0 0 rgba(239,68,68,0);    background-color: rgba(239,68,68,0); }
    25%  { box-shadow: 0 0 0 6px rgba(239,68,68,0.55); background-color: rgba(239,68,68,0.10); }
    100% { box-shadow: 0 0 0 16px rgba(239,68,68,0);   background-color: rgba(239,68,68,0); }
}

/* --- Points floater (+1000 rises above the input) --- */
.battle-points-floater {
    position: fixed;
    z-index: 9001;
    pointer-events: none;
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 16px rgba(0,0,0,0.20);
    animation: battle-points-rise 1.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    transform: translate(-50%, 0);
    will-change: transform, opacity;
}
.battle-points-floater-base {
    background: linear-gradient(135deg, #1E40E8, #4d6cfb);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.battle-points-floater-good {
    background: linear-gradient(135deg, #1E40E8, #0E7C5A);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.battle-points-floater-great {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 0 16px rgba(245,158,11,0.45));
}
@keyframes battle-points-rise {
    0%   { opacity: 0; transform: translate(-50%, 12px)  scale(0.85); }
    20%  { opacity: 1; transform: translate(-50%, -16px) scale(1.15); }
    50%  { opacity: 1; transform: translate(-50%, -52px) scale(1.00); }
    100% { opacity: 0; transform: translate(-50%, -90px) scale(0.95); }
}

/* --- Screen flash (subtle full-viewport tint on each correct) --- */
.battle-screen-flash {
    position: fixed;
    inset: 0;
    z-index: 9000;
    pointer-events: none;
    mix-blend-mode: screen;
    animation: battle-screen-flash-fade 400ms ease-out forwards;
}
@keyframes battle-screen-flash-fade {
    0%   { opacity: 0.35; }
    100% { opacity: 0; }
}

/* --- Question-card shake (wrong answer) --- */
.battle-question-card-shake {
    animation: battle-shake-x 300ms ease-in-out;
}
@keyframes battle-shake-x {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-5px); }
    40%      { transform: translateX(5px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(3px); }
}

/* --- Self streak chip (bottom-right of play area, tier escalation) --- */
.battle-self-streak {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 50;
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
    background: linear-gradient(135deg, #facc15, #f59e0b);
    box-shadow: 0 4px 18px rgba(0,0,0,0.16);
    transition: background 200ms ease, box-shadow 200ms ease;
}
.battle-self-streak:not([hidden]) {
    display: inline-flex;
}
.battle-self-streak-emoji { font-size: 1.15rem; line-height: 1; }
.battle-self-streak-num { font-variant-numeric: tabular-nums; }

.battle-self-streak.tier-ember {
    background: linear-gradient(135deg, #facc15, #f59e0b);
}
.battle-self-streak.tier-storm {
    background: linear-gradient(135deg, #3b82f6, #1E40E8);
    box-shadow: 0 4px 22px rgba(30,64,232,0.35);
}
.battle-self-streak.tier-inferno {
    background: linear-gradient(135deg, #f87171, #ef4444);
    box-shadow: 0 4px 24px rgba(239,68,68,0.45);
}
.battle-self-streak.tier-legendary {
    background: linear-gradient(135deg, #fde047, #f59e0b 50%, #b45309);
    box-shadow: 0 0 26px rgba(245,158,11,0.65), 0 4px 20px rgba(0,0,0,0.20);
}
.battle-self-streak.is-pulsing {
    animation: battle-streak-punch 220ms ease;
}
@keyframes battle-streak-punch {
    0%   { transform: scale(1); }
    35%  { transform: scale(1.22); }
    70%  { transform: scale(1.04); }
    100% { transform: scale(1); }
}

/* --- "STREAK BROKEN" stamp (1s overlay when wrong after streak ≥3) --- */
.battle-streak-broken-stamp {
    position: fixed;
    left: 50%;
    top: 38%;
    z-index: 9001;
    pointer-events: none;
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 4px;
    color: #ef4444;
    text-shadow: 0 4px 22px rgba(239,68,68,0.4), 0 1px 0 rgba(0,0,0,0.15);
    animation: battle-stamp-pop 1.0s ease-out forwards;
    transform: translate(-50%, -50%);
}
@keyframes battle-stamp-pop {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(1.4) rotate(-6deg); }
    18%  { opacity: 1; transform: translate(-50%, -50%) scale(1.0) rotate(-3deg); }
    65%  { opacity: 1; transform: translate(-50%, -50%) scale(1.0) rotate(-3deg); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.92) rotate(-3deg); }
}

/* --- Round-win banner ("FIRST!  Alex  +1000") --- */
.battle-question-card { position: relative; }
.battle-round-win-banner {
    position: absolute;
    left: 50%;
    top: -12px;
    transform: translate(-50%, -100%);
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-radius: 999px;
    background: linear-gradient(135deg, #1E40E8, #4d6cfb);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 12px 30px rgba(30,64,232,0.30);
    animation: battle-round-win-pop 1.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    white-space: nowrap;
}
.battle-round-win-banner-self {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    box-shadow: 0 14px 30px rgba(245,158,11,0.40);
}
.battle-round-win-banner-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 0.85rem;
    font-weight: 700;
}
.battle-round-win-banner-avatar img {
    width: 100%; height: 100%; object-fit: cover;
}
.battle-round-win-banner-name { font-size: 0.95rem; }
.battle-round-win-banner-pts {
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.22);
    font-size: 0.85rem;
    letter-spacing: 0.3px;
}
@keyframes battle-round-win-pop {
    0%   { opacity: 0; transform: translate(-50%, -130%) scale(0.9); }
    15%  { opacity: 1; transform: translate(-50%, -100%) scale(1.05); }
    25%  { opacity: 1; transform: translate(-50%, -100%) scale(1.0); }
    80%  { opacity: 1; transform: translate(-50%, -100%) scale(1.0); }
    100% { opacity: 0; transform: translate(-50%, -120%) scale(0.95); }
}

/* Mobile: shrink streak chip + stamp so they don't crowd the input. */
@media (max-width: 720px) {
    .battle-self-streak {
        right: 12px;
        bottom: 12px;
        padding: 6px 12px;
        font-size: 0.95rem;
    }
    .battle-streak-broken-stamp {
        font-size: 2rem;
        letter-spacing: 2px;
    }
    .battle-round-win-banner {
        padding: 8px 14px;
        font-size: 0.9rem;
    }
    .battle-points-floater {
        font-size: 1.9rem;
    }
}

/* Reduced-motion: keep color/text feedback, drop big motion. */
@media (prefers-reduced-motion: reduce) {
    .battle-question-card-shake,
    .battle-self-streak.is-pulsing {
        animation: none;
    }
    .battle-screen-flash {
        opacity: 0.15;
        animation: none;
    }
    .battle-points-floater,
    .battle-streak-broken-stamp,
    .battle-round-win-banner {
        animation-duration: 0.25s;
    }
}

/* ==========================================================
   Animated mascots (BattleCharacter.js)

   The placeholder span carries one of three avatar size classes
   (.battle-player-avatar, .battle-scorestrip-avatar, .battle-podium-avatar)
   AND .battle-character-slot. The size class still wins for outer
   dimensions, but the slot rules below override the circular crop +
   solid background that the avatar style applies (mascots have their
   own shape and shouldn't be clipped into circles).

   Character SVGs use viewBox 0 0 120 150 (4:5). preserveAspectRatio
   in the SVG handles letterboxing when the slot box is more square,
   so the character is always centered and never stretched.
   ========================================================== */
.battle-character-slot {
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow: visible !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Hint to the browser: animations will mutate transforms below. */
    will-change: transform;
}
.battle-character-slot svg {
    width: 130%;
    height: 130%;
    display: block;
    overflow: visible;
}
/* Podium slot gets a bigger character — it's the celebration moment. */
.battle-podium-avatar.battle-character-slot {
    width: 72px;
    height: 90px;
}
.battle-podium-avatar.battle-character-slot svg {
    width: 100%;
    height: 100%;
}

/* ==========================================================
   Character picker modal (battle lobby "Change mascot")
   ========================================================== */
.battle-mascot-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--color-border-tertiary, rgba(0,0,0,0.15));
    border-radius: var(--border-radius-md, 8px);
    color: var(--ink, var(--text-primary));
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
}
.battle-mascot-cta:hover {
    background: rgba(0,0,0,0.04);
}
.battle-mascot-cta-preview {
    display: inline-block;
    width: 28px;
    height: 35px;
}
.battle-mascot-cta-preview svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}
.battle-mascot-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 16px 0 8px;
}
.battle-mascot-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    background: transparent;
    border: 1.5px solid var(--color-border-tertiary, rgba(0,0,0,0.12));
    border-radius: var(--border-radius-md, 8px);
    cursor: pointer;
    font: inherit;
}
.battle-mascot-tile:hover {
    background: rgba(30, 64, 232, 0.04);
    border-color: var(--primary, #1E40E8);
}
.battle-mascot-tile-selected {
    background: rgba(30, 64, 232, 0.08);
    border-color: var(--primary, #1E40E8);
    border-width: 2px;
}
.battle-mascot-tile-art {
    width: 64px;
    height: 80px;
    display: inline-block;
}
.battle-mascot-tile-art svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}
.battle-mascot-tile-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary, #1A2E3A);
}


/* ==========================================================
   Group Study rating chips — shown next to player names in
   lobby roster, scoreboard, podium, leaderboard table.
   Per-folder Elo rating; "?" flag for provisional players.
   ========================================================== */
.bp-rating-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(0,0,0,0.06);
    color: var(--text, #111);
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
}
.bp-rating-prov {
    margin-left: 1px;
    color: var(--text-muted, #777);
    font-weight: 500;
}
.bp-rating-delta-up,
.bp-rating-delta-down,
.bp-rating-delta-zero {
    font-size: 0.85em;
    margin-left: 2px;
    font-weight: 700;
}
.bp-rating-delta-up   { color: var(--green, #16a34a); }
.bp-rating-delta-down { color: var(--red, #dc2626); }
.bp-rating-delta-zero { color: var(--text-muted, #999); }
