:root {
  --bg: #0b1120;
  --bg-elevated: #161f36;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.1);
  --purple: #8b5cf6;
  --purple-light: #a78bfa;
  --cyan: #06b6d4;
  --cyan-light: #22d3ee;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #8291ab;
  --radius: 20px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.bg-glow {
  position: fixed;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  z-index: 0;
  pointer-events: none;
}
.bg-glow-1 {
  background: radial-gradient(circle, var(--purple), transparent 70%);
  top: -20vmax;
  left: -20vmax;
  animation: drift1 22s ease-in-out infinite alternate;
}
.bg-glow-2 {
  background: radial-gradient(circle, var(--cyan), transparent 70%);
  bottom: -25vmax;
  right: -20vmax;
  animation: drift2 26s ease-in-out infinite alternate;
}
@keyframes drift1 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(6vmax, 4vmax) scale(1.15); }
}
@keyframes drift2 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(-5vmax, -6vmax) scale(1.1); }
}

#app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  backdrop-filter: blur(20px);
  background: rgba(11, 17, 32, 0.6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 13px;
  background: linear-gradient(90deg, var(--purple-light), var(--cyan-light));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px 2px var(--cyan);
}
.topbar-status {
  font-size: 10px;
  color: #34d399;
  text-shadow: 0 0 8px #34d399;
}

main#views {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  animation: fadeIn 0.28s ease;
}
.view.hidden { display: none; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.view-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.glass-card {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  padding: 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  margin-bottom: 14px;
  white-space: pre-wrap;
  line-height: 1.5;
  color: var(--text-secondary);
}

.glass-btn, .glass-btn-sm {
  border: 1px solid rgba(139, 92, 246, 0.4);
  background: rgba(139, 92, 246, 0.15);
  color: var(--text-primary);
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.glass-btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.glass-btn:hover, .glass-btn-sm:hover {
  background: rgba(139, 92, 246, 0.28);
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.35);
}
.glass-btn:active, .glass-btn-sm:active { transform: scale(0.97); }

/* ---------- Chat ---------- */
#view-chat { padding: 0; }
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  max-width: 280px;
  font-size: 14px;
}
.chat-empty-orb {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--cyan-light), var(--purple));
  box-shadow: 0 0 40px rgba(139, 92, 246, 0.5);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.08); opacity: 1; }
}

.msg {
  max-width: 82%;
  padding: 12px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  border: 1px solid var(--border);
  animation: msgIn 0.25s ease;
  white-space: pre-wrap;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.msg.user {
  align-self: flex-end;
  background: rgba(139, 92, 246, 0.25);
  border-color: rgba(139, 92, 246, 0.35);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(6, 182, 212, 0.15);
  border-color: rgba(6, 182, 212, 0.3);
  border-bottom-left-radius: 4px;
}
.msg.thinking { color: var(--text-muted); font-style: italic; }

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(11, 17, 32, 0.7);
  backdrop-filter: blur(20px);
}
.chat-input-bar input {
  flex: 1;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  padding: 12px 18px;
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s ease;
}
.chat-input-bar input:focus { border-color: var(--purple); }
.send-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  color: white;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}
.send-btn:hover { box-shadow: 0 0 20px rgba(139, 92, 246, 0.5); }
.send-btn:active { transform: scale(0.92); }

.mic-btn {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
  overflow: visible;
}
.mic-orb {
  position: absolute;
  left: 50%;
  bottom: 62px;
  width: 46px;
  height: 46px;
  margin-left: -23px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--cyan-light), var(--purple));
  box-shadow: 0 0 30px rgba(139, 92, 246, 0.6);
  pointer-events: none;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
  animation: micOrbBreathe 1.8s ease-in-out infinite;
}
.mic-orb.hidden { display: none; }
@keyframes micOrbBreathe {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}
.mic-btn:hover { background: rgba(255, 255, 255, 0.12); }
.mic-btn:active { transform: scale(0.92); }
.mic-btn.recording {
  background: rgba(139, 92, 246, 0.2);
  border-color: rgba(139, 92, 246, 0.4);
}

/* ---------- Stats ---------- */
.stats-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
}
.stat-chip {
  flex-shrink: 0;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.stat-chip b { color: var(--cyan-light); font-size: 14px; }

/* ---------- Distribution chart ---------- */
.distribution-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
}
.distribution-card.hidden { display: none; }
.distribution-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  font-size: 12.5px;
}
.legend-item { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Segmented control ---------- */
.segmented {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}
.segmented-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.segmented-btn.active {
  background: rgba(139, 92, 246, 0.25);
  color: var(--text-primary);
}
.memory-tab.hidden { display: none; }

.graph-wrap {
  position: relative;
  width: 100%;
  height: 320px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
  overflow: hidden;
  margin-bottom: 12px;
}
.graph-wrap canvas { width: 100%; height: 100%; display: block; }

.timeline-item {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 13.5px;
  color: var(--text-secondary);
  border-left: 3px solid var(--purple);
}

/* ---------- Memory / Search ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  padding: 10px 14px;
  outline: none;
}
.result-item {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 13.5px;
  color: var(--text-secondary);
}
.result-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }

/* ---------- Projects ---------- */
.project-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 10px;
}
.project-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 8px currentColor; }
.project-info { flex: 1; }
.project-name { font-weight: 600; font-size: 14.5px; }
.project-desc { font-size: 12.5px; color: var(--text-muted); }
.project-count { font-size: 11px; color: var(--text-muted); }

/* ---------- Profile ---------- */
.profile-form { display: flex; flex-direction: column; gap: 12px; }
.profile-form label { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.profile-form input, .profile-form textarea {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: vertical;
}
.profile-form input:focus, .profile-form textarea:focus { border-color: var(--purple); }
.save-hint { font-size: 12px; color: var(--cyan-light); min-height: 16px; }

.danger-zone { display: flex; flex-direction: column; gap: 10px; }
.danger-zone h3 { margin: 0 0 4px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.danger-btn {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
}
.danger-btn:hover { background: rgba(248, 113, 113, 0.22); box-shadow: 0 0 16px rgba(248, 113, 113, 0.3); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  display: flex;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: rgba(11, 17, 32, 0.75);
  backdrop-filter: blur(20px);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10.5px;
  padding: 8px 2px;
  border-radius: 12px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.nav-icon { font-size: 18px; }
.nav-btn.active {
  color: var(--text-primary);
  background: rgba(139, 92, 246, 0.15);
}
.nav-btn.active .nav-icon { filter: drop-shadow(0 0 6px var(--purple-light)); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 4px; }
