/* ═══════════════════════════════════════════════════════════════════
   Live Classroom — CSS
   Premium dark glass-morphism theme
   ═══════════════════════════════════════════════════════════════════ */

/* iOS "Tap to listen" button pulsing animation */
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0   rgba(167, 139, 250, 0.7); transform: scale(1); }
    50%  { box-shadow: 0 0 0 8px rgba(167, 139, 250, 0);   transform: scale(1.04); }
    100% { box-shadow: 0 0 0 0   rgba(167, 139, 250, 0);   transform: scale(1); }
}
#cr-ios-unlock-btn {
    animation: pulse 1.5s ease-in-out infinite;
    white-space: nowrap;
}

/* ─── Fullscreen Layout ─── */
.classroom-page {
    position: fixed; inset: 0;
    background-color: #f8f9fa;
    background-image: none;
    display: flex; flex-direction: column;
    z-index: 1000;
    font-family: 'Baloo 2', sans-serif;
    color: #1a1a2e;
}

/* ─── Toolbar ─── */
.cr-toolbar {
    display: flex; align-items: center; gap: 4px;
    padding: 6px 12px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.cr-toolbar-title {
    font-weight: 800; font-size: 0.95rem;
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    margin-right: 8px;
    white-space: nowrap;
}

.cr-toolbar-divider {
    width: 1px; height: 28px;
    background: #e2e8f0;
    margin: 0 4px;
}

.cr-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 36px; height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #4a5568;
    font-size: 0.78rem; font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    gap: 5px;
    white-space: nowrap;
    font-family: inherit;
}
.cr-btn:hover {
    background: #f0edff;
    border-color: rgba(108,92,231,0.4);
    color: #6C5CE7;
}
.cr-btn.active {
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    border-color: #6C5CE7;
    color: #fff;
    box-shadow: 0 2px 8px rgba(108,92,231,0.3);
}
.cr-btn.danger {
    background: #fff5f5;
    border-color: rgba(231,76,60,0.3);
    color: #e74c3c;
}
.cr-btn.danger:hover {
    background: #ffe5e5;
}
.cr-btn.success {
    background: #f0fdf4;
    border-color: rgba(46,204,113,0.3);
    color: #16a34a;
}

/* ─── Main Content ─── */
.cr-content {
    flex: 1; display: flex;
    overflow: hidden;
    min-height: 0;
}

/* ─── Board Area (Left) ─── */
.cr-board-area {
    flex: 1; display: flex; flex-direction: column;
    align-items: center;
    padding: 12px;
    min-width: 0;
    position: relative;
    overflow-y: auto;
    background: #f1f5f9;
}

.cr-board-wrapper {
    position: relative;
    width: 100%;
    max-width: min(65vh, 560px);
    aspect-ratio: 1;
    box-shadow: 0 8px 32px rgba(108,92,231,0.18), 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 6px;
}

/* Desktop: expand board to 80% of viewport height */
@media (min-width: 1024px) {
    .cr-board-wrapper {
        max-width: min(75vh, 720px);
    }
    .cr-move-list {
        max-width: min(75vh, 720px);
    }
    .cr-nav-buttons {
        max-width: min(75vh, 720px);
    }
}

/* During active question — prevent ALL browser gestures on the board
   so Chessground can receive touch events for piece dragging */
.cr-board-wrapper.cr-question-active {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.cr-board-wrapper.cr-question-active cg-wrap {
    touch-action: none;
}

/* Bug #5 fix: Also apply touch-action when student has allowMoveColor permission
   (outside of question mode). Without this, Android/iOS browser intercepts
   touch events as scroll/zoom instead of letting Chessground handle piece drag. */
.cr-board-wrapper.cr-move-allowed {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.cr-board-wrapper.cr-move-allowed cg-wrap {
    touch-action: none;
}

.cr-board-wrapper cg-board {
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

/* Move list below board */
.cr-move-list {
    width: 100%;
    max-width: min(65vh, 560px);
    margin-top: 8px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 6px 10px;
    max-height: 140px;
    overflow-y: auto;
    display: flex; flex-wrap: wrap; gap: 2px;
    align-content: flex-start;
    align-items: baseline;
}

.cr-move-list::-webkit-scrollbar { width: 4px; }
.cr-move-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.cr-move-btn {
    padding: 2px 6px; border-radius: 4px;
    border: none; background: transparent;
    color: #475569;
    font-size: 0.75rem; cursor: pointer;
    font-family: monospace;
    transition: all 0.1s;
}
.cr-move-btn:hover { background: #f0edff; color: #6C5CE7; }
.cr-move-btn.active {
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    color: #fff; font-weight: 700;
    box-shadow: 0 2px 8px rgba(108,92,231,0.3);
}
.cr-move-num {
    color: #94a3b8;
    font-size: 0.7rem;
    padding: 2px 2px;
    font-family: monospace;
}

/* ─── Move Tree (Lichess-style) ─── */
.cr-move-tree {
    display: inline; /* flow inline like text */
    font-size: 0.75rem;
    line-height: 1.8;
}

/* Comment text in { } braces */
.cr-comment {
    color: #9ca3af;
    font-style: italic;
    font-size: 0.7rem;
    margin: 0 3px;
    word-break: break-word;
}

/* Variation block ( ... ) */
.cr-variation {
    display: block;
    margin: 1px 0 1px 14px;
    padding: 2px 6px;
    border-left: 2px solid rgba(108,92,231,0.25);
    color: #64748b;
    font-size: 0.7rem;
    line-height: 1.7;
}

/* Moves inside a variation */
.cr-move-btn.cr-var-move {
    font-size: 0.7rem;
    color: #64748b;
    padding: 1px 4px;
}
.cr-move-btn.cr-var-move:hover { color: #6C5CE7; background: #f0edff; }
.cr-move-btn.cr-var-move.active {
    background: rgba(108,92,231,0.2);
    color: #6C5CE7;
    font-weight: 700;
}

/* NAG annotation badge (!, ?, !?, ?!) */
.cr-nag {
    font-size: 0.65rem;
    font-weight: 800;
    color: #f59e0b;
    margin-left: 1px;
    font-style: normal;
}

/* Move navigation buttons */
.cr-nav-buttons {
    display: flex; gap: 4px; margin-top: 6px;
    max-width: min(65vh, 560px); width: 100%;
    justify-content: center;
}

.cr-nav-btn {
    padding: 6px 14px; border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #475569;
    font-size: 0.85rem; cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    font-weight: 600;
}
.cr-nav-btn:hover {
    background: #f0edff;
    border-color: rgba(108,92,231,0.4);
    color: #6C5CE7;
}

/* ─── Right Sidebar ─── */
.cr-sidebar {
    width: 320px;
    display: flex; flex-direction: column;
    border-left: 1px solid #e2e8f0;
    background: #ffffff;
    overflow: hidden;
}

.cr-sidebar-tabs {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
}

.cr-sidebar-tab {
    flex: 1;
    padding: 10px 4px;
    text-align: center;
    font-size: 0.75rem; font-weight: 700;
    color: #94a3b8;
    cursor: pointer;
    border: none; background: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-family: inherit;
}
.cr-sidebar-tab:hover { color: #6C5CE7; }
.cr-sidebar-tab.active {
    color: #6C5CE7;
    border-bottom-color: #6C5CE7;
}

.cr-sidebar-panel {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.cr-sidebar-panel::-webkit-scrollbar { width: 3px; }
.cr-sidebar-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ─── Chat ─── */
.cr-chat-messages {
    flex: 1; overflow-y: auto;
    display: flex; flex-direction: column;
    gap: 4px; padding: 6px;
    min-height: 0;
}

.cr-chat-msg {
    font-size: 0.78rem; line-height: 1.3;
    padding: 4px 8px; border-radius: 8px;
    background: #f8fafc;
    word-break: break-word;
    color: #334155;
}
.cr-chat-msg-name {
    font-weight: 700; font-size: 0.72rem;
    margin-right: 4px;
}
.cr-chat-msg-name.admin { color: #e74c3c; }
.cr-chat-msg-name.student { color: #3498db; }

.cr-chat-input-bar {
    display: flex; gap: 6px;
    padding: 8px;
    border-top: 1px solid #e2e8f0;
}

.cr-chat-input {
    flex: 1;
    padding: 8px 12px; border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #1e293b; font-size: 0.8rem;
    outline: none;
    font-family: inherit;
}
.cr-chat-input::placeholder { color: #94a3b8; }
.cr-chat-input:focus {
    border-color: rgba(108,92,231,0.4);
    background: #fff;
}

.cr-chat-send {
    padding: 8px 14px; border-radius: 10px;
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    color: #fff; border: none;
    font-weight: 700; cursor: pointer;
    font-family: inherit;
}

/* ─── Leaderboard ─── */
.cr-lb-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    margin-bottom: 4px;
    transition: all 0.2s;
    color: #1e293b;
}
.cr-lb-item:nth-child(1) {
    background: linear-gradient(135deg, rgba(255,215,0,0.12), rgba(255,165,0,0.06));
    border-color: rgba(255,200,0,0.3);
}
.cr-lb-item:nth-child(2) {
    background: linear-gradient(135deg, rgba(100,116,139,0.1), rgba(148,163,184,0.06));
    border-color: rgba(148,163,184,0.3);
}
.cr-lb-item:nth-child(3) {
    background: linear-gradient(135deg, rgba(180,83,9,0.1), rgba(217,119,6,0.06));
    border-color: rgba(180,83,9,0.2);
}
.cr-lb-rank {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-weight: 800; font-size: 0.75rem;
    background: #e2e8f0;
    color: #475569;
    flex-shrink: 0;
}
.cr-lb-name {
    flex: 1; font-weight: 600; font-size: 0.82rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: #1e293b;
}
.cr-lb-score {
    font-weight: 800; font-size: 0.9rem;
    color: #6C5CE7;
}

/* ─── Participants ─── */
.cr-participant-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    margin-bottom: 3px;
    font-size: 0.8rem;
    color: #1e293b;
}
.cr-participant-name { flex: 1; font-weight: 600; color: #1e293b; }
.cr-participant-actions { display: flex; gap: 4px; }

.cr-participant-btn {
    width: 28px; height: 28px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.cr-participant-btn:hover {
    background: #f0edff;
    border-color: rgba(108,92,231,0.4);
    color: #6C5CE7;
}
.cr-participant-btn.active-hand {
    background: rgba(243,156,18,0.2);
    border-color: rgba(243,156,18,0.4);
    color: #f39c12;
    animation: handPulse 1s ease-in-out infinite;
}

@keyframes handPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(243,156,18,0.3); }
    50% { box-shadow: 0 0 0 6px rgba(243,156,18,0); }
}


/* ─── Question Overlay (Student) — LEGACY, kept for reference ─── */
.cr-question-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 20;
    animation: fadeIn 0.3s;
    padding: 20px;
}

.cr-question-card {
    background: linear-gradient(135deg, rgba(30,27,60,0.95), rgba(20,18,40,0.98));
    border: 1px solid rgba(108,92,231,0.3);
    border-radius: 20px;
    padding: 24px;
    max-width: 420px; width: 100%;
    box-shadow: 0 16px 64px rgba(0,0,0,0.6);
    text-align: center;
}

/* ─── Question Banner (Student — compact, below board) ─── */
.cr-question-banner {
    width: 100%;
    max-width: min(75vh, 720px);
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 14px;
    background: #ffffff;
    border: 2px solid #6C5CE7;
    box-shadow: 0 4px 16px rgba(108,92,231,0.15);
    animation: slideUp 0.3s ease;
}

.cr-qb-left {
    flex-shrink: 0;
}

.cr-qb-timer {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: #f0edff;
    border: 2px solid #6C5CE7;
    font-size: 1.3rem; font-weight: 800;
    color: #6C5CE7;
    transition: all 0.3s;
}
.cr-qb-timer.urgent {
    color: #e74c3c;
    border-color: #e74c3c;
    background: #fff5f5;
    animation: timerPulse 0.5s ease-in-out infinite;
}

.cr-qb-center {
    flex: 1;
    min-width: 0;
}

.cr-qb-text {
    font-size: 0.9rem; font-weight: 700;
    color: #1e293b;
    line-height: 1.3;
}

.cr-qb-hint {
    font-size: 0.72rem;
    color: #64748b;
    margin-top: 2px;
}

.cr-qb-right {
    display: flex; flex-direction: column;
    gap: 2px;
    font-size: 0.75rem; font-weight: 700;
    flex-shrink: 0;
    text-align: right;
    color: #475569;
}

.cr-question-text {
    font-size: 1.1rem; font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #fff, #a78bfa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.cr-question-timer {
    font-size: 2rem; font-weight: 800;
    margin: 12px 0;
}
.cr-question-timer.urgent { color: #e74c3c; animation: timerPulse 0.5s ease-in-out infinite; }

@keyframes timerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.cr-question-hint {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.5);
    margin-top: 8px;
}

/* Answer feedback */
.cr-answer-feedback {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    z-index: 30;
    animation: answerPop 0.8s ease forwards;
    pointer-events: none;
}

@keyframes answerPop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1) translateY(-30px); opacity: 0; }
}

/* ─── Ask Question Dialog (Admin) ─── */
.cr-ask-dialog {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    max-width: 400px; width: 90%;
}
.cr-ask-dialog label {
    display: block;
    font-size: 0.85rem; font-weight: 700;
    color: #475569;
    margin-bottom: 6px;
    margin-top: 12px;
}
.cr-ask-dialog input, .cr-ask-dialog textarea {
    width: 100%;
    padding: 10px 12px; border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e293b; font-size: 0.9rem;
    font-family: inherit; outline: none;
    transition: all 0.2s;
}
.cr-ask-dialog input:focus, .cr-ask-dialog textarea:focus {
    border-color: #6C5CE7;
    box-shadow: 0 0 0 3px rgba(108,92,231,0.15);
}

/* Question Tabs */
.cr-ask-tabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 15px;
}
.cr-ask-tab {
    padding: 10px 20px;
    font-weight: 700;
    color: #64748b;
    background: transparent;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.cr-ask-tab.active {
    color: #6C5CE7;
    border-bottom-color: #6C5CE7;
}

/* Eval Buttons for Admin */
.cr-eval-options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 10px;
}
.cr-eval-options-grid .cr-eval-opt {
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    font-weight: 700;
    text-align: center;
    transition: all 0.2s;
    font-size: 0.9rem;
}
.cr-eval-options-grid .cr-eval-opt:hover {
    border-color: #cbd5e1;
}
.cr-eval-options-grid .cr-eval-opt.active {
    border-color: #6C5CE7;
    background: #ede9fe;
    color: #4c1d95;
}

/* Eval Buttons for Students */
.cr-eval-student-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
    margin-top: 15px;
    width: 100%;
}
.cr-eval-btn {
    padding: 12px 6px;
    border: none;
    border-radius: 8px;
    font-weight: 800;
    font-size: 0.85rem;
    cursor: pointer;
    transition: transform 0.15s, filter 0.15s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}
.cr-eval-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}
.cr-eval-btn:active {
    transform: translateY(0);
}
.cr-eval-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}
.cr-eval-w-win { background: linear-gradient(135deg, #f1f5f9, #e2e8f0); color: #1e293b; border: 1px solid #cbd5e1; }
.cr-eval-w-adv { background: linear-gradient(135deg, #e0f2fe, #bae6fd); color: #0369a1; }
.cr-eval-w-slight { background: linear-gradient(135deg, #f0fdfa, #ccfbf1); color: #0f766e; }
.cr-eval-equal { background: linear-gradient(135deg, #e2e8f0, #94a3b8); color: #0f172a; }
.cr-eval-b-slight { background: linear-gradient(135deg, #64748b, #475569); color: #f8fafc; }
.cr-eval-b-adv { background: linear-gradient(135deg, #334155, #1e293b); color: #f8fafc; }
.cr-eval-b-win { background: linear-gradient(135deg, #0f172a, #020617); color: #f8fafc; border: 1px solid #334155; }

/* ─── Set Position Editor ─── */
.cr-fen-editor {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0;
    border: 2px solid rgba(108,92,231,0.3);
    border-radius: 4px;
    overflow: hidden;
}
.cr-fen-cell {
    aspect-ratio: 1;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}
.cr-fen-cell.light { background: #f0d9b5; }
.cr-fen-cell.dark { background: #b58863; }
.cr-fen-cell:hover { outline: 2px solid #6C5CE7; outline-offset: -2px; }

.cr-fen-pieces {
    display: flex; gap: 4px; flex-wrap: wrap;
    justify-content: center;
    padding: 8px;
}
.cr-fen-piece {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.15);
    background: rgba(0,0,0,0.04);
    cursor: pointer;
    transition: all 0.15s;
}
.cr-fen-piece:hover {
    background: rgba(108,92,231,0.2);
    border-color: rgba(108,92,231,0.4);
}
.cr-fen-piece.selected {
    background: rgba(108,92,231,0.3);
    border-color: #6C5CE7;
    box-shadow: 0 0 8px rgba(108,92,231,0.3);
}

/* ─── Status Bar ─── */
.cr-status-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 6px 14px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    font-size: 0.75rem;
    color: #64748b;
}
.cr-status-live {
    display: inline-flex; align-items: center; gap: 4px;
}
.cr-status-live::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #e74c3c;
    animation: livePulse 1.5s ease-in-out infinite;
}
@keyframes livePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ─── Pawn Structure Mode ─── */
.cr-pawn-mode piece:not([class*="pawn"]) {
    opacity: 0.07 !important;
    filter: grayscale(1) !important;
}

/* ─── Blind Mode ─── */
.cr-blind-mode piece {
    opacity: 0 !important;
}

/* ─── Student Join Card ─── */
.cr-join-card {
    max-width: 440px; width: 90%;
    background: linear-gradient(135deg, rgba(30,27,60,0.95), rgba(20,18,40,0.98));
    border: 1px solid rgba(108,92,231,0.25);
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 16px 64px rgba(0,0,0,0.5);
    text-align: center;
}

.cr-join-title {
    font-size: 1.4rem; font-weight: 800;
    background: linear-gradient(135deg, #a78bfa, #6C5CE7);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.cr-join-subtitle {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.5);
    margin-bottom: 20px;
}

.cr-join-btn {
    padding: 12px 32px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    color: #fff;
    border: none;
    font-size: 1rem; font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow: 0 4px 20px rgba(108,92,231,0.3);
}
.cr-join-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(108,92,231,0.5);
}

/* ─── Admin Classroom list (in admin dashboard) ─── */
.cr-admin-card {
    padding: 14px;
    border-radius: 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
    cursor: pointer;
    color: #1e293b;
}
.cr-admin-card:hover {
    border-color: rgba(108,92,231,0.3);
    background: #f0edff;
}

/* ─── Video area ─── */
.cr-video-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    margin-bottom: 8px;
}
.cr-video-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0,0,0,0.4);
    aspect-ratio: 16/9;
}
.cr-video-item video {
    width: 100%; height: 100%;
    object-fit: cover;
}
.cr-video-label {
    position: absolute; bottom: 4px; left: 6px;
    font-size: 0.65rem; font-weight: 700;
    background: rgba(0,0,0,0.6);
    padding: 2px 6px; border-radius: 4px;
}

/* ─── Animations ─── */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .cr-content {
        flex-direction: column;
    }
    .cr-sidebar {
        /* Mobile: floating popup for chat/scores/participants */
        position: fixed;
        bottom: 0; left: 0; right: 0;
        width: 100%;
        height: 70vh;
        border-left: none;
        border-top: 1px solid rgba(108,92,231,0.3);
        z-index: 50;
        display: none; /* toggled by chat btn */
        background: linear-gradient(180deg, rgba(20,18,40,0.98), rgba(10,8,25,0.99));
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
    }
    .cr-sidebar.cr-sidebar-open {
        display: flex;
    }
    /* PIP camera: small video at bottom-left of board area, always visible */
    .cr-video-grid {
        position: absolute;
        bottom: 8px; left: 8px;
        z-index: 15;
        width: 120px;
        border-radius: 10px;
        overflow: hidden;
        box-shadow: 0 4px 20px rgba(0,0,0,0.6);
        border: 1px solid rgba(108,92,231,0.3);
        background: rgba(0,0,0,0.5);
    }
    .cr-video-item {
        aspect-ratio: 4/3;
    }
    .cr-video-label {
        font-size: 0.55rem;
    }
    .cr-board-wrapper {
        max-width: min(50vh, 400px);
    }
    .cr-toolbar {
        padding: 4px 8px;
        gap: 3px;
    }
    .cr-btn {
        min-width: 30px; height: 30px;
        font-size: 0.72rem;
        padding: 0 6px;
    }
    .cr-move-list { max-height: 90px; }
    .cr-nav-buttons { gap: 2px; }
}

/* ─── Admin Live View (During Active Question) ─── */
.cr-admin-liveview {
    width: 100%;
    max-width: min(65vh, 560px);
    margin-top: 10px;
    background: linear-gradient(135deg, rgba(30,27,60,0.95), rgba(20,18,40,0.98));
    border: 1px solid rgba(108,92,231,0.3);
    border-radius: 16px;
    padding: 16px;
    animation: slideUp 0.3s ease;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);`n    color: #f8fafc;
}

.cr-lv-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.cr-lv-timer {
    width: 52px; height: 52px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(108,92,231,0.2), rgba(168,85,247,0.1));
    border: 2px solid rgba(108,92,231,0.4);
    font-size: 1.4rem; font-weight: 800;
    color: #a78bfa;
    flex-shrink: 0;
    transition: all 0.3s;
}
.cr-lv-timer.urgent {
    color: #e74c3c;
    border-color: rgba(231,76,60,0.6);
    background: rgba(231,76,60,0.15);
    animation: timerPulse 0.5s ease-in-out infinite;
}

.cr-lv-question-text {
    font-size: 0.9rem; font-weight: 700;
    color: rgba(255,255,255,0.85);
    margin-bottom: 8px;
    line-height: 1.3;
}

.cr-lv-topmoves {
    font-size: 0.78rem;
}

.cr-lv-movebar {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 3px;
}

.cr-lv-movename {
    width: 48px;
    font-weight: 700;
    font-size: 0.78rem;
    text-align: right;
    flex-shrink: 0;
    font-family: monospace;
}

.cr-lv-bartrack {
    flex: 1;
    height: 14px;
    background: rgba(255,255,255,0.06);
    border-radius: 4px;
    overflow: hidden;
}

.cr-lv-barfill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
    min-width: 2px;
}

.cr-lv-movecount {
    width: 24px;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(255,255,255,0.5);
    text-align: center;
}

.cr-lv-tabs {
    display: flex;
    gap: 4px;
    margin: 10px 0 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding-bottom: 8px;
}

.cr-lv-tab {
    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.03);
    color: rgba(255,255,255,0.5);
    font-size: 0.72rem; font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.cr-lv-tab:hover {
    background: rgba(108,92,231,0.1);
    color: rgba(255,255,255,0.8);
}
.cr-lv-tab.active {
    background: rgba(108,92,231,0.2);
    border-color: rgba(108,92,231,0.4);
    color: #a78bfa;
}

.cr-lv-students {
    max-height: 200px;
    overflow-y: auto;
}
.cr-lv-students::-webkit-scrollbar { width: 3px; }
.cr-lv-students::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.cr-lv-student-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 8px;
    margin-bottom: 2px;
    background: rgba(255,255,255,0.02);
    transition: background 0.15s;
}
.cr-lv-student-row:hover {
    background: rgba(255,255,255,0.05);
}

.cr-lv-student-name {
    flex: 1;
    font-size: 0.78rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cr-lv-student-move {
    font-size: 0.78rem;
    font-weight: 700;
    color: rgba(255,255,255,0.5);
    font-family: monospace;
    min-width: 40px;
    text-align: center;
}

.cr-lv-student-time {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.35);
    min-width: 40px;
    text-align: right;
}

@media (max-width: 480px) {
    .cr-board-wrapper {
        max-width: min(45vh, 320px);
    }
    .cr-sidebar { height: 35vh; }
    .cr-admin-liveview { padding: 10px; }
    .cr-lv-timer { width: 40px; height: 40px; font-size: 1.1rem; }
    .cr-lb-podium { gap: 2px; }
    .cr-lb-podium-card { padding: 6px 2px 4px; border-radius: 8px; }
    .cr-lb-medal { font-size: 1.2rem; }
    .cr-lb-podium-name { font-size: 0.58rem; }
    .cr-lb-podium-stats .stat-value { font-size: 0.65rem; }
}

/* ═══════════════════════════════════════════════════════════════════
   LEADERBOARD — Chesslang-style Podium
   ═══════════════════════════════════════════════════════════════════ */

.cr-lb-wrap {
    padding: 8px;
    overflow-y: auto;
    height: 100%;
}

/* ─── Top 3 Podium ─── */
.cr-lb-podium {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    padding: 4px 0;
}

.cr-lb-podium-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 4px 8px;
    border-radius: 12px;
    position: relative;
    min-width: 0;
    transition: transform 0.2s;
}
.cr-lb-podium-card:hover { transform: translateY(-2px); }

.cr-lb-podium-card.gold {
    background: linear-gradient(135deg, rgba(255,215,0,0.15), rgba(255,193,7,0.08));
    border: 1.5px solid rgba(255,215,0,0.3);
}
.cr-lb-podium-card.silver {
    background: linear-gradient(135deg, rgba(192,192,192,0.12), rgba(156,163,175,0.06));
    border: 1.5px solid rgba(192,192,192,0.25);
}
.cr-lb-podium-card.bronze {
    background: linear-gradient(135deg, rgba(205,127,50,0.12), rgba(180,83,9,0.06));
    border: 1.5px solid rgba(205,127,50,0.2);
}

.cr-lb-medal {
    font-size: 1.6rem;
    line-height: 1;
    margin-bottom: 4px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.cr-lb-podium-name {
    font-weight: 700;
    font-size: 0.68rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    padding: 0 2px;
}

.cr-lb-podium-stats {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.58rem;
    opacity: 0.7;
}
.cr-lb-podium-stats span {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}
.cr-lb-podium-stats .stat-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-size: 0.5rem;
    opacity: 0.6;
}
.cr-lb-podium-stats .stat-value {
    font-weight: 800;
    font-size: 0.75rem;
}

/* ─── Table Header ─── */
.cr-lb-header {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.cr-lb-header .col-pos { width: 32px; }
.cr-lb-header .col-name { flex: 1; }
.cr-lb-header .col-pts { width: 50px; text-align: right; }
.cr-lb-header .col-att { width: 55px; text-align: right; }

/* ─── Table Row ─── */
.cr-lb-row {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    transition: background 0.15s;
    font-size: 0.8rem;
    color: #1e293b;
}
.cr-lb-row:hover {
    background: rgba(0,0,0,0.03);
}
.cr-lb-row .col-pos {
    width: 32px;
    font-weight: 800;
    font-size: 0.75rem;
    color: #94a3b8;
}
.cr-lb-row .col-name {
    flex: 1;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cr-lb-row .col-pts {
    width: 50px;
    text-align: right;
    font-weight: 800;
    color: #a78bfa;
}
.cr-lb-row .col-att {
    width: 55px;
    text-align: right;
    font-weight: 700;
    color: #94a3b8;
}

/* Green highlight for active/recent students */
.cr-lb-row .col-name.highlight {
    background: rgba(46,204,113,0.15);
    padding: 2px 8px;
    border-radius: 10px;
    color: #2ecc71;
    font-weight: 700;
}

/* ═══ Light Theme (for history modal) ═══ */
.cr-lb-light .cr-lb-header {
    border-bottom-color: rgba(0,0,0,0.08);
    color: #374151;
    opacity: 0.5;
}
.cr-lb-light .cr-lb-row {
    border-bottom-color: rgba(0,0,0,0.05);
    color: #1f2937;
}
.cr-lb-light .cr-lb-row:hover {
    background: rgba(0,0,0,0.02);
}
.cr-lb-light .cr-lb-row .col-pos {
    color: #6b7280;
}
.cr-lb-light .cr-lb-row .col-pts {
    color: #4f46e5;
}
.cr-lb-light .cr-lb-podium-card.gold {
    background: linear-gradient(135deg, rgba(255,215,0,0.12), rgba(255,193,7,0.05));
    border-color: rgba(255,215,0,0.25);
}
.cr-lb-light .cr-lb-podium-card.silver {
    background: linear-gradient(135deg, rgba(192,192,192,0.1), rgba(156,163,175,0.04));
    border-color: rgba(192,192,192,0.2);
}
.cr-lb-light .cr-lb-podium-card.bronze {
    background: linear-gradient(135deg, rgba(205,127,50,0.1), rgba(180,83,9,0.04));
    border-color: rgba(205,127,50,0.15);
}
.cr-lb-light .cr-lb-podium-name { color: #1f2937; }
.cr-lb-light .cr-lb-podium-stats { color: #374151; }
.cr-lb-light .cr-lb-row .col-name.highlight {
    background: rgba(46,204,113,0.12);
    color: #16a34a;
}

/* ─── Reconnect Banner ─── */
@keyframes slideDown {
    from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes spinReconnect {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.cr-reconnect-spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spinReconnect 0.8s linear infinite;
}

/* =======================================================================
   ANALYSIS PANEL � Lichess-style sidebar between board and chat
   Visible to admin always; visible to students only when shared.
   ======================================================================= */

.cr-analysis-panel {
    width: 390px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-left: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
    overflow-x: hidden;
}
.cr-analysis-panel::-webkit-scrollbar { width: 3px; }
.cr-analysis-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }
.cr-analysis-panel.cr-ap-student { width: 330px; }

.cr-ap-section { padding: 10px; border-bottom: 1px solid #e2e8f0; }
.cr-ap-notation { flex: 1; display: flex; flex-direction: column; }
.cr-ap-notation .cr-move-list {
    max-width: 100%; flex: 1; max-height: 360px;
    border: none; border-top: 1px solid #e2e8f0;
    border-radius: 0; margin-top: 0; background: transparent;
}
.cr-ap-notation .cr-nav-buttons {
    max-width: 100%;
    border-top: 1px solid #e2e8f0;
    padding: 6px 4px; margin-top: 0;
}

.cr-ap-header {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 8px; flex-wrap: wrap;
}
.cr-ap-title { font-size: 0.75rem; font-weight: 800; color: #334155; white-space: nowrap; }

.cr-engine-badge {
    font-size: 0.62rem; font-weight: 700; color: #94a3b8;
    background: #f1f5f9; border: 1px solid #e2e8f0;
    border-radius: 4px; padding: 1px 5px; white-space: nowrap; flex-shrink: 0;
}

.cr-ap-share-btn {
    margin-left: auto; padding: 3px 8px; height: 24px;
    border-radius: 6px; border: 1px solid #e2e8f0;
    background: #f8fafc; color: #64748b;
    font-size: 0.65rem; font-weight: 700; cursor: pointer;
    font-family: inherit; transition: all 0.15s; white-space: nowrap;
}
.cr-ap-share-btn:hover { background: #f0edff; border-color: rgba(108,92,231,0.3); color: #6C5CE7; }
.cr-ap-share-btn.active {
    background: linear-gradient(135deg,rgba(108,92,231,0.12),rgba(167,139,250,0.08));
    border-color: rgba(108,92,231,0.4); color: #6C5CE7;
    box-shadow: 0 0 0 2px rgba(108,92,231,0.1);
}

.cr-ap-run-btn {
    padding: 3px 8px; height: 24px;
    border-radius: 6px; border: 1px solid rgba(245,158,11,0.3);
    background: rgba(245,158,11,0.08); color: #b45309;
    font-size: 0.65rem; font-weight: 800; cursor: pointer;
    font-family: inherit; transition: all 0.15s; white-space: nowrap;
}
.cr-ap-run-btn:hover { background: rgba(245,158,11,0.18); border-color: rgba(245,158,11,0.5); }
.cr-ap-run-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.cr-eval-bar-wrap { padding: 0 0 8px; }
.cr-eval-bar {
    position: relative; height: 18px; border-radius: 4px;
    background: #1a1a2e; overflow: hidden; border: 1px solid #e2e8f0; transition: all 0.3s;
}
.cr-eval-bar-white {
    position: absolute; left: 0; top: 0; bottom: 0;
    background: #f8f9fa; border-right: 1px solid #cbd5e1;
    transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
    min-width: 5%; max-width: 95%;
}
.cr-eval-label {
    position: absolute; left: 50%; top: 50%;
    transform: translate(-50%,-50%);
    font-size: 0.68rem; font-weight: 800; color: #f8fafc;
    pointer-events: none; white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.cr-engine-lines { display: flex; flex-direction: column; gap: 3px; }
.cr-engine-placeholder {
    font-size: 0.72rem; color: #94a3b8;
    text-align: center; padding: 12px 4px; font-style: italic;
}
.cr-engine-line {
    display: flex; align-items: flex-start; gap: 6px;
    padding: 5px 6px; border-radius: 6px;
    background: #f8fafc; border: 1px solid #e2e8f0;
    transition: background 0.1s; cursor: default;
}
.cr-engine-line:hover { background: #f0edff; border-color: rgba(108,92,231,0.2); }

.cr-pv-eval {
    font-size: 0.72rem; font-weight: 800;
    min-width: 38px; text-align: center;
    padding: 2px 4px; border-radius: 4px;
    flex-shrink: 0; background: #e2e8f0; color: #475569;
}
.cr-pv-eval.positive { background: rgba(22,163,74,0.12); color: #15803d; }
.cr-pv-eval.negative { background: rgba(220,38,38,0.1); color: #b91c1c; }

.cr-pv-moves { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; min-width: 0; }
.cr-pv-num { font-size: 0.62rem; color: #94a3b8; font-family: monospace; }
.cr-pv-san { font-size: 0.72rem; font-weight: 600; color: #334155; font-family: monospace; }
.cr-pv-san.first-move {
    font-size: 0.78rem; font-weight: 800; color: #1e293b;
    background: rgba(108,92,231,0.08); border-radius: 3px; padding: 0 3px;
}

@media (max-width: 1023px) { .cr-analysis-panel { display: none !important; } }



/* Leaderboard dark mode overrides for mobile */
@media (max-width: 768px) {
    .cr-lb-podium-name, .cr-lb-podium-stats, .cr-lb-podium-stats .stat-label { color: #f8fafc; }
    .cr-lb-header { color: #cbd5e1; border-bottom: 1px solid rgba(255,255,255,0.1); }
    .cr-lb-row { color: #e2e8f0; border-bottom: 1px solid rgba(255,255,255,0.1); }
    .cr-lb-row .col-name.highlight { color: #4ade80; background: rgba(74,222,128,0.15); }
}

/* ═══════════════════════════════════════════════════════════════════
   SESSION SUMMARY MODAL
   ═══════════════════════════════════════════════════════════════════ */
.cr-summary-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.72);
    backdrop-filter: blur(10px);
    z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    animation: fadeIn 0.35s ease;
}

.cr-summary-card {
    background: #ffffff;
    border-radius: 24px;
    padding: 32px 28px 24px;
    max-width: 560px; width: 100%;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 24px 80px rgba(0,0,0,0.35), 0 4px 16px rgba(108,92,231,0.15);
    animation: summaryPop 0.4s cubic-bezier(0.34,1.56,0.64,1);
    position: relative;
}

@keyframes summaryPop {
    from { opacity: 0; transform: scale(0.88) translateY(20px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.cr-summary-header {
    text-align: center;
    margin-bottom: 24px;
}

.cr-summary-trophy {
    font-size: 3.5rem;
    line-height: 1;
    margin-bottom: 8px;
    display: block;
    animation: trophyBounce 0.6s 0.2s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes trophyBounce {
    from { opacity: 0; transform: scale(0.5) rotate(-10deg); }
    to   { opacity: 1; transform: scale(1) rotate(0deg); }
}

.cr-summary-title {
    font-size: 1.5rem; font-weight: 900;
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}
.cr-summary-subtitle {
    font-size: 0.82rem; color: #94a3b8; font-weight: 500;
}

/* Stats grid */
.cr-summary-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 24px;
}
.cr-summary-stat {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px 10px;
    text-align: center;
    transition: transform 0.2s;
}
.cr-summary-stat:hover { transform: translateY(-2px); }
.cr-summary-stat-icon { font-size: 1.4rem; margin-bottom: 4px; }
.cr-summary-stat-value {
    font-size: 1.4rem; font-weight: 900;
    color: #1e293b;
    line-height: 1;
}
.cr-summary-stat-label {
    font-size: 0.62rem; font-weight: 700;
    color: #94a3b8; text-transform: uppercase;
    letter-spacing: 0.5px; margin-top: 4px;
}

/* Accuracy ring */
.cr-summary-accuracy {
    display: flex; align-items: center; justify-content: center;
    gap: 16px; margin-bottom: 20px;
    padding: 16px; border-radius: 16px;
    background: linear-gradient(135deg, rgba(108,92,231,0.06), rgba(167,139,250,0.04));
    border: 1px solid rgba(108,92,231,0.15);
}
.cr-summary-ring {
    position: relative; width: 70px; height: 70px; flex-shrink: 0;
}
.cr-summary-ring svg { transform: rotate(-90deg); }
.cr-summary-ring-bg { fill: none; stroke: #e2e8f0; stroke-width: 6; }
.cr-summary-ring-fill {
    fill: none; stroke: #6C5CE7; stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4,0,0.2,1);
}
.cr-summary-ring-text {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 900; color: #6C5CE7;
}
.cr-summary-acc-info { flex: 1; }
.cr-summary-acc-label {
    font-size: 0.72rem; font-weight: 700; color: #94a3b8;
    text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px;
}
.cr-summary-acc-desc {
    font-size: 0.88rem; font-weight: 700; color: #1e293b;
}

/* Leaderboard section */
.cr-summary-lb-title {
    font-size: 0.8rem; font-weight: 800; color: #475569;
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 6px;
}

.cr-summary-lb-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 20px; }

.cr-summary-lb-row {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 12px;
    background: #f8fafc; border: 1px solid #e2e8f0;
    transition: all 0.15s;
}
.cr-summary-lb-row.top1 {
    background: linear-gradient(135deg, rgba(255,215,0,0.12), rgba(255,165,0,0.06));
    border-color: rgba(255,200,0,0.35);
}
.cr-summary-lb-row.top2 {
    background: linear-gradient(135deg, rgba(180,180,180,0.12), rgba(148,163,184,0.06));
    border-color: rgba(180,180,180,0.3);
}
.cr-summary-lb-row.top3 {
    background: linear-gradient(135deg, rgba(180,83,9,0.1), rgba(217,119,6,0.06));
    border-color: rgba(180,83,9,0.2);
}
.cr-summary-lb-rank {
    width: 26px; height: 26px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 900;
    background: #e2e8f0; color: #64748b; flex-shrink: 0;
}
.cr-summary-lb-name { flex: 1; font-weight: 600; font-size: 0.85rem; color: #1e293b; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-summary-lb-score { font-size: 0.9rem; font-weight: 800; color: #6C5CE7; }
.cr-summary-lb-acc { font-size: 0.72rem; color: #94a3b8; margin-left: 6px; }

/* Close button */
.cr-summary-close-btn {
    width: 100%; padding: 14px;
    border-radius: 14px; border: none;
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    color: #fff; font-size: 1rem; font-weight: 800;
    cursor: pointer; font-family: inherit;
    box-shadow: 0 4px 20px rgba(108,92,231,0.35);
    transition: all 0.2s;
    letter-spacing: 0.3px;
}
.cr-summary-close-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(108,92,231,0.5);
}
.cr-summary-close-btn:active { transform: translateY(0); }

/* ═══════════════════════════════════════════════════════════════════
   RICH TEXT PANEL — Note editor beside chessboard
   ═══════════════════════════════════════════════════════════════════ */

/* Board + Notes split container (replaces plain cr-board-area) */
.cr-board-notes-split {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-width: 0;
    overflow: hidden;
    position: relative;
}

/* The board column inside the split */
.cr-board-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    overflow-y: auto;
    background: #f1f5f9;
    flex-shrink: 0;
    min-width: 240px;
    /* Ensure board wrapper fills the column width properly */
    box-sizing: border-box;
}

/* When notes panel is open, constrain board wrapper to fit in the smaller column */
.cr-board-col .cr-board-wrapper {
    max-width: min(65vh, calc(100% - 24px));
}
@media (min-width: 1024px) {
    .cr-board-col .cr-board-wrapper {
        max-width: min(72vh, calc(100% - 24px));
    }
}

/* Drag handle between board and notes */
.cr-split-handle {
    width: 6px;
    background: transparent;
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    transition: background 0.15s;
    user-select: none;
}
.cr-split-handle::after {
    content: '';
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 3px; height: 40px; border-radius: 2px;
    background: #cbd5e1;
    transition: background 0.15s, height 0.15s;
}
.cr-split-handle:hover,
.cr-split-handle.dragging {
    background: rgba(108,92,231,0.06);
}
.cr-split-handle:hover::after,
.cr-split-handle.dragging::after {
    background: #6C5CE7;
    height: 60px;
}

/* Notes panel */
.cr-notes-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-left: 1px solid #e2e8f0;
    min-width: 180px;
    overflow: hidden;
    transition: min-width 0.15s;
}

/* Notes toolbar */
.cr-notes-toolbar {
    display: flex; align-items: center;
    gap: 2px; padding: 6px 10px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.cr-notes-toolbar-title {
    font-size: 0.72rem; font-weight: 800;
    color: #6C5CE7; margin-right: 6px;
    white-space: nowrap;
}
.cr-notes-divider {
    width: 1px; height: 20px;
    background: #e2e8f0; margin: 0 3px; flex-shrink: 0;
}
.cr-notes-btn {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: #475569;
    font-size: 0.8rem; font-weight: 700;
    cursor: pointer; font-family: inherit;
    transition: all 0.12s;
    flex-shrink: 0;
}
.cr-notes-btn:hover {
    background: #f0edff;
    border-color: rgba(108,92,231,0.3);
    color: #6C5CE7;
}
.cr-notes-btn.active {
    background: rgba(108,92,231,0.12);
    border-color: rgba(108,92,231,0.35);
    color: #6C5CE7;
}
/* Alignment buttons with SVG icons */
.cr-align-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.cr-align-btn svg {
    display: block;
    flex-shrink: 0;
}
.cr-notes-select {
    height: 26px; padding: 0 4px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff; color: #475569;
    font-size: 0.72rem; font-family: inherit;
    cursor: pointer; outline: none;
}
.cr-notes-select:focus { border-color: rgba(108,92,231,0.4); }

/* Broadcast badge */
.cr-notes-broadcast-btn {
    margin-left: auto;
    padding: 3px 8px; height: 24px;
    border-radius: 6px; border: 1px solid rgba(46,204,113,0.3);
    background: rgba(46,204,113,0.08); color: #16a34a;
    font-size: 0.62rem; font-weight: 700; cursor: pointer;
    font-family: inherit; white-space: nowrap;
    transition: all 0.15s; flex-shrink: 0;
}
.cr-notes-broadcast-btn.active {
    background: rgba(46,204,113,0.2);
    border-color: rgba(46,204,113,0.5);
    box-shadow: 0 0 0 2px rgba(46,204,113,0.12);
}
.cr-notes-broadcast-btn:hover { background: rgba(46,204,113,0.15); }

/* The editable content area */
.cr-notes-editor {
    flex: 1;
    padding: 14px 16px;
    overflow-y: auto;
    outline: none;
    font-size: 0.9rem;
    line-height: 1.7;
    color: #1e293b;
    font-family: 'Baloo 2', 'Georgia', sans-serif;
    caret-color: #6C5CE7;
}
.cr-notes-editor:empty::before {
    content: attr(data-placeholder);
    color: #94a3b8;
    pointer-events: none;
}
.cr-notes-editor h1 { font-size: 1.4rem; font-weight: 900; color: #1e293b; margin: 6px 0 4px; }
.cr-notes-editor h2 { font-size: 1.15rem; font-weight: 800; color: #1e293b; margin: 6px 0 4px; }
.cr-notes-editor h3 { font-size: 0.95rem; font-weight: 700; color: #1e293b; margin: 4px 0 3px; }
.cr-notes-editor ul { padding-left: 20px; margin: 4px 0; }
.cr-notes-editor ol { padding-left: 20px; margin: 4px 0; }
.cr-notes-editor li { margin-bottom: 2px; }
.cr-notes-editor blockquote {
    border-left: 3px solid #6C5CE7;
    padding-left: 10px; margin: 6px 0;
    color: #64748b; font-style: italic;
}
.cr-notes-editor a { color: #6C5CE7; text-decoration: underline; }
.cr-notes-editor hr { border: none; border-top: 1px solid #e2e8f0; margin: 8px 0; }
.cr-notes-editor::-webkit-scrollbar { width: 4px; }
.cr-notes-editor::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Student view: notes are read-only */
.cr-notes-editor[readonly], .cr-notes-editor.cr-notes-readonly {
    background: #f8fafc;
    cursor: default;
}

/* Notes footer (word count) */
.cr-notes-footer {
    padding: 4px 12px;
    font-size: 0.62rem; color: #94a3b8;
    border-top: 1px solid #e2e8f0;
    display: flex; justify-content: space-between; align-items: center;
    background: #f8fafc; flex-shrink: 0;
}

/* Hide notes panel when split handle is all the way left */
.cr-notes-panel.cr-notes-hidden {
    display: none;
}

/* Toggle notes button (in toolbar) */
.cr-btn.cr-notes-toggle-active {
    background: linear-gradient(135deg, rgba(108,92,231,0.12), rgba(167,139,250,0.08));
    border-color: rgba(108,92,231,0.35);
    color: #6C5CE7;
}

@media (max-width: 1023px) {
    /* Tablet/small desktop: hide drag handle, keep notes as overlay */
    .cr-split-handle { display: none !important; }
    /* Board col always fills split container */
    .cr-board-col { flex: 1; min-width: 0; }
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE NOTES PANEL — Full-screen overlay on phone
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* On mobile: notes panel is a fixed full-screen overlay */
    .cr-notes-panel:not(.cr-notes-hidden) {
        position: fixed !important;
        inset: 0 !important;
        z-index: 100 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-left: none !important;
        border-radius: 0 !important;
        flex: unset !important;
        min-width: unset !important;
    }
    /* Hide board-col when mobile notes are showing (admin switched to notes view) */
    .cr-board-col.cr-mobile-notes-active {
        display: none !important;
    }
    /* Notes toolbar smaller on mobile */
    .cr-notes-toolbar {
        padding: 6px 8px;
        gap: 1px;
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    .cr-notes-toolbar-title { display: none; } /* save space */
    .cr-notes-btn {
        width: 32px; height: 32px;
        font-size: 0.85rem; flex-shrink: 0;
    }
    .cr-notes-select { font-size: 0.7rem; max-width: 90px; }
    .cr-notes-editor { font-size: 0.88rem; padding: 12px; }
    /* Back-to-board button visible on mobile inside notes toolbar */
    .cr-notes-back-btn {
        display: flex !important;
    }
    /* Split container behaves as simple column on mobile */
    .cr-board-notes-split {
        flex-direction: column;
    }
}

/* Back to board button (hidden on desktop, shown on mobile inside notes toolbar) */
.cr-notes-back-btn {
    display: none;
    align-items: center; justify-content: center;
    padding: 0 10px; height: 32px;
    border-radius: 8px; border: 1px solid rgba(108,92,231,0.3);
    background: rgba(108,92,231,0.08); color: #6C5CE7;
    font-size: 0.72rem; font-weight: 700; cursor: pointer;
    font-family: inherit; white-space: nowrap; flex-shrink: 0;
    transition: all 0.15s;
    margin-right: 4px;
}
.cr-notes-back-btn:hover { background: rgba(108,92,231,0.18); }

/* Mobile view-mode toggle in status bar */
.cr-mobile-view-toggle {
    display: none;
    align-items: center; gap: 0;
    background: rgba(108,92,231,0.08);
    border: 1px solid rgba(108,92,231,0.3);
    border-radius: 8px; overflow: hidden;
    margin-left: auto; flex-shrink: 0;
}
.cr-mobile-view-toggle button {
    padding: 3px 10px; height: 28px;
    border: none; background: transparent;
    color: #64748b;
    font-size: 0.7rem; font-weight: 700; cursor: pointer;
    font-family: inherit; transition: all 0.15s;
}
.cr-mobile-view-toggle button.active {
    background: linear-gradient(135deg, #6C5CE7, #a78bfa);
    color: #fff;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.15);
}
.cr-mobile-view-toggle button:not(.active):hover {
    color: #6C5CE7;
    background: rgba(108,92,231,0.08);
}
@media (max-width: 768px) {
    .cr-mobile-view-toggle { display: flex; }
}

/* ═══════════════════════════════════════════════════════════════════
   SESSION SUMMARY — Mobile compact
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .cr-summary-card {
        padding: 20px 16px 16px;
        border-radius: 16px;
        max-height: 95vh;
    }
    .cr-summary-trophy { font-size: 2.5rem; }
    .cr-summary-title { font-size: 1.15rem; }
    .cr-summary-subtitle { font-size: 0.75rem; }
    /* 2-column grid on small phones */
    .cr-summary-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        margin-bottom: 16px;
    }
    .cr-summary-stat { padding: 10px 6px; border-radius: 10px; }
    .cr-summary-stat-icon { font-size: 1.1rem; }
    .cr-summary-stat-value { font-size: 1.1rem; }
    .cr-summary-stat-label { font-size: 0.55rem; }
    /* Accuracy row stacks */
    .cr-summary-accuracy { flex-direction: column; gap: 8px; padding: 12px; }
    .cr-summary-ring { width: 55px; height: 55px; }
    .cr-summary-ring svg { width: 55px; height: 55px; }
    /* Leaderboard */
    .cr-summary-lb-row { padding: 7px 8px; }
    .cr-summary-lb-name { font-size: 0.78rem; }
    .cr-summary-lb-score { font-size: 0.82rem; }
    .cr-summary-close-btn { padding: 12px; font-size: 0.9rem; }
    /* Ring SVG viewBox = 70x70, r=30 → at 55px scale */
    .cr-summary-ring-text { font-size: 0.75rem; }
}
