* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
}

.container {
    max-width: 100vw;
    padding: 10px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 1.8rem;
    color: #4a5568;
    margin-bottom: 10px;
    font-weight: 700;
}

.counter-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.counter-label {
    font-size: 1.2rem;
    font-weight: 600;
    color: #666;
}

.counter-value {
    font-size: 2rem;
    font-weight: bold;
    color: #e53e3e;
    background: #fed7d7;
    padding: 8px 16px;
    border-radius: 10px;
    min-width: 60px;
    text-align: center;
}

.camera-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 0 auto 20px;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    background: #000;
}

#videoElement {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

#canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.detection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

.ball-indicator {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid #00ff00;
    border-radius: 50%;
    background: rgba(0, 255, 0, 0.2);
    display: none;
    transform: translate(-50%, -50%);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.2); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

.status-text {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.btn-secondary {
    background: linear-gradient(45deg, #ff6b6b, #ee5a52);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

.btn-tertiary {
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    color: white;
    box-shadow: 0 4px 15px rgba(78, 205, 196, 0.3);
}

.btn-tertiary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(78, 205, 196, 0.4);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.settings {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.setting-group {
    margin-bottom: 15px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
}

.setting-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.setting-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.setting-group span {
    display: inline-block;
    margin-left: 10px;
    font-weight: bold;
    color: #666;
    min-width: 50px;
}

.info {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.info p {
    margin-bottom: 10px;
    line-height: 1.6;
    color: #666;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .container {
        padding: 5px;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .counter-value {
        font-size: 1.8rem;
        padding: 6px 12px;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
        min-width: 100px;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
    }
    
    .settings, .info {
        padding: 15px;
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    #videoElement {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    .header {
        margin-bottom: 10px;
        padding: 10px;
    }
    
    .header h1 {
        font-size: 1.3rem;
        margin-bottom: 5px;
    }
    
    .controls {
        margin-bottom: 10px;
    }
    
    .settings, .info {
        padding: 10px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .ball-indicator {
        border-width: 2px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .header, .settings, .info {
        background: rgba(45, 55, 72, 0.95);
        color: #e2e8f0;
    }
    
    .header h1, .setting-group label {
        color: #e2e8f0;
    }
    
    .counter-label, .setting-group span, .info p {
        color: #cbd5e0;
    }
}