* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    font-family: 'Arial', 'Microsoft YaHei', sans-serif;
    padding: 10px;
    user-select: none;
}
.game-wrapper {
    background: linear-gradient(145deg, #2d3436, #1e272e);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.5), 0 0 40px rgba(0, 150, 255, 0.15);
}
.board-container {
    background: #fff;
    border-radius: 6px;
    padding: 2px;
    display: inline-block;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
}
#sudoku-board {
    border-collapse: collapse;
    margin: 0 auto;
    background: #fff;
}
#sudoku-board td {
    width: 48px;
    height: 48px;
    text-align: center;
    font-size: 22px;
    font-weight: bold;
    border: 1px solid #bbb;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}
#sudoku-board td.border-right { border-right: 2.5px solid #333; }
#sudoku-board td.border-bottom { border-bottom: 2.5px solid #333; }
#sudoku-board td.border-left { border-left: 2.5px solid #333; }
#sudoku-board td.border-top { border-top: 2.5px solid #333; }
#sudoku-board td.given { color: #2d3436; background: #e8e8e8; }
#sudoku-board td.user { color: #0984e3; background: #fff; }
#sudoku-board td.conflict { color: #d63031 !important; }
#sudoku-board td.selected { background: #d5e8ff !important; }
#sudoku-board td:hover:not(.given) { background: #eef4ff; }
#sudoku-board td .pencil-marks {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}
#sudoku-board td .pencil-marks span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #636e72;
    font-weight: normal;
}
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}
.top-bar .left, .top-bar .right { flex: 0 0 auto; min-width: 90px; }
.top-bar .center { flex: 1; display: flex; justify-content: center; }
.timer {
    color: #74b9ff;
    font-size: 20px;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    background: rgba(9, 132, 227, 0.1);
    padding: 4px 14px;
    border-radius: 8px;
    border: 1px solid rgba(9, 132, 227, 0.3);
    display: inline-block;
}
.completed-count {
    color: #00b894;
    font-size: 16px;
    font-weight: bold;
    background: rgba(0, 184, 148, 0.1);
    padding: 4px 14px;
    border-radius: 8px;
    border: 1px solid rgba(0, 184, 148, 0.3);
    text-align: right;
    white-space: nowrap;
}
.num-pad {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0 6px 0;
    max-width: 444px;
}
.num-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}
.num-row .num-btn {
    flex: 1;
    height: 0;
    min-height: 56px;
    padding: 10px 0;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-size: clamp(18px, 4vw, 22px);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    aspect-ratio: 3 / 8;
}
.num-btn:hover {
    background: rgba(9, 132, 227, 0.3);
    border-color: #0984e3;
    transform: translateY(-2px);
}
.num-btn:active { transform: translateY(0); }
.num-btn.active {
    background: #0984e3;
    border-color: #0984e3;
    box-shadow: 0 0 12px rgba(9, 132, 227, 0.5);
}
.num-btn.clear-btn {
    font-size: clamp(16px, 3.5vw, 20px);
    color: #ff7675;
    border-color: rgba(255, 118, 117, 0.3);
}
.num-btn.clear-btn:hover {
    background: rgba(255, 118, 117, 0.2);
    border-color: #ff7675;
}
.num-btn.clear-btn.active {
    background: #ff7675;
    border-color: #ff7675;
    color: #fff;
}
.num-btn.note-btn {
    font-size: clamp(20px, 4.5vw, 24px);
    color: rgba(255,255,255,0.4);
    border-color: rgba(255,255,255,0.15);
}
.num-btn.note-btn:hover { border-color: rgba(253, 203, 110, 0.5); }
.num-btn.note-btn.active {
    background: #fdcb6e;
    border-color: #fdcb6e;
    color: #2d3436;
    box-shadow: 0 0 12px rgba(253, 203, 110, 0.5);
}
.num-btn.mode-btn {
    font-size: clamp(12px, 2.8vw, 15px);
    color: #74b9ff;
    border-color: rgba(116, 185, 255, 0.3);
}
.num-btn.mode-btn:hover {
    background: rgba(116, 185, 255, 0.2);
    border-color: #74b9ff;
}
.num-btn.active-digit {
    background: #00b894 !important;
    border-color: #00b894 !important;
    color: #fff !important;
    box-shadow: 0 0 16px rgba(0, 184, 148, 0.6) !important;
    transform: translateY(-2px);
}
.num-btn.clear-btn.active-digit {
    background: #ff7675 !important;
    border-color: #ff7675 !important;
    box-shadow: 0 0 16px rgba(255, 118, 117, 0.6) !important;
}
.num-btn.mode-btn.active {
    background: #74b9ff;
    border-color: #74b9ff;
    color: #fff;
}
.controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 10px 0;
    max-width: 444px;
}
.controls button {
    padding: 24px 0;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: #fff;
    font-family: inherit;
    width: 100%;
}
.controls button:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn-next { background: linear-gradient(145deg, #0984e3, #0767b0); box-shadow: 0 4px 15px rgba(9,132,227,0.4); }
.btn-level { background: linear-gradient(145deg, #00b894, #00a383); box-shadow: 0 4px 15px rgba(0,184,148,0.4); }
.btn-hint { background: linear-gradient(145deg, #fdcb6e, #e0b055); box-shadow: 0 4px 15px rgba(253,203,110,0.4); color: #2d3436 !important; }
.btn-reset { background: linear-gradient(145deg, #e17055, #d35a40); box-shadow: 0 4px 15px rgba(225,112,85,0.4); }
.btn-home { background: linear-gradient(145deg, #636e72, #4a5357); box-shadow: 0 4px 15px rgba(99,110,114,0.4); }
.btn-rules { background: linear-gradient(145deg, #6c5ce7, #5a4bd1); box-shadow: 0 4px 15px rgba(108,92,231,0.4); }
.difficulty-label {
    color: #74b9ff;
    font-size: 18px;
    font-weight: bold;
    background: rgba(116, 185, 255, 0.1);
    padding: 5px 20px;
    border-radius: 8px;
    border: 1px solid rgba(116, 185, 255, 0.3);
    display: inline-block;
}
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: #1e272e;
    border: 3px solid #0984e3;
    border-radius: 16px;
    padding: 30px 40px;
    text-align: center;
    box-shadow: 0 0 50px rgba(9,132,227,0.3);
    max-width: 380px;
}
.modal-box .icon { font-size: 48px; margin-bottom: 10px; }
.modal-box .title { font-size: 24px; font-weight: bold; color: #fff; margin-bottom: 8px; }
.modal-box .detail { color: #a0aec0; font-size: 15px; margin-bottom: 18px; line-height: 1.5; }
.modal-box button {
    padding: 10px 30px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: linear-gradient(145deg, #0984e3, #0767b0);
    color: #fff;
    transition: all 0.2s;
    font-family: inherit;
}
.modal-box button:hover { transform: translateY(-2px); filter: brightness(1.1); }
.level-modal { max-width: 400px; padding: 20px 24px; }
.level-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid rgba(255,255,255,0.1);
}
.level-item:hover { transform: translateX(3px); filter: brightness(1.15); }
.level-item.completed { background: linear-gradient(145deg, #00b894, #00a383); }
.level-item.current { background: linear-gradient(145deg, #0984e3, #0767b0); }
.level-item.uncompleted { background: linear-gradient(145deg, #636e72, #4a5357); }
.level-item .level-id { font-weight: bold; font-size: 14px; color: #fff; min-width: 50px; }
.level-item .level-diff { font-size: 12px; color: rgba(255,255,255,0.85); flex: 1; text-align: center; }
.level-item .level-status { font-size: 13px; min-width: 70px; text-align: right; }
.level-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.page-btn {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: bold;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: linear-gradient(145deg, #636e72, #4a5357);
    color: #fff;
    transition: all 0.15s;
    font-family: inherit;
}
.page-btn:hover { transform: translateY(-1px); filter: brightness(1.1); }
.page-info { color: #a0aec0; font-size: 12px; min-width: 50px; text-align: center; }
.level-jump {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #a0aec0;
    font-size: 12px;
}
.level-jump input {
    width: 40px;
    padding: 3px 6px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 12px;
    text-align: center;
    font-family: inherit;
}
@media (max-width: 480px) {
    #sudoku-board td { width: 38px; height: 38px; font-size: 18px; }
    .num-row .num-btn { min-height: 80px; font-size: clamp(14px, 4vw, 18px); }
    .num-btn.note-btn { font-size: clamp(16px, 4.5vw, 20px); }
    .num-btn.clear-btn { font-size: clamp(13px, 3.5vw, 16px); }
    .num-btn.mode-btn { font-size: clamp(15px, 4vw, 20px); }
    .game-wrapper { padding: 8px; }
    .modal-box { padding: 20px 24px; margin: 0 10px; }
    .top-bar .left, .top-bar .right { min-width: 70px; }
    .timer { font-size: 16px; padding: 3px 10px; }
    .completed-count { font-size: 14px; padding: 3px 10px; }
    .difficulty-label { font-size: 15px; padding: 3px 14px; }
}

@media (orientation: portrait) and (max-width: 480px) {
    body { padding: 4px; }
    .game-wrapper {
        padding: 8px;
        width: 100%;
        max-width: 100%;
    }
    .board-container {
        width: 100%;
        aspect-ratio: 1;
    }
    #sudoku-board {
        width: 100%;
        height: 100%;
        table-layout: fixed;
    }
    #sudoku-board td {
        font-size: min(4.5vw, 20px);
        padding: 0;
    }
    #sudoku-board td .pencil-marks span { font-size: min(2.5vw, 11px); }
    .controls { max-width: 100%; grid-template-columns: repeat(3, 1fr); }
    .num-row .num-btn { min-height: 70px; font-size: clamp(12px, 3.5vw, 16px); }
    .num-btn.note-btn { font-size: clamp(14px, 4.5vw, 20px); }
    .num-btn.clear-btn { font-size: clamp(11px, 3vw, 15px); }
    .num-btn.mode-btn { font-size: clamp(13px, 3.8vw, 18px); }
    .timer { font-size: min(4vw, 18px); }
    .completed-count { font-size: min(3.5vw, 16px); }
    .controls button { font-size: min(3.5vw, 14px); padding: 18px 0; }
    .difficulty-label { font-size: min(4vw, 16px); padding: 3px 14px; }
}