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

body {
    font-family: 'Segoe UI', 'Arial', sans-serif;
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%;
    animation: gradient 15s ease infinite;
    color: #fff;
    overflow: hidden;
    height: 100vh;
    position: relative;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

@keyframes gradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#app {
    width: 100%;
    height: 100vh;
    position: relative;
    z-index: 1;
}

.floating-fruits {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.fruit-emoji {
    position: absolute;
    font-size: 3rem;
    opacity: 0.3;
    animation: float 8s infinite ease-in-out;
    animation-delay: var(--delay);
    left: var(--x);
}

@keyframes float {
    0%, 100% { 
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.3;
    }
    90% {
        opacity: 0.3;
    }
    100% { 
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}

/* Screens */
.screen {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 20px;
}

.screen.active {
    display: flex;
}

/* Start Screen */
#startScreen {
    text-align: center;
    z-index: 2;
    justify-content: flex-start;   /* top-aligned + scrollable so Start is always reachable */
    overflow-y: auto;
    padding: 30px 20px 50px;
}

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

#startScreen h1 {
    font-size: 6rem;
    margin-bottom: 1rem;
    text-shadow: 
        0 0 10px rgba(255, 255, 255, 0.8),
        0 0 20px rgba(255, 255, 255, 0.5),
        0 0 30px #ff00de,
        0 5px 15px rgba(0, 0, 0, 0.3);
    animation: glow 2s ease-in-out infinite alternate;
    font-weight: 900;
    letter-spacing: 2px;
    position: relative;
    display: inline-block;
}

.title-emoji {
    display: inline-block;
    animation: rotate 3s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.title-underline {
    height: 4px;
    background: linear-gradient(90deg, transparent, #fff, transparent);
    border-radius: 2px;
    animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 0.3; transform: scaleX(0.5); }
    50% { opacity: 1; transform: scaleX(1); }
}

@keyframes glow {
    from { text-shadow: 0 0 10px rgba(255, 255, 255, 0.5), 0 0 20px rgba(255, 255, 255, 0.3); transform: scale(1); }
    to { text-shadow: 0 0 20px rgba(255, 255, 255, 1), 0 0 30px #ff00de, 0 0 40px #ff00de; transform: scale(1.05); }
}

.subtitle {
    font-size: 1.6rem;
    margin-bottom: 2.5rem;
    opacity: 0.95;
    font-weight: 300;
    letter-spacing: 1px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    animation: fadeIn 1s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 0.95; transform: translateY(0); }
}

.instructions {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    border-radius: 20px;
    padding: 2.5rem;
    margin-bottom: 2rem;
    max-width: 600px;
    transition: transform 0.3s ease;
}

.instructions:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.2);
}

.instructions h3 {
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
    font-weight: 700;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.instructions ul {
    list-style: none;
    text-align: left;
}

.instructions li {
    padding: 1rem 0;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    line-height: 1.6;
}

.instructions li .icon {
    font-size: 1.8rem;
    flex-shrink: 0;
}

.instructions li strong {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.btn-primary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    color: white;
    padding: 1.5rem 4rem;
    font-size: 1.8rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 20px rgba(245, 87, 108, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.btn-primary::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(255,255,255,0.2), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.btn-primary:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 20px 40px rgba(245, 87, 108, 0.6);
}

.btn-primary:active {
    transform: translateY(-2px) scale(1.02);
}

.camera-note {
    margin-top: 1rem;
    font-size: 0.9rem;
    opacity: 0.7;
}

.timer-selection {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    border-radius: 20px;
    padding: 2rem;
    margin-bottom: 2.5rem;
    max-width: 600px;
    transition: transform 0.3s ease;
}

.timer-selection:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.2);
}

.timer-selection h3 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.timer-options {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.timer-option {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 1.2rem 2.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: 140px;
}

.timer-option:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.timer-option.active {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-color: white;
    box-shadow: 0 8px 25px rgba(245, 87, 108, 0.6);
    transform: scale(1.05);
}

.no-timer-option {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.no-timer-option label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.no-timer-option label:hover {
    transform: scale(1.05);
}

.no-timer-option input[type="checkbox"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
    accent-color: #f5576c;
}

/* Game Screen */
#gameScreen {
    padding: 0;
}

.game-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-around;
    padding: 1rem 2rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 10;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.game-header.combo-active {
    border-color: rgba(255, 215, 0, 0.6);
    box-shadow: 0 8px 32px rgba(255, 215, 0, 0.3), 0 0 20px rgba(255, 215, 0, 0.2);
    animation: headerShimmer 1s ease-in-out infinite;
}

@keyframes headerShimmer {
    0%, 100% { background: rgba(0, 0, 0, 0.6); }
    50% { background: rgba(50, 40, 0, 0.7); }
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.stat .label {
    font-size: 0.9rem;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat .value {
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#score {
    animation: scorePulse 0.5s ease-in-out;
}

@keyframes scorePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); color: #ffd700; }
}

#timer {
    transition: all 0.3s ease;
}

#combo {
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stat .value.pulse {
    animation: statPulse 0.3s ease-out;
}

@keyframes statPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); text-shadow: 0 0 20px currentColor; }
    100% { transform: scale(1); }
}

.stat .value.combo-burst {
    animation: comboBurst 0.5s ease-out;
}

@keyframes comboBurst {
    0% { transform: scale(1); }
    25% { transform: scale(1.5) rotate(5deg); }
    50% { transform: scale(1.3) rotate(-5deg); color: #ffff00; }
    75% { transform: scale(1.4) rotate(3deg); }
    100% { transform: scale(1); color: #ffd700; }
}

.btn-stop {
    background: linear-gradient(135deg, #ff4757 0%, #ff6348 100%);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 0.8rem 2rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
    position: relative;
    overflow: hidden;
}

.btn-stop::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-stop:hover::before {
    width: 300px;
    height: 300px;
}

.btn-stop:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 20px rgba(255, 71, 87, 0.6);
}

.btn-stop:active {
    transform: translateY(-1px) scale(0.98);
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

@keyframes timerWarning {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.8; }
}

.timer-warning {
    animation: timerWarning 0.5s ease-in-out infinite;
}

#webcam {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

/* Game Over Screen */
#gameOverScreen {
    text-align: center;
}

#gameOverScreen h1 {
    font-size: 4rem;
    margin-bottom: 2rem;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.final-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.stat-box {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 2rem;
    min-width: 150px;
}

.stat-label {
    font-size: 1rem;
    opacity: 0.8;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
}

/* Loading Indicator */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 100;
    background: rgba(0, 0, 0, 0.8);
    padding: 2rem;
    border-radius: 20px;
    display: none;
}

.loading.active {
    display: block;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    #startScreen h1 {
        font-size: 3rem;
    }
    
    .subtitle {
        font-size: 1.2rem;
    }
    
    .stat .value {
        font-size: 1.5rem;
    }
    
    .final-stats {
        flex-direction: column;
        gap: 1rem;
    }
}
