*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #7c6af7;
  --accent-hover: #9585ff;
  --user-bg: #1e1e2e;
  --assistant-bg: #141414;
  --code-bg: #0a0a0a;
  --danger: #e05c5c;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }

/* ── Auth overlay ── */
#auth-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#auth-overlay.hidden { display: none; }

.auth-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem; width: 360px;
}
.auth-box h1 { font-size: 1.4rem; font-weight: 600; margin-bottom: .25rem; }
.auth-box p { color: var(--text-dim); font-size: .875rem; margin-bottom: 1.5rem; }
.auth-box input {
  width: 100%; padding: .625rem .75rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-size: .9rem; outline: none; margin-bottom: 1rem;
}
.auth-box input:focus { border-color: var(--accent); }
.auth-error { color: var(--danger); font-size: .8rem; margin-top: -.5rem; margin-bottom: .75rem; display: none; }
.auth-error.visible { display: block; }

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; max-width: 860px; margin: 0 auto; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .875rem 1.25rem; border-bottom: 1px solid var(--border);
  background: var(--bg); position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 1rem; font-weight: 600; color: var(--text); letter-spacing: .02em; }
header span { font-size: .75rem; color: var(--accent); background: rgba(124,106,247,.12); padding: .2rem .5rem; border-radius: 4px; }

#new-chat-btn {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  padding: .375rem .75rem; border-radius: 6px; cursor: pointer; font-size: .8rem;
  transition: border-color .15s, color .15s;
}
#new-chat-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── Messages ── */
#messages {
  flex: 1; overflow-y: auto; padding: 1.25rem;
  display: flex; flex-direction: column; gap: .75rem;
}
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message { max-width: 100%; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.message.user { align-self: flex-end; max-width: 80%; }
.message.assistant { align-self: flex-start; max-width: 90%; }

.bubble {
  padding: .75rem 1rem; border-radius: 12px; font-size: .9rem; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.message.user .bubble { background: var(--user-bg); border: 1px solid var(--border); border-radius: 12px 12px 2px 12px; }
.message.assistant .bubble { background: var(--assistant-bg); border: 1px solid var(--border); border-radius: 2px 12px 12px 12px; }

/* code in bubbles */
.bubble code { background: var(--code-bg); padding: .15em .35em; border-radius: 4px; font-size: .85em; font-family: 'JetBrains Mono', 'Fira Code', monospace; }
.bubble pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: .875rem 1rem; margin: .5rem 0; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; font-size: .82em; }

.thinking { color: var(--text-dim); font-size: .8rem; padding: .5rem 0 .25rem; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }

/* ── Input ── */
#input-area {
  padding: 1rem 1.25rem 1.25rem; border-top: 1px solid var(--border); background: var(--bg);
}
#input-row { display: flex; gap: .625rem; align-items: flex-end; }
#message-input {
  flex: 1; resize: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .625rem .875rem; color: var(--text); font-size: .9rem;
  font-family: inherit; line-height: 1.5; min-height: 44px; max-height: 200px; outline: none;
  transition: border-color .15s;
}
#message-input:focus { border-color: var(--accent); }
#send-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  width: 44px; height: 44px; cursor: pointer; font-size: 1.1rem; display: flex;
  align-items: center; justify-content: center; transition: background .15s; flex-shrink: 0;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { background: var(--border); cursor: not-allowed; }

.hint { color: var(--text-dim); font-size: .72rem; margin-top: .375rem; text-align: right; }

/* btn shared */
button { cursor: pointer; }
