* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: #000;
    color: #fff;
    overflow: hidden;
    user-select: none;
}

#game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

/* Overlays - block all clicks so nothing passes through to canvas/menu */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    pointer-events: auto;
}

.overlay.hidden {
    display: none;
}

/* Shop Styles */
.shop-container {
    position: relative;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #0052FF;
    border-radius: 15px;
    padding: 20px;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 82, 255, 0.5);
}

/* Shop close button: top-right corner, square like Settings window */
#shop-overlay .shop-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 4px;
    background: #cc0000;
    border: 2px solid #990000;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    z-index: 10;
}
#shop-overlay .shop-close-btn:hover {
    background: #ee0000;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(204, 0, 0, 0.5);
}

.shop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    padding-right: 44px;
    border-bottom: 2px solid #0052FF;
    flex-wrap: wrap;
    gap: 10px;
    flex-shrink: 0;
}

.shop-header h2 {
    color: #00ffff;
    text-shadow: 0 0 10px #00ffff;
    font-size: 2em;
}

.shop-currency {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
}

.shop-currency span {
    padding: 5px 10px;
    border-radius: 5px;
    background: rgba(0, 82, 255, 0.2);
    border: 1px solid #0052FF;
}

#shop-gold {
    color: #ffd700;
    text-shadow: 0 0 5px #ffd700;
}

#shop-lightning {
    color: #00ffff;
    text-shadow: 0 0 5px #00ffff;
}

#shop-diamonds {
    color: #ff00ff;
    text-shadow: 0 0 5px #ff00ff;
}

.close-btn {
    background: #ff4444;
    border: none;
    color: white;
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
}

.close-btn:hover {
    background: #ff6666;
    transform: scale(1.1);
    box-shadow: 0 0 15px #ff4444;
}

.shop-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.tab-btn {
    background: #2a2a4e;
    border: 2px solid #0052FF;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.tab-btn:hover {
    background: #3a3a5e;
    border-color: #00ffff;
}

.tab-btn.active {
    background: #0052FF;
    border-color: #00ffff;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
}

.shop-content {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.shop-item {
    background: #1a1a2e;
    border: 2px solid #333;
    border-radius: 10px;
    padding: 15px;
    transition: all 0.3s;
}

.shop-item:hover {
    border-color: #0052FF;
    box-shadow: 0 0 15px rgba(0, 82, 255, 0.3);
    transform: translateY(-2px);
}

.shop-item.owned {
    border-color: #00ff00;
    background: rgba(0, 255, 0, 0.1);
}

.shop-item-icon {
    font-size: 48px;
    text-align: center;
    margin-bottom: 10px;
}

.shop-item-name {
    font-size: 18px;
    font-weight: bold;
    color: #00ffff;
    margin-bottom: 8px;
    text-align: center;
}

.shop-item-stats {
    font-size: 12px;
    color: #aaa;
    margin-bottom: 10px;
    line-height: 1.5;
}

.shop-item-price {
    font-size: 16px;
    color: #ffd700;
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
}

.shop-item-btn {
    width: 100%;
    padding: 10px;
    background: #0052FF;
    border: none;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s;
}

.shop-item-btn:hover:not(:disabled) {
    background: #0066ff;
    box-shadow: 0 0 10px rgba(0, 82, 255, 0.5);
}

.shop-item-btn:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.shop-item-btn.owned {
    background: #00aa00;
}

/* Pause/Game Over Styles */
.pause-container,
.gameover-container {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #00ffff;
    border-radius: 15px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.5);
    max-width: 400px;
    width: 90%;
    margin: 0 auto;
}

.pause-container h2,
.gameover-container h2 {
    color: #00ffff;
    text-shadow: 0 0 10px #00ffff;
    font-size: 2.5em;
    margin-bottom: 30px;
}

/* Pause overlay: switch between normal (Resume/Reset/Menu) and check-in waiting (no buttons) */
.pause-content-normal.hidden,
.pause-content-checkin-waiting.hidden {
    display: none !important;
}

/* When check-in waiting: push the message box to the top so it stays visible above the transaction signing popup */
#pause-overlay.pause-checkin-waiting {
    align-items: flex-start;
    padding-top: 3vh;
}
#pause-overlay.pause-checkin-waiting .pause-container {
    align-self: flex-start;
    margin-top: 0;
}

.pause-content-checkin-waiting {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.pause-checkin-waiting-text {
    color: #00ffff;
    font-size: 1.1em;
    line-height: 1.5;
    max-width: 320px;
    margin: 0;
}

.menu-btn {
    background: #0052FF;
    border: 2px solid #00ffff;
    color: white;
    padding: 15px 30px;
    margin: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.3s;
    min-width: 200px;
}

.menu-btn:hover {
    background: #0066ff;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
    transform: scale(1.05);
}

.reset-btn {
    background: linear-gradient(135deg, #cc0000 0%, #ff4400 100%) !important;
    border: 2px solid #ff4444 !important;
    color: #ffffff !important;
    margin-top: 10px;
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.5);
}

.reset-btn:hover {
    background: linear-gradient(135deg, #ff0000 0%, #ff6600 100%) !important;
    border-color: #ff6666 !important;
    box-shadow: 0 0 25px rgba(255, 68, 68, 0.8);
    transform: scale(1.05);
}

.exit-btn {
    background: linear-gradient(135deg, #ff6600 0%, #ff8800 100%) !important;
    border: 2px solid #ff8844 !important;
    color: #ffffff !important;
    margin-top: 10px;
    box-shadow: 0 0 15px rgba(255, 136, 68, 0.5);
}

.exit-btn:hover {
    background: linear-gradient(135deg, #ff8800 0%, #ffaa00 100%) !important;
    border-color: #ffaa66 !important;
    box-shadow: 0 0 25px rgba(255, 136, 68, 0.8);
    transform: scale(1.05);
}

/* Leaderboard Styles – table has horizontal scroll so Check-in date fits */
#leaderboard-overlay {
    overflow-x: hidden;
}

.leaderboard-container {
    position: relative;
    background: linear-gradient(135deg, #0f1a2e 0%, #152548 100%);
    border: 2px solid #00ffff;
    border-radius: 12px;
    padding: 12px 14px;
    width: min(96vw, 520px);
    max-width: 100%;
    max-height: 88vh;
    overflow-x: hidden;
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.4);
}

/* Leaderboard close button: top-right corner, square like Shop/Settings */
#leaderboard-overlay .leaderboard-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 4px;
    background: #cc0000;
    border: 2px solid #990000;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    z-index: 10;
}
#leaderboard-overlay .leaderboard-close-btn:hover {
    background: #ee0000;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(204, 0, 0, 0.5);
}

.leaderboard-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    margin-bottom: 2px;
    border-radius: 8px;
}

/* Horizontal scrollbar – shop style, miniature (so users see they can scroll) */
.leaderboard-table-wrap::-webkit-scrollbar {
    height: 8px;
}

.leaderboard-table-wrap::-webkit-scrollbar-track {
    background: #1a1a2e;
    border-radius: 4px;
}

.leaderboard-table-wrap::-webkit-scrollbar-thumb {
    background: #0052FF;
    border-radius: 4px;
}

.leaderboard-table-wrap::-webkit-scrollbar-thumb:hover {
    background: #0066ff;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-right: 44px;
    flex-wrap: wrap;
}

.leaderboard-header h2 {
    color: #00ffff;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.6);
    font-size: 1.35em;
}

.leaderboard-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.menu-btn.small-btn {
    padding: 6px 10px;
    min-width: auto;
    font-size: 12px;
}

.leaderboard-section {
    margin-bottom: 14px;
}

.leaderboard-section:last-child {
    margin-bottom: 0;
}

.leaderboard-section h3 {
    color: #00ff88;
    margin-bottom: 6px;
    font-size: 0.95em;
}

.leaderboard-section h3.error {
    color: #ff6666;
}

.leaderboard-table {
    min-width: 520px;
    width: 100%;
    border-collapse: collapse;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    overflow: hidden;
    table-layout: fixed;
    font-size: 10px;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 4px 5px;
    text-align: left;
    border-bottom: 1px solid rgba(0, 255, 255, 0.15);
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
    text-align: center;
    width: 6%;
}

.leaderboard-table th {
    color: #00ffff;
    background: rgba(0, 82, 255, 0.25);
    text-transform: uppercase;
    font-size: 9px;
    letter-spacing: 0.04em;
}

.leaderboard-table td:nth-child(1) { width: 6%; }   /* # */
.leaderboard-table td:nth-child(2) { width: 14%; } /* Score */
.leaderboard-table td:nth-child(3) { width: 20%; } /* Player */
.leaderboard-table td:nth-child(4) { width: 8%; }  /* Wave */
.leaderboard-table td:nth-child(5) { width: 18%; } /* Date */
.leaderboard-table td:nth-child(6) { width: 8%; }  /* Streak */
.leaderboard-table td:nth-child(7) { width: 18%; min-width: 72px; } /* Check-in */

.leaderboard-table th:nth-child(1) { width: 6%; }
.leaderboard-table th:nth-child(2) { width: 14%; }
.leaderboard-table th:nth-child(3) { width: 20%; }
.leaderboard-table th:nth-child(4) { width: 8%; }
.leaderboard-table th:nth-child(5) { width: 18%; }
.leaderboard-table th:nth-child(6) { width: 8%; }
.leaderboard-table th:nth-child(7) { width: 18%; min-width: 72px; } /* Check-in */

.leaderboard-table tbody tr:nth-child(even) {
    background: rgba(0, 255, 255, 0.05);
}

.leaderboard-table tbody tr:hover {
    background: rgba(0, 255, 255, 0.12);
}

/* Milestone Celebration Animations */
@keyframes milestonePopIn {
    0% { 
        transform: translate(-50%, -50%) scale(0.1);
        opacity: 0;
    }
    60% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes milestonePopOut {
    from { 
        opacity: 1; 
    }
    to { 
        opacity: 0; 
    }
}

.milestone-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.milestone-character {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 400px;
    height: auto;
    animation: milestonePopIn 0.6s ease-out forwards,
               milestonePopOut 0.4s ease-in 2.1s forwards;
    transform: translate(-50%, -50%);
}

.milestone-text {
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: 48px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    animation: milestonePopIn 0.6s ease-out forwards,
               milestonePopOut 0.4s ease-in 2.1s forwards;
    transform: translate(-50%, -50%);
    white-space: nowrap;
}

#final-stats {
    margin: 20px 0;
    font-size: 18px;
    color: #aaa;
}

/* Scrollbar Styling (on shop content area) */
.shop-content::-webkit-scrollbar {
    width: 10px;
}

.shop-content::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.shop-content::-webkit-scrollbar-thumb {
    background: #0052FF;
    border-radius: 5px;
}

.shop-content::-webkit-scrollbar-thumb:hover {
    background: #0066ff;
}

/* Instructions / How to Play overlay – same style as shop (scroll + close X) */
.instructions-container {
    position: relative;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #0052FF;
    border-radius: 15px;
    padding: 20px;
    max-width: 90%;
    max-height: 90%;
    width: 500px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(0, 82, 255, 0.5);
}

#instructions-overlay .instructions-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 4px;
    background: #cc0000;
    border: 2px solid #990000;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    z-index: 10;
}

#instructions-overlay .instructions-close-btn:hover {
    background: #ee0000;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(204, 0, 0, 0.5);
}

.instructions-header {
    margin-bottom: 15px;
    padding-bottom: 12px;
    padding-right: 44px;
    border-bottom: 2px solid #0052FF;
    flex-shrink: 0;
}

.instructions-header h2 {
    color: #00ffff;
    text-shadow: 0 0 10px #00ffff;
    font-size: 1.6em;
    margin: 0;
}

.instructions-content {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

/* Same scrollbar as shop */
.instructions-content::-webkit-scrollbar {
    width: 10px;
}

.instructions-content::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.instructions-content::-webkit-scrollbar-thumb {
    background: #0052FF;
    border-radius: 5px;
}

.instructions-content::-webkit-scrollbar-thumb:hover {
    background: #0066ff;
}

.instructions-body {
    white-space: pre-line;
    font-family: Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #e8e8e8;
    margin: 0;
    padding: 4px 8px 16px 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-weight: 500;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .shop-container {
        padding: 15px;
        max-width: 95%;
    }
    
    .shop-content {
        grid-template-columns: 1fr;
    }
    
    .shop-tabs {
        flex-direction: column;
    }
    
    .tab-btn {
        width: 100%;
    }
}
