:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #66736b;
  --line: #dbe3dc;
  --paper: #f8faf8;
  --panel: #ffffff;
  --accent: #116a5b;
  --accent-strong: #0d5845;
  --accent-soft: #e9f3ef;
  --berry: #b8462f;
  --shadow: 0 14px 38px rgba(23, 33, 27, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

a {
  color: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(248, 250, 248, 0.93);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 560px) auto;
  gap: 16px;
  align-items: center;
  max-width: 1500px;
  margin: 0 auto;
  padding: 14px 20px;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  white-space: nowrap;
}

.sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.refresh-status-banner {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(100%, 680px);
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
}

.refresh-status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.refresh-status-text {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.refresh-status-banner.loading .refresh-status-pill,
.refresh-status-banner.idle .refresh-status-pill {
  background: #eef2ef;
  color: #51635a;
}

.refresh-status-banner.ok .refresh-status-pill {
  background: #dff4eb;
  color: #0e6a52;
}

.refresh-status-banner.error .refresh-status-pill {
  background: #f9e1dc;
  color: #a23d2a;
}

.surface {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.searchbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  box-shadow: 0 2px 10px rgba(23, 33, 27, 0.04);
}

.searchbox span,
.select-shell span {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.searchbox input,
.select-shell select {
  width: 100%;
  border: 0;
  outline: 0;
  font: inherit;
  background: transparent;
  color: var(--ink);
  min-width: 0;
}

.summary-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats-inline {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.stats-inline strong {
  color: var(--ink);
  font-size: 13px;
}

.metric-sep {
  color: #b7c2ba;
}

.select-shell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  min-width: 150px;
}

.linklike {
  display: inline-flex;
  align-items: center;
  padding: 9px 11px;
  text-decoration: none;
  color: var(--accent-strong);
  font-size: 13px;
  white-space: nowrap;
}

.action-btn {
  padding: 9px 11px;
  font: inherit;
  cursor: pointer;
  color: var(--accent-strong);
  background: var(--panel);
}

.action-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.layout {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px 20px 40px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
}

.sidebar {
  position: sticky;
  top: 82px;
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding-right: 2px;
}

.sidebar-head {
  margin-bottom: 12px;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 18px;
}

.sidebar-head p {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.category-list {
  display: grid;
  gap: 7px;
}

.category-btn {
  width: 100%;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.category-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.category-cover {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  background: #e8eee9;
}

.category-cover-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
}

.category-name {
  min-width: 0;
}

.category-name strong {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-name span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.category-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.mainpanel {
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.panel-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.panel-status {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(23, 33, 27, 0.05);
}

.card.select-mode .select-box {
  display: inline-flex;
}

.thumb-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.thumb-button img {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  object-fit: cover;
  background: #e8eee9;
}

.card-body {
  padding: 9px;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
}

.card-title {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  word-break: break-all;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
}

.meta-line strong {
  font-size: 14px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
  color: #315148;
  overflow-wrap: anywhere;
}

.action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
}

.select-box {
  display: none;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.select-box input {
  margin: 0;
  accent-color: var(--accent);
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  color: var(--accent-strong);
  text-decoration: none;
  white-space: nowrap;
}

.empty {
  padding: 44px 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
  text-align: center;
  color: var(--muted);
}

.loadmore {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.loadmore button {
  border: 0;
  background: var(--accent);
  color: white;
  min-width: 180px;
  min-height: 42px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.loadmore button[hidden] {
  display: none;
}

.preview-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(1200px, calc(100% - 24px));
}

.preview-dialog::backdrop {
  background: rgba(10, 18, 14, 0.72);
  backdrop-filter: blur(10px);
}

.preview-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: white;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
}

.preview-visual {
  background: linear-gradient(135deg, #f3f7f4, #f8efe6);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 360px;
}

.preview-card img {
  max-width: 100%;
  max-height: 92vh;
  display: block;
  object-fit: contain;
}

.preview-meta {
  padding: 20px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.preview-meta h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  word-break: break-all;
}

.preview-meta p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.7;
}

.preview-actions {
  display: grid;
  gap: 10px;
}

button,
.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: white;
  border: 0;
}

.ghost-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.close-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  color: var(--ink);
}

@media (max-width: 1080px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .summary-tools {
    justify-content: flex-start;
  }

  .refresh-status-text {
    white-space: normal;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .preview-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  .layout {
    padding-left: 12px;
    padding-right: 12px;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
