:root {
  color-scheme: dark;
  font: 100%/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --page: #13121b;
  --panel: #1d1b2a;
  --field: #171622;
  --line: #3b374e;
  --ink: #f5f1ff;
  --muted: #b9b3cd;
  --accent: #d0bcff;
  --accent-ink: #24153a;
  --error: #ffadbc;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: radial-gradient(ellipse at 67% 0%, #302542 0%, transparent 62%), var(--page);
  color: var(--ink);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.6; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.app {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 1.5rem;
}

.entry { width: min(100%, 27rem); }

.wordmark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.2rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.mark {
  position: relative;
  width: 1.7rem;
  height: 0.875rem;
}

.mark::before, .mark::after {
  position: absolute;
  top: 0;
  width: 0.875rem;
  height: 0.875rem;
  border: 2px solid #c8b1ff;
  border-radius: 50%;
  content: "";
}

.mark::before { left: 0.1rem; }
.mark::after { right: 0.1rem; border-color: #dfa8ce; }

.card {
  padding: clamp(1.25rem, 6vw, 2rem);
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--panel);
  box-shadow: 0 1.5rem 5rem #09071066;
}

h1, p { margin: 0; }
.card h1 { margin-bottom: 0.6rem; font-size: 1.75rem; line-height: 1.18; letter-spacing: -0.035em; }
.question, .loading { color: var(--muted); }
.loading { text-align: center; }
.stack { display: flex; flex-direction: column; align-items: stretch; gap: 0.55rem; margin-top: 1.45rem; }
.stack label { color: var(--muted); font-size: 0.9rem; font-weight: 600; }

input:not([type="file"]), textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--field);
  color: var(--ink);
}

input::placeholder, textarea::placeholder { color: #aca5c3; }

.primary, .subtle, .text-button {
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.8rem;
  font-size: 0.95rem;
  font-weight: 650;
}

.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover:enabled { background: #e2d4ff; }
.stack .primary { margin-top: 0.45rem; }
.subtle { border-color: var(--line); background: #262338; color: var(--ink); }
.subtle:hover:enabled, .text-button:hover:enabled { background: #312b45; }
.text-button { color: var(--muted); background: transparent; }
.error { color: var(--error); font-size: 0.9rem; overflow-wrap: anywhere; }
.error:empty { display: none; }

.avatar {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
  place-items: center;
  overflow: hidden;
  border: 1px solid #bfb2e438;
  border-radius: 50%;
  background: #453759;
  color: #f8efff;
  font-weight: 650;
}

.avatar--rose { background: #5a374e; }
.avatar--large { width: 4.25rem; height: 4.25rem; font-size: 1.4rem; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-options { display: grid; gap: 0.55rem; }
.profile-option { display: flex; align-items: center; gap: 0.75rem; min-width: 0; text-align: left; }
.profile-option span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-control { display: flex; flex-wrap: wrap; align-items: center; gap: 0.85rem; margin-bottom: 0.7rem; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.photo-actions .text-button { padding-inline: 0.55rem; }

.conversation {
  display: grid;
  width: min(100%, 51rem);
  height: min(51rem, calc(100dvh - 3rem));
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1.45rem;
  box-shadow: 0 1.5rem 6rem #09071088;
  background: var(--panel);
}

.chat-heading, .contact { display: flex; align-items: center; gap: 0.75rem; }
.chat-heading { justify-content: space-between; padding: 0.8rem clamp(0.85rem, 3.5vw, 1.35rem); border-bottom: 1px solid var(--line); }
.contact, .contact-text { min-width: 0; }
.contact-text h1 { overflow: hidden; font-size: 1.1rem; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.contact-text p { color: var(--muted); font-size: 0.875rem; }
.avatar-button { padding: 0.15rem; border: 0; border-radius: 50%; background: transparent; }
.avatar-button:hover .avatar { border-color: var(--accent); }

.chat-scroll {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.8rem;
  overflow: auto;
  padding: 1rem clamp(0.85rem, 3.5vw, 1.35rem);
  background: radial-gradient(#bfb2e418 1px, transparent 1px) 0 0 / 1.1rem 1.1rem, #181624;
  scrollbar-color: #656078 transparent;
}

.chat-scroll:focus-visible { outline-offset: -3px; }
.older { align-self: center; }
.empty { align-self: center; margin: auto 0; padding: 0.35rem 0.7rem; color: var(--muted); }

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: auto 0 0;
  padding: 0;
  list-style: none;
}

.messages:empty { display: none; }
.date-label { align-self: center; margin-block: 0.45rem; color: var(--muted); font-size: 0.8rem; }
.message { display: flex; align-items: end; gap: 0.5rem; min-width: 0; }
.message--mine { justify-content: flex-end; }
.message .avatar { width: 1.8rem; height: 1.8rem; font-size: 0.75rem; }

.bubble {
  max-width: min(80%, 35rem);
  padding: 0.48rem 0.72rem;
  border: 1px solid #504660;
  border-radius: 0.95rem 0.95rem 0.95rem 0.3rem;
  background: #30293f;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.message--mine .bubble {
  border-color: #73619d;
  border-radius: 0.95rem 0.95rem 0.3rem 0.95rem;
  background: #544275;
}

.bubble p { white-space: pre-wrap; }
.bubble time { display: block; margin-top: 0.15rem; color: #e2d7f2; font-size: 0.75rem; text-align: right; }

.composer {
  padding: 0.8rem clamp(0.85rem, 3.5vw, 1.35rem);
  padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.compose-row { display: flex; align-items: end; gap: 0.6rem; }
.composer textarea { display: block; flex: 1; min-width: 0; min-height: 2.75rem; max-height: 9rem; field-sizing: content; resize: none; }
.composer .primary { min-height: 3.1rem; }
.composer .error { margin-top: 0.35rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 40rem), (max-height: 34rem) {
  .app:has(.conversation:not([hidden])) { padding: 0; }
  .conversation { width: 100%; height: 100dvh; border: 0; border-radius: 0; }
  .chat-heading { padding-top: max(0.8rem, env(safe-area-inset-top)); }
}
