.stellina-assistant {
  --stellina-gutter: 20px;
  --stellina-dock-size: 60px;
  --stellina-nav-offset: 0px;
  --stellina-safe-bottom: var(--mobile-safe-bottom, env(safe-area-inset-bottom, 0px));
  --stellina-safe-right: env(safe-area-inset-right, 0px);
  --stellina-safe-left: env(safe-area-inset-left, 0px);
  --stellina-dock-bottom: calc(var(--stellina-safe-bottom) + var(--stellina-nav-offset) + var(--stellina-gutter));
  --stellina-panel-lift: calc(var(--stellina-dock-bottom) + var(--stellina-dock-size) + 12px);
  --stellina-panel-top: max(14px, env(safe-area-inset-top, 0px));
  --stellina-window-height: 100vh;
  --stellina-frame: #494063;
  --stellina-header: #242039;
  --stellina-thread-bg: #131521;
  --stellina-reply: #202234;
  --stellina-question: #33274e;
  --stellina-button: #c4afff;
  --stellina-button-hover: #d6c7ff;
  --stellina-button-text: #201735;
  --stellina-halo: #926ce05c;
  --stellina-shadow: 0 22px 64px #0304119c, 0 4px 14px #09051253;
}

@supports (height: 100dvh) {
  .stellina-assistant { --stellina-window-height: 100dvh; }
}

html[data-theme="light"] .stellina-assistant {
  --stellina-frame: #d8c8f5;
  --stellina-header: #f0e7ff;
  --stellina-thread-bg: #faf8fd;
  --stellina-reply: #fff;
  --stellina-question: #eee5ff;
  --stellina-button: #6843e8;
  --stellina-button-hover: #5731ce;
  --stellina-button-text: #fff;
  --stellina-halo: #b69aea8c;
  --stellina-shadow: 0 20px 62px #38205d26, 0 4px 14px #38205d14;
}

.mobile-app .stellina-assistant {
  --stellina-nav-offset: var(--mobile-nav-height, 74px);
}

.mobile-app.mobile-keyboard-open .stellina-assistant {
  --stellina-nav-offset: 0px;
}

.stellina-launcher {
  position: fixed;
  z-index: 90;
  inset: auto calc(var(--stellina-gutter) + var(--stellina-safe-right)) var(--stellina-dock-bottom) auto;
  display: grid;
  place-items: center;
  width: var(--stellina-dock-size);
  height: var(--stellina-dock-size);
  padding: 4px;
  border: 1px solid var(--stellina-frame);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 28%, #fff0c9, #d7bdfb 73%);
  box-shadow: 0 5px 16px #3d27614a, 0 0 0 4px var(--stellina-halo);
  color: #482b80;
  transition: box-shadow .18s;
}

.stellina-launcher:hover,
.stellina-launcher[aria-expanded="true"] {
  box-shadow: 0 7px 22px #3d276168, 0 0 0 5px var(--stellina-halo);
}

.stellina-launcher img,
.stellina-panel-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.stellina-launcher-indicator {
  position: absolute;
  inset: auto -3px 1px auto;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 2px solid var(--space-card);
  border-radius: 50%;
  background: #6843e8;
  color: #fff;
  font-size: 10px;
  line-height: 1;
}

.stellina-launcher-indicator .icon { width: 10px; height: 10px; }
.nav-open .stellina-launcher,
.mobile-keyboard-open .stellina-launcher { visibility: hidden; }

dialog.stellina-panel {
  position: fixed;
  z-index: 180;
  inset: auto calc(var(--stellina-gutter) + var(--stellina-safe-right)) max(var(--stellina-panel-lift), var(--stellina-viewport-bottom, 0px)) auto;
  width: min(400px, calc(100vw - var(--stellina-safe-left) - var(--stellina-safe-right) - 2 * var(--stellina-gutter)));
  height: min(580px, calc(var(--stellina-viewport-height, var(--stellina-window-height)) - var(--stellina-panel-lift) - var(--stellina-panel-top)));
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--stellina-frame);
  border-radius: 22px;
  background: var(--space-card);
  color: var(--text-main);
  box-shadow: var(--stellina-shadow);
}

.stellina-panel[open] {
  display: flex;
  flex-direction: column;
  animation: stellina-panel-enter .2s ease-out both;
}

@keyframes stellina-panel-enter {
  from { opacity: .5; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.stellina-panel-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 12px 13px 12px 16px;
  border-bottom: 1px solid var(--stellina-frame);
  background: radial-gradient(ellipse at 4% -10%, var(--stellina-halo), transparent 80%), var(--stellina-header);
}

.stellina-panel-avatar {
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  padding: 3px;
  border: 1px solid var(--stellina-frame);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 28%, #fff0c9, #d7bdfb 73%);
}

.stellina-panel-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 730;
  letter-spacing: -.035em;
  line-height: 1.2;
}

.stellina-panel-head :is(small, p) {
  display: block;
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.stellina-panel .stellina-panel-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-main);
}

.stellina-panel-close:hover { background: var(--space-card); }
.stellina-panel-close .icon { width: 19px; height: 19px; }

.stellina-panel-content {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.stellina-source-row {
  display: grid;
  flex: none;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 15px;
  border-bottom: 1px solid var(--space-border);
  color: var(--text-muted);
  font-size: 13px;
}

.stellina-panel .stellina-source {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 6px 9px;
  border: 1px solid var(--stellina-frame);
  border-radius: 9px;
  background: var(--space-card);
  color: var(--text-main);
  font-size: 14px;
  text-overflow: ellipsis;
}

.stellina-library-link {
  grid-column: 2;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  font-weight: 650;
}

.stellina-library-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.stellina-thread {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 10px;
  min-height: 62px;
  padding: 14px 15px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--stellina-thread-bg);
}

.stellina-welcome {
  align-self: flex-start;
  max-width: 30ch;
  margin: 0;
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.55;
}

.stellina-bubble {
  flex: none;
  align-self: flex-start;
  max-width: 92%;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--space-border);
  border-radius: 15px 15px 15px 5px;
  background: var(--stellina-reply);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.stellina-bubble.is-user {
  align-self: flex-end;
  border-color: var(--stellina-frame);
  border-radius: 15px 15px 5px 15px;
  background: var(--stellina-question);
  white-space: pre-wrap;
}

.stellina-bubble :is(h1, h2, h3, h4) { font-size: 1em; }
.stellina-bubble :is(h1, h2, h3, h4, p, ul, ol, pre) { margin: 0 0 .65em; }
.stellina-bubble > :last-child { margin-bottom: 0; }
.stellina-bubble :is(ul, ol) { padding-inline-start: 1.35em; }
.stellina-bubble pre { max-width: 100%; overflow: auto; }
.stellina-bubble a { color: var(--accent); text-decoration: underline; }

.stellina-panel a.cite {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  max-width: 100%;
  padding: 2px 7px;
  border: 1px solid var(--stellina-frame);
  border-radius: 8px;
  background: var(--stellina-question);
  color: var(--accent);
  font-size: .86em;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.stellina-panel a.cite:hover { text-decoration: underline; }

.stellina-suggestions {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 15px 9px;
  background: var(--stellina-thread-bg);
}

.stellina-suggestions button {
  min-height: 44px;
  padding: 6px 11px;
  border: 1px solid var(--stellina-frame);
  border-radius: 999px;
  background: var(--stellina-reply);
  color: var(--text-main);
  font-size: 12px;
  line-height: 1.35;
}

.stellina-suggestions button:hover { background: var(--stellina-question); }

.stellina-chat-status {
  flex: none;
  margin: 0;
  padding: 4px 16px;
  background: var(--stellina-thread-bg);
  color: var(--text-muted);
  font-size: 12px;
}

.stellina-chat-status:empty { display: none; }
.stellina-chat-status:is(.is-error, [data-state="error"]) { color: var(--danger); }

.stellina-compose {
  display: grid;
  flex: none;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 7px;
  margin: 0;
  padding: 9px 13px 7px;
  border-top: 1px solid var(--space-border);
}

.stellina-panel .stellina-compose textarea {
  width: 100%;
  min-height: 44px;
  max-height: 112px;
  padding: 10px 11px;
  resize: vertical;
  border: 1px solid var(--stellina-frame);
  border-radius: 12px;
  background: var(--stellina-thread-bg);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
}

.stellina-compose textarea::placeholder { color: var(--text-muted); }

.stellina-panel .stellina-compose button[type="submit"] {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: var(--stellina-button);
  color: var(--stellina-button-text);
  font-weight: 650;
}

.stellina-panel .stellina-compose button[type="submit"]:hover:not(:disabled) { background: var(--stellina-button-hover); }
.stellina-compose button .icon { width: 18px; height: 18px; }

.stellina-panel-footer {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 2px 8px;
  padding: 0 13px 3px;
}

.stellina-panel-footer :is(a, button, label) {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 2px 3px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: start;
}

.stellina-panel-footer a { color: var(--accent); font-weight: 650; }
.stellina-panel-footer :is(a, button):hover { text-decoration: underline; text-underline-offset: 3px; }
.stellina-panel-footer .icon { width: 14px; height: 14px; }
.stellina-panel-footer label { cursor: pointer; }

.stellina-panel .stellina-motion-toggle {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

@media (max-width: 650px) {
  .stellina-assistant {
    --stellina-gutter: 12px;
    --stellina-dock-size: 54px;
    --stellina-panel-lift: var(--stellina-dock-bottom);
  }

  dialog.stellina-panel {
    left: calc(var(--stellina-gutter) + var(--stellina-safe-left));
    width: auto;
    max-width: 480px;
    height: min(520px, calc(var(--stellina-viewport-height, var(--stellina-window-height)) - var(--stellina-panel-lift) - var(--stellina-panel-top)));
    margin-inline: auto;
    border-radius: 19px;
  }

  .stellina-launcher[aria-expanded="true"] { visibility: hidden; }
  .stellina-panel .stellina-source,
  .stellina-panel .stellina-compose textarea { font-size: 16px; }
  .mobile-keyboard-open .stellina-suggestions { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stellina-panel[open] { animation: none; }
  .stellina-launcher { transition: none; }
}
