* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px;
    touch-action: manipulation;
}

.container {
    max-width: 500px;
    width: 100%;
    background: white;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
}

#fireworks-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    z-index: 1000;
    border-radius: 20px;
    overflow: hidden;
}

#fireworks-container.active {
    opacity: 1;
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0;
    background: #333;
    border: 3px solid #333;
    margin-bottom: 12px;
    aspect-ratio: 1;
    max-width: 100%;
}

.cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    font-size: clamp(1.44em, 4.8vw, 2.16em);
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #ddd;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s;
}

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

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

.cell.given {
    background: #f0f0f0;
    color: #333;
    font-weight: 700;
}

.cell.user-input {
    color: #667eea;
}

.cell.note {
    color: #555;
    font-style: italic;
    padding: 0;
}

.notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    gap: 0;
    font-size: 0.57em;
}

.note-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    line-height: 0.8;
}

.note-cell.invalid-note {
    color: #cc0000;
}

.cell.selected {
    background: #ffd700;
}

.cell.highlighted {
    background: #fffacd;
}

.cell.error {
    background: #ffcccc;
    color: #cc0000;
}

.cell.correct {
    background: #ccffcc;
}

.note-mode-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border: 2px solid #764ba2;
    border-radius: 10px;
}

.note-mode-label {
    font-size: 0.9em;
    font-weight: 600;
    color: #764ba2;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #764ba2;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.number-pad.note-mode .number-btn:not(.erase-btn) {
    color: #999;
    border-color: #999;
    font-style: italic;
}

.number-pad.note-mode .number-btn:not(.erase-btn):active {
    background: #999;
    color: white;
}

.number-btn {
    aspect-ratio: 1;
    font-size: 1.5em;
    font-weight: 600;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-btn:active {
    transform: scale(0.95);
    background: #667eea;
    color: white;
}

.number-btn.completed {
    background: #e0e0e0;
    color: #999;
    border-color: #ccc;
}

.number-btn.completed:active {
    background: #d0d0d0;
    color: #888;
}

.number-pad.note-mode .number-btn.completed {
    background: #e0e0e0;
    color: #999;
    border-color: #ccc;
    font-style: normal;
}

.number-pad.note-mode .number-btn.completed:active {
    background: #d0d0d0;
    color: #888;
}

.erase-btn {
    border-color: #e74c3c;
    color: #e74c3c;
}

.erase-btn:active {
    background: #e74c3c;
    color: white;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.difficulty-select {
    grid-column: 1 / 3;
    padding: 10px;
    font-size: 1em;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: white;
    color: #667eea;
    font-weight: 600;
    cursor: pointer;
}

.btn {
    padding: 10px;
    font-size: 1em;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:active {
    background: #5568d3;
    transform: scale(0.98);
}

.btn-secondary {
    background: #764ba2;
    color: white;
}

.btn-secondary:active {
    background: #63408a;
    transform: scale(0.98);
}

.message {
    margin-top: 10px;
    padding: 10px;
    text-align: center;
    border-radius: 8px;
    font-weight: 600;
    min-height: 40px;
    visibility: hidden;
}

.message.success {
    background: #d4edda;
    color: #155724;
    visibility: visible;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    visibility: visible;
}

.message.info {
    background: #d1ecf1;
    color: #0c5460;
    visibility: visible;
}

@media (max-width: 400px) {
    body {
        padding: 2px;
    }

    .container {
        padding: 8px;
        border-radius: 8px;
    }

    .sudoku-board {
        margin-bottom: 8px;
    }

    .number-pad {
        gap: 4px;
        margin-bottom: 8px;
    }

    .controls {
        gap: 4px;
    }

    .message {
        margin-top: 8px;
        padding: 8px;
    }
}
