:root {
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #e8edf7;
  background: #0b1020;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(88, 120, 255, 0.18), transparent 34rem),
    #0b1020;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.app {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 64px;
}

.page-header,
.section-title,
.poll-actions,
.inline-field,
.composer {
  display: flex;
  align-items: center;
}

.page-header {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.65rem, 4vw, 2.45rem);
  letter-spacing: -0.04em;
}

h2 {
  font-size: 1rem;
}

.eyebrow {
  margin-bottom: 6px;
  color: #8ea4ff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.panel {
  margin-top: 16px;
  padding: 22px;
  border: 1px solid #273250;
  border-radius: 16px;
  background: rgba(17, 24, 43, 0.92);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
}

.section-title {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-title > span,
.poll-actions {
  color: #94a0b8;
  font-size: 0.82rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.wide {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  color: #aeb9cf;
  font-size: 0.86rem;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #34415f;
  border-radius: 9px;
  outline: none;
  color: #f3f6fc;
  background: #0d1426;
  transition: border-color 120ms, box-shadow 120ms;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 78px;
  padding: 11px 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #6f8cff;
  box-shadow: 0 0 0 3px rgba(111, 140, 255, 0.15);
}

.inline-field {
  gap: 8px;
}

.primary,
.secondary,
.danger,
.ghost {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 9px;
  white-space: nowrap;
}

.primary {
  color: white;
  background: #627ef2;
}

.primary:hover {
  background: #718bfa;
}

.secondary {
  border: 1px solid #405071;
  color: #d9e1f2;
  background: #202b42;
}

.danger {
  border: 1px solid #75404b;
  color: #ffc3ca;
  background: #41232b;
}

.ghost {
  color: #aeb9cf;
  background: transparent;
}

.status {
  padding: 7px 12px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
}

.status.idle {
  color: #9aa8c3;
}

.status.loading {
  color: #f8c969;
}

.status.success {
  color: #68dda6;
}

.status.error {
  color: #ff8896;
}

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

.affinity-state {
  color: #c4b5fd;
  font-weight: 600;
}

.messages {
  min-height: 280px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 16px;
  border: 1px solid #273250;
  border-radius: 12px;
  background: #0d1426;
}

.empty-state {
  padding: 96px 12px;
  color: #75829c;
  text-align: center;
}

.message {
  width: fit-content;
  max-width: min(78%, 700px);
  margin-bottom: 12px;
  padding: 11px 13px;
  border: 1px solid #33405d;
  border-radius: 4px 13px 13px;
  background: #1a2439;
}

.message.assistant,
.message.human {
  margin-right: auto;
  border-radius: 4px 13px 13px 13px;
}

.message.user {
  margin-left: auto;
  border-color: #536dd0;
  border-radius: 13px 4px 13px 13px;
  background: #344d9b;
}

.message.context {
  margin: 0 auto 12px;
  border-color: #8a6a22;
  background: #2b2618;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: #aab6cc;
  font-size: 0.72rem;
  user-select: none;
}

.message-meta .copy-message {
  margin-left: auto;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid #46557a;
  border-radius: 6px;
  color: #d5def2;
  background: #24314d;
  font-size: 0.72rem;
  cursor: pointer;
}

.message-meta .copy-message:hover {
  border-color: #6f84b8;
  background: #2d3d60;
}

.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
  user-select: text;
  -webkit-user-select: text;
}

.message-image {
  display: block;
  width: min(100%, 240px);
  margin-top: 10px;
  border-radius: 10px;
  object-fit: cover;
}

.message-link {
  color: #9ec1ff;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.message-link:hover {
  color: #c7dbff;
}

.map-card {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #3d527d;
  border-radius: 10px;
  background: #182338;
}

.map-card-title {
  margin-bottom: 8px;
  color: #d7e2f7;
  font-size: 0.85rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

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

.map-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid #536dd0;
  border-radius: 7px;
  color: #e8edf7;
  background: #2a3f78;
  font-size: 0.78rem;
  text-decoration: none;
  cursor: pointer;
}

.map-action.secondary {
  border-color: #46557a;
  background: #24314d;
}

.map-action:hover {
  border-color: #7b93df;
  background: #35519a;
}

.map-action.secondary:hover {
  border-color: #6f84b8;
  background: #2d3d60;
}

.map-embed {
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid #334265;
  border-radius: 8px;
  background: #0f1524;
}

.map-embed iframe {
  display: block;
  width: 100%;
  height: 260px;
  border: 0;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 10px;
  margin-top: 16px;
}

.composer-toolbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.composer-toolbar label {
  margin: 0;
}

.emoji-toggle {
  min-height: 32px;
  padding: 4px 12px;
}

.emoji-panel {
  grid-column: 1 / -1;
  padding: 10px;
  border: 1px solid #334265;
  border-radius: 10px;
  background: #121a2e;
}

.emoji-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.emoji-tab {
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid #46557a;
  border-radius: 999px;
  color: #c7d3ea;
  background: #1c2740;
  font-size: 0.78rem;
}

.emoji-tab:hover {
  border-color: #6f84b8;
}

.emoji-tab.active {
  border-color: #6f84b8;
  color: #eef3ff;
  background: #2d3d60;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 4px;
  max-height: 168px;
  overflow: auto;
}

.emoji-item {
  min-height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  color: inherit;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
}

.emoji-item:hover {
  border-color: #536dd0;
  background: #24314d;
}

.composer > textarea {
  grid-column: 1;
}

.composer > #sendMessage {
  height: 78px;
}

.error-box {
  margin-bottom: 14px;
  padding: 11px 13px;
  border: 1px solid #7c3947;
  border-radius: 9px;
  color: #ffd0d5;
  background: #3a1d25;
  white-space: pre-wrap;
}

pre {
  max-height: 310px;
  margin: 0;
  overflow: auto;
  color: #b9c7e2;
  font: 0.82rem/1.55 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 20px, 1080px);
    padding-top: 22px;
  }

  .page-header,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .wide {
    grid-column: auto;
  }

  .poll-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .message {
    max-width: 92%;
  }
}
