:root {
  color-scheme: light;
  --ink: #27231f;
  --muted: #746d65;
  --cream: #fffaf0;
  --paper: rgba(255, 255, 255, 0.88);
  --orange: #f26b38;
  --orange-dark: #d94e20;
  --yellow: #ffd66b;
  --green: #5dac7b;
  --line: rgba(54, 43, 32, 0.12);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 20px;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, #ffe7a4 0 10%, transparent 31%),
    radial-gradient(circle at 88% 82%, #ffc6ae 0 8%, transparent 30%),
    #f6eedf;
}

button,
textarea {
  font: inherit;
}

.background-blob {
  position: fixed;
  z-index: -1;
  border-radius: 42% 58% 63% 37% / 40% 44% 56% 60%;
  filter: blur(1px);
  opacity: 0.55;
  animation: drift 12s ease-in-out infinite alternate;
}

.blob-one {
  top: -120px;
  right: 8%;
  width: 330px;
  height: 330px;
  background: #ffc167;
}

.blob-two {
  bottom: -170px;
  left: 5%;
  width: 390px;
  height: 390px;
  background: #f49a7a;
  animation-delay: -5s;
}

.app-shell {
  width: min(100%, 780px);
  height: min(880px, calc(100vh - 40px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  background: var(--paper);
  box-shadow:
    0 30px 90px rgba(75, 48, 25, 0.16),
    0 2px 10px rgba(75, 48, 25, 0.08);
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 25px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand h1 {
  margin: 0 0 3px;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0.04em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(93, 172, 123, 0.13);
}

.character-avatar {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 3px solid #fff;
  border-radius: 19px;
  object-fit: cover;
  object-position: 50% 22%;
  box-shadow:
    0 5px 14px rgba(70, 45, 22, 0.18),
    0 0 0 1px rgba(54, 43, 32, 0.08);
}

.clear-button {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition:
    color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.clear-button:hover {
  color: var(--ink);
  background: #fff5e4;
  transform: translateY(-1px);
}

.chat {
  overflow-y: auto;
  padding: 28px 25px 14px;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 7px;
}

.chat::-webkit-scrollbar-thumb {
  border-radius: 20px;
  background: #ded3c5;
}

.message-row,
.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 18px;
  animation: message-in 230ms ease-out;
}

.message-row.user {
  justify-content: flex-end;
}

.mini-avatar {
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  border: 2px solid #fff;
  border-radius: 10px;
  object-fit: cover;
  object-position: 50% 20%;
  box-shadow: 0 2px 6px rgba(60, 45, 30, 0.15);
}

.message {
  max-width: min(78%, 560px);
  padding: 12px 15px;
  border-radius: 7px 18px 18px 18px;
  background: #f2ece2;
  line-height: 1.62;
  box-shadow: 0 2px 5px rgba(60, 45, 30, 0.05);
}

.message-row.user .message {
  color: #fff;
  border-radius: 18px 7px 18px 18px;
  background: var(--orange);
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message p + p {
  margin-top: 7px;
}

.typing-row {
  margin: 0;
  padding: 4px 25px 8px;
}

.typing-bubble {
  display: flex;
  gap: 5px;
  padding: 14px 16px;
  border-radius: 7px 18px 18px 18px;
  background: #f2ece2;
}

.typing-bubble i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9c9185;
  animation: bounce 900ms ease-in-out infinite;
}

.typing-bubble i:nth-child(2) {
  animation-delay: 120ms;
}

.typing-bubble i:nth-child(3) {
  animation-delay: 240ms;
}

.hidden {
  display: none;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 8px 18px 0;
  padding: 8px 8px 8px 17px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: #fff;
  box-shadow: 0 8px 28px rgba(75, 48, 25, 0.08);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: rgba(242, 107, 56, 0.48);
  box-shadow: 0 8px 32px rgba(242, 107, 56, 0.13);
}

textarea {
  width: 100%;
  max-height: 130px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  line-height: 1.5;
}

textarea::placeholder {
  color: #aaa096;
}

#send-button {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 11px 15px;
  border: 0;
  border-radius: 13px;
  color: #fff;
  background: var(--orange);
  font-weight: 700;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

#send-button:hover {
  background: var(--orange-dark);
  transform: translateY(-1px);
}

#send-button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

#send-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.contract {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  margin: 10px 18px 0;
  padding: 7px 8px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 250, 240, 0.78);
}

.contract-label {
  flex: 0 0 auto;
  color: var(--orange-dark);
  font-size: 11px;
  font-weight: 800;
}

.contract code {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contract button {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-size: 11px;
  cursor: pointer;
}

.contract button:hover {
  background: var(--orange-dark);
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 5px;
}

.social-links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  transition:
    color 160ms ease,
    background 160ms ease;
}

.social-links a:hover {
  color: var(--orange-dark);
  background: #fff1df;
}

.social-links span {
  color: var(--ink);
  font-weight: 700;
}

.footnote {
  margin: 5px 0 11px;
  color: #9a9086;
  font-size: 11px;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
}

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-5px);
  }
}

@keyframes drift {
  to {
    transform: translate(28px, 20px) rotate(8deg);
  }
}

@media (max-width: 600px) {
  body {
    display: block;
    padding: 0;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .topbar {
    padding: 17px 16px;
  }

  .character-avatar {
    width: 52px;
    height: 52px;
    border-radius: 17px;
  }

  .brand h1 {
    font-size: 22px;
  }

  .brand p {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .clear-button {
    padding: 8px 10px;
    font-size: 12px;
  }

  .chat {
    padding: 22px 14px 10px;
  }

  .typing-row {
    padding-right: 14px;
    padding-left: 14px;
  }

  .message {
    max-width: 85%;
  }

  .composer {
    margin-right: 10px;
    margin-left: 10px;
  }

  .contract {
    margin-right: 10px;
    margin-left: 10px;
  }

  #send-button span {
    display: none;
  }

  #send-button {
    padding: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
