:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f6f7f9;
  --border: #e6e7eb;
  --text: #1a1a1d;
  --text-muted: #6b6f76;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --radius: 12px;
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.06);
  --header-h: 56px;
  --sidebar-w: 200px;
}

html[data-theme="dark"] {
  --bg: #0e0f12;
  --surface: #16181d;
  --surface-alt: #1c1f25;
  --border: #262a31;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --accent: #8b8df0;
  --accent-soft: rgba(139, 141, 240, 0.18);
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header .brand { font-weight: 600; font-size: 16px; }
.app-header .spacer { flex: 1; }

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
}

.theme-toggle {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}
.theme-toggle:hover { background: var(--surface-alt); }

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 8px;
  overflow-y: auto;
}
.sidebar .cat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  width: 100%;
  text-align: left;
  position: relative;
}
.sidebar .cat:hover { background: var(--surface-alt); }
.sidebar .cat[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.sidebar .cat[aria-pressed="true"]::before {
  content: "";
  position: absolute; left: 2px; top: 8px; bottom: 8px;
  width: 2px; background: var(--accent); border-radius: 2px;
}

@media (max-width: 768px) {
  .sidebar {
    display: flex; gap: 6px;
    overflow-x: auto; overflow-y: hidden;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 8px 12px;
  }
  .sidebar .cat { width: auto; white-space: nowrap; padding: 6px 12px; }
  .sidebar .cat[aria-pressed="true"]::before { display: none; }
}

main.cards {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  align-content: start;
}

.site-card {
  display: block;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.site-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}
.site-card[hidden] { display: none; }

.site-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.site-logo {
  width: 40px; height: 40px; border-radius: 10px;
  object-fit: cover; background: var(--surface-alt);
}
.site-logo.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--accent); background: var(--accent-soft);
}
.site-name { margin: 0; font-size: 15px; font-weight: 600; }
.site-desc { margin: 0; font-size: 13px; color: var(--text-muted); line-height: 1.5; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  width: 280px; max-width: 50vw;
  padding: 0 12px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
}
.search-box input {
  flex: 1; border: none; outline: none; background: transparent;
  color: var(--text); font: inherit;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
}

@media (max-width: 768px) {
  .app-header { padding: 0 12px; gap: 8px; }
  .search-box { width: 100%; max-width: none; }
  main.cards { padding: 12px; grid-template-columns: 1fr 1fr; gap: 12px; }
}

@media (max-width: 480px) {
  main.cards { grid-template-columns: 1fr; }
}

.site-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
