@font-face {
  font-family: Raleway;
  src: url('./raleway.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --page: #080618;
  --header: #141521;
  --wall: #10111b;
  --ink: #fff;
  --muted: #b0b5c5;
  --line: #2c3142;
  --cyan: #00cafe;
  font-family: Raleway, system-ui, sans-serif;
}

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

body {
  margin: 0;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  background: radial-gradient(ellipse at center, #161e31 0%, var(--page) 68%);
  color: var(--ink);
}

.chat {
  width: min(100%, 518px);
  height: min(708px, calc(100dvh - 40px));
  min-height: 300px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: var(--wall);
  box-shadow: 0 24px 90px #04030bb0;
}

.contact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 17px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
}

.avatar { flex: none; border-radius: 50%; object-fit: cover; border: 1px solid #ffffff23; }
.contact h1 { margin: 0; font-size: 1.1rem; font-weight: 800; line-height: 1.2; }
.contact p { margin: 4px 0 0; color: var(--muted); font-size: .76rem; font-weight: 640; line-height: 1.35; }

.thread {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 15px;
  background: radial-gradient(circle at center, #ffffff14 .75px, transparent .9px) 0 0 / 19px 19px var(--wall);
  scrollbar-width: thin;
  scrollbar-color: #4a5265 transparent;
}

.bubble {
  width: fit-content;
  position: relative;
  flex: 0 0 auto;
  max-width: 87%;
  margin: 0;
  padding: 10px 13px;
  background: var(--bubble);
  font-size: .99rem;
  font-weight: 595;
  line-height: 1.48;
  overflow-wrap: anywhere;
  animation: appear .18s ease-out both;
}

.incoming { --bubble: #252936; border-radius: 3px 13px 13px 13px; }
.outgoing { --bubble: #13384b; align-self: flex-end; border-radius: 13px 3px 13px 13px; }
.incoming::before, .outgoing::before { content: ''; position: absolute; top: 0; width: 6px; height: 8px; background: var(--bubble); }
.incoming::before { right: calc(100% - 2px); clip-path: polygon(0 0, 100% 0, 100% 100%); }
.outgoing::before { left: calc(100% - 2px); clip-path: polygon(0 0, 100% 0, 0 100%); }

.typing { display: flex; align-items: center; gap: 5px; min-height: 36px; }
.typing .dot { width: 6px; height: 6px; border-radius: 50%; background: #b8d4e2; animation: typing 1s infinite ease-in-out; }
.typing .dot:nth-of-type(3) { animation-delay: .13s; }
.typing .dot:nth-of-type(4) { animation-delay: .26s; }
@keyframes typing { 0%, 60%, 100% { opacity: .45; transform: translateY(0); } 28% { opacity: 1; transform: translateY(-3px); } }
@keyframes appear { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

.composer {
  background: var(--header);
  border-top: 1px solid var(--line);
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
}

.choices { flex: none; width: min(87%, 290px); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.choices button { border: 1px solid #357a95; color: #ccf5ff; background: #142737; border-radius: 25px; font-weight: 780; min-height: 47px; padding: 8px 10px; }
.choices button:hover { background: #21455e; }

.reply { display: grid; grid-template-columns: minmax(0, 1fr) 48px; align-items: center; gap: 8px; }
.reply input { min-width: 0; min-height: 48px; border: 1px solid #3e4558; padding: 0 15px; border-radius: 24px; background: #222636; color: var(--ink); font-size: 1rem; font-weight: 650; }
.reply input::placeholder { color: var(--muted); }
.reply input[aria-invalid='true'] { border-color: #ff9da9; }

button, input { font-family: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid #8deaff; outline-offset: 2px; }
.send, .open, .retry { display: flex; justify-content: center; align-items: center; gap: 8px; min-height: 48px; border: 0; border-radius: 26px; background: var(--cyan); color: var(--page); text-decoration: none; font-weight: 860; }
.retry { width: 100%; }
.send:hover, .open:hover, .retry:hover { background: #82e7ff; }
.error { margin: 7px 4px 0; color: #ffb2c1; font-size: .85rem; font-weight: 670; }
.edit { display: block; margin: 2px auto -8px; padding: 4px 10px; min-height: 44px; color: #bceafa; background: none; border: 0; font-size: .78rem; font-weight: 760; text-decoration: underline; text-underline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 600px) {
  body { display: block; min-height: 0; padding: 0; overflow: hidden; }
  .chat { width: 100%; height: 100dvh; height: var(--visible-height, 100dvh); min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
  .contact { padding-top: max(12px, env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
