:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #262b36;
  --text: #e6e8ee;
  --muted: #8a92a6;
  --accent: #5b8cff;
  --user: #24365f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 0.35rem 0.75rem; }
button.ghost:hover { color: var(--text); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

.login { height: 100%; display: grid; place-items: center; padding: 1rem; }
.card {
  width: min(340px, 100%);
  display: grid;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
}
.card h1 { margin: 0 0 0.25rem; font-size: 1.3rem; }
.error { color: #ff7a7a; margin: 0; min-height: 1.2em; font-size: 0.9rem; }

.app { height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
header { gap: 0.5rem; flex-wrap: wrap; }
.pickers, .actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.pickers { flex: 1; min-width: 0; }
select {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  max-width: 100%;
}
#model { max-width: 260px; }
.cost { font-size: 0.8rem; color: var(--muted); }
.cost.free { color: #6fd38f; }

.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.9rem; }
.empty { margin: auto; color: var(--muted); text-align: center; }

.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); padding: 0.55rem 0.85rem; border-radius: 14px 14px 4px 14px; max-width: 85%; white-space: pre-wrap; }
.msg.assistant { align-self: stretch; }
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.thinking { color: var(--muted); }
.msg.thinking::after { content: "…"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.msg pre { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; overflow-x: auto; }
.msg code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.9em; }
.msg :not(pre) > code { background: var(--panel); padding: 0.1rem 0.35rem; border-radius: 4px; }
.msg a { color: var(--accent); }

.composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.composer textarea { flex: 1; resize: none; max-height: 40vh; }
