:root {
  color-scheme: dark;
  --bg: #070a0f;
  --panel: #0d1218;
  --panel-strong: #121923;
  --panel-raised: #171f2a;
  --text: #e8edf5;
  --muted: #93a1b3;
  --line: #243244;
  --user: #145e7a;
  --user-text: #ffffff;
  --accent: #f08b4a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top, rgba(73, 98, 137, 0.18), transparent 36%),
    linear-gradient(180deg, #0b1016 0%, var(--bg) 100%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  max-width: 760px;
  height: 100dvh;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 18, 24, 0.92);
  backdrop-filter: blur(16px);
}

.icon-button,
.new-chat-button,
.send-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: transparent;
}

.icon-button span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark,
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(180deg, #243244 0%, #151c26 100%);
  color: var(--text);
  font-weight: 720;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 1rem;
  line-height: 1.15;
}

.brand p {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
}

.new-chat-button {
  min-height: 40px;
  padding: 0 13px;
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--text);
  font-weight: 650;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-feed {
  overflow-y: auto;
  padding: 18px 14px 20px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 18px;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 420ms ease,
    transform 420ms ease;
}

.message.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.message.user {
  justify-content: flex-end;
}

.suggestion-message {
  justify-content: flex-end;
  margin-bottom: 18px;
}

.message.user .bubble {
  max-width: min(82%, 560px);
  background: linear-gradient(180deg, #1a6f90 0%, var(--user) 100%);
  color: var(--user-text);
}

.message.assistant .bubble {
  max-width: min(86%, 600px);
  background: var(--panel-strong);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.bubble {
  border-radius: 8px;
  padding: 12px 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.bubble p {
  margin: 0;
}

.suggestion-bubble {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: min(84vw, 560px);
  margin-left: auto;
  padding: 14px 16px;
  border: 1px solid rgba(240, 139, 74, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(240, 139, 74, 0.14), rgba(240, 139, 74, 0.05)),
    var(--panel-raised);
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  cursor: pointer;
}

.suggestion-bubble-text {
  font-size: 0.98rem;
  line-height: 1.35;
  font-weight: 650;
  white-space: nowrap;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 18px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.55;
  animation: typingPulse 1s infinite ease-in-out;
}

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

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

.composer {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 44px;
  align-items: end;
  padding: 10px 14px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(13, 18, 24, 0.95);
  backdrop-filter: blur(16px);
}

.composer textarea {
  grid-column: 1 / 2;
  width: 100%;
  max-height: 150px;
  min-height: 44px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
  background: var(--panel-raised);
  color: var(--text);
  line-height: 1.35;
}

.composer textarea:focus {
  border-color: color-mix(in srgb, var(--user), #fff 20%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--user), transparent 82%);
}

.send-button {
  grid-column: 2 / 3;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #0b0f14;
}

.send-button svg {
  width: 23px;
  height: 23px;
  fill: currentColor;
}

.send-button:disabled {
  cursor: default;
  opacity: 0.5;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.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 (min-width: 761px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px;
  }

  .app-shell {
    height: min(860px, calc(100vh - 48px));
    min-height: 620px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
  }
}
