/* Inherit mostly from style.css, but add specific layout overrides */

#game-container {
    position: relative;
    width: 100%;
    flex-grow: 1;
    height: 100%;
    min-height: 400px;
    background-color: #222;
    border: 4px solid #444;
    overflow: hidden;
    cursor: crosshair;
}

.game-view {
    display: flex;
    justify-content: flex-start;
    gap: 20px;
    height: calc(100vh - 100px); /* Adjust based on header */
    padding: 10px;
    box-sizing: border-box;
}

#sidebar-left {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.tower-panel {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 15px;
    border: 2px solid #444;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    border-radius: 8px;
}

.tower-panel h3 {
    text-align: center;
    color: #ffd700;
    margin-bottom: 15px;
    border-bottom: 1px solid #555;
    padding-bottom: 10px;
}

.card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.tower-card {
    background: #334155;
    border: 2px solid #475569;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: grab;
    transition: transform 0.2s, background 0.2s;
    user-select: none;
    position: relative;
}

.tower-card:hover {
    background: #475569;
    transform: translateY(-2px);
    border-color: #64748b;
}

.tower-card:active {
    cursor: grabbing;
}

.tower-card.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

.tower-icon {
    width: 40px;
    height: 40px;
    background: #000;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.tower-name {
    font-size: 0.8rem;
    font-weight: bold;
    text-align: center;
}

.tower-stats {
    font-size: 0.7rem;
    color: #ccc;
    text-align: center;
}

.tower-cost {
    color: #ffd700;
    font-weight: bold;
    font-size: 0.9rem;
}

.upgrade-btn {
    width: 100%;
    padding: 4px;
    font-size: 0.7rem;
    margin-top: 5px;
    background: linear-gradient(to bottom, #3b82f6, #2563eb);
    border: none;
    color: white;
    border-radius: 4px;
    cursor: pointer;
}

.upgrade-btn:hover {
    filter: brightness(1.1);
}

/* Header Adjustments */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: #1a1a2e;
    border-bottom: 1px solid #333;
    flex-wrap: wrap;
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #4ade80; /* Nice green */
    white-space: nowrap;
    margin-right: 20px;
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    flex: 1;
}

.header-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: bold;
    white-space: nowrap;
}

.header-controls .btn {
    width: auto;
    margin: 0;
    padding: 6px 12px;
}

progress {
    height: 15px;
    border-radius: 4px;
    overflow: hidden;
}

#player-hp-bar::-webkit-progress-value { background: #3b82f6; }
#enemy-hp-bar::-webkit-progress-value { background: #ef4444; }

/* Mobile Responsive */
@media (max-width: 768px) {
    #app {
        display: flex;
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    .game-view {
        flex-direction: column;
        padding: 5px;
        gap: 5px;
        height: auto;
        flex: 1;
    }

    #game-container {
        order: 1;
        height: 60vh; /* Canvas takes 60% */
        width: 100%;
    }

    #sidebar-left {
        order: 2;
        width: 100%;
        height: 30vh; /* Controls take remaining space */
        min-height: 0;
    }

    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }

    .tower-card {
        padding: 5px;
    }

    .tower-icon {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
}

/* Modals */
.modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #1e293b;
    border: 2px solid #475569;
    padding: 20px;
    width: 90%;
    max-width: 500px;
    border-radius: 10px;
    color: #fff;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    max-height: 80vh;
    overflow-y: auto;
}

.close-modal {
    float: right;
    font-size: 24px;
    cursor: pointer;
    color: #94a3b8;
}

.close-modal:hover {
    color: #fff;
}

/* Highlight affordable items */
.can-afford {
    /* Use !important to override default borders or styles */
    border-color: #ffd700 !important;
    box-shadow: 0 0 8px #ffd700, inset 0 0 5px rgba(255, 215, 0, 0.2) !important;
    transition: all 0.3s ease;
}

/* Specific button overrides to make sure they glow */
button.can-afford {
    border: 1px solid #ffd700 !important;
}

.tower-card.can-afford {
    border: 2px solid #ffd700 !important;
}

.hero-card {
    background: #334155;
    border: 2px solid #475569;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    color: #fff;
    transition: transform 0.2s, background 0.2s;
}

.hero-card:hover {
    background: #475569;
    transform: translateY(-2px);
    border-color: #64748b;
}

.hero-shape {
    width: 20px;
    height: 20px;
    margin-bottom: 5px;
}

.hero-shape.circle {
    border-radius: 50%;
}

.hero-shape.triangle {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 20px solid;
    background: transparent !important;
}

.hero-shape.square {
    /* Square is default div */
}

.hero-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.hero-name {
    font-size: 0.8rem;
    font-weight: bold;
}

.hero-count-label {
    font-size: 0.7rem;
    color: #ccc;
    margin-bottom: 5px;
}

.spawn-btn, .hero-upgrade-btn {
    width: 100%;
    padding: 4px;
    font-size: 0.7rem;
    margin-top: 2px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.spawn-btn {
    background: linear-gradient(to bottom, #3b82f6, #2563eb);
    color: white;
}

.hero-upgrade-btn {
    background: #475569;
    color: #cbd5e1;
    font-size: 0.65rem;
}

.spawn-btn:hover, .hero-upgrade-btn:hover {
    filter: brightness(1.1);
}

.spawn-btn:disabled, .hero-upgrade-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #1e293b;
}

#minimap {
    background-color: #111;
    border: 1px solid #444;
    margin-right: auto;
    vertical-align: middle;
}

/* Ensure minimap shrinks on small screens if needed, or hide it */
@media (max-width: 600px) {
    #minimap {
        display: none;
    }
}

/* Flip Card Styles */
.flip-container {
    perspective: 1000px;
    position: relative;
    /* Determine height dynamically based on children */
}

.flip-container.flipped .flipper {
    transform: rotateY(180deg);
}

.flipper {
    transition: transform 0.6s;
    transform-style: preserve-3d;
    position: relative;
    width: 100%;
    height: 100%; /* Matches container */
}

/* Front and Back common styles */
.front, .back {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    width: 100%;
    box-sizing: border-box;
    border-radius: 8px; /* Match existing radius */
}

.front {
    position: relative; /* Let the front determine the height */
    z-index: 2;
    transform: rotateY(0deg);
}

.back {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    transform: rotateY(180deg);
    background: #1e293b; /* Darker slate */
    border: 2px solid #475569; /* Match border */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px;
    z-index: 1;
}

/* Specific styles for back content */
.back h4 {
    margin: 0 0 5px 0;
    color: #ffd700;
    font-size: 0.9rem;
}

.back .stat-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.75rem;
    margin-bottom: 2px;
    color: #cbd5e1;
}

.back .stat-label {
    font-weight: bold;
    color: #94a3b8;
}

/* Ensure original cards lose their margin/layout props if needed,
   but they are now inside .flipper, so they should fill it. */

.hero-card, .tower-card {
    /* Ensure they fill the flipper if needed, but 'width: 100%' on .front handles it. */
    height: 100%; /* Make sure front fills height if back is taller? No, front dictates height. */
}
