:root {
    --neon-green: #00ff00;
    --neon-blue: #00ffff;
    --dark-bg: #001a1a;
    --grid-bg: #002626;
    --cell-bg-0: #1a1a1a;
    --cell-bg-1: #4a4a4a;
    --cell-text: #ffffff;
    --button-bg: #004d4d;
    --button-hover: #008080;
    --neon-red: #ff3333;
    --border-0: #00aa00; /* Light blue border for 0 tiles */
    --border-1: #25aa00; /* Orange border for 1 tiles */
    --cell-text-0: #00ddff;
    --cell-text-1: #00ff33;
}

body {
    background-color: var(--dark-bg);
    color: var(--neon-blue);
    font-family: 'Orbitron', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    font-size: 16px;
    line-height: 1.5;
    position: relative;
}

.container {
    background-color: var(--grid-bg);
    border: 2px solid var(--neon-blue);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 20px var(--neon-blue);
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 100vh;
    padding: 20px;
    box-sizing: border-box;
}

#controls {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
}

#grid-container {
    display: grid;
    gap: 10px;
    max-width: 70vmin;
    max-height: 70vmin;
    aspect-ratio: 1 / 1;
    --container-size: 70vmin;
    --cell-size: calc(var(--container-size) / 3);
    --font-size: 5vmin;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    font-size: var(--font-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    border-radius: 1vmin;
    cursor: pointer;
    transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
    backface-visibility: hidden;
    transform: translateZ(0);
    will-change: transform;
    border: 2px solid;
}

.cell-0 {
    background-color: var(--cell-bg-0);
    color: var(--cell-text-0);
    border-color: var(--border-0);
}

.cell-1 {
    background-color: var(--cell-bg-1);
    color: var(--cell-text-1);
    border-color: var(--border-1);
}

.cell:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px var(--neon-blue);
}

.cell.flipping {
    animation: flip 0.3s ease;
}

@keyframes flip {
    0% { transform: perspective(400px) rotateX(0); }
    50% { transform: perspective(400px) rotateX(90deg); }
    100% { transform: perspective(400px) rotateX(0); }
}

button {
    background-color: var(--button-bg);
    color: var(--neon-blue);
    border: 2px solid var(--neon-blue);
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 16px;
    font-family: 'Orbitron', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
    font-size: 1rem;
    padding: 10px 15px;
    min-width: 100px;
}

button:hover {
    background-color: var(--button-hover);
    color: var(--neon-green);
    box-shadow: 0 0 15px var(--neon-blue);
}

#moves, #timer {
    font-size: 24px;
    margin: 10px 0;
    text-shadow: 0 0 5px var(--neon-green);
    color: var(--neon-green);
}

#win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 10, 10, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#win-overlay.hidden {
    display: none !important;
}

#win-message {
    background-color: var(--grid-bg);
    border: 2px solid var(--neon-blue);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 0 30px var(--neon-blue);
}

#top-right-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 10px;
    z-index: 1000;
}

#top-right-controls button {
    background: none;
    border: none;
    color: var(--neon-blue);
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#top-right-controls button:hover {
    color: var(--neon-green);
    text-shadow: 0 0 15px var(--neon-blue);
}

#settings-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--grid-bg);
    border: 2px solid var(--neon-blue);
    border-radius: 10px;
    padding: 20px;
    z-index: 1000;
}

.hidden {
    display: none !important;
}

@keyframes neon-pulse {
    0% {
        box-shadow: 0 0 5px var(--neon-green);
    }
     50% {
        box-shadow: 0 0 20px var(--neon-green), 0 0 30px var(--neon-green);
    }
    100% {
        box-shadow: 0 0 5px var(--neon-green);
    }
}

.container {
    animation: neon-pulse 2s infinite;
}

#level-select {
    display: grid;
    gap: 10px;
    padding: 20px;
    background-color: var(--grid-bg);
    border-radius: 10px;
    box-shadow: 0 0 20px var(--neon-blue);
}

.level-cell {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 5px;
    border: 2px solid transparent;
}

.level-cell.locked {
    background-color: #8B3A3A; /* Darker, more muted red */
    color: #D3D3D3; /* Light grey text for a softer contrast */
    cursor: not-allowed;
    opacity: 0.7; /* Slightly transparent to further mute the appearance */
}

.level-cell.locked:hover {
    transform: none;
    box-shadow: none;
}

.level-cell.unlocked {
    background-color: #2c3e50;
    color: #ecf0f1;
}

.level-cell.completed {
    background-color: #27ae60;
    color: #ecf0f1;
}

.level-cell.unlocked:hover,
.level-cell.completed:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.level-cell.easy { border-color: #2ecc71; }
.level-cell.medium { border-color: #3498db; }
.level-cell.hard { border-color: #e74c3c; }

#settings-menu .setting-option {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#settings-menu select, #settings-menu button {
    background-color: var(--button-bg);
    color: var(--neon-blue);
    border: 2px solid var(--neon-blue);
    border-radius: 5px;
    padding: 5px 10px;
    font-size: 16px;
    font-family: 'Orbitron', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
}

#settings-menu select:hover, #settings-menu button:hover {
    background-color: var(--button-hover);
    color: var(--neon-green);
    box-shadow: 0 0 15px var(--neon-blue);
}

/* Add these new CSS variables for themes */
.theme-default {
    --neon-green: #00ff00;
    --neon-blue: #00ffff;
    --dark-bg: #001a1a;
    --grid-bg: #002626;
    --cell-bg-0: #003366;
    --cell-bg-1: #006633;
    --cell-text: #ffffff;
    --button-bg: #004d4d;
    --button-hover: #008080;
}

.theme-light {
    --neon-green: #00cc00;
    --neon-blue: #0066cc;
    --dark-bg: #f0f0f0;
    --grid-bg: #ffffff;
    --cell-bg-0: #e6f3ff;
    --cell-bg-1: #ffe6e6;
    --cell-text-0: #0066cc;
    --cell-text-1: #cc0000;
    --button-bg: #e6e6e6;
    --button-hover: #cccccc;
    --border-0: #0099ff;
    --border-1: #ff3333;
}

.theme-dark {
    --neon-green: #33ff33;
    --neon-blue: #33ffff;
    --dark-bg: #000000;
    --grid-bg: #1a1a1a;
    --cell-bg-0: #002233;
    --cell-bg-1: #003300;
    --cell-text: #ffffff;
    --button-bg: #333333;
    --button-hover: #4d4d4d;
    --border-0: #66ccff; /* Lighter blue for dark theme */
    --border-1: #ff9933; /* Lighter orange for dark theme */
}

.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--grid-bg);
    color: var(--neon-blue);
    padding: 20px;
    border: 2px solid var(--neon-blue);
    border-radius: 10px;
    width: 80%;
    max-width: 500px;
}

.modal-content h2, .modal-content h3 {
    color: var(--neon-green);
}

.modal-content ul {
    text-align: left;
    margin-bottom: 20px;
}

.modal-content li {
    margin-bottom: 10px;
}

#close-tips {
    display: block;
    margin: 20px auto 0;
}

#score-display {
    font-size: 24px;
    margin-top: 10px;
}

#game-over-screen {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--grid-bg);
    border: 2px solid var(--neon-blue);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
}

#high-scores-list {
    text-align: left;
    max-height: 200px;
    overflow-y: auto;
    margin: 20px 0;
}

#bonus-time {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 36px;
    color: var(--neon-green);
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

#bonus-time.show {
    opacity: 1;
}

/* If you have any specific styles for story mode, update them here */
.story-mode .cell {
    /* Remove any conflicting styles and ensure it matches the general cell style */
    width: 60px;
    height: 60px;
    border: 2px solid var(--neon-blue);
}

.theme-light .cell:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

#difficulty {
    background-color: #2c3e50;
    color: #ecf0f1;
    border: 2px solid #3498db;
    padding: 10px;
    font-size: 16px;
    font-family: 'Orbitron', sans-serif;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#difficulty:hover {
    background-color: #34495e;
}

#difficulty:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.5);
}

#difficulty option {
    background-color: #2c3e50;
    color: #ecf0f1;
}

/* Responsive grid container */
#grid-container {
    display: grid;
    gap: 5px;
    margin: 0 auto;
    max-width: 90vmin; /* Use vmin for square aspect ratio */
    max-height: 90vmin;
}

.cell {
    aspect-ratio: 1 / 1;
    font-size: 4vmin;
}

/* Responsive buttons and controls */
button, select {
    font-size: 1rem;
    padding: 10px 15px;
    margin: 5px;
    min-width: 100px;
}

/* Media queries for different screen sizes */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }

    #grid-container {
        max-width: 95vmin;
        max-height: 95vmin;
    }

    .cell {
        font-size: 5vmin; /* Increased from 4vmin */
    }

    button, select {
        font-size: 0.9rem;
        padding: 8px 12px;
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 12px;
    }

    #grid-container {
        max-width: 98vmin;
        max-height: 98vmin;
    }

    .cell {
        font-size: 5.5vmin; /* Increased from 4.5vmin */
    }

    button, select {
        font-size: 0.8rem;
        padding: 6px 10px;
        min-width: 60px;
    }
}

/* Adjust layout for mobile */
@media (max-width: 768px) {
    #game-container, #level-select {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    #controls {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
}

.landscape #game-container {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
}

.portrait #game-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

@media (max-width: 768px) {
    button, select, .level-cell {
        min-height: 44px; /* Minimum touch target size */
        min-width: 44px;
    }
}

@media (max-width: 768px) {
    #grid-container {
        width: 95vmin;
        height: 95vmin;
        gap: 2.2vmin; /* Increase gap for smaller screens */
    }
}

@media (max-width: 480px) {
    #grid-container {
        width: 98vmin;
        height: 98vmin;
        gap: 2.5vmin; /* Further increase gap for very small screens */
    }
}

#score-container {
    position: absolute;
    top: 10px;
    left: 10px;
    text-align: left;
    font-size: 1.2rem;
    color: var(--neon-green);
}

#score-display, #high-score-display {
    margin-bottom: 5px;
}

.cell-0, .cell-1 {
    transition: background-color 0.15s ease;
}

#top-controls {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
}

#score-container {
    display: flex;
    flex-direction: column;
}

#top-right-controls {
    display: flex;
    gap: 10px;
}

#grid-container {
    display: grid;
    gap: 10px;
    max-width: 70vmin;
    max-height: 70vmin;
    aspect-ratio: 1 / 1;
    --container-size: 70vmin;
    --cell-size: calc(var(--container-size) / 3);
    --font-size: 5vmin;
}

#bottom-controls {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-top: 20px;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    font-size: var(--font-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    border-radius: 1vmin;
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.15s ease;
    backface-visibility: hidden;
    transform: translateZ(0);
    will-change: transform;
}

@media (max-height: 600px) {
    #grid-container {
        max-width: 60vmin;
        max-height: 60vmin;
        --container-size: 60vmin;
    }
}

@media (max-width: 480px) {
    #grid-container {
        max-width: 80vmin;
        max-height: 80vmin;
        --container-size: 80vmin;
    }
}

#title-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100%;
}

