/* Xiangqi Board Wrapper */
.xiangqi-board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.xiangqi-board-container {
    position: relative;
    display: inline-block;
    padding: 15px;
    background: linear-gradient(135deg, #deb887 0%, #d2a060 100%);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

[data-bs-theme="dark"] .xiangqi-board-container {
    background: linear-gradient(135deg, #8b7355 0%, #6d5840 100%);
}

/* Xiangqi Board */
.xiangqi-board {
    position: relative;
    width: min(90vw, 450px);
    aspect-ratio: 9 / 10;
    background:
        /* Vertical lines */
        repeating-linear-gradient(90deg, transparent, transparent calc(100% / 9 - 1px), #333 calc(100% / 9 - 1px), #333 calc(100% / 9)),
        /* Horizontal lines */
        repeating-linear-gradient(0deg, transparent, transparent calc(100% / 10 - 1px), #333 calc(100% / 10 - 1px), #333 calc(100% / 10)),
        /* Board color */
        #deb887;
    background-size: 100% 100%;
    border: 3px solid #5d4e37;
    border-radius: 4px;
    user-select: none;
}

[data-bs-theme="dark"] .xiangqi-board {
    background:
        repeating-linear-gradient(90deg, transparent, transparent calc(100% / 9 - 1px), #222 calc(100% / 9 - 1px), #222 calc(100% / 9)),
        repeating-linear-gradient(0deg, transparent, transparent calc(100% / 10 - 1px), #222 calc(100% / 10 - 1px), #222 calc(100% / 10)),
        #8b7355;
    border-color: #3d3428;
}

/* River */
.xiangqi-board::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: calc(50% - 5%);
    height: 10%;
    background: linear-gradient(180deg,
        transparent 0%,
        rgba(100, 150, 200, 0.15) 20%,
        rgba(100, 150, 200, 0.2) 50%,
        rgba(100, 150, 200, 0.15) 80%,
        transparent 100%
    );
    pointer-events: none;
}

/* River text */
.river-text {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: calc(min(90vw, 450px) / 18);
    font-weight: bold;
    color: #5d4e37;
    pointer-events: none;
    letter-spacing: 0.5em;
}

[data-bs-theme="dark"] .river-text {
    color: #a89070;
}

.river-text.left {
    left: 10%;
}

.river-text.right {
    right: 10%;
}

/* Palace diagonals drawn via JS */
.palace-line {
    position: absolute;
    background: #333;
    height: 2px;
    transform-origin: left center;
    pointer-events: none;
}

[data-bs-theme="dark"] .palace-line {
    background: #222;
}

/* Board Point (intersection) */
.board-point {
    position: absolute;
    width: calc(100% / 9);
    height: calc(100% / 10);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1;
}

.board-point.selected .xiangqi-piece {
    box-shadow: 0 0 0 4px #4CAF50, 0 4px 12px rgba(0, 0, 0, 0.3);
}

.board-point.legal-move::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background-color: rgba(76, 175, 80, 0.5);
    border-radius: 50%;
    z-index: 0;
}

.board-point.legal-capture::after {
    content: '';
    position: absolute;
    width: 80%;
    height: 80%;
    border: 4px solid rgba(244, 67, 54, 0.6);
    border-radius: 50%;
    background: transparent;
    z-index: 0;
}

/* Highlight capturable enemy piece with red border */
.board-point.legal-capture .xiangqi-piece {
    box-shadow: 0 0 0 4px rgba(244, 67, 54, 0.8), 0 4px 12px rgba(244, 67, 54, 0.4) !important;
    animation: pulse-capture 1s ease-in-out infinite;
}

@keyframes pulse-capture {
    0%, 100% { box-shadow: 0 0 0 4px rgba(244, 67, 54, 0.8), 0 4px 12px rgba(244, 67, 54, 0.4); }
    50% { box-shadow: 0 0 0 5px rgba(244, 67, 54, 0.6), 0 4px 16px rgba(244, 67, 54, 0.3); }
}

.board-point.last-move::before {
    content: '';
    position: absolute;
    width: 50%;
    height: 50%;
    background: rgba(255, 235, 59, 0.4);
    border-radius: 50%;
    z-index: 0;
}

/* Last move connecting line */
.last-move-line {
    position: absolute;
    height: 3px;
    background: linear-gradient(90deg, rgba(255, 193, 7, 0.6), rgba(255, 152, 0, 0.6));
    border-radius: 2px;
    transform-origin: left center;
    pointer-events: none;
    z-index: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

[data-bs-theme="dark"] .last-move-line {
    background: linear-gradient(90deg, rgba(255, 193, 7, 0.5), rgba(255, 152, 0, 0.5));
}

.board-point.hint::after {
    content: '';
    position: absolute;
    width: 90%;
    height: 90%;
    border: 4px solid #4CAF50;
    border-radius: 50%;
    z-index: 0;
    animation: pulse-hint 1s ease-in-out infinite;
}

@keyframes pulse-hint {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.95); }
}

/* Xiangqi Piece */
.xiangqi-piece {
    width: 85%;
    height: 85%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(min(90vw, 450px) / 15);
    font-weight: bold;
    cursor: grab;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    z-index: 2;
    user-select: none;
}

.xiangqi-piece:active {
    cursor: grabbing;
}

.xiangqi-piece.red-piece {
    background: linear-gradient(145deg, #fff5f5 0%, #ffcccc 50%, #ffaaaa 100%);
    border: 3px solid #cc0000;
    color: #cc0000;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25), inset 0 2px 4px rgba(255, 255, 255, 0.5);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.xiangqi-piece.black-piece {
    background: linear-gradient(145deg, #4a4a4a 0%, #2a2a2a 50%, #1a1a1a 100%);
    border: 3px solid #000;
    color: #fff;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.1);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.xiangqi-piece.dragging {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    transform: scale(1.15);
    opacity: 0.9;
}

.board-point.drag-over::after {
    content: '';
    position: absolute;
    width: 90%;
    height: 90%;
    background: rgba(255, 193, 7, 0.3);
    border-radius: 50%;
    z-index: 0;
}

/* Player Info */
.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--bs-tertiary-bg);
    border-radius: 8px;
    width: min(90vw, 450px);
    box-sizing: border-box;
}

.player-avatar {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 20px;
    font-weight: bold;
    flex-shrink: 0;
}

.player-avatar.red-side {
    background: linear-gradient(135deg, #ffcccc 0%, #ff9999 100%);
    color: #cc0000;
    border: 2px solid #cc0000;
}

.player-avatar.black-side {
    background: linear-gradient(135deg, #4a4a4a 0%, #2a2a2a 100%);
    color: #fff;
    border: 2px solid #000;
}

.player-info.active-turn {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: #fff;
}

/* Thinking Badge */
.thinking-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    background: var(--bs-warning);
    color: #000;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    animation: pulse 1.5s ease-in-out infinite;
}

.player-info.active-turn .thinking-badge {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

/* Captured pieces inline */
.captured-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    font-size: 1rem;
    margin-left: auto;
    min-height: 24px;
}

.captured-inline span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
}

.captured-inline .red-captured {
    background: #ffcccc;
    color: #cc0000;
    border: 1px solid #cc0000;
}

.captured-inline .black-captured {
    background: #333;
    color: #fff;
    border: 1px solid #000;
}

/* Game Info Bar */
.game-info-bar {
    background: var(--bs-tertiary-bg);
    border-radius: 8px;
    padding: 12px 20px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.material-info {
    flex-direction: column;
    gap: 4px;
}

/* Status Dot */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.red-turn {
    background: linear-gradient(135deg, #ff6666 0%, #cc0000 100%);
    border: 2px solid #990000;
}

.status-dot.black-turn {
    background: linear-gradient(135deg, #4a4a4a 0%, #1a1a1a 100%);
    border: 2px solid #000;
}

.status-dot.game-over {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
    border: 2px solid #d32f2f;
}

/* Material Advantage Bar */
.material-bar {
    height: 8px;
    width: 120px;
    background: linear-gradient(to right, #1a1a1a 50%, #ff6666 50%);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
}

.material-indicator {
    height: 100%;
    background: #4CAF50;
    transition: width 0.3s ease;
}

/* Move History */
.move-history-details {
    background: var(--bs-tertiary-bg);
    border-radius: 8px;
    overflow: hidden;
}

.move-history-summary {
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 600;
    user-select: none;
}

.move-history-summary:hover {
    background: var(--bs-secondary-bg);
}

.move-history-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
}

.move-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.move-number {
    font-weight: 600;
    color: var(--bs-secondary);
    font-size: 0.875rem;
    min-width: 24px;
}

.move-entry {
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-family: monospace;
    font-size: 0.9rem;
}

.move-entry:hover {
    background: var(--bs-primary);
    color: #fff;
}

/* Game Over Modal */
.game-over-icon {
    font-size: 5rem;
    line-height: 1;
}

/* Animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Board flip animation */
.xiangqi-board.flipped {
    transform: rotate(180deg);
}

.xiangqi-board.flipped .xiangqi-piece {
    transform: rotate(180deg);
}

.xiangqi-board.flip-animation {
    transition: transform 0.4s ease;
}

/* Responsive */
@media (max-width: 576px) {
    .xiangqi-board-container {
        padding: 10px;
    }

    .xiangqi-piece {
        font-size: calc(90vw / 16);
    }

    .player-info {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    .player-avatar {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .captured-inline span {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }
}
