:root {
  --bg: #0b0d12;
  --panel: #12151d;
  --line: #222735;
  --text: #e7ebf3;
  --muted: #8b93a7;
  --accent: #4d8dff;
  --user: #1b2233;
  --radius: 14px;
  --maxw: 820px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---- top bar ---- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(12px, env(safe-area-inset-left)) 10px max(12px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.controls {
  display: flex;
  gap: 8px;
}

select,
button,
textarea {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

select,
button {
  padding: 7px 11px;
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- log ---- */
.log {
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.empty {
  max-width: var(--maxw);
  margin: 8vh auto 0;
  padding: 0 18px;
  text-align: center;
}

.empty h1 {
  font-size: clamp(22px, 5vw, 30px);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 22px;
}

.chips button {
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
}

.msg {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 12px;
}

.msg + .msg {
  border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--user);
  color: var(--muted);
}

.msg.assistant .avatar {
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  color: #cfe0ff;
}

.body {
  min-width: 0;
  overflow-wrap: anywhere;
}

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

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

.body pre {
  background: #0a0c11;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  font-size: 13px;
}

.body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.body :not(pre) > code {
  background: #0a0c11;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

.body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

.body th,
.body td {
  border: 1px solid var(--line);
  padding: 6px 9px;
  text-align: left;
}

.body a {
  color: var(--accent);
}

.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.meta button {
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 7px;
  background: transparent;
}

.reasoning {
  border-left: 2px solid var(--line);
  padding-left: 10px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13.5px;
}

.error {
  color: #ffb4b4;
}

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

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

/* ---- composer ---- */
.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  width: min(var(--maxw), 100%);
  margin: 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}

textarea {
  flex: 1;
  resize: none;
  padding: 11px 13px;
  max-height: 42vh;
  line-height: 1.5;
}

.composer button {
  height: 42px;
  min-width: 68px;
}

#send {
  background: var(--accent);
  border-color: var(--accent);
  color: #06101f;
  font-weight: 600;
}

#stop {
  background: #ff5c5c;
  border-color: #ff5c5c;
  color: #1a0505;
}

/* ---- footer ---- */
.foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: 0 18px calc(8px + env(safe-area-inset-bottom));
  font-size: 11.5px;
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 560px) {
  .msg {
    grid-template-columns: 22px 1fr;
    gap: 9px;
    padding: 12px 14px;
  }

  .avatar {
    width: 22px;
    height: 22px;
    font-size: 10px;
    border-radius: 7px;
  }

  .foot {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    animation: none !important;
  }
}
