:root {
    --bg-color: #f0f8ff;
    --primary-color: #ff6b6b;
    --text-color: #333;
    --tile-color-1: #4ecdc4;
    /* Red-ish */
    --tile-color-2: #ffe66d;
    /* Yellow */
    --tile-color-3: #ff6b6b;
    /* Red */
    --tile-color-4: #1a535c;
    /* Blue */
    --tile-empty: #ddd;

    /* Classic Toy (Default) */
    --wood-frame: #e0c097;
    --wood-bg: #fdf5e6;
    --tile-red: #e74c3c;
    --tile-blue: #3498db;
    --tile-green: #2ecc71;
    --tile-yellow: #f1c40f;
    --tile-orange: #e67e22;
    --tile-purple: #9b59b6;
    --tile-cyan: #1abc9c;
    --tile-pink: #ff9ff3;
}

[data-theme="dark"] {
    --bg-color: #2c3e50;
    --primary-color: #e74c3c;
    --text-color: #ffffff;
    /* FORCE WHITE TEXT */
    --wood-frame: #34495e;
    --wood-bg: #2c3e50;
    --tile-red: #c0392b;
    --tile-blue: #2980b9;
    --tile-green: #27ae60;
    --tile-yellow: #f39c12;
    --tile-orange: #d35400;
}

[data-theme="pastel"] {
    --bg-color: #fdf2e9;
    --primary-color: #ffb8b8;
    --text-color: #636e72;
    --wood-frame: #dfe6e9;
    --wood-bg: #fff;
    --tile-red: #fab1a0;
    --tile-blue: #74b9ff;
    --tile-green: #55efc4;
    --tile-yellow: #ffeaa7;
    --tile-orange: #fdcb6e;
}

[data-theme="neon"] {
    --bg-color: #000;
    --primary-color: #f0f;
    --text-color: #0f0;
    --wood-frame: #111;
    --wood-bg: #000;
    /* Neon Colors */
    --tile-red: #ff0055;
    --tile-blue: #00ccff;
    --tile-green: #39ff14;
    --tile-yellow: #ffff00;
    --tile-orange: #ff5e00;
}

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

body {
    font-family: 'Fredoka', cursive;
    /* Playful font */
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.game-container {
    background-color: #fff;
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 600px;
    width: 95%;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    position: relative;
}

h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin: 0;
    flex-grow: 1;
}

.settings-icon {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    transition: transform 0.3s;
}

.settings-icon:hover {
    transform: rotate(45deg);
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #555;
}

.main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

@media (min-width: 600px) {
    .main-content {
        flex-direction: row;
        justify-content: space-around;
        align-items: flex-start;
    }
}

.panel {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 15px;
    border: 2px solid #eee;
}

.grid-3x3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    background-color: var(--wood-frame);
    padding: 8px;
    border-radius: 10px;
}

/* Stats Bar */
.stats-bar {
    width: 100%;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.5rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-around;
    font-size: 0.9rem;
    color: var(--text-color);
}

.stats-bar.hidden {
    display: none;
}

/* Play Area */
.main-grid {
    width: 300px;
    height: 300px;
}

.tile {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0;
    /* Hidden by default for kids */
    font-weight: bold;
    color: white;
    /* Text color for advanced mode */
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.3s, box-shadow 0.3s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    user-select: none;
}

/* Hint Highlight */
.tile.hint-suggested {
    animation: pulse 1.5s infinite;
    z-index: 10;
    border: 3px solid white;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
    }
}

.mode-advanced .tile {
    font-size: 2rem;
    /* Show numbers in advanced mode */
}


.tile::after {
    /* Shine effect for plastic/wood look */
    content: '';
    position: absolute;
    top: 5%;
    left: 5%;
    width: 90%;
    height: 40%;
    border-radius: 5px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0));
    pointer-events: none;
}

.tile.empty {
    background-color: transparent;
    /* Show background frame */
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: default;
}

.tile.empty::after {
    display: none;
}

.tile:hover:not(.empty) {
    transform: scale(1.02);
}

/* Target Area */
.mini-grid {
    width: 150px;
    height: 150px;
    gap: 4px;
    padding: 4px;
}

.mini-grid .tile {
    cursor: default;
    box-shadow: none;
    font-size: 0;
}

.mini-grid .tile:hover {
    transform: none;
}

/* Colors (Up to 8 for Advanced) */
.color-red {
    background-color: var(--tile-red);
}

.color-blue {
    background-color: var(--tile-blue);
}

.color-green {
    background-color: var(--tile-green);
}

.color-yellow {
    background-color: var(--tile-yellow);
}

.color-orange {
    background-color: var(--tile-orange);
}

.color-purple {
    background-color: var(--tile-purple);
}

/* New */
.color-cyan {
    background-color: var(--tile-cyan);
}

/* New */
.color-pink {
    background-color: var(--tile-pink);
}

/* New */

.controls {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.hint-group {
    display: flex;
    gap: 1rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(255, 107, 107, 0.3);
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(255, 107, 107, 0.4);
}

.btn-highlight {
    background-color: var(--tile-green);
    color: white;
    border: none;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.3);
    transition: all 0.2s;
}

.btn-highlight:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(46, 204, 113, 0.4);
}

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

.btn-secondary {
    background-color: var(--wood-frame);
    color: var(--text-color);
    border: 2px solid #ccc;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: #dcdde1;
}

/* Settings Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #888;
}

.setting-item {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.range-container {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: #666;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    position: relative;
}

.toggle-switch input {
    display: none;
}

.slider {
    width: 40px;
    height: 22px;
    background-color: #ccc;
    border-radius: 22px;
    position: relative;
    transition: .4s;
    display: inline-block;
}

.slider:before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(18px);
}

.label-text {
    font-size: 0.9rem;
    color: #666;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    background: white;
    padding: 3rem;
    border-radius: 20px;
    text-align: center;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Shared styles for Game Headers */
.home-btn {
    text-decoration: none;
    font-size: 1.5rem;
    margin-right: 1rem;
    padding: 5px 10px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    transition: transform 0.2s, background 0.2s;
}

.home-btn:hover {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .home-btn {
    background: rgba(255, 255, 255, 0.1);
}

/* ==================== MOBILE HEIGHT OPTIMIZATION ==================== */
/* Optimized for iPhone and short viewports to fit all content without scrolling */

@media (max-height: 700px) {
    .game-container {
        padding: 1rem;
    }

    header {
        margin-bottom: 0.75rem;
    }

    h1 {
        font-size: 1.75rem;
    }

    .main-content {
        gap: 0.75rem;
    }

    .panel {
        padding: 0.5rem;
    }

    h2 {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
    }

    /* Smaller target grid */
    .mini-grid {
        width: 120px;
        height: 120px;
        gap: 3px;
        padding: 3px;
    }

    /* Slightly smaller main grid */
    .main-grid {
        width: 260px;
        height: 260px;
        gap: 6px;
        padding: 6px;
    }

    .controls {
        margin-top: 0.75rem;
        gap: 0.5rem;
    }

    .btn-primary,
    .btn-highlight,
    .btn-secondary {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    .btn-icon.big-icon {
        font-size: 1.5rem;
        padding: 0.5rem;
    }

    .hint-group {
        gap: 0.5rem;
    }
}

/* Extra short screens (iPhone SE) */
@media (max-height: 600px) {
    .game-container {
        padding: 0.75rem;
    }

    header {
        margin-bottom: 0.5rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .main-content {
        gap: 0.5rem;
    }

    /* Even smaller grids */
    .mini-grid {
        width: 100px;
        height: 100px;
    }

    .main-grid {
        width: 220px;
        height: 220px;
    }

    .controls {
        margin-top: 0.5rem;
    }
}