/* ============================================================
   SCR WHOLE-REACTOR DIAGRAM
   Markup + script: includes/whole-reactor.php
   Enqueued in functions.php, on the StackCR page template only.

   Over 960px : a 16:9 stage, edge to edge with the parent wrapper.
                Its left/right edges are where the reference's leader
                lines start and end (x 196–3647 of the 3840px slide).
                Headings, dots and lines scale with it (cqw units);
                body copy inherits the site's body size.
   960px down : cropped to the model, dots become toggle buttons
                and one label at a time shows in a panel.

   Dot positions (--x / --y on each dot, in the HTML) are
   percentages of the PNG itself, so they hold at every size.
   They were measured against SlideDiagramOnly@2x_REFERENCE.png.
   If the PNG is re-rendered, keep the same framing or re-measure.
   ============================================================ */

.scr-whole {
    --scr-whole-max: var(--tecs-container-max); /* 1280px — raise for a bigger desktop diagram */
    --scr-whole-accent: var(--tecs-green-500);
    color: var(--tecs-white); /* no background: sits on the parent section's colour */
    overflow: hidden; /* the transparent PNG margins overhang when cropped */
}

.scr-whole-container {
    position: relative;
    max-width: var(--scr-whole-max);
    margin-inline: auto;
    aspect-ratio: 16 / 9;
    container-type: inline-size;
}

/* Figure: fills the stage on desktop, is the crop box on mobile */
.scr-whole-figure {
    position: absolute;
    inset: 0;
    margin: 0;
}

/* Exactly the PNG's box. Dots are children, so they move with it. */
.scr-whole-model {
    position: absolute;
    left: 1.7990%;
    top: 0.7077%;
    width: 98.1628%;
    aspect-ratio: 16 / 9;
}

.scr-whole-model img {
    display: block;
    pointer-events: none; /* transparent margins overhang other content */
    width: 100%;
    height: 100%;
}

/* Leader lines. Drawn in the reference's 3840 × 2160 coordinates;
   the viewBox in the PHP crops that to the stage. */
.scr-whole-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.scr-whole-lines path {
    fill: none;
    stroke: var(--scr-whole-accent);
    stroke-width: 2px;
    vector-effect: non-scaling-stroke;
}

/* Dots: the button is the hit area, ::before is the visible square */
.scr-whole-dot {
    --dot-size: max(12px, 1.0417cqw);
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--dot-size);
    height: var(--dot-size);
    padding: 0;
    border: 0;
    background: none;
    transform: translate(-50%, -50%);
}

.scr-whole-dot::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--dot-size);
    height: var(--dot-size);
    background-color: var(--scr-whole-accent);
    transform: translate(-50%, -50%);
}

.scr-whole-label {
    position: absolute;
    width: var(--w);
    color: var(--tecs-white);
}

.scr-whole-label .tecs-heading-xs {
    margin-bottom: 0.1em;
    /* font-size: 1.91cqw; */
    color: var(--tecs-white);
    text-transform: uppercase;
    white-space: nowrap;
}

.scr-whole-label .tecs-body {
    /* font-size: 1.53cqw; */
    /* line-height: 1.24; */
}

.scr-whole-label sub {
    font-size: 0.65em;
    line-height: 0;
}

/* Left column hangs below its line, right column stands on its line */
.scr-whole-label--left {
    left: 0;
    top: var(--line);
    margin-top: 0.75cqw;
}

.scr-whole-label--right {
    right: 0;
    bottom: var(--line);
    margin-bottom: 0.75cqw;
    text-align: right;
    text-wrap: balance;
}

#scr-whole-label-1 { --line: 10.153%; --w: 38cqw; }
#scr-whole-label-2 { --line: 31.944%; --w: 36.5cqw; }
#scr-whole-label-3 { --line: 51.520%; --w: 34cqw; }
#scr-whole-label-4 { --line: 76.041%; --w: 29.5cqw; }
#scr-whole-label-5 { --line: 66.150%; --w: 27cqw; }
#scr-whole-label-6 { --line: 40.315%; --w: 30cqw; }
#scr-whole-label-7 { --line: 11.003%; --w: 33cqw; }


/* ============================================================
   960px AND BELOW — tappable dots
   ============================================================ */
@media (max-width: 960px) {

    .scr-whole-container {
        --model-height: clamp(400px, 58svh, 150vw);
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--tecs-sp-6);
        aspect-ratio: auto;
        padding: var(--tecs-sp-7) var(--tecs-sp-4);
    }

    .scr-whole-lines {
        display: none;
    }

    /* Crop box: exactly the model's bounds within the PNG */
    .scr-whole-figure {
        position: relative;
        inset: auto;
        flex: none;
        height: var(--model-height);
        aspect-ratio: 542 / 1053;
        overflow: hidden; /* the PNG is ~3.5× wider than this crop */
    }

    /* Same PNG box, re-placed so the model fills the crop box */
    .scr-whole-model {
        left: -125.092%;
        top: -1.519%;
        width: 354.244%;
    }

    .scr-whole-dot {
        --dot-size: 16px;
        --hit-size: 34px;
        width: var(--hit-size);
        height: var(--hit-size);
    }

    .scr-whole-labels {
        width: 100%;
        max-width: 34rem;
    }

    .scr-whole-label,
    .scr-whole-label--left,
    .scr-whole-label--right {
        position: static;
        width: auto;
        margin: 0;
        text-align: left;
        text-wrap: wrap;
    }

    .scr-whole-label + .scr-whole-label {
        margin-top: var(--tecs-sp-5);
    }

    .scr-whole-label .tecs-heading-xs {
        margin-bottom: 0.3em;
        font-size: 1.25rem;
        white-space: normal;
    }

    .scr-whole-label .tecs-body {
        font-size: var(--tecs-fs-body);
        line-height: var(--tecs-lh-body);
    }

    /* --- With JS: one label at a time ---
       Everything shares one grid cell, so the panel is always as
       tall as its longest label and the page doesn't jump. */
    .scr-whole.is-enhanced .scr-whole-labels {
        display: grid;
        padding-top: var(--tecs-sp-4);
        border-top: 2px solid var(--scr-whole-accent);
    }

    .scr-whole.is-enhanced .scr-whole-label {
        grid-area: 1 / 1;
        margin: 0;
    }

    .scr-whole.is-enhanced .scr-whole-label {
        visibility: hidden;
    }

    .scr-whole.is-enhanced .scr-whole-label.is-active {
        visibility: visible;
    }

    .scr-whole.is-enhanced .scr-whole-dot {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .scr-whole.is-enhanced .scr-whole-dot::before {
        box-shadow: 0 0 0 2px var(--tecs-green-950);
        transition: transform 0.15s ease, background-color 0.15s ease;
    }

    .scr-whole.is-enhanced .scr-whole-dot[aria-expanded="true"] {
        z-index: 1;
    }

    .scr-whole.is-enhanced .scr-whole-dot[aria-expanded="true"]::before {
        background-color: var(--tecs-white);
        box-shadow: 0 0 0 2px var(--scr-whole-accent);
        transform: translate(-50%, -50%) scale(1.25);
    }

    .scr-whole.is-enhanced .scr-whole-dot:focus-visible {
        outline: 2px solid var(--tecs-white);
        outline-offset: -2px;
    }

    /* Two-up when there's room, including phones in landscape */
    @media (min-width: 600px) {
        .scr-whole-container {
            --model-height: clamp(400px, 82svh, 640px);
            flex-direction: row;
            justify-content: center;
            gap: var(--tecs-sp-9);
        }

        .scr-whole-labels {
            flex: 0 1 22rem;
        }

        .scr-whole:not(.is-enhanced) .scr-whole-labels {
            flex-basis: 24rem;
        }
    }
}


/* ============================================================
   ANIMATION + PREV / NEXT
   Behaviour: includes/js/diagram-hotspots.js (shared).
   ============================================================ */

.scr-whole {
    --scr-whole-nav-hover: var(--scr-whole-accent);
}

.scr-whole-nav {
    display: none;
}

/* Desktop: labels rise in one at a time the first time the diagram
   scrolls into view. --i (label order) is set by the script. */
@media (min-width: 961px) and (prefers-reduced-motion: no-preference) {
    .scr-whole.is-enhanced .scr-whole-label {
        transition:
            opacity 0.7s ease,
            transform 0.7s cubic-bezier(0.2, 0.7, 0.3, 1);
        transition-delay: calc(var(--i, 0) * 180ms);
    }

    .scr-whole.is-enhanced:not(.is-revealed) .scr-whole-label {
        opacity: 0;
        transform: translateY(1rem);
    }
}

@media (max-width: 960px) {

    /* --- Labels share one grid cell. Only the active label, and
       the one animating out, are visible. --- */
    .scr-whole.is-enhanced .scr-whole-labels > .is-active,
    .scr-whole.is-enhanced .scr-whole-labels > .is-leaving {
        visibility: visible;
    }

    /* Direction of travel comes from --dx on the root:
       next = 1, previous = -1. */
    .scr-whole.is-enhanced .scr-whole-labels > .is-active {
        animation: scr-whole-in 0.4s cubic-bezier(0.2, 0.7, 0.3, 1) both;
    }

    .scr-whole.is-enhanced .scr-whole-labels > .is-leaving {
        pointer-events: none;
        animation: scr-whole-out 0.25s ease-in both;
    }

    @keyframes scr-whole-in {
        from {
            opacity: 0;
            transform: translate(calc(var(--dx, 0) * 1.5rem), 0);
        }
    }

    @keyframes scr-whole-out {
        to {
            opacity: 0;
            transform: translate(calc(var(--dx, 0) * -1.5rem), 0);
        }
    }

    /* --- Prev / next, under the label --- */
    .scr-whole.is-enhanced .scr-whole-nav {
        position: relative;
        z-index: 1;
        display: flex;
        grid-row: 2;
        align-items: center;
        gap: var(--tecs-sp-3);
        margin-top: var(--tecs-sp-5);
    }

    .scr-whole-prev,
    .scr-whole-next {
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: none;
        color: inherit;
        font-size: 2.5rem; /* icon is 1em */
        line-height: 0;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.2s ease;
    }

    .scr-whole-prev svg,
    .scr-whole-next svg {
        display: block;
    }

    .scr-whole-prev svg {
        transform: rotate(180deg);
    }

    .scr-whole-prev:hover { color: var(--scr-whole-nav-hover); }
    .scr-whole-next:hover { color: var(--scr-whole-nav-hover); }

    .scr-whole-prev:focus-visible,
    .scr-whole-next:focus-visible {
        outline: 2px solid currentColor;
        outline-offset: 2px;
    }

    .scr-whole-count {
        min-width: 3.5em;
        margin: 0;
        text-align: center;
        font-variant-numeric: tabular-nums;
        opacity: 0.7;
    }

    /* --- Dots: a slow pulse behind each one, staggered by --i.
       Stops on the open dot. --- */
    .scr-whole.is-enhanced .scr-whole-dot::after {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        z-index: -1;
        width: var(--dot-size);
        height: var(--dot-size);
        background-color: var(--scr-whole-accent);
        opacity: 0;
        filter: blur(1px);
        transform: translate(-50%, -50%);
        animation: scr-whole-pulse 2.4s ease-out infinite;
        animation-delay: calc(var(--i, 0) * 0.35s);
    }

    .scr-whole.is-enhanced .scr-whole-dot[aria-expanded="true"]::after {
        animation: none;
    }

    @keyframes scr-whole-pulse {
        0% {
            opacity: 0.6;
            transform: translate(-50%, -50%) scale(1);
        }
        70%,
        100% {
            opacity: 0;
            transform: translate(-50%, -50%) scale(2.6);
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .scr-whole.is-enhanced .scr-whole-dot::after {
        display: none;
    }

    .scr-whole.is-enhanced .scr-whole-labels > .is-active,
    .scr-whole.is-enhanced .scr-whole-labels > .is-leaving {
        animation: none;
    }

    .scr-whole.is-enhanced .scr-whole-labels > .is-leaving {
        visibility: hidden;
    }
}
