/* ————————————————————————————————————————————————
   Tarsus AI — academic editorial theme
   parchment + ink navy + terracotta
———————————————————————————————————————————————— */

:root {
  --paper: #f6f1e7;
  --paper-deep: #efe7d8;
  --ink: #1c2433;
  --ink-soft: #4a5468;
  --ink-faint: #8b91a0;
  --terra: #c4552d;
  --terra-soft: #e8c9bb;
  --aegean: #2e6e73;
  --line: #ddd2bf;
  --card: #fffdf8;
  --shadow: 0 1px 2px rgba(28, 36, 51, 0.06), 0 8px 28px rgba(28, 36, 51, 0.08);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* grain + warm wash */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
}

.backdrop {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

/* Cleopatra's Gate — faint arches */
.arc {
  position: absolute;
  border: 1.5px solid var(--line);
  border-bottom: none;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  opacity: 0.55;
}
.arc-1 { width: 560px; height: 300px; right: -140px; bottom: -40px; }
.arc-2 { width: 380px; height: 205px; right: -50px; bottom: -40px; border-color: var(--terra-soft); }

/* ——— top bar ——— */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--paper) 84%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.crest {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card);
  padding: 4px;
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--terra);
  overflow: hidden;
}

.crest img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.topbar-text { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.04em; }

.status-pill {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--aegean);
  background: color-mix(in srgb, var(--aegean) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--aegean) 25%, transparent);
  padding: 5px 12px;
  border-radius: 999px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--aegean);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.7); opacity: 0.5; }
}

/* ——— chat column ——— */

.chat {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 20px 12px;
  position: relative;
  z-index: 1;
}

/* hero / empty state */

.hero {
  text-align: center;
  padding: 9vh 8px 40px;
  animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--terra);
  margin: 0 0 18px;
}

.hero-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(34px, 6vw, 52px);
  line-height: 1.08;
  margin: 0 0 18px;
}

.hero-title em {
  font-style: italic;
  color: var(--terra);
}

.hero-copy {
  max-width: 480px;
  margin: 0 auto 34px;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.65;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.chip {
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.chip:hover {
  color: var(--terra);
  border-color: var(--terra);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* messages */

.messages { display: flex; flex-direction: column; gap: 22px; padding-bottom: 8px; }

.msg {
  max-width: 86%;
  animation: rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

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

.msg.user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  font-size: 15px;
  line-height: 1.55;
  box-shadow: var(--shadow);
}

.msg.assistant { align-self: stretch; max-width: 100%; }

.bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 18px 22px;
  box-shadow: var(--shadow);
}

/* answer text (markdown) */

.answer { font-size: 15.5px; line-height: 1.7; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0.6em 0; }
.answer a { color: var(--aegean); text-decoration-color: color-mix(in srgb, var(--aegean) 40%, transparent); text-underline-offset: 3px; }
.answer a:hover { color: var(--terra); }
.answer strong { font-weight: 700; }
.answer ul, .answer ol { padding-left: 1.3em; margin: 0.6em 0; }
.answer li { margin: 0.25em 0; }
.answer code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--paper-deep);
  padding: 2px 6px;
  border-radius: 6px;
}
.answer blockquote {
  margin: 0.8em 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--terra);
  color: var(--ink-soft);
}
.answer table { border-collapse: collapse; margin: 0.8em 0; font-size: 0.92em; }
.answer th, .answer td { border: 1px solid var(--line); padding: 6px 10px; }
.answer th { background: var(--paper-deep); }

/* streaming caret */
.answer.streaming::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: text-bottom;
  background: var(--terra);
  border-radius: 2px;
  animation: caret 0.9s steps(2) infinite;
}

@keyframes caret { 50% { opacity: 0; } }

/* ——— research trace ——— */

.trace { padding: 4px 2px; }

.trace-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 5px 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  animation: rise 0.3s ease both;
}

.trace-step .marker {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 0.5px;
  display: grid;
  place-items: center;
  position: relative;
}

.trace-step .marker::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
}

.trace-step:not(:last-child) .marker::after {
  content: "";
  position: absolute;
  top: 16px;
  width: 1.5px;
  height: 14px;
  background: var(--line);
}

.trace-step.active { color: var(--ink); font-weight: 600; }

.trace-step.active .marker::before {
  background: var(--terra);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--terra) 18%, transparent);
  animation: breathe 1.1s ease-in-out infinite;
}

.trace-step.done .marker::before {
  background: var(--aegean);
  width: 7px;
  height: 7px;
}

/* collapsed trace summary */

.trace-summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: color 0.15s ease;
  user-select: none;
}

.trace-summary:hover { color: var(--terra); }

.trace-summary .tick { color: var(--aegean); font-weight: 700; }

.trace.collapsed-list { display: none; margin-bottom: 10px; }
.trace.collapsed-list.open { display: block; }

/* ——— sources & tools ——— */

.meta { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 14px; }

.meta-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 9px;
}

.sources { display: flex; flex-direction: column; gap: 8px; }

.source-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  transition: all 0.16s ease;
}

.source-card:hover {
  border-color: var(--terra);
  transform: translateX(3px);
}

.source-num {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--terra);
  background: color-mix(in srgb, var(--terra) 11%, transparent);
}

.source-body { min-width: 0; display: flex; flex-direction: column; }

.source-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-host {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}

.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.tool-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--aegean);
  background: color-mix(in srgb, var(--aegean) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--aegean) 22%, transparent);
  border-radius: 6px;
  padding: 3px 8px;
}

/* error bubble */
.msg.error .bubble { border-color: #d9907c; background: #fdf3ef; }

/* ——— composer ——— */

.composer-wrap {
  position: sticky;
  bottom: 0;
  z-index: 10;
  padding: 10px 20px 14px;
  background: linear-gradient(to top, var(--paper) 65%, transparent);
}

.composer {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 22px;
  padding: 10px 10px 10px 20px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease;
}

.composer:focus-within { border-color: var(--terra); }

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  max-height: 140px;
  padding: 4px 0;
}

.composer textarea::placeholder { color: var(--ink-faint); }

.send {
  flex: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 14px;
  background: var(--terra);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.18s ease;
}

.send:hover:not(:disabled) { transform: scale(1.06) rotate(-4deg); background: #ad4623; }
.send:disabled { background: var(--line); color: var(--ink-faint); cursor: default; }

.footnote {
  text-align: center;
  font-size: 11px;
  color: var(--ink-faint);
  margin: 10px 0 0;
}

/* ——— responsive ——— */

@media (max-width: 600px) {
  .topbar-sub { display: none; }
  .msg { max-width: 94%; }
  .bubble { padding: 15px 16px; }
  .hero { padding-top: 5vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* Campus route map (Leaflet) */
.route-map {
  height: 260px;
  margin-top: 14px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  z-index: 0;
}
.route-map .leaflet-container {
  height: 100%;
  width: 100%;
  font: inherit;
  background: #e9eef2;
}
