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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.5s ease;
}

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

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

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

body:not(.beginner):not(.intermediate):not(.advanced) {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

/* ==================== Screen Management ==================== */
.screen {
    display: none;
    width: 100%;
    max-width: 700px;
    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;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    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 #4facfe;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.difficulty-dropdown:hover {
    border-color: #00f2fe;
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
}

.difficulty-dropdown:focus {
    outline: none;
    border-color: #00f2fe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 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, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 172, 254, 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: #f0f9ff;
    padding: 20px;
    border-radius: 15px;
}

.instructions h3 {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    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: #4facfe;
    font-weight: bold;
    margin-right: 8px;
}

/* ==================== Template Badge ==================== */
.template-badge {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    margin: 10px 0;
    display: inline-block;
    font-size: 0.9em;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    animation: fadeInDown 0.5s ease-out;
}

.template-badge span {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==================== Inline Instructions ==================== */
.instructions-inline {
    background: rgba(255, 255, 255, 0.95);
    border-left: 4px solid #4facfe;
    padding: 12px 20px;
    border-radius: 10px;
    margin: 15px 0;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.instructions-inline p {
    margin: 0;
    color: #333;
    font-size: 0.95em;
    line-height: 1.6;
}

.instructions-inline strong {
    color: #4facfe;
    font-weight: 600;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 12px;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
    color: #555;
}

.legend-box {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9em;
}

.legend-box.fixed {
    background: #e3f2fd;
    border: 2px solid #90caf9;
}

.legend-box.editable {
    background: white;
    border: 2px solid #ddd;
}

.legend-box.operator {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.legend-box.blank {
    background: #2d3436;
    border: 2px solid #2d3436;
}

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

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

.stat {
    background: white;
    padding: 15px 20px;
    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;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.timer-stat .stat-value {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff5252 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ==================== Crossword Grid ==================== */
.crossword-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr); /* Default, dynamically set in JS */
    gap: 2px;
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    padding: 10px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    margin: 15px 0;
    max-width: 650px;
    width: 100%;
}

.cell {
    aspect-ratio: 1;
    background: white;
    border: 2px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4em; /* Adjusted for better readability */
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    border-radius: 4px;
    position: relative;
}

.cell.blank {
    background: #1a202c;
    border-color: #1a202c;
    cursor: default;
}

.cell.operator {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    cursor: default;
    font-size: 1.8em; /* Larger operators for visibility */
}

.cell.fixed {
    background: #f0f9ff;
    color: #2d3436;
    cursor: default;
}

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

.cell.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.5), 0 0 20px rgba(102, 126, 234, 0.4);
    transform: scale(1.08);
    z-index: 20;
}

.cell.highlight {
    background: rgba(79, 172, 254, 0.15);
    border-color: #4facfe;
    box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.3);
}

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

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

.cell.clue-num {
    font-size: 0.7em;
    position: absolute;
    top: 2px;
    left: 4px;
    color: #999;
}

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

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

.num-btn:hover {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(79, 172, 254, 0.4);
}

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

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

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

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

/* ==================== Victory Stats ==================== */
.level-stats {
    margin: 30px 0;
    background: #f0f9ff;
    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 {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
}

.victory-title {
    font-size: 2.5em;
    background: linear-gradient(135deg, #4caf50 0%, #8bc34a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    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; }
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .game-title {
        font-size: 2.5em;
    }
    
    .crossword-grid {
        max-width: 95vw;
    }
    
    .cell {
        font-size: 1.4em;
    }
    
    .cell.operator {
        font-size: 1.6em;
    }
    
    .number-pad {
        max-width: 95vw;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .num-btn {
        font-size: 1.5em;
        min-height: 50px;
    }
    
    .instructions-inline {
        font-size: 0.85em;
        padding: 10px 15px;
    }
}

@media (max-width: 480px) {
    .cell {
        font-size: 1.2em;
    }
    
    .cell.operator {
        font-size: 1.4em;
    }
    
    .num-btn {
        font-size: 1.2em;
        min-height: 45px;
    }
    
    .number-pad {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .header-info {
        flex-wrap: wrap;
    }
    
    .instructions-inline {
        font-size: 0.8em;
        padding: 8px 12px;
    }
    
    .stat {
        flex: 1 1 45%;
    }
}
