/* ===== Mèo Bom: design tokens + card component. Builds on the shared skin tokens (--op-*, --lm-*).
   Card art is the inline SVG sprite resources/views/client/meo-bom/_card-sprite.blade.php;
   names / effects come from the catalog JSON (_card-catalog-json.blade.php) as HTML overlays.

   Card markup (category class from catalog[kind].category):
     <button type="button" class="mb-card mb-card--turn" data-kind="attack">
       <svg class="mb-card__art" viewBox="0 0 100 140" aria-hidden="true"><use href="#mb-card-attack"/></svg>
       <span class="mb-card__name">Dí Lượt</span>
       <span class="mb-card__effect">Kết thúc lượt, không rút…</span>
     </button>
     <div class="mb-card mb-card--back" role="img" aria-label="Lá bài úp"><svg class="mb-card__art" viewBox="0 0 100 140" aria-hidden="true"><use href="#mb-card-back"/></svg></div>
   Sizes: .mb-card--hand / --table / --zoom (or set --mb-card-w inline on the card). The effect line shows only when the
   card is at least 150px wide (container query), so hand / table cards keep the art readable.
   States: .is-playable, .is-selected or [aria-pressed="true"], :disabled or .is-disabled, :focus-visible. ===== */
:root {
    /* Ink + paper (card outline, text) */
    --mb-ink: #2B1B12;
    --mb-paper: #FFF8EC;
    --mb-paper-2: #F6EAD3;

    /* Category bands: white text on each passes WCAG AA (≥ 5.4:1) */
    --mb-danger: #C81E32;   --mb-danger-soft: #FFE1DC;
    --mb-rescue: #16794A;   --mb-rescue-soft: #DDF3E4;
    --mb-reaction: #6A34B5; --mb-reaction-soft: #ECE2FA;
    --mb-turn: #B3480A;     --mb-turn-soft: #FFE8D3;
    --mb-info: #1D5BBF;     --mb-info-soft: #DFEBFC;
    --mb-social: #B21858;   --mb-social-soft: #FCE0EC;
    --mb-cat: #7A4A1F;      --mb-cat-soft: #F6EAD3;

    /* States */
    --mb-playable: #FACC15;
    --mb-selected: var(--op-accent, #E86F2C);
    --mb-focus: rgba(232, 111, 44, .6);

    /* Table */
    --mb-felt: #2F6B4F;
    --mb-felt-2: #24563F;
    --mb-felt-line: rgba(255, 248, 236, .18);
    --mb-seat-bg: var(--op-bg-card, #fff);
    --mb-seat-active: var(--op-accent, #E86F2C);
    --mb-seat-out: #9CA3AF;

    /* Card sizes: hand fits 10 overlapping cards on a 360px phone */
    --mb-card-w-hand: clamp(56px, 17vw, 88px);
    --mb-card-w-table: clamp(52px, 13vw, 76px);
    --mb-card-w-zoom: min(72vw, 260px);
    --mb-ease: cubic-bezier(.2, .8, .2, 1);
    /* Overshooting spring (select lift, pops); linear() version below where supported. Same curve as MB.Motion.spring */
    --mb-spring: cubic-bezier(.3, 1.4, .5, 1);
    --mb-shadow: 0 3px 0 rgba(43, 27, 18, .25), 0 10px 18px -12px rgba(43, 27, 18, .55);
}

/* ---- Card ---- */
.mb-card {
    --mb-card-w: var(--mb-card-w-hand);
    --mb-band: var(--mb-cat);
    --mb-band-soft: var(--mb-cat-soft);
    position: relative;
    display: inline-block;
    flex: none;
    box-sizing: border-box;
    width: var(--mb-card-w);
    aspect-ratio: 5 / 7;
    container-type: inline-size;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: calc(var(--mb-card-w) * .09);
    background: none;
    color: var(--mb-ink);
    font: inherit;
    text-align: left;
    vertical-align: top;
    -webkit-tap-highlight-color: transparent;
    filter: drop-shadow(0 2px 0 rgba(43, 27, 18, .22));
    transition: transform .32s var(--mb-spring), filter .18s;
}
@supports (transition-timing-function: linear(0, 1)) {
    :root {
        --mb-spring: linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163,
            1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1.004 83.8%, 1);
    }
}
button.mb-card { cursor: pointer; }
.mb-card--danger { --mb-band: var(--mb-danger); --mb-band-soft: var(--mb-danger-soft); }
.mb-card--rescue { --mb-band: var(--mb-rescue); --mb-band-soft: var(--mb-rescue-soft); }
.mb-card--reaction { --mb-band: var(--mb-reaction); --mb-band-soft: var(--mb-reaction-soft); }
.mb-card--turn { --mb-band: var(--mb-turn); --mb-band-soft: var(--mb-turn-soft); }
.mb-card--info { --mb-band: var(--mb-info); --mb-band-soft: var(--mb-info-soft); }
.mb-card--social { --mb-band: var(--mb-social); --mb-band-soft: var(--mb-social-soft); }
.mb-card--cat { --mb-band: var(--mb-cat); --mb-band-soft: var(--mb-cat-soft); }

.mb-card--hand { --mb-card-w: var(--mb-card-w-hand); }
.mb-card--table { --mb-card-w: var(--mb-card-w-table); }
.mb-card--zoom { --mb-card-w: var(--mb-card-w-zoom); filter: drop-shadow(0 18px 24px rgba(43, 27, 18, .35)); }

.mb-card__art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

/* Name sits on the top band (band = top 17.9% of the 100×140 face) */
.mb-card__name {
    position: absolute;
    top: 2.2%;
    left: 6%;
    right: 6%;
    height: 15.5%;
    display: flex;
    align-items: center;
    overflow: hidden;
    color: #fff;
    font-size: max(9px, 10.5cqw);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.01em;
    white-space: nowrap;
    text-overflow: ellipsis;
    pointer-events: none;
}
/* Effect line: only on cards wide enough to read it (zoom, guide gallery) */
.mb-card__effect { display: none; }
@container (min-width: 150px) {
    .mb-card__effect {
        position: absolute;
        left: 6%;
        right: 6%;
        bottom: 4.5%;
        display: block;
        padding: 4cqw 5cqw;
        border: max(2px, 1.4cqw) solid var(--mb-ink);
        border-radius: 5cqw;
        background: rgba(255, 248, 236, .94);
        color: var(--mb-ink);
        font-size: 6.4cqw;
        font-weight: 600;
        line-height: 1.25;
        pointer-events: none;
    }
}

/* States */
.mb-card.is-playable { filter: drop-shadow(0 0 0 transparent) drop-shadow(0 0 5px var(--mb-playable)) drop-shadow(0 2px 0 rgba(43, 27, 18, .22)); }
.mb-card.is-selected, .mb-card[aria-pressed="true"] {
    transform: translateY(-14%);
    filter: drop-shadow(0 0 0 transparent) drop-shadow(0 0 4px var(--mb-selected)) drop-shadow(0 8px 10px rgba(43, 27, 18, .35));
}
.mb-card:disabled, .mb-card.is-disabled { cursor: not-allowed; filter: grayscale(.65) brightness(.92) drop-shadow(0 2px 0 rgba(43, 27, 18, .15)); }
@media (hover: hover) {
    button.mb-card:not(:disabled):not(.is-disabled):not(.is-selected):not([aria-pressed="true"]):hover { transform: translateY(-6%); }
}
.mb-card:focus { outline: none; }
.mb-card:focus-visible { outline: 3px solid var(--mb-focus); outline-offset: 3px; }

/* ---- Hand: overlapping row that fits its width. REQUIRED: set --mb-hand-n to the card count (JS, inline style);
   overlap = at least 30% of a card, more when n cards would not fit (margin % = row content width).
   Scrolls sideways only past ~16 cards on a 360px phone, when even 80% overlap cannot fit. ---- */
.mb-hand {
    --mb-hand-n: 10;
    --mb-hand-overlap: max(calc(var(--mb-card-w-hand) * -.8),
        min(calc(var(--mb-card-w-hand) * -.3), calc((100% - var(--mb-hand-n) * var(--mb-card-w-hand)) / max(var(--mb-hand-n) - 1, 1))));
    display: flex;
    align-items: flex-end;
    /* room above for the selected lift (14% of card height) + glow + focus ring: overflow-x clips y too.
       Side padding holds the fan spill: the edge card turns < 15deg round a pivot 1.82 card-widths below its top,
       so its top corner swings out <= .46 w (+ .05 w when lifted). The overlap's 100% is the content box,
       so the fit already excludes this padding and the fanned row never clips or scrolls before its 80% cap. */
    padding: calc(var(--mb-card-w-hand) * 1.4 * .14 + 12px) calc(var(--mb-card-w-hand) * .5) 6px;
    overflow-x: auto;
    scrollbar-width: none;
}
.mb-hand::-webkit-scrollbar { display: none; }
.mb-hand > .mb-card + .mb-card { margin-left: var(--mb-hand-overlap); }
/* Auto margins centre the row yet keep the first card reachable when it overflows */
.mb-hand > .mb-card:first-child { margin-left: auto; }
.mb-hand > .mb-card:last-child { margin-right: auto; }
/* Fan: each card rotates / drops by its offset from the middle (--d, set by the hand render). Individual
   rotate / translate properties so the select lift, hover tilt and FLIP (transform) compose on top. */
.mb-hand { --mb-fan-step: min(4deg, calc(30deg / var(--mb-hand-n))); --mb-fan-drop: min(3px, calc(48px / (var(--mb-hand-n) * var(--mb-hand-n)))); padding-bottom: 16px; }
.mb-hand > .mb-card { transform-origin: 50% 130%; rotate: calc(var(--d, 0) * var(--mb-fan-step)); translate: 0 calc(var(--d, 0) * var(--d, 0) * var(--mb-fan-drop)); }
.mb-hand > .mb-card:hover, .mb-hand > .mb-card:focus-visible, .mb-hand > .mb-card.is-selected { z-index: 1; }
@media (hover: hover) {
    .mb-hand > button.mb-card:not(:disabled):not(.is-disabled):not(.is-selected):not([aria-pressed="true"]):hover {
        transform: translateY(-8%) perspective(500px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
    }
}
/* Drag-to-play: selected cards are draggable on touch only on my turn (else a swipe scrolls the row) */
.mb-my-turn .mb-hand > .mb-card[aria-pressed="true"] { touch-action: none; }
.mb-hand > .mb-card.is-dragging { opacity: .3; }
.mb-drag-ghost { position: fixed; left: 0; top: 0; z-index: 950; pointer-events: none; will-change: transform; }
.mb-drag-ghost .mb-card { position: absolute; left: calc(var(--i, 0) * 12px); top: calc(var(--i, 0) * -4px);
    filter: drop-shadow(0 0 5px var(--mb-selected)) drop-shadow(0 16px 16px rgba(43, 27, 18, .4)); }
/* Just drawn / received (set by MB.Motion.flipList for 1.2 s) */
.mb-hand > .mb-card.is-new { z-index: 1; filter: drop-shadow(0 0 0 transparent) drop-shadow(0 0 7px #FDE68A) drop-shadow(0 0 14px rgba(250, 204, 21, .7)); }

@media (prefers-reduced-motion: reduce) {
    .mb-card { transition: none; }
}
