@font-face {
    font-family: Beleren;
    src: url("https://cdn.jsdelivr.net/npm/@saeris/typeface-beleren-bold@1.0.1/Beleren2016-Bold.woff") format("woff");
    font-display: block;
}

@font-face {
    font-family: Mana;
    src: url("https://cdn.jsdelivr.net/npm/mana-font@1.18.0/fonts/mana.woff2") format("woff2");
    font-display: block;
}

:root {
    /* The hover preview's timing, shared by its tooltips. */
    --preview-in: 0.36s cubic-bezier(0.25, 1, 0.5, 1);
    --bg: #14161a;
    --panel: #1e2128;
    --text: #e6e6e6;
    --muted: #9aa0aa;
    --accent: #d4a24c;
    --error: #ff7a7a;
    --mana-w: #f7f7c0;
    --mana-u: #63c0f7;
    --mana-b: #848584;
    --mana-r: #ff5350;
    --mana-g: #18b565;
    --mana-c: #cec3bd;
    color-scheme: dark;
}

/* Still scrollable with the wheel, touch and keyboard. */
html,
.sheet-body {
    scrollbar-width: none;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, sans-serif;
}

/* Warm glow rising from the bottom of the screen, gently breathing. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    background:
        radial-gradient(ellipse 80% 50% at 50% 100%, rgb(255 90 20 / 0.28), transparent),
        radial-gradient(ellipse 45% 35% at 10% 100%, rgb(255 140 40 / 0.18), transparent),
        radial-gradient(ellipse 45% 35% at 90% 100%, rgb(220 60 20 / 0.18), transparent);
    pointer-events: none;
    animation: glow-breathe 9s ease-in-out infinite alternate;
}

@keyframes glow-breathe {
    from {
        opacity: 0.7;
    }

    to {
        opacity: 1;
    }
}

.embers {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    body::before {
        animation: none;
    }
}

main {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

main.wide {
    --page-pad: 1.5rem;
    /* Fits the 8 mana values at the bar's 2.5rem toggle size (12.4em + padding). */
    --panel-w: 33.25rem;
    max-width: none;
    padding-inline: var(--page-pad);
}

a {
    color: var(--accent);
}

header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--panel);
}

.tagline {
    color: var(--muted);
    font-style: italic;
    opacity: 0.6;
}

.brand {
    font-family: Beleren, system-ui, sans-serif;
    font-weight: normal;
    font-size: 1.6rem;
    text-decoration: none;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.brand img {
    width: 3rem;
    height: 3rem;
}

footer {
    padding: 1.5rem;
    color: var(--muted);
    font-size: 0.8rem;
    text-align: center;
}

footer p {
    margin: 0.25rem 0;
}

button {
    padding: 0.5rem 1rem;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: #111;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

input,
select {
    padding: 0.5rem;
    border: 1px solid #333842;
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    font: inherit;
}

.error {
    color: var(--error);
    white-space: pre-line;
}

.muted {
    color: var(--muted);
}

.mana {
    display: inline-grid;
    place-items: center;
    position: relative;
    width: 1.2em;
    height: 1.2em;
    border-radius: 50%;
    box-shadow: 0 0 0 0.05em #000;
    color: #000;
    font-style: normal;
    font-weight: 700;
    line-height: 1;
    /* Not a length: that would align the box's baseline, which is the number's, or the bottom edge for images. */
    vertical-align: middle;
}

/* In running text, taller than the line's text without making the line taller. */
p .mana {
    width: 1.05em;
    height: 1.05em;
    margin-block: -0.2em;
}

.mana>img {
    width: 100%;
    height: 100%;
}

.mana>span {
    font-size: 0.95em;
}

.mana.split>* {
    position: absolute;
}

.mana.split>img {
    width: 52%;
    height: 52%;
}

.mana.split>span {
    font-size: 0.6em;
}

.mana>.mana-num {
    font-weight: normal;
    font-size: 0.9em;
    /* Centers the digits' own height (cap height to baseline) rather than the font's line box. */
    text-box: trim-both cap alphabetic;
}

.mana.split>.mana-num {
    display: grid;
    place-items: center;
    width: 52%;
    height: 52%;
    font-size: 0.58em;
}

.mana>.mana-num::before {
    content: attr(data-text);
    font-family: Beleren;
}

.mana>.mana-num.plus {
    display: flex;
    align-items: center;
    gap: 0.03em;
    margin-left: 0.2em;
}

.mana>.mana-num.plus::after {
    content: "+";
    font-family: Beleren, sans-serif;
    font-size: 0.7em;
    line-height: 1;
}

.mana-fallback .mana>.mana-num::before {
    content: attr(data-glyph);
    font-family: Mana;
    font-size: 0.8em;
}

.mana.split> :first-child {
    top: 6%;
    left: 6%;
}

.mana.split> :last-child {
    right: 6%;
    bottom: 6%;
}

.mana-cost {
    display: inline-flex;
    gap: 0.1em;
}

.mana-toggle {
    display: inline-flex;
    padding: 0;
    border-radius: 50%;
    background: none;
    font: inherit;
    transition: box-shadow 0.2s ease, filter 0.2s ease;
}

/* Glow appears instantly but fades out on leave. */
.mana-toggle:hover {
    filter: brightness(1.15);
    transition: none;
}

/* Once a row has a selection, the rest of it fades back. */
[data-row]:has([aria-pressed="true"]) .mana-toggle:not([aria-pressed="true"]):not(:hover) {
    filter: grayscale(0.6) brightness(0.7);
}

/* White, static version of the orange "on" glow below. */
.mana-toggle:not([aria-pressed="true"]):hover {
    position: relative;
    isolation: isolate;
    box-shadow: 0 0 0.35em 0.1em rgb(255 255 255 / 0.22);
}

.mana-toggle:not([aria-pressed="true"]):hover::before {
    content: "";
    position: absolute;
    inset: -0.1em;
    z-index: -1;
    border-radius: inherit;
    background: rgb(255 255 255 / 0.48);
    filter: blur(0.05em);
}

/* Animating the gradient angle (rather than rotating the element) keeps the glow's shape for non-circles. */
@property --glow-angle {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0turn;
}

.mana-toggle[aria-pressed="true"],
.filters-toggle.active,
.search-box:has(input:not(:placeholder-shown)) {
    position: relative;
    isolation: isolate;
    box-shadow: 0 0 0.35em 0.1em rgb(255 110 20 / 0.5);
}

/* Two counter-rotating gradient rings behind the element make bright spots drift around the glow. */
.mana-toggle[aria-pressed="true"]::before,
.mana-toggle[aria-pressed="true"]::after,
.filters-toggle.active::before,
.filters-toggle.active::after,
.search-box:has(input:not(:placeholder-shown))::before,
.search-box:has(input:not(:placeholder-shown))::after {
    content: "";
    position: absolute;
    inset: -0.1em;
    z-index: -1;
    border-radius: inherit;
    filter: blur(0.05em);
}

.mana-toggle[aria-pressed="true"]::before,
.filters-toggle.active::before,
.search-box:has(input:not(:placeholder-shown))::before {
    background: conic-gradient(from var(--glow-angle), #ff8a1a, #ffc04d 10%, #ff8a1a 22%, #ff7a12 40%, #ffd166 52%, #ff8a1a 64%, #ff7a12 80%, #ffb340 88%, #ff8a1a);
    animation: glow-spin 7s linear infinite;
}

.mana-toggle[aria-pressed="true"]::after,
.filters-toggle.active::after,
.search-box:has(input:not(:placeholder-shown))::after {
    background: conic-gradient(from var(--glow-angle), transparent, rgb(255 235 160 / 0.9) 8%, transparent 18%, transparent 55%, rgb(255 225 130 / 0.8) 63%, transparent 72%);
    animation: glow-spin 11s linear infinite reverse;
}

@keyframes glow-spin {
    to {
        --glow-angle: 1turn;
    }
}

/* The open panel already shows the selected filters. */
.filters-toggle.active[aria-expanded="true"] {
    box-shadow: none;
}

.filters-toggle.active[aria-expanded="true"]::before,
.filters-toggle.active[aria-expanded="true"]::after {
    content: none;
}

@media (prefers-reduced-motion: reduce) {

    .mana-toggle[aria-pressed="true"]::before,
    .mana-toggle[aria-pressed="true"]::after,
    .filters-toggle.active::before,
    .filters-toggle.active::after,
    .search-box:has(input:not(:placeholder-shown))::before,
    .search-box:has(input:not(:placeholder-shown))::after {
        animation: none;
    }
}

.mana-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.card-filters {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem 0;
    container-type: scroll-state;
}

/* Backdrop only once stuck over the cards, so the embers show through at the top of the page. */
.card-filters::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: rgb(20 22 26 / 0.8);
    backdrop-filter: blur(8px);
    transition: opacity 0.2s ease;
}

@container not scroll-state(stuck: top) {
    .card-filters::before {
        opacity: 0;
    }
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}

.search-box {
    position: relative;
    /* Ends at the panel's right edge (minus the 3rem filter button and the 1rem gap). */
    flex: 0 1 calc(var(--panel-w) - 4rem);
    border-radius: 999px;
    font-size: 1.25rem;
}

.search-box input {
    display: block;
    width: 100%;
    height: 3rem;
    padding-inline: 1.25rem 3rem;
    border-radius: inherit;
    outline: none;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.search-box input:focus {
    border-color: #4a505c;
    background: #2a2e37;
}

.search-box input::-webkit-search-cancel-button {
    display: none;
}

.search-clear {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    display: grid;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border-radius: 50%;
    background: none;
    color: var(--muted);
    transform: translateY(-50%);
    transition: color 0.15s ease;
}

.search-clear:hover,
.search-clear:focus-visible {
    color: var(--text);
}

.search-clear:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Clear and help share one slot: help while empty (and focused), clear once there's text. */
.search-box:has(input:placeholder-shown) .search-clear:not(.search-help),
.search-box:has(input:not(:placeholder-shown)) .search-help,
.search-box:not(:focus-within) .search-help {
    display: none;
}

.help {
    width: min(46rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 0;
    border: 1px solid #333842;
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 12px 32px rgb(0 0 0 / 0.5);
}

.help::backdrop {
    background: rgb(0 0 0 / 0.6);
    backdrop-filter: blur(2px);
}

.help .sheet-head {
    position: sticky;
    top: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid #333842;
    background: var(--panel);
}

.help h2,
.help h3 {
    margin: 0;
    font-family: Beleren, system-ui, sans-serif;
    font-weight: normal;
}

.help h2 {
    font-size: 1.5rem;
}

.help h3 {
    margin: 1.25rem 0 0.5rem;
    color: var(--accent);
    font-size: 1.15rem;
}

.help-body {
    padding: 0.25rem 1.25rem 1.25rem;
}

.help p {
    margin: 0.5rem 0;
}

.help code {
    padding: 0.05em 0.35em;
    border-radius: 4px;
    background: #16181d;
    color: #ffc04d;
    font-size: 0.9em;
    white-space: nowrap;
}

.help table {
    width: 100%;
    border-collapse: collapse;
}

.help td {
    padding: 0.3rem 0.5rem;
    border-top: 1px solid #2c3039;
    vertical-align: top;
}

.help td:first-child {
    width: 1%;
    white-space: nowrap;
}

.help td:nth-child(3) {
    text-align: right;
}

.help-cols {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 1.5rem;
}

.help-examples {
    display: grid;
    gap: 0.4rem;
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--muted);
}

.help-examples button {
    margin-right: 0.5rem;
    padding: 0;
    background: none;
    font-weight: normal;
}

.help-examples button:hover code {
    background: #383d48;
}

.help-examples button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 700px) {
    .help-cols {
        grid-template-columns: 1fr;
    }

    .help td:nth-child(3) {
        display: none;
    }
}

/* 2.5rem x 1.2em mana circle = the 3rem search box height. */
.toggle-row {
    display: flex;
    gap: 0.4em;
    font-size: 2.5rem;
}

/* Divider between the two quick filters. */
.filter-bar .mana-values {
    padding-left: 1rem;
    border-left: 1px solid #333842;
}

.filters-toggle {
    flex: none;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border-radius: 50%;
    background: none;
    font-size: 1.25rem;
    transition: filter 0.15s ease;
}

.filters-disk {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0.5rem;
    border: 1px solid #4a505c;
    border-radius: 50%;
    background: #2a2e37;
    color: var(--text);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

/* Same as the zoom buttons when closed. */
.filters-toggle:hover .filters-disk {
    border-color: #646b79;
    background: #383d48;
}

/* Neutral "on" look while the panel is open (orange means a filter is set). */
.filters-toggle[aria-expanded="true"] .filters-disk,
.filters-toggle[aria-expanded="true"]:hover .filters-disk {
    border-color: #8a93a3;
    background: #3d4250;
    color: #fff;
}

.filters-disk path,
.filters-disk rect {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

/* Open: the sliders fold into a chevron pointing at the panel (close). */
.filters-toggle[aria-expanded="true"] .filters-disk path:nth-of-type(1) {
    transform: translateY(3px) rotate(-45deg) scaleX(0.53);
}

.filters-toggle[aria-expanded="true"] .filters-disk path:nth-of-type(2) {
    transform: scaleX(0);
    opacity: 0;
}

.filters-toggle[aria-expanded="true"] .filters-disk path:nth-of-type(3) {
    transform: translateY(-3px) rotate(45deg) scaleX(0.53);
}

.filters-toggle[aria-expanded="true"] .filters-disk rect {
    transform: scale(0);
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {

    .filters-disk path,
    .filters-disk rect {
        transition: none;
    }
}

.results-layout {
    display: flex;
    align-items: flex-start;
}

.results {
    flex: 1;
    min-width: 0;
    /* The card gaps scale with this width (cqw), so they shrink with the menu open. */
    container-type: inline-size;
}

.filter-panel {
    position: sticky;
    top: var(--bar-h, 4.5rem);
    display: flex;
    flex: none;
    flex-direction: column;
    width: var(--panel-w);
    height: calc(100vh - var(--panel-top, 4.5rem) - max(1rem, var(--panel-bottom, 0px)));
    border: 1px solid #333842;
    border-radius: 12px;
    background: var(--panel);
    overflow: hidden;
    /* Scrolling past the menu's ends doesn't scroll the page. */
    overscroll-behavior: contain;
}

.filter-panel[hidden] {
    display: none;
}

.sheet-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Radius = half the header height: a pill when closed, a rounded box when open. */
.filter-panel details {
    flex: none;
    border: 1px solid #4a505c;
    border-radius: 1.3rem;
    background: #16181d;
    overflow: hidden;
}

.filter-panel details[open]>summary {
    border-bottom: 1px solid #333842;
}

/* Same glow as the mana toggles, drawn as a border gradient since overflow: hidden clips pseudo-elements. */
.filter-panel details:has(.option[aria-pressed="true"]:not([data-format=""], [data-game=""])) {
    border-color: transparent;
    background:
        linear-gradient(#16181d, #16181d) padding-box,
        conic-gradient(from var(--glow-angle), #ff8a1a, #ffc04d 10%, #ff8a1a 22%, #ff7a12 40%, #ffd166 52%, #ff8a1a 64%, #ff7a12 80%, #ffb340 88%, #ff8a1a) border-box;
    box-shadow: 0 0 5px rgb(255 110 20 / 0.45);
    animation: glow-spin 7s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
    .filter-panel details {
        animation: none;
    }
}

.filter-panel summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 1rem;
    font-family: Beleren, system-ui, sans-serif;
    font-size: 1.2rem;
    list-style: none;
    cursor: pointer;
}

/* Takes the room left before the chevron, which the icons are fitted to. */
.summary-icons {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    margin: 0 0.75rem 0 0.5rem;
    overflow: hidden;
    font-size: 1rem;
}

.summary-icons>* {
    flex: none;
}

.summary-icons .wildcard {
    width: 1.2rem;
    height: 1.2rem;
}

.summary-icons .type-glyph {
    color: inherit;
}

/* Room for the chips' focus outline. */
.summary-icons.open {
    gap: 4px;
    padding: 2px;
}

.set-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.set-chip img {
    width: 1.2rem;
    height: 1.2rem;
    object-fit: contain;
    filter: invert(1) brightness(0.85);
}

button.set-chip {
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: rgb(255 110 20 / 0.18);
    color: inherit;
    font: inherit;
    /* Shorter than the title's line, so the first chip doesn't grow the header. */
    line-height: 1;
    transition: background-color 0.15s ease;
}

button.set-chip img {
    width: 1rem;
    height: 1rem;
}

button.set-chip:hover {
    background: rgb(255 110 20 / 0.32);
}

button.set-chip:focus-visible {
    outline: 2px solid var(--accent);
}

.filter-panel summary::-webkit-details-marker {
    display: none;
}

.filter-panel summary::after {
    content: "";
    width: 0.45em;
    height: 0.45em;
    border: solid currentColor;
    border-width: 2px 2px 0 0;
    transform: translateY(25%) rotate(-45deg);
    transition: transform 0.15s ease;
}

.filter-panel details:not([open])>summary::after {
    transform: translateY(-25%) rotate(135deg);
}

.option-grid,
.option-list {
    display: grid;
    gap: 2px;
    padding: 6px;
}

.option-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.option-grid>[data-value="basic"] {
    grid-column: 1 / -1;
}

.option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    padding: 6px 12px;
    border-radius: 999px;
    background: #16181d;
    color: var(--text);
    font-weight: 500;
    text-align: left;
    transition: background-color 0.15s ease;
}

.option[hidden] {
    display: none;
}

.list-search {
    position: relative;
    border-bottom: 1px solid #333842;
}

.list-search input {
    display: block;
    width: 100%;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    border: 0;
    border-radius: 0;
    background: #1c1f25;
    outline: none;
    transition: background-color 0.15s ease;
}

.list-search input:focus {
    background: #2a2e37;
}

.list-search input::-webkit-search-cancel-button {
    display: none;
}

.list-search-clear {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    display: grid;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    background: none;
    color: var(--muted);
    transform: translateY(-50%);
    transition: color 0.15s ease;
}

.list-search-clear:hover,
.list-search-clear:focus-visible {
    color: var(--text);
}

.list-search-clear:focus-visible {
    outline: 2px solid var(--accent);
}

.list-search:has(input:placeholder-shown) .list-search-clear {
    display: none;
}

.option:hover {
    background: #262a32;
}

.option[aria-pressed="true"] {
    background: linear-gradient(90deg, rgb(255 110 20 / 0.18), rgb(255 110 20 / 0) 90%);
    color: #ffc04d;
}

.option:focus-visible,
.filters-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Inside the box, so it isn't clipped by overflow: hidden. */
.filter-panel summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.option-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
}

/* Scryfall set icons are black SVGs. */
.option-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: invert(1) brightness(0.85);
}

.option-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.type-glyph {
    color: var(--muted);
    font-family: Mana;
    font-size: 1.3rem;
    font-weight: normal;
    line-height: 1;
}

.option[aria-pressed="true"] .type-glyph {
    color: inherit;
}

/* MTG Arena wildcard emblem (Mana font's rarity glyph) in the rarity's metal. */
.wildcard {
    width: 1.5rem;
    height: 1.5rem;
    mask: url("/symbols/wildcard.svg") center / contain no-repeat;
}

.wildcard.common {
    background: linear-gradient(#ffffff, #d9dce1);
}

.wildcard.uncommon {
    background: linear-gradient(#e3f2fa, #6f8b99);
}

.wildcard.rare {
    background: linear-gradient(#f6e3a1, #a8862f);
}

.wildcard.mythic {
    background: linear-gradient(#ffb45a, #c0391b);
}

.icon-button {
    display: grid;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0.6rem;
    border-radius: 50%;
    background: #2a2e37;
    color: var(--text);
}

/* Rows that don't fit in the bar (classes set by fitBar() in cards.js) move to the panel. */
.filter-panel .sheet-only,
.colors-in-panel .card-filters .colors,
.mv-in-panel .card-filters .mana-values {
    display: none;
}

.colors-in-panel .filter-panel .colors,
.mv-in-panel .filter-panel .mana-values {
    display: grid;
    /* 8 columns (the mana values) so the 7 colors line up with them. */
    grid-template-columns: repeat(8, 1.2em);
    justify-content: space-between;
}

@media (max-width: 700px) {
    main.wide {
        --page-pad: 0.75rem;
        padding-inline: var(--page-pad);
    }

    .filter-bar {
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    .search-box {
        flex: 1 1 0;
        min-width: 0;
        font-size: 1.1rem;
    }

    .card-size {
        margin-left: 0;
    }

    /* Takes the whole screen below the bar until the filter button is clicked again. */
    .filter-panel {
        position: fixed;
        inset: var(--bar-bottom, 4.5rem) 0 0;
        z-index: 1;
        width: auto;
        height: auto;
        border: 0;
        border-top: 1px solid var(--panel);
        border-radius: 0;
        background: var(--bg);
    }

    body:has(.filter-panel:not([hidden])) {
        overflow: hidden;
    }

    /* Sized so the 8 mana values fit one row; colors match. */
    .filter-panel .toggle-row {
        font-size: clamp(1.25rem, 7vw, 2.5rem);
    }
}

#status:empty {
    display: none;
}

/* Until the last page, keeps the footer out of view so it doesn't push the sticky side menu up. */
#more {
    height: 100vh;
}

.card-grid {
    /* Scales with card size: bigger cards (fewer columns) get more room. */
    --gap-y: calc(17cqw / var(--cols, 5));
    --gap-x: calc(14cqw / var(--cols, 5));
    display: grid;
    grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr));
    gap: var(--gap-y) var(--gap-x);
    /* Outer space matches the gaps; the page padding already provides part of the sides. */
    padding: var(--gap-y) max(0px, var(--gap-x) - var(--page-pad, 0px));
    transition: opacity 0.15s;
}

/* Previous results while a new search loads; the delay keeps fast responses from flickering. */
.card-grid.stale {
    opacity: 0.5;
    transition-delay: 0.1s;
}

/* Next to the open menu there's no page padding on the left. */
.filter-panel:not([hidden])+.results .card-grid {
    padding-left: var(--gap-x);
}

.filter-panel:not([hidden])+.results .card-grid.single {
    padding-left: var(--page-pad, 0px);
}

/* One card per row: only the page padding on the sides, aligned with the bar. */
.card-grid.single {
    /* Same vertical-to-horizontal ratio as the other sizes. */
    --gap-y: calc(var(--page-pad, 0px) * 17 / 14);
    padding-inline: 0;
}

.card-size {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.card-size button {
    display: grid;
    width: 3rem;
    height: 3rem;
    padding: 0.7rem;
    border: 1px solid #4a505c;
    border-radius: 50%;
    background: #2a2e37;
    color: var(--text);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.card-size button:hover:not(:disabled) {
    border-color: #646b79;
    background: #383d48;
}

.card-size button:disabled {
    color: var(--muted);
    opacity: 0.5;
    cursor: default;
}

.card-size button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.card-tile {
    position: relative;
    isolation: isolate;
    aspect-ratio: 488 / 680;
    border-radius: 4.75% / 3.5%;
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.5);
    transition: box-shadow 0.2s ease;
}

/* Same glow as a selected mana toggle: two counter-rotating blurred gradient rings behind the card
   (the tile has no background so they show through). */
.card-tile::before,
.card-tile::after {
    content: "";
    position: absolute;
    inset: -3px;
    z-index: -1;
    border-radius: 4.75% / 3.5%;
    filter: blur(1.5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.card-tile::before {
    background: conic-gradient(from var(--glow-angle), #ff8a1a, #ffc04d 10%, #ff8a1a 22%, #ff7a12 40%, #ffd166 52%, #ff8a1a 64%, #ff7a12 80%, #ffb340 88%, #ff8a1a);
}

.card-tile::after {
    background: conic-gradient(from var(--glow-angle), transparent, rgb(255 235 160 / 0.9) 8%, transparent 18%, transparent 55%, rgb(255 225 130 / 0.8) 63%, transparent 72%);
}

@media (hover: hover) {

    .card-tile:hover::before,
    .card-tile:hover::after {
        opacity: 1;
        transition: none;
    }

    .card-tile:hover::before {
        animation: glow-spin 7s linear infinite;
    }

    .card-tile:hover::after {
        animation: glow-spin 11s linear infinite reverse;
    }

    .card-tile:hover {
        box-shadow: 0 4px 12px rgb(0 0 0 / 0.5), 0 0 10px 3px rgb(255 110 20 / 0.5);
        transition: none;
    }
}

@media (prefers-reduced-motion: reduce) {

    .card-tile:hover::before,
    .card-tile:hover::after {
        animation: none;
    }
}

.card-tile img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: var(--panel);
    object-fit: cover;
}

.card-placeholder {
    display: grid;
    place-items: center;
    height: 100%;
    padding: 1rem;
    border-radius: inherit;
    background: var(--panel);
    text-align: center;
}

.card-preview {
    position: fixed;
    z-index: 10;
    aspect-ratio: 488 / 680;
    border-radius: 4.75% / 3.5%;
    box-shadow: 0 6px 16px rgb(0 0 0 / 0.8), 0 20px 70px 10px rgb(0 0 0 / 0.9);
    pointer-events: none;
    animation: preview-in var(--preview-in);
}

.card-preview img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: var(--panel);
}

@keyframes preview-in {
    from {
        opacity: 0;
        scale: var(--scale-from);
        translate: var(--slide-from, 0);
    }
}

.card-keywords {
    /* Room for the tooltips' shadows, which overflow: hidden would clip. */
    --shadow-room: 24px;
    position: fixed;
    z-index: 10;
    display: flex;
    flex-direction: column;
    margin: calc(-1 * var(--shadow-room));
    padding: var(--shadow-room);
    overflow: hidden;
    pointer-events: none;
    /* Moves with the card's edge, so the tooltips come out right from it. */
    animation: keywords-follow var(--preview-in);
}

.card-keywords[hidden] {
    display: none;
}

/* Below the tooltips, which they slide out under. */
.card-parts {
    --shadow-room: 24px;
    position: fixed;
    z-index: 9;
    margin: calc(-1 * var(--shadow-room));
    padding: var(--shadow-room);
    overflow: hidden;
    pointer-events: none;
    animation: keywords-follow var(--preview-in);
}

.card-parts[hidden] {
    display: none;
}

.card-parts-row {
    display: flex;
    width: max-content;
    animation: keyword-in var(--preview-in);
}

.card-part {
    margin: 0;
}

/* A tab above the card, like MTG Arena's. */
.card-part figcaption {
    width: fit-content;
    max-width: 100%;
    height: var(--part-header);
    margin: 0 auto;
    padding: 6px 0.8em 0;
    overflow: hidden;
    border-radius: 10px 10px 0 0;
    background: #000;
    /* Smaller on small cards, so the label still fits. */
    font: min(1.6rem, var(--part-width) / 13)/calc(var(--part-header) - 6px) Beleren, serif;
    font-variant: small-caps;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--text);
}

.card-part img {
    display: block;
    width: 100%;
    aspect-ratio: 488 / 680;
    border-radius: 4.75% / 3.5%;
    background: var(--panel);
    box-shadow: 0 6px 16px rgb(0 0 0 / 0.8);
}

.card-keyword {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 14px 20px;
    border-radius: 8px;
    background: #1a1d23;
    /* The parts' shadow, so equal gaps look equal. */
    box-shadow: 0 6px 16px rgb(0 0 0 / 0.8);
    animation: keyword-in var(--preview-in);
}

.keyword-icon {
    flex: none;
    width: 1.6em;
    font: 2.3rem/1 Mana;
    text-align: center;
    color: var(--accent);
}

/* Arena's icons are black SVGs, drawn in the text color like the glyphs. */
.keyword-image {
    height: 1em;
    background: currentColor;
    mask: var(--icon) center / contain no-repeat;
}

.tap-symbol {
    font-family: Mana;
    font-style: normal;
}

.card-keyword h3 {
    margin: 0 0 4px;
    font: 1.55rem Beleren, serif;
    color: var(--text);
}

.card-keyword p {
    margin: 0;
    font-size: 1.3rem;
    line-height: 1.45;
    font-style: italic;
    color: #d0d3d9;
    white-space: pre-line;
}

@keyframes keywords-follow {
    from {
        translate: var(--follow-from, 0);
    }
}

@keyframes keyword-in {
    from {
        opacity: var(--fade-from, 0);
        translate: var(--slide-from, 0);
    }
}

@media (prefers-reduced-motion: reduce) {

    .card-preview,
    .card-keywords,
    .card-keyword,
    .card-parts,
    .card-parts-row {
        animation: none;
    }
}

@media (max-width: 700px) {
    .tagline {
        display: none;
    }
}