:root {
  color-scheme: dark;
  --bg: #111412;
  --panel: #191c1a;
  --line: #30362f;
  --text: #ece8dc;
  --muted: #a9afa4;
  --accent: #d2b56f;
  --accent-2: #76b7a4;
  --danger: #e07a6f;
  --chat-font-size: 14px;
  --control-font-size: 13px;
  --rp-action-color: #8ec5d6;
  --rp-thought-color: #b9a7e8;
  --rp-expression-color: #e8a58f;
  --rp-speech-color: #f1d58a;
  --user-message-color: #e8e2d2;
  --assistant-name: "G4 MeroMero";
  --user-name: "你";
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  overflow: hidden;
}

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

.app {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr) minmax(260px, 320px);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.panel-scroll {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.app-mark svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: var(--control-font-size);
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #101210;
  color: var(--text);
  outline: none;
  border-radius: 6px;
  font-size: var(--control-font-size);
  font-weight: 400;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent-2);
}

#systemPrompt,
#openingScene {
  height: 170px;
  min-height: 130px;
  max-height: 240px;
  resize: none;
  padding: 12px;
  line-height: 1.5;
}

.seed-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#characterSeed {
  height: 92px;
  min-height: 76px;
  max-height: 150px;
  resize: vertical;
  padding: 10px;
  line-height: 1.5;
}

.seed-actions {
  display: grid;
  grid-template-columns: 108px 1fr;
  align-items: center;
  gap: 10px;
}

#analyzeCharacter {
  height: 34px;
  color: #19150a;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

#analyzeStatus {
  min-width: 0;
  color: var(--muted);
  font-size: var(--control-font-size);
}

.profile-panel,
.personality-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-list {
  display: grid;
  gap: 7px;
}

.profile-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(68px, 82px) 1fr;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.profile-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: var(--control-font-size);
  font-weight: 700;
  white-space: nowrap;
}

.profile-row input,
.profile-row select {
  height: 34px;
  min-width: 0;
  padding: 0 9px;
}

select {
  appearance: auto;
  color: var(--text);
}

.segmented {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.segmented.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segmented.five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.segmented button {
  height: 32px;
  min-width: 0;
  padding: 0 4px;
  border-color: #3a4038;
  background: #101210;
  color: var(--muted);
  font-size: var(--control-font-size);
  font-weight: 400;
  white-space: nowrap;
}

.segmented button.active {
  border-color: var(--accent);
  background: #2a2413;
  color: var(--text);
  font-weight: 700;
}

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

.section-head span {
  color: var(--muted);
  font-size: var(--control-font-size);
  font-weight: 700;
}

#resetPersonality {
  width: auto;
  height: 28px;
  padding: 0 10px;
  font-size: var(--control-font-size);
}

.microcopy {
  margin: 0;
  line-height: 1.5;
}

.style-preview {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid #3a4038;
  border-radius: 6px;
  background: #101210;
  color: var(--muted);
  font-size: var(--control-font-size);
  line-height: 1.55;
}

.style-preview strong {
  color: var(--accent);
}

.style-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.style-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid #3a4038;
  border-radius: 999px;
  background: #171b17;
  color: #c7cec2;
  font-size: var(--control-font-size);
  line-height: 1.2;
}

.trait-list {
  display: grid;
  gap: 7px;
}

.trait-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(86px, 1fr) 126px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #141714;
  padding: 7px 8px;
}

.trait-label {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.trait-name {
  color: var(--text);
  font-size: var(--control-font-size);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trait-help {
  position: relative;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #485046;
  border-radius: 50%;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  cursor: help;
  user-select: none;
}

.trait-help:hover::after,
.trait-help:focus::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 18px;
  top: -8px;
  z-index: 20;
  width: min(260px, 68vw);
  padding: 9px 10px;
  border: 1px solid #485046;
  border-radius: 6px;
  background: #101210;
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-line;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.trait-levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 0;
}

.trait-level {
  height: 28px;
  min-width: 0;
  padding: 0;
  border-color: #3a4038;
  background: #101210;
  color: var(--muted);
  font-size: var(--control-font-size);
  font-weight: 400;
}

.trait-level.active {
  border-color: var(--accent);
  background: #2a2413;
  color: var(--text);
  font-weight: 700;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.sampler-settings.hidden {
  display: none;
}

.display-settings {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.role-manager,
.global-settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.global-settings {
  width: 100%;
  margin-top: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px 10px;
  padding-top: 8px;
  font-size: 12px;
}

.global-settings .sampler-settings {
  display: contents;
}

.global-settings .sampler-settings.hidden {
  display: none;
}

.field-user-name {
  order: 1;
}

.field-temperature {
  order: 2;
}

.field-font-size {
  order: 3;
}

.field-max-tokens {
  order: 4;
}

.field-top-p {
  order: 5;
}

.field-min-p {
  order: 6;
}

.global-settings .field {
  gap: 4px;
}

.global-settings .field span,
.global-settings .field-label {
  font-size: 12px;
  line-height: 1.2;
}

.global-settings input {
  height: 30px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 12px;
}

.global-settings .trait-help {
  width: 13px;
  height: 13px;
  font-size: 9px;
}

.role-manager-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.role-manager-head h2 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
}

#createRole {
  width: auto;
  height: 32px;
  padding: 0 10px;
  color: #19150a;
  background: var(--accent);
  border-color: var(--accent);
  font-size: var(--control-font-size);
  font-weight: 700;
}

.role-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: calc((100% - 16px) / 3);
  grid-template-columns: none;
  gap: 8px;
  width: 100%;
  height: 112px;
  min-height: 112px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  padding: 8px;
  border: 1px solid #30362f;
  border-radius: 8px;
  background: #111411;
  scrollbar-width: thin;
}

.role-empty {
  grid-column: 1 / -1;
  min-width: 100%;
  min-height: 90px;
  display: grid;
  place-items: center;
  border: 1px dashed #3a4038;
  border-radius: 8px;
  color: var(--muted);
  font-size: var(--control-font-size);
}

.role-tile {
  position: relative;
  min-width: 0;
  min-height: 90px;
  display: grid;
  grid-template-rows: 52px auto;
  justify-items: center;
  align-items: center;
  gap: 5px;
  padding: 8px 5px 6px;
  border: 1px solid #343a33;
  border-radius: 8px;
  background: #151915;
  cursor: pointer;
}

.role-tile:hover,
.role-tile.active {
  border-color: var(--accent);
  background: #1d211a;
}

.role-avatar,
.city-role-photo,
.role-avatar-preview {
  display: grid;
  place-items: center;
  border: 1px solid #485046;
  background-color: #141714;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  color: var(--accent);
  font-weight: 700;
  overflow: hidden;
}

.role-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 20px;
}

.role-tile-name {
  max-width: 100%;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-detail-button {
  position: absolute;
  right: 4px;
  top: 4px;
  width: auto;
  height: 22px;
  padding: 0 5px;
  border-color: rgba(210, 181, 111, 0.55);
  background: rgba(16, 18, 16, 0.86);
  color: var(--accent);
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
}

.selected-role-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111411;
  padding: 10px 12px;
  width: 100%;
}

.city-role-photo {
  width: 100%;
  height: auto;
  min-height: 180px;
  flex: 1 1 auto;
  margin-top: 10px;
  border-radius: 8px;
  border: 1px dashed #485046;
  background-color: #0f120f;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 12px;
  line-height: 1.2;
}

.city-role-photo.has-photo {
  border-style: solid;
  color: transparent;
}

.selected-role-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.selected-role-info strong {
  color: var(--text);
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-role-info span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.selected-role-summary {
  margin: 0;
  color: #c7cec2;
  font-size: 12px;
  line-height: 1.45;
}

.role-summary-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}

.role-summary-tags span {
  max-width: 100%;
  padding: 2px 7px 3px;
  border: 1px solid rgba(210, 181, 111, 0.36);
  border-radius: 999px;
  background: rgba(210, 181, 111, 0.08);
  color: var(--accent);
  font-size: 11px;
  line-height: 1.2;
}

.role-summary-style,
.role-summary-desc {
  margin: 0;
}

.role-summary-style strong {
  color: var(--text);
}

.role-summary-desc {
  margin-top: 6px;
  color: var(--muted);
}

input {
  height: 38px;
  padding: 0 10px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
  flex: 0 0 auto;
  width: 100%;
}

.actions button {
  height: 34px;
  font-size: 13px;
  font-weight: 700;
}

button {
  height: 40px;
  border: 1px solid var(--line);
  background: #20251f;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  color: #73786f;
}

#send {
  background: var(--accent);
  color: #19150a;
  border-color: var(--accent);
  font-weight: 700;
}

#stop:not(:disabled) {
  color: var(--danger);
}

.chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 78px auto;
  overflow: hidden;
}

.messages {
  overflow: auto;
  padding: 26px clamp(18px, 4vw, 56px);
  display: block;
  font-size: var(--chat-font-size);
}

.empty {
  margin: auto;
  max-width: 560px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}

.msg {
  width: min(1040px, 100%);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
  line-height: 1.65;
  white-space: normal;
  overflow-wrap: anywhere;
  margin: 0 auto;
}

.msg.user {
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--user-message-color) 44%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--user-message-color) 5%, transparent);
  color: var(--user-message-color);
}

.msg.assistant {
  color: #e3e7dd;
}

.msg-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.msg-avatar {
  position: relative;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid #59614f;
  border-radius: 50%;
  background-color: #141714;
  background-position: center 24%;
  background-size: cover;
  background-repeat: no-repeat;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.msg-avatar.has-photo {
  color: transparent;
}

.msg-avatar.loading::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px solid rgba(210, 181, 111, 0.18);
  border-top-color: var(--accent);
  border-right-color: rgba(118, 183, 164, 0.8);
  border-radius: 50%;
  animation: avatarHaloSpin 0.9s linear infinite;
}

@keyframes avatarHaloSpin {
  to {
    transform: rotate(360deg);
  }
}

.msg-name {
  color: #c7cec2;
  font-weight: 700;
}

.msg-environment {
  color: #8f978d;
  font-size: 12px;
}

.msg-body {
  white-space: pre-wrap;
}

.msg.pending .msg-body:empty {
  display: none;
}

.msg.assistant .rp-speech {
  color: var(--rp-speech-color);
}

.msg.assistant .rp-thought {
  color: var(--rp-thought-color);
}

.msg.assistant .rp-action,
.msg.assistant .rp-activity {
  color: var(--rp-action-color);
}

.msg.assistant .rp-expression,
.msg.assistant .rp-status {
  color: var(--rp-expression-color);
}

.msg.assistant .rp-memory {
  color: #cdb7ea;
}

.msg.system {
  width: min(1040px, 100%);
  color: var(--muted);
}

.msg::before {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.msg.user::before {
  content: var(--user-name);
}

.msg.assistant::before {
  content: none;
  display: none;
}

.msg.system::before {
  content: "\7cfb\7edf";
}

.suggestions {
  height: 78px;
  min-height: 78px;
  padding: 8px clamp(12px, 3vw, 38px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  overflow: hidden;
  background: #111411;
}

.suggestions:empty {
  display: grid;
}

.suggestions.loading {
  display: block;
  width: 100%;
  margin: 0;
  padding: 16px clamp(12px, 3vw, 38px);
}

.suggestion {
  height: 62px;
  max-height: 62px;
  min-height: 0;
  padding: 7px 10px;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border-color: #3a4038;
  background: #171b17;
  contain: paint;
}

.suggestion-text {
  display: -webkit-box;
  max-height: calc(1.28em * 3);
  line-height: 1.28;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  overflow-wrap: anywhere;
}

.suggestion:hover {
  background: #222820;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
  padding: 10px clamp(12px, 3vw, 38px) 12px;
  border-top: 1px solid var(--line);
  background: #121512;
}

#input {
  min-height: 46px;
  max-height: 180px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
  font-size: var(--chat-font-size);
}

.composer-actions {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
}

.composer-actions button {
  width: 100%;
  height: auto;
  min-height: 36px;
}

#silence {
  border-color: #485046;
  background: #101210;
  color: #c7cec2;
  font-weight: 700;
}

#silence:hover:not(:disabled) {
  border-color: var(--accent-2);
  color: var(--accent-2);
  background: #17211d;
}

.city-panel {
  border-left: 1px solid var(--line);
  background: #151916;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

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

.city-head h2 {
  margin: 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.2;
}

.city-head p {
  margin-top: 4px;
  font-size: 12px;
}

#refreshCity {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 17px;
}

.city-map {
  position: relative;
  flex: 0 0 clamp(210px, 34vh, 300px);
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: url("/static/town-map.png?v=rp-town-map-v2-20260703") center / cover no-repeat, #9edb72;
}

.city-map::before,
.city-map::after {
  content: "";
  position: absolute;
  pointer-events: none;
  display: none;
}

.city-map::before {
  left: -18%;
  top: 43%;
  width: 92%;
  height: 22px;
  transform: rotate(24deg);
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(108, 169, 181, 0.28), rgba(108, 169, 181, 0.45), transparent);
  box-shadow: 0 0 18px rgba(95, 156, 170, 0.18);
}

.city-map::after {
  right: -22%;
  bottom: -18%;
  width: 70%;
  height: 58%;
  border-radius: 50% 0 0 0;
  border-left: 2px solid rgba(211, 184, 116, 0.34);
  border-top: 2px solid rgba(211, 184, 116, 0.24);
  background: radial-gradient(circle at 45% 48%, rgba(92, 160, 174, 0.38), rgba(42, 83, 96, 0.18) 56%, transparent 57%);
}

.city-place {
  position: absolute;
  z-index: 2;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #2f6e50;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  box-shadow: 0 5px 12px rgba(40, 82, 52, 0.22);
  pointer-events: none;
}

.city-place.selected {
  border-color: #fff7bf;
  color: #174633;
  background: #fff8d7;
  box-shadow: 0 0 0 4px rgba(255, 245, 159, 0.38), 0 8px 18px rgba(40, 82, 52, 0.32);
}

.city-place.character-here {
  border-color: #fff7bf;
  color: #174633;
  box-shadow: 0 0 0 5px rgba(255, 224, 86, 0.45), 0 8px 18px rgba(40, 82, 52, 0.32);
}

.city-place.user-here::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1fae8a;
  border: 1px solid #ffffff;
}

.role-location-dot {
  position: absolute;
  z-index: 5;
  left: var(--x);
  top: var(--y);
  transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px)));
  width: 12px;
  height: 12px;
  display: grid;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--role-color);
  padding: 0;
  color: transparent;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.72), 0 4px 10px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.role-location-dot.active {
  width: 16px;
  height: 16px;
  border-color: #ffffff;
  background: #ff315f;
  box-shadow: 0 0 0 3px #151915, 0 0 0 7px rgba(255, 49, 95, 0.38), 0 8px 18px rgba(0, 0, 0, 0.58);
  animation: roleDotFloat 1.8s ease-in-out infinite;
}

.role-location-dot.active::after {
  content: "";
  position: absolute;
  inset: -7px;
  border: 1px solid rgba(255, 49, 95, 0.72);
  border-radius: 50%;
  animation: roleDotPulse 1.8s ease-out infinite;
}

@keyframes roleDotFloat {
  0%, 100% {
    margin-top: 0;
  }
  50% {
    margin-top: -3px;
  }
}

@keyframes roleDotPulse {
  0% {
    opacity: 0.78;
    transform: scale(0.65);
  }
  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

.city-place span {
  position: absolute;
  left: 50%;
  top: 29px;
  transform: translateX(-50%);
  width: max-content;
  max-width: 76px;
  padding: 2px 6px 3px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 999px;
  background: rgba(82, 181, 86, 0.92);
  color: #ffffff;
  font-size: 9px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  pointer-events: none;
  white-space: normal;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
}

.city-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111411;
  padding: 12px;
}

.memory-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.city-card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.city-card-title span {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.city-card-title strong {
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

#cityLocationDescription {
  margin: 0 0 10px;
  color: #c7cec2;
  font-size: 12px;
  line-height: 1.55;
}

.city-state-list {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.city-state-list div {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
}

.city-state-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.city-state-list dd {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.city-memory {
  display: grid;
  gap: 7px;
  flex: 0 0 auto;
  max-height: 96px;
  overflow: hidden;
}

.city-memory-item {
  color: #c7cec2;
  font-size: 12px;
  line-height: 1.45;
  border-left: 2px solid #485046;
  padding-left: 8px;
}

.city-role-row {
  width: 100%;
  height: auto;
  min-height: 30px;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 6px 7px;
  border: 1px solid #30362f;
  border-radius: 6px;
  background: #101310;
  color: var(--text);
  text-align: left;
}

.city-role-row span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--role-color);
}

.city-role-row strong,
.city-role-row em {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-style: normal;
}

.city-role-row strong {
  color: var(--text);
}

.city-role-row em {
  color: var(--accent);
}

.city-role-row.active {
  border-color: var(--accent);
  background: #1b1a12;
}

.modal {
  width: min(780px, calc(100vw - 32px));
  max-height: min(86vh, 820px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
}

.modal[open] {
  animation: dialogFadeIn 160ms ease-out both;
}

.modal.dialog-exit[open] {
  animation: dialogFadeOut 150ms ease-in both;
}

.small-modal {
  width: min(560px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.modal[open]::backdrop {
  animation: backdropFadeIn 160ms ease-out both;
}

.modal.dialog-exit[open]::backdrop {
  animation: backdropFadeOut 150ms ease-in both;
}

.modal-card {
  max-height: inherit;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--panel);
}

.modal.dialog-enter .modal-card {
  animation: modalRiseIn 190ms cubic-bezier(0.18, 0.82, 0.24, 1) both;
}

.modal.dialog-exit .modal-card {
  animation: modalDropOut 150ms ease-in both;
}

@keyframes dialogFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes backdropFadeIn {
  from { background: rgba(0, 0, 0, 0); }
  to { background: rgba(0, 0, 0, 0.58); }
}

@keyframes dialogFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes backdropFadeOut {
  from { background: rgba(0, 0, 0, 0.58); }
  to { background: rgba(0, 0, 0, 0); }
}

@keyframes modalRiseIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modalDropOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

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

.icon-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.modal-scroll {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.modal-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

.modal-actions button {
  width: auto;
  min-width: 96px;
  padding: 0 14px;
}

#saveRole,
#startConversation {
  color: #19150a;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.danger-button {
  color: var(--danger);
  border-color: rgba(224, 122, 111, 0.45);
  background: #211514;
}

#roleSaveStatus {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.avatar-row {
  align-items: start;
}

.avatar-picker {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.role-avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  font-size: 24px;
}

#roleAvatar {
  height: auto;
  padding: 8px;
}

#userRelationship {
  height: 110px;
  min-height: 90px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 48vh;
    overflow: auto;
  }

  #systemPrompt,
  #openingScene {
    min-height: 120px;
  }

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

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

  .msg {
    width: 100%;
  }

  .city-panel {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 42vh;
  }
}

@media (min-width: 861px) and (max-width: 1180px) {
  .app {
    grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  }

  .city-panel {
    display: none;
  }
}
