.ribosome-launcher {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 72;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 7px 16px 7px 8px;
  border: 1px solid rgba(107, 225, 255, .52);
  border-radius: 999px;
  color: #f5fbff;
  background: linear-gradient(135deg, rgba(16, 31, 58, .98), rgba(24, 18, 52, .98));
  box-shadow: 0 18px 52px rgba(0, 0, 0, .46), 0 0 30px rgba(67, 229, 255, .12);
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}

body.ribosome-open { overflow: hidden; }

.ribosome-launcher:hover,
.ribosome-launcher:focus-visible {
  transform: translateY(-2px);
  border-color: var(--cyan);
  box-shadow: 0 20px 58px rgba(0, 0, 0, .5), 0 0 34px rgba(67, 229, 255, .2);
}

.ribosome-launcher[aria-expanded="true"] { opacity: 0; pointer-events: none; }
.ribosome-launcher img { width: 44px; height: 44px; object-fit: contain; }
.ribosome-launcher span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.ribosome-launcher strong { font: 800 13px "Manrope", sans-serif; letter-spacing: .01em; }
.ribosome-launcher small { margin-top: 4px; color: #8ea7c4; font-size: 10px; }

.ribosome-dialog {
  position: fixed;
  inset: auto max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) auto;
  width: min(430px, calc(100vw - 32px));
  height: min(720px, calc(100dvh - 40px));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(76, 130, 169, .72);
  border-radius: 22px;
  color: var(--text);
  background: linear-gradient(180deg, #0b1428, #080f1f 58%, #070c18);
  box-shadow: 0 30px 100px rgba(0, 0, 0, .58), 0 0 45px rgba(67, 229, 255, .09);
}

.ribosome-dialog[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.ribosome-dialog::backdrop { background: rgba(1, 4, 10, .62); backdrop-filter: blur(4px); }

.ribosome-head {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 14px 13px;
  border-bottom: 1px solid rgba(62, 90, 129, .5);
  background: radial-gradient(circle at 12% 0, rgba(67, 229, 255, .13), transparent 35%);
}

.ribosome-head img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  filter: drop-shadow(0 7px 14px rgba(35, 185, 225, .16));
}

.ribosome-head h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.ribosome-head p { margin: 2px 0 0; color: #90a7c3; font-size: 11px; }
.ribosome-status { color: var(--green); }
.ribosome-status::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: currentColor; box-shadow: 0 0 9px currentColor; }

.ribosome-close {
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 50%;
  color: #94a9c2;
  background: transparent;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.ribosome-close:hover,
.ribosome-close:focus-visible { color: white; border-color: var(--line2); background: rgba(255, 255, 255, .04); }

.ribosome-thread {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 15px 22px;
  scrollbar-width: thin;
  scrollbar-color: #304767 transparent;
}

.ribosome-message { display: flex; gap: 9px; margin: 0 0 14px; }
.ribosome-message.user { justify-content: flex-end; }
.ribosome-message-avatar { flex: 0 0 28px; width: 28px; height: 28px; margin-top: 3px; object-fit: contain; }
.ribosome-bubble { max-width: 86%; padding: 12px 13px; border: 1px solid #253b5d; border-radius: 6px 16px 16px 16px; color: #c9d7e7; background: #0e1a31; font-size: 13px; line-height: 1.55; }
.ribosome-message.user .ribosome-bubble { border-color: rgba(67, 229, 255, .35); border-radius: 16px 6px 16px 16px; color: #effbff; background: rgba(24, 112, 139, .23); }
.ribosome-bubble p { margin: 0 0 9px; white-space: pre-line; }
.ribosome-bubble p:last-child { margin-bottom: 0; }
.ribosome-bubble strong { color: #f4f8fd; }
.ribosome-bubble ul { margin: 8px 0 0; padding-left: 18px; }
.ribosome-bubble li + li { margin-top: 7px; }
.ribosome-bubble .ribosome-limit { color: #ffc978; }

.ribosome-sources { margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(67, 97, 136, .42); }
.ribosome-sources span { display: block; margin-bottom: 6px; color: #728aa7; font: 700 9px "Manrope", sans-serif; letter-spacing: .11em; text-transform: uppercase; }
.ribosome-sources a { display: block; padding: 5px 0; color: #73e7f8; font-size: 11px; line-height: 1.35; }
.ribosome-sources a:hover { color: white; }
.ribosome-web-citations { margin-top: 12px !important; padding-top: 10px; border-top: 1px solid rgba(67, 97, 136, .42); color: #a5bad0; font-size: 12px; }
.ribosome-web-citations a { color: #73e7f8; text-decoration: underline; text-underline-offset: 2px; }

.ribosome-suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.ribosome-suggestions button {
  padding: 7px 9px;
  border: 1px solid #2b4968;
  border-radius: 999px;
  color: #b6c9dc;
  background: rgba(12, 28, 50, .78);
  font-size: 10px;
  line-height: 1.25;
  cursor: pointer;
}
.ribosome-suggestions button:hover,
.ribosome-suggestions button:focus-visible { border-color: var(--cyan); color: white; }

.ribosome-thinking { display: inline-flex; gap: 4px; align-items: center; min-height: 12px; }
.ribosome-thinking i { width: 5px; height: 5px; border-radius: 50%; background: #75dfee; animation: ribosome-pulse 1s infinite ease-in-out; }
.ribosome-thinking i:nth-child(2) { animation-delay: .13s; }
.ribosome-thinking i:nth-child(3) { animation-delay: .26s; }
@keyframes ribosome-pulse { 0%, 70%, 100% { opacity: .3; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.ribosome-compose {
  padding: 11px 12px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(62, 90, 129, .5);
  background: rgba(6, 12, 24, .95);
}
.ribosome-form { display: grid; grid-template-columns: minmax(0, 1fr) 42px; gap: 8px; align-items: end; }
.ribosome-form textarea {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 43px;
  max-height: 112px;
  resize: none;
  padding: 11px 12px;
  border: 1px solid #2b4162;
  border-radius: 13px;
  outline: none;
  color: white;
  background: #0c172b;
  font-size: 13px;
  line-height: 1.45;
}
.ribosome-form textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(67, 229, 255, .08); }
.ribosome-send { width: 42px; height: 42px; border: 0; border-radius: 12px; color: #041119; background: linear-gradient(135deg, var(--cyan), #85c7ff); font-size: 18px; font-weight: 800; cursor: pointer; }
.ribosome-send:disabled { opacity: .45; cursor: wait; }
.ribosome-privacy { margin: 7px 2px 0; color: #657b96; font-size: 11px; line-height: 1.4; text-align: center; }

@media (max-width: 600px) {
  .ribosome-launcher { right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); min-height: 54px; padding-right: 14px; }
  .ribosome-launcher img { width: 40px; height: 40px; }
  .ribosome-dialog {
    --ribosome-top-gap: max(8px, env(safe-area-inset-top));
    --ribosome-bottom-gap: max(8px, env(safe-area-inset-bottom));
    --ribosome-left-gap: max(8px, env(safe-area-inset-left));
    --ribosome-right-gap: max(8px, env(safe-area-inset-right));
    inset: auto;
    top: calc(var(--ribosome-viewport-top, 0px) + var(--ribosome-top-gap));
    left: calc(var(--ribosome-viewport-left, 0px) + var(--ribosome-left-gap));
    box-sizing: border-box;
    width: calc(var(--ribosome-viewport-width, 100vw) - var(--ribosome-left-gap) - var(--ribosome-right-gap));
    height: calc(var(--ribosome-viewport-height, 100dvh) - var(--ribosome-top-gap) - var(--ribosome-bottom-gap));
    border-radius: 18px;
  }
  .ribosome-head { grid-template-columns: 40px minmax(0, 1fr) 44px; gap: 10px; padding: 8px 12px; }
  .ribosome-head img { width: 40px; height: 40px; }
  .ribosome-close { width: 44px; height: 44px; }
  .ribosome-thread { padding: 12px; }
  .ribosome-message { gap: 7px; margin-bottom: 10px; }
  .ribosome-message-avatar { flex-basis: 22px; width: 22px; height: 22px; }
  .ribosome-bubble { box-sizing: border-box; min-width: 0; max-width: 89%; padding: 10px 12px; font-size: 14px; overflow-wrap: anywhere; }
  .ribosome-dialog .ribosome-suggestions button { min-height: 36px; border-color: #375472; background: #14283e; color: #d3ecf7; font-size: 12px; }
  .ribosome-compose { padding: 9px 10px; }
  .ribosome-form { grid-template-columns: minmax(0, 1fr) 44px; }
  .ribosome-form textarea { min-height: 44px; max-height: 84px; padding: 9px 11px; font-size: 16px; caret-color: var(--reader-surface-link, #73e7f8); }
  .ribosome-send { width: 44px; height: 44px; }
  .ribosome-compose .ribosome-quota { margin: 6px 2px; }
  html[data-home-style="app"] .ribosome-dialog .ribosome-message.user .ribosome-bubble {
    background: #17364b !important;
    border-color: #376477 !important;
  }
}

/* Safari can show the page through its keyboard toolbar outside the visual viewport. */
@media (max-width: 600px) and (hover: none) and (pointer: coarse) {
  html:has(> body.ribosome-open) { background: var(--reader-surface, #0d1529); }
  body.ribosome-open > :not(.ribosome-dialog),
  body.ribosome-open::before,
  body.ribosome-open::after { opacity: 0 !important; }
  .ribosome-dialog[open] {
    --ribosome-top-gap: 0px;
    --ribosome-right-gap: 0px;
    --ribosome-bottom-gap: 0px;
    --ribosome-left-gap: 0px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .ribosome-dialog::backdrop {
    background: var(--reader-surface, #0d1529);
    backdrop-filter: none;
  }
  .ribosome-head { padding-top: max(8px, env(safe-area-inset-top)); }
  .ribosome-compose { padding-bottom: max(9px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .ribosome-launcher { transition: none; }
  .ribosome-thinking i { animation: none; opacity: .7; }
}

/* References stay available without repeating full article titles in the answer. */
.ribosome-references { margin-top: 12px; border-top: 1px solid rgba(67,97,136,.42); padding-top: 8px; }
.ribosome-references summary { cursor: pointer; font-size: 12px; color: #a5bad0; }
.ribosome-references .ribosome-sources { border: 0; padding-top: 4px; margin-top: 4px; }
.ribosome-bubble p > a { white-space: nowrap; font-size: .85em; text-decoration: underline; text-underline-offset: 2px; }

.ribosome-quota { margin: 8px 2px; color: #a5bad0; font-size: 12px; line-height: 1.4; }
.ribosome-quota a,.ribosome-signin { color: #73e7f8; text-decoration: underline; text-underline-offset: 2px; }
.ribosome-signin { display: inline-block; margin-top: 6px; }
.ribosome-disclosure { margin: 4px 2px 0; font-size: 12px; }
.ribosome-disclosure summary { cursor: pointer; }
.ribosome-disclosure p { max-height: 24dvh; overflow-y: auto; text-align: left; }

/* Keep the composer and its quota on the same surface in every saved palette. */
html[data-home-style] .ribosome-compose {
  background: var(--reader-surface, #0e0d0b) !important;
  border-color: var(--reader-edge, #bb8a43);
  color: var(--reader-surface-ink, #f7d58b);
}
html[data-home-style] .ribosome-compose :is(.ribosome-quota,.ribosome-privacy) {
  color: var(--reader-surface-soft, #e9d7b5) !important;
}
html[data-home-style] .ribosome-compose .ribosome-quota a,
html[data-home-style] .ribosome-bubble .ribosome-signin {
  color: var(--reader-surface-link, #f4c76e) !important;
}
html[data-home-style] .ribosome-form textarea::placeholder {
  color: var(--reader-surface-soft, #e9d7b5);
  opacity: 1;
}
