:root {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --ink: #2b3445;
  --sub: #8a94a6;
  --line: #e3e8f0;
  --accent: #4f7cff;
  --accent-soft: #e8eefe;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 26px; }
.titles h1 { font-size: 17px; margin: 0; line-height: 1.2; white-space: nowrap; }
.titles .sub { font-size: 11px; color: var(--sub); }
.toolbar { display: flex; align-items: center; gap: 10px; }
.mode-switch {
  display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px;
}
.mode-switch button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 8px;
  font-size: 13px; color: var(--sub); cursor: pointer; font-family: inherit;
}
.mode-switch button.active { background: var(--accent); color: #fff; }
#btnUpdate {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 7px 14px; border-radius: 10px; font-size: 13px; cursor: pointer; font-family: inherit;
}
#btnUpdate:hover { border-color: var(--accent); color: var(--accent); }
#btnUpdate:disabled { opacity: .5; cursor: default; }

/* ---------- 搜索栏 ---------- */
#searchBar {
  display: flex; gap: 8px; padding: 10px 16px 0;
  flex: 0 0 auto;
}
#searchBar.hidden { display: none; }
#searchInput {
  flex: 1; padding: 10px 14px; font-size: 15px; border: 1.5px solid var(--line);
  border-radius: 10px; outline: none; font-family: inherit; background: var(--panel); color: var(--ink);
}
#searchInput:focus { border-color: var(--accent); }
#btnClear {
  border: 0; background: var(--accent-soft); color: var(--accent);
  padding: 0 16px; border-radius: 10px; cursor: pointer; font-size: 13px; font-family: inherit;
}

/* ---------- 提示条 ---------- */
#hintBar {
  flex: 0 0 auto; padding: 8px 16px 0; font-size: 12.5px; color: var(--sub);
  min-height: 26px;
}
#hintBar b { color: var(--accent); }

/* ---------- 性格筛选 ---------- */
#personaBar {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 16px 0;
}
#personaBar .p-label { font-size: 12.5px; color: var(--sub); }
.persona-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 4px 12px 4px 5px; border-radius: 999px; font-size: 13px;
  cursor: pointer; font-family: inherit; line-height: 1.5;
}
.persona-chip img { width: 22px; height: 22px; display: block; border-radius: 6px; }
.persona-chip:hover { border-color: var(--accent); }
.persona-chip.active {
  border-color: var(--accent); background: var(--accent-soft);
  color: var(--accent); font-weight: bold;
}
.persona-chip .n { font-size: 11px; color: var(--sub); font-weight: normal; }
.persona-chip.active .n { color: var(--accent); }

/* ---------- 主面板 ---------- */
#panels {
  flex: 1 1 auto; display: flex; gap: 12px; padding: 10px 16px 16px; min-height: 0;
}
.panel {
  flex: 1 1 50%; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.panel-head {
  display: flex; align-items: baseline; gap: 8px; padding: 12px 14px 8px;
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head .count { font-size: 12px; color: var(--sub); }
.panel-search {
  margin-left: auto; width: 46%; max-width: 260px; padding: 6px 12px;
  font-size: 13px; border: 1.5px solid var(--line); border-radius: 9px;
  outline: none; font-family: inherit; background: var(--bg); color: var(--ink);
}
.panel-search:focus { border-color: var(--accent); background: #fff; }
.grid {
  flex: 1 1 auto; overflow-y: auto; padding: 12px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px;
  align-content: start;
}

/* ---------- 卡片 ---------- */
.card {
  position: relative; border-radius: 12px; padding: 8px 6px 6px; cursor: pointer;
  background: #fbfcfe; border: 1.5px solid transparent; text-align: center;
  transition: border-color .12s, transform .08s, background .12s;
  user-select: none;
}
.card:hover { background: var(--accent-soft); }
.card:active { transform: scale(.97); }
.card .pic { position: relative; width: 72px; height: 72px; margin: 0 auto; }
.card .pic img { width: 100%; height: 100%; object-fit: contain; }
.card .nm { font-size: 12.5px; margin-top: 5px; line-height: 1.25; word-break: break-all; }
.card .alias { font-size: 10.5px; color: var(--sub); margin-top: 1px; word-break: break-all; }
.card.selected { border-color: var(--accent); background: var(--accent-soft); }
.card.dimmed { opacity: .28; }
.card .badge {
  position: absolute; width: 26px; height: 26px; object-fit: contain;
  filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.25)); pointer-events: none;
}
.card .badge.b-char { top: -4px; left: -4px; }   /* 角色左上角 */
.card .badge.b-food { top: -4px; right: -4px; }  /* 食物右上角 */

/* 空态 */
.empty-msg { padding: 30px 10px; text-align: center; color: var(--sub); font-size: 13px; }
.empty-msg.hidden, .hidden { display: none !important; }

/* 滚动条 */
.grid::-webkit-scrollbar { width: 8px; }
.grid::-webkit-scrollbar-thumb { background: #ccd4e0; border-radius: 4px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: rgba(35, 42, 60, .92); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 10px; z-index: 99; max-width: 80vw; line-height: 1.5;
}

/* ---------- 窄屏 ---------- */
@media (max-width: 720px) {
  /* 手机：固定视口、双面板上下分、各自内部滚动（类App体验） */
  html, body { height: 100%; overflow: hidden; }
  body { height: 100vh; height: 100dvh; }
  #topbar { padding: 8px 10px; gap: 8px; }
  .titles h1 { font-size: 14px; }
  .titles .sub { font-size: 10px; display: block; line-height: 1.3; }
  #btnUpdate { white-space: nowrap; padding: 7px 10px; font-size: 12px; flex: 0 0 auto; }
  #hintBar { padding: 6px 10px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #personaBar {
    flex-wrap: nowrap; overflow-x: auto; padding: 8px 10px 0;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  #personaBar::-webkit-scrollbar { display: none; }
  #personaBar .p-label, .persona-chip { flex: 0 0 auto; }
  #panels { flex-direction: column; padding: 8px 10px 10px; gap: 8px; overflow: hidden; }
  .panel { flex: 1 1 0; min-height: 0; }
  .panel-head { flex-wrap: wrap; padding: 8px 10px 6px; gap: 6px; }
  .panel-head .count { margin-left: auto; }
  .panel-search { order: 3; width: 100%; max-width: none; margin-left: 0; }
  .grid { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px; }
  .card .pic { width: 56px; height: 56px; }
}
