/* ============================================
   CHESS ROGUE — Premium UI v5
   ============================================ */

/* --- Tokens --- */
:root {
    --bg-0: #121212;
    --bg-1: #1a1a1a;
    --bg-2: #242424;
    --bg-3: #2e2e2e;
    --border: rgba(255, 255, 255, 0.08);
    --border-hi: rgba(255, 255, 255, 0.15);
    --text-1: #f3f4f6;
    --text-2: #9ca3af;
    --text-3: #6b7280;
    --gold: #fbbf24;
    --gold-dim: #b45309;
    --ruby: #f43f5e;
    --ruby-dim: #9f1239;
    --emerald: #10b981;
    --emerald-dim: #047857;
    --sapphire: #3b82f6;
    --sapphire-dim: #1d4ed8;
    --hero-fill: linear-gradient(135deg, #60a5fa, #3b82f6, #2563eb);
    --hero-glow: rgba(59, 130, 246, 0.5);
    --enemy-fill: linear-gradient(135deg, #fb7185, #f43f5e, #e11d48);
    --enemy-glow: rgba(244, 63, 94, 0.4);
    --boss-fill: linear-gradient(135deg, #c084fc, #9333ea, #7e22ce);
    --boss-glow: rgba(147, 51, 234, 0.6);
    --cell-a: #e9b5a3;
    --cell-b: #403353;
    --hl-bg: rgba(251, 191, 36, 0.4);
    --hl-border: rgba(251, 191, 36, 0.85);
    --atk-bg: rgba(244, 63, 94, 0.45);
    --atk-border: rgba(244, 63, 94, 0.85);
    --font: 'Inter', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --tr-fast: 120ms ease;
    --tr-med: 250ms ease;
    --tr-smooth: 350ms cubic-bezier(.16, 1, .3, 1);
}

/* --- Reset --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font);
    background: var(--bg-0);
    color: var(--text-1);
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    background-image:
        radial-gradient(ellipse at 50% -20%, rgba(59, 130, 246, 0.07), transparent 60%),
        radial-gradient(ellipse at 50% 120%, rgba(244, 63, 94, 0.05), transparent 60%);

    /* Prevenir comportamientos nativos móviles molestos */
    overscroll-behavior-y: none;
    /* Evita que recargue al arrastrar hacia abajo (pull-to-refresh) */
    touch-action: pan-x pan-y;
    /* Permite scroll pero evita zoom (pinch-to-zoom) */
    user-select: none;
    /* Evita seleccionar texto por error al mantener presionado */
    -webkit-user-select: none;
}

/* --- App --- */
#app {
    width: 100%;
    max-width: 520px;
    padding: 8px 8px 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: transform 0.1s ease;
    min-height: 100dvh;
    justify-content: center;
}

#app.shake-active {
    animation: screen-shake 0.3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes screen-shake {

    0%,
    100% {
        transform: translateX(0) translateY(0);
    }

    20%,
    60% {
        transform: translateX(-6px) rotate(-1deg);
    }

    40%,
    80% {
        transform: translateX(6px) rotate(1deg);
    }
}

/* --- Modern Dashboard --- */
#dashboard {
    width: 100%;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.dash-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dash-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tb-logo {
    font-size: 1.4rem;
    color: var(--gold);
    filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.5));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0)
    }

    50% {
        transform: translateY(-2px)
    }
}

.tb-title {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--text-1), var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dash-stats {
    display: flex;
    gap: 8px;
}

.stat-badge {
    background: var(--bg-2);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: var(--r-sm);
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-2);
    text-transform: uppercase;
}

.stat-badge span {
    font-family: var(--mono);
    color: var(--gold);
    font-size: 0.8rem;
    margin-left: 4px;
}

.dash-bottom {
    display: flex;
    gap: 10px;
    align-items: center;
}

#hp-box {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.hp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-2);
}

.hp-header span:last-child {
    font-family: var(--mono);
    color: var(--ruby);
    font-weight: 700;
}

.hp-track {
    width: 100%;
    height: 6px;
    background: rgba(244, 63, 94, 0.12);
    border-radius: 3px;
    overflow: hidden;
}

.hp-fill {
    height: 100%;
    width: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--ruby), #fb7185);
    transition: width 0.5s var(--tr-smooth);
}

.hp-fill.low {
    animation: hp-pulse 1.2s ease-in-out infinite;
}

@keyframes hp-pulse {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: 0.5
    }
}

#relics-container {
    display: flex;
    gap: 6px;
    padding: 4px;
    background: transparent;
    min-height: 34px;
    min-width: 42px;
    align-items: center;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
}

.relic-icon-small {
    font-size: 1.2rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-1);
    border: 2px solid var(--border-hi);
    transition: transform var(--tr-fast), box-shadow var(--tr-fast);
}

.relic-icon-small:hover {
    transform: translateY(-2px) scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

.relic-icon-small.cat-attack {
    border-color: var(--ruby);
}

.relic-icon-small.cat-movement {
    border-color: var(--sapphire);
}

.relic-icon-small.cat-health {
    border-color: var(--emerald);
}

.relic-icon-small.cat-special {
    border-color: var(--gold);
}

.relic-icon-small.cat-passive {
    border-color: #8b5cf6;
    /* violet */
}

.relic-icon-small.cat-legendary {
    border-color: #f97316;
    box-shadow: 0 0 10px rgba(249, 115, 22, 0.6);
    animation: pulse-leg 2s infinite;
}

@keyframes pulse-leg {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(249, 115, 22, 0.4)
    }

    50% {
        box-shadow: 0 0 15px rgba(249, 115, 22, 0.8)
    }
}

#deck-stats {
    display: flex;
    gap: 6px;
}

.deck-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: var(--bg-2);
    border: 2px solid var(--border);
    border-radius: 20px;
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-1);
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
}

.deck-pill.clickable {
    cursor: pointer;
    transition: all 0.2s;
}

.deck-pill.clickable:hover {
    transform: translateY(-2px);
    border-color: var(--gold);
    color: var(--gold);
}

/* --- Phase Banner --- */
#phase-banner {
    width: 100%;
    text-align: center;
    padding: 6px 12px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    position: relative;
    overflow: hidden;
}

#phase-text {
    font-size: 0.78rem;
    color: var(--text-2);
    font-weight: 500;
    transition: color var(--tr-med);
}

#phase-text.highlight {
    color: var(--gold);
    font-weight: 700;
}

/* --- Board --- */
#board-wrapper {
    width: 100%;
    aspect-ratio: 1;
    max-width: 480px;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid var(--cell-b);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    background-image: url('./assets/atlas.png');
    background-size: 400% 200%; /* 512/128=4, 256/128=2 */
    background-position: 4.166667% 6.25%; /* X:16px, Y:8px offsets */
    background-repeat: no-repeat;
    image-rendering: pixelated;
}

#game-board {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    background: transparent;
}

.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    transition: background var(--tr-fast), box-shadow var(--tr-fast);
    user-select: none;
    -webkit-user-select: none;
    border: none;
    background: transparent !important;
}

.cell .coord {
    display: none;
}

.cell.highlighted {
    background: var(--hl-bg) !important;
    box-shadow: inset 0 0 0 1px var(--hl-border);
    cursor: pointer;
}

.cell.highlighted:hover {
    background: rgba(251, 191, 36, 0.3) !important;
    box-shadow: inset 0 0 0 2px var(--gold);
}

.cell.attack-target {
    background: var(--atk-bg) !important;
    box-shadow: inset 0 0 0 1px var(--atk-border);
    cursor: pointer;
}

.cell.attack-target:hover {
    background: rgba(244, 63, 94, 0.3) !important;
}

/* --- Pieces Layer --- */
#pieces-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.piece {
    position: absolute;
    width: calc(100% / 8);
    height: calc(100% / 8);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.22s cubic-bezier(.22, 1, .36, 1), top 0.22s cubic-bezier(.22, 1, .36, 1);
    z-index: 2;
    pointer-events: none;
}

.piece-inner {
    width: 65%;
    height: 65%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 3.5vw, 1.6rem);
    position: relative;
}

/* Hero */
.piece.hero .piece-inner {
    background: var(--hero-fill);
    box-shadow: 0 0 15px var(--hero-glow);
    animation: hero-breathe 2.5s ease-in-out infinite;
}

.piece.hero.shielded .piece-inner {
    filter: drop-shadow(0 0 8px var(--sapphire)) brightness(1.2);
}

.piece.hero.shielded::after {
    content: '';
    position: absolute;
    inset: -4px;
    border: 2px solid var(--sapphire);
    border-radius: 50%;
    animation: shield-spin 3s linear infinite;
    pointer-events: none;
}

@keyframes shield-spin {
    0% {
        transform: rotate(0deg) scale(1)
    }

    50% {
        transform: rotate(180deg) scale(1.05)
    }

    100% {
        transform: rotate(360deg) scale(1)
    }
}

@keyframes hero-breathe {

    0%,
    100% {
        box-shadow: 0 0 15px var(--hero-glow)
    }

    50% {
        box-shadow: 0 0 25px var(--hero-glow)
    }
}

.hero-trail {
    position: absolute;
    width: calc(100% / 8);
    height: calc(100% / 8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    pointer-events: none;
}

.hero-trail .piece-inner {
    width: 65%;
    height: 65%;
    border-radius: 50%;
    background: var(--hero-fill);
    opacity: 0.3;
    animation: trail-fade 0.45s ease-out forwards;
}

@keyframes trail-fade {
    0% {
        opacity: 0.3;
        transform: scale(1)
    }

    100% {
        opacity: 0;
        transform: scale(0.5)
    }
}

/* Enemy */
.piece.enemy .piece-inner {
    background: var(--enemy-fill);
    box-shadow: 0 0 12px var(--enemy-glow);
    transition: filter var(--tr-med);
}

.piece.enemy.boss .piece-inner {
    background: var(--boss-fill);
    box-shadow: 0 0 20px var(--boss-glow);
    width: 85%;
    height: 85%;
    font-size: 1.8rem;
}

.enemy-hp-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-0);
    border: 1.5px solid var(--ruby);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 0.55rem;
    font-weight: 800;
    color: var(--ruby);
    z-index: 3;
}

/* --- Retro Sprites (Gameboy Atlas) --- */
.piece-sprite {
    width: 80%;
    height: 80%;
    background-image: url('./assets/atlas.png') !important;
    background-color: transparent !important;
    background-repeat: no-repeat !important;
    background-size: 3200% 1600% !important;
    image-rendering: pixelated;
    /* Fallback in case of text inside */
    color: transparent;
}

.piece-inner.sprite-mode {
    box-shadow: none !important;
    border-radius: 0;
}

.piece.hero .piece-inner.sprite-mode {
    filter: drop-shadow(0 0 10px var(--sapphire));
}
.piece.enemy .piece-inner.sprite-mode {
    filter: drop-shadow(0 0 8px var(--ruby));
}
.piece.enemy.boss .piece-inner.sprite-mode {
    filter: drop-shadow(0 0 15px #c084fc);
    width: 100%; height: 100%;
}

/* Dark Pieces (Y=208px -> 86.666%) */
.sprite-king-dark   { background-position: 3.226% 86.666% !important; }
.sprite-queen-dark  { background-position: 6.452% 86.666% !important; }
.sprite-rook-dark   { background-position: 9.677% 86.666% !important; }
.sprite-bishop-dark { background-position: 12.903% 86.666% !important; }
.sprite-knight-dark { background-position: 16.129% 86.666% !important; }
.sprite-pawn-dark   { background-position: 19.355% 86.666% !important; }

/* Light Pieces (Y=224px -> 93.333%) */
.sprite-king-light   { background-position: 3.226% 93.333% !important; }
.sprite-queen-light  { background-position: 6.452% 93.333% !important; }
.sprite-rook-light   { background-position: 9.677% 93.333% !important; }
.sprite-bishop-light { background-position: 12.903% 93.333% !important; }
.sprite-knight-light { background-position: 16.129% 93.333% !important; }
.sprite-pawn-light   { background-position: 19.355% 93.333% !important; }

.piece.enemy.boss .enemy-hp-badge {
    width: 22px;
    height: 22px;
    border-color: #c084fc;
    color: #c084fc;
    font-size: 0.65rem;
    top: -6px;
    right: -6px;
}

.enemy-order-badge {
    position: absolute;
    bottom: -4px;
    left: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-0);
    border: 1.5px solid var(--sapphire);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 0.55rem;
    font-weight: 800;
    color: var(--text-1);
    z-index: 4;
}

.piece.enemy.boss .enemy-order-badge {
    width: 22px;
    height: 22px;
    font-size: 0.65rem;
    bottom: -6px;
    left: -6px;
}

.enemy-cd-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-0);
    border: 1.5px solid var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 0.55rem;
    font-weight: 800;
    color: var(--gold);
    z-index: 4;
    box-shadow: 0 0 5px rgba(251, 191, 36, 0.3);
}

.piece.enemy.boss .enemy-cd-badge {
    width: 22px;
    height: 22px;
    font-size: 0.65rem;
    top: -6px;
    left: -6px;
}

/* Stunned */
.piece.enemy.stunned .piece-inner {
    filter: grayscale(1) opacity(0.6);
    box-shadow: none;
}

.piece.enemy.stunned::after {
    content: '💤';
    position: absolute;
    top: -10px;
    right: -5px;
    font-size: 0.8rem;
    animation: float-stun 2s infinite ease-in-out;
}

@keyframes float-stun {

    0%,
    100% {
        transform: translateY(0) scale(1);
        opacity: 0.8;
    }

    50% {
        transform: translateY(-4px) scale(1.1);
        opacity: 1;
    }
}

/* Status indicators (burned, vulnerable) */
.enemy-status {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    z-index: 5;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
    animation: float-stun 2s infinite ease-in-out;
    white-space: nowrap;
}

.piece.enemy.damaged .piece-inner {
    animation: shake 0.35s ease-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translate(0, 0)
    }

    25% {
        transform: translate(4px, -2px)
    }

    50% {
        transform: translate(-4px, 2px)
    }

    75% {
        transform: translate(2px, 1px)
    }
}

.piece.enemy.dying .piece-inner {
    animation: die-blink 0.4s ease-out forwards;
}

@keyframes die-blink {

    0%,
    30% {
        filter: brightness(10) saturate(0);
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: scale(0);
        filter: brightness(1);
    }
}

.piece.hero.damaged .piece-inner {
    animation: hero-flash 0.4s ease-out;
}

@keyframes hero-flash {

    0%,
    100% {
        filter: none
    }

    50% {
        filter: brightness(2.5)
    }
}

.damage-float {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--mono);
    font-size: 1rem;
    font-weight: 900;
    color: var(--text-1);
    z-index: 20;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 10px var(--ruby);
    animation: dmg-float 0.8s ease-out forwards;
}

.damage-float.heal {
    color: var(--emerald);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 10px var(--emerald);
}

@keyframes dmg-float {
    0% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1)
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-25px) scale(1.2)
    }
}

/* --- Hand --- */
#hand-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding-top: 15px;
}

#hand-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hh-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-3);
    font-weight: 700;
}

.hh-count {
    font-family: var(--mono);
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-2);
    background: var(--bg-2);
    padding: 2px 8px;
    border-radius: 12px;
}

#card-hand {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: nowrap;
    max-width: 100%;
}

/* --- Card (Premium Rounded) --- */
.card {
    width: 90px;
    height: 130px;
    min-width: 0;
    flex-shrink: 1;
    background: linear-gradient(160deg, #2a2a30, #1a1a20);
    border: 2px solid var(--border-hi);
    border-radius: var(--r-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.2s cubic-bezier(.22, 1, .36, 1), box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.06) 0%, transparent 50%);
    pointer-events: none;
}

.card:hover:not(.disabled) {
    transform: translateY(-6px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6);
    border-color: var(--text-3);
}

.card.selected {
    transform: translateY(-10px);
    border-color: var(--gold);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.25), 0 16px 32px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(251, 191, 36, 0.2);
}

.card.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(0.8);
}

.card .card-icon {
    font-size: 2.2rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    margin-bottom: 2px;
}

.card .card-name {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--text-1);
    letter-spacing: -0.02em;
}

.card .card-desc {
    font-size: 0.48rem;
    color: var(--text-3);
    text-align: center;
    padding: 0 6px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card .card-dmg {
    font-family: var(--mono);
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--ruby);
    margin-top: 2px;
}

.card[data-piece="rook"] .card-icon {
    color: #a78bfa;
}

.card[data-piece="bishop"] .card-icon {
    color: #34d399;
}

.card[data-piece="pawn"] .card-icon {
    color: #fbbf24;
}

.card[data-piece="knight"] .card-icon {
    color: #60a5fa;
}

/* --- Ability Button --- */
.ability-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sapphire-dim), var(--sapphire));
    border: 2px solid var(--border-hi);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: all var(--tr-fast);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.ability-btn:hover:not(.disabled) {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.5);
    border-color: var(--gold);
}

.ability-btn.ready {
    animation: ability-glow 2s infinite;
}

@keyframes ability-glow {

    0%,
    100% {
        box-shadow: 0 0 10px var(--gold)
    }

    50% {
        box-shadow: 0 0 20px var(--gold)
    }
}

.ability-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(1);
    transform: none;
    box-shadow: none;
    animation: none;
}

#ability-icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
}

#ability-cooldown {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--ruby);
}

#ability-cooldown.hidden {
    display: none;
}

/* --- End Turn --- */
#end-turn-btn {
    width: 100%;
    max-width: 240px;
    background: linear-gradient(135deg, var(--emerald-dim), var(--emerald));
    border: none;
    border-radius: var(--r-md);
    color: var(--text-1);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 800;
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--tr-fast);
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#end-turn-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
    filter: brightness(1.1);
}

#end-turn-btn.disabled {
    opacity: 0.25;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    filter: none;
    animation: none;
}

#end-turn-btn.glow-active:not(.disabled) {
    animation: btn-glow 1.5s ease-in-out infinite;
}

@keyframes btn-glow {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
        filter: brightness(1);
    }

    50% {
        box-shadow: 0 0 25px rgba(16, 185, 129, 1);
        filter: brightness(1.2);
    }
}

/* --- Reset --- */
#reset-btn {
    position: fixed;
    bottom: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-3);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--tr-fast);
    z-index: 10;
}

#reset-btn:hover {
    background: var(--bg-3);
    color: var(--text-1);
}

/* --- Log --- */
#combat-log {
    width: 100%;
    max-height: 80px;
    overflow-y: auto;
    padding: 6px 10px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    scrollbar-width: thin;
    scrollbar-color: var(--text-3) transparent;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

#combat-log.log-hidden {
    max-height: 0;
    padding: 0;
    border: none;
    overflow: hidden;
    opacity: 0;
}

#log-toggle-btn {
    position: fixed;
    bottom: 12px;
    right: 54px;
    width: 36px;
    height: 36px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-3);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--tr-fast);
    z-index: 10;
}

#log-toggle-btn:hover {
    background: var(--bg-3);
    color: var(--gold);
}

#log-toggle-btn.log-active {
    color: var(--gold);
    border-color: var(--gold);
}

#log-entries {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.log-entry {
    font-family: var(--mono);
    font-size: 0.55rem;
    color: var(--text-3);
    animation: log-in 0.25s ease-out;
}

.log-entry.attack {
    color: var(--ruby);
}

.log-entry.move {
    color: var(--emerald);
}

.log-entry.info {
    color: var(--sapphire);
}

.log-entry.gold {
    color: var(--gold);
}

@keyframes log-in {
    from {
        opacity: 0;
        transform: translateX(-6px)
    }

    to {
        opacity: 1;
        transform: none
    }
}

/* --- Overlay Modals (Glassmorphism) --- */
#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    animation: overlay-in 0.3s ease-out;
}

.modal-content {
    background: linear-gradient(160deg, #1e1e24, #161618);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--r-lg);
    padding: 30px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: modal-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-hidden {
    display: none !important;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    animation: overlay-in 0.3s ease-out;
}

@keyframes overlay-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.relic-list-item {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.relic-list-item:last-child {
    border-bottom: none;
}

.relic-list-item .relic-icon-small {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.5rem;
}

.relic-list-item h4 {
    margin: 0 0 5px 0;
    color: var(--text-1);
    font-size: 1.1rem;
}

.relic-list-item p {
    margin: 0;
    color: var(--text-2);
    font-size: 0.9rem;
    line-height: 1.4;
}

@keyframes modal-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95)
    }

    to {
        opacity: 1;
        transform: none
    }
}

.modal-content h2 {
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-1), var(--text-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-content.victory h2 {
    background: linear-gradient(135deg, var(--gold), var(--emerald));
    -webkit-background-clip: text;
}

.modal-content p {
    color: var(--text-2);
    font-size: 0.9rem;
    line-height: 1.5;
}

.modal-btn {
    background: linear-gradient(135deg, var(--gold-dim), var(--gold));
    border: none;
    border-radius: var(--r-md);
    color: #000;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 800;
    padding: 12px 32px;
    cursor: pointer;
    transition: transform var(--tr-fast), box-shadow var(--tr-fast), filter var(--tr-fast);
    align-self: center;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(251, 191, 36, 0.35);
    filter: brightness(1.1);
}

/* Draft / Relic Container */
.draft-container {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 10px;
}

.relic-card {
    width: 120px;
    padding: 16px 12px;
    background: linear-gradient(160deg, #252530, #18181e);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--r-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(.22, 1, .36, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.relic-card:hover {
    transform: translateY(-6px) scale(1.02);
    border-color: var(--gold);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(251, 191, 36, 0.15);
}

.relic-icon {
    font-size: 2.4rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    margin-bottom: 4px;
}

.relic-name {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-1);
    line-height: 1.1;
}

.relic-desc {
    font-size: 0.55rem;
    color: var(--text-3);
    text-align: center;
    line-height: 1.3;
}

/* Responsive - Teléfono */
@media(max-width:420px) {
    #app {
        padding: 6px 4px 44px;
        gap: 4px;
    }

    #hand-area {
        padding-top: 8px;
    }

    #card-hand {
        gap: 4px;
        justify-content: center;
        padding-bottom: 5px;
    }

    .card {
        width: 55px;
        height: 80px;
        min-width: 55px;
        gap: 2px;
        flex-shrink: 0;
    }

    .card .card-icon {
        font-size: 1.4rem;
    }

    .card .card-name {
        font-size: 0.5rem;
    }

    /* 1. Solo ocultamos la descripción si la carta está en la MANO */
    #card-hand .card .card-desc {
        display: none;
    }

    /* 2. Las cartas del DRAFT siempre muestran su descripción */
    .draft-container .card .card-desc {
        display: -webkit-box !important;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        overflow: hidden;
        font-size: 0.62rem;
        line-height: 1.25;
        margin-top: 4px;
        color: var(--text-2);
        padding: 0 4px;
    }

    /* 3. Cartas del Draft: tamaño correcto para mostrar texto */
    .draft-container .card {
        width: 90px;
        height: auto;
        min-height: 125px;
        padding: 8px 5px;
        flex-shrink: 0;
    }

    /* 4. Draft container scrollable en móvil */
    .draft-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .card .card-dmg {
        font-size: 0.5rem;
        margin-top: 0;
    }

    .cell .coord {
        display: none;
    }

    .modal-content {
        padding: 15px;
    }

    .start-title {
        font-size: 2rem;
    }

    .start-subtitle {
        font-size: 1rem;
    }

    .start-instructions {
        font-size: 0.85rem;
        padding: 15px;
    }

    #deck-stats {
        flex-wrap: wrap;
        justify-content: center;
    }

    .deck-pill {
        padding: 4px 8px;
        min-height: 36px;
        min-width: 36px;
        font-size: 0.75rem;
        border-width: 1px;
    }

    #dashboard {
        padding: 8px;
        gap: 6px;
    }

    .stat-badge {
        padding: 2px 5px;
        font-size: 0.55rem;
    }

    .stat-badge span {
        font-size: 0.7rem;
    }

    #phase-banner {
        padding: 4px 8px;
    }

    #phase-text {
        font-size: 0.7rem;
    }
}

/* --- Start Screen --- */
#start-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-0);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image:
        radial-gradient(circle at 50% 40%, rgba(251, 191, 36, 0.06), transparent 50%),
        radial-gradient(circle at 50% 80%, rgba(59, 130, 246, 0.08), transparent 60%);
}

.start-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    animation: modal-up 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.start-title {
    font-size: 3.2rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--gold), #f59e0b, #fbbf24);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 20px rgba(251, 191, 36, 0.4));
    letter-spacing: -0.02em;
}

.start-subtitle {
    font-size: 1.2rem;
    color: var(--text-2);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 0.95rem;
}

.start-instructions {
    text-align: left;
    background: linear-gradient(160deg, #1e1e24, #161618);
    padding: 20px;
    border-radius: var(--r-md);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-2);
    font-size: 0.9rem;
    line-height: 1.7;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

#start-screen.hidden {
    display: none;
}

/* --- Walls & Danger Zones --- */
.wall {
    position: absolute;
    width: calc(100% / 8);
    height: calc(100% / 8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    pointer-events: none;
}

.wall-inner {
    width: 85%;
    height: 85%;
    background: var(--bg-2);
    border: 2px solid var(--text-3);
    border-radius: 4px;
    background-image: repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(255, 255, 255, 0.05) 4px, rgba(255, 255, 255, 0.05) 8px);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8), 0 4px 10px rgba(0, 0, 0, 0.5);
}

/* Hazard Tiles */
.hazard {
    position: absolute;
    width: calc(100% / 8);
    height: calc(100% / 8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 0;
    pointer-events: none;
    font-size: 1.4rem;
    border-radius: 4px;
}

.hazard.lava {
    background: radial-gradient(circle, rgba(220, 38, 38, 0.35) 0%, rgba(220, 38, 38, 0.1) 70%);
    animation: lava-pulse 2s ease-in-out infinite;
}

.hazard.ice {
    background: radial-gradient(circle, rgba(56, 189, 248, 0.3) 0%, rgba(56, 189, 248, 0.08) 70%);
    animation: ice-shimmer 3s ease-in-out infinite;
}

.hazard.fountain {
    background: radial-gradient(circle, rgba(74, 222, 128, 0.3) 0%, rgba(74, 222, 128, 0.08) 70%);
    animation: fountain-glow 2.5s ease-in-out infinite;
}

@keyframes lava-pulse {

    0%,
    100% {
        box-shadow: inset 0 0 12px rgba(239, 68, 68, 0.4);
    }

    50% {
        box-shadow: inset 0 0 20px rgba(239, 68, 68, 0.7);
    }
}

@keyframes ice-shimmer {

    0%,
    100% {
        box-shadow: inset 0 0 10px rgba(56, 189, 248, 0.3);
    }

    50% {
        box-shadow: inset 0 0 18px rgba(56, 189, 248, 0.6);
    }
}

@keyframes fountain-glow {

    0%,
    100% {
        box-shadow: inset 0 0 10px rgba(74, 222, 128, 0.3);
    }

    50% {
        box-shadow: inset 0 0 16px rgba(74, 222, 128, 0.5);
    }
}

.danger-zone {
    box-shadow: inset 0 0 15px rgba(244, 63, 94, 0.4);
    background: rgba(244, 63, 94, 0.1) !important;
}

.danger-flash {
    box-shadow: inset 0 0 25px rgba(244, 63, 94, 0.8);
    background: rgba(244, 63, 94, 0.4) !important;
    animation: flash-pulse 0.3s ease-in-out infinite alternate;
}

/* Estado Congelado */
.piece.frozen {
    filter: hue-rotate(160deg) brightness(1.3) drop-shadow(0 0 10px #60a5fa) !important;
    transition: filter 0.5s ease;
}

.piece.frozen::after {
    content: '❄️';
    position: absolute;
    top: -12px;
    right: -12px;
    font-size: 1.3rem;
    z-index: 5;
    animation: bounce 2s infinite;
}


@keyframes flash-pulse {
    from {
        opacity: 0.7;
    }

    to {
        opacity: 1;
    }
}

/* --- Ranged Attack Animation --- */
.projectile {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--enemy-fill);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--ruby);
    z-index: 10;
    pointer-events: none;
    transition: left 0.3s linear, top 0.3s linear;
}

/* Varied Enemies */
.piece.enemy[data-type="rook"] .piece-inner {
    border-radius: 4px;
}

.piece.enemy[data-type="bishop"] .piece-inner {
    border-radius: 50% 50% 0 0;
}

/* --- Tooltip --- */
#enemy-tooltip {
    position: fixed;
    z-index: 300;
    pointer-events: none;
    background: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-hi);
    border-radius: var(--r-sm);
    padding: 8px 12px;
    width: 200px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8);
    transform: translate(-50%, -110%);
    transition: opacity 0.15s ease-out;
}

#enemy-tooltip.hidden {
    opacity: 0;
}

#tt-title {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--ruby);
    margin-bottom: 4px;
}

#tt-desc {
    font-size: 0.65rem;
    color: var(--text-2);
    line-height: 1.4;
}

/* Telegraph Line */
.telegraph {
    position: absolute;
    z-index: 5;
    pointer-events: none;
    background: rgba(244, 63, 94, 0.4);
    box-shadow: 0 0 10px rgba(244, 63, 94, 0.6);
    transform-origin: 0% 50%;
    animation: flash-line 0.3s ease-out forwards;
}

@keyframes flash-line {
    0% {
        opacity: 1;
        width: 0;
    }

    100% {
        opacity: 0;
        width: var(--line-dist);
    }
}

/* --- Layout PC Horizontal --- */
@media(min-width: 800px) {
    #app {
        max-width: 1100px;
        width: 100%;
        display: grid;
        grid-template-columns: minmax(400px, 550px) minmax(300px, 450px);
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "board dashboard"
            "board phase"
            "board hand"
            "board log";
        align-content: center;
        justify-content: center;
        gap: 15px 50px;
        padding: 40px 20px;
        min-height: 100dvh;
    }

    #board-wrapper {
        grid-area: board;
        max-width: none;
        width: 100%;
        align-self: center;
    }

    #dashboard,
    #phase-banner,
    #hand-area,
    #combat-log {
        width: 100%;
    }

    #dashboard {
        grid-area: dashboard;
    }

    #phase-banner {
        grid-area: phase;
    }

    #hand-area {
        grid-area: hand;
        padding-top: 5px;
    }

    #combat-log {
        grid-area: log;
        max-height: 250px;
    }
}

/* --- Enciclopedia --- */
.enc-tab-btn {
    background: var(--bg-1);
    color: var(--text-2);
    border: 1px solid var(--border);
    transition: all 0.2s;
}
.enc-tab-btn.active {
    background: var(--bg-3);
    color: var(--gold);
    border-color: var(--gold);
}

.enc-card {
    display: flex;
    gap: 12px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 12px;
    align-items: flex-start;
}
.enc-card.bad {
    border-left: 3px solid var(--ruby);
}
.enc-card.good {
    border-left: 3px solid var(--emerald);
}
.enc-icon {
    font-size: 1.8rem;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    background: var(--bg-2);
    border-radius: 4px;
    border: 1px solid var(--border-hi);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
}
.enc-info h3 {
    margin: 0 0 4px 0;
    font-size: 1rem;
    color: var(--gold);
}
.enc-info p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-2);
    line-height: 1.3;
}
.enc-tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-3);
    font-size: 0.65rem;
    text-transform: uppercase;
    font-family: var(--mono);
    margin-right: 6px;
    margin-bottom: 4px;
}