/* ═══════════════════════════════════════════════════════
   PGN Game Study — "Xem Ván Mẫu"
   ═══════════════════════════════════════════════════════ */

.pgn-page {
    min-height: 100vh;
    background: var(--bg-main, #0f0e17);
    color: #f0ebe3;
    font-family: 'Baloo 2', sans-serif;
    padding-bottom: 40px;
}

.pgn-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(255,160,50,0.12), rgba(255,100,20,0.06));
    border-bottom: 2px solid rgba(255,160,50,0.25);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.pgn-back-btn {
    background: rgba(255, 160, 50, 0.15);
    border: 1px solid rgba(255, 160, 50, 0.3);
    color: #f0ebe3;
    padding: 8px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.pgn-back-btn:hover { background: rgba(255, 160, 50, 0.25); transform: translateX(-2px); }

.pgn-header-title {
    flex: 1;
    font-size: 1.25rem;
    font-weight: 900;
    background: linear-gradient(135deg, #ffa030, #ff6914);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Collections grid */
.pgn-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px;
}

.pgn-section-title {
    font-size: 1rem;
    font-weight: 800;
    color: rgba(240,235,227,0.6);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 16px;
}

.pgn-collections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.pgn-collection-card {
    background: linear-gradient(135deg, rgba(255,160,50,0.1), rgba(255,100,20,0.05));
    border: 2px solid rgba(255,160,50,0.25);
    border-radius: 18px;
    padding: 22px 18px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}
.pgn-collection-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(255,160,50,0.6), transparent);
}
.pgn-collection-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255,160,50,0.5);
    box-shadow: 0 8px 24px rgba(255,130,30,0.2);
}
.pgn-collection-card.locked {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.6);
}
.pgn-collection-card.locked:hover { transform: none; box-shadow: none; }

.pgn-col-icon { font-size: 2.4rem; margin-bottom: 10px; }
.pgn-col-name { font-weight: 900; font-size: 1.05rem; margin-bottom: 4px; color: #ffa030; }
.pgn-col-desc { font-size: 0.78rem; opacity: 0.65; margin-bottom: 10px; line-height: 1.4; }
.pgn-col-meta { display: flex; gap: 10px; font-size: 0.75rem; opacity: 0.6; flex-wrap: wrap; }
.pgn-col-badge {
    padding: 2px 8px;
    border-radius: 8px;
    background: rgba(255,160,50,0.15);
    color: #ffa030;
    font-weight: 700;
}
.pgn-lock-badge {
    position: absolute;
    top: 10px; right: 10px;
    font-size: 1.2rem;
}

/* Game list */
.pgn-game-list { display: flex; flex-direction: column; gap: 10px; }

.pgn-game-card {
    background: rgba(255,255,255,0.08);
    border: 1.5px solid rgba(255,255,255,0.18);
    border-radius: 14px;
    padding: 16px 18px;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    align-items: center;
    gap: 14px;
    backdrop-filter: blur(6px);
}
.pgn-game-card:hover {
    border-color: rgba(255,160,50,0.55);
    background: rgba(255,160,50,0.1);
    transform: translateX(4px);
    box-shadow: 0 4px 20px rgba(255,130,30,0.15);
}
.pgn-game-num {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffa030, #ff6914);
    display: flex; align-items: center; justify-content: center;
    font-weight: 900;
    font-size: 0.85rem;
    flex-shrink: 0;
    color: #fff;
}
.pgn-game-info { flex: 1; }
.pgn-game-title { font-weight: 800; font-size: 0.95rem; margin-bottom: 3px; color: #f0ebe3; }
.pgn-game-meta { font-size: 0.75rem; display: flex; gap: 8px; flex-wrap: wrap; color: rgba(240,235,227,0.65); }
.pgn-game-accuracy {
    margin-left: auto;
    font-weight: 900;
    font-size: 1.1rem;
    min-width: 60px;
    text-align: right;
}

/* ═══ Player Screen — 3-column layout ═══ */
.pgn-player-wrap {
    display: grid;
    grid-template-columns: 220px 2fr minmax(220px, 320px);
    gap: 16px;
    align-items: start;
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 16px;
}

/* Left panel: timer + progress + slots */
.pgn-left-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Right panel: move history — scrollable, fixed height on desktop */
.pgn-right-panel {
    background: linear-gradient(135deg, rgba(20,20,40,0.9), rgba(30,25,50,0.9));
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 16px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,160,50,0.3) transparent;
}

/* Lock page scroll + full-size layout on desktop when in game */
@media (min-width: 801px) {
    .pgn-page.pgn-playing {
        overflow: hidden;
        height: 100vh;
    }

    /* Break out of the 900px pgn-content constraint */
    .pgn-page.pgn-playing #pgn-main-content {
        max-width: none !important;
        padding: 0 !important;
        width: 100%;
    }

    /* Switch to flexbox for predictable sizing */
    .pgn-page.pgn-playing .pgn-player-wrap {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 16px;
        max-width: none;
        width: 100%;
        padding: 10px 20px;
        box-sizing: border-box;
        height: auto;
        overflow: visible;
    }

    /* Left panel: exact 70vh height, no scroll, stretch to fill */
    .pgn-page.pgn-playing .pgn-left-panel {
        width: 220px;
        flex-shrink: 0;
        height: 70vh;
        max-height: 70vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    /* Compact info cards inside left panel */
    .pgn-page.pgn-playing .pgn-left-panel .pgn-info-card {
        padding: 10px 12px;
        border-radius: 12px;
    }

    /* Slots panel fills remaining space */
    .pgn-page.pgn-playing #pgn-move-panel {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    /* Compact timer ring */
    .pgn-page.pgn-playing .pgn-timer-ring {
        width: 84px;
        height: 84px;
        margin-bottom: 4px;
    }
    .pgn-page.pgn-playing .pgn-timer-ring svg {
        width: 84px;
        height: 84px;
    }
    .pgn-page.pgn-playing .pgn-timer-num {
        font-size: 1.5rem;
    }
    .pgn-page.pgn-playing .pgn-timer-label {
        font-size: 0.68rem;
    }
    .pgn-page.pgn-playing .pgn-timer-wrap {
        padding: 4px 0;
    }

    /* Compact progress section */
    .pgn-page.pgn-playing .pgn-info-card h4 {
        font-size: 0.68rem;
        margin-bottom: 6px;
    }
    .pgn-page.pgn-playing .pgn-progress-label {
        font-size: 0.68rem;
    }

    /* Compact move slots */
    .pgn-page.pgn-playing .pgn-move-slot {
        padding: 7px 10px;
        font-size: 0.82rem;
    }
    .pgn-page.pgn-playing .pgn-move-slots {
        gap: 6px;
    }
    .pgn-page.pgn-playing .pgn-move-hint {
        font-size: 0.65rem;
    }
    .pgn-page.pgn-playing .pgn-move-slot .slot-num {
        width: 20px;
        height: 20px;
        font-size: 0.65rem;
    }

    /* Center: board section — 70vh × 70vh square */
    .pgn-page.pgn-playing .pgn-board-section {
        flex-shrink: 0;
        width: 70vh;
    }
    .pgn-page.pgn-playing .pgn-board-wrap {
        width: 70vh;
        height: 70vh;
        max-width: none;
    }

    /* Right panel: fills remaining space, 70vh tall */
    .pgn-page.pgn-playing .pgn-right-panel {
        flex: 1;
        min-width: 200px;
        max-height: 70vh;
        overflow-y: auto;
    }
}

@media (max-width: 800px) {
    .pgn-player-wrap {
        grid-template-columns: 1fr;
    }
    .pgn-left-panel { order: 2; flex-direction: row; flex-wrap: wrap; gap: 10px; }
    .pgn-left-panel .pgn-info-card { flex: 1 1 140px; }
    .pgn-board-section { order: 1; }
    .pgn-right-panel { order: 3; max-height: 300px; }
}

.pgn-board-section { position: relative; }

.pgn-board-wrap {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    aspect-ratio: 1;
    width: 100%;
    margin: 0 auto;
}
#pgn-cg-wrap { width: 100%; height: 100%; }

.pgn-turn-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, backdrop-filter 0.3s;
}
.pgn-turn-overlay.active { opacity: 1; pointer-events: all; backdrop-filter: blur(3px); }
.pgn-turn-overlay-msg {
    background: linear-gradient(135deg, rgba(30,25,50,0.95), rgba(20,15,40,0.98));
    border: 2px solid rgba(255,160,50,0.8);
    box-shadow: 0 10px 40px rgba(0,0,0,0.6), 0 0 20px rgba(255,160,50,0.3);
    border-radius: 20px;
    padding: 24px 32px;
    text-align: center;
    max-width: 300px;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.pgn-turn-overlay.active .pgn-turn-overlay-msg {
    transform: scale(1);
}
.pgn-turn-overlay-msg h3 { font-size: 1.6rem; margin-bottom: 8px; color: #ffa030; }
.pgn-turn-overlay-msg p { font-size: 0.95rem; opacity: 0.85; color: #f0ebe3; }

/* Side panel */
.pgn-side-panel { display: flex; flex-direction: column; gap: 14px; }

.pgn-info-card {
    background: linear-gradient(135deg, rgba(20,20,40,0.9), rgba(30,25,50,0.9));
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 16px;
    color: #f0ebe3;
}
.pgn-info-card h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 1px; opacity: 0.5; margin-bottom: 10px; }

/* Timer ring */
.pgn-timer-wrap { text-align: center; padding: 10px 0; }
.pgn-timer-ring { position: relative; width: 110px; height: 110px; margin: 0 auto 8px; }
.pgn-timer-ring svg { transform: rotate(-90deg); }
.pgn-timer-ring circle.bg { fill: none; stroke: rgba(255,255,255,0.08); stroke-width: 8; }
.pgn-timer-ring circle.prog {
    fill: none;
    stroke: #ffa030;
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.pgn-timer-ring circle.prog.urgent { stroke: #e74c3c; }
.pgn-timer-num {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 900;
    color: #ffa030;
    font-variant-numeric: tabular-nums;
}
.pgn-timer-num.urgent { color: #e74c3c; }
.pgn-timer-label { font-size: 0.75rem; opacity: 0.55; }

/* Move slots */
.pgn-move-slots { display: flex; flex-direction: column; gap: 8px; }
.pgn-move-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1.5px solid rgba(255,255,255,0.08);
    transition: all 0.25s;
    font-size: 0.9rem;
}
.pgn-move-slot .slot-num {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: rgba(255,160,50,0.15);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem;
    font-weight: 900;
    color: #ffa030;
    flex-shrink: 0;
}
.pgn-move-slot.filled { border-color: rgba(255,160,50,0.4); background: rgba(255,160,50,0.08); }
.pgn-move-slot.correct { border-color: rgba(46,204,113,0.5); background: rgba(46,204,113,0.08); }
.pgn-move-slot.wrong { border-color: rgba(231,76,60,0.5); background: rgba(231,76,60,0.08); }
.pgn-move-slot.penalty { border-color: rgba(231,76,60,0.7); background: rgba(231,76,60,0.12); }
.pgn-move-slot .slot-move { font-weight: 700; font-family: monospace; }
.pgn-move-slot .slot-result { margin-left: auto; font-size: 0.9rem; }

.pgn-move-hint { font-size: 0.72rem; opacity: 0.5; text-align: center; margin-top: 4px; }

/* Status indicators */
.pgn-phase-badge {
    text-align: center;
    padding: 8px 14px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 0.82rem;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.pgn-phase-badge.intro { background: rgba(52,152,219,0.15); color: #3498db; border: 1px solid rgba(52,152,219,0.3); }
.pgn-phase-badge.playing { background: rgba(255,160,50,0.15); color: #ffa030; border: 1px solid rgba(255,160,50,0.3); }
.pgn-phase-badge.auto { background: rgba(155,89,182,0.15); color: #9b59b6; border: 1px solid rgba(155,89,182,0.3); }
.pgn-phase-badge.done { background: rgba(46,204,113,0.15); color: #2ecc71; border: 1px solid rgba(46,204,113,0.3); }

/* Progress bar */
.pgn-progress-section { margin-bottom: 4px; }
.pgn-progress-label { font-size: 0.72rem; opacity: 0.8; margin-bottom: 5px; color: #f0ebe3; }
.pgn-progress-bar { height: 6px; background: rgba(255,255,255,0.08); border-radius: 99px; overflow: hidden; }
.pgn-progress-fill { height: 100%; background: linear-gradient(90deg, #ffa030, #ff6914); border-radius: 99px; transition: width 0.5s; }

/* Move history — new numbered format */
.pgn-move-history {
    display: block;
    font-size: 0.88rem;
    line-height: 1.8;
}

.pgn-hist-row {
    display: flex;
    align-items: baseline;
    gap: 2px;
    padding: 1px 0;
    flex-wrap: nowrap;
}

.pgn-hist-num {
    color: rgba(240,235,227,0.35);
    font-size: 0.72rem;
    font-weight: 700;
    min-width: 26px;
    user-select: none;
    flex-shrink: 0;
}

.pgn-hist-move {
    padding: 2px 7px;
    border-radius: 6px;
    font-family: monospace;
    font-weight: 600;
    font-size: 0.9rem;
    color: rgba(240,235,227,0.8);
    cursor: default;
    flex-shrink: 0;
}

.pgn-hist-move.user {
    color: #ffa030;
    background: rgba(255,160,50,0.1);
}

.pgn-hist-move.current {
    background: rgba(255,160,50,0.28);
    color: #ffc060;
    outline: 1px solid rgba(255,160,50,0.6);
    font-weight: 800;
}

/* PGN comment block between moves */
.pgn-hist-comment {
    font-size: 0.76rem;
    color: rgba(240,235,227,0.45);
    font-style: italic;
    padding: 3px 8px 5px 30px;
    line-height: 1.5;
    border-left: 2px solid rgba(255,160,50,0.18);
    margin: 1px 0 3px 0;
}

/* Right panel section title */
.pgn-right-title {
    font-size: 0.7rem;
    letter-spacing: 1px;
    font-weight: 800;
    color: rgba(240,235,227,0.35);
    text-transform: uppercase;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

/* Result screen */
.pgn-result-card {
    background: linear-gradient(135deg, rgba(20,15,40,0.97), rgba(30,20,50,0.98));
    border: 2px solid rgba(255,160,50,0.35);
    border-radius: 24px;
    padding: 36px 28px;
    text-align: center;
    max-width: 520px;
    margin: 40px auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.pgn-result-icon { font-size: 4rem; margin-bottom: 12px; }
.pgn-result-title { font-size: 1.6rem; font-weight: 900; margin-bottom: 6px; color: #ffa030; }
.pgn-result-accuracy {
    font-size: 3.5rem;
    font-weight: 900;
    line-height: 1;
    margin: 16px 0;
    background: linear-gradient(135deg, #ffa030, #ff6914);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.pgn-result-sub { font-size: 0.85rem; opacity: 0.6; margin-bottom: 24px; }
.pgn-result-breakdown {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.pgn-result-stat {
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 10px 16px;
    min-width: 80px;
}
.pgn-result-stat .stat-val { font-size: 1.4rem; font-weight: 900; }
.pgn-result-stat .stat-lbl { font-size: 0.68rem; opacity: 0.5; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }
.pgn-result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Turn result feedback */
.pgn-turn-result {
    background: rgba(30,25,50,0.96);
    border-radius: 14px;
    padding: 14px 16px;
    margin-top: 10px;
}
.pgn-turn-result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 0.82rem;
}
.pgn-turn-result-row:last-child { border-bottom: none; }
.pgn-tr-move { font-family: monospace; font-weight: 700; }
.pgn-tr-label { opacity: 0.6; }
.pgn-tr-score { font-weight: 900; }
.pgn-tr-score.correct { color: #2ecc71; }
.pgn-tr-score.wrong { color: #e74c3c; }
.pgn-tr-score.penalty { color: #c0392b; }

/* Loading */
.pgn-loading {
    text-align: center;
    padding: 60px 20px;
    opacity: 0.6;
    font-size: 1rem;
}

/* Early penalty warning */
.pgn-penalty-warning {
    background: rgba(231,76,60,0.15);
    border: 1.5px solid rgba(231,76,60,0.4);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 0.78rem;
    color: #e74c3c;
    font-weight: 700;
    text-align: center;
    animation: shake 0.4s ease;
}
@keyframes shake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* Auto-play spinning indicator */
.pgn-auto-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    opacity: 0.7;
    justify-content: center;
    padding: 8px 0;
}
.pgn-spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: #9b59b6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ Admin Editor ═══ */
.pgn-admin-wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px; }
.pgn-admin-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    align-items: start;
}
@media (max-width: 850px) { .pgn-admin-grid { grid-template-columns: 1fr; } }

.pgn-admin-sidebar {
    background: rgba(20,20,40,0.8);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 16px;
    position: sticky;
    top: 80px;
}
.pgn-admin-board-area {
    background: rgba(20,20,40,0.8);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 16px;
}
.pgn-admin-board-wrap {
    width: 100%;
    aspect-ratio: 1;
    max-width: 420px;
    border-radius: 12px;
    overflow: hidden;
    margin: 0 auto 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
#pgn-admin-cg { width: 100%; height: 100%; }

.pgn-alt-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.pgn-alt-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    background: rgba(255,160,50,0.08);
    border: 1px solid rgba(255,160,50,0.25);
    border-radius: 8px;
    font-size: 0.82rem;
}
.pgn-alt-move { font-family: monospace; font-weight: 700; color: #ffa030; }
.pgn-alt-del {
    margin-left: auto;
    background: rgba(231,76,60,0.15);
    border: none;
    color: #e74c3c;
    border-radius: 6px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
}
.pgn-move-nav {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.pgn-move-nav button {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.06);
    color: inherit;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    transition: all 0.2s;
}
.pgn-move-nav button:hover { background: rgba(255,160,50,0.15); border-color: rgba(255,160,50,0.4); }
.pgn-move-nav button.active { background: rgba(255,160,50,0.2); border-color: #ffa030; color: #ffa030; }
.pgn-current-move-label {
    font-size: 0.78rem;
    opacity: 0.6;
    text-align: center;
    margin-bottom: 8px;
}
