/* === START OF COMPLETE SSM CSS === */

/* === Sudoku Streak Master Styling (Bottom Controls Layout) === */

.ssm-container {
    max-width: 500px; /* Overall container width */
    margin: 20px auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    position: relative;
    box-sizing: border-box;
}
*, *::before, *::after { box-sizing: inherit; } /* Apply box-sizing everywhere */

/* --- Header --- */
#ssm-game-container .ssm-header {
    text-align: center;
    margin-bottom: 20px;
}
#ssm-game-container .ssm-header h1 {
    margin: 0 0 10px 0;
    font-size: 1.8em;
    color: #333;
}
#ssm-game-container .ssm-stats {
    font-size: 0.9em;
    color: #555;
    line-height: 1.4;
}
#ssm-game-container .ssm-stats span {
    display: inline-block;
    margin: 0 5px;
    white-space: nowrap;
}
#ssm-game-container .ssm-stats strong {
    color: #000;
}
#ssm-game-container .ssm-login-prompt {
    font-size: 0.9em;
    margin-top: 10px;
    background-color: #f8f9fa;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
}
#ssm-game-container .ssm-login-prompt p {
    margin: 0;
}


/* --- Grid Styling --- */
#ssm-game-container .ssm-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 90%;
    max-width: 450px;
    aspect-ratio: 1 / 1;
    border: 3px solid #333;
    margin: 0 auto; /* Center the grid */
    background-color: #ccc;
    gap: 1px;
    padding: 1px;
    position: relative;
    transition: opacity 0.3s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border-radius: 3px;
    overflow: hidden;
}

#ssm-game-container .ssm-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    font-size: clamp(1em, 4.5vw, 1.8em);
    font-weight: bold;
    color: #17a2b8; /* User-entered numbers color */
    cursor: pointer;
    position: relative;
    padding: 0;
    line-height: 1;
    text-align: center;
    transition: background-color 0.2s ease;
    border: none;
}
#ssm-game-container .ssm-cell.ssm-border-right { margin-right: 2px; }
#ssm-game-container .ssm-cell.ssm-border-bottom { margin-bottom: 2px; }
#ssm-game-container .ssm-cell:focus { outline: 2px solid orange; outline-offset: -2px; z-index: 10; }
#ssm-game-container .ssm-cell.ssm-prefilled { background-color: #e9ecef; color: #343a40; cursor: default; font-weight: 600; }
#ssm-game-container .ssm-cell.ssm-selected:not(.ssm-prefilled) { background-color: #cce5ff; }
#ssm-game-container .ssm-cell.ssm-error:not(.ssm-prefilled) { background-color: #f8d7da; color: #721c24; font-weight: bold; }

/* --- Pencil Marks --- */
#ssm-game-container .ssm-cell .ssm-pencil-marks {
    position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    font-size: calc(clamp(1em, 4.5vw, 1.8em) * 0.33); font-weight: normal;
    color: #6c757d; pointer-events: none; line-height: 1.1; text-align: center;
    align-items: center; justify-items: center; padding: 1px;
}

/* === Bottom Controls Area === */
#ssm-game-container .ssm-controls {
    width: 90%; /* Match grid width */
    max-width: 450px; /* Match grid max-width */
    margin: 20px auto 0; /* Space above, centered, no space below */
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 5px;
    border: 1px solid #dee2e6;
    display: flex;
    flex-direction: column; /* Stack rows vertically */
    align-items: center;
    gap: 10px; /* Space between rows (palette, actions, options) */
}

/* Control Rows (Palette, Actions, Options) */
#ssm-game-container .ssm-number-palette,
#ssm-game-container .ssm-action-buttons,
#ssm-game-container .ssm-options {
    display: flex;
    flex-wrap: wrap; /* Allow items to wrap */
    justify-content: center; /* Center items */
    align-items: center; /* Align items vertically */
    gap: 6px 8px; /* Row gap, Column gap */
    width: 100%;
    visibility: visible;
    opacity: 1;
}
#ssm-game-container .ssm-options {
    border-top: 1px solid #eee; /* Separator line */
    padding-top: 10px;
}

/* Buttons inside the controls */
#ssm-game-container .ssm-controls button,
#ssm-game-container .ssm-controls label {
    margin: 0; /* Use gap for spacing */
}

#ssm-game-container .ssm-controls button {
    font-size: clamp(0.9em, 2.5vw, 1.1em); /* Slightly smaller buttons */
    min-width: 35px; /* Adjust size */
    height: 35px; /* Adjust size */
    padding: 5px;
    cursor: pointer;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background-color: #fff;
    color: #495057; /* Default text color */
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
    vertical-align: middle;
}
#ssm-game-container .ssm-controls button:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
    color: #343a40;
}
#ssm-game-container .ssm-controls button:active {
    background-color: #dee2e6;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

/* Specific Button Styles */
#ssm-game-container .ssm-erase-button {
    background-color: #f8d7da;
    color: #721c24;
    font-weight: bold;
    border-color: #f5c6cb;
}
#ssm-game-container .ssm-erase-button:hover {
    background-color: #f1b0b7;
    border-color: #eba3ab;
    color: #721c24;
}
#ssm-game-container #ssm-pencil-toggle-btn.active {
    background-color: #cce5ff;
    border-color: #b8daff;
    color: #004085;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
#ssm-game-container #ssm-hint-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #e9ecef;
    color: #6c757d;
}

/* Options Area Styling */
#ssm-game-container .ssm-options label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85em; /* Slightly smaller options text */
    color: #495057;
    padding: 5px 8px; /* Add some padding to labels */
    border: 1px solid transparent; /* Reserve space */
    border-radius: 4px;
}
#ssm-game-container .ssm-options label:hover {
    background-color: #e9ecef;
    border-color: #ced4da;
}
#ssm-game-container .ssm-options input[type="checkbox"] {
    cursor: pointer;
    margin: 0;
    width: 1em;
    height: 1em;
    vertical-align: middle; /* Align checkbox */
}
#ssm-game-container #ssm-timer {
    min-width: 45px;
    font-weight: bold;
    background-color: #e9ecef;
    padding: 5px 6px; /* Match label padding */
    border-radius: 3px;
    font-size: 0.85em;
    line-height: 1;
    color: #495057;
    text-align: center;
    border: 1px solid #ced4da; /* Add border */
}
#ssm-game-container #ssm-timer:not([style*="display: none"]) {
    display: inline-block; /* Still need this if toggled */
}


/* --- Message Area (Below Controls) --- */
#ssm-game-container .ssm-message-area {
    width: 90%; /* Match grid width */
    max-width: 450px; /* Match grid max-width */
    margin: 15px auto 0; /* Space above, centered */
    padding: 10px 15px;
    min-height: 1.5em;
    text-align: center;
    font-weight: bold;
    border-radius: 4px;
    border: 1px solid transparent;
    display: none;
    line-height: 1.4;
}
#ssm-game-container .ssm-message-area:not(:empty) { display: block; }
#ssm-game-container .ssm-message-area.success { background-color: #d4edda; color: #155724; border-color: #c3e6cb; }
#ssm-game-container .ssm-message-area.error { background-color: #f8d7da; color: #721c24; border-color: #f5c6cb; }


/* --- Loading Indicator Style --- */
#ssm-game-container .ssm-grid.ssm-loading { opacity: 0.5; cursor: wait; pointer-events: none; }
#ssm-game-container .ssm-grid.ssm-loading::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    width: 40px; height: 40px; margin: -20px 0 0 -20px;
    border: 5px solid #f3f3f3; border-top: 5px solid #3498db; border-radius: 50%;
    animation: ssm-spin 0.8s linear infinite; z-index: 20;
}
@keyframes ssm-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- Solved State --- */
#ssm-game-container .ssm-grid.ssm-solved { /* Optional: Visual cue */ }
#ssm-game-container .ssm-grid.ssm-solved .ssm-cell { cursor: default; outline: none; box-shadow: none; }
#ssm-game-container .ssm-grid.ssm-solved .ssm-cell:not(.ssm-prefilled) { color: #28a745; }


/* === Difficulty Modal Styles === */

/* The Overlay */
.ssm-modal-overlay {
    position: fixed; /* Cover the whole screen */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.65); /* Semi-transparent black background */
    display: flex; /* Use flexbox for centering */
    justify-content: center; /* Center horizontally */
    align-items: center; /* Center vertically */
    z-index: 1001; /* High z-index to ensure it's on top */
    /* DEFAULT STATE: Hidden via opacity and visibility for transitions */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease-in-out, visibility 0s linear 0.25s;
}
/* SHOWN STATE (when .ssm-show class is added by JS) */
.ssm-modal-overlay.ssm-show {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease-in-out, visibility 0s linear 0s;
}

/* The Modal Box */
.ssm-modal {
    background-color: #fff;
    padding: 25px 30px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    text-align: center;
    position: relative; /* Needed for positioning the close button */
    min-width: 280px; /* Minimum width */
    max-width: 90%; /* Maximum width relative to screen */
    /* Apply transition only when shown/hidden */
    transform: translateY(-20px);
    transition: transform 0.25s ease-in-out;
}
/* Adjust transform when shown */
.ssm-modal-overlay.ssm-show .ssm-modal {
     transform: translateY(0);
}

/* Modal Title */
.ssm-modal h3 {
    margin: 0 0 20px 0;
    font-size: 1.4em;
    color: #333;
    font-weight: 600;
}

/* Container for modal buttons */
.ssm-modal-buttons {
    display: flex;
    flex-direction: column; /* Stack buttons vertically */
    gap: 10px; /* Space between buttons */
    align-items: stretch; /* Make buttons take full width */
}

/* Difficulty buttons inside the modal */
.ssm-modal-buttons .ssm-difficulty-btn {
    font-size: 1.1em;
    padding: 12px 15px; /* More padding */
    border: 1px solid #ced4da;
    border-radius: 5px;
    background-color: #f8f9fa;
    color: #495057;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
    width: 100%;
    display: block;
    box-sizing: border-box;
}
.ssm-modal-buttons .ssm-difficulty-btn:hover {
    background-color: #e2e6ea;
    border-color: #adb5bd;
}
.ssm-modal-buttons .ssm-difficulty-btn:active {
    transform: scale(0.98); /* Subtle press effect */
}

/* Optional: Different styling per difficulty */
.ssm-modal-buttons .ssm-difficulty-btn[data-difficulty="easy"]:hover { background-color: #c3e6cb; }
.ssm-modal-buttons .ssm-difficulty-btn[data-difficulty="medium"]:hover { background-color: #b8daff; }
.ssm-modal-buttons .ssm-difficulty-btn[data-difficulty="hard"]:hover { background-color: #f5c6cb; }

/* Close button ('X') */
.ssm-modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.8em;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
}
.ssm-modal-close:hover {
    color: #333;
}
/* === END MODAL Styles === */


/* --- Responsive Adjustments --- */
@media (max-width: 520px) {
    #ssm-game-container { padding: 0 10px; }
    #ssm-game-container .ssm-grid, #ssm-game-container .ssm-controls, #ssm-game-container .ssm-message-area { width: 100%; max-width: none; }
    #ssm-game-container .ssm-header h1 { font-size: 1.6em; }
    #ssm-game-container .ssm-controls button { min-width: 33px; height: 33px; font-size: 0.9em; }
    #ssm-game-container .ssm-controls { padding: 8px; gap: 8px; }
    #ssm-game-container .ssm-options { padding-top: 8px; }
    .ssm-modal { padding: 20px; } /* Less padding on small screens */
    .ssm-modal h3 { font-size: 1.2em; margin-bottom: 15px;}
    .ssm-modal-buttons .ssm-difficulty-btn { font-size: 1em; padding: 10px; }
}

@media (max-width: 400px) {
    #ssm-game-container .ssm-stats span { margin: 0 2px; font-size: 0.8em; }
    #ssm-game-container .ssm-controls button { min-width: 30px; height: 30px; font-size: 0.85em; }
    #ssm-game-container .ssm-options label { font-size: 0.8em; padding: 4px 6px; }
    #ssm-game-container #ssm-timer { font-size: 0.8em; padding: 4px 6px; }
    #ssm-game-container .ssm-number-palette, #ssm-game-container .ssm-action-buttons, #ssm-game-container .ssm-options { gap: 4px 6px; }
}

/* === END OF COMPLETE SSM CSS === */