:root {
    --bg: #16171c;
    --panel: #1f2128;
    --panel-2: #2a2d36;
    --line: #353946;
    --text: #eceef3;
    --muted: #9aa0ad;
    --accent: #8bac0f;
    --accent-2: #b5d334;
    --danger: #e5484d;
    --on-accent: #0f1a00;
    --warn: #f0c674;
    --toggle-off: #4a4f5c;
    --glass: rgba(31, 33, 40, .94);
    --toast-bg: rgba(20, 21, 26, .92);
    --scrim: rgba(0, 0, 0, .45);
    --shadow: rgba(0, 0, 0, .5);
    --logo-2: #59c3a6;
    --radius: 14px;
    color-scheme: dark;
}

/* Menu color themes (3 dark, 3 light), chosen with the sun/moon button. */
#app[data-theme="midnight"] {
    --panel: #121a2b;
    --panel-2: #1c2740;
    --line: #2a3756;
    --text: #e8eefc;
    --muted: #93a1c0;
    --accent: #4f8cff;
    --accent-2: #7fb0ff;
    --on-accent: #fff;
    --toggle-off: #3b4866;
    --glass: rgba(18, 26, 43, .94);
    --toast-bg: rgba(14, 20, 34, .94);
    --logo-2: #b88cff;
}

#app[data-theme="grape"] {
    --panel: #1f1726;
    --panel-2: #2c2136;
    --line: #3d2f4a;
    --text: #f1eaf7;
    --muted: #a898b6;
    --accent: #b57bff;
    --accent-2: #d3a9ff;
    --on-accent: #1d0636;
    --toggle-off: #4d3d5c;
    --glass: rgba(31, 23, 38, .94);
    --toast-bg: rgba(24, 17, 30, .94);
    --logo-2: #ff8fc8;
}

#app[data-theme="paper"],
#app[data-theme="sand"],
#app[data-theme="sky"] {
    --scrim: rgba(20, 22, 28, .3);
    --shadow: rgba(30, 34, 45, .22);
    --danger: #d1343a;
    color-scheme: light;
}

#app[data-theme="paper"] {
    --panel: #f7f8fa;
    --panel-2: #ffffff;
    --line: #dde1e8;
    --text: #1d2129;
    --muted: #6a7180;
    --accent: #5f8c00;
    --accent-2: #4b7300;
    --on-accent: #fff;
    --warn: #9a6400;
    --toggle-off: #c4c9d3;
    --glass: rgba(247, 248, 250, .95);
    --toast-bg: rgba(255, 255, 255, .96);
    --logo-2: #1f9c7d;
}

#app[data-theme="sand"] {
    --panel: #f6efe3;
    --panel-2: #fffaf1;
    --line: #e2d6c1;
    --text: #2e2418;
    --muted: #7d6d58;
    --accent: #d9731a;
    --accent-2: #b85c0c;
    --on-accent: #fff;
    --warn: #9a5a00;
    --toggle-off: #d3c5ad;
    --glass: rgba(246, 239, 227, .95);
    --toast-bg: rgba(255, 250, 241, .96);
    --logo-2: #c2410c;
}

#app[data-theme="sky"] {
    --panel: #eef4fb;
    --panel-2: #ffffff;
    --line: #d2dfee;
    --text: #15233a;
    --muted: #5d6f88;
    --accent: #2f6fde;
    --accent-2: #1f5bc4;
    --on-accent: #fff;
    --warn: #93600a;
    --toggle-off: #bccbdd;
    --glass: rgba(238, 244, 251, .95);
    --toast-bg: rgba(255, 255, 255, .96);
    --logo-2: #0e9aa7;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    position: fixed;
    inset: 0;
}

#app::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Plastic: fine grain + soft mottling, and a broad sheen across the shell. */
#app::before {
    background: url("../img/grain.png") 0 0 / 192px 192px repeat;
    opacity: var(--grain-opacity, .5);
    mix-blend-mode: soft-light;
}

#app {
    position: fixed;
    inset: 0;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    background: var(--sheen), var(--body-bg);
}

/* ------------------------------------------------------------------ screen */
#screen {
    position: absolute;
    left: 0;
    top: 0;
    background: #000;
    border-radius: 4px;
    box-shadow: 0 0 0 1px #000, 0 10px 30px rgba(0, 0, 0, .55);
    overflow: hidden;
    will-change: transform;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    image-rendering: -moz-crisp-edges;
}

#canvas.smooth {
    image-rendering: auto;
}

#lcd {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, rgba(0, 0, 0, .22) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, .22) 1px, transparent 1px);
}

#lcd[hidden] {
    display: none;
}

#fps {
    position: absolute;
    top: 4px;
    left: 4px;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, .6);
    font: 600 11px/1.4 ui-monospace, Menlo, monospace;
    color: #b5d334;
}

#save-indicator,
#turbo-indicator {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s;
}

#turbo-indicator {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

#turbo-indicator.on {
    opacity: .85;
}

#save-indicator.show {
    animation: flash 1.2s ease;
}

@keyframes flash {
    0% { opacity: 0; }
    15% { opacity: .9; }
    70% { opacity: .9; }
    100% { opacity: 0; }
}

/* ---------------------------------------------------------------- controls */
#controls {
    position: absolute;
    inset: 0;
    touch-action: none;
    z-index: 2;
}

.ctrl {
    position: absolute;
    left: 0;
    top: 0;
    transition: opacity .15s;
    will-change: transform;
}

.ctrl.hidden {
    display: none;
}

.ctrl em,
.ctrl span {
    pointer-events: none;
}

/* Shared "printed on the case" label style (navy italic on the DMG) */
.ctrl em {
    font: italic 700 1em/1 "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    letter-spacing: .08em;
    color: var(--label);
    white-space: nowrap;
}

/* ---- D-pad: matte cross in a recess; it tilts toward the pressed side ---- */
.ctrl-dpad svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* Model B: the SVG holds all 9 states; show only the current one. */
.ctrl-dpad .st {
    display: none;
}

.ctrl-dpad[data-st="rest"] .st-rest,
.ctrl-dpad[data-st="up"] .st-up,
.ctrl-dpad[data-st="down"] .st-down,
.ctrl-dpad[data-st="left"] .st-left,
.ctrl-dpad[data-st="right"] .st-right,
.ctrl-dpad[data-st="ul"] .st-ul,
.ctrl-dpad[data-st="ur"] .st-ur,
.ctrl-dpad[data-st="dl"] .st-dl,
.ctrl-dpad[data-st="dr"] .st-dr {
    display: inline;
}

/* ---- A / B: matte convex buttons inside a slanted oval recess ---- */
.ab-well {
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 999px;
    background: var(--ab-well);
    box-shadow:
        inset 0 3px 4px rgba(0, 0, 0, .22),
        inset 0 -1px 1px var(--well-light),
        0 1px 0 var(--well-light);
    pointer-events: none;
    transform-origin: center;
}

.ab-well[hidden] {
    display: none;
}

.ctrl-a .face,
.ctrl-ta .face,
.ctrl-tb .face,
.ctrl-b .face,
.ctrl-turbo .face,
.ctrl-rewind .face,
.ctrl-slow .face,
.ctrl-palette .face,
.ctrl-menu .face {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .045s, box-shadow .045s, filter .045s;
}

.ctrl-a .face,
.ctrl-ta .face,
.ctrl-tb .face,
.ctrl-b .face {
    background:
        radial-gradient(70% 45% at 50% 22%, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 70%),
        linear-gradient(180deg, var(--ab-hi) 0%, var(--ab) 38%, var(--ab) 70%, var(--ab-lo) 100%);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, .3),
        inset 0 -2px 3px rgba(0, 0, 0, .22),
        0 3px 0 var(--ab-side),
        0 5px 6px rgba(0, 0, 0, .28);
}

.ctrl-a.pressed .face,
.ctrl-ta.pressed .face,
.ctrl-tb.pressed .face,
.ctrl-b.pressed .face {
    transform: translateY(3px);
    filter: brightness(.9);
    box-shadow:
        inset 0 1px 2px rgba(0, 0, 0, .25),
        inset 0 -1px 2px rgba(0, 0, 0, .15),
        0 0 0 var(--ab-side),
        0 1px 2px rgba(0, 0, 0, .3);
}

.ctrl-a em,
.ctrl-ta em,
.ctrl-tb em,
.ctrl-b em {
    position: absolute;
    left: 50%;
    top: 112%;
    transform: translateX(-50%);
    font-size: .58em;
}

/* ---- Start / Select: rubber pills in slots, slanted with their labels ---- */
.ctrl-start .rot,
.ctrl-select .rot {
    position: absolute;
    inset: 0;
    transform: rotate(-25deg);
}

.ctrl-start .slot,
.ctrl-select .slot {
    position: absolute;
    left: 10%;
    right: 10%;
    top: 14%;
    height: 42%;
    border-radius: 999px;
    background: var(--ab-well);
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, .25), 0 1px 0 var(--well-light);
}

.ctrl-start .pill,
.ctrl-select .pill {
    position: absolute;
    left: 16%;
    right: 16%;
    top: 19%;
    height: 30%;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--pill-hi) 0%, var(--pill) 55%, var(--pill-lo) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 2px 0 var(--pill-lo), 0 3px 3px rgba(0, 0, 0, .25);
    transition: transform .045s, box-shadow .045s;
}

.ctrl-start.pressed .pill,
.ctrl-select.pressed .pill {
    transform: translateY(2px);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, .3), 0 0 0 var(--pill-lo);
}

.ctrl-start em,
.ctrl-select em {
    position: absolute;
    left: 0;
    right: 0;
    top: 70%;
    text-align: center;
    font-size: .86em;
}

/* ---- Turbo and menu: small rubber buttons ---- */
.ctrl-turbo .face,
.ctrl-rewind .face,
.ctrl-slow .face,
.ctrl-palette .face,
.ctrl-menu .face {
    background: linear-gradient(180deg, var(--pill-hi) 0%, var(--pill) 55%, var(--pill-lo) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .25),
        0 0 0 3px var(--ab-well),
        0 2px 0 3px rgba(0, 0, 0, .08),
        0 3px 4px 3px rgba(0, 0, 0, .12);
    color: var(--pill-text);
    font-weight: 800;
}

.ctrl-turbo span,
.ctrl-rewind span {
    letter-spacing: -.12em;
    font-size: .75em;
}

.ctrl-slow span {
    font-size: .8em;
}

.ctrl-palette span {
    font-size: .95em;
}

.ctrl-turbo.pressed .face,
.ctrl-rewind.pressed .face,
.ctrl-slow.pressed .face,
.ctrl-palette.pressed .face,
.ctrl-menu.pressed .face {
    transform: translateY(2px);
    filter: brightness(.88);
}

/* Layout editor */
#controls.editing .ctrl {
    outline: 2px dashed rgba(255, 255, 255, .55);
    outline-offset: 4px;
    border-radius: 12px;
}

#controls.editing .ctrl-a,
#controls.editing .ctrl-ta,
#controls.editing .ctrl-tb,
#controls.editing .ctrl-b,
#controls.editing .ctrl-turbo,
#controls.editing .ctrl-rewind,
#controls.editing .ctrl-slow,
#controls.editing .ctrl-palette,
#controls.editing .ctrl-menu {
    border-radius: 50%;
}

#controls.editing .ctrl.selected {
    outline: 3px solid var(--accent-2);
}

#controls.editing .ctrl.disabled {
    filter: grayscale(1);
}

#app.editing #screen {
    filter: brightness(.45);
}

#editor,
#screen-editor {
    position: absolute;
    z-index: 5;
    left: 50%;
    top: calc(env(safe-area-inset-top) + 8px);
    transform: translateX(-50%) translateY(var(--panel-y, 0px));
    transition: transform .2s ease;
    width: min(420px, calc(100% - 16px));
    max-height: calc(50% - 16px);
    overflow-y: auto;
    padding: 12px 14px 0;
    background: var(--glass);
    color: var(--text);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px var(--shadow);
    touch-action: pan-y;
    font-size: 14px;
}

#app[data-orientation="landscape"] #editor,
#app[data-orientation="landscape"] #screen-editor {
    max-height: calc(100% - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    width: min(380px, 46%);
}

#editor[hidden],
#screen-editor[hidden],
#screen-drag[hidden] {
    display: none;
}

.editor-head {
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
}

.editor-head .hint {
    color: var(--muted);
    font-size: 12px;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.chip {
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}

.editor-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.editor-actions .btn {
    flex: 1;
}

/* Screen editor: the panel sits at the bottom (portrait) or on the right
   (landscape) so the screen can be dragged around above it. */
#screen-editor {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + 8px);
}

#app[data-orientation="landscape"] #screen-editor {
    left: auto;
    right: calc(env(safe-area-inset-right) + 8px);
    top: calc(env(safe-area-inset-top) + 8px);
    bottom: auto;
    transform: none;
}

#screen-drag {
    position: absolute;
    inset: 0;
    z-index: 4;
    touch-action: none;
    cursor: move;
}

#app.screen-editing #controls {
    opacity: .25;
}

#app.screen-editing #screen {
    outline: 2px dashed var(--accent-2);
    outline-offset: 4px;
}

#app.screen-editing.screen-auto #screen {
    outline-style: solid;
    outline-color: var(--line);
}

.seg {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin: 4px 0 6px;
    border-radius: 12px;
    background: var(--panel-2);
    border: 1px solid var(--line);
}

.seg button {
    flex: 1;
    padding: 8px 10px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.seg button.active {
    background: var(--accent);
    color: var(--on-accent);
}

/* -------------------------------------------------------------------- menu */
#menu {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: var(--scrim);
    touch-action: auto;
    animation: fade .18s ease;
}

#menu[hidden] {
    display: none;
}

@keyframes fade {
    from { opacity: 0; }
}

@keyframes slide {
    from { transform: translateY(30px); opacity: .5; }
}

.sheet {
    width: min(560px, 100%);
    max-height: calc(100% - env(safe-area-inset-top) - 12px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    padding: 0 16px calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 40px var(--shadow);
    animation: slide .22s ease;
    -webkit-user-select: none;
    user-select: none;
}

/* Palette page: keep the game visible for a live preview. */
#menu[data-page="palette"] {
    background: transparent;
}

#app[data-orientation="portrait"] #menu[data-page="palette"] .sheet {
    max-height: 48%;
}

#app[data-orientation="landscape"] #menu[data-page="palette"] {
    justify-content: flex-end;
}

#app[data-orientation="landscape"] #menu[data-page="palette"] .sheet {
    width: min(360px, 42%);
    margin-right: env(safe-area-inset-right);
}

#app[data-orientation="landscape"] #menu {
    align-items: center;
}

#app[data-orientation="landscape"] .sheet {
    border-radius: 20px;
    border-bottom: 1px solid var(--line);
    max-height: calc(100% - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px);
    padding-bottom: 16px;
}

.sheet header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: grid;
    /* The title takes the space left by the buttons (up to five on the right). */
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin: 0 -16px 8px;
    padding: 12px 12px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.sheet h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sheet h2 {
    margin: 20px 0 6px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}

.logo {
    font-weight: 800;
    letter-spacing: .02em;
    background: linear-gradient(90deg, var(--accent-2), var(--logo-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 0;
    background: var(--panel-2);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.page[hidden] {
    display: none;
}

.list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 13px 14px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
}

.item[hidden] {
    display: none;
}

.item:active,
.btn:active,
.palette:active {
    transform: scale(.98);
}

.item.primary {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 700;
}

/* Main menu: cards in two columns */
.tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 88px;
    padding: 12px 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 1px 2px var(--shadow);
}

.tile svg {
    flex: none;
    width: 26px;
    height: 26px;
    color: var(--accent-2);
}

.tile span {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.tile.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.tile.primary svg {
    color: var(--on-accent);
}

.tile:active {
    transform: scale(.97);
}

.tile:disabled,
.item:disabled {
    opacity: .4;
    cursor: default;
    transform: none;
}

.coffee {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 18px 0 4px;
}

.coffee a.bmc {
    display: inline-flex;
    border-radius: 12px;
    overflow: hidden;
    min-height: 50px;
    min-width: 181px;
    align-items: center;
    justify-content: center;
    background: #ffdd00;
    color: #000;
    font-weight: 700;
    text-decoration: none;
}

.coffee img {
    display: block;
    height: 50px;
    width: 181px;
}

/* Same light sweep as "Importar lista" */
.coffee a.bmc {
    position: relative;
}

.coffee a.bmc::after {
    content: "";
    position: absolute;
    top: -20%;
    bottom: -20%;
    left: -60%;
    width: 40%;
    pointer-events: none;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .75), transparent);
    transform: skewX(-20deg);
    animation: shine 2.8s ease-in-out infinite;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.header-actions {
    display: flex;
    gap: 6px;
    justify-self: end;
}

@media (max-width: 360px) {
    .header-actions {
        gap: 4px;
    }

    .header-actions .round-btn {
        width: 30px;
        height: 30px;
    }

    .sheet header {
        gap: 4px;
        padding-left: 8px;
        padding-right: 8px;
    }
}

.sheet header > .icon-btn {
    justify-self: start;
}

/* Theme switch: a small circle filled with the theme's accent color. */
.round-btn {
    width: 34px;
    height: 34px;
    align-self: center;
}

#camera-btn svg,
#gif-btn svg {
    width: 18px;
    height: 18px;
}

#camera-btn[hidden],
#gif-btn[hidden] {
    display: none;
}

.popover-anchor {
    position: sticky;
    top: 62px;
    z-index: 2;
    height: 0;
}

.popover {
    position: absolute;
    right: 0;
    top: -6px;
    display: flex;
    flex-direction: column;
    width: max-content;
    max-width: 100%;
    padding: 6px;
    border-radius: 14px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    box-shadow: 0 10px 30px var(--shadow);
    animation: fade .15s ease;
}

.popover[hidden] {
    display: none;
}

.popover button {
    padding: 11px 14px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}

.popover button:active {
    background: var(--panel);
}

#theme-btn {
    width: 34px;
    height: 34px;
    align-self: center;
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: inset 0 0 0 2px var(--panel), 0 0 0 1px var(--line);
}

#theme-btn svg {
    width: 18px;
    height: 18px;
}

.now {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 2px 12px;
}

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

.now strong {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--panel-2);
    color: var(--accent-2);
}

.welcome {
    margin: 4px 2px 14px;
    color: var(--muted);
    text-align: center;
}

.note {
    color: var(--muted);
    font-size: 13px;
    margin: 6px 2px 12px;
}

.note.warn {
    color: var(--warn);
}

.note a {
    color: var(--accent-2);
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 20px 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 16px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.btn.block {
    display: flex;
    width: 100%;
    margin: 8px 0;
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.btn.danger.block {
    margin-top: 22px;
}

.btn.danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn.ghost {
    background: transparent;
}

.btn.small {
    padding: 7px 12px;
    font-size: 14px;
    border-radius: 10px;
}

.btn:disabled {
    opacity: .4;
}

.cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--panel-2);
    border: 1px solid transparent;
}

.card.current {
    border-color: var(--accent);
}

.rom-info,
.state-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.rom-info strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.state-info .card-actions {
    margin-top: 6px;
}

.thumb {
    width: 96px;
    aspect-ratio: 160 / 144;
    flex: none;
    border-radius: 6px;
    background: #0d0e11;
    display: grid;
    place-items: center;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
}

.thumb img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.palettes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.palette {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    border-radius: 12px;
    border: 2px solid transparent;
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.palette.active {
    border-color: var(--accent-2);
}

.swatches {
    display: flex;
    height: 22px;
    border-radius: 6px;
    overflow: hidden;
}

.swatches i {
    flex: 1;
}

.swatches.sprites {
    height: 8px;
    width: 60%;
}

.custom-colors {
    display: flex;
    gap: 8px;
}

.custom-colors input {
    flex: 1;
    height: 44px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: none;
    -webkit-appearance: none;
    appearance: none;
}

.custom-colors input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.custom-colors input::-webkit-color-swatch {
    border: 0;
    border-radius: 9px;
}

/* Form rows */
.row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 2px;
    border-bottom: 1px solid var(--line);
}

.row[hidden] {
    display: none;
}

.row.check {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.row output {
    color: var(--muted);
    margin-left: 4px;
}

select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent-2);
    height: 28px;
}

.toggle {
    -webkit-appearance: none;
    appearance: none;
    flex: none;
    width: 50px;
    height: 30px;
    border-radius: 999px;
    background: var(--toggle-off);
    position: relative;
    cursor: pointer;
    transition: background .2s;
    margin: 0;
}

.toggle::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

.toggle:checked {
    background: var(--accent);
}

.toggle:checked::after {
    transform: translateX(20px);
}

.toggle:disabled {
    opacity: .4;
}

.keys {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.keys td {
    padding: 6px 2px;
    border-bottom: 1px solid var(--line);
}

.keys td:last-child {
    color: var(--muted);
    text-align: right;
}

/* ------------------------------------------------------------------- toast */
#toast {
    position: absolute;
    z-index: 20;
    left: 50%;
    top: calc(env(safe-area-inset-top) + 12px);
    max-width: calc(100% - 32px);
    transform: translate(-50%, -20px);
    padding: 9px 16px;
    border-radius: 999px;
    background: var(--toast-bg);
    box-shadow: 0 4px 18px var(--shadow);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    text-align: center;
}

#toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.card.homebrew {
    align-items: flex-start;
}

.card.homebrew .rom-info strong {
    white-space: normal;
}

.card .desc {
    margin: 4px 0 8px;
    font-size: 13px;
    color: var(--text);
    opacity: .85;
}

a.btn {
    text-decoration: none;
}

/* ------------------------------------------------------------------ skins */
[data-skin] {
    --body-bg: linear-gradient(172deg, #d3d0c8 0%, #c9c6bd 50%, #bebab1 100%);
    --sheen: linear-gradient(115deg, rgba(255, 255, 255, .16) 0%, rgba(255, 255, 255, 0) 38%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, .06) 100%);
    --grain-opacity: .5;
    --well: rgba(0, 0, 0, .1);
    --well-light: rgba(255, 255, 255, .45);
    --ab-well: rgba(0, 0, 0, .06);
    --bezel: #85868f;
    --bezel-2: #74757f;
    --bezel-text: #e4e4ec;
    --bz-text: "DOT MATRIX WITH STEREO SOUND";
    --stripe1: #8a1f4f;
    --stripe2: #2c2f7a;
    --led: #ff2b2b;
    --dpad: #36363b;
    --dpad-side: #19191c;
    --ab: #b01d58;
    --ab-hi: #c93f74;
    --ab-lo: #8a1544;
    --ab-side: #6a0f33;
    --pill: #8e8c91;
    --pill-hi: #a4a2a7;
    --pill-lo: #6c6a70;
    --pill-text: #f2f2f5;
    --label: #2e3a8c;
    --brand: #2e3a8c;
    --grille: rgba(0, 0, 0, .2);
}

[data-skin^="gbc"] {
    --sheen: linear-gradient(115deg, rgba(255, 255, 255, .2) 0%, rgba(255, 255, 255, 0) 35%, rgba(0, 0, 0, 0) 65%, rgba(0, 0, 0, .12) 100%);
    --grain-opacity: .6;
    --well: rgba(0, 0, 0, .16);
    --well-light: rgba(255, 255, 255, .22);
    --ab-well: rgba(0, 0, 0, .1);
    --bezel: #1f1f24;
    --bezel-2: #17171b;
    --bezel-text: #8d8d96;
    --bz-text: "";
    --stripe1: transparent;
    --stripe2: transparent;
    --led: #3cff6a;
    --dpad: #2c2c31;
    --dpad-side: #121214;
    --ab: #2f2f35;
    --ab-hi: #4a4a52;
    --ab-lo: #222227;
    --ab-side: #111114;
    --pill: #3a3a41;
    --pill-hi: #4b4b53;
    --pill-lo: #26262b;
    --label: rgba(255, 255, 255, .85);
    --brand: rgba(255, 255, 255, .92);
    --grille: rgba(0, 0, 0, .22);
}

[data-skin="gbc-berry"] { --body-bg: linear-gradient(170deg, #d9195c 0%, #c1124e 55%, #a80d43 100%); }
[data-skin="gbc-grape"] { --body-bg: linear-gradient(170deg, #6a4bb0 0%, #5a3d9e 55%, #4b318a 100%); }
[data-skin="gbc-teal"] { --body-bg: linear-gradient(170deg, #1cb0b8 0%, #139aa3 55%, #0d858d 100%); }

[data-skin="gbc-kiwi"] {
    --body-bg: linear-gradient(170deg, #afd64e 0%, #9cc43c 55%, #88ad2f 100%);
    --label: #1e2a0a;
    --brand: #1e2a0a;
}

[data-skin="gbc-dandelion"] {
    --body-bg: linear-gradient(170deg, #fbd23a 0%, #f1c21b 55%, #ddaf0d 100%);
    --label: #2b2205;
    --brand: #2b2205;
}

/* Transparent shells: the circuit board shows through the tinted plastic */
[data-skin^="clear"] {
    --pcb: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><rect width='240' height='240' fill='%231d4733'/><g fill='none' stroke='%23d0a94e' stroke-opacity='.5' stroke-width='2.5'><path d='M0 30H60L80 50H150L170 30H240'/><path d='M0 125H40L60 145V240'/><path d='M100 240V180L120 160H240'/><path d='M30 0V18'/><path d='M200 0V60L180 80H125'/><path d='M0 85H30L50 105H95'/><path d='M150 50V92'/><path d='M180 160V200H240'/></g><g fill='%23d0a94e' fill-opacity='.75'><circle cx='60' cy='30' r='3.5'/><circle cx='95' cy='105' r='3.5'/><circle cx='125' cy='80' r='3.5'/><circle cx='60' cy='240' r='3.5'/><circle cx='30' cy='18' r='3.5'/></g><rect x='110' y='96' width='64' height='44' rx='3' fill='%23141414'/><g stroke='%23a5a5a5' stroke-width='2'><path d='M116 96v-6M126 96v-6M136 96v-6M146 96v-6M156 96v-6M166 96v-6M116 140v6M126 140v6M136 140v6M146 140v6M156 140v6M166 140v6'/></g><rect x='18' y='160' width='26' height='11' rx='2' fill='%23c9b08a'/><rect x='24' y='160' width='3' height='11' fill='%238a3a2a'/><rect x='32' y='160' width='3' height='11' fill='%23333'/><circle cx='200' cy='210' r='12' fill='%232f3138'/><circle cx='200' cy='210' r='8' fill='none' stroke='%23999' stroke-opacity='.4'/><rect x='175' y='20' width='34' height='22' rx='2' fill='%23202020'/></svg>");
    --grain-opacity: .2;
    --sheen: linear-gradient(115deg, rgba(255, 255, 255, .22) 0%, rgba(255, 255, 255, 0) 30%);
    --well: rgba(0, 0, 0, .2);
    --well-light: rgba(255, 255, 255, .18);
    --ab-well: rgba(0, 0, 0, .14);
    --dpad-side: rgba(0, 0, 0, .75);
    --ab-side: rgba(0, 0, 0, .55);
    --pill-lo: rgba(0, 0, 0, .45);
    --bezel: rgba(20, 20, 26, .88);
    --bezel-2: rgba(12, 12, 16, .9);
    --bezel-text: #a4a4b0;
    --bz-text: "DOT MATRIX WITH STEREO SOUND";
    --stripe1: rgba(200, 60, 120, .8);
    --stripe2: rgba(80, 90, 200, .8);
    --grille: rgba(0, 0, 0, .3);
}

[data-skin="clear-atomic"] {
    --body-bg: linear-gradient(160deg, rgba(255, 255, 255, .18) 0%, rgba(255, 255, 255, 0) 35%),
        linear-gradient(rgba(105, 62, 170, .62), rgba(80, 40, 140, .7)), var(--pcb);
    --dpad: rgba(45, 25, 75, .92);
    --ab: rgba(130, 85, 200, .92);
    --ab-hi: rgba(190, 160, 240, .95);
    --ab-lo: rgba(70, 35, 120, .95);
    --pill: rgba(90, 60, 140, .9);
    --pill-hi: rgba(130, 95, 185, .9);
    --label: rgba(255, 255, 255, .9);
    --brand: rgba(255, 255, 255, .92);
}

[data-skin="clear-ice"] {
    --body-bg: linear-gradient(160deg, rgba(255, 255, 255, .35) 0%, rgba(255, 255, 255, 0) 40%),
        linear-gradient(rgba(215, 225, 235, .58), rgba(190, 205, 220, .66)), var(--pcb);
    --dpad: rgba(40, 44, 56, .9);
    --ab: rgba(200, 210, 225, .9);
    --ab-hi: rgba(255, 255, 255, .95);
    --ab-lo: rgba(120, 135, 160, .95);
    --pill: rgba(120, 130, 150, .9);
    --pill-hi: rgba(160, 170, 190, .9);
    --label: #1d2333;
    --brand: #1d2333;
}

[data-skin="clear-jungle"] {
    --body-bg: linear-gradient(160deg, rgba(255, 255, 255, .2) 0%, rgba(255, 255, 255, 0) 35%),
        linear-gradient(rgba(60, 150, 85, .6), rgba(40, 120, 65, .68)), var(--pcb);
    --dpad: rgba(20, 50, 30, .92);
    --ab: rgba(70, 170, 95, .92);
    --ab-hi: rgba(160, 230, 175, .95);
    --ab-lo: rgba(25, 90, 45, .95);
    --pill: rgba(40, 100, 60, .9);
    --pill-hi: rgba(70, 135, 90, .9);
    --label: rgba(255, 255, 255, .9);
    --brand: rgba(255, 255, 255, .92);
}

[data-skin="clear-smoke"] {
    --body-bg: linear-gradient(160deg, rgba(255, 255, 255, .12) 0%, rgba(255, 255, 255, 0) 35%),
        linear-gradient(rgba(25, 26, 32, .7), rgba(15, 16, 20, .78)), var(--pcb);
    --dpad: rgba(10, 10, 12, .92);
    --ab: rgba(60, 62, 72, .92);
    --ab-hi: rgba(120, 122, 135, .95);
    --ab-lo: rgba(20, 20, 25, .95);
    --pill: rgba(55, 57, 66, .9);
    --pill-hi: rgba(80, 82, 92, .9);
    --label: rgba(255, 255, 255, .8);
    --brand: rgba(255, 255, 255, .85);
}

/* Game Boy Pocket style shells: metallic and bright plastics, gray bezel */
[data-skin^="pocket"] {
    --sheen: linear-gradient(115deg, rgba(255, 255, 255, .3) 0%, rgba(255, 255, 255, 0) 32%, rgba(0, 0, 0, 0) 68%, rgba(0, 0, 0, .1) 100%);
    --grain-opacity: .3;
    --bz-text: "";
    --stripe1: transparent;
    --stripe2: transparent;
}

[data-skin="pocket-silver"] {
    --body-bg: linear-gradient(170deg, #dfe1e5 0%, #c3c6cc 45%, #a9adb4 100%);
    --label: #33363d;
    --brand: #33363d;
}

[data-skin="pocket-gold"] {
    --body-bg: linear-gradient(170deg, #ead08a 0%, #c9a548 50%, #a8842c 100%);
    --bezel: #5d5340;
    --bezel-2: #4a4232;
    --label: #3a2a08;
    --brand: #3a2a08;
    --ab: #6b5320;
    --ab-hi: #8a6e33;
    --ab-lo: #4e3b14;
    --ab-side: #36280c;
}

[data-skin="pocket-red"] {
    --body-bg: linear-gradient(170deg, #e2454a 0%, #c8282e 55%, #a81c22 100%);
    --bezel: #2a2a30;
    --bezel-2: #1f1f24;
    --label: rgba(255, 255, 255, .9);
    --brand: rgba(255, 255, 255, .92);
    --ab: #2f2f35;
    --ab-hi: #4a4a52;
    --ab-lo: #222227;
    --ab-side: #111114;
}

[data-skin="pocket-pink"] {
    --body-bg: linear-gradient(170deg, #f8bfd0 0%, #f0a0b8 55%, #dc86a0 100%);
    --label: #5a1f36;
    --brand: #5a1f36;
    --ab: #d8467c;
    --ab-hi: #ea6f9a;
    --ab-lo: #b03062;
    --ab-side: #861e48;
}

[data-skin="gbc-tangerine"] { --body-bg: linear-gradient(170deg, #ff9640 0%, #f47a1f 55%, #d86510 100%); }

[data-skin="gbc-sky"] {
    --body-bg: linear-gradient(170deg, #80cdf2 0%, #5bb8e8 55%, #3e9fd2 100%);
    --label: #0d2a40;
    --brand: #0d2a40;
}

/* Famicom colors: maroon body with golden labels */
[data-skin="famicom"] {
    --body-bg: linear-gradient(170deg, #a02830 0%, #8c1c22 55%, #74141a 100%);
    --grain-opacity: .35;
    --bezel: #e8e0cf;
    --bezel-2: #d6ccb6;
    --bezel-text: #8c1c22;
    --bz-text: "";
    --stripe1: #c9a548;
    --stripe2: #c9a548;
    --dpad: #2a2a2e;
    --ab: #e0d6c0;
    --ab-hi: #f4ecdb;
    --ab-lo: #c4b89c;
    --ab-side: #8f8468;
    --pill: #c9a548;
    --pill-hi: #dcbd6a;
    --pill-lo: #a8842c;
    --pill-text: #3a2a08;
    --label: #e8c76a;
    --brand: #e8c76a;
}

[data-skin="clear-ruby"] {
    --body-bg: linear-gradient(160deg, rgba(255, 255, 255, .2) 0%, rgba(255, 255, 255, 0) 35%),
        linear-gradient(rgba(180, 30, 60, .6), rgba(140, 15, 45, .7)), var(--pcb);
    --dpad: rgba(60, 10, 20, .92);
    --ab: rgba(210, 60, 90, .92);
    --ab-hi: rgba(245, 150, 170, .95);
    --ab-lo: rgba(120, 15, 40, .95);
    --pill: rgba(130, 30, 50, .9);
    --pill-hi: rgba(170, 60, 80, .9);
    --label: rgba(255, 255, 255, .9);
    --brand: rgba(255, 255, 255, .92);
}

[data-skin="clear-ocean"] {
    --body-bg: linear-gradient(160deg, rgba(255, 255, 255, .2) 0%, rgba(255, 255, 255, 0) 35%),
        linear-gradient(rgba(40, 110, 180, .6), rgba(25, 80, 150, .7)), var(--pcb);
    --dpad: rgba(10, 30, 60, .92);
    --ab: rgba(70, 140, 210, .92);
    --ab-hi: rgba(160, 205, 245, .95);
    --ab-lo: rgba(20, 70, 130, .95);
    --pill: rgba(35, 85, 140, .9);
    --pill-hi: rgba(65, 115, 170, .9);
    --label: rgba(255, 255, 255, .9);
    --brand: rgba(255, 255, 255, .92);
}

[data-skin="dark"] {
    --grain-opacity: .25;
    --sheen: none;
    --well: rgba(0, 0, 0, .35);
    --well-light: rgba(255, 255, 255, .05);
    --ab-well: rgba(0, 0, 0, .25);
    --dpad-side: #0c0c0e;
    --ab-side: #3d0920;
    --pill-lo: #24252b;
    --bezel-2: #08090b;
    --body-bg: radial-gradient(120% 80% at 50% 0%, #22242c 0%, #16171c 60%);
    --bezel: #0d0e11;
    --bezel-text: #6e7280;
    --stripe1: #6d1a40;
    --stripe2: #262a6a;
    --dpad: #34363e;
    --ab: #8c1d4c;
    --ab-hi: #b8487a;
    --ab-lo: #5a0f30;
    --pill: #3a3c45;
    --pill-hi: #4a4c56;
    --label: #9aa0ad;
    --brand: #9aa0ad;
    --grille: rgba(255, 255, 255, .06);
}

/* Screen frame (bezel) */
#bezel {
    position: absolute;
    left: 0;
    top: 0;
    background: linear-gradient(180deg, var(--bezel) 0%, var(--bezel-2) 100%);
    border-radius: calc(var(--u) * 5) calc(var(--u) * 5) calc(var(--u) * 24) calc(var(--u) * 5);
    box-shadow: inset 0 calc(var(--u) * .6) calc(var(--u) * 1.2) rgba(0, 0, 0, .35), 0 1px 0 rgba(255, 255, 255, .35);
    pointer-events: none;
}

#bezel::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(125deg, rgba(255, 255, 255, .14) 0%, rgba(255, 255, 255, .03) 30%, rgba(255, 255, 255, 0) 31%);
    pointer-events: none;
}

#bezel[hidden],
#brand[hidden] {
    display: none;
}

.bz-top {
    position: absolute;
    left: 4%;
    right: 4%;
    top: calc(var(--u) * 4.6);
    display: flex;
    align-items: center;
    gap: calc(var(--u) * 1.8);
}

.bz-top i {
    flex: 1;
    height: calc(var(--u) * 2.2);
    border-top: calc(var(--u) * .7) solid var(--stripe1);
    border-bottom: calc(var(--u) * .7) solid var(--stripe2);
}

.bz-top span {
    font: 600 calc(var(--u) * 3.2) / 1 "Helvetica Neue", Arial, sans-serif;
    letter-spacing: .04em;
    color: var(--bezel-text);
    white-space: nowrap;
}

.bz-top span::before {
    content: var(--bz-text);
}

.bz-led {
    position: absolute;
    left: calc(var(--u) * 1.5);
    top: 42%;
    width: calc(var(--u) * 11);
    text-align: center;
}

.bz-led b {
    display: block;
    width: calc(var(--u) * 3.4);
    height: calc(var(--u) * 3.4);
    margin: 0 auto calc(var(--u) * 1.6);
    border-radius: 50%;
    background: #3b1515;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, .6);
    transition: background .3s, box-shadow .3s;
}

#app.led-on .bz-led b {
    background: var(--led);
    box-shadow: 0 0 calc(var(--u) * 2) var(--led), inset 0 -1px 2px rgba(0, 0, 0, .3);
}

/* The power LED glows softly, like the real one. */
#app.led-on .bz-led b {
    animation: led-glow 2.6s ease-in-out infinite;
}

@keyframes led-glow {
    0%, 100% {
        filter: brightness(1);
        box-shadow: 0 0 calc(var(--u) * 1.6) var(--led), inset 0 -1px 2px rgba(0, 0, 0, .3);
    }
    50% {
        filter: brightness(1.25);
        box-shadow: 0 0 calc(var(--u) * 3.2) var(--led), 0 0 calc(var(--u) * 1) var(--led), inset 0 -1px 2px rgba(0, 0, 0, .2);
    }
}

.bz-led span {
    display: block;
    font: 600 calc(var(--u) * 2) / 1 "Helvetica Neue", Arial, sans-serif;
    letter-spacing: .03em;
    color: var(--bezel-text);
}

#app[data-family="gbc"] .bz-led span::after {
    content: "";
}

#app.framed #screen {
    border-radius: 1px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .55), 0 0 0 3px rgba(0, 0, 0, .12);
}

/* The LCD sits behind the bezel: inner shadow from the frame edge + glass reflection. */
#app.framed #screen::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    box-shadow:
        inset 0 6px 8px -3px rgba(0, 0, 0, .55),
        inset 5px 0 7px -4px rgba(0, 0, 0, .4),
        inset -2px 0 4px -2px rgba(0, 0, 0, .25),
        inset 0 -2px 3px -2px rgba(0, 0, 0, .2);
    background: linear-gradient(125deg, rgba(255, 255, 255, .07) 0%, rgba(255, 255, 255, .02) 35%, rgba(255, 255, 255, 0) 36%);
}

/* Logo under the screen */
#brand {
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    align-items: center;
    padding-left: 3%;
    color: var(--brand);
    pointer-events: none;
    white-space: nowrap;
}

#brand b {
    font: 800 .78em/1 "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    letter-spacing: .01em;
    margin-right: .18em;
}

#brand em {
    font: italic 500 1.05em/1 "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    letter-spacing: .02em;
}

#brand sup {
    font: 600 .3em/1 "Helvetica Neue", Arial, sans-serif;
    margin-left: .15em;
    align-self: flex-start;
    margin-top: .9em;
}

#brand .color {
    display: none;
    margin-left: .3em;
    font: italic 900 .72em/1 "Arial Black", "Helvetica Neue", Arial, sans-serif;
    letter-spacing: .02em;
}

#app[data-family="gbc"] #brand .color {
    display: inline;
}

#brand .color b:nth-child(1) { color: #ff3b4f; }
#brand .color b:nth-child(2) { color: #8c6cff; }
#brand .color b:nth-child(3) { color: #3fd16a; }
#brand .color b:nth-child(4) { color: #ffd23c; }
#brand .color b:nth-child(5) { color: #33b6ff; }

/* Decorative speaker grille */
#body-deco {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#speaker {
    position: absolute;
    right: 5%;
    bottom: calc(env(safe-area-inset-bottom) + 5%);
    width: 26vmin;
    height: 15vmin;
    display: none;
    gap: 2.4vmin;
    transform: rotate(-30deg);
}

#speaker i {
    flex: 1;
    border-radius: 99px;
    background: var(--grille);
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, .3), 0 1px 0 var(--well-light);
}

#app.framed[data-orientation="portrait"] #speaker {
    display: flex;
}

/* Skin picker */
.skins {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.skin {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border-radius: 12px;
    border: 2px solid transparent;
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.skin.active {
    border-color: var(--accent-2);
}

.skin-preview {
    position: relative;
    display: block;
    height: 84px;
    border-radius: 8px 8px 22px 8px;
    background: var(--body-bg);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
    overflow: hidden;
}

.skin-preview i {
    position: absolute;
    display: block;
}

.sp-screen {
    left: 14%;
    right: 14%;
    top: 8%;
    height: 44%;
    border-radius: 3px 3px 10px 3px;
    background: var(--bezel);
}

.sp-screen::after {
    content: "";
    position: absolute;
    left: 18%;
    right: 18%;
    top: 16%;
    bottom: 14%;
    background: #9bbc0f;
}

.sp-dpad {
    left: 14%;
    top: 62%;
    width: 22%;
    height: 26%;
    background:
        linear-gradient(var(--dpad), var(--dpad)) center / 34% 100% no-repeat,
        linear-gradient(var(--dpad), var(--dpad)) center / 100% 34% no-repeat;
}

.sp-a,
.sp-b {
    width: 14%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--ab);
}

.sp-a {
    right: 12%;
    top: 60%;
}

.sp-b {
    right: 30%;
    top: 70%;
}

/* Remapping */
.mapping {
    display: flex;
    flex-direction: column;
}

.map-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--line);
}

.map-name {
    font-weight: 600;
    font-size: 14px;
}

.map-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}

.map-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-btn i {
    font-style: normal;
}

#capture {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, .65);
    touch-action: none;
}

#capture[hidden] {
    display: none;
}

.capture-box {
    width: min(360px, calc(100% - 32px));
    padding: 20px;
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: pulse 1.4s ease infinite;
}

.capture-box small {
    color: var(--muted);
}

@keyframes pulse {
    50% { box-shadow: 0 0 0 4px rgba(181, 211, 52, .35); }
}

/* ----------------------------------------------------------------- library */
.lib-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

.lib-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.lib-row select {
    flex: 1;
    min-width: 0;
}

.lib-row .icon-btn {
    flex: none;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

input.text,
textarea.text,
input[type="search"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-size: 16px;
    -webkit-user-select: text;
    user-select: text;
}

textarea.text {
    resize: vertical;
}

input.text:focus,
textarea:focus,
input[type="search"]:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

.card.lib {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.lib-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.card.lib .desc {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
}

.card.lib .details {
    color: var(--muted);
    font-size: 13px;
}

.card.lib .details a {
    color: var(--accent-2);
    font-weight: 600;
}

.card.lib .desc[hidden],
.card.lib .details[hidden] {
    display: none;
}

.cover {
    position: relative;
    flex: none;
    width: 64px;
    height: 58px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--panel);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.cover img,
.entry-cover img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: pixelated;
}

.cover-ph {
    font-size: 22px;
    font-weight: 800;
    color: var(--muted);
}

.card.lib .rom-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card.lib .rom-info strong,
.card.txt-list .rom-info strong {
    white-space: normal;
    overflow-wrap: anywhere;
}

.card.lib .meta {
    overflow-wrap: anywhere;
}

.status {
    align-self: flex-start;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
}

.status.s-ok {
    color: var(--accent-2);
    border-color: var(--accent-2);
}

.status.s-busy {
    color: var(--text);
}

.status.s-error {
    color: var(--danger);
    border-color: var(--danger);
}

.bar {
    display: block;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    overflow: hidden;
}

.bar[hidden] {
    display: none;
}

.bar i {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width .2s;
}

.lib-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: none;
}

.fav {
    width: 34px;
    height: 34px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 20px;
    cursor: pointer;
}

.fav.on {
    color: #f5b301;
}

.lib-actions .more {
    padding: 7px 10px;
}

/* Grid view: covers in columns */
.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.lib-grid .empty {
    grid-column: 1 / -1;
}

.lib-grid .card.lib {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px;
}

.lib-grid .lib-main {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.lib-grid .card.lib .desc {
    font-size: 13px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
}

.lib-grid .card.lib .details {
    font-size: 12px;
}

.lib-grid .cover {
    width: 100%;
    height: auto;
    aspect-ratio: 10 / 9;
}

.lib-grid .cover-ph {
    font-size: 36px;
}

.lib-grid .lib-actions {
    justify-content: space-between;
}

/* Import page */
.format,
code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12.5px;
}

.format {
    margin: 0 2px 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    overflow-x: auto;
    white-space: pre;
}

.import-editor {
    display: flex;
    height: 260px;
    margin: 10px 0 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: var(--panel-2);
}

#import-gutter {
    flex: none;
    margin: 0;
    padding: 10px 6px 10px 8px;
    min-width: 36px;
    overflow: hidden;
    text-align: right;
    color: var(--muted);
    background: var(--panel);
    border-right: 1px solid var(--line);
    font: 13px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    -webkit-user-select: none;
    user-select: none;
}

#import-text {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 10px;
    border: 0;
    resize: none;
    background: transparent;
    color: var(--text);
    font: 13px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    white-space: pre;
    overflow: auto;
    overflow-wrap: normal;
    -webkit-user-select: text;
    user-select: text;
}

@supports (-webkit-touch-callout: none) {
    /* iOS zooms into inputs smaller than 16px. */
    #import-text,
    #import-gutter {
        font-size: 16px;
    }
}

#import-text:focus {
    outline: none;
}

#import-result .summary {
    margin: 8px 2px;
    font-weight: 600;
}

#import-result ul {
    margin: 4px 0 8px;
    padding-left: 18px;
    color: var(--danger);
    font-size: 13px;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 6px;
}

.preview-table td {
    padding: 5px 4px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
}

.preview-table td:first-child {
    color: var(--muted);
    width: 2.5em;
}

/* Entry page */
.entry-head {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    margin: 4px 0 6px;
}

.entry-cover {
    position: relative;
    flex: none;
    width: 128px;
    aspect-ratio: 10 / 9;
    border-radius: 10px;
    overflow: hidden;
    background: var(--panel-2);
    display: grid;
    place-items: center;
}

.entry-cover .cover-ph {
    font-size: 40px;
}

.entry-side {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    min-width: 0;
}

.entry-side .note {
    margin: 0;
}

.row-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

a.btn.block[hidden],
.btn[hidden] {
    display: none;
}

/* Import help: one-line hint with a "?" button that unfolds the details */
.help {
    margin: 0 2px 10px;
}

.help summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    list-style: none;
    cursor: pointer;
}

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

.help summary .note {
    margin: 0;
}

.help-btn {
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 800;
    font-size: 15px;
}

.help[open] .help-btn {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
}

.help-body {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    font-size: 13px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.help-body p {
    margin: 0 0 8px;
}

.help-body p:last-child {
    margin-bottom: 0;
}

.help-body ul {
    margin: 0 0 8px;
    padding-left: 18px;
}

.help-body code {
    font-size: 12px;
}

/* Bundled TXT lists on the import page */
.card.txt-list {
    align-items: center;
}

.card.txt-list .rom-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card.txt-list .desc {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.card.txt-list .desc[hidden] {
    display: none;
}

/* Library buttons: [Importar lista] [Añadir ROM] */
.lib-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 12px 0 2px;
}

.btn.block.lib-lists {
    margin-top: 14px;
}

/* Yellow button with a light sweep */
.btn.shine {
    position: relative;
    overflow: hidden;
    background: #ffd60a;
    border-color: #ffd60a;
    color: #000;
    isolation: isolate;
}

.btn.shine::after {
    content: "";
    position: absolute;
    top: -20%;
    bottom: -20%;
    left: -60%;
    width: 40%;
    z-index: -1;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .85), transparent);
    transform: skewX(-20deg);
    animation: shine 2.8s ease-in-out infinite;
}

@keyframes shine {
    0% { left: -60%; }
    45%, 100% { left: 130%; }
}

@media (prefers-reduced-motion: reduce) {
    #app.led-on .bz-led b {
        animation: none;
    }

    .coffee a.bmc::after,
    .btn.shine::after {
        animation: none;
        display: none;
    }
}

/* Running game at the top of the menu */
#now-playing .now-card {
    margin: 2px 0 12px;
}

.now-card .cover {
    cursor: default;
}

.now-card .now-label {
    color: var(--accent-2);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.now-card .desc {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

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

/* First-run welcome */
#welcome,
.dialog {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 16px;
    background: var(--scrim);
    animation: fade .2s ease;
}

#welcome[hidden],
.dialog[hidden] {
    display: none;
}

.welcome-box {
    width: min(360px, 100%);
    padding: 22px 20px 18px;
    border-radius: 20px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: 0 14px 40px var(--shadow);
    text-align: center;
    animation: slide .25s ease;
}

.welcome-box img {
    border-radius: 16px;
}

.welcome-box h2 {
    margin: 10px 0 6px;
    font-size: 20px;
}

.welcome-box p {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 16px;
}

/* Telegram channel button: round logo next to Buy Me a Coffee */
.coffee a.tg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #229ed9;
    box-shadow: 0 4px 14px rgba(34, 158, 217, .35);
}

.coffee a.tg svg {
    width: 100%;
    height: 100%;
    flex: none;
}

.coffee a.tg:active {
    transform: scale(.97);
}

/* Small phones: keep both buttons on one row */
@media (max-width: 400px) {
    .coffee a.bmc {
        min-height: 44px;
        min-width: 159px;
    }

    .coffee img {
        height: 44px;
        width: 159px;
    }

    .coffee a.tg {
        width: 44px;
        height: 44px;
    }
}

.credit {
    margin: 14px 0 2px;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

/* Storage usage */
.storage-bar {
    height: 10px;
    margin: 6px 2px 2px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    overflow: hidden;
}

.storage-bar i {
    display: block;
    height: 100%;
    background: var(--accent);
}

.storage-bar.full i {
    background: var(--danger);
}

#storage-info .keys {
    margin: 4px 0 6px;
}

/* Header: language toggle */
.lang-btn span {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .02em;
}

/* Tiles: an odd last tile takes the whole row */
.tile[hidden] {
    display: none;
}

.tiles .tile.wide {
    grid-column: 1 / -1;
    flex-direction: row;
    min-height: 60px;
}

/* Share button on game cards, under the favorite star */
.icon-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lib-grid .icon-col {
    flex-direction: row;
}

.share {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.share svg {
    width: 20px;
    height: 20px;
}

.share:active {
    color: var(--accent-2);
}

/* Cheats */
.card.cheat {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cheat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cheat-info code {
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.text.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    text-transform: uppercase;
}

/* GIF recording indicator */
#rec {
    position: absolute;
    z-index: 12;
    top: calc(env(safe-area-inset-top) + 10px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 0;
    border-radius: 999px;
    background: rgba(20, 20, 24, .78);
    color: #fff;
    font: 700 14px/1 system-ui, sans-serif;
    letter-spacing: .04em;
    cursor: pointer;
}

#rec[hidden] {
    display: none;
}

#rec b {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ff3b30;
    animation: rec-blink 1s steps(2, start) infinite;
}

#rec span {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

@keyframes rec-blink {
    to { visibility: hidden; }
}

.gif-preview {
    display: block;
    width: 100%;
    max-height: 50vh;
    object-fit: contain;
    margin: 6px 0 14px;
    border-radius: 10px;
    background: #0d0e11;
    image-rendering: pixelated;
}

/* Shared game dialog */
.share-cover {
    width: 96px;
    height: 96px;
    margin: 0 auto 10px;
    border-radius: 14px;
    background: var(--panel-2) url('../img/icon-192.png') center / cover no-repeat;
    overflow: hidden;
}

.share-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Small phones: the card buttons go to their own row under the title */
@media (max-width: 380px) {
    .cards:not(.lib-grid) .card.lib .lib-main {
        flex-wrap: wrap;
    }

    .cards:not(.lib-grid) .card.lib .rom-info {
        flex: 1 1 0;
    }

    .cards:not(.lib-grid) .card.lib .lib-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .cards:not(.lib-grid) .card.lib .icon-col {
        flex-direction: row;
    }
}

/* Grip of the editor panels: drag to move the panel, tap to hide / show it */
.panel-grip {
    position: sticky;
    bottom: 0;
    display: grid;
    place-items: center;
    height: 30px;
    margin: 8px -14px 0;
    background: var(--panel);
    border-top: 1px solid var(--line);
    cursor: grab;
    touch-action: none;
}

.panel-grip span {
    width: 44px;
    height: 5px;
    border-radius: 3px;
    background: var(--muted);
}

#editor.dragging,
#screen-editor.dragging {
    transition: none;
}

/* iOS haptics: transparent label over each control, linked to a hidden switch */
#controls label[data-haptic] {
    position: absolute;
    inset: -15%;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    pointer-events: none;
}

#controls.haptics label[data-haptic] {
    pointer-events: auto;
}

#controls label[data-haptic] input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    visibility: hidden;
}

/* AliExpress ads: carousel (menu, controllers page), catalog and game start */
.ads {
    margin: 18px 0 6px;
}

.ads[hidden] {
    display: none;
}

.ads-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 2px 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.ads-all {
    border: 0;
    background: none;
    color: var(--accent-2);
    font: inherit;
    letter-spacing: 0;
    text-transform: none;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
}

.ads-track {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    touch-action: pan-x pan-y;
}

.ads-track::-webkit-scrollbar {
    display: none;
}

.ad {
    flex: 0 0 calc((100% - 20px) / 3);
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
    color: var(--text);
}

.ad-img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e62e04' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M5 8h14l-1.2 12H6.2z'/><path d='M9 8a3 3 0 0 1 6 0'/></svg>") center / 36% no-repeat;
}

.ad-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #fff;
}

.ad-caption {
    font-size: 12px;
    font-weight: 700;
    color: #e62e04;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ad-caption[hidden] {
    display: none;
}

.ads-note {
    margin: 6px 2px 0;
    color: var(--muted);
    font-size: 11px;
}

/* Catalog */
.products {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.product,
.ad-big {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel-2);
    color: var(--text);
    text-decoration: none;
}

.product-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 2px 2px;
}

.product-text strong {
    font-size: 14px;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.product-text small {
    color: #e62e04;
    font-weight: 700;
    font-size: 13px;
}

.product-text em {
    font-style: normal;
    color: var(--accent-2);
    font-size: 13px;
    font-weight: 600;
}

/* Game start ad */
#ad-dialog {
    z-index: 40;
}

.ad-box {
    width: min(340px, 100%);
    padding: 14px;
    text-align: left;
}

.ad-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.ad-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 0;
    background: var(--panel-2);
    color: var(--text);
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
}

.ad-close:disabled {
    color: var(--muted);
    cursor: default;
}

.ad-big .ad-img {
    border-radius: 12px;
}

.ad-box .ads-note {
    margin: 8px 0 0;
    font-size: 11px;
}

/* Main menu: endless product belt */
.ads-marquee {
    overflow: hidden;
    touch-action: pan-y;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
}

.ads-belt {
    display: flex;
    gap: 10px;
    width: max-content;
    will-change: transform;
}

.ads-belt .ad {
    flex: none;
}

/* Products belt right under the now-playing card */
.ads.ads-top {
    margin: 4px 0 14px;
}

/* Invite button: shown on the main page, with a light glint */
.invite-btn {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    color: var(--accent-2);
    box-shadow: 0 0 0 0 var(--accent);
    animation: invite-pulse 2.8s ease-in-out infinite;
}

.invite-btn svg {
    width: 18px;
    height: 18px;
}

.invite-btn::after {
    content: "";
    position: absolute;
    top: -20%;
    bottom: -20%;
    left: -60%;
    width: 45%;
    z-index: -1;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .55), transparent);
    transform: skewX(-20deg);
    animation: shine 2.8s ease-in-out infinite;
}

@keyframes invite-pulse {
    0%, 60%, 100% { box-shadow: 0 0 0 0 transparent; }
    30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent); }
}

#menu:not([data-page="main"]) #invite-btn {
    display: none;
}

/* Main page: the back button takes no room (the header has more buttons) */
#menu[data-page="main"] #menu-back {
    display: none;
}

#menu-title .logo {
    cursor: default;
    -webkit-tap-highlight-color: transparent;
}

.invite-url {
    margin: -4px 0 14px !important;
    font-weight: 700;
    color: var(--accent-2) !important;
    word-break: break-all;
}

.welcome-box .btn.block + .btn.block {
    margin-top: 8px;
}

@media (prefers-reduced-motion: reduce) {
    .invite-btn,
    .invite-btn::after {
        animation: none;
    }
}

/* "Surprise me": full row, purple-blue with a breathing aura */
.lib-buttons .btn.aura {
    grid-column: 1 / -1;
}

.btn.aura {
    position: relative;
    isolation: isolate;
    border: 0;
    color: #fff;
    font-weight: 800;
    letter-spacing: .02em;
    background: linear-gradient(120deg, #7c3aed, #4f46e5 50%, #06b6d4);
    background-size: 200% 100%;
    animation: aura-glow 2.6s ease-in-out infinite, aura-shift 6s linear infinite;
}

/* Soft halo around the button */
.btn.aura::before {
    content: "";
    position: absolute;
    inset: -3px;
    z-index: -1;
    border-radius: inherit;
    background: linear-gradient(120deg, #a855f7, #22d3ee, #a855f7);
    filter: blur(8px);
    opacity: .55;
    animation: aura-halo 2.6s ease-in-out infinite;
}

.btn.aura span {
    text-shadow: 0 1px 6px rgba(0, 0, 0, .35);
}

@keyframes aura-glow {
    0%, 100% { box-shadow: 0 0 6px 0 rgba(168, 85, 247, .45); }
    50% { box-shadow: 0 0 18px 4px rgba(34, 211, 238, .55); }
}

@keyframes aura-halo {
    0%, 100% { opacity: .35; transform: scale(.98); }
    50% { opacity: .8; transform: scale(1.03); }
}

@keyframes aura-shift {
    to { background-position: 200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .btn.aura,
    .btn.aura::before {
        animation: none;
    }
}

/* Screen editor: more display settings, folded */
.screen-more {
    margin-top: 4px;
    border-top: 1px solid var(--line);
}

.screen-more summary {
    padding: 10px 2px;
    color: var(--accent-2);
    font-weight: 600;
    cursor: pointer;
}

/* Library search with its own clear button */
.search-box {
    position: relative;
}

.search-box input {
    width: 100%;
    padding-right: 44px;
}

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

.search-clear {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: var(--panel-2);
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.search-clear[hidden] {
    display: none;
}

.search-clear:active {
    color: var(--text);
}

/* Turbo A / B: like A and B, a bit lighter */
.ctrl-ta .face,
.ctrl-tb .face {
    filter: saturate(.85) brightness(1.12);
}

.ctrl-ta em,
.ctrl-tb em {
    font-size: .46em !important;
    letter-spacing: .04em;
    white-space: nowrap;
}
