/* =========================================================
   全局布局（最后加载，覆盖各主题的横向 header）
   · 左侧竖排侧边栏（可折叠）
   · 工具栏置顶（可开关）
   · 紧凑卡片（可开关）
   · 设置面板 + 开关样式
   ========================================================= */

header {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 224px;
  height: 100vh;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 6px;
  padding: 14px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  border-bottom: none !important;
  border-right: 1px solid rgba(0, 0, 0, .1);
  box-shadow: 1px 0 10px rgba(0, 0, 0, .04);
  transition: width .3s cubic-bezier(.25, .1, .25, 1), padding .3s cubic-bezier(.25, .1, .25, 1);
}

/* 侧栏顶部工具行：设置 */
.sb-tools { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.sb-tools .btn { flex: 1; }

/* 折叠把手：贴在侧栏右缘，垂直居中（脱离 header 流，避免被裁剪） */
#sbToggle {
  position: fixed;
  left: 210px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 80;
  width: 26px;
  height: 48px;
  padding: 0;
  border-radius: 0 10px 10px 0;
  clip-path: none !important;
  background: var(--paper, var(--a-bg, #fff));
  border: 1px solid rgba(0, 0, 0, .15);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
  transition: left .3s cubic-bezier(.25, .1, .25, 1);
}
body.sb-collapsed #sbToggle { left: 50px; }

.logo { justify-content: flex-start; margin-bottom: 8px; }
.logo > div:last-child { font-size: 16px; }

nav { flex-direction: column; align-items: stretch; gap: 2px; }
nav a { display: block; text-align: left; }

header .spacer { flex: 1; }

#appBtn, #styleBtn { width: 100%; text-align: center; }
#appBtn { margin-top: 8px; }

#userArea { flex-direction: column; align-items: stretch; gap: 6px; margin-top: 12px; }
.user-chip { justify-content: flex-start; }
#userArea .btn { width: 100%; }

main {
  max-width: 1100px;
  margin-left: max(224px, calc(50% - 438px));
  margin-right: 0;
  transition: margin-left .3s cubic-bezier(.25, .1, .25, 1);
}
footer { margin-left: 224px; transition: margin-left .3s cubic-bezier(.25, .1, .25, 1); }

/* ---------- 折叠侧栏 ---------- */
body.sb-collapsed header { width: 64px; padding: 12px 8px; }
body.sb-collapsed .sb-tools { flex-direction: column; }
body.sb-collapsed header .logo > div:last-child,
body.sb-collapsed header nav,
body.sb-collapsed header #appBtn,
body.sb-collapsed header #styleBtn,
body.sb-collapsed header #userArea { display: none; }
body.sb-collapsed header .logo { justify-content: center; }
body.sb-collapsed main { margin-left: max(64px, calc(50% - 518px)); }
body.sb-collapsed footer { margin-left: 64px; }

/* ---------- 置顶工具栏（滚动时吸顶） ---------- */
body:not(.no-sticky) .toolbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper, var(--a-bg, var(--bp-paper, #fff)));
  padding: 8px;
  margin: -8px -8px 14px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08);
}

/* ---------- 紧凑卡片 ---------- */
body.compact .grid { gap: 10px; }
body.compact .card-cover { height: 108px; }
body.compact .card-body { padding: 10px 12px 12px; }

/* ---------- 设置面板 ---------- */
.set-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 300; }
.set-card {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid #e2e2e6;
  border-radius: 14px;
  padding: 16px 20px;
  z-index: 301;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: #1d1d1f;
  animation: set-pop .2s ease;
}
@keyframes set-pop { from { transform: translate(-50%, -48%); opacity: 0; } to { transform: translate(-50%, -50%); opacity: 1; } }
.set-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.set-head button { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: #6e6e73; line-height: 1; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-top: 1px solid #f0f0f2; }
.set-row:first-of-type { border-top: 0; }
.set-info { display: flex; flex-direction: column; }
.set-info b { font-size: 14px; font-weight: 600; }
.set-info span { font-size: 12px; color: #86868b; margin-top: 2px; }
.set-tip { font-size: 12px; color: #a0a0a6; margin-top: 10px; text-align: center; }

/* 开关（switch） */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: #d1d1d6;
  border-radius: 999px;
  transition: background .2s ease;
  cursor: pointer;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s ease;
}
.switch input:checked + .slider { background: #0071e3; }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ---------- 小屏：回退顶部横条（忽略折叠态） ---------- */
@media (max-width: 880px) {
  header {
    position: sticky;
    top: 0; left: auto; bottom: auto;
    width: 100%; height: auto;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto; overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid rgba(0, 0, 0, .1);
  }
  .sb-tools { margin-bottom: 0; }
  .logo { margin-bottom: 0; }
  nav { flex-direction: row; align-items: center; }
  nav a { white-space: nowrap; }
  header .spacer { flex: 1; }
  #appBtn, #styleBtn, #userArea { width: auto; margin-top: 0; }
  #userArea { flex-direction: row; align-items: center; }
  #userArea .btn { width: auto; }
  main { margin-left: 0; }
  footer { margin-left: 0; }
  #sbToggle { display: none; }

  body.sb-collapsed header { width: 100%; }
  body.sb-collapsed .sb-tools { flex-direction: row; }
  body.sb-collapsed header .logo > div:last-child,
  body.sb-collapsed header nav,
  body.sb-collapsed header #appBtn,
  body.sb-collapsed header #styleBtn,
  body.sb-collapsed header #userArea { display: flex; }
  body.sb-collapsed main, body.sb-collapsed footer { margin-left: 0; }
}

/* =========================================================
   移动端细化（Prompt 5）
   ========================================================= */
html, body { overflow-x: hidden; }

@media (max-width: 768px) {
  /* 吸顶工具栏下移，避开顶部横条，避免遮挡内容 */
  body:not(.no-sticky) .toolbar { top: 52px; }
  main { padding: 18px 12px 64px; }
  .hero { padding: 26px 18px; margin-bottom: 18px; }
  .hero h1 { font-size: 30px; }
  .hero p { font-size: 14px; margin-bottom: 16px; }
  .hero-stats { gap: 22px; }
  .stat b { font-size: 24px; }
  /* 卡片：窄屏两列自适应，很窄时单列 */
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card-title { font-size: 14px; }
  /* 详情页：封面占满宽度，避免横向溢出 */
  .detail-cover { width: 100%; height: auto; aspect-ratio: 1 / 1; }
  .detail-head { gap: 16px; }
  .detail-info h1 { font-size: 24px; }
  .detail-cols { gap: 14px; }
  .col { padding: 16px; }
  .profile-head { flex-wrap: wrap; gap: 12px; }
  .profile-stats { margin-left: 0; }
  .profile-sections { gap: 14px; }
}

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

@media (max-width: 600px) {
  /* 弹窗全屏：登录/注册、设置面板 */
  .modal-card, .set-card {
    top: 0; left: 0;
    transform: none;
    width: 100vw; max-width: 100vw;
    height: 100vh;
    border-radius: 0;
    overflow-y: auto;
    animation: none;
  }
  .search-box { min-width: 100%; }
  .select { flex: 1 1 auto; min-width: 0; }
  .toolbar { gap: 6px; }
  .comment-main, .need-login { padding: 12px; }
}

/* =========================================================
   榜单页 / 管理后台（js/rank.js、js/admin.js）
   · 只用新增的 .rank-* / .admin-* 类名，不覆盖任何既有规则
   · 颜色走两套主题的变量链，深浅与红蓝外观都自适应
   ========================================================= */
.rank-page, .admin-page {
  --rk-ink: var(--ink, var(--a-ink, #1d1d1f));
  --rk-dim: var(--dim, var(--a-gray, #6e6e73));
  --rk-faint: var(--faint, var(--a-gray3, #86868b));
  --rk-line: var(--ink, var(--a-bg2, #e3e3e8));
  --rk-panel: var(--card, var(--a-panel, #fff));
  --rk-bg: var(--paper, var(--a-bg2, #f2f2f6));
  --rk-accent: var(--red, var(--a-blue, #0071e3));
}

.rank-head, .admin-head { margin-bottom: 14px; }
.rank-head h1, .admin-head h1 { margin: 2px 0 6px; font-size: 26px; }
.rank-sub, .admin-sub { font-size: 13px; color: var(--rk-dim); }
.admin-sub { margin-top: 2px; }
.rank-readonly { margin-bottom: 14px; }
.rank-count-tip { margin-left: auto; align-self: center; font-size: 13px; color: var(--rk-dim); }

.rank-list { display: flex; flex-direction: column; gap: 8px; }
.rank-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: var(--rk-panel);
  border: 1.5px solid var(--rk-line);
  border-radius: 12px;
}
.rank-no { flex: 0 0 34px; text-align: center; font-weight: 800; font-size: 16px; color: var(--rk-ink); }
.rank-cover { flex: 0 0 48px; width: 48px; height: 48px; overflow: hidden; border-radius: 8px; display: block; }
.rank-cover .cover-img { width: 100%; height: 100%; object-fit: cover; }
.rank-main { flex: 1 1 auto; min-width: 0; }
.rank-title { font-weight: 700; font-size: 15px; color: var(--rk-ink); text-decoration: none; }
.rank-title:hover { color: var(--rk-accent); }
.rank-meta {
  font-size: 12px; color: var(--rk-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rank-diff { flex: 0 0 auto; font-size: 12px; color: var(--rk-dim); }
.rank-score { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.rank-avg { min-width: 40px; text-align: right; font-weight: 800; font-size: 17px; color: var(--rk-ink); }
.rank-count { font-size: 12px; color: var(--rk-faint); }
.rank-count::after { content: ' 人'; }

.admin-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .admin-cols { grid-template-columns: 1fr; } }
.admin-col {
  padding: 14px;
  background: var(--rk-panel);
  border: 1.5px solid var(--rk-line);
  border-radius: 12px;
}
.admin-col h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 16px; }
.admin-filters { display: flex; gap: 8px; margin-bottom: 10px; }
.admin-filters input {
  flex: 1 1 auto; min-width: 0;
  padding: 6px 10px;
  font-family: inherit; font-size: 13px;
  color: var(--rk-ink);
  background: var(--rk-panel);
  border: 1.5px solid var(--rk-line);
  border-radius: 8px;
}
.admin-comment-row { padding: 9px 0; border-top: 1px dashed var(--rk-line); }
.admin-comment-row:first-child { border-top: none; }
.admin-comment-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.admin-comment-song { font-weight: 700; font-size: 13px; color: var(--rk-ink); text-decoration: none; }
.admin-comment-user { font-size: 12px; color: var(--rk-dim); }
.admin-comment-time { font-size: 11px; color: var(--rk-faint); }
.admin-comment-text { font-size: 13px; color: var(--rk-ink); word-break: break-word; }
.admin-comment-del {
  margin-left: auto;
  padding: 3px 10px;
  font-family: inherit; font-size: 12px;
  color: var(--rk-ink);
  background: transparent;
  border: 1.5px solid var(--rk-line);
  border-radius: 8px;
  cursor: pointer;
}
.admin-comment-del:hover { color: var(--rk-accent); border-color: var(--rk-accent); }

.admin-user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-top: 1px dashed var(--rk-line);
}
.admin-user-row:first-child { border-top: none; }
.admin-user-main { flex: 1 1 auto; min-width: 0; }
.admin-user-name { font-weight: 700; font-size: 14px; color: var(--rk-ink); }
.admin-user-me { font-weight: 400; font-size: 12px; color: var(--rk-faint); }
.admin-user-mail { font-size: 12px; color: var(--rk-dim); word-break: break-all; }
.admin-user-stats { flex: 0 0 auto; font-size: 12px; color: var(--rk-faint); }
.admin-user-role {
  flex: 0 0 auto;
  padding: 2px 9px;
  font-size: 12px;
  color: var(--rk-dim);
  background: var(--rk-bg);
  border-radius: 999px;
}
.admin-user-role.is-admin { color: #fff; background: var(--rk-accent); }
.admin-toggle-admin {
  flex: 0 0 auto;
  padding: 3px 10px;
  font-family: inherit; font-size: 12px;
  color: var(--rk-ink);
  background: transparent;
  border: 1.5px solid var(--rk-line);
  border-radius: 8px;
  cursor: pointer;
}
.admin-toggle-admin:hover:not([disabled]) { color: var(--rk-accent); border-color: var(--rk-accent); }
.admin-toggle-admin[disabled] { opacity: .45; cursor: default; }
.admin-note { margin-top: 16px; font-size: 12px; line-height: 1.9; color: var(--rk-faint); }
.admin-note code { background: var(--rk-bg); padding: 1px 5px; border-radius: 5px; }
