/* === Card Styles ===
 * Cards scale with the window. Each card sets --card-w, and its font-size is a
 * fraction of that width; everything inside is sized in em, so text and art
 * scale with the card.
 */

.card {
    --card-w: var(--hand-card-w);
    --domain-color: var(--border-subtle);
    --domain-glow: var(--accent-glow);
    --art-bg: var(--bg-dark);
    width: var(--card-w);
    height: calc(var(--card-w) * 1.42);
    font-size: calc(var(--card-w) * 0.1);
    border-radius: 0.4em;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s ease;
    flex-shrink: 0;
    user-select: none;
}

.card:hover {
    transform: translateY(-8px);
    z-index: 5;
}

/* Per-domain colors */
.card.domain-void {
    --domain-color: var(--void-color);
    --domain-glow: var(--void-glow);
    --art-bg: linear-gradient(180deg, #1a0a2e 0%, #0d0520 100%);
}
.card.domain-blood {
    --domain-color: var(--blood-color);
    --domain-glow: var(--blood-glow);
    --art-bg: linear-gradient(180deg, #2d0a0a 0%, #1a0000 100%);
}
.card.domain-shadow {
    --domain-color: #374151;
    --domain-glow: #9ca3af;
    --art-bg: linear-gradient(180deg, #1a1a1a 0%, #0d0d0d 100%);
}
.card.domain-body {
    --domain-color: var(--body-color);
    --domain-glow: var(--body-glow);
    --art-bg: linear-gradient(180deg, #2e1a0a 0%, #1a0f05 100%);
}
.card.domain-will {
    --domain-color: var(--will-color);
    --domain-glow: var(--will-glow);
    --art-bg: linear-gradient(180deg, #1a0a2e 0%, #0f051a 100%);
}

.card-inner {
    width: 100%;
    height: 100%;
    border-radius: 0.4em;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 0.15em solid var(--domain-color);
    background: var(--bg-dark);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card:hover .card-inner {
    box-shadow: 0 0 1em color-mix(in srgb, var(--domain-glow) 40%, transparent);
}

/* Playable now: bright border in the domain's glow color */
.card.can-play .card-inner {
    border-color: var(--domain-glow);
    box-shadow: 0 0 0.8em color-mix(in srgb, var(--domain-glow) 45%, transparent);
}

/* Your turn, but you can't play it (not enough essence, or a domain already played) */
.card.unaffordable {
    filter: brightness(0.7) saturate(0.6);
    cursor: default;
}

.card.unaffordable .card-inner {
    border-color: color-mix(in srgb, var(--domain-color) 40%, var(--bg-dark));
}

/* Card Header (cost + name). Names wrap to a second line instead of truncating. */
.card-header {
    display: flex;
    align-items: flex-start;
    padding: 0.3em 0.4em;
    gap: 0.3em;
    background: rgba(0, 0, 0, 0.3);
}

/* Cost: grey number = generic (any essence); colored symbols = essence from that domain */
.card-cost {
    display: flex;
    align-items: center;
    gap: 0.12em;
    flex-shrink: 0;
}

.cost-generic {
    width: 1.5em;
    height: 1.5em;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    font-weight: 700;
    background: #3a3a4a;
    border: 1px solid #77778c;
    color: #ececf3;
}

.cost-pip {
    width: 1.3em;
    height: 1.3em;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72em;
    border: 1px solid;
}

.cost-pip.domain-void { color: var(--void-glow); border-color: var(--void-glow); background: rgba(107, 33, 168, 0.45); }
.cost-pip.domain-blood { color: #fca5a5; border-color: var(--blood-glow); background: rgba(127, 29, 29, 0.6); }
.cost-pip.domain-shadow { color: #d1d5db; border-color: #9ca3af; background: rgba(55, 65, 81, 0.6); }
.cost-pip.domain-body { color: var(--body-glow); border-color: var(--body-glow); background: rgba(180, 83, 9, 0.4); }
.cost-pip.domain-will { color: var(--will-glow); border-color: var(--will-glow); background: rgba(109, 40, 217, 0.45); }

.card-name {
    font-family: 'Cinzel', serif;
    font-size: 0.78em;
    font-weight: 700;
    line-height: 1.15;
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word; /* break between words; only split a word that can't fit at all */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Card Art Area */
.card-art {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.8em;
    position: relative;
    overflow: hidden;
    background: var(--art-bg);
}

/* Real illustrations (card.image) fill the art area */
.card-art img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Card Type Line */
.card-type {
    font-size: 0.55em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.2em 0.5em;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.3);
    text-align: center;
}

/* Card Text */
.card-text {
    padding: 0.35em 0.5em;
    font-size: 0.68em;
    line-height: 1.25;
    color: #cfccd9;
}

/* Flavor text (shown in the hover preview) */
.card-flavor {
    padding: 0 0.6em 0.5em;
    font-size: 0.6em;
    font-style: italic;
    line-height: 1.3;
    color: var(--text-secondary);
}

.card-flavor-by {
    margin-top: 0.2em;
    text-align: right;
    font-style: normal;
    font-size: 0.92em;
    opacity: 0.85;
}

/* Card Stats (Attack/Health for entities) */
.card-stats {
    display: flex;
    justify-content: space-between;
    padding: 0.2em 0.5em;
    background: rgba(0, 0, 0, 0.3);
}

.card-attack, .card-health {
    font-size: 0.9em;
    font-weight: 700;
}

.card-attack {
    color: #f87171;
}

.card-health {
    color: #4ade80;
}

/* Card Back (opponent's hand) */
.card-back {
    width: 60px;
    height: 80px;
    border-radius: 6px;
    background: var(--bg-dark);
    border: 2px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 10px,
            rgba(124, 58, 237, 0.05) 10px,
            rgba(124, 58, 237, 0.05) 20px
        );
}

.card-back-symbol {
    font-size: 2rem;
    color: var(--accent);
    opacity: 0.3;
}

/* ---- Card type frames ----
 * Entity: rectangular art and a stats bar (the default).
 * Ritual: arched art window.
 * Relic: oval medallion inside a double frame.
 * Domain: glowing full-width art, heavy border, centered name.
 */
.card-type::before {
    margin-right: 0.35em;
}
.card.card-type-entity .card-type::before { content: '\25C6'; }  /* ◆ */
.card.card-type-ritual .card-type::before { content: '\2726'; }  /* ✦ */
.card.card-type-relic .card-type::before { content: '\2B2E'; }   /* ⬮ */
.card.card-type-domain .card-type::before { content: '\2B22'; }  /* ⬢ */

.card.card-type-ritual .card-inner {
    background: linear-gradient(180deg, var(--bg-dark) 0%, #1c1528 100%);
}

.card.card-type-ritual .card-art {
    margin: 0.35em 0.5em 0.15em;
    border-radius: 50% 50% 0.3em 0.3em / 35% 35% 0.3em 0.3em;
    border: 1px solid color-mix(in srgb, var(--domain-glow) 50%, transparent);
}

.card.card-type-ritual .card-type {
    color: #d8b4fe;
}

.card.card-type-relic .card-inner {
    outline: 1px solid color-mix(in srgb, var(--essence-color) 40%, transparent);
    outline-offset: -0.4em;
}

.card.card-type-relic .card-art {
    width: 74%;
    margin: 0.4em auto 0.2em;
    border-radius: 50%;
    border: 0.2em double color-mix(in srgb, var(--essence-color) 75%, transparent);
    box-shadow: inset 0 0 1em rgba(0, 0, 0, 0.6);
}

.card.card-type-relic .card-type {
    color: var(--essence-color);
}

.card.card-type-domain .card-inner {
    border-width: 0.25em;
}

.card.card-type-domain .card-header {
    justify-content: center;
    text-align: center;
}

.card.card-type-domain .card-art {
    font-size: 3.4em;
    background:
        radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--domain-glow) 35%, transparent), transparent 65%),
        var(--art-bg);
}

.card.card-type-domain .card-type {
    color: var(--domain-glow);
}

/* Selected/Active states */
.card.selected {
    transform: translateY(-12px);
}

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

.card.exhausted {
    opacity: 0.6;
    transform: rotate(5deg);
}

/* Just summoned: can block, can't attack yet */
.card.summoning-sick .card-art {
    filter: grayscale(0.6) brightness(0.8);
}

/* Keyword line on board cards */
.card-keywords {
    padding: 0.2em 0.5em;
    font-size: 0.62em;
    font-weight: 700;
    text-align: center;
    color: var(--accent-glow);
    letter-spacing: 0.05em;
}

/* Battlefield cards */
.board-row .card {
    --card-w: var(--board-card-w);
    height: calc(var(--card-w) * 1.4);
}

.board-row.crowded .card { --card-w: var(--fit-card-w); } /* UI.fitBoard */
.board-row.crowded { row-gap: 6px; padding-top: 4px; padding-bottom: 4px; }

.board-row .card:hover {
    transform: translateY(-4px);
}

/* Large hover preview with full text and flavor */
#card-preview {
    position: fixed;
    z-index: 120; /* above everything, including the deck builder and dialogs */
    pointer-events: none;
    display: none;
}

#card-preview.visible {
    display: block;
}

/* Large, fully readable card (hover preview and cast animation) */
.card.card-large {
    --card-w: 260px;
    height: auto;
    min-height: calc(var(--card-w) * 1.42);
    cursor: default;
    filter: none;
}

.card.card-large,
.card.card-large:hover {
    transform: none;
}

.card.card-large .card-inner {
    min-height: calc(var(--card-w) * 1.42);
    box-shadow: 0 0 2em rgba(0, 0, 0, 0.8), 0 0 1em color-mix(in srgb, var(--domain-glow) 35%, transparent);
}

.card.card-large .card-art {
    flex: 0 0 calc(var(--card-w) * 0.6);
}

.card.card-large .card-name {
    -webkit-line-clamp: unset;
}

.card-name.card-name-long {
    font-size: 0.66em;
    letter-spacing: -0.01em;
}
