:root {
    /* Colors */
    --primary-color: #3498db;
    --primary-dark: #2980b9;
    --secondary-color: #9b59b6;
    --accent-color: #27ae60;
    --text-color: #333;
    --text-dark: #2c3e50;
    --text-light: #777;
    --background-color: #f5f5f5;
    --cell-bg: #fff;
    --cell-alt-bg: #e6e6e6;
    --cell-hover: #d9e9f7;
    --cell-highlight: #d4e8f7;
    --cell-selected: #bbdefb;
    --border-color: #aaaaaa;
    --error-color: #e74c3c;
    --hint-counter-bg: #1a5089;
    --border-dark: #000;
    --hover-overlay: rgba(62, 130, 247, 0.35);  /* Semi-transparent blue */
    
    /* Spacing */
    --gap-small: 5px;
    --gap-medium: 10px;
    --gap-large: 20px;
    --gap-xlarge: 30px;
    
    /* Font sizes */
    --font-small: 12px;
    --font-medium: 16px;
    --font-large: 24px;
    --font-xlarge: 28px;

    /* Border values */
    --border-thin: 1.5px;
    --border-medium: 2px;
    --border-thick: 4px;
}

/* Core layout */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

body {
    font-family: 'Arial', sans-serif;
    display: flex !important;
    flex-direction: column !important;
    align-items: center;
    background-color: var(--background-color);
    color: var(--text-color);
    min-height: 100vh !important; /* Ensure body is at least full viewport height */
}

h1 {
    color: var(--primary-color);
    margin: 0; /* Reset margin */
    padding: 0;
    font-size: 32px;
    font-weight: bold;
    letter-spacing: 0.5px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
  }


  .difficulty-label {
    font-size: 18px;
    font-weight: bold;
    color: var(--primary-dark);
    margin-right: 10px;
}

.difficulty {
    display: inline-flex;
    align-items: center;
    margin: 0;
    gap: 12px;
    font-size: large;
    /* Removed white background and shadow */
}

#difficulty-select {
    font-size: 16px;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-weight: 500;
    background-color: #f8f9fa;
    color: var(--text-dark);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#difficulty-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 4px rgba(52, 152, 219, 0.5);
    outline: none;
}

#difficulty-select:hover {
    border-color: var(--primary-color);
}

#difficulty-select option {
    font-size: 16px;
    padding: 8px;
    background-color: white;
}

.game-header {
    position: relative;
    width: 827px; /* This should match the exact width of your grid container */
    max-width: 827px !important;
    margin-left: 300px; /* This should match the left offset of your grid container */
    margin-right: auto;
    
    /* Keep other styles */
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-left: 0;
    padding-right: 0;
    box-sizing: border-box;
}

.header-divider {
    width: 100%;
    height: 1px;
    background-color: #ddd; /* Lighter color than the footer border */
    margin: 10px 0;
    box-sizing: border-box;
    position: relative;
    left: 0;
    right: 0;
}

.game-title-area {
    display: flex;
    align-items: center;
}

.difficulty-selector {
    display: flex;
    align-items: center;
}

/* Game containers */
.game-container {
  display: flex;
  justify-content: center;
  align-items: flex-start; /* ✅ This prevents vertical shift */
  margin: 20px auto;
  max-width: 1200px;    flex-direction: column;
    align-items: center;
    gap: var(--gap-medium);
    width: 100%;
    max-width: 1100px;
    height: auto;
    padding: 10px 20px 0 20px;
    box-sizing: border-box;
    margin: 0 auto; /* Center the container */
}

.game-container {
  width: 100%;
  max-width: 1100px;
  padding-left: 20px;
  padding-right: 20px;
  box-sizing: border-box;
}

.game-area {
    display: flex;
    flex-direction: row;
    justify-content: flex-start; /* Change from center to flex-start */
    gap: var(--gap-xlarge);
    width: 100%;
    margin-top: 10px;
    box-sizing: border-box;
}

.right-side-content {
    order: 2;
    display: flex;
    flex-direction: column;
    gap: var(--gap-large);
    height: 100%;
    justify-content: space-between;
    margin-top: -25px;
}

.left-side-content {
    order: 1;
    margin-right: auto; /* Push it left by adding auto margin on right */
    align-self: flex-start; /* Align to top */
    width: 300px !important;
    flex-shrink: 0 !important;
    position: relative !important;
}

/* Board styles */
#board {
    order: 1;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 0;
    position: relative;
    background-color: var(--cell-bg);
    border: var(--border-thick) solid var(--border-dark);
    margin: 0 auto;
    height: fit-content;
}

/* Cell styling */
.cell {
    width: 55px;
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--cell-bg);
    font-size: var(--font-xlarge);
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    color: #000000;
    text-shadow: 0px 0px 1px rgba(0, 0, 0, 0.2);
    position: relative;
    border: 1.5px solid var(--border-color);
    transition: all 0.15s ease;
}

/* Updated highlight colors to create stronger visual distinction */

/* Cells with same number - stronger blue highlight */
.cell.highlight-same {
    background-color: rgba(1, 39, 99, 0.4) !important; /* Deeper blue with higher opacity */
}

/* Cells in same row/column/block - lighter highlight */
.cell.highlight-related {
    background-color: rgba(230, 241, 255, 0.6) !important; /* Light blue with lower opacity */
}

.cell:hover {
    background-color: var(--cell-hover);
    position: relative;
}

.cell:hover::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--hover-overlay);
    z-index: 0; /* Keep below the cell content */
    pointer-events: none; /* Allow clicking through the overlay */
}

.cell.highlight-same {
    background-color: var(--cell-highlight) !important;
}

.cell.selected {
    background-color: var(--cell-selected) !important;
}

.cell.hint .cell-number {
    color: #3498db; /* Slightly different blue for hints */
    font-weight: 500;
}

/* Keep the colors for given and incorrect cells as they are */
.cell.given .cell-number {
    font-weight: 500;
    color: #000; /* Given numbers remain black */
}

.cell:not(.given):not(.incorrect) .cell-number {
    color: #4a90e2; /* Light blue color for user entries */
    font-weight: 500; /* Make it slightly bolder for better visibility */
}

.cell.incorrect .cell-number {
    color: var(--error-color);
    font-style: italic;
}

/* Alternate cell background pattern */
.cell[data-row="0"][data-col="0"], .cell[data-row="0"][data-col="1"], .cell[data-row="0"][data-col="2"],
.cell[data-row="1"][data-col="0"], .cell[data-row="1"][data-col="1"], .cell[data-row="1"][data-col="2"],
.cell[data-row="2"][data-col="0"], .cell[data-row="2"][data-col="1"], .cell[data-row="2"][data-col="2"],
.cell[data-row="0"][data-col="6"], .cell[data-row="0"][data-col="7"], .cell[data-row="0"][data-col="8"],
.cell[data-row="1"][data-col="6"], .cell[data-row="1"][data-col="7"], .cell[data-row="1"][data-col="8"],
.cell[data-row="2"][data-col="6"], .cell[data-row="2"][data-col="7"], .cell[data-row="2"][data-col="8"],
.cell[data-row="3"][data-col="3"], .cell[data-row="3"][data-col="4"], .cell[data-row="3"][data-col="5"],
.cell[data-row="4"][data-col="3"], .cell[data-row="4"][data-col="4"], .cell[data-row="4"][data-col="5"],
.cell[data-row="5"][data-col="3"], .cell[data-row="5"][data-col="4"], .cell[data-row="5"][data-col="5"],
.cell[data-row="6"][data-col="0"], .cell[data-row="6"][data-col="1"], .cell[data-row="6"][data-col="2"],
.cell[data-row="7"][data-col="0"], .cell[data-row="7"][data-col="1"], .cell[data-row="7"][data-col="2"],
.cell[data-row="8"][data-col="0"], .cell[data-row="8"][data-col="1"], .cell[data-row="8"][data-col="2"],
.cell[data-row="6"][data-col="6"], .cell[data-row="6"][data-col="7"], .cell[data-row="6"][data-col="8"],
.cell[data-row="7"][data-col="6"], .cell[data-row="7"][data-col="7"], .cell[data-row="7"][data-col="8"],
.cell[data-row="8"][data-col="6"], .cell[data-row="8"][data-col="7"], .cell[data-row="8"][data-col="8"] {
    background-color: var(--cell-alt-bg);
}

.cell-number {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 40px; /* Increased from var(--font-xlarge) to a specific larger size */
    font-weight: normal;
    font-family: 'Arial', Times, serif;
    z-index: 1;
    color: #333;
}

/* Pencil marks */
.pencil-marks, .user-pencil-marks {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    font-size: var(--font-small);
    font-weight: normal;
}

.pencil-marks {
    font-family: 'Arial', Times, serif;
    color: #777;
}

.user-pencil-marks {
    font-family: 'Arial', Times, serif;
    color: var(--secondary-color);
}

.pencil-mark, .user-pencil-mark {
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--gap-medium);
    width: 100%;
    max-width: 280px;
    margin-bottom: 0; /* Remove bottom margin from number pad */
}

.number-pad-wrapper {
    position: relative !important;
    top: auto !important;
}

/* Button styles */
button {
    padding: 10px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: var(--font-medium);
    transition: background-color 0.3s;
    width: 100%;
    text-align: center;
}

button:hover {
    background-color: var(--primary-dark);
}

.number-btn {
    width: 100% !important; /* Fill the grid cell */
    height: 80px !important;
    font-size: 36px;
    font-weight: bold;
    padding: 0;
    background-color: var(--primary-color);
    color: white;
}

.clear-btn {
    width: 100% !important;
    height: auto !important;
    font-size: var(--font-medium);
    padding: 10px;
    grid-column: auto;
}

/* Controls */
.controls-container {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    margin-bottom: 15px;
}

.controls-container button {
    width: 60px !important;
    height: 60px !important;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-xlarge);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* Special button states */
button.magic-pen-active {
    background-color: var(--accent-color);
}

button.pencil-mode-active {
    background-color: var(--secondary-color);
}

#hint-btn {
    background-color: var(--primary-color);
    color: white;
    position: relative;
}

/* Info elements */
.info {
    display: flex;
    gap: var(--gap-xlarge);
    margin-bottom: var(--gap-medium);
    flex-wrap: wrap;
    justify-content: center;
}

.timer, .mistakes, .hints {
    font-size: 18px;
    font-weight: bold;
}

/* Info panel */
.info-panel {
    margin-top: 0;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.info-panel .timer,
.info-panel .mistakes {
    font-size: var(--font-medium);
    font-weight: bold;
    color: var(--text-dark);
}

/* Grid elements */
.grid-container {
    order: 2;
    display: grid;
    grid-template-columns: auto auto;
    gap: var(--gap-xlarge);
    height: 100%;
    margin-left: 0;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    grid-template-columns: auto auto !important;
    position: relative !important;
    height: auto !important;
}

.grid-board-cell {
    grid-column: 1;
}

.grid-controls-cell {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

/* Grid dividers */
.divider-line {
    position: absolute;
    background-color: #000;
    z-index: 1;
    pointer-events: none;
}

.vertical-divider {
    width: 4px;
    top: 0;
    bottom: 0;
}

.horizontal-divider {
    height: 4px;
    left: 0;
    right: 0;
}

/* Hint button styling */
.hint-counter {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: var(--hint-counter-bg);
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid white;
}

.hint-icon {
    font-size: var(--font-large);
}

/* New game button */
.new-game-container {
    margin-top: 0; /* Remove top margin from new game container */
    width: 100%;
    max-width: 280px;
}

#new-game-btn {
    width: 100% !important;
    max-width: 100%; /* Prevent it from exceeding container width */
    height: 60px !important;
    font-size: var(--font-large);
}

#new-game-btn.number-btn {
    grid-column: 1 / span 3;
    grid-row: 4;
    width: 100% !important;
    height: 80px !important;
    font-size: var(--font-xlarge);
    margin-top: 5px;
}

/* Consistent icon sizing */
#hint-btn, #undo-btn, #pencil-mode-btn, #new-game-btn, .clear-btn {
    color: white;
    font-size: var(--font-large);
}

/* Footer styles */
.footer {
    width: 100%;
    text-align: center;
    padding: 10px 0;
    margin-top: 10px;
    border-top: 1px solid #ddd;
}

.footer-links {
    margin-bottom: var(--gap-medium);
}

.footer-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.3s;
}

.footer-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.footer-divider {
    margin: 0 var(--gap-medium);
    color: #999;
}

.copyright {
    font-size: 12px;
    color: var(--text-light);
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: white;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.modal-title {
    font-size: var(--font-large);
    font-weight: bold;
    color: var(--text-dark);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: var(--font-large);
    cursor: pointer;
    color: #7f8c8d;
    padding: 5px;
}

.modal-close:hover {
    color: var(--error-color);
}

.modal-body {
    line-height: 1.6;
}

.modal-body h2 {
    color: var(--text-dark);
    margin-top: var(--gap-large);
    margin-bottom: var(--gap-medium);
}

/* Ad container */
.ad-container {
    min-width: 300px;
    min-height: 250px;
    display: block !important;
    background-color: #f0f0f0;
    height: 250px !important;
    min-height: 250px !important;
    width: 300px !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Form elements */
select {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

/* Styles for larger tablets and small desktops (768px-1137px) */
@media (min-width: 769px) and (max-width: 1137px) {
        #print-btn {
        display: none !important;
    }
    /* Switch to side-by-side layout */
    .game-area {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        align-items: flex-start !important;
        justify-content: center !important;
        gap: 30px !important;
        max-width: 1100px !important;
        margin: 0 auto !important;
    }
    
    /* Adjust grid container for side-by-side layout */
    .grid-container {
        flex-direction: row !important;
        gap: 25px !important;
        justify-content: center !important;
        margin: 0 auto !important;
        align-items: flex-start !important;
    }
    
    /* Center align the header */
    .game-header {
        justify-content: center !important;
        gap: 60px !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
    
    /* Large board size for this range */
    .cell {
        width: 50px !important;
        height: 50px !important;
    }
    
    .cell-number {
        font-size: 28px !important;
    }
    
    /* Normal board border thickness */
    #board {
        border-width: 3px !important;
    }
    
    .vertical-divider {
        width: 3px !important;
    }
    
    .horizontal-divider {
        height: 3px !important;
    }
    
    /* Spacious control area */
    .grid-controls-cell {
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        gap: 15px !important;
    }
    
    /* Controls sizing */
    .controls-container {
        max-width: 240px !important;
        width: 240px !important;
        gap: 10px !important;
        margin: 0 auto 10px auto !important;
    }
    
    .controls-container button {
        width: 50px !important;
        height: 50px !important;
    }
    
    /* Number pad sizing */
    .number-pad {
        max-width: 240px !important;
        width: 240px !important;
        gap: 8px !important;
        margin: 0 auto 10px auto !important;
    }
    
    .number-btn {
        font-size: 26px !important;
    }
    
    .clear-btn {
        height: 40px !important;
        margin-top: 5px !important;
        font-size: 16px !important;
    }
    
    /* New game button */
    .new-game-container {
        max-width: 240px !important;
        width: 240px !important;
        margin: 0 auto !important;
    }
    
    #new-game-btn {
        width: 100% !important;
        height: 50px !important;
        font-size: 20px !important;
    }
    
    /* Info panel */
    .info-panel {
        max-width: 240px !important;
        width: 240px !important;
        padding: 8px 10px !important;
        margin: 0 auto 10px auto !important;
    }
    
    .info-panel .timer,
    .info-panel .mistakes {
        font-size: 16px !important;
    }
    
    /* Ad placement */
    .left-side-content {
        order: 3 !important;
        width: 100% !important;
        max-width: 728px !important;
        margin: 20px auto !important;
    }
    
    .ad-container {
        margin: 0 auto !important;
        width: 100% !important;
    }
    
    /* Responsive adjustments for different screen sizes in this range */
    @media (min-width: 769px) and (max-width: 900px) {
        /* Slightly smaller for smaller screens in this range */
        .cell {
            width: 47px !important;
            height: 47px !important;
        }
        
        .cell-number {
            font-size: 26px !important;
        }
    }
    
    @media (min-width: 901px) and (max-width: 1137px) {
        /* Larger for bigger screens in this range */
        .cell {
            width: 52px !important;
            height: 52px !important;
        }
        
        .cell-number {
            font-size: 30px !important;
        }
    }
}

/* Tablet styles following the same layout pattern as 480px */
@media (min-width: 481px) and (max-width: 768px) {
        #print-btn {
        display: none !important;
    }
    /* Force column layout like on mobile */
    .game-area {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
        max-width: 450px !important;
        margin: 0 auto !important;
        gap: 10px !important;
    }
    
    .grid-container {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        margin: 0 auto !important;
        gap: 10px !important;
        max-width: 450px !important;
    }
    
    /* Board cell styling (similar to 480px) */
    .grid-board-cell {
        width: 100% !important;
        margin: 0 auto !important;
        display: flex !important;
        justify-content: center !important;
    }
    
    /* Controls cell styling (similar to 480px) */
    .grid-controls-cell {
        width: 100% !important;
        max-width: 450px !important;
        margin: 0 auto !important;
        padding: 0 5px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }
    
    /* Board sizing - smaller for tablets */
    #board {
        margin: 0 auto !important;
        border: 3px solid var(--border-dark) !important;
        order: 1 !important;
    }
    
    .cell {
        width: 42px !important;
        height: 42px !important;
    }
    
    .cell-number {
        font-size: 25px !important;
    }
    
    /* Number pad styling (matching 480px pattern) */
    .number-pad {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
        margin: 10px auto !important;
        width: 100% !important;
        max-width: 240px !important;
        order: 2 !important;
    }
    
    .number-btn {
        box-sizing: border-box !important;
        aspect-ratio: 1/1 !important;
        width: 100% !important; 
        height: auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 24px !important;
    }
    
    .clear-btn {
        grid-column: span 3 !important;
        aspect-ratio: auto !important;
        height: 40px !important;
        margin-top: 4px !important;
        font-size: 16px !important;
        width: 100% !important;
    }
    
    /* Controls container (matching 480px pattern) */
    .controls-container {
        display: flex !important;
        justify-content: space-between !important;
        gap: 8px !important;
        width: 100% !important;
        max-width: 240px !important;
        margin: 0 auto !important;
    }
    
    .controls-container button {
        width: 45px !important;
        height: 45px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
    }
    
    /* New game button (matching 480px pattern) */
    .new-game-container {
        width: 100% !important;
        max-width: 240px !important;
        margin: 5px auto !important;
    }
    
    #new-game-btn {
        width: 100% !important;
        height: 45px !important;
        font-size: 18px !important;
        margin-top: 4px !important;
    }
    
    /* Info panel (matching 480px pattern) */
    .info-panel {
        width: 100% !important;
        max-width: 240px !important;
        margin: 5px auto 10px auto !important;
        display: flex !important;
        justify-content: space-between !important;
        padding: 5px 8px !important;
        margin-bottom: 8px !important;
        font-size: 14px !important;
    }
    
    /* Other elements (same as 480px) */
    .left-side-content {
        width: 100% !important;
        max-width: 450px !important;
        margin: 10px auto 15px auto !important;
        order: 3 !important;
    }
    
    /* Header styling */
    .game-header {
        gap: 40px !important;
        margin: 10px auto !important;
        justify-content: center !important;
        margin-left: auto !important;
    }
    
    h1 {
        font-size: 28px !important;
    }
    
    /* Adjustments for different tablet sizes */
    /* Very small tablets (481-520px) */
    @media (min-width: 481px) and (max-width: 520px) {
            #print-btn {
        display: none !important;
    }
        .cell {
            width: 37px !important;
            height: 37px !important;
        }
        
        .cell-number {
            font-size: 22px !important;
        }
        
        .number-pad {
        max-width: 210px !important;
        width: 210px !important;
    }
    
    /* Ensure new game container has exact same width */
    .new-game-container {
        max-width: 210px !important;
        width: 210px !important;
    }
    
    /* Force the new game button to stay within container */
    #new-game-btn {
        width: 100% !important;
        max-width: 210px !important;
        box-sizing: border-box !important;
        padding: 0 5px !important;
    }
    
    /* Info panel and controls with matching width */
    .info-panel, .controls-container {
        max-width: 210px !important;
        width: 210px !important;
    }
    }
    
/* Optimized sizing for 521-620px range to ensure all elements fit on screen */
@media (min-width: 521px) and (max-width: 620px) {
        #print-btn {
        display: none !important;
    }
    /* Smaller board */
    .cell {
        width: 38px !important;
        height: 38px !important;
    }
    
    .cell-number {
        font-size: 23px !important;
    }
    
    /* Reduced gap in grid container to save vertical space */
    .grid-container {
        gap: 5px !important;
    }
    
    /* More compact controls */
    .controls-container {
        max-width: 210px !important;
        width: 210px !important;
        gap: 6px !important;
    }
    
    .controls-container button {
        width: 43px !important;
        height: 43px !important;
    }
    
    /* Smaller number pad */
    .number-pad {
        max-width: 210px !important;
        width: 210px !important;
        gap: 5px !important;
        margin: 5px auto !important;
    }
    
    /* Smaller number buttons */
    .number-btn {
        font-size: 22px !important;
    }
    
    /* Compact clear button */
    .clear-btn {
        height: 35px !important;
        margin-top: 3px !important;
    }
    
    /* Ensure new game button fits */
    .new-game-container {
        max-width: 210px !important;
        width: 210px !important;
        margin: 3px auto !important;
    }
    
    #new-game-btn {
        width: 100% !important;
        max-width: 210px !important;
        height: 40px !important;
        font-size: 17px !important;
        box-sizing: border-box !important;
        padding: 0 5px !important;
    }
    
    /* More compact info panel */
    .info-panel {
        max-width: 210px !important;
        width: 210px !important;
        padding: 4px 6px !important;
        margin-bottom: 5px !important;
    }
    
    /* Reduce space taken by the board borders */
    #board {
        border-width: 2px !important;
    }
    
    .vertical-divider, .horizontal-divider {
        width: 2px !important;
        height: 2px !important;
    }
}
    
/* Ultra-compact layout for 621-768px to ensure new game button visibility */
@media (min-width: 621px) and (max-width: 768px) {
        #print-btn {
        display: none !important;
    }
    /* Significantly smaller board */
    .cell {
        width: 39px !important;
        height: 39px !important;
    }
    
    .cell-number {
        font-size: 23px !important;
    }
    
    /* Minimal gaps between elements */
    .grid-container {
        gap: 5px !important;
    }
    
    /* Reduce height of elements */
    .controls-container {
        max-width: 230px !important;
        width: 230px !important;
        gap: 6px !important;
        margin: 2px auto 4px auto !important;
    }
    
    .controls-container button {
        width: 45px !important;
        height: 45px !important;
    }
    
    /* Compact number pad */
    .number-pad {
        max-width: 230px !important;
        width: 230px !important;
        gap: 5px !important;
        margin: 4px auto !important;
    }
    
    /* Smaller number buttons */
    .number-btn {
        font-size: 22px !important;
    }
    
    /* Minimal clear button */
    .clear-btn {
        height: 34px !important;
        margin-top: 2px !important;
        font-size: 15px !important;
    }
    
    /* Compact new game button */
    .new-game-container {
        max-width: 230px !important;
        width: 230px !important;
        margin: 2px auto 3px auto !important;
    }
    
    #new-game-btn {
        width: 100% !important;
        max-width: 230px !important;
        height: 38px !important;
        font-size: 16px !important;
        padding: 0 5px !important;
        margin: 0 !important;
    }
    
    /* Minimal info panel */
    .info-panel {
        max-width: 230px !important;
        width: 230px !important;
        padding: 3px 8px !important;
        margin: 2px auto 4px auto !important;
        font-size: 13px !important;
    }
    
    .info-panel .timer,
    .info-panel .mistakes,
    .info-panel .hints {
        font-size: 13px !important;
    }
    
    /* Thinner borders */
    #board {
        border-width: 2px !important;
    }
    
    .vertical-divider, .horizontal-divider {
        width: 2px !important;
        height: 2px !important;
    }
    
    /* Smaller SVG icons */
    .svg-icon {
        width: 20px !important;
        height: 20px !important;
    }
    
    /* Adjust left content */
    .left-side-content {
        margin-top: 8px !important;
    }
    
    /* Ensure no unnecessary padding in game container */
    .game-container {
        padding: 5px !important;
        gap: 3px !important;
    }
    
    /* Force minimal space between header and game area */
    .game-header {
        margin-bottom: 3px !important;
    }
    
    .header-divider {
        margin: 2px 0 !important;
    }
}
}


/* Mobile */
@media (max-width: 480px) {
        #print-btn {
        display: none !important;
    }
    /* Core layout fixes */
    body {
        padding-top: 5px;
        padding-bottom: 10px;
        align-items: center !important;
        overflow-x: hidden;
    }
    
    html, body {
        width: 100%;
        max-width: 100vw;
    }
    
    h1 {
        margin-top: 5px;
        margin-bottom: 2px;
    }

    .difficulty {
        margin-bottom: 5px;
    }
    
    /* Game header */
    .game-header {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
        display: flex;
        justify-content: center;
        gap: 30px;
        padding: 0 10px;
        margin: 5px auto 5px auto;
    }
    
    .header-divider {
        margin: 5px 0;
        max-width: 95%;
        margin-left: auto;
        margin-right: auto;
    }
    
    /* Game container */
    .game-container {
        width: 100%;
        margin-left: auto;
        margin-right: auto;
        padding: 0 5px;
        box-sizing: border-box;
        gap: 5px;
        overflow-x: hidden;
    }
    
    /* Game area structure */
    .game-area {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        max-width: 360px;
        margin: 0 auto;
        padding: 0;
        gap: 8px;
        min-height: unset;
        height: auto;
    }
    
    /* Grid structure */
    .grid-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        margin: 0 auto;
        gap: 10px;
        max-width: 360px;
    }
    
    .grid-board-cell {
        width: 100%;
        margin: 0 auto;
        display: flex;
        justify-content: center;
    }
    
    .grid-controls-cell {
        width: 100%;
        max-width: 360px;
        margin: 0 auto;
        padding: 0 5px;
    }
    
    /* Board styling */
    #board {
        margin: 0 auto;
        border: 3px solid var(--border-dark);
        order: 1;
    }
    
    .cell {
        width: 38px;
        height: 38px;
        font-size: 20px;
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
        transition: none;
    }
    
    .cell-number {
        font-size: 24px;
        line-height: 1;
    }
    
    .user-pencil-marks, .pencil-marks {
        font-size: 9px;
        opacity: 0.9;
    }
    
    .user-pencil-mark, .pencil-mark {
        font-weight: 500;
    }
    
    /* Cell highlighting */
    .cell.highlight-same {
        background-color: rgba(1, 39, 99, 0.3) !important;
    }
    
    .cell.highlight-related {
        background-color: rgba(230, 241, 255, 0.4) !important;
    }
    
    .cell.selected {
        background-color: rgba(187, 222, 251, 0.9) !important;
        box-shadow: inset 0 0 0 2px rgba(41, 98, 255, 0.5);
    }
    
    /* Board dividers */
    .vertical-divider {
        width: 3px;
    }
    
    .horizontal-divider {
        height: 3px;
    }
    
    /* Left content/ad area */
    .left-side-content {
        width: 100%;
        max-width: 320px;
        margin: 10px auto 15px auto;
        order: 3;
    }
    
    .ad-container {
        width: 100%;
        max-width: 320px;
        margin: 0 auto;
        overflow: hidden;
        height: auto;
    }
    
    /* Number pad */
    .number-pad {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
        margin: 10px auto;
        width: 100%;
        max-width: 190px;
        order: 2;
    }
    
    .number-btn {
        box-sizing: border-box;
        aspect-ratio: 1/1;
        width: 100% !important; 
        height: auto !important;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        margin: 0;
        font-size: 22px;
    }
    
    .clear-btn {
        grid-column: span 3;
        aspect-ratio: auto;
        height: 40px !important;
        margin-top: 4px;
        font-size: 16px;
        width: 100% !important;
    }
    
    /* Controls */
    .controls-container {
        display: flex;
        justify-content: space-between;
        gap: 8px;
        width: 100%;
        max-width: 190px;
        margin: 0 auto;
    }
    
    .controls-container button {
        width: 38px !important;
        height: 38px !important;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        font-size: 20px;
    }
    
    /* New game button */
    .new-game-container {
        width: 100%;
        max-width: 190px;
        margin: 5px auto;
    }
    
    #new-game-btn {
        grid-column: span 3;
        width: 100% !important;
        height: 45px !important;
        aspect-ratio: auto;
        font-size: 18px;
        margin-top: 4px;
    }
    
    /* Info panel */
    .info-panel {
        width: 100%;
        max-width: 280px;
        margin: 5px auto 10px auto;
        display: flex;
        justify-content: space-between;
        padding: 5px 8px;
        margin-bottom: 8px;
        font-size: 14px;
        border-radius: 4px;
        background-color: rgba(240, 240, 240, 0.5);
    }
    
    .info-panel .timer,
    .info-panel .mistakes,
    .info-panel .hints {
        font-size: 12px;
    }
    
    /* SVG Icons */
    .svg-icon {
        width: 20px;
        height: 20px;
        stroke-width: 2.5;
    }
    
    /* Hint counter */
    .hint-counter {
        width: 18px;
        height: 18px;
        font-size: 11px;
        top: -5px;
        right: -5px;
        border: 1.5px solid white;
        font-weight: bold;
    }
    
    .hint-icon {
        font-size: 20px;
    }
    
    /* Modal styling */
    .modal-content {
        padding: 12px;
        max-height: 85vh;
        width: 92%;
    }
    
    .modal-header {
        padding-bottom: 10px;
        margin-bottom: 10px;
    }
    
    .modal-title {
        font-size: 20px;
    }
    
    .modal-body {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .modal-body h2 {
        font-size: 18px;
        margin-top: 15px;
        margin-bottom: 8px;
    }
    
    .modal-body h3 {
        font-size: 16px;
        margin-top: 12px;
        margin-bottom: 6px;
    }
    
    .modal-body p, .modal-body li {
        margin-bottom: 8px;
    }
    
    /* Completion modal */
    .completion-container {
        padding: 10px 5px;
    }
    
    .completion-header h2 {
        font-size: 24px;
        margin-bottom: 8px;
    }
    
    .completion-header p {
        font-size: 16px;
    }
    
    .completion-stats {
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .completion-stat {
        padding: 8px;
    }
    
    .stat-label {
        font-size: 12px;
        margin-bottom: 3px;
    }
    
    .stat-value {
        font-size: 18px;
    }
    
    .completion-message {
        font-size: 14px;
        margin-bottom: 15px;
        padding: 0 10px;
    }
    
    .completion-buttons {
        flex-direction: column;
        gap: 10px;
        width: 100%;
        max-width: 180px;
        margin: 0 auto;
    }
    
    .completion-btn {
        width: 100%;
        padding: 10px 15px;
        font-size: 15px;
    }
    
    /* Footer */
    .footer {
        padding: 8px 0;
        margin-top: 15px;
        width: 100% !important;
        text-align: center !important;
        margin-left: auto !important;
        margin-right: auto !important;
        margin-top: auto !important;
    }
    
    .footer-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px 0;
        margin-bottom: 5px;
        line-height: 1.6;
    }
    
    .footer-link {
        font-size: 11px;
        padding: 0 6px;
    }
    
    .footer-divider {
        margin: 0 1px;
        font-size: 11px;
    }
    
    .copyright {
        font-size: 10px;
    }
}


/* Focused fix for 480px screens - following successful 360px strategy */
@media (min-width: 361px) and (max-width: 480px) {
        #print-btn {
        display: none !important;
    }
    
    /* Board size adjustments */
    .cell {
        width: 36px;  /* Slightly larger than 360px screens */
        height: 36px;
    }
    
    .cell-number {
        font-size: 22px;
    }
    
    /* Keep number pad proportional */
    .number-pad {
        max-width: 180px;
        gap: 5px;
    }
    
    .number-btn {
        width: 55px !important;
        height: 55px !important;
        font-size: 22px;
    }
    
    /* New game button matching number pad */
    .new-game-container {
        max-width: 180px;
        width: 100%;
    }
    
    #new-game-btn {
        height: 45px !important;
        font-size: 18px;
    }
    
    /* Controls matching number pad */
    .controls-container {
        max-width: 180px;
        gap: 8px;
    }
    
    .controls-container button {
        width: 38px !important;
        height: 38px !important;
    }
    
    /* Info panel matching other elements */
    .info-panel {
        max-width: 180px;
    }
}

/* ===== COMPLETE SOLUTION FOR 360PX MAX-WIDTH SCREENS ===== */
@media (max-width: 360px) {
        #print-btn {
        display: none !important;
    }
    /* Game header optimization */
    .game-header {
        gap: 8px;
        margin: 3px auto;
        padding: 0 5px;
    }
    
    h1 {
        font-size: 20px;
        margin: 2px 0;
    }
    
    .difficulty-label {
        font-size: 12px;
        margin-right: 2px;
    }
    
    #difficulty-select {
        font-size: 12px;
        padding: 3px 5px;
    }
    
    .header-divider {
        margin: 2px 0;
    }
    
    /* Game container & area */
    .game-container {
        padding: 0 2px;
        gap: 3px;
    }
    
    .game-area {
        gap: 4px;
    }
    
    /* Board sizing */
    #board {
        border: 2px solid var(--border-dark);
    }
    
    .cell {
        width: 31px;
        height: 31px;
    }
    
    .cell-number {
        font-size: 19px;
    }
    
    .user-pencil-marks, .pencil-marks {
        font-size: 7px;
    }
    
    /* Divider lines */
    .vertical-divider {
        width: 2px;
    }
    
    .horizontal-divider {
        height: 2px;
    }
    
    /* Grid layout */
    .grid-container {
        gap: 4px;
    }
    
    .grid-controls-cell {
        padding: 0 2px;
    }
    
    /* Info panel */
    .info-panel {
        margin: 2px auto 4px auto;
        padding: 3px 5px;
        font-size: 11px;
        max-width: 145px;
    }
    
    .info-panel .timer,
    .info-panel .mistakes,
    .info-panel .hints {
        font-size: 10px;
    }
    
    /* Controls container */
    .controls-container {
        gap: 5px;
        max-width: 145px;
        margin: 0 auto 3px auto;
    }
    
    .controls-container button {
        width: 30px !important;
        height: 30px !important;
    }
    
    .svg-icon {
        width: 15px;
        height: 15px;
    }
    
    .hint-counter {
        width: 15px;
        height: 15px;
        font-size: 9px;
        top: -3px;
        right: -3px;
    }
    
    /* Number pad */
    .number-pad {
        max-width: 145px;
        gap: 3px;
        margin: 3px auto;
    }
    
    .number-btn {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1/1;
        font-size: 16px;
        font-weight: normal;
    }
    
    .clear-btn {
        grid-column: span 3;
        aspect-ratio: auto;
        height: 28px !important;
        margin-top: 2px;
        font-size: 12px;
    }
    
    /* New game button */
    .new-game-container {
        width: 100%;
        max-width: 145px;
        margin: 2px auto;
    }
    
    #new-game-btn {
        width: 100% !important;
        height: 30px !important;
        font-size: 14px;
        margin-top: 1px;
    }
    
    /* Ad container */
    .left-side-content {
        margin: 5px auto;
    }
    
    .ad-container {
        min-height: 180px;
    }
    
    /* Footer */
    .footer {
        margin-top: 5px;
        padding: 4px 0;
    }
    
    .footer-link {
        font-size: 9px;
    }
    
    .footer-divider {
        font-size: 9px;
    }
    
    .copyright {
        font-size: 8px;
    }
    
    /* Modal updates */
    .modal-content {
        padding: 10px;
    }
    
    .modal-title {
        font-size: 18px;
    }
    
    .modal-body {
        font-size: 13px;
    }
    
    /* Completion modal */
    .completion-header h2 {
        font-size: 20px;
    }
    
    .completion-header p {
        font-size: 13px;
    }
    
    .stat-value {
        font-size: 15px;
    }
    
    .completion-message {
        font-size: 12px;
    }
    
    .completion-btn {
        padding: 7px 10px;
        font-size: 13px;
    }
}

/* Landscape mode for tablets and mobile */
@media (max-width: 768px) and (orientation: landscape) {
        #print-btn {
        display: none !important;
    }
    
    body {
        height: auto;
        padding: 5px 0 20px 0;
    }
    
    h1 {
        margin-top: 5px;
        margin-bottom: 3px;
    }
    
    .game-container {
        padding: 5px;
        padding-bottom: 15px;
        height: auto;
        gap: 5px;
    }
    
    .game-area {
        flex-direction: row;
        align-items: flex-start;
        flex-wrap: wrap;
        justify-content: center;
        margin: 0 0 10px 0;
        gap: 15px;
    }
    
    .cell {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .number-pad {
        margin: 0 auto;
    }
    
    .footer {
        margin-top: 5px;
        padding: 5px 0;
    }
}
/* Force left alignment */
body {
    align-items: flex-start !important;
}

.game-container{
    width: 100%;
    max-width: 1100px;
    margin-left: 0;
    margin-right: auto;
    padding: 0 20px;
    box-sizing: border-box;
}


.game-area {
    justify-content: flex-start !important;
    margin-left: 0 !important;
    width: auto !important;
}

.left-side-content {
    margin-left: 0 !important;
}

.grid-container {
    margin-left: 0 !important;
}

#board {
    margin-left: 0 !important;
}

.footer {
    /* No changes to the footer's original styling */
    width: 100% !important; /* Keep full width */
    text-align: center !important; /* Keep text centered */
    margin-left: auto !important; /* Auto margins for centering */
    margin-right: auto !important;
    padding-left: 0 !important; /* Reset padding */
    margin-top: auto !important; /* Push footer to bottom of flex container */
}

/* Completion Modal Styles */
.completion-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    text-align: center;
}

.completion-header {
    margin-bottom: 20px;
}

.completion-header h2 {
    font-size: 32px;
    color: var(--primary-color);
    margin-bottom: 10px;
    animation: pop 0.5s ease-out;
}

.completion-header p {
    font-size: 18px;
    color: var(--text-dark);
}

.completion-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 25px;
    width: 100%;
    max-width: 400px;
}

.completion-stat {
    background-color: #f5f9ff;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.stat-label {
    display: block;
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 22px;
    font-weight: bold;
    color: var(--text-dark);
}

.completion-message {
    margin-bottom: 25px;
    font-size: 16px;
    color: var(--text-dark);
    max-width: 450px;
}

.completion-buttons {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}

.completion-btn {
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
}

.primary-btn:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.share-btn {
    background-color: #ffffff;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.share-btn:hover {
    background-color: #f0f8ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

/* Animation for the congratulations heading */
@keyframes pop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Responsive styles */
@media (max-width: 600px) {
    .completion-stats {
        grid-template-columns: 1fr;
    }
    
    .completion-buttons {
        flex-direction: column;
        width: 100%;
        max-width: 200px;
    }
    
    .completion-btn {
        width: 100%;
    }
}

.number-btn {
    position: relative; /* Ensure positioning context for the checkmark */
    overflow: visible; /* Allow the checkmark to overflow the button */
}

.number-btn.completed::after {
    content: "✓";
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 16px;
    color: #2ecc71; /* Bright green color */
    font-weight: bold;
    text-shadow: 0px 0px 2px rgba(255, 255, 255, 0.7); /* Make it stand out on blue background */
}

/* Alternative to checkmark - adds a top indicator bar */
.number-btn.completed-alt::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background-color: #2ecc71; /* Bright green color */
    border-radius: 2px 2px 0 0;
}

/* Optional: Slightly dim the button to indicate it's fully used */
.number-btn.completed {
    background-color: #2980b9; /* A bit darker than the primary color */
}

/* SVG icon styles for control buttons */
.svg-icon {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: white;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media print {
    body * {
        visibility: hidden;
    }
    
    #board, #board * {
        visibility: visible;
    }
    
    #board {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
        max-width: 100vw;
    }
    
    /* Hide the decorative divider lines as they might not print well */
    .divider-line {
        border-width: 3px !important;
    }
    
    /* Improve visibility of cells for printing */
    .cell {
        border: 1px solid #000 !important;
    }
    
    /* Make the cell numbers larger and clearer for printing */
    .cell-number {
        font-size: 24px !important;
        font-weight: bold !important;
    }
    
    /* Hide pencil marks if they would be too small to print clearly */
    .user-pencil-marks {
        visibility: visible;
        font-size: 8px !important;
    }
    
    /* Hide any notifications or overlays */
    .notification, .overlay {
        display: none !important;
    }
    
    /* Ensure the board prints at a reasonable size */
    @page {
        size: portrait;
        margin: 1cm;
    }
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-right: 0; /* Ensure it aligns with the right edge */
}

.game-header h1 {
    margin: 0;
    padding: 0;
}

#print-btn {
    height: 37px;
    width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 12px;
    box-sizing: border-box;
    font-size: 16px;
    font-weight: 500;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#print-btn .svg-icon {
    width: 16px;
    height: 16px;
    stroke: white;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

