:root {
  color-scheme: dark;
  --background: #111216;
  --surface: #191a20;
  --surface-raised: #202127;
  --surface-soft: #25262d;
  --border: rgba(255, 255, 255, .08);
  --text: #f2f1f5;
  --muted: #a1a0aa;
  --dim: #777781;
  --accent: #c9b6ff;
  --accent-strong: #a989ff;
  --user: #292332;
  --danger: #ffaaa7;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse at 52% -20%, rgba(137, 107, 255, .13), transparent 46%),
    var(--background);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100%, 920px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 22px 28px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand img { border-radius: 12px; }
.brand-copy { display: grid; line-height: 1.25; }
.brand-copy strong { font-size: 14px; letter-spacing: .01em; }
.brand-copy small { margin-top: 3px; color: var(--dim); font-size: 11px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.icon-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, .025);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, color .18s ease;
}

.icon-button:hover { background: var(--surface-raised); color: var(--text); }
.icon-button[aria-pressed="true"] { color: var(--accent); border-color: rgba(201, 182, 255, .35); }
.speaker-icon { font-size: 17px; line-height: 1; }

.unlock-panel {
  width: min(100%, 440px);
  margin: auto;
  padding: 42px 0 70px;
}

.unlock-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 0 26px;
  border: 1px solid rgba(201, 182, 255, .22);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(201, 182, 255, .2), rgba(129, 96, 255, .08));
  color: var(--accent);
  font-size: 28px;
  box-shadow: 0 10px 40px rgba(134, 95, 255, .14);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
}

h1 { margin: 0; font-size: clamp(23px, 5vw, 30px); line-height: 1.2; letter-spacing: -.035em; }
.intro { margin: 12px 0 27px; color: var(--muted); font-size: 14px; }
.unlock-form label { display: block; margin-bottom: 8px; color: #d5d3dc; font-size: 12px; font-weight: 600; }
.key-row { display: flex; gap: 9px; }

.key-row input {
  width: 100%;
  min-width: 0;
  height: 47px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: .035em;
}

.key-row input:focus, textarea:focus { border-color: rgba(201, 182, 255, .56); }

.primary-button {
  min-width: 98px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #20172f;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:disabled { opacity: .55; cursor: wait; }
.form-error { min-height: 21px; margin: 9px 0 0; color: var(--danger); font-size: 12px; }
.fine-print { margin-top: 30px; color: var(--dim); font-size: 11px; }

.dot-dialog {
  width: min(460px, calc(100% - 32px));
  max-height: calc(100dvh - 48px);
  overflow: auto;
  padding: 26px;
  border: 1px solid rgba(201, 182, 255, .25);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .4);
}
.dot-dialog::backdrop { background: rgba(0, 0, 0, .65); }
.dot-dialog h2 { margin: 0; font-size: 24px; line-height: 1.2; letter-spacing: -.025em; }
.dot-dialog .intro { margin-bottom: 22px; }
.dot-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.dot-help { margin: 22px 0 10px; color: var(--muted); font-size: 12px; }

.chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-heading { display: flex; align-items: end; justify-content: space-between; gap: 14px; padding: 32px 2px 18px; }
.chat-heading h1 { font-size: clamp(22px, 4vw, 27px); }
.chat-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 0 0 14px; }
.chat-toolbar-actions { display: flex; align-items: center; gap: 7px; }
.project-picker { display: grid; flex: 1; gap: 4px; max-width: 380px; color: var(--muted); font-size: 10px; font-weight: 600; }
.project-picker select {
  width: 100%;
  min-height: 38px;
  padding: 0 34px 0 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.project-picker select:focus { border-color: rgba(201, 182, 255, .56); }
.project-picker select:disabled { opacity: .55; }

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
}

.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: #d8b76c; box-shadow: 0 0 8px rgba(216, 183, 108, .4); }
.connection-badge[data-state="ready"] .connection-dot { background: #72d6a0; box-shadow: 0 0 8px rgba(114, 214, 160, .45); }
.connection-badge[data-state="offline"] .connection-dot { background: #ed827d; box-shadow: 0 0 8px rgba(237, 130, 125, .4); }

.thread-note {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid rgba(201, 182, 255, .11);
  border-radius: 12px;
  background: rgba(201, 182, 255, .035);
  color: var(--muted);
  font-size: 11px;
}

.note-icon { width: 17px; height: 17px; display: grid; place-items: center; border-radius: 50%; background: rgba(201, 182, 255, .14); color: var(--accent); font-size: 11px; font-weight: 700; }

.conversation-panel {
  flex: 0 0 auto;
  max-height: min(38dvh, 360px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(25, 26, 32, .96);
}
.conversation-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.conversation-panel-heading div { display: grid; gap: 2px; }
.conversation-panel-heading strong { color: var(--text); font-size: 12px; }
.conversation-panel-heading span { color: var(--dim); font-size: 10px; }
.conversation-list { display: grid; gap: 6px; overflow: auto; min-height: 0; scrollbar-color: #3d3d47 transparent; scrollbar-width: thin; }
.conversation-card {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, .025);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.conversation-card:hover, .conversation-card[data-active="true"] { border-color: rgba(201, 182, 255, .4); background: rgba(201, 182, 255, .07); }
.conversation-card-title { overflow: hidden; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.conversation-card-meta, .conversation-card-preview { overflow: hidden; color: var(--dim); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-card-preview { color: var(--muted); }
.conversation-empty { padding: 12px 4px; color: var(--dim); font-size: 11px; text-align: center; }
.load-more-button { min-height: 32px; border: 0; border-radius: 9px; background: var(--surface-raised); color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; }
.load-more-button:hover { color: var(--text); }

.message-list {
  flex: 1;
  min-height: 230px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 17px;
  padding: 25px 0 18px;
  scrollbar-color: #3d3d47 transparent;
  scrollbar-width: thin;
}

.empty-state { margin: auto; padding: 28px 10px; text-align: center; color: var(--dim); }
.empty-symbol { width: 44px; height: 44px; display: grid; place-items: center; margin: 0 auto 13px; border: 1px solid var(--border); border-radius: 15px; color: var(--accent); font-size: 21px; }
.empty-state strong { display: block; margin-bottom: 5px; color: #cfced6; font-size: 13px; font-weight: 600; }
.empty-state p { margin: 0; font-size: 12px; }

.message { display: flex; gap: 10px; align-items: flex-start; }
.message.user { justify-content: flex-end; }
.message-avatar { width: 28px; height: 28px; display: grid; flex: 0 0 auto; place-items: center; border: 1px solid rgba(201, 182, 255, .22); border-radius: 10px; background: rgba(201, 182, 255, .1); color: var(--accent); font-size: 12px; }
.message.user .message-avatar { display: none; }
.message-content { max-width: min(82%, 680px); }
.message.user .message-content { order: -1; }
.message-name { margin: 0 0 5px 2px; color: var(--dim); font-size: 10px; font-weight: 600; }
.message.user .message-name { text-align: right; }
.message-bubble { padding: 11px 14px; border: 1px solid var(--border); border-radius: 5px 15px 15px; background: var(--surface); color: #e5e3eb; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .message-bubble { border-color: rgba(201, 182, 255, .13); border-radius: 15px 5px 15px 15px; background: var(--user); }
.message-time { margin: 4px 3px 0; color: var(--dim); font-size: 9px; }
.message.user .message-time { text-align: right; }

.typing-indicator { display: flex; align-items: center; gap: 4px; min-height: 23px; padding: 0 0 13px 38px; color: var(--dim); font-size: 11px; }
.typing-indicator span { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); animation: bounce 1s infinite ease-in-out; }
.typing-indicator span:nth-child(2) { animation-delay: .12s; }
.typing-indicator span:nth-child(3) { animation-delay: .24s; margin-right: 4px; }
.typing-indicator em { font-style: normal; }
@keyframes bounce { 0%, 60%, 100% { opacity: .45; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.composer {
  display: flex;
  align-items: end;
  gap: 9px;
  padding: 9px;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: 17px;
  background: rgba(31, 32, 39, .92);
  box-shadow: 0 18px 54px rgba(0, 0, 0, .18);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 150px;
  resize: none;
  padding: 8px 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  outline: none;
  background: transparent;
  color: var(--text);
  line-height: 1.4;
}

.composer textarea::placeholder { color: var(--dim); }
.mic-button, .send-button { width: 39px; height: 39px; display: grid; flex: 0 0 auto; place-items: center; border: 0; border-radius: 12px; cursor: pointer; transition: background .18s ease, transform .18s ease; }
.mic-button { background: transparent; color: var(--muted); }
.mic-button:hover { background: var(--surface-soft); color: var(--accent); }
.mic-button.listening { background: rgba(255, 122, 143, .16); color: #ff94a6; animation: pulse 1.2s infinite; }
.mic-button svg, .send-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.send-button { background: var(--accent); color: #20172f; }
.send-button:hover { background: #dacdff; transform: translateX(1px); }
.send-button:disabled, .mic-button:disabled { opacity: .45; cursor: default; transform: none; animation: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 122, 143, .08); } }

.composer-meta { display: flex; justify-content: space-between; gap: 10px; padding: 8px 5px 0; color: var(--dim); font-size: 10px; }
.toast { position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); left: 18px; width: max-content; max-width: min(440px, calc(100% - 36px)); margin: auto; padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px; background: #282831; color: var(--text); font-size: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

[hidden] { display: none !important; }

@media (max-width: 560px) {
  .app-shell { padding: 12px 15px max(14px, env(safe-area-inset-bottom)); }
  .topbar { padding-bottom: 13px; }
  .brand { gap: 8px; }
  .brand img { width: 34px; height: 34px; }
  .brand-copy strong { font-size: 13px; }
  .brand-copy small { font-size: 10px; }
  .icon-button { min-height: 35px; padding: 0 9px; font-size: 11px; }
  .top-actions { gap: 6px; }
  .chat-heading { padding: 23px 1px 14px; }
  .chat-toolbar { align-items: stretch; flex-direction: column; gap: 8px; }
  .project-picker { max-width: none; }
  .chat-toolbar-actions { justify-content: flex-end; }
  .thread-note { font-size: 10px; }
  .message-list { min-height: 180px; padding-top: 18px; }
  .message-content { max-width: 88%; }
  .message-bubble { font-size: 13.5px; }
  .composer-meta { font-size: 9px; }
}

@media (max-width: 370px) {
  .app-shell { padding-right: 11px; padding-left: 11px; }
  .brand-copy small { display: none; }
  .icon-button { padding: 0 7px; }
  .composer-meta span:last-child { display: none; }
}
