:root {
    --primary-bg: #1a1a2e;
    --secondary-bg: #16213e;
    --accent-color: #e94560;
    --text-color: #f0f0f0;
    --ui-border: #0f3460;
    --tower-placeholder: rgba(255, 255, 255, 0.2);
     --potion-color: #9d4edd; /* Purple/Magenta for Potions/Upgrade Points */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--primary-bg);
}

#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

#game-canvas {
    background-size: cover;
    background-position: center;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allow clicks to pass through to canvas */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

#top-bar, #bottom-bar {
    width: 100%;
    display: flex;
    /* Existing justify-content and align-items */
    padding: 10px 15px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
    pointer-events: all;
    justify-content: space-between; /* Distribute items */
    align-items: center;
    flex-wrap: wrap; /* Allow wrap if needed */
    gap: 10px; /* Gap between top bar items */
}

#bottom-bar {
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    flex-wrap: wrap; /* Allow bottom bar content to wrap */
    gap: 10px; /* Gap between items in bottom bar */
    justify-content: flex-end; /* Push controls to the right */
    align-items: flex-end; /* Align items to the bottom */
     padding-right: 15px;
     padding-left: 15px;
     /* Only one main item now: control-buttons-area */
     justify-content: center; /* Center the single control block */
}

.resource-display {
    display: flex;
    align-items: center;
    color: var(--text-color);
    font-size: clamp(16px, 4vw, 24px);
    font-weight: bold;
    background-color: var(--secondary-bg);
    padding: 5px 10px;
    border-radius: 20px;
    border: 2px solid var(--ui-border);
    text-shadow: 1px 1px 2px black;
    flex-shrink: 0; /* Prevent shrinking */
}

.resource-display img {
    width: clamp(20px, 5vw, 30px);
    height: auto;
    margin-right: 8px;
}

/* New style for top bar buttons to give them padding/styling */
.top-bar-button {
    padding: 5px 10px;
    background-color: #00c2a2; /* A different color, maybe? */
    color: var(--text-color);
    border: none;
    border-radius: 8px;
    font-size: clamp(12px, 3vw, 16px);
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    pointer-events: all;
    flex-shrink: 0; /* Prevent shrinking */
}
.top-bar-button:hover {
    background-color: #00a387;
}
.top-bar-button:disabled {
    background-color: #555;
    cursor: not-allowed;
}

/* Specific style for the Reset Save button */
#reset-save-button {
    background-color: #d9534f; /* Reddish color */
}
#reset-save-button:hover:not(:disabled) {
     background-color: #c9302c; /* Darker red on hover */
}

/* Adjust Speed Boost Button style to fit Top Bar */
#speed-boost-button {
     /* Uses top-bar-button class */
     background-color: #ffca3a; /* Yellow color */
     color: var(--primary-bg); /* Dark text for contrast */
}

#speed-boost-button:hover:not(:disabled) {
    background-color: #f0b300; /* Darker yellow on hover */
}

#speed-boost-button .cost img {
    filter: invert(1); /* Make diamond white on yellow background */
}


/* New styles for the control buttons area - now contains EVERYTHING in the bottom bar */
#control-buttons-area {
    display: flex; /* Arrange children (tower selection, codes, buttons) */
    flex-wrap: wrap; /* Allow children to wrap onto multiple lines */
    gap: 10px; /* Gap between individual elements within the control area */
    align-items: center; /* Align items vertically within their flex line */
    justify-content: center; /* Center content horizontally within the area */
     width: 100%; /* Allow it to take full width if needed for wrapping */
    max-width: 800px; /* Optional: Limit max width for larger screens */
     /* Removed margin-left: auto; as it's the only item in bottom-bar */
}

#tower-selection {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 5px 0;
    /* Removed margin-left: auto; */
     /* Now managed by flex-wrap and gap of parent (#control-buttons-area) */
     width: auto; /* Let flex determine width */
     max-width: 100%; /* Prevent overflow, allow wrapping */
     /* Ensure it takes priority for horizontal scroll space if needed */
     flex-grow: 1; /* Allow it to grow */
     flex-shrink: 1; /* Allow it to shrink */
     min-width: 0; /* Prevent overflow */
     /* Added styles for better visibility when scrolling on mobile */
     scrollbar-width: thin; /* Firefox */
     scrollbar-color: var(--accent-color) var(--secondary-bg); /* Firefox */
}

/* Webkit scrollbar styles */
#tower-selection::-webkit-scrollbar {
  height: 8px;
}

#tower-selection::-webkit-scrollbar-track {
  background: var(--secondary-bg);
  border-radius: 10px;
}

#tower-selection::-webkit-scrollbar-thumb {
  background-color: var(--accent-color);
  border-radius: 10px;
  border: 2px solid var(--secondary-bg);
}

.tower-card {
    width: 60px;
    height: 75px;
    background-color: var(--secondary-bg);
    border: 2px solid var(--ui-border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

.tower-card.selected {
    border-color: var(--accent-color);
    transform: scale(1.1);
}

.tower-card.disabled {
    filter: grayscale(1) brightness(0.6);
    cursor: not-allowed;
}


.tower-card img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.tower-cost {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: var(--text-color);
    font-weight: bold;
}
.tower-cost img {
    width: 12px;
    height: 12px;
    margin-right: 2px;
}

.control-button {
    padding: 10px 15px;
    background-color: var(--accent-color);
    color: var(--text-color);
    border: none;
    border-radius: 8px;
    font-size: clamp(14px, 3.5vw, 18px);
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    pointer-events: all;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

.control-button:hover {
    background-color: #c43750;
}
.control-button:disabled {
    background-color: #555;
    cursor: not-allowed;
}

.cost {
    display: flex;
    align-items: center;
    font-size: 12px;
    opacity: 0.8;
}

.cost img {
    width: 14px;
    height: 14px;
    margin-right: 3px;
}

#code-redemption {
    display: flex;
    align-items: center;
    gap: 5px;
    /* Removed margin-right */
}

#code-input {
    background-color: var(--secondary-bg);
    border: 1px solid var(--ui-border);
    border-radius: 5px;
    color: var(--text-color);
    padding: 8px;
    width: 120px; /* Fixed width, adjust as needed */
    font-size: 14px;
    pointer-events: all;
}

#code-input::placeholder {
    color: #aaa;
}

#redeem-code-button {
    background-color: var(--accent-color);
    border: none;
    color: var(--text-color);
    font-weight: bold;
    font-size: 18px;
    border-radius: 5px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    pointer-events: all;
    transition: background-color 0.2s;
}
#redeem-code-button:hover {
    background-color: #c43750;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    pointer-events: all;
    overflow-y: auto; /* Add scroll for smaller screens */
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background-color: var(--secondary-bg);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid var(--ui-border);
    color: var(--text-color);
    text-align: center;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    animation: modal-appear 0.3s ease-out;
    max-height: 90vh; /* Limit height on small screens */
    overflow-y: auto; /* Add scroll inside modal content */
}

@keyframes modal-appear {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-content h2 {
    color: var(--accent-color);
    margin-bottom: 15px;
}

.modal-content button {
    margin-top: 20px;
    padding: 12px 25px;
    background-color: var(--accent-color);
    color: var(--text-color);
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
}

/* Gacha Modal Specific Styles */
#gacha-type-selector {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap; /* Allow buttons to wrap */
}
.gacha-select-button {
     /* Inherits base button styles, override as needed */
     padding: 8px 15px; /* Smaller padding */
     margin-top: 0 !important; /* Override default button margin */
     font-size: 14px !important; /* Smaller font */
     background-color: #555 !important; /* Default state color */
}
.gacha-select-button.active {
    background-color: var(--accent-color) !important; /* Active state color */
}
#potion-gacha-select-button.active {
    background-color: var(--potion-color) !important; /* Distinct color for potion button */
}

.gacha-section {
     margin-top: 15px;
     padding-top: 15px;
     border-top: 1px dashed rgba(255,255,255,0.1);
}
.gacha-section.hidden {
    display: none;
}

#gacha-probabilities {
    font-size: 0.9em;
    margin-top: 15px; /* Adjusted margin */
    margin-bottom: 15px;
    color: #aaa;
    font-style: italic;
    text-align: left; /* Align probabilities list left */
}
#gacha-probabilities ul {
     list-style: none;
     padding: 0;
     margin: 0;
}
#gacha-probabilities li {
     margin-bottom: 8px;
}
#gacha-probabilities li ul {
     margin-top: 4px;
     margin-left: 15px;
}
#gacha-probabilities li li {
     font-size: 0.9em;
     margin-bottom: 4px;
}


.gacha-result { /* Applies to both diamond and potion result divs */
    margin: 20px 0;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.gacha-result img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    animation: gacha-reveal 0.5s ease-out;
}

@keyframes gacha-reveal {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.gacha-crystal { /* Applies to both diamond and potion crystal divs */
    width: 100px;
    height: 100px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin: 10px auto;
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
}
#gacha-crystal-diamond {
     background-image: url('diamond.png');
}
#gacha-crystal-potion {
     background-image: url('upgrade_point.png'); /* Use potion icon */
}


.gacha-crystal:hover:not(.spinning) { /* Only scale if not spinning */
    transform: scale(1.1);
}

.gacha-crystal.spinning {
    animation: spin-and-glow 1.5s ease-in-out;
}

@keyframes spin-and-glow {
    0% { transform: scale(1) rotate(0deg); filter: brightness(1); }
    50% { transform: scale(1.2) rotate(180deg); filter: brightness(2) drop-shadow(0 0 15px #00ffff); }
    100% { transform: scale(1) rotate(360deg); filter: brightness(1); }
}


#tower-info-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 250px;
    background-color: var(--secondary-bg);
    border-radius: 8px;
    border: 2px solid var(--ui-border);
    padding: 15px;
    color: var(--text-color);
    z-index: 50;
    pointer-events: all;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}
#tower-info-panel.hidden {
    display: none;
}
#tower-info-panel h3 {
    color: var(--accent-color);
    text-align: center;
}
#tower-info-panel p {
    margin: 8px 0;
}
#tower-info-panel button {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    background-color: var(--accent-color);
    color: var(--text-color);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
#tower-info-panel button:disabled {
    background-color: #555;
    cursor: not-allowed;
}
#tower-info-panel .cost {
    display: flex;
    align-items: center;
    font-size: 12px;
    opacity: 0.9;
}
#tower-info-panel .cost img {
    width: 14px;
    height: 14px;
    margin-right: 3px;
}
#close-info-panel {
    background-color: #666 !important;
     margin-top: 15px; /* Add more space above close */
}

#gacha-message {
    margin: 5px 0 10px;
    font-weight: bold;
    color: var(--accent-color);
    min-height: 1.2em;
}

#game-message {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(22, 33, 62, 0.9);
    color: var(--text-color);
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px solid var(--ui-border);
    z-index: 2000;
    font-size: clamp(14px, 3vw, 18px);
    text-align: center;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    pointer-events: none;
}
#game-message.hidden {
    display: none;
}

/* Codes Modal Styles (already existed, adding map modal below) */
#codes-modal .modal-content h2 {
    margin-bottom: 5px;
}
#codes-modal .modal-content p {
    font-size: 0.9em;
    margin-bottom: 10px;
}
#codes-list {
    /* Styles applied dynamically in JS for flexibility */
}

/* New Map Selection Modal Styles */
#map-selection-modal .modal-content h2 {
     color: #00c2a2; /* Different color for map modal */
}
#map-list {
    display: flex;
    flex-direction: column; /* Stack map options vertically */
    gap: 15px;
    margin-top: 20px;
    max-height: 300px; /* Limit height for scroll */
    overflow-y: auto;
    padding-right: 5px; /* Add padding for scrollbar */
}

.map-option {
    background-color: rgba(0,0,0,0.2);
    border: 2px solid var(--ui-border);
    border-radius: 8px;
    padding: 10px;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}
.map-option:hover {
     border-color: #00c2a2;
     background-color: rgba(0,0,0,0.3);
}
.map-option img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    margin-bottom: 5px;
    max-height: 150px; /* Limit image height */
    object-fit: cover;
}
.map-option h3 {
     font-size: 1.2em;
     margin: 0;
     color: var(--text-color);
}

/* Specific style for the Reset Save button */
#reset-save-button {
    background-color: #d9534f; /* Reddish color */
}
#reset-save-button:hover:not(:disabled) {
     background-color: #c9302c; /* Darker red on hover */
}

/* NEW: Potion Upgrade Section styles */
.potion-upgrade-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed rgba(255,255,255,0.1);
}
.potion-upgrade-section p {
     text-align: center;
     font-weight: bold;
}
.potion-upgrade-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Space between potion buttons */
    margin-top: 10px;
}
.potion-upgrade-buttons button {
    padding: 8px 10px; /* Smaller padding than main upgrade */
    background-color: #3a86ff; /* A distinct color, like blue */
    color: var(--text-color);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
    display: flex; /* Ensure cost aligns if added later */
    justify-content: center;
    align-items: center;
}
.potion-upgrade-buttons button:hover {
     background-color: #2a75d9;
}
.potion-upgrade-buttons button:disabled {
    background-color: #555;
    cursor: not-allowed;
}