@import url("https://fonts.googleapis.com/css2?family=Ma+Shan+Zheng&display=swap");

:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #111111;
  --panel: #ffffff;
  --muted: #737979;
  --accent: #3b5998;
  --accent-soft: #f0f4ff;
  --line: #e5e5e5;
}

* {
  box-sizing: border-box;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: Tahoma, Arial, Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
  background: #ffffff;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-size: 19px;
  white-space: nowrap;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 1px;
}

.scene-wrap {
  position: relative;
  height: calc(100dvh - 58px);
  width: 100%;
  overflow: hidden;
}

#crowd-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.scene-hint {
  position: absolute;
  top: auto;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  padding: 6px 16px;
  border-radius: 999px;
  z-index: 4;
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
  color: #6b5d4d;
}

.hero-quote {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 620px);
  text-align: center;
  font-family: "Ma Shan Zheng", "PingFang SC", serif;
  font-size: clamp(20px, 4vw, 32px);
  color: rgba(62, 50, 36, 0.6);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  pointer-events: none;
  line-height: 1.4;
  letter-spacing: 1px;
}

.chat-modal,
.history-panel,
.profile-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(40, 30, 20, 0.16);
}

.chat-modal-card {
  width: min(94vw, 620px);
  height: 88dvh;
  max-height: 88dvh;
  background: rgba(245, 245, 245, 0.95);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  animation: pop-in 0.22s ease;
}

@keyframes pop-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.chat-close {
  align-self: flex-end;
  background: transparent;
  color: #7a6c5c;
  border: 1px solid var(--line);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
}

.chat-avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 4px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  object-fit: cover;
  background: #f0e7da;
  flex-shrink: 0;
  display: block;
}

.chat-meta {
  text-align: center;
  flex-shrink: 0;
}

.chat-meta strong {
  font-size: 17px;
}

.chat-meta .muted {
  font-size: 12px;
  color: var(--muted);
  margin: 3px 0 0;
}

.memory-preview {
  background: #f5ead9;
  color: #8a6a45;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  flex-shrink: 0;
  text-align: center;
}

.chat-log {
  background: #f4eee4;
  border-radius: 12px;
  padding: 12px;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

.chat-log .msg {
  margin: 0 0 10px;
}

.chat-log .msg-user {
  color: #4a5a44;
}

.chat-log .msg-ai {
  color: #3a2f22;
}

.chat-status {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  min-height: 18px;
}

.quick-replies {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding: 2px 0;
  min-height: 0;
}

.quick-btn {
  background: #fdf6ec;
  color: #9a6b3f;
  border: 1px solid #ecdcc6;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.quick-btn:hover {
  background: #f5e2cc;
  border-color: #d9b98f;
  transform: translateY(-1px);
}

.chat-form {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

input {
  flex: 1;
  border: 1px solid #d9cfc0;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 15px;
  outline: none;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}

input:focus {
  border-color: var(--accent);
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.ghost-btn {
  background: #efe6d8;
  color: #6d5d4a;
  font-weight: 500;
}

/* History panel */
.history-card {
  width: min(94vw, 620px);
  min-height: min(50vh, 380px);
  max-height: 88dvh;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-head h2 {
  margin: 0;
  font-size: 17px;
}

.profile-card {
  width: min(94vw, 700px);
  background: rgba(255, 255, 255, 0.97);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 16px;
  min-height: min(76vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.profile-head,
.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.profile-head h2 {
  margin: 0;
  font-size: 16px;
}

.profile-row input {
  flex: 1;
}

.profile-list {
  flex: 0 1 auto;
  max-height: 22dvh;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}

.profile-chip {
  background: #f5f5f5;
  border: 1px solid #ccc;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  color: #333;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s ease;
}

.profile-chip:hover {
  background: #f0f4ff;
  border-color: #98b0f0;
}

.profile-chip.active {
  border-color: #3b5998;
  background: #f0f4ff;
  color: #3b5998;
}

.profile-detail {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  background: #f5f6f6;
  border-radius: 10px;
  padding: 14px;
  font-size: 14px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.profile-summary {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.profile-summary img {
  width: 76px;
  height: 76px;
  border-radius: 10px;
  border: 1px solid #e0e0e0;
  flex-shrink: 0;
  background: #fff;
  object-fit: cover;
}

.profile-summary-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}

.profile-summary-meta {
  font-size: 12px;
  color: #666;
  margin: 3px 0 0;
}

.profile-summary-intro {
  font-size: 13px;
  color: #444;
  line-height: 1.65;
  margin: 6px 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.profile-full-detail {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.profile-toggle-btn {
  align-self: flex-start;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #d0d0d0;
  background: #fff;
  color: #222;
  cursor: pointer;
  font-size: 12px;
}

.profile-action-bar {
  flex-shrink: 0;
  padding: 8px 0 0;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.profile-chat-btn {
  display: block;
  width: 100%;
  padding: 12px;
  background: #3b5998;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.profile-chat-btn:hover {
  background: #2a4494;
  transform: translateY(-1px);
}

.profile-reset-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  background: #ffffff;
  color: #a0563f;
  border: 1px solid #d8b0a0;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.profile-reset-btn:hover {
  background: #fdf3ef;
  border-color: #c0806a;
  transform: translateY(-1px);
}

.profile-empty {
  text-align: center;
  color: #999;
  padding: 30px 20px;
  font-size: 13px;
}

.history-list {
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.history-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.history-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid #e4d9c8;
  object-fit: cover;
  background: #f0e7da;
  flex-shrink: 0;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-name {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}

.history-preview {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  flex-shrink: 0;
  text-align: right;
}

.history-count {
  font-size: 11px;
  color: var(--muted);
}

.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-line;
}

.hidden {
  display: none !important;
}
