/* 全局样式 */
:root {
    /* Layout */
    --cell-size: min(9vw, 9vh);

    /* Colors - Light Theme */
    --bg-primary: #f0f2f5;
    --text-primary: #1a202c;
    --text-secondary: #2c3e50;
    --theme-toggle-color: #ffa500;
    --primary-color: #4299e1;
    --primary-dark: #3182ce;
    --primary-light: #63b3ed;
    --primary-shadow: rgba(99, 179, 237, 0.2);
    --error-color: #f56565;
    --error-light: rgba(231, 76, 60, 0.1);
    --cell-bg: #fff;
    --cell-bg-hover: #f8f9fa;
    --cell-bg-selected: #ebf5fb;
    --cell-bg-fixed: #f8f9f9;
    --cell-bg-related: #e6f2ff;
    --cell-border: #bdc3c7;
    --cell-border-dark: #34495e;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --shadow-color-hover: rgba(0, 0, 0, 0.15);
    --delete-color: #e74c3c;
    --delete-bg: rgba(231, 76, 60, 0.1);
    --number-filled: #3182ce;
    --text-light: #ffffff;
    --gradient-light: rgba(255, 255, 255, 0.1);
    --gradient-dark: rgba(255, 255, 255, 0);
    --timer-bg: #e6f2ff;
    --timer-border: #c5d9f1;
}

/* 深色主题 */
[data-theme="dark"] {
    /* Colors - Dark Theme */
    --bg-primary: #1a202c;
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --theme-toggle-color: #f1c40f;
    --primary-color: #4299e1;
    --primary-dark: #3182ce;
    --primary-light: #63b3ed;
    --primary-shadow: rgba(99, 179, 237, 0.3);
    --error-color: #fc8181;
    --error-light: rgba(245, 101, 101, 0.2);
    --cell-bg: #2d3748;
    --cell-bg-hover: #3a4a63;
    --cell-bg-selected: #4299e1;
    --cell-bg-fixed: #2d3748;
    --cell-bg-related: #2c3e50;
    --cell-border: #4a5568;
    --cell-border-dark: #2d3748;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --shadow-color-hover: rgba(0, 0, 0, 0.4);
    --delete-color: #fc8181;
    --delete-bg: rgba(245, 101, 101, 0.2);
    --number-filled: #63b3ed;
    --text-light: #ffffff;
    --gradient-light: rgba(255, 255, 255, 0.05);
    --gradient-dark: rgba(255, 255, 255, 0);
    --timer-bg: #2d3748;
    --timer-border: #4a5568;
}

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

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease;
}

/* 控制按钮共用样式 */
.control-button {
    position: fixed;
    top: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--cell-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 2px 5px var(--shadow-color);
    transition: all 0.3s ease;
    z-index: 1000;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.control-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color-hover);
}

.control-button i {
    font-size: 0.9rem;
}

/* 返回按钮 */
#back-button {
    left: 20px;
    color: var(--primary-color);
}

/* 主题切换按钮 */
#theme-button {
    right: 20px;
    color: var(--theme-toggle-color);
}

/* 手机端样式 */
@media screen and (max-width: 768px) {
    #back-button i, #theme-button i {
        font-size: 1rem;
    }
}

/* 主容器样式 */
.container {
    width: 100%;
    max-width: min(95vw, 800px);
    margin: 0 auto;
    padding: 5px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 100vh;
    box-sizing: border-box;
}

/* 标题和计时器容器 */
.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: min(10px, 3vh);
    width: min(80vw, 80vh, 500px);
    margin-left: auto;
    margin-right: auto;
}

h1 {
    height: 100%;
    display: flex;
    color: var(--text-primary);
    font-size: clamp(1.6rem, 5vw, 2.6rem);
    margin-left: 16px;
    text-shadow: 1px 1px 2px var(--shadow-color);
    line-height: 1.2;
    align-items: center;
    
}

/* 计时器容器样式 */
.timer-wrapper {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-right: 16px;
}

.timer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: linear-gradient(to bottom, var(--timer-bg), var(--timer-bg));
    border: 1px solid var(--timer-border);
    border-radius: 6px;
    padding: 6px 16px;
    box-shadow: 0 2px 4px var(--shadow-color);
    transition: all 0.3s ease;
}

.timer-container:hover {
    box-shadow: 0 4px 8px var(--shadow-color);
    transform: translateY(-1px);
}

/* 计时器标签样式 */
.timer-label {
    color: var(--text-primary);
    font-size: clamp(0.8rem, 2vw, 1rem);
    margin-bottom: 2px;
    text-shadow: 0 1px 1px var(--shadow-color);
    font-weight: 500;
}

/* 计时器样式 */
.timer {
    color: var(--primary-color);
    font-size: clamp(1.0rem, 3vw, 1.4rem);
    margin-bottom: 0;
    font-family: 'Courier New', monospace;
    text-shadow: 0 1px 1px var(--shadow-color);
    transition: all 0.3s ease;
    font-weight: bold;
}

/* 棋盘和控件容器 */
.game-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: min(20px, 3vh);
}

/* 游戏控制区域 */
.game-controls {
    width: min(80vw, 80vh, 500px);
    margin: min(2px, 3vh) auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: min(10px, 1.5vw);
    padding: min(5px, 1.5vw);
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.game-controls::-webkit-scrollbar {
    display: none;
}

/* 确保所有控件在一行显示 */
.game-controls > * {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
}

/* 应用共享样式 */
.minimal-button, .minimal-select {
    /* 继承minimal-control的样式 */
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    background-color: var(--cell-bg);
    border: 1px solid var(--cell-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 45px;
    width: 100%; /* 确保元素占据分配的全部宽度 */
}

/* 简约按钮样式 */
.minimal-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    white-space: nowrap;
}

.minimal-button i {
    font-size: 14px;
    opacity: 0.8;
}

.minimal-button:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--text-light);
    transform: translateY(-1px);
}

.minimal-button:active {
    transform: translateY(0);
}

/* 简约下拉菜单样式 */
.minimal-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 8px 32px 8px 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
}

.minimal-select:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.minimal-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-shadow);
}

/* 响应式调整 */
@media (max-width: 480px) {
    .minimal-button, .minimal-select {
        padding: 6px 12px;
        font-size: 13px;
        min-height: 36px;
    }

    .minimal-select {
        padding: 6px 28px 6px 12px;
        font-size: 13px;
        min-height: 36px;
    }

    .minimal-button i {
        font-size: 13px;
    }
}

/* 数独棋盘 */
.board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    background-color: var(--cell-border-dark);
    border: 2px solid var(--cell-border);
    width: min(80vw, 80vh, 500px);
    margin: 0 auto min(15px, 2vh);
    aspect-ratio: 1;
    padding: 4px;
    border-radius: 6px;
    box-shadow: 0 4px 15px var(--shadow-color);
    box-sizing: border-box;
    overflow: hidden;
}

/* 单元格样式 */
.cell {
    min-height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background-color: var(--cell-bg);
    font-size: clamp(16px, min(4vw, 4vh), 32px);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    aspect-ratio: 1;
}

.cell:hover:not(.fixed) {
    background-color: var(--cell-bg-hover);
    transition: all 0.2s ease;
}

/* 数字显示样式 */
.number-display {
    font-size: inherit;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.2s ease;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 删除按钮样式 */
.delete-button {
    position: absolute;
    top: calc(var(--cell-size) * 0.05);
    right: calc(var(--cell-size) * 0.05);
    width: calc(var(--cell-size) * 0.2);
    height: calc(var(--cell-size) * 0.2);
    font-size: calc(var(--cell-size) * 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--delete-color);
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    border-radius: 50%;
    background-color: var(--delete-bg);
    transform: scale(0.8);
    pointer-events: auto;
}

/* 只在鼠标悬停时显示删除按钮 */
.cell:hover .delete-button {
    opacity: 1;
    transform: scale(1);
}

/* 删除按钮悬停效果 */
.delete-button:hover {
    background-color: var(--delete-color);
    color: var(--text-light);
    transform: scale(1.1);
}

/* 3x3宫格边框 */
.cell:nth-child(9n+1),
.cell:nth-child(9n+2),
.cell:nth-child(9n+3),
.cell:nth-child(9n+4),
.cell:nth-child(9n+5),
.cell:nth-child(9n+6),
.cell:nth-child(9n+7),
.cell:nth-child(9n+8),
.cell:nth-child(9n+9) {
    border-right: 1px solid var(--cell-border);
}

.cell:nth-child(9n+1) {
    border-left: 1px solid var(--cell-border);
}

.cell:nth-child(9n+3),
.cell:nth-child(9n+6) {
    border-right: 3px solid var(--cell-border);
}

.cell:nth-child(-n+81) {
    border-bottom: 1px solid var(--cell-border);
}

.cell:nth-child(n+1):nth-child(-n+9) {
    border-top: 1px solid var(--cell-border);
}

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

/* 单元格状态 */
.cell.selected {
    background-color: var(--cell-bg-selected);
    box-shadow: inset 0 0 0 2px var(--primary-color);
    animation: select-pulse 2s infinite;
    transition: all 0.3s ease;
}

.cell.selected .number-display {
    color: var(--text-primary);
    text-shadow: 0 1px 3px var(--shadow-color);
    transform: translate(-50%, -50%) scale(1.05);
}

/* 默认数字样式（初始数字） */
.cell.fixed .number-display {
    color: var(--text-secondary);
    text-shadow: 0 1px 2px var(--shadow-color);
    font-weight: 700;
}

.cell.fixed {
    background-color: var(--cell-bg-fixed);
    cursor: not-allowed;
}

/* 玩家填写的数字样式 */
.cell.filled .number-display {
    color: var(--number-filled);
    text-shadow: 0 0 2px var(--primary-shadow);
    font-weight: 400;
    animation: number-appear 0.3s ease-out;
}

/* 错误状态 */
.cell.error .number-display {
    color: var(--error-color);
    animation: shake 0.5s;
    text-shadow: 0 0 3px var(--error-light);
}

/* 相关单元格高亮 */
.cell.related {
    background-color: var(--cell-bg-related);
    animation: related-fade 0.3s ease-in;
}

/* 弹出式数字选择器 */
.number-selector {
    position: fixed;
    display: none;
    background: var(--cell-bg);
    border-radius: min(12px, 3vw);
    box-shadow: 0 4px 20px var(--shadow-color);
    border: 1px solid var(--cell-border);
    padding: min(8px, 2vw);
    z-index: 1000;
    animation: popup 0.2s ease-out;
    max-width: 90vw;
    margin: auto;
}

.number-selector.active {
    display: block;
}

.number-selector-grid {
    display: grid;
    grid-template-columns: repeat(3, var(--cell-size));
    gap: 1px;
    justify-content: center;
}

/* 数字选择器-数字样式*/
.number-selector .number {
    width: var(--cell-size);
    height: var(--cell-size);
    font-size: calc(var(--cell-size) * 0.35);
    border: none;
    border-radius: 8px;
    background-color: var(--cell-bg-hover);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.number-selector .number:hover {
    background-color: var(--primary-color);
    color: var(--text-light);
    transform: scale(1.05);
}

/* 数字选择器-清除按钮样式 */
.number-selector .number-clear-btn {
    width: calc(var(--cell-size) * 3);
    height: var(--cell-size);
    font-size: calc(var(--cell-size) * 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--cell-bg-hover);
    color: var(--delete-color);
    border: none;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.number-selector .number-clear-btn:hover {
    background-color: var(--delete-color);
    color: var(--text-light);
    transform: scale(1.02);
}

@keyframes popup {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 动画效果 */
@keyframes shake {
    0%, 100% { transform: translate(-50%, -50%); }
    25% { transform: translate(-53%, -50%); }
    75% { transform: translate(-47%, -50%); }
}

@keyframes select-pulse {
    0%, 100% { 
        box-shadow: inset 0 0 0 2px var(--primary-color);
        transform: scale(1);
    }
    50% { 
        box-shadow: inset 0 0 0 2px var(--primary-dark);
        transform: scale(1.02);
    }
}

@keyframes number-appear {
    0% { 
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1);
    }
    100% { 
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes related-fade {
    0% { 
        background-color: var(--cell-bg-selected);
        transform: scale(1.02);
    }
    100% { 
        background-color: var(--cell-bg-related);
        transform: scale(1);
    }
}

/* 响应式设计 */
/* 平板和中等屏幕 */
@media (max-width: 768px) {
    h1 {
        font-size: clamp(30px, 6vw, 36px);
    }

    .container {
        gap: min(20px, 3vh);
        padding: min(8px, 3vw);
    }

    .game-container {
        padding: 0 min(10px, 2vw);
    }

    .game-controls {
        width: 100%; 
    }
    
    .board {
        padding: 2px;
        border-width: 2px;
    }
    
    .cell {
        min-height: 28px;
        font-size: clamp(16px, 4.5vw, 20px);
    }

    .number-selector {
        padding: min(6px, 1.5vw);
    }
}

/* 手机端 */
@media (max-width: 480px) {
    .game-container {
        padding: 0 min(5px, 2vw);
    }
    
    .board {
        gap: 0.5px;
        border-width: 1px;
        border-radius: 4px;
        max-width: none;
        width: 100%;
        margin: 0 auto;
    }
    
    .game-controls {
        width: 100%;
        max-width: none;
        margin: min(2px, 3vh) auto;
    }
    
    .cell {
        min-height: 26px;
        font-size: clamp(18px, 5.5vw, 22px);
    }
    
    /* 在小屏幕上始终显示删除按钮 */
    .delete-button {
        opacity: 1;
        transform: scale(1);
    }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
    .cell {
        font-size: clamp(14px, 4.5vw, 18px);
    }
    
    .game-controls button,
    .game-controls select {
        font-size: clamp(10px, 3vw, 14px);
    }
}