body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: #f4f4f4;
    color: #333;
    box-sizing: border-box;
    overflow-x: hidden;
}

.main-content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    flex-grow: 1;
}

.game-header {
    width: 100%;
    background-color: #3498db;
    color: white;
    padding: 10px 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center; /* Center main content (title) */
    align-items: center;
    box-sizing: border-box;
    height: 70px;
    border-radius: 8px 8px 0 0;
    margin-top: 20px;
    position: relative; /* Needed for absolute positioning of header-buttons */
}

.game-title {
    margin: 0;
    font-size: 1.8em;
    letter-spacing: 2px;
    text-align: center; /* Explicitly center text */
    padding-right: 0; /* Remove any padding that might offset centering */
    color: white;
    z-index: 2;
}

.header-buttons {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    position: absolute; /* Position buttons absolutely within header */
    right: 20px; /* Align to the right edge of the header */
    top: 50%; /* Center vertically */
    transform: translateY(-50%); /* Adjust for vertical centering */
    z-index: 3; /* Ensure buttons are above title if needed */
}

.left-header-button {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 8px 12px;
    font-size: 1.5em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    position: absolute; /* Position button absolutely within header */
    left: 20px; /* Align to the left edge of the header */
    top: 50%; /* Center vertically */
    transform: translateY(-50%); /* Adjust for vertical centering */
    z-index: 3;
}

.left-header-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: white;
}

.header-buttons button {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 8px 12px;
    font-size: 1.5em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
}

.header-buttons button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: white;
}

.header-buttons button .material-symbols-outlined,
.left-header-button .material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.game-container {
    background-color: #fff;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    padding: 15px;
    text-align: center;
    width: calc(100% - 30px);
    margin-bottom: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

h1 { /* This rule applies to other h1s not the game-title */
    color: #3498db;
    margin-bottom: 15px;
}

.stats-header p {
    display: inline-block;
    margin: 0 8px;
    font-size: 1em;
    font-weight: bold;
}

/* Hide timer text by making it the same color as the background */
.hidden-timer-text {
    color: #fff;
}

.stats-header {
    margin-bottom: 5px; /* Reduced from 15px to tighten space below stats header and above new message */
}

.info-message { /* Style for "No words found" message */
    color: #e74c3c; /* Reddish for warning */
    font-weight: bold;
    margin-top: 5px; /* Space below stats header */
    margin-bottom: 10px; /* Space above grid */
    min-height: 20px; /* Reserve space even when empty */
    opacity: 0;
    transition: opacity 0.3s ease-out;
    text-align: center; /* Center the message */
}

.info-message.show {
    opacity: 1;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    width: 100%;
    max-width: 300px;
    margin: 10px auto 15px auto; /* Reduced top margin to 10px from message, bottom margin remains 15px above buttons */
    border: 2px solid #ccc;
    padding: 5px;
    border-radius: 5px;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    -moz-user-select: none;
    touch-action: pan-y;
}

.grid-column {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    border: 1px solid #eee;
    height: 300px;
    position: relative;
    overflow: hidden;
}

.column-letters {
    display: flex;
    flex-direction: column;
    width: 100%;
    position: absolute;
    left: 0;
}

.grid-cell {
    width: 100%;
    min-height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    font-weight: bold;
    text-transform: uppercase;
    background-color: #ecf0f1;
    color: #333;
    box-shadow: none;
    border: 1px solid #ccc;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    -moz-user-select: none;
    flex-shrink: 0;
    will-change: transform, background-color, color, box-shadow;
    transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.grid-cell.highlight {
    background-color: #2ecc71;
    color: white;
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.7);
}

.grid-cell.highlighted-temp {
    animation: foundWordAnimation 1s forwards;
}

@keyframes foundWordAnimation {
    0% {
        transform: scale(1);
        background-color: #2ecc71;
        color: white;
        box-shadow: 0 0 10px rgba(46, 204, 113, 0.7);
    }
    50% {
        transform: scale(1.1);
        background-color: #27ae60;
        color: white;
        box-shadow: 0 0 15px rgba(46, 204, 113, 1);
    }
    100% {
        transform: scale(1);
        background-color: #ecf0f1;
        color: #333;
        box-shadow: none;
    }
}


.shift-area {
    position: absolute;
    width: 100%;
    height: 50%;
    left: 0;
    z-index: 10;
    cursor: pointer;
    touch-action: none;
}

.shift-area.top {
    top: 0;
}

.shift-area.bottom {
    bottom: 0;
}

.game-actions {
    display: flex;
    justify-content: space-between; /* Space out buttons */
    align-items: center;
    width: 100%;
    max-width: 300px; /* Match grid width */
    margin: 5px auto 10px auto; /* Reduced top margin to 5px from grid, bottom margin to 10px before border */
    box-sizing: border-box; /* Crucial for padding/width */
    padding: 0 5px; /* Match grid's horizontal padding */
}

/* Base style for action buttons (Evaluate and Give Up) */
.action-button {
    color: white;
    border: none;
    padding: 10px 15px; /* Slightly reduced padding */
    font-size: 1.1em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: flex; /* Allow icon and text to be side-by-side */
    align-items: center;
    gap: 8px; /* Space between icon and text */
    flex-grow: 1; /* Allow buttons to grow */
    max-width: 140px; /* Max width for each button to prevent overstretching */
    justify-content: center; /* Center content within button */
}

.action-button .material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20; /* Smaller icon size for buttons */
}


/* Specific styles for Evaluate button */
.evaluate-button {
    background-color: #2ecc71; /* Green */
}

.evaluate-button:hover {
    background-color: #27ae60; /* Darker green on hover */
}

/* Specific styles for Give Up button */
.give-up-button {
    background-color: #e74c3c; /* Red */
}

.give-up-button:hover {
    background-color: #c0392b; /* Darker red on hover */
}

.action-button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.found-words-container {
    margin-top: 5px; /* Reduced margin from border-top to remove whitespace */
    text-align: left;
    border-top: 1px solid #eee;
    padding-top: 5px; /* Reduced padding between border and label */
}

.found-words-container h2 {
    color: #3498db;
    margin-bottom: 5px; /* Reduced space below label */
}

#found-words-list {
    list-style: none;
    padding: 0;
    max-height: 200px; /* Increased max-height for main game found words list */
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 8px;
    border-radius: 5px;
    background-color: #fdfdfd;

    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
}

#found-words-list .found-word-item {
    background-color: #e0ffe0;
    padding: 5px 8px;
    border-radius: 4px;
    font-weight: bold;
    color: #27ae60;
    white-space: nowrap;
    display: inline-block;
}

/* Modal Styling */
.modal {
    display: none; /* Crucial: Hides the modal by default */
    position: fixed; /* Stays in place even when scrolling */
    z-index: 1000; /* Sits on top of everything */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Enable scroll if content is too long */
    background-color: rgba(0, 0, 0, 0.7); /* Black w/ opacity */
    justify-content: center; /* Center content horizontally */
    align-items: center; /* Center content vertically */
    padding: 10px; /* Add some padding around the modal for smaller screens */
    box-sizing: border-box; /* Include padding in width/height */
}

.modal-content {
    background-color: #fefefe;
    margin: auto; /* Centering for block elements, combined with flex above */
    padding: 20px;
    border: 1px solid #888;
    width: 90%; /* Responsive width */
    max-width: 500px; /* Max width for larger screens */
    border-radius: 10px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
    position: relative;
    text-align: left;
    max-height: 90vh; /* Revert to 90vh, as children will expand more. */
    overflow-y: auto; /* Ensure modal content scrolls if it gets too big */
}

.modal-content .close-modal-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
}

.modal-content .close-modal-button:hover,
.modal-content .close-modal-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal-content h2, .modal-content h3 {
    color: #3498db;
    margin-top: 0;
    margin-bottom: 15px;
    text-align: center;
}

.modal-content ul {
    list-style-type: disc;
    margin-left: 20px;
    margin-bottom: 15px;
}

.modal-content ul li {
    margin-bottom: 8px;
}

/* Specific styling for words display in game over modal */
#missed-words-display {
    margin-top: 15px;
    text-align: left; /* Keep text aligned left for lists */
    max-height: 500px; 
    overflow-y: auto; /* Keep scroll if this section overflows */
    border: 1px solid #eee;
    padding: 10px;
    border-radius: 5px;
    background-color: #fdfdfd;

    display: flex; /* Keep flex for word tags */
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start; /* Align words to left for easier reading */
}

#missed-words-display h3 {
    width: 100%;
	text-align: left;
}

#missed-words-display p {
    width: 100%;
    text-align: center; /* Center the "Words you missed/found" labels */
    margin-bottom: 10px;
    font-weight: bold;
    color: #333;
}

#missed-words-display .missed-word,
#missed-words-display .found-in-modal {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 5px;
    font-weight: bold;
    text-transform: uppercase;
}

#missed-words-display .missed-word {
    background-color: #ffe0e0; /* Light red for missed words */
    color: #c0392b; /* Darker red text */
}

#missed-words-display .found-in-modal {
    background-color: #e0ffe0; /* Light green for found words */
    color: #27ae60; /* Darker green text */
}

.modal-button {
    background-color: #3498db;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    margin-top: 20px;
    transition: background-color 0.3s ease;
    width: auto; /* Allow button to size to content */
}

.modal-button:hover {
    background-color: #2980b9;
}

.modal-button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Specific styling for buttons inside modal content, excluding close button */
.modal-content button:not(.close-modal-button) {
    display: block; /* Make them block to take full width */
    margin-left: auto; /* Center block buttons */
    margin-right: auto; /* Center block buttons */
}

.modal-content button:not(.close-modal-button):hover {
    filter: brightness(1.1);
}

.modal-content button:not(.close-modal-button):disabled {
    filter: none;
    opacity: 0.7;
}

.stats-link {
    display: block;
    text-align: center;
    margin-top: 10px;
    color: #3498db;
    text-decoration: none;
    font-weight: bold;
    transition: color 0.2s ease;
}

.stats-link:hover {
    color: #2980b9;
}

#game-history-list {
    padding-left: 1px; /* Adjust this to move the entire list left or right */
}

#game-history-list li {
    /* This removes default list-item indentation and sets your own */
    list-style-position: inside; /* Keeps the bullet inside the list item's content box */
    padding-left: 0; /* Adjust this value as needed */
    margin-left: 0; /* Adjust this value as needed */
    text-indent: -1.5em; /* This pulls the text back to the left, under the bullet */
    padding-top: 5px; /* Add a little space between lines if needed */
    padding-bottom: 5px; /* Add a little space between lines if needed */
}

.message-box {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    min-width: 250px;
    text-align: center;
}

.message-box.show {
    opacity: 1;
    visibility: visible;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .main-content-wrapper {
        margin: 0;
    }
    .game-container {
        margin: 0;
        padding: 15px;
    }

    .game-header {
        padding: 8px 15px;
        height: 60px;
        margin-top: 15px;
    }
    .game-title {
        font-size: 1.5em;
    }
    .header-buttons {
        right: 15px; /* Adjust position for mobile */
    }

    .left-header-button {
        left: 15px;
    }

    .header-buttons button, .left-header-button {
        padding: 6px 10px;
        font-size: 1.3em;
    }

    .grid-cell {
        font-size: 1.5em;
        min-height: 50px;
    }

    .grid-column {
        height: 250px;
    }

    .stats-header {
        margin-bottom: 4px; /* Mobile adjustment */
    }

    .info-message {
        margin-top: 4px; /* Mobile adjustment */
        margin-bottom: 8px; /* Mobile adjustment */
        font-size: 0.9em;
    }

    .game-actions {
        margin: 4px auto 8px auto; /* Mobile adjustment */
        padding: 0 5px;
    }

    .action-button {
        padding: 8px 12px; /* Smaller padding for mobile */
        font-size: 1em;
        gap: 6px;
        max-width: 120px; /* Further restrict max-width for mobile */
    }

    .action-button .material-symbols-outlined {
        font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 18; /* Even smaller icon */
    }

    .found-words-container {
        margin-top: 4px; /* Mobile adjustment */
        padding-top: 4px; /* Mobile adjustment */
    }

    .found-words-container h2 {
        margin-bottom: 4px; /* Mobile adjustment */
    }

    #found-words-list {
        max-height: 150px; /* Increased max-height for mobile found words */
        padding: 6px;
        gap: 5px;
    }

    #found-words-list .found-word-item {
        padding: 4px 7px;
    }

    .modal-content {
        padding: 15px;
        max-height: 90vh; /* No change here, let inner content manage scroll */
    }
    .modal-content .close-modal-button {
        font-size: 1.5em;
        top: 5px;
        right: 5px;
    }

    #missed-words-display {
        max-height: 500px; 
    }
}