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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    background: var(--color-bg, #FFF9E6);
}

.game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    padding: 1rem;
    padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
}

.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
}

.header-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 1rem;
}

.title {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary, #FFD93D);
}

.level-display {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text, #333);
}

.canvas-wrapper {
    width: min(90vw, 90vh - 200px, 400px);
    aspect-ratio: 1;
    border-radius: var(--radius-md, 12px);
    overflow: hidden;
    box-shadow: var(--shadow-card, 0 4px 20px rgba(0, 0, 0, 0.3));
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--color-bg-secondary, #FFF5D6);
    cursor: grab;
}

#canvas:active {
    cursor: grabbing;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 1rem;
    font-size: 1.1rem;
}

.crossings {
    color: var(--color-accent, #FF6B6B);
    font-weight: 600;
}

.crossings.solved {
    color: var(--color-success, #4CAF50);
}

.timer {
    color: var(--color-text, #333);
    transition: color 0.2s;
}

.timer.urgent {
    color: var(--color-accent, #FF6B6B);
    font-weight: 700;
    animation: pulse 0.5s ease-in-out infinite;
}

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

/* Control instructions */
.controls-inline {
    margin: 0.75rem 0;
}

.control-pill {
    background: rgba(128, 128, 128, 0.1);
    color: var(--color-text-light, #666);
}

.control-pill .touch {
    background: var(--color-primary, #FFD93D);
}

.result-time {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-success, #4CAF50);
    margin: 0.5rem 0;
}

.best-level {
    font-size: 1.1rem;
    color: var(--color-text, #333);
    margin: 0 0 1rem;
}

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

.start-btn {
    margin-top: 0.5rem;
    background: var(--color-primary, #FFD93D);
    color: var(--color-text, #333);
    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);
}

.start-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring, 0 0 0 3px rgba(74, 144, 217, 0.5));
}

.home-link {
    position: fixed;
    bottom: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-text-light, #666);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: var(--color-card-bg, #fff);
    box-shadow: var(--shadow-card, 0 4px 6px rgba(0, 0, 0, 0.1));
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    z-index: 200;
}

.home-link:hover {
    background: var(--color-bg-secondary, #FFF5D6);
    color: var(--color-text, #333);
    box-shadow: var(--shadow-card-hover, 0 8px 20px rgba(0, 0, 0, 0.15));
}

.home-link:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring, 0 0 0 3px rgba(74, 144, 217, 0.5));
}

/* State visibility */
.state-idle .stats,
.state-idle .result-time,
.state-idle .share-container {
    display: none;
}

.state-playing .result-time,
.state-playing .share-container,
.state-playing .start-btn,
.state-playing .controls-inline {
    display: none;
}

.state-celebrating .controls-inline {
    display: none;
}

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

.state-gameover .result-time {
    color: var(--color-accent, #FF6B6B);
}

/* Hide SEO content during gameplay */
.state-playing .how-to-play,
.state-playing .related-games,
.state-celebrating .how-to-play,
.state-celebrating .related-games,
.state-solved .how-to-play,
.state-solved .related-games,
.state-gameover .how-to-play,
.state-gameover .related-games {
    display: none;
}

/* Fade in UI elements on solve */
.state-solved .result-time,
.state-solved .best-level,
.state-solved .share-container,
.state-solved .start-btn {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

    .level-display {
        font-size: 1rem;
    }

    .stats {
        font-size: 1rem;
        gap: 1.5rem;
    }

    .start-btn {
        padding: 0.75rem 2rem;
        font-size: 1.1rem;
    }
}

/* Very small screens and iOS safe areas */
@media (max-height: 600px) {
    .game-container {
        padding-top: 0.5rem;
    }

    .header-info {
        margin-bottom: 0.5rem;
    }

    .stats {
        margin-top: 0.5rem;
    }

    .instruction {
        margin: 0.5rem 0;
    }

    .result-time {
        margin: 0.25rem 0;
    }

    .best-level {
        margin: 0 0 0.5rem;
    }

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

    .start-btn {
        padding: 0.6rem 1.75rem;
        font-size: 1rem;
    }
}
