/* ═══ B平台表格修正（自动注入）═══ */
.rili-markdown-renderer table { display:table!important; table-layout:auto!important; width:100%!important; border-collapse:collapse!important; }
.rili-markdown-renderer table caption { display:table-caption!important; caption-side:top!important; text-align:center!important; padding:8px!important; }
.rili-markdown-renderer thead { display:table-header-group!important; }
.rili-markdown-renderer tbody { display:table-row-group!important; }
.rili-markdown-renderer tr { display:table-row!important; }
.rili-markdown-renderer th, .rili-markdown-renderer td { display:table-cell!important; }

/* ═══ B平台按钮组保护（自动注入 — 防止按钮消失）═══
   原理：B平台消息操作按钮结构为：
   .flex.items-center.gap-1.ml-auto (hover显隐包装)
     └── .bg-muted.rounded.flex.p-0.5 (按钮组容器)
           └── button.rounded-full.size-7 (单个按钮)
   以下规则使用高specificity + !important确保按钮
   不被任何转换后/透传的CSS规则意外隐藏
   ═══════════════════════════════════════════════ */
/* 按钮组容器保护 */
.w-full.h-full.flex.group .bg-muted.rounded.flex.p-0\.5,
.is-user .bg-muted.rounded.flex.p-0\.5,
.is-assistant .bg-muted.rounded.flex.p-0\.5 {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  overflow: visible !important;
  position: relative !important;
  width: auto !important;
  height: auto !important;
  max-height: none !important;
  pointer-events: auto !important;
  clip: auto !important;
  clip-path: none !important;
}
/* 单个按钮保护 */
.w-full.h-full.flex.group .bg-muted.rounded.flex.p-0\.5 > button,
.is-user .bg-muted.rounded.flex.p-0\.5 > button,
.is-assistant .bg-muted.rounded.flex.p-0\.5 > button {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  position: relative !important;
  clip: auto !important;
  clip-path: none !important;
}
/* hover显隐包装层保护 — 仅保留B平台原生的opacity过渡 */
.flex.items-center.gap-1.ml-auto.md\:opacity-0.group-hover\:opacity-100 {
  visibility: visible !important;
  display: flex !important;
  pointer-events: auto !important;
  overflow: visible !important;
}
/* 操作行保护 */
.flex.w-full.items-center.justify-between.gap-2.px-2 {
  display: flex !important;
  visibility: visible !important;
  overflow: visible !important;
}

/* =============================================
 * 吟游诗人逸闻学院 · DND聊天框美化方案（修正版）
 * 核心风格：古旧羊皮纸 | 烫金装饰 | 叙事感衬线字体
 * 修正内容：
 *   1. 生命值条宽度改用 --hp-pct 小数（0~1），通过 calc(var(--hp-pct)*100%) 计算百分比
 *   2. 移除重复/错误的 width 声明
 *   3. 调整选择器优先级，确保自定义样式生效
 * ============================================= */

/* --- 全局基础：羊皮纸背景 --- */
ai {
  --bg-parchment: #faf5eb;
  --bg-panel: rgba(255, 248, 235, 0.92);
  --text-primary: #3b2a1f;
  --text-secondary: #6b5a4a;
  --accent-dark: #5c3d2e;
  --accent-red: #9b2c2c;
  --accent-magic: #3a4f8a;
  --accent-quest: #7a6b3a;
  --gold: #b8860b;
  --silver: #6b7b8d;
  --copper: #a05a2c;
  --shadow-soft: 0 2px 10px rgba(92, 61, 46, 0.12);
  --shadow-lift: 0 6px 18px rgba(92, 61, 46, 0.18);
  --radius-sm: 6px;
  --radius-md: 10px;
  --font-main: 'Georgia', 'Noto Serif', serif;
  --font-ui: 'Segoe UI', 'Roboto', system-ui, sans-serif;

  display: block;
  background: linear-gradient(160deg, #faf5eb 0%, #ede0cc 100%);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 15px;
  line-height: 1.5;
  padding: 8px;
  border-radius: var(--radius-md);
  position: relative;
}

/* --- 所有 details 面板统一样式 --- */
ai details.status-panel,
ai details.char-panel,
ai details.npc-panel,
ai details.quest-panel,
ai details.theatre-panel,
ai details.memory-panel,
ai details.action-panel {
  margin: 10px 0;
  background: var(--bg-panel);
  border: 1px solid rgba(92, 61, 46, 0.2);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

ai details.status-panel:hover,
ai details.char-panel:hover,
ai details.npc-panel:hover,
ai details.quest-panel:hover,
ai details.theatre-panel:hover,
ai details.memory-panel:hover,
ai details.action-panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}

/* --- Summary 标题栏 --- */
ai details > summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--accent-dark);
  background: linear-gradient(90deg, rgba(92, 61, 46, 0.08) 0%, transparent 70%);
  border-bottom: 1px solid rgba(92, 61, 46, 0.15);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

ai details > summary::-webkit-details-marker {
  display: none;
}

/* SVG 图标（内联，不依赖外部资源） */
ai details > summary::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.7;
}

ai details.status-panel > summary::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235c3d2e' d='M12 20a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm0-1.5a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13z'/%3E%3Cpath fill='%235c3d2e' d='M12 6v6l4 2'/%3E%3C/svg%3E");
}
ai details.char-panel > summary::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235c3d2e' d='M12 4a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM6.5 18v-2c0-2.2 1.8-4 4-4h3c2.2 0 4 1.8 4 4v2'/%3E%3C/svg%3E");
}
ai details.npc-panel > summary::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235c3d2e' d='M16 11c1.7 0 3-1.3 3-3s-1.3-3-3-3-3 1.3-3 3 1.3 3 3 3zm-8 0c1.7 0 3-1.3 3-3S9.7 5 8 5 5 6.3 5 8s1.3 3 3 3zm0 2c-2.3 0-7 1.2-7 3.5V19h14v-2.5c0-2.3-4.7-3.5-7-3.5zm8 0c-.3 0-.6 0-1 .1 1.2.8 2 1.9 2 3.4V19h6v-2.5c0-2.3-4.7-3.5-7-3.5z'/%3E%3C/svg%3E");
}
ai details.quest-panel > summary::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235c3d2e' d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2l5 5h-5V4zM8 13h8v2H8v-2zm0 4h8v2H8v-2z'/%3E%3C/svg%3E");
}
ai details.theatre-panel > summary::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235c3d2e' d='M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z'/%3E%3C/svg%3E");
}
ai details.memory-panel > summary::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235c3d2e' d='M13 9h-2V7h2v2zm0 4h-2v-2h2v2zm0 4h-2v-2h2v2zm6-10h-2V5h-2v2H9V5H7v2H5a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2zm0 12H5V9h14v10z'/%3E%3C/svg%3E");
}
ai details.action-panel > summary::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235c3d2e' d='M16.2 3C14.8 1.6 13 1 11 1 8.2 1 6 3.2 6 6c0 1.2.5 2.3 1.3 3.2L3 20h4l2-4h2l2 4h4l-4.3-10.8C13.5 8.3 14 7.2 14 6c0-.8-.3-1.6-.8-2.2L16.2 3zM11 3c1.7 0 3 1.3 3 3s-1.3 3-3 3-3-1.3-3-3 1.3-3 3-3z'/%3E%3C/svg%3E");
}

/* --- 状态网格 --- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 14px;
  font-size: 0.9rem;
}

.s-item {
  display: flex;
  flex-direction: column;
}

.s-item .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.s-item .value {
  font-weight: bold;
  color: var(--accent-dark);
}

/* --- 主角卡片主体 --- */
.char-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
}

.char-header {
  grid-column: 1 / -1;
  border-bottom: 2px dashed rgba(92, 61, 46, 0.25);
  padding-bottom: 10px;
  margin-bottom: 6px;
}

.nameplate {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}

.nameplate h3 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--accent-dark);
  letter-spacing: 0.02em;
}

.title-tag {
  font-size: 0.8rem;
  background: var(--accent-dark);
  color: #f5efe0;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: normal;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.meta-row span {
  white-space: nowrap;
}

.meta-row em {
  font-style: normal;
  font-weight: bold;
  color: var(--accent-dark);
}

.col-left,
.col-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.block {
  background: rgba(255, 255, 250, 0.6);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border: 1px solid rgba(92, 61, 46, 0.1);
}

.block h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- 生命值条（修正核心） --- */
.stat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.stat-bar .label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 45px;
}

.bar-bg {
  flex: 1;
  height: 10px;
  background: #e2d6c5;
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

/*  !!! 关键修正：宽度由自定义属性 --hp-pct 决定，值为 0~1 的小数，AI 填充时需计算 !!! */
.bar-fill.hp {
  height: 100%;
  background: linear-gradient(90deg, #c0392b, #e74c3c);
  box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.4);
  /* 示例：style="--hp-pct: 0.75" 则宽度为 75% */
  width: calc(var(--hp-pct) * 100%);
  transition: width 0.6s ease;
}

.stat-bar .val {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--accent-dark);
}

.val.ac {
  font-size: 1.1rem;
}

.inline-stats {
  display: flex;
  gap: 14px;
  font-size: 0.85rem;
  margin-top: 4px;
}

.inline-stats b {
  color: var(--accent-dark);
}

/* --- 属性网格 --- */
.attr-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.attr {
  text-align: center;
  padding: 6px 2px;
  background: rgba(92, 61, 46, 0.04);
  border-radius: 4px;
}

.attr-name {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: block;
}

.attr-val {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--accent-dark);
  display: block;
}

.attr-mod {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* --- 熟练项 --- */
.proficiencies {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.85rem;
}

.prof-cat {
  display: flex;
  gap: 4px;
}

.prof-cat b {
  min-width: 40px;
  color: var(--accent-dark);
}

/* --- 外貌 / 性格 --- */
.appearance p,
.personality p {
  margin: 4px 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* --- 施法 --- */
.spellcasting {
  border-left: 3px solid var(--accent-magic);
}

.spell-dc {
  font-size: 0.8rem;
  font-weight: normal;
  color: var(--accent-magic);
}

.spell-attr {
  font-size: 0.85rem;
  margin: 4px 0;
}

.cantrips {
  font-size: 0.85rem;
  margin: 4px 0;
}

.cantrips b {
  color: var(--accent-dark);
}

.spell-slots {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.slot-tier {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(58, 79, 138, 0.08);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
}

.slot-tier span:first-child {
  font-weight: bold;
  color: var(--accent-magic);
}

/* --- 特性 & 资源 & 装备 --- */
.feature-item,
.res-item,
.equip-item {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.85rem;
  margin: 4px 0;
  padding: 4px;
  border-radius: 4px;
  background: rgba(92, 61, 46, 0.03);
}

.feature-item b,
.equip-item b {
  color: var(--accent-dark);
  min-width: 60px;
}

.res-item {
  justify-content: space-between;
}

.res-val {
  font-weight: bold;
  color: var(--accent-red);
}

.backpack {
  font-size: 0.85rem;
  margin: 4px 0;
}

.backpack b {
  color: var(--accent-dark);
}

.currency {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.coin {
  font-weight: bold;
  font-size: 0.9rem;
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.coin em {
  font-size: 0.7rem;
  font-style: normal;
  font-weight: normal;
  color: var(--text-secondary);
}

.coin.gp {
  color: var(--gold);
}
.coin.sp {
  color: var(--silver);
}
.coin.cp {
  color: var(--copper);
}

/* --- NPC 面板 --- */
.npc-card {
  padding: 14px;
  border-bottom: 1px solid rgba(92, 61, 46, 0.08);
}

.npc-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.npc-header h4 {
  margin: 0;
  color: var(--accent-dark);
}

.npc-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.npc-traits {
  display: flex;
  gap: 18px;
  font-size: 0.85rem;
  margin: 4px 0;
}

.npc-rel {
  font-weight: bold;
  color: var(--accent-red);
}

.npc-desc {
  margin: 6px 0;
  font-size: 0.85rem;
}

.npc-desc p {
  margin: 3px 0;
}

.npc-divider {
  text-align: center;
  color: var(--accent-dark);
  font-size: 1.2rem;
  padding: 6px;
  opacity: 0.4;
}

/* --- 任务面板 --- */
.quest-block {
  padding: 8px 14px;
  border-bottom: 1px dashed rgba(92, 61, 46, 0.1);
}

.quest-block h4 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--accent-quest);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quest-marker {
  color: var(--accent-red);
  margin-right: 4px;
}

.quest-main {
  font-weight: bold;
}

.quest-side {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0;
}

.quest-reward {
  font-size: 0.8rem;
  background: rgba(122, 107, 58, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
}

ul.rumors,
ul.secrets {
  margin: 4px 0;
  padding-left: 20px;
  font-size: 0.85rem;
}

ul.rumors li,
ul.secrets li {
  margin: 2px 0;
}

/* --- 吟游诗人剧场 --- */
.bard-quote {
  margin: 10px 14px;
  padding: 10px 16px;
  background: rgba(92, 61, 46, 0.06);
  border-left: 4px solid var(--accent-dark);
  font-style: italic;
  color: var(--text-secondary);
}

.theatre-scene,
.theatre-whisper,
.theatre-news {
  margin: 8px 14px;
  padding: 6px 10px;
  background: rgba(255, 250, 240, 0.7);
  border-radius: var(--radius-sm);
}

.theatre-scene h5,
.theatre-whisper h5,
.theatre-news h5 {
  margin: 0 0 4px;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--accent-dark);
  letter-spacing: 0.04em;
}

.theatre-scene p,
.theatre-whisper p,
.theatre-news p {
  margin: 2px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* --- 记忆表格 --- */
.mem-section {
  padding: 10px 14px;
}

.mem-section h4 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--accent-dark);
}

.mem-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(92, 61, 46, 0.2);
}

.mem-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 450px;
}

.mem-table th,
.mem-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(92, 61, 46, 0.1);
}

.mem-table th {
  background: rgba(92, 61, 46, 0.08);
  font-weight: bold;
  color: var(--accent-dark);
  white-space: nowrap;
}

.mem-table tr:last-child td {
  border-bottom: none;
}

/* --- 行动推荐 --- */
.action-list {
  padding: 8px 14px 14px 30px;
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.8;
}

.action-list li::marker {
  color: var(--accent-red);
  font-weight: bold;
}

/* --- 响应式 --- */
@media (max-width: 640px) {
  .status-grid {
    grid-template-columns: 1fr;
  }
  .char-body {
    grid-template-columns: 1fr;
  }
  .attr-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .meta-row {
    flex-direction: column;
    gap: 2px;
  }
  .quest-side {
    flex-direction: column;
  }
  .currency {
    flex-direction: column;
    gap: 4px;
  }
  .action-list {
    padding-left: 24px;
  }
}