:root {
  --bg: #14161a;
  --panel: #191c22;
  --card: #21252d;
  --card-h: #282d37;
  --border: #2d323c;
  --text: #e6e9ef;
  --muted: #8b94a3;
  --dim: #666e7c;
  --accent: #5b9cf8;
  --accent-bg: #22314a;
  --star: #f0b73f;
}

html[data-theme="light"] {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --card: #ffffff;
  --card-h: #f0f2f5;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #6b7480;
  --dim: #98a0ac;
  --accent: #2563eb;
  --accent-bg: #e4edfd;
  --star: #d98c0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- 顶栏 ---------- */
#topbar {
  position: relative;
  flex: none;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

#brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
}

#brand-logo {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

#menu-btn, #theme-btn {
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
  line-height: 1;
}
#menu-btn { display: none; }
#menu-btn:hover, #theme-btn:hover { background: var(--card-h); }

#random-btn {
  height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, #4a7cf0, #7a5cf0);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: filter .15s;
}
#random-btn:hover { filter: brightness(1.15); }
#random-btn:active { filter: brightness(0.95); }

#geekhub-btn {
  height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
#geekhub-btn::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .18);
}
#geekhub-btn:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

#search-wrap {
  position: relative;
  flex: 1;
  max-width: 520px;
}

#search {
  width: 100%;
  height: 36px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  outline: none;
}
#search:focus { border-color: var(--accent); }
#search::-webkit-search-cancel-button { display: none; }

#clear-btn {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
#clear-btn:hover { background: var(--card-h); color: var(--text); }

/* ---------- 布局 ---------- */
#app {
  display: flex;
  flex: 1;
  min-height: 0;
}

#sidebar {
  width: 262px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
  padding: 10px 6px 40px;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 8px;
  font-size: 12px;
  color: var(--muted);
}

#scope-reset {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}

/* ---------- 分类树 ---------- */
.tn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  line-height: 1.35;
}
.tn:hover { background: var(--card-h); }
.tn.on { background: var(--accent-bg); }
.tn.on .tn-name { color: var(--accent); }

.tn-arrow {
  width: 14px;
  flex: none;
  text-align: center;
  color: var(--dim);
  font-size: 10px;
  transition: transform .12s;
}
.tn-arrow.open { transform: rotate(90deg); }
.tn-arrow.leaf { visibility: hidden; }

.tn-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.tn-n {
  flex: none;
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.tn-kids { display: none; }
.tn-kids.open { display: block; }

/* ---------- 主区 ---------- */
#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}

#crumb {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#crumb b { color: var(--text); font-weight: 500; }
#crumb span { cursor: pointer; }
#crumb span:hover { color: var(--accent); }

#tools {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

#sort, #star-filter {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  cursor: pointer;
}
#star-filter.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

#view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  background: var(--card);
}
#view-toggle button {
  width: 32px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
#view-toggle button.on { background: var(--accent-bg); color: var(--accent); }
#view-toggle button:not(.on):hover { color: var(--text); }

#count { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- 列表视图 ---------- */
#list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  padding: 8px 14px 14px;
  overscroll-behavior: contain;
  overflow-anchor: none;
  scroll-behavior: auto;
}

#rows.view-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  height: 62px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}
.row:hover { background: var(--card-h); border-color: var(--accent); }

.fav-box {
  position: relative;
  width: 20px;
  height: 20px;
  flex: none;
}

.fav {
  position: absolute;
  inset: 0;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: contain;
}

.fav-txt {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.row-mid {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.row-title {
  display: block;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.row-star {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
}
.row:hover .row-star { opacity: 1; }
.row-star:hover { background: var(--border); }
.row-star.on { opacity: 1; color: var(--star); }

#crumb .sep { color: var(--dim); }

/* ---------- 网格视图 ---------- */
#rows.view-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), 1fr);
  gap: 10px;
}

.gcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: 148px;
  padding: 16px 12px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  text-decoration: none;
  color: inherit;
  text-align: center;
  overflow: hidden;
}
.gcard:hover { background: var(--card-h); border-color: var(--accent); }

.gcard .fav-box { width: 44px; height: 44px; }
.gcard .fav { width: 28px; height: 28px; }
.gcard .fav-txt { font-size: 17px; }

.gcard-title {
  font-size: 12.5px;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  width: 100%;
}

.gcard-sub {
  margin-top: auto;
  max-width: 100%;
  font-size: 10.5px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 空状态 / loading ---------- */
#empty {
  padding: 60px 20px;
  text-align: center;
}
.empty-title { font-size: 15px; margin-bottom: 6px; }
.empty-sub { font-size: 13px; color: var(--muted); }

#loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  color: var(--muted);
}
#loading.done { display: none; }

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#mask {
  display: none;
  position: fixed;
  inset: 54px 0 0;
  z-index: 19;
  background: rgba(0, 0, 0, .45);
}

/* ---------- 页脚 ---------- */
#footer {
  flex: none;
  padding: 7px 14px 8px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.65;
}
#footer p { margin: 0; }
#footer p + p { margin-top: 1px; }
#footer b { color: var(--text); font-weight: 500; }
#footer a { color: var(--accent); text-decoration: none; }
#footer a:hover { text-decoration: underline; }
.ft-mail { margin-left: 12px; white-space: nowrap; }

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  #menu-btn { display: block; }
  #brand span { display: none; }
  #brand-logo { width: 26px; height: 26px; }
  #random-btn { padding: 0 10px; font-size: 12.5px; }
  #geekhub-btn { padding: 0 9px; font-size: 12px; }
  #geekhub-btn::before { display: none; }
  #sidebar {
    position: fixed;
    left: 0;
    top: 54px;
    bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .18s;
    width: 78%;
    max-width: 300px;
  }
  #sidebar.open { transform: translateX(0); }
  #mask.show { display: block; }
  #toolbar { padding: 8px 10px; }
  #list-scroll { padding: 8px 10px 14px; }
  #count { display: none; }
  #rows.view-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  #topbar { gap: 8px; padding: 0 10px; }
  #footer { padding: 6px 10px 7px; font-size: 10.5px; }
  .ft-mail { margin-left: 0; display: block; }
}
