* {
    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;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    padding: 1rem;
}

.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: #FFD93D;
}

.level-display {
    font-size: 1.25rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
}

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

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #16213e;
    cursor: grab;
}

#canvas:active {
    cursor: grabbing;
}

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

.crossings {
    color: #FF6B6B;
    font-weight: 600;
}

.crossings.solved {
    color: #4CAF50;
}

.timer {
    color: rgba(255, 255, 255, 0.7);
    transition: color 0.2s;
}

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

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

.instruction {
    color: rgba(255, 255, 255, 0.6);
    font-size: 1rem;
    margin: 0.75rem 0;
    text-align: center;
}

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

.best-level {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.7);
    margin: 0 0 1rem;
}

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

.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);
}

/* 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 {
    display: none;
}

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

.state-gameover .result-time {
    color: #FF6B6B;
}

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

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

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