body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f0f0f0;
    margin: 0;
    padding: 10px;
}

h1 {
    color: #333;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

#board {
    display: grid;
    grid-template-columns: repeat(9, 66px);
    grid-template-rows: repeat(9, 66px);
    width: 594px;
    height: 594px;
    border: 3px solid #000;
}

.cell {
    width: 66px;
    height: 66px;
    font-size: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    background-color: #fff;
    border: 1px solid #ccc;
    box-sizing: border-box;
    position: relative;
}

.main-number {
    color: #123456;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.notes {
    display: none;
}

.cell.notes-mode .notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    font-size: 12px;
    color: #888;
    padding: 2px;
}

.notes-mode .main-number {
    display: none;
}

.cell .notes span {
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
}
.cell .notes span.note-1 { grid-area: 1 / 1; }
.cell .notes span.note-2 { grid-area: 1 / 2; }
.cell .notes span.note-3 { grid-area: 1 / 3; }
.cell .notes span.note-4 { grid-area: 2 / 1; }
.cell .notes span.note-5 { grid-area: 2 / 2; }
.cell .notes span.note-6 { grid-area: 2 / 3; }
.cell .notes span.note-7 { grid-area: 3 / 1; }
.cell .notes span.note-8 { grid-area: 3 / 2; }
.cell .notes span.note-9 { grid-area: 3 / 3; }

.cell:nth-child(n+28):nth-child(-n+36),
.cell:nth-child(n+55):nth-child(-n+63) {
    border-top: 2px solid #000;
}

.cell:nth-child(3n + 1):not(:nth-child(9n+1)) {
    border-left: 2px solid #000;
}

.given {
    background-color: #e0e0e0;
    cursor: default;
    font-weight: bold;
}

.selected {
    background-color: #a0c0e0;
}

.error {
    background-color: #ff6666;
    color: #fff;
}

#numbers {
    display: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: 594px;
    margin-top: 20px;
}

.number-btn {
    width: 66px;
    height: 66px;
    font-size: 32px;
    cursor: pointer;
    border: 1px solid #ccc;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.number-btn .count {
    font-size: 14px;
    color: #888;
    margin-top: 5px;
}

.number-btn:disabled {
    background-color: #e0e0e0;
    color: #aaa;
    cursor: not-allowed;
}

#notes-btn.active {
    background-color: #a0c0e0;
}

#difficulty-selector {
    margin-top: 10px;
}

#controls {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

button {
    padding: 11px 22px;
    font-size: 18px;
    cursor: pointer;
    border: 1px solid #ccc;
    background-color: #fff;
}

#status {
    margin-top: 10px;
    display: flex;
    gap: 30px;
}

#timer {
    font-size: 16px;
    color: #333;
}

#time-display {
    font-weight: bold;
}

/* --- Estils per a la finestra emergent --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: #fff;
    padding: 30px 40px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.modal-content h2 {
    color: #4CAF50;
    margin-bottom: 10px;
}

#new-game-btn {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 5px;
    margin-top: 20px;
}

/* Adaptació responsive per a pantalles petites */
@media (max-width: 600px) {
    body {
        padding: 5px;
    }
    
    #board {
        width: calc(100vw - 10px);
        height: calc(100vw - 10px);
    }

    .cell {
        width: calc((100vw - 10px - 6px) / 9);
        height: calc((100vw - 10px - 6px) / 9);
        font-size: 20px;
    }
    
    .cell.notes-mode .notes, .cell .notes {
        font-size: 8px;
    }

    #numbers {
        flex-wrap: wrap;
        width: calc(100vw - 10px);
        justify-content: space-between;
    }

    .number-btn {
        width: calc((100vw - 10px - 8px * 2) / 9);
        height: calc((100vw - 10px - 8px * 2) / 9);
        font-size: 18px;
    }

    .number-btn .count {
        font-size: 10px;
        margin-top: 2px;
    }

    #controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    #controls button {
        padding: 9px 13px;
        font-size: 15px;
    }

    .modal-content {
        padding: 20px;
        width: 80%;
    }
}