@tailwind base;
@tailwind components;
@tailwind utilities;

/* ===== 昔涟主题全局样式 ===== */

@layer base {
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  html,
  body,
  #root {
    height: 100%;
    overflow: hidden;
  }

  body {
    font-family:
      'Noto Sans SC',
      -apple-system,
      BlinkMacSystemFont,
      'Segoe UI',
      Roboto,
      sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: #FFFAF5;
  }

  ::selection {
    background: rgba(244, 114, 182, 0.3);
    color: #9d174d;
  }

  /* 滚动条美化 */
  ::-webkit-scrollbar {
    width: 6px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: rgba(244, 114, 182, 0.3);
    border-radius: 3px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: rgba(244, 114, 182, 0.5);
  }
}

/* ===== 动画 ===== */
@layer utilities {
  .animate-bounce {
    animation: bounce 0.8s ease-in-out infinite;
  }

  @keyframes bounce {
    0%,
    100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-4px);
    }
  }
}

/* 动作消息淡入动画 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fadeIn {
  animation: fadeIn 0.4s ease-out;
}

/* ===== 流式渲染动画 ===== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 流式消息容器：轻微淡入效果 */
.message-streaming {
  animation: fadeInUp 0.3s ease-out;
}

/* 独立的闪烁光标工具类，可用于显式 span 元素 */
.animate-streaming-cursor {
  display: inline;
}

.animate-streaming-cursor::after {
  content: '▊';
  animation: cursorBlink 1s step-end infinite;
  color: #7c3aed;
  margin-left: 2px;
}

/* ===== 聊天背景 ===== */
.chat-background {
  position: relative;
  isolation: isolate;
  background-image: url('/images/Cyrene_ChatBackground/Vertical/2nd_Form/1.png');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

/* 半透明遮罩：避免背景色彩过于鲜艳影响阅读 */
.chat-background::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  z-index: -1;
}

/* 横屏时使用 Landscape 背景 */
@media (orientation: landscape) {
  .chat-background {
    background-image: url('/images/Cyrene_ChatBackground/Landscape/3rd_Form/1.png');
  }
}

/* 深色模式 */
@media (prefers-color-scheme: dark) {
  body {
    background: #1a1a2e;
  }

  ::selection {
    background: rgba(244, 114, 182, 0.2);
    color: #fbcfe8;
  }

  .chat-background::before {
    background: rgba(0, 0, 0, 0.4);
  }
}

/* ===== 语音识别动画 ===== */
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}

.voice-btn-active {
  animation: voice-pulse 1.5s ease-in-out infinite;
}

/* 实时识别文本淡入效果 */
@keyframes interim-fade {
  from { opacity: 0.5; }
  to { opacity: 0.9; }
}

.interim-text {
  animation: interim-fade 0.3s ease-in-out;
}

/* ===== TTS 文字转语音动画 ===== */
@keyframes tts-wave {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.85;
  }
}

.tts-playing {
  animation: tts-wave 1s ease-in-out infinite;
}

/* ===== Markdown 渲染样式 ===== */
.markdown-body h1 { font-size: 1.25rem; font-weight: 700; margin: 0.75rem 0 0.5rem; }
.markdown-body h2 { font-size: 1.1rem; font-weight: 700; margin: 0.75rem 0 0.4rem; }
.markdown-body h3 { font-size: 1rem; font-weight: 700; margin: 0.6rem 0 0.3rem; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 0.95rem; font-weight: 600; margin: 0.5rem 0 0.25rem; }
.markdown-body p { margin: 0.3rem 0; }
.markdown-body ul, .markdown-body ol { margin: 0.3rem 0; padding-left: 1.5rem; }
.markdown-body li { margin: 0.15rem 0; }
.markdown-body ul li { list-style-type: disc; }
.markdown-body ol li { list-style-type: decimal; }
.markdown-body strong { font-weight: 700; color: inherit; }
.markdown-body em { font-style: italic; }
.markdown-body a { color: #ec4899; text-decoration: underline; word-break: break-all; }
.markdown-body a:hover { color: #be185d; }
.markdown-body blockquote {
  border-left: 3px solid #f9a8d4;
  padding-left: 0.75rem;
  margin: 0.4rem 0;
  color: #9ca3af;
  font-style: italic;
}
.markdown-body hr { border: none; border-top: 1px solid #fce7f3; margin: 0.75rem 0; }
.markdown-body table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; font-size: 0.85rem; }
.markdown-body th, .markdown-body td { border: 1px solid #fce7f3; padding: 0.35rem 0.6rem; text-align: left; }
.markdown-body th { background: #fdf2f8; font-weight: 600; }
.markdown-body img { max-width: 100%; height: auto; border-radius: 0.5rem; margin: 0.3rem 0; }
.markdown-body pre { background: #1e293b; border-radius: 0.5rem; padding: 0; margin: 0.5rem 0; overflow-x: auto; }
.markdown-body pre code { display: block; padding: 0.75rem 1rem; color: #e2e8f0; font-size: 0.8rem; line-height: 1.6; white-space: pre; }
.markdown-body code.inline-code {
  background: #fce7f3;
  color: #be185d;
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  font-size: 0.85em;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}
.markdown-body > *:first-child { margin-top: 0; }
.markdown-body > *:last-child { margin-bottom: 0; }

/* 深色模式 Markdown */
@media (prefers-color-scheme: dark) {
  .markdown-body a { color: #f472b6; }
  .markdown-body a:hover { color: #fbcfe8; }
  .markdown-body blockquote { border-left-color: #9d174d; color: #9ca3af; }
  .markdown-body th, .markdown-body td { border-color: #374151; }
  .markdown-body th { background: #1f2937; }
  .markdown-body hr { border-top-color: #374151; }
  .markdown-body code.inline-code { background: #4a1942; color: #fbcfe8; }
  .markdown-body pre { background: #0f172a; }
  .markdown-body pre code { color: #e2e8f0; }
}
