/* Base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: -webkit-fill-available;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000000;
    background: linear-gradient(145deg, #000000 0%, #1a1a1a 100%);
    min-height: 100vh;
    /* mobile viewport bug fix */
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    position: fixed;
    width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.container {
    width: 100%;
    max-width: 500px;
    padding: 1rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    margin: 1rem;
    /* Ensure content doesn't overflow on small screens */
    overflow: hidden;
    /* Safe area insets for iOS */
    padding: max(1rem, env(safe-area-inset-top))
             max(1rem, env(safe-area-inset-right))
             max(1rem, env(safe-area-inset-bottom))
             max(1rem, env(safe-area-inset-left));
}

.buttons {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.zero-btn, .train-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    min-width: 110px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.train-btn:disabled,
.zero-btn:disabled {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    opacity: 0.7;
    cursor: not-allowed;
    box-shadow: none;
}

.status {
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.feedback {
    font-size: 1rem;
    color: #94a3b8;
    margin: 0.75rem 0;
    padding: 0 0.5rem;
    line-height: 1.4;
}

.timer {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0.75rem 0;
    min-height: 3rem;
}

canvas {
    width: min(calc(100vw - 2rem), 300px);
    height: min(calc(100vw - 2rem), 300px);
    background: #000000;
    border-radius: 16px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    margin: 0.75rem auto;
    display: block;
    touch-action: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.score {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0.75rem 0;
}

.hidden {
    display: none !important;
}

/* Landscape mode */
@media (orientation: landscape) {
    body {
        padding: 0.5rem;
    }
    
    .container {
        margin: 0.5rem;
        padding: 0.75rem;
    }
    
    canvas {
        width: min(calc(100vh - 8rem), 300px);
        height: min(calc(100vh - 8rem), 300px);
    }
    
    .buttons {
        margin-bottom: 0.5rem;
    }
    
    .status {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .feedback {
        font-size: 0.9375rem;
        margin: 0.5rem 0;
    }
    
    .timer {
        font-size: 2rem;
        min-height: 2.5rem;
    }
    
    .score {
        font-size: 2rem;
    }
}

/* Small screens */
@media (max-width: 360px) {
    .container {
        margin: 0.5rem;
        padding: 0.75rem;
        border-radius: 16px;
    }
    
    .zero-btn, .train-btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        min-width: 100px;
    }
    
    .status {
        font-size: 1rem;
    }
    
    .feedback {
        font-size: 0.875rem;
    }
}

/* Prevent bounce scroll */
body {
    touch-action: none;
    overscroll-behavior: none;
}

/* iOS height fix */
@supports (-webkit-touch-callout: none) {
    body {
        height: -webkit-fill-available;
    }
}