:root {
  --bg: #ffffff;
  --bg-2: #f9f9f9;
  --panel: #ffffff;
  --panel-2: #f4f4f4;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --muted: #6e6e6e;
  --accent: #0d0d0d;
  --accent-2: #0d0d0d;
  --danger: #ef4444;
  --radius: 12px;
  --sidebar-w: 260px;
  --shadow: 0 0 0 1px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 16px;
}
.app { display: flex; height: 100vh; width: 100vw; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width .2s ease, margin .2s ease;
  overflow: hidden;
}
.sidebar.collapsed { width: 0; border-right: none; }
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 8px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: var(--text); }
.brand-logo { width: 24px; height: 24px; border-radius: 6px; object-fit: contain; }
.search-wrap { padding: 0 12px 8px; }
.search-wrap input {
  width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13px; outline: none;
}
.search-wrap input:focus { border-color: #b3b3b3; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.chat-item {
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  color: var(--text);
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); }
.chat-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { opacity: 0; font-size: 12px; color: var(--muted); }
.chat-item:hover .del { opacity: 1; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.ghost-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; width: 100%;
}
.ghost-btn:hover { color: var(--text); background: var(--panel-2); }
.new-chat-btn {
  margin: 8px 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.new-chat-btn:hover { background: var(--panel-2); }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.topbar-title { flex: 1; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 8px; font-size: 13px; max-width: 180px; outline: none;
}
.icon-btn {
  background: transparent; color: var(--text); border: none;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--panel-2); }
.api-status { font-size: 12px; padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border); color: var(--muted); background: var(--bg); }
.api-status.ok { color: #10a37f; border-color: rgba(16,163,127,.3); }
.api-status.bad { color: var(--danger); border-color: rgba(239,68,68,.3); }

/* Chat area */
.chat-area { flex: 1; overflow-y: auto; padding: 0; position: relative; }
.welcome { max-width: 768px; margin: 0 auto; padding: 60px 24px 24px; text-align: center; }
.welcome-logo-img { width: 48px; height: 48px; border-radius: 12px; margin-bottom: 16px; object-fit: contain; }
.welcome h1 { font-size: 28px; margin: 8px 0 4px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 24px; }
.sug {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 20px; cursor: pointer; font-size: 13px;
}
.sug:hover { background: var(--panel-2); }

.messages { max-width: 768px; margin: 0 auto; padding: 24px 24px 120px; display: flex; flex-direction: column; gap: 24px; }
.msg { display: flex; gap: 12px; min-width: 0; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  background: var(--panel-2); color: var(--text);
}
.msg.assistant .avatar { background: #10a37f; color: #fff; }
.msg.user .avatar { display: none; }
.bubble-wrap { flex: 1; min-width: 0; }
.msg.user .bubble-wrap { text-align: right; }
.msg.assistant .bubble-wrap { text-align: left; }
.bubble {
  padding: 0; border-radius: 0; font-size: 16px; line-height: 1.7;
  background: transparent; border: none;
  overflow-wrap: break-word; word-break: normal; white-space: normal;
  min-width: 0;
  max-width: 100%;
  width: max-content;
}
.msg.user .bubble {
  background: var(--panel-2); border-radius: 24px; padding: 6px 16px;
  max-width: 75%;
  /* debug */
}
.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: #f4f4f4; border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; }
.bubble code { font-family: 'JetBrains Mono', monospace; font-size: 14px; }
.bubble :not(pre) > code { background: rgba(0,0,0,.06); padding: 1px 6px; border-radius: 4px; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble h1,.bubble h2,.bubble h3 { margin: 10px 0 6px; }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.msg-actions button:hover { color: var(--text); background: var(--panel-2); }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); opacity: .4;} 40% { transform: translateY(-6px); opacity: 1;} }

/* Composer */
.composer { position: relative; padding: 12px 24px 16px; background: #fff; border-top: 1px solid var(--border); }
.composer-inner { max-width: 768px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; background: var(--bg); border: 1px solid var(--border); border-radius: 24px; padding: 8px 8px 8px 16px; box-shadow: 0 0 15px rgba(0,0,0,.05); }
.composer-inner:focus-within { border-color: #b3b3b3; }
#input { flex: 1; background: transparent; border: none; color: var(--text); font-size: 16px; resize: none; max-height: 200px; outline: none; padding: 6px 0; font-family: inherit; }
.send-btn { background: var(--text); border: none; color: #fff; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.send-btn:disabled { opacity: .3; cursor: not-allowed; }
.composer-meta { max-width: 768px; margin: 6px auto 0; display: flex; justify-content: space-between; align-items: center; padding: 0 8px; }
.temp-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.temp-label input { width: 100px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: var(--bg); border: 1px solid var(--border); border-radius: 16px; width: 90%; max-width: 520px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-body label { display: block; margin: 10px 0 6px; font-size: 13px; color: var(--muted); }
.modal-body textarea { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.modal-body input, .modal-body select { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 14px; margin-bottom: 8px; }
.row { display: flex; gap: 8px; margin-top: 12px; }

.mobile-only { display: none; }
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .messages { padding: 16px 16px 120px; }
  .composer { padding: 8px 12px 12px; }
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #d1d1d1; border-radius: 3px; }

/* Auth overlay */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.4); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.auth-overlay.hidden { display: none; }
.auth-card {
  background: #fff; border-radius: 16px; padding: 32px 28px;
  width: 90%; max-width: 400px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.15);
}
.auth-logo { width: 56px; height: 56px; border-radius: 12px; margin-bottom: 12px; }
.auth-card h2 { margin: 8px 0 4px; font-size: 22px; }
.auth-tabs { display: flex; gap: 8px; margin: 16px 0; justify-content: center; }
.auth-tabs button {
  padding: 8px 20px; border-radius: 20px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 14px; color: var(--muted);
}
.auth-tabs button.active { background: var(--text); color: #fff; border-color: var(--text); }
#authForm { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
#authForm input {
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 14px; outline: none;
}
#authForm input:focus { border-color: #b3b3b3; }
.auth-submit {
  padding: 10px; border-radius: 8px; border: none; background: var(--text);
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 4px;
}
.auth-submit:hover { opacity: .9; }
.auth-error { color: var(--danger); min-height: 16px; margin-top: 8px; }
.auth-card a { color: var(--accent); text-decoration: none; font-size: 13px; }
.auth-card a:hover { text-decoration: underline; }
.auth-divider { display: flex; align-items: center; text-align: center; margin: 12px 0; color: var(--muted); font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-bottom: 1px solid var(--border); }
.auth-divider span { padding: 0 10px; }
.google-btn {
  width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 14px; font-weight: 500;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.google-btn:hover { background: var(--panel-2); }
#appRoot.blurred { filter: blur(4px); pointer-events: none; }

/* Intro overlay - cinematic */
.intro-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #000; color: #fff;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.intro-letterbox {
  position: absolute; left: 0; right: 0; height: 12%; background: #000; z-index: 5;
}
.intro-letterbox.top { top: 0; }
.intro-letterbox.bottom { bottom: 0; }
.intro-overlay.hidden { display: none; }
.intro-progress {
  position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
  background: rgba(255,255,255,.15); z-index: 10;
}
.intro-progress-bar {
  height: 100%; width: 0%; background: linear-gradient(90deg, #2563eb, #7c3aed);
  animation: progressFill 18s linear forwards;
}
.intro-skip {
  position: absolute; top: 24px; right: 24px; z-index: 10;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
  color: #fff; padding: 8px 16px; border-radius: 20px; cursor: pointer; font-size: 13px;
}
.intro-skip:hover { background: rgba(255,255,255,.2); }
.intro-sound {
  position: absolute; top: 24px; left: 24px; z-index: 10;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
  color: #fff; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.intro-sound:hover { background: rgba(255,255,255,.2); }
.intro-particles {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 20% 30%, rgba(255,255,255,.6), transparent),
    radial-gradient(1.5px 1.5px at 60% 70%, rgba(37,99,235,.8), transparent),
    radial-gradient(2px 2px at 80% 20%, rgba(124,58,237,.7), transparent),
    radial-gradient(1px 1px at 40% 80%, rgba(255,255,255,.5), transparent),
    radial-gradient(1.5px 1.5px at 10% 90%, rgba(37,99,235,.6), transparent);
  background-size: 100% 100%;
  animation: particlesDrift 20s linear infinite;
}
@keyframes particlesDrift {
  0% { transform: translateY(0) translateX(0); opacity: .6; }
  50% { opacity: .9; }
  100% { transform: translateY(-20px) translateX(10px); opacity: .6; }
}
.intro-scenes { position: relative; width: 100%; height: 100%; }
.scene {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
}
.scene-bg {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(37,99,235,.15) 0%, transparent 70%);
}
.scene-content { position: relative; z-index: 2; text-align: center; padding: 24px; max-width: 800px; }
.scene-logo {
  width: 120px; height: 120px; border-radius: 30px;
  box-shadow: 0 0 80px rgba(37,99,235,.6);
  animation: logoGlow 3s ease-in-out infinite;
}
.scene-title {
  font-size: 72px; font-weight: 900; margin: 20px 0 6px; letter-spacing: -2px;
  background: linear-gradient(135deg, #fff, #93c5fd);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.scene-heading { font-size: 48px; font-weight: 800; margin: 0 0 12px; color: #fff; }
.scene-sub { font-size: 22px; color: rgba(255,255,255,.7); }
.scene-content { opacity: 0; }
.scene.active .scene-content { animation: sceneIn .8s cubic-bezier(.16,1,.3,1) both; }
@keyframes sceneWindow {
  0% { opacity: 1; pointer-events: auto; }
  99% { opacity: 1; pointer-events: auto; }
  100% { opacity: 0; pointer-events: none; }
}
.intro-cta {
  margin-top: 24px; padding: 14px 32px; border-radius: 30px; border: none;
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.intro-cta:hover { transform: scale(1.05); }
@keyframes logoGlow {
  0%,100% { box-shadow: 0 0 60px rgba(37,99,235,.4); }
  50% { box-shadow: 0 0 100px rgba(124,58,237,.7); }
}
@keyframes sceneIn {
  0% { opacity: 0; transform: translateY(40px) scale(.95); filter: blur(10px); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}
@keyframes progressFill {
  0% { width: 0%; }
  100% { width: 100%; }
}

/* Account row */
.account-row { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; }
.account-avatar { width: 24px; height: 24px; border-radius: 50%; }
#accountName { flex: 1; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#accountBtn { width: 28px; height: 28px; }

/* Settings tabs */
.settings-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.settings-tab {
  padding: 6px 14px; border-radius: 8px; border: none; background: transparent;
  cursor: pointer; font-size: 13px; color: var(--muted);
}
.settings-tab.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.tab-panel.hidden { display: none; }
.select.full { width: 100%; }