*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 400;
  background: #050505;
  color: #fff;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* Particle canvas */
#particle-bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* Screens */
.screen { display: none; position: relative; z-index: 1; min-height: 100vh; }
.screen.active { display: flex; }

/* Auth */
.auth-screen { align-items: center; justify-content: center; padding: 20px; }
.auth-container {
  position: relative;
  z-index: 1;
  width: 100%; max-width: 420px;
  background: rgba(10,10,10,0.85);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 48px 40px;
  backdrop-filter: blur(40px);
  text-align: center;
}
.auth-logo svg { width: 80px; height: 80px; margin-bottom: 24px; }
.auth-title {
  font-size: 14px; font-weight: 700;
  letter-spacing: 0.35em; text-transform: uppercase;
  color: rgba(255,255,255,0.7); margin-bottom: 8px;
}
.auth-sub { font-size: 12px; color: rgba(255,255,255,0.25); margin-bottom: 36px; letter-spacing: 0.05em; }
.auth-step { display: none; flex-direction: column; gap: 12px; }
.auth-step.active { display: flex; }
.auth-input {
  width: 100%; padding: 14px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  color: #fff; font-size: 14px;
  font-family: inherit; outline: none;
  transition: border-color 0.2s;
}
.auth-input:focus { border-color: rgba(78, 205, 196, 0.4); }
.auth-input::placeholder { color: rgba(255,255,255,0.2); }
.auth-btn {
  width: 100%; padding: 14px;
  background: #4ECDC4; color: #050505;
  border: none; border-radius: 10px;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.2em; text-transform: uppercase;
  cursor: pointer; font-family: inherit;
  transition: opacity 0.2s;
}
.auth-btn:hover { opacity: 0.9; }
.auth-btn:disabled { opacity: 0.4; cursor: default; }
.auth-error { color: #e07a5f; font-size: 12px; margin-top: 12px; min-height: 18px; }
.auth-info { color: rgba(255,255,255,0.35); font-size: 12px; margin-top: 8px; }
.auth-toggle { margin-top: 20px; font-size: 11px; color: rgba(255,255,255,0.2); }
.auth-toggle a { color: #4ECDC4; cursor: pointer; text-decoration: none; }

/* App layout */
.app-screen { display: none; height: 100vh; }
.app-screen.active { display: flex; }
#app-shell { display: flex; height: 100vh; position: relative; z-index: 1; }
#sidebar {
  width: 220px; min-width: 220px;
  background: rgba(8,8,8,0.95);
  border-right: 1px solid rgba(255,255,255,0.04);
  display: flex; flex-direction: column;
  padding: 20px 12px;
  overflow-y: auto;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease;
}
#sidebar.collapsed {
  width: 56px; min-width: 56px;
  padding: 20px 8px;
  overflow-x: hidden;
}
#sidebar.collapsed .sidebar-label { display: none; }
#sidebar.collapsed .nav-btn { justify-content: center; padding: 10px; }
#sidebar.collapsed .sidebar-brand { justify-content: center; }
#sidebar.collapsed .sidebar-brand svg { margin: 0; }
.sidebar-collapse-btn { margin-bottom: 8px; }
#sidebar::-webkit-scrollbar { width: 3px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 2px; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 8px; margin-bottom: 24px; }
.sidebar-brand svg { width: 32px; height: 32px; }
.sidebar-brand-text { font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.5); letter-spacing: 0.08em; }
.sidebar-section-label {
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: rgba(255,255,255,0.12);
  padding: 16px 8px 8px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  background: none; border: none;
  color: rgba(255,255,255,0.35);
  font-size: 12px; font-family: inherit;
  cursor: pointer; border-radius: 8px;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}
.nav-btn:hover { background: rgba(255,255,255,0.03); color: rgba(255,255,255,0.6); }
.nav-btn.active { background: rgba(78, 205, 196, 0.06); color: #4ECDC4; }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-bottom { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.04); }
.brain-status { font-size: 10px; color: rgba(255,255,255,0.25); padding: 8px; }
.brain-label {
  display: inline-block;
  padding: 2px 6px; border-radius: 3px;
  font-size: 8px; font-weight: 700;
  letter-spacing: 0.15em;
  background: rgba(78, 205, 196, 0.1); color: #4ECDC4;
}
.brain-label.brain-active {
  background: rgba(78, 205, 196, 0.2);
  box-shadow: 0 0 8px rgba(78, 205, 196, 0.3), 0 0 16px rgba(78, 205, 196, 0.1);
}
.user-info {
  display: block; width: 100%;
  padding: 8px; margin-top: 8px;
  background: none; border: none;
  color: rgba(255,255,255,0.2);
  font-size: 10px; font-family: inherit;
  cursor: pointer; text-align: left;
  border-radius: 6px;
}
.user-info:hover { color: rgba(255,255,255,0.5); }

/* Main content */
#main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.panel {
  display: none; flex-direction: column; flex: 1; overflow: hidden;
  animation: panel-fade-in 0.2s ease;
}
.panel.active { display: flex; }
@keyframes panel-fade-in { from { opacity: 0; } to { opacity: 1; } }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.panel-title { font-size: 11px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(255,255,255,0.3); }
.panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* Chat */
#messages { flex: 1; overflow-y: auto; padding: 24px; scroll-behavior: smooth; }
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 2px; }
.msg { padding: 16px 0; max-width: 720px; }
.msg-header { display: flex; align-items: center; gap: 8px; }
.msg-role {
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  margin-bottom: 8px;
}
.msg-role.user { color: rgba(255,255,255,0.25); }
.msg-role.polarity { color: rgba(78, 205, 196, 0.5); }
.msg-body { font-size: 14px; line-height: 1.7; color: rgba(255,255,255,0.75); }
.msg-body p { margin-bottom: 8px; }
.msg-body pre {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.04);
  padding: 14px; overflow-x: auto;
  margin: 8px 0; font-size: 12px;
  font-family: "SF Mono", "Fira Code", monospace;
  line-height: 1.5; border-radius: 8px;
}
.msg-body code {
  background: rgba(255,255,255,0.06);
  padding: 2px 6px; font-size: 12px;
  font-family: "SF Mono", "Fira Code", monospace;
  border-radius: 4px;
}
.msg-body pre code { background: none; padding: 0; }
.msg-tools { font-size: 10px; color: rgba(78, 205, 196, 0.3); margin-top: 6px; }
.speak-btn {
  background: none; border: none;
  color: rgba(255,255,255,0.2);
  cursor: pointer; padding: 2px;
  transition: color 0.15s;
  display: flex; align-items: center;
}
.speak-btn:hover { color: rgba(78, 205, 196, 0.6); }
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; gap: 16px;
  color: rgba(255,255,255,0.1); font-size: 13px;
}
.empty-state svg { width: 48px; height: 48px; }
#chat-input-area {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 16px 24px 24px;
  border-top: 1px solid rgba(255,255,255,0.04);
}
#chat-input-area textarea {
  flex: 1; padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  color: #fff; font-size: 14px;
  font-family: inherit; outline: none;
  resize: none; min-height: 20px; max-height: 200px;
  overflow-y: auto;
}
#chat-input-area textarea:focus { border-color: rgba(78, 205, 196, 0.3); }
#chat-input-area textarea::placeholder { color: rgba(255,255,255,0.15); }
.mic-btn, .send-btn {
  padding: 12px;
  background: rgba(78, 205, 196, 0.1);
  border: 1px solid rgba(78, 205, 196, 0.15);
  border-radius: 10px;
  color: #4ECDC4;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.mic-btn:hover, .send-btn:hover { background: rgba(78, 205, 196, 0.18); }
.mic-btn.listening { background: rgba(255,80,80,0.2); border-color: rgba(255,80,80,0.4); color: #ff5050; animation: pulse-mic 1s ease-in-out infinite; }
.mic-btn.processing { background: rgba(78,205,196,0.2); border-color: rgba(78,205,196,0.4); animation: pulse-mic 0.5s ease-in-out infinite; }
@keyframes pulse-mic { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Onboarding progress */
.onboarding-progress {
  padding: 8px 24px 4px;
  border-top: 1px solid rgba(255,255,255,0.04);
}
.onboarding-bar {
  display: flex; align-items: center; gap: 10px;
}
.onboarding-label {
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(78,205,196,0.5); white-space: nowrap;
}
.onboarding-pct {
  font-size: 9px; font-weight: 600;
  color: rgba(255,255,255,0.25); min-width: 28px; text-align: right;
}
.onboarding-hint {
  font-size: 10px; color: rgba(255,255,255,0.2);
  padding: 4px 0 2px; font-style: italic;
}

.char-count {
  font-size: 10px;
  color: rgba(255,255,255,0.2);
  align-self: flex-end;
  padding-bottom: 4px;
  white-space: nowrap;
}
.char-count.near-limit { color: rgba(255,160,122,0.7); }
#chat-input-area { position: relative; }

/* Shared UI */
.panel-error {
  padding: 12px 16px;
  background: rgba(255,80,80,0.08);
  border: 1px solid rgba(255,80,80,0.15);
  border-radius: 8px;
  color: rgba(255,120,120,0.9);
  font-size: 12px; margin-bottom: 16px;
}
.panel-loading {
  display: flex; align-items: center; justify-content: center;
  padding: 40px; gap: 12px;
  color: rgba(255,255,255,0.2);
  font-size: 11px; letter-spacing: 0.15em;
  text-transform: uppercase;
}
.panel-loading::before {
  content: ''; width: 14px; height: 14px;
  border: 2px solid rgba(78,205,196,0.15);
  border-top-color: rgba(78,205,196,0.6);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); }  }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 6px;
}
.skeleton-card { height: 100px; margin-bottom: 12px; }
.skeleton-line { height: 12px; margin-bottom: 8px; }
.skeleton-line.short { width: 60%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.panel-empty {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  padding: 60px 20px; gap: 8px;
  color: rgba(255,255,255,0.12); font-size: 12px;
}
.panel-btn {
  background: rgba(78, 205, 196, 0.1);
  border: 1px solid rgba(78, 205, 196, 0.2);
  color: #4ECDC4;
  padding: 8px 16px;
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  cursor: pointer; font-family: inherit;
  border-radius: 6px;
  transition: background 0.2s;
}
.panel-btn:hover { background: rgba(78, 205, 196, 0.18); }
.panel-btn:disabled { opacity: 0.4; cursor: default; }
.panel-search {
  width: 100%; padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  color: #fff; font-size: 13px;
  font-family: inherit; outline: none;
  margin-bottom: 16px;
}
.panel-search:focus { border-color: rgba(78, 205, 196, 0.3); }
.panel-search::placeholder { color: rgba(255,255,255,0.2); }

/* Loading skeleton */
.skeleton {
  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: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 6px;
}
.skeleton-line { height: 12px; margin-bottom: 8px; }
.skeleton-line:last-child { width: 60%; }
.skeleton-card { height: 100px; border-radius: 10px; }
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.card {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 16px; cursor: default;
  transition: border-color 0.2s;
}
.card:hover { border-color: rgba(255,255,255,0.12); }
.card-title { font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.85); margin-bottom: 6px; }
.card-meta { font-size: 10px; color: rgba(255,255,255,0.3); letter-spacing: 0.05em; margin-bottom: 8px; }
.card-desc { font-size: 12px; color: rgba(255,255,255,0.45); line-height: 1.5; }
.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 4px;
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
}
.badge-teal { background: rgba(78,205,196,0.12); color: #4ECDC4; }
.badge-coral { background: rgba(255,160,122,0.12); color: #FFA07A; }
.badge-purple { background: rgba(187,143,206,0.12); color: #BB8FCE; }
.badge-dim { background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.3); }
.progress-bar { width: 100%; height: 4px; background: rgba(255,255,255,0.05); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; border-radius: 2px; transition: width 0.3s ease; }

/* Tree */
.tree-node { margin-bottom: 8px; }
.tree-toggle {
  background: none; border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer; font-family: inherit;
  font-size: 12px; padding: 8px 12px;
  width: 100%; text-align: left;
  border-radius: 6px;
  transition: background 0.15s;
}
.tree-toggle:hover { background: rgba(255,255,255,0.03); }
.tree-children { padding-left: 20px; margin-top: 4px; border-left: 1px solid rgba(255,255,255,0.04); }

/* Incognito */
.incognito-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.06);
  padding: 6px 12px;
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: rgba(255,255,255,0.2);
  cursor: pointer; font-family: inherit;
  border-radius: 4px;
  transition: border-color 0.2s, color 0.2s;
}
.incognito-btn.active { border-color: rgba(78, 205, 196, 0.3); color: #4ECDC4; }

/* Nexus canvas */
.nexus-canvas { width: 100%; height: 400px; border-radius: 10px; background: rgba(0,0,0,0.3); margin-bottom: 16px; }

/* Typing indicator */
.typing-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: rgba(78,205,196,0.4); margin: 0 2px; animation: typing 1.4s ease-in-out infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

/* How It Works */
.sidebar-help {
  margin-top: 16px; padding: 0 12px;
  border-top: 1px solid rgba(255,255,255,0.04);
  padding-top: 12px;
}
.help-content {
  padding: 8px 0;
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.help-intro {
  font-size: 11px; color: rgba(255,255,255,0.4);
  line-height: 1.6; margin-bottom: 12px;
  font-style: italic;
}
.help-item { margin-bottom: 10px; }
.help-item strong {
  font-size: 11px; color: rgba(78, 205, 196, 0.7);
  display: block; margin-bottom: 2px;
}
.help-item p {
  font-size: 10px; color: rgba(255,255,255,0.25);
  line-height: 1.5;
}

/* Changelog */
.sidebar-changelog {
  margin-top: 8px; padding: 0 12px;
  border-top: 1px solid rgba(255,255,255,0.04);
  padding-top: 12px;
}
.changelog-toggle {
  display: flex; align-items: center; gap: 8px;
  width: 100%; background: none; border: none;
  color: rgba(255,255,255,0.3); cursor: pointer;
  font-size: 10px; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; font-family: inherit;
  padding: 4px 0;
}
.changelog-toggle:hover { color: rgba(255,255,255,0.5); }
.changelog-arrow { margin-left: auto; font-size: 10px; }
.changelog-list {
  max-height: 280px; overflow-y: auto;
  margin-top: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.changelog-entry { margin-bottom: 2px; }
.changelog-version {
  display: block; width: 100%;
  background: none; border: none;
  color: rgba(255,255,255,0.35);
  font-size: 11px; font-family: inherit;
  cursor: pointer; text-align: left;
  padding: 4px 0;
  transition: color 0.15s;
}
.changelog-version:hover { color: rgba(255,255,255,0.6); }
.changelog-highlights {
  list-style: none; padding: 0; margin: 0 0 8px 0;
}
.changelog-highlights li {
  font-size: 10px; color: rgba(255,255,255,0.2);
  padding: 2px 0 2px 12px;
  position: relative; line-height: 1.5;
}
.changelog-highlights li::before {
  content: "·";
  position: absolute; left: 2px;
  color: rgba(78, 205, 196, 0.4);
  font-weight: bold;
}

/* Settings */
.settings-group {
  margin-bottom: 20px;
}
.settings-label {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  display: block; margin-bottom: 8px;
}
.settings-value {
  color: #4ECDC4; font-weight: 700;
}
.settings-input {
  width: 100%; padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  color: #fff; font-size: 13px;
  font-family: inherit; outline: none;
  transition: border-color 0.2s;
}
.settings-input:focus { border-color: rgba(78, 205, 196, 0.3); }
.settings-range {
  width: 100%; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: rgba(255,255,255,0.08);
  border-radius: 2px; outline: none;
}
.settings-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px;
  background: #4ECDC4; border-radius: 50%;
  cursor: pointer;
}
.settings-range::-moz-range-thumb {
  width: 16px; height: 16px;
  background: #4ECDC4; border-radius: 50%;
  cursor: pointer; border: none;
}
.settings-toggle {
  padding: 6px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  color: rgba(255,255,255,0.3);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer; font-family: inherit;
  transition: all 0.2s;
}
.settings-toggle.active {
  background: rgba(78, 205, 196, 0.1);
  border-color: rgba(78, 205, 196, 0.3);
  color: #4ECDC4;
}

/* Walkthrough */
.walkthrough-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: walkthrough-in 0.3s ease;
}
@keyframes walkthrough-in { from { opacity: 0; } to { opacity: 1; } }
.walkthrough-card {
  width: 100%; max-width: 440px;
  background: rgba(15,15,15,0.95);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
}
.walkthrough-step-counter {
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: rgba(78, 205, 196, 0.5);
  margin-bottom: 20px;
}
.walkthrough-title {
  font-size: 18px; font-weight: 600;
  color: rgba(255,255,255,0.9);
  margin-bottom: 12px;
}
.walkthrough-body {
  font-size: 13px; color: rgba(255,255,255,0.45);
  line-height: 1.7; margin-bottom: 32px;
}
.walkthrough-actions {
  display: flex; gap: 12px; justify-content: center;
}
.walkthrough-skip {
  padding: 10px 20px;
  background: none; border: none;
  color: rgba(255,255,255,0.2);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer; font-family: inherit;
}
.walkthrough-skip:hover { color: rgba(255,255,255,0.4); }
.walkthrough-next {
  padding: 10px 24px;
  background: #4ECDC4; color: #050505;
  border: none; border-radius: 8px;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  cursor: pointer; font-family: inherit;
  transition: opacity 0.2s;
}
.walkthrough-next:hover { opacity: 0.9; }

/* Mobile */
.mobile-header { display: none; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.hamburger { background: none; border: none; color: rgba(255,255,255,0.4); cursor: pointer; padding: 4px; display: flex; align-items: center; }
.mobile-title { font-size: 11px; font-weight: 600; letter-spacing: 0.15em; text-transform: uppercase; color: rgba(255,255,255,0.3); }
.mobile-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 99; }
.mobile-overlay.active { display: block; }

@media (max-width: 768px) {
  /* Safe area insets for notched phones */
  body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* App shell fills viewport properly */
  #app-shell { height: 100dvh; }
  .screen { min-height: 100dvh; }

  /* Sidebar: slide-in drawer with smooth easing */
  #sidebar {
    position: fixed; left: -280px; top: 0; bottom: 0;
    width: 260px; min-width: 260px;
    z-index: 100;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: calc(20px + env(safe-area-inset-top));
    backdrop-filter: blur(20px);
    background: rgba(5,5,5,0.97);
  }
  #sidebar.open { left: 0; }
  #sidebar.collapsed { width: 260px; min-width: 260px; padding: 20px 12px; }
  #sidebar.collapsed .sidebar-label { display: block; }
  #sidebar.collapsed .nav-btn { justify-content: flex-start; padding: 10px 12px; }
  .sidebar-collapse-btn { display: none; }

  /* Mobile header */
  .mobile-header {
    display: flex;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  /* Chat area */
  #messages { padding: 12px 16px; }
  .msg { padding: 12px 0; }
  .msg-body { font-size: 14px; line-height: 1.65; }
  .msg-body pre { font-size: 11px; padding: 10px; overflow-x: auto; max-width: calc(100vw - 64px); }

  /* Chat input: sticky bottom with safe area */
  #chat-input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 6px;
  }
  #chat-input-area textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 14px;
    border-radius: 20px;
  }
  .mic-btn, .send-btn {
    padding: 10px;
    border-radius: 50%;
    min-width: 42px; min-height: 42px;
  }

  /* Onboarding compact */
  .onboarding-progress { padding: 6px 12px 2px; }
  .onboarding-label { font-size: 8px; }
  .onboarding-hint { font-size: 9px; }

  /* Cards single column */
  .card-grid { grid-template-columns: 1fr; }
  .card { padding: 14px; }

  /* Panel header compact */
  .panel-header { padding: 12px 16px; }
  .panel-body { padding: 16px; }

  /* Auth: full-bleed on small screens */
  .auth-screen { padding: 16px; }
  .auth-container {
    padding: 36px 24px;
    border-radius: 12px;
    max-width: 100%;
  }
  .auth-logo svg { width: 64px; height: 64px; margin-bottom: 16px; }
  .auth-title { font-size: 12px; }

  /* Walkthrough fits mobile */
  .walkthrough-card { padding: 28px 20px; }
  .walkthrough-title { font-size: 16px; }
  .walkthrough-body { font-size: 12px; margin-bottom: 24px; }

  /* Touch-friendly tap targets (Apple HIG: 44pt minimum) */
  .nav-btn { min-height: 44px; padding: 12px; }
  .panel-btn { min-height: 44px; padding: 12px 16px; }
  .auth-btn { min-height: 48px; font-size: 12px; }
  .auth-input { min-height: 48px; padding: 14px 16px; font-size: 16px; }
  .hamburger { min-width: 44px; min-height: 44px; justify-content: center; }
  .tree-toggle { min-height: 44px; padding: 12px; }
  .speak-btn { min-width: 32px; min-height: 32px; padding: 6px; }

  /* Touch feedback: active states (hover doesn't exist on touch) */
  .nav-btn:active { background: rgba(255,255,255,0.06); }
  .card:active { border-color: rgba(78,205,196,0.2); background: rgba(255,255,255,0.03); }
  .panel-btn:active { background: rgba(78,205,196,0.25); }
  .auth-btn:active { opacity: 0.8; }
  .mic-btn:active, .send-btn:active { background: rgba(78,205,196,0.3); }

  /* Nexus: globe/graph takes less vertical space on mobile */
  .nexus-overlay { padding-top: 45%; }
  .nexus-view-toggle { gap: 6px; }
  .view-arrow { min-width: 36px; min-height: 36px; }

  /* Settings inputs full width */
  .settings-input { font-size: 16px; }

  /* Char count repositioned */
  .char-count { font-size: 9px; }
}

/* Small phones (iPhone SE, etc) */
@media (max-width: 375px) {
  .auth-container { padding: 28px 20px; }
  .walkthrough-card { padding: 24px 16px; }
  #chat-input-area textarea { font-size: 16px; padding: 8px 12px; }
  .msg-body { font-size: 13px; }
  .panel-header { padding: 10px 12px; }
}

@media (min-width: 769px) { .mobile-header { display: none; } .mobile-overlay { display: none !important; } }

/* Nexus view toggle */
.nexus-view-toggle { display: flex; align-items: center; gap: 8px; }
.view-arrow {
  background: none; border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.5); font-size: 16px; cursor: pointer;
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.view-arrow:hover:not(:disabled) { background: rgba(78,205,196,0.1); color: #4ECDC4; }
.view-arrow:disabled { opacity: 0.2; cursor: default; }
.view-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.15em;
  text-transform: uppercase; color: rgba(255,255,255,0.4);
  min-width: 40px; text-align: center;
}

/* Digest tabs */
.digest-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
}
.digest-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(255,255,255,0.4);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}
.digest-tab:hover {
  color: rgba(255,255,255,0.55);
}
.digest-tab.active {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
  font-weight: 600;
}

/* Filter legend */
.nexus-filters {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.nexus-filter-btn {
  display: flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.6); font-size: 10px; padding: 3px 8px;
  border-radius: 12px; cursor: pointer; transition: opacity 0.15s, background 0.15s;
}
.nexus-filter-btn:hover { background: rgba(255,255,255,0.06); }
.nexus-filter-btn.inactive { opacity: 0.25; }

/* Globe / Graph */
.nexus-body { position: relative; }
.globe-container {
  position: absolute; inset: 0; z-index: 0;
  overflow: hidden; background: transparent;
  opacity: 0; transition: opacity 1.5s ease;
}
.globe-container.loaded { opacity: 1; }
.globe-container canvas {
  width: 100%; height: 100%; display: block;
  cursor: grab;
}
.globe-container canvas:active { cursor: grabbing; }
.nexus-overlay {
  position: relative; z-index: 1;
  pointer-events: none;
  padding-top: 60%;  /* push content below globe center */
}
.nexus-overlay > * { pointer-events: auto; }
.globe-tooltip {
  position: absolute; pointer-events: none;
  background: rgba(5,5,5,0.92); border: 1px solid rgba(78,205,196,0.25);
  border-radius: 6px; padding: 8px 12px;
  font-size: 11px; color: rgba(255,255,255,0.85);
  line-height: 1.5; white-space: nowrap;
  opacity: 0; transition: opacity 0.15s; z-index: 10;
}
.globe-tooltip.visible { opacity: 1; }
.globe-tooltip .tooltip-name { font-weight: 600; }
.globe-tooltip .tooltip-cat { color: rgba(255,255,255,0.4); font-size: 10px; margin-top: 2px; }

/* Accessibility */
.skip-link {
  position: absolute; top: -40px; left: 0; z-index: 999;
  background: #4ECDC4; color: #050505; padding: 8px 16px;
  font-size: 12px; font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 0; }
*:focus-visible {
  outline: 2px solid rgba(78,205,196,0.6);
  outline-offset: 2px;
}
button:focus:not(:focus-visible), input:focus:not(:focus-visible), textarea:focus:not(:focus-visible) {
  outline: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
