/* ==================== 变量 ==================== */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --glow-1: rgba(99, 102, 241, .10);
  --glow-2: rgba(236, 72, 153, .08);
  --card: #ffffff;
  --border: rgba(0, 0, 0, .06);
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-2: #ec4899;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, .05), 0 16px 40px rgba(0, 0, 0, .12);
  --radius: 14px;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1014;
  --glow-1: rgba(99, 102, 241, .16);
  --glow-2: rgba(236, 72, 153, .10);
  --card: #171a20;
  --border: rgba(255, 255, 255, .08);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #818cf8;
  --accent-2: #f472b6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .4);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 16px 40px rgba(0, 0, 0, .55);
}

/* ==================== 基础 ==================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color .3s, color .3s;
}
body::before, body::after {
  content: '';
  position: fixed;
  width: 60vw;
  height: 60vw;
  max-width: 800px;
  max-height: 800px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(80px);
}
body::before { top: -20vw; left: -10vw; background: var(--glow-1); }
body::after { bottom: -25vw; right: -15vw; background: var(--glow-2); }

.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ==================== 顶栏 ==================== */
.m-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.m-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  min-width: 0;
}
.m-brand-mark {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.m-brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.m-icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.m-icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--accent); }
.m-icon-btn.active { border-color: var(--accent); color: var(--accent); }
.m-switch {
  padding: 7px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.m-switch:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--accent); }

/* ==================== 站内过滤下拉 ==================== */
.m-filter-wrap { position: relative; }
.m-filter-pop {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 300px;
  max-width: calc(100vw - 28px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-hover);
  z-index: 50;
}
.m-filter-pop::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 14px;
  width: 10px;
  height: 10px;
  background: var(--card);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  transform: rotate(45deg);
}
.m-filter-icon { font-size: 15px; color: var(--muted); flex-shrink: 0; }
#filter-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  padding: 6px 0;
}
#filter-input::placeholder { color: var(--muted); }
.m-filter-count { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ==================== 主区 ==================== */
.m-main {
  position: relative;
  z-index: 2;
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

/* Hero */
.m-hero { text-align: center; margin-bottom: 32px; }
.m-greeting { font-size: 15px; color: var(--muted); margin-bottom: 6px; }
.m-clock {
  font-size: 56px;
  font-weight: 200;
  letter-spacing: 2px;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.m-date { font-size: 13px; color: var(--muted); margin-top: 4px; }

.m-search {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 640px;
  margin: 24px auto 0;
  padding: 6px 6px 6px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: box-shadow .2s ease, border-color .2s ease;
}
.m-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent), var(--shadow);
}
.m-search-icon { font-size: 18px; color: var(--muted); flex-shrink: 0; }
#engine-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 8px 0;
}
#engine-input::placeholder { color: var(--muted); }
.m-engine {
  border: none;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}

/* 分类胶囊 */
.m-pills {
  display: flex;
  flex-wrap: wrap; /* 允许换行 */
  justify-content: center; /* 核心：居中对齐 */
  gap: 8px;
  padding: 4px 2px 16px;
}
.m-pill {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s ease, background .15s ease, border-color .15s ease, transform .15s ease;
}
.m-pill:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }
.m-pill.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}

/* 分组 */
.m-group { margin-bottom: 28px; }
.m-group-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-left: 2px;
}
.m-group-count { font-size: 12px; font-weight: 400; color: var(--muted); }

.m-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

/* 卡片 */
.m-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  min-width: 0;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.m-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.m-card-icon {
  width: 36px; height: 36px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}
.m-card-body { min-width: 0; flex: 1; }
.m-card-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-card-desc {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 页脚 */
.m-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* 回顶部 */
.m-back-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.m-back-top:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: var(--accent); }
.m-back-top.hidden { display: none !important; }

/* 下雪 */
#snow-canvas {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ==================== 响应式 ==================== */
@media (max-width: 767px) {
  .m-header { padding: 10px 14px; }
  .m-brand-text { display: none; }
  .m-main { padding: 28px 14px 48px; }
  .m-clock { font-size: 42px; }
  .m-search { margin-top: 18px; }
  .m-engine { padding: 8px 8px; }
  .m-grid { grid-template-columns: 1fr; }
  .m-back-top { right: 14px; bottom: 14px; width: 40px; height: 40px; }
  .m-filter-pop { width: 260px; }
}

/* ==================== 减少动态效果 ==================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (max-width: 767px) {
  .m-search {
    padding: 4px 4px 4px 12px;
    gap: 6px;
  }
  .m-search-icon { font-size: 16px; }
  #engine-input { font-size: 14px; padding: 8px 0; }
  .m-engine {
    min-width: 0;
    max-width: 84px;
    flex-shrink: 1;
    padding: 6px 8px;
    font-size: 12px;
  }
  .m-header { gap: 8px; }
  .m-actions { gap: 6px; }
  .m-switch { padding: 6px 10px; font-size: 12px; }
  .m-filter-pop { right: -6px; }
}

@media (max-width: 767px) {
  /* 1. 允许顶栏按钮换行，防止被挤出屏幕 */
  .m-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }
  .m-switch { padding: 6px 10px; font-size: 12px; }
  .m-icon-btn { width: 32px; height: 32px; }

  /* 2. 下拉过滤框改为固定定位，左右留边距，绝不出屏 */
  .m-filter-pop {
    position: fixed;
    top: 64px; /* 在顶栏下方 */
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
    box-shadow: 0 10px 30px rgba(0,0,0,.15);
  }
  .m-filter-pop::before { display: none; } /* 全宽时不需要小三角了 */
}