/* ========== Reset & Variables ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #1e2a4a;
  --accent: #7c3aed;
  --accent-light: #a78bfa;
  --accent-glow: rgba(124, 58, 237, 0.3);
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; flex-direction: column; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.page { display: none; }
.page.active { display: flex; }

/* ========== Buttons ========== */
.btn-glow {
  padding: 14px 36px;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  border: none;
  border-radius: var(--radius);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px var(--accent-glow);
  font-family: var(--font);
}
.btn-glow:hover { transform: translateY(-2px); box-shadow: 0 6px 30px var(--accent-glow); }
.btn-glow:active { transform: translateY(0); }
.btn-glow:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-outline {
  padding: 10px 20px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: var(--font);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent-light); }

/* ========== Form ========== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.3s ease;
  font-family: var(--font);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.gender-select { display: flex; gap: 12px; }
.gender-btn {
  flex: 1;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: var(--font);
}
.gender-btn.active { border-color: var(--accent); color: var(--accent-light); background: rgba(124,58,237,0.1); }

/* ========== Auth Page ========== */
.auth-page {
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 1001;
  overflow-y: auto;
}
.auth-page.active { display: flex; }

.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
  max-width: 480px;
  width: 100%;
  position: relative;
  animation: fadeInUp 0.6s ease;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.auth-tab {
  padding: 10px 32px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.3s;
  font-family: var(--font);
}
.auth-tab.active {
  background: rgba(124,58,237,0.15);
  color: var(--accent-light);
}

.auth-form {
  width: 100%;
  animation: fadeIn 0.3s ease;
}

.auth-error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
  min-height: 20px;
}

.auth-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 0;
  animation: fadeIn 0.3s ease;
}
.auth-loading h3 { font-size: 18px; color: var(--text-primary); }

/* ========== Onboarding ========== */
.onboarding-page {
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 1000;
  overflow-y: auto;
}
.onboarding-page.active { display: flex; }

.ob-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
  max-width: 480px;
  width: 100%;
  animation: fadeInUp 0.6s ease;
}

.ob-glow-orb {
  position: absolute;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  border-radius: 50%;
  filter: blur(60px);
  animation: orbPulse 4s ease-in-out infinite;
  pointer-events: none;
}

.ob-mirror-icon { font-size: 80px; margin-bottom: 16px; display: block; animation: floatY 3s ease-in-out infinite; }
.ob-title { font-size: 48px; font-weight: 700; margin-bottom: 12px; background: linear-gradient(135deg, var(--accent-light), #c4b5fd, var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.ob-subtitle { font-size: 18px; color: var(--text-secondary); margin-bottom: 40px; }

.ob-form-title { font-size: 24px; margin-bottom: 24px; }
.ob-form-card {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  backdrop-filter: blur(10px);
}

.ob-engine-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin: 32px 0;
  max-width: 360px;
}
.ob-engine-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  opacity: 0.3;
  transition: all 0.5s ease;
}
.ob-engine-icon.lit {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}
.ob-loading-hint { color: var(--text-muted); font-size: 14px; }

.ob-traits-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin: 24px 0;
  max-height: 50vh;
  overflow-y: auto;
}
.ob-trait-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  animation: fadeInUp 0.4s ease;
}
.ob-trait-card h4 { color: var(--accent-light); margin-bottom: 8px; font-size: 15px; }
.ob-trait-card p { color: var(--text-secondary); font-size: 14px; line-height: 1.6; }

/* ========== Main Page Layout ========== */
.main-page {
  position: fixed;
  inset: 0;
  flex-direction: row;
  background: var(--bg-primary);
}
.main-page.active { display: flex; }

/* ========== Sidebar ========== */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}
.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.user-nickname { font-size: 15px; font-weight: 600; }
.user-trait-brief { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }

.sidebar-nav {
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font);
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.nav-item.active { background: rgba(124,58,237,0.12); color: var(--accent-light); }
.nav-icon { font-size: 18px; }

.sidebar-sessions {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.new-session-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.new-session-btn:hover { border-color: var(--accent); color: var(--accent-light); }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.session-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.2s;
  position: relative;
}
.session-item:hover { background: rgba(255,255,255,0.04); }
.session-item.active { background: rgba(124,58,237,0.1); }
.session-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-secondary);
}
.session-item.active .session-title { color: var(--text-primary); }
.session-delete {
  display: block;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.2s;
  opacity: 0.5;
}
.session-delete:hover { color: var(--danger); opacity: 1; }
.session-item:hover .session-delete { opacity: 0.8; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-btn, .logout-btn {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  font-family: var(--font);
}
.settings-btn:hover { border-color: var(--accent); color: var(--accent-light); }
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

.debug-toggle-btn {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  font-family: var(--font);
  opacity: 0.4;
}
.debug-toggle-btn:hover { opacity: 0.7; }
.debug-toggle-btn.active { opacity: 1; color: var(--warning); border-color: var(--warning); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ========== Content ========== */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  z-index: 10;
}
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}
.topbar-title { font-size: 16px; font-weight: 600; }

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  position: relative;
}
.view.active { display: flex; }

/* ========== Chat View ========== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 40px;
  animation: fadeIn 0.5s ease;
}
.chat-welcome-icon { font-size: 64px; margin-bottom: 16px; }
.chat-welcome h2 { font-size: 20px; margin-bottom: 8px; color: var(--text-secondary); }
.chat-welcome p { font-size: 14px; color: var(--text-muted); }

/* Messages */
.message {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 12px;
  animation: fadeInUp 0.3s ease;
}
.message.user { flex-direction: row-reverse; }

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.message.user .message-avatar { background: linear-gradient(135deg, var(--accent), #6d28d9); }
.message.assistant .message-avatar { background: var(--bg-card); }

.message-bubble {
  max-width: 75%;
  min-width: 0;
}
.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  border-radius: 16px 4px 16px 16px;
  padding: 12px 16px;
}
.message.assistant .message-bubble {
  background: var(--bg-card);
  border-radius: 4px 16px 16px 16px;
  padding: 12px 16px;
}

.message-content {
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
}
.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content code {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.message-content pre {
  background: rgba(0,0,0,0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.message-content pre code { background: none; padding: 0; }
.message-content ul, .message-content ol { padding-left: 20px; margin: 8px 0; }
.message-content h1, .message-content h2, .message-content h3 { margin: 12px 0 8px; }
.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 8px 0;
}
.message-content table { border-collapse: collapse; margin: 8px 0; width: 100%; }
.message-content th, .message-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  font-size: 13px;
}
.message-content th { background: rgba(255,255,255,0.05); }

.message-charts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.message-chart-tag {
  font-size: 11px;
  padding: 2px 8px;
  background: rgba(124,58,237,0.15);
  border-radius: 10px;
  color: var(--accent-light);
}

/* Typing cursor */
.typing-cursor::after {
  content: '▊';
  animation: blink 0.8s infinite;
  color: var(--accent-light);
}

/* Thinking indicator */
.thinking-indicator {
  max-width: 780px;
  width: 100%;
  margin: 0 auto 16px;
  display: flex;
  gap: 12px;
  animation: fadeInUp 0.3s ease;
}
.thinking-bubble {
  background: var(--bg-card);
  border-radius: 4px 16px 16px 16px;
  padding: 12px 16px;
  color: var(--accent-light);
  font-style: italic;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-light);
  animation: thinkingBounce 1.4s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ========== Reasoning Block (AI thinking) ========== */
.reasoning-block { margin-bottom: 8px; }
.reasoning-block.collapsed .reasoning-content { display: none; }
.reasoning-toggle {
  cursor: pointer; color: var(--text-muted); font-size: 0.85em;
  padding: 4px 8px; border-radius: 6px; background: rgba(255,255,255,0.03);
  user-select: none;
}
.reasoning-toggle:hover { background: rgba(255,255,255,0.06); }
.reasoning-content {
  color: var(--text-muted); font-style: italic; font-size: 0.85em;
  padding: 8px; margin-top: 4px; border-left: 2px solid var(--border);
  max-height: 300px; overflow-y: auto; white-space: pre-wrap;
}
.toggle-icon { transition: transform 0.2s; display: inline-block; }
.reasoning-block:not(.collapsed) .toggle-icon { transform: rotate(90deg); }

/* Debug button on user messages */
.debug-msg-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 4px;
  float: right;
  font-family: monospace;
  transition: all 0.2s;
}
.debug-msg-btn:hover { border-color: var(--warning); color: var(--warning); }
body.debug-mode .debug-msg-btn { display: inline-block; }

/* Debug inline button (next to send) */
.debug-inline-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.3;
  padding: 4px 6px;
  transition: all 0.2s;
  flex-shrink: 0;
}
.debug-inline-btn:hover { opacity: 0.6; }
.debug-inline-btn.active { opacity: 1; filter: drop-shadow(0 0 4px var(--warning)); }

/* Debug toast */
.debug-toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--warning);
  color: #000;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.debug-toast.show { opacity: 1; }

/* Tool result cards in chat */
.tool-card {
  background: rgba(16,185,129,0.08);
  border: 1px solid rgba(16,185,129,0.2);
  border-radius: var(--radius);
  padding: 14px;
  margin: 8px 0;
}
.tool-card.task-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.tool-card .task-check {
  width: 22px;
  height: 22px;
  border: 2px solid var(--success);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  background: transparent;
  color: transparent;
  font-size: 14px;
}
.tool-card .task-check:hover { background: rgba(16,185,129,0.15); }
.tool-card .task-check.done { background: var(--success); color: white; }
.tool-card .task-title { font-weight: 600; font-size: 14px; color: var(--success); }
.tool-card .task-desc { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.tool-card.traits-card {
  background: rgba(124,58,237,0.08);
  border-color: rgba(124,58,237,0.2);
}
.tool-card.traits-card .traits-notice {
  font-size: 14px;
  color: var(--accent-light);
}

/* Selected engines chips */
.selected-engines {
  display: flex;
  gap: 8px;
  padding: 0 20px;
  flex-wrap: wrap;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}
.selected-engines:empty { display: none; padding: 0; }

.engine-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(124,58,237,0.12);
  border: 1px solid var(--accent);
  border-radius: 16px;
  font-size: 12px;
  color: var(--accent-light);
  animation: fadeIn 0.2s;
}
.chip-remove {
  cursor: pointer;
  opacity: 0.6;
  margin-left: 2px;
  font-size: 14px;
}
.chip-remove:hover { opacity: 1; }

/* Chat input */
.chat-input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
}
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 780px;
  margin: 0 auto;
}
.engine-plus-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  border-radius: 10px;
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.engine-plus-btn:hover { border-color: var(--accent); color: var(--accent-light); }

#chatInput {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  resize: none;
  max-height: 150px;
  line-height: 1.5;
  font-family: var(--font);
  transition: border-color 0.3s;
}
#chatInput:focus { border-color: var(--accent); }

.send-btn {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ========== Engine Panel ========== */
.engine-panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  backdrop-filter: blur(2px);
}
.engine-panel-overlay.show { display: block; }

.engine-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  max-height: 70vh;
  overflow-y: auto;
}
.engine-panel.show { transform: translateY(0); }

.engine-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
}
.panel-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.engine-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.engine-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.engine-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, transparent 40%, var(--accent-glow));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s;
}
.engine-card:hover::before { opacity: 1; }
.engine-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.engine-card.selected {
  border-color: var(--accent);
  background: rgba(124,58,237,0.08);
  box-shadow: 0 0 20px var(--accent-glow);
}
.engine-card.selected::before { opacity: 1; }

.engine-card-icon { font-size: 32px; margin-bottom: 8px; }
.engine-card-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.engine-card-desc { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: none; }

/* ========== Tasks View ========== */
.tasks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
}
.tasks-header h2 { font-size: 20px; }
.task-date-picker {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  font-family: var(--font);
}

.tasks-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 80px;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  transition: all 0.3s ease;
  animation: fadeInUp 0.3s ease;
}
.task-item.completed {
  opacity: 0.5;
}
.task-item.completed .task-item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-checkbox {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  background: transparent;
  font-size: 14px;
  color: transparent;
}
.task-checkbox:hover { border-color: var(--success); }
.task-item.completed .task-checkbox {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.task-item-body { flex: 1; min-width: 0; }
.task-item-title { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.task-item-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.task-item-meta { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.task-source-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 8px;
  background: rgba(124,58,237,0.1);
  color: var(--accent-light);
}
.task-source-tag.user { background: rgba(148,163,184,0.1); color: var(--text-secondary); }
.task-recur-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 8px;
  background: rgba(245,158,11,0.12);
  color: var(--warning);
}
.task-next-info {
  font-size: 11px;
  color: var(--success);
}

.task-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  opacity: 0;
  transition: all 0.2s;
}
.task-item:hover .task-delete-btn { opacity: 1; }
.task-delete-btn:hover { color: var(--danger); }

/* Task type select in modal */
.task-type-select { display: flex; gap: 12px; }
.task-type-btn {
  flex: 1;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: var(--font);
}
.task-type-btn.active { border-color: var(--accent); color: var(--accent-light); background: rgba(124,58,237,0.1); }

.fab-btn {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 10;
}
.fab-btn:hover { transform: scale(1.1); }

/* ========== Traits View ========== */
.traits-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
}
.traits-header h2 { font-size: 20px; }

.traits-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
}

.trait-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  transition: all 0.3s ease;
  animation: fadeInUp 0.3s ease;
}
.trait-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.trait-section-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.trait-section-icon { font-size: 24px; }
.trait-section-name { font-size: 16px; font-weight: 600; }
.trait-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  transition: transform 0.3s;
}
.trait-toggle-btn.collapsed { transform: rotate(-90deg); }

.trait-section-body {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.trait-section-body.hidden { display: none; }

/* New two-column layout for challenges/strengths */
.trait-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 600px) {
  .trait-two-col { grid-template-columns: 1fr; }
}
.trait-col-challenges h5 {
  color: #f59e0b;
  font-size: 14px;
  margin-bottom: 8px;
}
.trait-col-strengths h5 {
  color: #10b981;
  font-size: 14px;
  margin-bottom: 8px;
}
.trait-col-challenges ul, .trait-col-strengths ul {
  list-style: none;
  padding: 0;
}
.trait-col-challenges li {
  padding: 6px 0;
  font-size: 13px;
  color: #fbbf24;
  line-height: 1.6;
  border-bottom: 1px solid rgba(245,158,11,0.1);
}
.trait-col-strengths li {
  padding: 6px 0;
  font-size: 13px;
  color: #6ee7b7;
  line-height: 1.6;
  border-bottom: 1px solid rgba(16,185,129,0.1);
}
.trait-col-challenges li:last-child,
.trait-col-strengths li:last-child { border-bottom: none; }

.trait-advice {
  margin-top: 12px;
  padding: 12px;
  background: rgba(124,58,237,0.06);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* Core summary area */
.traits-core-section {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}
.traits-core-section h4 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--accent-light);
}
.core-challenges, .core-strengths {
  margin-bottom: 12px;
}
.core-challenges h5 { color: #f59e0b; font-size: 14px; margin-bottom: 6px; }
.core-strengths h5 { color: #10b981; font-size: 14px; margin-bottom: 6px; }
.core-challenges ul, .core-strengths ul { list-style: disc; padding-left: 20px; }
.core-challenges li { color: #fbbf24; font-size: 13px; line-height: 1.6; }
.core-strengths li { color: #6ee7b7; font-size: 13px; line-height: 1.6; }
.overall-advice {
  padding: 12px;
  background: rgba(124,58,237,0.08);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.trait-list { list-style: none; }
.trait-list li {
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.trait-list li:last-child { border-bottom: none; }
.trait-list li strong { color: var(--accent-light); font-weight: 500; }

.trait-interpretation {
  margin-top: 12px;
  padding: 12px;
  background: rgba(124,58,237,0.06);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* Traits edit mode */
.trait-edit-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  font-family: var(--font);
  margin: 4px 0;
}
.trait-edit-input:focus { border-color: var(--accent); }
.trait-new-edit {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  font-family: var(--font);
  resize: vertical;
  line-height: 1.5;
}
.trait-new-edit:focus { border-color: var(--accent); }
.trait-add-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 12px;
  font-size: 13px;
  margin-top: 4px;
  width: 100%;
  transition: all 0.2s;
}
.trait-add-btn:hover { border-color: var(--accent); color: var(--accent); }
.trait-delete-item {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
}

.traits-summary {
  padding: 20px 24px;
  border-top: 1px solid var(--border);
}
.traits-summary h3 { font-size: 16px; margin-bottom: 8px; }
.traits-summary p { font-size: 14px; color: var(--text-secondary); line-height: 1.7; }

/* ========== Empty State ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  animation: fadeIn 0.5s ease;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-secondary); }
.empty-state p { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }

/* ========== Spinner ========== */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

/* ========== Modal ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  animation: fadeInUp 0.3s ease;
}
.modal-sm { max-width: 380px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 2px 6px;
}

.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px 20px; text-align: right; }

/* ========== Debug Modal ========== */
.modal-debug {
  max-width: 90vw;
  width: 900px;
  max-height: 90vh;
}
.modal-debug .modal-header {
  flex-wrap: wrap;
  gap: 8px;
}
.debug-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}
.debug-tab {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.debug-tab.active {
  background: rgba(124,58,237,0.15);
  color: var(--accent-light);
  border-color: var(--accent);
}
.debug-body {
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.debug-actions {
  margin-bottom: 8px;
  text-align: right;
}
.debug-json {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 12px;
  line-height: 1.6;
  color: #c9d1d9;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 60vh;
  overflow-y: auto;
}
.debug-json .json-key { color: #7ee787; }
.debug-json .json-string { color: #a5d6ff; }
.debug-json .json-number { color: #f2cc60; }
.debug-json .json-bool { color: #ff7b72; }
.debug-json .json-null { color: #8b949e; }

/* ========== Bottom Tabs (Mobile) ========== */
.bottom-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 6px 0 env(safe-area-inset-bottom, 6px);
  z-index: 50;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
  font-family: var(--font);
}
.tab-item.active { color: var(--accent-light); }
.tab-icon { font-size: 20px; }

/* ========== Animations ========== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes floatY { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes orbPulse { 0%,100% { transform: scale(1); opacity: 0.5; } 50% { transform: scale(1.2); opacity: 0.8; } }
@keyframes thinkingBounce {
  0%,80%,100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  /* --- Sidebar --- */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 80vw;
    max-width: 300px;
    transform: translateX(-100%);
    z-index: 100;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger-btn { display: block; }
  .bottom-tabs { display: flex; }
  .sidebar-nav { display: none; }

  /* --- Topbar safe area --- */
  .topbar {
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
  }

  /* --- Bottom tabs safe area --- */
  .bottom-tabs {
    padding-bottom: env(safe-area-inset-bottom, 6px);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* --- Chat input above bottom tabs --- */
  .chat-input-area {
    padding: 10px 12px calc(12px + 66px + env(safe-area-inset-bottom));
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
  }

  /* --- Chat area --- */
  .chat-area {
    padding: 12px;
    padding-bottom: 8px;
  }

  /* --- Message bubbles --- */
  .message-bubble { max-width: 85%; }
  .message { padding: 0 4px; gap: 8px; }

  /* --- Engine panel safe area --- */
  .engine-panel {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
  }
  .engine-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .engine-card-desc { display: none; }

  /* --- Tasks & Traits bottom padding for bottom-tabs --- */
  .tasks-header { padding: 16px 16px 8px; }
  .tasks-list { padding: 0 16px calc(80px + env(safe-area-inset-bottom)); }
  .traits-header { padding: 16px 16px 8px; }
  .traits-content { padding: 0 16px calc(80px + env(safe-area-inset-bottom)); }

  /* --- FAB above bottom tabs --- */
  .fab-btn {
    bottom: calc(70px + env(safe-area-inset-bottom));
    right: 16px;
  }

  /* --- Selected engines chips --- */
  .selected-engines { padding: 0 12px; }

  /* --- Modal full-screen on mobile --- */
  .modal {
    width: 95vw;
    max-width: 95vw;
    max-height: 90vh;
    border-radius: 14px;
  }
  .modal-debug { max-width: 98vw; width: 98vw; }
  .debug-tabs { flex-wrap: wrap; }

  /* --- Touch targets (min 44x44) --- */
  .nav-item { padding: 12px 14px; min-height: 44px; }
  .session-item { padding: 12px 16px; min-height: 44px; }
  .tab-item { min-height: 44px; padding: 8px 0; }
  .tab-icon { font-size: 22px; }
  .task-checkbox { width: 28px; height: 28px; font-size: 16px; }
  .settings-btn, .logout-btn { min-height: 44px; }
  .modal-close { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
  .panel-close-btn { min-width: 44px; min-height: 44px; }
  .engine-plus-btn { width: 44px; height: 44px; }
  .send-btn { width: 44px; height: 44px; }

  /* --- Font sizes --- */
  .ob-title { font-size: 36px; }
  .chat-welcome-icon { font-size: 48px; }
  .ob-mirror-icon { font-size: 64px; }

  /* --- Input font-size >= 16px to prevent iOS zoom --- */
  #chatInput { font-size: 16px; }
  .form-group input,
  .form-group select,
  .form-group textarea { font-size: 16px; }
  .trait-edit-input { font-size: 16px; }

  /* --- Auth page safe area --- */
  .auth-page {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .auth-container { padding: 24px 16px; }
}

/* ========== Small phones ========== */
@media (max-width: 480px) {
  .ob-title { font-size: 32px; }
  .ob-subtitle { font-size: 16px; margin-bottom: 28px; }
  .ob-mirror-icon { font-size: 56px; }
  .chat-welcome-icon { font-size: 40px; }
  .chat-welcome h2 { font-size: 18px; }
  .chat-welcome { padding: 24px 12px; }

  .message-content { font-size: 14px; }
  .message-bubble { max-width: 88%; }

  .engine-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .engine-card { padding: 12px 6px; }
  .engine-card-icon { font-size: 28px; margin-bottom: 4px; }
  .engine-card-name { font-size: 12px; }

  .ob-form-card { padding: 16px; }
  .auth-container { padding: 20px 12px; }

  .trait-section { padding: 14px; }
  .trait-section-name { font-size: 15px; }

  .btn-glow { padding: 12px 28px; font-size: 15px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 220px; min-width: 220px; }
  .engine-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1025px) {
  .engine-card-desc { display: block; }
}

/* ========== Tasks Sub-Tabs ========== */
.tasks-sub-tabs {
  display: flex;
  gap: 0;
  margin: 0 24px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.tasks-sub-tab {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;
  font-family: var(--font);
}
.tasks-sub-tab.active {
  background: rgba(124,58,237,0.15);
  color: var(--accent-light);
}
.tasks-sub-view { display: none; flex: 1; overflow: hidden; flex-direction: column; min-height: 0; height: 0; }
.tasks-sub-view.active { display: flex; }
.tasks-sub-view .tasks-list { flex: 1; overflow-y: auto; padding: 0 24px 80px; }

/* ========== Enhanced Task Items (Review) ========== */
.task-item { position: relative; }
.task-item.completing {
  opacity: 0.5;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.task-item .task-reflection {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: none;
}
.task-item.completed .task-reflection { display: block; }
.task-item .task-reflection-toggle {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
  padding: 4px 0;
}
.task-item .task-reflection-toggle:hover { color: var(--text-secondary); }
.task-reflection-body { display: none; margin-top: 8px; }
.task-reflection-body.show { display: block; }

.task-mood-tag {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 8px;
  background: rgba(124,58,237,0.1);
  color: var(--accent-light);
  margin-bottom: 6px;
}
.task-review-note {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-style: italic;
}

/* AI feedback bubble */
.task-ai-feedback {
  background: rgba(124,58,237,0.06);
  border: 1px solid rgba(124,58,237,0.15);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  position: relative;
}
.task-ai-feedback::before {
  content: '🪞';
  position: absolute;
  top: -10px;
  left: 10px;
  font-size: 16px;
}

/* Skeleton loading for AI thinking */
.task-ai-skeleton {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-card);
  margin-top: 8px;
}
.task-ai-skeleton .skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  margin-bottom: 8px;
}
.task-ai-skeleton .skeleton-line:last-child { width: 60%; margin-bottom: 0; }
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ========== Review Modal ========== */
.review-mood-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.review-mood-btn {
  flex: 1;
  min-width: 70px;
  padding: 10px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.3s;
  font-family: var(--font);
  text-align: center;
}
.review-mood-btn.active {
  border-color: var(--accent);
  color: var(--accent-light);
  background: rgba(124,58,237,0.12);
}

/* ========== 24h Timeline ========== */
.timeline-container {
  flex: 1;
  overflow-y: auto;
  position: relative;
  padding: 0 16px 80px;
  -webkit-overflow-scrolling: touch;
}
.timeline-grid {
  position: relative;
  min-height: calc(24 * 60px);
}
.timeline-hour-row {
  position: absolute;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: flex-start;
  border-top: 1px solid rgba(255,255,255,0.04);
}
.timeline-hour-label {
  width: 50px;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 4px;
  text-align: right;
  padding-right: 12px;
  user-select: none;
}
.timeline-hour-area {
  flex: 1;
  height: 100%;
  position: relative;
  cursor: pointer;
}
.timeline-hour-area:hover {
  background: rgba(124,58,237,0.03);
}

/* Now line */
.timeline-now-line {
  position: absolute;
  left: 50px;
  right: 16px;
  height: 2px;
  background: var(--danger);
  z-index: 10;
  pointer-events: none;
  display: none;
}
.timeline-now-line::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

/* Timeline blocks */
.timeline-block {
  position: absolute;
  left: 54px;
  right: 8px;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  z-index: 5;
  overflow: hidden;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.timeline-block:hover {
  transform: scale(1.02);
  z-index: 6;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.timeline-block-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.timeline-block-time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 2px;
}
.timeline-block.status-planned {
  background: rgba(96,165,250,0.15);
  border-color: rgba(96,165,250,0.3);
  color: #93c5fd;
}
.timeline-block.status-in_progress {
  background: rgba(16,185,129,0.15);
  border-color: rgba(16,185,129,0.3);
  color: #6ee7b7;
}
.timeline-block.status-done {
  background: rgba(148,163,184,0.1);
  border-color: rgba(148,163,184,0.2);
  color: var(--text-muted);
}
.timeline-block.status-skipped {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.2);
  color: #fca5a5;
}

/* ========== Proposal Card (Chat) ========== */
.proposal-card {
  background: rgba(124,58,237,0.08);
  border: 1px solid rgba(124,58,237,0.25);
  border-radius: var(--radius);
  padding: 16px;
  margin: 8px 0;
  animation: fadeInUp 0.3s ease;
}
.proposal-card-header {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 10px;
}
.proposal-card-summary {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 14px;
}
.proposal-card-actions {
  display: flex;
  gap: 10px;
}
.proposal-accept-btn {
  padding: 8px 18px;
  background: linear-gradient(135deg, var(--success), #059669);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.proposal-accept-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 10px rgba(16,185,129,0.3); }
.proposal-accept-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.proposal-negotiate-btn {
  padding: 8px 18px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.proposal-negotiate-btn:hover { border-color: var(--accent); color: var(--accent-light); }
.proposal-card.accepted {
  opacity: 0.7;
  border-color: var(--success);
}
.proposal-card.accepted .proposal-card-actions { display: none; }
.proposal-accepted-label {
  color: var(--success);
  font-size: 14px;
  font-weight: 500;
  display: none;
}
.proposal-card.accepted .proposal-accepted-label { display: block; }

/* ========== Timeline Mobile ========== */
@media (max-width: 768px) {
  .tasks-sub-tabs { margin: 0 16px 8px; }
  .timeline-container { padding: 0 8px 80px; }
  .timeline-hour-label { width: 40px; font-size: 11px; padding-right: 8px; }
  .timeline-block { left: 44px; right: 4px; font-size: 12px; padding: 4px 8px; }
  .review-mood-btn { min-width: 60px; font-size: 12px; padding: 8px 6px; }
}

/* ========== Transit (当下) View ========== */
.transit-header {
  padding: 20px 24px 12px;
}
.transit-header h2 { font-size: 20px; }
.transit-date {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.transit-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
}
.transit-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  background-image: linear-gradient(135deg, rgba(124,58,237,0.03) 0%, rgba(16,185,129,0.03) 100%);
}
.transit-section {
  margin-bottom: 20px;
}
.transit-section:last-child { margin-bottom: 0; }
.transit-section h3 {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

/* Pillar cards (三列) */
.transit-pillars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.transit-pillar-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.transit-pillar-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}
.transit-pillar-card.wuxing-wood::before { background: #22c55e; }
.transit-pillar-card.wuxing-fire::before { background: #ef4444; }
.transit-pillar-card.wuxing-earth::before { background: #f59e0b; }
.transit-pillar-card.wuxing-metal::before { background: #e2e8f0; }
.transit-pillar-card.wuxing-water::before { background: #3b82f6; }
.pillar-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.pillar-ganzhi {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.pillar-nayin {
  font-size: 12px;
  color: var(--text-secondary);
}

/* JieQi progress */
.jieqi-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 15px;
}
.jieqi-current { color: var(--accent-light); font-weight: 600; }
.jieqi-arrow { color: var(--text-muted); }
.jieqi-next { color: var(--text-secondary); }
.jieqi-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}
.jieqi-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 3px;
  transition: width 0.5s ease;
}
.jieqi-days {
  font-size: 12px;
  color: var(--text-muted);
}

/* Auspicious tags */
.ausp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.ausp-label {
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 6px;
  flex-shrink: 0;
}
.ausp-good { background: rgba(16,185,129,0.15); color: var(--success); }
.ausp-bad { background: rgba(239,68,68,0.15); color: var(--danger); }
.ausp-tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
}
.ausp-tag-good { background: rgba(16,185,129,0.08); color: #6ee7b7; }
.ausp-tag-bad { background: rgba(239,68,68,0.08); color: #fca5a5; }

/* Positions */
.position-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  font-size: 14px;
}
.position-item:last-child { border-bottom: none; }
.position-label { color: var(--text-secondary); }
.position-value { color: var(--text-primary); font-weight: 500; }

/* Natal relation */
.natal-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.transit-advice-btn {
  width: 100%;
  margin-top: 8px;
}

/* ========== 八字排盘表格 ========== */
.bazi-daymaster-info {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}
.bazi-table {
  display: grid;
  gap: 8px;
}
.bazi-table-4 { grid-template-columns: repeat(4, 1fr); }
.bazi-table-3 { grid-template-columns: repeat(3, 1fr); }
.bazi-pillar {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.bazi-pillar-label {
  font-size: 11px;
  color: var(--text-muted);
}
.bazi-shishen {
  font-size: 11px;
  color: var(--text-secondary);
  min-height: 16px;
}
.bazi-daymaster-label {
  color: var(--accent-light);
  font-weight: 600;
}
.bazi-stem {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}
.bazi-stem.bazi-daymaster {
  text-shadow: 0 0 8px var(--accent-glow);
  position: relative;
}
.bazi-stem.bazi-daymaster::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}
.bazi-branch {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}
.bazi-hidegan {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  min-height: 20px;
  margin-top: 2px;
}
.bazi-hidegan-item {
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.bazi-hidegan-ss {
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
}
.bazi-nayin {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 五行着色 */
.bazi-wx-木 { color: #22c55e; }
.bazi-wx-火 { color: #ef4444; }
.bazi-wx-土 { color: #f59e0b; }
.bazi-wx-金 { color: #e2e8f0; }
.bazi-wx-水 { color: #3b82f6; }

/* 移动端响应式 */
@media (max-width: 380px) {
  .bazi-table-4 { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .bazi-pillar { padding: 8px 4px; }
  .bazi-stem, .bazi-branch { font-size: 20px; }
  .bazi-hidegan-item { font-size: 11px; }
  .bazi-hidegan-ss { font-size: 8px; }
}

/* ========== Intention Cards (日课) ========== */
.intention-cards {
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 16px;
}
.intention-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all 0.4s ease;
  position: relative;
  overflow: hidden;
}
.intention-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius);
  padding: 1px;
  background: linear-gradient(135deg, transparent 60%, rgba(124,58,237,0.2));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.intention-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.intention-icon { font-size: 24px; }
.intention-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.intention-minimal {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.intention-duration {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.intention-last-touch { min-height: 0; }

.btn-touch {
  padding: 8px 20px;
  background: rgba(124,58,237,0.1);
  border: 1px solid rgba(124,58,237,0.3);
  border-radius: 8px;
  color: var(--accent-light);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.btn-touch:hover {
  background: rgba(124,58,237,0.2);
  border-color: var(--accent);
}

/* AI echo after touch */
.touch-ai-echo {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  padding: 8px 0;
  font-style: italic;
}
.touch-ai-echo.sensing {
  animation: pulse-sensing 1.5s ease-in-out infinite;
  color: var(--text-muted);
}
.touch-ai-echo.fade-in {
  animation: fadeIn 0.8s ease;
}
@keyframes pulse-sensing {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.touch-actions {
  display: flex;
  gap: 12px;
}
.btn-touch-done, .btn-touch-chat {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-touch-done {
  background: var(--bg-tertiary, #2a2a3e);
  color: var(--text-secondary);
}
.btn-touch-done:hover { opacity: 0.8; }
.btn-touch-chat {
  background: var(--accent, #7c3aed);
  color: #fff;
}
.btn-touch-chat:hover { opacity: 0.85; }

/* Card touched state (今日已触碰) */
.intention-card.touched {
  opacity: 0.55;
  position: relative;
}
.intention-card.touched .intention-title {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}
.intention-done-mark {
  color: var(--accent, #7c3aed);
  font-size: 18px;
  margin-left: auto;
}
.intention-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: 4px;
  opacity: 0.4;
  transition: opacity 0.2s, color 0.2s;
}
.intention-delete-btn:hover {
  opacity: 1;
  color: #ef4444;
}
.intention-card.touched .btn-touch {
  opacity: 0.6;
  font-size: 12px;
}

/* Card sink animation */
.intention-card.sinking {
  transform: scale(0.85);
  opacity: 0;
  transition: all 0.6s ease;
}
.intention-card.sinking::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 0; height: 0;
  border-radius: 50%;
  background: rgba(124,58,237,0.15);
  transform: translate(-50%, -50%);
  animation: rippleSink 0.6s ease forwards;
}
@keyframes rippleSink {
  to { width: 300px; height: 300px; opacity: 0; }
}

/* ========== Touch Panel (觉察记录) ========== */
.touch-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.4s ease;
  backdrop-filter: blur(2px);
}
.touch-panel-overlay.show { opacity: 1; }

.touch-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px 24px calc(24px + env(safe-area-inset-bottom));
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(26,26,46,0.95);
}
.touch-panel.show {
  transform: translateY(0);
}
.touch-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.touch-panel-header h3 {
  font-size: 18px;
  color: var(--text-primary);
}
.touch-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Dimension sliders */
.touch-dimensions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dimension-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.dim-label-left, .dim-label-right {
  font-size: 13px;
  color: var(--text-muted);
  width: 40px;
  flex-shrink: 0;
}
.dim-label-left { text-align: right; }
.dim-label-right { text-align: left; }

/* Custom slider */
.dim-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
}
.dim-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: transform 0.2s;
}
.dim-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.dim-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.touch-prompt {
  font-size: 15px;
  color: var(--accent-light);
  font-style: italic;
  text-align: center;
}
.touch-note {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  resize: none;
  font-family: var(--font);
  transition: border-color 0.3s;
}
.touch-note:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.touch-deep {
  color: var(--text-muted);
  font-size: 14px;
}
.touch-deep summary {
  cursor: pointer;
  padding: 6px 0;
  user-select: none;
}
.touch-deep summary:hover { color: var(--text-secondary); }
.touch-long-note {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  resize: none;
  font-family: var(--font);
  margin-top: 8px;
  transition: border-color 0.3s;
}
.touch-long-note:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* ========== Wuwei (无为期) ========== */
.wuwei-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 60px 24px;
  gap: 32px;
}
.wuwei-breath-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.1), rgba(255,255,255,0.03));
  animation: breathe 6s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 0.8; }
}
.wuwei-text {
  font-size: 18px;
  color: var(--text-muted);
  letter-spacing: 4px;
}
.wuwei-end-btn {
  margin-top: 20px;
  opacity: 0.5;
  transition: opacity 0.3s;
}
.wuwei-end-btn:hover { opacity: 1; }

.tasks-wuwei-btn {
  font-size: 12px;
  padding: 6px 12px;
}
.tasks-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== Transit & Intention Mobile ========== */
@media (max-width: 768px) {
  .transit-header { padding: 16px 16px 8px; }
  .transit-content { padding: 0 16px calc(80px + env(safe-area-inset-bottom)); }
  .transit-pillar-card { padding: 10px 6px; }
  .pillar-ganzhi { font-size: 18px; }
  .intention-cards { padding: 0 16px; padding-bottom: 16px; }
  .touch-panel { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
}
