/* Motion and text streaming for the lesson page: an optional layer over lesson.css.
   Everything that hides content lives behind html.js and prefers-reduced-motion: no-preference,
   so the page reads in full with JavaScript off or motion reduced. motion.js and stream.js add the hooks. */

/* ---------- Page entrance (pure CSS; fill "backwards" so no transform lingers) ---------- */

@keyframes m-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes m-show { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: no-preference) {
  html.js .article > .crumbs,
  html.js .article > h1,
  html.js .article > .meta,
  html.js .article > .toc-mobile,
  html.js .article > :nth-child(6),
  html.js .article > :nth-child(7) {
    animation: m-rise 450ms var(--aiops-ease-enter) backwards;
  }
  html.js .article > h1 { animation-delay: 60ms; }
  html.js .article > .meta { animation-delay: 120ms; }
  html.js .article > .toc-mobile,
  html.js .article > :nth-child(6) { animation-delay: 180ms; }
  html.js .article > :nth-child(7) { animation-delay: 240ms; }

  /* The lead waits for motion.js to stream it; if the script never arrives it appears at 1.5 s. */
  html.js .article > .lead:not(.m-live):not(.m-done) { animation: m-show 1ms linear 1500ms both; }
}

/* ---------- Scroll reveal ---------- */

@media (prefers-reduced-motion: no-preference) {
  html.js .m-reveal {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 450ms var(--aiops-ease-enter), transform 450ms var(--aiops-ease-enter);
  }
  html.js .m-reveal.is-in { opacity: 1; transform: none; }
  html.js .m-reveal.m-now { transition: none; }
}
@media print { html.js .m-reveal { opacity: 1 !important; transform: none !important; } }

/* ---------- Reading progress ---------- */

.m-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--aiops-accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

/* ---------- "On this page" indicator ---------- */

.rail .toc { position: relative; }
.m-toc-bar {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 1px;
  border-radius: 2px;
  background: var(--aiops-accent);
  transform-origin: 0 0;
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms var(--aiops-ease-move), opacity 160ms var(--aiops-ease-enter);
}
.m-toc-bar.is-on { opacity: 1; }
.m-toc-bar.m-now { transition: none; }

/* ---------- Build steps: the line draws itself, reached marks light up ---------- */

.steps.m-build .step::before {
  content: "";
  position: absolute;
  z-index: 1;
  left: 11px;
  top: 32px;
  bottom: 4px;
  width: 2px;
  border-radius: 2px;
  background: var(--aiops-accent);
  transform: scaleY(var(--m-line, 0));
  transform-origin: 50% 0;
  pointer-events: none;
}
.steps.m-build .step:last-child::before { display: none; }
.steps.m-build .step > .step-mark {
  transition: background-color 220ms var(--aiops-ease-enter), color 220ms var(--aiops-ease-enter), box-shadow 220ms var(--aiops-ease-enter);
}
.steps.m-build .step.is-reached > .step-mark {
  background: var(--aiops-accent-tint);
  color: var(--aiops-accent-ink);
  box-shadow: inset 0 0 0 1px var(--aiops-accent-line);
}

/* ---------- Checks: the tick pops and draws; the count gets a tick that rings when all pass ---------- */

@keyframes m-pop { from { transform: scale(0.85); } to { transform: scale(1); } }
@keyframes m-draw { from { stroke-dashoffset: 14; } to { stroke-dashoffset: 0; } }
@keyframes m-ring {
  from { transform: scale(1); opacity: 0.55; }
  to { transform: scale(2.1); opacity: 0; }
}

.tick .step-mark svg { stroke-dasharray: 14; stroke-dashoffset: 0; }
@media (prefers-reduced-motion: no-preference) {
  html.js .tick input:checked + .step-mark { animation: m-pop 220ms var(--aiops-ease-enter); }
  html.js .tick input:checked + .step-mark svg { animation: m-draw 260ms var(--aiops-ease-enter) 40ms backwards; }
}

.prose .checks-count { position: relative; transition: color 200ms var(--aiops-ease-enter); }
.checks-count .m-cc {
  position: absolute;
  left: -41px;
  top: 1px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: var(--aiops-mark);
  box-shadow: inset 0 0 0 1px var(--aiops-border-strong);
  transition: background-color 200ms var(--aiops-ease-enter), color 200ms var(--aiops-ease-enter), box-shadow 200ms var(--aiops-ease-enter);
}
.checks-count .m-cc svg { width: 12px; height: 12px; stroke-width: 2; stroke-dasharray: 14; stroke-dashoffset: 0; }
.checks-count .m-cc::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--aiops-ok);
  opacity: 0;
  pointer-events: none;
}
.checks-count.is-done .m-cc { background: var(--aiops-ok); color: var(--aiops-ok-text); box-shadow: none; }
@media (prefers-reduced-motion: no-preference) {
  .checks-count.is-done .m-cc { animation: m-pop 240ms var(--aiops-ease-enter); }
  .checks-count.is-done .m-cc svg { animation: m-draw 300ms var(--aiops-ease-enter) 60ms backwards; }
  .checks-count.is-done .m-cc::after { animation: m-ring 700ms var(--aiops-ease-enter) 80ms 1; }
}
@media (max-width: 599px) { .checks-count .m-cc { left: -35px; } }
html:not(.js) .checks-count .m-cc { display: none; }

/* ---------- Go deeper: height animation ---------- */

@supports selector(::details-content) {
  @media (prefers-reduced-motion: no-preference) {
    .deeper details { interpolate-size: allow-keywords; }
    .deeper details::details-content {
      height: 0;
      overflow: clip;
      opacity: 0;
      transition: height 220ms var(--aiops-ease-move), opacity 180ms var(--aiops-ease-enter), content-visibility 220ms allow-discrete;
    }
    .deeper details[open]::details-content { height: auto; opacity: 1; }
  }
}

/* ---------- Theme switch cross-fade ---------- */

::view-transition-old(root),
::view-transition-new(root) { animation-duration: 200ms; animation-timing-function: ease; }

/* ---------- Text streaming (stream.js): chunks fade in behind a caret ---------- */

.m-live .m-chunk { opacity: 0; filter: blur(4px); }
.m-live .m-chunk.is-on {
  opacity: 1;
  filter: blur(0);
  transition: opacity 250ms var(--aiops-ease-enter), filter 250ms var(--aiops-ease-enter);
}
.m-live.m-hold .m-chunk { transition: none; }

@keyframes m-caret { 50% { opacity: 0.25; } }
.m-caret {
  position: relative;
  display: inline-block;
  width: 0;
  height: 1em;
  vertical-align: -0.12em;
}
.m-caret::after {
  content: "";
  position: absolute;
  left: 1px;
  top: 0;
  bottom: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--aiops-accent);
  opacity: 0.75;
  animation: m-caret 900ms ease-in-out infinite;
}

/* ---------- Code box: SKILL.md while Claude writes it, and Replay ---------- */

@keyframes m-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.code-head .hint.m-writing { display: inline-flex; align-items: center; gap: 6px; }
.code-head .hint.m-writing .logo { width: 14px; height: 14px; }
.code-head .hint.m-writing .m-shim {
  color: var(--aiops-text-muted);
  background: linear-gradient(90deg, var(--aiops-text-muted) 0%, var(--aiops-text-muted) 40%, var(--aiops-text) 50%, var(--aiops-text-muted) 60%, var(--aiops-text-muted) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: m-shimmer 1.4s linear infinite;
}
.m-replay {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--aiops-text-muted);
  font: 500 13px/20px var(--aiops-font-sans);
  cursor: pointer;
  opacity: 1;
  transition: color 150ms ease, background-color 150ms ease, opacity 200ms var(--aiops-ease-enter), scale 120ms var(--aiops-ease-enter);
}
.m-replay:hover { color: var(--aiops-text); background: var(--aiops-hover); }
.m-replay:active { scale: 0.97; }
.m-replay.is-hidden { opacity: 0; pointer-events: none; }
.m-replay + .copy { margin-left: 0; }
@media (max-width: 859px) { .m-replay { height: 36px; } }

@media (prefers-reduced-motion: reduce) {
  .m-caret::after, .code-head .hint.m-writing .m-shim { animation: none; }
}
