.companion {
  --companion-bottom: 5.5rem;
  --companion-height: calc(100dvh - 7rem);
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: var(--companion-bottom);
  z-index: 140;
  max-width: calc(100vw - 2rem);
  font: 400 0.78rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0;
}

.companion[hidden],
.companion [hidden] {
  display: none !important;
}

body.is-intro .companion,
body.is-password .companion,
body.is-site-revealing .companion,
body.is-locked .companion {
  visibility: hidden;
  pointer-events: none;
}

.companion button,
.companion a,
.companion input,
.companion select,
.companion textarea {
  -webkit-tap-highlight-color: transparent;
}

.companion :focus-visible {
  outline: 2px solid #a8f0ce;
  outline-offset: 3px;
}

.companion-launcher {
  position: relative;
  display: grid;
  justify-items: center;
  grid-template-rows: 10.5rem 1.25rem 1.25rem;
  width: 9rem;
  height: 13rem;
  padding: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.companion-figure {
  position: relative;
  display: block;
  width: 9rem;
  height: 10.5rem;
  transform-origin: 50% 100%;
  transition: transform 240ms ease;
}

.companion-sprite,
.companion-sprite-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.companion-figure[data-motion-ready="true"] .companion-sprite {
  visibility: hidden;
}

.companion-figure[data-gesture="nod"] {
  animation: companionNod 720ms steps(4, end) both;
}

@keyframes companionNod {
  0%, 100% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(2px) rotate(2deg); }
  65% { transform: translateY(-1px) rotate(-1deg); }
}

.companion-name {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.1rem 0.25rem;
  background: #0a0c0b;
  color: #e0e7e2;
  font-size: 0.6rem;
  line-height: 1rem;
}

.companion-dock {
  position: relative;
  width: 9rem;
}

.companion-activity {
  display: block;
  width: 100%;
  padding: 0.1rem;
  overflow: hidden;
  color: #a4b6aa;
  font-size: 0.58rem;
  line-height: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.companion:is([data-duo="true"], [data-wide="true"]) .companion-dock,
.companion:is([data-duo="true"], [data-wide="true"]) .companion-launcher,
.companion:is([data-duo="true"], [data-wide="true"]) .companion-figure {
  width: 14rem;
}

.companion-name > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.companion-name b {
  color: #a3b0a7;
  font-weight: 400;
}

.companion-controls {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
}

.companion-controls .companion-icon {
  position: relative;
  border-radius: 3px;
  background: #0c100ee6;
}

.companion-icon:disabled {
  opacity: 0.4;
  cursor: default;
}

.companion-controls [role="tooltip"] {
  position: absolute;
  right: 0;
  bottom: calc(100% + 5px);
  z-index: 2;
  width: max-content;
  max-width: 12rem;
  border: 1px solid #465349;
  padding: 0.3rem 0.45rem;
  background: #151b17;
  color: #d7e3db;
  font-size: 0.62rem;
  pointer-events: none;
  opacity: 0;
}

.companion-controls button:hover [role="tooltip"],
.companion-controls button:focus-visible [role="tooltip"] {
  opacity: 1;
}

.companion-speech {
  position: absolute;
  right: calc(100% + 0.5rem);
  bottom: 5.5rem;
  width: 18rem;
  border: 1px solid #4b6354;
  border-radius: 5px;
  padding: 0.9rem 2.5rem 0.9rem 0.9rem;
  background: #101b15;
  box-shadow: 0 8px 24px #0007;
  color: #ecf5ee;
  overflow-wrap: anywhere;
}

.companion-speech > span {
  display: block;
  margin-bottom: 0.5rem;
  color: #a8f0ce;
  font-size: 0.58rem;
}

.companion-speech p {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.55;
}

.companion-speech .companion-icon {
  position: absolute;
  top: 0;
  right: 0;
}

.companion-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  margin-right: -1.5rem;
}

.companion-replies button {
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid #4b6354;
  border-radius: 3px;
  background: #1b3022;
  color: #d4fbe5;
  font: inherit;
  font-size: 10px;
  text-align: left;
  cursor: pointer;
}

.companion-playbox {
  position: absolute;
  right: calc(100% + 12px);
  bottom: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(19rem, calc(100vw - 2rem));
  max-height: min(30rem, var(--companion-height));
  border: 1px solid #465c4d;
  border-radius: 5px;
  background: #0d1410;
  box-shadow: 0 10px 36px #0009;
}

.companion-playbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  border-bottom: 1px solid #314337;
  padding-left: 12px;
  background: #17201a;
}

.companion-playbar h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: #e4efe6;
  font: 500 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0;
}

.companion-playbody {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: #526959 #101712;
}

.companion-activity-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.companion-company {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  margin-bottom: 12px;
  color: #e4efe6;
  font-size: 11px;
  cursor: pointer;
}

.companion-company > span:nth-child(2) {
  flex: 1;
}

.companion-company small {
  display: block;
  margin-top: 3px;
  color: #a3b4aa;
  font-size: 9px;
}

.companion-company input {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: #a8f0ce;
}

.companion-vesta-thumb {
  position: relative;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  overflow: hidden;
}

.companion-vesta-thumb img {
  position: absolute;
  left: -34px;
  top: -2px;
  width: 288px;
  height: 96px;
  max-width: none;
  image-rendering: pixelated;
}

.companion-mode-label {
  margin: 16px 0 10px;
  border-top: 1px solid #33483a;
  padding-top: 12px;
  color: #99afa1;
  font-size: 10px;
}

.companion-activity-grid button {
  display: grid;
  place-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 74px;
  border: 1px solid #33483a;
  border-radius: 3px;
  padding: 9px 4px;
  background: #152119;
  color: #d4e2d8;
  font: inherit;
  font-size: 10px;
  line-height: 1.4;
  cursor: pointer;
}

.companion-activity-grid img {
  width: 22px;
  height: 22px;
}

.companion-activity-grid button:hover:not(:disabled),
.companion-context-choice:hover,
.companion-replies button:hover {
  border-color: #a8f0ce;
  background: #213b2a;
}

.companion-activity-grid button:disabled,
.companion-context-choice:disabled {
  opacity: 0.4;
  cursor: default;
}

.companion-context-choice {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 54px;
  margin-top: 10px;
  border: 0;
  border-top: 1px solid #35473b;
  padding: 10px 0;
  background: transparent;
  color: #a8f0ce;
  font: inherit;
  font-size: 11px;
  text-align: left;
  cursor: pointer;
}

.companion-context-choice > span:first-child {
  color: #94a69a;
  font-size: 10px;
}

.companion-play-status {
  display: block;
  margin-top: 8px;
  color: #a3b7a9;
  font-size: 10px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.companion-sketch-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 10px;
  margin-bottom: 10px;
}

.companion-inks {
  display: flex;
  gap: 2px;
}

.companion-inks button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}

.companion-inks button::before {
  content: "";
  width: 18px;
  height: 18px;
  background: var(--ink);
}

.companion-inks button[aria-pressed="true"] {
  border-color: var(--ink);
}

.companion-brush {
  display: grid;
  flex: 1;
  gap: 4px;
  min-width: 64px;
  max-width: 90px;
  color: #b5c2b9;
  font-size: 10px;
}

.companion-brush input {
  width: 100%;
  min-height: 24px;
  margin: 0;
  accent-color: #a8f0ce;
}

.companion-sketch-stage {
  position: relative;
}

.companion-sketch {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 12 / 7;
  border: 1px solid #425b49;
  background: #0b100d;
  touch-action: none;
  image-rendering: pixelated;
  cursor: crosshair;
}

.companion-pen {
  position: absolute;
  left: 50%;
  top: 50%;
  display: none;
  width: 10px;
  height: 10px;
  border: 1px solid #f4efe7;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.companion-sketch-stage:has(canvas:focus-visible) .companion-pen {
  display: block;
}

.companion-sketch-footer {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
}

.companion-sketch-footer > span {
  flex: 1;
  min-width: 0;
  color: #95a89b;
  font-size: 9px;
  overflow-wrap: anywhere;
}

.companion-sketch-footer .companion-icon {
  width: 38px;
  flex-basis: 38px;
}

.companion-highfive {
  position: absolute;
  left: 50%;
  top: 8%;
  width: max-content;
  padding: 5px 8px;
  border: 1px solid #a8f0ce;
  background: #13261a;
  color: #d5fbe5;
  font-size: 9px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
}

.companion-figure[data-reaction="highfive"] .companion-highfive {
  animation: companionHighFive 1100ms steps(6, end) both;
}

.companion-highfive i {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #a8f0ce;
}

.companion-highfive i:nth-child(1) { left: -12px; top: -8px; }
.companion-highfive i:nth-child(2) { right: -10px; top: 4px; background: #f69b88; }
.companion-highfive i:nth-child(3) { left: 20px; top: -16px; background: #e7d878; }
.companion-highfive i:nth-child(4) { right: 16px; bottom: -10px; }

@keyframes companionHighFive {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  20%, 75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -16px); }
}

.companion-name i,
.companion-process i {
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  background: #a8f0ce;
}

.companion-hello {
  position: absolute;
  top: 0.1rem;
  right: 85%;
  border: 1px solid #39473e;
  padding: 0.2rem 0.5rem;
  background: #111713;
  color: #a8f0ce;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.companion-launcher:focus-visible .companion-hello {
  opacity: 1;
  transform: none;
}

.companion-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(22rem, calc(100vw - 2rem));
  max-height: var(--companion-height);
  overflow: hidden;
  border: 1px solid #3a463e;
  border-radius: 6px;
  background: #0c100e;
  box-shadow: 0 12px 45px #0009;
}

.companion-bar {
  display: flex;
  align-items: center;
  min-height: 2.8rem;
  padding: 0 0.25rem 0 0.85rem;
  gap: 0.3rem;
  border-bottom: 1px solid #ffffff16;
  background: #151b17;
}

.companion-process {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 0.45rem;
  min-width: 0;
  color: #f1f4f0;
  font-size: 0.65rem;
}

.companion-process > span {
  color: #9ea99f;
}

.companion-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.75rem;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  color: #d7e3db;
  background: transparent;
  cursor: pointer;
}

.companion-icon img,
.companion-choice img,
.companion-submit img,
.companion-faq summary img {
  flex: 0 0 auto;
  width: 1.1rem;
  height: 1.1rem;
  object-fit: contain;
}

.companion-content {
  min-height: 0;
  padding: 1.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #47574d #0c100e;
}

.companion-command {
  margin: 0 0 0.75rem;
  color: #a8f0ce;
  font-size: 0.66rem;
}

.companion h2 {
  margin: 0;
  color: #f7f4ec;
  font: 500 1.15rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.companion-copy {
  margin: 0.75rem 0 1.15rem;
  color: #b7c0b9;
}

.companion-actions {
  border-top: 1px solid #ffffff20;
}

.companion-choice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 4.15rem;
  border-bottom: 1px solid #ffffff20;
  padding: 0.7rem 0;
  background: transparent;
  color: #f1f4f0;
  cursor: pointer;
  text-align: left;
}

.companion-choice small {
  display: block;
  margin-top: 0.25rem;
  color: #8c9d91;
  font-size: 0.62rem;
}

.companion-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  margin-top: 0.8rem;
  color: #a8b6ad;
  font-size: 0.66rem;
}

.companion-links a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
}

.companion-faq {
  margin: 1rem 0 1.3rem;
  border-top: 1px solid #ffffff20;
}

.companion-faq details {
  border-bottom: 1px solid #ffffff20;
}

.companion-faq summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  min-height: 3rem;
  padding: 0.55rem 0;
  list-style: none;
  cursor: pointer;
}

.companion-faq summary::-webkit-details-marker {
  display: none;
}

.companion-faq details[open] summary img {
  transform: rotate(90deg);
}

.companion-faq details p {
  margin: 0 0 1rem;
  color: #b7c0b9;
}

.companion-form {
  margin-top: 1.2rem;
}

.companion-form fieldset {
  display: grid;
  gap: 0.85rem;
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

.companion-form label {
  display: grid;
  gap: 0.4rem;
  color: #b7c0b9;
  font-size: 0.68rem;
}

.companion-form input,
.companion-form select,
.companion-form textarea {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  border: 1px solid #465349;
  border-radius: 3px;
  padding: 0.6rem;
  background: #141b16;
  color: #f1f4f0;
  font: 400 1rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0;
}

.companion-form textarea {
  min-height: 6.8rem;
  max-height: 12rem;
  resize: vertical;
}

.companion-form-note {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem;
  color: #95a49a;
  font-size: 0.6rem;
}

.companion-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 2.9rem;
  border: 1px solid #728f7e;
  border-radius: 3px;
  padding: 0.65rem 0.75rem;
  background: #20382b;
  color: #d4fbe5;
  text-align: left;
  cursor: pointer;
}

.companion-submit:disabled,
.companion-form fieldset:disabled {
  opacity: 0.65;
  cursor: wait;
}

.companion-form-status {
  margin: 0;
  color: #a8f0ce;
  overflow-wrap: anywhere;
}

.companion-form-status:not(:empty) {
  margin-top: 0.9rem;
}

.companion-form-status[data-state="error"] {
  color: #ffc1b2;
}

.companion-mail {
  display: inline-block;
  margin-top: 0.7rem;
  color: #d7e3db;
  text-decoration: underline;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.companion-receipt {
  margin: 0.1rem 0 1.4rem;
  color: #a8f0ce;
  font: inherit;
  line-height: 1.3;
}

.companion-prompt {
  border-top: 1px solid #ffffff16;
  padding: 0.55rem 1.25rem;
  color: #8c9d91;
  font-size: 0.6rem;
}

.companion-prompt span {
  color: #a8f0ce;
}

@media (hover: hover) {
  .companion-launcher:hover .companion-figure {
    transform: translateY(-3px) rotate(-2deg);
  }

  .companion-launcher:hover .companion-hello {
    opacity: 1;
    transform: none;
  }

  .companion-choice:hover,
  .companion-faq summary:hover,
  .companion-links a:hover,
  .companion-icon:hover {
    color: #a8f0ce;
  }

  .companion-submit:hover:not(:disabled) {
    background: #2b4938;
  }
}

@media (max-width: 620px) {
  .companion:is([data-duo="true"], [data-wide="true"]) .companion-dock,
  .companion:is([data-duo="true"], [data-wide="true"]) .companion-launcher,
  .companion:is([data-duo="true"], [data-wide="true"]) .companion-figure {
    width: 12rem;
  }

  .companion:is([data-duo="true"], [data-wide="true"]) .companion-figure {
    height: 9rem;
  }

  .companion:is([data-duo="true"], [data-wide="true"]) .companion-launcher {
    grid-template-rows: 9rem 1.25rem 1.25rem;
    height: 11.5rem;
  }

  .companion:is([data-duo="true"], [data-wide="true"]) .companion-playbox {
    max-height: min(28rem, calc(var(--companion-height) - 15rem));
  }
  .companion-dock {
    width: 9rem;
  }

  .companion-controls {
    gap: 4px;
  }

  .companion-playbox {
    right: 0;
    bottom: calc(100% + 8px);
    max-height: min(28rem, calc(var(--companion-height) - 14rem));
  }

  .companion-launcher {
    grid-template-rows: 8.167rem 1.25rem 1.25rem;
    width: 7rem;
    height: 10.667rem;
    margin-inline: auto;
  }

  .companion-figure {
    width: 7rem;
    height: 8.167rem;
  }

  .companion-speech {
    right: 0;
    bottom: calc(100% + 0.5rem);
    width: min(18rem, calc(100vw - 2rem));
  }

  .companion-replies button {
    min-height: 44px;
  }

  .companion-process > span {
    display: none;
  }

  .companion-content {
    padding: 1rem;
  }
}

@media (max-height: 740px) and (max-width: 620px) {
  .companion-playbox,
  .companion:is([data-duo="true"], [data-wide="true"]) .companion-playbox {
    position: fixed;
    right: 1rem;
    bottom: var(--companion-bottom);
    max-height: var(--companion-height);
  }
}

@media (max-height: 540px) {
  .companion:is([data-duo="true"], [data-wide="true"]) .companion-dock,
  .companion:is([data-duo="true"], [data-wide="true"]) .companion-launcher,
  .companion:is([data-duo="true"], [data-wide="true"]) .companion-figure {
    width: 10rem;
  }

  .companion:is([data-duo="true"], [data-wide="true"]) .companion-figure {
    height: 7.5rem;
  }

  .companion:is([data-duo="true"], [data-wide="true"]) .companion-launcher {
    grid-template-rows: 7.5rem 1.25rem 1.25rem;
    height: 10rem;
  }
  .companion-speech {
    display: none;
  }

  .companion-speech[data-kind="interaction"] {
    position: fixed;
    right: 1rem;
    bottom: var(--companion-bottom);
    display: block;
    max-height: var(--companion-height);
    overflow-y: auto;
  }

  .companion-launcher {
    width: 6rem;
    margin-inline: auto;
  }

  .companion-dock {
    width: 9rem;
  }

  .companion-launcher {
    grid-template-rows: 7rem 1.25rem 1.25rem;
    height: 9.5rem;
  }

  .companion-figure {
    width: 6rem;
    height: 7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .companion *,
  .companion *::before,
  .companion *::after {
    transition: none !important;
    animation: none !important;
  }

  .companion-launcher:hover .companion-figure {
    transform: none;
  }

  .companion-figure[data-reaction="highfive"] .companion-highfive {
    opacity: 1;
  }
}
