/* ========== 全局 ========== */
:root {
  --bg: #0a0a1a;
  --surface: #12122a;
  --surface-light: #1a1a3e;
  --border: #2a2a4a;
  --text: #e2e8f0;
  --text-muted: #8888aa;
  --accent: #7c5cbf;
  --accent-glow: #9b7fd4;
  --gold: #d4a853;
  --gold-glow: #f0d078;
  --danger: #e0556a;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

/* ========== 星空背景 ========== */
.stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.star {
  position: absolute;
  background: white;
  border-radius: 50%;
  animation: twinkle ease-in-out infinite alternate;
}
@keyframes twinkle {
  0% { opacity: 0.3; transform: scale(1); }
  100% { opacity: 1; transform: scale(1.5); }
}

/* ========== 主容器 ========== */
#app {
  position: relative;
  z-index: 1;
  max-width: 700px;
  margin: 0 auto;
  padding: 24px 20px 100px;
}

/* ========== 头部 ========== */
.header { text-align: center; padding: 40px 0 32px; }
.logo { font-size: 28px; font-weight: 700; letter-spacing: 2px; color: var(--text); }
.subtitle { color: var(--text-muted); font-size: 14px; margin-top: 4px; display: block; }

/* ========== 页面切换 ========== */
.page { display: none; animation: fadeIn 0.4s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ========== 梦境输入 ========== */
.dream-input-area { margin-top: 8px; }
#dream-input {
  width: 100%;
  padding: 20px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  line-height: 1.8;
  resize: vertical;
  min-height: 140px;
  font-family: inherit;
  transition: var(--transition);
}
#dream-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 30px rgba(124, 92, 191, 0.15); }
#dream-input::placeholder { color: var(--text-muted); opacity: 0.6; }
#dream-input.shake { animation: shake 0.5s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ========== 按钮 ========== */
button { cursor: pointer; font-family: inherit; border: none; transition: var(--transition); }
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 16px; padding: 14px 24px;
  background: linear-gradient(135deg, var(--accent), #6c4db8);
  color: white; font-size: 16px; font-weight: 600;
  border-radius: var(--radius); letter-spacing: 1px;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 30px rgba(124, 92, 191, 0.35); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px;
  background: var(--surface-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.btn-secondary:hover { border-color: var(--accent); background: #222244; }

.btn-outline {
  padding: 10px 20px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.btn-outline:hover { color: var(--text); border-color: var(--accent); }

.btn-danger {
  padding: 10px 20px;
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.btn-danger:hover { border-color: var(--danger); background: rgba(224, 85, 106, 0.08); }

.btn-sm { padding: 6px 14px; font-size: 12px; }

/* ========== 加载动画 ========== */
.loading-area { padding: 60px 0; text-align: center; }
.dream-loader { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.dream-loader p { color: var(--text-muted); font-size: 14px; }
.moon {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 40px var(--gold-glow), 0 0 80px rgba(240, 208, 120, 0.3);
  animation: moonPulse 2s ease-in-out infinite;
}
@keyframes moonPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 40px var(--gold-glow), 0 0 80px rgba(240, 208, 120, 0.3); }
  50% { transform: scale(1.15); box-shadow: 0 0 60px var(--gold-glow), 0 0 120px rgba(240, 208, 120, 0.5); }
}

/* ========== 结果区域 ========== */
.result-area { margin-top: 24px; }
.hidden { display: none !important; }

.result-header {
  text-align: center;
  margin-bottom: 28px;
  padding: 24px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.result-header h2 { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.dream-date { color: var(--text-muted); font-size: 13px; }

.section-label { font-size: 14px; color: var(--gold); margin: 24px 0 12px; font-weight: 500; letter-spacing: 1px; }

/* ========== 符号卡片 ========== */
.symbols-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.symbol-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: var(--transition);
}
.symbol-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.symbol-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; color: var(--accent-glow); }
.symbol-meaning { font-size: 12px; color: var(--gold); margin-bottom: 8px; }
.symbol-detail { font-size: 13px; color: var(--text-muted); line-height: 1.7; }

/* ========== 叙事卡片 ========== */
.narrative-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  font-size: 15px;
  line-height: 2;
  color: #d0d0e8;
}

/* ========== 插画区 ========== */
.illustration-area { margin-top: 8px; }
.illustration-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.illustration-container img { width: 100%; display: block; }
.image-placeholder { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.image-placeholder span { display: block; margin-bottom: 12px; font-size: 14px; }
.image-loading { text-align: center; padding: 40px 20px; }
.image-loading span { display: block; color: var(--text-muted); font-size: 14px; margin-top: 12px; }
.spinner {
  width: 36px; height: 36px;
  margin: 0 auto;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ========== 底部导航 ========== */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: center; gap: 4px;
  padding: 10px 16px 24px;
  background: linear-gradient(transparent, var(--bg) 30%, var(--bg));
}
.tab {
  padding: 10px 20px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50px;
  font-size: 13px;
  font-weight: 500;
}
.tab.active { background: var(--surface-light); color: var(--text); border-color: var(--accent); }
.tab:hover { border-color: var(--accent); }

/* ========== 日记页 ========== */
.diary-layout { display: grid; gap: 20px; grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) { .diary-layout { grid-template-columns: 1fr; } }

.diary-calendar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.calendar-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
  font-weight: 600; font-size: 14px;
}
.cal-nav {
  background: none; border: none; color: var(--text-muted);
  font-size: 14px; padding: 4px 8px; border-radius: 6px;
}
.cal-nav:hover { color: var(--text); background: var(--surface-light); }

.calendar-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: 11px; color: var(--text-muted);
  margin-bottom: 8px; padding: 4px 0;
}
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px;
  text-align: center;
}
.cal-day {
  padding: 8px 4px; font-size: 13px; border-radius: 8px;
  cursor: pointer; transition: var(--transition);
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
}
.cal-day:hover { background: var(--surface-light); }
.cal-day.has-dream { font-weight: 700; color: var(--gold); position: relative; }
.cal-day.has-dream::after {
  content: '';
  position: absolute; bottom: 3px; width: 4px; height: 4px;
  border-radius: 50%; background: var(--accent);
}
.cal-day.today { border: 1px solid var(--accent); }
.cal-day.selected { background: var(--accent); color: white; }
.cal-day.selected.has-dream::after { background: white; }

.diary-list { max-height: 400px; overflow-y: auto; }
.diary-entry {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition);
}
.diary-entry:hover { border-color: var(--accent); }
.diary-entry-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.diary-entry-title { font-weight: 600; font-size: 14px; }
.diary-badge { font-size: 14px; }
.diary-entry-preview { font-size: 12px; color: var(--text-muted); }
.empty-hint { color: var(--text-muted); font-size: 14px; text-align: center; padding: 40px 0; }

/* ========== 画廊页 ========== */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.gallery-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: var(--transition);
}
.gallery-item:hover { transform: scale(1.03); border-color: var(--accent); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(transparent 50%, rgba(0,0,0,0.8));
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 12px;
  opacity: 0; transition: var(--transition);
}
.gallery-item:hover .gallery-item-overlay { opacity: 1; }
.gallery-item-overlay span { font-weight: 600; font-size: 13px; }
.gallery-item-overlay small { font-size: 11px; color: #aaa; }

/* ========== 设置页 ========== */
.settings-form { max-width: 480px; margin: 0 auto; }
.setting-group { margin-bottom: 20px; }
.setting-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.setting-group input[type="text"],
.setting-group input[type="password"],
.setting-group select {
  width: 100%; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
  font-family: inherit; transition: var(--transition);
}
.setting-group input:focus, .setting-group select:focus {
  outline: none; border-color: var(--accent);
}
.hint { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.model-select-row { display: flex; gap: 8px; }
.model-select { flex: 1; }
.settings-msg { text-align: center; margin-top: 12px; font-size: 13px; min-height: 20px; }

/* ========== 弹窗 ========== */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.modal-content {
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  max-width: 560px; width: 100%; max-height: 85vh; overflow-y: auto;
  animation: fadeIn 0.3s ease;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { color: var(--text); background: var(--surface-light); }

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
