:root {
  --bg-top: #fff6ea;
  --bg-bottom: #ffe3cb;
  --panel: rgba(255, 252, 248, 0.9);
  --panel-strong: rgba(255, 248, 240, 0.98);
  --text: #2f241c;
  --muted: #7b6759;
  --line: rgba(125, 88, 58, 0.12);
  --orange: #f58220;
  --orange-deep: #de6e10;
  --user: #fff0df;
  --assistant: #ffffff;
  --shadow: 0 16px 36px rgba(122, 76, 37, 0.1);
  --radius-xl: 32px;
  --radius-lg: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 34%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overflow: hidden;
}

.page-shell {
  height: 100dvh;
  padding: 24px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(14px);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffcf98, var(--orange));
  color: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
}

.brand-name {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.app-layout {
  display: grid;
  grid-template-rows: 1fr auto;
  height: calc(100dvh - 88px);
  max-width: 980px;
  margin: 0 auto;
  overflow: hidden;
}

.welcome-panel {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  text-align: center;
  padding: 40px 20px 12px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.welcome-panel.is-hidden {
  opacity: 0;
  transform: translateY(-16px);
  pointer-events: none;
  height: 0;
  overflow: hidden;
  padding: 0;
}

.group-logo {
  width: min(220px, 42vw);
  filter: drop-shadow(0 24px 40px rgba(125, 71, 31, 0.16));
}

.welcome-panel h1 {
  max-width: 700px;
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1.02;
}

.chat-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 18px;
  min-height: 0;
  overflow: hidden;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 20px 4px 18px;
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(145, 100, 63, 0.5) transparent;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

.messages::-webkit-scrollbar {
  width: 12px;
}

.messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(245, 130, 32, 0.58), rgba(181, 117, 67, 0.58));
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(245, 130, 32, 0.8), rgba(181, 117, 67, 0.8));
  border: 3px solid transparent;
  background-clip: content-box;
}

.message {
  display: grid;
  gap: 6px;
  padding-inline: 6px;
}

.message-role {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  padding-inline: 6px;
}

.message-bubble {
  max-width: min(100%, 760px);
  padding: 16px 18px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--assistant);
  box-shadow: var(--shadow);
  line-height: 1.55;
  white-space: pre-wrap;
}

.message-bubble p,
.message-bubble ul,
.message-bubble pre,
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
  margin: 0;
}

.message-bubble p + p,
.message-bubble p + ul,
.message-bubble ul + p,
.message-bubble pre + p,
.message-bubble pre + ul,
.message-bubble p + pre,
.message-bubble ul + pre,
.message-bubble h1 + p,
.message-bubble h2 + p,
.message-bubble h3 + p,
.message-bubble h4 + p,
.message-bubble h5 + p,
.message-bubble h6 + p,
.message-bubble p + h1,
.message-bubble p + h2,
.message-bubble p + h3,
.message-bubble p + h4,
.message-bubble p + h5,
.message-bubble p + h6 {
  margin-top: 12px;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
  font-family: "Space Grotesk", sans-serif;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.message-bubble h1 {
  font-size: 2rem;
}

.message-bubble h2 {
  font-size: 1.75rem;
}

.message-bubble h3 {
  font-size: 1.5rem;
}

.message-bubble h4 {
  font-size: 1.25rem;
}

.message-bubble h5,
.message-bubble h6 {
  font-size: 1.05rem;
}

.message-bubble ul {
  padding-left: 20px;
}

.message-bubble strong {
  font-weight: 800;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(245, 130, 32, 0.12);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.95em;
}

.message-bubble pre {
  overflow-x: auto;
  padding: 14px;
  border-radius: 16px;
  background: #2b211a;
  color: #fff6ea;
  white-space: pre-wrap;
}

.message-bubble pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.message-bubble.is-pending {
  min-width: 84px;
  white-space: nowrap;
}

.typing-dots {
  display: inline-flex;
  align-items: flex-end;
  gap: 8px;
  height: 20px;
}

.typing-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f2a14b, var(--orange));
  animation: typing-bounce 0.9s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.12s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  40% {
    transform: translateY(-7px);
    opacity: 1;
  }
}

.message.user {
  justify-items: end;
}

.message.user .message-bubble {
  background: var(--user);
}

.chat-form {
  position: sticky;
  bottom: 0;
  padding: 8px 0 0;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  padding: 14px;
  background: var(--panel-strong);
  border: 1px solid rgba(125, 88, 58, 0.16);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transition: border-color 0.22s ease, box-shadow 0.22s ease, background 0.22s ease;
  min-height: 84px;
}

.input-wrap.is-expanded {
  border-color: rgba(245, 130, 32, 0.28);
  box-shadow: 0 18px 42px rgba(122, 76, 37, 0.12);
  background: rgba(255, 250, 244, 0.99);
}

textarea {
  width: 100%;
  min-height: 54px;
  max-height: 220px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  padding: 8px 10px;
}

textarea::placeholder {
  color: #a08979;
}

.send-button {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb156, var(--orange));
  color: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.98rem;
  font-weight: 700;
  padding: 16px 22px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease;
}

.send-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #ffbf71, var(--orange-deep));
}

.stop-button {
  border: 1px solid rgba(125, 88, 58, 0.18);
  border-radius: 999px;
  background: #fff7ef;
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.98rem;
  font-weight: 700;
  padding: 16px 22px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease;
}

.stop-button:hover {
  transform: translateY(-1px);
  background: #ffe6cf;
}

@media (max-width: 720px) {
  .page-shell {
    padding: 16px;
  }

  .welcome-panel {
    padding-top: 24px;
  }

  .messages {
    padding: 10px 12px 4px 10px;
  }

  .input-wrap {
    gap: 10px;
    align-items: stretch;
    flex-direction: column;
  }

  .send-button {
    width: 100%;
  }

  .stop-button {
    width: 100%;
  }

  .chat-actions {
    width: 100%;
    flex-direction: column;
  }

  .app-layout {
    height: calc(100dvh - 72px);
  }
}
