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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
}

.game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: rgba(0, 0, 0, 0.3);
}

.title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: #FFD93D;
}

.stats {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
}

.score-label {
    color: rgba(255, 255, 255, 0.6);
}

.score {
    font-weight: 700;
    color: #4CAF50;
}

.game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.board {
    display: grid;
    grid-template-columns: repeat(20, 1fr);
    gap: 1px;
    background: #16213e;
    border-radius: 8px;
    padding: 4px;
    width: min(90vw, 90vh - 180px, 400px);
    aspect-ratio: 1;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.cell {
    background: #1a1a2e;
    border-radius: 2px;
    aspect-ratio: 1;
}

.cell.snake {
    background: #4CAF50;
    border-radius: 3px;
}

.cell.snake-head {
    background: #66BB6A;
    border-radius: 3px;
}

.cell.food {
    background: radial-gradient(circle at 30% 30%, #FF8A80, #FF6B6B);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
    animation: foodPulse 0.6s ease-in-out infinite alternate;
}

@keyframes foodPulse {
    from { transform: scale(0.85); }
    to { transform: scale(1); }
}

.controls-block {
    padding: 0.75rem 1rem 3.5rem;
    text-align: center;
}

.controls-row {
    margin-bottom: 0.5rem;
}

.controls-row:last-child {
    margin-bottom: 0;
}

.desktop-only {
    display: flex;
    justify-content: center;
}

.mobile-only {
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    .desktop-only { display: none; }
    .mobile-only { display: flex; justify-content: center; }
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 46, 0.98);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.overlay-content {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
}

.overlay-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #FFD93D;
    margin: 0 0 1rem;
}

.overlay-text {
    font-size: 1.25rem;
    color: rgba(255, 255, 255, 0.8);
    margin: 0 0 1.5rem;
}

.overlay-score {
    font-size: 2rem;
    font-weight: 700;
    color: #4CAF50;
    margin: 0 0 0.5rem;
}

.overlay-best {
    font-size: 1.25rem;
    color: rgba(255, 255, 255, 0.7);
    margin: 0 0 1.5rem;
}

.share-container {
    margin-bottom: 1.5rem;
}

.start-btn {
    background: #FFD93D;
    color: #1a1a2e;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.25rem;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(255, 217, 61, 0.4);
}

.start-btn:active {
    transform: scale(0.98);
}

.home-link {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
    transition: background 0.2s ease, color 0.2s ease;
    z-index: 200;
}

.home-link:hover {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

/* Hide controls during play */
.state-playing .controls-block {
    opacity: 0.3;
}

/* New best celebration */
.overlay-title.new-best {
    animation: celebrate 0.5s ease;
}

@keyframes celebrate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); color: #4CAF50; }
}

/* Responsive */
@media (max-width: 600px) {
    .header {
        padding: 0.75rem 1rem;
    }

    .title {
        font-size: 1.25rem;
    }

    .stats {
        font-size: 1rem;
    }

    .overlay-title {
        font-size: 2rem;
    }

    .controls-block {
        padding: 0.5rem;
    }
}
