* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Arial', 'Microsoft YaHei', sans-serif;
    background-color: #E8DCC4;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #D4C4A8;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
    align-self: stretch;
}

.back-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #333;
    padding: 5px 10px;
}

.title {
    font-size: 20px;
    font-weight: bold;
    color: #333;
}

.placeholder {
    width: 44px;
}

.level-select-container {
    width: 100%;
    max-width: 500px;
    padding: 20px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 20px;
}

.level-card {
    aspect-ratio: 1;
    background-color: #D4C4A8;
    border: 2px solid #333;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.level-card:hover {
    background-color: #C4B498;
    transform: translateY(-2px);
}

.level-card.locked {
    background-color: #B8A888;
    cursor: not-allowed;
    opacity: 0.7;
}

.level-card.locked::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 16px;
    background: #666;
    border-radius: 3px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -30%);
}

.level-card.locked::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 10px;
    border: 2px solid #666;
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    top: calc(50% - 14px);
    left: 50%;
    transform: translateX(-50%);
}

.level-card.completed {
    border-color: #4CAF50;
}

.level-card.completed .level-status {
    display: block;
}

.level-status {
    display: none;
    position: absolute;
    bottom: 8px;
    font-size: 10px;
    color: #4CAF50;
}

.level-card.not-developed {
    background-color: #C8C8C8;
    cursor: default;
}

.level-card.not-developed:hover {
    transform: none;
}

.level-time {
    position: absolute;
    top: 8px;
    font-size: 10px;
    color: #666;
}

.level-number {
    font-size: 14px;
    font-weight: bold;
    color: #333;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    padding: 10px 0;
}

.page-btn {
    padding: 8px 18px;
    background-color: #D4C4A8;
    border: 2px solid #333;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
}

.page-btn:hover {
    background-color: #C4B498;
    transform: translateY(-2px);
}

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

.page-info {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    min-width: 50px;
    text-align: center;
}

.level-card.locked .level-number {
    opacity: 0;
}

.timer {
    font-size: 14px;
    color: #333;
    font-weight: bold;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.error-count {
    font-size: 12px;
    color: #CC0000;
    font-weight: bold;
}

.modal-time {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

.modal-record {
    font-size: 14px;
    color: #4CAF50;
    font-weight: bold;
    margin-bottom: 15px;
}

.game-container {
    width: 100%;
    max-width: 500px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
}

.level-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 15px;
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: min(90vw, 450px, calc(100vh - 280px));
    height: min(90vw, 450px, calc(100vh - 280px));
    border: 3px solid #000;
    background-color: #F5F5DC;
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(16px, 5vw, 28px);
    font-weight: normal;
    color: #1a1a1a;
    border: 1px solid #000;
    cursor: pointer;
    position: relative;
    background-color: #F5F5DC;
    transition: background-color 0.1s;
}

.cell:nth-child(3n) {
    border-right: 2px solid #000;
}

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

.cell:nth-child(-n+9) {
    border-top: none;
}

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

.cell:nth-child(n+73) {
    border-bottom: none;
}

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

.cell.fixed {
    font-weight: bold;
    color: #000;
}

.cell.selected {
    background-color: #D4C4A8;
}

.cell.highlight-row,
.cell.highlight-col,
.cell.highlight-box {
    background-color: #E8DCC4;
}

.cell.highlight-same {
    background-color: #D0C0A0;
}

.cell.selected.highlight-row,
.cell.selected.highlight-col,
.cell.selected.highlight-box,
.cell.selected.highlight-same {
    background-color: #C4B498;
}

.cell.error {
    color: #CC0000;
}

.cell.highlight {
    background-color: #E8DCC4;
}

.notes-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    padding: 1px;
}

.note {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(10px, 2.5vw, 14px);
    color: #666;
    font-weight: normal;
}

.controls {
    width: 100%;
    margin-top: 20px;
}

.control-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.control-btn {
    padding: 10px 15px;
    font-size: 16px;
    border: 2px solid #333;
    border-radius: 8px;
    background-color: #D4C4A8;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background-color: #C4B498;
}

.control-btn.active {
    background-color: #333;
    color: #fff;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 10px;
    background-color: #D4C4A8;
    border-radius: 10px;
}

.num-btn {
    aspect-ratio: 1;
    font-size: clamp(24px, 6vw, 32px);
    font-weight: bold;
    border: 2px solid #333;
    border-radius: 8px;
    background-color: #F5F5DC;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
}

.num-btn:hover {
    background-color: #E8DCC4;
}

.num-btn:active {
    background-color: #C4B498;
}

.num-btn.hidden {
    visibility: hidden;
    pointer-events: none;
}

.num-btn:nth-child(10) {
    grid-column: span 1;
}

@media (max-width: 400px) {
    .level-grid {
        gap: 8px;
    }
    
    .level-number {
        font-size: 16px;
    }
    
    .control-btn {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .number-pad {
        gap: 5px;
        padding: 8px;
    }
}

@media (min-width: 500px) {
    .sudoku-board {
        width: min(450px, calc(100vh - 280px));
        height: min(450px, calc(100vh - 280px));
    }
}

@media (min-width: 768px) {
    .header {
        padding: 15px 30px;
    }

    .back-btn {
        font-size: 28px;
    }

    .title {
        font-size: 24px;
    }

    .level-select-container {
        max-width: 800px;
        padding: 30px;
    }

    .level-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 14px;
    }

    .level-number {
        font-size: 16px;
    }

    .level-status {
        font-size: 12px;
    }

    .level-time {
        font-size: 12px;
    }

    .game-container {
        max-width: 700px;
        padding: 25px;
    }

    .sudoku-board {
        width: min(60vw, 480px, calc(100vh - 260px));
        height: min(60vw, 480px, calc(100vh - 260px));
    }

    .cell {
        font-size: clamp(18px, 2.5vw, 28px);
    }

    .note {
        font-size: clamp(11px, 1.2vw, 14px);
    }

    .control-btn {
        padding: 10px 20px;
        font-size: 16px;
    }

    .number-pad {
        max-width: 480px;
        margin: 0 auto;
        gap: 8px;
        padding: 12px;
    }

    .num-btn {
        font-size: clamp(24px, 2.5vw, 30px);
        aspect-ratio: auto;
        padding: 8px 0;
    }
}

@media (min-width: 1200px) {
    .level-select-container {
        max-width: 1000px;
    }

    .level-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 16px;
    }

    .game-container {
        max-width: 700px;
    }

    .sudoku-board {
        width: min(50vw, 500px, calc(100vh - 260px));
        height: min(50vw, 500px, calc(100vh - 260px));
    }

    .number-pad {
        max-width: 500px;
    }
}

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

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: #F5F5DC;
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    border: 3px solid #333;
    max-width: 320px;
    width: 90%;
}

.modal-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.modal-title {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
}

.modal-message {
    font-size: 16px;
    color: #666;
    margin-bottom: 25px;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.modal-btn {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    border: 2px solid #333;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn.primary {
    background-color: #333;
    color: #fff;
}

.modal-btn.primary:hover {
    background-color: #555;
}

.modal-btn.secondary {
    background-color: #D4C4A8;
    color: #333;
}

.modal-btn.secondary:hover {
    background-color: #C4B498;
}

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

.modal-content.gameover .modal-icon {
    font-size: 48px;
}

.modal-content.gameover .modal-message {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
}
