/* 全局样式 */
* {
    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;
    color: #333;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部样式 */
.game-header {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    max-width: 520px;
    margin: 0 auto;
}

.game-header h1 {
    text-align: center;
    color: #4a5568;
    font-size: 2.5rem;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

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

.difficulty-selector select {
    padding: 8px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.difficulty-selector select:hover {
    border-color: #667eea;
}

.timer {
    font-size: 1.2rem;
    font-weight: bold;
    color: #4a5568;
}

/* 主游戏区域 */
.game-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    max-width: 700px;
    margin: 0 auto;
}

.game-board-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 520px;
    display: flex;
    justify-content: center;
}

/* 数独网格样式 */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 2px;
    background: #2d3748;
    border-radius: 10px;
    padding: 12px;
    width: 480px;
    height: 480px;
    margin: 0 auto;
}

.cell {
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.cell:hover {
    background: #e6fffa;
}

.cell.selected {
    background: #bee3f8 !important;
    box-shadow: inset 0 0 0 2px #3182ce;
}

.cell.given {
    background: #f7fafc;
    color: #2d3748;
    cursor: default;
}

.cell.given:hover {
    background: #f7fafc;
}

.cell.error {
    background: #fed7d7 !important;
    color: #c53030;
}

.cell.highlight {
    background: #fef5e7;
}

/* 3x3宫格边框 */
.cell:nth-child(3n) {
    border-right: 2px solid #2d3748;
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid #2d3748;
}

/* 数字面板样式 */
.number-pad {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 520px;
}

.number-pad h3 {
    margin-bottom: 10px;
    color: #4a5568;
    text-align: center;
    font-size: 1.1rem;
}

.number-buttons {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
}

/* 侧边栏样式 */
.game-sidebar {
    display: flex;
    flex-direction: row;
    gap: 15px;
    width: 100%;
    max-width: 520px;
}

.game-actions,
.game-stats {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    flex: 1;
}

.game-stats h3 {
    margin-bottom: 10px;
    color: #4a5568;
    text-align: center;
    font-size: 1rem;
}

.number-btn {
    padding: 8px 4px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    background: white;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.number-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.erase-btn {
    grid-column: span 9;
    background: #fed7d7;
    color: #c53030;
    border-color: #feb2b2;
}

.erase-btn:hover {
    background: #c53030;
    color: white;
}

.game-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    height: fit-content;
}

.action-btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: #667eea;
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 32px;
}

.action-btn:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
}

.action-btn:hover {
    background: #5a67d8;
    transform: translateY(-2px);
}

.action-btn:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
}

.game-stats {
    font-size: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: start;
}

.game-stats h3 {
    grid-column: span 2;
    margin-bottom: 8px;
    text-align: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    text-align: center;
}

.stat-item span:first-child {
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 2px;
}

.stat-item span:last-child {
    font-weight: bold;
    color: #333;
}

/* 模态框样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 2rem;
}

.modal-content p {
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: #666;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

/* 移动端视窗优化 */
@media (max-width: 768px) {
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
        overflow-x: hidden;
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    html {
        height: -webkit-fill-available;
    }
    
    .container {
        padding: 10px;
        max-width: 100%;
    }
    
    .game-header {
        padding: 15px;
        margin-bottom: 10px;
    }
    
    .game-header h1 {
        font-size: 1.8rem;
        margin-bottom: 10px;
    }
    
    .game-controls {
        justify-content: space-between;
        gap: 10px;
    }
    
    .timer {
        font-size: 1rem;
    }
    
    .game-main {
        gap: 10px;
        max-width: 100%;
    }
    
    .number-pad {
        max-width: 320px;
        padding: 12px;
    }
    
    .number-pad h3 {
        margin-bottom: 8px;
        font-size: 1rem;
    }
    
    .number-buttons {
        gap: 6px;
    }
    
    .number-btn {
        padding: 8px;
        font-size: 1rem;
    }
    
    .game-board-container {
        padding: 15px;
        width: 100%;
        max-width: 320px;
    }
    
    .sudoku-grid {
        width: 280px;
        height: 280px;
    }
    
    .cell {
        font-size: 1rem;
    }
    
    .game-sidebar {
        width: 100%;
        max-width: 320px;
        gap: 10px;
    }
    
    .game-actions {
        flex: 1;
        min-width: 100px;
        padding: 15px;
        gap: 8px;
    }
    
    .action-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    .game-stats {
        width: 100%;
        padding: 15px;
        margin-top: 0;
    }
    
    .game-stats h3 {
        margin-bottom: 10px;
        font-size: 1rem;
    }
    
    .stat-item {
        margin-bottom: 6px;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 5px;
        height: 100vh;
        height: -webkit-fill-available;
        display: flex;
        flex-direction: column;
    }
    
    .game-header {
        padding: 8px;
        margin-bottom: 5px;
        flex-shrink: 0;
    }
    
    .game-header h1 {
        font-size: 1.4rem;
        margin-bottom: 5px;
    }
    
    .game-controls {
        flex-direction: row;
        justify-content: space-between;
        gap: 5px;
        font-size: 0.9rem;
    }
    
    .game-main {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 8px;
        overflow: hidden;
        padding: 0 10px;
    }
    
    .number-pad {
        max-width: 280px;
        padding: 10px;
    }
    
    .number-pad h3 {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }
    
    .number-buttons {
        gap: 4px;
    }
    
    .number-btn {
        padding: 6px;
        font-size: 0.9rem;
    }
    
    .game-board-container {
        padding: 10px;
        max-width: 280px;
        flex-shrink: 0;
    }
    
    .sudoku-grid {
        width: 250px;
        height: 250px;
    }
    
    .cell {
        font-size: 0.9rem;
    }
    
    .game-sidebar {
        max-width: 280px;
        gap: 8px;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }
    
    .game-actions {
        padding: 10px;
        gap: 4px;
        min-width: auto;
    }
    
    .action-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
        min-height: 28px;
    }
    
    .game-stats {
        padding: 10px;
        font-size: 0.7rem;
    }
    
    .game-stats h3 {
        margin-bottom: 5px;
        font-size: 0.9rem;
    }
    
    .stat-item {
        margin-bottom: 3px;
        font-size: 0.75rem;
        padding: 2px 0;
    }
    
    .modal-content {
        padding: 20px;
        margin: 10px;
        max-width: 280px;
        width: 95%;
    }
    
    .modal-content h2 {
        font-size: 1.3rem;
    }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
    .container {
        padding: 5px;
        gap: 5px;
    }
    
    .game-header {
        padding: 8px;
        gap: 8px;
    }
    
    .game-header h1 {
        font-size: 1.2rem;
    }
    
    .game-controls {
        gap: 8px;
        padding: 8px;
    }
    
    .game-main {
        gap: 5px;
    }
    
    .number-pad {
        max-width: 240px;
        padding: 8px;
    }
    
    .number-pad h3 {
        margin-bottom: 5px;
        font-size: 0.9rem;
    }
    
    .number-buttons {
        gap: 3px;
    }
    
    .number-btn {
        padding: 4px;
        font-size: 0.8rem;
        min-height: 28px;
    }
    
    .game-board-container {
        padding: 8px;
        max-width: 240px;
    }
    
    .sudoku-grid {
        width: 220px;
        height: 220px;
    }
    
    .cell {
        font-size: 0.8rem;
    }
    
    .game-sidebar {
        max-width: 240px;
        gap: 6px;
    }
    
    .game-actions {
        padding: 8px;
        gap: 4px;
    }
    
    .action-btn {
        padding: 4px 8px;
        font-size: 0.7rem;
        min-height: 28px;
    }
    
    .game-stats {
        padding: 8px;
        font-size: 0.65rem;
    }
    
    .modal-content {
        padding: 15px;
        width: 95%;
        max-width: 240px;
    }
}

/* 动画效果 */
@keyframes cellFill {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.cell.filled {
    animation: cellFill 0.2s ease;
}

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

.victory-animation {
    animation: victory 0.6s ease-in-out;
}