* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
}

body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    font-family: 'Nunito', sans-serif;
    background: #87CEEB;
    touch-action: none;
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    overflow: hidden;
}

#game-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw;
    max-height: 100vh;
    display: block;
    z-index: 1;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    display: none;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    z-index: 100;
}

.screen.active {
    display: flex !important;
}

.overlay {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
}

#menu-screen {
    background: linear-gradient(180deg, #64B5F6 0%, #81D4FA 30%, #A5D6A7 70%, #FFCC80 100%);
    z-index: 200;
}

.menu-content {
    width: 100%;
    max-width: 500px;
    max-height: 100vh;
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.logo-container {
    position: relative;
    margin-bottom: 10px;
}

.game-title {
    font-family: 'Fredoka One', cursive;
    font-size: clamp(2.5rem, 12vw, 5rem);
    background: linear-gradient(135deg, #FF6B6B 0%, #FFE66D 25%, #4ECDC4 50%, #A06CD5 75%, #FF8C42 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: titleBounce 2s ease-in-out infinite;
    filter: drop-shadow(3px 3px 0 rgba(0,0,0,0.1));
    text-align: center;
}

@keyframes titleBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.02); }
}

.subtitle {
    font-size: clamp(0.9rem, 4vw, 1.4rem);
    color: #5D4037;
    margin-top: 3px;
    font-weight: 600;
    text-align: center;
}

.candy-decoration {
    position: absolute;
    width: clamp(20px, 5vw, 30px);
    height: clamp(20px, 5vw, 30px);
    border-radius: 50%;
    animation: candyFloat 3s ease-in-out infinite;
}

.candy-dec-1 {
    top: -15px;
    left: clamp(-25px, -5vw, -40px);
    background: radial-gradient(circle at 30% 30%, #FF8A8A, #FF6B6B);
}

.candy-dec-2 {
    top: 15px;
    right: clamp(-30px, -6vw, -50px);
    background: radial-gradient(circle at 30% 30%, #FFF59D, #FFE66D);
    animation-delay: 0.5s;
}

.candy-dec-3 {
    bottom: -8px;
    left: 60%;
    background: radial-gradient(circle at 30% 30%, #A8E6CF, #4ECDC4);
    animation-delay: 1s;
}

@keyframes candyFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(15deg); }
}

.candy-carousel {
    display: flex;
    gap: clamp(8px, 3vw, 15px);
    margin: 10px 0;
}

.carousel-candy {
    width: clamp(30px, 8vw, 40px);
    height: clamp(30px, 8vw, 40px);
    border-radius: 50%;
    animation: carouselBounce 1s ease-in-out infinite;
}

.carousel-candy:nth-child(1) { background: radial-gradient(circle at 30% 30%, #FF8A8A, #FF6B6B); animation-delay: 0s; }
.carousel-candy:nth-child(2) { background: radial-gradient(circle at 30% 30%, #FFF59D, #FFE66D); animation-delay: 0.1s; }
.carousel-candy:nth-child(3) { background: radial-gradient(circle at 30% 30%, #A8E6CF, #4ECDC4); animation-delay: 0.2s; }
.carousel-candy:nth-child(4) { background: radial-gradient(circle at 30% 30%, #D4A5FF, #A06CD5); animation-delay: 0.3s; }
.carousel-candy:nth-child(5) { background: radial-gradient(circle at 30% 30%, #FFB347, #FF8C42); animation-delay: 0.4s; }

@keyframes carouselBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-15px) scale(1.1); }
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 2vh, 15px);
    width: 100%;
    max-width: 320px;
    margin: 15px 0;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: clamp(12px, 3vh, 15px) clamp(20px, 5vw, 30px);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(0.9rem, 4vw, 1.3rem);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: linear-gradient(145deg, #FF6B6B, #FF8C42);
    color: white;
    box-shadow: 0 clamp(4px, 1vh, 6px) 0 #CC5555, 0 10px 20px rgba(0, 0, 0, 0.2);
}

.btn-primary:hover {
    transform: translateY(-3px);
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #CC5555, 0 5px 10px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background: linear-gradient(145deg, #4ECDC4, #45B7AA);
    color: white;
    box-shadow: 0 clamp(3px, 0.8vh, 4px) 0 #3AA89E, 0 8px 15px rgba(0, 0, 0, 0.15);
}

.btn-secondary:hover {
    transform: translateY(-2px);
}

.btn-back {
    background: rgba(255, 255, 255, 0.9);
    color: #666;
    padding: 10px 20px;
    font-size: clamp(0.85rem, 3vw, 1rem);
    box-shadow: 0 3px 0 #ccc;
}

.settings-panel {
    display: flex;
    gap: clamp(10px, 3vw, 20px);
    margin: 10px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.8);
    padding: 8px 15px;
    border-radius: 20px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.setting-label {
    font-weight: 700;
    color: #5D4037;
    font-size: clamp(0.8rem, 3vw, 1rem);
}

.toggle-switch {
    position: relative;
    width: clamp(40px, 10vw, 50px);
    height: clamp(22px, 5vw, 26px);
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 80%;
    width: 40%;
    left: 6%;
    bottom: 10%;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

input:checked + .toggle-slider {
    background: linear-gradient(145deg, #4ECDC4, #45B7AA);
}

input:checked + .toggle-slider::before {
    transform: translateX(calc(100% + 8%));
}

.high-score {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(145deg, #FFD700, #FFC107);
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 800;
    color: #5D4037;
    box-shadow: 0 4px 15px rgba(255, 193, 7, 0.4);
    margin-top: 8px;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
}

.trophy {
    font-size: clamp(1rem, 4vw, 1.3rem);
}

#levels-screen, #how-to-play-screen {
    background: linear-gradient(180deg, #81D4FA 0%, #A5D6A7 50%, #FFCC80 100%);
    z-index: 200;
}

.screen-content {
    width: 100%;
    max-width: 600px;
    max-height: 100vh;
    padding: 15px;
    text-align: center;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.screen-content h2 {
    font-family: 'Fredoka One', cursive;
    font-size: clamp(1.8rem, 8vw, 3rem);
    color: #5D4037;
    margin-bottom: 15px;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: clamp(6px, 2vw, 10px);
    margin: 15px 0;
    padding: 0 5px;
}

.level-btn {
    aspect-ratio: 1;
    border: none;
    border-radius: clamp(10px, 3vw, 15px);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(0.9rem, 4vw, 1.5rem);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.level-btn.unlocked {
    background: linear-gradient(145deg, #FFE66D, #FFD700);
    color: #5D4037;
    box-shadow: 0 3px 0 #E6BE00, 0 6px 15px rgba(0, 0, 0, 0.15);
}

.level-btn.unlocked:hover {
    transform: translateY(-2px) scale(1.05);
}

.level-btn.locked {
    background: linear-gradient(145deg, #BDBDBD, #9E9E9E);
    color: #666;
    cursor: not-allowed;
    box-shadow: 0 2px 0 #757575;
}

.level-btn.current {
    background: linear-gradient(145deg, #4ECDC4, #45B7AA);
    color: white;
    box-shadow: 0 3px 0 #3AA89E, 0 6px 15px rgba(0, 0, 0, 0.2);
    animation: pulse 1.5s ease-in-out infinite;
}

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

.level-stars {
    font-size: clamp(0.4rem, 2vw, 0.5em);
    margin-top: 2px;
}

.how-to-content {
    max-width: 700px;
}

.instructions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(140px, 40vw), 1fr));
    gap: clamp(8px, 2vw, 15px);
    margin: 15px 0;
}

.instruction-card {
    background: rgba(255, 255, 255, 0.9);
    padding: clamp(10px, 3vw, 15px);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.instruction-icon {
    font-size: clamp(1.5rem, 6vw, 2rem);
    margin-bottom: 6px;
}

.instruction-card p {
    font-size: clamp(0.75rem, 3vw, 0.9rem);
    color: #5D4037;
    font-weight: 600;
}

.powerups-guide {
    background: rgba(255, 255, 255, 0.9);
    padding: 12px 15px;
    border-radius: 12px;
    margin: 15px 0;
}

.powerups-guide h3 {
    color: #5D4037;
    margin-bottom: 8px;
    font-size: clamp(1rem, 4vw, 1.2rem);
}

.powerup-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-weight: 600;
    color: #666;
    font-size: clamp(0.8rem, 3vw, 1rem);
}

.powerup-icon {
    min-width: 30px;
    height: 30px;
    width: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
    color: white;
}

.powerup-icon.magnet { background: #FF69B4; }
.powerup-icon.double { background: #FFD700; color: #333; }
.powerup-icon.slowmo { background: #5DADE2; }
.powerup-icon.shield { background: #4ECDC4; }

#game-ui {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    z-index: 50;
    pointer-events: none;
    padding: clamp(8px, 2vh, 10px) clamp(10px, 3vw, 15px);
}

.ui-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 5px;
}

.ui-left, .ui-right {
    display: flex;
    gap: clamp(5px, 2vw, 10px);
    pointer-events: auto;
    flex-wrap: wrap;
}

.ui-center {
    pointer-events: auto;
}

.score-box, .combo-box, .level-box, .target-box {
    background: rgba(255, 255, 255, 0.95);
    padding: clamp(5px, 1.5vh, 8px) clamp(10px, 3vw, 18px);
    border-radius: clamp(12px, 3vw, 20px);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
    border: 2px solid #FFD700;
    min-width: clamp(60px, 15vw, 90px);
}

.ui-label {
    font-size: clamp(0.55rem, 2vw, 0.7rem);
    color: #888;
    font-weight: 700;
    text-transform: uppercase;
}

.score-box span:last-child { color: #FF6B6B; font-weight: 800; font-size: clamp(1rem, 4vw, 1.3rem); }
.combo-box span:last-child { color: #A06CD5; font-weight: 800; font-size: clamp(1rem, 4vw, 1.3rem); }
.level-box span:last-child { color: #4ECDC4; font-weight: 800; font-size: clamp(1rem, 4vw, 1.3rem); }
.target-box span:last-child { color: #FF8C42; font-weight: 800; font-size: clamp(1rem, 4vw, 1.3rem); }
.level-total { color: #888 !important; font-size: clamp(0.8rem, 3vw, 1rem) !important; }

.pause-btn {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #FFD700;
    border-radius: 50%;
    width: clamp(35px, 10vw, 45px);
    height: clamp(35px, 10vw, 45px);
    font-size: clamp(1rem, 4vw, 1.3rem);
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pause-btn:hover {
    transform: scale(1.1);
}

.ui-bottom {
    margin-top: clamp(5px, 1.5vh, 10px);
    display: flex;
    justify-content: center;
}

.progress-container {
    width: 100%;
    max-width: min(400px, 80vw);
    height: clamp(8px, 2vh, 12px);
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4ECDC4, #FFE66D, #FF6B6B);
    border-radius: 10px;
    transition: width 0.3s ease;
}

#powerup-display {
    position: fixed;
    top: clamp(70px, 15vh, 100px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    display: none;
    background: rgba(255, 255, 255, 0.95);
    padding: clamp(8px, 2vh, 12px) clamp(15px, 4vw, 30px);
    border-radius: 20px;
    border: 2px solid #4ECDC4;
    font-size: clamp(0.9rem, 3.5vw, 1.1rem);
    font-weight: 800;
    color: #5D4037;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    animation: powerupPop 0.3s ease;
    white-space: nowrap;
}

@keyframes powerupPop {
    0% { transform: translateX(-50%) scale(0); }
    50% { transform: translateX(-50%) scale(1.1); }
    100% { transform: translateX(-50%) scale(1); }
}

.pause-content, .complete-content, .gameover-content, .win-content {
    background: rgba(255, 255, 255, 0.98);
    padding: clamp(20px, 5vh, 40px) clamp(15px, 4vw, 30px);
    border-radius: clamp(15px, 4vw, 30px);
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.4s ease;
}

@keyframes slideIn {
    0% { transform: translateY(-30px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

.pause-content h2, .complete-content h2, .gameover-content h2, .win-content h2 {
    font-family: 'Fredoka One', cursive;
    font-size: clamp(1.8rem, 8vw, 2.5rem);
    margin-bottom: 15px;
}

.complete-content h2 { color: #4ECDC4; }
.gameover-content h2 { color: #FF6B6B; }
.win-content h2 { color: #FFD700; }

.stars-container {
    font-size: clamp(2rem, 10vw, 3rem);
    margin-bottom: 10px;
}

.star {
    display: inline-block;
    margin: 0 3px;
    opacity: 0.3;
    transition: all 0.5s ease;
}

.star.earned {
    opacity: 1;
    animation: starPop 0.5s ease;
}

@keyframes starPop {
    0% { transform: scale(0) rotate(-180deg); }
    50% { transform: scale(1.3) rotate(10deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.complete-stats, .gameover-stats, .win-stats {
    display: flex;
    justify-content: center;
    gap: clamp(10px, 3vw, 20px);
    margin: 15px 0 20px;
    flex-wrap: wrap;
}

.stat-item {
    background: #F5F5F5;
    padding: clamp(8px, 2vh, 12px) clamp(12px, 3vw, 20px);
    border-radius: 12px;
    min-width: clamp(80px, 20vw, 100px);
}

.stat-label {
    display: block;
    font-size: clamp(0.65rem, 2.5vw, 0.8rem);
    color: #888;
    font-weight: 700;
    text-transform: uppercase;
}

.stat-value {
    display: block;
    font-size: clamp(1.1rem, 5vw, 1.5rem);
    font-weight: 800;
    color: #4ECDC4;
}

.trophy-container {
    font-size: clamp(3rem, 15vw, 5rem);
    animation: trophyBounce 1s ease-in-out infinite;
}

@keyframes trophyBounce {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
}

.win-message {
    font-size: clamp(1rem, 4vw, 1.2rem);
    color: #666;
    margin-bottom: 15px;
}

.complete-content .btn, .gameover-content .btn, .win-content .btn, .pause-content .btn {
    width: 100%;
    max-width: min(250px, 80vw);
    margin: 5px auto;
}

@media (max-width: 480px) {
    .levels-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .settings-panel {
        flex-direction: row;
        align-items: center;
    }
    
    .instructions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 360px) {
    .menu-content {
        padding: 10px;
    }
    
    .candy-carousel {
        margin: 8px 0;
    }
    
    .menu-buttons {
        margin: 10px 0;
        gap: 8px;
    }
    
    .levels-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 5px;
    }
}

@media (min-aspect-ratio: 16/9) and (max-height: 500px) {
    .menu-content {
        padding: 8px;
    }
    
    .game-title {
        font-size: 2rem;
    }
    
    .candy-carousel {
        margin: 5px 0;
    }
    
    .menu-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    
    .menu-buttons .btn {
        flex: 1 1 calc(50% - 8px);
        min-width: 140px;
        padding: 10px 15px;
    }
    
    .settings-panel {
        flex-direction: row;
    }
}

@media (hover: none) {
    .btn:hover {
        transform: none;
    }
    
    .btn:active {
        transform: scale(0.98);
    }
}
