* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #f4f1ea;
    color: #2c3e50;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

.sudoku-header {
    width: 100%;
    max-width: 540px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}
.sudoku-header h1 { margin: 0; font-size: 1.6rem; font-weight: 800; }
.sudoku-header h1 span { font-size: 0.6rem; color: #999; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.sudoku-main { width: 100%; max-width: 500px; padding: 8px 12px 24px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.difficulty { display: flex; gap: 6px; }
.diff-btn {
    border: 1px solid #cfc8b8;
    background: #fff;
    color: #5a6b78;
    padding: 7px 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
}
.diff-btn.active { background: #3498db; color: #fff; border-color: #3498db; }
.status { display: flex; align-items: center; gap: 10px; }
.timer-wrap { font-variant-numeric: tabular-nums; font-weight: 700; }
.new-game-btn {
    background: #3498db; color: #fff; border: none;
    padding: 8px 14px; border-radius: 8px; font-weight: 700; cursor: pointer;
}
.new-game-btn:hover { background: #2980b9; }

/* ----- Board ----- */
.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    aspect-ratio: 1 / 1;
    width: 100%;
    border: 3px solid #2c3e50;
    background: #2c3e50;
    gap: 1px;
}
.cell {
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    color: #2980b9;
}
.cell.bx-right { border-right: 2px solid #2c3e50; }
.cell.bx-bottom { border-bottom: 2px solid #2c3e50; }
.cell.given { color: #2c3e50; font-weight: 800; cursor: default; }
.cell.selected { background: #cfe8fb; }
.cell.same { background: #e8f3fc; }
.cell.conflict { color: #e74c3c; background: #fdecea; }

.bests { text-align: center; font-size: 0.8rem; color: #7f8c8d; margin: 10px 0; font-variant-numeric: tabular-nums; }

/* ----- Number pad ----- */
.numpad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.pad-key {
    height: 52px;
    border: 1px solid #cfc8b8;
    background: #fff;
    border-radius: 8px;
    font-size: 1.3rem;
    font-weight: 700;
    color: #2c3e50;
    cursor: pointer;
}
.pad-key:active { background: #cfe8fb; }
.pad-erase { color: #e74c3c; }

/* ----- Win modal ----- */
.win-modal {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center; justify-content: center;
    z-index: 200; padding: 20px;
}
.win-modal.open { display: flex; }
.win-box {
    background: #fff; border-radius: 14px; padding: 28px 32px; text-align: center;
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}
.win-box h2 { margin: 0 0 12px; }
.win-box p { margin: 6px 0; }
.win-box .win-best { color: #7f8c8d; font-size: 0.9rem; }
.win-box .new-game-btn { margin-top: 16px; }

.version-info { position: fixed; bottom: 6px; right: 8px; font-size: 0.65rem; color: #bbb; }

@media (max-width: 420px) {
    .cell { font-size: 1.25rem; }
    .pad-key { height: 46px; font-size: 1.15rem; }
}
