body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background-color: #f4f4f4;
    min-height: 100vh;
}

h1, h2 {
    color: #333;
    text-align: center;
}

#instructions {
    margin: 15px 0;
    font-size: 1.1em;
    color: #555;
    min-height: 1.5em; /* Prevent layout shift */
    text-align: center;
}

#feedback-area {
    color: #d9534f; /* Reddish for errors/warnings */
    min-height: 1.2em; /* Prevent layout shift */
    margin-bottom: 10px;
    font-weight: bold;
    text-align: center;
}


/* --- Grid Layout --- */
#grid-container {
    display: grid;
    grid-template-columns: repeat(4, 70px); /* 4 columns */
    grid-template-rows: repeat(4, 70px);    /* 4 rows */
    gap: 10px;
    margin-bottom: 25px;
    border: 1px solid #ccc;
    padding: 10px;
    background-color: #e9e9e9;
    width: fit-content;
}

.grid-cell {
    background-color: #f8f8f8;
    border: 1px solid #bbb;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease;
    position: relative; /* For potential future additions */
}

.grid-cell:not(.disabled):hover {
    background-color: #e0e0e0;
}

/* State when cell is disabled (Phase 2, no circle) */
.grid-cell.disabled {
    background-color: #d0d0d0;
    opacity: 0.6;
    cursor: not-allowed;
    border-color: #aaa;
    pointer-events: none; /* Explicitly disable click events */
}

.grid-cell.disabled .circle-placeholder {
    display: none; /* Hide placeholder if cell is disabled */
}

/* Circle placeholder within the cell */
.circle-placeholder {
    width: 80%;
    height: 80%;
    border-radius: 50%;
    border: 2px solid transparent;
    background-color: transparent;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    box-sizing: border-box;
    display: none; /* Hidden by default */
}

/* State when cell has a circle (placed) but no specific color */
.grid-cell.has-circle .circle-placeholder {
    display: block;
    /* Remove background-color from here - it will be set by color classes */
}

/* --- Color Classes (Applied with higher specificity) --- */
.grid-cell.has-circle .circle-placeholder.uncolored { 
    background-color: #ffffff; 
    border-color: #555; 
}
.grid-cell.has-circle .circle-placeholder.red { 
    background-color: #ff4d4d; 
    border-color: transparent; 
}
.grid-cell.has-circle .circle-placeholder.green { 
    background-color: #4caf50; 
    border-color: transparent; 
}
.grid-cell.has-circle .circle-placeholder.blue { 
    background-color: #2196f3; 
    border-color: transparent; 
}
.grid-cell.has-circle .circle-placeholder.purple { 
    background-color: #9c27b0; 
    color: white; 
    border-color: transparent; 
}

/* --- Button Styling --- */
#controls {
    margin-bottom: 20px;
    display: flex;
    gap: 15px;
}

#controls button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    color: white;
}

#confirm-button { background-color: #5cb85c; } /* Green */
#confirm-button:hover { background-color: #4cae4c; }

#check-button { background-color: #007bff; } /* Blue */
#check-button:hover { background-color: #0056b3; }

#reset-button { background-color: #f0ad4e; } /* Orange */
#reset-button:hover { background-color: #ec971f; }

#homework-button {
    background-color: #17a2b8; /* Teal */
}
#homework-button:hover {
    background-color: #138496;
}

/* --- Results Area Styling (mostly reused) --- */
#results-area {
    width: 90%;
    max-width: 600px;
    background-color: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin-top: 15px;
    word-break: break-word; /* Ensure long words or spans break properly */
}

#results-area ul {
    list-style: disc; /* restore bullet points */
    padding-left: 1.5em;
}
#results-area li {
    display: list-item; /* ensure bullets display */
    margin-bottom: 12px;
    line-height: 1.6;
}

#results-area li { margin-bottom: 10px; font-size: 14px; line-height: 1.5; display: flex; align-items: center; }
#results-area .status { font-weight: bold; margin-left: 8px; padding: 3px 6px; border-radius: 4px; color: white; display: inline-block; }
.honored { background-color: #4caf50; }
.violated { background-color: #f44336; }
.pending { color: #777; font-style: italic; background-color: transparent;}
.grid-cell.has-circle {
    z-index: 1; /* Ensure proper stacking context */
}

.grid-cell.has-circle .circle-placeholder {
    cursor: pointer; /* Show pointer cursor to indicate clickable */
}

.modal.hidden {
    display: none !important; /* Force hidden state with !important */
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

/* Modern Modal Styling */
.modal.hidden {
    display: none;
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: #fff;
    padding: 28px;
    max-width: 400px;
    width: 90%;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(0);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-content h2 {
    margin-top: 0;
    color: #333;
    font-size: 1.5rem;
    margin-bottom: 20px;
}

#answer-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 24px;
    box-sizing: border-box;
    transition: border-color 0.3s, box-shadow 0.3s;
}

#answer-input:focus {
    outline: none;
    border-color: #17a2b8;
    box-shadow: 0 0 0 3px rgba(23, 162, 184, 0.2);
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.modal-buttons button {
    padding: 12px 24px;
    font-size: 16px;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    transition: transform 0.15s, background-color 0.3s;
}

.modal-buttons button:hover {
    transform: translateY(-2px);
}

.modal-buttons button:active {
    transform: translateY(0);
}

#answer-submit {
    background-color: #17a2b8;
}

#answer-submit:hover {
    background-color: #138496;
}

#answer-cancel {
    background-color: #6c757d;
}

#answer-cancel:hover {
    background-color: #5a6268;
}

.modal-content {
    background: #fff;
    padding: 20px;
    max-width: 300px;
    width: 90%;
    border-radius: 8px;
    text-align: center;
}

.modal-buttons {
    margin-top: 10px;
    display: flex;
    justify-content: space-evenly;
}

.color-word {
    margin: 0 5px; /* Add horizontal spacing around colored words */
    word-break: break-word; /* Prevent overflow of colored words */
}

/* Enhanced list item styling */
#results-area li {
    margin-bottom: 15px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    padding-right: 100px; /* Make room for the status badge */
    display: flex;
    flex-wrap: wrap;
}

/* Make status badges stay together */
#results-area .status {
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 4px;
    color: white;
    white-space: nowrap; /* Prevent "Not Good" from breaking */
    position: absolute;
    right: 0;
    top: 0;
}

/* For smaller screens */
@media (max-width: 600px) {
    #results-area li {
        padding-right: 0; /* Remove right padding */
        margin-bottom: 25px; /* More space between rules */
    }
    
    #results-area .status {
        position: static; /* Remove absolute positioning */
        margin-top: 8px; /* Add top margin when it wraps */
        display: block;
        width: fit-content;
        margin-left: 26px; /* Align with rule text */
    }
}

/* Color word spacing */
.color-word {
    display: inline-block; /* Prevents breaking within colored words */
    margin: 0 2px;
}

/* Responsive Design for Smaller Screens */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    #results-area {
        padding: 10px;
        font-size: 14px; /* Reduce font size for smaller screens */
    }

    #results-area ul {
        padding-left: 1em; /* Adjust padding for smaller screens */
    }

    #results-area li {
        flex-wrap: wrap; /* Allow wrapping for long lines */
        margin-bottom: 8px; /* Reduce spacing between items */
    }

    #results-area .status {
        margin-left: 0; /* Remove left margin for better alignment */
        margin-top: 5px; /* Add top margin for spacing when wrapping */
    }

    h1, h2 {
        font-size: 1.5em; /* Adjust heading sizes */
    }

    #controls button {
        font-size: 14px; /* Reduce button font size */
        padding: 8px 16px; /* Adjust button padding */
    }
}
