/* Screen-reader-only text: keeps form labels accessible without adding visible copy. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Index agent: centered character and chat UI preview. */
.index-agent {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  width: min(520px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  transform: translate(-50%, -47%);
}

.index-agent-character {
  position: relative;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Penguin sprite stage: stable square prevents animation from shifting the chat box. */
.index-agent-sprite {
  position: relative;
  width: clamp(210px, 24vw, 330px);
  aspect-ratio: 1;
  animation: index-agent-float 3.6s ease-in-out infinite;
}

/* Sprite frames: resting penguin, blink poses, and two waving poses. */
.index-agent-sprite img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  image-rendering: auto;
  animation-duration: 18s;
  animation-timing-function: steps(1, end);
  animation-iteration-count: infinite;
}

.index-agent-sprite img:nth-child(1) {
  animation-name: index-agent-rest-frame;
}

.index-agent-sprite img:nth-child(2) {
  animation-name: index-agent-blink-frame-two;
}

.index-agent-sprite img:nth-child(3) {
  animation-name: index-agent-blink-frame-three;
}

.index-agent-sprite img:nth-child(4) {
  animation-name: index-agent-blink-frame-four;
}

.index-agent-sprite img:nth-child(5) {
  animation-name: index-agent-wave-frame-one;
  transform: scale(1.08);
}

.index-agent-sprite img:nth-child(6) {
  animation-name: index-agent-wave-frame-two;
  transform: scale(1.08);
}

.index-agent-sprite img:nth-child(7),
.index-agent-sprite img:nth-child(8),
.index-agent-sprite img:nth-child(9),
.index-agent-sprite img:nth-child(10),
.index-agent-sprite img:nth-child(11),
.index-agent-sprite img:nth-child(12),
.floating-agent-sprite img:nth-child(7),
.floating-agent-sprite img:nth-child(8),
.floating-agent-sprite img:nth-child(9),
.floating-agent-sprite img:nth-child(10),
.floating-agent-sprite img:nth-child(11),
.floating-agent-sprite img:nth-child(12) {
  animation: none;
  opacity: 0;
}

.index-agent.is-sleeping .index-agent-sprite img,
.floating-agent.is-sleeping .floating-agent-sprite img {
  animation: none;
  opacity: 0;
}

.index-agent.is-sleeping .index-agent-sprite img:nth-child(7),
.floating-agent.is-sleeping .floating-agent-sprite img:nth-child(7) {
  animation: penguin-sleep-frame-one 1.4s steps(1, end) infinite;
}

.index-agent.is-sleeping .index-agent-sprite img:nth-child(8),
.floating-agent.is-sleeping .floating-agent-sprite img:nth-child(8) {
  animation: penguin-sleep-frame-two 1.4s steps(1, end) infinite;
  transform: scale(1.06);
}

.index-agent.is-loving .index-agent-sprite img,
.floating-agent.is-loving .floating-agent-sprite img {
  animation: none;
  opacity: 0;
}

.index-agent.is-loving .index-agent-sprite img:nth-child(9),
.floating-agent.is-loving .floating-agent-sprite img:nth-child(9) {
  animation: penguin-love-frame-one 4s steps(1, end) 1;
  transform: scale(1.12);
}

.index-agent.is-loving .index-agent-sprite img:nth-child(10),
.floating-agent.is-loving .floating-agent-sprite img:nth-child(10) {
  animation: penguin-love-frame-two 4s steps(1, end) 1;
  transform: scale(1.08);
}

.index-agent.is-sad .index-agent-sprite img,
.floating-agent.is-sad .floating-agent-sprite img {
  animation: none;
  opacity: 0;
}

.index-agent.is-sad .index-agent-sprite img:nth-child(11),
.floating-agent.is-sad .floating-agent-sprite img:nth-child(11) {
  animation: penguin-sad-frame-one 2.8s steps(1, end) 1 forwards;
}

.index-agent.is-sad .index-agent-sprite img:nth-child(12),
.floating-agent.is-sad .floating-agent-sprite img:nth-child(12) {
  animation: penguin-sad-frame-two 2.8s steps(1, end) 1 forwards;
}

/* Agent response: code-drawn speech bubble that expands with its text. */
.index-agent-dialogue {
  position: absolute;
  left: calc(100% + 34px);
  top: 16%;
  z-index: 8;
  width: max-content;
  min-width: 230px;
  max-width: min(360px, calc(50vw - 72px));
  padding: 18px 21px;
  border: 0;
  border-radius: 20px;
  background: #f5f5f3;
  color: #111316;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(10px) scale(0.96);
  transform-origin: 0 50%;
  transition: opacity 180ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1), visibility 180ms ease;
}

/* Bubble tail: overlaps the body so it reads as one continuous shape. */
.index-agent-dialogue-tail {
  position: absolute;
  left: -17px;
  top: 54%;
  z-index: 2;
  width: 30px;
  height: 30px;
  background: #f5f5f3;
  clip-path: polygon(100% 0, 100% 100%, 0 50%);
  transform: translateY(-50%);
}

.index-agent-dialogue .penguin-dialogue-content {
  max-width: 100%;
  max-height: min(42vh, 360px);
  padding-right: 7px;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 15.5px;
  line-height: 1.48;
  font-weight: 400;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.penguin-dialogue-content::-webkit-scrollbar {
  width: 7px;
}

.penguin-dialogue-content::-webkit-scrollbar-track {
  background: rgba(17, 19, 22, 0.08);
  border-radius: 999px;
}

.penguin-dialogue-content::-webkit-scrollbar-thumb {
  background: rgba(17, 19, 22, 0.38);
  border-radius: 999px;
}

.penguin-response-line + .penguin-response-line {
  margin-top: 0.18em;
}

.penguin-response-gap {
  height: 0.72em;
}

.penguin-response-list-item {
  position: relative;
  padding-left: 1.2em;
}

.penguin-response-list-item::before {
  content: attr(data-marker);
  position: absolute;
  left: 0;
  font-weight: 700;
}

.penguin-dialogue-content strong {
  font-weight: 700;
}

.index-agent-dialogue.is-thinking .penguin-dialogue-content::after,
.floating-agent-dialogue.is-thinking .penguin-dialogue-content::after {
  content: ".";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: penguin-thinking-dots 1.2s steps(1, end) infinite;
}

.index-agent-dialogue.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

/* Chat shell: rounded gray composer that grows with multiple lines. */
.index-agent-chat {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  align-items: end;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 13px;
  background: #55585d;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

/* Chat input: grows until the composer reaches its practical height limit. */
.index-agent-chat textarea {
  min-width: 0;
  min-height: 62px;
  max-height: 176px;
  padding: 20px 18px 18px;
  resize: none;
  overflow: hidden;
  overscroll-behavior: contain;
  border: 0;
  outline: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.94);
  font: 500 17px/1.45 Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

.index-agent-chat textarea::placeholder {
  color: rgba(255, 255, 255, 0.5);
  font-size: 17px;
}

.index-agent-chat:focus-within {
  border-color: rgba(19, 216, 255, 0.58);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.32),
    0 0 0 1px rgba(19, 216, 255, 0.18);
}

/* Send control: visual-only arrow button for the current UI pass. */
.index-agent-send {
  position: relative;
  width: 64px;
  height: 64px;
  align-self: end;
  border: 0;
  border-left: 0;
  background: #55585d;
  color: #fff;
  cursor: pointer;
  transition: background 160ms ease;
}

.index-agent-send:hover,
.index-agent-send:focus-visible {
  background: #55585d;
}

.index-agent-send:focus-visible {
  outline: 2px solid rgba(19, 216, 255, 0.72);
  outline-offset: -3px;
}

/* Send icon: cleaned version of the supplied send-button asset. */
.index-agent-send img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: invert(1);
  transform: rotate(180deg);
}

@keyframes index-agent-rest-frame {
  0%,
  4.99%,
  13%,
  37.99%,
  39.68%,
  59.99%,
  61.68%,
  83.99%,
  92%,
  100% {
    opacity: 1;
  }

  5%,
  12.99%,
  38%,
  39.67%,
  60%,
  61.67%,
  84%,
  91.99% {
    opacity: 0;
  }
}

@keyframes index-agent-blink-frame-two {
  0%,
  37.99%,
  38.56%,
  59.99%,
  60.56%,
  100% {
    opacity: 0;
  }

  38%,
  38.55%,
  60%,
  60.55% {
    opacity: 1;
  }
}

@keyframes index-agent-blink-frame-three {
  0%,
  38.55%,
  39.12%,
  60.55%,
  61.12%,
  100% {
    opacity: 0;
  }

  38.56%,
  39.11%,
  60.56%,
  61.11% {
    opacity: 1;
  }
}

@keyframes index-agent-blink-frame-four {
  0%,
  39.11%,
  39.68%,
  61.11%,
  61.68%,
  100% {
    opacity: 0;
  }

  39.12%,
  39.67%,
  61.12%,
  61.67% {
    opacity: 1;
  }
}

@keyframes index-agent-wave-frame-one {
  0%,
  4.99%,
  7%,
  8.99%,
  11%,
  83.99%,
  86%,
  87.99%,
  90%,
  100% {
    opacity: 0;
  }

  5%,
  6.99%,
  9%,
  10.99%,
  84%,
  85.99%,
  88%,
  89.99% {
    opacity: 1;
  }
}

@keyframes index-agent-wave-frame-two {
  0%,
  6.99%,
  9%,
  10.99%,
  13%,
  85.99%,
  88%,
  89.99%,
  92%,
  100% {
    opacity: 0;
  }

  7%,
  8.99%,
  11%,
  12.99%,
  86%,
  87.99%,
  90%,
  91.99% {
    opacity: 1;
  }
}

@keyframes index-agent-float {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

@keyframes penguin-sleep-frame-one {
  0%,
  49.99% {
    opacity: 1;
  }

  50%,
  100% {
    opacity: 0;
  }
}

@keyframes penguin-sleep-frame-two {
  0%,
  49.99% {
    opacity: 0;
  }

  50%,
  100% {
    opacity: 1;
  }
}

@keyframes penguin-thinking-dots {
  0%,
  33.32% {
    content: ".";
  }

  33.33%,
  66.65% {
    content: "..";
  }

  66.66%,
  100% {
    content: "...";
  }
}

@keyframes penguin-love-frame-one {
  0%,
  24.99%,
  50%,
  74.99% {
    opacity: 1;
  }

  25%,
  49.99%,
  75%,
  100% {
    opacity: 0;
  }
}

@keyframes penguin-love-frame-two {
  0%,
  24.99%,
  50%,
  74.99% {
    opacity: 0;
  }

  25%,
  49.99%,
  75%,
  100% {
    opacity: 1;
  }
}

@keyframes penguin-sad-frame-one {
  0%,
  24.99%,
  50%,
  74.99% {
    opacity: 1;
  }

  25%,
  49.99%,
  75%,
  100% {
    opacity: 0;
  }
}

@keyframes penguin-sad-frame-two {
  0%,
  24.99%,
  50%,
  74.99% {
    opacity: 0;
  }

  25%,
  49.99%,
  75%,
  100% {
    opacity: 1;
  }
}

/* Floating agent: compact draggable assistant shown on every non-index page. */
.floating-agent {
  position: fixed;
  right: 96px;
  bottom: 52px;
  z-index: 100000;
  width: min(460px, calc(100vw - 64px));
  display: grid;
  grid-template-columns: 132px 42px 24px minmax(0, 1fr);
  grid-template-areas: "sprite search . content";
  align-items: center;
  gap: 0;
  opacity: 1;
  visibility: visible;
  transition: opacity 180ms ease, visibility 180ms ease;
}

body.is-index-page .floating-agent {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.floating-agent.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.floating-agent-sprite {
  grid-area: sprite;
  position: relative;
  width: 142px;
  aspect-ratio: 1;
  cursor: grab;
  touch-action: none;
  animation: index-agent-float 3.6s ease-in-out infinite;
}

.floating-agent-sprite:active {
  cursor: grabbing;
}

.floating-agent-sprite img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  animation-duration: 18s;
  animation-timing-function: steps(1, end);
  animation-iteration-count: infinite;
}

.floating-agent-sprite img:nth-child(1) { animation-name: index-agent-rest-frame; }
.floating-agent-sprite img:nth-child(2) { animation-name: index-agent-blink-frame-two; }
.floating-agent-sprite img:nth-child(3) { animation-name: index-agent-blink-frame-three; }
.floating-agent-sprite img:nth-child(4) { animation-name: index-agent-blink-frame-four; }
.floating-agent-sprite img:nth-child(5) { animation-name: index-agent-wave-frame-one; transform: scale(1.08); }
.floating-agent-sprite img:nth-child(6) { animation-name: index-agent-wave-frame-two; transform: scale(1.08); }

.floating-agent-search {
  grid-area: search;
  position: relative;
  z-index: 2;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: #55585d;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.82);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease, visibility 160ms ease;
}

.floating-agent.has-response .floating-agent-search {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
}

.floating-agent-search:hover,
.floating-agent-search:focus-visible {
  background: #62656a;
  transform: scale(1.06);
}

.floating-agent-search:focus-visible {
  outline: 2px solid rgba(19, 216, 255, 0.72);
  outline-offset: 3px;
}

.floating-agent-search img {
  width: 27px;
  height: 27px;
  object-fit: contain;
  filter: invert(1);
}

/* Floating composer: same behavior as index, scaled for a persistent utility. */
.floating-agent-chat {
  grid-column: 2 / 5;
  grid-row: 1;
  z-index: 3;
  width: calc(100% - 40px);
  justify-self: start;
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: end;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 11px;
  background: #55585d;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.38);
  transform: scaleX(1);
  transform-origin: 0 50%;
  transition: opacity 160ms ease, transform 200ms cubic-bezier(0.22, 1, 0.36, 1), visibility 160ms ease;
}

.floating-agent.has-response .floating-agent-chat {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scaleX(0.18);
}

.floating-agent-chat:focus-within {
  border-color: rgba(19, 216, 255, 0.58);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(19, 216, 255, 0.18);
}

.floating-agent-chat textarea {
  min-width: 0;
  min-height: 46px;
  max-height: 116px;
  padding: 14px 13px 12px;
  resize: none;
  overflow: hidden;
  overscroll-behavior: contain;
  border: 0;
  outline: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.94);
  font: 500 14px/1.42 Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

.floating-agent-chat textarea::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.floating-agent-send {
  width: 48px;
  height: 48px;
  align-self: end;
  border: 0;
  background: #55585d;
  color: #fff;
  cursor: pointer;
}

.index-agent.is-streaming .index-agent-send,
.floating-agent.is-streaming .floating-agent-send,
.floating-agent-search:disabled {
  cursor: wait;
  opacity: 0.55;
}

.floating-agent-send:focus-visible {
  outline: 2px solid rgba(19, 216, 255, 0.72);
  outline-offset: -3px;
}

.floating-agent-send img {
  width: 29px;
  height: 29px;
  object-fit: contain;
  filter: invert(1);
  transform: rotate(180deg);
}

/* Floating response replaces the composer to the right of the penguin. */
.floating-agent-dialogue {
  grid-area: content;
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 14px 16px;
  border: 0;
  border-radius: 16px;
  background: #f5f5f3;
  color: #111316;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(8px) scale(0.96);
  transform-origin: 0 50%;
  transition: opacity 180ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1), visibility 180ms ease;
}

.floating-agent-dialogue.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

.floating-agent-dialogue .penguin-dialogue-content {
  position: relative;
  z-index: 1;
  max-height: min(46vh, 340px);
  padding-right: 7px;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 14px;
  line-height: 1.45;
  font-weight: 400;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.floating-agent-dialogue-tail {
  position: absolute;
  left: -15px;
  top: 50%;
  z-index: 2;
  width: 24px;
  height: 24px;
  background: #f5f5f3;
  clip-path: polygon(100% 0, 100% 100%, 0 50%);
  transform: translateY(-50%);
}

@media (max-width: 900px) {
  .floating-agent {
    right: 32px;
    bottom: 28px;
    width: min(390px, calc(100vw - 28px));
    grid-template-columns: 100px 36px 22px minmax(0, 1fr);
    gap: 0;
  }

  .floating-agent-sprite {
    width: 108px;
  }

  .floating-agent-search {
    width: 36px;
    height: 36px;
  }

  .floating-agent-search img {
    width: 23px;
    height: 23px;
  }

  .floating-agent-chat {
    width: calc(100% - 30px);
    min-height: 44px;
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .floating-agent-chat textarea {
    min-height: 42px;
    max-height: 96px;
    padding: 12px 11px 10px;
    font-size: 13px;
  }

  .floating-agent-send {
    width: 44px;
    height: 44px;
  }

  .floating-agent-send img {
    width: 26px;
    height: 26px;
  }

  .floating-agent-dialogue {
    padding: 12px 13px;
  }

  .floating-agent-dialogue .penguin-dialogue-content {
    font-size: 13px;
  }

  /* Mobile index agent sizing. */
  .index-agent {
    width: min(440px, calc(100vw - 36px));
    gap: 16px;
    transform: translate(-50%, -43%);
  }

  .index-agent-sprite {
    width: clamp(185px, 56vw, 260px);
  }

  .index-agent-chat {
    min-height: 56px;
    grid-template-columns: minmax(0, 1fr) 56px;
    border-radius: 12px;
  }

  .index-agent-chat textarea {
    min-height: 54px;
    max-height: 140px;
    padding: 16px 15px 14px;
    font-size: 16px;
  }

  .index-agent-chat textarea::placeholder {
    font-size: 16px;
  }

  .index-agent-send {
    width: 56px;
    height: 56px;
  }

  .index-agent-dialogue {
    left: calc(100% + 10px);
    top: 12%;
    min-width: min(160px, 43vw);
    max-width: 43vw;
    padding: 15px 17px;
    border-width: 3px;
    border-radius: 17px;
    transform: translateX(8px) scale(0.96);
    transform-origin: 0 50%;
  }

  .index-agent-dialogue.is-visible {
    transform: translateX(0) scale(1);
  }

  .index-agent:has(.index-agent-dialogue.is-visible) .index-agent-character {
    transform: translateX(-25vw);
  }

  .index-agent-dialogue .penguin-dialogue-content {
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .index-agent-sprite,
  .floating-agent-sprite {
    animation: none;
  }

  .index-agent-sprite img,
  .floating-agent-sprite img {
    animation: none;
  }

  .index-agent-sprite img:first-child,
  .floating-agent-sprite img:first-child {
    opacity: 1;
  }

  .index-agent.is-sleeping .index-agent-sprite img:first-child,
  .floating-agent.is-sleeping .floating-agent-sprite img:first-child {
    opacity: 0;
  }

  .index-agent.is-sleeping .index-agent-sprite img:nth-child(7),
  .floating-agent.is-sleeping .floating-agent-sprite img:nth-child(7) {
    animation: none;
    opacity: 1;
  }

  .index-agent.is-loving .index-agent-sprite img:first-child,
  .floating-agent.is-loving .floating-agent-sprite img:first-child {
    opacity: 0;
  }

  .index-agent.is-loving .index-agent-sprite img:nth-child(9),
  .floating-agent.is-loving .floating-agent-sprite img:nth-child(9) {
    animation: none;
    opacity: 1;
  }

  .index-agent.is-sad .index-agent-sprite img:first-child,
  .floating-agent.is-sad .floating-agent-sprite img:first-child {
    opacity: 0;
  }

  .index-agent.is-sad .index-agent-sprite img:nth-child(11),
  .floating-agent.is-sad .floating-agent-sprite img:nth-child(11) {
    animation: none;
    opacity: 1;
  }
}
