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

:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #111;
  --panel: #ffffff;
  --muted: #737979;
}

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

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

body {
  margin: 0;
  font-family: Tahoma, Arial, Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  padding: 12px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

h1 {
  margin: 0;
  font-size: 18px;
  white-space: nowrap;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

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

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

.hero-quote {
  position: absolute;
  top: 21%;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 640px);
  text-align: center;
  font-family: "Ma Shan Zheng", Tahoma, Arial, sans-serif;
  font-size: clamp(20px, 4vw, 34px);
  color: rgba(32, 38, 37, 0.74);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  pointer-events: none;
  line-height: 1.35;
  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;
}

.chat-modal-card {
  width: min(92vw, 620px);
  height: 90dvh;
  max-height: 90dvh;
  background: rgba(245, 245, 245, 0.92);
  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;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-card {
  width: min(92vw, 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: 18px;
}

.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-item:active {
  background: rgba(0, 0, 0, 0.07);
}

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

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

.history-name {
  font-size: 15px;
  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: 15px;
  line-height: 1.8;
  white-space: pre-line;
}

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

.profile-list,
.profile-detail {
  background: #f5f6f6;
  border-radius: 10px;
  padding: 10px;
  min-height: 120px;
  max-height: 34dvh;
  overflow: auto;
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.profile-card {
  width: min(92vw, 700px);
  background: rgba(245, 245, 245, 0.96);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 14px;
  min-height: min(76vh, 700px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

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

.profile-list {
  min-height: 78px;
  max-height: 20dvh;
  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: 14px;
  color: #333;
  cursor: pointer;
  font-weight: 500;
}

.profile-chip.active {
  border-color: #333;
  background: #e8e8e8;
  color: #111;
}

.profile-detail {
  min-height: 220px;
  max-height: 34dvh;
  white-space: pre-wrap;
  line-height: 1.5;
}

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

.quick-btn {
  background: #f0f4ff;
  color: #3b5998;
  border: 1px solid #d4ddf7;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.quick-btn:hover {
  background: #dbe4ff;
  border-color: #98b0f0;
  transform: translateY(-1px);
  color: #2a4494;
}

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

input {
  flex: 1;
  border: 1px solid #d6d9d9;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
}

button {
  border: 0;
  border-radius: 8px;
  background: #111;
  color: #fff;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

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

.ghost-btn {
  background: #ebeeee;
  color: #232626;
}

.memory-preview {
  background: #eef2ff;
  color: #2a3180;
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  flex-shrink: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-avatar {
  width: 76px;
  height: 76px;
  margin: 2px auto 6px;
  border: 1px solid #d8dbdb;
  object-fit: cover;
  background: #fff;
  flex-shrink: 0;
}

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

.chat-close {
  align-self: flex-end;
  flex-shrink: 0;
}

.chat-status {
  background: #f0f4f4;
  color: #4a5252;
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  flex-shrink: 0;
}

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

.msg {
  margin: 0 0 14px 0;
  line-height: 1.7;
  letter-spacing: 0.2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg-user {
  color: #1f3d8f;
}

.hidden {
  display: none;
}

@media (max-width: 768px) {
  .app {
    max-width: 430px;
  }

  .chat-modal-card,
  .history-card,
  .profile-card {
    width: 94vw;
  }

  .chat-modal-card {
    height: 92dvh;
    max-height: 92dvh;
  }

  .hero-quote {
    top: 18%;
  }

  /* Mobile readable but no overflow */
  h1 {
    font-size: 16px;
  }

  h2 {
    font-size: 18px;
  }

  .scene-hint {
    font-size: 13px;
    padding: 8px 12px;
  }

  button {
    font-size: 14px;
    padding: 9px 10px;
    white-space: nowrap;
  }

  input {
    font-size: 16px;
  }

  .chat-log {
    font-size: 16px;
    line-height: 1.75;
  }

  .profile-list,
  .profile-detail {
    font-size: 14px;
  }

  .muted,
  .memory-preview,
  .chat-status {
    font-size: 13px;
  }

  .profile-chip {
    font-size: 13px;
  }

  .top-actions {
    gap: 6px;
  }

  .chat-log {
    padding-right: 12px;
  }
}

@media (min-width: 769px) {
  .scene-wrap {
    height: calc(88dvh - 58px);
  }
}
