:root {
  --var-fill-1: #f6f8fe;
  --var-fill-2: #c4ceee;
  --var-fill-3: #6659a6;
  --var-fill-4: #462d53;
}

/* =========================
   Base / Typography
========================= */
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Bellefair", serif;
  background: #f0f0f0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-weight: normal;
}

/* =========================
   Layout: Chat Window
========================= */
.chat-window {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1280px;
  margin: auto;
  background: white;
  border-radius: 48px;
  overflow: hidden;
}

.chat-window.chat-loading .chat-input,
.chat-window.chat-loading .send-btn,
.chat-window.chat-loading .chip {
  pointer-events: none;
  opacity: 0.5;
  cursor: not-allowed;
  transition: opacity 0.3s ease;
}

/* =========================
   Header Section
========================= */
.chat-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  text-align: center;
  height: 100vh;
  transition: all 0.6s ease;
}

.chat-window.chat-started .chat-header {
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  padding: 24px;
  text-align: left;
  height: auto;
}

/* Avatar */
.chat-avatar {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 1px solid var(--var-fill-2);
  margin-bottom: 16px;
  object-fit: cover;
  transition: all 0.6s ease;
}

.chat-window.chat-started .chat-avatar {
  width: 48px;
  height: 48px;
  margin-right: 8px;
}

/* Title Group */
.chat-title-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.6s ease;
}

.chat-window.chat-started .chat-title-group {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.chat-title {
  font-size: 2.9rem;
  color: var(--var-fill-4);
  transition: font-size 0.6s ease;
}

.chat-window.chat-started .chat-title {
  font-size: 1rem;
  display: none;
}

.chat-subtitle {
  font-size: 2.2rem;
  color: var(--var-fill-3);
  transition: font-size 0.6s ease;
}

.chat-window.chat-started .chat-subtitle {
  font-size: 1.2rem;
}

.chat-window.chat-started .chat-subtitle::before {
  content: "\2022";
  margin: 0 0px;
  display: none;
}

/* =========================
   Messages Area
========================= */
.chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.user-message {
  align-self: flex-end;
  background: var(--var-fill-1);
  color: var(--var-fill-3);
  padding: 12px 16px;
  border-radius: 32px;
  font-size: 1.5rem;
  max-width: 640px;
  line-height: 1.15;
  overflow-wrap: anywhere;
  word-break: break-word;
  opacity: 0;
  transform: translateY(12px);
  animation: messageSlideUp 0.5s ease forwards;
}

@keyframes messageSlideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.gpt-response {
  align-self: flex-start;
  color: var(--var-fill-4);
  font-size: 1.6rem;
  line-height: 1.15;
  max-width: 640px;
  padding: 16px 16px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.gpt-response a {
  color: var(--var-fill-3);
  text-decoration: underline;
}

.thinking-message {
  color: var(--var-fill-3);
  opacity: 0.5;
  animation: breathe 1.6s ease-in-out infinite;
  font-size: 1.5rem;
  align-self: flex-start;
  padding: 16px 16px;
  min-height: 64px;
  transition: opacity 0.3s ease;
}

@keyframes breathe {
  0% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 0.4;
  }
}

.fade-word {
  opacity: 0;
  display: inline;
  overflow-wrap: anywhere;
  animation: wordFadeIn 0.25s ease-out forwards;
}

@keyframes wordFadeIn {
  from {
    opacity: 0;
    transform: translateX(6px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* =========================
   Input Section
   - Textarea is anchored at the bottom and expands upward to three lines
   - Send button remains fixed at the bottom right
========================= */
.input-container {
  background: var(--var-fill-1);
  border-radius: 32px;
  padding: 16px;
  margin: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: flex-end;
  border-radius: 32px;
  padding-right: 40px;
}

/* Chat input grows upward and allows scrolling past
   three lines of text. */
.chat-input {
  width: 100%;
  min-height: 32px;
  padding: 8px 56px 8px 8px;
  border: none;
  border-radius: 32px;
  font-size: 1.6rem;
  background: transparent;
  color: var(--var-fill-3);
  font-family: "Bellefair", serif;
  resize: none;
  line-height: 1.5;
  box-sizing: border-box;
  overflow-x: hidden;

  overflow-y: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-height: calc(1.5em * 3);
}

.chat-input:focus {
  outline: none;
}

.chat-input::placeholder {
  color: var(--var-fill-3);
  opacity: 0.5;
}

/* Send Button - anchored to the bottom right of the input wrapper */
.send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--var-fill-3);
  color: var(--var-fill-1);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.3s ease;
}

.send-btn svg {
  width: 24px;
  height: 24px;
  transform: translate(4px, 0);
  display: block;
}

.send-btn:hover {
  background: var(--var-fill-4);
}

/* =========================
   Suggestions (Chips)
========================= */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background-color: rgba(196, 206, 238, 0.25);
  color: var(--var-fill-3);
  font-size: 1.2rem;
  padding: 8px 12px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-family: "Bellefair", serif;
  transition: background 0.3s ease;
  height: 32px;
  display: flex;
  align-items: center;
}

.chip:hover {
  background-color: rgba(196, 206, 238, 0.5);
}

/* =========================
   Restart Button
========================= */
.restart-btn {
  position: absolute;
  top: 32px;
  right: 32px;
  width: 32px;
  height: 32px;
  background-color: var(--var-fill-3);
  color: var(--var-fill-1);
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background 0.3s ease;
  display: none;
  z-index: 10;
  padding: 0;
  align-items: center;
  justify-content: center;
  -webkit-appearance: none;
  appearance: none;
}

.restart-btn svg {
  width: 24px;
  height: 24px;
  display: block;
}

.chat-window.chat-started .restart-btn {
  display: flex;
}

.restart-btn:hover {
  background: var(--var-fill-4);
}

/* =========================
   Accessibility
========================= */
@media (prefers-reduced-motion: reduce) {
  .chat-header,
  .chat-avatar,
  .chat-title-group,
  .user-message,
  .fade-word {
    transition: none !important;
    animation: none !important;
  }
}
/* =========================
   Mobile improvements (<= 640px)
========================= */
@media (max-width: 768px) {
  /* Scale down avatar and title area */
  .chat-avatar {
    width: 104px;
    height: 104px;
  }

  .chat-title {
    font-size: 2.5rem; /* more aggressive scaling */
  }

  .chat-subtitle {
    font-size: 1.6rem;
  }

  /* Scale chat bubbles */
  .user-message,
  .gpt-response {
    font-size: 1.2rem;
    line-height: 1.15;
  }

  /* Input and thinking text */
  .chat-input,
  .thinking-message {
    font-size: 1.2rem;
  }

  /* Horizontal scroll for chips */
  .suggestions {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

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

  .chip {
    flex: 0 0 auto;
    font-size: 1.1rem;
    white-space: nowrap; /* prevent wrapping */
  }

  /* Tighter padding to reduce breakage */
  .chat-header {
    padding: 12px;
    gap: 8px;
  }

  .input-container {
    margin: 12px;
    padding: 12px;
  }
}
