:root {
    --bg-color: #2c3e50;
    --text-color: #ecf0f1;
    --card-width: 120px;
    --card-height: 168px; /* 1.4 aspect ratio */
    --card-radius: 10px;
    --accent-red: #e74c3c;
    --accent-black: #2c3e50;
    --highlight: #f1c40f;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

#app {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header & Stats */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid rgba(255,255,255,0.1);
    padding-bottom: 10px;
}

h1 { margin: 0; font-size: 1.5rem; }

.stats-bar {
    display: flex;
    gap: 20px;
    font-size: 1.2rem;
    font-weight: bold;
}

.hp-bar { color: var(--accent-red); }
.deck-count { color: var(--highlight); }

.theme-selector {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 0.9rem;
    cursor: pointer;
}

.theme-selector option {
    background: var(--bg-color);
}

/* Game Area */
.game-board {
    display: flex;
    flex-direction: column;
    gap: 40px;
    flex-grow: 1;
}

/* Weapon Slot */
.weapon-area {
    display: flex;
    align-items: center;
    gap: 20px;
    background: rgba(0,0,0,0.2);
    padding: 15px;
    border-radius: var(--card-radius);
}

.weapon-slot {
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed rgba(255,255,255,0.3);
    border-radius: var(--card-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: rgba(255,255,255,0.5);
    position: relative;
}

.weapon-info {
    flex-grow: 1;
}

/* Room (The 4 cards) */
.room-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: calc(var(--card-height) + 20px);
}

.room-cards {
    display: grid;
    grid-template-columns: repeat(4, var(--card-width));
    gap: 15px;
    justify-content: center;
}

/* Actions */
.actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.card-slot-empty {
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed rgba(255,255,255,0.1);
    border-radius: var(--card-radius);
}

/* History / Footer */
.history-area {
    margin-top: auto;
    border-top: 2px solid rgba(255,255,255,0.1);
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.defeated-container, .discard-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.defeated-pile, .discard-pile {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    max-height: 120px;
    overflow-y: auto;
    background: rgba(0,0,0,0.1);
    padding: 5px;
    border-radius: 5px;
}

.mini-card {
    width: 30px;
    height: 42px;
    background: white;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: black;
    border: 1px solid #ccc;
}

.mini-card.red { color: var(--accent-red); }
.mini-card.black { color: var(--accent-black); }


/* Card Styles */
.card {
    width: var(--card-width);
    height: var(--card-height);
    background-color: white;
    border-radius: var(--card-radius);
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.4);
}

.card.red { color: var(--accent-red); }
.card.black { color: var(--accent-black); }

.card-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--card-radius);
}

.card-corner {
    position: absolute;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.top-left { top: 5px; left: 5px; }
.bottom-right { bottom: 5px; right: 5px; transform: rotate(180deg); }

.card-center {
    font-size: 3.5rem;
}

/* Card Back Pattern */
.card-back {
    width: 100%;
    height: 100%;
    border-radius: var(--card-radius);
    background-color: #34495e;
    background-image: 
        repeating-linear-gradient(
            45deg,
            #2c3e50,
            #2c3e50 10px,
            #34495e 10px,
            #34495e 20px
        );
    border: 4px solid white;
    box-sizing: border-box;
}

/* Overlay for Monster Cards */
.card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.2s;
    border-radius: var(--card-radius);
    pointer-events: none; /* Let clicks pass through if hidden */
    z-index: 10;
}

.card:hover .card-overlay {
    opacity: 1;
    pointer-events: auto;
}

.overlay-btn {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    background: #ecf0f1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background-color 0.1s;
    padding: 0;
}

.overlay-btn:hover {
    transform: scale(1.1);
    background: white;
}

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

.overlay-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(1);
    transform: none;
}

/* Modal / Rules */
.rules-container {
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 5px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.rules-container a { color: var(--highlight); }

.game-over {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    text-align: center;
}

.game-over h2 { font-size: 3rem; margin-bottom: 20px; }
.game-over.win { color: var(--highlight); }
.game-over.lose { color: var(--accent-red); }

/* Utility */
.shake {
    animation: shake 0.5s;
}

@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); }
}