/* ===== 全局变量 ===== */
:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: rgba(25, 25, 60, 0.85);
  --bg-card-hover: rgba(35, 35, 80, 0.9);
  --text-primary: #e8e0f0;
  --text-secondary: #a89cc0;
  --text-muted: #6b5f85;
  --accent: #7c5cbf;
  --accent-light: #9d7ce8;
  --accent-glow: rgba(124, 92, 191, 0.3);
  --gold: #d4a853;
  --gold-glow: rgba(212, 168, 83, 0.2);
  --danger: #c0392b;
  --success: #27ae60;
  --border: rgba(124, 92, 191, 0.2);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== 背景粒子画布 ===== */
#bg-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ===== 主容器 ===== */
.main-container {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 20px 60px;
  min-height: 100vh;
}

/* ===== 顶栏 ===== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  margin-bottom: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo h1 {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.moon-icon { font-size: 28px; }

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s;
}
.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--accent-light);
  border-color: var(--accent);
}

/* ===== 输入区域 ===== */
.input-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.input-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.input-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}
.sparkle { font-size: 20px; }

textarea {
  width: 100%;
  background: rgba(10, 10, 30, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.7;
  resize: vertical;
  min-height: 140px;
  transition: border-color 0.3s;
  font-family: inherit;
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea::placeholder { color: var(--text-muted); }

.input-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  font-family: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5a3d8a);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px var(--accent-glow);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-large {
  padding: 14px 40px;
  font-size: 16px;
  border-radius: 50px;
}
.btn-icon { font-size: 18px; }

/* ===== 加载动画 ===== */
.loading {
  text-align: center;
  padding: 60px 20px;
}
.moon-loader {
  width: 50px; height: 50px;
  margin: 0 auto 20px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent-light);
  animation: spin 1.2s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p {
  color: var(--text-secondary);
  font-size: 16px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ===== 结果卡片 ===== */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  animation: fadeInUp 0.5s ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent-light);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-icon { font-size: 16px; }

.summary-card p {
  font-size: 17px;
  line-height: 1.7;
  color: var(--text-primary);
}

/* 氛围标签 */
.mood-badge {
  display: inline-block;
  margin-top: 12px;
  padding: 6px 16px;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent-glow), var(--gold-glow));
  border: 1px solid var(--accent);
  color: var(--accent-light);
}

/* ===== 元素标签 ===== */
.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.element-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 500;
  background: rgba(124, 92, 191, 0.15);
  border: 1px solid rgba(124, 92, 191, 0.3);
  color: var(--accent-light);
  cursor: pointer;
  transition: all 0.25s;
}
.element-tag:hover {
  background: rgba(124, 92, 191, 0.3);
  transform: translateY(-1px);
}
.element-tag .tag-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
}

/* 元素详情列表 */
.elements-list {
  display: grid;
  gap: 12px;
}

.element-item {
  background: rgba(10, 10, 30, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: border-color 0.3s;
}
.element-item:hover {
  border-color: var(--accent);
}

.element-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.element-item-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--gold);
}

.element-item-symbolism {
  font-size: 13px;
  color: var(--accent-light);
  background: rgba(124, 92, 191, 0.15);
  padding: 2px 10px;
  border-radius: 50px;
}

.element-item-interpretation {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== 心理学 / 传统 / 建议 ===== */
#psych-card p, #trad-card p, #suggest-card p {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-secondary);
}

.suggestion-card {
  border-color: rgba(212, 168, 83, 0.3);
  background: linear-gradient(135deg, var(--bg-card), rgba(42, 36, 20, 0.6));
}

/* ===== 幸运信息 ===== */
.lucky-card {
  background: linear-gradient(135deg, var(--bg-card), rgba(25, 20, 40, 0.9));
  border-color: rgba(212, 168, 83, 0.3);
}

.lucky-items {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.lucky-item {
  flex: 1;
  min-width: 120px;
  text-align: center;
  padding: 16px;
  background: rgba(10, 10, 30, 0.5);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.lucky-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lucky-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
}

/* ===== 梦境配图 ===== */
.image-card { text-align: center; }

#dream-image-container {
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.dream-image {
  max-width: 100%;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

/* ===== 结果操作按钮 ===== */
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 8px;
}

/* ===== 历史侧边栏 ===== */
.sidebar {
  position: fixed;
  top: 0; right: -360px;
  width: 360px; height: 100%;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 90;
  transition: right 0.35s ease;
  display: flex;
  flex-direction: column;
}
.sidebar.active { right: 0; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 18px;
  color: var(--text-primary);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.history-item {
  padding: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  margin-bottom: 8px;
}
.history-item:hover {
  background: var(--bg-card);
  border-color: var(--border);
}

.history-date {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.history-text {
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}

.history-mood {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 50px;
  background: rgba(124, 92, 191, 0.15);
  color: var(--accent-light);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
.toast.info { background: var(--accent); color: #fff; }

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  .main-container { padding: 16px 12px 40px; }
  .input-card { padding: 20px; }
  .result-card { padding: 18px; }
  .lucky-items { flex-direction: column; }
  .sidebar { width: 85%; right: -85%; }
  .btn-large { padding: 12px 30px; font-size: 15px; }
}
