* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --charcoal: #0d0d0e;
  --surface: #171718;
  --surface-raised: #232325;
  --ivory: #ccccca;
  --muted: #8a8d91;
  --green: #1f3b34;
  --line: rgba(246, 244, 239, 0.08);
}

html,
body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--charcoal);
}

body {
  color: var(--ivory);
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  width: min(100%, 760px);
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  margin: 0 auto;
  padding:
    max(36px, env(safe-area-inset-top))
    32px
    max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.chatbox {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-bottom: clamp(40px, 10vh, 100px);
  text-align: center;
  transition: opacity 180ms ease;
}

h1 {
  margin-bottom: 24px;
  color: var(--ivory);
  font-size: clamp(32px, 5vw, 44px);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.welcome p {
  color: #b6b4b0;
  font-size: 17px;
  line-height: 1.65;
}

.welcome .active-byline {
  display: none;
}

.messages {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 32px 4px 24px;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-raised) transparent;
}

.has-conversation .welcome {
  flex: 0 0 auto;
  align-items: flex-start;
  padding-bottom: 0;
  padding-left: 4px;
  text-align: left;
}

.has-conversation .welcome h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 500;
  letter-spacing: 0;
}

.has-conversation .welcome p {
  display: none;
}

.has-conversation .welcome .active-byline {
  display: block;
  margin-top: 6px;
  color: #747679;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.3;
}

.has-conversation .messages {
  display: flex;
}

@media (min-width: 901px) {
  .has-conversation .welcome {
    position: fixed;
    top: max(36px, env(safe-area-inset-top));
    left: 40px;
    z-index: 1;
    padding: 0;
  }
}

.message {
  max-width: min(78%, 520px);
  padding: 14px 17px;
  border-radius: 18px;
  color: #e9e7e2;
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user {
  align-self: flex-end;
  background: var(--surface-raised);
  border-bottom-right-radius: 6px;
}

.bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

form {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

input {
  min-width: 0;
  flex: 1;
  padding: 12px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ivory);
  font-size: 16px;
}

input::placeholder {
  color: var(--muted);
}

button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--ivory);
  color: #161616;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background-color 160ms ease;
}

button span {
  font-size: 25px;
  font-weight: 400;
  line-height: 1;
  transform: translateY(-1px);
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

form:focus-within {
  border-color: rgba(246, 244, 239, 0.2);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    0 0 0 3px rgba(31, 59, 52, 0.45);
}

footer {
  flex: 0 0 auto;
  padding-top: 18px;
  color: #6f7072;
  font-size: 11px;
  text-align: center;
}

footer span {
  color: #cfcac0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 600px) {
  .app {
    width: 100%;
    padding:
      max(24px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  h1 {
    margin-bottom: 20px;
    font-size: clamp(30px, 8.5vw, 36px);
  }

  .welcome p {
    font-size: 16px;
  }

  .welcome {
    padding-bottom: clamp(24px, 8vh, 64px);
  }

  .messages {
    padding: 20px 2px 16px;
    gap: 12px;
  }

  .has-conversation .welcome {
    padding-left: 2px;
  }

  .message {
    max-width: 86%;
    padding: 12px 14px;
    font-size: 15px;
  }

  form {
    border-radius: 20px;
  }

  input {
    padding-left: 8px;
  }

  button {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }
}

@media (max-width: 360px) {
  .app {
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }

  h1 {
    font-size: 29px;
  }

  .message {
    max-width: 90%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
