@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700&family=Spectral:wght@400;500&display=swap');

/* Card styles for Moonfall game */

/* Define card dimensions as CSS variables for consistency */
:root {
    --card-width: 45px;
    --card-height: 80px;
}

.card {
    width: var(--card-width); /* Use CSS variable for consistency */
    height: var(--card-height); /* Use CSS variable for consistency */
    margin: 0 20px; /* Increased horizontal margin to 20px for much wider spacing */
    border-radius: 0; /* Removed corner rounding */
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    /* Update transition to include z-index */
    /* Apply transform/shadow instantly, delay z-index drop on hover-out */
    transition: transform 0.2s ease, box-shadow 0.2s ease, z-index 0s ease 0.2s;
    box-shadow: 0 0 8px rgba(238, 219, 241, 0.5);
    border: 1px solid rgba(238, 219, 241, 0.3);
}

/* Removed generic hover style as it conflicts with specialized hover behavior in player hand */
/* Only apply hover shadow effect without transformation */
.card:hover {
    box-shadow: 0 0 12px rgba(238, 219, 241, 0.8);
}

.card.draggable {
    cursor: grab;
    /* Removed default glow; glow will appear on hover via .card:hover */
    /* Ensure draggable cards use normal transform-origin */
    transform-origin: center center;
    /* Explicitly allow dragging */
    -webkit-user-drag: element;
    /* The user-drag property is non-standard, using only webkit version */
}

.card.draggable:hover {
    transform: translateY(-5px) scale(1.05);
    /* Override the large scale effect when hovering over draggable cards */
    /* This ensures cards don't get too large when preparing to drag */
    z-index: 10;
    transform-origin: center center;
}

.card.draggable:active {
    cursor: grabbing;
    /* Return to normal size when actively grabbing */
    transform: scale(1);
    transform-origin: center center;
}

/* Force normal size during dragging operations */
.card.dragging {
    transform: scale(1) !important;
    transform-origin: center center !important;
    z-index: 200 !important; /* Keep on top during drag */
    /* Blue glow for card under drag */
    box-shadow: 0 0 14px rgba(0, 128, 255, 0.9) !important;
    border: 1px solid rgba(0, 128, 255, 0.6) !important;
    /* Do not intercept pointer events so targets underneath can receive dragover/drop */
    pointer-events: none !important;
}

/* --- Highlight states (priority: red > orange > blue > white > green) --- */
.card.legal-play {
    /* Green glow for playable cards */
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.7);
    border: 1px solid rgba(0, 255, 0, 0.4);
}

/* Orange glow for all potential targets during a drag operation */
.potential-target {
    box-shadow: 0 0 12px rgba(255, 165, 0, 0.8) !important;
    border: 1px solid rgba(255, 165, 0, 0.5) !important;
}

/* Red glow for the currently hovered/active target */
.valid-target {
    box-shadow: 0 0 14px rgba(255, 0, 0, 0.9) !important;
    border: 1px solid rgba(255, 0, 0, 0.6) !important;
}

/* Status text overlay (always visible; repositions on enlarge) */
.card-status {
    opacity: 1;
    transition: opacity 0.2s ease-in-out;
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 6px;
    line-height: 1;
    padding: 1px 2px;
    text-align: center;
    border-radius: 2px;
    z-index: 4;
    pointer-events: none; /* Allow clicks to pass through */
    display: flex;
    flex-direction: column;
    gap: 2px;
    white-space: normal;
    overflow: hidden;
    
}

/* Optional subtle change on hover */
.card:hover .card-status { opacity: 1; }

/* When enlarged, let inner elements protrude outside the original box */
.card.hover-active {
    overflow: visible;
}

/* Reveal & reposition when enlarged (hover-active) */
.card.hover-active .card-status {
    opacity: 1;

    /* Move outside card to the right */
    position: absolute;
    /* Reset default bottom/right so they do not conflict */
    bottom: auto;
    right: auto;
    left: calc(100% + 8px); /* gap from card edge */
    top: 0;

    /* Flexible sizing */
    width: auto;
    max-width: 200px;
    min-width: 85px;
    white-space: normal; /* allow wrapping */
    overflow-wrap: break-word;
    overflow: visible;
    text-align: left;

    /* Typography & style */
    font-size: 5px;
    line-height: 1;
    padding: 4px 8px;
    background: rgba(0,0,0,0.75);
    border-left: 3px solid rgba(255,255,255,0.35);
    border-radius: 2px;

    /* Elevation */
    z-index: 110;
    box-shadow: 0 2px 8px rgba(0,0,0,0.55);
}

/* Reposition status banner when a board card is hovered (enlarged by scale) */
#player-board .card:not(.dragging):not(:active):hover .card-status,
#opponent-board .card:not(.dragging):not(:active):hover .card-status {
    opacity: 1;
    position: absolute;
    bottom: auto;
    right: auto;
    left: calc(100% + 8px);
    top: 0;
    transform: none;

    width: auto;
    max-width: 200px;
    min-width: 85px;
    white-space: normal;
    overflow-wrap: break-word;
    overflow: visible;
    text-align: left;
    font-size: 5px;
    line-height: 1;
    padding: 4px 8px;
    background: rgba(0,0,0,0.75);
    border-left: 3px solid rgba(255,255,255,0.35);
    border-radius: 2px;
    z-index: 110;
    box-shadow: 0 2px 8px rgba(0,0,0,0.55);
}

/* Hover Hint overlay (hidden by default, separate from status) */
.card-hint {
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    text-align: center;
    background: rgba(10, 14, 24, 0.35);
    color: #fff;
    font-size: 7px;
    line-height: 1.1;
    border-radius: 2px;
    z-index: 5; /* raised on visible */
    pointer-events: none;
    white-space: normal;
    overflow: hidden;
}

/* Reveal hint centered ON TOP of the card when enlarged/hovered (distinct from status) */
.card.hover-active .card-hint.visible-hint,
#player-board .card:not(.dragging):not(:active):hover .card-hint.visible-hint,
#opponent-board .card:not(.dragging):not(:active):hover .card-hint.visible-hint {
    opacity: 1;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    text-align: center;
    width: auto;
    max-width: none;
    min-width: 0;
    overflow: visible;
    white-space: normal;
    overflow-wrap: break-word;

    font-family: 'Cinzel', serif;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.6px;
    font-size: 9px;
    line-height: 1.15;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.9), 0 0 10px rgba(123,190,255,0.6);
    background: radial-gradient(ellipse at center, rgba(10,14,24,0.75) 0%, rgba(10,14,24,0.45) 60%, rgba(10,14,24,0.25) 100%);
    border: 1px solid rgba(123, 190, 255, 0.45);
    border-radius: 3px;

    z-index: 150; /* above card content, below off-card status banner */
    box-shadow: 0 2px 10px rgba(0,0,0,0.55);
}

/* Additional status line styling */
/* Removed .status-line styling; no longer needed since status uses <br> */
/* .status-line {
    width: 100%;
    white-space: normal;
} */

.card-status span {
    font-weight: bold;
}

.card-status span {
    font-weight: bold;
}

/* Card status indicators */
.card.summoned-this-turn {
    opacity: 0.7;
}

.card.summoned-this-turn::after {
    content: "Can't use this turn";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.6rem;
    padding: 2px;
    text-align: center;
}

.card.used-this-turn {
    opacity: 0.7;
}

.card.used-this-turn::after {
    content: "Already used";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.6rem;
    padding: 2px;
    text-align: center;
}

/* Expanded card status banner for enlarged cards */
.card.hover-active .card-status,
#player-board .card:not(.dragging):not(:active):hover .card-status,
#opponent-board .card:not(.dragging):not(:active):hover .card-status {
    top: 0;
    bottom: auto;
    left: calc(100% + 6px);
    transform: none;

    width: auto;
    max-width: 200px;
    min-width: 85px;
    height: auto;

    overflow: visible;

    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

/* Card front and back */
.card-back {
    background-image: url('/assets/images/cardback.png');
    background-size: cover;
    background-position: center;
    background-color: rgba(0, 0, 0, 0.5);
}

.card-front {
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    color: #060F19;
    background-color: rgba(0, 0, 0, 0.5);
    position: relative;
    box-sizing: border-box;
    isolation: isolate;
}

.card-front::before {
    /* default fallback frame */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/assets/images/cardfront.png');
    background-size: cover;
    background-position: center;
    z-index: 2;
}

/* Specific frames per card type */
.card-front.spell-card::before {
    background-image: url('/assets/images/cardfront_spell.png');
}

.card-front.creature-card::before {
    background-image: url('/assets/images/cardfront_creature.png');
}

/* Card-specific font overrides */
.card-name,
.card-cost {
    font-family: 'Cinzel', serif;
    text-transform: uppercase;
    letter-spacing: 0.15px;
}

.card-desc {
    font-family: 'Spectral', serif;
    font-weight: 500;
    letter-spacing: 0.1px;
}

/* Card elements */
.card-cost {
    position: absolute;
    top: 4px;
    left: 2px;
    color: #060F19;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 8px;
    z-index: 3;
}

.card-name {
    position: absolute !important;
    top: 4.4px !important;
    left: 21.5px !important;
    margin-top: 0 !important; /* Override media query margin-top values */
    width: 40.9px !important; /* Increased width by 2.5x */
    height: 8px !important; /* Fixed height for the title box */
    display: flex !important; /* Use flexbox for centering */
    justify-content: center !important; /* Center horizontally */
    align-items: center !important; /* Center vertically */
    text-align: center !important; /* Center text alignment */
    box-sizing: border-box !important; /* Include padding in width/height calculation */
    font-weight: bold;
    font-size: 2.73px !important; /* 5% larger than previous size */
    padding: 0 2px !important; /* Horizontal padding retained */
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    /* line-height will adjust automatically with font-size */
    z-index: 3;
    color: #060F19;
    text-shadow: 0 0 1px rgba(255,255,255,0.5);
}

.card-image {
    position: relative;
    height: 45px;
    margin: 18px 4px 4px 4px;
    overflow: visible;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.card-image img {
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
    pointer-events: none;
    user-select: none;
    display: block !important;
    opacity: 1 !important;
    z-index: 1;
    transform: scale(1.15);
    transform-origin: center center;
}

/* When using character portraits inside card slots, crop equally left/right to fit */
.card-image img.character-portrait {
    object-fit: cover !important;
    object-position: center center !important;
    transform: none !important; /* avoid extra zooming */
}

.card-desc {
    font-size: 4.5px;
    padding: 3px 6px 6px 6px;
    margin-bottom: 1px;
    line-height: normal;
    position: relative;
    z-index: 3;
    text-align: center;

    /* Fill remaining space and center content vertically */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;

    /* Add overflow hidden as a fallback in case JS fails */
    overflow: hidden;
}

.card.drag-over {
    box-shadow: 0 0 10px 5px rgba(0, 255, 0, 0.6);
    border: 2px solid lime;
    transform: scale(1.05);
}

/* Responsive card sizes */
@media screen and (min-width: 768px) {
    :root {
        --card-width: 56px;
        --card-height: 100px;
    }

    .card-cost {
        width: 15px;
        height: 15px;
        font-size: 5px;
    }

    .card-name {
        font-size: 5px;
        margin-top: 17px;
    }

    .card-image {
        height: 40px;
    }

    .card-desc {
        font-size: 6px;
        height: 20px;
    }
}

@media screen and (min-width: 1200px) {
    :root {
        --card-width: 68px;
        --card-height: 120px;
    }

    .card-cost {
        width: 18px;
        height: 18px;
        font-size: 12px;
    }

    .card-name {
        font-size: 5px;
        margin-top: 20px;
    }

    .card-image {
        height: 48px;
    }

    .card-desc {
        font-size: 5px;
        height: 22px;
    }
}
