img {
  max-width: 100%; /* 图片最大宽度不超过其父容器的 100% */
  height: auto;    /* 高度自动等比例缩放，防止图片变形 */
  display: block;  /* 消除图片底部的微小空隙 */
}

/* 容器：严禁固定高度，靠内容自然撑开 */
.danmaku-container {
  display: flex;
  flex-direction: column;
  gap: 16px; /* 固定的间距，防堆叠核心 */
  padding: 20px;
  max-width: 550px;
  background: #f8f9fa;
  border-radius: 16px;
}

/* 基础卡片 */
.danmaku-item {
  display: flex;
  flex-direction: column; /* 名字和内容分行，给流式文本留足横向空间 */
  gap: 6px;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  
  /* 仅做淡入，不做任何形变或位移，保证100%稳定 */
  animation: fadeInOnly 0.3s ease-out forwards;
}

/* 角色名字轻量化 */
.danmaku-item .avatar {
  font-size: 12px;
  font-weight: 600;
  color: #868e96;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* 文本区域：自适应换行 */
.danmaku-item .content {
  font-size: 14px;
  color: #212529;
  line-height: 1.6;
  word-break: break-word; /* 防止长文本或表情包撑破布局 */
}

/* 差异化微调（仅通过左侧精致的线条区分角色，不破坏整体的极简感） */
.danmaku-item.mom { border-left: 3px solid #ff8787; }
.danmaku-item.user { border-left: 3px solid #4dabf7; }
.danmaku-item.narrator { 
  border-left: 3px solid #f1c40f; 
  background: #fffdf5; /* 乐子人稍微带有舞台感底色 */
}

/* 绝对安全的纯淡入动画 */
@keyframes fadeInOnly {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Details：流式输出稳定版 ===== */
details {
  margin: 18px 0;
  border: 1px solid #e1e5e9;
  border-left: 4px solid #74c0fc;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;

  /*
   * 流式输出时不使用阴影动画和尺寸动画，
   * 减少页面持续重绘、闪烁。
   */
  box-shadow: 0 2px 8px rgba(33, 37, 41, 0.05);
}

/* 当前情况 */
details:first-of-type {
  border-left-color: #4dabf7;
}

/* 记忆回廊 */
details:last-of-type {
  border-left-color: #adb5bd;
}

/* ===== Summary 标题栏 ===== */
details > summary {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 12px 46px 12px 16px;
  box-sizing: border-box;

  color: #343a40;
  background: #f8f9fa;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.5;

  cursor: pointer;
  user-select: none;
  list-style: none;
  outline: none;

  /*
   * 流式更新时不要给 summary 设置 transition，
   * 避免 DOM 更新过程中颜色反复过渡。
   */
}

/* 隐藏浏览器默认箭头 */
details > summary::-webkit-details-marker {
  display: none;
}

details > summary::marker {
  content: "";
}

/* 自定义箭头 */
details > summary::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 18px;
  width: 8px;
  height: 8px;
  border-right: 2px solid #868e96;
  border-bottom: 2px solid #868e96;
  transform: translateY(-65%) rotate(45deg);
}

/* 展开状态箭头 */
details[open] > summary::after {
  transform: translateY(-30%) rotate(225deg);
}

details > summary:hover {
  color: #212529;
  background: #f1f3f5;
}

details > summary:focus-visible {
  outline: 2px solid rgba(77, 171, 247, 0.55);
  outline-offset: -2px;
}

details[open] > summary {
  color: #212529;
  background: #f6f8fa;
  border-bottom: 1px solid #e9ecef;
}

/* ===== Details 内容间距 ===== */
details > :not(summary) {
  margin-left: 16px;
  margin-right: 16px;
}

details > summary + * {
  margin-top: 16px;
}

details > :last-child:not(summary) {
  margin-bottom: 16px;
}

/* ===== 文本排版 ===== */
details p {
  margin-top: 10px;
  margin-bottom: 10px;
  line-height: 1.75;
}

details ul,
details ol {
  margin-top: 10px;
  margin-bottom: 14px;
  padding-left: 24px;
}

details li {
  margin: 5px 0;
  line-height: 1.7;
}

details,
details p,
details li,
details td,
details th {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ===== 表格 ===== */
details table {
  width: calc(100% - 32px);
  margin: 14px 16px 18px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #e5e9ed;
  border-radius: 9px;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.55;
}

details th,
details td {
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  border-right: 1px solid #edf0f2;
  border-bottom: 1px solid #edf0f2;
}

details th {
  color: #495057;
  background: #f7f8fa;
  font-weight: 650;
}

details td {
  color: #343a40;
  background: #ffffff;
}

details th:last-child,
details td:last-child {
  border-right: none;
}

details tr:last-child td {
  border-bottom: none;
}

/* ===== 移动端 ===== */
@media (max-width: 600px) {
  details {
    margin: 14px 0;
    border-radius: 10px;

    /*
     * 移动端流式渲染时阴影重绘开销更明显，
     * 使用更轻量的阴影。
     */
    box-shadow: 0 1px 4px rgba(33, 37, 41, 0.05);
  }

  details > summary {
    min-height: 44px;
    padding: 10px 40px 10px 12px;
    font-size: 14px;
  }

  details > summary::after {
    right: 15px;
    width: 7px;
    height: 7px;
  }

  details > :not(summary) {
    margin-left: 12px;
    margin-right: 12px;
  }

  details > summary + * {
    margin-top: 13px;
  }

  details > :last-child:not(summary) {
    margin-bottom: 13px;
  }

  details table {
    display: block;
    width: calc(100% - 24px);
    margin: 12px;
    overflow-x: auto;
    white-space: nowrap;
    font-size: 12px;
    -webkit-overflow-scrolling: touch;
  }

  details th,
  details td {
    min-width: 110px;
    padding: 8px;
  }

  details th:last-child,
  details td:last-child {
    min-width: 220px;
    white-space: normal;
  }
}