.companion-lab-launcher {
  position: fixed;
  z-index: 12020;
  right: 22px;
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  color: #eafff9;
  background: linear-gradient(125deg, rgba(13, 45, 45, .82), rgba(7, 22, 31, .72));
  box-shadow: 0 18px 58px rgba(0, 3, 11, .38), inset 0 1px 0 rgba(255, 255, 255, .14);
  backdrop-filter: blur(24px) saturate(154%);
  -webkit-backdrop-filter: blur(24px) saturate(154%);
  cursor: pointer;
}

.companion-lab-launcher i,
.companion-lab-connection i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7aebdc;
  box-shadow: 0 0 16px rgba(122, 235, 220, .82);
}

.companion-lab-launcher small {
  color: #dfff75;
  font: 700 9px/1 "Avenir Next", "PingFang SC", sans-serif;
  letter-spacing: .12em;
}

.companion-lab {
  position: fixed;
  z-index: 12030;
  top: 14px;
  right: 14px;
  bottom: 14px;
  width: min(520px, calc(100vw - 28px));
  padding: 24px;
  overflow: auto;
  color: #eafcf8;
  background:
    radial-gradient(circle at 15% 0%, rgba(93, 232, 218, .16), transparent 38%),
    radial-gradient(circle at 100% 74%, rgba(118, 161, 255, .12), transparent 42%),
    linear-gradient(145deg, rgba(7, 25, 29, .91), rgba(4, 12, 20, .87));
  box-shadow: -30px 0 100px rgba(0, 3, 12, .48), inset 0 1px 0 rgba(255, 255, 255, .12);
  backdrop-filter: blur(36px) saturate(165%);
  -webkit-backdrop-filter: blur(36px) saturate(165%);
  transform: translateX(calc(100% + 34px));
  opacity: 0;
  pointer-events: none;
  transition: transform .42s cubic-bezier(.2, .82, .18, 1), opacity .3s ease;
}

.companion-lab.is-open {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

.companion-lab header,
.companion-lab-heading,
.companion-lab-connection,
.companion-lab-actions,
.companion-lab-history article {
  display: flex;
  align-items: center;
}

.companion-lab header { justify-content: space-between; gap: 18px; }
.companion-lab header small,
.companion-lab-heading > small {
  color: rgba(164, 234, 223, .66);
  font: 700 10px/1 "Avenir Next", "PingFang SC", sans-serif;
  letter-spacing: .14em;
}
.companion-lab h2 { margin: 7px 0 0; font: 700 clamp(22px, 3vw, 31px)/1.05 "Avenir Next", "PingFang SC", sans-serif; letter-spacing: -.035em; }
.companion-lab h3 { margin: 0; font: 650 15px/1.2 "Avenir Next", "PingFang SC", sans-serif; }
.companion-lab button,
.companion-lab select,
.companion-lab input,
.companion-lab a {
  border: 0;
  color: #e8fbf7;
  font: inherit;
}
.companion-lab button,
.companion-lab a { cursor: pointer; }
.companion-lab header button {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .07);
}

.companion-lab-connection {
  gap: 10px;
  margin: 22px 0 12px;
  padding: 12px 14px;
  border-radius: 15px;
  color: rgba(226, 244, 240, .68);
  background: rgba(255, 255, 255, .035);
  font-size: 12px;
}
.companion-lab-connection i { background: #ffae79; box-shadow: 0 0 14px rgba(255, 174, 121, .68); }
.companion-lab-connection.is-connected i { background: #dfff75; box-shadow: 0 0 14px rgba(223, 255, 117, .76); }

.companion-lab-live {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.companion-lab-live > div {
  min-width: 0;
  padding: 13px;
  border-radius: 17px;
  background: linear-gradient(145deg, rgba(255, 255, 255, .065), rgba(255, 255, 255, .018));
}
.companion-lab-live small,
.companion-lab-live strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.companion-lab-live small { color: rgba(188, 222, 218, .55); font-size: 9px; letter-spacing: .06em; }
.companion-lab-live strong { margin-top: 7px; font-size: 12px; font-weight: 650; }

.companion-lab-section { margin-top: 24px; }
.companion-lab-heading { gap: 10px; margin-bottom: 12px; }
.companion-state-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}
.companion-state-grid button {
  min-height: 54px;
  padding: 9px 7px;
  border-radius: 15px;
  text-align: left;
  background: rgba(255, 255, 255, .045);
  transition: transform .2s ease, background .2s ease, color .2s ease;
}
.companion-state-grid button:hover { transform: translateY(-2px); color: #dfff75; background: rgba(124, 235, 217, .1); }
.companion-state-grid small { display: block; margin-top: 4px; color: rgba(186, 215, 212, .48); font-size: 8px; }

.companion-command-form label { display: block; min-width: 0; }
.companion-command-form label > span { display: flex; justify-content: space-between; margin: 0 0 7px 3px; color: rgba(207, 231, 227, .64); font-size: 11px; }
.companion-command-form select,
.companion-command-form input:not([type="range"]) {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border-radius: 15px;
  outline: 0;
  background: rgba(255, 255, 255, .055);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07);
}
.companion-command-form > label,
.companion-lab-pair { margin-top: 12px; }
.companion-lab-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.companion-command-form input[type="range"] { width: 100%; accent-color: #78e9d9; }
.companion-lab-actions { flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.companion-lab-actions button,
.companion-lab-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 14px;
  text-decoration: none;
  background: rgba(255, 255, 255, .06);
}
.companion-lab-actions .companion-lab-primary {
  color: #071619;
  background: linear-gradient(120deg, #dfff75, #72ead9);
  box-shadow: 0 12px 34px rgba(114, 234, 217, .18);
  font-weight: 750;
}

.companion-lab-history { display: grid; gap: 7px; }
.companion-lab-audit { display: grid; gap: 7px; }
.companion-lab-history p { color: rgba(194, 219, 214, .56); font-size: 12px; }
.companion-lab-history article {
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 15px;
  background: rgba(255, 255, 255, .038);
}
.companion-lab-audit p { color: rgba(194, 219, 214, .56); font-size: 12px; }
.companion-lab-audit article {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .035);
  box-shadow: inset 2px 0 0 rgba(124, 235, 217, .28);
}
.companion-lab-audit article[data-status="rejected"],
.companion-lab-audit article[data-status="expired"],
.companion-lab-audit article[data-status="preempted"] { box-shadow: inset 2px 0 0 rgba(255, 148, 119, .62); }
.companion-lab-audit b { color: #bff6eb; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.companion-lab-audit span { overflow: hidden; color: rgba(202, 226, 222, .62); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.companion-lab-audit time { color: rgba(177, 211, 206, .46); font-size: 9px; }
.companion-lab-history article div { min-width: 0; }
.companion-lab-history strong,
.companion-lab-history span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.companion-lab-history strong { font-size: 11px; }
.companion-lab-history span { margin-top: 3px; color: rgba(196, 222, 217, .58); font-size: 10px; }
.companion-lab-history time { color: rgba(177, 211, 206, .46); font-size: 9px; }

@media (max-width: 720px) {
  .companion-lab-launcher { right: 12px; bottom: 12px; }
  .companion-lab {
    top: auto;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 91dvh;
    padding: 20px 16px calc(18px + env(safe-area-inset-bottom));
    border-radius: 28px 28px 0 0;
    transform: translateY(calc(100% + 24px));
  }
  .companion-lab.is-open { transform: none; }
  .companion-lab-live { grid-template-columns: 1fr 1fr; }
  .companion-state-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 430px) {
  .companion-lab-pair { grid-template-columns: 1fr; }
  .companion-state-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .companion-lab,
  .companion-state-grid button { transition: none !important; }
}
/* Device-aware companion stage editor ------------------------------------- */
.companion-stage-intro {
  margin: 0 0 14px;
  max-width: 58ch;
  color: rgba(222, 240, 237, .62);
  font-size: 12px;
  line-height: 1.65;
}

.companion-stage-devices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(0, 8, 13, .38);
}

.companion-stage-devices button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgba(226, 241, 239, .62);
  cursor: pointer;
}

.companion-stage-devices button small {
  display: block;
  margin-top: 3px;
  color: rgba(126, 231, 255, .46);
  font-size: 8px;
  letter-spacing: .1em;
}

.companion-stage-devices button.is-active {
  color: #f4fff9;
  background: linear-gradient(110deg, rgba(139, 255, 185, .16), rgba(86, 177, 255, .1));
  box-shadow: inset 3px 0 rgba(187, 255, 212, .88);
}

.companion-stage-preview {
  --stage-evidence-end: 46%;
  --stage-anchor-x: 78%;
  --stage-anchor-y: 56%;
  --stage-robot-scale: .4;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 8.8;
  overflow: hidden;
  border-radius: 24px;
  background:
    radial-gradient(circle at var(--stage-anchor-x) var(--stage-anchor-y), rgba(98, 216, 255, .16), transparent 21%),
    linear-gradient(rgba(116, 220, 242, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(116, 220, 242, .045) 1px, transparent 1px),
    linear-gradient(145deg, rgba(7, 25, 31, .94), rgba(4, 11, 18, .92));
  background-size: auto, 24px 24px, 24px 24px, auto;
  touch-action: none;
}

.companion-stage-preview[data-device="tablet"] {
  width: 78%;
  aspect-ratio: 4 / 3;
  margin-inline: auto;
}

.companion-stage-preview[data-device="mobile"] {
  width: 48%;
  min-width: 190px;
  aspect-ratio: 9 / 16;
  max-height: 330px;
  margin-inline: auto;
}

.companion-stage-evidence {
  position: absolute;
  z-index: 1;
  inset: 13% auto 10% 5%;
  width: calc(var(--stage-evidence-end) - 8%);
  display: grid;
  gap: 6%;
}

.companion-stage-evidence i {
  display: block;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(111, 255, 177, .18), rgba(7, 17, 24, .24));
  box-shadow: inset 3px 0 rgba(132, 255, 184, .75);
}

.companion-stage-evidence i:nth-child(2) {
  background: linear-gradient(90deg, rgba(84, 182, 255, .2), rgba(7, 17, 24, .24));
  box-shadow: inset 3px 0 rgba(105, 220, 255, .78);
}

.companion-stage-evidence i:nth-child(3) {
  background: linear-gradient(90deg, rgba(255, 190, 91, .18), rgba(7, 17, 24, .24));
  box-shadow: inset 3px 0 rgba(255, 204, 113, .78);
}

.companion-stage-boundary {
  position: absolute;
  z-index: 2;
  top: 8%;
  bottom: 8%;
  left: var(--stage-evidence-end);
  width: 1px;
  background: linear-gradient(transparent, rgba(161, 255, 200, .55), transparent);
  box-shadow: 0 0 16px rgba(118, 255, 179, .2);
}

.companion-stage-robot {
  position: absolute;
  z-index: 4;
  left: var(--stage-anchor-x);
  top: var(--stage-anchor-y);
  width: calc(74px * (.62 + var(--stage-robot-scale)));
  aspect-ratio: .78;
  padding: 0;
  border: 0;
  border-radius: 42% 42% 34% 34%;
  transform: translate(-50%, -50%);
  background: linear-gradient(150deg, #c9ecf2, #647e99 44%, #142236 68%, #9fd9e4);
  box-shadow: 0 14px 35px rgba(0, 0, 0, .42), 0 0 25px rgba(104, 220, 255, .18), inset 0 2px rgba(255, 255, 255, .68);
  cursor: grab;
}

.companion-stage-robot:active { cursor: grabbing; }

.companion-stage-robot span {
  position: absolute;
  top: 22%;
  width: 21%;
  aspect-ratio: .82;
  border-radius: 45%;
  background: #e9ffff;
  box-shadow: 0 0 13px rgba(129, 240, 255, .8), inset 0 -4px rgba(88, 173, 209, .44);
}

.companion-stage-robot span:first-child { left: 21%; }
.companion-stage-robot span:nth-child(2) { right: 21%; }

.companion-stage-robot i {
  position: absolute;
  left: 32%;
  right: 32%;
  bottom: 16%;
  height: 14%;
  border-radius: 999px;
  background: #d8ff77;
  box-shadow: 0 0 13px rgba(216, 255, 119, .58);
}

.companion-stage-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 13px;
}

.companion-stage-controls label {
  padding: 12px;
  border-radius: 15px;
  background: rgba(2, 11, 17, .4);
}

.companion-stage-controls label > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: rgba(228, 243, 241, .72);
  font-size: 10px;
}

.companion-stage-controls output {
  color: #baffd2;
  font-variant-numeric: tabular-nums;
}

.companion-stage-controls input[type="range"] {
  width: 100%;
  accent-color: #9bf4bc;
}

.companion-stage-status {
  display: block;
  margin-top: 11px;
  color: rgba(200, 225, 221, .5);
  line-height: 1.5;
}

@media (max-width: 560px) {
  .companion-stage-controls { grid-template-columns: 1fr; }
  .companion-stage-preview[data-device="mobile"] { width: 58%; }
}
