.dialog {
  position: fixed;
  right: calc(14px + var(--safe-right));
  bottom: calc(64px + var(--safe-bottom));
  width: min(440px, calc(100vw - 28px));
  max-height: min(64vh, 580px);
  max-height: min(64dvh, 580px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 22%),
    rgba(13, 17, 25, 0.96);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  z-index: 25;
  overflow: hidden;
  animation: dialog-in 180ms ease both;
}

.dialog[hidden] {
  display: none;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(111, 211, 230, 0.08), transparent);
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border: 1px solid rgba(111, 211, 230, 0.35);
  border-radius: 12px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.22), transparent 45%),
    linear-gradient(135deg, rgba(111, 211, 230, 0.5), rgba(183, 156, 255, 0.4));
  color: #07100f;
  font-size: 16px;
  font-weight: 800;
}

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

.dialog-id {
  min-width: 0;
}

.dialog-head h2 {
  margin: 0;
  overflow: hidden;
  font-size: 15.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-head p {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}

.icon-btn:hover {
  border-color: rgba(111, 211, 230, 0.55);
  background: var(--surface-3);
  color: var(--text);
}

.dialog-log {
  flex: 1;
  min-height: 96px;
  padding: 14px 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 13px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-npc {
  align-self: flex-start;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  background: var(--surface-2);
}

.msg-player {
  align-self: flex-end;
  border: 1px solid rgba(111, 211, 230, 0.35);
  border-bottom-right-radius: 4px;
  background: linear-gradient(135deg, rgba(111, 211, 230, 0.22), rgba(183, 156, 255, 0.18));
}

.msg-streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: caret 0.8s steps(1) infinite;
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

.msg-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.03em;
}

.msg-rejected {
  margin: 4px 0 0;
  padding-left: 14px;
  color: var(--bad);
  font-size: 11px;
}

.dialog-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 15px 10px;
}

.dialog-suggestions:empty,
.dialog-suggestions[hidden] {
  display: none;
}

.dialog-suggestions button {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(30, 37, 51, 0.7);
  color: var(--text-soft);
  font-size: 11px;
  white-space: nowrap;
  transition: border-color 140ms ease, color 140ms ease;
}

.dialog-suggestions button:hover:not(:disabled) {
  border-color: rgba(111, 211, 230, 0.55);
  color: var(--text);
}

.dialog-suggestions button:disabled {
  opacity: 0.45;
}

.dialog-form {
  display: flex;
  gap: 8px;
  padding: 11px 12px;
  border-top: 1px solid var(--line);
}

.dialog-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.dialog-form input::placeholder {
  color: var(--muted-2);
}

.dialog-form input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(111, 211, 230, 0.28);
}

.dialog-form button {
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 20px rgba(63, 185, 210, 0.18);
  color: #06100f;
  font-weight: 800;
  transition: filter 140ms ease, transform 140ms ease;
}

.dialog-form button:hover:not(:disabled) {
  filter: brightness(1.06);
}

.dialog-form button:active:not(:disabled) {
  transform: translateY(1px);
}

.dialog-form button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.dialog-status {
  min-height: 17px;
  margin: 0;
  padding: 0 15px 9px;
  color: var(--muted);
  font-size: 11px;
}

.dialog-status[data-tone="error"] {
  color: var(--bad);
}

@media (hover: none), (pointer: coarse) {
  .icon-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .dialog-suggestions button {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .dialog-form input,
  .dialog-form button {
    min-height: 44px;
  }
}

@media (max-width: 720px) {
  .dialog {
    right: calc(8px + var(--safe-right));
    left: calc(8px + var(--safe-left));
    bottom: calc(8px + var(--safe-bottom));
    width: auto;
    max-height: min(76vh, 640px);
    max-height: min(76dvh, calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom)));
    border-radius: 16px;
  }

  .icon-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .dialog-log {
    min-height: 110px;
  }

  .dialog-suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .dialog-suggestions::-webkit-scrollbar {
    display: none;
  }

  .dialog-suggestions button {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .dialog-form input {
    min-height: 44px;
    font-size: 16px;
  }

  .dialog-form button {
    min-height: 44px;
  }
}

@media (max-height: 560px) {
  .dialog {
    top: calc(8px + var(--safe-top));
    bottom: calc(8px + var(--safe-bottom));
    max-height: none;
  }

  .dialog-log {
    min-height: 64px;
  }
}
