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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(45deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    color: white;
    overflow-x: hidden;
    padding: 0;
}

.game-container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 500px;
    width: 100%;
    text-align: center;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

.game-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    pointer-events: none;
}

.header {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.title {
    font-size: 1.8rem;
    margin-bottom: 0.2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 255, 255, 0.3); }
    to { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5), 0 0 30px rgba(255, 255, 255, 0.5); }
}

.navigation {
    margin-bottom: 0.3rem;
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    flex-wrap: wrap;
}

.nav-button {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-decoration: none;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    font-size: 0.75rem;
    backdrop-filter: blur(5px);
}

.nav-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    color: white;
}

.game-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-height: 0;
}

.button-container {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
}

.share-button,
.control-button {
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    font-weight: bold;
    border: none;
    border-radius: 15px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    touch-action: manipulation;
    flex: 1;
    min-width: 0;
    max-width: 120px;
}

.share-button {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
}

.control-button {
    background: linear-gradient(45deg, #8e44ad, #9b59b6);
}

.share-button:hover,
.control-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.share-button:active,
.control-button:active {
    transform: scale(0.95);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* Stats Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #2c2c2e;
    color: #fff;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 480px;
    position: relative;
    text-align: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
}

.modal-close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin: 20px 0;
}

.distribution-grid {
    display: grid;
    gap: 8px;
    margin-top: 15px;
    text-align: left;
}

.dist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
}

.dist-bar {
    background-color: #4a4a4c;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    text-align: right;
    min-width: 25px;
    transition: width 0.5s ease-in-out;
}

.dist-bar.highlight {
    background-color: #538d4e; /* Green for the current game's score */
}

/* Combined game mode and difficulty selector */
.game-mode-selector,
.difficulty-selector {
    position: relative;
    z-index: 1;
    margin-bottom: 0.5rem;
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

/* Mode button for daily mode - styled like Alpha-Bit */
.mode-button {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    font-weight: bold;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.mode-button.active {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

.mode-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.difficulty-button {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    font-weight: bold;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.difficulty-button.active {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

.difficulty-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.new-game-button {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    font-weight: bold;
    border: none;
    border-radius: 20px;
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 1px;
    touch-action: manipulation;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.new-game-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.new-game-button:active {
    transform: scale(0.95);
}

.game-info {
    position: relative;
    z-index: 1;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.moves-left {
    font-size: 0.9rem;
    font-weight: bold;
    color: #ffeb3b;
    transition: all 0.3s ease;
}

.moves-left.warning {
    color: #ff9800;
    animation: pulse 1s ease-in-out infinite;
}

.moves-left.danger {
    color: #f44336;
    animation: pulse 0.5s ease-in-out infinite;
}

.difficulty {
    font-size: 0.75rem;
    color: #e0e0e0;
}

.message {
    position: relative;
    z-index: 1;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.message.success {
    background: rgba(76, 175, 80, 0.3);
    border-color: rgba(76, 175, 80, 0.5);
    animation: successPulse 0.5s ease-in-out;
}

.message.error {
    background: rgba(244, 67, 54, 0.3);
    border-color: rgba(244, 67, 54, 0.5);
    animation: shake 0.5s ease-in-out;
}

.message.info {
    background: rgba(255, 193, 7, 0.3);
    border-color: rgba(255, 193, 7, 0.5);
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.game-board {
    position: relative;
    z-index: 1;
    margin-bottom: 0.6rem;
    display: grid;
    gap: 0px;
    max-width: 350px;
    width: 350px;
    height: 350px;
    margin: 0 auto 0.6rem auto;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.2);
    padding: 3px;
    border-radius: 6px;
}

.cell {
    aspect-ratio: 1;
    border-radius: 0px;
    transition: all 0.15s ease;
    cursor: pointer;
    border: none;
    min-width: 25px;
    min-height: 25px;
    position: relative;
}

.cell:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.cell.flooded {
    animation: flood 0.4s ease-out;
}

.cell.new-color {
    animation: colorChange 0.6s ease-out;
}

@keyframes flood {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5); }
    100% { transform: scale(1); }
}

@keyframes colorChange {
    0% { transform: scale(1); filter: brightness(1); }
    25% { transform: scale(1.1); filter: brightness(1.3); }
    50% { transform: scale(1.05); filter: brightness(1.5); }
    100% { transform: scale(1); filter: brightness(1); }
}

.color-palette {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 0.8rem;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: 0.4rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.color-button {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.color-button::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), transparent);
    pointer-events: none;
}

.color-button:hover {
    transform: scale(1.15);
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.4);
}

.color-button.selected {
    border-color: #ffd700;
    border-width: 4px;
    transform: scale(1.2);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.color-button:active {
    transform: scale(1.1);
}

.stats {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    margin-bottom: 0.3rem;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding-bottom: 0.5rem;
}

.stat-item {
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 70px;
    transition: all 0.3s ease;
}

.stat-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.stat-value {
    font-size: 1.1rem;
    font-weight: bold;
    color: #ffd700;
}

.stat-label {
    font-size: 0.65rem;
    color: #e0e0e0;
    margin-top: 0.25rem;
}

/* Color definitions */
.color-0 { background-color: #e74c3c; } /* Red */
.color-1 { background-color: #3498db; } /* Blue */
.color-2 { background-color: #2ecc71; } /* Green */
.color-3 { background-color: #f39c12; } /* Orange */
.color-4 { background-color: #9b59b6; } /* Purple */
.color-5 { background-color: #fa4180; } /* Pink */

/* Mobile optimizations */
@media (max-width: 600px) {
    body {
        padding: 0;
    }
    
    .game-container {
        border-radius: 0;
        height: 100dvh;
        max-width: none;
        padding: 0.8rem;
    }
    
    .title {
        font-size: 1.5rem;
        margin-bottom: 0.3rem;
    }
    
    .navigation {
        margin-bottom: 0.6rem;
        gap: 0.3rem;
    }
    
    .nav-button {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }

    .button-container {
        gap: 0.3rem;
        margin-bottom: 0.8rem;
    }
    
    .share-button,
    .control-button {
        padding: 0.5rem 0.6rem;
        font-size: 0.65rem;
        border-radius: 12px;
        letter-spacing: 0.3px;
        max-width: 100px;
    }
    
    .game-mode-selector,
    .difficulty-selector {
        margin-bottom: 0.6rem;
        gap: 0.3rem;
        flex-wrap: wrap;
    }
    
    .mode-button,
    .difficulty-button {
        padding: 0.35rem 0.7rem;
        font-size: 0.75rem;
    }

    .new-game-button {
        padding: 0.35rem 0.7rem;
        font-size: 0.7rem;
    }
    
    .game-info {
        margin-bottom: 0.6rem;
        padding: 0.5rem;
    }
    
    .moves-left {
        font-size: 0.85rem;
    }
    
    .difficulty {
        font-size: 0.7rem;
    }
    
    .game-board {
        max-width: 320px;
        max-height: 320px;
        width: 90vw;
        height: 90vw;
        gap: 0px;
        margin-bottom: 0.5rem;
        padding: 2px;
    }

    .cell {
        min-width: 21px;
        min-height: 21px;
    }

    .stats {
        gap: 0.5rem;
        margin-bottom: 0.3rem;
        padding-bottom: 0.3rem;
    }
    
    .message {
        font-size: 0.8rem;
        padding: 0.4rem;
        margin-bottom: 0.5rem;
        min-height: 35px;
    }
    
    .color-palette {
        gap: 8px;
        margin-bottom: 0.4rem;
        padding: 0.4rem;
    }
    
    .color-button {
        width: 42px;
        height: 42px;
        border-width: 2px;
    }
    
    .color-button.selected {
        border-width: 3px;
    }
    
    .stat-item {
        padding: 0.35rem 0.5rem;
        min-width: 65px;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .stat-label {
        font-size: 0.6rem;
    }
}

/* Extra small screens */
@media (max-width: 375px) {
    .game-container {
        padding: 0.6rem;
    }
    
    .title {
        font-size: 1.4rem;
    }
    
    .game-board {
        max-width: 260px;
        width: 260px;
        height: 260px;
        gap: 0px;
        margin-bottom: 0.5rem;
    }

    .cell {
        min-width: 17px;
        min-height: 17px;
    }

    .color-palette {
        gap: 6px;
        margin-bottom: 0.5rem;
    }

    .stats {
        gap: 0.4rem;
        margin-bottom: 0.3rem;
        padding-bottom: 0.2rem;
    }

    .new-game-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.75rem;
        margin-bottom: 0.2rem;
    }
    
    .color-button {
        width: 40px;
        height: 40px;
    }

    .button-container {
        gap: 0.25rem;
    }
    
    .share-button,
    .control-button {
        padding: 0.45rem 0.5rem;
        font-size: 0.6rem;
        max-width: 85px;
    }
    
    .game-mode-selector,
    .difficulty-selector {
        gap: 0.25rem;
        margin-bottom: 0.5rem;
    }
    
    .mode-button,
    .difficulty-button {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
    }

    .new-game-button {
        padding: 0.3rem 0.6rem;
        font-size: 0.65rem;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .game-container {
        height: 100vh;
        padding: 0.4rem;
    }
    
    .header {
        margin-bottom: 0.5rem;
    }
    
    .title {
        font-size: 1.2rem;
        margin-bottom: 0.3rem;
    }
    
    .navigation {
        margin-bottom: 0.3rem;
    }
    
    .game-mode-selector,
    .difficulty-selector {
        margin-bottom: 0.3rem;
        gap: 0.2rem;
    }
    
    .mode-button,
    .difficulty-button {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
    }

    .new-game-button {
        padding: 0.3rem 0.6rem;
        font-size: 0.6rem;
    }
    
    .game-info {
        margin-bottom: 0.4rem;
        padding: 0.4rem;
    }
    
    .message {
        margin-bottom: 0.4rem;
        padding: 0.4rem;
        min-height: 30px;
    }
    
    .game-board {
        margin-bottom: 0.5rem;
        max-width: 260px;
        width: 260px;
        height: 260px;
        gap: 0px;
    }

    .cell {
        min-width: 16px;
        min-height: 16px;
    }

    .stats {
        gap: 0.4rem;
        margin-bottom: 0.3rem;
        padding-bottom: 0.5rem;
    }
    
    .color-palette {
        margin-bottom: 0.5rem;
    }
    
    .share-button,
    .control-button {
        padding: 0.4rem 0.45rem;
        font-size: 0.55rem;
        max-width: 75px;
    }
}