/* ===== Simon the spider ===== */
/* Walks along "How I work" on wide screens, revealing each step.
   spider.js adds the class "spider-walk" only when it's safe to run. */

/* The box Simon walks inside */
.steps-track {
    position: relative;
    margin-top: 3rem;
}

.steps-track .steps {
    margin-top: 0;   /* the track has the space now */
}

/* Hidden unless spider.js switches him on */
.spider {
    display: none;
}

.spider-walk .spider {
    display: block;
    position: absolute;
    top: 1.75rem;                     /* level with the middle of the circles */
    left: var(--spider-x, 12.5%);     /* spider.js moves this */
    transform: translate(-50%, -50%);
    z-index: 2;                       /* walks in front of the circles */
    overflow: visible;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.spider.is-gone {
    opacity: 0;
}

/* ----- Simon's colours ----- */
.spider {
    --simon: #7A8A78;   /* a soft sage, friendlier than black */
}

.spider-legs path {
    fill: none;
    stroke: var(--simon);
    stroke-width: 2.6;
    stroke-linecap: round;
}

.spider-body   { fill: var(--simon); }
.spider-eye    { fill: #fff; }
.spider-pupil  { fill: #2E352E; }
.spider-shine  { fill: #fff; }
.spider-cheek  { fill: #EBB4A8; opacity: 0.9; }

.spider-smile {
    fill: none;
    stroke: #2E352E;
    stroke-width: 1.1;
    stroke-linecap: round;
}

/* ----- Walking: wiggly legs and a little bounce ----- */
.legs-a,
.legs-b,
.spider-bob {
    transform-box: view-box;
    transform-origin: 0 0;
}

.spider.is-walking .legs-a {
    animation: spider-legs 0.22s ease-in-out infinite alternate;
}

.spider.is-walking .legs-b {
    animation: spider-legs 0.22s ease-in-out infinite alternate-reverse;
}

.spider.is-walking .spider-bob {
    animation: spider-bob 0.22s ease-in-out infinite alternate;
}

@keyframes spider-legs {
    from { transform: rotate(-7deg); }
    to   { transform: rotate(7deg); }
}

@keyframes spider-bob {
    from { transform: translateY(0); }
    to   { transform: translateY(-1.5px); }
}

/* ----- The trail and the steps ----- */
/* The dotted line grows behind Simon instead of being there from the start */
.spider-walk .steps::before {
    right: auto;
    width: var(--trail, 0%);
}

/* Each step waits for Simon, then fades in */
.spider-walk .step {
    opacity: 0;
    transition: opacity 0.5s ease;
}

.spider-walk .step.is-reached {
    opacity: 1;
}

/* ===== Phones and tablets: Simon drops down his thread ===== */
/* spider.js adds "spider-drop" to the track on narrower screens */

.spider-drop .spider {
    display: block;
    position: absolute;
    left: 1.75rem;                      /* the middle of the circles */
    top: var(--spider-y, 0px);          /* spider.js moves this */
    transform: translate(-50%, -50%);
    z-index: 2;
    overflow: visible;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

/* Simon's silk thread, growing down behind him */
.spider-drop::before {
    content: "";
    position: absolute;
    left: calc(1.75rem - 1px);
    top: 0;
    height: var(--thread, 0px);         /* spider.js grows this */
    border-left: 2px dashed var(--sage);
    opacity: 0.4;
}

/* His thread replaces the per-step dotted lines */
.spider-drop .step::after {
    display: none;
}

/* Each step waits for Simon, then fades in */
.spider-drop .step {
    opacity: 0;
    transition: opacity 0.5s ease;
}

.spider-drop .step.is-reached {
    opacity: 1;
}

/* A gentle sway while he rests at each step, like a real dangling spider */
.spider.is-resting .spider-bob {
    animation: spider-sway 1s ease-in-out infinite alternate;
}

@keyframes spider-sway {
    from { transform: rotate(-4deg); }
    to   { transform: rotate(4deg); }
}