/*
 * Polls ([ds_poll]): a question, a few answers, then each answer's share of
 * the vote as a bar that grows out of the answer itself.
 *
 * Loads after picker.css and builds on it: the root is `.dscp .dspl`, so the
 * --dscp-* tokens, heading reset, hero triangles and pill carry over. Only
 * what's new is here, prefixed dspl-.
 *
 * States, set on the root by poll.js:
 *   .is-ready     answers can be tapped
 *   .is-voting    one answer is chosen, the vote is on its way
 *   .is-results   the bars are showing (plus .is-done / .is-moved / .is-net /
 *                 .is-closed for which line shows under the question)
 *   .is-changing  with .is-ready / .is-voting: "Change my answer" was tapped;
 *                 the reader's answer stays checked while they pick again
 *   .is-error     something failed; answers can be tapped again
 *
 * Doc: design-system/ds/components/ds-poll.md
 */

.dspl {
    --dspl-ease: cubic-bezier(.2, .8, .2, 1);
    /* A touch of overshoot, so a bar settles rather than stops. */
    --dspl-spring: cubic-bezier(.22, 1.18, .36, 1);
    --dspl-fill: color-mix(in srgb, var(--dscp-t1) 15%, transparent);
    --dspl-fill-mine: color-mix(in srgb, var(--dscp-teal-600) 62%, transparent);
    min-height: 100vh;
    min-height: 100svh;
}

/* ---- hero ---- */
.dspl-hero {
    padding: calc(var(--dscp-header) + clamp(36px, 6vw, 88px)) 0 clamp(64px, 8vw, 112px);
}
.dspl-inner {
    position: relative;
    max-width: 640px;
    margin: 0 auto;
    padding: 0 var(--dscp-gutter);
    text-align: center;
}
.dspl-inner > * {
    animation: dscp-rise .8s var(--dscp-ease) both;
}
.dspl-inner > :nth-child(2) { animation-delay: .06s; }
.dspl-inner > :nth-child(3) { animation-delay: .12s; }
.dspl-inner > :nth-child(4) { animation-delay: .18s; }
.dspl-inner > :nth-child(5) { animation-delay: .24s; }
.dscp .dspl-hero p.dspl-pill {
    animation: dscp-pop .6s var(--dscp-ease) both;
}
.dscp .dspl-hero h1.dscp-h1 {
    margin: 0 0 16px;
    font-size: clamp(36px, 4.8vw, 60px) !important;
    line-height: 1.06 !important;
}

/* ---- the line under the question: one per state, crossfaded in place ---- */
.dspl-leads {
    display: grid;
    max-width: 540px;
    margin: 0 auto;
}
.dscp .dspl-leads p.dspl-lead {
    grid-area: 1 / 1;
    margin: 0 !important;
    color: var(--dscp-t2);
    font: 400 clamp(17px, 1.7vw, 19px)/1.5 var(--dscp-ui) !important;
    text-wrap: pretty;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity .45s var(--dspl-ease), transform .45s var(--dspl-ease), visibility 0s .45s;
}
/* Specific enough to beat the base rule above. */
.dscp.dspl:not(.is-results):not(.is-error):not(.is-changing) .dspl-leads p.dspl-lead--ask,
.dscp.dspl.is-changing:not(.is-results):not(.is-error) .dspl-leads p.dspl-lead--change,
.dscp.dspl.is-error .dspl-leads p.dspl-lead--error,
.dscp.dspl.is-done .dspl-leads p.dspl-lead--done,
.dscp.dspl.is-moved .dspl-leads p.dspl-lead--moved,
.dscp.dspl.is-net .dspl-leads p.dspl-lead--net,
.dscp.dspl.is-closed .dspl-leads p.dspl-lead--closed {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: .15s, .15s, 0s;
}
.dscp .dspl-leads p.dspl-lead--error {
    color: var(--dscp-amber);
}

/* ---- answers ---- */
.dspl-options {
    display: grid;
    gap: 12px;
    margin: clamp(32px, 4vw, 44px) 0 0;
    text-align: left;
}
.dscp button.dspl-opt {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 76px;
    padding: 16px 18px 16px 22px;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid var(--dscp-border-emph) !important;
    border-radius: var(--dscp-radius-card) !important;
    background: color-mix(in srgb, var(--dscp-band) 88%, transparent) !important;
    color: var(--dscp-t1) !important;
    text-align: left;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    -webkit-tap-highlight-color: transparent;
    transition: border-color .25s, background-color .25s, transform .2s var(--dspl-ease), opacity .4s;
}
.dspl:not(.is-ready) button.dspl-opt {
    cursor: default;
}
.dspl.is-ready button.dspl-opt:hover {
    border-color: color-mix(in srgb, var(--dscp-teal-400) 60%, var(--dscp-border-emph)) !important;
    background: var(--dscp-hover) !important;
}
.dspl.is-ready button.dspl-opt:active {
    transform: scale(.985);
}

/* The bar: the whole answer's width, scaled to its share. */
.dspl-opt__fill {
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--dspl-fill);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 1.25s var(--dspl-spring);
    transition-delay: calc(var(--i, 0) * 90ms + 120ms);
}
.dspl-opt.is-mine .dspl-opt__fill {
    background: var(--dspl-fill-mine);
}
.dspl.is-results .dspl-opt__fill {
    transform: scaleX(var(--share, 0));
}
/* Live updates after the first reveal move without the stagger. */
.dspl.is-settled .dspl-opt__fill {
    transition-delay: 0s;
}

.dspl-opt__text {
    display: grid;
    gap: 3px;
    flex: 1;
    min-width: 0;
}
.dspl-opt__label {
    font: 500 19px/1.2 var(--dscp-ui);
    color: var(--dscp-t1);
}
.dspl-opt__note {
    font: 400 14.5px/1.35 var(--dscp-ui);
    color: var(--dscp-t3);
    transition: color .4s;
}
.dspl.is-results .dspl-opt__note {
    color: color-mix(in srgb, var(--dscp-t2) 80%, transparent);
}

/* The circle on the right: empty to start, a check on the reader's answer. */
.dspl-opt__mark {
    display: grid;
    place-items: center;
    flex: none;
    width: 30px;
    height: 30px;
    border: 1.5px solid var(--dscp-border-emph);
    border-radius: 999px;
    color: transparent;
    font-size: 16px;
    transition: border-color .25s, background-color .3s, color .3s, opacity .4s, transform .4s var(--dspl-ease);
}
.dspl.is-ready .dspl-opt:hover .dspl-opt__mark {
    border-color: var(--dscp-teal-400);
}
.dspl-opt.is-mine .dspl-opt__mark {
    border-color: var(--dscp-teal-400);
    background: var(--dscp-teal-400);
    color: var(--dscp-teal-950);
    animation: dspl-check .5s var(--dspl-spring) both;
}
.dspl.is-results .dspl-opt:not(.is-mine) .dspl-opt__mark {
    opacity: 0;
    transform: scale(.6);
}
@keyframes dspl-check {
    0% { transform: scale(.4); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* Choosing: the answer lights up, the rest step back until the bars arrive. */
.dscp .dspl-opt.is-mine {
    border-color: var(--dscp-teal-400) !important;
}
.dspl.is-voting .dspl-opt:not(.is-mine) {
    opacity: .5;
}
.dspl.is-voting .dspl-opt.is-mine::after {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--dscp-teal-400) 55%, transparent);
    animation: dspl-ring 1.2s var(--dspl-ease) infinite;
    pointer-events: none;
}
@keyframes dspl-ring {
    to { box-shadow: 0 0 0 10px transparent; }
}

/* Until the page knows where this device stands. */
.dspl:not(.is-ready):not(.is-voting):not(.is-results):not(.is-error) .dspl-opt {
    opacity: .7;
}

.dscp .dspl-hero p.dspl-foot {
    margin: 22px 0 0 !important;
    color: var(--dscp-t4);
    font: 400 13px/1.4 var(--dscp-ui) !important;
}

/* "Change my answer": a quiet text button at the end of the line under the
   answers, so it follows that line's alignment (centred on a poll page, left
   in a path gift's drawer). */
.dscp button.dspl-change {
    display: inline;
    margin: 0 0 0 6px;
    padding: 2px 0;
    border: 0 !important;
    border-radius: 0 !important;
    background: none !important;
    color: var(--dscp-t3) !important;
    font: 500 13px/1.4 var(--dscp-ui) !important;
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--dscp-t3) 45%, transparent);
    text-underline-offset: 3px;
    transition: color .2s, text-decoration-color .2s;
}
.dscp button.dspl-change:hover {
    color: var(--dscp-teal-300) !important;
    text-decoration-color: currentColor;
}
.dscp button.dspl-change:disabled {
    opacity: .6;
    cursor: default;
}

/* Testing only (polls.php → revote): a quiet text button under the results. */
.dscp button.dspl-again {
    margin: 10px 0 0;
    padding: 6px 12px;
    border: 1px dashed var(--dscp-border-emph) !important;
    border-radius: 999px !important;
    background: transparent !important;
    color: var(--dscp-t3) !important;
    font: 500 12.5px/1.2 var(--dscp-ui) !important;
    transition: color .2s, border-color .2s;
}
.dscp button.dspl-again:hover {
    border-color: var(--dscp-teal-400) !important;
    color: var(--dscp-t1) !important;
}

@media (max-width: 560px) {
    .dspl-options {
        gap: 10px;
    }
    .dscp button.dspl-opt {
        min-height: 70px;
        padding: 14px 14px 14px 18px;
    }
    .dspl-opt__label {
        font-size: 18px;
    }
    .dspl-opt__note {
        font-size: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dspl-inner > *,
    .dscp .dspl-hero p.dspl-pill,
    .dspl-opt.is-mine .dspl-opt__mark,
    .dspl.is-voting .dspl-opt.is-mine::after {
        animation: none !important;
    }
    .dspl-opt__fill {
        transition: transform .3s linear;
        transition-delay: 0s;
    }
}
