:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  --page: #121018;
  --surface: #1c1828;
  --thread: #16131f;
  --input: #211b2e;
  --bubble: #322749;
  --ink: #f3eefb;
  --muted: #c6bbd7;
  --placeholder: #b5a7c7;
  --border: #3b324a;
  --control-border: #827393;
  --accent: #c7b2ff;
  --accent-hover: #dacaff;
  --on-accent: #241739;
  --control-hover: #42355b;
  --brand: #4d39ad;
  --danger: #ffb4ca;
  --shadow: 0 1.1rem 3rem #08060d80;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
p { margin: 0; }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .6; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.shell {
  display: grid;
  place-items: center;
  min-block-size: 100vh;
  min-block-size: 100dvh;
  padding: 1.5rem;
  background: radial-gradient(ellipse at 10% 5%, #271e3a, transparent 55%), var(--page);
}

.welcome { width: min(100%, 29rem); }
.welcome-card {
  padding: clamp(1.5rem, 7vw, 3.25rem);
  border: 1px solid var(--border);
  border-radius: 1.75rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.welcome h1 {
  margin: 1.3rem 0 .45rem;
  font-size: clamp(2.15rem, 10vw, 3.15rem);
  line-height: 1.1;
  letter-spacing: -.06em;
}
.welcome p { color: var(--muted); line-height: 1.5; }
.welcome .button { inline-size: 100%; margin-top: 1.65rem; }
.welcome .notice { margin-top: .95rem; }

.brand-mark {
  position: relative;
  display: inline-grid;
  flex: none;
  inline-size: 2.65rem;
  aspect-ratio: 1;
  border-radius: 25%;
  background: var(--brand);
}
.brand-mark-large { inline-size: 4.45rem; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; }
.brand-mark::before {
  inset: 24% 29% 37% 21%;
  border-radius: 26% 26% 26% 5%;
  background: #fff;
  z-index: 1;
}
.brand-mark::after {
  inset: 43% 19% 22% 41%;
  border-radius: 30% 30% 5% 30%;
  background: #c9bfff;
}

.button {
  border: 1px solid transparent;
  border-radius: .78rem;
  min-block-size: 2.75rem;
  padding: .55rem .85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 650;
  text-decoration: none;
  text-align: center;
  line-height: 1.2;
}
.button-primary { color: var(--on-accent); background: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-quiet { color: var(--accent); background: transparent; font-size: .9rem; }
.button-quiet:hover:not(:disabled), .button-attach:hover:not(:disabled) { background: var(--control-hover); }
.button-attach { color: var(--accent); background: var(--surface); border-color: var(--control-border); font-size: .9rem; }

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 57rem);
  height: min(50rem, calc(100vh - 3rem));
  height: min(50rem, calc(100dvh - 3rem));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 1.4rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.chat-header {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.chat-title { flex: 1; min-inline-size: 0; }
.chat-title h1 { margin: 0; font-size: 1.18rem; line-height: 1.18; letter-spacing: -.025em; }
.chat-title p { margin-top: .25rem; color: var(--muted); font-size: .875rem; line-height: 1.25; }
.thread {
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--thread);
  padding: 1.1rem 1.25rem;
  scrollbar-gutter: stable;
}
.thread:focus-visible { outline-offset: -4px; }
.empty {
  display: grid;
  place-content: center;
  text-align: center;
  min-block-size: 100%;
  gap: .35rem;
  color: var(--muted);
  line-height: 1.5;
}
.empty strong { color: var(--ink); }
.messages { list-style: none; padding: 0; margin: 0; display: grid; gap: .8rem; }
.message {
  justify-self: end;
  max-inline-size: min(85%, 34rem);
  min-inline-size: 0;
  padding: .65rem .85rem;
  border-radius: 1rem 1rem .28rem 1rem;
  background: var(--bubble);
  display: grid;
  gap: .4rem;
}
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.48; }
.message-image {
  display: block;
  inline-size: auto;
  block-size: auto;
  max-inline-size: 100%;
  max-block-size: 24rem;
  border-radius: .65rem;
}
.message-file { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .65rem; }
.message-file span { overflow-wrap: anywhere; font-size: .875rem; }
.message-file .button { margin-inline: -.3rem; padding-inline: .3rem; }
.message-time { justify-self: end; color: var(--muted); font-size: .8rem; }

.composer { display: grid; gap: .5rem; padding: .85rem 1.15rem; border-top: 1px solid var(--border); }
.composer-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: end; gap: .55rem; }
textarea {
  min-block-size: 2.75rem;
  max-block-size: 8rem;
  resize: vertical;
  padding: .65rem .65rem;
  border-radius: .78rem;
  border: 1px solid var(--control-border);
  color: var(--ink);
  background: var(--input);
  line-height: 1.35;
}
textarea::placeholder { color: var(--placeholder); }
.attachment { display: flex; align-items: center; justify-content: space-between; gap: .5rem; color: var(--muted); }
.attachment span { min-inline-size: 0; overflow-wrap: anywhere; font-size: .9rem; }
.attachment button { flex: none; }
.notice, .welcome .notice { color: var(--danger); line-height: 1.42; font-size: .9rem; overflow-wrap: anywhere; }

@media (max-width: 38rem) {
  .shell:has(.chat:not([hidden])) { display: block; padding: 0; background: var(--surface); }
  .chat {
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
  }
  .chat-header { padding: .7rem .65rem .7rem .85rem; gap: .55rem; }
  .thread { padding-inline: .8rem; scrollbar-gutter: auto; }
  .composer {
    padding: .65rem .7rem max(.65rem, env(safe-area-inset-bottom));
  }
  .composer-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; }
  .button-attach { grid-column: 1 / -1; justify-self: start; }
  .message { max-inline-size: 91%; }
}
