:root {
    --primary-color: #007bff;
    --secondary-color: #0056b3;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --selected-color: #cce5ff;
    --highlight-color: #e6f3ff;
    --border-radius: 8px;
    --box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    --transition: all 0.3s ease;
    --zoom-level: 1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #e0eafc, #cfdef3);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    color: #333;
}

.user-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    padding: 10px;
}

.user-controls select,
.user-controls button {
    background: #007bff;
    border: none;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    padding: 8px 12px;
    border-radius: var(--border-radius);
}

.user-controls select {
    background-color: var(--secondary-color);
}

.user-controls button:hover {
    transform: scale(1.05);
}

.container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 15px;
    gap: 20px;
    flex-wrap: wrap;
}

.game-area {
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    width: 100%;
    max-width: 800px;
}

.controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.stats {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--dark-color);
    background: var(--light-color);
    padding: 10px 15px;
    border-radius: var(--border-radius);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-item i {
    font-size: 1rem;
}

.grid-container {
    margin: 10px auto;
    width: 100%;
    max-width: 100%;
    transform: scale(var(--zoom-level));
    transform-origin: center top;
    transition: transform 0.2s ease;
    /* overflow: auto; */
    border: none;
    display: flex;
    justify-content: center;
}

.grid {
    display: grid;
    gap: 1px;
    background-color: #333;
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 100%;
    aspect-ratio: 1 / 1;
}

.cell {
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    aspect-ratio: 1;
    font-size: 1.5rem;
    user-select: none;
    transition: var(--transition);
    position: relative;
    border: 1px solid #999;
}

.grid-size-36 .cell { font-size: 0.5rem; }
.grid-size-25 .cell { font-size: 0.6rem; }
.grid-size-20 .cell { font-size: 0.8rem; }
.grid-size-18 .cell { font-size: 0.9rem; }
.grid-size-16 .cell { font-size: 1rem; }
.grid-size-15 .cell { font-size: 1rem; }
.grid-size-14 .cell { font-size: 1.1rem; }
.grid-size-12 .cell { font-size: 1.2rem; }
.grid-size-10 .cell { font-size: 1.3rem; }
.grid-size-9 .cell { font-size: 1.5rem; }
.grid-size-8 .cell { font-size: 1.6rem; }
.grid-size-6 .cell { font-size: 1.8rem; }
.grid-size-4 .cell { font-size: 2rem; }

.cell:hover:not(.fixed) {
    transform: scale(1.05);
    z-index: 2;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
}

.cell.fixed {
    background-color: #f0f0f0;
    font-weight: 600;
    color: var(--dark-color);
}

.cell.error {
    background-color: #ffebee;
    color: var(--danger-color);
}

.cell.correct {
    background-color: #e8f5e9;
    color: var(--success-color);
}

.cell.selected {
    border: 3px solid var(--primary-color);
    background-color: var(--selected-color);
    z-index: 3;
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.5);
}

.cell.highlight {
    background-color: var(--highlight-color);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 3px 10px rgba(0,0,0,0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cell.duplicate {
    background-color: #fff3e0;
}

.cell-notes {
    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: 0.5em;
    padding: 2px;
    pointer-events: none;
}

.note-number {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
    gap: 8px;
    background: white;
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 20px;
    align-self: flex-start;
    max-width: 300px;
    width: 100%;
}

.number-btn,
.zoom-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 8px;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(12px, 2vw, 16px);
}

.number-btn:hover,
.zoom-btn:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.number-btn:active,
.zoom-btn:active {
    transform: translateY(0);
}

.number-btn.clear {
    background-color: var(--danger-color);
}

.number-btn.notes {
    background-color: var(--warning-color);
    color: var(--dark-color);
}

.zoom-btn {
    background-color: #17a2b8;
}

.zoom-value {
    padding: 8px;
    background-color: var(--light-color);
    border-radius: var(--border-radius);
    text-align: center;
    font-size: clamp(12px, 2vw, 16px);
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 25px;
    border: 2px solid var(--primary-color);
    text-align: center;
    border-radius: var(--border-radius);
    box-shadow: 0 5px 25px rgba(0,0,0,0.3);
    z-index: 1000;
    max-width: 400px;
    width: 90%;
    animation: fadeIn 0.3s ease;
}

.popup h2 {
    margin-bottom: 15px;
    color: var(--primary-color);
}

.popup p {
    margin-bottom: 20px;
    line-height: 1.6;
}

.popup-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.popup button {
    padding: 10px 20px;
    border-radius: var(--border-radius);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.popup button.primary {
    background-color: var(--primary-color);
    color: white;
}

.popup button.secondary {
    background-color: var(--light-color);
    color: var(--dark-color);
}

.popup button.close {
    background-color: var(--danger-color);
    color: white;
}

.popup button:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

#loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--primary-color);
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

select,
button {
    padding: 10px 15px;
    font-size: clamp(14px, 1.5vw, 16px);
    border-radius: var(--border-radius);
    border: none;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    min-width: 100px;
    text-align: center;
}

select:hover,
button:hover {
    background-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

select:focus,
button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.3);
}

#fullscreen-btn {
    background-color: var(--success-color);
}

#fullscreen-btn:hover {
    background-color: #218838;
}

#hint-btn {
    background-color: var(--warning-color);
    color: var(--dark-color);
}

#hint-btn:hover {
    background-color: #e0a800;
}

#solve-btn {
    background-color: var(--danger-color);
}

#solve-btn:hover {
    background-color: #c82333;
}

#save-btn {
    background-color: #6f42c1;
}

#save-btn:hover {
    background-color: #5a32a3;
}

#print-btn {
    background-color: #17a2b8;
}

#print-btn:hover {
    background-color: #138496;
}

#history-btn {
    background-color: #fd7e14;
}

#history-btn:hover {
    background-color: #e06c00;
}

.game-history {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.game-history table {
    width: 100%;
    border-collapse: collapse;
}

.game-history th,
.game-history td {
    padding: 8px;
    border: 1px solid #ddd;
    text-align: center;
}

.game-history th {
    background-color: var(--primary-color);
    color: white;
}

.confirmation-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: 0 5px 25px rgba(0,0,0,0.3);
    z-index: 2000;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.shake {
    animation: shake 0.5s;
}

.pulse {
    animation: pulse 1.5s infinite;
}

.dark-theme {
    background: linear-gradient(135deg, #121212, #1e1e1e);
    color: #f0f0f0;
}

.dark-theme .game-area,
.dark-theme .number-pad,
.dark-theme .game-history {
    background-color: #2d2d2d;
    color: #f0f0f0;
}

.dark-theme .cell {
    background-color: #3d3d3d;
    color: #f0f0f0;
}

.dark-theme .cell.fixed {
    background-color: #333;
    color: #f0f0f0;
}

.dark-theme .cell.selected {
    background-color: #1a3d5a;
    border-color: #00b4ff;
}

.dark-theme .cell.highlight {
    background-color: #2a2a2a;
}

.dark-theme .cell.correct {
    background-color: #1e3d1e;
    color: #a0f0a0;
}

.dark-theme .cell.error {
    background-color: #3d1e1e;
    color: #f0a0a0;
}

.dark-theme .cell.duplicate {
    background-color: #3d2e1e;
}

.dark-theme .stats {
    background-color: #333;
    color: #f0f0f0;
}

.dark-theme .popup,
.dark-theme .confirmation-dialog {
    background-color: #2d2d2d;
    color: #f0f0f0;
    border-color: #0066cc;
}

.dark-theme select,
.dark-theme button {
    color: #f0f0f0;
}

.dark-theme .number-btn.notes {
    color: #121212;
}

.dark-theme .note-number {
    color: #aaa;
}

.dark-theme .zoom-btn {
    background-color: #17a2b8;
}

body.fullscreen .container {
    margin: 0;
    padding: 15px;
    max-width: 100%;
    height: 100vh;
    align-items: flex-start;
}

body.fullscreen .game-area {
    max-width: 100%;
    padding: 15px;
    flex: 1;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -60%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}

@keyframes spin {
   0% { transform: rotate(0deg); }
   100% { transform: rotate(360deg); }
}

@keyframes shake {
   0%, 100% { transform: translateX(0); }
   10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
   20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes pulse {
   0% { transform: scale(1); }
   50% { transform: scale(1.05); }
   100% { transform: scale(1); }
}

@media print {
    body * { visibility: hidden; }
    #print-area, #print-area * { visibility: visible; }
    #print-area { position: absolute; left: 0; top: 0; width: 100%; }
    .no-print { display: none !important; }
    .grid { width: 100% !important; height: auto !important; transform: none !important; }
    .cell { font-size: 20px !important; }
}

/* Killer mode cage borders and sum labels */
.cell {
    position: relative;
}
.cell .cage-box {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 0 solid #e67e22; /* killer cage border color */
    box-sizing: border-box;
}
.cell .cage-label {
    position: absolute;
    top: 2px;
    left: 4px;
    font-weight: 600;
    opacity: 0.9;
    user-select: none;
    pointer-events: none;
    font-size: 0.7em;
    color: #007bff;
}

/* Responsive design for different screen sizes */
@media (min-width: 1200px) {
    .container {
        flex-direction: row;
        align-items: flex-start;
    }
    .number-pad {
        position: sticky;
        top: 100px;
    }
}

@media (max-width: 1199px) {
    .container {
        flex-direction: column;
        align-items: center;
    }
    .number-pad {
        position: relative;
        top: auto;
        max-width: 100%;
    }
    .game-area {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
        gap: 15px;
    }
    
    .game-area {
        padding: 15px;
        gap: 12px;
    }
    
    .controls {
        gap: 8px;
    }
    
    select, button {
        padding: 8px 12px;
        font-size: 14px;
        min-width: 80px;
    }
    
    .stats {
        font-size: 0.8rem;
        padding: 8px 12px;
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    
    .grid-container {
        margin: 5px auto;
    }
    
    /* Adjust cell font sizes for mobile */
    .grid-size-36 .cell { font-size: 0.4rem; }
    .grid-size-25 .cell { font-size: 0.5rem; }
    .grid-size-20 .cell { font-size: 0.6rem; }
    .grid-size-18 .cell { font-size: 0.7rem; }
    .grid-size-16 .cell { font-size: 0.8rem; }
    .grid-size-15 .cell { font-size: 0.8rem; }
    .grid-size-14 .cell { font-size: 0.9rem; }
    .grid-size-12 .cell { font-size: 1rem; }
    .grid-size-10 .cell { font-size: 1.1rem; }
    .grid-size-9 .cell { font-size: 1.2rem; }
    .grid-size-8 .cell { font-size: 1.3rem; }
    .grid-size-6 .cell { font-size: 1.5rem; }
    .grid-size-4 .cell { font-size: 1.7rem; }
    
    .cell .cage-label {
        font-size: 0.6em;
    }
    
    .popup {
        padding: 20px;
    }
    
    .popup-buttons {
        flex-direction: column;
    }
}

@media (max-width: 576px) {
    .container {
        padding: 5px;
    }
    
    .game-area {
        padding: 10px;
    }
    
    .user-controls {
        gap: 5px;
    }
    
    .user-controls select,
    .user-controls button {
        padding: 6px 10px;
        font-size: 0.9rem;
    }
    
    .controls {
        gap: 5px;
    }
    
    select, button {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 70px;
    }
    
    .stats {
        font-size: 0.75rem;
        padding: 6px 10px;
    }
    
    .number-pad {
        padding: 10px;
        gap: 5px;
    }
    
    .number-btn,
    .zoom-btn {
        min-width: 35px;
        min-height: 35px;
        padding: 6px;
    }
    
    .zoom-value {
        min-width: 35px;
        min-height: 35px;
        padding: 6px;
    }
    
    /* Further adjust cell font sizes for very small screens */
    .grid-size-36 .cell { font-size: 0.35rem; }
    .grid-size-25 .cell { font-size: 0.45rem; }
    .grid-size-20 .cell { font-size: 0.55rem; }
    .grid-size-18 .cell { font-size: 0.6rem; }
    .grid-size-16 .cell { font-size: 0.7rem; }
    .grid-size-15 .cell { font-size: 0.7rem; }
    .grid-size-14 .cell { font-size: 0.8rem; }
    .grid-size-12 .cell { font-size: 0.9rem; }
    .grid-size-10 .cell { font-size: 1rem; }
    .grid-size-9 .cell { font-size: 1.1rem; }
    .grid-size-8 .cell { font-size: 1.2rem; }
    .grid-size-6 .cell { font-size: 1.4rem; }
    .grid-size-4 .cell { font-size: 1.6rem; }
    
    .cell .cage-label {
        font-size: 0.5em;
        top: 1px;
        left: 2px;
    }
}

/* Push Button */


body.paused .grid-container,
body.paused #number-pad {
  display: none !important;
}


body.paused .game-area {
  filter: blur(5px);
  pointer-events: none;
}
