@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Roboto:wght@300;400;700&display=swap');

:root {
    --color-bg-dark: #0b0c10;
    --color-bg-panel: #1f2833;
    --color-primary: #66fcf1;
    --color-secondary: #45a29e;
    --color-accent: #c5c6c7;
    --color-text: #e0e0e0;
    --font-ui: 'Orbitron', sans-serif;
    --font-body: 'Roboto', sans-serif;
}

/* Global Reset */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 20px 0;
    /* Add top/bottom padding to prevent clipping */
    background-color: #0b0c10;
    color: #c5c6c7;
    font-family: 'Roboto', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    /* Strict height */
    overflow: hidden;
    /* No scrollbars */
}

h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: 3.5rem;
    text-align: center;
    width: 100%;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 6px;
    font-weight: 900;

    /* Ultra Modern Gradient */
    background: linear-gradient(180deg, #fff 0%, #00f2ff 50%, #00c3ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    /* Fallback in case clip fails is solid color, but clip hides it */

    /* Deep Glow Layers */
    text-shadow:
        0 0 10px rgba(0, 242, 255, 0.3),
        0 0 20px rgba(0, 242, 255, 0.3),
        0 0 40px rgba(0, 242, 255, 0.3),
        0 0 80px rgba(0, 242, 255, 0.3);

    position: relative;
    animation: titlePulse 4s ease-in-out infinite alternate;
}

/* Optional Glitch Overlay Effect via Pseudo-element? */
h1::before {
    content: attr(data-text);
    /* Need to add data-text attribute in HTML if we want this */
}

@keyframes titlePulse {
    0% {
        text-shadow:
            0 0 10px rgba(0, 242, 255, 0.4),
            0 0 20px rgba(0, 242, 255, 0.4),
            0 0 40px rgba(0, 242, 255, 0.2);
        transform: scale(1);
    }

    100% {
        text-shadow:
            0 0 15px rgba(0, 242, 255, 0.8),
            0 0 30px rgba(0, 242, 255, 0.6),
            0 0 60px rgba(0, 242, 255, 0.4),
            0 0 10px rgba(255, 255, 255, 0.3);
        /* White core flare */
        transform: scale(1.02);
    }
}

#game-wrapper {
    display: flex;
    flex-direction: row;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    /* Removed fixed scale to let flexbox handle it, max-width controls size */
    max-width: 95vw;
    max-height: 90vh;
}

/* ... existing canvas ... */
#gameCanvas {
    background-color: #000;
    border: 2px solid var(--color-secondary);
    border-radius: 8px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
    cursor: crosshair;
    display: block;
}

/* Game Container */
#game-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    /* Ensure top alignment */
    justify-content: center;
    /* Center horizontally if space permits */
}

#gameCanvas {
    background-color: #000;
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.2);
    border: 1px solid #1a1a2e;
    cursor: crosshair;
    border-radius: 8px;
}

#ui-panel-wrapper {
    display: flex;
    gap: 15px;
    height: 600px;
    /* Match canvas height */
}

.ui-sidebar {
    width: 220px;
    /* Slight increase for better fit */
    background: rgba(10, 10, 15, 0.95);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;

    /* Scrollbar Styling */
    scrollbar-width: thin;
    scrollbar-color: #00f2ff #1a1a2e;
}

.ui-sidebar::-webkit-scrollbar {
    width: 6px;
}

.ui-sidebar::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.ui-sidebar::-webkit-scrollbar-thumb {
    background-color: #00f2ff;
    border-radius: 3px;
}

/* Ensure shop grid fits */
.shop-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

/* Button Active State - Ensure this works! */
.neon-btn.active {
    background: var(--color-primary);
    color: #000 !important;
    /* Force black text for contrast */
    box-shadow: 0 0 15px var(--color-primary);
    border-color: var(--color-primary);
}

gap: 8px;
}

/* Button Active State */
.neon-btn.active {
    background: var(--color-primary);
    color: #000;
    box-shadow: 0 0 15px var(--color-primary);
}

/* ... UI Panel ... */
/* ... Stats ... */
.stats-card {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--color-primary);
    font-family: var(--font-ui);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.0rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 4px;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--color-secondary);
}

.stat-value {
    color: #fff;
    font-weight: bold;
}

.controls-section,
.shop-section,
.skills-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

button {
    background: linear-gradient(135deg, var(--color-secondary), #2c3e50);
    border: none;
    color: white;
    padding: 12px;
    border-radius: 4px;
    font-family: var(--font-ui);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

button:hover {
    filter: brightness(1.2);
    box-shadow: 0 0 10px var(--color-secondary);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
    box-shadow: none;
}

/* Speed Buttons - Full Width & Equal Size */
.speed-controls {
    display: flex;
    gap: 5px;
    margin: 10px 0;
    width: 100%;
}

.speed-btn {
    flex: 1;
    /* Equal width */
    background: #1f2833;
    border: 1px solid #66fcf1;
    color: #66fcf1;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    padding: 5px 0;
    transition: all 0.2s;
    text-align: center;
}

.speed-btn:hover,
.speed-btn.active {
    background: #66fcf1;
    color: #0b0c10;
    box-shadow: 0 0 10px #66fcf1;
}

/* Sidebar Columns for Shop/Skills */
.shop-section h3,
.skills-section h3 {
    margin: 10px 0 5px 0;
    font-size: 1rem;
    color: #66fcf1;
    text-transform: uppercase;
    border-bottom: 1px solid #45a29e;
    padding-bottom: 5px;
}

#shop-container,
#skills-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* 2 Columns Enforced */
    gap: 8px;
    margin-bottom: 10px;
}

.tower-btn,
.skill-btn {
    width: 100%;
    /* Fill grid cell */
    box-sizing: border-box;
    padding: 8px 4px;
    font-size: 0.8rem;
    text-transform: uppercase;
}

.shop-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tower-btn {
    text-align: center;
    font-size: 0.8rem;
    padding: 10px 5px;
    border: 1px solid transparent;
}

.tower-btn:hover {
    border-color: var(--color-primary);
}

.skill-btn {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

/* Modal / Overflow specific styles can go here */
.upgrade-overlay {
    position: absolute;
    background: rgba(11, 12, 16, 0.95);
    border: 1px solid var(--color-primary);
    padding: 15px;
    border-radius: 8px;
    display: none;
    /* Hidden by default */
    z-index: 100;
    width: 200px;
}

.upgrade-option {
    margin-bottom: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
}

.upgrade-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

@keyframes shake {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    20% {
        transform: translate(-3px, 0px) rotate(1deg);
    }

    30% {
        transform: translate(3px, 2px) rotate(0deg);
    }

    40% {
        transform: translate(1px, -1px) rotate(1deg);
    }

    50% {
        transform: translate(-1px, 2px) rotate(-1deg);
    }

    60% {
        transform: translate(-3px, 1px) rotate(0deg);
    }

    70% {
        transform: translate(3px, 1px) rotate(-1deg);
    }

    80% {
        transform: translate(-1px, -1px) rotate(1deg);
    }

    90% {
        transform: translate(1px, 2px) rotate(0deg);
    }

    100% {
        transform: translate(1px, -2px) rotate(-1deg);
    }
}

.shake {
    animation: shake 0.5s;
    animation-iteration-count: 1;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #0b0c10;
    border: 2px solid #e74c3c;
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 0 50px rgba(231, 76, 60, 0.5);
    min-width: 300px;
    animation: fadeIn 0.5s ease-out;
}

.neon-text {
    color: #e74c3c;
    text-shadow: 0 0 10px #e74c3c, 0 0 20px #e74c3c;
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    margin-bottom: 20px;
}

/* Toast Notifications (Bottom Right, Cool Style) */
.toast-notification {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: rgba(10, 10, 15, 0.95);
    border: 1px solid var(--color-primary);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.3);
    padding: 15px 20px;
    border-radius: 4px;
    /* Techy sharp-ish corners */
    color: #fff;
    z-index: 2000;
    font-family: 'Orbitron', sans-serif;
    transform: translateX(120%);
    /* Start off-screen right */
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Springy */
    display: flex;
    flex-direction: column;
    min-width: 250px;
    border-left: 5px solid var(--color-primary);
    /* Accent bar */
}

.toast-notification.show {
    transform: translateX(0);
}

.toast-notification::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent 0%, rgba(0, 242, 255, 0.05) 100%);
    pointer-events: none;
}

.modal-stats {
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    font-size: 1.2rem;
    margin-bottom: 30px;
    line-height: 1.6;
}

.modal-stats span {
    color: var(--color-primary);
    font-weight: bold;
}

/* Controls Section Updates */
.controls-row {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    width: 100%;
}

.btn-half {
    flex: 1;
    display: flex;
    flex-direction: column;
    /* Icon top, Text bottom */
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 10px 0;
    line-height: 1.2;
}

.icon-bar {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-top: 10px;
    gap: 5px;
}

.btn-icon-only {
    flex: 1;
    font-size: 1.5em;
    padding: 8px 0;
    display: flex;
    justify-content: center;
    /* Center icon */
    align-items: center;
}

/* Achievement Grid */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    /* 5 Columns */
    gap: 8px;
    padding: 10px;
    overflow-x: hidden;
}

.achievement-item {
    background: rgba(20, 20, 30, 0.9);
    border: 1px solid #333;
    padding: 8px;
    /* Compact padding */
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: all 0.3s ease;
    min-height: 80px;
    /* Smaller height */
}

.achievement-icon {
    font-size: 1.5em;
    /* Smaller icon */
    margin-bottom: 5px;
    margin-right: 0;
    /* Reset */
    opacity: 0.3;
}

.achievement-item.unlocked .achievement-icon {
    opacity: 1;
}

.achievement-info h4 {
    margin: 2px 0;
    font-size: 0.75em;
    /* Smaller font */
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.achievement-item.unlocked .achievement-info h4 {
    color: #f1c40f;
}

.achievement-info p {
    display: none;
    /* Compact mode: hide desc until hover? Or just show title */
}

.achievement-item:hover .achievement-info p {
    display: block;
    font-size: 0.7em;
    color: #ccc;
    position: absolute;
    background: #000;
    padding: 5px;
    border: 1px solid #444;
    z-index: 20;
    width: 150px;
    left: 50%;
    transform: translateX(-50%);
}

/* Large Modal & Scroll List */
.large-modal {
    width: 900px !important;
    /* Wider for 5 columns */
    max-width: 95vw;
}

.neon-btn {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
    padding: 15px 30px;
    font-size: 1.2rem;
    font-family: 'Orbitron', sans-serif;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    box-shadow: 0 0 10px rgba(102, 252, 241, 0.2);
}

.neon-btn:hover {
    background: var(--color-primary);
    color: #000;
    box-shadow: 0 0 30px rgba(102, 252, 241, 0.8);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}


/* Mobile / Tablet Responsive */

/* 1. Only apply fixed scale on large screens (Desktop) */
@media (max-width: 1024px) {
    #game-wrapper {
        transform: none;
        /* Disable scale on mobile to use natural flow */
        width: 100%;
        height: 100%;
        border: none;
        border-radius: 0;
        padding: 5px;
        box-sizing: border-box;
        gap: 10px;
    }

    body {
        height: auto;
        min-height: 100vh;
        justify-content: flex-start;
        padding-top: 10px;
        overflow-y: auto;
        /* Allow scroll if needed */
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 10px;
    }
}

/* 2. Portrait Mode Effect (Vertical) */
@media (max-width: 1024px) and (orientation: portrait) {
    #game-wrapper {
        flex-direction: column;
        align-items: center;
    }

    #gameCanvas {
        width: 100% !important;
        height: auto !important;
        /* Preserve Aspect Ratio */
        max-height: 60vh;
    }

    #ui-panel {
        width: 100%;
        max-width: 100%;
        border-left: none;
        border-top: 2px solid #00f2ff;
        flex-direction: row;
        /* Horizontal layout for controls if spacious */
        flex-wrap: wrap;
        padding: 10px;
    }

    .stats-card {
        flex: 1 1 100%;
        /* Full width stats on top of panel */
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        gap: 10px;
        margin-bottom: 5px;
    }

    .stat-row {
        flex-direction: column;
        border-bottom: none;
        font-size: 0.9rem;
    }

    .controls-section {
        flex: 1 1 45%;
    }

    .shop-section {
        flex: 1 1 100%;
        order: 3;
    }

    .skills-section {
        flex: 1 1 45%;
    }

    .shop-grid {
        grid-template-columns: repeat(4, 1fr);
        /* More columns for towers */
    }
}

/* 3. Landscape Mode Effect (Horizontal Mobile) */
@media (max-width: 1024px) and (orientation: landscape) {
    #game-wrapper {
        flex-direction: row;
        align-items: flex-start;
        height: 100vh;
        padding: 5px;
    }

    body {
        padding-top: 0;
        height: 100vh;
        overflow: hidden;
    }

    h1 {
        display: none;
        /* Hide title to save space */
    }

    #gameCanvas {
        height: 95vh !important;
        width: auto !important;
        max-width: 75vw;
    }

    #ui-panel {
        width: 25vw;
        height: 95vh;
        padding: 10px;
        overflow-y: auto;
    }

    .shop-grid {
        grid-template-columns: 1fr;
        /* 1 column for tight sidebars */
    }

    .stats-card {
        padding: 8px;
    }

    .stat-row {
        font-size: 0.8rem;
    }
}

/* 4. Touch Adjustments */
@media (hover: none) and (pointer: coarse) {
    button {
        min-height: 44px;
        /* Touch target size */
        padding: 15px;
    }

    .tower-btn {
        padding: 15px 5px;
    }
}