* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
}

.container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 500px;
    width: 90%;
    backdrop-filter: blur(10px);
}

header h1 {
    color: #4a4a4a;
    margin-bottom: 20px;
    font-size: 2.5em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.game-modes {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    background: #f0f0f0;
    color: #666;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    font-weight: 500;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mode-btn.active {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.mode-btn:hover:not(.active) {
    background: #e0e0e0;
    transform: translateY(-1px);
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
    flex-direction: column;
}

.game-info > div {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.infinite-status {
    width: 100%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 15px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.infinite-status.hidden {
    display: none;
}

.infinite-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.infinite-icon {
    font-size: 1.5em;
    animation: rotate 2s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.stop-btn {
    padding: 6px 15px;
    border: none;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.stop-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.infinite-timer {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 14px;
    opacity: 0.9;
    flex-wrap: wrap;
}

.infinite-countdown {
    text-align: center;
    margin: 20px 0;
}

.infinite-countdown.hidden {
    display: none;
}

.countdown-bar {
    width: 100%;
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
    margin: 15px 0;
}

.countdown-progress {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #45a049);
    border-radius: 3px;
    transition: width 1s linear;
}

.skip-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 20px;
    background: #4caf50;
    color: white;
    cursor: pointer;
    font-size: 14px;
    margin-top: 10px;
    transition: all 0.3s ease;
}

.skip-btn:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.current-player {
    font-size: 1.3em;
    font-weight: bold;
    color: #4a4a4a;
    padding: 10px 20px;
    background: #f8f9fa;
    border-radius: 25px;
    border: 2px solid #667eea;
}

.score {
    display: flex;
    gap: 15px;
    font-weight: bold;
    color: #666;
}

.score span {
    padding: 8px 15px;
    background: #f0f0f0;
    border-radius: 15px;
    font-size: 14px;
}

.game-container {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 5px;
    background: #667eea;
    border-radius: 15px;
    padding: 10px;
    max-width: 300px;
    width: 100%;
}

.cell {
    background: white;
    border-radius: 10px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(.taken) {
    background: #f8f9fa;
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.cell.taken {
    cursor: not-allowed;
}

.cell.winning {
    background: #4caf50 !important;
    color: white;
    animation: pulse 0.6s ease-in-out;
}

.cell.x {
    color: #ff6b6b !important;
    animation: fadeIn 0.3s ease-in-out;
}

.cell.o {
    color: #4ecdc4 !important;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.game-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.control-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 25px;
    background: #667eea;
    color: white;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.3s ease;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:hover {
    background: #5a6fd8;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

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

.game-result {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.game-result.hidden {
    display: none;
}

.result-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.result-content h2 {
    margin-bottom: 20px;
    font-size: 2em;
    color: #4a4a4a;
}

.play-again-btn {
    padding: 15px 30px;
    border: none;
    border-radius: 25px;
    background: #4caf50;
    color: white;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.play-again-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
}

/* 响应式设计 */
@media (max-width: 600px) {
    .container {
        padding: 20px;
        width: 95%;
    }
    
    header h1 {
        font-size: 2em;
    }
    
    .game-modes {
        gap: 8px;
    }
    
    .mode-btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .game-info {
        gap: 10px;
    }
    
    .current-player {
        font-size: 1.1em;
    }
    
    .score {
        justify-content: center;
    }
    
    .infinite-timer {
        gap: 15px;
        font-size: 12px;
    }
    
    .infinite-indicator {
        gap: 8px;
    }
    
    .cell {
        font-size: 2.5em;
    }
    
    .game-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .control-btn {
        width: 80%;
        max-width: 200px;
    }
    
    .result-content {
        padding: 30px 20px;
        margin: 20px;
    }
    
    .result-content h2 {
        font-size: 1.5em;
    }
}

@media (max-width: 400px) {
    .mode-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .cell {
        font-size: 2em;
    }
    
    .score span {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .infinite-timer {
        flex-direction: column;
        gap: 5px;
    }
}

/* 暗色主题支持 */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    }
    
    .container {
        background: rgba(26, 32, 44, 0.95);
        color: #e2e8f0;
    }
    
    header h1 {
        color: #e2e8f0;
    }
    
    .current-player {
        background: #4a5568;
        color: #e2e8f0;
        border-color: #667eea;
    }
    
    .score span {
        background: #4a5568;
        color: #e2e8f0;
    }
    
    .mode-btn {
        background: #4a5568;
        color: #e2e8f0;
    }
    
    .result-content {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .result-content h2 {
        color: #e2e8f0;
    }
}

/* 移动端触摸优化 */
@media (hover: none) and (pointer: coarse) {
    /* 移动设备专用样式 */
    .cell:hover:not(.taken) {
        /* 移除hover效果，避免移动端的粘性hover */
        background: white;
        transform: none;
        box-shadow: none;
    }
    
    .cell:active:not(.taken) {
        background: #f0f8ff;
        transform: scale(0.95);
    }
    
    /* 确保已下棋子的颜色不受触摸影响 */
    .cell.taken.x {
        color: #ff6b6b !important;
    }
    
    .cell.taken.o {
        color: #4ecdc4 !important;
    }
    
    /* 确保已下棋子不会有背景色变化 */
    .cell.taken:active {
        background: white !important;
        transform: none;
    }
    
    .mode-btn:hover:not(.active) {
        background: #f0f0f0;
        transform: none;
    }
    
    .mode-btn:active {
        transform: scale(0.95);
    }
    
    .control-btn:hover {
        background: #667eea;
        transform: none;
        box-shadow: none;
    }
    
    .control-btn:active {
        background: #5a6fd8;
        transform: scale(0.95);
    }
    
    /* 增加触摸目标大小 */
    .cell {
        min-height: 80px;
        min-width: 80px;
    }
    
    button {
        min-height: 44px;
        min-width: 44px;
    }
}