:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-subtle: #efefe9;
  --surface-hover: #fafaf8;
  --ink: #111418;
  --ink-secondary: #4b5563;
  --ink-muted: #6b7280;
  --border: rgba(15, 23, 36, 0.09);
  --border-strong: rgba(15, 23, 36, 0.16);
  --shadow-card: 0 1px 2px rgba(15, 23, 36, 0.04), 0 8px 24px rgba(15, 23, 36, 0.03);
  --shadow-card-hover: 0 4px 12px rgba(15, 23, 36, 0.06), 0 18px 36px rgba(15, 23, 36, 0.07);
  --pill-active-bg: #111418;
  --pill-active-ink: #ffffff;
  --pin-bg: rgba(17, 20, 24, 0.78);
  --pin-ink: #ffffff;
  --tag-bg: #f2f3f0;
  --tag-border: rgba(15, 23, 36, 0.08);
  --focus-ring: #2563eb;
  --accent-dot: #16a34a;
  --max: 1160px;
  color-scheme: light;
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei",
    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

html.dark {
  --bg: #0a0d12;
  --surface: #11161f;
  --surface-subtle: #161d28;
  --surface-hover: #151c27;
  --ink: #eef2f7;
  --ink-secondary: #9aa5b5;
  --ink-muted: #768396;
  --border: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.17);
  --shadow-card: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-card-hover: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 18px 40px rgba(0, 0, 0, 0.45);
  --pill-active-bg: #eef2f7;
  --pill-active-ink: #0a0d12;
  --pin-bg: rgba(10, 13, 18, 0.8);
  --pin-ink: #eef2f7;
  --tag-bg: rgba(255, 255, 255, 0.045);
  --tag-border: rgba(255, 255, 255, 0.08);
  --focus-ring: #cddc4a;
  --accent-dot: #cddc4a;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  min-width: 320px;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
}

html.dark body {
  background:
    radial-gradient(ellipse 80% 340px at 50% 0%, rgba(36, 62, 92, 0.16), transparent 70%),
    var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.page {
  width: min(calc(100% - 48px), var(--max));
  margin: 0 auto;
  padding: 40px 0 64px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.identity {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  display: grid;
  place-items: center;
  flex: none;
}

.logo-mark svg {
  width: 22px;
  height: 22px;
}

.identity__text h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.identity__text p {
  margin: 3px 0 0;
  color: var(--ink-secondary);
  font-size: 13.5px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-secondary);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.count-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-dot);
}

.theme-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}

.theme-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: var(--surface-subtle);
}

.theme-btn svg {
  width: 17px;
  height: 17px;
}

.theme-btn .icon-sun {
  display: none;
}

html.dark .theme-btn .icon-sun {
  display: block;
}

html.dark .theme-btn .icon-moon {
  display: none;
}

/* ---- Controls (Search + Categories) ---- */
.controls {
  padding: 22px 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1 1 280px;
  max-width: 380px;
}

.search-box__icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--ink-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 42px 0 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 140ms ease;
}

.search-box input::placeholder {
  color: var(--ink-muted);
}

.search-box input:hover {
  border-color: var(--border-strong);
}

.search-box input:focus {
  outline: none;
  border-color: var(--focus-ring);
}

.search-box__kbd,
.search-box__clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.search-box__kbd {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--ink-muted);
  font: 500 11px/18px ui-monospace, "SFMono-Regular", Consolas, monospace;
  text-align: center;
  pointer-events: none;
}

.search-box.has-value .search-box__kbd {
  display: none;
}

.search-box__clear {
  display: none;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--ink-secondary);
  cursor: pointer;
  place-items: center;
}

.search-box.has-value .search-box__clear {
  display: grid;
}

.search-box__clear svg {
  width: 13px;
  height: 13px;
}

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-pill {
  height: 34px;
  padding: 0 13px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}

.filter-pill:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.filter-pill[aria-pressed="true"] {
  border-color: transparent;
  background: var(--pill-active-bg);
  color: var(--pill-active-ink);
}

.filter-pill__num {
  font-size: 11.5px;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}

/* ---- Card Grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  align-items: stretch;
}

.tool-card {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.tool-card[hidden] {
  display: none;
}

.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  background: var(--surface-hover);
  box-shadow: var(--shadow-card-hover);
}

.tool-card__link {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.tool-card__media {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

.tool-card__media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 280ms ease;
}

.tool-card:hover .tool-card__media img {
  transform: scale(1.018);
}

.pin-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  height: 24px;
  padding: 0 9px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: var(--pin-bg);
  backdrop-filter: blur(8px);
  color: var(--pin-ink);
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.pin-badge svg {
  width: 11px;
  height: 11px;
}

.tool-card__body {
  flex: 1;
  padding: 18px 20px 18px;
  display: flex;
  flex-direction: column;
}

.tool-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tool-card__title-group {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.tool-card__head h2 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-pill {
  height: 20px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--tag-border);
  background: var(--tag-bg);
  color: var(--ink-secondary);
  font-size: 10.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex: none;
}

.pin-pill svg {
  width: 10px;
  height: 10px;
}

.tool-card__launch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--ink-muted);
  display: grid;
  place-items: center;
  flex: none;
  transition: color 140ms ease, transform 160ms ease, background-color 140ms ease;
}

.tool-card__launch svg {
  width: 15px;
  height: 15px;
}

.tool-card:hover .tool-card__launch {
  color: var(--ink);
  background: var(--surface-subtle);
  transform: translate(1.5px, -1.5px);
}

.tool-card__desc {
  margin: 8px 0 0;
  color: var(--ink-secondary);
  font-size: 13.5px;
  line-height: 1.58;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 43px;
}

.tool-card__tags {
  margin-top: 14px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-card__tags span {
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--tag-border);
  background: var(--tag-bg);
  color: var(--ink-secondary);
  font-size: 11.5px;
  line-height: 1.45;
}

.tool-card__foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--ink-muted);
}

.tool-card__kind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tool-card__kind svg {
  width: 14px;
  height: 14px;
}

.tool-card__host {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 11.5px/1.2 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* ---- Empty Search State ---- */
.empty-state {
  padding: 56px 24px;
  border-radius: 14px;
  border: 1px dashed var(--border-strong);
  background: var(--surface);
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state p {
  margin: 0;
  color: var(--ink-secondary);
  font-size: 14px;
}

.empty-state button {
  margin-top: 14px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.empty-state button:hover {
  border-color: var(--focus-ring);
}

/* ---- Footer ---- */
.footer {
  margin-top: auto;
  padding-top: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--ink-muted);
  font-size: 12.5px;
}

.footer a {
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}

.footer a:hover {
  color: var(--ink);
}

.footer kbd {
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  font: 500 11px/1.2 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* ---- Responsive ---- */
@media (max-width: 1020px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .page {
    width: min(calc(100% - 32px), var(--max));
    padding: 24px 0 48px;
  }

  .topbar {
    padding-bottom: 20px;
  }

  .count-badge {
    display: none;
  }

  .controls {
    padding: 18px 0 20px;
    gap: 12px;
  }

  .search-box {
    max-width: none;
    flex-basis: 100%;
  }

  .filters {
    width: 100%;
    gap: 6px;
  }

  .filter-pill {
    height: 32px;
    padding: 0 9px;
    font-size: 12px;
    gap: 5px;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .tool-card__desc {
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
