/* The card browser: the Play Mat. Builds on /style.css (tokens, bar, banners, the printed card
   face, the sky); everything here is the mat, its filters and the stand beside it. */

.browser {
    width: 100%;
    max-width: calc(1480px + var(--gutter) * 2);
    margin: 0 auto;
    padding: 0 var(--gutter);
}
.browser-head { padding: clamp(24px, 3vw, 44px) 0 clamp(22px, 2.6vw, 32px); }
.browser-head h1 {
    font-size: clamp(2.1rem, 4.4vw, 3.6rem);
    color: var(--gold-hi);
    text-wrap: balance;
    text-shadow: 0 0.06em 0.5em rgba(6, 3, 13, 0.8);
}
.browser-head p { margin-top: 14px; max-width: 60ch; font-size: 1.125rem; color: var(--ink); }

.browse {
    --stick: calc(var(--bar-h) + 16px);
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 330px;
    grid-template-areas: "filters mat inspect";
    gap: clamp(20px, 2vw, 30px);
    align-items: start;
}

/* ── Filters ──────────────────────────────────────────────────────────── */
.filters {
    grid-area: filters;
    position: sticky; top: var(--stick);
    max-height: calc(100vh - var(--stick) - 16px);
    overflow-y: auto;
    padding: 4px 6px 16px 0;
    scrollbar-width: thin;
}
.f-search label, .f-group legend {
    display: block;
    margin: 0 0 8px;
    padding: 0;
    font: 600 0.72rem/1 var(--display); letter-spacing: 0.16em; text-transform: uppercase;
    color: var(--ink-2);
}
.f-search input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--rim);
    border-radius: 10px;
    background: rgba(9, 5, 20, 0.85);
    color: var(--ink);
    font: 1rem/1.2 var(--body);
}
.f-search input::placeholder { color: var(--ink-3); }
.f-search input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-color: transparent; }
.f-search input::-webkit-search-cancel-button { filter: invert(0.8) sepia(1) saturate(3) hue-rotate(5deg); }
.f-toggle, .f-show { display: none; }
.f-group { margin: 24px 0 0; padding: 0; border: 0; min-width: 0; }
.f-options { display: flex; flex-direction: column; gap: 2px; }

.f-chip {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--ink);
    font: 1rem/1.2 var(--body);
    text-align: left;
    cursor: pointer;
    transition: background-color 160ms, border-color 160ms, color 160ms, opacity 160ms;
}
.f-chip:hover { background: rgba(255, 255, 255, 0.06); }
.f-chip[aria-pressed="true"] {
    background: rgba(245, 199, 78, 0.13);
    border-color: rgba(245, 199, 78, 0.6);
    color: var(--gold-hi);
}
/* An option that would show nothing with the other filters as they are. */
.f-chip.is-empty { opacity: 0.5; }
.f-chip img { width: 28px; height: 28px; flex: none; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.6)); transition: transform 200ms var(--ease-out); }
.f-chip[aria-pressed="true"] img { transform: scale(1.12); }
.f-icon { width: 20px; height: 20px; flex: none; margin: 0 4px; color: var(--gold); }
.f-count {
    margin-left: auto;
    font: 600 0.8rem/1 var(--display);
    font-variant-numeric: tabular-nums lining-nums;
    color: var(--ink-3);
}
.f-chip[aria-pressed="true"] .f-count { color: var(--gold); }

/* Cost: the printed cost gem, numbered. */
.f-costs { flex-direction: row; flex-wrap: wrap; gap: 8px; }
.f-chip.f-cost {
    width: 40px; height: 40px; min-height: 0;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    border: 0;
    background: url('/img/gems/norse.webp') center / contain no-repeat;
    color: var(--ink);
    font-size: 1rem;
    text-shadow: 0 1px 2px var(--sky), 0 0 6px var(--sky);
    transition: transform 200ms var(--ease-out), box-shadow 200ms, opacity 160ms;
}
.f-chip.f-cost:hover { background-color: transparent; transform: translateY(-2px); }
.f-chip.f-cost[aria-pressed="true"] { background-color: transparent; box-shadow: 0 0 0 2px var(--gold), 0 4px 10px rgba(0, 0, 0, 0.6); }
.f-classes { flex-direction: row; gap: 6px; }
.f-classes .f-chip { width: auto; justify-content: center; border-color: var(--rim); font-family: var(--display); font-size: 0.8rem; letter-spacing: 0.04em; }
.f-art { border-color: var(--rim); }
.f-clear:not(.banner) {
    padding: 6px 0;
    border: 0; background: none;
    color: var(--gold-hi);
    font: 1rem/1 var(--body);
    text-decoration: underline; text-underline-offset: 0.25em; text-decoration-color: rgba(245, 199, 78, 0.5);
    cursor: pointer;
}
.f-clear:not(.banner):hover { text-decoration-color: var(--gold); }

/* ── The mat: violet felt, stitched with gold ─────────────────────────── */
.mat {
    grid-area: mat;
    position: relative;
    min-height: 70vh;
    padding: clamp(18px, 2vw, 28px);
    border-radius: 18px;
    background:
        radial-gradient(70% 50% at 50% 18%, rgba(110, 60, 190, 0.3), transparent 70%),
        radial-gradient(120% 100% at 50% 50%, transparent 55%, rgba(4, 2, 10, 0.55) 100%),
        url('/img/cards/felt.webp') center / 256px auto repeat,
        #170d2e;
    box-shadow:
        inset 0 0 60px rgba(0, 0, 0, 0.55),
        0 0 0 4px #0b0518,
        0 0 0 5px rgba(245, 199, 78, 0.38),
        0 40px 70px -30px rgba(0, 0, 0, 0.9);
}
.mat::before {
    content: '';
    position: absolute; inset: 9px;
    border: 1.5px dashed rgba(245, 199, 78, 0.42);
    border-radius: 10px;
    pointer-events: none;
}
.mat:focus { outline: none; }
/* What the filters left, gold-stamped onto the felt; clearing and sorting beside it. */
.mat-bar {
    position: relative;
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px;
    margin: 2px 4px 22px;
    padding-bottom: 14px;
    border-bottom: 1px dashed rgba(245, 199, 78, 0.3);
}
.mat-count {
    font: 600 0.8rem/1 var(--display); letter-spacing: 0.12em; text-transform: uppercase;
    color: #f3d79a;
}
.mat-count b {
    margin-right: 6px;
    font-size: 1.9rem; letter-spacing: 0;
    font-variant-numeric: tabular-nums lining-nums;
    color: var(--gold-hi);
    vertical-align: -0.12em;
}
.f-sort {
    display: flex; align-items: center; gap: 10px;
    margin-left: auto;
    font: 600 0.72rem/1 var(--display); letter-spacing: 0.16em; text-transform: uppercase;
    color: var(--ink-2);
}
.f-sort select {
    min-height: 40px;
    padding: 8px 34px 8px 12px;
    border: 1px solid var(--rim);
    border-radius: 10px;
    background: rgba(9, 5, 20, 0.85) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%23f5c74e' stroke-width='1.6'/%3E%3C/svg%3E") right 12px center / 12px 8px no-repeat;
    color: var(--ink);
    font: 1rem/1.2 var(--body);
    letter-spacing: normal; text-transform: none;
    appearance: none;
}
.mat-grid {
    position: relative;
    list-style: none; margin: 0; padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 22px 16px;
}
.mat-item { min-width: 0; }
.mat-card {
    position: relative;
    display: block;
    width: 100%;
    padding: 0; border: 0;
    background: none;
    border-radius: 4.4% / 3.04%;
    cursor: pointer;
    perspective: 900px;
    -webkit-tap-highlight-color: transparent;
}
.mat-lift {
    --lift: 0px; --tilt-x: 0deg; --tilt-y: 0deg;
    display: block;
    transition: transform 300ms var(--ease-out);
}
/* Only a card being handled carries a 3D transform: 180 resting cards stay flat, so they don't
   each become a compositor layer. */
.mat-card:hover .mat-lift,
.mat-card[aria-current] .mat-lift,
.mat-lift.is-tilting {
    transform: translateY(var(--lift)) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
}
/* The glare is a blend layer; it exists only while a card is tilting. */
.mat .cf-glare { display: none; }
.mat .mat-lift.is-tilting .cf-glare { display: block; }
/* A box shadow on the face, not a filter: 180 filtered cards are heavy to scroll on a phone. */
.mat-lift .card-face { box-shadow: 0 10px 14px -2px rgba(0, 0, 0, 0.55); transition: box-shadow 300ms; }
.mat-card:hover .mat-lift { --lift: -6px; }
.mat-card:hover .mat-lift .card-face { box-shadow: 0 18px 22px -4px rgba(0, 0, 0, 0.6); }
.mat-lift.is-tilting .cf-glare { opacity: 1; }
/* The card that's picked up: raised, and ringed in gold where it lay. */
.mat-card[aria-current] .mat-lift { --lift: -8px; }
.mat-card[aria-current] .mat-lift .card-face { box-shadow: 0 18px 22px -4px rgba(0, 0, 0, 0.6); }
.mat-card[aria-current]::after {
    content: '';
    position: absolute; inset: -6px -6px -2px;
    border: 2px solid var(--gold);
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}
.mat-card:focus-visible { outline-offset: 6px; border-radius: 10px; }
.mat-empty { padding: 72px 16px; text-align: center; }
.mat-empty p { font-size: 1.125rem; margin-bottom: 22px; }
.mat-note { padding: 40px 16px; text-align: center; }

/* ── The stand: the picked-up card, read closely ──────────────────────── */
.inspect {
    grid-area: inspect;
    position: sticky; top: var(--stick);
}
.inspect-scroll {
    max-height: calc(100vh - var(--stick) - 16px);
    overflow-y: auto;
    scrollbar-width: thin;
    padding: 22px 22px 18px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(20, 12, 40, 0.92), rgba(10, 6, 22, 0.94));
    box-shadow: inset 0 0 0 1px var(--rim), 0 30px 60px -24px rgba(0, 0, 0, 0.9);
}
.inspect-head { display: none; }
.inspect-empty { padding: 28px 4px; text-align: center; color: var(--ink-2); }
.inspect-card { width: min(100%, 300px); margin: 0 auto; filter: drop-shadow(0 22px 26px rgba(0, 0, 0, 0.7)); }
.inspect-card .card-face { cursor: default; }
.inspect-body { margin-top: 22px; }
.inspect-name { font-size: 1.5rem; line-height: 1.15; color: var(--gold-hi); text-wrap: balance; }
.inspect-name:focus { outline: none; }
.inspect-meta { margin-top: 6px; font-size: 0.98rem; color: var(--ink-2); }
.inspect-facts { margin: 16px 0 0; border-top: 1px solid var(--rim); }
.inspect-facts > div,
.inspect-terms .term {
    padding: 9px 0;
    border-bottom: 1px solid var(--rim);
}
.inspect-facts > div { display: grid; grid-template-columns: 6.5em 1fr; gap: 10px; }
.inspect-facts dt {
    padding-top: 0.2em;
    font: 600 0.72rem/1.4 var(--display); letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--ink-3);
}
.inspect-facts dd { margin: 0; font-size: 1rem; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.pip { width: 18px; height: 18px; flex: none; background: center / contain no-repeat; }
.pip-character { background-image: url('/img/pip-character.svg'); }
.pip-magic { background-image: url('/img/pip-magic.svg'); }
.inspect-terms { margin-top: 24px; }
.inspect-terms h3 {
    font: 600 0.72rem/1 var(--display); letter-spacing: 0.16em; text-transform: uppercase;
    color: var(--ink-2);
}
.inspect-terms dl { margin: 10px 0 0; border-top: 1px solid var(--rim); }
.term dt { font: 700 0.95rem/1.2 var(--display); letter-spacing: 0.02em; color: var(--ink); }
.term dd { margin: 5px 0 0; font-size: 0.97rem; line-height: 1.45; color: var(--ink-2); }
.inspect-nav {
    display: flex; justify-content: space-between; gap: 8px;
    margin-top: 18px;
}
.inspect-nav button {
    min-height: 40px;
    padding: 6px 4px;
    border: 0; background: none;
    font: 600 0.8rem/1 var(--display); letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--gold-hi);
    cursor: pointer;
}
.inspect-nav button:hover:not(:disabled) { color: var(--ink); text-decoration: underline; text-underline-offset: 0.35em; }
.inspect-nav button:disabled { color: var(--ink-3); opacity: 0.45; cursor: default; }

/* The card's morph from the mat to the stand (View Transitions), and nothing else moving. */
::view-transition-old(root), ::view-transition-new(root) { animation: none; }
::view-transition-group(picked-card) { animation-duration: 520ms; animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); }
::view-transition-old(picked-card), ::view-transition-new(picked-card) { animation-duration: 520ms; height: 100%; }

/* ── Close ────────────────────────────────────────────────────────────── */
.cards-close {
    max-width: 760px;
    margin: 0 auto;
    padding: clamp(90px, 10vw, 140px) 0 clamp(80px, 9vw, 120px);
    text-align: center;
}
.cards-close p { margin: 18px auto 0; max-width: 44ch; font-size: 1.15rem; }
.cards-close .actions { justify-content: center; }

@media (prefers-reduced-motion: reduce) {
    .mat-lift, .f-chip, .f-chip img { transition: none; }
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ── Narrower: filters fold into a bar above the mat ──────────────────── */
@media (max-width: 1179px) {
    .browse {
        grid-template-columns: minmax(0, 1fr) 320px;
        grid-template-areas: "filters filters" "mat inspect";
        row-gap: 22px;
    }
    .filters {
        position: static; max-height: none; overflow: visible;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "search toggle" "panel panel";
        align-items: end;
        gap: 0 14px;
        padding: 0;
    }
    .f-search { grid-area: search; }
    .f-toggle { grid-area: toggle; display: inline-flex; gap: 10px; min-height: 44px; }
    .f-active {
        display: inline-grid; place-items: center;
        min-width: 22px; height: 22px; padding: 0 6px;
        border-radius: 10px;
        background: var(--outline); color: var(--gold-hi);
        font: 700 0.72rem/1 var(--display); letter-spacing: 0;
    }
    .f-active[hidden] { display: none; }
    .f-panel {
        grid-area: panel;
        display: none;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 4px 28px;
        margin-top: 10px;
        padding: 6px 18px 20px;
        border-radius: 10px;
        background: rgba(12, 7, 26, 0.9);
        box-shadow: inset 0 0 0 1px var(--rim);
    }
    .filters.is-open .f-panel { display: grid; }
    .f-pantheons, .f-types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; }
    .f-group { margin-top: 18px; }
    .f-show { display: inline-flex; grid-column: 1 / -1; justify-self: start; margin-top: 22px; }
}
@media (max-width: 899px) {
    .browse { grid-template-columns: minmax(0, 1fr); grid-template-areas: "filters" "mat"; }
    .mat { padding: 16px 14px 20px; min-height: 50vh; }
    .mat::before { inset: 6px; }
    .mat-bar { margin: 2px 2px 18px; }
    .f-sort { margin-left: 0; }
    .mat-grid { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 18px 12px; }
    /* A picked card opens as a sheet over the mat: a dialog with its own solid header. */
    .inspect { position: static; }
    .inspect.is-sheet {
        position: fixed; left: 0; right: 0; bottom: 0; top: 6svh;
        z-index: 60;
        animation: sheet-up 380ms var(--ease-out);
    }
    .inspect.is-sheet .inspect-scroll {
        height: 100%; max-height: none;
        border-radius: 18px 18px 0 0;
        padding: 0 18px calc(24px + env(safe-area-inset-bottom));
        background: linear-gradient(180deg, #170d30, #0b0618);
    }
    .inspect.is-sheet .inspect-head {
        display: flex; justify-content: flex-end;
        position: sticky; top: 0; z-index: 2;
        margin: 0 -18px 16px;
        padding: 6px 18px;
        background: #170d30;
        box-shadow: 0 1px 0 var(--rim);
    }
    .inspect-close {
        min-height: 44px;
        padding: 8px 4px;
        border: 0; background: none;
        font: 600 0.8rem/1 var(--display); letter-spacing: 0.14em; text-transform: uppercase;
        color: var(--gold-hi);
        text-decoration: underline; text-underline-offset: 0.4em; text-decoration-color: rgba(245, 199, 78, 0.5);
        cursor: pointer;
    }
    .inspect.is-sheet .inspect-card { width: min(74vw, 320px); }
    body.sheet-open { overflow: hidden; }
    .sheet-backdrop {
        position: fixed; inset: 0; z-index: 55;
        background: rgba(6, 3, 13, 0.72);
    }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .inspect.is-sheet { animation: none; } }
@media (max-width: 640px) {
    .f-panel { padding: 4px 14px 18px; }
}
