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

:root {
    --primary-color: #4a90d9;
    --primary-dark: #357abd;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --light-bg: #f8f9fa;
    --dark-text: #212529;
    --border-color: #dee2e6;
    --cell-selected: #bbdefb;
    --cell-highlight: #e3f2fd;
    --cell-same-number: #c8e6c9;
    --cell-error: #ffcdd2;
    --cell-given: #f5f5f5;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--dark-text);
    line-height: 1.6;
}

.app-container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 20px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    margin-bottom: 5px;
}

header .subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

main {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-lg);
    flex: 1;
}

.game-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.difficulty-selector label {
    font-weight: 500;
    color: var(--secondary-color);
}

.difficulty-selector select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.difficulty-selector select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--light-bg);
    color: var(--dark-text);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-secondary.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.game-info {
    display: flex;
    justify-content: space-around;
    margin-bottom: 15px;
    padding: 10px;
    background: var(--light-bg);
    border-radius: 10px;
}

.game-info > div {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.95rem;
}

.game-info .icon {
    font-size: 1.1rem;
}

.sudoku-container {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    background: #333;
    border: 3px solid #333;
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
}

.cell {
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 5vw, 1.5rem);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s;
    position: relative;
    user-select: none;
}

.cell:hover {
    background: var(--cell-highlight);
}

.cell.selected {
    background: var(--cell-selected);
}

.cell.highlighted {
    background: var(--cell-highlight);
}

.cell.same-number {
    background: var(--cell-same-number);
}

.cell.given {
    background: var(--cell-given);
    color: #333;
}

.cell.error {
    background: var(--cell-error);
    color: var(--danger-color);
}

.cell.user-input {
    color: var(--primary-color);
}

.cell.hint {
    color: var(--success-color);
}

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

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

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

.cell .notes {
    position: absolute;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    font-size: clamp(0.4rem, 2vw, 0.6rem);
    font-weight: 400;
    color: var(--secondary-color);
}

.cell .notes span {
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 15px;
    max-width: 350px;
    margin-left: auto;
    margin-right: auto;
}

.num-btn {
    aspect-ratio: 1;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: white;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--dark-text);
}

.num-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.num-btn:active {
    transform: scale(0.95);
}

.num-btn.erase-btn {
    background: var(--light-bg);
}

.num-btn.completed {
    opacity: 0.4;
    pointer-events: none;
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 15px;
}

.action-buttons .btn {
    padding: 10px 8px;
    font-size: 0.85rem;
    justify-content: center;
}

.message {
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    font-weight: 500;
    margin-top: 10px;
    animation: fadeIn 0.3s ease;
}

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

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

.message.info {
    background: #cce5ff;
    color: #004085;
}

.message.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

footer {
    text-align: center;
    padding: 20px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

footer a {
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: opacity 0.2s;
}

footer a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 90%;
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-content h2 {
    font-size: 1.8rem;
    margin-bottom: 15px;
}

.modal-content p {
    margin-bottom: 10px;
    color: var(--secondary-color);
}

.modal-content .win-time,
.modal-content .win-difficulty {
    font-size: 1.1rem;
    font-weight: 500;
}

.modal-content .btn {
    margin-top: 20px;
    padding: 12px 30px;
}

@media (max-width: 480px) {
    .app-container {
        padding: 10px;
    }

    header h1 {
        font-size: 2rem;
    }

    main {
        padding: 15px;
    }

    .game-controls {
        flex-direction: column;
        gap: 10px;
    }

    .game-info {
        font-size: 0.85rem;
        padding: 8px;
    }

    .number-pad {
        gap: 5px;
    }

    .num-btn {
        font-size: 1.1rem;
    }

    .action-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .action-buttons .btn {
        padding: 12px 8px;
    }
}

@media (max-width: 350px) {
    .game-info {
        flex-wrap: wrap;
        gap: 8px;
    }

    .action-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --light-bg: #2d2d2d;
        --dark-text: #f0f0f0;
        --border-color: #444;
        --cell-selected: #1e3a5f;
        --cell-highlight: #1a2634;
        --cell-same-number: #1e3a2e;
        --cell-error: #5c2626;
        --cell-given: #3a3a3a;
    }

    body {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    }

    main {
        background: #242424;
    }

    .cell {
        background: #333;
    }

    .cell.given {
        background: var(--cell-given);
        color: #e0e0e0;
    }

    .num-btn {
        background: #333;
        color: #f0f0f0;
        border-color: #444;
    }

    .num-btn:hover {
        background: var(--primary-color);
    }

    .difficulty-selector select {
        background: #333;
        color: #f0f0f0;
        border-color: #444;
    }

    .modal-content {
        background: #333;
        color: #f0f0f0;
    }
}
