body {
    font-family: 'Roboto', Arial, sans-serif;
    display: flex;
    justify-content: flex-start; /* Align content to the top */
    align-items: center;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    background-color: #e9eef2; /* Lighter, softer background */
    color: #333;
    padding: 20px; /* Add padding to body */
    box-sizing: border-box;
}

.screen {
    text-align: center;
    padding: 20px;
    width: 100%;
    max-width: 600px; /* Maintain max-width for content */
    box-sizing: border-box;
    margin-bottom: 20px; /* Space between screen sections */
}

.screen:last-child {
    margin-bottom: 0;
}


.hidden {
    display: none !important;
}

h1 {
    font-size: 2.8rem;
    color: #2c3e50; /* Darker blue for heading */
    margin-bottom: 15px;
}

h2 {
    font-size: 2rem;
    color: #34495e; /* Slightly lighter blue */
    margin-bottom: 15px;
}

p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 20px;
}

.btn {
    padding: 12px 25px;
    font-size: 1.1rem;
    cursor: pointer;
    background-color: #3498db; /* Primary button blue */
    color: white;
    border: none;
    border-radius: 8px;
    transition: background-color 0.3s, transform 0.1s;
    margin: 5px;
    font-weight: bold;
}

.btn:hover {
    background-color: #2980b9; /* Darker blue on hover */
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #7f8c8d; /* Grey for secondary actions */
}

.btn-secondary:hover {
    background-color: #607071; /* Darker grey */
}

.btn-danger {
    background-color: #e74c3c; /* Red for danger/reset */
}
.btn-danger:hover {
    background-color: #c0392b; /* Darker red */
}

.btn-smart {
    background-color: #9b59b6; /* Purple */
    color: white;
    margin-bottom: 15px; /* Add some space below it */
}

.btn-smart:hover {
    background-color: #8e44ad; /* Darker purple */
}


.start-screen-buttons {
    margin-top: 20px;
}

#game-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 350px; /* Match grid container roughly */
    margin-bottom: 15px;
    font-size: 1.2rem;
    font-weight: bold;
}
#current-score-display { color: #27ae60; /* Green for score */}
#timer-display { color: #c0392b; /* Red for timer */}


#number-display {
    font-size: 3rem;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 10px; /* Reduced margin as Smart Place button is below */
    padding: 10px 20px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#grid-container {
    width: 100%;
    max-width: 380px; /* For a 5-column grid */
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.grid { /* Reverted to standard CSS Grid */
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 5 columns */
    gap: 8px; /* Adjust gap as preferred */
    width: 100%; /* Ensure grid takes up container width */
}

/* .grid-row class is no longer needed and should be removed if present */

.cell {
    width: 60px; /* Or make it responsive: calc((100% - 4 * 8px) / 5); */
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.1rem; 
    transition: background-color 0.2s, border-color 0.2s, transform 0.2s;
    color: white;
    position: relative;
    border: 2px solid;
    border-radius: 6px; 
    font-weight: bold;
    box-sizing: border-box; /* Important for width calculations */
}


.cell .number { 
    font-size: 1.3rem;
    font-weight: bold;
    z-index: 1;
}

.cell .order { 
    position: absolute;
    bottom: 3px;
    right: 3px;
    font-size: 0.65rem;
    font-weight: normal;
    background-color: rgba(0,0,0,0.2);
    padding: 1px 3px;
    border-radius: 3px;
}

.cell .spot { 
    position: absolute;
    top: 3px;
    left: 3px;
    font-size: 0.65rem;
    font-weight: normal;
    background-color: rgba(0,0,0,0.2);
    padding: 1px 3px;
    border-radius: 3px;
}

.cell.active { 
    background-color: #2ecc71; 
    border-color: #27ae60; 
    color: white;
}
.cell.active:hover {
    background-color: #29b765;
    transform: scale(1.05);
}


.cell.inactive { 
    background-color: #bdc3c7; 
    color: #7f8c8d;
    border-color: #95a5a6; 
}
.cell.inactive:hover {
    background-color: #cacfd2;
    border-color: #808b8d;
}


.cell.move-target { 
    background-color: #f1c40f; 
    border-color: #f39c12; 
    cursor: pointer;
}
.cell.move-target:hover {
    transform: scale(1.05);
}

.cell.locked { 
    background-color: #e74c3c; 
    border-color: #c0392b; 
    cursor: not-allowed;
}

.cell.locked .lock-icon {
    position: absolute;
    top: 5px; 
    right: 5px;
    font-size: 0.9rem;
    color: white;
    z-index: 2;
}

#feedback {
    margin-top: 20px;
    font-size: 1rem;
    min-height: 20px; 
    color: #c0392b; 
    font-weight: bold;
}

#end-screen #final-score-info {
    margin-top: 10px;
    font-size: 1.2em;
    font-weight: bold;
}


.stats-container {
    text-align: left;
    margin-top: 20px;
    padding: 15px 20px;
    background-color: #ffffff;
    border: 1px solid #bdc3c7;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-sizing: border-box;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.stats-container h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.4rem;
    color: #2c3e50;
    text-align: center;
    border-bottom: 1px solid #ecf0f1;
    padding-bottom: 10px;
}

.stats-container p {
    margin: 8px 0;
    font-size: 1rem;
    color: #555;
}
.stats-container p span {
    font-weight: bold;
    color: #333;
}


/* Modal Styles */
.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

.modal-content {
    background-color: #fefefe;
    margin: auto; 
    padding: 25px 30px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative; 
}

.modal-content h2 {
    margin-top: 0;
    color: #2c3e50;
}

.modal-content ol, .modal-content ul {
    padding-left: 20px;
}
.modal-content li {
    margin-bottom: 10px;
    line-height: 1.5;
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.setting-item {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
}
.setting-item label {
    margin-right: 10px;
    font-size: 1rem;
}
.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
}
.setting-item input[type="number"] {
    padding: 8px;
    font-size: 1rem;
    border-radius: 5px;
    border: 1px solid #ccc;
    width: 80px;
}


@media (max-width: 640px) {
    body { padding: 10px; }
    .screen { padding: 15px; }
    h1 { font-size: 2.2rem; }
    h2 { font-size: 1.8rem; }
    .btn { padding: 10px 18px; font-size: 1rem; }

    #grid-container { max-width: 95vw; } /* Allow grid to use more width */
    .cell {
        /* Make cell size responsive based on viewport and grid container */
        /* Assuming 5 columns and gap of 8px. Adjust if gap changes */
        width: calc((100% - 4 * 8px) / 5);
        height: calc((100% - 4 * 8px) / 5); 
        min-width: 40px; /* Prevent cells from becoming too small */
        min-height: 40px;
        font-size: 0.9rem;
    }
    .cell .number { font-size: 1rem; }
    .cell .order, .cell .spot { font-size: 0.55rem; }


    #number-display { font-size: 2.5rem; }
    #game-info { font-size: 1rem; }
    .stats-container { padding: 10px 15px; max-width: 90vw; }
    .stats-container h3 { font-size: 1.2rem; }
    .stats-container p { font-size: 0.9rem; }

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

    .update-banner {
        width: 95%;
        padding: 14px;
    }

    .update-banner h2 {
        font-size: 1.15rem;
    }

    .update-banner p {
        font-size: 0.92rem;
        margin-bottom: 12px;
    }

    .update-banner-link {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
    }
}

@media (max-width: 420px) {
    .grid { gap: 5px; }
    .cell {
        width: calc((100% - 4 * 5px) / 5);
        height: calc((100% - 4 * 5px) / 5);
        min-width: 35px;
        min-height: 35px;
        font-size: 0.8rem;
    }
    .cell .number { font-size: 0.9rem;}
}

/* Start Screen Specific Styling */
#start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center content vertically if page is tall enough */
    padding: 20px 15px; /* Adjusted padding */
    max-width: 500px; /* Constrain width for better focus */
    margin-left: auto; /* Center the block itself */
    margin-right: auto;
}

#start-screen h1 {
    font-size: 3rem; /* Slightly larger for more impact */
    color: #2c3e50;
    margin-bottom: 15px;
}

#start-screen p { /* The instruction paragraph */
    font-size: 1.1rem;
    color: #555; /* Slightly softer text color */
    line-height: 1.6;
    margin-bottom: 25px; /* Increased space before Start button */
    text-align: center;
}

.update-banner {
    width: 90%;
    max-width: 420px;
    margin: 0 0 20px;
    padding: 16px 18px;
    border-radius: 10px;
    border: 1px solid #bdd8ea;
    background: linear-gradient(135deg, #f8fcff 0%, #edf6fd 100%);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.12);
}

.update-banner h2 {
    margin: 0 0 8px;
    font-size: 1.3rem;
    color: #1f4f72;
}

.update-banner p {
    margin: 0 0 14px;
    font-size: 0.98rem;
    line-height: 1.5;
    color: #355161;
}

.update-banner-link {
    display: inline-block;
    margin: 0;
    text-decoration: none;
    font-size: 1rem;
    padding: 10px 20px;
}

#start-button { /* The main Start Game button */
    padding: 15px 40px; /* Larger padding for emphasis */
    font-size: 1.3rem;
    margin-bottom: 15px; /* Space below Start Game button */
    width: 80%; /* Make it a bit wider */
    max-width: 300px; /* But not too wide */
}

.start-screen-buttons { /* Container for How to Play & Settings */
    display: flex;
    justify-content: center; /* Center buttons if they are side-by-side */
    gap: 15px; /* Space between How to Play and Settings */
    margin-bottom: 30px; /* Increased space before High Score */
    width: 100%;
}

.start-screen-buttons .btn-secondary {
    padding: 10px 25px;
    font-size: 1rem;
    background-color: #7f8c8d;
    flex-grow: 1; /* Allow buttons to grow and fill space if needed */
    max-width: 180px; /* Max width for each secondary button */
}
.start-screen-buttons .btn-secondary:hover {
    background-color: #607071;
}


/* Styling for High Score and Game Stats containers on the start screen */
/* The image shows #high-score-display and #stats (which uses .stats-container) */
/* We can use a common class or style them consistently */

#high-score-display,
#stats.stats-container { /* Ensure #stats also uses .stats-container consistently if it's the general stats box */
    background-color: #ffffff;
    border: 1px solid #dfe4ea; /* Softer border color */
    border-radius: 8px;
    padding: 20px 25px; /* Increased padding */
    width: 90%; /* Control width */
    max-width: 400px; /* Max width */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* Softer, more modern shadow */
    margin-top: 0; /* Remove top margin if #start-screen handles spacing */
    margin-bottom: 20px; /* Space between stat boxes */
    text-align: left; /* Align text to left within boxes */
}

#high-score-display h3,
#stats.stats-container h3 {
    font-size: 1.5rem; /* Consistent heading size */
    color: #34495e;
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px; /* Space below heading */
    padding-bottom: 10px;
    border-bottom: 1px solid #ecf0f1; /* Lighter border */
}

#high-score-display p,
#stats.stats-container p {
    font-size: 1rem;
    color: #495057; /* Darker text for better readability */
    margin-bottom: 8px; /* Tighter spacing for list items */
    line-height: 1.5;
}
#high-score-display p span,
#stats.stats-container p span {
    font-weight: bold;
    color: #2c3e50; /* Stronger color for stat values */
    float: right; /* Align values to the right for a common style */
}

/* Clearfix for floated spans if any parent wrapping issues occur, though usually not needed for P tags */
#high-score-display p::after,
#stats.stats-container p::after {
    content: "";
    clear: both;
    display: table;
}


/* General .stats-container adjustments if it's also used on the end-screen */
/* This ensures the end-screen stats also benefit from some of these styles if desired, */
/* but the specific layout here targets the start-screen version. */
.stats-container {
    background-color: #ffffff;
    border: 1px solid #dfe4ea;
    border-radius: 8px;
    padding: 20px 25px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    margin-bottom: 20px;
    text-align: left;
}

.stats-container h3 {
    font-size: 1.5rem;
    color: #34495e;
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ecf0f1;
}

.stats-container p {
    font-size: 1rem;
    color: #495057;
    margin-bottom: 8px;
    line-height: 1.5;
}
.stats-container p span {
    font-weight: bold;
    color: #2c3e50;
    float: right;
}
.stats-container p::after { /* Clearfix for floated spans */
    content: "";
    clear: both;
    display: table;
}
