* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #fffdf2;
    color: #333;
}

header {
    text-align: center;
    padding: 36px 20px 30px;
    background: #e4f4df;
    border-bottom: 4px solid #dceeff;
}

.back-link {
    display: inline-block;
    margin-bottom: 16px;
    color: #333;
    text-decoration: none;
    font-weight: bold;
}

h1 {
    margin: 0 0 10px;
    font-size: 2.5rem;
}

header p {
    margin: 0;
}

main {
    max-width: 760px;
    margin: 0 auto;
    padding: 40px 20px 60px;
}

.difficulty-panel,
.board-section {
    background: #eee5fa;
    border-radius: 16px;
    padding: 28px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .06);
}

.board-section {
    margin-top: 28px;
    background: #f9e8ef;
}

.difficulty-panel h2,
.board-section h2 {
    margin-top: 0;
}

.difficulty-buttons,
.game-options {
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    margin: 24px 0;
}

.game-options {
    margin-top: 0;
    margin-bottom: 18px;
}

button {
    min-width: 120px;
    padding: 12px 18px;
    border: 1px solid rgba(0, 0, 0, .12);
    border-radius: 10px;
    background: #fff;
    color: #333;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
}

button:hover {
    background: #ffe2d6;
}

button:disabled {
    cursor: default;
    opacity: .5;
}

.game-options button.active {
    background: #dceeff;
    border-color: #6d9ecf;
}

#status {
    margin-bottom: 0;
    line-height: 1.5;
}

#status.conflict-status {
    color: #8b2f2f;
    font-weight: 700;
}

#status.success-status {
    color: #246b3f;
    font-weight: 700;
}

.sudoku-board {
    width: min(100%, 540px);
    aspect-ratio: 1 / 1;
    margin: 18px auto 0;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    background: #fff;
    border: 3px solid #333;
}

.sudoku-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid #aaa;
    border-bottom: 1px solid #aaa;
    font-size: clamp(1rem, 5vw, 1.75rem);
    user-select: none;
}

.sudoku-cell.fixed {
    font-weight: 700;
    background: #fffdf2;
}

.sudoku-cell.empty,
.sudoku-cell.user-value,
.sudoku-cell.has-notes {
    background: #fff;
    cursor: pointer;
}

.sudoku-cell.user-value {
    color: #245a88;
    font-weight: 600;
}

.sudoku-cell.selected {
    background: #dceeff;
    outline: 3px solid #6d9ecf;
    outline-offset: -3px;
}

.sudoku-cell.conflict {
    background: #ffd9d9;
    color: #8b1f1f;
}

.sudoku-cell.selected.conflict {
    background: #ffcaca;
    outline-color: #b94a4a;
}

.pencil-grid {
    position: absolute;
    inset: 2px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    align-items: center;
    justify-items: center;
    color: #5a6670;
    font-size: clamp(.46rem, 1.7vw, .72rem);
    font-weight: 600;
    line-height: 1;
}

.pencil-mark {
    width: 100%;
    min-width: 0;
    text-align: center;
}

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

.sudoku-cell:nth-last-child(-n + 9) {
    border-bottom: 0;
}

.sudoku-cell.box-right {
    border-right: 3px solid #333;
}

.sudoku-cell.box-bottom {
    border-bottom: 3px solid #333;
}

.number-pad {
    width: min(100%, 540px);
    margin: 20px auto 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.number-pad button {
    min-width: 0;
    width: 100%;
    padding: 12px 6px;
}

#erase-cell {
    grid-column: span 1;
}

@media (max-width: 600px) {
    h1 { font-size: 2rem; }
    main { padding: 28px 12px 40px; }
    .difficulty-panel,
    .board-section { padding: 20px 12px; }
    .difficulty-buttons { flex-direction: column; }
    .difficulty-buttons button { width: 100%; }
    .game-options { gap: 8px; }
    .game-options button { min-width: 0; flex: 1; padding: 10px 8px; }
    .sudoku-cell { font-size: clamp(.95rem, 7vw, 1.5rem); }
    .pencil-grid { font-size: clamp(.42rem, 2.8vw, .64rem); }
    .number-pad { grid-template-columns: repeat(5, 1fr); }
    .number-pad button { font-size: 1.05rem; padding: 12px 2px; }
}
