:root {
  color-scheme: light;
  --bg: #f3f3f1;
  --header: rgba(255, 255, 255, 0.97);
  --panel: #ffffff;
  --panel-soft: #f7f7f7;
  --note: #ffffff;
  --user: #a9e98e;
  --text: #202120;
  --text-inverse: #111111;
  --muted: #7a7c7a;
  --faint: #a6a8a6;
  --line: rgba(0, 0, 0, 0.065);
  --line-strong: rgba(0, 0, 0, 0.16);
  --primary: #2f7d65;
  --primary-hover: #286b57;
  --danger: #a6474f;
  --shadow: 0 22px 58px rgba(0, 0, 0, 0.12);
  --soft-shadow: none;
  font-family:
    Inter, "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.chat-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
}

.chat-header {
  z-index: 10;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 6px;
  padding: max(9px, env(safe-area-inset-top)) 12px 8px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.header-spacer {
  width: 44px;
  height: 36px;
}

.chat-title {
  min-width: 0;
  text-align: center;
}

.chat-title h1 {
  margin-bottom: 2px;
  font-size: 16px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: 0;
}

.chat-title p {
  position: relative;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--line);
  background: color-mix(in srgb, var(--panel) 74%, transparent);
  color: var(--text);
}

.chat-main {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 12px 18px;
  scroll-behavior: smooth;
}

.messages {
  width: min(100%, 720px);
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

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

.message-row.assistant {
  justify-content: flex-start;
}

.message-row.assistant.continuation {
  margin-top: -6px;
}

.message-column {
  max-width: min(74%, 530px);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.message-column.assistant {
  align-items: flex-start;
}

.avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #dadada;
  color: #ffffff;
  font-size: 15px;
  font-weight: 650;
  line-height: 1;
  user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.avatar.user {
  background: #4f6f64;
}

.message {
  position: relative;
  max-width: 100%;
  padding: 9px 11px;
  border-radius: 7px;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.message.user {
  color: var(--text-inverse);
  background: var(--user);
  box-shadow: none;
}

.message.user::after {
  content: "";
  position: absolute;
  top: 12px;
  right: -4px;
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  background: var(--user);
}

.message.assistant {
  background: var(--note);
  box-shadow: none;
}

.message.assistant::before {
  content: "";
  position: absolute;
  top: 12px;
  left: -4px;
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  background: var(--note);
}

.typing-bubble {
  min-width: 48px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.typing-bubble span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #a3a5a3;
  animation: typing-pulse 1.15s ease-in-out infinite;
  animation-delay: calc(var(--dot-index) * 0.14s);
}

@keyframes typing-pulse {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  35% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

.scene-note {
  padding-left: 2px;
  color: #8a8a8a;
  font-size: 12px;
  line-height: 1.45;
}

.composer {
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 7px;
  padding: 7px 10px max(7px, env(safe-area-inset-bottom));
  background: rgba(250, 250, 249, 0.98);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.composer textarea {
  min-height: 38px;
  max-height: 120px;
  resize: none;
  padding: 8px 11px;
  border: 1px solid #e6e6e3;
  border-radius: 9px;
  outline: none;
  background: #ffffff;
  color: var(--text);
  box-shadow: none;
  line-height: 1.5;
  overflow-y: auto;
}

.composer textarea::placeholder {
  color: var(--faint);
}

.composer textarea:focus {
  border-color: #a8c8bb;
  box-shadow: 0 0 0 3px rgba(47, 125, 101, 0.07);
}

.send-button,
.stop-button {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 38px;
  border-radius: 8px;
}

.send-button,
.primary {
  background: var(--primary);
  color: #ffffff;
  font-weight: 680;
}

.send-button {
  font-size: 14px;
  font-weight: 520;
  line-height: 1;
}

.send-button:disabled {
  background: #d9d9d6;
  color: #ffffff;
  opacity: 1;
}

.send-button:hover,
.send-button:focus-visible,
.primary:hover,
.primary:focus-visible {
  background: var(--primary-hover);
}

.stop-button,
.secondary {
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: #ffffff;
  color: var(--text);
}

.stop-button {
  font-size: 12px;
}

.primary,
.secondary,
.text-button {
  min-height: 34px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
}

.primary,
.secondary {
  padding: 0 13px;
}

.text-button {
  padding: 0 4px;
  background: transparent;
  color: var(--danger);
}

.danger-button {
  min-width: 72px;
  min-height: 34px;
  justify-self: end;
  padding: 0 13px;
  border: 1px solid rgba(166, 71, 79, 0.18);
  border-radius: 8px;
  background: #ffffff;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

.danger-button:hover,
.danger-button:focus-visible {
  background: #fff7f7;
  border-color: rgba(166, 71, 79, 0.28);
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.14);
}

.settings-drawer {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 21;
  width: min(92vw, 540px);
  max-height: min(88vh, 600px);
  transform: translate(-50%, -50%);
  display: block;
  overflow: hidden;
  border-radius: 14px;
  background: #f5f5f3;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.14);
}

.settings-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: inherit;
  padding: 18px 20px 20px;
  overflow-y: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-head h2 {
  margin-bottom: 3px;
  font-size: 17px;
  line-height: 1.2;
  font-weight: 620;
  letter-spacing: 0;
}

.drawer-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input,
select {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  outline: none;
  background: #f8f8f7;
  color: var(--text);
}

input:focus,
select:focus {
  border-color: rgba(26, 173, 25, 0.28);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(26, 173, 25, 0.07);
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-section {
  display: grid;
  gap: 6px;
}

.settings-section-label {
  margin: 0 4px;
  color: #8d8f8d;
  font-size: 11px;
  line-height: 1.35;
}

.settings-group {
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  background: #ffffff;
}

.account-row,
.settings-row {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(130px, 0.75fr) minmax(210px, 1.25fr);
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.account-row {
  grid-template-columns: 44px minmax(0, 1fr);
}

.settings-row.last {
  border-bottom: 0;
}

.settings-row.stacked-row {
  min-height: auto;
  grid-template-columns: minmax(0, 1fr);
  padding-bottom: 6px;
  border-bottom: 0;
}

.settings-row strong,
.account-main strong {
  display: block;
  color: #151515;
  font-size: 13px;
  line-height: 1.25;
  font-weight: 560;
  letter-spacing: 0;
}

.settings-row p,
.account-main p {
  margin: 4px 0 0;
  color: #929292;
  font-size: 11px;
  line-height: 1.45;
}

.avatar-picker {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
  background: transparent;
}

.avatar.preview {
  width: 44px;
  height: 44px;
  border-radius: 8px;
}

.wechat-field {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.wechat-field span {
  color: #8c8c8c;
  font-size: 11px;
}

.compact-field input {
  max-width: none;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.insight-list,
.letter-view {
  padding: 0 18px 14px;
}

.insight-item {
  padding: 10px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.045);
}

.insight-item:first-child {
  border-top: 0;
}

.insight-item strong,
.letter-paper strong {
  display: block;
  color: #191919;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 560;
}

.insight-item p,
.letter-paper p,
.empty-insight {
  margin: 4px 0 0;
  color: #767676;
  font-size: 12px;
  line-height: 1.6;
}

.insight-meta {
  display: block;
  margin-top: 4px;
  color: #a0a0a0;
  font-size: 11px;
  line-height: 1.4;
}

.empty-insight {
  padding: 8px 0 2px;
}

.letter-paper {
  padding: 12px;
  border-radius: 10px;
  background: #f7f7f7;
}

.letter-paper p {
  white-space: pre-wrap;
  color: #3b3b3b;
}

.local-privacy-note {
  margin: 0;
  color: #8f8f8f;
  text-align: center;
  font-size: 11px;
  line-height: 1.5;
}

.empty {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 30;
  width: min(92vw, 420px);
  padding: 10px 12px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: #24211d;
  color: #fffaf2;
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.5;
}

.fatal-fallback {
  width: min(100% - 40px, 360px);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  align-content: center;
  gap: 12px;
  text-align: center;
}

.fatal-fallback h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
  font-weight: 650;
}

.fatal-fallback p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.fatal-fallback button {
  width: fit-content;
  min-height: 36px;
  margin: 4px auto 0;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 560;
}

@media (min-width: 780px) {
  .chat-header,
  .composer {
    padding-left: max(12px, calc((100vw - 720px) / 2));
    padding-right: max(12px, calc((100vw - 720px) / 2));
  }

  .chat-main {
    padding-top: 28px;
  }
}

@media (max-width: 420px) {
  .chat-header {
    padding-right: 10px;
    padding-left: 10px;
  }

  .chat-main {
    padding-right: 12px;
    padding-left: 12px;
  }

  .message-column {
    max-width: calc(100% - 58px);
  }

  .message {
    padding: 9px 11px;
    font-size: 14px;
  }

  .avatar {
    width: 36px;
    height: 36px;
  }

  .composer {
    padding-right: 10px;
    padding-left: 10px;
  }
}

@media (max-width: 760px) {
  .settings-drawer {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-height: 100vh;
    height: 100vh;
    transform: none;
    border-radius: 0;
  }

  .settings-content {
    padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
    gap: 14px;
  }

  .drawer-head h2 {
    font-size: 18px;
  }

  .settings-form {
    gap: 12px;
  }
}

@media (max-width: 520px) {
  .settings-row {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
    padding: 11px 13px;
  }

  .account-row {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .row-actions {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-main {
    scroll-behavior: auto;
  }

  .typing-bubble span {
    animation: none;
    opacity: 0.65;
  }
}

.product-notice {
  max-width: 560px;
  margin: 16px auto;
  padding: 0 16px;
  color: #777;
  font-size: 12px;
  line-height: 1.65;
  text-align: center;
  overflow-wrap: anywhere;
}

:root { -webkit-text-size-adjust: 100%; }
.remember-key { display: flex; align-items: center; gap: 8px; font-size: 13px; line-height: 1.5; }
.remember-key input { width: 16px; height: 16px; accent-color: var(--primary); }
.key-note { display: block; color: var(--muted); font-size: 11px; }
@media (max-width: 640px) {
  input, textarea, select { font-size: 16px !important; }
  .chat-shell { height: var(--app-height, 100dvh); }
  .settings-drawer { height: var(--app-height, 100dvh); max-height: var(--app-height, 100dvh); }
}
