:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #111418;
  --muted: #5b6470;
  --line: #e3e6ea;
  --accent: #1f4fd8;
  --accent-fg: #ffffff;
  --user-bg: #eef1f6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1013;
    --fg: #e8eaed;
    --muted: #9aa3ad;
    --line: #24282e;
    --accent: #6c8cff;
    --accent-fg: #0e1013;
    --user-bg: #1a1e24;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1013;
  --fg: #e8eaed;
  --muted: #9aa3ad;
  --line: #24282e;
  --accent: #6c8cff;
  --accent-fg: #0e1013;
  --user-bg: #1a1e24;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.bar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

button {
  font: inherit;
  cursor: pointer;
}

#theme {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
  border-radius: 8px;
}

#log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.msg.bot {
  align-self: flex-start;
  border: 1px solid var(--line);
}

#composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

#input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 10px 12px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

#send {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

#send:disabled { opacity: 0.5; cursor: default; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}