/* --- Bubble Wrap --- */
#bubble-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--bubble-size), 1fr));
    flex: 0 1 auto;
    gap: clamp(8px, 2.5vw, 14px);
    width: min(100%, 520px);
    min-height: 0;
    max-height: min(70dvh, 640px);
    overflow-y: auto;
    padding: clamp(16px, 4vw, 32px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8), 0 20px 40px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    overscroll-behavior: contain;
    scrollbar-width: thin;
    touch-action: manipulation;
    -webkit-overflow-scrolling: touch;
}

#reset-bubbles {
    flex: 0 0 auto;
    min-height: 44px;
    margin-top: clamp(1rem, 3vw, 2rem);
    padding: 12px 16px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 12px;
    appearance: none;
    -webkit-appearance: none;
    background: rgba(15, 23, 42, 0.65);
    color: var(--text-secondary);
    font-size: clamp(11px, 2.5vw, 14px);
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
    transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

@media (hover: hover) {
    #reset-bubbles:hover {
        border-color: rgba(94, 234, 212, 0.65);
        background: rgba(30, 41, 59, 0.96);
        color: #ffffff;
    }
}

.bubble {
    width: 100%;
    max-width: 52px;
    aspect-ratio: 1;
    margin: 0 auto;
    padding: 0;
    border: 0;
    border-radius: 50%;
    appearance: none;
    -webkit-appearance: none;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.4), rgba(255,255,255,0.1) 40%, rgba(0,0,0,0.2) 80%);
    box-shadow:
        inset 2px 2px 5px rgba(255,255,255,0.5),
        inset -3px -3px 8px rgba(0,0,0,0.4),
        0 4px 8px rgba(0,0,0,0.5);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s, box-shadow 0.15s;
    position: relative;
}

.bubble::after {
    content: '';
    position: absolute;
    top: 15%;
    left: 15%;
    width: 25%;
    height: 25%;
    background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.bubble:active {
    transform: scale(0.85);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.bubble.popped {
    background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.05), rgba(0,0,0,0.3));
    box-shadow: inset 3px 3px 6px rgba(0,0,0,0.8);
    transform: scale(0.92);
    opacity: 0.4;
    cursor: default;
}

.bubble.popped::after {
    display: none;
}

.bubble.just-popped {
    animation: bubble-pop 0.24s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.bubble-progress {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 12px;
    width: min(100%, 360px);
    margin: 0 0 14px;
    padding: 10px 14px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.48);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.14);
    backdrop-filter: blur(10px);
}

.bubble-progress-bar {
    flex: 0 1 auto;
    width: 0;
    max-width: 100%;
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: linear-gradient(90deg, #2dd4bf, #99f6e4);
    box-shadow: 0 0 12px rgba(45, 212, 191, 0.3);
    transition: width 0.25s ease;
}

.bubble-progress-text {
    min-width: 3.5rem;
    color: #cbd5e1;
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-align: right;
}

.bubble-progress.all-popped {
    border-color: rgba(94, 234, 212, 0.34);
    background: rgba(13, 148, 136, 0.13);
}

.bubble-progress.all-popped .bubble-progress-text {
    color: #99f6e4;
}

#bubble-grid.all-popped {
    border-color: rgba(94, 234, 212, 0.24);
    box-shadow: inset 0 0 34px rgba(13, 148, 136, 0.1), 0 20px 45px rgba(0, 0, 0, 0.36);
}

.pop-ring,
.pop-particle {
    position: fixed;
    z-index: 500;
    pointer-events: none;
    user-select: none;
}

.pop-ring {
    width: var(--pop-size);
    height: var(--pop-size);
    border: 2px solid rgba(153, 246, 228, 0.72);
    border-radius: 50%;
    box-shadow: 0 0 18px rgba(45, 212, 191, 0.2);
    transform: translate(-50%, -50%) scale(0.35);
    animation: pop-ring 0.55s ease-out forwards;
}

.pop-particle {
    width: var(--pop-size);
    height: var(--pop-size);
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #f0fdfa, #5eead4 55%, rgba(45, 212, 191, 0.15));
    box-shadow: 0 0 9px rgba(94, 234, 212, 0.34);
    animation: pop-particle var(--pop-duration) cubic-bezier(0.15, 0.65, 0.25, 1) forwards;
}

@keyframes bubble-pop {
    0% { transform: scale(1); opacity: 1; }
    38% { transform: scale(var(--pop-scale, 0.9)); opacity: 0.82; }
    72% { transform: scale(1.1); opacity: 0.56; }
    100% { transform: scale(0.92); opacity: 0.4; }
}

@keyframes pop-ring {
    0% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.3); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.45); }
}

@keyframes pop-particle {
    0% {
        opacity: 0.95;
        transform: translate(-50%, -50%) rotate(var(--pop-angle)) translateX(2px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) rotate(var(--pop-angle)) translateX(var(--pop-distance)) translateY(var(--pop-drift)) scale(0.25);
    }
}
