* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Arial', sans-serif; background: #0a0a1a; color: #eee; overflow: hidden; height: 100vh; }
.screen { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; }
.screen.active { display: flex; align-items: center; justify-content: center; }

/* Loading */
.loading-content, .start-content, .gameover-content, .victory-content { text-align: center; padding: 2rem; }
.loading-content h1, .start-content h1 { font-size: 2.5rem; color: #f44; text-shadow: 0 0 20px rgba(255,0,0,0.5); margin-bottom: 1rem; }
.loading-bar { width: 300px; height: 8px; background: #333; border-radius: 4px; margin: 1rem auto; overflow: hidden; }
.loading-progress { height: 100%; background: linear-gradient(90deg, #f44, #fa0); width: 0; transition: width 0.1s; border-radius: 4px; }
.tagline { font-size: 1.2rem; color: #aaa; margin-bottom: 2rem; }

/* Buttons */
.btn-primary { background: linear-gradient(135deg, #f44, #c00); color: #fff; border: none; padding: 14px 40px; font-size: 1.3rem; font-weight: bold; border-radius: 8px; cursor: pointer; text-transform: uppercase; letter-spacing: 2px; transition: all 0.2s; }
.btn-primary:hover { transform: scale(1.05); box-shadow: 0 0 20px rgba(255,0,0,0.4); }
.btn-secondary { background: #333; color: #fff; border: 1px solid #555; padding: 10px 30px; font-size: 1rem; border-radius: 6px; cursor: pointer; margin-top: 0.5rem; }

/* Game Info */
.game-info { text-align: left; max-width: 500px; margin: 1.5rem auto 0; background: rgba(255,255,255,0.05); padding: 1.5rem; border-radius: 8px; }
.game-info h3 { color: #f80; margin-bottom: 0.5rem; }
.game-info ul { padding-left: 1.5rem; margin-bottom: 0.5rem; }
.game-info li { margin: 0.3rem 0; color: #ccc; }

/* Game Layout */
.game-container { display: flex; width: 100%; height: 100vh; background: #0a0a1a; }
#sidebar { width: 220px; min-width: 220px; background: #111; border-right: 1px solid #222; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar-content { padding: 10px; flex: 1; display: flex; flex-direction: column; gap: 10px; }
#game-main { flex: 1; display: flex; flex-direction: column; align-items: center; position: relative; overflow: hidden; }

/* Stats */
.stats-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { background: rgba(255,255,255,0.05); padding: 6px 8px; border-radius: 4px; display: flex; align-items: center; gap: 4px; }
.stat-label { font-size: 0.85rem; }
.stat-value { font-weight: bold; font-size: 1rem; color: #fff; }

/* Tower Selection */
.tower-selection h3 { font-size: 0.9rem; color: #888; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.tower-buttons { display: flex; flex-direction: column; gap: 4px; }
.tower-btn { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.05); border: 1px solid #333; border-radius: 6px; padding: 8px; cursor: pointer; color: #eee; transition: all 0.15s; }
.tower-btn:hover { background: rgba(255,255,255,0.1); border-color: #555; }
.tower-btn.selected { background: rgba(255,100,0,0.15); border-color: #f80; }
.tower-btn.unaffordable { opacity: 0.4; }
.tower-icon { font-size: 1.3rem; width: 28px; text-align: center; }
.tower-name { flex: 1; font-size: 0.85rem; font-weight: bold; }
.tower-cost { font-size: 0.8rem; color: #fa0; font-weight: bold; }

/* Tower Info Panel */
.tower-info-panel { background: rgba(255,255,255,0.05); border: 1px solid #333; border-radius: 6px; padding: 10px; }
.tower-info-panel h3 { color: #fa0; margin-bottom: 6px; font-size: 0.95rem; }
#tower-details div { font-size: 0.85rem; margin: 2px 0; color: #ccc; }
.tower-actions { display: flex; gap: 6px; margin-top: 8px; }
.btn-upgrade { flex: 1; background: #284; color: #fff; border: 1px solid #3a6; padding: 6px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; font-weight: bold; }
.btn-upgrade:hover { background: #3a6; }
.btn-sell { flex: 1; background: #842; color: #fff; border: 1px solid #a63; padding: 6px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; font-weight: bold; }
.btn-sell:hover { background: #a63; }

/* Game Header */
.game-header { display: flex; gap: 8px; padding: 8px; width: 100%; justify-content: center; }
.btn-wave { background: linear-gradient(135deg, #0a0, #070); color: #fff; border: none; padding: 8px 20px; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 0.95rem; }
.btn-wave:hover { background: linear-gradient(135deg, #0c0, #090); }
.btn-icon { background: rgba(255,255,255,0.1); border: 1px solid #333; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 1rem; color: #eee; }
.btn-icon:hover { background: rgba(255,255,255,0.2); }

/* Canvas */
#game-canvas { border: 1px solid #333; background: #1a1a2e; display: block; cursor: crosshair; }

/* Game Over / Victory */
.gameover-content h1 { font-size: 3rem; color: #f44; text-shadow: 0 0 30px rgba(255,0,0,0.6); margin-bottom: 1rem; }
.gameover-content p { font-size: 1.1rem; margin: 0.3rem 0; color: #ccc; }
.victory-content h1 { font-size: 3rem; color: #fa0; text-shadow: 0 0 30px rgba(255,200,0,0.6); margin-bottom: 1rem; }
.victory-content p { font-size: 1.1rem; margin: 0.3rem 0; color: #ccc; }

/* Ad Slots */
.ad-slot { margin-top: auto; }
.ad-placeholder { background: rgba(255,255,255,0.03); border: 1px dashed #333; padding: 20px; text-align: center; color: #444; font-size: 0.8rem; border-radius: 4px; }

/* Responsive */
@media (max-width: 768px) {
    .game-container { flex-direction: column; height: 100vh; height: 100dvh; }
    #sidebar { width: 100%; min-width: auto; max-height: 130px; border-right: none; border-bottom: 1px solid #333; overflow-x: auto; overflow-y: hidden; }
    .sidebar-content { flex-direction: row; flex-wrap: nowrap; gap: 8px; align-items: center; padding: 6px; }
    .stats-panel { display: flex; gap: 6px; flex-shrink: 0; }
    .stat { padding: 4px 6px; font-size: 0.8rem; }
    .tower-selection { flex: 1; overflow-x: auto; }
    .tower-selection h3 { display: none; }
    .tower-buttons { flex-direction: row; flex-wrap: nowrap; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tower-btn { flex-direction: column; padding: 6px 4px; min-width: 65px; flex-shrink: 0; }
    .tower-icon { font-size: 1.1rem; }
    .tower-name { font-size: 0.65rem; }
    .tower-cost { font-size: 0.7rem; }
    .tower-info-panel { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: #111; border-top: 2px solid #fa0; padding: 8px; }
    .tower-actions { flex-direction: row; }
    #game-main { flex: 1; min-height: 0; }
    .game-header { padding: 4px; gap: 4px; }
    .btn-wave { padding: 6px 14px; font-size: 0.85rem; }
    .btn-icon { padding: 4px 8px; font-size: 0.9rem; }
    #game-canvas { touch-action: none; }
    /* Ads on mobile — show below game */
    #ad-sidebar { display: none; }
    #ad-between-waves { display: block !important; }
    #ad-between-waves .ad-placeholder { padding: 15px; min-height: 50px; font-size: 0.85rem; }
    /* Mobile ad banner */
    .mobile-ad { display: block !important; }
    .loading-content h1, .start-content h1 { font-size: 1.4rem; }
    .start-content { padding: 1rem; }
    .game-info { padding: 1rem; font-size: 0.9rem; }
    .gameover-content, .victory-content { padding: 1rem; }
    .leaderboard-form { padding: 1rem; }
}
@media (max-width: 480px) {
    .tower-btn { min-width: 55px; padding: 4px 2px; }
    .tower-cost { font-size: 0.65rem; }
    .tower-name { font-size: 0.6rem; }
    .stats-panel { gap: 4px; }
    .stat { padding: 3px 4px; font-size: 0.75rem; }
}

/* Ad banners — skinny strip */
#ad-between-waves {
    display: block !important;
    width: 100%;
    margin: 0 auto;
    padding: 0;
    height: 50px;
    overflow: hidden;
}
#ad-between-waves .ad-placeholder,
#ad-between-waves .zenads-slot {
    height: 50px;
    max-height: 50px;
    overflow: hidden;
    text-align: center;
    transform-origin: top center;
}
#ad-between-waves .ad-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #444;
    padding: 0;
}
#ad-between-waves img, #ad-between-waves iframe {
    max-height: 50px !important;
    object-fit: contain;
}
#ad-sidebar .zenads-slot {
    min-height: 250px;
}
.zenads-slot { background: transparent; }

/* Leaderboard */
.final-stats { margin-bottom: 1.5rem; }
.final-score { font-size: 1.5rem; font-weight: bold; color: #fa0; margin-top: 0.5rem; }
.leaderboard-form { background: rgba(255,255,255,0.05); border: 1px solid #333; border-radius: 8px; padding: 1.5rem; max-width: 350px; margin: 0 auto 1rem; }
.leaderboard-form h2 { color: #fa0; margin-bottom: 0.3rem; font-size: 1.3rem; }
.lb-subtitle { color: #888; font-size: 0.85rem; margin-bottom: 1rem; }
.leaderboard-form input { width: 100%; padding: 10px 12px; margin-bottom: 0.6rem; background: #1a1a2e; border: 1px solid #444; border-radius: 6px; color: #fff; font-size: 1rem; }
.leaderboard-form input:focus { border-color: #fa0; outline: none; }
.btn-leaderboard { width: 100%; padding: 12px; font-size: 1.1rem; }
.lb-status { color: #0f0; font-size: 0.9rem; margin-top: 0.5rem; }
.lb-status.error { color: #f44; }
.leaderboard-display { background: rgba(255,255,255,0.05); border: 1px solid #333; border-radius: 8px; padding: 1rem; max-width: 350px; margin: 0 auto 1rem; }
.leaderboard-display h2 { color: #fa0; margin-bottom: 0.8rem; }
.lb-entry { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 0.9rem; }
.lb-entry .lb-rank { color: #fa0; font-weight: bold; width: 30px; }
.lb-entry .lb-player { flex: 1; }
.lb-entry .lb-score { color: #0f0; font-weight: bold; }
.lb-entry.lb-you { background: rgba(255,200,0,0.1); padding: 6px 4px; border-radius: 4px; }


/* Force landscape on mobile */
@media (max-width: 768px) and (orientation: portrait) {
    #game-screen .game-container {
        display: none;
    }
    #game-screen::after {
        content: '📱 Rotate your phone to play! 🔄';
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: #0a0a1a;
        color: #fa0;
        font-size: 1.5rem;
        font-weight: bold;
        text-align: center;
        padding: 2rem;
        z-index: 100;
    }
}

/* Landscape mobile layout */
@media (max-height: 500px) and (orientation: landscape) {
    .game-container { flex-direction: row !important; height: 100vh; height: 100dvh; }
    #sidebar { width: 140px !important; min-width: 140px !important; max-height: none !important; height: 100vh; height: 100dvh; border-right: 1px solid #333; border-bottom: none !important; overflow-y: auto; }
    .sidebar-content { flex-direction: column !important; flex-wrap: nowrap !important; padding: 4px !important; }
    .stats-panel { display: grid !important; grid-template-columns: 1fr 1fr; gap: 3px; }
    .stat { padding: 2px 4px; font-size: 0.7rem; }
    .tower-buttons { flex-direction: column !important; flex-wrap: nowrap !important; gap: 2px !important; }
    .tower-btn { flex-direction: row !important; padding: 3px 4px !important; min-width: auto !important; gap: 4px; }
    .tower-icon { font-size: 0.9rem; width: 20px; }
    .tower-name { font-size: 0.6rem; flex: 1; }
    .tower-cost { font-size: 0.6rem; }
    .tower-selection h3 { display: block; font-size: 0.7rem; margin-bottom: 2px; }
    #game-main { flex: 1; min-width: 0; }
    .game-header { padding: 2px 4px; }
    .btn-wave { padding: 3px 10px; font-size: 0.75rem; }
    .btn-icon { padding: 2px 6px; font-size: 0.8rem; }
    #ad-sidebar { display: none; }
    #ad-between-waves { display: block !important; }
    #ad-between-waves .ad-placeholder, #ad-between-waves .zenads-slot { min-height: 40px; max-height: 50px; overflow: hidden; padding: 4px; }
    .tower-info-panel { position: fixed; right: 0; top: 0; bottom: 0; width: 160px; z-index: 20; background: #111; border-left: 2px solid #fa0; }
}


/* Sidebar toggle for mobile */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    z-index: 50;
    background: rgba(255,140,0,0.9);
    border: none;
    color: #fff;
    font-size: 1.2rem;
    padding: 12px 6px;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
}

@media (max-height: 500px) and (orientation: landscape) {
    .sidebar-toggle {
        display: block;
    }
    #sidebar {
        transition: transform 0.2s ease;
        z-index: 25;
        position: relative;
    }
    #sidebar.collapsed {
        transform: translateX(-100%);
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
    }
    #sidebar.collapsed + #game-main,
    .game-container:has(#sidebar.collapsed) #game-main {
        margin-left: 0;
    }
}


/* Floating zoom controls */
.zoom-controls {
    pointer-events: auto;
    display: none;
    position: fixed;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
    flex-direction: column;
    gap: 8px;
}
.zoom-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid rgba(255,140,0,0.6);
    background: rgba(0,0,0,0.75);
    color: #fa0;
    font-size: 1.6rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.zoom-btn:active {
    background: rgba(255,140,0,0.7);
}

@media (max-width: 768px), (max-height: 500px) {
    .zoom-controls {
    pointer-events: auto; display: flex; }
}
