/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 根变量定义 */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --accent-primary: #007bff;
    --accent-secondary: #6c757d;
    --accent-success: #28a745;
    --accent-danger: #dc3545;
    --border-color: #dee2e6;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s ease;
}

/* 暗色主题 */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #404040;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --accent-primary: #4dabf7;
    --accent-secondary: #868e96;
    --accent-success: #51cf66;
    --accent-danger: #ff6b6b;
    --border-color: #495057;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* 基础样式 */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: var(--transition);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 头部样式 */
.header {
    text-align: center;
    margin-bottom: 30px;
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin-bottom: 5px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* 游戏控制区域 */
.game-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
    gap: 15px;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.difficulty-selector label {
    font-weight: 500;
    color: var(--text-primary);
}

.difficulty-selector select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.difficulty-selector select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.timer-display {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: 600;
}

.timer-label {
    color: var(--text-secondary);
}

.timer {
    color: var(--accent-primary);
    font-family: 'Courier New', monospace;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: 6px;
    min-width: 120px;
    text-align: center;
}

.control-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* 按钮样式 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background: var(--accent-secondary);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* 游戏区域 */
.game-area {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    margin-bottom: 30px;
}

.game-grid {
    display: grid;
    gap: 8px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.game-grid[data-size="3"] {
    grid-template-columns: repeat(3, 1fr);
}

.game-grid[data-size="4"] {
    grid-template-columns: repeat(4, 1fr);
}

.game-grid[data-size="5"] {
    grid-template-columns: repeat(5, 1fr);
}

.game-grid[data-size="6"] {
    grid-template-columns: repeat(6, 1fr);
}

.grid-cell {
    width: 80px;
    height: 80px;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.grid-cell:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
    box-shadow: var(--shadow);
}

.grid-cell.correct {
    background: var(--accent-success);
    color: white;
    border-color: var(--accent-success);
    animation: correctPulse 0.3s ease;
}

.grid-cell.wrong {
    background: var(--accent-danger);
    color: white;
    border-color: var(--accent-danger);
    animation: wrongShake 0.3s ease;
}

.grid-cell.completed {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    opacity: 0.8;
}

/* 动画效果 */
@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* 开始界面 */
.start-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    backdrop-filter: blur(5px);
}

.start-content {
    text-align: center;
    color: white;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.start-content h2 {
    font-size: 2rem;
    margin-bottom: 15px;
    color: var(--accent-primary);
}

.start-content p {
    font-size: 1.1rem;
    margin-bottom: 30px;
    color: var(--text-secondary);
}

.stats-preview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 30px;
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent-primary);
}

/* 完成界面 */
.complete-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    backdrop-filter: blur(5px);
}

.complete-content {
    text-align: center;
    color: white;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow);
    animation: slideIn 0.5s ease;
}

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

.complete-content h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--accent-success);
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin: 30px 0;
}

.result-item {
    text-align: center;
}

.result-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.result-value {
    display: block;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--accent-primary);
}

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

/* 统计面板 */
.stats-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.stats-header h3 {
    color: var(--text-primary);
    font-size: 1.2rem;
}

.stats-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-name {
    color: var(--text-secondary);
    font-weight: 500;
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-hover);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    color: var(--text-primary);
    font-size: 1.3rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: var(--transition);
}

.close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border-left: 4px solid var(--accent-primary);
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.history-time {
    font-weight: 600;
    color: var(--text-primary);
}

.history-date {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.history-difficulty {
    background: var(--accent-primary);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* 主题切换按钮 */
.theme-toggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-hover);
}

/* 工具类 */
.hidden {
    display: none !important;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .game-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .control-buttons {
        justify-content: center;
    }
    
    .grid-cell {
        width: 60px;
        height: 60px;
        font-size: 1.2rem;
    }
    
    .stats-preview,
    .result-stats {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .stats-content {
        grid-template-columns: 1fr;
    }
    
    .result-actions {
        flex-direction: column;
    }
    
    .theme-toggle {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
    }
}

@media (max-width: 480px) {
    .grid-cell {
        width: 50px;
        height: 50px;
        font-size: 1rem;
    }
    
    .game-grid {
        gap: 5px;
        padding: 15px;
    }
    
    .start-content,
    .complete-content {
        padding: 20px;
    }
}
