:root {
    --board-columns: 8;
    --board-rows: 8;
    --board-width: min(92vw, 640px);
    --board-bg: #1f7a3f;
    --board-border: #0f4a27;
    --cell-border: rgba(255, 255, 255, 0.18);
    --cell-hover-bg: rgba(255, 255, 255, 0.06);
    --cell-selected-bg: rgba(255, 255, 255, 0.08);
    --cell-valid-bg: rgba(255, 255, 255, 0.12);
    --cell-last-move-bg: rgba(255, 255, 255, 0.14);
    --piece-size: 84%;
    --othello-black-piece-top: #66605a;
    --othello-black-piece-mid: #47423d;
    --othello-black-piece-bottom: #2f2b28;
    --othello-white-piece-top: #f7f3eb;
    --othello-white-piece-mid: #ece5da;
    --othello-white-piece-bottom: #d8cfc2;
}



.chessboard-stack {
    display: flex;
    flex-direction: column;
    align-self: center;
    width: var(--board-width);
    max-width: 100%;
}

.piece-count-strip {
    position: relative;
    width: 100%;
    min-height: 58px;
    border: 1px solid rgba(201, 169, 98, 0.18);
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 10px 24px rgba(26, 26, 26, 0.05);
    overflow: visible;
}

.piece-count-strip-track {
    position: absolute;
    inset: 0;
    display: flex;
    border-radius: inherit;
    overflow: hidden;
}

.piece-count-strip-fill {
    height: 100%;
    flex: 0 0 auto;
    transition: flex-basis 0.28s ease;
}

.piece-count-strip-fill--black {
    flex-basis: var(--piece-count-black-share, 50%);
    background:
        radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.12), transparent 34%),
        linear-gradient(150deg, #66605a 0%, #47423d 58%, #2f2b28 100%);
}

.piece-count-strip-fill--white {
    flex-basis: var(--piece-count-white-share, 50%);
    background:
        radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.92), transparent 38%),
        linear-gradient(150deg, #f7f3eb 0%, #ece5da 62%, #d8cfc2 100%);
    border-left: 1px solid rgba(102, 90, 76, 0.12);
}

.piece-count-strip-label {
    position: absolute;
    top: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.08rem;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.14);
}

.piece-count-strip-label--black {
    left: calc(var(--piece-count-black-share, 50%) / 2);
    color: #f1ece4;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.28);
}

.piece-count-strip-label--white {
    left: calc(var(--piece-count-black-share, 50%) + (var(--piece-count-white-share, 50%) / 2));
    color: #4f4942;
}

.piece-count-strip-tag {
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    line-height: 1;
}

.piece-count-strip-value {
    max-width: 100%;
    font-size: clamp(0.95rem, 1.05vw + 0.4rem, 1.28rem);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.chessboard {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.chessboard {
    background:
        radial-gradient(circle at center, rgba(255, 255, 255, 0.16), transparent 70%),
        linear-gradient(180deg, #2a8f49 0%, #1d733c 100%);
    border: 1px solid rgba(15, 74, 39, 0.95);
    box-shadow:
        0 22px 44px rgba(26, 26, 26, 0.14),
        inset 0 0 0 8px rgba(255, 255, 255, 0.08);
}

.cell {
    position: relative;
    border: 1px solid var(--cell-border);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    height: 100%;
    aspect-ratio: 1 / 1;
    transition: background-color 0.18s ease, transform 0.18s ease;
}

.cell:hover {
    background-color: var(--cell-hover-bg);
}

.cell.valid-move {
    background-color: var(--cell-valid-bg);
}

.cell.valid-move::after {
    content: '';
    position: absolute;
    inset: 36%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.42);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.14);
    pointer-events: none;
}

.cell.last-move {
    background-color: var(--cell-last-move-bg);
}

.cell.flip-highlight {
    background-color: rgba(255, 82, 82, 0.18);
    box-shadow: inset 0 0 0 2px rgba(255, 82, 82, 0.52);
}

.piece {
    width: var(--piece-size);
    height: var(--piece-size);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    position: relative;
    z-index: 1;
}

.cell.flip-highlight .piece {
    animation: othello-flip-highlight 1.6s ease-out both;
    will-change: transform, filter;
}

.piece.black {
    background:
        radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.22), transparent 34%),
        linear-gradient(150deg, var(--othello-black-piece-top) 0%, var(--othello-black-piece-mid) 58%, var(--othello-black-piece-bottom) 100%);
    box-shadow:
        0 7px 16px rgba(47, 43, 40, 0.28),
        inset 0 1px 1px rgba(255, 255, 255, 0.16),
        inset 0 -5px 8px rgba(22, 20, 18, 0.3);
}

.piece.white {
    background:
        radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.96), transparent 38%),
        linear-gradient(150deg, var(--othello-white-piece-top) 0%, var(--othello-white-piece-mid) 62%, var(--othello-white-piece-bottom) 100%);
    border: 1px solid rgba(102, 90, 76, 0.18);
    box-shadow:
        0 7px 16px rgba(116, 104, 92, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.92),
        inset 0 -4px 7px rgba(170, 160, 148, 0.22);
}

.cell.last-move .piece::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 18%;
    height: 18%;
    background-color: rgba(255, 0, 0, 0.7);
    border-radius: 50%;
    z-index: 10;
}

@keyframes othello-flip-highlight {
    0% {
        transform: perspective(240px) rotateY(82deg) scale(0.88);
        filter: brightness(1.35) saturate(1.2);
    }

    38% {
        transform: perspective(240px) rotateY(0deg) scale(1.08);
        filter: brightness(1.28) saturate(1.16);
    }

    72% {
        transform: perspective(240px) rotateY(0deg) scale(1.02);
        filter: brightness(1.16) saturate(1.08);
    }

    100% {
        transform: perspective(240px) rotateY(0deg) scale(1);
        filter: brightness(1) saturate(1);
    }
}

@media (min-width: 1179px) {
    :root {
        --board-width: min(100%, 820px, 100cqh);
    }

    .game-layout {
        container-type: size;
    }

    .chessboard {
        flex: 0 1 auto;
        width: min(100%, 820px, 100cqh);
        max-width: 820px;
        max-height: 100cqh;
        height: auto !important;
        margin: 0 auto;
    }
}

@media (min-width: 1280px) {
    :root {
        --board-width: min(100%, 820px, 100cqh);
    }

    .game-layout {
        gap: clamp(1.6rem, 2vw, 2.4rem);
    }

    .game-sidebar {
        flex: 0 0 220px;
        max-width: 220px;
    }

    .chessboard {
        flex: 0 1 auto;
        width: min(100%, 820px, 100cqh);
        max-width: 820px;
        max-height: 100cqh;
        height: auto !important;
        margin: 0 auto;
    }
}

@media (min-width: 1179px) and (max-height: 850px) {
    .game-layout {
        align-items: flex-start;
    }
}

@media (max-width: 1024px) {
    :root {
        --board-width: min(85vw, 85dvh);
    }
}

@media (max-width: 1178px) {
    .right-sidebar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .right-sidebar > * {
        min-width: 0;
    }

    #game-room-info,
    #game-scoreboard {
        margin-bottom: 0;
    }
}

@media (max-width: 480px) {
    .piece-count-strip {
        min-height: 50px;
    }

    .piece-count-strip-tag {
        font-size: 0.61rem;
        letter-spacing: 0.06em;
    }

    .piece-count-strip-value {
        font-size: 1rem;
    }
}

/* ============ 人机对战相关样式 ============ */

/* 房间操作行 */
.room-actions-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: stretch;
}

.room-actions-row #create-room-btn {
    flex: 1;
    margin-bottom: 0;
}

.robot-room-btn {
    flex: 0 0 30%;
    min-height: 52px;
    padding: 0.85rem 1rem;
    font-size: 0.96rem;
    font-family: var(--font-serif-base);
    letter-spacing: 0.12em;
    background: linear-gradient(135deg, #4a7c59, #3a6347);
    color: #fff;
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease, background-color 0.28s ease, opacity 0.28s ease;
    box-shadow: 0 8px 20px rgba(26, 26, 26, 0.08);
}

.robot-room-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(26, 26, 26, 0.14);
    background: linear-gradient(135deg, #5a8c69, #4a7357);
}

/* 房间列表机器人标签 */
.room-robot-tag {
    display: inline-block;
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: linear-gradient(135deg, #4a7c59, #3a6347);
    color: #fff;
    margin-left: 0.4rem;
    vertical-align: middle;
    font-weight: 600;
    letter-spacing: 0.04em;
}

/* 计分板机器人角标 */
.game-scoreboard-side.is-robot-side::before {
    content: '机器人';
    position: absolute;
    top: -0.46rem;
    right: -0.44rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.8rem;
    height: 1.72rem;
    padding: 0 0.4rem;
    border: 1px solid rgba(74, 124, 89, 0.66);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(240, 255, 244, 0.98), rgba(180, 220, 190, 0.96));
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    color: #2d4a35;
    pointer-events: none;
    box-shadow: 0 8px 16px rgba(26, 26, 26, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.62);
    letter-spacing: 0.04em;
    white-space: nowrap;
    z-index: 1;
}

/* 如果同时是玩家侧和机器人侧，优先显示"我" */
.game-scoreboard-side.is-player-side.is-robot-side::before {
    content: '我';
    min-width: auto;
    width: 1.72rem;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(201, 169, 98, 0.66);
    background: linear-gradient(180deg, rgba(255, 252, 244, 0.98), rgba(231, 211, 164, 0.96));
    color: var(--deep-charcoal);
}

/* 人机对战难度选择弹窗 */
#robot-difficulty-modal .modal-content {
    min-width: 340px;
    padding: 2rem 2rem 1.6rem;
}

#robot-difficulty-modal h3 {
    color: var(--deep-charcoal);
    margin-bottom: 0.35rem;
    font-size: 1.15rem;
    letter-spacing: 0.14em;
}

#robot-difficulty-modal p {
    color: var(--muted);
    margin-bottom: 1.4rem;
    font-size: 0.88rem;
    letter-spacing: 0.06em;
}

#robot-difficulty-modal .difficulty-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
}

#robot-difficulty-modal .difficulty-btn {
    min-height: 54px;
    padding: 0.85rem 1rem;
    border: 1px solid transparent;
    border-radius: 16px;
    cursor: pointer;
    font-family: var(--font-serif-base);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: #fff;
    transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease;
    box-shadow: 0 6px 16px rgba(26, 26, 26, 0.1);
    position: relative;
    overflow: hidden;
}

#robot-difficulty-modal .difficulty-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.12) 0%, transparent 50%);
    border-radius: inherit;
    pointer-events: none;
}

#robot-difficulty-modal .difficulty-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(26, 26, 26, 0.16);
}

#robot-difficulty-modal .difficulty-btn--beginner {
    background: linear-gradient(135deg, #6a9f7a, #4a7c59);
}

#robot-difficulty-modal .difficulty-btn--beginner:hover {
    background: linear-gradient(135deg, #7aaf8a, #5a8c69);
}

#robot-difficulty-modal .difficulty-btn--intermediate {
    background: linear-gradient(135deg, #c9a962, #a8894a);
}

#robot-difficulty-modal .difficulty-btn--intermediate:hover {
    background: linear-gradient(135deg, #d9b972, #b8995a);
}

#robot-difficulty-modal .difficulty-btn--advanced {
    background: linear-gradient(135deg, #c97a4a, #a85a2a);
}

#robot-difficulty-modal .difficulty-btn--advanced:hover {
    background: linear-gradient(135deg, #d98a5a, #b86a3a);
}

#robot-difficulty-modal .difficulty-btn--nightmare {
    background: linear-gradient(135deg, #8b3a4a, #6a1a2a);
}

#robot-difficulty-modal .difficulty-btn--nightmare:hover {
    background: linear-gradient(135deg, #9b4a5a, #7a2a3a);
}

#robot-difficulty-modal .difficulty-cancel-row {
    display: flex;
    justify-content: center;
}

#robot-difficulty-modal .difficulty-cancel-btn {
    min-height: 42px;
    padding: 0.6rem 2rem;
    border: 1px solid rgba(201, 169, 98, 0.28);
    border-radius: 999px;
    cursor: pointer;
    font-family: var(--font-serif-base);
    font-size: 0.88rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.6);
    transition: transform 0.28s ease, box-shadow 0.28s ease, background-color 0.28s ease, color 0.28s ease;
}

#robot-difficulty-modal .difficulty-cancel-btn:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.85);
    color: var(--deep-charcoal);
    box-shadow: 0 6px 14px rgba(26, 26, 26, 0.08);
}
