/* === Board Layout === */

/* Opponent Area */
#opponent-area {
    display: flex;
    flex-direction: column;
}

#opponent-hand {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 8px 20px;
    min-height: 60px;
}

/* Too many card backs for the width: scroll sideways (auto margins keep a short hand centered) */
#opponent-hand { justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
#opponent-hand::-webkit-scrollbar { display: none; }
#opponent-hand > :first-child { margin-left: auto; }
#opponent-hand > :last-child { margin-right: auto; }
#opponent-hand > * { flex-shrink: 0; }

#opponent-hand .card-back {
    width: 60px;
    height: 80px;
    border-radius: 4px;
}

#opponent-hand .card-back .card-back-symbol {
    font-size: 1rem;
}

/* Battlefield */
#battlefield {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
    padding: 10px 40px;
    position: relative; /* anchors the game log and action bar */
}

/* Keep the board rows clear of the game log (left, 210px) and the side panel (right, 190px),
   so a full board wraps instead of running under them */
@media (min-width: 900px) {
    #battlefield { padding-left: 245px; padding-right: 225px; }
}

.board-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 10px 15px;
    min-height: calc(var(--board-card-h) + 22px);
    align-items: center;
    border: 1px solid rgba(42, 42, 62, 0.2);
    background: rgba(18, 18, 26, 0.4);
    flex-wrap: nowrap;      /* one line: a full board shrinks, then overlaps (UI.fitBoards); no scrolling, attacks lunge out of the row */
    align-content: center;
}
/* Overlapped cards: the one you point at comes to the front */
.board-row.crowded .card:hover { z-index: 5; }

#opponent-board {
    border-radius: 8px 8px 0 0;
    border-bottom: none;
}

#player-board {
    border-radius: 0 0 8px 8px;
    border-top: none;
}

.board-row:empty::after {
    content: '';
    display: block;
}

/* Player Area */
#player-area {
    display: flex;
    flex-direction: column;
}

.essence-pool {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 6px 20px;
    background: rgba(18, 18, 26, 0.6);
    border-top: 1px solid var(--border-subtle);
    min-height: 36px;
    align-items: center;
    flex-wrap: wrap;
}

.essence-gem {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    border: 2px solid;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Spent this turn */
.essence-gem.tapped {
    opacity: 0.25;
    transform: scale(0.8);
    filter: grayscale(1);
}

/* The opponent's essence sits inline in their stats bar */
.essence-pool.compact {
    flex: 1;
    min-height: 0;
    padding: 0 20px;
    background: none;
    border: none;
}

.essence-pool.compact .essence-gem {
    width: 20px;
    height: 20px;
    font-size: 0.6rem;
}

.essence-pool.compact .essence-group-label {
    font-size: 0.7rem;
}

/* One box per domain: "Body 2/3" followed by its gems */
.essence-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px 3px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.3);
}

.essence-group-label {
    font-size: 0.75rem;
    font-weight: 700;
    margin-right: 4px;
    color: var(--text-secondary);
}

.essence-group.domain-body { border-color: color-mix(in srgb, var(--body-color) 60%, transparent); }
.essence-group.domain-will { border-color: color-mix(in srgb, var(--will-color) 60%, transparent); }
.essence-group.domain-shadow { border-color: #374151; }
.essence-group.domain-void { border-color: color-mix(in srgb, var(--void-color) 60%, transparent); }
.essence-group.domain-blood { border-color: color-mix(in srgb, var(--blood-color) 60%, transparent); }

.essence-gem.domain-void {
    border-color: var(--void-color);
    color: var(--void-glow);
    background: rgba(107, 33, 168, 0.2);
}

.essence-gem.domain-blood {
    border-color: var(--blood-color);
    color: var(--blood-glow);
    background: rgba(127, 29, 29, 0.2);
}

.essence-gem.domain-shadow {
    border-color: var(--shadow-color);
    color: var(--shadow-glow);
    background: rgba(31, 41, 55, 0.2);
}

.essence-gem.domain-body {
    border-color: var(--body-color);
    color: var(--body-glow);
    background: rgba(180, 83, 9, 0.2);
}

.essence-gem.domain-will {
    border-color: var(--will-color);
    color: var(--will-glow);
    background: rgba(109, 40, 217, 0.2);
}

/* Player Hand */
#player-hand {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px 15px;
    min-height: calc(var(--hand-card-h) + 25px);
    align-items: flex-end;
    background: linear-gradient(0deg, rgba(10, 10, 15, 0.8) 0%, transparent 100%);
}

/* A hand too big to overlap further scrolls sideways (UI.fitHand); swipe on touch screens.
   Extra top padding (cancelled by the negative margin) leaves room for lifted cards. */
#player-hand > .card { flex-shrink: 0; }
#player-hand > :first-child { margin-left: auto; }
#player-hand > :last-child { margin-right: auto; }
#player-hand.scrolls {
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    padding-top: 34px;
    margin-top: -24px;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 58, 237, 0.6) transparent;
}
#player-hand.scrolls > .card { scroll-snap-align: start; }
#player-hand.scrolls::-webkit-scrollbar { height: 6px; }
#player-hand.scrolls::-webkit-scrollbar-thumb { background: rgba(124, 58, 237, 0.6); border-radius: 3px; }

/* === Targeting === */

/* The card waiting for a target stays lifted in your hand */
#player-hand .card.targeting-source {
    transform: translateY(-20px);
}

#player-hand .card.targeting-source .card-inner {
    border-color: var(--essence-color);
    box-shadow: 0 0 1.2em rgba(245, 158, 11, 0.7);
}

/* Legal targets pulse red */
.card.target-valid {
    cursor: crosshair;
}

.card.target-valid .card-inner {
    border-color: #f87171;
}

/* Pulsing glows fade a fixed shadow (opacity only), so they don't repaint every frame */
.card.target-valid::after,
.card.block-target::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 0.4em;
    pointer-events: none;
    box-shadow: 0 0 1.4em rgba(248, 113, 113, 0.9), inset 0 0 0 2px rgba(248, 113, 113, 0.9);
    animation: glow-breathe 1s ease-in-out infinite;
}

.card.block-target::after {
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.6);
    animation-duration: 1.2s;
}

#opponent-info.target-valid {
    cursor: crosshair;
    position: relative;
}

#opponent-info.target-valid::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    box-shadow: 0 0 1.4em rgba(248, 113, 113, 0.9), inset 0 0 0 2px rgba(248, 113, 113, 0.9);
    animation: glow-breathe 1s ease-in-out infinite;
}

/* Dropzone highlights during card play */
.board-row.drop-target {
    background: rgba(124, 58, 237, 0.1);
    border-color: var(--accent);
    border-style: dashed;
}

/* === Combat states === */

/* Your entity is ready to attack */
.card.can-attack .card-inner {
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.35);
}

/* Declared / selected as an attacker */
.board-row .card.attacking,
.board-row .card.attacking:hover {
    transform: translateY(-14px);
}

#opponent-board .card.attacking,
#opponent-board .card.attacking:hover {
    transform: translateY(14px);
}

.card.attacking .card-inner {
    border-color: var(--health-color);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
}

/* Block phase: your entities that can block */
.card.can-block .card-inner {
    box-shadow: 0 0 10px rgba(96, 165, 250, 0.35);
}

.card.selected-blocker .card-inner {
    border-color: var(--essence-color);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.7);
}

.card.blocking .card-inner {
    border-color: #60a5fa;
    box-shadow: 0 0 18px rgba(96, 165, 250, 0.6);
}

/* An attacker the selected blocker can legally block */
.card.block-target {
    cursor: crosshair;
}


.block-badge {
    position: absolute;
    left: 50%;
    bottom: -10px;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    background: #1e3a5f;
    border: 1px solid #60a5fa;
    color: #dbeafe;
    z-index: 2;
}

/* Break the Ward: enemy relics you can target pulse like target entities */
.relic-medallion.target-valid { cursor: crosshair; position: relative; }
.relic-medallion.target-valid::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 12px;
    pointer-events: none;
    box-shadow: 0 0 1.4em rgba(248, 113, 113, 0.9), inset 0 0 0 2px rgba(248, 113, 113, 0.9);
    animation: glow-breathe 1s ease-in-out infinite;
}
