/* ── 控制列 ── */
#card-viewer {
  max-width: 100%;
}

#viewer-controls {
  display: none;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 12px;
  padding: 16px 20px;
  transition: background 0.2s, border-color 0.2s;
}
body.light #viewer-controls { background: #fff; border-color: #cbd5e1; }

.ctrl-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.ctrl-label {
  font-size: 12px;
  color: #94a3b8;
  min-width: 52px;
}
body.light .ctrl-label { color: #64748b; }

.filter-group { display: flex; flex-wrap: wrap; gap: 6px; }

.filter-group label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: #cbd5e1;
  cursor: pointer;
  padding: 2px 6px;
  border: 1px solid #334155;
  border-radius: 4px;
  user-select: none;
}
.filter-group label:hover { border-color: #64748b; }
.filter-group input[type=checkbox] { accent-color: #60a5fa; }
body.light .filter-group label { color: #334155; border-color: #cbd5e1; }
body.light .filter-group label:hover { border-color: #94a3b8; }

.btn-sm {
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid #475569;
  border-radius: 4px;
  background: #1e293b;
  color: #cbd5e1;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-sm:hover { background: #334155; }
.btn-sm.active { background: #1d4ed8; border-color: #3b82f6; color: #fff; }
body.light .btn-sm { background: #e2e8f0; border-color: #94a3b8; color: #334155; }
body.light .btn-sm:hover { background: #cbd5e1; }
body.light .btn-sm.active { background: #1d4ed8; border-color: #3b82f6; color: #fff; }

#count-label { font-size: 12px; color: #64748b; }

/* 玩家資訊列 */
#player-info-bar {
  display: none;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 8px 12px;
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 6px;
  flex-wrap: wrap;
  transition: background 0.2s, border-color 0.2s;
}
body.light #player-info-bar { background: #fff; border-color: #cbd5e1; }

#player-info-bar .pi-item { display: flex; flex-direction: column; gap: 2px; }
#player-info-bar .pi-label { font-size: 10px; color: #64748b; line-height: 1; }
#player-info-bar .pi-value { font-size: 14px; font-weight: 700; color: #f1f5f9; line-height: 1; }
body.light #player-info-bar .pi-value { color: #1e293b; }

/* ── Grid ── */
.grid { display: flex; flex-wrap: wrap; gap: 16px; }

/* ── 卡片外框 ── */
.op-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 120px;
}

.op-card {
  position: relative;
  width: 120px;
  border-radius: 6px;
  overflow: hidden;
  background: #1a1a2e;
  border: 1px solid #333;
}
body.light .op-card { background: #e2e8f0; border-color: #94a3b8; }

.op-card .portrait {
  display: block;
  width: 100%;
  aspect-ratio: 180 / 360;
  object-fit: cover;
  object-position: top center;
}

/* 稀有度左側色條 */
.op-card .rarity-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.rarity-6 { background: linear-gradient(to bottom, #ff8c00, #ffd700); }
.rarity-5 { background: linear-gradient(to bottom, #d4a017, #f0c040); }
.rarity-4 { background: linear-gradient(to bottom, #7b2fbe, #b06ae9); }
.rarity-3 { background: linear-gradient(to bottom, #1a6fb5, #4da6ff); }
.rarity-2 { background: linear-gradient(to bottom, #2e7d32, #66bb6a); }
.rarity-1 { background: linear-gradient(to bottom, #555, #999); }

/* 左側縱列 */
.op-card .left-col {
  position: absolute;
  top: 4px; left: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.op-card .prof-icon { width: 24px; height: 24px; object-fit: contain; filter: drop-shadow(0 1px 3px #000); }

.op-card .elite-lvl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: rgba(0,0,0,0.55);
  border-radius: 4px;
  padding: 2px 3px;
}
.op-card .elite-icon { width: 18px; height: 18px; object-fit: contain; }
.op-card .level-text { font-size: 13px; font-weight: 700; color: #fff; line-height: 1; }

/* 右上：稀有度 */
.op-card .top-right { position: absolute; top: 4px; right: 4px; }
.op-card .rarity-icon { height: 14px; width: auto; object-fit: contain; filter: drop-shadow(0 1px 2px #000); }

/* 下方漸層遮罩 */
.op-card .bottom-mask {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 64px;
  background: linear-gradient(to top, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}

/* 左下：內嵌名字 */
.op-card .inline-name {
  position: absolute;
  bottom: 6px; left: 7px;
  font-size: 11px; font-weight: 600;
  color: #f1f5f9;
  text-shadow: 0 1px 3px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
}

/* 右下：潛能 */
.op-card .bottom-right { position: absolute; bottom: 1px; right: 4px; }
.op-card .potential-icon { width: 18px; height: 18px; object-fit: contain; }

/* 技能 & 模組橫排 */
.op-card .skill-row {
  position: absolute;
  bottom: 26px; left: 8px; right: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 技能格 */
.skill-wrap { position: relative; width: 32px; height: 32px; flex-shrink: 0; overflow: visible; }
.skill-wrap .skill-icon {
  width: 32px; height: 32px;
  object-fit: contain;
  border-radius: 4px;
  background: rgba(0,0,0,0.55);
}
.skill-wrap .skill-badge {
  position: absolute;
  top: -3px; left: -3px;
  width: 12px; height: 12px;
  object-fit: contain;
}
.skill-wrap .skill-badge-txt {
  position: absolute;
  top: -3px; left: -3px;
  width: 12px; height: 12px;
  background: #000; color: #fff;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: 2px; line-height: 1;
}

/* 模組格 */
.equip-wrap {
  position: relative;
  width: 32px; height: 32px;
  flex-shrink: 0;
  border-radius: 4px;
  background-color: rgba(0,0,0,0.55);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* overlay 容器：絕對定位在 skill-wrap 上方，內部橫排 */
.equip-overlay-row {
  position: absolute;
  bottom: 100%;
  left: 0;
  display: flex;
  flex-direction: row;
  gap: 4px;
  margin-bottom: 2px;
  z-index: 2;
}

/* overlay 容器內的模組格（尺寸同一般，不再需要 absolute） */
.equip-overlay-row .equip-wrap {
  background-size: 130%;
}
.equip-overlay-row .equip-wrap.equip-original {
  background-size: 24px 31px;
}

/* 卡片下方名稱 */
.op-name {
  font-size: 11px; color: #ccc;
  text-align: center;
  margin-top: 4px;
  max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
body.light .op-name { color: #334155; }
.op-name.hidden { display: none; }

/* export status */
#export-status { font-size: 11px; color: #64748b; }

/* ── 模組等級徽章（卡片 & 表格共用）── */
.equip-wrap { position: relative; }
.equip-level-badge {
  position: absolute;
  top: -3px; left: -3px;
  width: 12px; height: 12px;
  background: #1d4ed8; color: #fff;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: 2px; line-height: 1;
  z-index: 3;
}

/* ── 統計欄位 ── */
#stats-bar {
  display: none;
  margin-bottom: 16px;
  background: #1e2130;
  border: 1px solid #2d3348;
  border-radius: 12px;
  padding: 12px 16px;
  transition: background 0.2s, border-color 0.2s;
}
body.light #stats-bar { background: #fff; border-color: #cbd5e1; }

#stats-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.stats-toggle-btn {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.stats-toggle-btn:hover { color: #f1f5f9; }
body.light .stats-toggle-btn { color: #64748b; }
body.light .stats-toggle-btn:hover { color: #1e293b; }

.stats-rarity-filter { display: flex; gap: 6px; flex-wrap: wrap; }

#stats-content { margin-top: 10px; }
#stats-content.collapsed { display: none; }

.stats-grid {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.stats-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 48px;
}
.stats-num {
  font-size: 22px;
  font-weight: 700;
  color: #60a5fa;
  line-height: 1;
}
body.light .stats-num { color: #1d4ed8; }
.stats-label {
  font-size: 10px;
  color: #64748b;
  white-space: nowrap;
}

.stats-sep {
  width: 1px;
  height: 32px;
  background: #2d3348;
  margin: 0 4px;
}
body.light .stats-sep { background: #cbd5e1; }

/* ── 表格模式 ── */
#op-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: #cbd5e1;
}
body.light #op-table { color: #334155; }

#op-table th {
  text-align: left;
  padding: 8px 6px;       /* ← 左右 padding，調小可讓欄位更緊湊 */
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  border-bottom: 1px solid #2d3348;
  white-space: nowrap;
}
body.light #op-table th { border-color: #cbd5e1; color: #94a3b8; }

#op-table td {
  padding: 10px 6px;      /* ← 左右 padding，同上 */
  border-bottom: 1px solid #1e2130;
  vertical-align: middle;
}
body.light #op-table td { border-color: #f1f5f9; }

#op-table tbody tr:hover { background: rgba(255,255,255,0.04); }
body.light #op-table tbody tr:hover { background: rgba(0,0,0,0.03); }

/* 欄寬控制（用 max-width 限制，讓瀏覽器自動分配剩餘空間）*/

/* 頭像 */
.tbl-avatar-cell { width: 48px; }
.tbl-avatar {
  width: 40px; height: 40px;
  object-fit: cover;
  border-radius: 4px;
  background: #1a1a2e;
  display: block;
}
body.light .tbl-avatar { background: #e2e8f0; }

/* 職業 */
.tbl-prof-wrap { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.tbl-prof-icon { width: 20px; height: 20px; object-fit: contain; }

/* 稀有度 / 精英 / 潛能 */
.tbl-rarity-icon  { height: 14px; width: auto; object-fit: contain; display: block; }
.tbl-elite-icon   { width: 20px; height: 20px; object-fit: contain; display: block; }
body.light .tbl-elite-icon { filter: drop-shadow(0 0 2px rgba(0,0,0,0.5)); }
.tbl-potential-icon { width: 20px; height: 20px; object-fit: contain; display: block; }

/* 名稱欄：限制最大寬度，超出省略 */
#op-table th:nth-child(2),
#op-table td:nth-child(2) { max-width: 100px; }   /* ← 名稱欄最大寬，可調 */
#op-table td:nth-child(2) {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 職業/稀有度/精英/等級/潛能：固定窄寬 */
#op-table th:nth-child(3),
#op-table td:nth-child(3) { width: 80px; }         /* 職業 */
#op-table th:nth-child(4),
#op-table td:nth-child(4) { width: 50px; }         /* 稀有度 */
#op-table th:nth-child(5),
#op-table td:nth-child(5) { width: 40px; }         /* 精英 */
#op-table th:nth-child(6),
#op-table td:nth-child(6) { width: 40px; }         /* 等級 */
#op-table th:nth-child(7),
#op-table td:nth-child(7) { width: 40px; }         /* 潛能 */

/* 技能欄：3 個 36px 圖 + 2 個 4px gap = 116px */
#op-table th:nth-child(8),
#op-table td:nth-child(8) { width: 200px; }        /* ← 技能欄寬，可調 */

/* 模組欄：4 個 36px 圖 + 3 個 4px gap = 156px */
#op-table th:nth-child(9),
#op-table td:nth-child(9) { width: 200px; }        /* ← 模組欄寬，可調 */

/* 其他欄位不換行 */
#op-table td:not(:nth-child(2)):not(:nth-child(8)):not(:nth-child(9)) { white-space: nowrap; }

/* 技能列 */
.tbl-skill-list { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.tbl-skill-item {
  position: relative;
  width: 36px; height: 36px;
  flex-shrink: 0;
}
.tbl-skill-icon {
  width: 36px; height: 36px;
  object-fit: contain;
  border-radius: 4px;
  background: rgba(0,0,0,0.4);
  display: block;
}
.tbl-skill-badge {
  position: absolute;
  top: -3px; left: -3px;
  width: 12px; height: 12px;
  object-fit: contain;
}
.tbl-skill-badge-txt {
  position: absolute;
  top: -3px; left: -3px;
  width: 12px; height: 12px;
  background: #000; color: #fff;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: 2px; line-height: 1;
}

/* 模組列 */
.tbl-equip-list { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.tbl-equip-item {
  position: relative;
  width: 36px; height: 36px;
  flex-shrink: 0;
  border-radius: 4px;
  background-color: rgba(0,0,0,0.4);
  background-size: 130%;
  background-repeat: no-repeat;
  background-position: center;
}
.tbl-none { font-size: 12px; color: #475569; }
