:root {
  color-scheme: light;
  --bg: #f6efe6;
  --bg-soft: #fbf6ef;
  --panel: rgba(255, 251, 245, 0.94);
  --border: rgba(123, 102, 79, 0.12);
  --text: #2f251c;
  --muted: #7b6b5d;
  --accent: #1f7a66;
  --accent-2: #2d62db;
  --assistant: #fffaf3;
  --user: #2d62db;
  --shadow: 0 16px 40px rgba(111, 90, 64, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(45, 98, 219, 0.06), transparent 24%),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
p {
  margin: 0;
}

.app-shell {
  width: min(100%, 720px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px calc(132px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  padding: 4px 0 10px;
  background: linear-gradient(180deg, rgba(246, 239, 230, 0.96), rgba(246, 239, 230, 0.82) 76%, rgba(246, 239, 230, 0));
  backdrop-filter: blur(10px);
}

.header-title-group {
  display: grid;
  gap: 2px;
}

.header-eyebrow {
  font-size: 11px;
  color: var(--muted);
}

h1 {
  font-size: 20px;
  line-height: 1.1;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  flex: 1 1 auto;
  max-width: 220px;
}

.mode-button {
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  transition: background 140ms ease, color 140ms ease;
}

.mode-button.is-active {
  color: #fffdf9;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  font-weight: 700;
}

.chat-shell {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 28px;
}

.chat-list {
  display: grid;
  gap: 12px;
  padding: 4px 0 8px;
}

.chat-list > .message:first-child {
  margin-top: 2px;
}

.message {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.message.user {
  justify-content: flex-end;
}

.message.user .bubble-group {
  align-items: flex-end;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: #fffdf9;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}

.message.user .avatar {
  order: 2;
  background: linear-gradient(135deg, #5f84ea, #2d62db);
}

.bubble-group {
  max-width: min(84vw, 520px);
  display: grid;
  gap: 5px;
}

.message-name {
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
}

.bubble {
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--assistant);
  color: var(--text);
  line-height: 1.6;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant .bubble {
  border-top-left-radius: 8px;
}

.message.user .bubble {
  border-color: rgba(45, 98, 219, 0.08);
  background: var(--user);
  color: #fffdf9;
  border-top-right-radius: 8px;
}

.hero-message .bubble {
  background: rgba(255, 251, 245, 0.88);
}

.intro-bubble {
  display: grid;
  gap: 10px;
}

.intro-note {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.typing-bubble {
  color: var(--muted);
  min-width: 68px;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(45, 98, 219, 0.42);
  animation: typing-bounce 1.1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 1em;
  margin-left: 3px;
  border-radius: 999px;
  background: rgba(45, 98, 219, 0.28);
  vertical-align: -2px;
  animation: blink-caret 0.9s infinite;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 4px 0;
}

.chip-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
}

.chip-button:hover {
  background: rgba(255, 255, 255, 0.96);
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(45, 98, 219, 0.1);
  border-radius: 999px;
  background: rgba(45, 98, 219, 0.06);
  color: #3652a2;
}

.composer-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 30;
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 8px 12px 14px;
  background: linear-gradient(180deg, rgba(246, 239, 230, 0), rgba(246, 239, 230, 0.98) 26%);
  backdrop-filter: blur(12px);
}

.dock-hint {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.composer-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 56px;
  gap: 8px;
  align-items: end;
}

.composer-box {
  display: block;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}

.composer-box textarea {
  width: 100%;
  min-height: 24px;
  max-height: 132px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  resize: none;
  outline: none;
  line-height: 1.6;
}

.composer-box textarea::placeholder {
  color: #9b8a7b;
}

.mic-button,
.send-button {
  min-height: 44px;
  border: 0;
  border-radius: 50%;
  box-shadow: var(--shadow);
}

.mic-button {
  width: 44px;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--border);
}

.mic-button.is-recording {
  background: rgba(201, 110, 84, 0.2);
}

.mic-core {
  width: 16px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  position: relative;
  margin: 0 auto;
}

.mic-core::after {
  content: "";
  position: absolute;
  left: 4px;
  top: -10px;
  width: 8px;
  height: 14px;
  border-radius: 999px;
  background: var(--accent);
}

.send-button {
  width: 56px;
  border-radius: 22px;
  color: #fffdf9;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 13px;
  font-weight: 700;
}

.mic-button:disabled,
.send-button:disabled {
  opacity: 0.5;
}

@keyframes blink-caret {
  0%,
  100% {
    opacity: 0.2;
  }
  50% {
    opacity: 1;
  }
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (min-width: 768px) {
  .app-shell {
    width: min(100% - 24px, 560px);
    padding-top: 18px;
    padding-bottom: 128px;
  }

  .app-header {
    gap: 10px;
  }

  .header-actions {
    align-items: center;
  }
}
