/* Hero story player: the motion story card, its control dock and the faint
   doodles that drift behind the whole hero. Only pages with the player load it. */

/* ---------- Hero and the ambient layer ---------- */
.hero--story {
  position: relative;
  isolation: isolate;
}

.hero__ambient {
  position: absolute;
  inset-block: 0;
  left: 50%;
  z-index: -1;
  width: 100vw;
  height: 100%;
  translate: -50% 0;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(ellipse 70% 75% at 50% 45%, #000 40%, transparent 100%);
  mask-image: radial-gradient(ellipse 70% 75% at 50% 45%, #000 40%, transparent 100%);
}

.hero--story .hero__copy {
  position: relative;
  z-index: 1;
}

/* ---------- The story card ---------- */
.story {
  margin: 0;
  width: 100%;
}

.story__frame {
  position: relative;
  aspect-ratio: 10 / 7;
}

.story__frame::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(var(--line) 1px, transparent 1.2px) 0 0 / 22px 22px;
  -webkit-mask-image: radial-gradient(ellipse 60% 60% at 50% 48%, #000 30%, transparent 100%);
  mask-image: radial-gradient(ellipse 60% 60% at 50% 48%, #000 30%, transparent 100%);
}

.story__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Control dock ---------- */
.story__bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(var(--shadow-rgb), 0.05), 0 12px 28px -18px rgba(var(--shadow-rgb), 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal, 400ms) ease;
  container-type: inline-size;
}

.story[data-story-ready] .story__bar {
  opacity: 1;
  visibility: visible;
}

.story__steps {
  display: flex;
  flex: 1;
  gap: 0.15rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.story__steps li {
  flex: 1;
  min-width: 0;
}

.story__step {
  position: relative;
  width: 100%;
  overflow: hidden;
  padding: 0.5rem 0.4rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 0.8rem/1 var(--font-sans);
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.story__step::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 0.2rem;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.35;
  transform: scaleX(var(--p, 0));
  transform-origin: left center;
}

.story__step:hover { color: var(--ink); }

.story__step[aria-current="step"] {
  background: var(--paper);
  color: var(--ink);
}

.story__step[aria-current="step"]::after { opacity: 1; }

.story__step:focus-visible,
.story__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Round buttons ---------- */
.story__btn {
  position: relative;
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.story__btn:hover { border-color: var(--ink); }

.story__btn svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.story__btn .icon-fill { fill: currentColor; stroke: none; }

.story__btn [data-icon] { display: none; }
.story__btn[aria-pressed="true"] [data-icon="pause"],
.story__btn[aria-pressed="false"] [data-icon="play"] { display: block; }

/* Sound: one speaker with a mute cross, waves or a spinner on top */
.story__btn--sound [data-icon] { display: block; }
.story__btn--sound .snd-x,
.story__btn--sound .snd-waves,
.story__btn--sound .snd-spin { display: none; }

.story__btn--sound[data-state="off"] .snd-x,
.story__btn--sound[data-state="unavailable"] .snd-x,
.story__btn--sound[data-state="error"] .snd-x { display: inline; }
.story__btn--sound[data-state="on"] .snd-waves { display: inline; }
.story__btn--sound[data-state="loading"] .snd-spin { display: inline; }

.story__btn--sound[data-state="on"] {
  border-color: var(--accent);
  color: var(--accent);
}

.story__btn--sound[data-state="on"] .snd-waves path {
  animation: story-wave 1.2s ease-in-out infinite;
}

.story__btn--sound[data-state="on"] .snd-waves path + path { animation-delay: 0.2s; }

.story__btn--sound[data-state="loading"] .snd-spin {
  transform-origin: 12px 12px;
  animation: story-spin 0.8s linear infinite;
}

.story__btn--sound[data-state="error"] { color: var(--accent); }

.story__btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.story__btn--sound[data-state="loading"]:disabled { opacity: 1; }

/* A handwritten nudge to try the sound, gone once it is on */
.story__hint {
  position: absolute;
  right: calc(100% - 0.6rem);
  bottom: calc(100% + 0.35rem);
  display: none;
  align-items: flex-end;
  gap: 0.15rem;
  color: var(--accent);
  font: 700 1.15rem/1 var(--font-hand);
  white-space: nowrap;
  pointer-events: none;
  rotate: -3deg;
}

.story__hint svg {
  width: 1.6rem;
  height: 1.3rem;
  stroke-width: 1.6;
  translate: 0 0.35rem;
}

.story__btn--sound[data-state="off"] .story__hint { display: inline-flex; }

/* On a narrow card the canvas caption reaches the hint, so it hangs below the dock */
@container (max-width: 34rem) {
  .story__hint {
    top: calc(100% + 0.6rem);
    bottom: auto;
    align-items: flex-start;
  }

  .story__hint svg {
    scale: 1 -1;
    translate: 0 -0.45rem;
  }
}

@keyframes story-wave {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes story-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Behind the text (desktop option) ---------- */
@media (min-width: 961px) {
  /* width and justify-self come from sketch.css; on an absolute grid child
     they would beat the left inset, so both are reset here */
  .hero--behind .hero__visual {
    position: absolute;
    inset: 0 0 0 40%;
    z-index: 0;
    width: auto;
    max-width: none;
    justify-self: stretch;
  }

  .hero--behind .note--hero { display: none; }

  .hero--behind .story {
    position: absolute;
    inset: clamp(1rem, 3vw, 3rem) 0;
    display: flex;
    flex-direction: column;
    width: auto;
  }

  .hero--behind .story__frame {
    flex: 1;
    min-height: 0;
    aspect-ratio: auto;
  }

  .hero--behind .story__canvas {
    position: absolute;
    inset: 0;
  }

  .hero--behind .story__frame::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--paper) 0%, transparent 30%);
    pointer-events: none;
  }

  .hero--behind .story__bar {
    align-self: flex-end;
    width: min(30rem, 100%);
  }
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .story__bar { gap: 0.3rem; padding: 0.3rem; }
  .story__step { padding: 0.45rem 0.15rem; font-size: 0.72rem; }
  .story__btn { width: 2rem; height: 2rem; }
  .story__hint { font-size: 1rem; }
}

/* On the narrowest docks equal steps would cut "Sketch" and "Design" short */
@container (max-width: 20rem) {
  .story__steps li { flex: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .story__btn--sound[data-state="on"] .snd-waves path,
  .story__btn--sound[data-state="loading"] .snd-spin { animation: none; }
}
