/* ============================================================
   lib/sudoku-style.css — 数独闯关模块原生样式
   作用域限定 #sudokuPage，不影响好学伴其他页面
   keyframes 已重命名（sudoku-* 前缀）避免与好学伴动画冲突
   ============================================================ */

@keyframes sudoku-confetti-fall {
    0% { transform: translateY(-100px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes sudoku-bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-20px); }
    60% { transform: translateY(-10px); }
}
@keyframes sudoku-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}
@keyframes sudoku-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* 容器本身：建立定位上下文 */
#sudokuPage { position: relative; }

#sudokuPage .cell-border { border: 1px solid #D1D5DB; }
#sudokuPage .cell-highlight { background-color: #DBEAFE; transition: background-color 0.2s; }
#sudokuPage .cell-selected { background-color: #BFDBFE; transition: background-color 0.2s; }
#sudokuPage .cell-error { background-color: #FECACA; transition: background-color 0.2s; }
#sudokuPage .cell-conflict { color: #EF4444 !important; animation: sudoku-pulse 0.5s ease-in-out; }
#sudokuPage .btn-hover { transition: all 0.2s; }
#sudokuPage .btn-hover:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); }
#sudokuPage .grid-line { border-bottom: 2px solid #4B5563; border-right: 2px solid #4B5563; }

/* 3×3 宫分隔线加粗 —— 提升特异性(#id + 2类 = 1,2,0)覆盖 .cell-border 的 border 简写(1,1,0)
   JS 在宫边界单元格上添加 border-b-2 / border-r-2 类，此处确保它们以 3px 深色渲染 */
#sudokuPage .sudoku-cell.border-b-2 {
    border-bottom-width: 3px;
    border-bottom-color: #1f2937;
}
#sudokuPage .sudoku-cell.border-r-2 {
    border-right-width: 3px;
    border-right-color: #1f2937;
}

#sudokuPage #sudoku-grid {
    display: grid;
    border: 3px solid #1f2937; /* 外边框与 3×3 宫分隔线粗细/颜色一致 */
}
#sudokuPage .number-row { display: flex; justify-content: center; gap: 4px; margin-bottom: 4px; }
#sudokuPage .number-pad-container { display: flex; flex-direction: column; align-items: center; }

#sudokuPage .level-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; font-weight: 500;
    transition: all 0.2s;
    background: linear-gradient(145deg, #4D96FF, #6BCB77);
    color: white;
    box-shadow: 0 4px 8px rgba(77, 150, 255, 0.3);
}
#sudokuPage .level-unlocked { cursor: pointer; }
#sudokuPage .level-unlocked:hover { background-color: #2563EB; }
#sudokuPage .level-locked {
    background: linear-gradient(145deg, #e0e0e0, #c0c0c0);
    color: #9CA3AF; cursor: not-allowed; box-shadow: none;
}
#sudokuPage .level-current {
    box-shadow: 0 0 0 4px rgba(255, 217, 61, 0.6);
    border: 2px solid #FFD700; font-weight: 700;
    transform: scale(1.1);
}
#sudokuPage .level-completed { background: linear-gradient(145deg, #FFD93D, #FF9B50); }

#sudokuPage .medal-gold { color: #FFD700; }
#sudokuPage .medal-silver { color: #C0C0C0; }
#sudokuPage .medal-bronze { color: #CD7F32; }

#sudokuPage .confetti {
    position: absolute; width: 10px; height: 10px;
    background-color: #f00; border-radius: 50%;
    animation: sudoku-confetti-fall 3s linear forwards;
}
#sudokuPage .trophy-animation { animation: sudoku-bounce 1.5s ease infinite; }
#sudokuPage .float-animation { animation: sudoku-float 3s ease-in-out infinite; }

#sudokuPage .level-selector { max-height: 0; overflow: hidden; transition: max-height 0.5s ease; }
#sudokuPage .level-selector.open { max-height: 300px; }

#sudokuPage .sudoku-cell {
    width: 45px; height: 45px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; font-weight: 600; position: relative;
    transition: all 0.2s;
}
#sudokuPage .cell-main-number { font-size: 1.5rem; font-weight: 700; z-index: 2; }
#sudokuPage .cell-notes {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    display: grid; padding: 2px; z-index: 1;
}
#sudokuPage .note-number {
    font-size: 0.6rem; display: flex;
    align-items: center; justify-content: center;
    color: #6B7280;
}

#sudokuPage .number-btn-large {
    width: 50px; height: 50px; flex: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 700;
    border-radius: 0.5rem; background-color: #4D96FF;
    color: #fff; transition: all 0.2s;
}
#sudokuPage .number-btn-large:hover { background-color: #3d7bff; transform: translateY(-2px); }

#sudokuPage .clear-btn {
    width: 50px; height: 50px; flex: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: 700;
    border-radius: 0.5rem; background-color: #FF9B50;
    color: #fff; transition: all 0.2s;
}
#sudokuPage .clear-btn:hover { background-color: #e8853a; transform: translateY(-2px); }

#sudokuPage .result-modal,
#sudokuPage .confirm-modal,
#sudokuPage .backup-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 50; opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
}
#sudokuPage .result-modal.visible,
#sudokuPage .confirm-modal.visible,
#sudokuPage .backup-modal.visible {
    opacity: 1; pointer-events: auto;
}
#sudokuPage .result-content,
#sudokuPage .confirm-content,
#sudokuPage .backup-content {
    background-color: white; border-radius: 1rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    padding: 2rem; max-width: 28rem; width: 90%;
    transform: scale(0.95); transition: transform 0.3s;
    position: relative;
}
#sudokuPage .result-modal.visible .result-content,
#sudokuPage .confirm-modal.visible .confirm-content,
#sudokuPage .backup-modal.visible .backup-content {
    transform: scale(1);
}

#sudokuPage .toggle-switch {
    position: relative; display: inline-block;
    width: 50px; height: 24px;
}
#sudokuPage .toggle-switch input { opacity: 0; width: 0; height: 0; }
#sudokuPage .slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s;
    border-radius: 24px;
}
#sudokuPage .slider:before {
    position: absolute; content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white; transition: .4s;
    border-radius: 50%;
}
#sudokuPage input:checked + .slider { background-color: #3B82F6; }
#sudokuPage input:checked + .slider:before { transform: translateX(26px); }

#sudokuPage .note-mode-active {
    background-color: #6B46C1 !important; color: white !important;
    box-shadow: 0 0 0 3px rgba(107, 70, 193, 0.5);
    border: 2px solid white;
}

#sudokuPage .highlight-unique {
    background-color: #10B981 !important; color: white !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}
#sudokuPage .hidden-number { opacity: 0.3; pointer-events: none; }
#sudokuPage .highlight-same { background-color: rgba(16, 185, 129, 0.3) !important; }

#sudokuPage .close-btn {
    position: absolute; top: 12px; right: 12px;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; background-color: #F3F4F6;
    color: #4B5563; cursor: pointer;
    transition: all 0.2s; z-index: 10;
}
#sudokuPage .close-btn:hover { background-color: #E5E7EB; transform: rotate(90deg); }

#sudokuPage .difficulty-tabs {
    display: flex; flex-wrap: nowrap; justify-content: center;
    gap: 8px; margin-bottom: 25px; padding: 0 10px;
    overflow: hidden;
}
#sudokuPage .difficulty-tab {
    flex: 1; min-width: 80px; max-width: 100px;
    padding: 8px 5px; text-align: center;
    border-radius: 12px; font-weight: 600; font-size: 0.9rem;
    cursor: pointer; transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    border: 2px solid #e0e0e0;
    height: 55px; display: flex; flex-direction: column;
    justify-content: center; align-items: center;
}
#sudokuPage .difficulty-tab .tab-line { display: block; line-height: 1.1; }
#sudokuPage .difficulty-tab.active {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    border-color: transparent; color: white;
}
#sudokuPage .difficulty-tab:nth-child(1).active { background: linear-gradient(145deg, #6BCB77, #4D96FF); }
#sudokuPage .difficulty-tab:nth-child(2).active { background: linear-gradient(145deg, #FFD93D, #FF9B50); }
#sudokuPage .difficulty-tab:nth-child(3).active { background: linear-gradient(145deg, #FF9B50, #FF6B6B); }
#sudokuPage .difficulty-tab:nth-child(4).active { background: linear-gradient(145deg, #9C51E0, #6A67CE); }
#sudokuPage .difficulty-tab:hover:not(.active) { transform: translateY(-2px); box-shadow: 0 5px 10px rgba(0, 0, 0, 0.12); }

#sudokuPage .card {
    border-radius: 20px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    overflow: hidden; background: white;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
#sudokuPage .card:hover { transform: translateY(-5px); box-shadow: 0 15px 30px rgba(0, 0, 0, 0.12); }

#sudokuPage .fun-header {
    position: relative; text-align: center;
    padding: 20px 0; margin-bottom: 20px;
}
#sudokuPage .fun-header h1 {
    font-size: 2.5rem; font-weight: 800;
    background: linear-gradient(135deg, #4D96FF, #9C51E0);
    -webkit-background-clip: text; background-clip: text;
    color: transparent; margin: 0;
    letter-spacing: -0.5px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}
#sudokuPage .fun-header p {
    font-size: 1.1rem; color: #6c757d;
    max-width: 500px; margin: 10px auto 0;
    line-height: 1.4;
}

#sudokuPage #start-game {
    background: linear-gradient(135deg, #6BCB77, #4D96FF);
    color: white; border: none; border-radius: 50px;
    font-weight: 700; padding: 12px 40px; font-size: 1.1rem;
    box-shadow: 0 6px 12px rgba(107, 203, 119, 0.4);
    transition: all 0.3s ease;
}
#sudokuPage #start-game:hover {
    background: linear-gradient(135deg, #5ab666, #3d7bff);
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(107, 203, 119, 0.5);
}

#sudokuPage .game-title {
    display: flex; align-items: center; flex-wrap: wrap;
    justify-content: center; gap: 12px;
    margin-bottom: 15px;
    padding: 8px 0;
}
#sudokuPage .game-title h2 { font-size: 1rem; margin: 0; }
#sudokuPage .game-title span {
    background: linear-gradient(135deg, #4D96FF, #9C51E0);
    padding: 3px 8px; border-radius: 30px;
    color: white; font-weight: 600; font-size: 0.8rem;
    white-space: nowrap;
}

#sudokuPage .decoration { position: absolute; z-index: 0; opacity: 0.2; }
#sudokuPage .decoration-1 { top: 10%; left: 5%; width: 80px; height: 80px; border-radius: 50%; background: linear-gradient(145deg, #6BCB77, #4D96FF); }
#sudokuPage .decoration-2 { bottom: 15%; right: 5%; width: 60px; height: 60px; border-radius: 20px; background: linear-gradient(145deg, #FFD93D, #FF9B50); transform: rotate(45deg); }
#sudokuPage .decoration-3 { top: 20%; right: 10%; width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(145deg, #9C51E0, #6A67CE); }

#sudokuPage .content-container { position: relative; z-index: 1; }

/* 子页面：position:relative 让 .back-btn/.settings-icon 相对子页面定位，避开 stats-header */
#sudokuPage .page { display: none; position: relative; min-height: calc(100vh - 70px); }
#sudokuPage .page.active { display: block; }

#sudokuPage .settings-icon {
    position: absolute; top: 20px; right: 20px;
    font-size: 1.5rem; cursor: pointer; z-index: 10001;
    pointer-events: auto;
}
/* 仅作用于子页面内的返回按钮；stats-header 里的"返回首页"按钮走全局 .back-btn + flex 布局，自动靠右 */
#sudokuPage .page .back-btn {
    position: absolute; top: 20px; left: 20px;
    font-size: 1.5rem; cursor: pointer; z-index: 10001;
    pointer-events: auto;
}
/* 防御性保障：stats-header 里的"返回首页"按钮始终靠右，避免与标题重叠 */
#sudokuPage .stats-header {
    display: flex; justify-content: space-between; align-items: center;
}
#sudokuPage .stats-header .back-btn {
    position: static; margin-left: auto;
}

#sudokuPage #start-page { background: linear-gradient(135deg, #f0f9ff 0%, #c2e9fb 100%); }
#sudokuPage #settings-page { background: linear-gradient(135deg, #e0f7fa 0%, #bbdefb 100%); }

#sudokuPage .level-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 15px; max-width: 500px; margin: 0 auto;
    padding: 20px; max-height: 450px; overflow-y: auto;
}

#sudokuPage .game-header,
#sudokuPage .game-controls {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 10px 15px; max-width: 500px; margin: 0 auto;
}

#sudokuPage .timer-group {
    display: flex; gap: 8px; align-items: center;
    flex-wrap: nowrap; justify-content: center;
    width: 100%;
}
#sudokuPage .timer-display,
#sudokuPage .best-time-display {
    font-weight: bold; background: white;
    padding: 8px 15px; border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    font-variant-numeric: tabular-nums; /* 数字等宽，防止时间跳动导致宽度变化 */
    white-space: nowrap;
    display: flex; align-items: center; justify-content: center;
}
#sudokuPage .timer-display {
    font-size: 1.2rem;
    min-width: 112px; /* 固定最小宽度，容纳 "00:00" + 图标，防止宽度跳动 */
}
#sudokuPage .best-time-display {
    font-size: 1rem;
    min-width: 96px;
}
#sudokuPage #check {
    white-space: nowrap; flex: none; /* 检查按钮不收缩，保持横向 */
}

#sudokuPage .action-buttons {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 8px; max-width: 500px; margin: 0 auto;
    padding: 10px 0;
}
#sudokuPage .action-btn {
    width: auto; height: auto; display: block;
    padding: 10px 0; font-size: 0.9rem; text-align: center;
    border: none; border-radius: 8px; cursor: pointer;
    color: #fff; font-weight: 600; transition: all 0.2s;
}
#sudokuPage .action-btn:hover { transform: translateY(-2px); }
#sudokuPage .action-btn:disabled { cursor: not-allowed; opacity: 0.7; transform: none; }

#sudokuPage .result-stats { display: flex; justify-content: space-around; margin-bottom: 2rem; }
#sudokuPage .stat-item { text-align: center; }
#sudokuPage .stat-value { font-size: 2rem; font-weight: 700; display: block; margin-bottom: 0.25rem; }
#sudokuPage .stat-label { font-size: 0.875rem; color: #6B7280; }
#sudokuPage .correct-stat .stat-value { color: #10B981; }
#sudokuPage .error-stat .stat-value { color: #EF4444; }
#sudokuPage .empty-stat .stat-value { color: #6B7280; }

#sudokuPage .backup-buttons { display: flex; flex-direction: row; gap: 12px; margin-bottom: 25px; }
#sudokuPage .backup-btn {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; padding: 12px 20px; border-radius: 12px;
    font-weight: 600; cursor: pointer; transition: all 0.3s;
    text-align: center; flex: 1;
}
#sudokuPage .backup-btn i { font-size: 1.2rem; }
#sudokuPage .backup-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
#sudokuPage #backup-btn { background: linear-gradient(145deg, #4D96FF, #6BCB77); color: white; }
#sudokuPage #restore-btn { background: linear-gradient(145deg, #FFD93D, #FF9B50); color: white; }

#sudokuPage .backup-message { text-align: center; margin-bottom: 20px; font-size: 1.1rem; line-height: 1.4; }
#sudokuPage .backup-success { color: #10B981; }
#sudokuPage .backup-error { color: #EF4444; }
#sudokuPage .backup-info {
    background-color: #F3F4F6; border-radius: 8px;
    padding: 15px; margin: 15px 0;
    font-size: 0.9rem; color: #4B5563; line-height: 1.4;
}

#sudokuPage #file-input { display: none; }
#sudokuPage .timer-hidden { display: none; }

#sudokuPage .grid-type-tabs {
    display: flex; justify-content: center; gap: 10px;
    margin-bottom: 20px; flex-wrap: wrap;
}
#sudokuPage .grid-type-tab {
    padding: 8px 20px; border-radius: 20px;
    font-weight: 600; cursor: pointer;
    transition: all 0.3s; border: 2px solid transparent;
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
#sudokuPage .grid-type-tab.active {
    background: linear-gradient(145deg, #4D96FF, #9C51E0);
    color: white; box-shadow: 0 4px 8px rgba(77, 150, 255, 0.4);
    transform: translateY(-2px);
}
#sudokuPage .grid-type-tab:hover:not(.active) { transform: translateY(-1px); }

@media (min-width: 768px) {
    #sudokuPage .fun-header h1 { font-size: 3.5rem; }
    #sudokuPage .fun-header p { font-size: 1.3rem; }
    #sudokuPage .difficulty-tab { min-width: 100px; height: 65px; font-size: 1.1rem; }
    #sudokuPage .level-btn { width: 50px; height: 50px; font-size: 1.3rem; }
    #sudokuPage #start-game { padding: 15px 50px; font-size: 1.4rem; }
    #sudokuPage .game-title { justify-content: center; font-size: 1.5rem; margin-bottom: 0.5rem; }
    #sudokuPage .game-title h2 { font-size: 2rem; }
    #sudokuPage .game-title span { font-size: 1.2rem; }
    #sudokuPage .game-controls { justify-content: center; margin-bottom: 0.5rem; }
    #sudokuPage .timer-group { flex: none; justify-content: center; }
}

@media (min-width: 1024px) {
    #sudokuPage .sudoku-cell { width: 54px; height: 54px; }
    #sudokuPage .cell-main-number { font-size: 2rem; }
}

@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation: portrait) {
    #sudokuPage .fun-header h1 { font-size: 4rem; }
    #sudokuPage .fun-header p { font-size: 1.5rem; max-width: 600px; }
    #sudokuPage .difficulty-tab { min-width: 110px; height: 70px; font-size: 1.2rem; }
    #sudokuPage .level-btn { width: 55px; height: 55px; font-size: 1.4rem; }
    #sudokuPage #start-game { padding: 18px 60px; font-size: 1.6rem; margin-top: 30px; }
    #sudokuPage .sudoku-cell { width: 60px; height: 60px; }
    #sudokuPage .cell-main-number { font-size: 2.25rem; }
}

@media (max-width: 768px) {
    #sudokuPage .number-btn-large,
    #sudokuPage .clear-btn { height: 45px; width: 45px; font-size: 1.25rem; }
}

@media (max-width: 480px) {
    #sudokuPage #sudoku-grid {
        width: 100%; /* 手机端撑满容器，让 grid-template-columns: 1fr 自动计算宽度 */
    }
    #sudokuPage .sudoku-cell {
        aspect-ratio: 1; /* 保持正方形，让 grid-template-columns: 1fr 自动计算宽度 */
        width: auto;
        height: auto;
        max-width: none;
        max-height: none;
        min-width: 0;
        min-height: 0;
    }
    #sudokuPage .cell-main-number { font-size: 1.1rem; }
    #sudokuPage .number-btn-large,
    #sudokuPage .clear-btn { height: 40px; width: 40px; font-size: 0.875rem; }
    #sudokuPage .action-btn { font-size: 0.8rem; padding: 8px 0; }
    #sudokuPage .page .back-btn,
    #sudokuPage .settings-icon { top: 15px; font-size: 1.3rem; }
    #sudokuPage .page .back-btn { left: 15px; }
    #sudokuPage .settings-icon { right: 15px; }
    #sudokuPage .game-controls { flex-direction: row; justify-content: center; padding: 0 5px 10px; }
    #sudokuPage .timer-group { width: auto; justify-content: center; gap: 6px; }
    #sudokuPage .timer-display { font-size: 1rem; min-width: 92px; padding: 6px 10px; }
    #sudokuPage .best-time-display { font-size: 0.85rem; min-width: 80px; padding: 6px 10px; }
    #sudokuPage .game-title { flex-direction: row; align-items: center; gap: 4px; }
    #sudokuPage .game-title h2 { font-size: 0.9rem; margin-right: 4px; }
    #sudokuPage .game-title span { font-size: 0.7rem; padding: 2px 6px; }
    #sudokuPage .content-container { padding-left: 8px; padding-right: 8px; }
    #sudokuPage .card { padding: 10px 6px; }
}
