/* ============================================
   Chinese Chess — 5000YAN theme integration
   ============================================ */

/* ===== Chess Container ===== */
.chess-container {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
    transition: background-color 0.25s ease;
    position: relative;
}

/* ===== Board Layout ===== */
.chess_right {
    display: none;
}

/* ===== Game Status Bar ===== */
.game-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    max-width: 507px;
    margin: 0 auto;
    transition: background-color 0.25s ease;
}

.game-mode-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 16px;
    border-radius: 50px;
    background: var(--success);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
}

.game-turn-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.game-move-count {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* ===== Game Buttons ===== */
.controls-row {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.controls-row + .controls-row {
    margin-top: 10px;
}

.control-btn, .controls-row .game-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50px;
    line-height: 1;
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.9375rem;
    padding: 12px 30px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 500;
    border: none;
    white-space: nowrap;
}

/* Difficulty buttons: accent tint (desktop & mobile) */
.controls-row .game-btn.game-diff-btn {
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent);
}

.controls-row .game-btn.game-diff-btn:hover {
    background: var(--accent);
    color: #fff;
}

/* Undo button: site green (desktop & mobile) */
.control-btn.regret-btn {
    background: rgba(var(--success-rgb), 0.15);
    color: var(--success);
}

.control-btn.regret-btn:hover {
    background: rgba(var(--success-rgb), 0.25);
    color: var(--success);
}

/* Plain control buttons hover (Style, Reference, Guide) */
.control-btn:not(.regret-btn):hover,
.controls-row .game-btn:not(.game-diff-btn):hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-1px);
}

.control-btn:active, .controls-row .game-btn:active {
    transform: scale(0.97);
}

.control-btn:disabled,
.control-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

/* ===== Canvas ===== */
#chess {
    display: block;
    margin: 0 auto;
    border-radius: var(--radius);
    transition: background-color 0.25s ease;
}

/* ===== Game Controls Section (buttons grouped under canvas) ===== */
.game-controls {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 16px 12px;
    margin-top: 12px;
}

/* ===== Thinking Overlay ===== */
.thinking-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: background 0.25s ease;
}

.thinking-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 1.25rem 1.5rem;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
}

.thinking-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(var(--accent-rgb), 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Move Info Panel ===== */
.move_info {
    max-width: 320px;
    margin: 12px auto;
    font-size: 0.8125rem;
    line-height: 1.6;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--text-muted);
}

.move_info h3 {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 6px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.move_info h3::before {
    content: "\f1b2";
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    color: var(--accent);
}

/* ===== Loading Indicator ===== */
.chess-container .spinner-border {
    color: var(--text-muted);
}

.jiazaizhong {
    color: var(--text-secondary);
    font-size: 0.9rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* ===== Light Mode Overrides ===== */
html.light .chess-container {
    background: var(--card-bg);
}

html.light .thinking-overlay {
    background: rgba(0, 0, 0, 0.3);
}

/* ===== Desktop: hide short labels, show full ===== */
.btn-short { display: none; }
.btn-full { display: inline; }

/* ===== Responsive ===== */
@media (max-width: 576px) {
    .chess-container {
        padding: 0.25rem;
    }

    .game-status-bar {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .game-move-count {
        font-size: 0.7rem;
    }

    .controls-row {
        gap: 8px;
    }

    .controls-row + .controls-row {
        margin-top: 8px;
    }

    .control-btn, .controls-row .game-btn {
        flex: 1;
        padding: 12px 6px;
        font-size: 0.78rem;
        min-width: 0;
    }

    /* Style label shorter on mobile */
    #styleLabel {
        font-size: 0.6rem;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 60px;
        white-space: nowrap;
    }

    .game-controls {
        padding: 14px 8px;
    }

    .thinking-content {
        padding: 1.25rem 1.75rem;
        margin: 0 20px;
    }

    .move_info {
        padding: 10px 12px;
        font-size: 0.75rem;
    }
}

/* ============================================
   Modal Overlay (Reference Table & Guide)
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    animation: fadeIn 0.15s ease;
    padding: 16px;
    box-sizing: border-box;
}

.modal-box {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}

.ref-table-modal {
    max-width: 640px;
    width: 100%;
}

.guide-modal {
    max-width: 560px;
    width: 100%;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border-color, rgba(128,128,128,0.2));
    flex-shrink: 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.15s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 16px 20px 20px;
    overflow-y: auto;
    flex: 1;
}

/* ===== Reference Table ===== */
.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.ref-table th {
    text-align: left;
    padding: 8px 10px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color, rgba(128,128,128,0.2));
    white-space: nowrap;
}

.ref-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-color, rgba(128,128,128,0.1));
    color: var(--text-primary);
    vertical-align: middle;
}

.ref-table tr:last-child td {
    border-bottom: none;
}

.ref-char {
    font-size: 1.2rem;
    font-weight: 700;
    white-space: nowrap;
    text-align: center;
}

.ref-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.ref-note {
    margin: 10px 0 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* ===== Guide Modal Content ===== */
#guideContent h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 16px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color, rgba(128,128,128,0.15));
}

#guideContent h4:first-child {
    margin-top: 0;
}

#guideContent p {
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0 0 10px;
}

.guide-piece {
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    font-size: 0.8125rem;
}

.guide-piece p {
    margin: 4px 0 0;
    font-size: 0.75rem;
}

.guide-piece-chars {
    font-size: 1.1rem;
    font-weight: 700;
}

.guide-tips {
    padding-left: 20px;
    margin: 8px 0 0;
}

.guide-tips li {
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

/* ===== Mobile adjustments ===== */
@media (max-width: 576px) {
    .modal-box {
        max-height: 90vh;
    }

    .ref-table-modal {
        max-width: 100%;
    }

    .guide-modal {
        max-width: 100%;
    }

    .modal-header h3 {
        font-size: 0.95rem;
    }

    .ref-table {
        font-size: 0.75rem;
    }

    .ref-table th,
    .ref-table td {
        padding: 6px 6px;
    }

    .ref-char {
        font-size: 1rem;
    }
}

/* ===== Pulse Animation for difficulty buttons ===== */
@keyframes pulse-ring {
    0% {
        box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.35);
    }
    70% {
        box-shadow: 0 0 0 12px rgba(var(--accent-rgb), 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0);
    }
}

.pulse-anim {
    animation: pulse-ring 1.5s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

@media (max-width: 576px) {
    .pulse-anim {
        animation: pulse-ring 1.5s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
    }
}
