/* Cartridge. Frame styled after Noorjahan for qBittorrent (chiefhamim, GPL-2.0; colours and layout ideas only): warm canvas,
   12px cards with even 8px gaps, teal accent, Geist. The shelf and cartridges are Cartridge's own. */
@font-face { font-family: "Geist"; src: url("fonts/Geist-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Geist"; src: url("fonts/Geist-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Geist"; src: url("fonts/Geist-SemiBold.woff2") format("woff2"); font-weight: 600 700; font-display: swap; }
@font-face { font-family: "Rubik"; src: url("fonts/rubik.woff2") format("woff2"); font-weight: 300 900; font-display: swap; }

/* ---------- Tokens ---------- */
:root {
  --canvas: #ECE8E1; --card: #FAF8F4; --card-2: #F3F0EA; --line: #DFD9CF; --line-strong: #CBC3B6; --line-soft: #ECE7DF;
  --text: #1C1A16; --muted: #7D766B; --disabled: #B3ACA1;
  --accent: #1D786B; --accent-hover: #17695E; --accent-soft: #E3EEEA; --accent-ink: #FFFFFF;
  --hover: rgba(28, 26, 22, .05); --selected: rgba(29, 120, 107, .13);
  --red: #B33A27; --green: #3B8956; --orange: #8C6512;
  --shelf: #D2CBBF; --shelf-lip: #E4DED4;
  --shadow-sm: 0 1px 2px rgba(28, 26, 22, .05);
  --shadow-md: 0 6px 18px rgba(28, 26, 22, .09), 0 1px 3px rgba(28, 26, 22, .05);
  --shadow-lg: 0 14px 34px rgba(28, 26, 22, .13), 0 2px 6px rgba(28, 26, 22, .05);
  --thumb: rgba(28, 26, 22, .18); --thumb-hover: rgba(28, 26, 22, .32);
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --gap: 8px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --canvas: #0E1110; --card: #161B1A; --card-2: #1C2220; --line: #262E2C; --line-strong: #36403D; --line-soft: #1F2624;
  --text: #E8E4DC; --muted: #8A847A; --disabled: #4E5451;
  --accent: #52C3AF; --accent-hover: #6FD0BE; --accent-soft: #1B2E2B; --accent-ink: #04201B;
  --hover: rgba(255, 255, 255, .05); --selected: rgba(82, 195, 175, .15);
  --red: #F27A64; --green: #76C98E; --orange: #E2B653;
  --shelf: #2E3735; --shelf-lip: #1F2624;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35); --shadow-md: 0 6px 18px rgba(0,0,0,.45); --shadow-lg: 0 14px 34px rgba(0,0,0,.55);
  --thumb: rgba(255,255,255,.12); --thumb-hover: rgba(255,255,255,.22);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0E1110; --card: #161B1A; --card-2: #1C2220; --line: #262E2C; --line-strong: #36403D; --line-soft: #1F2624;
    --text: #E8E4DC; --muted: #8A847A; --disabled: #4E5451;
    --accent: #52C3AF; --accent-hover: #6FD0BE; --accent-soft: #1B2E2B; --accent-ink: #04201B;
    --hover: rgba(255, 255, 255, .05); --selected: rgba(82, 195, 175, .15);
    --red: #F27A64; --green: #76C98E; --orange: #E2B653;
    --shelf: #2E3735; --shelf-lip: #1F2624;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35); --shadow-md: 0 6px 18px rgba(0,0,0,.45); --shadow-lg: 0 14px 34px rgba(0,0,0,.55);
    --thumb: rgba(255,255,255,.12); --thumb-hover: rgba(255,255,255,.22);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--canvas); color: var(--text); }
body { font: 400 14px/1.45 "Geist", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--thumb); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--thumb-hover); }
* { scrollbar-color: var(--thumb) transparent; }
kbd { font: 500 11px "Geist", system-ui, sans-serif; color: var(--muted); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--card); }

/* ---------- Frame: canvas, cards, gaps ---------- */
.canvas { height: 100vh; height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: var(--gap);
  padding: calc(var(--gap) + env(safe-area-inset-top)) calc(var(--gap) + env(safe-area-inset-right)) env(safe-area-inset-bottom) calc(var(--gap) + env(safe-area-inset-left)); }
.body { display: grid; grid-template-columns: 236px 1fr; gap: var(--gap); min-height: 0; }

/* Toolbar card */
.topcard { display: flex; align-items: center; gap: 3px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 7px 10px; min-height: 52px; box-shadow: var(--shadow-sm); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; letter-spacing: -.01em; padding: 0 10px 0 4px; margin-right: 4px; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.tb-group { display: flex; align-items: center; gap: 3px; position: relative; }
.tb-group.divider { margin-left: 9px; }
.tb-group.divider::before { content: ""; position: absolute; left: -6px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.tb { height: 34px; min-width: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 8px;
  border: 1px solid transparent; border-radius: var(--r-sm); background: none; cursor: pointer; color: var(--text);
  transition: background-color .12s ease, border-color .12s ease, color .12s ease; }
.tb:hover { background: var(--hover); border-color: var(--line); }
.tb:active { background: var(--selected); }
.tb.wide { padding: 0 12px 0 9px; font-weight: 500; }
.tb.wide svg { color: var(--accent); }
.tb.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#themeBtn svg { display: none; }
#themeBtn[data-mode="light"] .i-sun, #themeBtn[data-mode="dark"] .i-moon, #themeBtn[data-mode="system"] .i-auto { display: block; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.filter { display: flex; align-items: center; gap: 7px; height: 34px; width: 260px; padding: 0 8px 0 10px; color: var(--muted);
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-md); transition: border-color .12s ease, box-shadow .12s ease; }
.filter svg { width: 16px; height: 16px; }
.filter:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--selected); }
.filter input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); padding: 0; }
.filter input::-webkit-search-cancel-button { display: none; }
.filter:focus-within kbd { display: none; }
.sortby { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.sortby select { height: 34px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card-2); color: var(--text);
  padding: 0 28px 0 10px; appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 15px, calc(100% - 10px) 15px; background-size: 4px 4px; background-repeat: no-repeat; }
.sortby select:hover { border-color: var(--line-strong); }

/* Sidebar card */
.rail { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 8px 0 12px; overflow-y: auto; overflow-x: hidden;
  box-shadow: var(--shadow-sm); user-select: none; }
.sec + .sec { margin-top: 4px; }
.sec-title { display: flex; align-items: center; gap: 6px; width: calc(100% - 16px); margin: 0 8px; padding: 8px 6px 6px; border: 0; background: none;
  cursor: pointer; color: var(--text); font-weight: 600; font-size: 13px; text-align: left; border-radius: var(--r-sm); }
.sec-title .chev { width: 12px; height: 12px; margin-left: auto; color: var(--muted); transition: transform .18s var(--ease); }
.sec.closed .chev { transform: rotate(-90deg); }
.sec-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .22s var(--ease); }
.sec.closed .sec-body { grid-template-rows: 0fr; }
.sec-body > ul { overflow: hidden; list-style: none; margin: 0; padding: 0 8px; }
.link { position: relative; display: flex; align-items: center; gap: 9px; width: 100%; height: 30px; margin: 1px 0; padding: 0 8px; border: 0;
  border-radius: var(--r-md); background: none; cursor: pointer; font-size: 13.5px; color: var(--text); text-align: left; white-space: nowrap;
  transition: background-color .1s ease, color .1s ease; }
.link:hover { background: var(--hover); }
.link[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.link[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 0 2px 2px 0; background: var(--accent); }
.link .ic { width: 16px; height: 16px; display: grid; place-items: center; color: var(--muted); }
.link[aria-current="true"] .ic { color: var(--accent); }
.link .mini { width: 11px; height: 13px; border-radius: 2px 4px 2px 2px; background: var(--c); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.link .label { overflow: hidden; text-overflow: ellipsis; }
.link .n { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.link[aria-current="true"] .n { color: inherit; opacity: .8; }

/* Main card */
.maincard { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.main-head { display: flex; align-items: baseline; gap: 10px; padding: 14px 22px 12px; border-bottom: 1px solid var(--line-soft); }
.main-head h1 { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; }
.scroller { flex: 1; overflow-y: auto; padding: 20px 22px 40px; scroll-behavior: smooth; }

/* Status bar: on the canvas, no card */
.statusbar { display: flex; align-items: center; gap: 14px; height: 32px; padding: 0 14px; color: var(--muted); font-size: 12.5px; }
.sb-spacer { flex: 1; }
.statusbar .pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; border: 1px solid transparent;
  background: none; color: var(--muted); font-size: 12.5px; cursor: default; }
.statusbar button.pill { cursor: pointer; }
.statusbar button.pill:hover { background: var(--hover); border-color: var(--line); color: var(--text); }
.statusbar .pill svg { width: 15px; height: 15px; }
#syncLine::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--s, var(--disabled)); }
#syncLine.ok { --s: var(--green); } #syncLine.busy { --s: var(--accent); } #syncLine.bad { --s: var(--red); }
#sbPad.on { color: var(--accent); }
.sb-progress { display: inline-flex; align-items: center; gap: 8px; }
.sb-progress .bar { width: 120px; height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; }
.sb-progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width .25s var(--ease); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--card); cursor: pointer; white-space: nowrap; font-weight: 500; color: var(--text); text-decoration: none;
  transition: background-color .12s ease, border-color .12s ease, transform .08s ease; }
.btn:hover { background: var(--hover); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--red); }
.btn.big { height: 40px; padding: 0 20px; font-size: 15px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.only-phone { display: none !important; }

/* ---------- Resume ---------- */
.resume { display: flex; align-items: center; gap: 26px; padding: 18px 24px; margin: 0 0 26px; background: var(--card-2);
  border: 1px solid var(--line); border-radius: var(--r-lg); }
.resume .stand { width: 150px; height: 140px; display: flex; align-items: flex-end; justify-content: center; flex: none; }
.resume .stand .art { transform: scale(1.08); transform-origin: bottom center; }
.resume .eyebrow { display: none; }
.resume h2 { font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; margin-bottom: 3px; }
.resume p { margin: 0 0 14px; color: var(--muted); }

/* ---------- Shelf ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); column-gap: 0; row-gap: 24px; }
.item { min-width: 0; position: relative; border-radius: var(--r-md); }
.slot { height: 172px; display: flex; align-items: flex-end; justify-content: center; padding: 0 12px;
  border-bottom: 4px solid var(--shelf); box-shadow: 0 5px 0 0 var(--shelf-lip); }
.play { border: 0; padding: 0; background: none; cursor: pointer; display: block; border-radius: 10px; outline-offset: 4px; }
.play .art { transition: transform .18s var(--ease), box-shadow .18s var(--ease); }
.play:hover .art, .item.kb .art { transform: translateY(-7px); }
.play:active .art { transform: translateY(-2px) scale(.98); }
.cap { padding: 11px 12px 0; display: flex; gap: 4px; align-items: flex-start; }
.cap > div { flex: 1; min-width: 0; }
.cap .t { font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cap .s { color: var(--muted); font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more { border: 1px solid transparent; background: none; width: 28px; height: 28px; border-radius: var(--r-sm); color: var(--muted); cursor: pointer; flex: none;
  margin-top: -4px; display: grid; place-items: center; opacity: 0; transition: opacity .12s ease, background-color .12s ease; }
.item:hover .more, .item:focus-within .more, .more:focus-visible { opacity: 1; }
.more:hover { background: var(--hover); border-color: var(--line); color: var(--text); }
@media (hover: none) { .more { opacity: 1; } }
.item.blocked .art { filter: grayscale(1); opacity: .5; }
.item.leaving { animation: leave .22s var(--ease) forwards; }
@keyframes leave { to { opacity: 0; transform: scale(.94); } }
.item.arrived .art { animation: arrive .4s var(--ease); }
@keyframes arrive { from { transform: translateY(-24px); opacity: 0; } }
.none { padding: 40px 0; color: var(--muted); }
.item.filler { pointer-events: none; }
.none button { margin-top: 10px; }

/* ---------- Cartridges, cards and cases ----------
   Each game is drawn as its real media. --body is the plastic, --label the sticker. */
.art { --body: #999; --label: #ccc; --li: #111; position: relative; display: block; background: var(--body); flex: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28), inset 0 -2px 0 rgba(0,0,0,.18), 0 6px 14px rgba(0,0,0,.18); }
.art .lbl { position: absolute; display: flex; align-items: flex-end; overflow: hidden; background: var(--label); color: var(--li);
  padding: 7px 8px; font-weight: 700; font-size: 13px; line-height: 1.15; letter-spacing: -.01em; text-align: left;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.art .lbl span { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.art .sys { position: absolute; font-size: 10px; font-weight: 600; opacity: .75; }
.art::before, .art::after { content: ""; position: absolute; }

/* Game Boy / Color: tall, clipped top-right corner, grip ridges */
.art.gb { width: 108px; height: 122px; border-radius: 4px 4px 8px 8px; clip-path: polygon(0 0, 86% 0, 100% 11%, 100% 100%, 0 100%); }
.art.gb::before { left: 10px; right: 22px; top: 6px; height: 9px; background: repeating-linear-gradient(90deg, rgba(0,0,0,.16) 0 2px, transparent 2px 5px); }
.art.gb .lbl { left: 10px; right: 10px; top: 24px; bottom: 18px; border-radius: 3px; }
/* Game Boy Advance: short and wide */
.art.gba { width: 134px; height: 86px; border-radius: 5px 5px 9px 9px; }
.art.gba::before { left: 50%; top: 0; width: 34px; height: 5px; margin-left: -17px; background: rgba(0,0,0,.2); border-radius: 0 0 4px 4px; }
.art.gba .lbl { left: 10px; right: 10px; top: 14px; bottom: 12px; border-radius: 3px; font-size: 12px; }
/* DS / 3DS: small card, clipped top-left corner */
.art.card { width: 92px; height: 104px; border-radius: 7px; clip-path: polygon(10% 0, 100% 0, 100% 100%, 0 100%, 0 9%); }
.art.card::before { left: 8px; right: 8px; bottom: 5px; height: 6px; background: repeating-linear-gradient(90deg, rgba(255,215,120,.55) 0 4px, transparent 4px 6px); }
.art.card .lbl { left: 8px; right: 8px; top: 14px; bottom: 18px; border-radius: 3px; font-size: 12px; }
/* Game Gear */
.art.gg { width: 112px; height: 84px; border-radius: 6px; }
.art.gg .lbl { left: 10px; right: 10px; top: 12px; bottom: 10px; border-radius: 3px; font-size: 12px; }
/* NES: tall grey box with ridged bottom */
.art.nes { width: 116px; height: 140px; border-radius: 3px; }
.art.nes::after { left: 0; right: 0; bottom: 0; height: 22px; background: repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 2px, transparent 2px 5px); }
.art.nes .lbl { left: 10px; right: 10px; top: 12px; bottom: 30px; border-radius: 2px; }
/* SNES: wide, rounded shoulders */
.art.snes { width: 140px; height: 112px; border-radius: 22px 22px 6px 6px; }
.art.snes::before { left: 6px; top: 34px; width: 7px; height: 46px; background: repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 2px, transparent 2px 5px); }
.art.snes::after { right: 6px; top: 34px; width: 7px; height: 46px; background: repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 2px, transparent 2px 5px); }
.art.snes .lbl { left: 20px; right: 20px; top: 16px; bottom: 16px; border-radius: 4px; }
/* N64: chunky with tapered top */
.art.n64 { width: 136px; height: 116px; border-radius: 6px 6px 8px 8px; clip-path: polygon(8% 0, 92% 0, 100% 18%, 100% 100%, 0 100%, 0 18%); }
.art.n64 .lbl { left: 16px; right: 16px; top: 14px; bottom: 22px; border-radius: 3px; }
.art.n64::after { left: 30px; right: 30px; bottom: 7px; height: 7px; background: rgba(0,0,0,.25); border-radius: 4px; }
/* Sega: black with a ribbed lip */
.art.sega { width: 118px; height: 136px; border-radius: 6px; }
.art.sega::before { left: 0; right: 0; top: 0; height: 16px; background: repeating-linear-gradient(90deg, rgba(255,255,255,.09) 0 3px, transparent 3px 6px); border-radius: 6px 6px 0 0; }
.art.sega .lbl { left: 9px; right: 9px; top: 24px; bottom: 12px; border-radius: 2px; }
/* PlayStation jewel case: square, dark spine */
.art.jewel { width: 132px; height: 128px; border-radius: 3px; }
.art.jewel::before { left: 0; top: 0; bottom: 0; width: 12px; background: rgba(0,0,0,.4); }
.art.jewel .lbl { left: 16px; right: 4px; top: 4px; bottom: 4px; border-radius: 1px; }
/* DVD-style case: tall */
.art.dvd { width: 104px; height: 148px; border-radius: 5px; }
.art.dvd::before { left: 0; top: 0; bottom: 0; width: 7px; background: rgba(0,0,0,.18); border-radius: 5px 0 0 5px; }
.art.dvd .lbl { left: 11px; right: 5px; top: 18px; bottom: 5px; border-radius: 2px; }
/* PSP UMD case: clear, tall, rounded */
.art.umd { width: 90px; height: 148px; border-radius: 10px; }
.art.umd .lbl { left: 6px; right: 6px; top: 6px; bottom: 6px; border-radius: 6px; font-size: 12px; }

.art .lbl { font-family: "Rubik", "Geist", system-ui, sans-serif; }

/* ---------- Empty ---------- */
.empty { max-width: 500px; margin: 5vh auto 0; text-align: center; }
.empty-shelf { display: flex; justify-content: center; align-items: flex-end; gap: 14px; height: 110px; border-bottom: 4px solid var(--shelf);
  box-shadow: 0 5px 0 var(--shelf-lip); margin-bottom: 28px; padding: 0 20px; }
.ghost { border: 2px dashed var(--line-strong); border-bottom: 0; border-radius: 6px 6px 0 0; }
.g1 { width: 58px; height: 68px; } .g2 { width: 76px; height: 50px; } .g3 { width: 52px; height: 60px; } .g4 { width: 66px; height: 88px; }
.empty h2 { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.empty p { color: var(--muted); margin: 8px 0 20px; }
.empty .hint { font-size: 12.5px; margin-top: 12px; }
.formats { text-align: left; margin-top: 24px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.formats summary { cursor: pointer; color: var(--muted); }
.formats ul { padding-left: 18px; color: var(--muted); font-size: 13px; }

.drop-overlay { position: fixed; inset: 8px; z-index: 40; display: grid; place-items: center; border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--canvas) 86%, transparent); border: 2px dashed var(--accent); font-size: 20px; font-weight: 600; color: var(--accent);
  animation: fade .14s ease; }
@keyframes fade { from { opacity: 0; } }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(48px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 14px;
  max-width: min(560px, 92vw); background: var(--card); color: var(--text); border: 1px solid var(--line); padding: 10px 10px 10px 16px; border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); font-size: 13.5px; animation: toastIn .22s var(--ease); }
.toast.bad { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); }
.toast.bad::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none; }
.toast #toastText { padding-right: 6px; }
.toast button { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 600; border-radius: var(--r-sm); padding: 6px 12px; cursor: pointer; }
.toast button:hover { background: var(--selected); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- Dialogs ---------- */
dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px;
  width: min(470px, 94vw); max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(14, 17, 16, .38); }
dialog[open] { animation: pop .2s var(--ease); }
dialog[open]::backdrop { animation: fade .2s ease; }
dialog.closing { animation: popOut .16s ease forwards; }
dialog.closing::backdrop { animation: fadeOut .16s ease forwards; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes popOut { to { opacity: 0; transform: translateY(6px) scale(.985); } }
@keyframes fadeOut { to { opacity: 0; } }
dialog.small { width: min(420px, 94vw); }
dialog h3 { font-size: 17px; font-weight: 600; }
dialog h4 { font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.file-name { color: var(--muted); word-break: break-all; margin: 4px 0 0; }
.field { display: block; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.field input, .field select { display: block; width: 100%; height: 36px; margin-top: 5px; background: var(--card-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 0 11px; color: var(--text); font-size: 14px; transition: border-color .12s ease, box-shadow .12s ease; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--selected); }
.check { display: flex; gap: 9px; align-items: center; margin-top: 14px; }
.check input { accent-color: var(--accent); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.actions.split { justify-content: space-between; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.pick-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 16px; }
.pick-opts .btn { justify-content: flex-start; }
.pick-opts .btn::before { content: ""; width: 10px; height: 12px; border-radius: 2px 4px 2px 2px; background: var(--c); }

.game-head { display: flex; gap: 20px; align-items: flex-end; }
.game-art { width: 150px; height: 160px; display: flex; align-items: flex-end; justify-content: center; flex: none;
  border-bottom: 4px solid var(--shelf); box-shadow: 0 5px 0 var(--shelf-lip); }
.game-main { flex: 1; min-width: 0; padding-bottom: 4px; }
.name-input { width: 100%; resize: none; overflow: hidden; line-height: 1.2; border: 0; border-bottom: 1px dashed transparent; background: none;
  font-size: 20px; font-weight: 600; letter-spacing: -.015em; padding: 2px 0; color: var(--text); }
.name-input:hover { border-bottom-color: var(--line-strong); }
.name-input:focus { outline: none; border-bottom-color: var(--accent); }
.game-main p { margin: 2px 0 14px; }
.why { font-size: 12.5px; color: var(--muted); margin-top: 10px !important; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 20px 0 0; padding: 12px 14px; background: var(--card-2);
  border: 1px solid var(--line-soft); border-radius: var(--r-md); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-all; }

dialog.side { margin: 8px 8px 8px auto; height: calc(100vh - 16px); max-height: none; width: min(440px, calc(100vw - 16px)); padding: 0 22px 26px; }
dialog.side[open] { animation: slideIn .24s var(--ease); }
dialog.side.closing { animation: slideOut .18s ease forwards; }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }
@keyframes slideOut { to { transform: translateX(24px); opacity: 0; } }
.side-head { position: sticky; top: 0; background: var(--card); display: flex; justify-content: space-between; align-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 0 10px; z-index: 1; }
.set { padding: 16px 0; border-top: 1px solid var(--line-soft); }
.set:first-of-type { border-top: 0; padding-top: 4px; }
.set p { margin: 0 0 6px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; height: 30px; border-radius: var(--r-sm); cursor: pointer; font-weight: 500; color: var(--muted); transition: background-color .15s ease, color .15s ease; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--card); color: var(--accent); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.set-row:last-child { border-bottom: 0; }
.set-row .row { margin-top: 0; flex-wrap: nowrap; }
.set-row.native { align-items: flex-start; flex-direction: column; }
.path { font-size: 12.5px; color: var(--muted); word-break: break-all; margin-top: 2px; }
.path b { color: var(--text); font-weight: 500; }
.set label.btn { display: inline-flex; margin: 0; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 4px 0 0; align-items: center; }
.keys dt { white-space: nowrap; } .keys dd { margin: 0; color: var(--muted); }

/* ---------- Launch overlay (library and player) ---------- */
.launch { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: var(--canvas); animation: fade .18s ease; }
.launch .bay { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.launch .slotline { width: 220px; height: 30px; border-radius: 0 0 12px 12px; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--shelf);
  position: relative; z-index: 2; }
.launch .art { animation: insert .55s var(--ease) .05s both; margin-bottom: -26px; }
.launch p { color: var(--muted); margin: 0; }
.launch b { color: var(--text); font-weight: 600; }
@keyframes insert { from { transform: translateY(-40px); opacity: 0; } 60% { opacity: 1; } to { transform: translateY(18px); } }

/* ---------- Player ---------- */
body.player { background: #000; overflow: hidden; }
#wrap { position: fixed; inset: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#game { width: 100%; height: 100%; }
.back { position: fixed; z-index: 10; top: calc(10px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left));
  display: inline-flex; align-items: center; gap: 4px; background: rgba(22, 27, 26, .72); color: #E8E4DC; text-decoration: none; border: 1px solid rgba(255,255,255,.08);
  padding: 6px 13px 6px 9px; border-radius: 999px; font: 500 13px "Geist", system-ui, sans-serif;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); opacity: .78; transition: opacity .15s ease; }
.back:hover { opacity: 1; }
.player-err { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; z-index: 90;
  background: var(--canvas); color: var(--text); font-family: "Geist", system-ui, sans-serif; }
.player-err p { max-width: 440px; margin: 0 auto 16px; }

/* ---------- View transitions ---------- */
::view-transition-old(shelf), ::view-transition-new(shelf) { animation-duration: .2s; animation-timing-function: var(--ease); }
::view-transition-new(shelf) { animation-name: shelfIn; }
@keyframes shelfIn { from { opacity: 0; transform: translateY(6px); } }
.scroller > #shelf { view-transition-name: shelf; }

/* ---------- Phone ---------- */
@media (max-width: 820px) {
  .sortby span { display: none; }
  .filter { width: 200px; }
  .tb.wide span { display: none; }
}
@media (max-width: 700px) {
  .only-phone { display: inline-flex !important; }
  .canvas { --gap: 6px; }
  .body { grid-template-columns: minmax(0, 1fr); }
  .sortby select { width: 120px; }
  .topcard { flex-wrap: wrap; row-gap: 8px; padding: 6px 8px; }
  .brand { padding-left: 2px; }
  .tb-right { order: 5; width: 100%; margin: 0; }
  .filter { flex: 1; width: auto; min-width: 0; }
  .topcard { min-width: 0; }
  .tb-right { min-width: 0; }
  .sortby { flex: none; }
  .rail { position: fixed; z-index: 50; top: calc(8px + env(safe-area-inset-top)); bottom: 8px; left: 8px; width: min(280px, 82vw);
    transform: translateX(-110%); transition: transform .26s var(--ease); box-shadow: var(--shadow-lg); }
  .rail.open { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 45; background: rgba(14, 17, 16, .35); animation: fade .2s ease; }
  .main-head { padding: 12px 16px 10px; }
  .scroller { padding: 16px 12px 30px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); row-gap: 20px; }
  .slot { height: 160px; padding: 0 6px; }
  .cap { padding: 10px 6px 0; }
  .resume { gap: 14px; padding: 14px; margin-bottom: 20px; }
  .resume .stand { width: 112px; height: 128px; }
  .resume .stand .art { transform: scale(.88); }
  .resume h2 { font-size: 18px; }
  .statusbar { height: 26px; font-size: 12px; }
  .statusbar #sbGames { display: none; }
  .game-head { flex-direction: column; align-items: stretch; }
  .game-art { width: 100%; }
  dialog.side { margin: 0; width: 100vw; height: 100dvh; border-radius: 0; }
  .toast { bottom: calc(36px + env(safe-area-inset-bottom)); }
}
@media (max-width: 380px) { .grid { grid-template-columns: repeat(2, 1fr); } .art { zoom: .88; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (hover: none) { .filter kbd { display: none; } }

/* Cover art on the label */
.art .lbl.cover { background-size: cover; background-position: center; padding: 0; }
.art .lbl.cover span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.pbar { position: fixed; z-index: 10; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); display: flex; gap: 2px;
  background: rgba(22, 27, 26, .72); border: 1px solid rgba(255,255,255,.08); border-radius: 999px; padding: 3px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); opacity: .78; transition: opacity .15s ease; }
.pbar:hover { opacity: 1; }
.pbar button { border: 0; background: none; color: #E8E4DC; font: 500 13px "Geist", system-ui, sans-serif; padding: 5px 11px; border-radius: 999px; cursor: pointer; }
.pbar button:hover { background: rgba(255,255,255,.1); }
.pbar button[aria-pressed="true"] { background: #52C3AF; color: #04201B; }
.tabs { margin-top: 18px; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--accent); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.tabpane { padding-top: 6px; min-height: 120px; }
.statebox { display: flex; gap: 14px; align-items: center; margin-top: 14px; padding: 10px; background: var(--card-2); border: 1px solid var(--line-soft); border-radius: var(--r-md); }
.statebox img { width: 120px; aspect-ratio: 4/3; object-fit: cover; border-radius: var(--r-sm); background: #000; flex: none; }
.statebox img:not([src]) { visibility: hidden; }
.statebox p { margin: 2px 0 0; }
.statebox .row { margin-top: 8px; }
.art-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 10px; }
.art-results button { border: 1px solid var(--line); background: var(--card-2); border-radius: var(--r-md); padding: 6px; cursor: pointer; text-align: left; font-size: 11.5px; color: var(--muted); }
.art-results button:hover { border-color: var(--accent); color: var(--text); }
.art-results img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; margin-bottom: 4px; }
/* Keep the emulator's messages clear of the Library and toolbar pills */
body.player .ejs_message { top: calc(52px + env(safe-area-inset-top)) !important; left: calc(12px + env(safe-area-inset-left)) !important; }
