:root {
  --sb-size: 9px;
  --sb-thumb: linear-gradient(180deg, #3a3228 0%, #2c3039 100%);
  --sb-thumb-hover: linear-gradient(180deg, #f2a65a 0%, #b8732f 100%);
  --sb-solid: #3a3f4a;
  --bg: #0d1015;
  --surface: #151a21;
  --surface-2: #1d232c;
  --line: #29303b;
  --text: #e9ecf1;
  --muted: #8d96a5;
  --accent: #f2a65a;
  --accent-ink: #1b1207;
  --danger: #ef7b7b;
  --ok: #7bd49b;
  --code-bg: #0f1318;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 18px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 340ms;
  --app-h: 100vh;
  --sidebar-w: 280px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@supports (height: 100dvh) {
  :root { --app-h: 100dvh; }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
svg { width: 20px; height: 20px; flex-shrink: 0; display: block; }

.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;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app {
  display: flex;
  height: var(--app-h);
  width: 100%;
  overflow: hidden;
  position: relative;
}

.main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- Sidebar (drawer on mobile) ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: min(84vw, 320px);
  height: var(--app-h);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 12px calc(14px + var(--safe-b));
  background: var(--surface);
  border-right: 1px solid var(--line);
  transform: translate3d(-104%, 0, 0);
  visibility: hidden;
  transition:
    transform var(--dur) var(--ease),
    visibility 0s linear var(--dur);
  will-change: transform;
}

.app.drawer-open .sidebar {
  transform: translate3d(0, 0, 0);
  visibility: visible;
  transition: transform var(--dur) var(--ease), visibility 0s linear 0s;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(5, 7, 10, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
}

.app.drawer-open .scrim,
.app.sheet-open .scrim {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur) var(--ease), visibility 0s linear 0s;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-weight: 500;
  transition: background-color 200ms var(--ease), border-color 200ms var(--ease), transform 160ms var(--ease);
}
.new-chat:active { transform: scale(0.97); }

.list-label {
  margin: 8px 6px 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.thread-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -4px;
  padding: 0 4px;
}

.thread {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  max-height: 44px;
  border-radius: 10px;
  overflow: hidden;
  transition:
    background-color 200ms var(--ease),
    opacity 240ms var(--ease),
    max-height 260ms var(--ease),
    min-height 260ms var(--ease),
    transform 240ms var(--ease);
}
.thread.is-active { background: var(--surface-2); }
.thread.is-new { animation: threadIn 360ms var(--ease) both; }
.thread.is-removing {
  opacity: 0;
  transform: translate3d(-12px, 0, 0);
  max-height: 0;
  min-height: 0;
}

.thread-open {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 4px 0 12px;
  text-align: left;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 200ms var(--ease);
}
.thread.is-active .thread-open { color: var(--text); }

.thread-del {
  height: 32px;
  min-width: 32px;
  margin-right: 6px;
  padding: 0 8px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 200ms var(--ease), color 200ms var(--ease), opacity 200ms var(--ease);
}
.thread-del svg { width: 16px; height: 16px; }
.thread-del.confirm { background: rgba(239, 123, 123, 0.14); color: var(--danger); }

.empty-threads {
  margin: 8px 6px;
  font-size: 13px;
  color: var(--muted);
}

.set-open {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--dur) var(--ease);
}
.set-open:hover { background: var(--surface-2); }
.set-open svg { width: 18px; height: 18px; color: var(--muted); }

.sidebar-note {
  margin: 0;
  padding: 10px 6px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Settings modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 7, 10, 0.64);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
}
.modal.open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur) var(--ease);
}
.modal-card {
  width: min(100%, 440px);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  transform: translateY(8px) scale(0.98);
  transition: transform var(--dur) var(--ease);
}
.modal.open .modal-card { transform: none; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.set-block { padding: 14px 0; border-top: 1px solid var(--line); }
.set-block:first-of-type { border-top: 0; }
.set-block h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.set-desc { margin: 0 0 12px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.key-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.key-field {
  flex: 1;
  min-width: 140px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  outline: none;
}
.key-field:focus { border-color: var(--accent); }
.ghost-btn {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--dur) var(--ease);
}
.ghost-btn:hover { background: var(--surface-2); }
.primary-btn {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
  transition: filter var(--dur) var(--ease);
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn.danger { background: var(--danger); color: #1b0707; }

/* ---------- Top bar ---------- */
/* No z-index on mobile: a stacking context here would trap the fixed bottom sheet under the scrim. */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: var(--muted);
  transition: background-color 200ms var(--ease), color 200ms var(--ease), transform 160ms var(--ease);
}
.icon-btn:active { transform: scale(0.92); background: var(--surface-2); color: var(--text); }

.model-wrap { position: relative; flex: 1; display: flex; justify-content: center; min-width: 0; }

.model-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 40px;
  padding: 0 12px 0 14px;
  border-radius: 12px;
  font-weight: 600;
  transition: background-color 200ms var(--ease), transform 160ms var(--ease);
}
.model-btn:active { transform: scale(0.97); background: var(--surface-2); }
.model-btn-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-btn .chev { width: 16px; height: 16px; color: var(--muted); transition: transform var(--dur) var(--ease); }
.model-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

/* Mobile: bottom sheet */
.model-menu {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  max-height: 78vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 10px calc(14px + var(--safe-b));
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  transform: translate3d(0, 105%, 0);
  visibility: hidden;
  transition: transform var(--dur) var(--ease), visibility 0s linear var(--dur);
  will-change: transform;
}
.app.sheet-open .model-menu {
  transform: translate3d(0, 0, 0);
  visibility: visible;
  transition: transform var(--dur) var(--ease), visibility 0s linear 0s;
}

.sheet-handle {
  width: 40px; height: 4px;
  margin: 2px auto 10px;
  border-radius: 4px;
  background: var(--line);
}

.menu-title {
  margin: 0 8px 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.model-opt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  text-align: left;
  transition: background-color 200ms var(--ease), transform 160ms var(--ease);
}
.model-opt:active { transform: scale(0.985); background: var(--surface-2); }
.model-opt[aria-selected="true"] { background: var(--surface-2); }
.model-opt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.model-opt-name { font-weight: 600; font-size: 14px; }
.model-opt-desc { font-size: 13px; color: var(--muted); }
.model-opt .check { color: var(--accent); opacity: 0; transform: scale(0.6); transition: opacity 200ms var(--ease), transform 260ms var(--ease); }
.model-opt[aria-selected="true"] .check { opacity: 1; transform: scale(1); }

/* ---------- Chat area ---------- */
.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chat-inner {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100%;
}
.chat-inner.is-switching { animation: fadeUp 380ms var(--ease) both; }

/* Welcome */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 12px 2px 0;
}
.welcome > * { animation: fadeUp 520ms var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
.welcome-mark {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
}
.welcome-mark svg { width: 26px; height: 26px; }
.welcome h1 {
  margin: 0;
  font-size: clamp(26px, 6.4vw, 36px);
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.welcome h1 span { color: var(--accent); }
.welcome p { margin: -10px 0 0; color: var(--muted); text-wrap: pretty; }

.suggestions { display: grid; grid-template-columns: 1fr; gap: 8px; }
.suggestion {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  animation: fadeUp 520ms var(--ease) both;
  animation-delay: calc(var(--i, 0) * 70ms);
  transition: background-color 200ms var(--ease), border-color 200ms var(--ease), transform 160ms var(--ease);
}
.suggestion:active { transform: scale(0.98); background: var(--surface-2); }
.suggestion strong { font-weight: 600; font-size: 14px; }
.suggestion span { font-size: 13px; color: var(--muted); }

/* Empty chat: everything fits on one screen, no scrolling */
.chat:has(.welcome) { overflow: hidden; }
.chat:has(.welcome) .chat-inner { height: 100%; padding-top: 12px; padding-bottom: 12px; }
.welcome { gap: 14px; padding: 0 2px; min-height: 0; }
.welcome-mark { width: 40px; height: 40px; border-radius: 12px; }
.welcome-mark svg { width: 22px; height: 22px; }
.welcome h1 { font-size: clamp(24px, 6vw, 32px); }
.welcome p { margin: -6px 0 0; font-size: 14px; }
.welcome .suggestions { grid-template-columns: 1fr 1fr; gap: 8px; }
.welcome .suggestion { padding: 10px 12px; border-radius: 12px; }
.welcome .suggestion strong { font-size: 13px; }
.welcome .suggestion span {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 599px) {
  .welcome .suggestion span { display: none; }
}
@media (max-height: 560px) {
  .welcome p { display: none; }
  .welcome-mark { display: none; }
}
@media (max-height: 430px) {
  .welcome .suggestions { display: none; }
}

/* Messages */
.msg { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.msg.is-new { animation: msgIn 420ms var(--ease) both; }

.msg--user { align-items: flex-end; }
.msg--user .bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 6px var(--radius);
  background: var(--surface-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-images { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 86%; }
.msg-images button {
  width: 108px; height: 108px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  transition: transform 200ms var(--ease);
}
.msg-images button:active { transform: scale(0.96); }
.msg-images img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-removed { font-size: 12px; color: var(--muted); }

.msg--ai { flex-direction: row; align-items: flex-start; gap: 12px; }
.ai-avatar {
  width: 28px; height: 28px;
  margin-top: 2px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  flex-shrink: 0;
}
.ai-avatar svg { width: 15px; height: 15px; }
.msg--ai.is-streaming .ai-avatar svg { animation: spin 2.4s linear infinite; }
.ai-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }

.md { overflow-wrap: anywhere; min-width: 0; max-width: 100%; line-height: 1.65; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h2, .md h3, .md h4 { margin: 18px 0 8px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
.md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--muted); }
.md strong { font-weight: 600; }
.md a { color: var(--accent); text-underline-offset: 3px; }
.md blockquote { margin: 0 0 12px; padding: 2px 0 2px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
}
.md table { display: block; max-width: 100%; overflow-x: auto; }
.code {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--code-bg);
  max-width: 100%;
  min-width: 0;
}
.code-head {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px;
  padding: 4px 6px 4px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-size: 12px; color: var(--muted);
}
.code-lang {
  font-family: var(--mono); font-weight: 500; color: var(--text);
  text-transform: lowercase; letter-spacing: 0.01em;
}
.code-meta { font-variant-numeric: tabular-nums; margin-right: auto; white-space: nowrap; }
.code-tools { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.code-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 10px; border-radius: 8px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}
.code-btn svg { width: 14px; height: 14px; }
.code-btn:active { background: var(--surface-2); }
.code-btn.is-done { color: var(--ok); }
.code-btn.is-failed { color: var(--danger); }
.chev-i { transition: transform 220ms var(--ease); }
[aria-expanded="true"] > .chev-i { transform: rotate(180deg); }

.code pre {
  margin: 0; padding: 12px 14px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.code.is-long:not(.is-open) pre { max-height: 340px; }
.code pre code {
  padding: 0; background: none;
  font-family: var(--mono);
  font-size: 13px; line-height: 1.6;
  white-space: pre; overflow-wrap: normal; word-break: normal;
  tab-size: 2;
}
.code-more {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 40px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px; font-weight: 500; color: var(--accent);
  transition: background-color 200ms var(--ease);
}
.code-more svg { width: 15px; height: 15px; }

/* Compact previews for long messages — presentation only. */
.md.is-clamped, .bubble.is-clamped {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 96px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 96px), transparent);
}
.md.is-clamped { max-height: 520px; }
.msg--user .bubble.is-clamped { max-height: 260px; }
.md.is-clamped .code.is-long:not(.is-open) pre { overflow: hidden; }
.msg-more {
  display: inline-flex; align-items: center; gap: 6px;
  align-self: flex-start;
  min-height: 34px; padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px; font-weight: 500; color: var(--text);
  transition: background-color 200ms var(--ease), border-color 200ms var(--ease);
}
.msg-more svg { width: 15px; height: 15px; color: var(--accent); }
.msg--user .msg-more { align-self: flex-end; }

.msg-actions { display: flex; gap: 2px; margin-left: -8px; opacity: 1; transition: opacity 240ms var(--ease); }
.msg--ai.is-streaming .msg-actions { opacity: 0; pointer-events: none; }
.act-btn {
  display: flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 8px;
  border-radius: 8px;
  font-size: 13px; color: var(--muted);
  transition: background-color 200ms var(--ease), color 200ms var(--ease), transform 160ms var(--ease);
}
.act-btn svg { width: 15px; height: 15px; }
.act-btn:active { transform: scale(0.94); background: var(--surface-2); }
.act-btn.is-done { color: var(--ok); }
.act-btn.is-failed { color: var(--danger); }

.typing { display: flex; gap: 5px; padding: 8px 0; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s var(--ease) infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
  .typing i:nth-child(3) { animation-delay: 0.3s; }

  .think { display: flex; align-items: center; min-height: 26px; padding: 6px 0; }
  .think-text {
    display: inline-block;
    font-size: 14.5px;
    font-weight: 500;
    background: linear-gradient(90deg, var(--muted) 0%, var(--text) 50%, var(--muted) 100%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: thinkShimmer 2s linear infinite;
    transition: opacity 160ms var(--ease), transform 160ms var(--ease);
  }
  .think-text::after { content: "…"; }
  .think-text.is-out { opacity: 0; transform: translateY(5px); }
  @keyframes thinkShimmer {
    to { background-position: -220% 0; }
  }
  @media (prefers-reduced-motion: reduce) {
    .think-text { animation: none; background: none; color: var(--muted); }
  }

  .stream-caret {
    display: inline-block;
    width: 7px;
    height: 1.05em;
    margin-left: 2px;
    vertical-align: text-bottom;
    border-radius: 2px;
    background: var(--text);
    opacity: 0.8;
    animation: caretBlink 1s steps(1) infinite;
  }
  @keyframes caretBlink {
    50% { opacity: 0; }
  }
  @media (prefers-reduced-motion: reduce) {
    .stream-caret { display: none; }
  }

.err {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(239, 123, 123, 0.35);
  border-radius: 14px;
  background: rgba(239, 123, 123, 0.08);
  color: var(--text);
  font-size: 14px;
  animation: fadeUp 320ms var(--ease) both;
}
.err .act-btn { margin-left: -8px; color: var(--danger); }

/* Scroll-to-bottom */
.to-bottom {
  position: absolute;
  left: 50%;
  bottom: calc(var(--composer-h, 120px) + 10px);
  z-index: 15;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  opacity: 0;
  visibility: hidden;
  transform: translate3d(-50%, 10px, 0) scale(0.9);
  transition: opacity 260ms var(--ease), transform 260ms var(--ease), visibility 0s linear 260ms;
}
.to-bottom svg { width: 18px; height: 18px; }
.to-bottom.show {
  opacity: 1;
  visibility: visible;
  transform: translate3d(-50%, 0, 0) scale(1);
  transition: opacity 260ms var(--ease), transform 260ms var(--ease), visibility 0s linear 0s;
}

/* ---------- Composer ---------- */
.composer {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 6px 10px calc(8px + var(--safe-b));
  background: var(--bg);
}

.composer-box {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  transition: border-color 220ms var(--ease), box-shadow 220ms var(--ease);
}
.composer-box.focused { border-color: #3a4352; box-shadow: 0 0 0 4px rgba(242, 166, 90, 0.08); }

.attachments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 12px;
  max-height: 0;
  transition: max-height var(--dur) var(--ease), padding var(--dur) var(--ease);
  scrollbar-width: none;
}
.attachments::-webkit-scrollbar { display: none; }
.attachments.has-items { max-height: 96px; padding: 12px 12px 0; }

.att {
  position: relative;
  flex-shrink: 0;
  width: 64px; height: 64px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-2);
  animation: popIn 320ms var(--ease) both;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease), width 240ms var(--ease), margin 240ms var(--ease);
}
  .att img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .att.is-removing { opacity: 0; transform: scale(0.7); width: 0; margin-right: -8px; }
  .att--file {
    width: auto;
    max-width: 200px;
    height: 48px;
    background: var(--surface-2);
    padding: 0 30px 0 10px;
  }
  .att-file { display: flex; align-items: center; gap: 8px; height: 100%; min-width: 0; }
  .att-file svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
  .att-name {
    font-size: 12.5px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .msg-files { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 86%; }
  .msg-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    transition: background var(--dur) var(--ease);
  }
  .msg-file:hover { background: var(--surface); }
  .msg-file svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
  .msg-file span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(13, 16, 21, 0.82);
  color: var(--text);
}
.att-del svg { width: 12px; height: 12px; }
.att.loading::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  animation: shimmer 1s linear infinite;
}

#input {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 200px;
  padding: 13px 16px 4px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.5;
  overflow-y: auto;
}
#input::placeholder { color: var(--muted); }

.composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 8px;
}
.hint { flex: 1; font-size: 12px; color: var(--muted); text-align: right; opacity: 0.8; }
.only-desktop { display: none; }

.send-btn {
  margin-left: auto;
  position: relative;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: background-color 220ms var(--ease), color 220ms var(--ease), transform 180ms var(--ease), opacity 220ms var(--ease);
}
.send-btn:active:not(:disabled) { transform: scale(0.9); }
.send-btn:disabled { background: var(--surface-2); color: var(--muted); cursor: default; }
.send-btn svg { position: absolute; transition: opacity 220ms var(--ease), transform 280ms var(--ease); }
.send-btn .ic-stop { width: 16px; height: 16px; opacity: 0; transform: scale(0.5); }
.send-btn.is-stop { background: var(--text); color: var(--bg); }
.send-btn.is-stop .ic-send { opacity: 0; transform: scale(0.5) translate3d(0, -6px, 0); }
.send-btn.is-stop .ic-stop { opacity: 1; transform: scale(1); }

.disclaimer { margin: 6px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

/* Drop zone */
.drop-zone {
  position: absolute;
  inset: 10px;
  z-index: 60;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: rgba(13, 16, 21, 0.86);
  color: var(--accent);
  font-weight: 600;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms var(--ease), visibility 0s linear 220ms;
}
.drop-zone.show { opacity: 1; visibility: visible; transition: opacity 220ms var(--ease), visibility 0s linear 0s; }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 7, 10, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms var(--ease), visibility 0s linear 300ms;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  transform: scale(0.92);
  transition: transform 360ms var(--ease);
}
.lightbox.open { opacity: 1; visibility: visible; transition: opacity 300ms var(--ease), visibility 0s linear 0s; }
.lightbox.open img { transform: scale(1); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top, 0px));
  z-index: 110;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 14px;
  opacity: 0;
  visibility: hidden;
  transform: translate3d(-50%, -10px, 0);
  transition: opacity 260ms var(--ease), transform 260ms var(--ease), visibility 0s linear 260ms;
}
.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate3d(-50%, 0, 0);
  transition: opacity 260ms var(--ease), transform 260ms var(--ease), visibility 0s linear 0s;
}

/* ---------- Keyframes ---------- */
@keyframes fadeUp {
  from { opacity: 0; transform: translate3d(0, 10px, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}
@keyframes msgIn {
  from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.985); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
@keyframes threadIn {
  from { opacity: 0; transform: translate3d(-10px, 0, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translate3d(0, 0, 0); }
  40% { opacity: 1; transform: translate3d(0, -3px, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- Hover only on real pointer devices (avoids sticky hover on phones) ---------- */
@media (hover: hover) and (pointer: fine) {
  .new-chat:hover, .suggestion:hover { background: var(--surface-2); border-color: #343c48; }
  .thread:hover { background: var(--surface-2); }
  .thread:hover .thread-open { color: var(--text); }
  .thread-del { opacity: 0; }
  .thread:hover .thread-del, .thread.is-active .thread-del, .thread-del.confirm, .thread-del:focus-visible { opacity: 1; }
  .thread-del:hover { color: var(--text); background: var(--bg); }
  .icon-btn:hover, .model-btn:hover, .act-btn:hover, .copy-code:hover, .code-btn:hover { background: var(--surface-2); color: var(--text); }
  .code-more:hover { background: var(--surface-2); }
  .msg-more:hover { background: var(--surface-2); border-color: #343c48; }
  .model-opt:hover { background: var(--surface-2); }
  .send-btn:hover:not(:disabled):not(.is-stop) { background: #f5b676; }
}

/* ---------- Tablet / Desktop ---------- */
@media (min-width: 600px) {
  .suggestions { grid-template-columns: 1fr 1fr; }
  .chat-inner { padding: 28px 20px 32px; }
  .chat:has(.welcome) .chat-inner { padding-top: 16px; padding-bottom: 16px; }
  .composer { padding: 6px 20px calc(10px + var(--safe-b)); }
}

@media (min-width: 900px) {
  .only-mobile { display: none; }
  .only-desktop { display: block; }

  .sidebar {
    position: relative;
    inset: auto;
    width: var(--sidebar-w);
    height: 100%;
    transform: none;
    visibility: visible;
    transition: none;
    will-change: auto;
  }
  .scrim { display: none; }

  .topbar { z-index: 20; padding: 10px 16px; border-bottom-color: transparent; }
  .model-wrap { justify-content: flex-start; }

  .model-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: auto; bottom: auto;
    width: 320px;
    max-height: 70vh;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
    transform: translate3d(0, -6px, 0) scale(0.97);
    transform-origin: top left;
    opacity: 0;
    transition: transform 240ms var(--ease), opacity 200ms var(--ease), visibility 0s linear 240ms;
  }
  .app.sheet-open .model-menu {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
    transition: transform 240ms var(--ease), opacity 200ms var(--ease), visibility 0s linear 0s;
  }
  .sheet-handle { display: none; }
  .menu-title { margin-top: 6px; }

  .msg--user .bubble, .msg-images { max-width: 75%; }
  .msg-images button { width: 140px; height: 140px; }
}

/* Users with Reduce Motion still get gentle fades — only large movement is removed. */
@media (prefers-reduced-motion: reduce) {
  @keyframes fadeUp { from { opacity: 0; } to { opacity: 1; } }
  @keyframes msgIn { from { opacity: 0; } to { opacity: 1; } }
  @keyframes threadIn { from { opacity: 0; } to { opacity: 1; } }
  .msg--ai.is-streaming .ai-avatar svg { animation-duration: 6s; }
}


/* ---------- LFG chip (in topbar) → /lfg ---------- */
.lfg-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 9px 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(242, 166, 90, 0.55);
  background: linear-gradient(180deg, rgba(242, 166, 90, 0.2), rgba(242, 166, 90, 0.06));
  box-shadow: 0 0 14px rgba(242, 166, 90, 0.16), inset 0 1px 0 rgba(255, 217, 160, 0.12);
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  animation: lfg-pulse 2.2s ease-in-out infinite;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease), transform 160ms var(--ease);
}
@keyframes lfg-pulse {
  0%, 100% {
    box-shadow: 0 0 8px rgba(242, 166, 90, 0.25), 0 0 0 0 rgba(242, 166, 90, 0.35), inset 0 1px 0 rgba(255, 217, 160, 0.12);
  }
  50% {
    box-shadow: 0 0 22px rgba(242, 166, 90, 0.55), 0 0 0 5px rgba(242, 166, 90, 0), inset 0 1px 0 rgba(255, 217, 160, 0.2);
  }
}
.lfg-wrap {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
}

/* Expanding halo so the eye catches the chip even in peripheral vision */
.lfg-ring {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  border: 1px solid rgba(242, 166, 90, 0.7);
  pointer-events: none;
  animation: lfg-ring 2.2s ease-out infinite;
}
@keyframes lfg-ring {
  0% { opacity: 0.75; transform: scale(1); }
  70% { opacity: 0; transform: scale(1.5); }
  100% { opacity: 0; transform: scale(1.5); }
}

/* Light sweeping across the chip face */
.lfg-chip { position: relative; overflow: hidden; }
.lfg-chip::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -60%;
  width: 45%;
  background: linear-gradient(100deg, transparent, rgba(255, 228, 184, 0.55), transparent);
  transform: skewX(-18deg);
  pointer-events: none;
  animation: lfg-shine 3.4s ease-in-out infinite;
}
@keyframes lfg-shine {
  0%, 55% { left: -60%; }
  85%, 100% { left: 125%; }
}

/* Coachmark that nudges the user toward the chip */
.lfg-coach {
  position: absolute;
  top: calc(100% + 11px);
  right: 0;
  z-index: 80;
  padding: 10px 18px;
  border-radius: 16px;
  border: 1px solid rgba(242, 166, 90, 0.55);
  background: var(--surface-2, #2a2724);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55), 0 0 26px rgba(242, 166, 90, 0.28);
  white-space: nowrap;
  opacity: 0;
  transform-origin: top right;
  pointer-events: none;
}
/* Bounces in, holds, then bounces back out the same way (3s), on a loop. */
.lfg-coach.show { animation: lfg-pop 9s ease-in-out infinite; }
.lfg-coach::before {
  content: "";
  position: absolute;
  top: -6px;
  right: 20px;
  width: 11px;
  height: 11px;
  background: var(--surface-2, #2a2724);
  border-left: 1px solid rgba(242, 166, 90, 0.55);
  border-top: 1px solid rgba(242, 166, 90, 0.55);
  transform: rotate(45deg);
}
.lfg-coach-text {
  display: block;
  font-size: 38px;
  line-height: 1;
}
@keyframes lfg-pop {
  0% { opacity: 0; transform: translateY(-14px) scale(0.4); }
  5% { opacity: 1; transform: translateY(6px) scale(1.18); }
  9% { transform: translateY(-3px) scale(0.95); }
  13% { transform: translateY(0) scale(1.05); }
  17%, 24% { opacity: 1; transform: translateY(0) scale(1); }
  28% { opacity: 1; transform: translateY(6px) scale(1.14); }
  33% { opacity: 0; transform: translateY(-14px) scale(0.4); }
  100% { opacity: 0; transform: translateY(-14px) scale(0.4); }
}

.lfg-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(242, 166, 90, 0.18), 0 0 8px rgba(242, 166, 90, 0.8);
}
.lfg-chip-text {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1;
  color: var(--text);
}
.lfg-chip-arrow { width: 13px; height: 13px; }
.lfg-chip:active { transform: scale(0.95); }
.lfg-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (hover: hover) and (pointer: fine) {
  .lfg-chip:hover {
    border-color: rgba(255, 217, 160, 0.9);
    box-shadow: 0 0 26px rgba(242, 166, 90, 0.5), inset 0 1px 0 rgba(255, 217, 160, 0.22);
  }
}

@media (max-width: 340px) {
  .lfg-chip { padding: 0 8px; gap: 5px; }
  .lfg-chip-arrow { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .lfg-chip { transition: none; animation: none; }
  .lfg-chip::after,
  .lfg-ring { animation: none; opacity: 0; }
  .lfg-coach.show { animation: none; opacity: 1; transform: none; }
}
