/* =============================================================================
 * 金蜡笔日记 / Trickcal Crayon — css/styles.css
 * 全局设计系统：亮/暗双主题、布局框架、卡片/按钮/chip/对话框、棋盘 Grid、响应式。
 * 纯原生 CSS，无预处理器、无框架。
 * ========================================================================== */

/* ----- 1. 设计令牌（Design Tokens） ----- */
:root {
  /* 属性色（攻/暴/生/防/抗） */
  --attr-attack: #ff5a6e;
  --attr-crit: #ff9f1c;
  --attr-health: #25c2a0;
  --attr-defense: #4d8bf0;
  --attr-crit-resist: #9b5de5;
  --attr-attack-soft: rgba(255, 90, 110, 0.16);
  --attr-crit-soft: rgba(255, 159, 28, 0.16);
  --attr-health-soft: rgba(37, 194, 160, 0.16);
  --attr-defense-soft: rgba(77, 139, 240, 0.16);
  --attr-crit-resist-soft: rgba(155, 93, 229, 0.16);

  /* 奖励阶色 */
  --tier-special: #f4b740;
  --tier-first: #f08a3c;
  --tier-second: #d96fb8;
  --tier-third: #6aa9f0;
  --tier-fourth: #8fcf6a;

  /* 间距 / 圆角 / 字体 */
  --space-1: 4px;
  --primary-soft: rgba(244, 183, 64, 0.16);
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --font-sans: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui,
    -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;

  --topbar-h: 56px;
  --bottomnav-h: 60px;
  --sidebar-w: 232px;
  --cell-size: 26px;
  --content-max: 1180px;
}

/* ----- 2. 主题：浅色（默认） ----- */
:root,
[data-theme="light"] {
  --bg: #f5f6fb;
  --bg-elevated: #ffffff;
  --bg-sunken: #eef0f7;
  --bg-hover: #f0f2f9;
  --surface: #ffffff;
  --border: #e3e6ef;
  --border-strong: #cdd2e1;
  --text: #1f2330;
  --text-soft: #5b6275;
  --text-faint: #9aa1b4;
  --primary: #f4b740;
  --primary-strong: #e0a017;
  --primary-contrast: #2a2208;
  --secondary: #9b5de5;
  --danger: #e5484d;
  --success: #25a46a;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, 0.06), 0 2px 8px rgba(20, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(20, 24, 40, 0.10);
  --shadow-lg: 0 12px 40px rgba(20, 24, 40, 0.18);
  color-scheme: light;
}

/* ----- 3. 主题：暗色 ----- */
[data-theme="dark"] {
  --bg: #14161f;
  --bg-elevated: #1d2030;
  --bg-sunken: #10121b;
  --bg-hover: #262a3d;
  --surface: #1d2030;
  --border: #2c3145;
  --border-strong: #3a405a;
  --text: #eef0f7;
  --text-soft: #aab2c8;
  --text-faint: #717a93;
  --primary: #f4b740;
  --primary-strong: #ffc94d;
  --primary-contrast: #2a2208;
  --secondary: #b07df0;
  --danger: #ff6166;
  --success: #36c183;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ----- 4. Reset ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}
h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 700;
  line-height: 1.25;
}
a {
  color: inherit;
  text-decoration: none;
}
button {
  font-family: inherit;
  cursor: pointer;
}
img {
  max-width: 100%;
  display: block;
}
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ----- 5. 布局骨架 ----- */
.app-shell {
  min-height: 100vh;
}

/* 顶栏 */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}
.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 800;
  font-size: 16px;
}
.topbar__logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
}
.topbar__logo-img {
  height: 28px;
  width: auto;
  object-fit: contain;
}
.topbar__title {
  font-weight: 600;
  color: var(--text-soft);
  font-size: 14px;
  margin-left: var(--space-1);
}
.topbar__spacer {
  flex: 1;
}
.topbar__menu {
  display: none;
}
.sidebar.is-open ~ .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* 侧边栏（桌面） */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 30;
  overflow-y: auto;
}
.nav-group__label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: var(--space-3) var(--space-3) var(--space-1);
  font-weight: 700;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-soft);
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.nav-item.is-active {
  background: var(--primary-soft, rgba(244, 183, 64, 0.16));
  color: var(--primary-strong);
}
.nav-item[data-soon] {
  opacity: 0.5;
  cursor: not-allowed;
}
.nav-item[data-soon]:hover {
  background: transparent;
  color: var(--text-soft);
}
.nav-item__icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
}
.nav-item__icon-img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

/* 主内容 */
.main {
  margin-top: var(--topbar-h);
  margin-left: var(--sidebar-w);
  padding: var(--space-5);
  min-height: calc(100vh - var(--topbar-h));
}
.content {
  max-width: var(--content-max);
  margin: 0 auto;
}
.page-head {
  margin-bottom: var(--space-5);
}
.page-head .page-back {
  margin-bottom: var(--space-3);
  padding-left: 8px;
  padding-right: 12px;
}
.page-head h1 {
  font-size: 22px;
}
.page-head p {
  margin: var(--space-2) 0 0;
  color: var(--text-soft);
}

/* 底部 Tab（移动） */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-h);
  display: none;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 40;
}
.bottomnav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
}
.bottomnav__item.is-active {
  color: var(--primary-strong);
}
.bottomnav__icon {
  font-size: 20px;
}
.bottomnav__icon-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

/* ----- 6. 组件：卡片 / 按钮 / chip ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card--pad {
  padding: var(--space-4);
}
.card--hover {
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.card--hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 14px;
  background: var(--bg-sunken);
  color: var(--text);
  transition: filter 0.15s ease, background 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover {
  filter: brightness(0.97);
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  background: var(--primary);
  color: var(--primary-contrast);
}
.btn--primary:hover {
  background: var(--primary-strong);
}
.btn--secondary {
  background: var(--secondary);
  color: #fff;
}
.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
}
.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn--sm {
  padding: 6px 12px;
  font-size: 13px;
}
.btn--block {
  width: 100%;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  display: inline-grid;
  place-items: center;
  font-size: 18px;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
  font-weight: 600;
  font-size: 13px;
  transition: all 0.12s ease;
  user-select: none;
}
.chip:hover {
  border-color: var(--primary);
}
.chip.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}
/* 属性/性格筛选 chip：纯图标（无边框、无背景、无文字），选中靠透明度区分 */
.chip--attr,
.chip--personality {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 12px;
  border: none;
  background: transparent;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.12s ease, transform 0.08s ease;
}
.chip--attr:hover,
.chip--personality:hover {
  transform: scale(1.08);
}
.chip--attr .icon-img--wrap,
.chip--personality .icon-img--wrap {
  --icon-size: 48px;   /* 图标 = 按键尺寸，图标即按键 */
  width: 100%;
  height: 100%;
  margin-right: 0;
}
.chip--attr .icon-img__img,
.chip--personality .icon-img__img {
  width: 100%;
  height: 100%;
}
/* 选中：仅图标变亮（alpha=1.0），不出现任何背景/边框变化 */
.chip--attr.is-active,
.chip--personality.is-active {
  opacity: 1;
  background: transparent;
  border-color: transparent;
  color: inherit;
}
.chip--sm {
  padding: 4px 10px;
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  background: var(--bg-sunken);
  color: var(--text-soft);
}
.badge--attr {
  color: #fff;
}
.badge--personality {
  background: var(--secondary);
  color: #fff;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-3);
}
.field__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
}
.field__hint {
  font-size: 11px;
  color: var(--text-faint);
}
.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  color: var(--text);
  transition: border-color 0.15s ease;
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  outline: none;
}
.textarea {
  resize: vertical;
  min-height: 90px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
}
.input--num {
  text-align: right;
}

/* 开关 */
.switch {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  border: none;
  transition: background 0.18s ease;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s ease;
}
.switch.is-on {
  background: var(--primary);
}
.switch.is-on::after {
  transform: translateX(18px);
}

/* ----- 7. 棋盘 Grid（等宽正方 + 密度类 + 三态属性边框 + lit tint 叠色） ----- */
.board {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-x: auto;
  padding-bottom: var(--space-2);
}
.board-layer {
  display: block;
  background: var(--bg-sunken);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.board-layer--dense { --cell-radius: 10px; }
.board-layer__title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  margin-bottom: 4px;
}
.board-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr));
  gap: 8px;
  justify-content: start;
}
.board-grid--dense { gap: 4px; }

/* 单元格：等宽正方（grid 列宽 1fr + aspect-ratio 保证正方） */
.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  max-width: var(--cell-cap, 88px);
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: transparent;
  overflow: hidden;
}
.board-layer--dense .cell,
.cell--dense { border-radius: 10px; }

/* 底图 / 文字 / lit 叠色 层级 */
.cell__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: inherit;
  pointer-events: none;
  max-width: 100%;
  max-height: 100%;
  display: block;
}
.cell__label {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  height: 100%;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
}
.cell__tint {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--tint, transparent);
  opacity: 0.18;
  border-radius: inherit;
  pointer-events: none;
}
.cell--purple {
  background: linear-gradient(135deg, #9b5de5, #6a3fd0);
}

/* 属性 tint 双变量（与 common.CELL_TINT_COLORS 逐位一致） */
.cell--attr-ATTACK      { --cell-tint: #E76F51; --cell-tint-35: rgba(231, 111, 81, 0.35); }
.cell--attr-CRIT        { --cell-tint: #F4A261; --cell-tint-35: rgba(244, 162, 97, 0.35); }
.cell--attr-HEALTH      { --cell-tint: #4CAF50; --cell-tint-35: rgba(76, 175, 80, 0.35); }
.cell--attr-DEFENSE     { --cell-tint: #4C6EF5; --cell-tint-35: rgba(76, 110, 245, 0.35); }
.cell--attr-CRIT_RESIST { --cell-tint: #9C6ADE; --cell-tint-35: rgba(156, 106, 222, 0.35); }

/* 非属性格：1dp 浅灰 α0.18 */
.cell--white,
.cell--start,
.cell--end {
  border: 1px solid rgba(150, 155, 170, 0.18);
}
.cell--white { background: var(--bg-sunken); }
.cell--start,
.cell--end { background: var(--bg-hover); }

/* EMPTY：透明占位（保留网格形状），无边框 */
.cell--empty {
  background: transparent;
  border: none;
}

/* 展示型属性格：弱透明度 */
.cell--display { opacity: 0.5; }

/* 紫系属性格：加载紫格图片，满亮显示（图片自带紫色，不走 --display 透明） */
.cell--purple-attr { /* 仅作语义标记，外观由 cell__img 决定 */ }

/* 未解锁的可涂色格：仅轻度降饱和 + 略降不透明度，
   既保留格子本身的颜色/样式可辨认，又能明显区分是否已解锁。 */
.cell.is-unlit .cell__img {
  filter: grayscale(0.55);
  opacity: 0.68;
}

/* 可解锁格：仅保留中性基础边框（来自 .cell）+ 指针/hover 反馈，
   不再使用彩色边框（点亮即去灰、恢复满色，无需彩色描边）。 */
.cell--clickable {
  cursor: pointer;
  transition: transform 0.08s ease;
}
.cell--clickable:hover { transform: scale(1.08); }

/* 卡片内 mini 蜡笔板（22dp 缩略，对齐安卓 LayerSummaryBlock） */
.char-boards {
  --cell-cap: 22px;
  margin: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.char-boards .board-layer {
  padding: 4px 6px;
  border-radius: 8px;
}
.char-boards .board-layer__title {
  font-size: 11px;
  margin-bottom: 2px;
}
.char-boards .board-grid {
  grid-template-columns: repeat(var(--cols), 22px);
  gap: 3px;
}
.char-boards .cell {
  width: 22px;
  height: 22px;
  aspect-ratio: auto;
  max-width: none;
  border-radius: 5px;
}
.char-boards .cell__label { font-size: 8px; }
/* mini 板只读：不显示可点击态（hover 放大 / 指针） */
.char-boards .cell--clickable { cursor: default; }
.char-boards .cell--clickable:hover { transform: none; }

/* ----- 卡片摘要（对齐截图：每层标题 + 彩色蜡笔板格子图片流式布局） ----- */
.card-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.card-summary__layer {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.card-summary__layer-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.card-summary__cells {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
/* 单个蜡笔板格子图片（cell_attack.png 等，约 26px 圆角方块） */
.card-summary__cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  opacity: 0.4; /* 未点亮：alpha 0.4（对齐安卓 UnlockableCellVisual） */
  transition: opacity 0.12s ease;
  background: transparent;
  overflow: hidden;
}
.card-summary__cell.is-lit {
  opacity: 1; /* 已点亮：alpha 1.0 */
}
.card-summary__cell-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
/* 蜡笔涂色模式：卡片内格子可直接点击涂色 */
.card-summary__cell--clickable {
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.card-summary__cell--clickable:hover {
  transform: scale(1.12);
}
/* 卡片分隔线（对齐安卓 HorizontalDivider） */
.char-card__divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}
/* 图标（容器叠加：文字底层 + 真图覆盖） */
.icon-img--wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  line-height: 1;
}
.icon-img__img {
  position: relative;
  z-index: 1;
  width: var(--icon-size, 18px);
  height: var(--icon-size, 18px);
  object-fit: contain;
  display: block;
}
.icon-img__fallback {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-soft);
}
/* 通用 chip 内图标（文字型 chip 用）；属性/性格 chip 由各自的 --icon-size 控制 */
.chip:not(.chip--attr):not(.chip--personality) .icon-img--wrap { --icon-size: 16px; margin-right: 3px; }
.badge--personality .icon-img--wrap { --icon-size: 14px; margin-right: 3px; }
.attr-bar__icon .icon-img--wrap { --icon-size: 18px; }
.gold-crayon-img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 4px;
}
.gold-crayon-img--tiny {
  width: 14px;
  height: 14px;
  margin-right: 2px;
}

/* ----- 8. 网格 / 列表 ----- */
.grid {
  display: grid;
  gap: var(--space-4);
}
.grid--chars {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  align-items: stretch;
}
.grid--pets {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.grid--tools {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* 角色卡片 */
.char-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  cursor: pointer;
  height: 100%; /* 均分栅格高度，整行卡片等高 */
}
.char-card__top {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.char-card__avatar {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--bg-sunken);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  flex: none;
  overflow: hidden;
}
.char-avatar__img,
.char-card__avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  filter: saturate(0.85) brightness(0.97);  /* 降低鲜艳度，更护眼 */
}
.char-card__avatar.char-avatar--compact {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font-size: 14px;
}
.char-card__name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;   /* 强制单行 */
  overflow: visible;        /* 完整显示，不截断 */
}
.char-card__meta {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
  align-items: center;
}
.char-card__bar {
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  overflow: hidden;
}
.char-card__bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}
.char-card__actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
}

/* 紧凑网格：5 列（窄屏 4 列），对齐安卓 */
/* 紧凑模式：固定适中尺寸的方块瓦片（头像约 88px），自动按宽度铺排 */
.compact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(0, 92px));
  gap: 8px;
  justify-content: start;
}
@media (max-width: 560px) {
  .compact-grid { grid-template-columns: repeat(auto-fill, minmax(0, 76px)); }
}

/* 紧凑瓦片：仅头像，正方填满；变暗盖 0.42 黑色半透明遮罩（对齐安卓 isCompactDimmed） */
.compact-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
}
.compact-tile .char-card__avatar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
}
.compact-tile.is-dimmed::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  border-radius: inherit;
  pointer-events: none;
}

/* ----- 9. 工具栏（筛选） ----- */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: stretch;
  margin-bottom: var(--space-4);
}
/* 每行：宽屏时同行，空间不足时整行内自动换行 */
.toolbar__line {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
}
.toolbar__group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 1 auto;
  min-width: 0;
}
/* 搜索框固定最长宽度，不强行延长占据剩余空间 */
.toolbar__group--search {
  flex: 0 0 auto;
}
.toolbar__group-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.toolbar__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.search-input {
  width: 260px;
  max-width: 100%;
}
/* 中等屏：搜索独占一行；属性/性格/操作各自独占一行，
   浏览+层级、匹配+显示 各保持同行 */
@media (max-width: 900px) {
  .toolbar__group--search { flex-basis: 100%; }
  .toolbar__group--attr { flex-basis: 100%; }
  .toolbar__group--personality { flex-basis: 100%; }
  .toolbar__group--actions { flex-basis: 100%; }
}
/* 窄屏：除匹配模式/显示外，其余分组独占一行（继续动态降级）；
   匹配模式与显示优先同排，仅当二者也放不下时再各自换行分两排 */
@media (max-width: 560px) {
  .toolbar__group:not(.toolbar__group--mode):not(.toolbar__group--display) { flex-basis: 100%; }
}

/* ----- 10. 涂色统计 ----- */

/* Hero */
.stats-hero {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.stats-hero__ring-wrap { position: relative; flex: none; }
.stats-hero__ring { display: block; transform: rotate(-90deg); }
.stats-hero__ring-bg { fill: none; stroke: var(--bg-sunken); stroke-width: 8; }
.stats-hero__ring-fill {
  fill: none;
  stroke: url(#stats-ring-grad);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.stats-hero__ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.stats-hero__ring-pct { font-size: 28px; font-weight: 800; line-height: 1; color: var(--text); }
.stats-hero__ring-sub { font-size: 11px; color: var(--text-soft); margin-top: 2px; font-weight: 600; }
.stats-hero__metrics { flex: 1; display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.stats-hero__metric { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; }
.stats-hero__metric-icon {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  display: grid; place-items: center; font-size: 20px; flex: none;
}
.stats-hero__metric-icon--crayon { background: none; }
.stats-hero__metric-icon--slot { background: none; }
.stats-hero__metric-icon-img { width: 36px; height: 36px; object-fit: contain; }
.stats-hero__metric-icon--crayon .gold-crayon-img { width: 36px; height: 36px; object-fit: contain; }
.stats-hero__metric-body { flex: 1; min-width: 0; }
.stats-hero__metric-value { font-size: 20px; font-weight: 800; line-height: 1.2; }
.stats-hero__metric-label { font-size: 11px; color: var(--text-faint); font-weight: 600; }
.stats-hero__metric-bar { height: 3px; background: var(--bg-sunken); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.stats-hero__metric-bar-fill { display: block; height: 100%; border-radius: 2px; transition: width 0.6s ease; }
.stats-hero__metric-bar-fill--crayon { background: var(--primary); }
.stats-hero__metric-bar-fill--slot { background: var(--secondary); }

/* 属性加成标签行 */
.stats-hero__bonus-row { padding: var(--space-2) 0; }
.stats-hero__bonus-label { font-size: 11px; color: var(--text-faint); font-weight: 600; margin-bottom: 6px; }
.stats-hero__bonus-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.stats-hero__bonus-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 12px;
  white-space: nowrap;
}
.stats-hero__bonus-tag img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: none;
}
.stats-hero__bonus-name { color: var(--text-soft); }
.stats-hero__bonus-value { font-weight: 800; font-variant-numeric: tabular-nums; }

/* 表头（去掉标题：直接进表格头） */
.master-head {
  display: grid;
  grid-template-columns: 100px 1.4fr repeat(3, 1fr);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}
.master-head__cell {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.master-head__cell--label {
  justify-content: center;
  text-align: center;
}
.master-head__cell--overview {
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.master-head__name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.master-head__meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 1px;
}
/* 行 */
.master-rows {
  padding: 0;
}
.master-row {
  display: grid;
  grid-template-columns: 100px 1.4fr repeat(3, 1fr);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.master-row:last-child {
  border-bottom: none;
}
.master-row:hover {
  background: var(--bg-hover);
}
/* 属性标签列 */
/* 属性标签：默认显示全名，窄屏切换为 2 字短名 */
.attr-label-full { display: inline; }
.attr-label-short { display: none; }
.master-row__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.master-row__label .attr-label { white-space: nowrap; }
.master-row__label img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex: none;
}
/* 单元格：进度条 + 数据 */
.master-row__cell {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  min-width: 0;
}
.master-row__cell--overview {
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.master-row__cell:not(.master-row__cell--overview) {
  border-right: 1px solid var(--border);
}
.master-row__cell:last-child {
  border-right: none;
}
/* 进度条 */
.master-row__bar {
  flex: 1;
  min-width: 30px;
  height: 6px;
  background: rgba(127, 127, 127, 0.12);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.master-row__bar-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}
/* 数据组：百分比 + count + 加成 */
.master-row__data {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex: none;
  white-space: nowrap;
}
.master-row__pct {
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 36px;
}
.master-row__nums {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}
.master-row__bonus {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
}

/* 底部 / 空状态 */
.stats-footer { text-align: center; padding: var(--space-4); color: var(--text-faint); font-size: 11px; }
.stats-empty { text-align: center; padding: var(--space-6); color: var(--text-faint); }
.stats-empty__icon { font-size: 48px; margin-bottom: var(--space-3); display: block; }

/* 响应式 */
@media (max-width: 900px) {
  .stats-hero { flex-direction: column; align-items: center; text-align: center; gap: var(--space-4); }
  .stats-hero__ring-wrap { margin: 0 auto; }
  .stats-hero__metrics { width: 100%; }
  .master-head, .master-row {
    grid-template-columns: 70px 1.2fr repeat(3, 1fr);
  }
  .master-row__label span { font-size: 12px; }
}
@media (max-width: 640px) {
  .master-row__cell { padding: 0 4px; gap: 4px; }
  /* 数据组改为垂直堆叠，让 X/Y 显示在百分比下方 */
  .master-row__data {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    line-height: 1.2;
  }
  .master-row__nums { display: inline; font-size: 10px; line-height: 1.2; }
  .master-row__pct { font-size: 12px; min-width: 28px; line-height: 1.2; }
  .master-row__bonus { display: none; }
  /* 属性名：换用 2 字短名（攻击力→攻击 / 暴击抗性→暴抗） */
  .attr-label-full { display: none; }
  .attr-label-short { display: inline; }
}
@media (max-width: 480px) {
  .master-head, .master-row {
    grid-template-columns: 50px repeat(3, 1fr);
  }
  .master-head__cell--overview,
  .master-row__cell--overview,
  .master-row__bonus { display: none; }
}

/* ----- 11. 计算器布局 ----- */
.calc-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  align-items: start;
}
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.result-table th,
.result-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.result-table th {
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.result-table td:last-child,
.result-table th:last-child {
  text-align: right;
}
.result-table tr.is-final td {
  font-weight: 800;
  font-size: 15px;
  background: var(--primary-soft, rgba(244, 183, 64, 0.1));
}
.result-table tr.is-final td:last-child {
  color: var(--primary-strong);
}
.result-table .row-desc {
  color: var(--text-faint);
  font-weight: 400;
  font-size: 11px;
  display: block;
}

/* 高级设置折叠 */
.collapsible__toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  font-weight: 700;
  background: none;
  border: none;
  padding: var(--space-2) 0;
}
.collapsible__body {
  display: none;
}
.collapsible.is-open .collapsible__body {
  display: block;
}
.collapsible__chevron {
  transition: transform 0.2s ease;
}
.collapsible.is-open .collapsible__chevron {
  transform: rotate(90deg);
}

/* ----- 12. 派遣 ----- */
.region-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3);
}
.pet-card-mini {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface);
}
.pet-thumb {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  object-fit: cover;
  flex: none;
  background: var(--bg-sunken);
}
.pet-thumb--placeholder {
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 15px;
}
.pet-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.pet-list-item.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft, rgba(244, 183, 64, 0.1));
}
.pet-list-item__name {
  flex: 1;
  font-weight: 600;
}
.pet-list-item__meta {
  font-size: 11px;
  color: var(--text-faint);
}
.rarity-tag {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
}
.rarity-COMMON { background: #cfd4e0; color: #2a2f3d; }
.rarity-ADVANCED { background: #b6e3c6; color: #14512f; }
.rarity-RARE { background: #bcd6ff; color: #1a3f7a; }
.rarity-LEGENDARY { background: #ffe6a8; color: #6b4a00; }

.assignment {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--surface);
}
.assignment__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
  gap: var(--space-2);
  flex-wrap: wrap;
}
.assignment__team {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.team-pet {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-sunken);
  border-radius: var(--radius-pill);
  padding: 3px 10px 3px 3px;
  font-size: 13px;
  font-weight: 600;
}
.team-pet img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
}
.task-bonus {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.report-box {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  max-height: 360px;
  overflow: auto;
  line-height: 1.6;
}

/* ----- 13. 对话框 ----- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 60;
  backdrop-filter: blur(2px);
}
.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dialog--sm {
  max-width: 460px;
}
.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.dialog__body {
  padding: var(--space-4);
  overflow: auto;
}
.dialog__foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}

/* ----- 14. 详情页布局（对齐安卓 CharacterDetailScreen） ----- */
.detail-header {
  margin-bottom: var(--space-3);
}
.detail-header__top {
  display: flex;
  align-items: center;
  gap: 14px;
}
.detail-header__top .char-card__avatar {
  width: 72px;
  height: 72px;
  font-size: 28px;
  border-radius: 16px;
  flex: none;
}
.detail-header__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.detail-header__name {
  font-size: 20px;
  font-weight: 800;
}
.detail-header__tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.detail-header__progress {
  text-align: right;
  flex: none;
  line-height: 1.3;
}
.detail-header__counts {
  font-size: 22px;
  font-weight: 800;
}

/* 各层蜡笔板：在大卡片内作为板块，不再独立成卡 */
.detail-layer-card {
  background: none;
  padding: var(--space-2);
}
.detail-layer-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.detail-layer-card__title {
  font-size: 15px;
  font-weight: 700;
}

/* 三层蜡笔板：并排紧凑布局（宽屏 3 列，窄屏自适应降级为 2 列 / 1 列） */
.detail-boards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  /* 同行卡片等高（grid 默认 align-items:stretch），确保三层背景一致 */
  align-items: stretch;
}
.detail-boards .detail-layer-card {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}
/* 隐藏棋盘自带的「第N层」标题（头部已有层信息） */
.detail-boards .board-layer__title {
  display: none;
}
/* 棋盘区域撑满卡片剩余高度，黑色背景铺满 */
.detail-boards .board-layer {
  --cell-cap: 46px;
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.detail-boards .board-grid {
  gap: 4px;
  justify-content: center;
  flex: 1;
}
.detail-boards .detail-layer-card__head {
  margin-bottom: 8px;
  flex: none;
}
@media (max-width: 880px) {
  .detail-boards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .detail-boards { grid-template-columns: 1fr; }
  .detail-boards .board-layer { --cell-cap: 52px; }
}
.empty-state {
  text-align: center;
  padding: var(--space-6);
  color: var(--text-faint);
}
.empty-state__icon {
  font-size: 40px;
  margin-bottom: var(--space-2);
}
.row {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}
.row--between {
  justify-content: space-between;
}
.muted {
  color: var(--text-soft);
}
.faint {
  color: var(--text-faint);
}
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin: var(--space-5) 0 var(--space-3);
}
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-4) 0;
  border: none;
}
.settings-author {
  margin-top: var(--space-5);
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}
.toast {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg-elevated);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.kbd {
  font-family: var(--font-mono);
  background: var(--bg-sunken);
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  font-size: 12px;
}

/* ----- 15. 响应式 ----- */
@media (min-width: 901px) {
  .topbar__menu {
    display: none !important;
  }
  .sidebar-backdrop {
    display: none !important;
  }
}
@media (max-width: 900px) {
  .sidebar {
    display: none;
  }
  .main {
    margin-left: 0;
    padding: var(--space-4);
    padding-bottom: calc(var(--bottomnav-h) + var(--space-5));
  }
  .bottomnav {
    display: flex;
  }
  .calc-layout {
    grid-template-columns: 1fr;
  }
  .topbar__title {
    display: none;
  }
  /* 移动端：顶栏显示汉堡按钮，sidebar 改为抽屉 */
  .topbar__menu {
    display: inline-grid;
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 20, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 35;
  }
  body.is-sidebar-open {
    overflow: hidden;
  }
  body.is-sidebar-open .sidebar {
    display: flex;
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }
  body.is-sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .sidebar {
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    width: 180px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 45; /* 盖在遮罩(35)之上，保证抽屉内容可见可点击 */
  }
}
@media (max-width: 560px) {
  .grid--chars {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  }
  :root {
    --cell-size: 22px;
  }
  .page-head h1 {
    font-size: 19px;
  }
}
