:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #24231f;
  background: #f6f4ef;
  font-synthesis: none;
  --paper: #fffefa;
  --ink-soft: #706e66;
  --line: #dedbd2;
  --accent: #dc5a36;
  --accent-dark: #b84325;
  --code: #262824;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(239, 205, 166, 0.22), transparent 30rem),
    #f6f4ef;
}

button, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  height: 62px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(222, 219, 210, 0.8);
  background: rgba(246, 244, 239, 0.86);
  backdrop-filter: blur(18px);
}

.brand {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: #252620;
  font-weight: 800;
  letter-spacing: -0.06em;
  text-decoration: none;
}

.model {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #4b4942;
  font-size: 13px;
  font-weight: 650;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #63a874;
  box-shadow: 0 0 0 4px rgba(99, 168, 116, 0.12);
}

.top-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink-soft);
  font-size: 12px;
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 11px;
  color: #45443e;
  background: rgba(255, 254, 250, 0.72);
}

main {
  width: min(820px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 92px 0 190px;
}

.empty-state {
  min-height: calc(100vh - 290px);
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.empty-state[hidden] { display: none; }

.mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid #33342e;
  border-radius: 18px;
  background: #272822;
  color: white;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.08em;
  box-shadow: 0 14px 30px rgba(46, 42, 33, 0.16);
}

.empty-state h1 {
  margin: 22px 0 8px;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 500;
  letter-spacing: -0.04em;
}

.empty-state p {
  max-width: 480px;
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.7;
}

.timeline { display: grid; gap: 24px; }

.message { min-width: 0; line-height: 1.72; }

.message.user {
  justify-self: end;
  max-width: min(82%, 650px);
  padding: 12px 16px;
  border: 1px solid #dfd7ca;
  border-radius: 18px 18px 5px 18px;
  background: #eee8de;
}

.message.user pre,
.thinking pre,
.tool-call pre,
.tool-result pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
}

.message.assistant { padding: 2px 4px; }
.message.assistant.streaming::after { content: "▍"; color: var(--accent); animation: blink 0.9s infinite; }
.message.assistant.partial { opacity: 0.72; }

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

.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 0.9em; }
.markdown a { color: var(--accent-dark); }
.markdown code {
  padding: 0.12em 0.35em;
  border-radius: 5px;
  background: #ebe8df;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}
.markdown pre {
  overflow-x: auto;
  padding: 15px;
  border-radius: 13px;
  background: var(--code);
  color: #f4f2e9;
}
.markdown pre code { padding: 0; background: transparent; color: inherit; }

.thinking,
.tool-call,
.tool-result {
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 254, 250, 0.64);
  overflow: hidden;
}

.thinking summary,
.tool-call summary,
.tool-result summary {
  padding: 9px 12px;
  color: #5d5b54;
  font-size: 12px;
  font-weight: 700;
  user-select: none;
}

.thinking pre,
.tool-call pre,
.tool-result pre {
  max-height: 360px;
  overflow: auto;
  padding: 0 12px 12px;
  color: #5f5d55;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
}

.tool-result.error { border-color: #e3a594; background: #fff5f1; }
.system-note { justify-self: center; color: var(--ink-soft); font-size: 12px; }

.error-banner {
  position: fixed;
  left: 50%;
  bottom: 148px;
  z-index: 30;
  width: min(720px, calc(100% - 40px));
  transform: translateX(-50%);
  padding: 11px 14px;
  border: 1px solid #e1aa9b;
  border-radius: 12px;
  color: #873a27;
  background: #fff3ef;
  box-shadow: 0 10px 28px rgba(75, 39, 30, 0.12);
}

.composer-shell {
  position: fixed;
  inset: auto 0 0;
  z-index: 20;
  padding: 18px 16px 24px;
  background: linear-gradient(transparent, #f6f4ef 30%);
}

.composer {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 14px 14px 10px;
  border: 1px solid #d8d4ca;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 18px 50px rgba(64, 57, 45, 0.14);
}

.composer textarea {
  width: 100%;
  min-height: 30px;
  max-height: 220px;
  resize: none;
  border: 0;
  outline: 0;
  color: #24231f;
  background: transparent;
  line-height: 1.55;
}

.composer textarea::placeholder { color: #aaa79e; }

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: #aaa79e;
  font-size: 11px;
}

.send-button,
.stop-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 11px;
  color: #fff;
  background: var(--accent);
  font-size: 19px;
  font-weight: 800;
}

.stop-button { background: #34352f; font-size: 13px; }

@media (max-width: 640px) {
  .topbar { grid-template-columns: auto 1fr auto; padding: 0 14px; }
  .model { justify-self: start; }
  #save-state { display: none; }
  .top-actions { gap: 8px; }
  main { width: min(100% - 24px, 820px); padding-top: 82px; }
  .message.user { max-width: 92%; }
  .composer-actions > span { display: none; }
  .composer-actions { justify-content: flex-end; }
}
