:root {
  --bg: #0c0c0f;
  --surface: #141820;
  --raised: #1a2030;
  --text: #fff;
  --text-2: #a7b0c2;
  --accent: #3c93ff;
  --green: #2dbf7a;
  --red: #e77065;
  --border: rgba(255, 255, 255, 0.07);
  --radius: 14px;
  --glow: 0 0 0 1px rgba(60, 147, 255, 0.25), 0 0 28px rgba(60, 147, 255, 0.18);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Onest, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(60, 147, 255, 0.14), transparent 55%),
    radial-gradient(ellipse 40% 30% at 100% 0%, rgba(45, 191, 122, 0.06), transparent 50%);
  background-attachment: fixed;
}

h1,
h2,
h3,
.brand {
  font-family: Unbounded, Onest, sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
}

a {
  color: var(--accent);
  text-decoration: none;
}

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

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #6bb0ff);
  box-shadow: var(--glow);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #041018;
}

.hint {
  color: var(--text-2);
  font-size: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.settings {
  padding: 16px;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.settings-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

@media (max-width: 720px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-2);
  font-size: 12px;
}

.field {
  width: 100%;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field:focus {
  border-color: rgba(60, 147, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(60, 147, 255, 0.15);
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  background: var(--raised);
  color: var(--text);
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(180deg, #4ea0ff, var(--accent));
  color: #041018;
  font-weight: 600;
  box-shadow: var(--glow);
}

.btn-primary:hover {
  box-shadow: 0 0 0 1px rgba(60, 147, 255, 0.4), 0 0 36px rgba(60, 147, 255, 0.28);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}

.btn-ghost:hover {
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--text);
}

.btn-danger {
  background: rgba(231, 112, 101, 0.12);
  border-color: rgba(231, 112, 101, 0.3);
  color: var(--red);
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
}

.pill strong {
  color: var(--text);
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.pill.ok {
  color: var(--green);
  border-color: rgba(45, 191, 122, 0.25);
  background: rgba(45, 191, 122, 0.08);
}

.pill.warn {
  color: #f0b24d;
  border-color: rgba(240, 178, 77, 0.25);
  background: rgba(240, 178, 77, 0.08);
}

.pill.err {
  color: var(--red);
  border-color: rgba(231, 112, 101, 0.25);
  background: rgba(231, 112, 101, 0.08);
}

.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 520px;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--text-2);
  max-width: 360px;
  padding: 24px;
}

.empty h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  color: var(--text);
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(100%, 760px);
  animation: fadeUp 0.25s ease;
}

.msg.user {
  align-self: flex-end;
}

.msg.assistant {
  align-self: stretch;
}

.bubble {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--raised);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble {
  background: linear-gradient(180deg, rgba(60, 147, 255, 0.22), rgba(60, 147, 255, 0.12));
  border-color: rgba(60, 147, 255, 0.28);
  border-bottom-right-radius: 6px;
}

.role {
  font-size: 11px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.thinking {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.thinking summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
  user-select: none;
}

.thinking summary::-webkit-details-marker {
  display: none;
}

.thinking summary::after {
  content: "▾";
  color: var(--text-2);
  transition: transform 0.15s;
}

.thinking:not([open]) summary::after {
  transform: rotate(-90deg);
}

.thinking-body {
  padding: 0 12px 12px;
  color: var(--text-2);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  max-height: 280px;
  overflow-y: auto;
}

.answer {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--raised);
  white-space: pre-wrap;
  word-break: break-word;
  border-bottom-left-radius: 6px;
  min-height: 24px;
}

.answer.streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.18));
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  outline: none;
  line-height: 1.45;
}

.composer textarea:focus {
  border-color: rgba(60, 147, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(60, 147, 255, 0.15);
}

.status {
  min-height: 18px;
  padding: 0 4px;
  color: var(--text-2);
  font-size: 12px;
}

.status.error {
  color: var(--red);
}

.status.ok {
  color: var(--green);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  max-width: min(360px, calc(100vw - 32px));
  display: none;
}

.toast.show {
  display: block;
  animation: fadeUp 0.2s ease;
}

.toast.error {
  border-color: rgba(231, 112, 101, 0.35);
}
