:root {
  color-scheme: light dark;
  --bg: #0f1419;
  --surface: #1a222d;
  --border: #2d3a4d;
  --text: #e7eef7;
  --muted: #9fb0c4;
  --accent: #3d9cf0;
  --accent-dim: #2563a8;
  --user-bg: #243044;
  --assistant-bg: #151c26;
  --radius: 12px;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #d5dde8;
    --text: #1a2332;
    --muted: #5c6b7e;
    --accent: #0b6bcb;
    --accent-dim: #084f98;
    --user-bg: #e3eefc;
    --assistant-bg: #f0f3f8;
  }
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.origin-notice {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0.75rem 1rem 0;
}

.origin-notice:not([hidden]) {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.origin-notice p {
  margin: 0.35rem 0;
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(200, 120, 0, 0.15);
  border: 1px solid rgba(200, 120, 0, 0.45);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
}

.origin-notice code {
  font-family: var(--mono);
  font-size: 0.88em;
}

.layout {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 650;
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.25rem;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 12rem;
}

.msg {
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
}

.msg--user {
  background: var(--user-bg);
  align-self: flex-end;
  max-width: 92%;
}

.msg--assistant {
  background: var(--assistant-bg);
  max-width: 100%;
}

.msg-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.msg-body {
  font-size: 0.95rem;
}

.msg-body :first-child {
  margin-top: 0;
}

.msg-body :last-child {
  margin-bottom: 0;
}

.msg-body pre,
.msg-body code {
  font-family: var(--mono);
  font-size: 0.84rem;
}

.code-block-wrap {
  margin: 0.65rem 0;
}

.code-block-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.code-copy-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.code-copy-btn:hover {
  background: var(--user-bg);
  border-color: var(--accent);
}

.msg-body pre {
  overflow-x: auto;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  user-select: text;
  cursor: text;
  -webkit-user-select: text;
}

@media (prefers-color-scheme: light) {
  .msg-body pre {
    background: #eef2f7;
  }
}

.msg-body pre code {
  background: none;
  padding: 0;
}

.msg-body code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
}

@media (prefers-color-scheme: light) {
  .msg-body code {
    background: #e2e8f0;
  }
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.composer textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
}

.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
}

.composer button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.15rem;
  background: var(--accent);
  color: #fff;
}

.composer button:hover {
  background: var(--accent-dim);
}

.composer button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.footer small {
  color: var(--muted);
  line-height: 1.45;
}

.footer code {
  font-family: var(--mono);
  font-size: 0.78em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.msg--error {
  border-color: #c94a4a;
  background: rgba(201, 74, 74, 0.12);
}

.msg--error .msg-body {
  white-space: pre-wrap;
}
