body {
    font-family: sans-serif;
    background-color: var(--bg-color-day);
    margin: 0;
    padding-top: 80px; /* Space for the menu bar */
    user-select: none; /* Prevent text selection */
    -webkit-user-drag: none; /* Prevent dragging */
    overflow-x: hidden; /* Prevent horizontal scrolling */
    color: var(--text-color-day);
    position: relative; /* For absolute positioning of children */
}

/* Subtle animated background gradient */
@keyframes bg-gradient-shift {
    0% { background-color: var(--bg-color-day); background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

body.animated-bg {
    background-image: linear-gradient(120deg, rgba(255,255,255,0.02), rgba(0,0,0,0.02) 25%, rgba(255,255,255,0.01) 60%);
    background-size: 300% 300%;
    animation: bg-gradient-shift 18s linear infinite;
}

.container {
    --final-scale: 1.2;
    text-align: center;
    transform: scale(var(--final-scale));
    margin-top: 50px;
}

#box {
    width: 250px;
    height: 250px;
    background-color: var(--box-bg-day);
    margin: 25px auto;
    cursor: pointer;
    border-radius: 50%; /* Circle Shape */
}

#box.waiting {
    background-color: var(--box-bg-day);
}

#box.ready {
    background-color: var(--box-ready-bg-day);
}

button {
    padding: 15px 30px;
    font-size: 20px;
    cursor: pointer;
}

/* Button ripple effect (pure CSS) */
button {
    position: relative;
    overflow: hidden;
}

button .ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    background: rgba(255,255,255,0.5);
    animation: ripple-effect 600ms cubic-bezier(.2,.9,.2,1) forwards;
    pointer-events: none;
}

@keyframes ripple-effect {
    to { transform: scale(4); opacity: 0; }
}

/* Subtle shine across the ready box (animation removed) */
#box.ready::before {
    content: '';
    position: absolute;
    left: -40%;
    top: -40%;
    width: 180%;
    height: 180%;
    background: linear-gradient(120deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.18) 50%, rgba(255,255,255,0.06) 100%);
    transform: rotate(12deg) translateX(-100%);
    pointer-events: none;
    border-radius: 50%;
}

@keyframes box-shine {
    to { transform: rotate(12deg) translateX(100%); opacity: 0; }
}



.fade-out {
    opacity: 0;
    transition: opacity 2s ease-out; /* Fade out over 2 seconds */
}

/* Leaderboard Button Styles */
#leaderboardButton {
    position: absolute;
    top: 70px;
    left: 15px;
    background: none;
    border: 2px solid var(--button-border-color);
    border-radius: 50%;
    padding: 5px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--icon-color);
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
    z-index: 1001; /* Ensure it's above the menu bar */
}

#leaderboardButton:hover {
    background-color: rgba(128, 128, 128, 0.2);
}

#leaderboardButton svg {
    width: 24px;
    height: 24px;
}

/* Leaderboard Panel Styles */
#leaderboardPanel {
    opacity: 0;
    visibility: hidden;
    position: absolute;
    top: 70px;
    left: 25px;
    width: 30%;
    padding: 25px;
    background-color: var(--container-bg-day);
    color: var(--text-color-day);
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out, transform 0.3s ease-in-out;
    transform: translateY(-20px);
}

#leaderboardPanel.leaderboard-panel-show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Enhanced, high-quality animations */
/* micro-particles for success */
.box-sparkles {
    position: relative;
}
.box-sparkles::after {
    content: '';
    position: absolute;
    inset: -8% -8%;
    pointer-events: none;
    background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,0.95) 0 4px, transparent 5px),
                      radial-gradient(circle at 80% 30%, rgba(255,220,80,0.95) 0 4px, transparent 6px),
                      radial-gradient(circle at 40% 80%, rgba(120,200,255,0.9) 0 3px, transparent 5px);
    background-repeat: no-repeat;
    opacity: 0;
    transform: scale(0.9);
    animation: sparkles-pop 680ms ease-out forwards;
}

@keyframes sparkles-pop {
    0% { opacity: 0; transform: scale(0.8) translateY(6px) rotate(-6deg); }
    40% { opacity: 1; transform: scale(1.02) translateY(-4px) rotate(2deg); }
    100% { opacity: 0; transform: scale(1.06) translateY(-22px) rotate(6deg); }
}

/* subtle 'explode' pulse for very fast responses */
.box-explode {
    animation: explode 420ms cubic-bezier(.22,.9,.3,1) forwards;
}
@keyframes explode {
    0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(255,255,255,0)); }
    30% { transform: scale(1.18); filter: drop-shadow(0 12px 24px rgba(0,0,0,0.18)); }
    100% { transform: scale(1); filter: drop-shadow(0 6px 12px rgba(0,0,0,0.12)); }
}

/* too-early 'snap back' */
.box-snap {
    animation: snap 420ms cubic-bezier(.2,.9,.2,1);
}
@keyframes snap {
    0% { transform: translateY(0) scale(1); }
    20% { transform: translateY(-8px) rotate(-2deg) scale(1.02); }
    60% { transform: translateY(6px) rotate(2deg) scale(0.98); }
    100% { transform: translateY(0) rotate(0) scale(1); }
}

/* Cancelled: calm fade */
.box-calm {
    animation: calm-fade 720ms ease-out forwards;
}
@keyframes calm-fade { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0.6; transform: scale(0.98); } }

/* Buttons: tactile micro-interaction */
button:active { transform: translateY(2px) scale(0.995); box-shadow: 0 2px 6px rgba(0,0,0,0.12) inset; }
button { transition: transform 220ms cubic-bezier(.2,.9,.2,1), box-shadow 220ms; }

/* Leaderboard: dramatic swoop-in with backdrop blur */
#leaderboardPanel {
    backdrop-filter: blur(0px) saturate(1);
}
#leaderboardPanel.leaderboard-panel-show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}


#leaderboardPanel h2 {
    margin-top: 0;
    font-size: 1.2em;
    text-align: center;
}

#leaderboardPanel .close-button {
    position: absolute;
    top: 5px;
    left: 10px;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-color-day);
}

#leaderboardPanel .close-button:hover,
#leaderboardPanel .close-button:focus {
    color: #f44336;
}

#scoreList {
    list-style-type: none;
    padding: 0;
    margin: 10px 0;
}

#scoreList li {
    padding: 5px 0;
    border-bottom: 1px solid var(--text-color-day);
    font-size: 0.9em;
    text-align: center;
}

#scoreList li:last-child {
    border-bottom: none;
}

#leaderboardPanel p {
    text-align: center;
    font-weight: bold;
    margin-top: 10px;
}

body.leaderboard-right #leaderboardButton {
    left: auto;
    right: 15px;
}

body.leaderboard-right #leaderboardPanel {
    left: auto;
    right: 25px;
}

body.leaderboard-right #leaderboardPanel .close-button {
    left: auto;
    right: 10px;
}

@media (max-width: 768px) {
    .container {
        transform: scale(1);
        margin-top: 30px;
    }

    #box {
        width: 200px;
        height: 200px;
    }

    #leaderboardPanel {
        width: 80%;
        left: 10%;
        right: 10%;
    }

    body.leaderboard-right #leaderboardPanel {
        left: 10%;
        right: 10%;
    }

    #leaderboardButton {
        top: 120px;
    }
}

#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f00;
    opacity: 0.7;
    animation: confetti-fall 5s linear forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-10vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

.high-score {
    font-weight: bold;
    color: #ffd700;
}

.high-score::before {
    content: '⭐';
    margin-right: 0.5em;
}

#challengeButton {
    margin-left: 10px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.modal-overlay.show {
    opacity: 1;
}

.modal-content {
    background-color: var(--container-bg-day);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    text-align: center;
    position: relative;
    transform: translateY(-20px);
    transition: transform 0.3s ease-in-out;
}

.modal-overlay.show .modal-content {
    transform: translateY(0);
}

.modal-content h2 {
    margin-top: 0;
    color: var(--text-color-day);
}

.modal-content p {
    color: var(--text-color-day);
    margin-bottom: 20px;
}

#challengeLink {
    width: 100%;
    padding: 10px;
    margin-bottom: 20px;
    border: 1px solid var(--button-border-color);
    border-radius: 5px;
    background-color: var(--bg-color-day);
    color: var(--text-color-day);
    text-align: center;
}

#copyChallengeLink {
    width: 100%;
}

.modal-content .close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    color: var(--text-color-day);
    cursor: pointer;
}