html, body {
    height: 100%;
    margin: 0;
    background: #0b0b12;
    color: #f1f1f1;
}

#app {
    height: 100%;
}

/* MudMainContent does not always pick up the fixed app bar height; pin it. */
.mud-main-content {
    padding-top: 48px !important;
}

.brand {
    font-weight: 700;
    letter-spacing: .12em;
}

/* Library: a carousel of system logos, a title panel for the selected system, and a shelf of box art.
   --system-color comes from the catalog (per console) and tints the backdrop, pills and generic boxes. */
.library {
    --system-color: #ff6d00;
    min-height: calc(100vh - 48px);
    background:
        radial-gradient(1400px 620px at 50% -20%, color-mix(in srgb, var(--system-color) 60%, transparent), transparent 72%),
        linear-gradient(180deg, color-mix(in srgb, var(--system-color) 18%, #121220) 0%, #0b0b12 55%);
    padding: 0 0 32px;
}

/* System carousel: the consoles stand on a ring seen a little from above, the selected one at the front.
   --ring (set by Library.razor, animated thanks to @property) turns the ring; each logo has its seat --a and works
   out its place on the circle with sin() and cos(), so a turn carries every logo along the circle the short way
   round, nearer ones bigger and brighter. Library.razor and js/library.js only ever change --ring. */
@property --ring { syntax: "<angle>"; inherits: true; initial-value: 0deg; }

.system-carousel {
    --rx: min(34vw, 440px); /* the ring is an ellipse: wide across, shallower in depth */
    --rz: 220px;
    --item-w: 230px;
    --item-h: 128px;
    position: relative;
    height: 224px;
    overflow: hidden;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    touch-action: pan-y;
    user-select: none;
    transition: --ring .6s cubic-bezier(.22, .8, .3, 1);
}

.carousel-stage { position: absolute; inset: 0; perspective: 900px; perspective-origin: 50% 15%; }

.carousel-item {
    --tab-color: #ff6d00;
    --t: calc(var(--a) + var(--ring));
    --front: calc((1 + cos(var(--t))) / 2); /* 1 at the front, 0 straight behind */
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--item-w);
    height: var(--item-h);
    margin: calc(var(--item-h) / -2) 0 0 calc(var(--item-w) / -2);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, .08);
    background: rgba(18, 18, 30, .55);
    color: inherit;
    text-decoration: none;
    transform: translate3d(calc(sin(var(--t)) * var(--rx)), calc((1 - var(--front)) * -46px), calc((cos(var(--t)) - 1) * var(--rz)))
        scale(calc(.7 + .38 * var(--front) * var(--front) * var(--front)));
    opacity: calc(.08 + .92 * var(--front) * var(--front));
    z-index: calc(var(--front) * 100);
    transition: background-color .3s, border-color .3s, box-shadow .3s;
}

.carousel-item:hover { border-color: rgba(255, 255, 255, .25); }

.carousel-item.selected {
    background: color-mix(in srgb, var(--tab-color) 30%, rgba(14, 14, 24, .85));
    border-color: color-mix(in srgb, var(--tab-color) 70%, white 10%);
    box-shadow: 0 10px 34px rgba(0, 0, 0, .55), 0 0 26px color-mix(in srgb, var(--tab-color) 55%, transparent);
}

.carousel-logo {
    width: 100%;
    height: 58px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .7));
    pointer-events: none;
}

.carousel-name {
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    opacity: .75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.carousel-item.selected .carousel-name { opacity: 1; font-weight: 600; }

.carousel-arrow.mud-icon-button {
    position: absolute;
    top: 50%;
    z-index: 200;
    transform: translateY(-50%);
    background: rgba(10, 10, 18, .55);
    border: 1px solid rgba(255, 255, 255, .14);
    color: #fff;
}

.carousel-arrow.mud-icon-button:hover { background: rgba(10, 10, 18, .85); }
.carousel-prev { left: max(12px, calc(50% - var(--rx) - var(--item-w) / 2 - 40px)); }
.carousel-next { right: max(12px, calc(50% - var(--rx) - var(--item-w) / 2 - 40px)); }

@media (max-width: 700px) {
    .system-carousel { --rx: 32vw; --rz: 140px; --item-w: 150px; --item-h: 92px; height: 160px; }
    .carousel-logo { height: 42px; }
    .carousel-name { font-size: 10px; }
}

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

/* Browsers without CSS trigonometry get a plain row of logos instead of the ring. */
@supports not (width: calc(sin(90deg) * 1px)) {
    .carousel-stage { position: static; display: flex; gap: 8px; padding: 12px 64px; overflow-x: auto; height: 100%; box-sizing: border-box; align-items: center; }
    .carousel-item { position: static; margin: 0; flex: 0 0 auto; transform: none; opacity: .6; }
    .carousel-item.selected { opacity: 1; }
}

/* Everything under the carousel. A column, so a narrow window can put the facts above the search (order). */
.system-view { display: flex; flex-direction: column; }

/* The right-hand side of the header is kept clear for the search box, which hangs from the dock above. */
.system-header {
    box-sizing: border-box;
    min-height: 106px;
    padding: 22px 400px 14px 28px;
}

.system-facts { min-width: 0; }

.system-blurb {
    margin: 0 0 12px;
    font-size: 15px;
    line-height: 1.45;
    color: #e6e6f0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
    max-width: 70ch;
}

.system-pills { display: flex; flex-wrap: wrap; gap: 10px; }

.pill {
    display: inline-flex;
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 6px;
    overflow: hidden;
    font-size: 13px;
    line-height: 1;
}

.pill-label { padding: 7px 10px; background: rgba(255, 255, 255, .9); color: #111; font-weight: 500; }
.pill-value { padding: 7px 12px; background: rgba(0, 0, 0, .35); color: #fff; font-variant-numeric: tabular-nums; }

/* The New pill is a button that searches for the recent additions; it wears the badge's yellow. */
.pill-new { cursor: pointer; padding: 0; font: inherit; border-color: #ffc400; }
.pill-new .pill-label { background: #ffc400; color: #5a1800; font-weight: 700; }
.pill-new:hover .pill-label, .pill-new:focus-visible .pill-label { background: #ffe066; }
.pill-new:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* The Homebrew pill searches for the tagged homebrews; it wears the tag's cyan. */
.pill-homebrew { cursor: pointer; padding: 0; font: inherit; border-color: #7fd6f2; }
.pill-homebrew .pill-label { background: #7fd6f2; color: #06303d; font-weight: 700; }
.pill-homebrew:hover .pill-label, .pill-homebrew:focus-visible .pill-label { background: #b3e8f8; }
.pill-homebrew:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* Search dock: a sticky anchor with no height, first in the column, and the search box hangs from it into the
   header's right-hand side. Sticky keeps the anchor (and so the box) on screen for as long as the shelf is: the
   box rests in the header, then rides 8px under the app bar. "stuck" (js/library.js, on scroll) gives it a
   backing while it rides over the covers. Right of it, 40px stay free for the letter rail. */
.search-dock { position: sticky; top: 42px; height: 0; z-index: 20; }
.system-search {
    position: absolute;
    top: 14px;
    right: 40px;
    width: 332px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    padding: 8px 10px 4px;
    border: 1px solid transparent;
    border-radius: 10px;
    transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.search-dock.stuck .system-search {
    background: rgba(14, 14, 24, .9);
    backdrop-filter: blur(8px);
    border-color: rgba(255, 255, 255, .14);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.system-search .mud-input-control { width: 100%; flex: 0 0 auto; }
.system-search-count { opacity: .7; }

/* Shelf and letter rail side by side. The rail is sticky too, so the letters stay beside the shelf all the way
   down; they shrink to fit the room there is (js/library.js sets max-height to the window below the rail's top;
   the one here is the fallback). A click jumps to the first box wearing that data-letter. */
.shelf-wrap { display: flex; align-items: flex-start; }
.shelf-col { flex: 1 1 auto; min-width: 0; }

/* Recently played: a row of up to five above the shelf, on a grid of its own with the shelf's columns, so its
   tiles are the size of every other tile. Its two headings ("Recently played", "All games") line up with the
   covers and run a rule out to the right. */
.shelf-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 12px 10px 2px 28px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: #e2e2ee;
}
.shelf-heading::after { content: ""; flex: 1 1 auto; height: 1px; background: rgba(255, 255, 255, .16); }
.recent .shelf + .shelf-heading { padding-top: 16px; }
.letter-rail {
    position: sticky;
    top: 56px;
    z-index: 10;
    flex: 0 0 24px;
    margin-right: 6px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 64px);
    max-height: calc(100dvh - 64px);
}
.letter-rail button {
    flex: 0 1 22px;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: none;
    color: #e2e2ee;
    font: inherit;
    font-size: clamp(8px, 1.6vh, 11px);
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}
.letter-rail button:hover:not(:disabled), .letter-rail button:focus-visible { background: var(--system-color); color: #fff; outline: none; }
.letter-rail button:disabled { opacity: .22; cursor: default; }

/* The shelf. A shelf only ever shows one system, and each system's boxes share one shape (NES, Genesis and
   Atari are tall, SNES and N64 are wide, GBA is square), so the tile takes the system's shape via --box-aspect
   and the columns widen for the wide ones via --box-min. The generic sleeve fills the same shape. Ratios are the
   medians of the libretro covers in the cache. Every tile on a shelf is exactly that shape: a cover close to it is
   cropped to it, one further off (arcade flyers vary, and some are landscape title screens) is shown whole on a
   blurred copy of itself (.loose, set by library.js). */
.shelf {
    --box-aspect: 0.7;
    --box-min: 150px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--box-min), 1fr));
    gap: 18px 14px;
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px 0 28px;
    scroll-margin-top: 56px;
}

[data-system="snes"], [data-system="n64"] { --box-aspect: 1.4; --box-min: 210px; }
[data-system="gba"], [data-system="psx"] { --box-aspect: 1; --box-min: 170px; }
[data-system="gb"], [data-system="gbc"], [data-system="neogeo"] { --box-aspect: 1.25; --box-min: 190px; }
[data-system="pcengine"] { --box-aspect: 0.85; --box-min: 160px; }
[data-system="atari2600"] { --box-aspect: 0.735; }
[data-system="fba"], [data-system="mame-libretro"], [data-system="mame-mame4all"] { --box-aspect: 0.76; --box-min: 150px; }

.box {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: inherit;
    text-decoration: none;
    transition: transform .12s ease-out;
    scroll-margin-top: 64px; /* a jump from the letter rail lands clear of the app bar */
}

.box:hover, .box:focus-visible { transform: translateY(-4px) scale(1.04); z-index: 1; outline: none; }
.box:hover .box-cover, .box:focus-visible .box-cover,
.box-generic:hover .box-cover, .box-generic:focus-visible .box-cover { box-shadow: 0 10px 28px rgba(0, 0, 0, .7), 0 0 0 2px var(--system-color); }

/* The frame is the tile: on the shelf the cover fills it (below) and the generic sleeve paints it. Positioned so
   the NEW sunburst can sit on its corner. On the pick panel the frame follows the cover instead (.pick). */
.box-cover {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    aspect-ratio: var(--box-aspect);
    width: 100%;
    border-radius: 4px;
    transition: box-shadow .12s ease-out;
}

/* NEW sunburst: a game added in the last 30 days (Game.IsNew). A 16-point star inside the top-right corner of the
   cover (inside, so the shelf's row above never clips it), drawn by the ::before so the element itself can carry
   the drop shadow (clip-path would clip a shadow on the same element). Scaled up on the pick panel. */
.box-new {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 2;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    transform: rotate(14deg);
    font-size: 11.5px;
    font-weight: 800;
    letter-spacing: .04em;
    color: #5a1800;
    text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .65));
    pointer-events: none;
    user-select: none;
}

.box-new::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: radial-gradient(circle at 40% 35%, #fff3a0 0%, #ffd23f 45%, #ffa000 100%);
    clip-path: polygon(50.0% 0.0%, 57.6% 11.7%, 69.1% 3.8%, 71.7% 17.6%, 85.4% 14.6%, 82.4% 28.3%, 96.2% 30.9%, 88.3% 42.4%, 100.0% 50.0%, 88.3% 57.6%, 96.2% 69.1%, 82.4% 71.7%, 85.4% 85.4%, 71.7% 82.4%, 69.1% 96.2%, 57.6% 88.3%, 50.0% 100.0%, 42.4% 88.3%, 30.9% 96.2%, 28.3% 82.4%, 14.6% 85.4%, 17.6% 71.7%, 3.8% 69.1%, 11.7% 57.6%, 0.0% 50.0%, 11.7% 42.4%, 3.8% 30.9%, 17.6% 28.3%, 14.6% 14.6%, 28.3% 17.6%, 30.9% 3.8%, 42.4% 11.7%);
}

.pick .box-new { top: 10px; right: 10px; width: 96px; height: 96px; font-size: 23px; }

/* Homebrew tag: a small cyan label in the top-left corner of the cover (Game.Homebrew). Moved right on the NES
   sleeves so it clears their pixel border. */
.box-homebrew {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    padding: 3px 6px 2px;
    border-radius: 3px;
    background: rgba(6, 48, 61, .85);
    border: 1px solid rgba(127, 214, 242, .7);
    color: #b3e8f8;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: .09em;
    text-transform: uppercase;
    pointer-events: none;
    user-select: none;
}

.box.box-generic[data-system="nes"] .box-homebrew { left: 30px; }
.pick .box-homebrew { top: 12px; left: 12px; padding: 6px 10px 5px; font-size: 13px; }
.pick.box-generic[data-system="nes"] .box-homebrew { left: 46px; }

.pick-note { margin: 6px 0 0; font-size: 13px; color: #b3e8f8; opacity: .85; max-width: 46ch; }

.box-cover > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 3px;
}

/* A shelf tile with art: the frame carries the shadow and clips the cover to the system's shape. */
.box:not(.box-generic) .box-cover {
    overflow: hidden;
    background: #0e0e16;
    box-shadow: 0 6px 16px rgba(0, 0, 0, .55);
}

/* A cover too far from that shape to crop (library.js, fit): all of it, on a blurred, darkened copy of itself that
   fills the rest of the tile. --art is the cover's URL. */
.box-cover.loose > img { position: relative; object-fit: contain; border-radius: 0; }
.box:not(.box-generic) .box-cover.loose::before {
    content: "";
    position: absolute;
    inset: -14%;
    background: var(--art) center / cover no-repeat;
    filter: blur(12px) brightness(.5) saturate(1.2);
}

.box-title {
    font-size: 12.5px;
    line-height: 1.25;
    min-height: 2.5em; /* room for two lines whether or not the title needs them, so every tile is the same height */
    text-align: center;
    opacity: .85;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Generic box for games without art: a sleeve styled after the console's real packaging, with the system logo
   on top and the title on the lower half. Each system sets its own base, band and pattern below; the defaults
   are a dark sleeve in the system colour. --gc-* are the knobs: base (background), band (the accent stripe),
   pattern (an overlay such as the Genesis grid or the NES pixel border), band-size and band-pos. */
.box-generic .box-cover {
    --gc-base: linear-gradient(170deg, color-mix(in srgb, var(--system-color) 45%, #1c1c28) 0%, #15151f 60%, #0e0e15 100%);
    --gc-band: linear-gradient(90deg, var(--system-color), color-mix(in srgb, var(--system-color) 55%, #000));
    --gc-pattern: none;
    --gc-pattern-size: auto;
    --gc-pattern-repeat: repeat;
    --gc-band-size: 100% 10px;
    --gc-band-pos: left top;
    --gc-text: #fff;
    --gc-logo-bg: transparent;
    align-items: stretch;
    position: relative;
    overflow: hidden;
    color: var(--gc-text);
    background-image: var(--gc-band), var(--gc-pattern), var(--gc-base);
    background-size: var(--gc-band-size), var(--gc-pattern-size), auto;
    background-position: var(--gc-band-pos), left top, left top;
    background-repeat: no-repeat, var(--gc-pattern-repeat), no-repeat;
    border: 1px solid rgba(255, 255, 255, .12);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .55);
}

.box:not(.box-generic) .box-generic-label, .pick:not(.box-generic) .box-generic-label { display: none; }

.box-generic-label {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 18px 10px 10px;
    box-sizing: border-box;
}

.box-generic-logo {
    align-self: center;
    height: 34px;
    max-width: 82%;
    object-fit: contain;
    padding: 3px 6px;
    border-radius: 3px;
    background: var(--gc-logo-bg);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .7));
}

[data-system="snes"] .box-generic-label, [data-system="n64"] .box-generic-label,
[data-system="gb"] .box-generic-label, [data-system="gbc"] .box-generic-label, [data-system="neogeo"] .box-generic-label { padding-top: 12px; }
[data-system="snes"] .box-generic-logo, [data-system="n64"] .box-generic-logo,
[data-system="gb"] .box-generic-logo, [data-system="gbc"] .box-generic-logo, [data-system="neogeo"] .box-generic-logo { height: 28px; }
[data-system="snes"] .box-generic-title, [data-system="n64"] .box-generic-title,
[data-system="gb"] .box-generic-title, [data-system="gbc"] .box-generic-title, [data-system="neogeo"] .box-generic-title { -webkit-line-clamp: 3; margin-bottom: 10px; }

.box-generic-title {
    font-weight: 700;
    font-size: 14px;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: auto;
    margin-bottom: 14px;
}

/* Nintendo Entertainment System: black box, grey pixel border down the left, red seal stripe along the bottom. */
.box[data-system="nes"] .box-cover, .pick[data-system="nes"] .box-cover {
    --gc-base: linear-gradient(180deg, #1a1a1a 0%, #050505 100%);
    --gc-pattern: repeating-linear-gradient(180deg, #d9d9d9 0 4px, #8a8a8a 4px 6px, #2a2a2a 6px 8px);
    --gc-pattern-size: 14px 100%;
    --gc-pattern-repeat: repeat-y;
    --gc-band: linear-gradient(180deg, #e60012, #b0000e);
    --gc-band-size: 100% 8px;
    --gc-band-pos: left bottom;
}
.box[data-system="nes"] .box-generic-label, .pick[data-system="nes"] .box-generic-label { padding-left: 24px; }

/* Super Nintendo: silver-grey box with the purple and blue stripe band. */
.box[data-system="snes"] .box-cover, .pick[data-system="snes"] .box-cover {
    --gc-base: linear-gradient(180deg, #6f6f78 0%, #3b3b45 55%, #26262e 100%);
    --gc-band: linear-gradient(90deg, #4a3fbd 0 25%, #7a4fd8 25% 50%, #3e7ad8 50% 75%, #5c3cb0 75%);
    --gc-band-size: 100% 14px;
    --gc-band-pos: left bottom;
}

/* Nintendo 64: red and black split on the diagonal. */
.box[data-system="n64"] .box-cover, .pick[data-system="n64"] .box-cover {
    --gc-base: linear-gradient(160deg, #c8102e 0%, #c8102e 42%, #1a1a1a 43%, #0a0a0a 100%);
    --gc-band: none;
}

/* Game Boy family: grey sleeve with the red/black stripe (GB), purple with the colour stripe (GBC), purple with
   white rules (GBA). */
.box[data-system="gb"] .box-cover, .pick[data-system="gb"] .box-cover {
    --gc-base: linear-gradient(180deg, #9a9a9a 0%, #5e5e5e 100%);
    --gc-band: linear-gradient(180deg, #c0392b 0 8px, #111 8px);
    --gc-band-size: 100% 22px;
    --gc-band-pos: left bottom;
    --gc-logo-bg: rgba(0, 0, 0, .55);
}
.box[data-system="gbc"] .box-cover, .pick[data-system="gbc"] .box-cover {
    --gc-base: linear-gradient(180deg, #5b2d9e 0%, #2f1a55 100%);
    --gc-band: linear-gradient(90deg, #e84393 0 20%, #f9ca24 20% 40%, #6ab04c 40% 60%, #22a6b3 60% 80%, #be2edd 80%);
    --gc-band-size: 100% 10px;
    --gc-band-pos: left bottom;
}
.box[data-system="gba"] .box-cover, .pick[data-system="gba"] .box-cover {
    --gc-base: linear-gradient(180deg, #4a2f93 0%, #2b1b57 100%);
    --gc-band: linear-gradient(180deg, #fff 0 2px, transparent 2px 10px, #fff 10px 12px);
    --gc-band-size: 100% 12px;
    --gc-band-pos: left 14px;
}

/* Sega: the black grid of the Genesis and Master System cases with the red band; Sega CD and Game Gear blue,
   32X yellow over red. */
.box[data-system="megadrive"] .box-cover, .pick[data-system="megadrive"] .box-cover,
.box[data-system="mastersystem"] .box-cover, .pick[data-system="mastersystem"] .box-cover,
.box[data-system="segacd"] .box-cover, .pick[data-system="segacd"] .box-cover,
.box[data-system="gamegear"] .box-cover, .pick[data-system="gamegear"] .box-cover,
.box[data-system="sega32x"] .box-cover, .pick[data-system="sega32x"] .box-cover {
    --gc-base: linear-gradient(180deg, #1c1c1c 0%, #050505 100%);
    --gc-pattern: linear-gradient(rgba(255, 255, 255, .11) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .11) 1px, transparent 1px);
    --gc-pattern-size: 12px 12px;
    --gc-band: linear-gradient(180deg, #e3001b, #a80014);
    --gc-band-size: 100% 16px;
    --gc-band-pos: left top;
    background-image: var(--gc-band), var(--gc-pattern), var(--gc-base);
    background-size: var(--gc-band-size), var(--gc-pattern-size), var(--gc-pattern-size), auto;
    background-position: left top, left top, left top, left top;
    background-repeat: no-repeat, repeat, repeat, no-repeat;
}
.box[data-system="mastersystem"] .box-cover, .pick[data-system="mastersystem"] .box-cover {
    --gc-base: linear-gradient(180deg, #f2f2f2 0%, #d8d8d8 100%);
    --gc-pattern: linear-gradient(rgba(0, 0, 0, .14) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, .14) 1px, transparent 1px);
    --gc-text: #111;
}
.box[data-system="mastersystem"] .box-generic-title, .pick[data-system="mastersystem"] .box-generic-title { text-shadow: none; }
.box[data-system="segacd"] .box-cover, .pick[data-system="segacd"] .box-cover { --gc-band: linear-gradient(180deg, #2b6cb0, #1d4a7a); }
.box[data-system="gamegear"] .box-cover, .pick[data-system="gamegear"] .box-cover { --gc-band: linear-gradient(180deg, #1565c0, #0d3f7a); }
.box[data-system="sega32x"] .box-cover, .pick[data-system="sega32x"] .box-cover { --gc-band: linear-gradient(180deg, #f5c400 0 8px, #e3001b 8px); }

/* Atari: woodgrain with the rainbow stripes of the silver-label era (2600), silver with the rainbow (7800),
   orange over black (Lynx). */
.box[data-system="atari2600"] .box-cover, .pick[data-system="atari2600"] .box-cover,
.box[data-system="atari7800"] .box-cover, .pick[data-system="atari7800"] .box-cover {
    --gc-base: repeating-linear-gradient(180deg, #5a3414 0 3px, #4a2a10 3px 5px, #5f3a18 5px 9px, #432408 9px 11px);
    --gc-band: linear-gradient(180deg, #d32f2f 0 16.6%, #f57c00 16.6% 33.3%, #fbc02d 33.3% 50%, #388e3c 50% 66.6%, #1976d2 66.6% 83.3%, #7b1fa2 83.3%);
    --gc-band-size: 100% 30px;
    --gc-band-pos: left bottom;
    --gc-logo-bg: rgba(0, 0, 0, .45);
}
.box[data-system="atari7800"] .box-cover, .pick[data-system="atari7800"] .box-cover { --gc-base: linear-gradient(180deg, #b9bcc2 0%, #7c8087 100%); --gc-text: #111; }
.box[data-system="atari7800"] .box-generic-title, .pick[data-system="atari7800"] .box-generic-title { text-shadow: none; }
.box[data-system="atarilynx"] .box-cover, .pick[data-system="atarilynx"] .box-cover {
    --gc-base: linear-gradient(180deg, #1a1a1a 0%, #0a0a0a 100%);
    --gc-band: linear-gradient(180deg, #ff8c00, #e65100);
    --gc-band-size: 100% 26px;
    --gc-band-pos: left bottom;
}

/* PC Engine: white HuCard sleeve with the orange rule. */
.box[data-system="pcengine"] .box-cover, .pick[data-system="pcengine"] .box-cover {
    --gc-base: linear-gradient(180deg, #fafafa 0%, #e6e6e6 100%);
    --gc-band: linear-gradient(180deg, #f07a1a, #d9640a);
    --gc-band-size: 100% 12px;
    --gc-band-pos: left top;
    --gc-text: #1a1a1a;
}
.box[data-system="pcengine"] .box-generic-title, .pick[data-system="pcengine"] .box-generic-title { text-shadow: none; }

/* PlayStation: black jewel case with the four-colour spine. */
.box[data-system="psx"] .box-cover, .pick[data-system="psx"] .box-cover {
    --gc-base: linear-gradient(180deg, #202020 0%, #050505 100%);
    --gc-band: linear-gradient(180deg, #e53935 0 25%, #fdd835 25% 50%, #43a047 50% 75%, #1e88e5 75%);
    --gc-band-size: 10px 100%;
    --gc-band-pos: left top;
}
.box[data-system="psx"] .box-generic-label, .pick[data-system="psx"] .box-generic-label { padding-left: 18px; }

/* Neo Geo: black and gold. */
.box[data-system="neogeo"] .box-cover, .pick[data-system="neogeo"] .box-cover {
    --gc-base: linear-gradient(180deg, #151515 0%, #000 100%);
    --gc-band: linear-gradient(90deg, #d4af37, #8a6d1f);
    --gc-band-size: 100% 6px;
    --gc-band-pos: left bottom;
}

/* Arcade: a lit marquee over a dark cabinet. */
.box[data-system="fba"] .box-cover, .pick[data-system="fba"] .box-cover,
.box[data-system="mame-libretro"] .box-cover, .pick[data-system="mame-libretro"] .box-cover,
.box[data-system="mame-mame4all"] .box-cover, .pick[data-system="mame-mame4all"] .box-cover {
    --gc-base: linear-gradient(180deg, #2b1a05 0%, #140d04 40%, #000 100%);
    --gc-band: radial-gradient(120% 90% at 50% 0%, #ffd54f 0%, #ff8f00 45%, rgba(255, 109, 0, 0) 100%);
    --gc-band-size: 100% 70px;
    --gc-band-pos: left top;
    --gc-pattern: repeating-linear-gradient(90deg, rgba(255, 255, 255, .04) 0 2px, transparent 2px 6px);
    --gc-logo-bg: rgba(0, 0, 0, .35);
}

/* Pick panel: the selected box brought forward over a dimmed shelf as one centred column: the cover scaled up to
   fill the card width, the title under it, Play under that. The generic sleeve rules above apply to .pick too. */
.pick-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(5, 5, 10, .78);
    backdrop-filter: blur(6px);
    animation: pick-fade .15s ease-out;
}

.pick {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    width: min(100%, 480px);
    max-height: calc(100vh - 48px);
    padding: 24px 24px 22px;
    border-radius: 10px;
    outline: none;
    text-align: center;
    background:
        radial-gradient(700px 360px at 50% 0%, color-mix(in srgb, var(--system-color) 35%, transparent), transparent 70%),
        linear-gradient(180deg, #1a1a28 0%, #0e0e16 100%);
    border: 1px solid rgba(255, 255, 255, .1);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .8);
    animation: pick-zoom .2s cubic-bezier(.2, .8, .2, 1);
}

.pick-cover { width: 100%; }

/* The frame grows with the image: covers are tall (NES) or wide (SNES, N64), so width fills the card and height
   follows, capped so the title and Play always fit on screen. The generic sleeve keeps a box shape instead. */
.pick .box-cover {
    aspect-ratio: auto;
    height: auto;
    min-height: 0;
}

/* width: 100% scales the cover up to the card; max-height + object-fit keep tall covers on screen. The shadow is
   a drop-shadow filter so it hugs the painted image rather than the letterboxed element box. */
.pick .box-cover img {
    width: 100%;
    height: auto;
    max-height: min(58vh, 560px);
    object-fit: contain;
    background: transparent;
    box-shadow: none;
    filter: drop-shadow(0 16px 30px rgba(0, 0, 0, .75));
}

.pick.box-generic .box-cover { aspect-ratio: var(--box-aspect, 0.7); max-height: min(58vh, 560px); }
.pick .box-generic-label { padding: 28px 22px 20px; }
.pick .box-generic-logo { height: 64px; }
.pick .box-generic-title { font-size: 28px; -webkit-line-clamp: 6; margin-bottom: 42px; }
.pick[data-system="nes"] .box-generic-label { padding-left: 40px; }
.pick[data-system="psx"] .box-generic-label { padding-left: 34px; }

.pick-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.pick-system-logo {
    height: 32px;
    object-fit: contain;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6));
}

.pick-title {
    margin: 0;
    font-size: 26px;
    line-height: 1.15;
    font-weight: 800;
    text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
    overflow-wrap: anywhere;
}

.pick-subtitle {
    margin: 0;
    font-size: 12px;
    opacity: .6;
    overflow-wrap: anywhere;
}

.pick-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
}

.pick-actions .mud-button-filled { min-width: 180px; }

@keyframes pick-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pick-zoom { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 560px) {
    .pick-backdrop { padding: 12px; }
    .pick { padding: 16px; gap: 14px; }
    .pick .box-cover img, .pick.box-generic .box-cover { max-height: 50vh; }
    .pick-title { font-size: 22px; }
}

/* Narrower, the search is a row of its own under the facts and rides as a bar across the top; the rail and a
   jump's landing place start below that bar. */
@media (max-width: 1100px) {
    .system-header { order: -1; min-height: 0; padding: 22px 28px 6px; }
    .search-dock { top: 52px; height: auto; padding: 0 18px; }
    .system-search { position: static; width: auto; align-items: stretch; }
    .letter-rail { top: 138px; max-height: calc(100vh - 146px); max-height: calc(100dvh - 146px); }
    .box, .shelf { scroll-margin-top: 146px; }
}

@media (max-width: 700px) {
    .system-header { padding: 16px 16px 4px; }
    .search-dock { padding: 0 6px; }
    .letter-rail { flex-basis: 22px; margin-right: 4px; }
    .shelf { --box-min: 118px; gap: 14px 10px; padding: 8px 6px 0 16px; }
    .shelf-heading { padding-left: 16px; padding-right: 6px; }
    [data-system="snes"], [data-system="n64"], [data-system="gb"], [data-system="gbc"], [data-system="neogeo"] { --box-min: 160px; }
}

/* Player */
.play {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
}

.play-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 12px;
}

.play-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.play-system, .play-hint {
    opacity: .7;
}

.play-host {
    flex: 1;
    background: #000;
    min-height: 240px;
}

.retrocade-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Playing together: the share dialog on the Play page, and the guest's Join page. */
.share-code {
    font: 700 34px/1.2 ui-monospace, Consolas, monospace;
    letter-spacing: .18em;
    user-select: all;
    margin: 2px 0 10px;
}
.share-link input { font-size: 13px; }
.share-player { display: flex; align-items: center; gap: 10px; min-height: 32px; }
.share-seat {
    width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .12); font-size: 12px; font-weight: 600;
}
.share-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-state { color: #9a9ab0; font-size: 12px; }
.share-state.share-on { color: #66bb6a; }

/* Legends dialog (Play page): one row per team, locked ones show a question mark. */
.legends-list { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; column-gap: 10px; row-gap: 2px; align-items: center; margin-top: 6px; max-height: 50vh; overflow-y: auto; scrollbar-width: thin; }
.legends-row { display: contents; }
.legends-row > * { padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); min-height: 26px; display: flex; align-items: center; }
.legends-team { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legends-name { font-size: 13px; color: #9a9ab0; white-space: nowrap; }
.legends-has .legends-name { color: #f1f1f1; }
.legends-era { font-size: 12px; color: #6a6a80; white-space: nowrap; }

.join-lobby {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    text-align: center;
}
.join-lobby > * { max-width: 440px; }
.join-code { flex: 0 0 auto; width: 220px; }
.join-code input { text-transform: uppercase; letter-spacing: .18em; text-align: center; font-family: ui-monospace, Consolas, monospace; }
.netplay-host { position: relative; overflow: hidden; }
.netplay-host.netplay-hidden { display: none; }
.netplay-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    outline: none;
}

@media (max-width: 900px) {
    .play-hint {
        display: none;
    }
}

/* Blazor boot */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: #2a2a3a;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: #ff6d00;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #111;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Save states drawer */
.saves-panel {
    padding: 16px;
}

.saves-item {
    display: flex;
    gap: 12px;
    padding: 8px;
    margin-bottom: 10px;
}

.saves-thumb {
    width: 112px;
    height: 84px;
    object-fit: cover;
    border-radius: 4px;
    background: #000;
    flex: 0 0 auto;
}

.saves-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: .4;
}

.saves-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.saves-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: auto;
}

/* A pinned save: never replaced by newer ones. */
.saves-kept {
    box-shadow: inset 3px 0 0 var(--mud-palette-primary);
}

/* Game memory (the battery save), under the save states. */
.saves-memory {
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px solid var(--mud-palette-divider);
}

/* Controller setup */
.controls-page {
    padding: 16px;
    height: calc(100vh - 48px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.controls-head, .controls-padbar, .controls-actionsbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls-body {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(300px, 1fr);
    gap: 24px;
    min-height: 0;
    flex: 1;
}

.controls-pad {
    min-width: 0;
}

.controls-actions {
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.controls-group {
    display: block;
    margin: 12px 4px 4px;
    opacity: .7;
}

.action-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    min-height: 36px;
}

.action-row:hover { background: rgba(255, 255, 255, .06); }
.action-row.listening { background: rgba(0, 229, 255, .14); outline: 1px solid rgba(0, 229, 255, .5); }
.action-row.hit { background: rgba(255, 109, 0, .28); }
.action-binding { font-size: .9em; opacity: .9; }
.controls-shortcuts-note { display: block; margin: 6px 4px 12px; }

.pad-svg {
    width: 100%;
    max-width: 720px;
    height: auto;
    display: block;
    user-select: none;
}

.pad-body { fill: #22222e; stroke: #3a3a4c; stroke-width: 2; }
.pad-part { cursor: pointer; }
.pad-part .shape { fill: #3a3a4c; stroke: #5a5a70; stroke-width: 2; transition: fill .08s, stroke .08s; }
.pad-part .well { fill: #16161f; stroke: #2e2e3c; stroke-width: 2; }
.pad-part:hover .shape { stroke: #ff6d00; }
.pad-part.bound .shape { stroke: #9a9ab0; }
.pad-part.listening .shape { stroke-dasharray: 4 3; }
.pad-part.current .shape { stroke: #00e5ff; stroke-width: 3; }
.pad-part.pressed .shape { fill: #ff6d00 !important; stroke: #ffc080 !important; }
.pad-part.pressed .assign { fill: #fff; }
.pad-stickdir.pressed .assign { fill: #ff6d00; }
.pad-part text { font-family: Roboto, Helvetica, Arial, sans-serif; text-anchor: middle; pointer-events: none; }
.pad-part .cap { fill: #e8e8f0; font-size: 13px; font-weight: 700; }
.pad-part .act { fill: #ffffff; font-size: 12px; font-weight: 700; }
.pad-part .act.small { font-size: 9px; }
.pad-part .phys, .pad-dpad .phys { fill: #8a8aa0; font-size: 10px; font-weight: 500; text-anchor: middle; pointer-events: none; font-family: Roboto, Helvetica, Arial, sans-serif; }
.controls-lastpress { display: flex; align-items: center; gap: 6px; min-height: 28px; margin-bottom: 4px; }
.controls-wake {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 8px;
    border: 2px solid #ff6d00;
    background: rgba(255, 109, 0, .12);
    animation: controls-wake-pulse 1.6s ease-in-out infinite;
}
.controls-wake-icon { font-size: 40px; color: #ff6d00; flex: none; }
@keyframes controls-wake-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 109, 0, .45); }
    50% { box-shadow: 0 0 0 8px rgba(255, 109, 0, 0); }
}
.pad-svg.asleep { opacity: .45; }
.controls-family { min-width: 260px; max-width: 420px; }
.controls-family-note { margin: -4px 0 0; }
.pad-part .assign { fill: #ff9a3c; font-size: 11px; font-weight: 600; }
.pad-part .assign.dir { fill: #c9c9d6; font-weight: 500; }
.pad-dpadcenter { fill: #3a3a4c; }
.face-a .shape { fill: #2f7d32; } .face-b .shape { fill: #a83232; } .face-x .shape { fill: #2f55a8; } .face-y .shape { fill: #b8961e; }
.face-a .cap, .face-b .cap, .face-x .cap, .face-y .cap { fill: #fff; }
.pad-guide .shape { fill: #2a2a38; }

@media (max-width: 1000px) {
    .controls-page { height: auto; }
    .controls-body { grid-template-columns: 1fr; }
    .controls-actions { max-height: 60vh; }
}

/* Xbox-style pads identify their buttons by colour and position; the physical names only add noise there. */
.pad-xbox .phys { display: none; }

/* Access (admin): invitations and the list of people who can sign in */
.access-page { padding: 16px; max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.access-head { display: flex; align-items: center; gap: 8px; }
.access-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.access-invite { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.access-invite .access-email { flex: 1 1 260px; }
.access-invite .access-hours { flex: 0 0 150px; }
.access-invite .mud-input-control { margin-top: 0; }
.access-link { display: flex; align-items: center; gap: 8px; }
.access-link .mud-input-control { flex: 1 1 auto; min-width: 0; }
.access-table td { overflow-wrap: anywhere; }
/* On a wide window a role, a date or an address stays on one line and only the email column gives way.
   Narrower than that everything may wrap, or a long IPv6 address squeezes the email into a sliver. */
@media (min-width: 1200px) { .access-table .access-role, .access-table .access-when, .access-table .access-where { white-space: nowrap; } }
.access-name { font-size: .8rem; }
.access-card-head { display: flex; align-items: center; gap: 8px; }
.access-plays-search { max-width: 340px; flex-grow: 0; }
.access-plays-view { width: auto; flex: 0 0 auto; }
.access-plays-count { font-variant-numeric: tabular-nums; }
.access-online { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; border-top: 1px solid rgba(255, 255, 255, .08); }
.access-online:first-of-type { border-top: none; }
.access-online-dot { flex: 0 0 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--mud-palette-success); box-shadow: 0 0 6px var(--mud-palette-success); }
.access-online-who { flex: 1 1 40%; min-width: 0; overflow-wrap: anywhere; }
.access-online-what { flex: 1 1 60%; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) { .access-online { flex-wrap: wrap; } .access-online-what { flex-basis: 100%; padding-left: 18px; } }
.access-ip { font-size: .8rem; font-family: ui-monospace, Consolas, monospace; user-select: all; }
.access-connection { margin-top: 10px; padding: 8px 10px; border-radius: 6px; background: rgba(255, 255, 255, .04); }
.access-request { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-top: 1px solid rgba(255, 255, 255, .08); }
.access-request:first-of-type { border-top: none; }
.access-request-who { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.access-request-note { margin-top: 4px; white-space: pre-line; font-size: .875rem; }
.access-headers { margin-top: 6px; }
.access-headers summary { cursor: pointer; color: var(--mud-palette-text-secondary); }
.access-header { font-size: .75rem; padding: 1px 0; overflow-wrap: anywhere; color: var(--mud-palette-text-secondary); }
.access-header-public { color: var(--mud-palette-primary); }
.access-actions { text-align: right; white-space: nowrap; }

@media (max-width: 560px) {
    .access-invite .access-hours { flex: 1 1 100%; }
    .access-link { flex-wrap: wrap; }
    .access-actions { white-space: normal; }
}

/* Sign-in pages and the "not on the list" gate */
.auth-page, .gate {
    min-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    text-align: center;
    box-sizing: border-box;
}
.gate .gate-wide { width: min(440px, 100%); flex: 0 0 auto; text-align: left; }
.appbar-user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; display: inline-block; vertical-align: bottom; }
@media (max-width: 560px) { .appbar-account .appbar-user { display: none; } }
.about-rows { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: baseline; }
.about-label { color: #9a9ab0; font-size: 13px; }
.about-value { font-family: ui-monospace, Consolas, monospace; font-size: 14px; user-select: all; }

/* A console's notice (Library.razor) */
.notice-title { display: inline-flex; align-items: center; gap: 8px; }
.notice-text { white-space: pre-line; }
