/* nesearch UI prototype — visual spec, not production CSS */
:root {
  --bg: #090b0f;
  --bg-elev: #0d1016;
  --surface: #11151d;
  --surface-2: #161b25;
  --surface-3: #1c2230;
  --border: #232a38;
  --border-strong: #323b4d;
  --text: #eef2f8;
  --text-2: #a6afc0;
  --text-3: #6f788a;
  --red: #ff4d57;
  --red-soft: rgba(255, 77, 87, 0.12);
  --red-line: rgba(255, 77, 87, 0.38);
  --amber: #ffb454;
  --amber-soft: rgba(255, 180, 84, 0.12);
  --green: #4ade9b;
  --green-soft: rgba(74, 222, 155, 0.12);
  --blue: #67a8ff;
  --blue-soft: rgba(103, 168, 255, 0.12);
  --violet: #b08cff;
  --violet-soft: rgba(176, 140, 255, 0.12);
  --sidebar: 224px;
  --detail: 368px;
  --top: 64px;
  --tray: 92px;
  --status: 26px;
  --radius: 12px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
::selection { background: rgba(255, 77, 87, 0.35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #252c3a; border: 3px solid transparent; background-clip: content-box; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #343e52; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--detail);
  grid-template-rows: var(--top) minmax(0, 1fr) var(--tray) var(--status);
  grid-template-areas:
    "top top top"
    "side main detail"
    "side tray tray"
    "status status status";
  background:
    radial-gradient(900px 520px at 4% -10%, rgba(255, 77, 87, 0.075), transparent 62%),
    radial-gradient(760px 520px at 108% -6%, rgba(103, 168, 255, 0.045), transparent 60%),
    var(--bg);
}
.app.no-detail {
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-areas: "top top" "side main" "side tray" "status status";
}
.app.no-detail .detail { display: none; }

/* ---------- top bar ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 20px 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 17, 0.82);
  backdrop-filter: blur(18px);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 9px; width: calc(var(--sidebar) - 36px); flex: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2b1620, #18121a);
  border: 1px solid rgba(255, 77, 87, 0.35);
  color: var(--red);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.brand-mark .icon { width: 18px; height: 18px; }
.brand-name { font: 600 15px/1 var(--mono); letter-spacing: -0.02em; }
.brand-ver { font: 9px/1 var(--mono); color: var(--text-3); border: 1px solid var(--border); border-radius: 4px; padding: 3px 4px; }

.searchbox {
  display: flex; align-items: center; gap: 9px;
  height: 38px; width: min(500px, 40vw);
  padding: 0 9px 0 11px;
  background: #0b0e14;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-3);
  transition: border-color .16s ease, box-shadow .16s ease;
}
.searchbox:focus-within { border-color: var(--red-line); box-shadow: 0 0 0 3px rgba(255, 77, 87, 0.09); color: var(--text-2); }
.searchbox input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 12.5px; }
.searchbox input::placeholder { color: var(--text-3); }
.searchbox kbd {
  font: 10px/1 var(--mono); color: var(--text-3);
  padding: 4px 5px; border: 1px solid var(--border); border-bottom-color: var(--border-strong);
  border-radius: 5px; background: var(--surface-2); white-space: nowrap;
}
.search-clear[hidden] { display: none; }
.search-clear { width: 20px; height: 20px; border-radius: 5px; color: var(--text-3); display: grid; place-items: center; }
.search-clear:hover { color: var(--text); background: var(--surface-3); }
.search-clear .icon { width: 13px; height: 13px; }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.source-select {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 9px 0 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-2); font-size: 11.5px;
}
.source-select select { appearance: none; border: 0; outline: 0; background: transparent; color: var(--text-2); padding-right: 2px; cursor: pointer; font-size: 11.5px; }
.source-select .icon { width: 12px; height: 12px; color: var(--text-3); }
.pulse { width: 6px; height: 6px; border-radius: 999px; background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 155, 0.12); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font-size: 11.5px; font-weight: 550; transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); border-color: var(--red); color: #19080b; font-weight: 700; box-shadow: 0 6px 18px rgba(255, 77, 87, 0.18); }
.btn.primary:hover { background: #ff646d; border-color: #ff646d; }
.btn.soft { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 9px; font-size: 10.5px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; color: var(--text-3); display: grid; place-items: center; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* ---------- sidebar ---------- */
.sidebar {
  grid-area: side;
  display: flex; flex-direction: column;
  padding: 16px 12px 12px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(14, 17, 23, 0.65), rgba(9, 11, 15, 0.35));
  overflow: auto;
}
.nav-label { padding: 2px 10px 9px; font-size: 9px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3); }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px;
  width: 100%; height: 37px; padding: 0 10px; border-radius: 8px;
  color: var(--text-2); font-size: 12px; text-align: left;
  transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg, rgba(255, 77, 87, 0.145), rgba(255, 77, 87, 0.035)); color: var(--text); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 2px;
  border-radius: 0 2px 2px 0; background: var(--red);
}
.nav-item.active .icon { color: var(--red); }
.nav-item .icon { width: 15px; height: 15px; color: var(--text-3); }
.nav-count { margin-left: auto; font: 10px var(--mono); color: var(--text-3); }
.nav-badge {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; display: grid; place-items: center;
  font: 9.5px var(--mono); color: #1d0709; background: var(--red);
}
.nav-dot { margin-left: auto; width: 6px; height: 6px; border-radius: 99px; background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 155, 0.1); }
.sidebar-spacer { flex: 1; min-height: 24px; }
.source-status {
  padding: 11px; border: 1px solid var(--border); border-radius: 10px;
  background: linear-gradient(155deg, var(--surface), #0d1016);
}
.source-status-head { display: flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 10.5px; font-weight: 600; }
.source-status-head > span:last-child { margin-left: auto; font: 9.5px var(--mono); color: var(--green); }
.source-status-row { display: flex; align-items: center; gap: 7px; margin-top: 8px; font-size: 10.5px; color: var(--text-3); }
.source-status-row .dot { width: 5px; height: 5px; border-radius: 99px; background: var(--green); }
.source-status-row .name { color: var(--text-2); }
.source-status-row .count { margin-left: auto; font: 9.5px var(--mono); color: var(--text-3); }
.source-status-foot { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; color: var(--text-3); font-size: 9.5px; }
.source-status-foot button { color: var(--text-2); font-size: 9.5px; }
.source-status-foot button:hover { color: var(--red); }
.sidebar-hint {
  display: flex; gap: 9px; align-items: flex-start; margin-top: 9px; padding: 10px;
  border: 1px dashed var(--border); border-radius: 10px; color: var(--text-3);
}
.sidebar-hint .icon { width: 14px; height: 14px; margin-top: 1px; color: var(--violet); }
.sidebar-hint strong { display: block; font-size: 10.5px; color: var(--text-2); font-weight: 600; }
.sidebar-hint span { display: block; font-size: 9.5px; line-height: 1.45; margin-top: 2px; }

/* ---------- main ---------- */
.main {
  grid-area: main;
  min-width: 0;
  overflow: auto;
  padding: 22px 24px 26px;
  scrollbar-gutter: stable;
}
.view[hidden] { display: none !important; }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 17px; }
.eyebrow { display: flex; align-items: center; gap: 6px; font: 9.5px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--red); margin-bottom: 7px; }
.eyebrow .icon { width: 12px; height: 12px; }
h1 { margin: 0; font-size: 25px; line-height: 1.1; letter-spacing: -0.035em; font-weight: 700; }
.view-sub { margin: 6px 0 0; font-size: 11.5px; color: var(--text-3); }
.view-sub b { color: var(--text-2); font-weight: 550; }
.view-actions { display: flex; align-items: center; gap: 8px; flex: none; padding-top: 3px; }
.select {
  height: 32px; padding: 0 28px 0 10px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236f788a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 9px center;
  appearance: none; outline: 0; color: var(--text-2); font-size: 10.5px; cursor: pointer;
}
.select:hover { border-color: var(--border-strong); color: var(--text); }
.segmented { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.segmented button { width: 27px; height: 26px; border-radius: 5px; display: grid; place-items: center; color: var(--text-3); }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.segmented .icon { width: 14px; height: 14px; }

.filter-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 29px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--border); background: rgba(17, 21, 29, .75);
  color: var(--text-3); font-size: 10.5px; white-space: nowrap;
  transition: border-color .14s ease, color .14s ease, background .14s ease;
}
.chip:hover { color: var(--text-2); border-color: var(--border-strong); }
.chip.active { color: #ffb7bc; border-color: rgba(255, 77, 87, .36); background: var(--red-soft); }
.chip .icon { width: 12px; height: 12px; }
.chip-sep { width: 1px; height: 17px; background: var(--border); margin: 0 4px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(182px, 1fr)); gap: 12px; }
.grid.list { grid-template-columns: 1fr; gap: 8px; }
.card {
  position: relative; min-width: 0; overflow: hidden; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px;
  background: linear-gradient(180deg, var(--surface), #0d1016);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: 0 14px 34px rgba(0, 0, 0, .34); }
.card.selected { border-color: rgba(255, 77, 87, .62); box-shadow: 0 0 0 1px rgba(255, 77, 87, .12), 0 16px 36px rgba(0, 0, 0, .38); }
.card-media { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: #05070a; }
.card-media img { width: 100%; height: 100%; display: block; object-fit: cover; image-rendering: pixelated; transition: transform .35s ease, filter .35s ease; }
.card:hover .card-media img { transform: scale(1.035); filter: brightness(1.05); }
.card-media::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(5, 7, 10, .05) 35%, rgba(5, 7, 10, .6)); pointer-events: none; }
.card-topline { position: absolute; top: 7px; left: 7px; right: 7px; display: flex; align-items: center; justify-content: space-between; gap: 5px; z-index: 2; }
.source-pill {
  display: inline-flex; align-items: center; gap: 5px; max-width: 76%;
  padding: 3px 6px; border-radius: 5px; background: rgba(7, 9, 13, .72);
  border: 1px solid rgba(255, 255, 255, .09); backdrop-filter: blur(8px);
  color: #c9d0dd; font: 8.5px/1.2 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.source-pill .dot { width: 4px; height: 4px; border-radius: 99px; background: var(--green); }
.source-pill.hh .dot { background: var(--violet); }
.source-pill.pd .dot { background: var(--amber); }
.card-dl {
  width: 25px; height: 25px; border-radius: 6px; display: grid; place-items: center;
  color: #dbe2ee; background: rgba(7, 9, 13, .68); border: 1px solid rgba(255, 255, 255, .11);
  backdrop-filter: blur(8px); transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.card-dl:hover { background: var(--red); border-color: var(--red); color: #1b0709; }
.card-dl .icon { width: 13px; height: 13px; }
.card-body { padding: 10px 11px 11px; }
.card-title { margin: 0; font-size: 12.5px; line-height: 1.3; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-author { margin: 3px 0 0; font-size: 10px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: 8px; font: 9px var(--mono); color: var(--text-3); }
.card-meta .sep { color: #394154; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 9px; }
.license-pill { display: inline-flex; align-items: center; gap: 4px; font: 8.5px var(--mono); color: var(--text-3); }
.license-pill .dot { width: 4px; height: 4px; border-radius: 99px; background: var(--green); }
.license-pill.unknown .dot { background: var(--amber); }
.card-kind { font: 8.5px var(--mono); color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.card-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255, 255, 255, .07); z-index: 3; }
.card-progress span { display: block; height: 100%; background: var(--red); }

/* list view */
.grid.list .card { display: grid; grid-template-columns: 118px minmax(0, 1fr); align-items: stretch; }
.grid.list .card-media { aspect-ratio: auto; height: 100%; min-height: 86px; }
.grid.list .card-media::after { background: linear-gradient(90deg, transparent 55%, rgba(13, 16, 22, .7)); }
.grid.list .card-body { display: flex; flex-direction: column; justify-content: center; padding: 10px 13px; }
.grid.list .card-title { font-size: 12.5px; }
.grid.list .card-foot { margin-top: 8px; }
.grid.list .card-topline { right: auto; }
.grid.list .card-topline .source-pill { display: none; }
.grid.list .card-dl { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
.grid.list .card-progress { left: 118px; }

.grid-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 15px; padding-top: 12px; border-top: 1px solid rgba(35, 42, 56, .6); }
.showing { font: 9.5px var(--mono); color: var(--text-3); }
.pager { display: flex; align-items: center; gap: 3px; }
.pager button { width: 24px; height: 24px; border-radius: 5px; color: var(--text-3); font: 10px var(--mono); display: grid; place-items: center; }
.pager button:hover { background: var(--surface-2); color: var(--text); }
.pager button.active { background: var(--red-soft); color: #ffb7bc; }
.pager .icon { width: 12px; height: 12px; }

.empty-state { padding: 54px 20px; text-align: center; border: 1px dashed var(--border); border-radius: 12px; background: rgba(17, 21, 29, .35); }
.empty-state .empty-icon { width: 42px; height: 42px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 12px; color: var(--text-3); background: var(--surface-2); }
.empty-state h2 { margin: 0 0 5px; font-size: 14px; }
.empty-state p { margin: 0 0 14px; color: var(--text-3); font-size: 11.5px; }

/* ---------- detail ---------- */
.detail {
  grid-area: detail;
  position: relative;
  overflow: auto;
  padding: 16px 18px 20px;
  border-left: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(15, 18, 25, .82), rgba(10, 12, 17, .85));
}
.detail-close { display: none; position: absolute; top: 8px; right: 8px; z-index: 5; width: 26px; height: 26px; border-radius: 6px; background: rgba(7,9,13,.72); border: 1px solid var(--border); color: var(--text-2); place-items: center; }
.detail-close:hover { color: var(--text); background: var(--surface-3); }
.detail-close .icon { width: 13px; height: 13px; }
.detail-media { position: relative; overflow: hidden; aspect-ratio: 3 / 2; border-radius: 11px; border: 1px solid var(--border); background: #05070a; }
.detail-media img { width: 100%; height: 100%; display: block; object-fit: cover; image-rendering: pixelated; }
.detail-media::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 55%, rgba(5, 7, 10, .4)); pointer-events: none; }
.detail-top-badges { position: absolute; left: 8px; top: 8px; display: flex; gap: 5px; z-index: 2; }
.detail-badge { padding: 3px 6px; border-radius: 5px; background: rgba(7, 9, 13, .74); border: 1px solid rgba(255,255,255,.1); font: 8.5px var(--mono); color: #dbe2ee; backdrop-filter: blur(8px); }
.detail-head { margin-top: 14px; }
.detail-title { margin: 0; font-size: 21px; line-height: 1.2; letter-spacing: -0.035em; font-weight: 700; }
.detail-author { margin: 5px 0 0; color: var(--text-3); font-size: 11px; }
.detail-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.mini-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 4px; font: 8.5px var(--mono); color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); }
.mini-chip.green { color: #9df0c8; background: var(--green-soft); border-color: rgba(74, 222, 155, .2); }
.mini-chip.amber { color: #ffd39a; background: var(--amber-soft); border-color: rgba(255, 180, 84, .2); }
.mini-chip.blue { color: #b7d4ff; background: var(--blue-soft); border-color: rgba(103, 168, 255, .2); }
.mini-chip.violet { color: #d5c4ff; background: var(--violet-soft); border-color: rgba(176, 140, 255, .2); }
.detail-desc { margin: 12px 0 0; color: var(--text-2); font-size: 11.5px; line-height: 1.65; }
.detail-actions { display: flex; gap: 7px; margin-top: 14px; }
.detail-actions .btn.primary { flex: 1; height: 37px; font-size: 11.5px; }
.detail-actions .btn.icon-only { width: 37px; padding: 0; flex: none; }
.detail-progress { margin-top: 8px; }
.progress-track { height: 4px; overflow: hidden; border-radius: 99px; background: #222938; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ff4d57, #ff8d6b); transition: width .4s ease; }
.progress-caption { display: flex; justify-content: space-between; margin-top: 5px; font: 9px var(--mono); color: var(--text-3); }
.section-label { margin: 18px 0 8px; font: 8.5px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); }
.meta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: rgba(17, 21, 29, .55); }
.meta-label { font: 8px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.meta-value { margin-top: 4px; font: 10.5px/1.2 var(--mono); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta-value.green { color: var(--green); }
.provenance { padding: 10px 11px; border: 1px solid var(--border); border-radius: 9px; background: rgba(17, 21, 29, .55); }
.prov-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 10px; }
.prov-row + .prov-row { margin-top: 7px; padding-top: 7px; border-top: 1px solid rgba(35, 42, 56, .6); }
.prov-row span:first-child { color: var(--text-3); }
.prov-row span:last-child { color: var(--text-2); font-family: var(--mono); font-size: 9.5px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prov-link { display: inline-flex; align-items: center; gap: 4px; color: var(--blue); font-size: 10px; margin-top: 8px; }
.prov-link:hover { text-decoration: underline; }
.detail-empty { padding: 50px 12px; text-align: center; color: var(--text-3); font-size: 11.5px; }

/* ---------- download tray ---------- */
.tray {
  grid-area: tray;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background: rgba(11, 14, 20, .93);
  backdrop-filter: blur(16px);
  z-index: 20;
  min-width: 0;
}
.tray-head { width: 132px; flex: none; }
.tray-title { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 650; }
.tray-title .icon { width: 13px; height: 13px; color: var(--red); }
.tray-sub { margin-top: 3px; font: 9px var(--mono); color: var(--text-3); }
.tray-items { display: flex; align-items: stretch; gap: 8px; flex: 1; min-width: 0; overflow: hidden; }
.dl-item {
  flex: 1; min-width: 188px; max-width: 310px;
  display: flex; flex-direction: column; justify-content: center; gap: 5px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px;
  background: linear-gradient(180deg, var(--surface), #0e1117);
}
.dl-top { display: flex; align-items: center; gap: 7px; min-width: 0; }
.dl-status-icon { width: 18px; height: 18px; flex: none; display: grid; place-items: center; border-radius: 5px; background: var(--surface-3); color: var(--text-3); }
.dl-status-icon .icon { width: 11px; height: 11px; }
.dl-item.downloading .dl-status-icon { color: var(--red); background: var(--red-soft); }
.dl-item.done .dl-status-icon { color: var(--green); background: var(--green-soft); }
.dl-item.queued .dl-status-icon { color: var(--amber); background: var(--amber-soft); }
.dl-name { min-width: 0; flex: 1; font-size: 10.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-pct { font: 9px var(--mono); color: var(--text-3); margin-left: auto; }
.dl-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font: 8.5px var(--mono); color: var(--text-3); }
.dl-meta .green { color: var(--green); }
.dl-item .progress-track { height: 2px; }
.dl-item .progress-track span { background: var(--red); }
.dl-item.done .progress-track span { background: var(--green); }
.dl-item.queued .progress-track span { background: #3a4356; }
.tray-more { flex: none; align-self: center; font: 9px var(--mono); color: var(--text-3); }
.tray-expand { flex: none; width: 26px; height: 26px; border-radius: 6px; color: var(--text-3); display: grid; place-items: center; }
.tray-expand:hover { background: var(--surface-2); color: var(--text); }

/* ---------- status bar ---------- */
.statusbar {
  grid-area: status;
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  border-top: 1px solid #151a24;
  background: #07090d;
  color: var(--text-3);
  font: 9px var(--mono);
  white-space: nowrap;
  overflow: hidden;
}
.status-item { display: inline-flex; align-items: center; gap: 5px; }
.status-item .pulse { width: 5px; height: 5px; }
.status-sep { color: #2b3342; }
.status-right { margin-left: auto; display: flex; align-items: center; gap: 13px; }
.status-right a { color: var(--text-3); }
.status-right a:hover { color: var(--text-2); }
.status-key { color: #4a5468; }
.statusbar code { color: #aeb7c7; font-family: var(--mono); }

/* ---------- views: downloads / library / sources / settings ---------- */
.view-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.view-title-row h1 { font-size: 23px; }
.panel { border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(180deg, var(--surface), #0e1117); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 11.5px; font-weight: 650; }
.panel-head .muted { color: var(--text-3); font: 9px var(--mono); }
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 9px 14px; text-align: left; font: 8.5px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); border-bottom: 1px solid var(--border); background: rgba(7, 9, 13, .35); }
.table td { padding: 10px 14px; border-bottom: 1px solid rgba(35, 42, 56, .52); font-size: 10.5px; color: var(--text-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: rgba(28, 34, 48, .35); }
.table .game-cell { display: flex; align-items: center; gap: 9px; min-width: 0; }
.table .thumb { width: 38px; height: 30px; border-radius: 5px; object-fit: cover; image-rendering: pixelated; border: 1px solid var(--border); background: #05070a; }
.table .game-name { font-size: 11px; color: var(--text); font-weight: 550; }
.table .game-sub { font: 8.5px var(--mono); color: var(--text-3); margin-top: 2px; }
.table .mono { font-family: var(--mono); font-size: 9px; color: var(--text-3); }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 5px; }
.row-btn { width: 24px; height: 24px; border-radius: 5px; display: grid; place-items: center; color: var(--text-3); }
.row-btn:hover { background: var(--surface-3); color: var(--text); }
.row-btn .icon { width: 12px; height: 12px; }
.status-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 4px; font: 8.5px var(--mono); }
.status-pill.downloading { color: #ffb7bc; background: var(--red-soft); }
.status-pill.queued { color: #ffd39a; background: var(--amber-soft); }
.status-pill.done { color: #9df0c8; background: var(--green-soft); }
.inline-progress { width: 88px; height: 4px; display: inline-block; vertical-align: middle; margin-right: 7px; }

.sources-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.source-card { padding: 13px; border: 1px solid var(--border); border-radius: 11px; background: linear-gradient(160deg, var(--surface), #0d1016); }
.source-card-head { display: flex; align-items: flex-start; gap: 9px; }
.source-logo { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.source-logo .icon { width: 15px; height: 15px; }
.source-logo.github { color: #d7dde8; }
.source-logo.hh { color: var(--violet); background: var(--violet-soft); }
.source-logo.pd { color: var(--amber); background: var(--amber-soft); }
.source-name { font-size: 11.5px; font-weight: 600; }
.source-type { margin-top: 2px; font: 8.5px var(--mono); color: var(--text-3); }
.source-status-dot { margin-left: auto; width: 6px; height: 6px; border-radius: 99px; background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 155, .1); }
.source-desc { margin: 10px 0 0; color: var(--text-3); font-size: 10px; line-height: 1.5; min-height: 30px; }
.source-stats { display: flex; gap: 14px; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); }
.source-stat b { display: block; font: 12px var(--mono); color: var(--text-2); font-weight: 500; }
.source-stat span { display: block; margin-top: 2px; font-size: 8.5px; color: var(--text-3); }
.source-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.source-card-foot .muted { font: 8.5px var(--mono); color: var(--text-3); }
.add-source { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 178px; border: 1px dashed var(--border-strong); border-radius: 11px; color: var(--text-3); background: rgba(17, 21, 29, .25); }
.add-source:hover { border-color: var(--red-line); color: var(--text-2); background: rgba(255, 77, 87, .03); }
.add-source .icon { width: 18px; height: 18px; }
.add-source span { font-size: 10px; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, .8fr); gap: 14px; }
.settings-panel { padding: 14px; border: 1px solid var(--border); border-radius: 11px; background: linear-gradient(160deg, var(--surface), #0d1016); }
.settings-panel h2 { margin: 0 0 3px; font-size: 11.5px; font-weight: 650; }
.settings-panel .hint { margin: 0 0 12px; color: var(--text-3); font-size: 10px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-top: 1px solid rgba(35, 42, 56, .55); }
.field:first-of-type { border-top: 0; }
.field label { font-size: 10.5px; color: var(--text-2); }
.field .sub { display: block; margin-top: 2px; font-size: 9px; color: var(--text-3); }
.input { height: 29px; min-width: 160px; padding: 0 8px; border: 1px solid var(--border); border-radius: 6px; background: #0a0d13; color: var(--text-2); font: 10px var(--mono); outline: 0; }
.input:focus { border-color: var(--red-line); }
.switch { position: relative; width: 32px; height: 18px; border-radius: 99px; background: #2a3242; transition: background .15s ease; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #a6afc0; transition: transform .15s ease, background .15s ease; }
.switch.on { background: var(--red); }
.switch.on::after { transform: translateX(14px); background: #fff; }
.settings-note { margin-top: 12px; padding: 10px; border: 1px dashed var(--border); border-radius: 8px; color: var(--text-3); font-size: 9.5px; line-height: 1.5; }
.settings-note code { font-family: var(--mono); color: var(--text-2); }

/* ---------- modal / toast ---------- */
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: rgba(3, 5, 8, .72); backdrop-filter: blur(8px); }
.modal-card { width: min(610px, 94vw); max-height: 88vh; overflow: auto; padding: 20px; border: 1px solid var(--border-strong); border-radius: 14px; background: #10141c; box-shadow: 0 30px 90px rgba(0, 0, 0, .55); }
.modal-head { display: flex; align-items: flex-start; gap: 11px; }
.modal-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--violet); background: var(--violet-soft); border: 1px solid rgba(176, 140, 255, .2); flex: none; }
.modal-icon .icon { width: 17px; height: 17px; }
.modal-title { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.02em; }
.modal-sub { margin: 4px 0 0; color: var(--text-3); font-size: 10.5px; line-height: 1.5; }
.modal-close { margin-left: auto; width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; color: var(--text-3); }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.code-block { position: relative; margin: 14px 0 0; padding: 12px 13px; border: 1px solid var(--border); border-radius: 9px; background: #07090d; color: #c6cedd; font: 11px/1.7 var(--mono); white-space: pre-wrap; word-break: break-word; }
.code-block .comment { color: #596274; }
.code-block .cmd { color: #f1f4f9; }
.code-block .flag { color: #ffb454; }
.modal-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 14px; }
.cli-note { display: flex; gap: 8px; margin-top: 12px; color: var(--text-3); font-size: 9.5px; line-height: 1.5; }
.cli-note .icon { width: 13px; height: 13px; color: var(--text-3); margin-top: 1px; flex: none; }
.toast {
  position: fixed; right: 20px; bottom: calc(var(--status) + var(--tray) + 12px); z-index: 120;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: #151a24; color: var(--text-2); font-size: 10.5px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
  transform: translateY(8px); opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast .icon { width: 13px; height: 13px; color: var(--green); }
.toast.warn .icon { color: var(--amber); }

/* ---------- responsive ---------- */
@media (max-width: 1220px) {
  .app { grid-template-columns: 200px minmax(0, 1fr); grid-template-areas: "top top" "side main" "side tray" "status status"; }
  .detail { display: none; }
  .detail.open {
    display: block; position: fixed; z-index: 60;
    top: var(--top); right: 0; bottom: calc(var(--tray) + var(--status));
    width: min(380px, 92vw); border-left: 1px solid var(--border-strong);
    background: #0f131b; box-shadow: -24px 0 70px rgba(0, 0, 0, .55);
  }
  .detail.open .detail-close { display: grid; }
  .brand { width: 176px; }
  .brand-ver { display: none; }
  .searchbox { width: min(420px, 42vw); }
  .tray-head { width: 112px; }
  .dl-item { min-width: 170px; }
}
@media (max-width: 900px) {
  .source-select { display: none; }
  .searchbox { width: min(360px, 48vw); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; }
}

input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }

/* source editor + local server */
.source-form { display: grid; gap: 12px; margin-top: 16px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field > label { font-size: 10px; font-weight: 600; color: var(--text-2); }
.form-field .hint { margin: 0; font-size: 9px; color: var(--text-3); line-height: 1.45; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input-text, .form-select {
  height: 33px; width: 100%; padding: 0 9px; border-radius: 7px;
  border: 1px solid var(--border); background: #0a0d13; color: var(--text-2);
  font: 10px var(--mono); outline: 0;
}
.input-text:focus, .form-select:focus { border-color: var(--red-line); box-shadow: 0 0 0 3px rgba(255,77,87,.08); }
.input-text::placeholder { color: #4d5668; }
.form-note { padding: 9px 10px; border: 1px dashed var(--border); border-radius: 7px; color: var(--text-3); font-size: 9px; line-height: 1.55; }
.form-note code { font-family: var(--mono); color: var(--text-2); }
.form-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0 0; border-top: 1px solid var(--border); }
.form-toggle label { font-size: 10px; color: var(--text-2); }
.server-box { display: flex; align-items: center; gap: 7px; margin-top: 10px; padding: 8px 9px; border: 1px solid var(--border); border-radius: 7px; background: #07090d; }
.server-box code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 10px var(--mono); color: var(--text-2); }
.server-box .row-btn { flex: none; }
.custom-source-card { animation: source-in .25s ease; }
@keyframes source-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* live-mode fallbacks for games without screenshots */
.card-placeholder, .detail-placeholder {
  width: 100%; height: 100%; display: grid; place-items: center;
  background:
    radial-gradient(120% 100% at 20% 0%, rgba(255,77,87,.18), transparent 55%),
    linear-gradient(145deg, #151b27, #090c12);
  color: #7d879b;
}
.card-placeholder .fallback-mark, .detail-placeholder .fallback-mark {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  font: 600 10px var(--mono); letter-spacing: .08em; text-transform: uppercase;
}
.card-placeholder .icon, .detail-placeholder .icon { width: 22px; height: 22px; color: var(--red); opacity: .8; }
.detail-placeholder .icon { width: 30px; height: 30px; }
.thumb-placeholder { width: 38px; height: 30px; border-radius: 5px; border: 1px solid var(--border); display: grid; place-items: center; background: #11151d; color: var(--red); font: 8px var(--mono); flex: none; }
.card-media > .card-placeholder, .detail-media > .detail-placeholder { position: absolute; inset: 0; z-index: 0; }
.card-media > img, .detail-media > img { position: relative; z-index: 1; }

/* emulator launch */
.play-row { display: flex; gap: 6px; margin-top: 7px; }
.play-row .btn { flex: 1; height: 34px; font-size: 10px; letter-spacing: .01em; }
.btn.play {
  color: #a5f3cf;
  background: rgba(74, 222, 155, .10);
  border-color: rgba(74, 222, 155, .28);
}
.btn.play:hover { background: rgba(74, 222, 155, .16); border-color: rgba(74, 222, 155, .45); color: #d7ffed; }
.btn.play:disabled { opacity: .38; cursor: not-allowed; }
.row-btn.play-emu { width: 22px; font: 7px var(--mono); color: var(--green); }
.row-btn.play-emu:hover { background: var(--green-soft); color: #c8ffe8; }
.emulator-state { font: 8.5px var(--mono); }
.emulator-state.ok { color: var(--green); }
.emulator-state.missing { color: var(--amber); }

/* library grid */
.library-grid[hidden], #libraryTableWrap[hidden] { display: none !important; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(218px, 1fr)); gap: 12px; padding: 13px; }
.library-card { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: linear-gradient(160deg, var(--surface), #0c0f15); min-width: 0; }
.library-card:hover { border-color: var(--border-strong); background: linear-gradient(160deg, var(--surface-2), #0d1118); }
.library-media { position: relative; aspect-ratio: 16 / 10; overflow: hidden; background: #07090d; }
.library-media > img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; position: relative; z-index: 1; display: block; }
.library-media > .card-placeholder { position: absolute; inset: 0; }
.library-body { padding: 10px 11px 11px; }
.library-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.library-title { margin: 0; font-size: 11.5px; font-weight: 650; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.library-meta { margin-top: 4px; color: var(--text-3); font: 8.5px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.library-tags { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.library-tags .mini-chip { font-size: 7.5px; }
.library-actions { display: flex; align-items: center; gap: 5px; margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--border); }
.library-actions .btn { height: 25px; padding: 0 7px; font-size: 8px; }
.library-actions .row-btn { margin-left: auto; }
.library-actions .row-btn + .row-btn { margin-left: 0; }
.library-empty { grid-column: 1 / -1; padding: 38px 16px; text-align: center; color: var(--text-3); }
.library-empty h2 { color: var(--text-2); font-size: 14px; margin: 0 0 5px; }
.library-empty p { margin: 0 0 12px; font-size: 10px; }
@media (max-width: 900px) { .library-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }

/* ---------------------------------------------------------------- sharing */
.share-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.share-label {
  display: block; margin-bottom: 7px;
  font: 9px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-3);
}
.share-row { display: flex; flex-wrap: wrap; gap: 6px; }
.share-btn {
  height: 27px; padding: 0 10px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font: 10.5px var(--mono); cursor: pointer; transition: color .15s ease, border-color .15s ease;
}
.share-btn:hover { color: var(--text); border-color: var(--border-strong); }
.share-btn:active { transform: translateY(1px); }

/* ================================================================ mobile */
/*
 * Phones (≤860px) get the app-shell treatment instead of a scaled-down
 * desktop: the sidebar becomes an off-canvas drawer, the detail panel a
 * bottom sheet, the download tray a horizontal strip, and tables scroll
 * sideways. Above 860px nothing here applies; touch laptops keep the desktop
 * layout and only get larger hit targets from the coarse-pointer block.
 */
.menu-btn,
.scrim,
.sidebar-close { display: none; }

@media (max-width: 860px), (orientation: landscape) and (max-height: 560px) {
  .app,
  .app.no-detail {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "top" "main" "tray" "status";
    height: 100vh;
    height: 100dvh;
  }

  /* ---- top bar: brand row + full-width search row ---- */
  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "menu brand actions" "search search search";
    align-items: center;
    gap: 8px;
    height: auto;
    padding: calc(8px + env(safe-area-inset-top, 0px))
      calc(12px + env(safe-area-inset-right, 0px)) 10px
      calc(12px + env(safe-area-inset-left, 0px));
  }
  .menu-btn {
    display: grid;
    grid-area: menu;
    width: 42px; height: 42px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text-2);
  }
  .app.nav-open .menu-btn { color: var(--text); border-color: var(--border-strong); }
  .brand { grid-area: brand; width: auto; min-width: 0; }
  .brand-ver { display: none; }
  .top-actions { grid-area: actions; margin-left: 0; gap: 6px; }
  .top-actions .icon-btn {
    width: 42px; height: 42px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface);
  }
  .top-actions .btn.ghost { width: 42px; height: 42px; padding: 0; font-size: 0; gap: 0; border-radius: 10px; }
  .searchbox { grid-area: search; width: 100%; height: 42px; }
  .searchbox kbd { display: none; }
  .source-select { display: none; }

  /* 16px keeps iOS Safari from zooming the page when an input is focused. */
  .searchbox input,
  .input,
  .input-text,
  .form-select { font-size: 16px; }

  /* ---- drawer ---- */
  .sidebar {
    position: fixed;
    z-index: 90;
    top: 0; bottom: 0; left: 0;
    width: min(84vw, 312px);
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px));
    border-right: 1px solid var(--border-strong);
    background: #0b0e13;
    box-shadow: 26px 0 70px rgba(0, 0, 0, 0.6);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .app.nav-open .sidebar { transform: none; visibility: visible; }
  .sidebar-close {
    display: grid; place-items: center;
    position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: 12px;
    width: 36px; height: 36px;
    border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface-2); color: var(--text-2);
  }
  .nav-item { height: 46px; font-size: 13.5px; border-radius: 10px; }
  .nav-item .icon { width: 17px; height: 17px; }
  .nav-count, .nav-badge { font-size: 11px; }
  .nav-label { padding: 14px 12px 8px; font-size: 10px; }
  .sidebar-spacer { min-height: 16px; }
  .source-status-head { font-size: 12px; }
  .source-status-row { font-size: 12px; }

  .scrim {
    display: block;
    position: fixed; inset: 0; z-index: 85;
    background: rgba(3, 5, 9, 0.64);
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }

  /* ---- main column ---- */
  .main {
    padding: 16px calc(14px + env(safe-area-inset-right, 0px))
      calc(20px + env(safe-area-inset-bottom, 0px))
      calc(14px + env(safe-area-inset-left, 0px));
  }
  .view-head,
  .view-title-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .view-actions { flex-wrap: wrap; padding-top: 0; }
  h1 { font-size: 26px; }
  .view-title-row h1 { font-size: 24px; }
  .view-sub { font-size: 12.5px; }
  .eyebrow { font-size: 10px; }

  /* filters scroll sideways instead of wrapping into five rows */
  .filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    margin-inline: calc(-14px - env(safe-area-inset-left, 0px)) calc(-14px - env(safe-area-inset-right, 0px));
    margin-block: 0 14px;
    padding: 2px calc(14px + env(safe-area-inset-right, 0px)) 6px calc(14px + env(safe-area-inset-left, 0px));
    scrollbar-width: none;
    mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
  }
  .filter-row::-webkit-scrollbar { display: none; }
  .chip { flex: none; height: 34px; font-size: 11.5px; }

  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.list { grid-template-columns: 1fr; }
  .grid.list .card { grid-template-columns: 108px minmax(0, 1fr); }
  .grid.list .card-progress { left: 108px; }
  .card-body { padding: 10px; }
  .card-title, .grid.list .card-title { font-size: 13px; }
  .card-author { font-size: 11px; }
  .card-meta { font-size: 9.5px; }
  .source-pill, .license-pill, .card-kind { font-size: 9.5px; }
  .card-dl { width: 32px; height: 32px; }
  .grid-foot { flex-wrap: wrap; gap: 8px; }
  .showing { font-size: 10.5px; }
  .pager button { width: 34px; height: 34px; font-size: 11px; }
  .empty-state { padding: 40px 16px; }
  .empty-state h2 { font-size: 16px; }

  /* tables scroll sideways instead of squashing */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #view-downloads .table,
  #view-library .table { min-width: 640px; }
  .table th { font-size: 9.5px; }
  .table td { font-size: 11.5px; }
  .row-btn { width: 34px; height: 34px; }

  .sources-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-panel h2 { font-size: 13px; }
  .settings-panel .hint { font-size: 10.5px; }
  .settings-note { font-size: 10.5px; }
  .field { flex-wrap: wrap; }
  .field label { font-size: 11.5px; }
  .field .sub { font-size: 10px; }
  .field .input { min-width: 0; width: 100%; max-width: none; height: 36px; }
  .source-desc { min-height: 0; font-size: 11.5px; }
  .source-type { font-size: 9.5px; }
  .add-source { min-height: 120px; }

  /* ---- detail: bottom sheet ---- */
  .detail.open {
    position: fixed;
    z-index: 96;
    top: auto; left: 0; right: 0; bottom: 0;
    width: auto;
    height: min(86dvh, 680px);
    padding: 20px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    border-left: 0;
    border-top: 1px solid var(--border-strong);
    border-radius: 16px 16px 0 0;
    background: linear-gradient(180deg, #121722, #0c0f15);
    box-shadow: 0 -26px 80px rgba(0, 0, 0, 0.62);
    animation: sheet-in 0.24s ease;
    overscroll-behavior: contain;
  }
  .detail.open::before {
    content: "";
    position: absolute; top: 8px; left: 50%;
    width: 40px; height: 4px; margin-left: -20px;
    border-radius: 99px; background: #2f3949;
  }
  .detail.open .detail-close { display: grid; top: 12px; right: 12px; width: 36px; height: 36px; }
  .detail-title { font-size: 20px; }
  .detail-author { font-size: 12px; }
  .detail-desc { font-size: 12.5px; }
  .mini-chip { font-size: 9.5px; }
  .meta-value { font-size: 11px; }
  .detail-actions .btn.primary { height: 44px; font-size: 12.5px; }
  .detail-actions .btn.icon-only { width: 44px; height: 44px; }
  .share-btn { height: 34px; }
  .detail-empty { padding: 36px 12px; }

  /* ---- download tray: one horizontal strip ---- */
  .tray {
    padding: 6px calc(10px + env(safe-area-inset-right, 0px)) 6px
      calc(10px + env(safe-area-inset-left, 0px));
    gap: 8px;
  }
  .tray-head { display: none; }
  .tray-items { overflow-x: auto; overflow-y: hidden; gap: 6px; scrollbar-width: none; }
  .tray-items::-webkit-scrollbar { display: none; }
  .dl-item { flex: none; min-width: 184px; max-width: 230px; }
  .tray-expand { width: 34px; height: 34px; }

  .statusbar {
    padding: 0 calc(12px + env(safe-area-inset-right, 0px))
      calc(env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
    gap: 8px; font-size: 8.5px; min-height: 24px;
  }
  .status-right { display: none; }

  .modal { padding: 12px; }
  .modal-card { width: 100%; max-height: 88dvh; padding: 16px; }
  .modal-title { font-size: 16px; }
  .modal-sub { font-size: 11.5px; }
  .toast {
    left: 12px; right: 12px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    justify-content: center;
  }

  @keyframes sheet-in {
    from { transform: translateY(100%); }
    to { transform: none; }
  }
}

/* Portrait tablets: two columns waste the width. */
@media (min-width: 600px) and (max-width: 860px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.list { grid-template-columns: 1fr; }
}

/* Landscape phones: a 390-560px tall canvas cannot afford a 100px top bar,
   a download tray and a bottom sheet, so they compact or move. */
@media (orientation: landscape) and (max-height: 560px) {
  .topbar {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "menu brand search actions";
    padding: 6px 12px;
    gap: 8px;
  }
  .searchbox { height: 38px; }
  .menu-btn, .top-actions .icon-btn { width: 38px; height: 38px; }
  .top-actions .btn.ghost { width: 38px; height: 38px; }
  .tray { display: none; }
  .main { padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px)); }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.list { grid-template-columns: 1fr; }
  .view-head, .view-title-row { flex-direction: row; align-items: flex-start; justify-content: space-between; gap: 12px; }
  .view-actions { flex-wrap: nowrap; }
  .detail.open {
    left: auto; right: 0; top: 0; bottom: 0;
    width: min(440px, 62vw); height: auto;
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
    border-radius: 16px 0 0 16px;
    border-left: 1px solid var(--border-strong);
    border-top: 0;
    animation: sheet-side 0.24s ease;
  }
  .detail.open::before { display: none; }
  .detail.open .detail-close { top: 12px; right: 12px; }
  @keyframes sheet-side {
    from { transform: translateX(100%); }
    to { transform: none; }
  }
}

/* Touch devices get finger-sized controls even when the layout stays wide. */
@media (pointer: coarse) {
  .nav-item { min-height: 46px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 36px; }
  .chip { min-height: 34px; }
  .icon-btn { width: 42px; height: 42px; }
  .row-btn { width: 34px; height: 34px; }
  .segmented button { width: 40px; height: 34px; }
  .switch { width: 40px; height: 22px; }
  .switch::after { width: 18px; height: 18px; }
  .switch.on::after { transform: translateX(18px); }
  .card-dl { width: 32px; height: 32px; }
}
