/* 响应式断点定义 */
@custom-media --mobile-s (width >= 320px);
@custom-media --mobile-m (width >= 375px);
@custom-media --mobile-l (width >= 425px);
@custom-media --tablet (width >= 768px);
@custom-media --laptop (width >= 1024px);
@custom-media --desktop (width >= 1440px);

/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6C5CE7;
    --secondary-color: #A8A4FF;
    --accent-color: #FF6B6B;
    --background-start: #8E2DE2;
    --background-end: #4A00E0;
    --text-color: #2D3436;
    --light-text: #636E72;
    --white: #FFFFFF;
    --cell-bg: rgba(255, 255, 255, 0.9);
    --shadow-color: rgba(0, 0, 0, 0.1);
    --x-color: #FF6B6B;
    --o-color: #26DE81;
}

/* 背景动画 */
@keyframes gradientBG {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

@keyframes floatingBubbles {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0.3;
    }
    50% {
        opacity: 0.8;
    }
    100% {
        transform: translateY(-100vh) rotate(360deg);
        opacity: 0;
    }
}

body {
    font-family: 'Quicksand', sans-serif;
    background: linear-gradient(-45deg,
    var(--background-start),
    var(--secondary-color),
    var(--primary-color),
    var(--background-end)),
    radial-gradient(circle at 20% 50%,
            rgba(255, 255, 255, 0.1) 0%,
            transparent 50%);
    background-size: 400% 400%, 200% 200%;
    animation: gradientBG 12s ease infinite,
    pulseGlow 8s ease infinite alternate;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
    position: relative;
    overflow: hidden;
}

@keyframes pulseGlow {
    0% {
        background-position: 20% 50%;
    }
    100% {
        background-position: 80% 50%;
    }
}

/* 背景效果容器 */
.bubbles {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -1;
    pointer-events: none;
}

/* 动态光晕效果 */
.glow {
    position: absolute;
    width: 150vw;
    height: 150vw;
    background: radial-gradient(circle, rgba(108, 92, 231, 0.15) 0%, transparent 60%);
    border-radius: 50%;
    animation: floatGlow 25s infinite ease-in-out alternate;
    opacity: 0.7;
    filter: blur(40px);
    will-change: transform;
}

@keyframes floatGlow {
    0% {
        transform: translate(-30%, -30%) scale(0.8);
    }
    50% {
        transform: translate(10%, 20%) scale(1.2);
    }
    100% {
        transform: translate(30%, -10%) scale(0.9);
    }
}

/* 星空粒子效果 */
.stars {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -2; /* 确保在背景之上但不会遮挡交互元素 */
}

.star {
    position: absolute;
    background-color: white;
    border-radius: 50%;
    animation: twinkle var(--duration, 5s) infinite ease-in-out;
    opacity: 0;
}

@keyframes twinkle {
    0%, 100% {
        opacity: 0;
        transform: scale(0.5);
    }
    50% {
        opacity: var(--opacity, 0.8);
        transform: scale(1);
    }
}

.bubble {
    position: absolute;
    bottom: -100px;
    background: rgba(255, 255, 255, 0.323);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    animation: floatingBubbles 15s linear infinite;
}

.bubble:nth-child(1) {
    width: 40px;
    height: 40px;
    left: 10%;
    animation-duration: 12s;
}

.bubble:nth-child(2) {
    width: 20px;
    height: 20px;
    left: 20%;
    animation-duration: 16s;
    animation-delay: 1s;
}

.bubble:nth-child(3) {
    width: 30px;
    height: 30px;
    left: 35%;
    animation-duration: 13s;
    animation-delay: 2s;
}

.bubble:nth-child(4) {
    width: 50px;
    height: 50px;
    left: 50%;
    animation-duration: 18s;
    animation-delay: 0s;
}

.bubble:nth-child(5) {
    width: 25px;
    height: 25px;
    left: 65%;
    animation-duration: 14s;
    animation-delay: 3s;
}

.bubble:nth-child(6) {
    width: 35px;
    height: 35px;
    left: 80%;
    animation-duration: 16s;
    animation-delay: 2s;
}

.bubble:nth-child(7) {
    width: 45px;
    height: 45px;
    left: 5%;
    animation-duration: 15s;
    animation-delay: 4s;
}

.bubble:nth-child(8) {
    width: 22px;
    height: 22px;
    left: 25%;
    animation-duration: 17s;
    animation-delay: 5s;
}

.bubble:nth-child(9) {
    width: 38px;
    height: 38px;
    left: 70%;
    animation-duration: 14s;
    animation-delay: 1.5s;
}

.bubble:nth-child(10) {
    width: 28px;
    height: 28px;
    left: 90%;
    animation-duration: 13s;
    animation-delay: 3.5s;
}

@keyframes floatingBubbles {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0.3;
    }
    50% {
        opacity: 1;
    }
    80% {
        opacity: 0.8;
    }
    100% {
        transform: translateY(-100vh) rotate(360deg);
        opacity: 0;
    }
}

.game-container {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: clamp(1rem, 5vw, 2rem);
}

.game-wrapper {
    width: min(100%, 800px);
    /* margin-inline: auto; */
}

/* 游戏布局 - 默认为上下布局（移动设备） */
.game-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

/* 棋盘区域和控制区域 */
.game-board-section,
.game-control-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2),
    0 0 8px rgba(0, 0, 0, 0.1);
    padding: clamp(1.5rem, 4vw, 2rem);
    width: 100%;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.18);
}

/* 游戏控制区域样式 */
.game-control-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

@media (min-width: 768px) {
    .game-control-section {
        align-items: flex-start;
        text-align: left;
        padding: 0 10px;
    }

    .game-info, .scoreboard, .controls {
        width: 100%;
    }

    .status {
        justify-content: center;
    }
}

.container:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25),
    0 5px 15px rgba(0, 0, 0, 0.15);
}

.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    animation: shimmer 2s infinite linear;
    background-size: 200% 100%;
}

@keyframes shimmer {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

h1 {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 6vw, 2.2rem);
    margin-bottom: clamp(1rem, 5vw, 1.5rem);
    color: var(--primary-color);
    text-shadow: 2px 2px 4px var(--shadow-color);
    position: relative;
    display: inline-block;
    animation: pulse 3s infinite ease-in-out;
}

h1::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transform: translateX(-50%);
    transition: width 0.3s ease;
}

h1:hover::after {
    width: 80%;
}

/* 游戏状态样式 */
.game-info {
    margin-bottom: 20px;
    width: 100%;
}

.status {
    font-size: clamp(1rem, 4vw, 1.3rem);
    font-weight: 600;
    color: var(--primary-color);
    height: clamp(30px, 8vw, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

@media (min-width: 768px) {
    .game-info {
        margin-bottom: 25px;
    }

    .status {
        justify-content: center;
        font-size: 1.4rem;
        height: auto;
        padding: 10px 0;
    }
}

.status.winner-x {
    color: var(--x-color);
    transform: scale(1.1);
}

.status.winner-o {
    color: var(--o-color);
    transform: scale(1.1);
}

.status.draw {
    color: var(--light-text);
}

/* 计分板样式 */
.scoreboard {
    display: flex;
    justify-content: center;
    gap: clamp(15px, 4vw, 25px);
    margin-bottom: clamp(1rem, 5vw, 1.5rem);
    padding: clamp(10px, 3vw, 15px);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.2));
    border-radius: clamp(10px, 3vw, 15px);
    box-shadow: 0 4px 15px var(--shadow-color);
}

.score {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(8px, 3vw, 12px) clamp(15px, 4vw, 20px);
    border-radius: clamp(8px, 3vw, 12px);
    background: var(--white);
    box-shadow: 0 4px 10px var(--shadow-color);
    transition: transform 0.3s ease;
    min-width: 80px;
}

@media (min-width: 768px) {
    .scoreboard {
        flex-direction: column;
        gap: 15px;
        padding: 20px;
        margin-bottom: 30px;
        background: linear-gradient(135deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.3));
    }

    .score {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        padding: 15px 20px;
        min-width: 200px;
    }

    .player {
        font-size: 1.1rem;
        margin-bottom: 0;
    }

    .score-value {
        font-size: 1.8rem;
    }

    .controls {
        display: flex;
        justify-content: center;
        width: 100%;
    }

    .btn {
        padding: 12px 30px;
        font-size: 1.1rem;
        min-width: 160px;
    }
}

.score:hover {
    transform: translateY(-2px);
}

.player {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--text-color);
}

.score-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* 棋盘样式 */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(6px, 2vw, 10px);
    margin: 0 auto clamp(1rem, 5vw, 1.5rem);
    position: relative;
    aspect-ratio: 1;
    width: min(100%, 280px);
    padding: clamp(8px, 2vw, 12px);
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.15), rgba(168, 164, 255, 0.15));
    border-radius: clamp(15px, 5vw, 20px);
    box-shadow: 0 10px 30px var(--shadow-color),
    inset 0 2px 10px rgba(255, 255, 255, 0.2);
    transition: transform 0.3s ease;
    position: relative;
    container-type: inline-size;
}

.board:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 35px var(--shadow-color),
    inset 0 2px 10px rgba(255, 255, 255, 0.2);
}

.cell {
    background: var(--cell-bg);
    border-radius: clamp(8px, 3vw, 12px);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.5rem, 5vw, 3rem);
    font-weight: bold;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2),
    inset 0 2px 4px rgba(255, 255, 255, 0.5);
    position: relative;
    z-index: 2;
    aspect-ratio: 1;
    width: 100%;
    min-width: 50px;
    min-height: 50px;
    overflow: hidden;
    border: 2px solid transparent;
    will-change: transform;
    touch-action: manipulation;
}

.cell:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25),
    inset 0 2px 4px rgba(255, 255, 255, 0.5);
    border-color: rgba(108, 92, 231, 0.3);
}

.cell:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 2px rgba(255, 255, 255, 0.4);
}

.cell.x::before, .cell.x::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 50px;
    background-color: var(--x-color);
    border-radius: 6px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
    transform-origin: center;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(0deg);
    opacity: 0;
}

.cell.x::before {
    transform: translate(-50%, -50%) rotate(45deg);
    animation: x-animation-before 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.cell.x::after {
    transform: translate(-50%, -50%) rotate(-45deg);
    animation: x-animation-after 0.4s 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes x-animation-before {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

@keyframes x-animation-after {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.cell.o::before {
    content: '';
    position: absolute;
    width: 60%;
    height: 60%;
    border: 12px solid var(--o-color);
    border-radius: 50%;
    transform: scale(0);
    animation: o-animation 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

@keyframes o-animation {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

/* 获胜线样式 */
.line {
    position: absolute;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    z-index: 1; /* 确保在撒花效果之上，但低于棋盘 */
    transform: scale(0);
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.line.show {
    opacity: 1;
    transform: scale(1);
    animation: celebrate 0.5s forwards,
    pulse 1.5s infinite ease-in-out;
    will-change: transform, opacity;
    z-index: 2;
    filter: drop-shadow(0 0 8px currentColor);
}

.line.x-win {
    background: var(--x-color) !important;
    box-shadow: 0 0 20px 4px var(--x-color);
    animation: celebrate 0.5s forwards,
    pulse 1.5s infinite ease-in-out,
    glow-x 2s infinite alternate;
}

.line.o-win {
    background: var(--o-color) !important;
    box-shadow: 0 0 20px 4px var(--o-color);
    animation: celebrate 0.5s forwards,
    pulse 1.5s infinite ease-in-out,
    glow-o 2s infinite alternate;
}

@keyframes glow-x {
    0% {
        box-shadow: 0 0 10px 2px var(--x-color);
    }
    100% {
        box-shadow: 0 0 30px 8px var(--x-color);
    }
}

@keyframes glow-o {
    0% {
        box-shadow: 0 0 10px 2px var(--o-color);
    }
    100% {
        box-shadow: 0 0 30px 8px var(--o-color);
    }
}

.line.horizontal {
    height: 12px;
    width: 280px;
    border-radius: 6px;
    top: 134px;
    left: 0;
}

/* 精确计算格子中心点：每个格子80px+10px gap+10px padding */
.line.horizontal.row-0 {
    top: 40px;
}

/* 第一行中心：10px padding + 40px (80/2) */
.line.horizontal.row-1 {
    top: 125px;
}

/* 第二行中心：10px padding + 80px + 10px gap + 40px */
.line.horizontal.row-2 {
    top: 210px;
}

/* 第三行中心：10px padding + 80px*2 + 10px*2 + 40px */

.line.vertical {
    width: 12px;
    height: 280px;
    border-radius: 6px;
    top: 0;
}

.line.vertical.col-0 {
    left: 40px;
}

/* 第一列中心：10px padding + 40px */
.line.vertical.col-1 {
    left: 125px;
}

/* 第二列中心：10px padding + 80px + 10px gap + 40px */
.line.vertical.col-2 {
    left: 210px;
}

/* 第三列中心：10px padding + 80px*2 + 10px*2 + 40px */

/* 添加像素级微调 */
.line.horizontal {
    width: 280px;
    margin-left: -1px; /* 补偿渲染误差 */
}

.line.vertical {
    height: 280px;
    margin-top: -1px;
}

.line.diagonal {
    width: 12px;
    height: 400px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 6px;
    top: -60px;
    transform-origin: center;
    z-index: 5;
}

.line.diagonal.left {
    left: 134px; /* 调整6px以补偿中心点 */
}

.line.diagonal.right {
    left: 134px;
}

.line.diagonal.left.show {
    transform: rotate(-45deg);
    animation: celebrate 0.5s;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.line.diagonal.right.show {
    transform: rotate(45deg);
    animation: celebrate 0.5s;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.line.x-win {
    background: var(--x-color) !important;
    box-shadow: 0 0 16px 2px var(--x-color);
}

.line.o-win {
    background: var(--o-color) !important;
    box-shadow: 0 0 16px 2px var(--o-color);
}

/* 添加微调动画 */
@keyframes fineAdjust {
    0% {
        transform: scale(0) translate(0, 0);
    }
    90% {
        transform: scale(1) translate(-1px, -1px);
    }
    100% {
        transform: scale(1) translate(0, 0);
    }
}

@keyframes celebrate {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1; /* 强制保持不透明度 */
    }
}

.line.show {
    opacity: 1;
    animation: celebrate 0.5s forwards; /* 添加forwards保持最终状态 */
}

/* 移除可能导致冲突的微调动画 */

/* 获胜单元格高亮效果 */
.cell.winner {
    animation: winner-cell 1s infinite alternate;
    box-shadow: 0 0 15px currentColor;
    transform: scale(1.05);
    z-index: 3;
}

@keyframes winner-cell {
    0% {
        box-shadow: 0 0 10px currentColor;
        transform: scale(1.02);
    }
    100% {
        box-shadow: 0 0 25px currentColor;
        transform: scale(1.08);
    }
}

.cell.winner.x {
    background: rgba(255, 107, 107, 0.2);
}

.cell.winner.o {
    background: rgba(38, 222, 129, 0.2);
}

/* 撒花效果容器 */
.confetti-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10; /* 修改为高优先级 */
    pointer-events: none;
    overflow: visible;
}

/* 单个撒花粒子样式 */
.confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    background: linear-gradient(45deg, #FF6B6B, #F9A825, #6C5CE7, #26DE81, #2BC4E2);
    border-radius: 50%;
    opacity: 0.9;
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.2));
    pointer-events: none; /* 粒子本身不阻挡交互 */
}

/* 按钮样式 */
.controls {
    margin-top: 30px;
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

.cell {
    overflow: hidden;
}

.cell::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 255, 255, .7) 0%, rgba(255, 255, 255, .3) 40%, rgba(255, 255, 255, 0) 70%);
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
    transition: 0s;
}

.cell:active::after {
    transform: scale(0);
    opacity: 1;
    animation: ripple 0.6s ease-out;
}

.status.winner-x, .status.winner-o {
    animation: celebrate 0.6s ease-in-out;
}

.btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    border: none;
    padding: clamp(10px, 3vw, 12px) clamp(20px, 5vw, 30px);
    font-size: clamp(0.9rem, 3.5vw, 1.1rem);
    font-weight: 600;
    border-radius: clamp(20px, 6vw, 25px);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
    font-family: 'Quicksand', sans-serif;
    position: relative;
    overflow: hidden;
    min-width: 120px;
    min-height: 44px; /* 满足WCAG触摸目标最小尺寸 */
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
            120deg,
            transparent,
            rgba(255, 255, 255, 0.3),
            transparent
    );
    transition: 0.5s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4);
}

.btn:hover::before {
    left: 100%;
}

.btn:active {
    transform: translateY(0);
}

/* 页脚样式 */
.footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(108, 92, 231, 0.2);
    color: var(--light-text);
    font-size: 0.9rem;
    font-weight: 500;
}

/* 响应式设计 */
/* 平板和电脑布局 - 左右布局 */
@media (min-width: 768px) {
    .game-wrapper {
        width: min(250%, 800px);
    }

    .container {
        padding: clamp(1.5rem, 4vw, 2.5rem);
    }

    .game-layout {
        flex-direction: row;
        justify-content: space-between;
        align-items: stretch;
        gap: 30px;
        min-height: 450px;
    }

    .game-board-section {
        flex: 1;
        max-width: 60%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .game-control-section {
        flex: 1;
        max-width: 40%;
        justify-content: space-between;
        gap: 20px;
        padding: 20px 0;
    }

    .board {
        margin: 0 auto;
        width: min(100%, 350px);
        height: min(100%, 350px);
    }

    .scoreboard {
        width: 100%;
        margin-bottom: 30px;
    }

    .controls {
        margin-top: 30px;
    }

    h1 {
        font-size: 2.5rem;
        margin-bottom: 2rem;
    }

    .footer {
        margin-top: 2rem;
        padding-top: 1.5rem;
        font-size: 1rem;
        width: 100%;
        text-align: center;
    }
}

@media (max-height: 700px) {
    body {
        padding: 5px 0;
    }

    .container {
        padding: 15px 10px;
        margin: 10px;
        width: unset;
    }

    h1 {
        font-size: 1.7rem;
        margin-bottom: 12px;
    }

    .game-info {
        margin-bottom: 12px;
    }

    .scoreboard {
        margin-bottom: 12px;
        padding: 8px;
    }

    .score {
        padding: 6px 12px;
    }

    .board {
        width: 240px;
        height: 240px;
        margin-bottom: 12px;
    }

    .footer {
        margin-top: 12px;
        font-size: 0.8rem;
    }
}

/* 中等手机屏幕 */
@media (max-width: 500px) {
    body {
        padding: 10px 0;
    }

    .container {
        padding: 15px;
        margin: 10px;
        width: unset;
    }

    .game-container {
        place-items: unset;
    }

    h1 {
        font-size: 1.8rem;
        margin-bottom: 15px;
    }

    .board {
        width: 260px;
        height: 260px;
        gap: 8px;
    }

    .cell {
        font-size: 2.2rem;
        border-radius: 10px;
    }

    .cell.x::before, .cell.x::after {
        width: 10px;
        height: 45px;
    }

    .cell.o::before {
        border-width: 10px;
    }

    .scoreboard {
        gap: 15px;
        padding: 10px;
        margin-bottom: 15px;
    }

    .score {
        padding: 8px 15px;
    }

    .player {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }

    .score-value {
        font-size: 1.6rem;
    }

    .status {
        font-size: 1.2rem;
        height: 30px;
    }

    .btn {
        padding: 10px 25px;
        font-size: 1rem;
    }

    .controls {
        margin-top: 20px;
    }
}

/* 小型手机屏幕 */
@media (max-width: 380px) {
    .container {
        padding: 12px 30px;
        margin: 8px;
        width: unset;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 12px;
    }

    .board {
        width: 230px;
        height: 230px;
        gap: 6px;
        padding: 8px;
    }

    .cell {
        font-size: 1.8rem;
        border-radius: 8px;
    }

    .cell.x::before, .cell.x::after {
        width: 8px;
        height: 40px;
    }

    .cell.o::before {
        border-width: 8px;
    }

    .scoreboard {
        gap: 12px;
        padding: 8px;
        margin-bottom: 12px;
    }

    .score {
        padding: 6px 10px;
    }

    .player {
        font-size: 0.8rem;
        margin-bottom: 3px;
    }

    .score-value {
        font-size: 1.4rem;
    }

    .status {
        font-size: 1rem;
        height: 25px;
    }

    .btn {
        padding: 8px 20px;
        font-size: 0.9rem;
    }

    .controls {
        margin-top: 15px;
    }

    .footer {
        margin-top: 10px;
        font-size: 0.75rem;
    }
}

/* 超小型手机屏幕 */
@media (max-width: 320px) {
    .container {
        padding: 10px 5px;
        margin: 5px;
        width: unset;
    }

    h1 {
        font-size: 1.3rem;
        margin-bottom: 10px;
    }

    .board {
        width: 200px;
        height: 200px;
        gap: 5px;
        padding: 6px;
    }

    .cell {
        font-size: 1.5rem;
    }

    .scoreboard {
        gap: 10px;
        padding: 6px;
    }

    .score {
        padding: 5px 8px;
    }

    .player {
        font-size: 0.75rem;
    }

    .score-value {
        font-size: 1.2rem;
    }
}

/* 容器查询支持 */
@container (min-width: 300px) {
    .cell {
        font-size: clamp(2rem, 6vw, 3rem);
    }
}

/* 性能优化 */
* {
    scroll-behavior: smooth;
    box-sizing: border-box;
}

/* 动画优化 */
.cell, .btn, .score {
    will-change: transform;
    backface-visibility: hidden;
}