/* 简约数独游戏样式 */
:root {
    --primary-color: #4a6fa5;
    --primary-dark: #385d8a;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --border-color: #dee2e6;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 6px 12px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s ease;
}

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

body {
    font-family: 'Inter', 'Segoe UI', 'Microsoft YaHei', sans-serif;
    line-height: 1.6;
    color: var(--dark-color);
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background-color: white;
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

/* 头部样式 */
.header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 2rem;
    text-align: center;
    border-bottom: 4px solid rgba(255, 255, 255, 0.1);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.header .subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* 游戏容器 */
.game-container {
    display: flex;
    flex: 1;
    padding: 2rem;
    gap: 2rem;
}

/* 游戏棋盘区域 */
.game-board {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* 数独网格 */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 0;
    background-color: var(--dark-color);
    border: 3px solid var(--dark-color);
    border-radius: 8px;
    overflow: hidden;
    width: min(80vw, 600px);
    height: min(80vw, 600px);
    margin: 0 auto;
    box-sizing: border-box;
}

.sudoku-cell {
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    user-select: none;
    box-sizing: border-box;
    border: 1px solid #ccc;
}

.sudoku-cell:hover {
    background-color: #e3f2fd;
}

/* 固定数字 - 题目给出的数字，使用柔和的浅灰色方格 */
.sudoku-cell.fixed {
    background-color: #f0f0f0;
}

/* 空格 - 纯白背景 */
.sudoku-cell.empty {
    background-color: #ffffff;
}

/* 用户填入 - 柔和的浅青蓝色方格，与题目数字明显区分 */
.sudoku-cell.user-filled {
    background-color: #e3f2fd;
}

/* 选中状态 - 当前正填入的单元格，使用明亮的蓝色方格 */
.sudoku-cell.selected {
    background-color: #64b5f6;
    color: #ffffff;
    box-shadow: inset 0 0 0 3px #42a5f5;
    transform: scale(1.02);
    z-index: 1;
}

/* 错误状态 - 使用柔和的红色方格 */
.sudoku-cell.error {
  background-color: #ef9a9a;
  color: #ffffff;
  animation: shake 0.3s;
}

/* 冲突状态 - 使用柔和的浅红色方格 */
/* 使用更高的特异性确保覆盖 user-filled 样式 */
.sudoku-cell.conflict,
.sudoku-cell.user-filled.conflict {
  background-color: #ffcdd2 !important;
}

/* 相同数字高亮 - 选中时高亮相同数字的方格，使用统一的蓝色系 */
/* 其他用户填入的相同数字高亮 - 柔和的浅蓝色方格 */
.sudoku-cell.same-number-user {
    background-color: #bbdefb !important;
}

/* 题目的相同数字高亮 - 温暖的浅黄色方格 */
.sudoku-cell.same-number-fixed {
    background-color: #ffecb3 !important;
}

/* 错误状态抖动动画 */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.sudoku-cell:nth-child(3n) {
    border-right: 2px solid var(--dark-color);
}

.sudoku-cell:nth-child(9n) {
    border-right: none;
}

.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--dark-color);
}

/* 游戏信息 */
.game-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    background-color: var(--light-color);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.info-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.info-label {
    font-weight: 600;
    color: var(--secondary-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

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

/* 游戏控制区域 */
.game-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 300px;
}

.control-section {
    background-color: var(--light-color);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.control-section h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 按钮样式 */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

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

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

.btn-primary:hover {
    background-color: var(--primary-dark);
}

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

.btn-warning {
    background-color: var(--warning-color);
    color: var(--dark-color);
}

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

.button-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

/* 难度按钮 */
.difficulty-buttons {
    display: flex;
    gap: 0.75rem;
}

.difficulty-btn {
    flex: 1;
    padding: 0.75rem;
    background-color: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
}

.difficulty-btn:hover {
    border-color: var(--primary-color);
    background-color: #f0f8ff;
}

.difficulty-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* 数字键盘 */
.number-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.number-btn {
    aspect-ratio: 1/1;
    font-size: 1.5rem;
    font-weight: 700;
    background-color: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-btn:hover {
    background-color: #f0f8ff;
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.number-btn:active {
    transform: scale(0.95);
}

.clear-btn {
    grid-column: span 3;
    aspect-ratio: auto;
    height: auto;
    padding: 0.75rem;
    background-color: var(--light-color);
}

/* 开关设置 */
.settings {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.switch input {
    display: none;
}

.slider {
    position: relative;
    width: 50px;
    height: 26px;
    background-color: #ccc;
    border-radius: 34px;
    transition: var(--transition);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    border-radius: 50%;
    transition: var(--transition);
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.switch-label {
    font-weight: 500;
}

/* 用户信息区域 */
.user-info {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.auth-buttons {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

/* 表单样式 */
.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark-color);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.1);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--secondary-color);
}

.form-error {
    color: var(--danger-color);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    text-align: center;
}

/* 排名样式 */
.difficulty-filter {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.difficulty-filter-btn {
    padding: 0.5rem 1rem;
    background-color: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
}

.difficulty-filter-btn:hover {
    border-color: var(--primary-color);
    background-color: #f0f8ff;
}

.difficulty-filter-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.rankings-container {
    background-color: var(--light-color);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.rankings-header {
    display: grid;
    grid-template-columns: 0.5fr 2fr 1.5fr 1fr 1fr;
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 1rem;
    font-weight: 600;
}

.rankings-list {
    max-height: 300px;
    overflow-y: auto;
}

.ranking-row {
    display: grid;
    grid-template-columns: 0.5fr 2fr 1.5fr 1fr 1fr;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.ranking-row:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

.ranking-row:hover {
    background-color: rgba(74, 111, 165, 0.05);
}

.rank-col {
    font-weight: 700;
    color: var(--primary-color);
}

.name-col {
    font-weight: 500;
}

.name-col.current-user {
    color: var(--primary-color);
    font-weight: 700;
}

.time-col {
    font-family: monospace;
    font-weight: 600;
}

.errors-col {
    text-align: center;
    font-weight: 600;
}

.games-col {
    text-align: center;
    font-weight: 600;
    color: var(--info-color);
}

.loading-rankings,
.no-rankings,
.error-rankings {
    padding: 2rem;
    text-align: center;
    color: var(--secondary-color);
}

.user-rank-info {
    background-color: var(--light-color);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    text-align: center;
    font-weight: 600;
}

.user-rank {
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* 页脚 */
.footer {
    background-color: var(--light-color);
    padding: 1.5rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.footer p {
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

.footer-note {
    font-size: 0.9rem;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.modal.active {
    display: flex;
}

.modal-content {
    background-color: white;
    padding: 2.5rem;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-hover);
    animation: modalFadeIn 0.3s ease;
}

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

.modal-content h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.modal-stats {
    background-color: var(--light-color);
    padding: 1.5rem;
    border-radius: 12px;
    margin: 1.5rem 0;
    text-align: left;
}

.modal-stats p {
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .game-container {
        flex-direction: column;
    }
    
    .game-controls {
        min-width: auto;
    }
    
    .sudoku-grid {
        width: min(85vw, 500px);
        height: min(85vw, 500px);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
        margin: 10px;
        min-height: auto;
    }
    
    .header {
        padding: 1.5rem;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .game-container {
        padding: 1.5rem;
    }
    
    .sudoku-grid {
        width: min(90vw, 400px);
        height: min(90vw, 400px);
    }
    
    .sudoku-cell {
        font-size: 1.2rem;
    }
    
    .game-info {
        grid-template-columns: 1fr;
    }
    
    .button-group {
        grid-template-columns: 1fr;
    }
    
    .difficulty-buttons {
        flex-direction: column;
    }
    
    .number-pad {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.75rem;
    }
    
    .game-container {
        padding: 1rem;
        gap: 1rem;
    }
    
    .sudoku-grid {
        width: min(95vw, 350px);
        height: min(95vw, 350px);
    }
    
    .sudoku-cell {
        font-size: 1rem;
    }
    
    .control-section {
        padding: 1rem;
    }
    
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    
    .modal-content {
        padding: 1.5rem;
    }
}

/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

/* 工具提示 */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: var(--dark-color);
    color: white;
    text-align: center;
    padding: 5px;
    border-radius: 6px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.9rem;
    font-weight: normal;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}
