:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1c2029;
  --border: #262a33;
  --fg: #e6e8ee;
  --muted: #8a92a5;
  --accent: #4c9aff;
  --accent-hot: #ff6b6b;
  --danger: #ff5c5c;
}
:root[data-theme="light"] {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #dfe3ea;
  --fg: #1a1d24;
  --muted: #667085;
  --accent: #2b6cb0;
  --accent-hot: #d64545;
  --danger: #c53030;
}
html { transition: background 0.2s, color 0.2s; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif; }

header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: 0.5px; }
.sub { color: var(--muted); margin: 0; font-size: 13px; }

.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.head-actions label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.head-actions input { background: var(--panel); border: 1px solid var(--border); color: var(--fg); padding: 6px 10px; border-radius: 6px; min-width: 260px; font-family: ui-monospace, monospace; }
.head-actions button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 14px; cursor: pointer; font-weight: 500; }
.head-actions button:hover { filter: brightness(1.1); }
.head-actions button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.head-actions button.ghost:hover { color: var(--fg); border-color: var(--accent); }
.head-actions button.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--fg);
  padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1;
}
.head-actions button.icon-btn:hover { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; }
.hint.ok { color: #7ee787; }
.hint.err { color: var(--danger); }

main { padding: 20px 24px 40px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 200px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.card-head .name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; letter-spacing: 0.3px; }
.card-head .name .pf-icon { width: 20px; height: 20px; border-radius: 4px; object-fit: contain; flex-shrink: 0; background: var(--panel-2); }
.card-head .name .badge { display: inline-block; padding: 1px 6px; margin-left: 6px; border-radius: 4px; background: var(--border); color: var(--muted); font-size: 11px; font-weight: 400; font-family: ui-monospace, monospace; }
.card-head .meta { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 11px; font-family: ui-monospace, monospace; }
.card-head .refresh {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  padding: 2px 6px; border-radius: 4px; font-size: 14px;
}
.card-head .refresh:hover { color: var(--accent); background: var(--border); }
.card-head .refresh.spin { animation: spin 0.8s linear infinite; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.card-body {
  padding: 6px 8px;
  overflow-y: auto;
  max-height: 520px;
  flex: 1;
}
.card-body::-webkit-scrollbar { width: 6px; }
.card-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.card-body::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.list { list-style: none; padding: 0; margin: 0; }
.list li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px 8px;
  border-radius: 6px;
  line-height: 1.4;
}
.list li:hover { background: var(--panel-2); }
.list .rank {
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  min-width: 22px;
  text-align: right;
  flex-shrink: 0;
}
.list .rank.top { color: var(--accent-hot); font-weight: 700; }
.list .title {
  color: var(--fg);
  text-decoration: none;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.list .title:hover { color: var(--accent); }
.list .side {
  color: var(--muted);
  font-size: 11px;
  font-family: ui-monospace, monospace;
  white-space: nowrap;
  flex-shrink: 0;
}

.state {
  padding: 24px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}
.state.err {
  color: var(--danger);
  font-family: ui-monospace, monospace;
  white-space: pre-wrap;
  text-align: left;
  word-break: break-word;
}
.state .retry { color: var(--accent); cursor: pointer; text-decoration: underline; margin-left: 4px; }

/* --- 设置抽屉 --- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 90;
  animation: fade-in 0.15s ease-out;
}
:root[data-theme="light"] .drawer-backdrop { background: rgba(0, 0, 0, 0.28); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 360px; max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex; flex-direction: column;
  animation: slide-in 0.2s ease-out;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] .drawer { box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); }
@keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0.3px; }
.drawer-head .icon-btn {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 16px; padding: 4px 8px; border-radius: 4px;
}
.drawer-head .icon-btn:hover { color: var(--fg); background: var(--panel-2); }

.drawer-hint { padding: 10px 16px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; border-bottom: 1px solid var(--border); }
.drawer-hint .handle-hint { color: var(--fg); font-family: ui-monospace, monospace; }

.prefs-list { list-style: none; padding: 6px 0; margin: 0; overflow-y: auto; flex: 1; }
.prefs-list::-webkit-scrollbar { width: 6px; }
.prefs-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.prefs-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid transparent;
  transition: background 0.1s;
  user-select: none;
}
.prefs-item:hover { background: var(--panel-2); }
.prefs-item.dragging { opacity: 0.4; background: var(--panel-2); }
.prefs-item.drag-over-top { border-top-color: var(--accent); }
.prefs-item.drag-over-bottom { border-bottom-color: var(--accent); }

.prefs-item .drag-handle {
  cursor: grab; color: var(--muted); font-size: 16px;
  padding: 2px 4px; border-radius: 3px;
  line-height: 1; user-select: none;
}
.prefs-item .drag-handle:hover { color: var(--fg); background: var(--border); }
.prefs-item .drag-handle:active { cursor: grabbing; }

.prefs-item input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer;
}
.prefs-item .prefs-icon {
  width: 20px; height: 20px; border-radius: 4px; object-fit: contain;
  background: var(--panel-2); flex-shrink: 0;
}
.prefs-item .prefs-label {
  flex: 1; color: var(--fg); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.prefs-item.hidden .prefs-label { color: var(--muted); text-decoration: line-through; }

.drawer-foot {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}
.drawer-foot .ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.drawer-foot .ghost:hover { color: var(--fg); border-color: var(--accent); }
