/* Coach section: a headline, three source icons, the owner's mascot scene and a small example chat.
   Everything is scoped under .s-coach. */
.s-coach {
  --coach-card-pad: var(--space-xl);
  --coach-bubble-radius: 22px;
  --coach-avatar-size: 48px;
  --coach-avatar-art: 104px; /* the scene is drawn larger than the circle so only the mascot shows */
  --coach-text-size: 16px;
  --coach-line: 1.5;
  --coach-exchange-gap: var(--space-xxl);
  --coach-stage-pad: var(--space-md);
  --coach-stage-radius: 32px;
  --coach-scene-size: 148px;
  --coach-icon-size: 22px;
  --coach-chip-ring: 2px;
  --coach-tint-hover: #dfe6ff;
  padding-block: calc(var(--section-gap) / 2);
  scroll-margin-top: calc(var(--space-xxxl) * -1);
}

.s-coach .coach-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-xxl);
}

.s-coach .coach-copy {
  display: grid;
  gap: var(--space-md);
  justify-items: start;
}

.s-coach .coach-copy > .label {
  color: var(--jet);
  font-weight: 700;
}

.s-coach .coach-title {
  font-size: clamp(32px, 4.6vw, 52px);
  line-height: 1.06;
  letter-spacing: -0.03em;
  color: var(--jet-ink);
}

/* What the coach reads: three plain icons with one-word labels. Not pills, so they do not look tappable. */
.s-coach .coach-reads {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-xl);
}

.s-coach .coach-read {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.s-coach .coach-read::before,
.s-coach .coach-evidence::before,
.s-coach .coach-chip::before {
  content: "";
  flex: none;
  width: var(--coach-icon-size);
  height: var(--coach-icon-size);
  background: center / contain no-repeat;
}

/* One icon, one meaning. */
.s-coach .coach-read--sessions::before {
  background-image: url("/assets/icons/icon-barbell.svg");
}

.s-coach .coach-read--meals::before {
  background-image: url("/assets/icons/icon-bowl.svg");
}

.s-coach .coach-read--checkins::before {
  background-image: url("/assets/icons/icon-check-in.svg");
}

.s-coach .coach-chip--reps::before {
  background-image: url("/assets/icons/icon-sets.svg");
}

.s-coach .coach-chip--calories::before {
  background-image: url("/assets/icons/icon-energy.svg");
}

.s-coach .coach-chip--easy::before {
  background-image: url("/assets/icons/icon-moon.svg");
}

.s-coach .coach-evidence--trend::before {
  background-image: url("/assets/icons/icon-arrow-up-trend.svg");
}

.s-coach .coach-evidence--scale::before {
  background-image: url("/assets/icons/icon-scale.svg");
}

.s-coach .coach-evidence--course::before {
  background-image: url("/assets/icons/icon-takeoff.svg");
}

/* Stage: the tinted panel that holds the mascot scene and the chat card. */
.s-coach .coach-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: var(--space-xs);
  margin-inline: calc(var(--space-sm) - var(--gutter));
  padding: var(--coach-stage-pad);
  background: var(--jet-tint);
  border-radius: var(--coach-stage-radius);
}

.s-coach .coach-scene {
  width: var(--coach-scene-size);
  height: auto;
}

.s-coach .coach-demo {
  justify-self: stretch;
}

/* The chat card */
.s-coach .coach-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-lg);
  padding: var(--coach-card-pad);
  background: var(--surface);
  border-radius: var(--radius-card-large);
  box-shadow: var(--shadow-sheet);
}

.s-coach .coach-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

/* The avatar is the same scene file, shown through a round window centred on the mascot. */
.s-coach .coach-avatar {
  position: relative;
  flex: none;
  width: var(--coach-avatar-size);
  height: var(--coach-avatar-size);
  overflow: hidden;
  border-radius: 50%;
  background: var(--jet-tint);
}

.s-coach .coach-avatar-art {
  position: absolute;
  top: calc(var(--coach-avatar-size) / 2 - var(--coach-avatar-art) * 0.6);
  left: calc(var(--coach-avatar-size) / 2 - var(--coach-avatar-art) * 0.5);
  width: var(--coach-avatar-art);
  max-width: none;
  height: var(--coach-avatar-art);
}

/* The thread. Without JavaScript it is a finished transcript of every exchange. */
.s-coach .coach-thread {
  display: flex;
  flex-direction: column;
  gap: var(--coach-exchange-gap);
}

.s-coach .coach-exchange {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-md);
  align-content: start;
}

/* The visitor's message: the brand-blue bubble. */
.s-coach .coach-question {
  justify-self: end;
  max-width: 88%;
  padding: 10px var(--space-lg);
  background: var(--jet);
  border-radius: var(--coach-bubble-radius);
  border-bottom-right-radius: 8px;
  font-size: var(--coach-text-size);
  font-weight: 600;
  line-height: 1.4;
  color: var(--surface);
  transform-origin: 100% 100%;
}

.s-coach .coach-answer {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  gap: var(--space-md);
}

.s-coach .coach-answer-text {
  font-size: var(--coach-text-size);
  line-height: var(--coach-line);
  color: var(--ink);
  text-wrap: pretty;
}

.s-coach .coach-answer-text strong {
  font-weight: 700;
  white-space: nowrap;
  color: var(--jet);
}

.s-coach .coach-word {
  display: inline-block;
}

/* Evidence: the one number the answer rests on. */
.s-coach .coach-evidence {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px 0 10px;
  background: var(--jet-tint);
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  color: var(--jet-ink);
  white-space: nowrap;
}

.s-coach .coach-evidence-number {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Thinking dots (added by the script), laid over the invisible answer so nothing moves when the words land. */
.s-coach .coach-thinking {
  position: absolute;
  inset: 0 auto auto 0;
  display: flex;
  align-items: center;
  gap: 5px;
  height: calc(var(--coach-text-size) * var(--coach-line));
  opacity: 0;
  pointer-events: none;
}

.s-coach .coach-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--jet);
  opacity: 0.3;
}

/* The controls only do something with JavaScript, so they only show with it. */
.s-coach .coach-chips {
  display: none;
}

/* ---------- Live demo (JavaScript running, script healthy) ---------- */

/* One exchange at a time. They all share one grid cell, so the card is always as tall as the
   tallest answer and nothing shifts when the visitor asks something else. */
.js .s-coach .coach-demo:not(.is-static) .coach-thread {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.js .s-coach .coach-demo:not(.is-static) .coach-exchange {
  grid-area: 1 / 1;
}

.js .s-coach .coach-demo:not(.is-static) .coach-exchange:not(.is-shown) {
  visibility: hidden;
}

.js .s-coach .coach-demo:not(.is-static) .coach-chips {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-sm);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--hairline);
}

.s-coach .coach-chip {
  --coach-icon-size: 28px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 76px;
  padding: 10px 6px;
  background: var(--jet-tint);
  border: 0;
  border-radius: var(--radius-card);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  color: var(--jet-ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--duration-snappy) var(--ease-snappy);
}

.s-coach .coach-chip:focus-visible {
  outline-offset: 3px;
  border-radius: var(--radius-card);
}

/* The question on show keeps a blue ring, so it is clear what was asked. */
.s-coach .coach-chip.is-active {
  background: var(--surface);
  box-shadow: inset 0 0 0 var(--coach-chip-ring) var(--jet);
  color: var(--jet);
}

@media (hover: hover) {
  .s-coach .coach-chip:not(.is-active):hover {
    background: var(--coach-tint-hover);
  }
}

/* Phases of an exchange: idle and thinking hold the answer's place, streaming writes it,
   done shows the evidence. */
.s-coach .coach-exchange[data-phase="idle"] .coach-answer-visual,
.s-coach .coach-exchange[data-phase="thinking"] .coach-answer-visual {
  opacity: 0;
}

.s-coach .coach-exchange[data-phase="idle"] .coach-thinking,
.s-coach .coach-exchange[data-phase="thinking"] .coach-thinking {
  opacity: 1;
}

.s-coach .coach-exchange[data-phase]:not([data-phase="done"]) .coach-evidence {
  opacity: 0;
  transform: translateY(6px);
}

.s-coach .coach-exchange[data-phase="done"] .coach-evidence {
  transition:
    opacity var(--duration-standard) var(--ease-standard),
    transform var(--duration-standard) var(--ease-standard);
}

@media (prefers-reduced-motion: no-preference) {
  .s-coach .coach-chip:active {
    transform: scale(0.96);
  }

  .s-coach .coach-chip.is-sending::before {
    animation: coach-dot 0.7s ease-in-out infinite;
  }

  .s-coach .coach-exchange[data-phase="thinking"] .coach-question {
    animation: coach-pop var(--duration-standard) var(--ease-standard) both;
  }

  .s-coach .coach-exchange[data-phase="thinking"] .coach-dot {
    animation: coach-dot 1s ease-in-out infinite;
  }

  .s-coach .coach-exchange[data-phase="thinking"] .coach-dot:nth-child(2) {
    animation-delay: 150ms;
  }

  .s-coach .coach-exchange[data-phase="thinking"] .coach-dot:nth-child(3) {
    animation-delay: 300ms;
  }
}

@keyframes coach-pop {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes coach-dot {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: none;
  }

  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (max-width: 359px) {
  .s-coach {
    --coach-card-pad: var(--space-lg);
    --coach-scene-size: 128px;
  }

  .s-coach .coach-title {
    font-size: 28px;
  }

  .s-coach .coach-reads {
    column-gap: var(--space-md);
  }

  .s-coach .coach-read {
    --coach-icon-size: 18px;
    gap: 6px;
    font-size: 13px;
  }

  .s-coach .coach-chip {
    font-size: 13px;
  }
}

@media (min-width: 640px) {
  .s-coach {
    --coach-card-pad: var(--space-xxxl);
    --coach-text-size: 17px;
    --coach-stage-pad: var(--space-xxl);
    --coach-stage-radius: 40px;
    --coach-scene-size: 176px;
  }

  .s-coach .coach-layout {
    gap: var(--space-xxxl);
  }

  .s-coach .coach-stage {
    margin-inline: 0;
  }

  .s-coach .coach-demo {
    justify-self: center;
    width: min(100%, 520px);
  }

  .s-coach .coach-card {
    gap: var(--space-xl);
  }

  .s-coach .coach-chip {
    font-size: 15px;
  }
}

/* Side by side: the card on the left and the mascot scene on the right, both inside the stage. */
@media (min-width: 1024px) {
  .s-coach {
    --coach-stage-pad: var(--space-section);
    --coach-scene-size: 300px;
  }

  .s-coach .coach-stage {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: var(--space-section);
  }

  .s-coach .coach-scene {
    order: 1;
  }

  .s-coach .coach-demo {
    justify-self: end;
    width: 100%;
    max-width: 480px;
  }

  /* Beside the long transcript (no JavaScript, or a failed script) the scene travels with the reader. */
  html:not(.js) .s-coach .coach-scene,
  .s-coach .coach-stage:has(.is-static) .coach-scene {
    position: sticky;
    top: 96px;
    align-self: start;
  }
}
