:root {
    --bg-dark: #0F1219;
    --primary: #64748B;
    --secondary: #94A3B8;
    --accent: #38BDF8;
    --text-light: #F8FAFC;
    --text-muted: #CBD5E1;
    --danger: #EF4444;
    --success: #10B981;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --border-radius: 12px;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: 'Inter', system-ui, sans-serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Layout */
#game-wrapper {
    display: flex;
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    max-height: 800px;
    background: #0B0E14;
    box-shadow: 0 0 40px rgba(0,0,0,0.8);
    position: relative;
    border: 1px solid rgba(255,255,255,0.05);
}

#main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

#sidebar {
    width: 300px;
    background: #111827;
    border-left: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
    overflow-y: auto;
}

/* Top Bar HUD */
#top-bar {
    height: 50px;
    background: var(--panel-bg);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 20px;
    backdrop-filter: blur(10px);
    z-index: 10;
}

.stat {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-light);
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Canvas Area */
#canvas-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: calc(100% - 50px);
    background-color: #1E293B; /* Grass/Floor color will be drawn on canvas, this is fallback */
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Panels */
.panel {
    background: var(--panel-bg);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: var(--border-radius);
    padding: 15px;
    backdrop-filter: blur(10px);
}

.flex-fill {
    flex: 1;
}

.panel h2, .panel h3 {
    color: var(--accent);
    margin-bottom: 10px;
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.panel h3 {
    font-size: 14px;
    color: var(--text-light);
}

.panel p {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 15px;
    line-height: 1.4;
}

/* Tower Selection */
.tower-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-light);
    border-radius: 8px;
    padding: 10px;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
}

.tower-btn:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: var(--accent);
}

.tower-btn.selected {
    background: rgba(56, 189, 248, 0.2);
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.hidden {
    display: none !important;
}

/* Regex Input */
.input-group {
    display: flex;
    align-items: center;
    background: #0B0E14;
    border: 1px solid var(--primary);
    border-radius: 6px;
    padding: 5px 10px;
    margin-bottom: 10px;
}

.regex-slash {
    color: var(--accent);
    font-weight: bold;
    font-family: 'Fira Code', monospace;
}

input[type="text"] {
    background: transparent;
    border: none;
    color: #fff;
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    width: 100%;
    padding: 5px;
    outline: none;
}

#tower-stats {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 15px;
}

/* Buttons */
button {
    width: 100%;
    padding: 12px;
    border-radius: 6px;
    border: none;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    position: relative;
    overflow: hidden;
}

button:active {
    transform: scale(0.98);
}

.btn-primary, #btn-build {
    background: var(--accent);
    color: #000;
    box-shadow: 0 4px 15px rgba(56, 189, 248, 0.4);
}

.btn-primary:hover, #btn-build:hover:not(:disabled) {
    background: #7DD3FC;
}

#btn-build:disabled {
    background: #334155;
    color: #94A3B8;
    cursor: not-allowed;
    box-shadow: none;
}

.secondary {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--text-light);
    margin-top: 5px;
}

.secondary:hover {
    background: rgba(255,255,255,0.05);
}

/* Cheat Sheet */
.cheat-sheet ul {
    list-style: none;
    font-size: 12px;
    line-height: 1.6;
}

.cheat-sheet li {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding: 4px 0;
}

.cheat-sheet code {
    background: rgba(56, 189, 248, 0.1);
    color: var(--accent);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
}

/* Modals */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--panel-bg);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 40px;
    border-radius: var(--border-radius);
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.modal h1 {
    color: var(--accent);
    margin-bottom: 20px;
    font-weight: 800;
}

.modal p {
    color: var(--text-muted);
    margin-bottom: 25px;
    line-height: 1.5;
}

.high-score-form {
    margin-bottom: 20px;
}

/* Leaderboard */
#leaderboard {
    margin-top: 30px;
    text-align: left;
}

#leaderboard h3 {
    text-align: center;
    color: var(--accent);
    margin-bottom: 10px;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    background: rgba(0,0,0,0.3);
    padding: 8px 15px;
    border-radius: 4px;
    margin-bottom: 5px;
    font-family: 'Fira Code', monospace;
    font-size: 14px;
}

/* Floating Text (Juice) */
#floating-text-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
}

.floating-text {
    position: absolute;
    font-family: 'Fira Code', monospace;
    font-weight: bold;
    text-shadow: 0 0 5px #000, 0 0 10px #000;
    pointer-events: none;
    animation: floatUp 1s ease-out forwards;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(0.5); opacity: 0; }
    20% { transform: translateY(-10px) scale(1.2); opacity: 1; }
    100% { transform: translateY(-40px) scale(1); opacity: 0; }
}

@keyframes shakeCanvas {
    0% { transform: translate(0, 0); }
    10% { transform: translate(-5px, -5px); }
    20% { transform: translate(5px, -5px); }
    30% { transform: translate(-5px, 5px); }
    40% { transform: translate(5px, 5px); }
    50% { transform: translate(-3px, -3px); }
    60% { transform: translate(3px, -3px); }
    70% { transform: translate(-3px, 3px); }
    80% { transform: translate(3px, 3px); }
    90% { transform: translate(-1px, -1px); }
    100% { transform: translate(0, 0); }
}

.shake {
    animation: shakeCanvas 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

/* Responsive */
@media (max-width: 768px) {
    #game-wrapper {
        flex-direction: column;
    }
    #sidebar {
        width: 100%;
        height: 300px;
        flex-direction: row;
        border-left: none;
        border-top: 1px solid rgba(255,255,255,0.1);
    }
    .panel {
        flex: 1;
        overflow-y: auto;
    }
}
