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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    overflow-x: hidden;
}

#game-container {
    width: 100%;
    max-width: 900px;
    padding: 20px;
}

.screen {
    display: none;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Main Menu */
#main-menu h1 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    background: linear-gradient(90deg, #00d4ff, #7b2cbf, #ff6b6b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    text-align: center;
    color: #888;
    margin-bottom: 25px;
    font-size: 1.1rem;
}

.game-selection {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.game-btn {
    background: linear-gradient(145deg, #1e1e3f, #2a2a5a);
    border: 2px solid #3a3a7a;
    border-radius: 12px;
    padding: 18px 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.game-btn:hover {
    transform: translateY(-3px);
    border-color: #00d4ff;
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.3);
}

.game-btn.featured {
    grid-column: 1 / -1;
    background: linear-gradient(145deg, #2a1a3f, #3a2a5a);
    border-color: #ff4444;
}

.game-btn.featured:hover {
    border-color: #ff6666;
    box-shadow: 0 8px 25px rgba(255, 68, 68, 0.3);
}

.game-btn .icon {
    font-size: 2rem;
}

.game-btn .title {
    font-size: 1rem;
    font-weight: bold;
    color: #fff;
}

.game-btn .desc {
    font-size: 0.75rem;
    color: #888;
    text-align: center;
}

.game-btn .highscore {
    font-size: 0.7rem;
    color: #ffd700;
    margin-top: 3px;
    padding: 2px 8px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 8px;
}

/* Menu Buttons */
.menu-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.menu-buttons button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #555;
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.menu-buttons button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #888;
}

.menu-buttons button.active {
    background: rgba(0, 212, 255, 0.3);
    border-color: #00d4ff;
}

/* Game Screen */
#game-screen {
    text-align: center;
}

#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 8px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

#game-info {
    display: flex;
    gap: 12px;
    font-size: 0.9rem;
    flex-wrap: wrap;
}

#game-info span {
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

#highscore-display {
    color: #ffd700 !important;
    background: rgba(255, 215, 0, 0.15) !important;
}

#header-buttons {
    display: flex;
    gap: 8px;
}

#header-buttons button {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s;
}

#pause-btn {
    background: #3498db !important;
}

#pause-btn:hover {
    background: #2980b9 !important;
}

#back-btn:hover {
    background: #c0392b;
}

#gameCanvas {
    background: #0a0a1a;
    border: 3px solid #3a3a7a;
    border-radius: 10px;
    display: block;
    margin: 0 auto;
    cursor: crosshair;
    max-width: 100%;
    height: auto;
    touch-action: none;
}

#game-controls {
    margin-top: 10px;
    color: #888;
    font-size: 0.85rem;
}

/* Tower Defense Panel */
#tower-panel {
    display: none;
    margin: 10px auto;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    max-width: 500px;
    width: fit-content;
}

#tower-panel:not(.hidden) {
    display: block;
}

#tower-selection {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.tower-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid #555;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 60px;
    max-height: 70px;
    height: auto;
}

.tower-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #888;
}

.tower-btn.selected {
    background: rgba(0, 212, 255, 0.3);
    border-color: #00d4ff;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.tower-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tower-icon {
    font-size: 1.5rem;
    margin-bottom: 2px;
}

.tower-cost {
    font-size: 0.7rem;
    color: #ffd700;
}

#ability-selection {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.ability-btn {
    padding: 10px 15px;
    font-size: 1.3rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid #555;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    width: 50px;
    height: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ability-btn:hover:not(.disabled):not(.cooldown) {
    background: rgba(255, 255, 255, 0.2);
    border-color: #00d4ff;
}

.ability-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ability-btn.cooldown {
    opacity: 0.6;
    border-color: #333;
}

#tower-info {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 1rem;
    color: #fff;
}

#tower-money {
    color: #ffd700;
    font-weight: bold;
}

#tower-wave {
    color: #00d4ff;
}

/* Pause Screen */
#pause-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#pause-screen.active {
    display: flex;
}

.pause-content {
    background: linear-gradient(145deg, #1e1e3f, #2a2a5a);
    padding: 40px 60px;
    border-radius: 20px;
    border: 2px solid #3a3a7a;
    text-align: center;
}

.pause-content h2 {
    font-size: 2.5rem;
    margin-bottom: 30px;
    color: #00d4ff;
}

.pause-content button {
    display: block;
    width: 100%;
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    color: white;
    border: none;
    padding: 15px 30px;
    margin: 10px 0;
    border-radius: 10px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
}

.pause-content button:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(0, 212, 255, 0.4);
}

#pause-menu-btn {
    background: #555 !important;
}

/* Touch Controls */
#touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 150px;
    display: flex;
    justify-content: space-between;
    padding: 10px 20px;
    pointer-events: none;
    z-index: 100;
}

#touch-controls.hidden {
    display: none;
}

#touch-left, #touch-right {
    pointer-events: auto;
}

#joystick-container {
    width: 120px;
    height: 120px;
}

#joystick-base {
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

#joystick-stick {
    width: 50px;
    height: 50px;
    background: rgba(0, 212, 255, 0.8);
    border-radius: 50%;
    position: absolute;
    transition: transform 0.1s;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.5);
}

#touch-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.touch-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(0, 212, 255, 0.6);
    border: 3px solid rgba(0, 212, 255, 0.8);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.touch-btn:active {
    transform: scale(0.9);
    background: rgba(0, 212, 255, 0.9);
}

.touch-btn.secondary {
    width: 55px;
    height: 55px;
    background: rgba(255, 107, 107, 0.6);
    border-color: rgba(255, 107, 107, 0.8);
    font-size: 1.2rem;
}

/* Game Over & Victory Screens */
#game-over, #victory {
    text-align: center;
    padding: 50px 30px;
    background: linear-gradient(145deg, #1e1e3f, #2a2a5a);
    border-radius: 20px;
    border: 2px solid #3a3a7a;
}

#game-over h2 {
    font-size: 2.5rem;
    color: #e74c3c;
    margin-bottom: 20px;
}

#victory h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
}

#final-score, #victory-score {
    font-size: 1.4rem;
    margin-bottom: 10px;
}

#new-highscore, #victory-highscore {
    font-size: 1.2rem;
    color: #ffd700;
    margin-bottom: 20px;
    animation: pulse 0.5s ease infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.hidden {
    display: none !important;
}

.victory-msg {
    color: #888;
    margin-bottom: 25px;
}

#game-over button, #victory button {
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    color: white;
    border: none;
    padding: 12px 35px;
    margin: 8px;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
}

#game-over button:hover, #victory button:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(0, 212, 255, 0.4);
}

#menu-btn, #victory-menu-btn {
    background: #555 !important;
}

/* Responsive */
@media (max-width: 700px) {
    .game-selection {
        grid-template-columns: repeat(2, 1fr);
    }

    .game-btn.featured {
        grid-column: 1 / -1;
    }

    #main-menu h1 {
        font-size: 1.8rem;
    }

    .game-btn {
        padding: 12px 8px;
    }

    .game-btn .icon {
        font-size: 1.6rem;
    }

    .game-btn .title {
        font-size: 0.85rem;
    }

    .game-btn .desc {
        font-size: 0.65rem;
    }

    #game-info {
        gap: 6px;
    }

    #game-info span {
        font-size: 0.75rem;
        padding: 3px 6px;
    }

    #game-header {
        flex-direction: column;
        gap: 8px;
    }

    #gameCanvas {
        max-width: 100%;
        height: auto;
    }

    .menu-buttons {
        gap: 8px;
    }

    .menu-buttons button {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .game-selection {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    #game-container {
        padding: 10px;
    }

    .pause-content {
        padding: 30px 40px;
    }

    .pause-content h2 {
        font-size: 2rem;
    }
}

/* Fullscreen mode */
body:fullscreen #game-container,
body:-webkit-full-screen #game-container {
    max-width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Player Name Section */
.player-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

.player-section label {
    color: #888;
    font-size: 0.95rem;
}

.player-section input {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid #3a3a7a;
    border-radius: 8px;
    padding: 8px 15px;
    color: #fff;
    font-size: 1rem;
    width: 180px;
    transition: border-color 0.3s;
}

.player-section input:focus {
    outline: none;
    border-color: #00d4ff;
}

.player-section input::placeholder {
    color: #666;
}

/* Leaderboard Screen */
#leaderboard-screen {
    text-align: center;
    padding: 20px;
}

#leaderboard-screen h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    background: linear-gradient(90deg, #ffd700, #ff6b6b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.leaderboard-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.tab-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid #3a3a7a;
    color: #fff;
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #00d4ff;
}

.tab-btn.active {
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    border-color: transparent;
}

#leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 20px;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    margin: 5px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    transition: background 0.3s;
}

.leaderboard-entry:hover {
    background: rgba(255, 255, 255, 0.1);
}

.leaderboard-entry.top-1 {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.3), rgba(255, 215, 0, 0.1));
    border: 1px solid #ffd700;
}

.leaderboard-entry.top-2 {
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.3), rgba(192, 192, 192, 0.1));
    border: 1px solid #c0c0c0;
}

.leaderboard-entry.top-3 {
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.3), rgba(205, 127, 50, 0.1));
    border: 1px solid #cd7f32;
}

.leaderboard-rank {
    width: 35px;
    font-weight: bold;
    font-size: 1.1rem;
    color: #888;
}

.leaderboard-entry.top-1 .leaderboard-rank { color: #ffd700; }
.leaderboard-entry.top-2 .leaderboard-rank { color: #c0c0c0; }
.leaderboard-entry.top-3 .leaderboard-rank { color: #cd7f32; }

.leaderboard-game {
    width: 35px;
    font-size: 1.2rem;
    text-align: center;
}

.leaderboard-name {
    flex: 1;
    text-align: left;
    padding-left: 15px;
    font-size: 1rem;
    color: #fff;
}

.leaderboard-score {
    font-weight: bold;
    font-size: 1.1rem;
    color: #00d4ff;
    min-width: 80px;
    text-align: right;
}

.leaderboard-date {
    font-size: 0.75rem;
    color: #666;
    min-width: 80px;
    text-align: right;
}

.leaderboard-empty {
    color: #666;
    padding: 40px;
    font-size: 1.1rem;
}

#leaderboard-back {
    background: #555;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s;
}

#leaderboard-back:hover {
    background: #666;
}

/* Scrollbar styling */
#leaderboard-list::-webkit-scrollbar {
    width: 8px;
}

#leaderboard-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

#leaderboard-list::-webkit-scrollbar-thumb {
    background: #3a3a7a;
    border-radius: 4px;
}

#leaderboard-list::-webkit-scrollbar-thumb:hover {
    background: #4a4a9a;
}

@media (max-width: 700px) {
    .player-section {
        flex-direction: column;
        gap: 8px;
    }

    .player-section input {
        width: 100%;
        max-width: 250px;
    }

    .leaderboard-tabs {
        gap: 5px;
    }

    .tab-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .leaderboard-entry {
        padding: 8px 10px;
    }

    .leaderboard-date {
        display: none;
    }
}
