/* The slider puzzle — see _0_utils/_modules/slider_captcha/.
 *
 * A modal. The guarded forms look exactly as they did; sending one opens this
 * `<dialog>` with `showModal()`, which puts it in the top layer — above a
 * sticky header and outside a scrolling card it may be nested in — with a
 * backdrop behind it and the focus kept inside. In it: a title, a line of
 * instruction, the picture with the piece over it, the track the handle is
 * dragged along, and the line under it that says how it went.
 *
 * Its colours are the page's when the page has a palette: on the v3 skin
 * `--brand`, `--surface`, `--ink`, `--line` and `--page` are the site's — and
 * the visitor's choice of them, light or dark — so the dialog wears them.
 * Anywhere else (a public site on a theme of its own) the fallbacks are a
 * violet on near-black. The tokens are declared on the dialog, not on :root,
 * so nothing here can repaint a page.
 *
 * The dialog still inherits from the form it sits in (a card's muted text, a
 * section's centring), so every inherited property it relies on is set on it,
 * and the rules for its buttons name the dialog too: a page's own
 * `.something button` would otherwise win.
 *
 * Which parts show is decided by `data-state`, set by the script: idle ->
 * loading -> ready -> dragging -> checking -> scoring (the match counting up)
 * -> success, or -> fail; and error when a puzzle could not be fetched.
 * Positions are set through the CSSOM (`style.transform`), which the CSP
 * allows; the markup has no `style`.
 *
 * `data-mode` is the other axis: "picture", or "work" — the way round the
 * picture, where a panel with a progress bar stands where the puzzle was and
 * the states run loading -> working -> checking -> success, or -> error.
 */

.slider-captcha {
    --sc-brand: var(--brand, #7c4dff);
    --sc-brand-deep: var(--brand-dark, #5e2ff4);
    --sc-brand-rgb: var(--brand-rgb, 124, 77, 255);
    --sc-surface: var(--surface, #100a24);
    --sc-well: var(--page, #0b0b29);
    --sc-ink: var(--ink, #e9e9f7);
    --sc-muted: var(--ink-muted, #9a9ec2);
    --sc-line: var(--line, rgba(124, 77, 255, 0.28));
    /* mixed toward the ink, so they read on a light surface and a dark one */
    --sc-success: color-mix(in srgb, #10b981 72%, var(--sc-ink));
    --sc-danger: color-mix(in srgb, #f43f5e 78%, var(--sc-ink));
    --sc-success-deep: #059669;
    --sc-danger-deep: #e11d48;
    --sc-radius: var(--radius-md, 12px);
    --sc-track: 48px;
    --sc-inset: 3px;

    width: min(400px, calc(100vw - 32px));
    margin: auto;
    padding: 20px 20px 18px;
    border: 1px solid rgba(var(--sc-brand-rgb), 0.5);
    border-radius: var(--radius-lg, 20px);
    background-color: var(--sc-surface);
    background-image: radial-gradient(120% 80% at 50% 0%, rgba(var(--sc-brand-rgb), 0.18) 0%, transparent 60%);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), 0 0 60px rgba(var(--sc-brand-rgb), 0.22);
    color: var(--sc-ink);
    font-size: 15px;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: normal;
    text-align: start;
    text-transform: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.slider-captcha[open] {
    animation: slider-captcha-in 0.22s ease-out;
}

.slider-captcha::backdrop {
    background-color: rgba(5, 4, 18, 0.62);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* A browser without showModal() gets the box fixed in the middle and no
   backdrop — enough to solve the puzzle and send the form. */
.slider-captcha.is-inline[open] {
    position: fixed;
    inset: 0;
    z-index: 10000;
}

/* ---------- the head ---------- */

.slider-captcha__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 2px;
}

.slider-captcha .slider-captcha__title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0;
    color: var(--sc-ink);
}

.slider-captcha .slider-captcha__lead {
    margin: 0 0 14px;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--sc-muted);
}

.slider-captcha .slider-captcha__close {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin-inline-end: -6px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: transparent;
    color: var(--sc-muted);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.slider-captcha .slider-captcha__close svg {
    width: 18px;
    height: 18px;
}

.slider-captcha .slider-captcha__close:hover {
    background-color: rgba(var(--sc-brand-rgb), 0.16);
    color: var(--sc-ink);
}

.slider-captcha .slider-captcha__close:focus-visible,
.slider-captcha .slider-captcha__refresh:focus-visible,
.slider-captcha .slider-captcha__handle:focus-visible,
.slider-captcha .slider-captcha__way:focus-visible,
.slider-captcha .slider-captcha__retry:focus-visible {
    outline: 2px solid rgba(var(--sc-brand-rgb), 0.8);
    outline-offset: 2px;
}

/* ---------- the picture ---------- */

.slider-captcha__stage {
    position: relative;
    aspect-ratio: 2 / 1;
    overflow: hidden;
    border: 1px solid var(--sc-line);
    border-bottom: 0;
    border-radius: var(--sc-radius) var(--sc-radius) 0 0;
    background:
        radial-gradient(80% 90% at 20% 10%, rgba(var(--sc-brand-rgb), 0.3), transparent 70%),
        var(--sc-well);
}

.slider-captcha__picture,
.slider-captcha__piece {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    height: 100%;
    max-width: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.slider-captcha__picture {
    width: 100%;
    object-fit: cover;
}

.slider-captcha__piece {
    width: auto;
    will-change: transform;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.45));
}

.slider-captcha:not([data-state="idle"]):not([data-state="loading"]):not([data-state="error"]) .slider-captcha__picture,
.slider-captcha:not([data-state="idle"]):not([data-state="loading"]):not([data-state="error"]) .slider-captcha__piece {
    opacity: 1;
}

/* What covers the picture while there is none: a spinner while one is on its
   way, the puzzle mark otherwise. */
.slider-captcha__veil {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(var(--sc-brand-rgb), 0.55);
    transition: opacity 0.3s ease;
}

.slider-captcha:not([data-state="idle"]):not([data-state="loading"]):not([data-state="error"]) .slider-captcha__veil {
    opacity: 0;
    pointer-events: none;
}

.slider-captcha__veil-icon {
    width: 42px;
    height: 42px;
}

.slider-captcha__spinner {
    display: none;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(var(--sc-brand-rgb), 0.25);
    border-top-color: var(--sc-brand);
    border-radius: 50%;
    animation: slider-captcha-spin 0.8s linear infinite;
}

.slider-captcha[data-state="loading"] .slider-captcha__spinner,
.slider-captcha[data-state="idle"] .slider-captcha__spinner {
    display: block;
}

.slider-captcha[data-state="loading"] .slider-captcha__veil-icon,
.slider-captcha[data-state="idle"] .slider-captcha__veil-icon {
    display: none;
}

.slider-captcha[data-state="error"] .slider-captcha__veil {
    color: var(--sc-danger);
}

/* on the picture, so it keeps its own white on dark whatever the page is */
.slider-captcha .slider-captcha__refresh {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background-color: rgba(11, 11, 41, 0.55);
    color: #ffffff;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.3s ease;
}

.slider-captcha .slider-captcha__refresh svg {
    width: 16px;
    height: 16px;
}

.slider-captcha .slider-captcha__refresh:hover {
    background-color: rgba(var(--sc-brand-rgb), 0.75);
}

.slider-captcha .slider-captcha__refresh:active {
    transform: rotate(-90deg);
}

/* nothing to swap once solved, and nothing to swap while one is on its way */
.slider-captcha[data-state="success"] .slider-captcha__refresh,
.slider-captcha[data-state="idle"] .slider-captcha__refresh,
.slider-captcha[data-state="loading"] .slider-captcha__refresh,
.slider-captcha[data-state="checking"] .slider-captcha__refresh,
.slider-captcha[data-state="scoring"] .slider-captcha__refresh {
    display: none;
}

/* ---------- the track ---------- */

.slider-captcha__track {
    position: relative;
    height: var(--sc-track);
    overflow: hidden;
    border: 1px solid var(--sc-line);
    border-radius: 0 0 var(--sc-radius) var(--sc-radius);
    background-color: var(--sc-well);
    transition: border-color 0.25s ease;
}

.slider-captcha__fill {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 0;
    background: linear-gradient(90deg, rgba(var(--sc-brand-rgb), 0.12) 0%, rgba(var(--sc-brand-rgb), 0.36) 100%);
}

/* A block with the track's line height, not a flex row: a centred flex item
   that is too wide spills out of both ends, where a block clips at the end
   with an ellipsis. */
.slider-captcha__label {
    position: absolute;
    inset: 0;
    display: block;
    padding: 0 14px 0 calc(var(--sc-track) + 10px);
    overflow: hidden;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: calc(var(--sc-track) - 2px);
    text-align: center;
    color: var(--sc-muted);
    white-space: nowrap;
    text-overflow: ellipsis;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

/* the instruction steps aside once the handle is on its way through it */
.slider-captcha[data-state="dragging"] .slider-captcha__label,
.slider-captcha[data-state="checking"] .slider-captcha__label,
.slider-captcha[data-state="scoring"] .slider-captcha__label,
.slider-captcha[data-state="success"] .slider-captcha__label,
.slider-captcha[data-state="fail"] .slider-captcha__label {
    opacity: 0;
}

/* A slow sheen across the words while the puzzle waits — the cue that the
   handle is there to be pulled. */
.slider-captcha[data-state="ready"] .slider-captcha__label {
    background: linear-gradient(90deg, var(--sc-muted) 0%, var(--sc-ink) 50%, var(--sc-muted) 100%) 0 0 / 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: slider-captcha-sheen 2.6s linear infinite;
}

.slider-captcha .slider-captcha__handle {
    position: absolute;
    top: var(--sc-inset);
    bottom: var(--sc-inset);
    left: var(--sc-inset);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--sc-track) - 2 * var(--sc-inset) - 2px);
    border-radius: 9px;
    background: linear-gradient(135deg, var(--sc-brand-deep) 0%, var(--sc-brand) 100%);
    box-shadow: 0 6px 16px rgba(var(--sc-brand-rgb), 0.4);
    color: #ffffff;
    cursor: grab;
    touch-action: none;
    will-change: transform;
    transition: background 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
}

.slider-captcha .slider-captcha__handle:focus {
    outline: none;
}

.slider-captcha[data-state="dragging"] .slider-captcha__handle {
    cursor: grabbing;
    box-shadow: 0 8px 22px rgba(var(--sc-brand-rgb), 0.55);
}

.slider-captcha[data-state="idle"] .slider-captcha__handle,
.slider-captcha[data-state="loading"] .slider-captcha__handle,
.slider-captcha[data-state="error"] .slider-captcha__handle {
    opacity: 0.55;
    cursor: default;
}

.slider-captcha[data-state="checking"] .slider-captcha__handle,
.slider-captcha[data-state="scoring"] .slider-captcha__handle,
.slider-captcha[data-state="success"] .slider-captcha__handle {
    cursor: default;
}

.slider-captcha__icon {
    display: none;
    width: 20px;
    height: 20px;
}

.slider-captcha:not([data-state="success"]):not([data-state="fail"]) .slider-captcha__icon--arrow,
.slider-captcha[data-state="success"] .slider-captcha__icon--check,
.slider-captcha[data-state="fail"] .slider-captcha__icon--cross {
    display: block;
}

/* the snap back after a miss, and nothing else — a drag follows the finger */
.slider-captcha.is-returning .slider-captcha__handle,
.slider-captcha.is-returning .slider-captcha__piece {
    transition: transform 0.3s ease;
}

.slider-captcha.is-returning .slider-captcha__fill {
    transition: width 0.3s ease;
}

/* ---------- outcomes ---------- */

.slider-captcha[data-state="success"] .slider-captcha__track {
    border-color: color-mix(in srgb, var(--sc-success) 60%, transparent);
}

.slider-captcha[data-state="success"] .slider-captcha__fill {
    background: linear-gradient(90deg, rgba(5, 150, 105, 0.14) 0%, rgba(16, 185, 129, 0.36) 100%);
}

.slider-captcha[data-state="success"] .slider-captcha__handle {
    background: linear-gradient(135deg, var(--sc-success-deep) 0%, #10b981 100%);
    box-shadow: 0 6px 16px rgba(5, 150, 105, 0.4);
}

.slider-captcha[data-state="fail"] .slider-captcha__track {
    border-color: color-mix(in srgb, var(--sc-danger) 65%, transparent);
    animation: slider-captcha-shake 0.42s ease;
}

.slider-captcha[data-state="fail"] .slider-captcha__fill {
    background: linear-gradient(90deg, rgba(225, 29, 72, 0.12) 0%, rgba(244, 63, 94, 0.36) 100%);
}

.slider-captcha[data-state="fail"] .slider-captcha__handle {
    background: linear-gradient(135deg, var(--sc-danger-deep) 0%, #f43f5e 100%);
    box-shadow: 0 6px 16px rgba(225, 29, 72, 0.38);
}

/* ---------- the line under the slider ---------- */

/* What the puzzle has to say — loading, checking, the match counting up, the
   verdict. Under the track, not on it: by the time there is a verdict the
   handle sits in the middle of the track. It keeps its height while empty,
   so a message arriving does not move the dialog. */
.slider-captcha .slider-captcha__status {
    min-height: 1.45em;
    margin: 10px 0 0;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.45;
    text-align: center;
    color: var(--sc-muted);
    font-variant-numeric: tabular-nums;
    transition: color 0.2s ease;
}

.slider-captcha[data-state="scoring"] .slider-captcha__status {
    color: var(--sc-ink);
}

.slider-captcha[data-state="success"] .slider-captcha__status {
    color: var(--sc-success);
}

.slider-captcha[data-state="fail"] .slider-captcha__status,
.slider-captcha[data-state="error"] .slider-captcha__status,
.slider-captcha[data-state="ready"] .slider-captcha__status:not(:empty) {
    color: var(--sc-danger);
}

/* ---------- the way round the picture ---------- */

/* One of the two at a time: the puzzle and its lead, or the work panel; and
   the switch that leads to whichever is not showing. */
.slider-captcha:not([data-mode="work"]) .slider-captcha__work,
.slider-captcha:not([data-mode="work"]) [data-slider-captcha-to-picture],
.slider-captcha[data-mode="work"] .slider-captcha__puzzle,
.slider-captcha[data-mode="work"] .slider-captcha__lead,
.slider-captcha[data-mode="work"] [data-slider-captcha-to-work] {
    display: none;
}

/* the box the puzzle stood in, picture and track together, so swapping the
   two does not move the dialog */
.slider-captcha__work {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    aspect-ratio: 360 / 228;
    padding: 18px 20px;
    border: 1px solid var(--sc-line);
    border-radius: var(--sc-radius);
    background:
        radial-gradient(80% 90% at 20% 10%, rgba(var(--sc-brand-rgb), 0.22), transparent 70%),
        var(--sc-well);
    text-align: center;
}

.slider-captcha__work-icon {
    flex: none;
    width: 40px;
    height: 40px;
    color: var(--sc-brand);
    transition: color 0.25s ease;
}

.slider-captcha[data-state="loading"] .slider-captcha__work-icon,
.slider-captcha[data-state="working"] .slider-captcha__work-icon {
    animation: slider-captcha-pulse 1.4s ease-in-out infinite;
}

.slider-captcha[data-state="success"] .slider-captcha__work-icon {
    color: var(--sc-success);
}

.slider-captcha[data-state="error"] .slider-captcha__work-icon {
    color: var(--sc-danger);
}

.slider-captcha .slider-captcha__work-lead {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--sc-muted);
}

/* A bar, not the browser's own: it is filled through `value`, never a
   `style`, and each engine paints its own part of it. */
.slider-captcha .slider-captcha__progress {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    flex: none;
    width: 100%;
    height: 8px;
    margin: 0;
    border: 0;
    border-radius: 999px;
    overflow: hidden;
    background-color: rgba(var(--sc-brand-rgb), 0.18);
    color: var(--sc-brand);
}

.slider-captcha .slider-captcha__progress::-webkit-progress-bar {
    border-radius: 999px;
    background-color: rgba(var(--sc-brand-rgb), 0.18);
}

.slider-captcha .slider-captcha__progress::-webkit-progress-value {
    border-radius: 999px;
    background: linear-gradient(90deg, var(--sc-brand-deep) 0%, var(--sc-brand) 100%);
    transition: width 0.2s ease;
}

.slider-captcha .slider-captcha__progress::-moz-progress-bar {
    border-radius: 999px;
    background: linear-gradient(90deg, var(--sc-brand-deep) 0%, var(--sc-brand) 100%);
}

.slider-captcha[data-state="success"] .slider-captcha__progress::-webkit-progress-value {
    background: var(--sc-success);
}

.slider-captcha[data-state="success"] .slider-captcha__progress::-moz-progress-bar {
    background: var(--sc-success);
}

/* only when a piece of work did not come through */
.slider-captcha .slider-captcha__retry {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 7px 16px;
    border: 1px solid rgba(var(--sc-brand-rgb), 0.55);
    border-radius: 999px;
    background-color: rgba(var(--sc-brand-rgb), 0.14);
    color: var(--sc-ink);
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.3;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.slider-captcha[data-mode="work"][data-state="error"] .slider-captcha__retry {
    display: inline-flex;
}

.slider-captcha .slider-captcha__retry:hover {
    background-color: rgba(var(--sc-brand-rgb), 0.3);
}

/* The switch between the two, under the status line. It used to be an
   underlined line of brand-coloured text, which read as part of the
   instructions rather than as a second way through, and was a small target
   on a phone. Now a hairline sets it off from the puzzle and it is a pill of
   its own: a round icon at the start, the words after it, 40px tall. */
.slider-captcha__ways {
    display: flex;
    justify-content: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--sc-line);
}

/* nothing to switch to while a pass is being checked or spent */
.slider-captcha[data-state="checking"] .slider-captcha__ways,
.slider-captcha[data-state="scoring"] .slider-captcha__ways,
.slider-captcha[data-state="success"] .slider-captcha__ways {
    visibility: hidden;
}

.slider-captcha .slider-captcha__way {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding-block: 5px;
    padding-inline: 5px 18px;
    border: 1px solid rgba(var(--sc-brand-rgb), 0.38);
    border-radius: 999px;
    background-color: rgba(var(--sc-brand-rgb), 0.07);
    color: var(--sc-ink);
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.12s ease;
}

/* The icon sits in a disc of its own. A flex box of a fixed size centres
   the drawing itself, whatever the line box around the words does. */
.slider-captcha .slider-captcha__way-icon {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: rgba(var(--sc-brand-rgb), 0.18);
    /* mixed toward the ink, like the success and error colours: the brand
       alone is too faint for a small drawing on a dark surface */
    color: color-mix(in srgb, var(--sc-brand) 60%, var(--sc-ink));
    transition: background-color 0.2s ease, color 0.2s ease;
}

.slider-captcha .slider-captcha__way-icon svg {
    display: block;
    width: 16px;
    height: 16px;
}

.slider-captcha .slider-captcha__way:hover {
    border-color: rgba(var(--sc-brand-rgb), 0.65);
    background-color: rgba(var(--sc-brand-rgb), 0.14);
}

.slider-captcha .slider-captcha__way:hover .slider-captcha__way-icon {
    background-color: var(--sc-brand);
    color: #fff;
}

.slider-captcha .slider-captcha__way:active {
    transform: scale(0.98);
}

@media (prefers-reduced-motion: reduce) {
    .slider-captcha .slider-captcha__way {
        transition: none;
    }

    .slider-captcha .slider-captcha__way:active {
        transform: none;
    }
}

/* ---------- the rest ---------- */

.slider-captcha__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Shown only without JavaScript, under the form — where the puzzle cannot
   open and the form will be refused. */
.slider-captcha-noscript {
    margin: 12px 0 0;
    font-size: 13px;
    text-align: center;
    color: #e11d48;
}

@keyframes slider-captcha-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

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

@keyframes slider-captcha-sheen {
    from {
        background-position: 100% 0;
    }
    to {
        background-position: -100% 0;
    }
}

@keyframes slider-captcha-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

@keyframes slider-captcha-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(2px); }
}

/* a narrow phone: the frame gives the picture and the words their room back */
@media (max-width: 380px) {
    .slider-captcha {
        padding: 16px 14px 14px;
    }

    .slider-captcha__label {
        padding-right: 8px;
        font-size: 12.5px;
        letter-spacing: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .slider-captcha,
    .slider-captcha * {
        animation: none !important;
        transition: none !important;
    }

    .slider-captcha[data-state="ready"] .slider-captcha__label {
        background: none;
        color: var(--sc-muted);
    }
}
