:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --surface: #ffffff;
  --ink: #171816;
  --muted: #7c7e78;
  --line: #e5e6e1;
  --accent: #20211f;
  --assistant: #ffffff;
  --user: #252724;
  --success: #39795a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.is-hidden {
  display: none !important;
}

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 50% 0%, #fff 0, transparent 45%),
    var(--bg);
}

.login-box {
  width: min(360px, 100%);
  padding: 2.4rem 2rem;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 24px 80px rgba(20, 22, 18, 0.08);
  text-align: center;
}

.brand-mark,
.avatar,
.message-avatar {
  display: grid;
  place-items: center;
  color: white;
  background: var(--accent);
  font-family: Georgia, serif;
}

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 1.2rem;
  border-radius: 18px;
  font-size: 1.8rem;
}

.login-box h1 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 2rem;
  letter-spacing: 0.04em;
}

.login-box > p {
  margin: 0.5rem 0 2.2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.login-box label {
  display: grid;
  gap: 0.55rem;
  text-align: left;
}

.login-box label span {
  color: var(--muted);
  font-size: 0.72rem;
}

.login-box input {
  width: 100%;
  height: 52px;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: #fafaf8;
}

.login-box input:focus {
  border-color: var(--ink);
}

.login-box button {
  width: 100%;
  height: 52px;
  margin-top: 0.8rem;
  border: 0;
  border-radius: 14px;
  color: white;
  background: var(--accent);
  cursor: pointer;
}

.error-text {
  min-height: 1.2rem;
  margin: 0.7rem 0 0 !important;
  color: #a9342e !important;
  font-size: 0.76rem !important;
}

.app-view {
  width: min(760px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(229, 230, 225, 0.85);
  background: rgba(245, 245, 242, 0.92);
  backdrop-filter: blur(18px);
}

.identity,
.header-actions {
  display: flex;
  align-items: center;
}

.identity {
  gap: 0.7rem;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 1.2rem;
}

.identity div:last-child {
  display: grid;
  gap: 0.15rem;
}

.identity strong {
  font-family: Georgia, serif;
  font-size: 1.05rem;
}

.identity span {
  color: var(--success);
  font-size: 0.68rem;
}

.header-actions {
  gap: 0.5rem;
}

.header-actions > button:not(.round-button) {
  height: 38px;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 0.75rem;
  cursor: pointer;
}

.history-drawer {
  position: fixed;
  z-index: 60;
  inset: 0;
}

.history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 21, 19, 0.3);
  backdrop-filter: blur(3px);
}

.history-panel {
  position: absolute;
  top: 0;
  right: max(0px, calc((100vw - 760px) / 2));
  width: min(360px, 88vw);
  height: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
  overflow-y: auto;
  background: var(--bg);
  box-shadow: -18px 0 50px rgba(20, 22, 18, 0.15);
}

.history-panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.history-panel > header div {
  display: grid;
  gap: 0.2rem;
}

.history-panel > header strong {
  font-family: Georgia, serif;
  font-size: 1.15rem;
}

.history-panel > header span,
.history-empty {
  color: var(--muted);
  font-size: 0.7rem;
}

.history-panel > header button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.2rem;
  cursor: pointer;
}

.history-list {
  display: grid;
  gap: 0.55rem;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr 32px;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 0.65rem 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.history-item.is-active {
  border-color: #959790;
}

.history-open {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.history-open strong,
.history-open span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-open strong {
  font-size: 0.82rem;
}

.history-open span {
  color: var(--muted);
  font-size: 0.66rem;
}

.history-delete {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  color: #9a3f38;
  background: #faf4f3;
  cursor: pointer;
}

.history-empty {
  padding: 2rem 0;
  text-align: center;
}

.round-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.conversation {
  flex: 1;
  padding: 1.2rem 1rem 9.5rem;
  overflow-y: auto;
}

.day-label {
  margin: 0.2rem 0 1.4rem;
  color: #a2a39f;
  font-size: 0.66rem;
  text-align: center;
}

.message {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

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

.message-avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 11px;
  font-size: 0.86rem;
}

.bubble {
  max-width: min(82%, 560px);
  padding: 0.78rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 4px 16px 16px 16px;
  background: var(--assistant);
  box-shadow: 0 4px 18px rgba(20, 22, 18, 0.025);
}

.message.user .bubble {
  border-color: var(--user);
  border-radius: 16px 4px 16px 16px;
  color: white;
  background: var(--user);
}

.bubble p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.bubble p + p {
  margin-top: 0.55rem;
}

.bubble .message-image {
  display: block;
  width: min(100%, 440px);
  max-height: 70dvh;
  margin: -0.35rem -0.45rem 0.65rem;
  border-radius: 12px;
  object-fit: contain;
  background: #efefeb;
}

.image-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.image-actions button,
.image-actions a {
  padding: 0.52rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fafaf8;
  font-size: 0.7rem;
  text-decoration: none;
  cursor: pointer;
}

.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin: 1.2rem 0 0 2.55rem;
}

.starter-grid button {
  min-height: 48px;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.7);
  color: #62645f;
  font-size: 0.76rem;
  text-align: left;
  cursor: pointer;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 52px;
  min-height: 22px;
}

.thinking i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #858780;
  animation: bounce 700ms infinite alternate;
}

.thinking i:nth-child(2) {
  animation-delay: 140ms;
}

.thinking i:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes bounce {
  to {
    transform: translateY(-5px);
    opacity: 0.45;
  }
}

.attachment-bar {
  position: fixed;
  z-index: 25;
  right: 0;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 0;
  display: grid;
  width: min(728px, calc(100% - 2rem));
  grid-template-columns: 44px 1fr 30px;
  gap: 0.65rem;
  align-items: center;
  margin: auto;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(20, 22, 18, 0.1);
}

.attachment-bar img {
  width: 44px;
  height: 44px;
  border-radius: 9px;
  object-fit: cover;
}

.attachment-bar div {
  display: grid;
  gap: 0.12rem;
}

.attachment-bar strong {
  font-size: 0.75rem;
}

.attachment-bar span {
  color: var(--muted);
  font-size: 0.65rem;
}

.attachment-bar button {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}

.composer {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  width: min(760px, 100%);
  grid-template-columns: 44px 1fr 44px;
  gap: 0.55rem;
  align-items: end;
  margin: auto;
  padding: 0.7rem 1rem max(0.7rem, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(229, 230, 225, 0.86);
  background: rgba(245, 245, 242, 0.96);
  backdrop-filter: blur(18px);
}

.attach-button,
.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
}

.attach-button {
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.25rem;
}

.input-wrap {
  position: relative;
  display: flex;
  min-height: 44px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
}

.input-wrap textarea {
  width: 100%;
  max-height: 124px;
  padding: 0.68rem 2.8rem 0.68rem 0.9rem;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  line-height: 1.45;
}

.voice-button {
  position: absolute;
  right: 0.45rem;
  bottom: 0.55rem;
  display: flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.voice-button span {
  width: 2px;
  height: 8px;
  border-radius: 2px;
  background: #74766f;
}

.voice-button span:nth-child(2) {
  height: 14px;
}

.voice-button.is-listening span {
  animation: voice 500ms infinite alternate;
}

.voice-button.is-listening span:nth-child(2) {
  animation-delay: 100ms;
}

.voice-button.is-listening span:nth-child(3) {
  animation-delay: 200ms;
}

.voice-button.is-processing {
  cursor: wait;
  opacity: 0.48;
}

.voice-button:disabled {
  cursor: wait;
}

@keyframes voice {
  to {
    height: 18px;
  }
}

.send-button {
  border: 0;
  color: white;
  background: var(--accent);
  font-size: 1.15rem;
}

.send-button:disabled {
  opacity: 0.42;
}

@media (min-width: 761px) {
  body {
    background: #e9eae6;
  }

  .app-view {
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
    box-shadow: 0 0 60px rgba(20, 22, 18, 0.05);
  }
}

@media (max-width: 480px) {
  .conversation {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  .starter-grid {
    margin-left: 2.3rem;
  }

  .bubble {
    max-width: 86%;
  }
}
