* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

/* Main game container - uses dark background for visual contrast with colorful tiles */
.game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-bg-secondary, #16213e);
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    font-family: var(--font-main);
    color: var(--color-text, #fff);
    padding: 1rem;
    padding-bottom: 4rem;
    overflow-y: auto;
}

.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 400px;
    margin: auto 0;
}

.title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    color: var(--color-primary);
}

.tagline {
    font-size: 1rem;
    color: var(--color-text-light, #888);
    margin: 0;
}

.controls-inline {
    margin: 0.5rem 0;
}

.stats {
    display: flex;
    gap: 2rem;
    margin: 0.5rem 0;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-light, #888);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text, #fff);
}

.chain-value {
    color: var(--color-primary);
}

/* Grid - 5x5 tile board */
.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1;
    padding: 8px;
    background: var(--color-bg, #16213e);
    border-radius: var(--radius-md, 12px);
}

.tile {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.15s;
    aspect-ratio: 1;
}

.tile:active {
    transform: scale(0.95);
}

/* Tile colors by value - light blue (low) -> orange -> red (high/dangerous) */
.tile[data-value="1"] {
    background: #81D4FA;
    color: #1a1a2e;
}

.tile[data-value="2"] {
    background: #29B6F6;
    color: #1a1a2e;
}

.tile[data-value="3"] {
    background: #FFA726;
    color: #1a1a2e;
}

.tile[data-value="4"] {
    background: #EF5350;
    color: #fff;
}

/* Value 5 (overflow state) - bright red, should be rare/momentary */
.tile[data-value="5"],
.tile[data-value="6"],
.tile[data-value="7"],
.tile[data-value="8"] {
    background: #D32F2F;
    color: #fff;
}

/* Overflow animation */
.tile.overflowing {
    animation: overflow-pulse 0.2s ease-out;
}

@keyframes overflow-pulse {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }
    50% {
        transform: scale(1.15);
        filter: brightness(1.5);
    }
    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

/* Receiving +1 animation */
.tile.receiving {
    animation: receive-pulse 0.15s ease-out;
}

@keyframes receive-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
    100% {
        transform: scale(1);
    }
}

/* Random spawn visual feedback */
.tile.spawned {
    animation: spawn-highlight 0.3s ease-out;
}

@keyframes spawn-highlight {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.8);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.4);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
    }
}

.instruction {
    font-size: 1rem;
    color: var(--color-text-light, #888);
    margin: 0.5rem 0;
    text-align: center;
    min-height: 1.5rem;
}

.hint {
    font-size: 0.875rem;
    color: var(--color-text-light, #666);
    margin: 0;
    text-align: center;
}

.share-container {
    margin: 0.5rem 0;
}

.home-link {
    position: fixed;
    bottom: max(1.5rem, env(safe-area-inset-bottom, 1.5rem));
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-text-light, #666);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s;
}

.home-link:hover {
    color: var(--color-text, #888);
}

/* State-based visibility */
.state-idle .grid,
.state-idle .stats {
    display: none;
}

.state-idle .controls-inline {
    display: block;
}

.state-playing .controls-inline,
.state-cascading .controls-inline,
.state-gameover .controls-inline {
    display: none;
}

.state-playing .tagline,
.state-cascading .tagline,
.state-gameover .tagline {
    display: none;
}

.state-idle .instruction,
.state-playing .instruction,
.state-cascading .instruction {
    display: none;
}

.state-idle .share-container,
.state-playing .share-container,
.state-cascading .share-container {
    display: none;
}

.state-gameover .hint {
    display: none;
}

/* Game over state - red text for game over */
.state-gameover .instruction {
    font-size: 1.25rem;
    color: var(--color-accent, #EF5350);
}

.state-gameover.new-best .chain-value {
    animation: celebrate 0.6s ease-out;
}

@keyframes celebrate {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.2) rotate(-5deg); }
    50% { transform: scale(1.3); }
    75% { transform: scale(1.2) rotate(5deg); }
}

/* Responsive adjustments */
@media (max-height: 600px) {
    .title {
        font-size: 1.5rem;
    }

    .content {
        gap: 0.5rem;
    }

    .grid {
        max-width: 280px;
    }

    .tile {
        font-size: 1.5rem;
    }
}

@media (max-width: 360px) {
    .grid {
        max-width: 280px;
        gap: 4px;
    }

    .tile {
        font-size: 1.5rem;
    }
}
