/*
 * Rollpix Spin & Win — base styles, shared by the storefront and the admin
 * preview (hence view/base).
 *
 * Everything is namespaced under .rollpix-saw so it cannot leak into the theme.
 *
 * Colours are NOT baked in here: every one of them reads a custom property that
 * the widget sets from the admin configuration. A template therefore decides
 * *layout* only — which is why there is no "dark" or "neon" template. Dark is
 * just a different set of colours.
 *
 * The fallbacks in each var() are the shipped defaults, so the stylesheet is
 * still correct on its own if the config ever fails to load.
 */

.rollpix-saw {
    --rpx-overlay: rgba(0, 0, 0, .55);
    --rpx-modal-bg: #ffffff;
    --rpx-text: #1f1f1f;
    --rpx-muted: rgba(31, 31, 31, .75);
    --rpx-border: #cccccc;
    --rpx-button-bg: #1f1f1f;
    --rpx-button-text: #ffffff;
    --rpx-pointer: #1f1f1f;
    --rpx-icon-bg: #1f1f1f;
    --rpx-icon-text: #ffffff;
    --rpx-radius: 14px;

    /* Size is configuration too (Apariencia → Tamaño). Layouts that are sized
       by the viewport — side, sheet — deliberately ignore these. */
    --rpx-modal-w: 440px;
    --rpx-wheel-w: 320px;

    /* How far the floating icon sits from the edges. Configurable because a
       fixed inset is what lands it on top of the site's own chat button. */
    --rpx-icon-x: 18px;
    --rpx-icon-y: 18px;
}

.rollpix-saw__overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--rpx-overlay);
    padding: 16px;
}

.rollpix-saw__overlay.is-open {
    display: flex;
}

.rollpix-saw__modal {
    position: relative;
    width: 100%;
    max-width: var(--rpx-modal-w);
    max-height: 92vh;
    overflow-y: auto;
    padding: 28px 24px 24px;
    border-radius: var(--rpx-radius);
    background: var(--rpx-modal-bg);
    color: var(--rpx-text);
    text-align: center;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .35);
}

.rollpix-saw__close {
    position: absolute;
    top: 8px;
    right: 12px;
    border: 0;
    background: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: inherit;
}

.rollpix-saw__title {
    margin: 0 0 6px;
    font-size: 22px;
    color: inherit;
}

.rollpix-saw__description {
    margin: 0 0 14px;
    font-size: 14px;
    color: var(--rpx-muted);
}

.rollpix-saw__wheel {
    position: relative;
    display: inline-block;
    margin-bottom: 16px;
}

/* The display size lives here, not in the canvas attributes: the JS sizes the
   backing store to whatever CSS grants, so the wheel stays sharp at any scale. */
.rollpix-saw__canvas {
    display: block;
    width: var(--rpx-wheel-w);
    max-width: 100%;
    aspect-ratio: 1 / 1;
    height: auto;
    transform: rotate(0deg);
}

/* Pointer sits at 12 o'clock — the template declares that angle as
   `pointer_angle: -90` and spinTo() lands the winning slice right here. */
.rollpix-saw__pointer {
    position: absolute;
    top: -6px;
    left: 50%;
    z-index: 2;
    width: 0;
    height: 0;
    transform: translateX(-50%);
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 20px solid var(--rpx-pointer);
}

.rollpix-saw__form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rollpix-saw__input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--rpx-border);
    border-radius: 8px;
    background: transparent;
    color: var(--rpx-text);
    font-size: 15px;
}

.rollpix-saw__consent {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    text-align: left;
    color: var(--rpx-muted);
}

.rollpix-saw__button {
    padding: 12px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--rpx-button-bg);
    color: var(--rpx-button-text);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.rollpix-saw__button[disabled] {
    opacity: .55;
    cursor: default;
}

.rollpix-saw__status {
    margin: 14px 0 0;
    font-size: 15px;
}

.rollpix-saw__coupon {
    display: none;
    margin-top: 10px;
    padding: 12px;
    border: 2px dashed var(--rpx-border);
    border-radius: 8px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    user-select: all;
}

.rollpix-saw__coupon.is-visible {
    display: block;
}

/*
 * Hardened against the host theme: Luma themes style `button` heavily, and
 * inherited padding, line-height or font would knock the circle out of shape.
 * Everything that matters is reset here rather than assumed.
 */
.rollpix-saw__icon {
    position: fixed;
    z-index: 9998;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 52px;
    height: 52px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--rpx-icon-bg);
    color: var(--rpx-icon-text);
    font: inherit;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
    -webkit-appearance: none;
    appearance: none;
    transition: box-shadow .15s ease, filter .15s ease;
}

/*
 * No hover transform on purpose: the middle positions already use
 * translateY(-50%) to centre themselves, and a scale() here would overwrite it
 * and drop the icon half a height down the page.
 */
.rollpix-saw__icon:hover,
.rollpix-saw__icon:focus-visible {
    box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
    filter: brightness(1.08);
}

.rollpix-saw__icon:focus-visible {
    outline: 2px solid var(--rpx-icon-text);
    outline-offset: 2px;
}

/*
 * The glyph is a little wheel drawn in CSS, not an emoji: emoji render
 * differently on every platform, sit off-centre inside a circle, and ignore
 * the configured icon colour.
 */
.rollpix-saw__icon::before {
    content: '';
    width: 26px;
    height: 26px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px currentColor;
    background: conic-gradient(
        currentColor 0 45deg,
        transparent 45deg 90deg,
        currentColor 90deg 135deg,
        transparent 135deg 180deg,
        currentColor 180deg 225deg,
        transparent 225deg 270deg,
        currentColor 270deg 315deg,
        transparent 315deg 360deg
    );
}

/* Hub, punched out in the icon's own background colour. */
.rollpix-saw__icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    margin: -4px 0 0 -4px;
    border-radius: 50%;
    background: var(--rpx-icon-bg);
}

.rollpix-saw__icon--bottom-right {
    right: var(--rpx-icon-x);
    bottom: var(--rpx-icon-y);
}

.rollpix-saw__icon--bottom-left {
    left: var(--rpx-icon-x);
    bottom: var(--rpx-icon-y);
}

.rollpix-saw__icon--top-right {
    right: var(--rpx-icon-x);
    top: var(--rpx-icon-y);
}

.rollpix-saw__icon--top-left {
    left: var(--rpx-icon-x);
    top: var(--rpx-icon-y);
}

/* The middle positions are centred vertically, so only the horizontal
   distance applies to them. */
.rollpix-saw__icon--middle-right {
    right: var(--rpx-icon-x);
    top: 50%;
    transform: translateY(-50%);
}

.rollpix-saw__icon--middle-left {
    left: var(--rpx-icon-x);
    top: 50%;
    transform: translateY(-50%);
}

/* ── Template: split (dos columnas, modal centrado) ────────── */

/*
 * Wheel on the left, form on the right, both fully visible. Unlike `side` the
 * modal stays centred and the wheel is not clipped, which suits a wide desktop
 * without taking over the viewport.
 *
 * The row numbers are the flow children of the modal: title, description, form,
 * status, coupon. The wheel spans all of them in the first column.
 */

.rollpix-saw--split .rollpix-saw__modal {
    display: grid;
    grid-template-columns: auto minmax(220px, 1fr);
    column-gap: 26px;
    align-items: center;
    max-width: calc(var(--rpx-modal-w) + var(--rpx-wheel-w));
    text-align: left;
}

.rollpix-saw--split .rollpix-saw__wheel {
    grid-area: 1 / 1 / 6 / 2;
    align-self: center;
    margin-bottom: 0;
}

.rollpix-saw--split .rollpix-saw__title { grid-area: 1 / 2; align-self: end; }
.rollpix-saw--split .rollpix-saw__description { grid-area: 2 / 2; }
.rollpix-saw--split .rollpix-saw__form { grid-area: 3 / 2; }
.rollpix-saw--split .rollpix-saw__status { grid-area: 4 / 2; }
.rollpix-saw--split .rollpix-saw__coupon { grid-area: 5 / 2; text-align: center; }

@media (max-width: 720px) {
    .rollpix-saw--split .rollpix-saw__modal {
        display: block;
        max-width: var(--rpx-modal-w);
        text-align: center;
    }

    .rollpix-saw--split .rollpix-saw__wheel {
        margin-bottom: 16px;
    }
}

/* ── Template: sheet (barra inferior) ──────────────────────── */

/*
 * A bar along the bottom, but a bounded and centred one rather than edge to
 * edge: stretched across a 1920px screen the wheel drifts to the far left and
 * the form spreads over a thousand-odd pixels, which reads as a mistake. The
 * bar is capped, floats just above the bottom edge, and the wheel-plus-form
 * pair is centred inside it, so the composition holds at any screen width.
 *
 * Sized by the viewport rather than by the Tamaño setting, like the side one.
 */

.rollpix-saw--sheet .rollpix-saw__overlay {
    align-items: flex-end;
    justify-content: center;
    padding: 0 24px 24px;
}

.rollpix-saw--sheet .rollpix-saw__modal {
    display: grid;
    /* The form column is capped as well: centring a pair whose second half
       keeps growing only moves the wheel further from the middle. */
    grid-template-columns: auto minmax(220px, 420px);
    justify-content: center;
    column-gap: 28px;
    align-items: center;
    width: 100%;
    max-width: min(880px, 100%);
    max-height: 60vh;
    padding: 16px 28px;
    border-radius: var(--rpx-radius);
    text-align: left;
}

.rollpix-saw--sheet .rollpix-saw__canvas {
    width: 160px;
}

.rollpix-saw--sheet .rollpix-saw__wheel {
    grid-area: 1 / 1 / 6 / 2;
    align-self: center;
    margin-bottom: 0;
}

.rollpix-saw--sheet .rollpix-saw__title { grid-area: 1 / 2; align-self: end; font-size: 19px; }
.rollpix-saw--sheet .rollpix-saw__description { grid-area: 2 / 2; margin-bottom: 8px; font-size: 13px; }
.rollpix-saw--sheet .rollpix-saw__form { grid-area: 3 / 2; }
.rollpix-saw--sheet .rollpix-saw__status { grid-area: 4 / 2; }
.rollpix-saw--sheet .rollpix-saw__coupon { grid-area: 5 / 2; text-align: center; }

@media (max-width: 720px) {
    .rollpix-saw--sheet .rollpix-saw__overlay {
        padding: 0 12px 12px;
    }

    .rollpix-saw--sheet .rollpix-saw__modal {
        display: block;
        max-height: 88vh;
        overflow-y: auto;
        padding: 20px;
        text-align: center;
    }

    .rollpix-saw--sheet .rollpix-saw__wheel {
        margin: 0 auto 14px;
    }

    .rollpix-saw--sheet .rollpix-saw__canvas {
        width: 200px;
    }
}

/* ── Template: corner (tarjeta anclada) ────────────────────── */

/*
 * A small card docked to the bottom-right, like a chat widget. The one layout
 * that does NOT block the page: the backdrop is transparent and lets clicks
 * through, so the visitor can keep browsing with the wheel sitting there.
 * The overlay colour setting therefore has no effect on this layout.
 */

.rollpix-saw--corner .rollpix-saw__overlay {
    align-items: flex-end;
    justify-content: flex-end;
    padding: 18px;
    background: transparent;
    pointer-events: none;
}

.rollpix-saw--corner .rollpix-saw__modal {
    pointer-events: auto;
    width: auto;
    max-width: min(var(--rpx-modal-w), 380px);
    max-height: 86vh;
    padding: 22px 20px 20px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, .3);
}

.rollpix-saw--corner .rollpix-saw__canvas {
    width: min(var(--rpx-wheel-w), 230px);
}

.rollpix-saw--corner .rollpix-saw__title {
    font-size: 19px;
}

@media (max-width: 720px) {
    .rollpix-saw--corner .rollpix-saw__overlay {
        align-items: center;
        justify-content: center;
    }
}

/* ── Template: side (media rueda a pantalla completa) ──────── */

/*
 * A panel flush against the left edge of the viewport, full height, with an
 * oversized wheel whose centre sits off-screen so the visible half runs from
 * top to bottom. The pointer is on the inner edge at 3 o'clock, which is why
 * this template declares `pointer_angle: 0` in di.xml — the spin animation
 * reads that angle, so moving the pointer in CSS alone would stop the wheel on
 * the wrong slice.
 *
 * The three sizes go through custom properties so the admin preview can render
 * the same layout inside a box instead of a viewport.
 */

.rollpix-saw--side {
    --rpx-panel-h: 100vh;
    --rpx-wheel-size: min(104vh, 860px);
    --rpx-wheel-visible: min(52vh, 430px);
}

.rollpix-saw--side .rollpix-saw__overlay {
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
}

.rollpix-saw--side .rollpix-saw__modal {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: min(960px, 100vw);
    max-width: none;
    height: var(--rpx-panel-h);
    max-height: var(--rpx-panel-h);
    margin: 0;
    padding: 40px 40px 40px 0;
    border-radius: 0 var(--rpx-radius) var(--rpx-radius) 0;
    overflow: hidden;
}

/* Out of the flex flow: the wheel is decoration positioned against the edge,
   and the form column centres itself without having to account for it. */
.rollpix-saw--side .rollpix-saw__wheel {
    position: absolute;
    top: 50%;
    left: 0;
    margin: 0;
    transform: translate(-52%, -50%);
}

.rollpix-saw--side .rollpix-saw__canvas {
    width: var(--rpx-wheel-size);
    max-width: none;
}

.rollpix-saw--side .rollpix-saw__pointer {
    top: 50%;
    right: -2px;
    left: auto;
    transform: translateY(-50%);
    border-top: 14px solid transparent;
    border-bottom: 14px solid transparent;
    border-right: 22px solid var(--rpx-pointer);
    border-left: 0;
}

/* Clear the visible half of the wheel. */
.rollpix-saw--side .rollpix-saw__title,
.rollpix-saw--side .rollpix-saw__description,
.rollpix-saw--side .rollpix-saw__form,
.rollpix-saw--side .rollpix-saw__status,
.rollpix-saw--side .rollpix-saw__coupon {
    position: relative;
    z-index: 1;
    margin-left: calc(var(--rpx-wheel-visible) + 44px);
    max-width: 400px;
    text-align: left;
}

.rollpix-saw--side .rollpix-saw__title {
    font-size: 28px;
    margin-bottom: 8px;
}

.rollpix-saw--side .rollpix-saw__coupon {
    text-align: center;
}

/*
 * Narrow viewports keep the very same composition — half wheel against the
 * edge, form beside it — instead of falling back to another layout. Two things
 * change.
 *
 * The panel takes half the screen rather than all of it: a phone-sized viewport
 * covered edge to edge reads as taking over the site, and the popup is meant to
 * be an offer, not a wall. It centres vertically and stays glued to the left.
 *
 * And the wheel takes its diameter from whichever of height and width is
 * smaller, showing a narrower slice of itself than on desktop. On a wide screen
 * the diameter follows the viewport HEIGHT, which is what makes the visible half
 * run top to bottom; in portrait that same rule yields an ~880px wheel whose
 * visible half eats the entire width and leaves nothing for the form.
 *
 * `--rpx-wheel-visible` has to stay exactly half of `--rpx-wheel-size`: it is
 * what the form column's offset is measured against, and if the two drift the
 * copy lands on top of the wheel.
 *
 * The pointer stays at 3 o'clock throughout, so `pointer_angle: 0` holds and
 * the wheel cannot stop on a different slice than the one the server drew.
 */
@media (max-width: 900px) {
    .rollpix-saw--side {
        /* Half the screen, with a floor so a landscape phone — which has very
           little height to give — still fits the form. */
        --rpx-panel-h: min(100vh, max(50vh, 340px));
        --rpx-wheel-size: min(52vh, 64vw);
        --rpx-wheel-visible: min(26vh, 32vw);
    }

    /* A half-height panel centres vertically instead of stretching, and stays
       flush against the left edge. */
    .rollpix-saw--side .rollpix-saw__overlay {
        align-items: center;
        justify-content: flex-start;
    }

    .rollpix-saw--side .rollpix-saw__modal {
        width: 100vw;
        padding: 20px 16px 20px 0;
        border-radius: 0 var(--rpx-radius) var(--rpx-radius) 0;
    }

    .rollpix-saw--side .rollpix-saw__title,
    .rollpix-saw--side .rollpix-saw__description,
    .rollpix-saw--side .rollpix-saw__form,
    .rollpix-saw--side .rollpix-saw__status,
    .rollpix-saw--side .rollpix-saw__coupon {
        margin-left: calc(var(--rpx-wheel-visible) + 16px);
        max-width: none;
    }

    .rollpix-saw--side .rollpix-saw__title {
        font-size: 20px;
    }

    .rollpix-saw--side .rollpix-saw__description {
        font-size: 13px;
    }

    .rollpix-saw--side .rollpix-saw__coupon {
        font-size: 17px;
        letter-spacing: 1px;
    }
}
