/* ═══════════════════════════════════════════
   异世界主题 — Isekai Realm UI
   ═══════════════════════════════════════════ */

/* ── 全局字体与变量 ── */
.group.is-user > div:first-child,
.group.is-assistant > div:first-child {
  --isekai-glow: rgba(180, 130, 255, 0.4);
  --isekai-border: rgba(200, 160, 255, 0.6);
  font-size: 1.05em !important;
}

/* ═══════════════════════════════════════════
   1. 独立框线界面 — 气泡基础
   ═══════════════════════════════════════════ */

/* 用户气泡 */
.group.is-user > div:first-child {
  background: linear-gradient(135deg, 
    rgba(255, 120, 180, 0.15), 
    rgba(200, 100, 255, 0.12), 
    rgba(100, 180, 255, 0.1)) !important;
  border: 1.5px solid rgba(255, 150, 200, 0.5) !important;
  border-radius: 16px !important;
  box-shadow: 
    0 0 12px rgba(255, 130, 180, 0.25),
    inset 0 0 20px rgba(255, 180, 220, 0.05) !important;
  position: relative !important;
  isolation: isolate !important;
  overflow: hidden !important;
}

/* AI气泡 */
.group.is-assistant > div:first-child {
  background: linear-gradient(135deg, 
    rgba(100, 200, 255, 0.1), 
    rgba(160, 120, 255, 0.12), 
    rgba(80, 220, 180, 0.08)) !important;
  border: 1.5px solid var(--isekai-border) !important;
  border-radius: 16px !important;
  box-shadow: 
    0 0 12px var(--isekai-glow),
    inset 0 0 20px rgba(180, 130, 255, 0.04) !important;
  position: relative !important;
  isolation: isolate !important;
  overflow: hidden !important;
}

/* ═══════════════════════════════════════════
   2. 随机变花颜色 — 气泡背景动效 (::before)
   ═══════════════════════════════════════════ */

.group.is-user > div:first-child::before {
  content: "" !important;
  position: absolute !important;
  inset: 0 !important;
  z-index: -1 !important;
  background: 
    radial-gradient(ellipse 80px 80px at 20% 30%, rgba(255, 100, 150, 0.2), transparent),
    radial-gradient(ellipse 60px 60px at 70% 60%, rgba(255, 200, 100, 0.15), transparent),
    radial-gradient(ellipse 50px 50px at 50% 80%, rgba(200, 100, 255, 0.12), transparent) !important;
  animation: flowerShiftUser 8s ease-in-out infinite alternate !important;
  opacity: 0.9 !important;
}

.group.is-assistant > div:first-child::before {
  content: "" !important;
  position: absolute !important;
  inset: 0 !important;
  z-index: -1 !important;
  background: 
    radial-gradient(ellipse 90px 90px at 75% 25%, rgba(100, 200, 255, 0.18), transparent),
    radial-gradient(ellipse 70px 70px at 25% 70%, rgba(180, 100, 255, 0.15), transparent),
    radial-gradient(ellipse 55px 55px at 50% 50%, rgba(80, 255, 180, 0.1), transparent) !important;
  animation: flowerShiftAI 10s ease-in-out infinite alternate !important;
  opacity: 0.9 !important;
}

@keyframes flowerShiftUser {
  0% { filter: hue-rotate(0deg); transform: scale(1); }
  33% { filter: hue-rotate(60deg); transform: scale(1.05); }
  66% { filter: hue-rotate(150deg); transform: scale(0.97); }
  100% { filter: hue-rotate(270deg); transform: scale(1.02); }
}

@keyframes flowerShiftAI {
  0% { filter: hue-rotate(0deg); transform: scale(1); }
  25% { filter: hue-rotate(90deg); transform: scale(1.03); }
  50% { filter: hue-rotate(180deg); transform: scale(0.98); }
  75% { filter: hue-rotate(250deg); transform: scale(1.04); }
  100% { filter: hue-rotate(330deg); transform: scale(1); }
}

/* ═══════════════════════════════════════════
   3. 文字可读性 — 高对比度前景
   ═══════════════════════════════════════════ */

.rili-markdown-renderer,
.rili-markdown-renderer * {
  color: #e8e0f0 !important;
  text-shadow: 
    0 0 2px rgba(0, 0, 0, 0.8),
    0 1px 3px rgba(0, 0, 0, 0.5) !important;
}

.rili-markdown-renderer strong,
.rili-markdown-renderer b {
  color: #ffd6e8 !important;
}

.rili-markdown-renderer em,
.rili-markdown-renderer i {
  color: #c8b8ff !important;
}

.rili-markdown-renderer h1,
.rili-markdown-renderer h2,
.rili-markdown-renderer h3,
.rili-markdown-renderer h4 {
  color: #ffffff !important;
  text-shadow: 
    0 0 6px rgba(200, 150, 255, 0.6),
    0 0 2px rgba(0, 0, 0, 0.9) !important;
}

.rili-markdown-renderer code {
  color: #a0ffda !important;
  background: rgba(0, 0, 0, 0.35) !important;
  border-radius: 4px !important;
  padding: 1px 5px !important;
}

.rili-markdown-renderer a {
  color: #80d4ff !important;
  text-decoration: underline !important;
}

/* ═══════════════════════════════════════════
   4. 折叠状态栏 <details> 美化
   ═══════════════════════════════════════════ */

.rili-markdown-renderer details {
  background: linear-gradient(145deg, 
    rgba(40, 20, 80, 0.85), 
    rgba(20, 10, 50, 0.9)) !important;
  border: 1.5px solid rgba(180, 130, 255, 0.5) !important;
  border-radius: 14px !important;
  padding: 14px 18px !important;
  margin: 10px 0 !important;
  box-shadow: 
    0 0 15px rgba(150, 100, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
  font-size: 1.2em !important;
  transition: box-shadow 0.3s ease !important;
}

.rili-markdown-renderer details[open] {
  box-shadow: 
    0 0 20px rgba(180, 130, 255, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08) !important;
}

.rili-markdown-renderer details summary {
  color: #e0d0ff !important;
  font-weight: 700 !important;
  font-size: 1.2em !important;
  cursor: pointer !important;
  padding: 6px 4px !important;
  list-style: none !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  text-shadow: 0 0 4px rgba(180, 130, 255, 0.4) !important;
  transition: color 0.2s ease !important;
}

.rili-markdown-renderer details summary:hover {
  color: #ffffff !important;
}

/* 自定义折叠箭头 */
.rili-markdown-renderer details summary::-webkit-details-marker {
  display: none !important;
}

.rili-markdown-renderer details summary::before {
  content: "⟡" !important;
  display: inline-block !important;
  font-size: 1em !important;
  transition: transform 0.3s ease !important;
  color: #c8a0ff !important;
}

.rili-markdown-renderer details[open] summary::before {
  transform: rotate(90deg) !important;
  color: #ff80c0 !important;
}

/* 折叠内容区 */
.rili-markdown-renderer details > *:not(summary) {
  font-size: 1.2em !important;
  color: #dcd0f0 !important;
  line-height: 1.7 !important;
}

.rili-markdown-renderer details p,
.rili-markdown-renderer details li,
.rili-markdown-renderer details span {
  font-size: 1.2em !important;
  color: #dcd0f0 !important;
}

/* ═══════════════════════════════════════════
   5. Markdown 表格 — 自适应 & 异世界风格
   ═══════════════════════════════════════════ */

/* 表格外层容器自适应 */
.rili-markdown-renderer div:has(> table),
.rili-markdown-renderer .table-wrapper {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  max-width: 100% !important;
  border-radius: 12px !important;
  margin: 12px 0 !important;
}

.rili-markdown-renderer table {
  width: 100% !important;
  min-width: 280px !important;
  border-collapse: separate !important;
  border-spacing: 0 !important;
  border: 1.5px solid rgba(180, 130, 255, 0.4) !important;
  border-radius: 12px !important;
  overflow: hidden !important;
  font-size: clamp(0.8em, 2.5vw, 1em) !important;
  table-layout: auto !important;
}

.rili-markdown-renderer th {
  background: linear-gradient(135deg, 
    rgba(80, 40, 160, 0.9), 
    rgba(120, 60, 200, 0.85)) !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  padding: clamp(6px, 2vw, 12px) clamp(8px, 2.5vw, 16px) !important;
  text-align: left !important;
  border-bottom: 2px solid rgba(200, 150, 255, 0.6) !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6) !important;
  white-space: nowrap !important;
}

.rili-markdown-renderer td {
  background: rgba(20, 10, 50, 0.7) !important;
  color: #e0d8f0 !important;
  padding: clamp(5px, 1.8vw, 10px) clamp(8px, 2.5vw, 16px) !important;
  border-bottom: 1px solid rgba(150, 100, 255, 0.2) !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5) !important;
  word-break: break-word !important;
  min-width: 60px !important;
}

.rili-markdown-renderer tr:nth-child(even) td {
  background: rgba(40, 20, 80, 0.6) !important;
}

.rili-markdown-renderer tr:hover td {
  background: rgba(100, 60, 180, 0.4) !important;
  color: #ffffff !important;
}

/* 最后一行去底边框 */
.rili-markdown-renderer tr:last-child td {
  border-bottom: none !important;
}

/* ═══════════════════════════════════════════
   6. 两个火柴人打架 — 加载动画
   ═══════════════════════════════════════════ */

/* 隐藏原生加载点 */
.flex.gap-2.w-full.h-full.items-center.justify-center > span {
  display: none !important;
}

.flex.gap-2.w-full.h-full.items-center.justify-center {
  position: relative !important;
  min-height: 60px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* 火柴人打架 SVG 动画 (SMIL内联) */
.flex.gap-2.w-full.h-full.items-center.justify-center::before {
  content: "" !important;
  display: block !important;
  width: 120px !important;
  height: 60px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 60'%3E%3C!-- 火柴人A --%3E%3Ccircle cx='30' cy='12' r='5' fill='none' stroke='%23c8a0ff' stroke-width='1.5'%3E%3Canimate attributeName='cy' values='12;10;12' dur='0.6s' repeatCount='indefinite'/%3E%3C/circle%3E%3Cline x1='30' y1='17' x2='30' y2='35' stroke='%23c8a0ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='30;32;30' dur='0.6s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='30' y1='35' x2='24' y2='50' stroke='%23c8a0ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='24;22;24' dur='0.6s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='30' y1='35' x2='36' y2='50' stroke='%23c8a0ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='36;38;36' dur='0.6s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='30' y1='22' x2='42' y2='18' stroke='%23ff80c0' stroke-width='1.8' stroke-linecap='round'%3E%3Canimate attributeName='x2' values='42;55;42' dur='0.4s' repeatCount='indefinite'/%3E%3Canimate attributeName='y2' values='18;15;18' dur='0.4s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='30' y1='22' x2='20' y2='28' stroke='%23c8a0ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='20;18;20' dur='0.5s' repeatCount='indefinite'/%3E%3C/line%3E%3C!-- 火柴人B --%3E%3Ccircle cx='90' cy='12' r='5' fill='none' stroke='%2380d4ff' stroke-width='1.5'%3E%3Canimate attributeName='cy' values='12;14;12' dur='0.5s' repeatCount='indefinite'/%3E%3C/circle%3E%3Cline x1='90' y1='17' x2='90' y2='35' stroke='%2380d4ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='90;88;90' dur='0.5s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='90' y1='35' x2='84' y2='50' stroke='%2380d4ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='84;82;84' dur='0.5s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='90' y1='35' x2='96' y2='50' stroke='%2380d4ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='96;98;96' dur='0.5s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='90' y1='22' x2='78' y2='18' stroke='%23ffb060' stroke-width='1.8' stroke-linecap='round'%3E%3Canimate attributeName='x2' values='78;65;78' dur='0.4s' repeatCount='indefinite'/%3E%3Canimate attributeName='y2' values='18;20;18' dur='0.4s' repeatCount='indefinite'/%3E%3C/line%3E%3Cline x1='90' y1='22' x2='100' y2='28' stroke='%2380d4ff' stroke-width='1.5'%3E%3Canimate attributeName='x2' values='100;102;100' dur='0.5s' repeatCount='indefinite'/%3E%3C/line%3E%3C!-- 碰撞火花 --%3E%3Ccircle cx='60' cy='17' r='2' fill='%23ffdd00' opacity='0'%3E%3Canimate attributeName='opacity' values='0;1;0' dur='0.4s' repeatCount='indefinite'/%3E%3Canimate attributeName='r' values='1;4;1' dur='0.4s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='58' cy='20' r='1.5' fill='%23ff6060' opacity='0'%3E%3Canimate attributeName='opacity' values='0;0.8;0' dur='0.35s' repeatCount='indefinite' begin='0.1s'/%3E%3C/circle%3E%3Ccircle cx='63' cy='15' r='1' fill='%23ffffff' opacity='0'%3E%3Canimate attributeName='opacity' values='0;1;0' dur='0.3s' repeatCount='indefinite' begin='0.2s'/%3E%3C/circle%3E%3Ctext x='60' y='56' text-anchor='middle' fill='%23c8a0ff' font-size='6' opacity='0.7'%3E⚔ Summoning...%3C/text%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-size: contain !important;
  background-position: center !important;
}

/* ═══════════════════════════════════════════
   7. 底部附加元素 & 按钮适配
   ═══════════════════════════════════════════ */

.text-xs.font-mono.text-muted-foreground {
  color: rgba(200, 180, 255, 0.7) !important;
}

.bg-muted.rounded.flex {
  background: rgba(30, 15, 60, 0.7) !important;
  border: 1px solid rgba(150, 100, 255, 0.3) !important;
  border-radius: 10px !important;
}

.bg-muted.rounded.flex button svg.lucide {
  stroke: rgba(200, 180, 255, 0.75) !important;
}

.bg-muted.rounded.flex button:hover svg.lucide {
  stroke: #ffffff !important;
  filter: drop-shadow(0 0 4px rgba(180, 130, 255, 0.6)) !important;
}

/* 按钮始终可见 */
.group .md\:opacity-0 {
  opacity: 1 !important;
}

/* ═══════════════════════════════════════════
   8. 移动端响应式补丁
   ═══════════════════════════════════════════ */

@media (max-width: 640px) {
  .rili-markdown-renderer details {
    padding: 10px 12px !important;
    font-size: 1.1em !important;
  }

  .rili-markdown-renderer details summary {
    font-size: 1.1em !important;
  }

  .rili-markdown-renderer table {
    font-size: clamp(0.72em, 3vw, 0.9em) !important;
    display: block !important;
    overflow-x: auto !important;
  }

  .rili-markdown-renderer th,
  .rili-markdown-renderer td {
    padding: 5px 8px !important;
  }

  .group.is-user > div:first-child,
  .group.is-assistant > div:first-child {
    border-radius: 12px !important;
  }
}