:root {
  --paper: #fbf5ea;
  --ink: #141414;
  --muted: rgba(20, 20, 20, 0.65);
  --line: rgba(20, 20, 20, 0.14);
  --panel: rgba(251, 245, 234, 0.85);
  --shadow: 0 22px 65px rgba(20, 20, 20, 0.18);
  --accent: #e2542e;
  --accent-2: #1a8f84;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Avenir Next", "Avenir", "Futura", "Trebuchet MS", sans-serif;
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: -30vmax;
  z-index: -1;
  background:
    radial-gradient(closest-side, rgba(226, 84, 46, 0.28), transparent 70%) 30% 30% / 70vmax 70vmax no-repeat,
    radial-gradient(closest-side, rgba(26, 143, 132, 0.22), transparent 70%) 70% 40% / 75vmax 75vmax no-repeat,
    radial-gradient(closest-side, rgba(20, 20, 20, 0.10), transparent 72%) 55% 70% / 90vmax 90vmax no-repeat,
    repeating-linear-gradient(135deg, rgba(20, 20, 20, 0.03) 0, rgba(20, 20, 20, 0.03) 2px, transparent 2px, transparent 10px);
  filter: blur(0px);
  transform: translateZ(0);
  animation: float 18s ease-in-out infinite;
}

@keyframes float {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  50% {
    transform: translate3d(1.5vmax, -1vmax, 0) rotate(0.6deg);
  }
  100% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 245, 234, 0.72);
  backdrop-filter: blur(10px);
}

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

.mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 30% 30%, rgba(251, 245, 234, 0.9), rgba(251, 245, 234, 0.25) 35%, transparent 36%),
    linear-gradient(145deg, rgba(226, 84, 46, 1), rgba(26, 143, 132, 1));
  box-shadow: 0 14px 32px rgba(20, 20, 20, 0.18);
  border: 1px solid rgba(20, 20, 20, 0.14);
}

.brand-text {
  min-width: 0;
}

.title {
  font-family: "Georgia", "Times New Roman", serif;
  letter-spacing: 0.2px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}

.subtitle {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.2;
  margin-top: 4px;
  max-width: 70ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

.control input {
  width: 86px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(251, 245, 234, 0.9);
  color: var(--ink);
  outline: none;
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 22px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 16px;
  min-height: calc(100vh - 78px);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.thread {
  padding: 18px 18px 10px 18px;
  max-height: calc(100vh - 240px);
  overflow: auto;
  scroll-behavior: smooth;
}

.msg {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 14px;
  padding: 14px 12px;
  border-top: 1px solid rgba(20, 20, 20, 0.08);
  animation: pop 240ms ease-out both;
}

.msg.user {
  grid-template-columns: 1fr 64px;
}

.msg:first-child {
  border-top: 0;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.who {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid rgba(20, 20, 20, 0.14);
  background: rgba(251, 245, 234, 0.9);
  font-weight: 700;
  color: rgba(20, 20, 20, 0.8);
  letter-spacing: 0.4px;
}

.badge.assistant {
  background: linear-gradient(145deg, rgba(226, 84, 46, 0.15), rgba(26, 143, 132, 0.12));
}

.content {
  color: var(--ink);
  display: flex;
  justify-content: flex-start;
}

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

.bubble {
  background: rgba(251, 245, 234, 0.75);
  border: 1px solid rgba(20, 20, 20, 0.12);
  border-radius: 16px;
  padding: 12px 12px;
  box-shadow: 0 8px 24px rgba(20, 20, 20, 0.06);
  width: fit-content;
  max-width: min(740px, 100%);
}

.bubble.user {
  border-right: 6px solid rgba(226, 84, 46, 0.55);
  border-left-color: rgba(20, 20, 20, 0.08);
  background: linear-gradient(145deg, rgba(226, 84, 46, 0.06), rgba(251, 245, 234, 0.8));
}

.bubble.assistant {
  border-left: 6px solid rgba(26, 143, 132, 0.55);
  background: linear-gradient(145deg, rgba(26, 143, 132, 0.05), rgba(251, 245, 234, 0.8));
}

.text {
  white-space: normal;
  line-height: 1.45;
  font-size: 15px;
}

.text.raw {
  white-space: pre-wrap;
}

.text .md-head {
  font-family: "Georgia", "Times New Roman", serif;
  letter-spacing: 0.2px;
  margin: 0 0 10px 0;
}

.text .md-p {
  margin: 0 0 10px 0;
}

.text .md-p:last-child {
  margin-bottom: 0;
}

.text .md-list {
  margin: 8px 0 10px 18px;
  padding: 0;
}

.text .md-list li {
  margin: 6px 0;
}

.md-code {
  margin: 10px 0;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(20, 20, 20, 0.14);
  background: rgba(20, 20, 20, 0.04);
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.35;
}

.inline-code {
  border: 1px solid rgba(20, 20, 20, 0.16);
  background: rgba(20, 20, 20, 0.04);
  padding: 2px 6px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.cite-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(20, 20, 20, 0.18);
  background: rgba(251, 245, 234, 0.82);
  color: rgba(20, 20, 20, 0.78);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 800;
  cursor: pointer;
  vertical-align: baseline;
}

.cite-ref:hover {
  background: rgba(20, 20, 20, 0.05);
}

.meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(20, 20, 20, 0.14);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(251, 245, 234, 0.82);
}

.pill strong {
  color: rgba(20, 20, 20, 0.85);
}

.cite-toggle {
  cursor: pointer;
  border: 1px solid rgba(20, 20, 20, 0.14);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(20, 20, 20, 0.04);
  color: rgba(20, 20, 20, 0.75);
  font-weight: 700;
}

.cite-toggle:hover {
  background: rgba(20, 20, 20, 0.06);
}

.citations {
  margin-top: 10px;
  display: none;
  border-top: 1px dashed rgba(20, 20, 20, 0.18);
  padding-top: 10px;
}

.citations.open {
  display: block;
}

.cite {
  padding: 10px 10px;
  border: 1px solid rgba(20, 20, 20, 0.10);
  border-radius: 14px;
  background: rgba(251, 245, 234, 0.55);
  margin-bottom: 10px;
}

.cite.flash {
  animation: flash 900ms ease-out both;
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 0 rgba(226, 84, 46, 0.0);
    border-color: rgba(226, 84, 46, 0.15);
  }
  30% {
    box-shadow: 0 0 0 6px rgba(226, 84, 46, 0.12);
    border-color: rgba(226, 84, 46, 0.38);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(226, 84, 46, 0.0);
    border-color: rgba(20, 20, 20, 0.10);
  }
}

.cite-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.cite-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 22px;
  border-radius: 10px;
  border: 1px solid rgba(20, 20, 20, 0.14);
  background: rgba(20, 20, 20, 0.03);
  color: rgba(20, 20, 20, 0.72);
  font-weight: 700;
}

.cite-excerpt {
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.35;
}

.composer {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 245, 234, 0.82);
  box-shadow: var(--shadow);
  padding: 12px;
}

.composer-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.input {
  width: 100%;
  resize: none;
  border: 1px solid rgba(20, 20, 20, 0.18);
  border-radius: 16px;
  padding: 12px 12px;
  font-size: 15px;
  outline: none;
  background: rgba(251, 245, 234, 0.9);
  color: var(--ink);
}

.input:focus {
  border-color: rgba(226, 84, 46, 0.55);
  box-shadow: 0 0 0 4px rgba(226, 84, 46, 0.12);
}

.btn {
  border: 1px solid rgba(20, 20, 20, 0.22);
  background: linear-gradient(145deg, rgba(226, 84, 46, 0.95), rgba(226, 84, 46, 0.82));
  color: rgba(251, 245, 234, 0.98);
  font-weight: 800;
  padding: 12px 14px;
  border-radius: 16px;
  cursor: pointer;
  letter-spacing: 0.3px;
  box-shadow: 0 16px 32px rgba(226, 84, 46, 0.18);
}

.btn:hover {
  filter: brightness(1.02);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

.hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  padding-left: 2px;
}

.typing {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.42);
  animation: bob 1.2s ease-in-out infinite;
}

.dot:nth-child(2) {
  animation-delay: 0.12s;
}

.dot:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  50% {
    transform: translateY(-4px);
    opacity: 0.95;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 14px 14px;
  }
  .wrap {
    padding: 14px;
  }
  .subtitle {
    display: none;
  }
  .msg {
    grid-template-columns: 54px 1fr;
    gap: 12px;
  }
  .msg.user {
    grid-template-columns: 1fr 54px;
  }
  .badge {
    width: 40px;
  }
}
