:root {
  --bg: #f4f7f3;
  --bg-soft: #e8efea;
  --surface: #ffffff;
  --surface-muted: #f9fbf8;
  --text: #223028;
  --muted: #65746d;
  --subtle: #87948e;
  --border: #d8e1db;
  --primary: #3f6655;
  --primary-strong: #31473d;
  --primary-fg: #ffffff;
  --accent: #9d6353;
  --accent-soft: #f0dfd7;
  --plum: #59485f;
  --danger: #a4473f;
  --success: #3f7a5a;
  --shadow: 0 18px 50px rgba(39, 59, 48, 0.12);
  --small-shadow: 0 10px 28px rgba(39, 59, 48, 0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(232, 239, 234, 0.95), rgba(244, 247, 243, 0.96) 42%, #f7f8f4),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 3px solid rgba(157, 99, 83, 0.38);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  box-shadow: 0 0 0 1px rgba(34, 48, 40, 0.04);
}

.screen {
  min-height: 100vh;
}

.auth-screen {
  padding: 18px 16px 26px;
}

.entry-hero {
  display: grid;
  gap: 16px;
  padding: 14px 0 8px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--small-shadow);
}

.brand-mark span {
  width: 22px;
  height: 22px;
  border: 3px solid var(--primary);
  border-right-color: var(--accent);
  border-bottom-color: var(--plum);
  border-radius: 50%;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

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

.hero-copy h1,
.section-head h1,
.consult-room h1 {
  margin-bottom: 10px;
  font-size: 31px;
  line-height: 1.12;
  font-weight: 760;
}

.hero-copy p:not(.eyebrow),
.consult-room p:not(.eyebrow),
.panel-lead,
.boundary-note p,
.modal-panel p {
  color: var(--muted);
  line-height: 1.72;
}

.hero-visual {
  margin: 2px 0 0;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid rgba(63, 102, 85, 0.16);
  background: var(--surface);
  box-shadow: var(--small-shadow);
  aspect-ratio: 1.52;
}

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

.entry-panel,
.boundary-note,
.empty-panel,
.history-item,
.modal-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--small-shadow);
}

.entry-panel {
  display: grid;
  gap: 18px;
  margin-top: 14px;
  padding: 18px;
}

.entry-panel h2 {
  margin-bottom: 8px;
  font-size: 24px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border-radius: 12px;
  background: var(--bg-soft);
}

.tab-button,
.tool-button,
.text-button,
.icon-button,
.send-button,
.primary-button {
  min-height: var(--tap);
  border: 0;
  border-radius: var(--radius-sm);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.tab-button {
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.tab-button.active {
  color: var(--primary-strong);
  background: var(--surface);
  box-shadow: 0 5px 16px rgba(39, 59, 48, 0.08);
}

.auth-form {
  display: grid;
  gap: 9px;
}

.field-label {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.field,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface);
}

.field {
  min-height: 48px;
  padding: 0 14px;
}

.field::placeholder,
textarea::placeholder {
  color: #98a39e;
}

.primary-button {
  width: 100%;
  color: var(--primary-fg);
  background: var(--primary);
  font-weight: 760;
}

.primary-button.ghost {
  margin: 14px 0 24px;
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--border);
}

.primary-button:active,
.tool-button:active,
.send-button:active,
.icon-button:active,
.text-button:active {
  transform: translateY(1px);
}

.error-text {
  min-height: 20px;
  margin: 2px 0 0;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}

.boundary-note {
  margin-top: 14px;
  padding: 16px;
  border-color: rgba(157, 99, 83, 0.28);
  background: linear-gradient(135deg, rgba(240, 223, 215, 0.68), rgba(255, 255, 255, 0.88));
}

.boundary-note strong {
  display: block;
  margin-bottom: 6px;
  color: var(--plum);
}

.boundary-note p {
  margin-bottom: 0;
  font-size: 13px;
}

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

.consult-room {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  gap: 14px;
  padding: calc(14px + env(safe-area-inset-top)) 14px 13px;
  color: var(--primary-fg);
  background:
    linear-gradient(135deg, rgba(49, 71, 61, 0.98), rgba(63, 102, 85, 0.97) 62%, rgba(89, 72, 95, 0.94));
  box-shadow: 0 8px 24px rgba(34, 48, 40, 0.18);
}

.consult-room h1 {
  margin-bottom: 6px;
  font-size: 22px;
}

.consult-room .eyebrow,
.consult-room p,
.consult-room p:not(.eyebrow) {
  color: rgba(255, 255, 255, 0.82);
}

.room-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.credit-badge {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 13px;
  border-radius: 999px;
  color: var(--primary-strong);
  background: rgba(255, 255, 255, 0.92);
  font-weight: 750;
}

.icon-button,
.text-button,
.tool-button {
  border: 1px solid var(--border);
  color: var(--primary-strong);
  background: var(--surface);
  font-weight: 720;
}

.icon-button {
  width: 44px;
  border-radius: 999px;
}

.text-button {
  margin-left: auto;
  padding: 0 14px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
}

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

.message-row {
  display: flex;
  margin-bottom: 12px;
}

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

.bubble {
  max-width: min(84%, 420px);
  padding: 12px 14px;
  border-radius: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 5px 16px rgba(39, 59, 48, 0.06);
  white-space: pre-wrap;
  line-height: 1.72;
}

.message-row.user .bubble {
  color: var(--primary-fg);
  background: var(--primary);
  border-color: rgba(63, 102, 85, 0.2);
}

.bubble.loading {
  color: var(--muted);
}

.empty-panel {
  padding: 18px;
}

.empty-panel h2 {
  margin-bottom: 8px;
  font-size: 22px;
}

.empty-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.72;
}

.starter-grid {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.starter-grid button {
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--primary-strong);
  background: var(--surface-muted);
  text-align: left;
}

.tools {
  display: grid;
  grid-template-columns: 1fr 1fr 1.25fr;
  gap: 8px;
  padding: 10px 10px;
  border-top: 1px solid var(--border);
  background: rgba(244, 247, 243, 0.94);
}

.tool-button {
  padding: 0 12px;
}

.tool-button.strong {
  color: var(--primary-fg);
  background: var(--accent);
  border-color: var(--accent);
}

.composer {
  display: grid;
  grid-template-columns: 1fr 68px;
  gap: 8px;
  align-items: end;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

textarea {
  min-height: 46px;
  max-height: 138px;
  padding: 12px 13px;
  resize: none;
  line-height: 1.5;
}

.send-button {
  color: var(--primary-fg);
  background: var(--primary);
  font-weight: 760;
}

.send-button:disabled {
  color: #87948e;
  background: #e3e9e5;
}

.history-screen {
  padding: 20px 14px;
}

.section-head h1 {
  font-size: 26px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  gap: 5px;
  min-height: 66px;
  padding: 13px 14px;
  color: var(--text);
  text-align: left;
}

.history-title {
  font-weight: 750;
}

.history-time {
  color: var(--muted);
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 35, 30, 0.44);
}

.modal-panel {
  position: relative;
  width: min(100%, 430px);
  padding: 24px 18px 18px;
}

.modal-panel h1 {
  margin-bottom: 8px;
  font-size: 25px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 26px;
}

.wechat-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.wechat-card span {
  color: var(--muted);
  font-size: 13px;
}

.wechat-card strong {
  grid-column: 1;
  color: var(--plum);
  font-size: 21px;
}

.wechat-card button {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translateX(-50%);
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--primary-fg);
  background: rgba(34, 48, 40, 0.92);
  box-shadow: var(--small-shadow);
  text-align: center;
}

.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;
}

[hidden] {
  display: none !important;
}

@media (min-width: 760px) {
  body {
    padding: 28px 0;
  }

  .app-shell {
    min-height: calc(100vh - 56px);
    border-radius: 24px;
    overflow: hidden;
  }

  .auth-screen {
    padding: 24px;
  }

  .entry-hero {
    grid-template-columns: 1.12fr 1fr;
    align-items: end;
  }

  .brand-mark {
    grid-column: 1 / -1;
  }

  .hero-copy h1 {
    max-width: 420px;
    font-size: 38px;
  }

  .hero-visual {
    align-self: center;
  }

  .chat-screen {
    height: calc(100vh - 56px);
    min-height: 760px;
  }
}

@media (max-width: 340px) {
  .hero-copy h1 {
    font-size: 28px;
  }

  .consult-room h1 {
    font-size: 20px;
  }

  .tools {
    grid-template-columns: 1fr 1fr;
  }

  .tools .strong {
    grid-column: 1 / -1;
  }
}

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