body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f0f0f0;
    margin: 0;
}


/* --- Main Container Layout (Desktop Default) --- */
.container {
    display: flex;
    flex-direction: row; /* Side-by-side on desktop */
    align-items: flex-start;
    gap: 40px;
    text-align: center;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Create a wrapper for the number pad and buttons on the right */
.side-panel {
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Start elements from the top */
    width: 250px;
}

#message {
    margin-top: 10px;
    font-size: 18px;
    font-weight: bold;
    height: 20px;
}

/* --- Sudoku Grid --- */

#sudoku-container {
    position: relative;
    display: flex;
    justify-content: center;
    margin: 0;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    
    /* RESPONSIVE: Use fluid units, then cap the max size */
    width: 95vw; 
    height: 95vw;
    max-width: 450px; /* Limits the size on large screens */
    max-height: 450px; 
    
    border: 4px solid #333;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    box-sizing: border-box; /* Crucial for responsive borders */
}

/* --- Cells --- */
.cell {
    border: 1px solid #ddd;
    display: flex;
    justify-content: center;
    align-items: center;
    /* RESPONSIVE: Font size scales with viewport/cell size */
    font-size: min(5.5vw, 24px); 
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    background-color: white;
    transition: background-color 0.1s;
    line-height: 1; /* Helps vertical centering */
}

/* Thicker borders for the 3x3 regions */
.cell:nth-child(3n) { border-right-width: 3px; border-right-color: #333; }
.cell:nth-child(9n) { border-right-width: 1px; border-right-color: #ddd; } 
/* First column thick border is managed by the grid container border */

/* Thicker bottom borders for 3x3 rows */
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom-color: #333;
    border-bottom-width: 3px;
}

/* Clue (pre-filled) cell styling */
.clue {
    background-color: #f8f8f8;
    color: #444;
    cursor: default;
    pointer-events: none;
}

/* Currently selected cell */
.selected {
    background-color: #bbdefb;
}

/* Error/Wrong Entry styling (RED) */
.error {
    background-color: #ffdddd !important;
    color: red;
}

/* Trophy Display (Overlay) */
#trophy-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 150px;
    opacity: 0;
    transition: opacity 1s, transform 1s;
    z-index: 10;
    pointer-events: none;
}
.trophy-shown {
    opacity: 1 !important;
    transform: translate(-50%, -50%) scale(1.1);
}

/* --- Number Pad Styling --- */
.number-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 250px;
    margin: 20px auto 10px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.num-button {
    padding: 15px;
    border: 1px solid #ddd;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    background-color: #e9e9e9;
    transition: background-color 0.1s;
}

.num-button:hover {
    background-color: #dcdcdc;
}

.clear-button {
    grid-column: span 3;
    background-color: #f7e0e0;
    color: #cc0000;
}

/* Control Button and Difficulty Selector (outside of .container) */
#controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    align-items: center;
}

.controls button, #controls button, #difficulty-select {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
}

#difficulty-select {
    background-color: #fff;
    color: #333;
    border: 1px solid #ddd;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 20px;
    margin-top: 30px;
    border-top: 1px solid #ddd;
    font-family: sans-serif;
    width: 100%;
}

footer a {
    color: #24292e;
    text-decoration: none;
    font-weight: bold;
}

footer a:hover {
    text-decoration: underline;
    color: #0366d6;
}


/* ########################################## */
/* ### MOBILE RESPONSIVE LAYOUT (Crucial) ### */
/* ########################################## */
@media (max-width: 768px) {
    
    /* 1. Stack the Sudoku Grid and the Side Panel */
    .container {
        flex-direction: column; /* Key change: stack vertically */
        gap: 20px; 
        padding: 10px; 
        width: 100%; 
        box-shadow: none; 
    }

    /* 2. Make the Side Panel full-width to align its content */
    .side-panel {
        width: 100%;
        align-items: center; /* Center the number pad and buttons within the panel */
        max-width: 450px; /* Cap size on wider phones */
    }

    /* 3. Adjust the Number Pad width */
    .number-pad {
        width: 90%; 
        max-width: 300px;
        margin: 10px auto;
    }

    /* 4. Center the buttons/controls below the main container */
    #controls {
        flex-direction: column;
        align-items: center;
        width: 90%;
        gap: 10px;
    }
    
    #controls button, #difficulty-select {
        width: 100%;
        max-width: 300px;
    }
}