/* Banknote Showcase widget
 *
 * .bn-group  all notes; the Sway idle animation rocks this
 * .bn-note   hit area, placed at its pose; the entrance animates this
 * .bn-move   hover lift / slide / straighten / scale, in the note's own frame
 * .bn-float  the Float idle animation
 * .bn-card   3D tilt and flip, holds both faces
 *
 * The script sets each note's pose as --x/--y (multiples of --w) and --r,
 * and the arrangement's scale as --ls. --stage-h is the stage height in
 * note widths, measured by the widget.
 */

.bn-stage {
    --w: clamp(150px, 20vw, 290px);
    --bn-ease: cubic-bezier(.22, 1, .36, 1);
    position: relative;
    width: 100%;
    height: calc(var(--w) * var(--stage-h, .95));
    /* Notes may reach above and below the stage, never sideways off the page. */
    overflow-x: clip;
}

.bn-stage.is-pending .bn-note,
.bn-stage.is-pending .bn-caption {
    opacity: 0;
}

/* A zero-size anchor at the middle of the stage: the notes are placed from
 * it, and Sway rotates it without pushing any box past the stage edges. */
.bn-stage .bn-group {
    position: absolute;
    left: 50%;
    top: calc(var(--w) * var(--stage-h, .95) / 2);
    width: 0;
    height: 0;
    transform-origin: 0 calc(var(--w) * .3);
}

/* Undo the theme's global button styles. */
.bn-stage .bn-note,
.bn-stage button.bn-note,
.bn-stage button.bn-note:hover,
.bn-stage button.bn-note:focus,
.bn-stage button.bn-note:active,
.bn-stage button.bn-pause,
.bn-stage button.bn-pause:hover,
.bn-stage button.bn-pause:focus,
.bn-stage button.bn-pause:active {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    color: inherit;
    font: inherit;
    line-height: 1;
}

.bn-stage .bn-note {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    width: calc(var(--w) * var(--k, 1));
    aspect-ratio: var(--ar, 2.03);
    z-index: var(--z, 1);
    transform: translate(-50%, -50%) translate(var(--x, 0px), var(--y, 0px)) rotate(var(--r, 0deg)) scale(var(--ls, 1));
    transition: transform .6s var(--bn-ease), z-index 0s linear .35s;
    -webkit-tap-highlight-color: transparent;
}
.bn-stage button.bn-note {
    cursor: pointer;
}
.bn-stage .bn-note.is-active {
    z-index: 20;
    transition: transform .6s var(--bn-ease), z-index 0s;
}
.bn-stage.is-shuffling .bn-note {
    transition: transform 1.2s var(--bn-ease) calc(var(--i, 0) * 70ms), z-index 0s;
}
.bn-stage .bn-note > * {
    pointer-events: none;
}
.bn-stage:not(.is-ready) .bn-note {
    pointer-events: none;
}
.bn-stage .bn-note:focus {
    outline: none;
}

.bn-stage .bn-move {
    position: absolute;
    inset: 0;
    display: block;
    transform: translate(var(--dx, 0px), var(--dy, 0px)) rotate(var(--dr, 0deg)) scale(var(--ds, 1));
    transition: transform .5s var(--bn-ease), filter .35s ease;
}
.bn-stage .bn-note.is-dim .bn-move {
    filter: brightness(.62) saturate(.75);
}
.bn-stage .bn-note.is-faded .bn-move {
    filter: brightness(.4) saturate(.6);
}

.bn-stage .bn-shadow {
    position: absolute;
    inset: 6% 4%;
    border-radius: 6px;
    background: rgba(2, 12, 45, .6);
    filter: blur(12px);
    opacity: .75;
    transform: translateY(10px);
    transition: transform .5s var(--bn-ease), opacity .5s ease;
}
.bn-stage .bn-note.is-active .bn-shadow {
    opacity: .95;
    transform: translateY(26px) scale(1.04);
}

.bn-stage .bn-float {
    position: absolute;
    inset: 0;
    display: block;
    perspective: 900px;
}

.bn-stage .bn-card {
    position: absolute;
    inset: 0;
    display: block;
    transform-style: preserve-3d;
    transform: rotateX(var(--rx, 0deg)) rotateY(calc(var(--ry, 0deg) + var(--flip, 0deg)));
    transition: transform .7s var(--bn-ease);
}
.bn-stage .bn-note.is-tracking .bn-card {
    transition: transform .12s linear;
}
.bn-stage .bn-note.is-flipped {
    --flip: 180deg;
}

.bn-stage .bn-face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    border-radius: 3px;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.bn-stage .bn-back {
    transform: rotateY(180deg);
}
.bn-stage .bn-note:focus-visible .bn-face {
    outline: 3px solid #ffd54a;
    outline-offset: 3px;
}

.bn-stage .bn-fx {
    position: absolute;
    inset: 0;
    border-radius: 3px;
    overflow: hidden;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    opacity: 0;
}
.bn-stage .bn-glare {
    background: radial-gradient(circle at var(--px, 50%) var(--py, 50%), rgba(255, 255, 255, .5), rgba(255, 255, 255, 0) 40%);
    mix-blend-mode: overlay;
    transition: opacity .3s ease;
}
.bn-stage .bn-holo {
    background: linear-gradient(115deg,
        transparent 22%, rgba(255, 70, 160, .6) 36%, rgba(255, 220, 90, .6) 45%,
        rgba(80, 255, 190, .6) 54%, rgba(70, 170, 255, .6) 63%, transparent 76%);
    background-size: 300% 300%;
    background-position: var(--hx, 50%) var(--hy, 50%);
    mix-blend-mode: color-dodge;
    transition: opacity .3s ease;
}
/* The light strip slides inside a clipping box so it never shows past the note. */
.bn-stage .bn-fx.bn-glint-clip {
    opacity: 1;
}
.bn-stage .bn-glint {
    position: absolute;
    inset: 0;
    display: block;
    opacity: 0;
    background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .8) 50%, transparent 65%);
    mix-blend-mode: soft-light;
}
.bn-stage[data-hover-active="tilt"] .bn-note.is-active .bn-glare {
    opacity: 1;
}
.bn-stage[data-hover-active="tilt"] .bn-note.is-active .bn-holo {
    opacity: .26;
}

/* ---------------- Idle animations ----------------
 * Float and Sway pause in place (no jump) when idle stops; Shimmer is
 * removed, since a paused light would leave a stripe on the note. */

@keyframes bn-float {
    0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg); }
    50% { transform: translate3d(var(--fx, 0px), var(--fy, -8px), 0) rotate(var(--sway, 1deg)); }
}
@keyframes bn-sway {
    0%, 100% { transform: rotate(-1.2deg) translateY(0); }
    50% { transform: rotate(1.2deg) translateY(calc(var(--w) * -.02)); }
}
@keyframes bn-shimmer {
    0% { transform: translateX(-120%); opacity: 0; }
    5% { opacity: 1; }
    14%, 100% { transform: translateX(120%); opacity: 0; }
}

.bn-stage[data-idle-active="float"] .bn-float {
    animation: bn-float calc(5.4s + var(--i, 0) * .55s) ease-in-out calc(var(--i, 0) * -1.3s) infinite;
    animation-play-state: paused;
}
.bn-stage[data-idle-active="float"] .bn-note:nth-child(even) .bn-float {
    --sway: -1deg;
}
.bn-stage[data-idle-active="sway"] .bn-group {
    animation: bn-sway 9s ease-in-out infinite;
    animation-play-state: paused;
}
.bn-stage.is-idle[data-idle-active="float"] .bn-float,
.bn-stage.is-idle[data-idle-active="sway"] .bn-group {
    animation-play-state: running;
}
.bn-stage.is-idle[data-idle-active="float"] .bn-note.is-active .bn-float {
    animation-play-state: paused;
}
.bn-stage.is-idle[data-idle-active="shimmer"] .bn-glint {
    animation: bn-shimmer 6.5s ease-in-out calc(var(--i, 0) * .16s + .4s) infinite;
}

/* ---------------- Name label and hint ---------------- */

.bn-stage .bn-caption {
    position: absolute;
    left: 50%;
    bottom: 0;
    z-index: 30;
    transform: translateX(-50%);
    pointer-events: none;
    white-space: nowrap;
    font: 600 13px/1 Arial, Helvetica, sans-serif;
    letter-spacing: .02em;
    color: #fff;
    background: rgba(4, 20, 60, .6);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, .2);
    padding: 9px 14px;
    border-radius: 999px;
    transition: opacity .3s ease;
}
/* Next to the picked note; the script sets top and left. */
.bn-stage .bn-caption.is-label {
    bottom: auto;
    transition: opacity .3s ease, top .35s var(--bn-ease), left .35s var(--bn-ease);
}
.bn-stage .bn-caption:empty,
.bn-stage:not(.is-ready) .bn-caption {
    opacity: 0;
}

/* ---------------- Pause button (WCAG 2.2.2) ---------------- */

.bn-stage button.bn-pause {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 31;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .35);
    background: rgba(4, 20, 60, .55);
    color: #fff;
    cursor: pointer;
    opacity: .7;
    transition: opacity .2s ease, background-color .2s ease;
}
.bn-stage button.bn-pause:hover,
.bn-stage button.bn-pause:focus-visible {
    opacity: 1;
    background: rgba(4, 20, 60, .85);
    border: 1px solid rgba(255, 255, 255, .35);
}
.bn-stage button.bn-pause:focus-visible {
    outline: 3px solid #ffd54a;
    outline-offset: 2px;
}
.bn-stage button.bn-pause[hidden] {
    display: none;
}
.bn-stage .bn-pause svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}
.bn-stage .bn-pause .bn-icon-play,
.bn-stage .bn-pause[aria-pressed="true"] .bn-icon-pause {
    display: none;
}
.bn-stage .bn-pause[aria-pressed="true"] .bn-icon-play {
    display: block;
}

/* ---------------- Reduced motion ----------------
 * Nothing moves; a picked note is outlined and the others dim. */

.bn-stage.is-rm .bn-note,
.bn-stage.is-rm.is-shuffling .bn-note {
    transition: none;
}
.bn-stage.is-rm .bn-move {
    transform: none;
    transition: filter .2s ease;
}
.bn-stage.is-rm .bn-card {
    transform: none;
    transition: none;
}
.bn-stage.is-rm .bn-float,
.bn-stage.is-rm .bn-group,
.bn-stage.is-rm .bn-glint {
    animation: none !important;
}
.bn-stage.is-rm .bn-face {
    -webkit-backface-visibility: visible;
    backface-visibility: visible;
}
.bn-stage.is-rm .bn-back {
    transform: none;
    opacity: 0;
    transition: opacity .25s ease;
}
.bn-stage.is-rm .bn-note.is-flipped .bn-back {
    opacity: 1;
}
.bn-stage.is-rm .bn-fx {
    display: none;
}
.bn-stage.is-rm .bn-shadow,
.bn-stage.is-rm .bn-note.is-active .bn-shadow {
    transition: none;
    transform: translateY(10px);
}
.bn-stage.is-rm .bn-note.is-active .bn-face {
    outline: 3px solid #ffd54a;
    outline-offset: 3px;
}

/* On phones the notes are small: the hint gets its own line, and the
 * arrangements that reach past the stage get room so they clear the text. */
@media (max-width: 767px) {
    .bn-stage {
        --w: clamp(120px, 36vw, 230px);
        margin: calc(var(--w) * .1) 0;
    }
    .bn-stage[data-hint-touch] {
        height: calc(var(--w) * var(--stage-h, .95) + 44px);
    }
}
