:root {
  --bg: #0e0f13;
  --bg-elevated: #16181f;
  --bg-elevated-2: #1d2029;
  --border: #262932;
  --text: #edeef2;
  --text-dim: #9498a3;
  --text-faint: #676c78;
  --accent: #8b7cf6;
  --accent-2: #6ee7d8;
  --accent-soft: rgba(139, 124, 246, 0.14);
  --user-bubble: #262a36;
  --danger: #f0655f;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7fb;
    --bg-elevated: #ffffff;
    --bg-elevated-2: #f0f0f7;
    --border: #e5e5ee;
    --text: #1b1c22;
    --text-dim: #62636e;
    --text-faint: #9497a3;
    --accent: #6d5bd0;
    --accent-2: #159c8b;
    --accent-soft: rgba(109, 91, 208, 0.1);
    --user-bubble: #eceafc;
    --shadow: 0 10px 30px rgba(30, 30, 60, 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 100%;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  font-size: 22px;
  line-height: 1;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-title {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11.5px;
  color: var(--text-faint);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.think-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.15s ease;
}

.model-select {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.model-select:hover { border-color: var(--accent); color: var(--text); }
.model-select:focus { outline: none; border-color: var(--accent); color: var(--text); }

.think-toggle:hover { border-color: var(--accent); color: var(--text); }

.think-toggle .think-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.15s ease;
}

.think-toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.think-toggle[aria-pressed="true"] .think-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.icon-btn {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover { border-color: var(--text-faint); color: var(--text); }

/* Chat area */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 12px;
  scroll-behavior: smooth;
}

.empty-state {
  max-width: 560px;
  margin: 10vh auto 0;
  text-align: center;
  padding: 0 20px;
}

.empty-mark {
  font-size: 38px;
  margin-bottom: 14px;
}

.empty-state h1 {
  font-size: 22px;
  font-weight: 650;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}

.empty-state p {
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.6;
  margin: 0;
}

.msg {
  max-width: 720px;
  margin: 0 auto 22px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  flex-shrink: 0;
  margin-top: 2px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
}

.msg.role-user .msg-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
}

.msg.role-assistant .msg-avatar {
  background: var(--bg-elevated-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg.role-assistant .msg-avatar::after {
  content: "✨";
  font-size: 13px;
}

.msg-body {
  min-width: 0;
  flex: 1;
}

.msg.role-user .msg-body {
  display: flex;
  justify-content: flex-end;
}

.msg.role-user .msg-content {
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  max-width: 85%;
  white-space: pre-wrap;
  font-size: 14.5px;
}

.msg.role-assistant .msg-content {
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.msg-content:empty::after {
  content: "";
}

.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content code {
  background: var(--bg-elevated-2);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.msg-content pre {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-content pre code {
  background: none;
  padding: 0;
}
.msg-content strong { font-weight: 650; }

/* Thinking block */
.thinking-block {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.thinking-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  text-align: left;
}

.thinking-toggle .chevron {
  transition: transform 0.18s ease;
  flex-shrink: 0;
}

.thinking-block.open .thinking-toggle .chevron {
  transform: rotate(90deg);
}

.thinking-block.active .thinking-label::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

.thinking-content {
  display: none;
  padding: 0 14px 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.thinking-block.open .thinking-content {
  display: block;
}

/* Typing dots */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 6px 0;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.msg-error {
  color: var(--danger);
  font-size: 13.5px;
  padding: 8px 12px;
  background: rgba(240, 101, 95, 0.1);
  border: 1px solid rgba(240, 101, 95, 0.3);
  border-radius: 10px;
}

/* Composer */
.composer {
  padding: 10px 16px 16px;
  background: var(--bg);
}

.composer-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
}

.composer-inner:focus-within {
  border-color: var(--accent);
}

#input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 200px;
  padding: 6px 0;
}

#input::placeholder { color: var(--text-faint); }

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.send-btn:not(:disabled):active {
  transform: scale(0.92);
}

.composer-hint {
  max-width: 720px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
}

@media (max-width: 640px) {
  .brand-sub { display: none; }
  .icon-btn { padding: 7px 10px; }
  .model-select { padding: 7px 8px; font-size: 12px; max-width: 120px; }
  .msg { max-width: 100%; }
}
