:root {
    --tg-bg-color: var(--tg-theme-bg-color, #ffffff);
    --tg-secondary-bg-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    --tg-text-color: var(--tg-theme-text-color, #000000);
    --tg-hint-color: var(--tg-theme-hint-color, #707579);
    --tg-link-color: var(--tg-theme-link-color, #3390ec);
    --tg-button-color: var(--tg-theme-button-color, #3390ec);
    --tg-button-text-color: var(--tg-theme-button-text-color, #ffffff);
    --tg-subtitle-text-color: var(--tg-theme-subtitle-text-color, #82868a);
}

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

html, body {
    height: 100%;
    width: 100%;
    touch-action: manipulation;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--tg-bg-color);
    color: var(--tg-text-color);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    transition: filter 0.5s cubic-bezier(.4,2,.4,1);
    /* Prevent zoom on double tap */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    
    /* Prevent scroll bounce */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Prevent screen rotation */
@media screen and (orientation: landscape) {
    body::before {
        content: "Please rotate your device to portrait mode";
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.9);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        z-index: 10000;
    }
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.title {
    color: var(--tg-text-color);
    font-size: 2.5em;
    margin-bottom: 30px;
    text-align: center;
    font-weight: 700;
}

.click-button-container {
    position: relative;
    margin-bottom: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.click-button {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 4px solid var(--tg-button-color);
    background: radial-gradient(circle at 60% 40%, #fff 0%, var(--tg-button-color) 60%, var(--tg-link-color) 100%);
    color: white;
    font-size: 2.5rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 40px rgba(51, 144, 236, 0.5);
    transition: box-shadow 0.2s, transform 0.1s, background 0.3s;
    position: relative;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    /* Fast tap response */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    
    /* Prevent text selection */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    
    /* Smooth transitions */
    will-change: transform, box-shadow;
    
    /* Hardware acceleration */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.click-button:hover {
    transform: scale(1.05);
}

.click-button:active {
    transform: scale(1.05);
    box-shadow: 0 0 80px rgba(51, 144, 236, 0.8);
}

.mood-emoji {
    font-size: 4rem;
    position: relative;
    z-index: 2;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Encouragement effect */
.encouragement {
    position: absolute;
    pointer-events: none;
    font-weight: bold;
    font-size: 2rem;
    color: #ffeb3b;
    text-shadow: 0 2px 12px #f00, 0 0 24px #ff0;
    animation: plusone 0.9s forwards;
    z-index: 20;
}

.button-text {
    position: relative;
    z-index: 2;
}

/* Heat blur effect for fast clicking */
.click-button.heat-blur {
    filter: blur(1px);
    animation: heatWave 0.3s ease-in-out;
}

@keyframes heatWave {
    0%, 100% { filter: blur(1px); }
    50% { filter: blur(2px); }
}

/* Boom effect for clicks */
.boom {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    animation: boom 0.4s ease-out forwards;
    z-index: 10;
}

@keyframes boom {
    0% { opacity: 0.7; transform: scale(0.2); }
    60% { opacity: 0.5; transform: scale(1.1); }
    100% { opacity: 0; transform: scale(1.7); }
}

/* Plus one effect */
.plusone {
    position: absolute;
    pointer-events: none;
    font-weight: bold;
    font-size: 1.5rem;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    animation: plusone 0.7s ease-out forwards;
    z-index: 15;
}

@keyframes plusone {
    0% { opacity: 0; transform: translateY(0) scale(1.1); }
    20% { opacity: 1; transform: translateY(-10px) scale(1.2); }
    80% { opacity: 1; transform: translateY(-30px) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(0.9); }
}

/* Rank up effect */
.rank-up-effect {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(45deg, #ff6b6b, #ffd93d);
    color: white;
    padding: 20px 40px;
    border-radius: 20px;
    font-size: 1.5rem;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: rankUpBounce 2s ease-out forwards;
    z-index: 1000;
}

@keyframes rankUpBounce {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0) rotate(180deg);
        opacity: 0;
    }
}

/* Celebration particles */
.rank-celebration {
    position: fixed;
    pointer-events: none;
    animation: celebrationFloat 1.5s ease-out forwards;
    z-index: 999;
}

@keyframes celebrationFloat {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-200px) rotate(360deg) scale(0);
        opacity: 0;
    }
}

/* Player rank highlight */
.player-rank-highlight {
    animation: playerPulse 1s ease-in-out 3;
    background: rgba(0, 242, 254, 0.2) !important;
    border-radius: 8px !important;
}

@keyframes playerPulse {
    0%, 100% { 
        background: rgba(0, 242, 254, 0.2) !important;
        transform: scale(1);
    }
    50% { 
        background: rgba(0, 242, 254, 0.4) !important;
        transform: scale(1.02);
    }
}

/* Explosion effect */
.explosion-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.explosion {
    position: absolute;
    width: 10px;
    height: 10px;
    background: radial-gradient(circle, #ffeb3b, #ff9800);
    border-radius: 50%;
    animation: explode 0.6s ease-out forwards;
}

@keyframes explode {
    0% {
        transform: scale(0) translate(0, 0);
        opacity: 1;
    }
    100% {
        transform: scale(3) translate(var(--dx), var(--dy));
        opacity: 0;
    }
}

/* Motivational messages */
.motivational-messages {
    position: absolute;
    top: -50px;
    width: 200px;
    text-align: center;
    pointer-events: none;
}

.motivational-message {
    position: absolute;
    color: #ffeb3b;
    font-weight: bold;
    font-size: 18px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    animation: floatUp 1.5s ease-out forwards;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-60px) scale(1.2);
        opacity: 0;
    }
}

/* Stats container */
.stats-container {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 40px;
    flex-wrap: wrap;
    gap: 10px;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.stat-item {
    background: var(--tg-secondary-bg-color);
    border-radius: 12px;
    padding: 16px 24px;
    text-align: center;
    min-width: 150px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.stat-label {
    display: block;
    color: var(--tg-hint-color);
    font-size: 13px;
    margin-bottom: 5px;
    font-weight: 500;
}

.stat-value {
    display: block;
    color: var(--tg-text-color);
    font-size: 24px;
    font-weight: 700;
}

/* Leaderboard */
.leaderboard-container {
    width: 100%;
    background: var(--tg-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.leaderboard-tabs {
    display: flex;
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--tg-bg-color);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.tab-button {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--tg-hint-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 14px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tab-button.active {
    background: var(--tg-button-color);
    color: var(--tg-button-text-color);
}

.tab-button:hover:not(.active) {
    background: rgba(51, 144, 236, 0.1);
    color: var(--tg-text-color);
}

.leaderboard-content h3 {
    color: var(--tg-text-color);
    text-align: center;
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 600;
}

.leaderboard-list {
    max-height: 300px;
    overflow-y: auto;
    /* Hide scrollbars while maintaining scroll functionality */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */
}

/* Hide scrollbars for WebKit browsers (Chrome, Safari, Edge) */
.leaderboard-list::-webkit-scrollbar {
    display: none;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--tg-bg-color);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.leaderboard-item.rank-1 { 
    border-left: 4px solid #ffd700;
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.1), var(--tg-bg-color));
}
.leaderboard-item.rank-2 { 
    border-left: 4px solid #c0c0c0;
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.1), var(--tg-bg-color));
}
.leaderboard-item.rank-3 { 
    border-left: 4px solid #cd7f32;
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.1), var(--tg-bg-color));
}

.position-changed {
    animation: positionChange 0.8s ease-out;
}

@keyframes positionChange {
    0% { transform: translateX(-20px); opacity: 0.5; background: rgba(76, 175, 80, 0.3); }
    25% { transform: translateX(10px); opacity: 0.8; background: rgba(76, 175, 80, 0.4); }
    50% { transform: translateX(-5px); opacity: 0.9; background: rgba(76, 175, 80, 0.5); }
    75% { transform: translateX(2px); opacity: 1; background: rgba(76, 175, 80, 0.3); }
    100% { transform: translateX(0); opacity: 1; background: transparent; }
}

/* Enhanced rank up celebrations */
.rank-improvement {
    animation: rankImprovement 1.2s ease-out;
    position: relative;
    overflow: visible;
}

@keyframes rankImprovement {
    0% { 
        transform: scale(1);
        box-shadow: 0 0 0 rgba(76, 175, 80, 0);
    }
    20% { 
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
    }
    40% { 
        transform: scale(1.02);
        box-shadow: 0 0 30px rgba(76, 175, 80, 0.8);
    }
    60% { 
        transform: scale(1.03);
        box-shadow: 0 0 25px rgba(76, 175, 80, 0.6);
    }
    80% { 
        transform: scale(1.01);
        box-shadow: 0 0 15px rgba(76, 175, 80, 0.4);
    }
    100% { 
        transform: scale(1);
        box-shadow: 0 0 0 rgba(76, 175, 80, 0);
    }
}

/* Rank drop animation */
.rank-drop {
    animation: rankDrop 0.6s ease-out;
}

@keyframes rankDrop {
    0% { 
        transform: translateY(0);
        opacity: 1;
    }
    50% { 
        transform: translateY(5px);
        opacity: 0.7;
        background: rgba(244, 67, 54, 0.1);
    }
    100% { 
        transform: translateY(0);
        opacity: 1;
        background: transparent;
    }
}

/* Sparkle effect for rank improvements */
@keyframes sparkleFloat {
    0% { 
        opacity: 0; 
        transform: scale(0) rotate(0deg) translateY(0px);
    }
    20% { 
        opacity: 1; 
        transform: scale(1.2) rotate(90deg) translateY(-5px);
    }
    80% { 
        opacity: 0.8; 
        transform: scale(1) rotate(270deg) translateY(-15px);
    }
    100% { 
        opacity: 0; 
        transform: scale(0.3) rotate(360deg) translateY(-25px);
    }
}

/* Avatar styles */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: white;
    margin-right: 12px;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.emoji-avatar {
    font-size: 18px;
    background-clip: text;
    -webkit-background-clip: text;
}

.player-rank {
    font-weight: 600;
    color: var(--tg-hint-color);
    margin-right: 8px;
    min-width: 25px;
    font-size: 14px;
}

.player-name {
    flex: 1;
    color: var(--tg-text-color);
    font-weight: 500;
    font-size: 15px;
}

.player-clicks {
    color: var(--tg-link-color);
    font-weight: 600;
    font-size: 15px;
}

.clicks-to-next {
    font-size: 0.9em;
    margin-left: 0.5em;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.clicks-to-next.very-close {
    color: #2e7d32;
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.2), rgba(139, 195, 74, 0.2));
    border-color: rgba(76, 175, 80, 0.4);
    animation: pulse 1s infinite, glow-green 2s ease-in-out infinite;
    box-shadow: 0 0 12px rgba(76, 175, 80, 0.3);
}

.clicks-to-next.close {
    color: #388e3c;
    background: linear-gradient(135deg, rgba(139, 195, 74, 0.15), rgba(156, 204, 101, 0.15));
    border-color: rgba(139, 195, 74, 0.3);
    animation: pulse 2s infinite;
    box-shadow: 0 0 8px rgba(139, 195, 74, 0.2);
}

.clicks-to-next.medium {
    color: #f57c00;
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.1), rgba(255, 152, 0, 0.1));
    border-color: rgba(255, 193, 7, 0.2);
    box-shadow: 0 0 6px rgba(255, 193, 7, 0.15);
}

.clicks-to-next.far {
    color: #d84315;
    background: linear-gradient(135deg, rgba(255, 152, 0, 0.1), rgba(244, 67, 54, 0.1));
    border-color: rgba(255, 152, 0, 0.2);
    box-shadow: 0 0 4px rgba(255, 152, 0, 0.1);
}

@keyframes glow-green {
    0%, 100% { 
        box-shadow: 0 0 12px rgba(76, 175, 80, 0.3);
        transform: scale(1);
    }
    50% { 
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.5);
        transform: scale(1.05);
    }
}

.loading {
    text-align: center;
    color: var(--tg-hint-color);
    padding: 20px;
    font-size: 14px;
}

.no-data {
    text-align: center;
    color: var(--tg-hint-color);
    padding: 20px;
    font-style: italic;
    font-size: 14px;
}

/* Player rank highlight */
.player-rank-highlight {
    animation: playerPulse 1s ease-in-out 3;
    background: linear-gradient(90deg, transparent, rgba(255,235,59,0.3), transparent) !important;
    border-radius: 8px !important;
}

@keyframes playerPulse {
    0%, 100% { 
        background: transparent; 
        transform: scale(1); 
    }
    50% { 
        background: rgba(255,235,59,0.2); 
        transform: scale(1.02); 
    }
}

/* Tab switch effect */
.tab-switch-effect {
    animation: tabSwitch 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes tabSwitch {
    0% { opacity: 0; transform: translateY(10px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Click counter animation */
.stat-value.animate {
    animation: pulse 0.3s ease;
}

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

/* Rank up effect */
.rank-up-effect {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: bold;
    color: #ffeb3b;
    text-shadow: 0 0 20px #ffeb3b, 0 0 40px #ff9800;
    pointer-events: none;
    z-index: 1000;
    animation: rankUpAnimation 2s ease-out forwards;
}

@keyframes rankUpAnimation {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5) rotateZ(-10deg); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2) rotateZ(5deg); }
    40% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotateZ(-2deg); }
    60% { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotateZ(1deg); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotateZ(0deg); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8) translateY(-50px); }
}

/* Celebration particles */
.rank-celebration {
    position: fixed;
    pointer-events: none;
    z-index: 999;
    animation: celebration 1.5s ease-out forwards;
    font-size: 2rem;
}

@keyframes celebration {
    0% { opacity: 1; transform: scale(1) rotateZ(0deg); }
    50% { opacity: 0.8; transform: scale(1.1) rotateZ(180deg); }
    100% { opacity: 0; transform: scale(0.3) rotateZ(360deg) translateY(-100px); }
}

/* Context leaderboard styles */
.context-info {
    background: var(--tg-secondary-bg-color, #17212b);
    border: 1px solid var(--tg-button-color, #4facfe);
    border-radius: 8px;
    padding: 0.7rem;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--tg-button-color, #4facfe);
    font-weight: 500;
}

.current-user-context {
    background: linear-gradient(135deg, 
        rgba(79, 172, 254, 0.15), 
        rgba(0, 242, 254, 0.15)
    );
    border: 2px solid var(--tg-button-color, #4facfe);
    box-shadow: 0 0 15px rgba(79, 172, 254, 0.3);
    transform: scale(1.02);
    animation: contextUserPulse 2s ease-in-out infinite;
}

@keyframes contextUserPulse {
    0%, 100% { 
        box-shadow: 0 0 15px rgba(79, 172, 254, 0.3);
        transform: scale(1.02);
    }
    50% { 
        box-shadow: 0 0 25px rgba(79, 172, 254, 0.5);
        transform: scale(1.03);
    }
}

/* Enhanced leaderboard item styles for context mode */
.leaderboard-item.current-user-context .player-rank {
    color: var(--tg-button-color, #4facfe);
    font-weight: bold;
    font-size: 1.1em;
}

.leaderboard-item.current-user-context .player-name {
    color: var(--tg-button-text-color, #ffffff);
    font-weight: bold;
}

.leaderboard-item.current-user-context .player-clicks {
    color: var(--tg-button-color, #4facfe);
    font-weight: bold;
}

/* Responsive design */
@media (max-width: 400px) {
    .click-button {
        width: 160px;
        height: 160px;
        font-size: 16px;
    }
    
    .title {
        font-size: 2em;
    }
    
    .stats-container {
        flex-direction: column;
        gap: 10px;
    }
    
    .stat-item {
        min-width: unset;
    }
}
