:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --border: #262626;
  --text: #f5f5f5;
  --text-dim: #999;
  --accent: #d4af37;
  --accent-soft: rgba(212, 175, 55, 0.15);
  --user-bubble: #1f1f1f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-soft);
}
.title {
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 14px;
  color: var(--accent);
}

.meta { display: flex; align-items: center; gap: 12px; }
.cost { color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.icon-btn {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}
.icon-btn:hover { color: var(--text); }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
}
.msg.error {
  align-self: center;
  color: #ff6b6b;
  border: 1px solid #5a1f1f;
  background: #1a0a0a;
  font-size: 13px;
}

.msg-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
}

.thinking {
  display: inline-flex;
  gap: 4px;
  padding: 0 4px;
}
.thinking span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim);
  animation: pulse 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(var(--safe-bot) + 10px);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 12px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); }
.composer button {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #0a0a0a;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: 92vw;
  width: 360px;
}
dialog::backdrop { background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.settings-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.settings-form h2 { margin: 0; font-size: 17px; letter-spacing: 0.1em; color: var(--accent); }
.settings-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.settings-form input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.settings-form .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.settings-form button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.settings-form button.primary { background: var(--accent); color: #0a0a0a; border-color: var(--accent); font-weight: 600; }
