:root {
  color-scheme: light;
  --ink: #19352f;
  --ink-soft: #53625e;
  --green: #23483f;
  --green-soft: #e7efeb;
  --terracotta: #c97755;
  --paper: #fffdf8;
  --canvas: #f3f0e8;
  --line: #e5e0d5;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.shell {
  width: min(920px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  box-shadow: 0 0 48px rgb(35 72 63 / 8%);
}

.site-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) 24px 14px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 253 248 / 92%);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-logo { width: 64px; height: 64px; object-fit: contain; flex: none; }
.brand-copy { min-width: 0; }
.brand h1 { margin: 0 0 3px; font-size: 22px; line-height: 1.2; letter-spacing: .08em; }
.brand p { margin: 0; color: var(--ink-soft); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  padding: 28px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.welcome {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 32px;
  text-align: center;
  color: var(--ink-soft);
}

.welcome img { width: 68px; height: 68px; object-fit: contain; margin-bottom: 12px; opacity: .9; }
.welcome h2 { margin: 0 0 8px; color: var(--ink); font-size: clamp(20px, 4vw, 25px); font-weight: 650; }
.welcome p { margin: 0; font-size: 14px; }
.welcome[hidden] { display: none; }

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 20px;
}

.quick-question {
  min-width: 0;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid #cfdcd5;
  border-radius: 999px;
  background: #f4f8f5;
  color: var(--green);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

.quick-question:hover { background: var(--green-soft); filter: none; }
.quick-question:focus-visible { outline-color: rgb(35 72 63 / 22%); }
.message-suggestions { justify-content: flex-start; margin-top: 12px; }

.message { margin: 0 0 18px; display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant.has-suggestions { flex-direction: column; align-items: flex-start; }
.bubble {
  max-width: min(78%, 660px);
  padding: 12px 15px;
  border-radius: 16px;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user .bubble { background: var(--green); color: #fff; border-bottom-right-radius: 5px; }
.assistant .bubble { background: #f6f3ec; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.assistant .bubble.typing {
  display: inline-flex;
  align-items: center;
  min-width: 64px;
  min-height: 48px;
  gap: 6px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #80908a;
  animation: typing-bounce 1.15s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: .14s; }
.typing-dot:nth-child(3) { animation-delay: .28s; }

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: .38; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}
.debug { margin-top: 8px; max-width: 82%; font-size: 12px; color: var(--ink-soft); }
.debug pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #f6f3ec; padding: 10px; border-radius: 8px; }

.composer {
  flex: none;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 14px 22px max(18px, env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
}

textarea {
  flex: 1;
  width: 100%;
  resize: none;
  overflow-y: hidden;
  min-height: 50px;
  max-height: 150px;
  padding: 13px 14px;
  border: 1px solid #cbc6ba;
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgb(35 72 63 / 10%); }
textarea::placeholder { color: #929991; }

button {
  min-width: 78px;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 13px;
  background: var(--terracotta);
  color: #fff;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
  transition: filter .2s, transform .2s;
}

button:hover { filter: brightness(.95); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 3px solid rgb(201 119 85 / 25%); outline-offset: 2px; }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

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

@media (max-width: 640px) {
  .shell { box-shadow: none; }
  .site-header { padding-right: 16px; padding-left: 16px; }
  .brand { gap: 10px; }
  .brand-logo { width: 54px; height: 54px; }
  .brand h1 { font-size: 19px; }
  .brand p { max-width: 230px; font-size: 12px; }
  .messages { padding: 20px 14px; }
  .welcome { padding: 24px 16px; }
  .quick-questions { flex-direction: column; align-items: stretch; width: 100%; max-width: 360px; }
  .quick-question { width: 100%; }
  .message-suggestions { align-items: flex-start; width: min(90%, 420px); }
  .bubble, .debug { max-width: 90%; }
  .composer { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
  button { min-width: 66px; padding: 0 14px; }
}

@media (max-width: 360px) {
  .brand p { max-width: 180px; }
  .bubble, .debug { max-width: 94%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .typing-dot { animation: none; opacity: .65; }
}
