:root {
  --bg: #f6f6f4;
  --card: #fff;
  --ink: #1a1a1a;
  --muted: #8b8b86;
  --line: #e7e7e2;
  --accent: #a31621;
  --chip: #ececea;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
.wrap { max-width: 1500px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 246, 244, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; padding: 16px 0 10px; }
h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: 0.02em; }
.stats { color: var(--muted); font-size: 13px; }
.stats b { color: var(--ink); font-weight: 600; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding-bottom: 12px; }
.toolbar input[type="search"], .toolbar select {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
.toolbar input[type="search"] { flex: 1 1 220px; min-width: 180px; }
.toolbar input[type="search"]:focus, .toolbar select:focus { border-color: var(--ink); }
.view-toggle { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--card); }
.view-toggle button {
  border: 0; background: transparent; padding: 8px 16px; font-size: 14px; cursor: pointer; color: var(--muted);
}
.view-toggle button.active { background: var(--ink); color: #fff; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; padding-bottom: 12px; }
.chip {
  border: 0; background: var(--chip); border-radius: 999px; padding: 6px 14px;
  font-size: 13px; cursor: pointer; color: #55554f;
}
.chip.active { background: var(--accent); color: #fff; }
.chip .n { opacity: 0.65; font-size: 12px; margin-left: 2px; }

/* ---------- set banner ---------- */
.setbar {
  display: none; align-items: center; gap: 12px; margin: 16px 0 4px;
  background: #1a1a1a; color: #fff; border-radius: 10px; padding: 12px 16px; font-size: 14px;
}
.setbar.show { display: flex; }
.setbar button { margin-left: auto; border: 1px solid #555; background: transparent; color: #fff; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }

/* ---------- grid ---------- */
.result-line { color: var(--muted); font-size: 13px; padding: 14px 0 10px; }
.grid { columns: 6 240px; column-gap: 16px; padding-bottom: 40px; }
.card {
  break-inside: avoid; background: var(--card); border-radius: 12px; overflow: hidden;
  margin-bottom: 16px; cursor: pointer; border: 1px solid var(--line);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card:hover { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10); transform: translateY(-2px); }
.card img { display: block; width: 100%; height: auto; background: #eee; }
.card .meta { padding: 10px 12px 12px; }
.card .title { font-size: 14px; line-height: 1.45; font-weight: 600; }
.card .sub { margin-top: 5px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.card .tags { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; background: var(--chip); color: #55554f; border-radius: 999px; padding: 2px 8px; }
.tag.cat { background: #f3e3e3; color: var(--accent); }
.img-missing {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: 160px; padding: 20px; text-align: center;
  background: repeating-linear-gradient(45deg, #f0f0ec, #f0f0ec 10px, #e9e9e4 10px, #e9e9e4 20px);
  color: var(--muted); font-size: 12px; line-height: 1.6;
}
.img-missing .t { font-size: 13px; color: #55554f; font-weight: 600; }

/* ---------- sets ---------- */
.sets-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; padding-bottom: 40px; }
.set-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; transition: box-shadow 0.15s ease, transform 0.15s ease; }
.set-card:hover { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10); transform: translateY(-2px); }
.set-card .cover { width: 100%; height: 170px; object-fit: cover; display: block; background: #eee; }
.set-card .cover-missing { height: 170px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; background: #f0f0ec; }
.set-card .meta { padding: 12px 14px 14px; }
.set-card .title { font-size: 15px; font-weight: 700; }
.set-card .sub { margin-top: 5px; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 15, 15, 0.88);
  display: none; align-items: center; justify-content: center; padding: 24px;
}
.lightbox.show { display: flex; }
.lb-box { display: flex; gap: 24px; max-width: 1100px; width: 100%; max-height: 92vh; }
.lb-box img { max-width: 62%; max-height: 92vh; object-fit: contain; border-radius: 8px; background: #222; }
.lb-info { color: #eee; overflow-y: auto; min-width: 260px; }
.lb-info h2 { margin: 0 0 10px; font-size: 19px; line-height: 1.4; }
.lb-info p { margin: 6px 0; font-size: 14px; line-height: 1.7; color: #ccc; }
.lb-info .lbl { color: #888; font-size: 12px; }
.lb-info a { color: #fff; text-decoration: underline; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.12); color: #fff; border: 0; width: 44px; height: 44px; border-radius: 50%; font-size: 20px; cursor: pointer; }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-close { position: absolute; top: 16px; right: 20px; background: none; border: 0; color: #fff; font-size: 28px; cursor: pointer; }

.loading, .empty { text-align: center; color: var(--muted); padding: 80px 0; font-size: 15px; }
footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; padding: 20px 0 32px; line-height: 1.8; }

@media (max-width: 900px) {
  .lb-box { flex-direction: column; overflow-y: auto; }
  .lb-box img { max-width: 100%; max-height: 55vh; }
  .grid { columns: 2 160px; }
}
