/* ==========================================================================
   基础层：复位、排版、布局骨架
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--app-font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

img { max-width: 100%; display: block; }
a { color: var(--md-sys-color-primary); text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.2rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
ul, ol { margin: 0; padding-left: 1.2em; }
code { font-family: var(--app-mono); font-size: .88em; background: var(--md-sys-color-surface-container-high); padding: 1px 5px; border-radius: var(--md-sys-shape-xs); }
mark { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); padding: 0 2px; border-radius: 3px; }
hr { border: 0; border-top: 1px solid var(--md-sys-color-outline-variant); margin: 20px 0; }

::selection { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }

:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
  border-radius: var(--md-sys-shape-xs);
}

/* 滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--md-sys-color-outline-variant) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline-variant); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---- 工具类 ---- */
.muted { color: var(--md-sys-color-on-surface-variant); }
.small { font-size: .85rem; }
.strong { font-weight: 650; color: var(--md-sys-color-on-surface); }
.danger { color: var(--md-sys-color-error); }
.nowrap { white-space: nowrap; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.inline { display: inline; }
.mt-0 { margin-top: 0; }
.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 999;
  background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary);
  padding: 10px 16px; border-radius: var(--md-sys-shape-full);
}
.skip-link:focus { left: 8px; }

/* ---- 顶栏 ---- */
.app-bar {
  position: sticky; top: 0; z-index: var(--app-z-bar);
  display: flex; align-items: center; gap: 12px;
  min-height: var(--app-bar-h);
  padding: 8px clamp(12px, 3vw, 28px);
  background: color-mix(in srgb, var(--md-sys-color-surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
@supports not (backdrop-filter: blur(4px)) {
  .app-bar { background: var(--md-sys-color-surface); }
}
.app-bar__brand { display: flex; align-items: center; gap: 10px; color: var(--md-sys-color-on-surface); flex: 0 0 auto; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 12px;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.app-bar__name { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }

.app-bar__search { position: relative; flex: 1 1 auto; max-width: 520px; margin-left: 8px; }
.app-bar__search input {
  width: 100%; height: 42px;
  padding: 0 14px 0 42px;
  border-radius: var(--md-sys-shape-full);
  border: 1px solid transparent;
  background: var(--md-sys-color-surface-container-high);
  transition: background var(--md-sys-motion-dur-3) var(--md-sys-motion-standard), border-color var(--md-sys-motion-dur-3);
}
.app-bar__search input:focus {
  outline: none;
  background: var(--md-sys-color-surface-container-highest);
  border-color: var(--md-sys-color-primary);
}
.app-bar__search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--md-sys-color-on-surface-variant); display: flex; }

.app-bar__actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }

/* 主题切换图标：浅色显示月亮，深色显示太阳 */
.theme-icon-light, .theme-icon-dark { display: inline-flex; }
[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }

/* ---- 页面容器 ---- */
.page {
  width: 100%;
  max-width: var(--app-max);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 28px) 64px;
}

/* ---- 首页 hero ---- */
.hero {
  position: relative;
  padding: clamp(24px, 5vw, 48px) clamp(18px, 4vw, 40px);
  border-radius: var(--md-sys-shape-xl);
  background:
    radial-gradient(120% 140% at 0% 0%, var(--md-sys-color-primary-container) 0%, transparent 55%),
    radial-gradient(120% 140% at 100% 0%, var(--md-sys-color-secondary-container) 0%, transparent 50%),
    var(--md-sys-color-surface-container-low);
  margin-bottom: 26px;
}
.hero__title { font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2.15rem); margin-bottom: 8px; }
.hero__sub { color: var(--md-sys-color-on-surface-variant); margin-bottom: 22px; }

.hero__search {
  display: flex; align-items: center; gap: 10px;
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-full);
  padding: 6px 6px 6px 16px;
  max-width: 680px;
  box-shadow: var(--md-sys-elevation-1);
  transition: border-color var(--md-sys-motion-dur-3), box-shadow var(--md-sys-motion-dur-3);
}
.hero__search:focus-within { border-color: var(--md-sys-color-primary); box-shadow: var(--md-sys-elevation-2); }
.hero__search input {
  flex: 1 1 auto; min-width: 0; border: 0; background: transparent; height: 40px; font-size: 15px;
}
.hero__search input:focus { outline: none; }
.hero__search-icon { color: var(--md-sys-color-on-surface-variant); display: flex; }

/* ---- 首页筛选栏：筛选 / 排序 分两组 ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  margin-top: 16px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.filter-group__label {
  flex: none;
  margin-right: 2px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--md-sys-color-on-surface-variant);
  opacity: .88;
  user-select: none;
}

/* 首页里选中的筛选芯片用 primary-container，比默认的次要色更好认 */
.filter-bar .md-chip {
  border-color: var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface-variant);
}
.filter-bar .md-chip:hover {
  border-color: var(--md-sys-color-outline);
  color: var(--md-sys-color-on-surface);
}
.filter-bar .md-chip.is-selected {
  background: var(--md-sys-color-primary-container);
  border-color: transparent;
  color: var(--md-sys-color-on-primary-container);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--md-sys-color-primary) 30%, transparent);
}

/* 排序是次要操作：默认无边框纯文字，选中才出现底色 */
.filter-bar .md-chip--sort {
  height: 30px;
  padding: 0 12px;
  border-color: transparent;
  font-size: 12.5px;
}
.filter-bar .md-chip--sort:hover {
  background: var(--md-sys-color-surface-container-high);
  border-color: transparent;
}
.filter-bar .md-chip--sort.is-selected {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  box-shadow: none;
  font-weight: 650;
}

@media (max-width: 720px) {
  .filter-bar { gap: 8px 14px; }
  .filter-group--sort { margin-left: 0; }
}

/* ---- 歌曲网格 ---- */
.song-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.song-card {
  position: relative;
  display: flex; gap: 14px; align-items: center;
  padding: 14px;
  border-radius: var(--md-sys-shape-lg);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: inherit;
  transition: background var(--md-sys-motion-dur-3) var(--md-sys-motion-standard),
              transform var(--md-sys-motion-dur-3) var(--md-sys-motion-standard),
              box-shadow var(--md-sys-motion-dur-3);
}
@media (hover: hover) {
  .song-card:hover {
    background: var(--md-sys-color-surface-container);
    transform: translateY(-2px);
    box-shadow: var(--md-sys-elevation-2);
  }
}
.song-card:active { transform: translateY(0); }
.song-card__cover {
  flex: 0 0 auto; width: 64px; height: 64px; border-radius: var(--md-sys-shape-md);
  overflow: hidden; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--md-sys-color-primary-container), var(--md-sys-color-secondary-container));
  color: var(--md-sys-color-on-primary-container);
  font-size: 1.6rem; font-weight: 700;
}
.song-card__cover img { width: 100%; height: 100%; object-fit: cover; }
.song-card__body { min-width: 0; flex: 1 1 auto; }
.song-card__title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-card__artist { color: var(--md-sys-color-on-surface-variant); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-card__badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.song-card__time { position: absolute; right: 12px; bottom: 10px; font-size: .75rem; color: var(--md-sys-color-on-surface-variant); }

/* ---- 搜索结果 ---- */
.search-head { margin-bottom: 18px; }
.search-head__title { margin-bottom: 4px; }
.result-list { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 10px; }
.result-item {
  padding: 16px 18px;
  border-radius: var(--md-sys-shape-lg);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: background var(--md-sys-motion-dur-3);
}
@media (hover: hover) { .result-item:hover { background: var(--md-sys-color-surface-container); } }
.result-item__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.result-item__title { font-size: 1.05rem; font-weight: 650; color: var(--md-sys-color-on-surface); }
.result-item__snippet { margin: 4px 0 8px; color: var(--md-sys-color-on-surface-variant); }
.result-item__badges { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---- 页脚 ---- */
.site-foot { border-top: 1px solid var(--md-sys-color-outline-variant); margin-top: 40px; }
.site-foot__inner {
  max-width: var(--app-max); margin: 0 auto;
  padding: 20px clamp(14px, 3vw, 28px);
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center;
  font-size: .85rem; color: var(--md-sys-color-on-surface-variant);
}
.site-foot__inner a:last-child { margin-left: auto; }

/* ---- 错误页 ---- */
.error-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: var(--md-sys-color-surface-container-low); }
.error-card { max-width: 520px; text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--md-sys-color-primary); line-height: 1; letter-spacing: -.04em; }

/* ---- 移动端 ---- */
@media (max-width: 760px) {
  :root { --app-bar-h: 58px; }
  .app-bar { flex-wrap: wrap; }
  .app-bar__search { order: 3; flex: 1 1 100%; max-width: none; margin: 4px 0 0; }
  .app-bar__name { font-size: .95rem; }
  .app-bar__admin { display: none; }
  .page { padding-top: 16px; }
  .song-grid { grid-template-columns: 1fr; }
  .hero { border-radius: var(--md-sys-shape-lg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
