/* Proof, the guide robot (landing page and client project page). Uses the tokens in site.css.
   Bottom-right launcher, a greeting bubble, a non-modal step card, and a red ring around the part
   of the page being explained. Rationale: docs/GUIDE.md */

/* The guide is pinned to the bottom-left and moved sideways with a transform (set in guide.js),
   so it can walk the whole width of the page. */
.guide {
  position: fixed;
  left: 0;
  bottom: 12px;
  z-index: 60;
  will-change: transform;
  font: 400 15px/1.5 var(--ui);
  color: var(--ink);
}

.guide[hidden] {
  display: none;
}

/* Launcher: Proof hovers freely in the corner, with its shadow on the "floor" */
.guide-bot {
  display: grid;
  place-items: end center;
  width: 86px;
  height: 96px;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: none;
  cursor: pointer;
}

.guide-bot .proof {
  transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.guide-bot:hover .proof {
  transform: translateY(-4px) scale(1.04);
}

.guide-bot:focus-visible {
  outline: 3px solid var(--red-ink);
  outline-offset: 2px;
}

.proof {
  width: 78px;
  height: 85px;
  overflow: visible;
  /* a soft outline so the white head reads on the dark and red sections too */
  filter: drop-shadow(0 2px 3px rgba(18, 18, 18, 0.16));
}

.proof .shell {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 2.4;
}

.proof .screen,
.proof .ink {
  fill: var(--ink);
}

.proof .red,
.proof-bulb {
  fill: var(--red);
}

.proof .ink-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.4;
  stroke-linecap: round;
}

.proof-eyes rect {
  fill: #fff;
}

.proof-mouth {
  fill: none;
  stroke: #fff;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.proof-shadow {
  fill: rgba(18, 18, 18, 0.14);
  transform-box: fill-box;
  transform-origin: center;
  animation: proof-shadow 3.6s ease-in-out infinite;
}

.proof .jets {
  stroke: var(--red);
  stroke-width: 2;
  animation: proof-jets 0.9s ease-in-out infinite;
}

.proof.mini {
  width: 32px;
  height: 35px;
  flex: none;
  filter: none;
}

.proof.mini .proof-shadow,
.proof.mini .jets {
  display: none;
}

.proof.mini .proof-float {
  animation: none;
}

/* Floating: it rises and drifts; the shadow below shrinks as it lifts */
.proof-float {
  transform-box: view-box;
  transform-origin: 32px 50px;
  animation: proof-float 3.6s ease-in-out infinite;
}

/* Looking around: the head tilts and the eyes glance inside the screen.
   --lx/--ly/--tilt come from guide.js (mouse, or the part of the page being explained). */
.proof-head {
  transform-box: view-box;
  transform-origin: 32px 41px;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.5s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.proof-look {
  transform: translate(calc(var(--lx, 0) * 1px), calc(var(--ly, 0) * 1px));
  transition: transform 0.35s cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* On its own (no mouse to follow) it glances left, right and up every few seconds */
.guide:not(.tracking) .proof-look {
  animation: proof-glance 8s ease-in-out infinite;
}

.guide:not(.tracking) .proof-head {
  animation: proof-tilt 8s ease-in-out infinite;
}

.proof-eyes {
  transform-box: fill-box;
  transform-origin: center;
  animation: proof-blink 4.6s infinite;
}

.proof-bulb {
  animation: proof-glow 2.4s ease-in-out infinite;
}

.proof-arm {
  transform-box: view-box;
  transform-origin: 44px 48px;
}

/* Walking: it turns to face the way it's going, leans in, bounces, and its legs swing */
.proof-face {
  transform-box: view-box;
  transform-origin: 32px 35px;
  transition: transform 0.25s ease;
}

.guide.facing-left .guide-bot .proof-face {
  transform: scaleX(-1);
}

.leg {
  transform-box: view-box;
}

.leg.l {
  transform-origin: 27px 57px;
}

.leg.r {
  transform-origin: 37px 57px;
}

.guide.walking .guide-bot .proof-float {
  animation: proof-walk 0.46s ease-in-out infinite;
}

.guide.walking .guide-bot .leg.l {
  animation: proof-step 0.46s ease-in-out infinite;
}

.guide.walking .guide-bot .leg.r {
  animation: proof-step 0.46s ease-in-out -0.23s infinite;
}

.guide.walking .guide-bot .proof-arm {
  animation: proof-swing 0.46s ease-in-out infinite;
}

.guide.walking .guide-bot .proof-shadow {
  animation: none;
}

/* Talking: the mouth opens and closes while the bubble is up */
.proof-mouth {
  transform-box: fill-box;
  transform-origin: center top;
}

.guide.talking .guide-bot .proof-mouth {
  animation: proof-talk 0.28s ease-in-out infinite alternate;
}

@keyframes proof-walk {
  0%,
  100% {
    transform: translateY(0) rotate(5deg);
  }
  50% {
    transform: translateY(-3px) rotate(5deg);
  }
}

@keyframes proof-step {
  0%,
  100% {
    transform: rotate(22deg);
  }
  50% {
    transform: rotate(-22deg);
  }
}

@keyframes proof-swing {
  0%,
  100% {
    transform: rotate(-10deg);
  }
  50% {
    transform: rotate(8deg);
  }
}

@keyframes proof-talk {
  to {
    transform: scaleY(2.4);
  }
}

/* Waves while it says hello; points its pen while a step is open */
.guide.is-greeting .guide-bot .proof-arm {
  animation: proof-wave 1.2s ease-in-out 3;
}

.guide.is-open .guide-bot .proof-arm {
  transform: rotate(-14deg);
  transition: transform 0.3s ease;
}

@keyframes proof-float {
  0%,
  100% {
    transform: translateY(0) rotate(-1.5deg);
  }
  50% {
    transform: translateY(-6px) rotate(1.5deg);
  }
}

@keyframes proof-shadow {
  50% {
    transform: scale(0.7);
    opacity: 0.55;
  }
}

@keyframes proof-jets {
  50% {
    opacity: 0.35;
  }
}

@keyframes proof-glance {
  0%,
  12%,
  36%,
  62%,
  86%,
  100% {
    transform: translate(0, 0);
  }
  18%,
  30% {
    transform: translate(-3px, 0.5px);
  }
  44%,
  56% {
    transform: translate(3px, -0.5px);
  }
  70%,
  78% {
    transform: translate(0.5px, -2px);
  }
}

@keyframes proof-tilt {
  0%,
  12%,
  36%,
  62%,
  86%,
  100% {
    transform: rotate(0);
  }
  18%,
  30% {
    transform: rotate(-7deg);
  }
  44%,
  56% {
    transform: rotate(6deg);
  }
  70%,
  78% {
    transform: rotate(-2deg);
  }
}

@keyframes proof-blink {
  0%,
  92%,
  100% {
    transform: scaleY(1);
  }
  95% {
    transform: scaleY(0.1);
  }
}

@keyframes proof-glow {
  50% {
    opacity: 0.55;
  }
}

@keyframes proof-wave {
  0%,
  100% {
    transform: rotate(0);
  }
  30% {
    transform: rotate(-26deg);
  }
  65% {
    transform: rotate(10deg);
  }
}

/* Speech bubbles sit above Proof's head; near an edge they slide over so they stay on screen */
.guide-hello,
.guide-say {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  animation: guide-fade 0.25s ease-out;
}

@keyframes guide-fade {
  from {
    opacity: 0;
  }
}

.guide.edge-left .guide-hello,
.guide.edge-left .guide-say {
  left: 4px;
  transform: none;
}

.guide.edge-right .guide-hello,
.guide.edge-right .guide-say {
  left: auto;
  right: 4px;
  transform: none;
}

.guide-hello {
  width: min(290px, calc(100vw - 24px));
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 18px 40px -18px rgba(18, 18, 18, 0.35);
}

/* Small talk: a dark bubble with a tail, gone after a few seconds */
.guide-say {
  width: max-content;
  max-width: min(230px, calc(100vw - 24px));
  margin: 0;
  padding: 9px 13px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font: 500 14px/1.35 var(--ui);
  text-align: center;
  pointer-events: none;
  box-shadow: 0 10px 24px -12px rgba(18, 18, 18, 0.5);
}

.guide-say::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top-color: var(--ink);
}

.guide.edge-left .guide-say::after {
  left: 38px;
}

.guide.edge-right .guide-say::after {
  left: auto;
  right: 32px;
}

.guide-say[hidden] {
  display: none;
}

.guide-hello p {
  margin: 0 0 12px;
  font-weight: 500;
}

.guide-hello-actions {
  display: flex;
  gap: 8px;
}

/* Step card */
.guide-panel {
  position: absolute;
  right: 0;
  bottom: 104px;
  width: min(360px, calc(100vw - 32px));
  padding: 14px 18px 12px;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: 0 24px 50px -20px rgba(18, 18, 18, 0.4);
  animation: guide-pop 0.22s ease-out;
}

.guide-panel[hidden],
.guide-hello[hidden] {
  display: none;
}

.guide-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

.guide-head span {
  flex: 1;
  line-height: 1.2;
}

.guide-head b {
  display: block;
  font-weight: 600;
}

.guide-head small {
  font-size: 13px;
  color: var(--ink-3);
}

.guide-x {
  border: 0;
  background: none;
  padding: 8px 4px;
  font: 500 14px/1 var(--ui);
  color: var(--ink-2);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.guide-count {
  margin: 0 0 4px;
  font: 600 12px/1.4 var(--ui);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--red-ink);
}

.guide-title {
  margin: 0 0 6px;
  font: 600 19px/1.25 var(--display);
  letter-spacing: -0.015em;
  outline: none;
}

.guide-text {
  margin: 0 0 14px;
  color: var(--ink-2);
}

.guide-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.guide-dots {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.guide-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rule-strong);
}

.guide-dots i.on {
  width: 16px;
  border-radius: 3px;
  background: var(--red);
}

.guide-btn {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: #fff;
  color: var(--ink);
  font: 500 14px/1 var(--ui);
  cursor: pointer;
}

.guide-btn.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.guide-btn.primary:hover {
  background: var(--red-hover);
}

.guide-btn:focus-visible,
.guide-x:focus-visible,
.guide-hide:focus-visible {
  outline: 2px solid var(--red-ink);
  outline-offset: 2px;
}

.guide-prefs {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--ink-3);
}

.guide-hide {
  display: inline;
  margin: 0;
  border: 0;
  background: none;
  font: 400 12px/1.4 var(--ui);
  color: var(--ink-3);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* The ring around the part of the page being explained */
.guide-ring {
  position: absolute;
  z-index: 55;
  pointer-events: none;
  border: 3px solid var(--red);
  border-radius: 16px;
  box-shadow: 0 0 0 6px rgba(229, 9, 20, 0.14);
  transition: top 0.3s ease, left 0.3s ease, width 0.3s ease, height 0.3s ease;
}

.guide-ring[hidden] {
  display: none;
}

/* On the red band the ring turns white */
.guide-ring.light {
  border-color: #fff;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.25);
}

.guide-ring.pulse {
  animation: guide-ring 1.4s ease-out 2;
}

@keyframes guide-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(229, 9, 20, 0.35);
  }
  100% {
    box-shadow: 0 0 0 14px rgba(229, 9, 20, 0);
  }
}

@keyframes guide-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@media (max-width: 640px) {
  .guide {
    bottom: 8px;
  }
  .guide-bot {
    width: 66px;
    height: 74px;
  }
  .proof {
    width: 60px;
    height: 66px;
  }
  .guide-hello {
    width: min(270px, calc(100vw - 24px));
  }
  .guide-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 92px;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .guide.walking .guide-bot .proof-float,
  .guide.walking .guide-bot .leg,
  .guide.walking .guide-bot .proof-arm,
  .guide.talking .guide-bot .proof-mouth,
  .guide-say,
  .proof-float,
  .proof-shadow,
  .proof .jets,
  .proof-head,
  .proof-look,
  .guide:not(.tracking) .proof-look,
  .guide:not(.tracking) .proof-head,
  .proof-eyes,
  .proof-bulb,
  .guide.is-greeting .guide-bot .proof-arm,
  .guide-ring.pulse,
  .guide-panel,
  .guide-hello {
    animation: none;
  }
  .guide,
  .guide-ring,
  .guide-bot .proof,
  .proof-face,
  .proof-head,
  .proof-look {
    transition: none !important;
  }
}

@media print {
  .guide,
  .guide-ring {
    display: none !important;
  }
}
