:root {
    --bg-color: #0b0b0b;
    --grid-line: #1a1a1a;
    --text-color: #e0e0e0;
    --accent-green: #00ff66;
    --accent-red: #ff3333;
    --accent-blue: #33ccff;
    --accent-purple: #aa00ff;
    --panel-bg: #141414;
    --ui-border: #333;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden; /* Prevent body scroll */
    height: 100vh;
}

#game-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    padding: 0;
}

.main-layout {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.game-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #000;
    overflow: hidden;
}

#gameCanvas {
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    cursor: crosshair;
}

#ui-panel {
    background-color: var(--panel-bg);
    border-left: 1px solid var(--ui-border);
    padding: 20px;
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: -4px 0 6px rgba(0,0,0,0.3);
    height: 100%;
    overflow: hidden; /* Prevent scrollbar on main container */
    z-index: 10;
}

.tower-select {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.tower-btn {
    position: relative; /* For hotkey absolute positioning */
    padding: 10px;
    border: 2px solid transparent;
    background-color: #222;
    color: #fff;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 4px;
    white-space: normal;
    line-height: 1.2;
    font-size: 11px;
    text-align: center;
}

.hotkey-indicator {
    position: absolute;
    top: 2px;
    left: 4px;
    font-family: 'Geo', sans-serif;
    font-weight: bold;
    font-size: 20px;
    color: rgba(255, 255, 255, 0.6);
    pointer-events: none;
    line-height: 1;
}

.tower-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.2);
}

.tower-btn.selected {
    border-color: var(--selected-color, #fff);
    background-color: #333;
}

.tower-btn:disabled, .tower-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(100%);
    border-color: #444;
    color: #666;
    pointer-events: none;
}

/* Dynamic borders handled by JS */


.config-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    font-size: 11px;
}

.config-group {
    background: #1a1a1a;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #333;
}

.config-group h4 {
    margin: 0 0 8px 0;
    color: #ccc;
    font-size: 12px;
    border-bottom: 1px solid #444;
    padding-bottom: 4px;
    text-transform: uppercase;
}

.config-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px; /* Compact */
}

.config-item label {
    color: #888;
    flex: 1;
    white-space: normal; /* Allow wrap */
    overflow: hidden;
    font-size: 10px; /* Smaller */
    margin-right: 4px;
    line-height: 1.1;
}

.config-item input {
    background: #222;
    border: 1px solid #333;
    color: #ccc;
    padding: 1px 4px;
    border-radius: 3px;
    width: 45px; /* Compact */
    text-align: right;
    font-family: monospace;
    font-size: 10px;
}

.config-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px 0; /* Vertical Gap between rows | Horizontal Gap */
}

.config-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-sizing: border-box;
}

/* Divider & Spacing Controls */
.config-col:nth-child(odd) {
    padding-right: 12px; /* Spacing between Left Column and Divider */
}

.config-col:nth-child(even) {
    border-left: 1px solid #333; /* The Vertical Divider Line */
    padding-left: 12px; /* Spacing between Divider and Right Column */
}

.config-col h5 {
    margin: 0 0 5px 0;
    color: #ccc; /* Default neutral, JS will override */
    font-size: 11px;
    text-transform: uppercase;
    border-bottom: 1px solid #333;
    padding-bottom: 2px;
}

.stats-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: #888;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--ui-border);
}

.stat-value {
    color: #fff;
    font-weight: bold;
}

#map-reference {
    width: 100%;
    max-width: 1200px;
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    background: var(--panel-bg);
    margin-top: 0;
    overflow: hidden;
}

#map-reference summary {
    padding: 10px;
    cursor: pointer;
    background: #222;
    color: #ccc;
    user-select: none;
    font-weight: bold;
}

#maps-container {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.map-entry {
    font-family: 'Courier New', Courier, monospace;
    white-space: pre;
    background: #000;
    padding: 10px;
    border: 1px solid #333;
    color: var(--accent-green);
    font-size: 12px;
    line-height: 1.2;
}

.map-title {
    color: #888;
    margin-bottom: 5px;
    font-family: sans-serif;
    font-size: 14px;
}
.map-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #1a1a1a;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #333;
}

.map-btn {
    background: #333;
    border: 1px solid #444;
    color: #eee;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    transition: all 0.2s;
    user-select: none;
}

.map-btn:hover {
    background: #444;
    border-color: #fff;
    color: #fff;
}

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

#map-current {
    font-weight: bold;
    color: var(--accent-green);
    min-width: 20px;
    text-align: center;
    font-family: monospace;
    font-size: 14px;
}

/* Splash Screen & Blur */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6); /* Semi-transparent overlay */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px); /* Additional blur on overlay itself */
}

#splash-content {
    background: rgba(20, 20, 20, 0.9);
    padding: 40px 60px;
    border: 1px solid var(--accent-green);
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0, 255, 102, 0.2);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

#splash-title {
    font-size: 48px;
    font-weight: bold;
    color: var(--accent-green);
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 10px rgba(0, 255, 102, 0.5);
    margin: 0;
}

#splash-subtitle {
    font-size: 18px;
    color: #ccc;
    margin-top: 10px;
    /* font-style: italic; */
}

#splash-note {
    font-size: 14px;
    color: #ccc;
    margin-top: 10px;
}

#btn-start-game {
    background: transparent;
    color: var(--accent-green);
    border: 2px solid var(--accent-green);
    padding: 15px 40px;
    font-size: 20px;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 20px;
    border-radius: 4px;
}

#btn-start-game:hover {
    background: var(--accent-green);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 255, 102, 0.6);
    transform: scale(1.05);
}

/* Blur Target */
#game-container.blurred {
    filter: blur(5px);
    pointer-events: none; /* Prevent clicking game through splash */
    transition: filter 0.5s ease;
}

.play-pause-btn {
    background: #222;
    border: 1px solid #444;
    color: var(--accent-green);
    cursor: pointer;
    font-size: 16px;
    padding: 12px;
    border-radius: 4px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
}
.play-pause-btn:hover { background: #333; border-color: #fff; }

.music-btn {
    background: #222;
    border: 1px solid #444;
    color: #aaa;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    margin-top: 10px;
    width: 100%;
    border-radius: 4px;
}
.music-btn:hover { background: #333; color: #fff; }
.music-btn.active { color: var(--accent-green); border-color: var(--accent-green); }
.music-btn.paused { color: #ffaa00; border-color: #ffaa00; }

#audio-panel {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    background: #1a1a1a;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #333;
    flex-shrink: 0; /* Never shrink */
}

/* Reusing music-btn style but override margins */
#audio-panel .music-btn {
    margin: 0;
    width: auto;
    padding: 6px 12px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    white-space: nowrap;
}

#btn-music {
    width: 90px; /* Fixed width for play/pause to prevent jitter */
}

#btn-next-song {
    width: auto; /* Fit content */
    padding: 6px 10px; /* Specific padding */
}

.audio-icon {
    display: inline-block;
    width: 14px; /* Fixed width for symbol */
    text-align: center;
    margin-right: 4px;
}

.vol-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.vol-label {
    font-size: 9px;
    color: #888;
    text-transform: uppercase;
    font-weight: bold;
}

.vol-btns {
    display: flex;
    gap: 2px;
}

.vol-btn {
    background: #333;
    border: 1px solid #444;
    color: #ccc;
    width: 20px;
    height: 18px; /* Compact */
    border-radius: 2px;
    cursor: pointer;
    font-size: 8px; /* Arrows small */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.vol-btn:hover {
    background: #444;
    color: #fff;
    border-color: #666;
}

.vol-btn:active {
    background: var(--accent-green);
    color: #000;
}

#ui-content-wrapper {
    position: relative; /* For Game Over Overlay */
    flex: 1; /* Take remaining height */
    overflow: hidden; /* Use hidden here, let children manage scroll */
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0; /* Firefox/Flex fix */
    padding-right: 2px; /* Scrollbar space */
    padding-bottom: 20px; /* Ensure gap at bottom */
}

#game-over-panel {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 20, 20, 0.95);
    z-index: 20;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    backdrop-filter: blur(2px);
}

#game-over-panel.active {
    display: flex;
}

.game-over-content {
    background: rgba(20, 20, 20, 0.9);
    padding: 50px 70px;
    border: 2px solid var(--accent-red);
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(255, 51, 51, 0.4);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

#game-over-panel h2 {
    font-size: 48px;
    color: var(--accent-red);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 15px rgba(255, 51, 51, 0.6);
    line-height: 1.1;
}

#game-over-panel p {
    font-size: 24px;
    color: #fff;
    margin: 0;
    font-weight: bold;
}

#btn-new-game {
    background: transparent;
    color: var(--accent-green);
    border: 2px solid var(--accent-green);
    padding: 15px 40px;
    font-size: 20px;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s;
    border-radius: 4px;
}

#btn-new-game:hover {
    background: var(--accent-green);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 255, 102, 0.6);
    transform: scale(1.05);
}

/* Config Tabs */
.config-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 0px;
    padding-bottom: 0px;
    margin-top: 10px;
}

.tab-btn {
    background: #222;
    border: 1px solid #444;
    color: #888;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    text-transform: uppercase;
    font-weight: bold;
    flex: 1;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: #333;
    color: #ccc;
}

.tab-btn.active {
    color: var(--accent-green);
    border-color: var(--accent-green);
    background: #1a1a1a;
    box-shadow: 0 0 10px rgba(0, 255, 102, 0.1);
}

.config-section {
    display: none;
    animation: fadeIn 0.2s ease-in-out;
}

.config-section.active {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

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

.dir-btn {
    background: #333;
    border: 1px solid #555;
    color: #ccc;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dir-btn:hover { background: #444; color: #fff; border-color: #fff; }
.dir-btn.active { background: #4b0082; color: #fff; border-color: #aa00ff; }

.hotkey-sub {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 8px;
    opacity: 0.7;
    font-family: monospace;
    font-weight: bold;
    color: #fff;
    pointer-events: none;
}

a {
    color: #FFFF00;
    text-decoration: underline;
    font-weight: bold;
    line-height: 1.1;
    padding: 0.5rem;
}



/* Context Panel Background */
.tower-context-panel {
    position: relative; /* Context for absolute canvas */
    overflow: hidden; /* contain the canvas */
    z-index: 1;
    flex: 1; /* Fill remaining height */
    overflow-y: auto; /* Scroll internally if needed */
    margin-bottom: 20px; /* Padding from bottom */
    min-height: 0; /* Allow shrinking */
}

#ctx-bg-canvas {
    z-index: 0;
}

.tower-context-panel > * {
    position: relative; /* Sit above canvas */
    z-index: 1; /* Above canvas */
}
