/* ============================================================
   Synapse UI — design shell
   Black canvas, living aurora, glass pill. Mobile-first.

   Aurora performance note: colours are STATIC per layer. We never
   animate gradient colours (that would re-rasterise the blurred
   gradients every frame). State changes cross-fade two layers via
   opacity, and only `transform`/`opacity` animate — both run on the
   compositor, so the blurred blob textures stay cached. Smooth on
   low-end mobile.
   ============================================================ */

:root {
  --bg: #000000;
  --fg: #f4f5f4;
  --fg-dim: #9aa0a0;
  --line: rgba(255, 255, 255, 0.1);

  --blob-blur: 42px;
  --blob-size: 60vmax;
  --blob-opacity: 0.6;

  --max-col: 720px;
  --app-h: 100dvh;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

/* ---------- Aurora ---------------------------------------- */
.aurora {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60vh;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* two stacked colour layers, cross-faded on state change */
.aurora__set {
  position: absolute;
  inset: 0;
  transition: opacity 1.1s ease;
  will-change: opacity;
}
.aurora__set--idle { opacity: 1; }
.aurora__set--think { opacity: 0; }
body[data-state="thinking"] .aurora__set--idle { opacity: 0; }
body[data-state="thinking"] .aurora__set--think { opacity: 1; }

.blob {
  position: absolute;
  bottom: -22vmax;
  width: var(--blob-size);
  height: var(--blob-size);
  border-radius: 50%;
  filter: blur(var(--blob-blur));
  opacity: var(--blob-opacity);
  will-change: transform;
  transform: translateZ(0);
}
.blob--1 { left: -14vmax; }
.blob--2 { left: 28vmax; }
.blob--3 { right: -16vmax; }

/* idle palette — calm green / amber / lime, slow drift */
.aurora__set--idle .blob--1 { background: radial-gradient(circle at 50% 50%, #34d399, transparent 62%); animation: drift1 16s ease-in-out infinite; }
.aurora__set--idle .blob--2 { background: radial-gradient(circle at 50% 50%, #fbbf24, transparent 62%); animation: drift2 21s ease-in-out infinite; }
.aurora__set--idle .blob--3 { background: radial-gradient(circle at 50% 50%, #a3e635, transparent 62%); animation: drift3 26s ease-in-out infinite; }

/* thinking palette — surging orange / red / rose, fast drift */
.aurora__set--think .blob--1 { background: radial-gradient(circle at 50% 50%, #ef4444, transparent 62%); animation: drift1 5s ease-in-out infinite; }
.aurora__set--think .blob--2 { background: radial-gradient(circle at 50% 50%, #fb923c, transparent 62%); animation: drift2 6.5s ease-in-out infinite; }
.aurora__set--think .blob--3 { background: radial-gradient(circle at 50% 50%, #fb7185, transparent 62%); animation: drift3 4.2s ease-in-out infinite; }

/* veil: melt the aurora into the black canvas toward the top */
.aurora__veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, transparent 0%, rgba(0, 0, 0, 0.35) 55%, var(--bg) 100%);
}

@keyframes drift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(10vmax, -6vmax) scale(1.18); }
}
@keyframes drift2 {
  0%, 100% { transform: translate(0, 0) scale(1.05); }
  50%      { transform: translate(-12vmax, -9vmax) scale(0.85); }
}
@keyframes drift3 {
  0%, 100% { transform: translate(0, 0) scale(0.95); }
  50%      { transform: translate(-8vmax, -5vmax) scale(1.22); }
}

/* ---------- App shell ------------------------------------- */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100svh;
  min-height: 100svh;
  height: var(--app-h); /* JS keeps this in sync with the visual viewport */
}

/* ---------- Thread ---------------------------------------- */
.thread {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: calc(16px + env(safe-area-inset-top)) 16px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.thread::-webkit-scrollbar { width: 7px; }
.thread::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
}

/* ---------- Messages -------------------------------------- */
.messages {
  width: 100%;
  max-width: var(--max-col);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.msg {
  animation: rise 0.45s ease both;
  font-size: 1rem;
  line-height: 1.6;
}
.msg--user {
  align-self: flex-end;
  max-width: 86%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  padding: 11px 16px;
  border-radius: 22px 22px 6px 22px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg--assistant {
  align-self: stretch;
  color: #e9eaea;
}
.msg--assistant > :first-child { margin-top: 0; }
.msg--assistant > :last-child { margin-bottom: 0; }
.msg--assistant p { margin: 0 0 0.85em; }
.msg--assistant h1, .msg--assistant h2, .msg--assistant h3 {
  font-weight: 500;
  line-height: 1.25;
  margin: 0 0 0.5em;
}
.msg--assistant h1 { font-size: 1.35rem; }
.msg--assistant h2 { font-size: 1.2rem; }
.msg--assistant h3 { font-size: 1.06rem; }
.msg--assistant ul { margin: 0 0 0.85em; padding-left: 1.25em; }
.msg--assistant li { margin: 0.15em 0; }
.msg--assistant a { color: #7dd3fc; text-underline-offset: 2px; }
.msg--assistant img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 14px;
  margin: 10px 0;
  border: 1px solid var(--line);
}
.msg--assistant code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.12em 0.4em;
  border-radius: 6px;
}
.msg--assistant pre {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.msg--assistant pre code {
  background: none;
  padding: 0;
  font-size: 0.86em;
  line-height: 1.55;
}

.msg--error {
  align-self: stretch;
  color: #fca5a5;
  font-size: 0.92rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  padding: 10px 14px;
}

/* ---------- Composer / pill ------------------------------- */
.composer {
  flex: 0 0 auto;
  padding: 8px 14px calc(12px + env(safe-area-inset-bottom));
}
.pill {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: var(--max-col);
  margin: 0 auto;
  padding: 7px 7px 7px 8px;
  background: rgba(22, 22, 24, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 28px;
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  transition: border-color 0.2s ease;
}
.pill:focus-within { border-color: rgba(255, 255, 255, 0.26); }

.pill__logo {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pill__logo img { display: block; opacity: 0.95; }

.pill__input {
  flex: 1 1 auto;
  min-width: 0;
  align-self: center;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--fg);
  font: inherit;
  font-size: 16px; /* >=16px avoids iOS zoom-on-focus */
  line-height: 1.4;
  max-height: 40vh;
  padding: 9px 2px;
  overflow-y: auto;
}
.pill__input::placeholder {
  color: var(--fg-dim);
  font-family: "Montserrat", sans-serif;
  font-weight: 100;
  letter-spacing: 0.06em;
}

.pill__send {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--fg); /* flat icon, constant colour in every state */
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease;
}
.pill__send:active { transform: scale(0.9); }
.pill__send:disabled { cursor: default; }

/* ---------- Dev panel ------------------------------------- */
.devpanel {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  z-index: 50;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  background: rgba(20, 20, 22, 0.85);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}
.devpanel[hidden] { display: none; }
.devpanel__title {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-right: 2px;
}
.devpanel button {
  font: inherit;
  font-size: 0.78rem;
  padding: 5px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  cursor: pointer;
}
.devpanel button:active { transform: scale(0.94); }

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

/* ---------- Larger screens -------------------------------- */
@media (min-width: 768px) {
  .thread { padding: calc(16px + env(safe-area-inset-top)) 24px 28px; }
  .composer { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}

/* ---------- Reduced motion -------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .blob {
    animation: none !important;
    transform: translateY(-4vmax) scale(1.05);
  }
  .aurora__set { transition: none; }
  .msg { animation: none !important; }
}
