/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    background: #1a0033;
}

/* Game Container */
.game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* Sparkle Background */
.sparkle-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #ff6b9d 0%, #c44569 20%, #764ba2 60%, #667eea 100%);
    overflow: hidden;
    pointer-events: none;
}

.sparkle-bg::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    animation: sparkle-rotate 20s linear infinite;
}

@keyframes sparkle-rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Floating Elements */
.floating-elements {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.float-element {
    position: absolute;
    font-size: 3rem;
    opacity: 0.2;
    animation: float-around 15s infinite ease-in-out;
}

.float-element.crown { top: 10%; left: 10%; animation-delay: 0s; }
.float-element.heart { top: 20%; right: 15%; animation-delay: 3s; }
.float-element.star { bottom: 30%; left: 20%; animation-delay: 6s; }
.float-element.diamond { bottom: 20%; right: 10%; animation-delay: 9s; }
.float-element.wand { top: 50%; left: 5%; animation-delay: 12s; }

@keyframes float-around {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(50px, -30px) rotate(90deg); }
    50% { transform: translate(-30px, 50px) rotate(180deg); }
    75% { transform: translate(30px, 30px) rotate(270deg); }
}

/* Menu Screen */
.menu-screen {
    align-items: center;
    justify-content: center;
}

.menu-content {
    position: relative;
    z-index: 10;
    text-align: center;
    max-width: 600px;
    padding: 20px;
}

.game-title {
    font-size: clamp(2.5rem, 7vw, 4rem);
    color: #fff;
    text-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.3),
        0 0 20px rgba(255, 182, 193, 0.5);
    margin-bottom: 10px;
    animation: title-glow 2s ease-in-out infinite;
}

@keyframes title-glow {
    0%, 100% { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 182, 193, 0.5); }
    50% { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3), 0 0 30px rgba(255, 182, 193, 0.8); }
}

.crown-icon {
    display: inline-block;
    animation: crown-bounce 2s ease-in-out infinite;
}

@keyframes crown-bounce {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-10px) rotate(5deg); }
}

.subtitle {
    font-size: clamp(1rem, 3vw, 1.5rem);
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 40px;
    font-style: italic;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px 30px;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    margin: 10px;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.btn:hover::before {
    left: 100%;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: linear-gradient(135deg, #ff6b9d 0%, #c44569 100%);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #ff85b1 0%, #d6668a 100%);
    box-shadow: 0 6px 20px rgba(255, 107, 157, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #8095f0 0%, #9369bd 100%);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-icon {
    font-size: 1.3rem;
}

/* Menu Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 40px;
}

/* Kingdom Stats */
.kingdom-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.stat {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-size: 1.1rem;
}

.stat-icon {
    font-size: 1.5rem;
}

/* Tutorial Screen */
.tutorial-screen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

.tutorial-content {
    position: relative;
    z-index: 10;
    max-width: 800px;
    padding: 40px 20px;
    color: #fff;
}

.tutorial-content h2 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.tutorial-sections {
    background: rgba(255, 255, 255, 0.1);
    padding: 30px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    margin-bottom: 30px;
}

.tutorial-section {
    margin-bottom: 30px;
}

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

.tutorial-section h3 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: #ffd700;
}

.tower-types {
    display: grid;
    gap: 15px;
}

.tower-info {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 15px;
}

.tower-icon {
    font-size: 2rem;
}

/* Gallery Screen */
.gallery-screen {
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

.gallery-content {
    position: relative;
    z-index: 10;
    max-width: 1000px;
    padding: 40px 20px;
    width: 100%;
}

.gallery-content h2 {
    text-align: center;
    color: #fff;
    font-size: 2.5rem;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.tower-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.tower-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 25px;
    text-align: center;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.tower-card.unlocked {
    background: rgba(255, 255, 255, 0.15);
    border-color: #ffd700;
}

.tower-card:not(.unlocked) {
    opacity: 0.6;
}

.tower-card:not(.unlocked) .tower-portrait {
    filter: grayscale(100%);
}

.tower-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.tower-portrait {
    font-size: 4rem;
    margin-bottom: 15px;
}

.tower-card h3 {
    color: #fff;
    font-size: 1.3rem;
    margin-bottom: 15px;
}

.tower-stats {
    margin-bottom: 15px;
}

.tower-stats p {
    color: rgba(255, 255, 255, 0.8);
    margin: 5px 0;
}

.tower-description {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    font-style: italic;
    margin-bottom: 10px;
}

.unlock-requirement {
    color: #ffd700;
    font-size: 0.9rem;
    font-weight: 600;
}

/* Game Screen */
.game-screen {
    background: #0a0015;
}

/* Game HUD */
.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
    z-index: 100;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.resource-display, .health-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 15px;
    border-radius: 25px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.resource-display {
    color: #ffd700;
    font-weight: 700;
    font-size: 1.1rem;
}

.health-display {
    color: #ff6b9d;
    font-weight: 700;
    font-size: 1.1rem;
}

.resource-icon, .health-icon {
    font-size: 1.3rem;
}

.wave-display {
    font-size: 1.5rem;
    color: #fff;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
}

.next-wave-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

.next-wave-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(79, 172, 254, 0.5);
}

.next-wave-btn:disabled {
    background: gray;
    cursor: not-allowed;
    transform: scale(1);
}

.ability-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    overflow: hidden;
}

.ability-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.ability-icon {
    font-size: 1.5rem;
}

.cooldown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
}

.ability-btn.on-cooldown .cooldown-overlay {
    display: block;
}

.speed-btn, .pause-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.speed-btn:hover, .pause-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Build Menu */
.build-menu, .upgrade-menu {
    position: absolute;
    background: rgba(20, 0, 40, 0.95);
    border: 2px solid #ff6b9d;
    border-radius: 20px;
    padding: 20px;
    z-index: 200;
    display: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.build-menu h3, .upgrade-menu h3 {
    color: #fff;
    text-align: center;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.tower-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.tower-option {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.tower-option:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #ff6b9d;
    transform: scale(1.05);
}

.tower-option:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tower-emoji {
    font-size: 2rem;
}

.tower-cost {
    color: #ffd700;
    font-size: 0.9rem;
    font-weight: 600;
}

.cancel-build, .close-upgrade {
    width: 100%;
    background: rgba(255, 0, 0, 0.2);
    border: 2px solid rgba(255, 0, 0, 0.4);
    color: #fff;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cancel-build:hover, .close-upgrade:hover {
    background: rgba(255, 0, 0, 0.3);
}

/* Upgrade Menu */
.tower-info-display {
    text-align: center;
    color: #fff;
    margin-bottom: 15px;
}

.tower-level {
    font-size: 1.2rem;
    font-weight: 600;
}

.upgrade-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.upgrade-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.upgrade-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.upgrade-icon {
    font-size: 1.3rem;
}

.upgrade-cost {
    color: #ffd700;
    font-weight: 600;
}

.sell-tower {
    width: 100%;
    background: rgba(255, 100, 100, 0.2);
    border: 2px solid rgba(255, 100, 100, 0.4);
    color: #fff;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 10px;
}

.sell-tower:hover {
    background: rgba(255, 100, 100, 0.3);
}

/* Game Canvas */
#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
}

/* Effects Layer */
.effects-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

/* Pause Screen */
.pause-screen {
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.pause-content {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.9) 0%, rgba(118, 75, 162, 0.9) 100%);
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.pause-content h2 {
    color: #fff;
    font-size: 2rem;
    margin-bottom: 30px;
}

.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

/* Game Over Screen */
.gameover-screen, .victory-screen {
    align-items: center;
    justify-content: center;
}

.gameover-content, .victory-content {
    position: relative;
    z-index: 10;
    background: rgba(255, 255, 255, 0.1);
    padding: 40px;
    border-radius: 30px;
    backdrop-filter: blur(10px);
    text-align: center;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.gameover-title, .victory-title {
    color: #fff;
    font-size: 3rem;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.gameover-stats {
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px 0;
    color: #fff;
}

.stat-label {
    font-size: 1.1rem;
    opacity: 0.8;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #ffd700;
}

.gameover-message, .victory-message {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.2rem;
    margin-bottom: 30px;
}

.gameover-buttons, .victory-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

/* Victory Screen Specific */
.victory-crown {
    font-size: 5rem;
    margin-bottom: 20px;
    animation: crown-spin 2s ease-in-out infinite;
}

@keyframes crown-spin {
    0%, 100% { transform: rotate(-10deg) scale(1); }
    50% { transform: rotate(10deg) scale(1.1); }
}

.victory-rewards {
    background: rgba(255, 215, 0, 0.1);
    border: 2px solid #ffd700;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 30px;
}

.victory-rewards h3 {
    color: #ffd700;
    margin-bottom: 15px;
}

.reward-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px 0;
    color: #fff;
    font-size: 1.1rem;
}

.reward-icon {
    font-size: 1.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-hud {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .hud-center {
        order: -1;
        width: 100%;
        text-align: center;
        margin-bottom: 10px;
    }
    
    .tower-options {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .game-title {
        font-size: 2rem;
    }
}

@media (max-width: 480px) {
    .kingdom-stats {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn {
        padding: 12px 25px;
        font-size: 1rem;
    }
    
    .tower-cards {
        grid-template-columns: 1fr;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes sparkle-burst {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: scale(1.5) rotate(180deg);
        opacity: 0;
    }
}

/* Tower Animations */
.tower {
    transition: all 0.3s ease;
}

.tower:hover {
    transform: scale(1.1);
}

.tower.attacking {
    animation: attack-pulse 0.3s ease;
}

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

/* Projectile Trails */
.projectile-trail {
    position: absolute;
    pointer-events: none;
    z-index: 30;
}

/* Enemy Hit Effects */
.enemy-hit {
    animation: hit-flash 0.2s ease;
}

@keyframes hit-flash {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(2) hue-rotate(180deg); }
}

/* Gold Collection Effect */
.gold-collect {
    position: absolute;
    color: #ffd700;
    font-weight: 700;
    font-size: 1.2rem;
    pointer-events: none;
    animation: gold-float 1s ease-out forwards;
}

@keyframes gold-float {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(-50px);
        opacity: 0;
    }
}