/* Base Styles - Ninja Theme */
html, body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 30%, #2d2d2d 70%, #1a1a1a 100%);
    overflow: hidden;
    font-family: 'Orbitron', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-text-size-adjust: none;
    font-size: 14px;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    color: #e8e8e8;
    position: relative;
}

/* Add subtle ninja texture overlay */
html::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(139, 69, 19, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(105, 105, 105, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(47, 79, 79, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 1;
}

/* Prevent text selection */
* {
    -webkit-user-select: none;
    user-select: none;
}

/* Game Layer */
#game-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* GameSalad Player */
#gse-player {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
}

#gse-player canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* UI Layer */
#ui-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2;
    pointer-events: none;
}

/* Modal Container */
.modals-container {
    position: fixed;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Overlay Base */
.overlay {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transform: translate3d(0,0,0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.overlay.show {
    display: flex;
}

/* Specific Overlays - Ninja Theme */
#mode-selection-overlay,
#invite-overlay,
#waiting-overlay,
#end-game-overlay,
#leaderboard-overlay,
#rewards-overlay,
#matchmaking-overlay,
#match-ready-overlay {
    background-image: url('../images/BackgroundMoonster.png');
}

/* Overlay Content - Ninja Theme */
.overlay-content {
    width: 92%;
    max-width: 800px;
    padding: 30px;
    margin: 0 auto;
    background: rgba(10, 10, 10, 0.95);
    border: 2px solid #3a3a3a;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

/* Button Styles - adjusted width but keeping other dimensions reduced */
button, 
.mode-button {
    width: 91%;  
    height: 40px;  
    margin: 7px auto;  
    border: none;
    border-radius: 10px;  
    color: white;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;  
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

button:hover,
.mode-button:hover,
.pvp-button:hover,
.epic-ready-button:hover,
.rematch-button:hover,
.back-to-menu-button:hover {
    transform: scale(1.02);
    background: linear-gradient(135deg, #2d2d2d 0%, #404040 100%) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.8) !important;
    border-color: #4a4a4a !important;
}

#mode-selection-overlay .mode-button {
    height: 49px;  
    margin: 0;
}

/* Mode Selection - adjusted container width */
#mode-selection-overlay .button-container {
    width: 91%;  
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;  
}

/* Ninja-Inspired Button Colors - Dark natural tones */
.challenge-button,
#invite-btn,
#start-game-btn,
#save-wallet-btn,
.back-button,
.solo-button,
#cancel-invite-btn,
#cancel-waiting-btn,
#close-end-game-btn,
#leaderboard-close-btn,
#copy-link-btn,
#toggle-diagnostics,
.rewards-button,
#close-rewards-btn,
.invite-button,
.mode-button,
.pvp-button,
.epic-ready-button,
.rematch-button,
.back-to-menu-button,
.epic-player-avatar,
.epic-player-badge {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%) !important;
    color: #e8e8e8 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6) !important;
    border: 2px solid #3a3a3a !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8) !important;
    font-weight: 600 !important;
}

/* Remove animations for cleaner look */
.challenge-button,
.invite-button {
    animation: none;
}

/* Mode Selection */
#mode-selection-overlay .overlay-content {
    gap: 30px;
    padding: 40px;
}

/* Leaderboard Overlay */
#leaderboard-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

#leaderboard-overlay.show {
    display: flex;
}

.leaderboard-content {
    width: 92%;
    max-width: 800px;
    background: rgba(28, 28, 29, 0.95);
    border-radius: 16px;
    margin: 0 auto;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px;
    height: 85vh;
    overflow-y: auto;
}

.leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

.leaderboard-header h2 {
    color: #FFD700;
    font-size: 24px;
    margin: 0;
    text-align: center;
    flex-grow: 1;
}

.leaderboard-header .back-button {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px 16px;
    font-size: 14px;
    height: auto;
    width: auto;
    margin: 0;
}

.leaderboard-image {
    width: 33.6px;
    height: 33.6px;
    margin-right: 16px;
}

.leaderboard-tabs {
    display: flex;
    gap: 8px;
    margin: 0;
    flex-wrap: wrap;
}

/* Leaderboard Tab Buttons */
.tab-button {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    color: #fff;
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.3s ease;
}

/* Time period buttons (Weekly, Monthly, All Time) - 20% smaller */
.period-tabs .tab-button {
    padding: 6px 13px;
    font-size: 9px;
}

/* iOS-specific fixes for Telegram WebApp */
@supports (-webkit-touch-callout: none) {
    .tab-button {
        padding: 4px 10px;
        font-size: 9px;
        height: auto;
        min-height: 0;
    }
    
    .period-tabs .tab-button {
        padding: 3px 8px;
        font-size: 8px;
    }
}

.tab-button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.tab-button.active {
    background: linear-gradient(to right, #FFD700, #FFA500);
    color: #000;
    font-weight: bold;
}

.type-tabs,
.period-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

/* Override any iOS-specific transformations */
@supports (-webkit-touch-callout: none) {
    .tab-button {
        -webkit-transform: none !important;
        transform: none !important;
    }
    
    .period-tabs .tab-button {
        -webkit-transform: scale(0.8) !important;
        transform: scale(0.8) !important;
    }
}

.table-wrapper {
    flex: 1;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-top: 8px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.leaderboard-table th {
    position: sticky;
    top: 0;
    background: rgba(28, 28, 29, 0.95);
    color: #999;
    font-weight: 600;
    text-align: left;
    padding: 12px;
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-table td {
    padding: 12px;
    color: white;
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.leaderboard-table tr:hover td {
    background: rgba(255, 255, 255, 0.05);
}

.rank-1 { color: #FFD700; }
.rank-2 { color: #C0C0C0; }
.rank-3 { color: #CD7F32; }

.current-user td {
    background: rgba(255, 215, 0, 0.1);
    font-weight: bold;
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    z-index: 10;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    border-top-color: #FFD700;
    animation: spin 0.8s linear infinite;
}

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

/* Global image size reduction */
img {
    width: 70%;
    height: auto;
    max-width: 100%;
}

/* Specific image adjustments */
.leaderboard-image {
    width: 33.6px;
    height: 33.6px;
}

.medal {
    width: 16.8px;
    height: 16.8px;
}

.wallet-indicator {
    width: 5.6px;
    height: 5.6px;
}

/* iPhone-specific styles - Fixed oversized values */
@supports (-webkit-touch-callout: none) {
    .overlay-content {
        transform: scale(1) !important;
        padding: 16px !important;    /* Reduced from 40px */
        width: 95% !important;       /* Reduced from 92% */
        max-width: 450px !important; /* Reduced from 800px */
    }

    button, 
    .mode-button {
        width: 100% !important;
        height: 44px !important;     /* Reduced from 116px */
        margin: 8px 0 !important;    /* Reduced from 22px */
        font-size: 14px !important;  /* Reduced from 34px */
        border-radius: 10px !important; /* Reduced from 28px */
    }

    #mode-selection-overlay .button-container {
        width: 100% !important;
        gap: 8px !important;         /* Reduced from 20px */
    }

    #mode-selection-overlay .mode-button {
        height: 44px !important;     /* Reduced from 116px */
    }

    .leaderboard-content {
        padding: 16px !important;    /* Reduced from 40px */
        height: 85vh !important;
    }

    .tab {
        font-size: 14px !important;  /* Reduced from 18px */
        padding: 8px 16px !important; /* Reduced from 14px 28px */
    }

    .leaderboard-table th {
        font-size: 14px !important;  /* Reduced from 20px */
        padding: 12px !important;    /* Reduced from 16px */
    }

    .leaderboard-table td {
        font-size: 14px !important;  /* Reduced from 18px */
        padding: 12px !important;    /* Reduced from 16px */
    }
}

/* Title Images - Removed problematic max-width rule that was interfering with specific sizing */
.moonsters-logo, .game-title {
    height: auto !important;
    display: block !important;
    margin: 10px auto !important;
}

/* iPhone-specific adjustments */
@supports (-webkit-touch-callout: none) {
    .moonsters-logo {
        width: min(90px, 20vw) !important; /* Much smaller - 50% of title */
        height: auto !important;
        max-width: 90px !important;
        max-height: none !important;
        transform: scale(1) !important; /* No scaling needed */
    }
    
    .game-title {
        width: min(180px, 40vw) !important; /* Much smaller title */
        height: auto !important;
        max-width: 180px !important;
        max-height: 15vh !important;
        transform: scale(1) !important; /* No scaling needed */
    }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .leaderboard-content {
        width: 100%;
        padding: 16px;
    }

    .leaderboard-title {
        font-size: 20px;
    }

    .tab {
        padding: 8px 16px;
        font-size: 14px;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 12px;
        font-size: 14px;
    }

    .type-tabs {
        gap: 8px;
        margin: 12px 0;
    }
}

/* Medals */
.medal {
    width: 16.8px;
    height: 16.8px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #000;
}

.medal-1 { background: linear-gradient(45deg, #FFD700, #FFA500); }
.medal-2 { background: linear-gradient(45deg, #C0C0C0, #E0E0E0); }
.medal-3 { background: linear-gradient(45deg, #CD7F32, #B87333); }

/* Leaderboard Medals */
.rank-medal {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin: 0 auto;
}

.medal-1 {
    background: linear-gradient(45deg, #FFD700, #FFA500);
    color: #000;
    box-shadow: 0 2px 4px rgba(255, 215, 0, 0.3);
}

.medal-2 {
    background: linear-gradient(45deg, #C0C0C0, #E0E0E0);
    color: #000;
    box-shadow: 0 2px 4px rgba(192, 192, 192, 0.3);
}

.medal-3 {
    background: linear-gradient(45deg, #CD7F32, #DBA170);
    color: #000;
    box-shadow: 0 2px 4px rgba(205, 127, 50, 0.3);
}

/* Leaderboard Table Styles */
.rank-cell {
    text-align: center;
    width: 60px;
}

.player-cell {
    text-align: left;
    padding-left: 16px;
}

.score-cell {
    text-align: right;
    padding-right: 16px;
    font-family: 'Roboto Mono', monospace;
}

.current-user {
    background: rgba(255, 215, 0, 0.1);
}

/* Wallet Status */
.wallet-connection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #2ecc71;
    margin: 8px 0;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
}

.wallet-indicator {
    width: 5.6px;
    height: 5.6px;
    background: #2ecc71;
    border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 6px #2ecc71;
    animation: glow 1.5s ease-in-out infinite alternate;
}

@keyframes glow {
    from { box-shadow: 0 0 4px #2ecc71; }
    to { box-shadow: 0 0 8px #2ecc71, 0 0 12px #2ecc71; }
}

/* Modal Base Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: none;
    pointer-events: auto;
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.moonsters-logo, .game-title {
    transform: none !important;
    scale: 1 !important;
    transform-origin: center !important;
}

/* Game Loading Overlay */
.gse-loading-overlay {
    position: fixed !important;
    top: auto !important;
    left: auto !important;
    bottom: 20px !important;
    right: 20px !important;
    width: auto !important;
    height: auto !important;
    background: none !important;
    z-index: 1000;
    display: none;  
    align-items: flex-end;
    justify-content: flex-end;
    pointer-events: none;
}

.gse-loading-overlay.show {
    display: flex !important;  
}

.gse-loading-overlay img {
    width: 50px !important;
    height: 50px !important;
    animation: spin 1.5s infinite linear;
}

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

/* Responsive adjustments */
@media (max-width: 768px) {
    .gse-loading-overlay {
        bottom: 15px !important;
        right: 15px !important;
    }
    
    .gse-loading-overlay img {
        width: 40px !important;
        height: 40px !important;
    }
}

/* iPhone-specific adjustments */
@supports (-webkit-touch-callout: none) {
    .gse-loading-overlay {
        bottom: 25px !important;
        right: 25px !important;
    }
    
    .gse-loading-overlay img {
        width: 60px !important;
        height: 60px !important;
    }
}
/* Leaderboard Buttons */
.nav-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    background: linear-gradient(to bottom, #f39c12, #d35400);
    box-shadow: 0 0 10px rgba(243, 156, 18, 0.3);
    -webkit-tap-highlight-color: transparent;
}

.nav-button:hover {
    background: linear-gradient(to bottom, #f5a623, #e67e22);
}

/* Cross-platform overlay styles */
.leaderboard-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: none;
}

.leaderboard-overlay.show {
    display: block;
}

/* Ensure proper scaling on all devices */
.leaderboard-content {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    height: 85vh;
    background: rgba(28, 28, 29, 0.95);
    border-radius: 16px;
    padding: 24px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Animations */
@keyframes pulseGlow {
    0% { box-shadow: 0 0 5px #39FF14; }
    50% { box-shadow: 0 0 15px #39FF14; }
    100% { box-shadow: 0 0 5px #39FF14; }
}

@keyframes referGlow {
    0% { box-shadow: 0 0 15px rgba(218, 34, 255, 0.3); }
    50% { box-shadow: 0 0 25px rgba(218, 34, 255, 0.5); }
    100% { box-shadow: 0 0 15px rgba(218, 34, 255, 0.3); }
}

@keyframes challengeGlow {
    0% { box-shadow: 0 0 15px rgba(102, 126, 234, 0.3); }
    50% { box-shadow: 0 0 25px rgba(102, 126, 234, 0.5); }
    100% { box-shadow: 0 0 15px rgba(102, 126, 234, 0.3); }
}

.auth-button-login {
    background: linear-gradient(135deg, #39FF14 0%, #007000 100%) !important;
    color: #fff !important;
}

.auth-button-logout {
    background: linear-gradient(135deg, #FF6B6B 0%, #D32F2F 100%) !important;
    color: #fff !important;
}

/* Input and form elements - iOS zoom prevention (simplified) */
input, textarea, select {
    font-size: 16px !important; /* Prevent iOS zoom */
}