:root {
  --bg: #1a1a1a;
  --panel: #232323;
  --border: #333;
  --text: #ececec;
  --muted: #9a9a9a;
  --accent: #c47a5a;
  --user-bg: #2d3a4a;
  --assistant-bg: #232323;
  --code-bg: #161616;
  --danger: #c25450;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f5ef;
    --panel: #ffffff;
    --border: #e0dcd2;
    --text: #1a1a1a;
    --muted: #6b6b6b;
    --accent: #b56a47;
    --user-bg: #e9eef5;
    --assistant-bg: #ffffff;
    --code-bg: #f0ede4;
    --danger: #b04540;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

select,
button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: var(--accent);
}

button#send {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button#delete-chat:hover {
  border-color: var(--danger);
  color: var(--danger);
}

main {
  overflow-y: auto;
  padding: 1.5rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scroll-behavior: smooth;
}

.message {
  max-width: 60rem;
  margin: 0 auto;
  width: 100%;
  display: flex;
  gap: 0.75rem;
}

.message .role {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
}

.message.user .role {
  background: var(--user-bg);
  color: var(--text);
}

.message.assistant .role {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.message .body {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.75rem 1rem;
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message.user .body {
  background: var(--user-bg);
}

.message.error .body {
  border-color: var(--danger);
  color: var(--danger);
}

.message .body p:first-child {
  margin-top: 0;
}
.message .body p:last-child {
  margin-bottom: 0;
}

.message pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  overflow-x: auto;
}

.message code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}

.message :not(pre) > code {
  background: var(--code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.cursor::after {
  content: "▍";
  margin-left: 0.1rem;
  animation: blink 1s steps(2, start) infinite;
  color: var(--accent);
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

form#composer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--bg);
}

textarea#input {
  flex: 1;
  resize: none;
  min-height: 2.5rem;
  max-height: 12rem;
  padding: 0.6rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

textarea#input:focus {
  border-color: var(--accent);
}

button#send,
button#stop {
  height: 2.5rem;
  padding: 0 1rem;
}

button#stop {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
