/* ============================================================
   超神学院 · 天使圣殿 — 全端统一美化CSS
   适配：网页端 (.ai-chat-container) + App端 (#viewer.built-in-css-active)
   功能：高亮标记 · 输入框白底金边 · 75%/全宽气泡 · 立绘展示
   ============================================================ */

/* ============================================================
   ★★★ 1. 全局基础变量（网页端） ★★★
   ============================================================ */
.ai-chat-container {
  --ink: #2e2418;
  --paper: #f7f3e8;
  --gold: #b49450;
  --gold-light: #d4b76a;
  --angel-blue: #5a7d9a;
  --void-purple: #7a6a9a;
  --border-subtle: rgba(180, 148, 80, 0.25);

  background-color: var(--paper);
  font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  line-height: 1.7;
  padding: 1rem;
  box-sizing: border-box;
}

/* 网页端全局文字颜色 */
.ai-chat-container,
.ai-chat-container * {
  color: var(--ink) !important;
}

/* 网页端次要信息弱化 */
.ai-chat-container .el-bubble-footer,
.ai-chat-container .el-bubble-footer *,
.ai-chat-container .last-turn,
.ai-chat-container .comm-post-author {
  color: #8b7a62 !important;
  font-size: 0.8rem;
}


/* ============================================================
   ★★★ 2. 时空信息行 ★★★
   ============================================================ */
.time-location-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  width: 100%;
  background: rgba(255, 252, 245, 0.9);
  border: 1px solid var(--border-subtle);
  border-radius: 40px;
  padding: 0.8rem 2rem;
  margin-bottom: 2rem;
  box-sizing: border-box;
}


/* ============================================================
   ★★★ 3. 消息气泡（75%宽度） ★★★
   ============================================================ */
.el-bubble-content {
  background: rgba(255, 252, 245, 0.95) !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: 20px !important;
  max-width: 75% !important;
  width: auto !important;
  padding: 1.4rem 1.8rem !important;
  margin-bottom: 1rem;
  word-break: break-word;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04) !important;
}

.el-bubble-start .el-bubble-content {
  margin-right: auto !important;
  margin-left: 0 !important;
  border-left: 4px solid var(--angel-blue) !important;
}

.el-bubble-end .el-bubble-content {
  margin-left: auto !important;
  margin-right: 0 !important;
  border-right: 4px solid var(--void-purple) !important;
}


/* ============================================================
   ★★★ 4. 正文叙事区 ★★★
   ============================================================ */
.narrative-body {
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 2rem 0.5rem !important;
  margin: 2rem 0;
  font-size: 1.2rem;
  line-height: 2.1;
  text-align: justify;
  word-break: break-word;
}

.narrative-body p {
  margin-bottom: 1.6rem;
  text-indent: 2.2em;
}

.narrative-body p:first-child {
  text-indent: 0;
}


/* ============================================================
   ★★★ 5. 标题 ★★★
   ============================================================ */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  font-family: 'Georgia', 'Times New Roman', serif !important;
  color: #6b4e1e !important;
  border-bottom: 2px solid #e0c88c !important;
  padding-bottom: 0.4rem !important;
  margin: 2rem 0 1rem !important;
}


/* ============================================================
   ★★★ 6. 高亮标记 ★★★
   ============================================================ */
.hl-npc { color: #8b5e14 !important; font-weight: 700; }
.hl-dialogue { color: #2a5f7a !important; font-style: italic; }
.hl-skill { color: #5f3d8a !important; font-weight: 700; }
.hl-location { color: #3d6b8a !important; }
.hl-item { color: #8a3d5f !important; }
.hl-danger { color: #b04444 !important; font-weight: 700; }
.hl-good { color: #2a6a4a !important; }
.hl-void { color: #6a4d8a !important; font-style: italic; }
.hl-angel { color: #5a7d9a !important; font-weight: 600; }
.hl-demon { color: #8a4d5a !important; font-weight: 600; }


/* ============================================================
   ★★★ 7. 折叠面板 ★★★
   ============================================================ */
details {
  width: 100% !important;
  background: rgba(255, 252, 245, 0.8);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 0.8rem 1.2rem;
  margin-bottom: 0.8rem;
  box-sizing: border-box;
}

summary {
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  padding: 0.4rem 0;
}

summary::before {
  content: '✧ ';
  color: var(--gold);
}


/* ============================================================
   ★★★ 8. 表格 ★★★
   ============================================================ */
.markdown-body table {
  width: 100% !important;
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.markdown-body th {
  background: rgba(180, 148, 80, 0.15);
  font-weight: 700;
}


/* ============================================================
   ★★★ 9. 选项按钮 ★★★
   ============================================================ */
.option-btn {
  width: 100% !important;
  background: rgba(255, 250, 240, 0.9) !important;
  border: 2px solid #e0c88c !important;
  border-radius: 14px !important;
  padding: 1rem 1.5rem !important;
  margin: 8px 0 !important;
  font-weight: 600;
  transition: 0.3s;
  color: #2e2418 !important;
}

.option-btn:hover {
  background: #e0c88c !important;
  border-color: #b08b4c !important;
  transform: translateX(6px);
}

.option-number {
  background: #d4a843 !important;
  color: white !important;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
}


/* ============================================================
   ★★★ 10. 输入框美化 ★★★
   ============================================================ */
.input-field,
.select-field,
input[type="text"],
input[type="number"],
textarea {
  background: #ffffff !important;
  border: 2px solid #d4a843 !important;
  color: #b49450 !important;
  border-radius: 8px !important;
  padding: 0.6rem 1rem !important;
  font-weight: 600;
  outline: none;
}

.input-field:focus,
.select-field:focus,
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
  border-color: #b08b4c !important;
  box-shadow: 0 0 8px rgba(180, 148, 80, 0.4);
}

.select-field {
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><path fill="%23b49450" d="M6 8L1 3h10z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 14px center;
}


/* ============================================================
   ★★★ 11. 立绘展示样式 ★★★
   ============================================================ */

/* 角色头像/立绘容器（矩形，适合竖版立绘） */
.profile-avatar,
.relation-avatar,
.npc-avatar {
  flex-shrink: 0;
  width: 120px;
  height: 160px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid #d4a84b;
  box-shadow: 0 0 20px rgba(212, 168, 75, 0.15);
  background: #0a080f;
  position: relative;
}

/* 立绘图片 */
.profile-avatar img,
.relation-avatar img,
.npc-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 无图占位 */
.profile-avatar:not(:has(img))::after,
.relation-avatar:not(:has(img))::after,
.npc-avatar:not(:has(img))::after {
  content: attr(data-placeholder);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 14px;
  font-weight: 700;
  color: #d4a84b;
  background: linear-gradient(135deg, #1a1230, #2d1a48);
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
  padding: 8px;
  box-sizing: border-box;
  word-break: break-all;
  line-height: 1.2;
}

/* 档案面板中的立绘行 */
.npc-avatar-row,
.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 0 14px 0;
  border-bottom: 1px solid #2d2448;
  margin-bottom: 14px;
}


/* ============================================================
   ★★★ 12. APP端美化 ★★★
   ============================================================ */
#viewer.built-in-css-active {
  --ink: #2e2418;
  --paper: #f7f3e8;
  --gold: #b49450;

  background-color: var(--paper) !important;
  font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  padding: 0.6rem !important;
  box-sizing: border-box;
}

#viewer.built-in-css-active,
#viewer.built-in-css-active * {
  color: var(--ink) !important;
}

#viewer.built-in-css-active .el-bubble-footer,
#viewer.built-in-css-active .last-turn,
#viewer.built-in-css-active .comm-post-author {
  color: #8b7a62 !important;
  font-size: 0.7rem;
}

/* App端 · 信息行 */
#viewer.built-in-css-active .time-location-bar {
  padding: 0.4rem 0;
  margin-bottom: 0.8rem;
  font-size: 0.75rem;
  background: transparent;
  border: none;
}

/* App端 · 气泡（全宽无边框） */
#viewer.built-in-css-active .viewer-message-card {
  background: rgba(255, 252, 245, 0.9) !important;
  border: none !important;
  border-radius: 6px !important;
  padding: 0.8rem !important;
  box-shadow: none !important;
}

/* App端 · 正文 */
#viewer.built-in-css-active .narrative-body {
  background: transparent !important;
  border: none !important;
  padding: 0.6rem 0 !important;
  margin: 0.6rem 0;
  font-size: 1rem;
  line-height: 1.8;
}

/* App端 · 折叠面板 */
#viewer.built-in-css-active details {
  background: rgba(255, 252, 245, 0.6);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
}

#viewer.built-in-css-active summary {
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  list-style: none;
}

#viewer.built-in-css-active summary::before {
  content: '✧ ';
  color: var(--gold);
}

/* App端 · 选项按钮 */
#viewer.built-in-css-active .option-btn {
  background: rgba(255, 252, 245, 0.8);
  border: 1px solid rgba(180, 148, 80, 0.2);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin: 4px 0;
  font-size: 0.9rem;
}

#viewer.built-in-css-active .option-number {
  background: #d4a843 !important;
  color: white !important;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  font-size: 0.8rem;
}

/* App端 · 表格 */
#viewer.built-in-css-active .markdown-body table {
  width: 100%;
  overflow-x: auto;
  font-size: 0.8rem;
}

#viewer.built-in-css-active .markdown-body th,
#viewer.built-in-css-active .markdown-body td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(180, 148, 80, 0.15);
  white-space: nowrap;
}

/* App端 · 输入框 */
#viewer.built-in-css-active .input-field,
#viewer.built-in-css-active .select-field,
#viewer.built-in-css-active input[type="text"],
#viewer.built-in-css-active input[type="number"],
#viewer.built-in-css-active textarea {
  background: #ffffff !important;
  border: 2px solid #d4a843 !important;
  color: #b49450 !important;
  border-radius: 8px !important;
  padding: 0.6rem 1rem !important;
  font-weight: 600;
  outline: none;
}

#viewer.built-in-css-active .input-field:focus,
#viewer.built-in-css-active .select-field:focus,
#viewer.built-in-css-active input[type="text"]:focus,
#viewer.built-in-css-active input[type="number"]:focus,
#viewer.built-in-css-active textarea:focus {
  border-color: #b08b4c !important;
  box-shadow: 0 0 8px rgba(180, 148, 80, 0.4);
}

#viewer.built-in-css-active .select-field {
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><path fill="%23b49450" d="M6 8L1 3h10z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 14px center;
}


/* ============================================================
   ★★★ 13. 移动端适配 ★★★
   ============================================================ */
@media (max-width: 768px) {
  .ai-chat-container {
    padding: 0.5rem;
  }

  .el-bubble-content {
    max-width: 100% !important;
    padding: 1rem 1.2rem !important;
    border-radius: 14px !important;
  }

  .narrative-body {
    font-size: 1rem;
    padding: 1rem 0.2rem !important;
    margin: 1rem 0;
    line-height: 1.9;
  }

  .narrative-body p {
    text-indent: 1.8em;
  }

  .time-location-bar {
    padding: 0.5rem 1rem;
    gap: 0.8rem;
    font-size: 0.8rem;
    border-radius: 30px;
  }

  .profile-avatar,
  .relation-avatar,
  .npc-avatar {
    width: 80px;
    height: 106px;
  }

  .npc-avatar-row,
  .profile-avatar-row {
    gap: 12px;
  }

  details {
    padding: 0.5rem 0.8rem;
  }

  summary {
    font-size: 0.9rem;
  }

  .option-btn {
    padding: 0.7rem 1rem !important;
    font-size: 0.9rem;
    border-radius: 10px !important;
  }

  .option-number {
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
    margin-right: 10px;
  }

  .markdown-body th,
  .markdown-body td {
    padding: 6px 8px;
    font-size: 0.8rem;
    white-space: normal;
  }

  .input-field,
  .select-field,
  input[type="text"],
  input[type="number"],
  textarea {
    padding: 0.5rem 0.8rem !important;
    font-size: 0.9rem !important;
  }
}

@media (max-width: 480px) {
  .profile-avatar,
  .relation-avatar,
  .npc-avatar {
    width: 60px;
    height: 80px;
  }

  .npc-avatar-row,
  .profile-avatar-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .narrative-body {
    font-size: 0.9rem;
  }

  .time-location-bar {
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
  }

  .option-btn {
    font-size: 0.8rem;
    padding: 0.5rem 0.8rem !important;
  }

  .option-number {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
    margin-right: 8px;
  }

  details {
    padding: 0.4rem 0.6rem;
  }

  summary {
    font-size: 0.8rem;
  }
}