:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --card-hover: #e7f4f1;
  --ink: #1c1917;
  --muted: #6b645b;
  --line: #e4ddd2;
  --accent: #0f766e;
  --accent-soft: #d7f3ee;
  --chip: #efe8dc;
  --shadow: 0 8px 24px rgba(28, 25, 23, 0.05);
  --usage-bg: #f0fdf9;
  --usage-border: #0f766e;
}

html[data-theme="dark"] {
  --bg: #141311;
  --card: #1c1b18;
  --card-hover: #243330;
  --ink: #f5f0e8;
  --muted: #a8a29a;
  --line: #2e2b26;
  --accent: #5eead4;
  --accent-soft: #134e4a;
  --chip: #26231e;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  --usage-bg: #134e4a;
  --usage-border: #5eead4;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #141311;
    --card: #1c1b18;
    --card-hover: #243330;
    --ink: #f5f0e8;
    --muted: #a8a29a;
    --line: #2e2b26;
    --accent: #5eead4;
    --accent-soft: #134e4a;
    --chip: #26231e;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    --usage-bg: #134e4a;
    --usage-border: #5eead4;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

.topbar {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.top-right { display: flex; align-items: center; gap: 10px; }

.home-link,
.theme-switch button,
.layout-switch button,
.filters button,
.quick button,
.page-size button,
.pager button,
.x-link,
.search,
.tag,
.actions a {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.home-link,
.theme-switch button,
.layout-switch button,
.filters button,
.quick button,
.page-size button,
.pager button,
.x-link {
  height: 36px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
}

.home-link:hover,
.theme-switch button:hover,
.layout-switch button:hover,
.filters button:hover,
.quick button:hover,
.page-size button:hover,
.pager button:hover,
.x-link:hover,
.tag:hover,
.actions a:hover {
  background: var(--card-hover);
  border-color: var(--accent);
}

.search:hover,
.search:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card-hover);
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
}
.home-icon { font-size: 16px; line-height: 1; filter: grayscale(1) contrast(1.4); }

.theme-switch, .layout-switch, .quick, .filters, .page-size, .pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.theme-switch button,
.layout-switch button,
.filters button,
.quick button,
.page-size button,
.pager button {
  border-radius: 999px;
  padding: 0 12px;
  cursor: pointer;
  font-size: 13px;
}

button.active,
.pager button.active,
.page-size button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
html[data-theme="dark"] button.active,
html[data-theme="auto"] button.active { color: #042f2e; }

.x-link {
  width: 36px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.x-link svg { width: 14px; height: 14px; fill: currentColor; }

.wrap { width: min(1080px, calc(100% - 32px)); margin: 0 auto; }

header { padding: 28px 0 22px; text-align: center; }
header h1 {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", "Songti SC", "Times New Roman", serif;
  font-size: clamp(56px, 10vw, 96px);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 0.95;
}
.tagline {
  margin: 16px 0 0;
  color: var(--muted);
  letter-spacing: 0.12em;
  font-size: clamp(15px, 2vw, 18px);
}

.search {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 16px;
  background: var(--card);
  color: var(--ink);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0 16px;
}
.filters { margin: 14px 0 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.grid.list {
  grid-template-columns: 1fr;
  gap: 8px;
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  height: 248px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  background: var(--card-hover);
  border-color: var(--accent);
  overflow: visible;
  z-index: 8;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 24px;
}
.grid:not(.list) .card-top .tags,
.grid:not(.list) .badges { display: none !important; }

.card h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.3;
  min-width: 0;
}
.card h3 .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-inline {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
}
.rank-inline.top1 { background: #f5d76e; color: #6b4e00; }
.rank-inline.top2 { background: #d7dde3; color: #334155; }
.rank-inline.top3 { background: #e7c3a8; color: #7a3e16; }

.summary {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fit {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.usage {
  display: none;
  position: absolute;
  left: 12px;
  right: 12px;
  top: 118px;
  width: auto;
  height: auto;
  max-height: none;
  margin: 0;
  padding: 10px 12px;
  background: var(--usage-bg);
  border: 1.5px solid var(--usage-border);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(15, 118, 110, 0.18);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 9;
}
.card:hover .usage { display: block; }

.time {
  position: absolute;
  left: 14px;
  bottom: 14px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

.card-bottom {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-top: auto;
  padding-top: 14px;
}
.tags {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  width: 100%;
  overflow: hidden;
}
.tag {
  flex: 0 0 auto;
  background: var(--chip);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
}

.stats {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
}
.stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--chip);
  border-radius: 8px;
  padding: 2px 7px;
  white-space: nowrap;
}
.stat svg { width: 12px; height: 12px; fill: currentColor; }

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.actions a {
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 10px;
  color: var(--ink);
  background: var(--bg);
  font-size: 13px;
  white-space: nowrap;
}
.actions a.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
html[data-theme="dark"] .actions a.primary,
html[data-theme="auto"] .actions a.primary { color: #042f2e; }

.grid.list .card {
  height: auto;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "title meta"
    "body actions";
  column-gap: 16px;
  row-gap: 6px;
  align-items: start;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: none;
}
.grid.list .card:hover { overflow: visible; z-index: 8; }
.grid.list .card-top {
  grid-area: meta;
  justify-content: flex-end;
  align-items: center;
  min-width: 0;
}
.grid.list .card-top .tags {
  display: flex !important;
  flex-wrap: wrap;
  justify-content: flex-end;
  width: auto;
  max-width: 360px;
  overflow: visible;
}
.grid.list h3 {
  grid-area: title;
  margin: 0;
  font-size: 16px;
  min-height: 24px;
}
.grid.list .list-body {
  grid-area: body;
  min-width: 0;
  max-width: 100%;
}
.grid.list .card-bottom {
  grid-area: actions;
  margin-top: 0;
  padding-top: 0;
  justify-content: flex-end;
  align-self: end;
}
.grid.list .card-bottom .tags { display: none; }
.grid.list .time { display: none; }
.grid.list .usage {
  display: none;
  top: 100%;
  left: 14px;
  right: 14px;
  bottom: auto;
  margin-top: 8px;
  background: var(--usage-bg);
  border: 1.5px solid var(--usage-border);
  box-shadow: 0 6px 20px rgba(15, 118, 110, 0.22);
}
.grid.list .card:hover .usage { display: block; }
.grid.list .summary {
  -webkit-line-clamp: 2;
  margin: 0;
}
.grid.list .fit {
  margin: 4px 0 0;
  -webkit-line-clamp: 1;
}

.pager-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 18px 0 28px;
}
.count {
  color: var(--muted);
  font-size: 13px;
  justify-self: start;
}
.pager { justify-self: center; }
.page-size { justify-self: end; }
.pager button { min-width: 36px; }

footer {
  color: var(--muted);
  font-size: 13px;
  padding: 0 0 40px;
  text-align: center;
  line-height: 1.7;
}
footer .about { margin: 0 0 8px; }
footer .about a { color: var(--accent); text-decoration: none; }
footer .traffic { margin: 0 0 8px; color: var(--ink); }
footer .note { margin: 0; }
.error { background: #fef2f2; color: #991b1b; padding: 12px 14px; border-radius: 10px; }

@media (max-width: 800px) {
  .pager-bar {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .grid.list .card {
    grid-template-areas:
      "title title"
      "meta meta"
      "body body"
      "actions actions";
  }
}
