/* ==================== Base Styles ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    transition: background 0.5s ease;
}

/* Difficulty-based backgrounds */
body.beginner {
    background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
}

body.intermediate {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
}

body.advanced {
    background: linear-gradient(135deg, #fd79a8 0%, #e84393 100%);
}

body:not(.beginner):not(.intermediate):not(.advanced) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ==================== Page Layout with Sidebars ==================== */
.page-wrapper {
    display: grid;
    grid-template-columns: 160px 1fr 160px;
    gap: 20px;
    min-height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.sidebar {
    min-height: 100vh;
}

.sidebar-left,
.sidebar-right {
    display: flex;
    align-items: flex-start;
    padding-top: 80px;
}

.sticky-ad {
    position: sticky;
    top: 20px;
    width: 160px;
    min-height: 600px;
}

.main-content {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
}

/* Responsive: Hide sidebars on tablets and mobile */
@media (max-width: 1024px) {
    .page-wrapper {
        grid-template-columns: 1fr;
        gap: 0;
    }
    
    .sidebar {
        display: none;
    }
}

.container {
    width: 100%;
    max-width: 650px;
}

/* ==================== Screen Management ==================== */
.screen {
    display: none;
    width: 100%;
    max-width: 650px;
    padding: 20px;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.screen.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
}

.screen-content {
    background: white;
    border-radius: 25px;
    padding: 40px 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 500px;
    width: 100%;
    animation: slideIn 0.4s ease-out;
}

.modal {
    animation: modalPop 0.3s ease-out;
}

@keyframes modalPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ==================== Typography ==================== */
.game-title {
    font-size: 3em;
    color: #667eea;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    font-weight: 800;
}

.game-subtitle {
    font-size: 1.2em;
    color: #666;
    margin-bottom: 30px;
}

/* ==================== Difficulty Selector ==================== */
.difficulty-selector {
    margin: 30px 0;
    width: 100%;
}

.difficulty-selector label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #555;
    font-size: 1.1em;
}

.difficulty-dropdown {
    width: 100%;
    padding: 15px;
    font-size: 1.1em;
    border: 2px solid #667eea;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.difficulty-dropdown:hover {
    border-color: #764ba2;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.difficulty-dropdown:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* ==================== Buttons ==================== */
.btn {
    padding: 15px 30px;
    font-size: 1.1em;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    margin: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
}

.btn-small {
    padding: 10px 20px;
    font-size: 0.95em;
}

.btn-danger {
    background: #ff6b6b;
    color: white;
}

.btn-danger:hover {
    background: #ff5252;
}

/* ==================== Instructions ==================== */
.instructions {
    margin-top: 30px;
    text-align: left;
    background: #f8f9ff;
    padding: 20px;
    border-radius: 15px;
}

.instructions h3 {
    color: #667eea;
    margin-bottom: 15px;
}

.instructions ul {
    list-style: none;
    padding-left: 0;
}

.instructions li {
    padding: 8px 0;
    color: #555;
    line-height: 1.5;
}

.instructions li:before {
    content: "✓ ";
    color: #667eea;
    font-weight: bold;
    margin-right: 8px;
}

/* ==================== Game Header ==================== */
.game-header {
    width: 100%;
    max-width: 550px;
    margin-bottom: 20px;
}

.header-info {
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.stat {
    background: white;
    padding: 15px 25px;
    border-radius: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    flex: 1;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.85em;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.6em;
    font-weight: bold;
    color: #667eea;
}

.timer-stat .stat-value {
    color: #ff6b6b;
}

/* ==================== Sudoku Grid ==================== */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0;
    background: #2d3436;
    padding: 4px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    margin-bottom: 25px;
    max-width: 550px;
    width: 100%;
}

.cell {
    aspect-ratio: 1;
    background: white;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.cell:hover:not(.fixed):not(.error) {
    background: #e3f2fd;
    transform: scale(1.05);
    z-index: 10;
}

.cell.fixed {
    background: #f5f5f5;
    color: #2d3436;
    cursor: default;
    font-weight: 700;
}

.cell.selected {
    background: #667eea;
    color: white;
    box-shadow: inset 0 0 0 3px #764ba2;
    transform: scale(1.08);
    z-index: 20;
}

.cell.highlight {
    background: #e8eaf6;
}

.cell.error {
    background: #ffebee;
    color: #c62828;
    animation: shake 0.4s ease-in-out;
}

.cell.correct {
    animation: correctPulse 0.5s ease-out;
}

/* Grid borders for 3x3 boxes */
.cell:nth-child(9n+3),
.cell:nth-child(9n+6) {
    border-right: 3px solid #2d3436;
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 3px solid #2d3436;
}

/* ==================== Number Pad ==================== */
.number-pad {
    display: none; /* Hidden - keyboard input only */
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    max-width: 550px;
    width: 100%;
    margin-bottom: 20px;
}

.num-btn {
    aspect-ratio: 1;
    border: none;
    background: white;
    font-size: 1.8em;
    font-weight: bold;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    color: #667eea;
}

.num-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(102, 126, 234, 0.4);
}

.num-btn:active {
    transform: translateY(-1px);
}

.num-btn.erase-btn {
    background: #ff6b6b;
    color: white;
    font-size: 1.5em;
}

.num-btn.erase-btn:hover {
    background: #ff5252;
}

/* ==================== Game Controls ==================== */
.game-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 550px;
    width: 100%;
}

/* ==================== Victory Stats ==================== */
.level-stats {
    margin: 30px 0;
    background: #f8f9ff;
    padding: 20px;
    border-radius: 15px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-item .stat-label {
    color: #666;
    font-weight: 600;
}

.stat-item .stat-value {
    color: #667eea;
    font-weight: 700;
}

.victory-title {
    font-size: 2.5em;
    color: #4caf50;
    margin-bottom: 10px;
}

.victory-message {
    font-size: 1.2em;
    color: #666;
    margin-bottom: 20px;
}

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

@keyframes correctPulse {
    0% { transform: scale(1); background: white; }
    50% { transform: scale(1.15); background: #c8e6c9; }
    100% { transform: scale(1); background: white; }
}

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

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .game-title {
        font-size: 2.5em;
    }
    
    .sudoku-grid {
        max-width: 95vw;
    }
    
    .cell {
        font-size: 1.5em;
    }
    
    .number-pad {
        max-width: 95vw;
    }
    
    .num-btn {
        font-size: 1.5em;
    }
    
    .game-controls {
        max-width: 95vw;
    }
}

@media (max-width: 480px) {
    .cell {
        font-size: 1.2em;
    }
    
    .num-btn {
        font-size: 1.3em;
    }
}
