/* ===== Reset & Base ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: sans-serif;
    background: #1a1a2e;
    color: #eee;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Left Panel: Preview + Log ===== */
#left-panel {
    width: 280px;
    background: #16213e;
    padding: 10px;
    display: flex;
    flex-direction: column;
    border-right: 2px solid #0f3460;
}

#preview-area {
    background: #0f3460;
    border-radius: 8px;
    padding: 10px;
    min-height: 320px;
    margin-bottom: 10px;
}

#preview-area h4 {
    margin-bottom: 5px;
    color: #e94560;
}

#preview-card-name {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 5px;
}

#preview-card-stats {
    font-size: 14px;
    margin-bottom: 5px;
}

#preview-card-text {
    font-size: 12px;
    color: #aaa;
    white-space: pre-wrap;
}

#log-area {
    flex: 1;
    background: #0f3460;
    border-radius: 8px;
    padding: 10px;
    overflow-y: auto;
    font-size: 11px;
    min-height: 0;
    /* Important for flex scrolling */
}

#log-area h4 {
    margin-bottom: 5px;
    color: #e94560;
}

.log-entry {
    border-bottom: 1px solid #1a1a2e;
    padding: 3px 0;
}

/* ===== Main Game Area ===== */
#main-area {
    flex: 1;
    padding: 10px;
    display: flex;
    flex-direction: column;
}

#status {
    padding: 5px;
    background: #0f3460;
    border-radius: 4px;
    margin-bottom: 10px;
}

#controls button {
    margin-right: 5px;
    padding: 8px 12px;
    cursor: pointer;
}

#game-area {
    display: none;
    flex-direction: row;
    flex: 1;
    gap: 10px;
}

#game-board {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ===== Right Panel ===== */
#right-panel {
    width: 180px;
    background: #16213e;
    border-radius: 4px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
}

.stat-box {
    margin-bottom: 5px;
}

.stat-label {
    font-size: 11px;
    color: #888;
}

#opp-stats-panel,
#my-stats-panel {
    font-size: 12px;
    color: #fff;
}

#game-controls {
    position: absolute;
    left: -120px;
    bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 110px;
}

#end-turn-btn {
    padding: 15px 10px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    background: #27ae60;
    color: #fff;
    border: 2px solid #2ecc71;
    border-radius: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

#end-turn-btn:hover {
    background: #2ecc71;
    box-shadow: 0 0 10px #27ae60;
}

#chain-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
}

#cancel-chain-btn {
    padding: 12px 24px;
    font-size: 14px;
    font-weight: bold;
    background: #e74c3c;
    color: #fff;
    border: 2px solid #c0392b;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

#cancel-chain-btn:hover {
    background: #c0392b;
    border-color: #e74c3c;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.6);
    transform: scale(1.05);
}

/* ===== Stats Panel ===== */
.stats-panel-new {
    display: flex;
    flex-direction: column;
    /* Column to stack BarsRow, DeckText, Timer */
    gap: 0.3vh;
    align-items: center;
    /* Center horizontally */
    height: 44vh;
    /* Increased height since buttons moved outside */
}

.stats-bars-row {
    display: flex;
    flex-direction: row;
    gap: 2vh;
    height: calc(100% - 4vh);
    /* Leave room for deck text and timer */
    align-items: flex-end;
    flex-shrink: 1;
}

/* HP Bar (Vertical) */
.hp-bar-container {
    width: 6vh;
    /* Relative width */
    height: 90%;
    /* Occupy most of the height, leave room for deck text if needed, or flex handles it */
    background: #444;
    border-radius: 1vh;
    position: relative;
    overflow: hidden;
    border: 0.4vh solid #777;
}

.stat-bar-fill {
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    transition: height 0.3s ease;
}

.hp-fill {
    background: linear-gradient(0deg, #c0392b, #e74c3c);
}

.stat-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Removed rotation */
    color: #fff;
    font-size: 3vh;
    /* Large readable font */
    font-weight: bold;
    text-shadow: 0.2vh 0.2vh 0.4vh #000;
    pointer-events: none;
    white-space: nowrap;
    z-index: 2;
}

/* Mana Container (Stacked) */
.mana-container {
    display: flex;
    flex-direction: column-reverse;
    flex-wrap: wrap-reverse;
    gap: 0.2vh;
    /* Reduced gap */
    height: 90%;
    align-items: center;
    justify-content: flex-start;
    width: 6vh;
}

.mana-crystal {
    width: 2.4vh;
    /* Reduced size */
    height: 2.4vh;
    background: #2c3e50;
    border: 0.3vh solid #7f8c8d;
    transform: rotate(45deg);
    margin: 0.5vh calc(0.5vh - 0.25vh);
    /* Tighter margins */
    flex-shrink: 0;
    transition: all 0.3s;
    box-shadow: inset 0 0 0.5vh #000;
}

.mana-crystal.active {
    background: #3498db;
    border-color: #5dade2;
    box-shadow: 0 0 1vh #3498db, inset 0 0 0.5vh #ecf0f1;
}

.mana-crystal.active.carryover {
    background: #1abc9c;
    /* Blue-green (Turquoise) */
    border-color: #16a085;
    box-shadow: 0 0 1vh #1abc9c, inset 0 0 0.5vh #e8f8f5;
}

.mana-crystal.empty {
    background: #16213e;
    border-color: #555;
    opacity: 1;
    /* Fully opaque as requested */
}

.mana-crystal.empty.extra-capacity {
    opacity: 0.4;
    /* Increased visibility */
    border-color: #444;
}

.deck-text {
    font-size: 1.5vh;
    color: #ccc;
    font-weight: bold;
    margin-top: 0.5vh;
}

/* ===== Timer Display ===== */
.timer-display {
    font-size: 2.5vh;
    font-weight: bold;
    color: #f39c12;
    text-align: center;
    margin-top: 0.5vh;
    padding: 0.5vh 1vh;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.5vh;
    border: 0.2vh solid #f39c12;
    transition: all 0.3s ease;
}

.timer-display.active {
    color: #27ae60;
    border-color: #27ae60;
    box-shadow: 0 0 1vh #27ae60;
}

.timer-display.warning {
    color: #e74c3c;
    border-color: #e74c3c;
    animation: timer-pulse 0.5s infinite;
}

@keyframes timer-pulse {

    0%,
    100% {
        box-shadow: 0 0 0.5vh #e74c3c;
    }

    50% {
        box-shadow: 0 0 1.5vh #e74c3c;
    }
}

/* ===== Player Sections ===== */
.player-section {
    margin-bottom: 10px;
}

.player-section h3 {
    font-size: 14px;
    margin-bottom: 5px;
    color: #e94560;
}

/* ===== Zone Styles ===== */
.zone {
    display: flex;
    justify-content: center;
    /* Center items */
    gap: 5px;
    min-height: calc(14vh);
    padding: 5px;
    border-radius: 4px;
    margin-bottom: 3px;
    align-items: flex-start;
}

.hand {
    background: rgba(100, 150, 255, 0.2);
}

.board {
    background: rgba(100, 255, 100, 0.2);
}

.spell {
    background: rgba(255, 100, 255, 0.2);
}

.enemy {
    opacity: 1;
}

/* ===== Card Styles ===== */
.card {
    width: calc(13vh);
    height: calc(13vh);
    background: #333;
    border: 2px solid #555;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    font-size: calc(1vh + 2px);
    text-align: center;
    cursor: pointer;
    transition: transform 0.1s;
    position: relative;
    flex-shrink: 0;
}

.card-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    border-radius: 2px;
}

.card-overlay {
    position: relative;
    z-index: 1;
    background: rgba(0, 0, 0, 0.7);
    width: 100%;
    padding: 2px;
}

.card:hover {
    transform: scale(1.05);
    border-color: #e94560;
}

.card.selected-attacker {
    border: 3px solid #f39c12;
    box-shadow: 0 0 15px #f39c12, 0 0 25px rgba(243, 156, 18, 0.5);
    animation: attacker-pulse 0.8s infinite;
}

@keyframes attacker-pulse {

    0%,
    100% {
        box-shadow: 0 0 15px #f39c12, 0 0 25px rgba(243, 156, 18, 0.5);
    }

    50% {
        box-shadow: 0 0 20px #e67e22, 0 0 35px rgba(230, 126, 34, 0.7);
    }
}

.card.selected-hand {
    border: 3px solid #3498db;
    box-shadow: 0 0 15px #3498db;
    transform: translateY(-10px);
}

.card.facedown {
    background: #222;
    border-color: #444;
}

.card .card-name {
    font-weight: bold;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    padding: 0 2px;
}

.card .card-stats {
    font-size: 10px;
}

.card .card-cost {
    position: absolute;
    top: 2px;
    left: 2px;
    background: #e94560;
    color: #fff;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-actions {
    display: none;
    position: absolute;
    bottom: 20%;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.85);
    padding: 4px;
    z-index: 10;
}

.card:hover .card-actions {
    display: flex;
    justify-content: center;
    gap: 2px;
}

.card-actions button {
    font-size: 9px;
    padding: 2px 5px;
    cursor: pointer;
    flex-shrink: 0;
}

.card-empty {
    visibility: hidden;
}

/* ===== Battle States ===== */
.turn-indicator {
    color: #0f0;
    font-weight: bold;
}

.selected-attacker {
    border-color: #ff0 !important;
    box-shadow: 0 0 10px #ff0;
}

/* ===== Target Selection Mode ===== */
/* ===== Target Selection Mode ===== */
.target-mode .card.valid-target {
    cursor: crosshair;
    animation: pulse 1s infinite;
    box-shadow: 0 0 5px #e94560;
    /* Initial shadow */
    border-color: #e94560;
    /* Emphasize border */
}

.target-mode .card:not(.valid-target):not(.card-empty) {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.5);
    /* Desaturate invalid targets */
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 5px #e94560;
    }

    50% {
        box-shadow: 0 0 15px #e94560;
    }
}

#target-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 100;
    pointer-events: none;
}

#target-overlay.active {
    display: block;
}

#target-prompt {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: #16213e;
    padding: 15px 30px;
    border-radius: 8px;
    text-align: center;
    z-index: 101;
    pointer-events: auto;
    border: 2px solid #e94560;
}

/* ===== Waiting Overlay ===== */
#waiting-overlay {
    display: none;
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: #16213e;
    padding: 15px 30px;
    border-radius: 8px;
    text-align: center;
    z-index: 100;
    border: 2px solid #f39c12;
    color: #f39c12;
}

#waiting-overlay.active {
    display: block;
}

/* ===== Custom Alert/Confirm Overlay ===== */
#custom-alert-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

#custom-alert-overlay.active {
    display: flex;
}

#custom-alert-box {
    background: #16213e;
    border: 2px solid #e94560;
    border-radius: 8px;
    padding: 20px;
    width: 300px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#custom-alert-message {
    font-size: 16px;
    color: #eee;
    white-space: pre-wrap;
}

#custom-alert-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.alert-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    color: #fff;
    transition: background 0.2s;
}

.alert-btn-primary {
    background: #e94560;
}

.alert-btn-primary:hover {
    background: #ff6b81;
}

.alert-btn-secondary {
    background: #0f3460;
}

.alert-btn-secondary:hover {
    background: #1a1a2e;
}

/* Preview Cost Badges */
.preview-cost-container {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-bottom: 5px;
    font-size: 13px;
    color: #ddd;
}

.preview-cost-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.preview-cost-circle {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 13px;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.cost-summon {
    background: #e94560;
    /* Matches card summon cost */
}

.cost-spell {
    background: #3498db;
    /* Matches spell cost */
}

.activated-ghost {
    opacity: 0.3 !important;
    filter: grayscale(100%);
    pointer-events: none;
    border: 1px dashed #3498db;
}