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

body {
    font-family: Arial, sans-serif;
    background-color: #0b0b0b;
    background-image: radial-gradient(circle at 10% 10%, rgba(255,110,0,0.03), transparent 20%), radial-gradient(circle at 90% 90%, rgba(138,43,226,0.02), transparent 18%);
    color: white;
    touch-action: manipulation;
    overflow: hidden;
    height: 100vh;
}

#game-ui-container {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh; /* ensure full viewport height on mobile */
    background: transparent;
    z-index: 5;
}

.game-area-container, .game-area-row {
    flex: 1 1 auto;
    display: flex;
    width: 100%;
    gap: 12px;
    align-items: stretch;
    justify-content: center;
}

#game-board {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0; /* allow flex children to shrink properly */
    display: grid;
    align-self: stretch;
    justify-self: stretch;
    box-sizing: border-box;
}

/* Ensure side panels / chat remain scrollable but don't push board size */
#side-panel, #chat-container {
    flex: 0 0 220px;
    height: 100%;
    overflow-y: auto;
}

/* Mobile: side panels collapse and game-board fills screen */
@media (max-width: 800px) {
    #side-panel, #chat-container { display: none; }
    #game-board { width: 100%; height: 100dvh; grid-auto-rows: 1fr; }
}

.game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 800px;
    margin: 0 auto;
}

.game-info {
    padding: 10px;
    background-color: #333;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.resources {
    display: flex;
    justify-content: space-between;
    font-size: 1.2rem;
    font-weight: bold;
}

.tower-selection {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    max-height: none; /* allow dynamic changes via class */
    overflow-y: visible;
}

/* New: make tower-selection scrollable when many towers exist */
.tower-selection.scrollable {
    display: block;
    max-height: calc(100dvh - 160px); /* leaves room for resources and controls */
    overflow-y: auto;
    padding: 8px;
    box-sizing: border-box;
}

.tower-btn {
    padding: 6px 8px; /* reduced from 8px 12px */
    font-size: 0.95rem; /* slightly smaller */
    min-width: 64px; /* ensure compact consistent width */
    background-color: #4CAF50;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

.tower-btn:hover {
    background-color: #45a049;
}

.tower-btn.selected {
    background-color: #2196F3;
}

.tower-btn:disabled {
    background-color: #777;
    cursor: not-allowed;
}

.game-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.game-controls button {
    padding: 8px 16px;
    background-color: #2196F3;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

#back-to-menu {
    background-color: #f44336;
}

#back-to-menu:hover {
    background-color: #d32f2f;
}

#create-enemy-btn {
    background-color: #ff5722;
}

#create-enemy-btn:hover {
    background-color: #e64a19;
}

#create-tower-btn {
    background-color: #9C27B0;
}

#create-tower-btn:hover {
    background-color: #7B1FA2;
}

#create-unit-factory-btn {
  background: #2196F3;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
}
#create-unit-factory-btn:hover { background: #1976D2; transform: translateY(-1px); }

#game-board {
    flex-grow: 1;
    background-color: #555;
    position: relative;
    overflow: visible;
    touch-action: manipulation;
    display: grid;
}

.cell {
    background-color: #8bc34a;
    border: 1px solid rgba(0, 0, 0, 0.1);
    position: relative;
    transition: background-color 0.2s;
}
/* Darken tile on hover for clear hover feedback */
.cell:hover {
    filter: brightness(0.85);
    cursor: pointer;
}

.cell.path {
    background-color: #795548;
}

.cell.non-buildable {
    background-color: #3a3a3a;
    border: 1px solid #222;
}

.cell.tower-placement-valid {
    background-color: rgba(76, 175, 80, 0.5);
}

.cell.tower-placement-invalid {
    background-color: rgba(244, 67, 54, 0.5);
}

.cell.map-volcano {
    background: radial-gradient(circle at 40% 30%, #40261a 0%, #2b1b12 40%, #1b0f0a 100%);
    border: 1px solid rgba(80,40,20,0.12);
    box-shadow: inset 0 -6px 18px rgba(0,0,0,0.35);
}
.cell.path.map-volcano {
    background: linear-gradient(180deg, rgba(255,120,40,0.08), rgba(255,64,0,0.12)), #3a2216;
    box-shadow: 0 0 18px rgba(255,88,34,0.06);
    border-color: rgba(255,120,40,0.18);
}

/* Add a subtle lava glow along the path edges */
.cell.path.map-volcano::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 2px;
    box-shadow: inset 0 0 20px rgba(255,90,20,0.08);
    pointer-events: none;
}

/* Canyon map floor / path visuals */
.cell.map-canyon {
    /* wheat / sand yellow palette for canyon floor */
    background: linear-gradient(180deg, #f5e0b2 0%, #edd9a0 40%, #e4cf8a 100%);
    border: 1px solid rgba(140,110,60,0.15);
    background-size: 40px 40px;
    background-image:
        linear-gradient(135deg, rgba(255,255,255,0.03) 25%, transparent 25%, transparent 75%, rgba(0,0,0,0.03) 75%),
        linear-gradient(225deg, rgba(0,0,0,0.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.03) 75%);
}
.cell.path.map-canyon {
    background: linear-gradient(180deg, rgba(0,0,0,0.12), rgba(0,0,0,0.06)), #513b2e;
    border-color: rgba(0,0,0,0.28);
}

/* Ensure path visuals remain readable when combined with existing path/non-buildable classes */
.cell.path { 
    /* keep existing subtle overrides but let map-specific rules take precedence */
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.tower {
    position: absolute;
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.tower-turret {
    position: absolute;
    width: 60%;
    height: 20%;
    background-color: rgba(0, 0, 0, 0.7);
    transform-origin: center left;
    left: 50%;
    border-radius: 3px;
}

.tower-range {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(33, 150, 243, 0.2);
    pointer-events: none;
    z-index: 1;
    border: 1px solid rgba(33, 150, 243, 0.4);
}

.tower-basic {
    background-color: #2196F3;
}

.tower-basic .tower-turret {
    background-color: #0d47a1;
}

.tower-sniper {
    background-color: #9C27B0;
}

.tower-sniper .tower-turret {
    background-color: #4a148c;
    width: 70%;
    height: 15%;
}

.tower-splash {
    background-color: #FF9800;
}

.tower-splash .tower-turret {
    background-color: #e65100;
    width: 50%;
    height: 25%;
    border-radius: 3px 10px 10px 3px;
}

.tower-frost {
    background-color: #00BCD4;
    border: 2px solid #80DEEA;
}

.tower-frost .tower-turret {
    background-color: #006064;
    height: 18%;
    border-radius: 3px 5px 5px 3px;
}

.tower-lightning {
    background-color: #FFEB3B;
    border: 2px solid #FFF59D;
}

.tower-lightning .tower-turret {
    background-color: #F57F17;
    height: 18%;
    border-radius: 3px;
}

.tower-poison {
    background-color: #4CAF50;
    border: 2px solid #81C784;
}

.tower-poison .tower-turret {
    background-color: #1B5E20;
    border-radius: 3px 8px 8px 3px;
    width: 55%;
}

.tower-bomb {
    background-color: #FF5722;
    border: 2px solid #FFAB91;
}

.tower-bomb .tower-turret {
    background-color: #BF360C;
    height: 30%;
    width: 45%;
    border-radius: 6px;
}

.tower-laser {
    background-color: #E91E63;
    border: 2px solid #F48FB1;
}
/* Add overlaser visuals (green) */
.tower-overlaser {
    background-color: #00C853; /* vivid green base */
    border: 2px solid #69F0AE;
}
.tower-overlaser .tower-turret {
    background-color: #007E33;
    height: 15%;
    width: 80%;
}

.tower-flamethrower {
    background-color: #FF7043;
    border: 2px solid #FFAB91;
    position: relative;
    overflow: visible;
}
.tower-flamethrower .tower-turret {
    width: 50%;
    height: 30%;
    left: 50%;
    top: 50%;
    transform-origin: center left;
    transform: translate(-50%, -50%) rotate(0deg);
    background: linear-gradient(90deg,#3e1700,#b45a1b);
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4), inset 0 -4px 8px rgba(255,160,90,0.12);
}
/* flame visual using pseudo-element on turret */
.tower-flamethrower .tower-turret::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border-radius: 50% 50% 30% 30%;
    background: radial-gradient(circle at 30% 30%, #fff59d 0%, #ffb74d 20%, #ff8a65 45%, #ff3d00 70%, transparent 71%);
    filter: blur(2px);
    box-shadow: 0 0 16px rgba(255,110,20,0.6);
    animation: flame-flicker 360ms infinite linear;
    pointer-events: none;
}
/* small flicker */
@keyframes flame-flicker {
    0% { transform: translateY(-50%) scale(0.9) translateX(0); opacity: 0.9; }
    50% { transform: translateY(-52%) scale(1.1) translateX(2px); opacity: 1; }
    100% { transform: translateY(-50%) scale(0.95) translateX(0); opacity: 0.92; }
}

.tower-mortar {
    background: radial-gradient(circle at 30% 30%, #ffcc80 0%, #ff8a65 40%, #bf360c 100%);
    border: 2px solid #bf360c;
    box-shadow: inset 0 -6px 12px rgba(0,0,0,0.35);
}
.tower-mortar .tower-turret {
    width: 50%;
    height: 36%;
    left: 50%;
    top: 42%;
    background: linear-gradient(180deg,#4e342e,#6d3f2b);
    border-radius: 6px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5), inset 0 -3px 6px rgba(255,200,160,0.06);
}
/* mortar barrel tip */
.tower-mortar .tower-turret::after { content:''; position:absolute; right:-8px; top:50%; transform:translateY(-50%); width:12px; height:12px; background:#ffcc80; border-radius:3px; box-shadow: 0 0 8px rgba(255,140,60,0.6); }

/* healer visuals */
.tower-healer {
    background: linear-gradient(180deg,#e8f5e9,#c8e6c9);
    border: 2px solid #81c784;
    box-shadow: 0 6px 14px rgba(76,175,80,0.08), inset 0 -4px 10px rgba(255,255,255,0.02);
}
.tower-healer .tower-turret { display:none; }
.tower-healer::before { content:'+'; position:absolute; font-weight:700; color:#2e7d32; font-size:22px; transform:translate(-50%,-50%); left:50%; top:48%; text-shadow:0 1px 0 rgba(255,255,255,0.2); }

/* ricochet visuals */
.tower-ricochet {
    background: conic-gradient(from 90deg at 50% 50%, #ffe082, #ffd54f 40%, #ffb300 100%);
    border: 2px solid #ffb300;
    box-shadow: 0 6px 12px rgba(255,193,7,0.08);
}
.tower-ricochet .tower-turret {
    width: 62%;
    height: 18%;
    left: 50%;
    top: 44%;
    background: linear-gradient(90deg,#fff176,#f57f17);
    border-radius: 3px;
    transform-origin: center left;
    box-shadow: 0 3px 6px rgba(0,0,0,0.35), inset 0 -2px 6px rgba(255,255,255,0.08);
}

/* Laser beam purple styling for ultralaser visuals when created at runtime */
.laser-beam.ultralaser {
    background-color: #8e24aa;
    box-shadow: 0 0 14px #6a1b9a;
}

.enemy {
    position: absolute;
    border-radius: 50%;
    z-index: 3;
    will-change: transform;
}

.enemy-basic {
    background-color: #F44336;
}

.enemy-fast {
    background-color: #FFEB3B;
    box-shadow: 0 0 5px #FFC107;
}

.enemy-tank {
    background-color: #607D8B;
    border: 2px solid #455A64;
}

.enemy-swift {
    background-color: #00BCD4;
    box-shadow: 0 0 8px #00BCD4;
}

.enemy-armored {
    background-color: #795548;
    border: 3px solid #4E342E;
}

.enemy-phantom {
    background-color: #9C27B0;
    box-shadow: 0 0 10px #9C27B0;
    opacity: 0.8;
}

.enemy-normal { background-color: #F44336; box-shadow: 0 0 6px rgba(244,67,54,0.35); }
.enemy-speedy { background-color: #FFEB3B; box-shadow: 0 0 8px rgba(255,235,59,0.35); }
.enemy-slow { background-color: #607D8B; box-shadow: 0 0 6px rgba(96,125,139,0.25); }
.enemy-basic_boss { background-color: #D32F2F; box-shadow: 0 0 18px rgba(211,47,47,0.45); }
.enemy-mystery { background-color: #9E9E9E; opacity: 0.95; box-shadow: 0 0 10px rgba(158,158,158,0.25); }
.enemy-slow_boss { background-color: #4E342E; box-shadow: 0 0 22px rgba(78,52,46,0.5); }
.enemy-speedy_boss { background-color: #FF8A65; box-shadow: 0 0 18px rgba(255,138,101,0.45); }

/* New enemy visuals */
.enemy-armored_heavy { background-color: #6D4C41; border: 2px solid #4E342E; box-shadow: 0 0 10px rgba(109,76,65,0.35); }
.enemy-swift_strike   { background-color: #00BCD4; box-shadow: 0 0 10px rgba(0,188,212,0.35); }
.enemy-regenerator    { background-color: #81C784; box-shadow: 0 0 10px rgba(129,199,132,0.25); }
.enemy-shielded       { background-color: #FFD54F; box-shadow: 0 0 12px rgba(255,213,79,0.3); border: 1px solid rgba(0,0,0,0.08); }

/* Small visual marker for regenerator */
.enemy-regenerator::after {
    content: '✚';
    position: absolute;
    font-size: 10px;
    color: rgba(255,255,255,0.9);
    top: 2px;
    right: 4px;
    text-shadow: 0 1px 1px rgba(0,0,0,0.6);
}

/* Shield shimmer for shielded */
.enemy-shielded::before {
    content: '';
    position: absolute;
    inset: -6%;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(255,213,79,0.25) inset;
    pointer-events: none;
}

.projectile {
    position: absolute;
    background-color: white;
    border-radius: 50%;
    width: 8px;
    height: 8px;
    transform: translate(-50%, -50%);
    z-index: 4;
}

.projectile-frost {
    background-color: #00BCD4;
    box-shadow: 0 0 5px 3px #80DEEA;
}

.projectile-poison {
    background-color: #4CAF50;
    box-shadow: 0 0 5px 2px #A5D6A7;
}

.projectile-lightning {
    background-color: #FFEB3B;
    box-shadow: 0 0 8px #FFF176;
}

.projectile-bomb {
    background-color: #FF5722;
    width: 12px;
    height: 12px;
}

.laser-beam {
    position: absolute;
    height: 4px;
    background-color: #F48FB1;
    box-shadow: 0 0 8px #E91E63;
    transform-origin: left center;
    z-index: 4;
}

.lightning-chain {
    position: absolute;
    height: 3px;
    background-color: #FFEB3B;
    box-shadow: 0 0 10px #FFF176;
    transform-origin: left center;
    z-index: 4;
    opacity: 0.8;
}

.status-effect {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
    opacity: 0.5;
}

.slow-effect {
    box-shadow: 0 0 5px 3px #00BCD4;
    border: 1px solid #00BCD4;
}

.poison-effect {
    box-shadow: 0 0 5px 2px #4CAF50;
    border: 1px solid #4CAF50;
}

.stun-effect {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    color: #FFEB3B;
    font-size: 16px;
    animation: rotate 1s linear infinite, stun-pulse 1s ease-in-out infinite;
    text-shadow: 0 0 4px black;
}

.stun-effect::before {
    content: '★';
}

.damage-text {
    position: absolute;
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 0 0 2px black;
    pointer-events: none;
    z-index: 6;
    transform: translate(-50%, -50%);
    transition: all 0.5s;
}

.poison-damage {
    color: #81C784;
}

.health-bar {
    position: absolute;
    height: 3px;
    background-color: #4CAF50;
    bottom: -5px;
    left: 0;
    transition: width 0.2s ease-in-out;
}

.tutorial {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.tutorial-content {
    background-color: #333;
    padding: 20px;
    border-radius: 8px;
    max-width: 90%;
    text-align: center;
    max-height: 90vh;
    overflow-y: auto;
    animation: menu-fade-in 0.3s ease-out;
}

.tutorial-content h2 {
    margin-bottom: 15px;
    color: #4CAF50;
}

.tutorial-content p {
    margin-bottom: 10px;
}

.tutorial-content button {
    margin-top: 15px;
    padding: 8px 16px;
    background-color: #2196F3;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
}

.toggle-btn {
    padding: 8px 16px;
    background-color: #777;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
}

.toggle-btn.active {
    background-color: #4CAF50;
}

#multiplayer-toggle {
    padding: 10px 14px;
    background-color: #777;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.08s;
}
#multiplayer-toggle.active {
    background-color: #FF7043;
    color: #120800;
    font-weight: 700;
}

.spike-pile {
    position: absolute;
    width: 25px;
    height: 25px;
    background-image: url('https://assets.website-files.com/622b71563f14920e599187a5/624385a53555234557b4927f_spikes.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transform: translate(-50%, -50%);
    z-index: 1;
    pointer-events: none;
    opacity: 0.8;
    transition: opacity 0.5s;
}

.upgrade-menu {
    position: fixed;
    top: 0;
    right: 0;
    transform: none;
    left: auto;
    width: 300px;
    height: 100%;
    max-width: 100%;
    background-color: #333;
    border-radius: 0;
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
    z-index: 10;
    display: none;
    flex-direction: column;
    padding: 15px;
    overflow-y: auto;
}

.upgrade-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid #555;
    padding-bottom: 10px;
}

.upgrade-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

#close-upgrade {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.upgrade-paths {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.upgrade-path {
    background-color: #444;
    padding: 10px;
    border-radius: 6px;
    min-height: 110px;
}

.path-name {
    font-weight: bold;
    margin-bottom: 8px;
    color: #4CAF50;
}

.seismic-ring {
    position: absolute;
    width: 120%;
    height: 120%;
    top: -10%;
    left: -10%;
    border: 2px dashed #D84315;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

.upgrade-levels {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
}

.level-node {
    width: 20px;
    height: 8px;
    background-color: #666;
    border-radius: 4px;
}

.level-node.active {
    background-color: #4CAF50;
}

.upgrade-btn {
    width: 100%;
    padding: 6px;
    background-color: #2196F3;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

.upgrade-btn:hover {
    background-color: #1976D2;
}

.upgrade-btn:disabled {
    background-color: #777;
    cursor: not-allowed;
}

.tower-stats {
    margin-top: 15px;
    padding: 10px;
    background-color: #444;
    border-radius: 6px;
    font-size: 0.9rem;
}

.stat-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.upgrade-description {
    font-size: 0.8rem;
    color: #BBB;
    margin-top: 5px;
    margin-bottom: 8px;
    line-height: 1.2;
}

.upgrade-description .value {
    color: #8BC34A;
    font-weight: bold;
}

.tower-level-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #4CAF50;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
}

.special-effect {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.6;
    animation: pulse 2s infinite;
}

.tier-4 {
    box-shadow: 0 0 10px 5px rgba(33, 150, 243, 0.7);
    border-radius: 50%;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.6;
    animation: pulse 2s infinite;
}

.tier-5 {
    box-shadow: 0 0 15px 8px rgba(255, 215, 0, 0.7);
    border-radius: 50%;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.7;
    animation: pulse 1.5s infinite, rotate 6s linear infinite;
}

.tier-5.path-1 {
    border: 2px solid #FF5722;
}

.tier-5.path-2 {
    border: 2px solid #E91E63;
}

.tier-5.path-3 {
    border: 2px solid #9C27B0;
}

.tier5-projectile {
    box-shadow: 0 0 10px 5px rgba(255, 215, 0, 0.7);
    background-color: #FFC107;
    width: 12px !important;
    height: 12px !important;
}

.tier5-explosion {
    box-shadow: 0 0 20px 10px rgba(255, 87, 34, 0.7);
    background-color: #FF5722 !important;
}

.critical-damage {
    color: #FF5722;
    font-size: 14px !important;
    font-weight: bold;
    text-shadow: 0 0 4px #000;
}

.storm-effect {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(33, 150, 243, 0.3) 0%, rgba(33, 150, 243, 0) 70%);
    transform: translate(-50%, -50%);
    z-index: 1;
    pointer-events: none;
}

.storm-lightning {
    position: absolute;
    height: 4px;
    background-color: #FFC107;
    box-shadow: 0 0 10px 2px #FFEB3B;
    transform-origin: left center;
    z-index: 4;
    opacity: 0.8;
}

.frozen-effect {
    box-shadow: 0 0 5px 3px #2196F3;
    border: 1px solid #2196F3;
    background-color: rgba(33, 150, 243, 0.3);
}

.lingering-effect {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 87, 34, 0.3) 0%, rgba(255, 87, 34, 0) 70%);
    transform: translate(-50%, -50%);
    z-index: 1;
    pointer-events: none;
}

.wave-completion-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background-color: rgba(76, 175, 80, 0.9);
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    font-size: 1.2rem;
    text-align: center;
    opacity: 0;
    transition: all 0.3s;
    z-index: 8;
    display: flex;
    flex-direction: column;
    gap: 5px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
}

.wave-completion-message.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.code-copy {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #333;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    z-index: 10;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.code-copy-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-copy-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #4CAF50;
}

#close-code-copy {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.code-copy-buttons {
    display: flex;
    gap: 10px;
}

.code-copy-buttons button {
    padding: 8px 12px;
    background-color: #2196F3;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

.code-copy-buttons button:hover {
    background-color: #1976D2;
}

.copy-status {
    font-size: 0.9rem;
    height: 20px;
    color: #8BC34A;
    text-align: center;
}

.sell-container {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* Targeting UI */
.targeting-container {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.targeting-label {
    color: #ccc;
    font-size: 0.9rem;
}

.targeting-group {
    display: flex;
    gap: 8px;
}

.target-btn {
    padding: 6px 10px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    color: #e6e6e6;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s, transform 0.08s;
    font-weight: 600;
}

.target-btn.active {
    background: #4CAF50;
    color: #042204;
    box-shadow: 0 6px 12px rgba(76,179,74,0.15);
}

.target-btn:hover { transform: translateY(-1px); }

.sell-btn, .move-btn {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
    font-size: 1rem;
}

.sell-btn {
    background-color: #F44336;
}

.sell-btn:hover {
    background-color: #D32F2F;
}

.move-btn {
    background-color: #FF9800;
}

.move-btn:hover {
    background-color: #FB8C00;
}

.move-btn:disabled {
    background-color: #777;
    cursor: not-allowed;
}

.ai-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 11;
}

.ai-menu-content {
    background-color: #333;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.ai-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #555;
    padding-bottom: 10px;
}

.ai-menu-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #9C27B0;
}

#close-ai-creator, #close-ai-enemy-creator {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.ai-menu-content p {
    color: #ccc;
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 0;
}

.ai-menu-content input,
.ai-menu-content textarea {
    width: 100%;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #555;
    background-color: #222;
    color: white;
    font-family: Arial, sans-serif;
    font-size: 1rem;
}

.ai-menu-content textarea {
    min-height: 100px;
    resize: vertical;
}

#generate-ai-tower {
    padding: 10px 16px;
    background-color: #9C27B0;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

#generate-ai-tower:hover {
    background-color: #7B1FA2;
}

#generate-ai-tower:disabled, #generate-ai-enemy:disabled {
    background-color: #777;
    cursor: not-allowed;
}

/* New: style the Unit Factory generate button to match primary blue buttons */
#generate-unit-factory {
    padding: 10px 16px;
    background-color: #2196F3;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

#generate-unit-factory:hover {
    background-color: #1976D2;
}

#generate-unit-factory:disabled {
    background-color: #777;
    cursor: not-allowed;
}

#ai-status {
    text-align: center;
    min-height: 20px;
    color: #8BC34A;
}

#generate-ai-enemy {
    padding: 10px 16px;
    background-color: #ff5722;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

#generate-ai-enemy:hover {
    background-color: #e64a19;
}

#ai-enemy-status {
    text-align: center;
    min-height: 20px;
    color: #8BC34A;
}

.custom-tower-btn {
    background-color: #9C27B0 !important;
    border: 1px solid #7B1FA2;
}

.custom-tower-btn:hover {
    background-color: #8e24aa !important;
}

.custom-tower-btn.selected {
    background-color: #6A1B9A !important;
}

.footer-promo {
    color: #FFC107;
    font-size: 0.9rem;
    padding: 10px 15px;
    border-radius: 8px;
    background-color: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.2);
}

#promo-popup {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #3e2723;
    color: white;
    border-radius: 10px;
    padding: 15px 20px;
    z-index: 100;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    gap: 15px;
    border: 1px solid #5d4037;
    transform: translateX(120%);
    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

#promo-popup.show {
    transform: translateX(0);
}

#promo-content {
    text-align: center;
}

#promo-content p {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: #e0e0e0;
}

#promo-link-btn {
    display: inline-block;
    padding: 8px 16px;
    background-color: #ff5722;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: bold;
    transition: background-color 0.3s, transform 0.2s;
}

#promo-link-btn:hover {
    background-color: #f4511e;
    transform: translateY(-1px);
}

#close-promo-popup {
    background: none;
    border: none;
    color: #a1887f;
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
    transition: color 0.3s;
}

#close-promo-popup:hover {
    color: white;
}

/* Custom enemy spawn panel */
.custom-enemy-panel-container {
    background-color: #222;
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    display: none; /* Initially hidden */
}

.custom-enemy-panel-container h4 {
    margin-top: 0;
    margin-bottom: 5px;
    color: #FF5722;
}

.custom-enemy-panel-container p {
    font-size: 0.8em;
    color: #999;
    margin-top: 0;
    margin-bottom: 10px;
}

.custom-enemy-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.custom-enemy-spawn-btn {
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.custom-enemy-spawn-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.1);
}

.custom-enemy-spawn-btn:disabled {
    background-color: #777 !important;
    cursor: not-allowed;
    transform: none;
    filter: brightness(0.7);
    box-shadow: none !important;
}

#broadcast-container {
    position: fixed;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 80%;
    max-width: 700px;
}

.broadcast-message {
    background-color: linear-gradient(180deg, rgba(255,110,0,0.98), rgba(255,165,0,0.95));
    color: #ffffff;
    padding: 12px 25px;
    border-radius: 8px;
    font-size: 1.3rem;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255,140,0,0.18);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    width: fit-content;
    max-width: 100%;
}

.broadcast-message.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.game-area-row {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

#game-board {
    flex: 1;
}

#side-panel {
    width: 180px;
    background-color: #2a2a2a;
    border-left: 2px solid #444;
    padding: 10px;
    box-sizing: border-box;
}

#side-panel .game-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#side-panel .game-controls button {
    width: 100%;
    padding: 6px 8px;
    font-size: 0.92rem;
}

.option-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* Difficulty selection block */
#difficulty-selection {
    background: rgba(6, 80, 21, 0.35); /* dark green transparent */
    border-radius: 12px;
    padding: 6px;
    display: inline-flex;
    gap: 6px;
    border: 1px solid rgba(76, 175, 80, 0.08);
    backdrop-filter: blur(4px);
}

.difficulty-btn {
    padding: 8px 12px;
    background: transparent;
    color: #cdebd3;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.18s, color 0.18s, transform 0.08s;
    font-weight: 600;
    min-width: 84px;
}

.difficulty-btn:hover { background: rgba(255,255,255,0.03); color: #e9ffe9; transform: translateY(-1px); }
.difficulty-btn.active {
    background: linear-gradient(180deg,#6bd36a,#3fb34a);
    color: #042204;
    box-shadow: 0 6px 18px rgba(63,179,74,0.2), inset 0 -2px 0 rgba(255,255,255,0.06);
}

/* Map select as rounded dark grey block */
#map-select {
    padding: 12px 14px;
    font-size: 1rem;
    background-color: #2f3133; /* dark grey */
    border: 1px solid #3f4143;
    border-radius: 10px;
    color: #e6e6e6;
    cursor: pointer;
    width: 100%;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.2);
}

/* My Saved Towers - compact scrollable mini list */
#custom-tower-list-container {
    display: none; /* default controlled by JS */
    margin-top: 12px;
    max-height: 160px;
    overflow: hidden;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(40,40,40,0.9), rgba(30,30,30,0.9));
    border: 1px solid rgba(255,255,255,0.03);
    padding: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}
/* inner list scroll */
#custom-tower-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    padding-right: 6px;
    max-height: 140px;
}
/* item style */
.custom-tower-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(0,0,0,0.18);
    color: #e8e8e8;
    font-size: 0.95rem;
    border: 1px solid rgba(255,255,255,0.02);
}
/* nicer X button */
.delete-tower-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    color: #ffb3b3;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 700;
    transition: background 0.12s, transform 0.08s, color 0.12s;
}
.delete-tower-btn:hover {
    background: rgba(244,67,54,0.12);
    color: #ff7b7b;
    transform: translateY(-1px);
}
/* ensure thin scrollbar for the mini list */
#custom-tower-list::-webkit-scrollbar { width: 8px; }
#custom-tower-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 6px; }
#custom-tower-list::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 800px) {
    /* Stack game area vertically and hide side-panel/chat to prioritize board */
    .game-area-row { flex-direction: column; gap: 10px; align-items: stretch; }
    #side-panel, #chat-container, #side-panel .game-controls { display: none !important; }
    #game-board { width: 100%; height: calc(100dvh - 220px); min-height: 360px; }
    .menu-content { max-width: 96%; padding: 14px; }
    .tower-selection { gap: 8px; padding: 6px; }
    .tower-selection.scrollable { max-height: 160px; }
    #chat-container { display: none !important; }
    #side-panel { position: fixed; bottom: 0; left: 0; right: 0; width: 100%; z-index: 30; border-left: none; border-top: 2px solid #444; background-color: #2a2a2a; padding: 8px; }
    #side-panel .game-controls { flex-direction: row; gap: 8px; flex-wrap: nowrap; overflow-x: auto; }
    #side-panel .game-controls button { flex: 0 0 auto; }
}

@media (max-width: 600px) {
    .resources {
        font-size: 0.9rem;
    }

    .tower-btn, .game-controls button {
        padding: 6px 8px;
        font-size: 0.9rem;
    }

    .upgrade-menu {
        width: 95%;
        max-width: 350px;
    }

    .menu-content {
        padding: 12px;
        max-width: 360px;
        width: 94%;
    }

    .game-title {
        font-size: 1.6rem;
        margin-bottom: 10px;
    }

    .option-group {
        gap: 6px;
    }

    .difficulty-btn {
        padding: 8px 10px;
        font-size: 0.9rem;
    }

    #map-select {
        padding: 10px;
        font-size: 0.95rem;
    }

    #start-game-btn {
        padding: 9px;
        font-size: 0.95rem;
    }

    #game-over-content h1 {
        font-size: 2.5rem;
    }

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

    .game-over-stats {
        flex-direction: column;
        gap: 15px;
    }

    .broadcast-message {
        font-size: 1rem;
        padding: 10px 15px;
    }

    #broadcast-container {
        top: 10%;
    }

    #side-panel {
        width: 180px;
    }

    #side-panel .game-controls button {
        font-size: 0.9rem;
        padding: 6px 8px;
    }

    .tower-btn { padding: 8px 10px; font-size: 0.9rem; min-height: 36px; }
    
    /* Make game controls a fixed bottom toolbar on mobile for easy access */
    .game-controls {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: 8px;
        display: flex;
        gap: 8px;
        justify-content: space-between;
        align-items: center;
        padding: 8px;
        background: rgba(34,34,34,0.95);
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.5);
        z-index: 60;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .game-controls button { flex: 0 0 auto; min-width: 68px; padding: 8px 10px; }
}

/* Larger touch targets and improved spacing for mobile */
.tower-btn, .game-controls button, .ai-menu-content input, .ai-menu-content textarea, .toggle-btn {
    padding: 8px 10px; /* reduced from larger mobile padding */
    font-size: 0.95rem;
    border-radius: 8px;
    min-height: 40px; /* slightly smaller touch targets but still usable */
    touch-action: manipulation;
}

/* Make start / primary buttons full width on small screens */
@media (max-width: 600px) {
    #start-game-btn, #start-wave, #restart-game-btn, #game-over-to-menu-btn, #create-tower-btn {
        width: 100%;
        display: block;
    }
    .menu-footer { flex-direction: column; gap: 8px; }
}

@keyframes menu-fade-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes game-over-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes pulse {
    0% {
        opacity: 0.6;
        transform: scale(1);
    }

    50% {
        opacity: 0.9;
        transform: scale(1.05);
    }

    100% {
        opacity: 0.6;
        transform: scale(1);
    }
}

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

    to {
        transform: rotate(360deg);
    }
}

@keyframes stun-pulse {
    0% {
        transform: scale(1) rotate(0deg);
    }

    50% {
        transform: scale(1.2) rotate(180deg);
    }

    100% {
        transform: scale(1) rotate(360deg);
    }
}

@keyframes fade-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

.ai-suggestions {
    margin-top: 15px;
    text-align: center;
}

#ai-suggestion-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 8px 0;
}

.suggestion-item {
    padding: 8px 12px;
    background: #444;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
}

.suggestion-item:hover {
    background: #555;
}

.game-title {
    font-size: 1.9rem;
    margin-bottom: 14px;
    color: #FF6A00; /* pumpkin orange */
    text-shadow: 0 0 15px rgba(76, 175, 80, 0.5);
    font-weight: bold;
    letter-spacing: 2px;
}

/* --- Main Menu --- */
#main-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    background-image: linear-gradient(45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.1) 75%, rgba(0, 0, 0, 0.1));
    background-size: 60px 60px;
    background-position: 0 0, 30px 30px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* allow content to start at top so it can scroll */
    overflow: auto; /* enable scrolling when content exceeds viewport */
    padding: 28px 0; /* breathing room at top/bottom */
}

.menu-content {
    background-color: #1a1512; /* deep charcoal for Halloween */
    padding: 18px;
    width: 92%;
    max-width: 480px; /* restore wider layout similar to previous versions */
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    text-align: center;
    border: 1px solid rgba(255,255,255,0.04);
    animation: menu-fade-in 0.45s ease-out;
    max-height: calc(100dvh - 64px); /* keep card inside viewport */
    overflow-y: auto; /* make internal content scrollable */
    -webkit-overflow-scrolling: touch;
}

#start-game-btn {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    font-weight: bold;
    background-color: #2196F3;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
}

#start-game-btn:hover {
    background-color: #1976d2;
    box-shadow: 0 0 15px rgba(33, 150, 243, 0.5);
    transform: scale(1.05);
}

#loading-status {
    margin-top: 15px;
    color: #aaa;
    font-size: 0.9rem;
    font-style: italic;
    min
}

.enemy-tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    transform: translate(-50%, -120%);
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

#dude-btm {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    height: auto;
    border-radius: 12px;
    z-index: 9999;
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
    opacity: 0.98;
    padding: 8px 12px;
    font-size: 28px;
    background: rgba(0,0,0,0.35);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
#dude-btm:hover {
    transform: translateX(-50%) translateY(-4px) scale(1.03);
    box-shadow: 0 10px 28px rgba(0,0,0,0.45);
}

#event-disclaimer {
    color: #FF8F00; /* warmer pumpkin warning */
    font-weight:800;
    font-size:1.15rem;
    text-align:center;
    border-radius:6px;
}

#game-over-content h1 {
    font-size: 3rem;
    color: #FF6A00;
    margin-bottom: 25px;
    text-shadow: 0 0 15px rgba(244, 67, 54, 0.6);
    font-weight: bold;
    letter-spacing: 2px;
}

.tower-creation-controls button {
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    background: #9C27B0;
    color: white;
    cursor: pointer;
    transition: background 0.18s, transform 0.08s;
}
.tower-creation-controls button:hover { background: #7B1FA2; transform: translateY(-2px); }

.export-tower-btn {
    background: transparent; border: 1px solid rgba(255,255,255,0.06);
    color: #cfe8ff; padding: 6px 10px; border-radius: 6px; cursor: pointer;
}

.god-tile {
    outline: 2px dashed gold;
    box-shadow: 0 0 18px rgba(255,215,0,0.12) inset;
    position: relative;
    background-image: linear-gradient(180deg, rgba(255,165,0,0.12), transparent) !important; /* Apply general amber tint */
    border-color: gold !important;
}
/* small crown marker */
.god-tile::after {
    content: '✦';
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 12px;
    color: gold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.tower img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
}