:root {
  --bg: #0b0c10;
  --bg-2: #101218;
  --panel: #161921;
  --panel-2: #1d212b;
  --panel-3: #262b37;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --ink: #eceef2;
  --ink-2: #c9cdd6;
  --muted: #9aa0ad;
  --faint: #626876;
  --accent: #f5b64e;
  --accent-ink: #1a1304;
  --accent-soft: rgba(245, 182, 78, 0.14);
  --rose: #ff6f8e;
  --rose-soft: rgba(255, 111, 142, 0.16);
  --ok: #4fd18b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
  --r: 12px;
  --r-lg: 18px;
  --sans: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --bar-h: 60px;
  --side-w: 248px;
  --cw: 184px;

  --ns-artist: #f5b64e;
  --ns-group: #ffa66b;
  --ns-parody: #8ee0a0;
  --ns-character: #79d6d0;
  --ns-language: #a8b4c8;
  --ns-female: #ff8fb1;
  --ns-male: #7fb3ff;
  --ns-mixed: #c59bff;
  --ns-other: #9aa0ad;
  --ns-cosplayer: #ffcf7a;
  --ns-location: #b6c8a0;
  --ns-wn: #d8b4ff;
}
html[data-density="s"] { --cw: 140px; }
html[data-density="m"] { --cw: 184px; }
html[data-density="l"] { --cw: 236px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); scrollbar-color: #2c3140 var(--bg); }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body.lock { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---------- top bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: rgba(11, 12, 16, 0.82);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(145deg, #ffd27a, #e79a2b);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 4px 14px rgba(245, 182, 78, 0.35);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.04em; }
.brand-name small { font-size: 10.5px; font-weight: 600; letter-spacing: 0.18em; color: var(--accent); vertical-align: 2px; margin-left: 2px; }

.views { display: flex; gap: 2px; padding: 3px; background: var(--panel); border-radius: 10px; flex: none; }
.view {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.view:hover { color: var(--ink); }
.view.on { background: var(--panel-3); color: var(--ink); }
.view .cnt { font-size: 11px; color: var(--faint); margin-left: 2px; }
.view.on .cnt { color: var(--accent); }

.search {
  flex: 1 1 320px;
  min-width: 160px;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 10px 0 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid transparent;
  transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--line-2); background: var(--panel-2); }
.search svg { color: var(--faint); flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  font: 11px/1 var(--sans);
  color: var(--faint);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  padding: 3px 6px;
}
.search:focus-within kbd { display: none; }
.search .clear { color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 4px; }
.search .clear:hover { color: var(--ink); }

.tools { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
.sort select {
  appearance: none;
  -webkit-appearance: none;
  height: 34px;
  padding: 0 28px 0 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%239aa0ad' stroke-width='1.7' stroke-linecap='round'%3E%3Cpath d='m6 8 4 4 4-4'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.sort select:hover { border-color: var(--line-2); }
.icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background .15s, color .15s;
}
.icon:hover { background: var(--panel); color: var(--ink); }
.icon.on { background: var(--accent-soft); color: var(--accent); }
.side-toggle { display: none; }

.live { display: grid; place-items: center; width: 22px; height: 34px; }
.live i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 0 rgba(79, 209, 139, 0);
}
.live.busy i { background: var(--ok); animation: pulse 2s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(79, 209, 139, 0.6); }
  100% { box-shadow: 0 0 0 10px rgba(79, 209, 139, 0); }
}

/* ---------- shell ---------- */
.shell { display: flex; align-items: flex-start; }
.side {
  flex: none;
  width: var(--side-w);
  position: sticky;
  top: var(--bar-h);
  height: calc(100vh - var(--bar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  scrollbar-width: thin;
}
.side-inner { padding: 18px 14px 24px; display: flex; flex-direction: column; gap: 22px; }
.sec h3 {
  margin: 0 0 8px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sec .more { font-size: 11px; font-weight: 500; color: var(--faint); letter-spacing: 0; text-transform: none; }
.sec .more:hover { color: var(--accent); }

.srcs { display: flex; gap: 4px; padding: 3px; background: var(--panel); border-radius: 10px; }
.src-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 4px 6px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  transition: background .15s, color .15s;
}
.src-btn:hover { color: var(--ink); }
.src-btn.on { background: var(--panel-3); color: var(--ink); }
.src-btn .n { font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.src-btn.on .n { color: var(--accent); }
.sec.dim { opacity: 0.45; pointer-events: none; }
.sec .note { color: var(--faint); font-size: 12px; padding: 4px 8px; line-height: 1.5; }
.badge.src { color: var(--faint); font-size: 9.5px; padding: 3px 5px; }
.card .top .l { display: flex; gap: 4px; }
.pill.src { background: transparent; border: 1px solid var(--line-2); color: var(--muted); }
.v-intro { margin: 0; color: var(--ink-2); font-size: 13px; line-height: 1.6; white-space: pre-line; }
.v-loading { color: var(--faint); font-size: 12px; }
.cats { display: flex; flex-direction: column; gap: 1px; }
.cat {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13px;
  text-align: left;
  transition: background .12s, color .12s;
}
.cat:hover { background: var(--panel); color: var(--ink); }
.cat.on { background: var(--panel-2); color: var(--ink); font-weight: 600; }
.cat .sw { width: 8px; height: 8px; border-radius: 3px; background: var(--c, var(--faint)); flex: none; }
.cat .n { margin-left: auto; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.cat.on .n { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px; }
.chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 12px;
  transition: all .12s;
}
.chip:hover { border-color: var(--line-2); color: var(--ink); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.facets { display: flex; flex-direction: column; gap: 1px; }
.facet {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--ink-2);
  text-align: left;
  transition: background .12s;
}
.facet:hover { background: var(--panel); color: var(--ink); }
.facet.on { background: var(--accent-soft); color: var(--accent); }
.facet .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.facet .n { margin-left: auto; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; flex: none; }
.facets .empty { color: var(--faint); font-size: 12px; padding: 4px 8px; }

.side-foot {
  margin-top: auto;
  padding: 14px 6px 0;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.7;
}
.side-foot b { color: var(--muted); font-weight: 600; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; padding: 18px 22px 60px; }
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}
.filters .count { font-variant-numeric: tabular-nums; }
.filters .count b { color: var(--ink); font-weight: 600; }
.ftag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12.5px;
}
.ftag i { font-style: normal; color: var(--ns, var(--muted)); font-size: 11px; }
.ftag button { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); font-size: 14px; line-height: 1; }
.ftag button:hover { background: var(--panel-3); color: var(--ink); }
.filters .reset { color: var(--faint); font-size: 12px; margin-left: 4px; }
.filters .reset:hover { color: var(--rose); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--cw), 1fr));
  gap: 16px 14px;
}

.card {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--panel);
  text-align: left;
  isolation: isolate;
  transform: translateZ(0);
  transition: transform .22s cubic-bezier(.2,.7,.2,1), box-shadow .22s;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow); z-index: 2; }
.card img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .35s ease, transform .5s cubic-bezier(.2,.7,.2,1);
}
.card img.ok { opacity: 1; }
.card:hover img { transform: scale(1.04); }
.card .mono {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 40px; font-weight: 700;
  color: var(--faint);
  background: radial-gradient(120% 90% at 50% 0%, var(--panel-3), var(--panel));
}
.card .veil {
  position: absolute; inset: auto 0 0;
  height: 62%;
  background: linear-gradient(180deg, transparent, rgba(8, 9, 12, 0.55) 45%, rgba(8, 9, 12, 0.95));
  pointer-events: none;
}
.card .top {
  position: absolute; inset: 8px 8px auto;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 6px;
  pointer-events: none;
}
.badge {
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(8, 9, 12, 0.66);
  backdrop-filter: blur(6px);
  color: var(--c, var(--ink));
}
.badge.pages { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.card .fav {
  position: absolute; top: 8px; right: 8px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: rgba(8, 9, 12, 0.66);
  backdrop-filter: blur(6px);
  color: var(--ink-2);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s, color .15s;
}
.card:hover .fav, .card .fav.on { opacity: 1; transform: none; }
.card .fav.on { color: var(--rose); }
.card .fav.on svg { fill: currentColor; }
.card .fav:hover { color: var(--rose); }
.card:hover .top .badge.pages { opacity: 0; }
.card .bottom {
  position: absolute; inset: auto 0 0;
  padding: 10px 11px 10px;
  display: flex; flex-direction: column; gap: 5px;
}
.card h3 {
  margin: 0;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.card .row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.card .row .lang { display: inline-flex; gap: 3px; margin-left: auto; }
.lang b {
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.22);
  color: var(--ink-2);
  letter-spacing: 0.02em;
}

.stars { position: relative; display: inline-block; font-size: 10px; letter-spacing: 1px; color: rgba(255,255,255,.22); line-height: 1; white-space: nowrap; }
.stars .on { position: absolute; left: 0; top: 0; overflow: hidden; color: var(--accent); white-space: nowrap; }

.skel { aspect-ratio: 5 / 7; border-radius: var(--r); background: linear-gradient(100deg, var(--panel) 30%, var(--panel-2) 50%, var(--panel) 70%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.foot { text-align: center; color: var(--faint); font-size: 12.5px; padding: 26px 0 8px; }
.foot .btn { margin-top: 8px; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-state .glyph { font-size: 44px; margin-bottom: 12px; color: var(--faint); }
.empty-state p { margin: 4px 0; }
.empty-state small { color: var(--faint); }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 7, 10, 0.72);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.v-backdrop {
  position: absolute; inset: -60px;
  background-position: center;
  background-size: cover;
  filter: blur(60px) saturate(1.4) brightness(0.45);
  opacity: 0.8;
  transition: background-image .3s;
  pointer-events: none;
}
.v-close, .v-nav {
  position: absolute;
  z-index: 3;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(20, 22, 28, 0.7);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  backdrop-filter: blur(8px);
  transition: background .15s, color .15s, transform .15s;
}
.v-close { top: 18px; right: 18px; }
.v-close:hover, .v-nav:hover { background: var(--panel-3); color: var(--ink); }
.v-nav { top: 50%; transform: translateY(-50%); }
.v-nav.prev { left: 18px; }
.v-nav.next { right: 18px; }
.v-nav:hover { transform: translateY(-50%) scale(1.06); }
.v-nav[disabled] { opacity: 0.3; pointer-events: none; }
.v-nav svg { width: 22px; height: 22px; }

.v-panel {
  position: relative;
  z-index: 2;
  width: min(1120px, 100%);
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: rgba(20, 22, 29, 0.88);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  animation: pop .22s cubic-bezier(.2,.7,.2,1);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.v-cover {
  position: relative;
  margin: 0;
  min-height: 420px;
  background: #0a0b0e;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.v-cover::before {
  content: "";
  position: absolute; inset: 0;
  background: var(--bgimg) center / cover;
  filter: blur(30px) brightness(0.5);
  transform: scale(1.2);
}
.v-cover img {
  position: relative;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity .25s;
}
.v-cover img[hidden] { display: none; }
.v-mono { position: relative; font-size: 72px; font-weight: 700; color: var(--faint); }
.v-mono[hidden] { display: none; }

.v-info {
  min-width: 0;
  overflow-y: auto;
  padding: 26px 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}
.v-head { display: flex; align-items: center; gap: 10px; }
.pill {
  display: inline-flex; align-items: center;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--panel-3);
  color: var(--c, var(--ink-2));
}
.pill.warn { background: var(--rose-soft); color: var(--rose); }
.v-idx { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; margin-left: auto; }
.v-info h2 { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.35; letter-spacing: -0.005em; }
.v-jpn { margin: -6px 0 0; color: var(--muted); font-size: 13.5px; }
.v-jpn:empty { display: none; }
.v-rating { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.v-rating .stars { font-size: 15px; letter-spacing: 2px; }
.v-rating b { color: var(--ink); font-weight: 600; }

.facts {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.facts div { padding: 9px 11px; border-radius: 9px; background: var(--panel-2); }
.facts dt { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.facts dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }

.v-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  background: var(--panel-3);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s, transform .1s;
}
.btn:hover { background: #2f3543; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: #ffc763; }
.btn.ghost { background: transparent; border: 1px solid var(--line-2); color: var(--ink-2); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.fav-on { background: var(--rose-soft); color: var(--rose); }
.btn.fav-on svg { fill: currentColor; }

.v-tags { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; border-top: 1px solid var(--line); }
.tg { display: grid; grid-template-columns: 78px 1fr; gap: 10px; align-items: baseline; }
.tg .ns { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--c, var(--muted)); padding-top: 4px; }
.tg .pills { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 12px;
  background: color-mix(in srgb, var(--c, var(--muted)) 12%, transparent);
  color: color-mix(in srgb, var(--c, var(--muted)) 85%, white);
  border: 1px solid color-mix(in srgb, var(--c, var(--muted)) 22%, transparent);
  transition: background .12s;
}
.tag:hover { background: color-mix(in srgb, var(--c, var(--muted)) 26%, transparent); }
.tag.on { background: var(--c, var(--muted)); color: #111; font-weight: 600; }
.v-hint { margin: auto 0 0; padding-top: 6px; color: var(--faint); font-size: 11.5px; }

.toast {
  position: fixed; left: 50%; bottom: 28px;
  z-index: 60;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: rise .2s ease;
}

.scrim { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .v-panel { grid-template-columns: minmax(260px, 360px) 1fr; }
  .facts { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 960px) {
  .side-toggle { display: grid; }
  .side {
    position: fixed;
    top: var(--bar-h);
    left: 0;
    bottom: 0;
    z-index: 25;
    height: auto;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.2,.7,.2,1);
    box-shadow: none;
  }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .scrim { display: block; position: fixed; inset: var(--bar-h) 0 0; z-index: 24; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.on { opacity: 1; pointer-events: auto; }
  .main { padding: 14px 14px 60px; }
}
@media (max-width: 720px) {
  :root { --bar-h: 56px; --cw: 150px; --tab-h: 58px; }
  html[data-density="s"] { --cw: 112px; }
  html[data-density="m"] { --cw: 150px; }
  html[data-density="l"] { --cw: 178px; }
  body { -webkit-tap-highlight-color: transparent; }

  /* one-row top bar: mark · search · live */
  .bar { padding: 0 10px 0 10px; gap: 8px; padding-top: env(safe-area-inset-top); height: calc(var(--bar-h) + env(safe-area-inset-top)); }
  .brand-name { display: none; }
  .search { flex: 1 1 auto; max-width: none; height: 40px; }
  .search kbd { display: none; }
  .tools { gap: 2px; }

  /* bottom tab bar (view buttons + filter are moved here by app.js) */
  nav.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 32;
    display: flex;
    height: calc(var(--tab-h) + env(safe-area-inset-bottom));
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    background: rgba(11, 12, 16, 0.9);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-top: 1px solid var(--line);
  }
  .tabbar .views { flex: 1; display: flex; gap: 2px; padding: 0; background: none; border-radius: 0; }
  .tabbar .view { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 0; border-radius: 10px; font-size: 12px; }
  .tabbar .view.on { background: var(--panel-2); color: var(--accent); }
  .tabbar .view .cnt { margin: 0; font-size: 10px; }
  .tabbar .side-toggle { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 25%; height: auto; border-radius: 10px; font-size: 12px; color: var(--muted); }
  .tabbar .side-toggle svg { width: 20px; height: 20px; }
  .tabbar .side-toggle.on { background: var(--accent-soft); color: var(--accent); }
  .tab-label { display: none; }
  .tabbar .tab-label { display: block; line-height: 1; }

  .main { padding: 12px 10px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); }
  .filters { margin-bottom: 10px; gap: 6px; }
  .grid { gap: 10px 8px; }
  .card { border-radius: 10px; }
  .card h3 { font-size: 12px; }
  .card .fav { opacity: 1; transform: none; width: 32px; height: 32px; }
  .card:hover { transform: none; box-shadow: none; }
  .card:hover img { transform: none; }
  .card:hover .top .badge.pages { opacity: 1; }
  .card .fav:not(.on) { opacity: 0; }

  /* filter drawer sits between the top bar and the tab bar */
  .side { top: calc(var(--bar-h) + env(safe-area-inset-top)); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); width: min(86vw, 340px); }
  .scrim { top: calc(var(--bar-h) + env(safe-area-inset-top)); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
  .side-tools[hidden] { display: none; }
  .tool-row { display: flex; gap: 8px; align-items: center; }
  .tool-row .sort { flex: 1; }
  .tool-row .sort select { width: 100%; height: 40px; }
  .tool-row .icon { width: 40px; height: 40px; background: var(--panel); border-color: var(--line); }
  .cat, .facet { padding: 9px 8px; }
  .chip { padding: 8px 12px; font-size: 13px; }

  /* viewer: full-screen sheet, read button pinned at the bottom */
  .viewer { padding: 0; }
  .v-panel {
    width: 100%;
    height: 100vh; height: 100dvh;
    max-height: none;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 44vh) 1fr;
    border-radius: 0;
    border: 0;
  }
  .v-cover { min-height: 0; }
  .v-cover img { max-height: 44vh; }
  .v-info { padding: 14px 14px 0; gap: 12px; }
  .v-info h2 { font-size: 16px; }
  .facts { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .facts div { padding: 7px 8px; }
  .facts dd { font-size: 12.5px; }
  .v-actions {
    position: sticky; bottom: 0; z-index: 2;
    order: 99;
    margin: auto -14px 0;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, transparent, rgba(20,22,29,.96) 30%);
    flex-wrap: nowrap;
  }
  .v-actions .btn { height: 44px; padding: 0 12px; }
  .v-actions .btn.primary { flex: 1; justify-content: center; font-size: 15px; }
  .v-actions #vCopy { display: none; }
  .v-actions .btn.ghost span { display: none; }
  .v-tags { padding-bottom: 12px; }
  .v-close { top: calc(10px + env(safe-area-inset-top)); right: 10px; width: 40px; height: 40px; }
  .v-nav { top: calc(44vh - 52px); transform: none; width: 40px; height: 40px; background: rgba(20,22,28,.55); }
  .v-nav:hover { transform: none; }
  .v-nav.prev { left: 10px; }
  .v-nav.next { right: 10px; }
  .v-hint { display: none; }
  .v-progress { order: 98; }
  .tg { grid-template-columns: 1fr; gap: 4px; }

  /* reader */
  .r-bar { height: calc(46px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  .r-scroll { padding: calc(46px + env(safe-area-inset-top)) 0 calc(24px + env(safe-area-inset-bottom)); }
  .r-pages { gap: 0; }
  .r-btn { width: 40px; height: 40px; }
  .r-pos { padding: 0 4px; }
  .r-note { top: calc(54px + env(safe-area-inset-top)); font-size: 12px; }
  .r-end { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* thin reading progress line, all sizes */
.r-prog { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; z-index: 3; background: rgba(255,255,255,.06); }
.r-prog i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
@media (hover: none) {
  .card .fav { opacity: 0; }
  .card .fav.on { opacity: 1; }
  .btn:hover, .icon:hover, .cat:hover, .facet:hover { background: inherit; }
}
@media (max-width: 720px) and (orientation: landscape) {
  .v-panel { grid-template-columns: minmax(200px, 40vw) 1fr; grid-template-rows: 1fr; }
  .v-cover img { max-height: 100vh; }
  .v-nav { top: 50%; transform: translateY(-50%); }
  .v-nav:hover { transform: translateY(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- reader ---------- */
.v-progress { margin: -4px 0 0; color: var(--faint); font-size: 12px; }
.reader {
  position: fixed; inset: 0;
  z-index: 70;
  background: #050608;
  display: flex;
  flex-direction: column;
  animation: fade .18s ease;
}
.r-bar {
  position: absolute; top: 0; left: 0; right: 0;
  z-index: 2;
  height: 50px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px;
  background: linear-gradient(180deg, rgba(5,6,8,.92), rgba(5,6,8,.75) 70%, transparent);
  transition: transform .2s ease, opacity .2s ease;
}
.reader.immersive .r-bar { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.r-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  color: var(--ink-2);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
}
.r-btn:hover { background: var(--panel-3); color: var(--ink); }
.r-btn.on { color: var(--accent); border-color: rgba(245,182,78,.4); }
.r-title { flex: 1; min-width: 0; font-size: 13px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; }
.r-pos { flex: none; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding: 0 8px; }
.r-note {
  position: absolute; top: 58px; left: 50%; z-index: 2;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(20,22,28,.9);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  font-size: 12.5px;
  white-space: nowrap;
  max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
.r-note.err { color: var(--rose); border-color: rgba(255,111,142,.4); }
.r-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 50px 0 40px; }
.r-pages { width: min(100%, var(--rw, 1000px)); margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.reader.orig .r-pages { width: max-content; max-width: 100%; }
.pg { position: relative; background: #101218; min-height: 120px; display: grid; place-items: center; }
.pg img { display: block; width: 100%; height: auto; }
.reader.orig .pg img { width: auto; max-width: 100vw; }
.pg .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; pointer-events: none; }
.pg .ph b { display: block; font-size: 22px; font-weight: 600; color: #2c3140; margin-bottom: 6px; }
.pg.loaded .ph { display: none; }
.pg .num { position: absolute; right: 8px; bottom: 8px; padding: 2px 7px; border-radius: 6px; background: rgba(5,6,8,.7); color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; opacity: 0; transition: opacity .15s; }
.pg:hover .num, .reader.immersive .pg .num { opacity: 1; }
.pg .retry { position: absolute; inset: auto auto 40% 50%; transform: translateX(-50%); }
.pg .spin { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #2c3140; border-top-color: var(--accent); animation: spin 1s linear infinite; margin: 0 auto 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.r-end { text-align: center; color: var(--muted); padding: 60px 20px 80px; }
.r-end p { margin: 0 0 14px; font-size: 14px; }
@media (max-width: 720px) {
  .r-scroll { padding-top: 46px; }
  .r-bar { height: 46px; }
  .r-pages { gap: 2px; }
}

/* base: tab bar is phone-only; body.pin is the iOS scroll lock */
.tabbar { display: none; }
body.pin { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
