/* ====== 高级纸质风样式 ====== */
@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:wght@400;600;700&family=Inter:wght@300;400;500;600&display=swap');

:root {
  --paper-primary: #fefcf8;      /* 米白主背景 */
  --paper-secondary: #f8f4ed;    /* 浅米黄 */
  --paper-accent: #e8e0d0;       /* 奶茶色 */
  --ink-primary: #3c2e26;        /* 深棕墨黑 */
  --ink-secondary: #6d5d4b;      /* 灰棕 */
  --ink-tertiary: #a69b8c;       /* 浅棕灰 */
  --gold-accent: #b8860b;        /* 暗金色 */
  --shadow: rgba(60, 46, 38, 0.08);
}

/* 纸张纹理基础 */
.paper-texture {
  background-image: 
    url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
}

/* 墨迹装饰 */
.ink-blot {
  position: absolute;
  background: radial-gradient(ellipse at center, rgba(60,46,38,0.05) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(135deg, var(--paper-secondary) 0%, var(--paper-accent) 100%);
  color: var(--ink-primary);
  line-height: 1.7;
  min-height: 100vh;
  padding: 20px;
}

/* 主容器 - 模拟厚重纸张 */
#app {
  max-width: 840px;
  margin: 0 auto;
  background: var(--paper-primary);
  border-radius: 4px; /* 纸张轻微卷边 */
  padding: 0;
  box-shadow: 
    0 10px 40px var(--shadow),
    inset 0 0 0 1px rgba(0,0,0,0.03); /* 纸边压痕 */
  position: relative;
  overflow: hidden;
  
  /* 纸张厚度模拟 */
  &::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: 
      repeating-linear-gradient(
        0deg,
        transparent,
        transparent 24px,
        rgba(60,46,38,0.015) 24px,
        rgba(60,46,38,0.015) 25px
      ); /* 横格纸纹理 */
    pointer-events: none;
    z-index: 0;
  }
}

/* 墨迹装饰元素 */
#app::after {
  content: '';
  position: absolute;
  bottom: -80px;
  right: -80px;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(184,134,11,0.05) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

/* ====== 头部样式 ====== */
.header {
  text-align: center;
  padding: 60px 40px 50px;
  background: linear-gradient(to bottom, var(--paper-secondary), transparent);
  position: relative;
  z-index: 1;
  
  h1 {
    font-family: 'Crimson Text', serif;
    font-size: 42px;
    font-weight: 700;
    color: var(--ink-primary);
    margin-bottom: 8px;
    letter-spacing: 1px;
    position: relative;
    display: inline-block;
    
    /* 标题下划线墨迹 */
    &::after {
      content: '';
      position: absolute;
      bottom: -8px;
      left: 20%;
      width: 60%;
      height: 2px;
      background: linear-gradient(to right, transparent, var(--gold-accent), transparent);
    }
  }
  
  .subtitle {
    font-family: 'Crimson Text', serif;
    font-style: italic;
    color: var(--ink-secondary);
    font-size: 18px;
    margin-top: 20px;
    font-weight: 400;
  }
}

/* ====== 内容区块 ====== */
.input-section,
.uid-section,
.cards-section,
.ai-interpretation,
.chat-section {
  margin: 30px 40px;
  padding: 30px;
  background: var(--paper-primary);
  border: 1px solid rgba(60,46,38,0.08);
  border-radius: 2px;
  box-shadow: 0 4px 12px var(--shadow);
  position: relative;
  z-index: 1;
}

/* 区块标题 */
.section-title {
  font-family: 'Crimson Text', serif;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink-primary);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--paper-accent);
  position: relative;
  
  &::before {
    content: '❧';
    position: absolute;
    right: 0;
    bottom: -10px;
    color: var(--gold-accent);
    font-size: 20px;
    background: var(--paper-primary);
    padding: 0 10px;
  }
}

/* ====== 表单元素 ====== */
textarea,
input[type="text"],
.chat-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--paper-accent);
  border-radius: 2px;
  background: rgba(255,255,255,0.7);
  font-size: 16px;
  transition: all 0.3s ease;
  font-family: inherit;
  color: var(--ink-primary);
  
  &::placeholder {
    color: var(--ink-tertiary);
    font-style: italic;
  }
  
  &:focus {
    outline: none;
    border-color: var(--gold-accent);
    box-shadow: 0 0 0 2px rgba(184,134,11,0.1);
    background: #fff;
  }
}

/* 下拉选择 */
select {
  flex: 0;
  padding: 14px 40px 14px 16px;
  border: 1px solid var(--paper-accent);
  border-radius: 2px;
  background: rgba(255,255,255,0.7);
  font-size: 16px;
  color: var(--ink-primary);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23b8860b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  
  &:hover {
    border-color: var(--gold-accent);
  }
}

/* ====== 按钮系统 ====== */
button {
  padding: 14px 28px;
  border-radius: 2px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: var(--ink-primary);
  color: var(--paper-primary);
  border: none;
  letter-spacing: 0.5px;
  
  &:hover {
    background: var(--gold-accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(60,46,38,0.15);
  }
  
  &:active {
    transform: translateY(0);
  }
  
  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }
}

.btn-secondary {
  background: transparent;
  color: var(--ink-secondary);
  border: 1px solid var(--paper-accent);
  
  &:hover {
    background: var(--paper-secondary);
    border-color: var(--gold-accent);
    color: var(--ink-primary);
  }
}

/* 加载动画 - 墨迹扩散 */
/* 在.loading类中添加 */

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--paper-accent);
  border-top: 2px solid var(--gold-accent);
  border-radius: 50%;
  animation: spin 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ====== 塔罗牌样式 ====== */
.cards {
  display: flex;
  gap: 20px;
  margin: 20px 0;
}

.card {
  flex: 1;
  padding: 24px 20px;
  background: var(--paper-primary);
  border: 1px solid var(--paper-accent);
  border-radius: 2px;
  text-align: center;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  box-shadow: 0 4px 8px var(--shadow);
  
  /* 牌面装饰边框 */
  &::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 1px solid rgba(184,134,11,0.2);
    pointer-events: none;
  }
  
  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(60,46,38,0.15);
    border-color: var(--gold-accent);
    
    &::before {
      border-color: rgba(184,134,11,0.4);
    }
  }
  
  strong {
    font-family: 'Crimson Text', serif;
    font-size: 20px;
    font-weight: 600;
    color: var(--ink-primary);
    display: block;
    margin-bottom: 8px;
  }
  
  div {
    font-size: 14px;
    color: var(--ink-secondary);
    font-weight: 500;
    margin: 4px 0;
    
    &:last-child {
      color: var(--gold-accent);
      font-family: 'Crimson Text', serif;
      font-style: italic;
    }
  }
}

/* ====== AI解析区域 ====== */
.ai-interpretation {
  .result {
    margin-top: 20px;
    padding: 24px;
    background: rgba(255,255,255,0.7);
    border: 1px solid var(--paper-accent);
    border-radius: 2px;
    font-size: 16px;
    line-height: 1.8;
    color: var(--ink-primary);
    font-family: 'Crimson Text', serif;
    position: relative;
    
    /* 引用符号装饰 */
    &::before {
      content: '"';
      position: absolute;
      top: -10px;
      left: 10px;
      font-size: 60px;
      color: var(--gold-accent);
      opacity: 0.15;
      font-family: serif;
    }
  }
}

/* ====== 对话区域 ====== */
/* ====== 聊天区域头部样式 ====== */

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--paper-accent);
  background: linear-gradient(to bottom, var(--paper-secondary), var(--paper-primary));
  position: relative;
  flex-shrink: 0;
}

.chat-title {
  font-family: 'Crimson Text', serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink-primary);
  letter-spacing: 0.5px;
  position: relative;
  padding-left: 28px;
}

/* 标题左侧装饰符号 */
.chat-title::before {
  content: '❦';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gold-accent);
  font-size: 18px;
}

/* 操作按钮组 */
.chat-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* 全屏模式下的头部特殊样式 */
.chat-section.fullscreen .chat-header {
  padding: 24px 30px;
  background: var(--paper-primary);
  box-shadow: 0 2px 8px var(--shadow);
  border-bottom: 1px solid var(--paper-accent);
}

/* 移动端适配 */
@media (max-width: 768px) {
  .chat-header {
    padding: 16px 20px;
  }
  
  .chat-title {
    font-size: 18px;
    padding-left: 24px;
  }
  
  .chat-actions {
    gap: 6px;
  }
}
.chat-section {
  .chat-messages {
    height: 300px;
    overflow-y: auto;
    padding: 20px;
    background: rgba(255,255,255,0.5);
    border: 1px solid var(--paper-accent);
    border-radius: 2px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  
  .message {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 18px;
    line-height: 1.6;
    position: relative;
    animation: fadeIn 0.3s ease-out;
    
    &.message-user {
      align-self: flex-end;
      background: var(--ink-primary);
      color: var(--paper-primary);
      border-bottom-right-radius: 4px;
      
      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        right: -6px;
        width: 0;
        height: 0;
        border-left: 6px solid var(--ink-primary);
        border-top: 6px solid transparent;
      }
    }
    
    &.message-ai {
      align-self: flex-start;
      background: var(--paper-secondary);
      color: var(--ink-primary);
      border-bottom-left-radius: 4px;
      
      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: -6px;
        width: 0;
        height: 0;
        border-right: 6px solid var(--paper-secondary);
        border-top: 6px solid transparent;
      }
    }
  }
}

.chat-input-container {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

/* ====== 会员区域 ====== */
.uid-section {
  background: linear-gradient(to bottom, var(--paper-secondary), var(--paper-primary));
  border: 1px solid var(--gold-accent);
  position: relative;
  
  &::before {
    content: '✦';
    position: absolute;
    top: -12px;
    left: 20px;
    font-size: 24px;
    color: var(--gold-accent);
    background: var(--paper-primary);
    padding: 0 10px;
  }
  
  .section-title {
    color: var(--gold-accent);
    
    &::before {
      background: var(--paper-secondary);
    }
  }
}

/* ====== 弹窗 ====== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(60,46,38,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(4px);
  
  > div {
    background: var(--paper-primary);
    padding: 40px;
    border-radius: 2px;
    max-width: 90%;
    max-height: 85vh;
    overflow: auto;
    width: 500px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    border: 1px solid var(--paper-accent);
    position: relative;
    
    /* 装订线装饰 */
    &::before {
      content: '';
      position: absolute;
      top: 20px;
      bottom: 20px;
      left: 20px;
      width: 2px;
      background: linear-gradient(to bottom, transparent, var(--gold-accent), transparent);
    }
  }
  
  h3 {
    font-family: 'Crimson Text', serif;
    font-size: 28px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--paper-accent);
    color: var(--ink-primary);
  }
  
  p {
    margin: 16px 0;
    line-height: 1.8;
  }
  
  strong {
    color: var(--gold-accent);
    font-weight: 600;
  }
  
  button {
    background: var(--ink-primary);
    color: var(--paper-primary);
    border: none;
    margin-top: 20px;
    font-family: 'Crimson Text', serif;
    font-size: 17px;
    letter-spacing: 0.5px;
    
    &:hover {
      background: var(--gold-accent);
    }
  }
}

/* ====== 历史记录 ====== */
.history {
  margin: 30px 40px 40px;
  padding: 30px;
  background: var(--paper-primary);
  border: 1px solid var(--paper-accent);
  
  .history-items {
    max-height: 280px;
    overflow-y: auto;
    
    &::-webkit-scrollbar {
      width: 6px;
    }
    
    &::-webkit-scrollbar-thumb {
      background: var(--paper-accent);
      border-radius: 3px;
    }
  }
  
  div {
    padding: 16px;
    border-bottom: 1px solid var(--paper-accent);
    cursor: pointer;
    transition: all 0.3s ease;
    
    &:hover {
      background: var(--paper-secondary);
      transform: translateX(4px);
    }
  }
}

/* ====== 响应式 ====== */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  
  #app {
    margin: 0;
    border-radius: 0;
  }
  
  .header {
    padding: 40px 20px;
    
    h1 {
      font-size: 32px;
    }
  }
  
  .input-section,
  .uid-section,
  .cards-section,
  .ai-interpretation,
  .chat-section,
  .history {
    margin: 20px;
    padding: 20px;
  }
}

/* ====== 全屏模式 ====== */
.chat-section.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  border-radius: 0;
  z-index: 1001;
  background: var(--paper-primary);
  border: none;
  
  .chat-messages {
    flex: 1;
    height: auto !important;
  }
}
.uid-section .controls {
  display: flex;
  flex-wrap: nowrap; /* 禁止换行 */
  gap: 12px;
  align-items: stretch; /* 元素高度一致 */
}

.uid-section input[type="text"] {
  flex: 1; /* 输入框占满剩余空间 */
  min-width: 0; /* 防止flex item溢出 */
}

.uid-section button {
  align-self: stretch; /* 按钮高度与输入框一致 */
}

.uid-section .btn-secondary {
  background: transparent;
  color: var(--ink-secondary);
  border: 1px solid var(--paper-accent);
  transition: all 0.3s ease;
}

.uid-section .btn-secondary:hover {
  background: rgba(184, 134, 11, 0.1);
  border-color: var(--gold-accent);
  color: var(--gold-accent);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

/* 动画 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
/* ====== Footer 样式优化 ====== */
footer {
  margin: 60px 40px 30px;
  padding: 30px 0 20px;
  border-top: 1px solid var(--paper-accent);
  text-align: center !important; /* 强制居中 */
  position: relative;
  z-index: 1;
}

footer p {
  font-family: 'Crimson Text', serif;
  font-size: 15px;
  color: var(--ink-secondary);
  line-height: 1.8;
  margin: 8px 0;
  font-style: italic;
  letter-spacing: 0.5px;
}

/* 添加装饰分隔线 */
footer::before {
  content: '❦';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--gold-accent);
  font-size: 24px;
  background: var(--paper-primary);
  padding: 0 15px;
  z-index: 2;
}

/* ====== 全屏按钮互斥显示修复 ====== */

/* 基础状态：只显示"全屏"按钮 */
.chat-actions .fullscreen-btn {
  display: inline-flex !important; /* 使用inline-flex更精确 */
}

.chat-actions .exit-fullscreen-btn {
  display: none !important;
}

/* 全屏状态：只显示"退出全屏"按钮 */
.chat-section.fullscreen .chat-actions .fullscreen-btn {
  display: none !important;
}

.chat-section.fullscreen .chat-actions .exit-fullscreen-btn {
  display: inline-flex !important;
}
/* ====== 全屏模式滚动修复 ====== */

/* 全屏时禁用页面滚动 */
body.chat-fullscreen {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* 全屏聊天布局重构 */
.chat-section.fullscreen {
  display: flex !important;
  flex-direction: column !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  background: var(--paper-primary) !important;
  margin: 0 !important;
  padding: 20px !important;
  z-index: 1001;
  border-radius: 0 !important;
}

/* 聊天消息区域 - 可滚动主体 */
.chat-section.fullscreen .chat-messages {
  flex: 1 1 auto !important; /* 占据所有可用空间 */
  height: auto !important;
  overflow-y: auto !important; /* 启用独立滚动 */
  -webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
  padding: 20px !important;
  margin-bottom: 15px !important;
}

/* 输入框容器 - 固定在底部 */
.chat-section.fullscreen .chat-input-container {
  flex: 0 0 auto !important; /* 不伸缩，固定高度 */
  margin-top: 0 !important;
  padding-top: 15px;
  border-top: 1px solid var(--paper-accent);
}

/* 防止输入框被键盘遮挡 */
.chat-section.fullscreen .chat-input {
  max-height: 120px;
  overflow-y: auto;
}

/* 移动端全屏优化 */
@media (max-width: 768px) {
  .chat-section.fullscreen {
    padding: 15px !important;
  }
  
  .chat-section.fullscreen .chat-messages {
    padding: 15px !important;
    max-height: calc(100vh - 140px) !important; /* 预留输入框+安全区高度 */
  }
  
  .chat-section.fullscreen .chat-input-container {
    padding: 10px 0 0;
  }
}