/* ===== Catch the bug game ===== */

.bug-game {
    background: var(--cream);
}

/* The title is a long sentence, so it gets a slightly smaller size */
.bug-game .section-title {
    max-width: 40rem;
    margin: 0 auto;
    font-size: clamp(1.5rem, 3.5vw, 2.25rem);
}

/* The play area */
.game-area {
    position: relative;
    height: 22rem;
    margin-top: 2.5rem;
    border-radius: 1.25rem;
    background: var(--bubble);
    overflow: hidden;          /* bugs can wander off the edges */
    text-align: left;
}

.game-score {
    position: absolute;
    top: 1rem;
    left: 1.25rem;
    color: var(--off-white);
    font-size: 0.9rem;
}

.game-count {
    font-weight: 600;
}

/* The fact that pops up after each catch */
.game-message {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    width: max-content;
    max-width: 80%;
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    background: var(--off-white);
    font-family: var(--font-heading);
    font-size: 1.25rem;
    line-height: 1.3;
    text-align: center;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.85);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.game-message.is-showing {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Simon and his thread */
.game-thread {
    position: absolute;
    top: 0;
    height: 0;
    z-index: 1;
    border-left: 1.5px dashed var(--off-white);
    opacity: 0.7;
}

.game-simon {
    --simon: #9DB09A;          /* a lighter sage, so he shows up on the green */
    position: absolute;
    top: -3rem;                /* hiding above the play area */
    left: 0;
    z-index: 2;
    overflow: visible;
    pointer-events: none;
}

/* The bug */
.game-bug {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.game-bug svg {
    display: block;
}

.game-bug:focus-visible {
    outline: 3px solid var(--butter);
    outline-offset: 2px;
    border-radius: 50%;
}

.bug-shell  { fill: var(--butter); stroke: #C9B77A; stroke-width: 1; }
.bug-line   { stroke: #C9B77A; stroke-width: 1; }
.bug-spot   { fill: #C9B77A; }
.bug-head   { fill: var(--sage); }
.bug-eye    { fill: #fff; }
.bug-pupil  { fill: #2E352E; }

.bug-feelers {
    fill: none;
    stroke: var(--sage);
    stroke-width: 1;
    stroke-linecap: round;
}

.bug-legs path {
    stroke: #2E352E;
    stroke-width: 1.5;
    stroke-linecap: round;
}

/* Scurrying legs (they stop once he's caught) */
.bug-legs {
    transform-box: view-box;
    transform-origin: 0 0;
}

.game-bug:not(.is-caught) .bug-legs {
    animation: bug-scurry 0.18s ease-in-out infinite alternate;
}

@keyframes bug-scurry {
    from { transform: scaleY(0.85); }
    to   { transform: scaleY(1.1); }
}

/* Until the script is ready, keep the bug and Simon out of sight */
.game-area:not(.is-ready) .game-bug,
.game-area:not(.is-ready) .game-simon {
    display: none;
}

/* The 5-bug reward */
.game-reward {
    margin-top: 1.5rem;
    font-weight: 500;
    line-height: 2.5;
}

/* ===== Simon button (homepage + footer) ===== */
.simon-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 1.25rem 0.5rem 0.75rem;
    border: 2px solid var(--bubble);
    border-radius: 999px;
    background: var(--bubble);
    color: var(--off-white);
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.simon-btn:hover,
.simon-btn:focus-visible {
    background: var(--sage);
    border-color: var(--sage);
    color: var(--off-white);
    transform: translateY(-3px);
}

.simon-btn-spider {
    --simon: #9DB09A;          /* light sage, so he shows on the green */
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    overflow: visible;
    transform-origin: top center;
}

/* On hover: Simon turns lighter (so he shows on the sage) and waves */
.simon-btn:hover .simon-btn-spider,
.simon-btn:focus-visible .simon-btn-spider {
    --simon: #9DB09A;
    animation: invite-wave 0.4s ease-in-out 3 alternate;
}

/* The homepage invite, centred under How I work */
.bug-invite {
    margin-top: 3.5rem;
    text-align: center;
}

/* A gentle little rock, like he's waving you over */
@keyframes invite-wave {
    from { transform: rotate(-6deg); }
    to   { transform: rotate(6deg); }
}

.bug-invite a {
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
    .invite-simon {
        animation: none;
    }
}

/* Link to the "beat the Machine" game */
.game-challenge {
    margin-top: 1.5rem;
    font-weight: 500;
}

.game-challenge a {
    color: var(--sage);
    text-underline-offset: 4px;
}

.game-challenge a:hover,
.game-challenge a:focus-visible {
    text-decoration-thickness: 2px;
}
