/* Popstage 单曲排行榜 —— 与编辑器同一套浅色视觉 */

:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f7f9fb;
  --ink: #14181d;
  --ink-2: #5a6572;
  --ink-3: #8b95a3;
  --line: #dfe4ea;
  --line-2: #eaeef2;
  --accent: #0e7490;
  --accent-ink: #065a70;
  --accent-soft: #e2f4f8;
  --gold: #b7791f;
  --gold-soft: #fdf3e0;
  --danger: #c0392b;
  --ok: #0f766e;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 29, .06);
  --shadow-md: 0 4px 16px rgba(20, 24, 29, .08);
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

/* ============================ 顶栏 ============================ */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 60px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0e7490, #155e75);
  color: #fff;
  font: 700 11px/1 var(--mono);
  letter-spacing: .5px;
  flex: none;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }

.topbar-meta { margin-left: auto; font-size: 12.5px; color: var(--ink-3); }
.topbar-actions { display: flex; gap: 8px; }

/* ============================ 主体 ============================ */

.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 18px 40px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 14px;
}
.section-head h2 { font-size: 17px; margin: 0; }
.section-tools { margin-left: auto; display: flex; gap: 8px; }

.select, .btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.btn:hover, .select:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent-ink); text-decoration: none; display: inline-flex; align-items: center; }
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }

/* 搜索框（总览，刷新右边） */
.search-input {
  height: 32px;
  width: 200px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--ink-3); }

.notice {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid #f3c1ba;
  border-radius: var(--radius);
  background: #fdf0ee;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- 歌曲网格 ---------- */

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

.song-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s, border-color .15s;
  display: flex;
  flex-direction: column;
}
.song-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.song-cover {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--panel-2);
}

.song-body { padding: 10px 12px 12px; }
.song-title {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.song-artist { font-size: 12px; color: var(--ink-3); margin-top: 1px; }

.song-stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  font-size: 11.5px;
  color: var(--ink-2);
}
.chip-accent { background: var(--accent-soft); border-color: #c3e6ef; color: var(--accent-ink); font-weight: 600; }
.chip-gold { background: var(--gold-soft); border-color: #eedcbb; color: var(--gold); font-weight: 600; }

.song-top {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.song-top b { color: var(--ink); font-family: var(--mono); }

/* ---------- 单曲详情 ---------- */

.detail-head { margin-bottom: 14px; }

.song-hero {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.song-hero-cover {
  width: 110px; height: 110px;
  border-radius: 8px;
  object-fit: contain;
  background: transparent;
  flex: none;
}
.song-hero-text h2 { margin: 0; font-size: 19px; }
.song-hero-text p { margin: 2px 0 0; color: var(--ink-2); }
.song-hero-stats { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px !important; }

/* ---------- 榜单表格 ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.rank-table { width: 100%; min-width: 700px; border-collapse: collapse; font-size: 13.5px; }
.rank-table th, .rank-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line-2);
}
.rank-table thead th {
  background: var(--panel-2);
  font-size: 12px;
  color: var(--ink-3);
  font-weight: 600;
  white-space: nowrap;
}
.rank-table tbody tr:last-child td { border-bottom: none; }
.rank-table tbody tr:hover { background: var(--panel-2); }

.col-rank { width: 52px; }
.col-score { width: 110px; }
.col-num { width: 110px; }
.col-time { width: 150px; }
.col-num, .col-score { text-align: right; }
th.col-score, th.col-num { text-align: right; }

.rank-cell { font-family: var(--mono); font-weight: 700; color: var(--ink-3); }
tr.rank-1 .rank-cell { color: var(--gold); }
tr.rank-2 .rank-cell, tr.rank-3 .rank-cell { color: var(--accent-ink); }

.player-name { font-weight: 600; }

.score-cell { font-family: var(--mono); font-weight: 700; font-size: 14px; }

.grade-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
}
/* FC/EXC 徽章：游戏结算特效图标（IconEffect 素材 128x128）
 * FC=ALL COMBO（allcombo_icon）、EXC=PERFECT PLAY（perfect_icon） */
.badge-img {
  height: 30px;
  width: auto;
  display: inline-block;
  vertical-align: middle;
  margin-left: 5px;
  border-radius: 4px;
}
/* 和评价图（rank-img 30px）并排时对齐 */
.rank-img + .badge-img { margin-left: 8px; }

/* 单曲榜「全部」视图：玩家块右边的小难度碟面图（与玩家框 52px 高相当） */
.player-with-diff { display: flex; align-items: center; gap: 10px; min-width: 0; }
.diff-disc {
  height: 56px;
  width: 56px;
  margin-left: 130px;
  object-fit: contain;
  flex: none;
}

/* 统计 chip 里的小图标（FC/EXC 计数用） */
.chip-icon {
  height: 16px;
  width: auto;
  display: inline-block;
  vertical-align: -3px;
  margin-right: 4px;
}

.diff-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
}
.diff-NM { background: #e8f0fe; color: #1d4ed8; border-color: #c7dbfa; }
.diff-HD { background: #fef3e2; color: #b45309; border-color: #f5ddb5; }
.diff-MX { background: #fdeaea; color: #b91c1c; border-color: #f5c6c6; }
.diff-EX { background: #f3e8fd; color: #7e22ce; border-color: #e4ccf7; }
.diff-SC { background: #e7f6f4; color: #0f766e; border-color: #bfe5e0; }

.time-cell { color: var(--ink-3); font-size: 12px; white-space: nowrap; }

/* ---------- 模式切换标签（POP MIXING / STAR MIXING / CLUB MIXING 占位） ---------- */

.mode-tabs {
  display: flex;
  gap: 8px;
  margin: 4px 0 14px;
}

.mode-tab {
  height: 34px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-2);
  font: 700 13px/1 var(--mono);
  letter-spacing: .3px;
  cursor: pointer;
}
.mode-tab:hover { border-color: var(--accent); color: var(--accent-ink); }
.mode-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.mode-tab-off,
.mode-tab-off:hover {
  background: var(--panel-2);
  border-color: var(--line-2);
  color: var(--ink-3);
  cursor: not-allowed;
  opacity: .7;
}

/* ---------- 难度切换标签 ---------- */

.diff-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.diff-tab {
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-2);
  font: 700 12.5px/1 var(--mono);
  cursor: pointer;
}
.diff-tab:hover { border-color: var(--accent); color: var(--accent-ink); }
.diff-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* 难度四色（tab 文字 = 难度色，选中 = 难度色实底白字）：NM 黄 HD 蓝 MX 红 EX 紫 */
.diff-tab.diffc-NM { color: #b45309; }
.diff-tab.diffc-HD { color: #2563eb; }
.diff-tab.diffc-MX { color: #dc2626; }
.diff-tab.diffc-EX { color: #9333ea; }
.diff-tab.diffc-NM.active { background: #d97706; border-color: #d97706; color: #fff; }
.diff-tab.diffc-HD.active { background: #2563eb; border-color: #2563eb; color: #fff; }
.diff-tab.diffc-MX.active { background: #dc2626; border-color: #dc2626; color: #fff; }
.diff-tab.diffc-EX.active { background: #9333ea; border-color: #9333ea; color: #fff; }
.diff-tab.diffc-NM:hover, .diff-tab.diffc-HD:hover, .diff-tab.diffc-MX:hover, .diff-tab.diffc-EX:hover {
  border-color: currentColor;
}

/* ---------- 玩家单元格：左块（头像上 + 昵称下）+ 右侧大称号条 ---------- */

.player-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }

.player-id {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: none;
}
.player-id .player-name {
  font-size: 12px;
  line-height: 1.2;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dj-icon {
  width: 84px; height: 52px;   /* 素材就是 104x64 宽图，84/52 = 104/64，不裁切 */
  border-radius: 8px;
  object-fit: contain;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  flex: none;
}
.dj-icon-none {
  display: inline-block;
  background:
    linear-gradient(135deg, var(--panel-2), var(--line-2));
}

.player-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.player-name { font-weight: 600; line-height: 1.25; }

.title-bar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  min-width: 166px;        /* 板子素材 204x64，52px 高对应 166px 宽，与头像等高 */
  max-width: 340px;
  height: 52px;
  padding: 0 14px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  overflow: hidden;
}
.title-bar-pattern {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.title-bar-text {
  position: relative;
  z-index: 1;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8), 0 0 3px rgba(0, 0, 0, .5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 312px;
}
.title-bar-plain {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 4px;
}
.title-bar-plain .title-bar-text {
  color: var(--ink-2);
  text-shadow: none;
}

.top-icon {
  width: 24px; height: 18px;
  border-radius: 4px;
  object-fit: contain;   /* DJ 头像是 104x64 宽图，完整显示不裁切 */
  vertical-align: -6px;
  background: transparent;
}

/* ---------- 其他 ---------- */

.empty { text-align: center; color: var(--ink-3); padding: 26px 0; margin: 0; }

.foot {
  text-align: center;
  padding: 16px;
  color: var(--ink-3);
  font-size: 12px;
  border-top: 1px solid var(--line-2);
}

@media (max-width: 640px) {
  .topbar-meta { display: none; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand-text span { display: none; }   /* 隐藏顶栏副标题，给「存档编辑器」入口让位 */

  .wrap { padding: 14px 10px 32px; }

  /* 模式标签（POP/STAR/CLUB）横向滚动，避免三个胶囊挤破 */
  .mode-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .mode-tab { flex: none; white-space: nowrap; }

  /* 排序工具栏换行，搜索框独占一行 */
  .section-head { flex-wrap: wrap; }
  .section-tools { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .search-input { flex: 1 1 100%; width: 100%; }

  .set-cover img { width: 64px; height: 64px; }
  .song-hero { flex-direction: column; align-items: flex-start; }
  .song-hero-cover { width: 84px; height: 84px; }
  .song-hero-text h2 { font-size: 17px; }

  /* 榜单列保持完整，只在表格容器内横向滚动。 */
  .rank-table { min-width: 700px; }
}

/* ---------- CLUB MIXING 盘组详情（3.7） ---------- */

.club-song { margin-bottom: 16px; }

.club-song-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-2);
}

.club-song-cover {
  width: 64px; height: 64px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  flex: none;
}

.club-song-meta { min-width: 0; }

.club-song-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
}

.club-song-artist {
  font-size: 12px;
  color: var(--ink-3);
  margin: 2px 0 6px;
}

.row-cover {
  width: 26px; height: 26px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  vertical-align: -8px;
  margin-right: 6px;
}

/* CLUB 一把一行：3+1 封面横排，每张封面下挂评价字母 */
.set-covers { display: flex; gap: 8px; flex-wrap: nowrap; }

.set-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.set-cover img {
  width: 84px; height: 84px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  display: block;
}


/* MAX COMBO 数字图（游戏内结算同款 num_max_*.png） */
.num-max {
  height: 26px;
  width: auto;
  display: inline-block;
  vertical-align: middle;
  margin-right: -11px; /* 游戏素材 64x64 里数字字形带留白，负边距把相邻位并拢（当前 -11） */
  image-rendering: auto;
}
.num-max:last-child { margin-right: 0; }

/* CLUB 总览：一行一个组曲（组选界面同款横幅图） */
.club-row {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color .15s;
}

.club-row:hover { border-color: var(--accent); }

.club-row-img {
  width: 300px;
  height: auto;
  display: block;
  border-radius: 6px;
  flex: none;
  background: var(--panel-2);
}

.club-row-info { min-width: 0; }

.club-row-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.club-row-sub { font-size: 12px; color: var(--ink-3); margin: 2px 0 8px; }

.club-row-top { font-size: 13px; color: var(--ink-2); margin-top: 8px; }

@media (max-width: 640px) {
  .club-row { flex-direction: column; align-items: stretch; }
  .club-row-img { width: 100%; }
}

/* CLUB 组曲列表：song-grid 默认多列网格，as-list 切单列堆叠 */
.song-grid.as-list { display: block; }

/* 组曲行的榜首头像放大 */
.club-row-top .top-icon { width: 42px; height: 42px; border-radius: 8px; vertical-align: middle; }

/* 组曲行榜首头像：DJ 头像素材是 104x64 宽图，按原比例显示不裁切 */
.club-top-icon {
  width: 63px; height: 39px;   /* 104:64 等比 */
  border-radius: 6px;
  object-fit: contain;
  vertical-align: middle;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
}

/* 组详情总分：游戏结算数字图（num_newrecord_*，切自 512x64 雪碧图） */
.num-record {
  height: 36px;
  width: auto;
  display: inline-block;
  vertical-align: middle;
  margin-right: 2px;
}

/* 总分数字图整组不换行（六位数在窄 td 里会折成多行） */
.set-score {
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  width: 100%;
}

/* 评价图（游戏结算 Rank_*.png） */
.rank-img {
  height: 30px;
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

/* STAR 评价：总评星板（256 方图带底）+ 准确率数字叠中央 */
.star-grade {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 54px;
  vertical-align: middle;
}
.star-plate {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.star-nums {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 3px;
}
.star-num {
  height: 27px;
  width: auto;
  display: block;
  margin-right: -2px;
}
.star-num:last-child { margin-right: 0; }

/* CLUB 组行内容居中（封面横排 / 总分数字图与表头对齐） */
.club-songs-td { text-align: center; }
.club-songs-td .set-covers { justify-content: center; }
.club-score-td { text-align: center; }
.club-score-td .set-score { margin: 0 auto; }
.club-grade-td { text-align: center; }
.club-songs-td .club-personal-covers {
  display: grid;
  grid-template-columns: repeat(4, minmax(66px, 1fr));
  gap: 10px 8px;
  min-width: 288px;
}
.club-songs-td .club-long-covers { grid-template-columns: repeat(3, minmax(66px, 1fr)); min-width: 214px; }
.club-personal-covers .set-cover img { width: 58px; height: 58px; object-fit: contain; }
.club-personal-covers .set-cover.is-unplayed img { opacity: .35; }
.club-personal-covers .set-cover small { font-size: 11px; white-space: nowrap; }
.club-chart-label { font-size: 10px; color: #666; white-space: nowrap; }
.club-progress { display: block; text-align: center; color: #666; margin-top: 6px; }

/* POP 单曲详情（3.7.1）：与 CLUB 组榜同一套游戏素材样式，数字列居中 */
.pop-td { text-align: center; }
.pop-grade-td { white-space: nowrap; }
.pop-td .set-score { margin: 0 auto; }

/* DJ 等级徽章：框图（70x60）+ 等级数字叠加，与头像同一行 */
.player-avatar-row { display: flex; align-items: center; gap: 8px; }
.player-level-slot { display: flex; align-items: center; justify-content: center; width: 46px; height: 39px; flex: none; }
.player-id { align-items: flex-start; }
.player-id .player-name { margin-left: 54px; }

.lv-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 39px;
}

.lv-box { width: 46px; height: 39px; display: block; }

.lv-nums {
  position: absolute;
  display: inline-flex;
  align-items: center;
  top: 82%;
  left: 58%;
  transform: translate(-50%, -50%);
}

.lv-nums img { height: 20px; width: auto; display: block; }
