/*
 * Cultina "Bild + Inhalt" (Media-Overlap) widget.
 * Image beside a content block; the content (optionally a white card) overlaps
 * the image's inner edge by --cmo-overlap (negative value = gap instead).
 * Geometry for the benchmark "Firma xyz" block: image 639 + card 659 − 188 = 1110.
 * Most values are driven by the widget's Style controls; this file holds the
 * structure, the overlap mechanics and the responsive stacking.
 */

/* ── Animation progress model ────────────────────────────────────────────
   ONE progress value --cmo-p (0 = rest, 1 = full effect) feeds every image
   effect AND the card colour. It is a blend of two sources, picked by the
   per-device mode var --cmo-mode (0 = hover, 1 = scroll, emitted responsively
   by the widget's "Auslöser" control):
     --cmo-p = (1-mode)*hover-p  +  mode*scroll-p
   HOVER drives the registered, transitionable --cmo-hover-p (0↔1) smoothly;
   SCROLL has the JS scrubber (assets/js/media-overlap.js) write --cmo-scroll-p
   per frame. We transition the REGISTERED --cmo-hover-p directly (a guaranteed
   transition on a direct value change) rather than --cmo-p, so the scroll path
   carries no transition and never lags behind the scroll. --cmo-p itself stays
   an unregistered, purely-derived pass-through that re-resolves each frame. */
@property --cmo-hover-p {
    syntax: '<number>';
    inherits: false;
    initial-value: 0;
}

.cmo {
    --cmo-overlap: 188px;
    /* animation hub */
    --cmo-mode: 0;            /* 0 = hover, 1 = scroll (per-device by control) */
    --cmo-hover-p: 0;         /* driven to 1 by :hover (registered → smooth) */
    --cmo-scroll-p: 0;        /* written each rAF frame by JS in scroll mode */
    --cmo-p: calc((1 - var(--cmo-mode)) * var(--cmo-hover-p)
                  +      var(--cmo-mode)  * var(--cmo-scroll-p));
    /* card colour endpoints (overridden by the card controls when enabled) */
    --cmo-card-bg: #FFFFFF;
    --cmo-card-hover-bg: #E8F5F9;
    display: flex;
    flex-direction: row;
    align-items: center;
    max-width: 1110px;
    width: 100%;
    margin-inline: auto;
}
.cmo--img-right { flex-direction: row-reverse; }

/* No-hover pointers (touch) cannot trigger the hover path at ANY width — a
   large tablet >1024px otherwise resolves to the desktop "Hover" default and
   the effect (and card colour-switch) would never fire, defeating the whole
   point of scroll mode. Force scroll mode wherever there is no hover capability.
   !important beats Elementor's element-id --cmo-mode emission; getComputedStyle
   then reports 1, so the JS scrubber activates too. Mouse/precise pointers
   (hover: hover) are unaffected and keep the configured per-breakpoint mode. */
@media (hover: none) {
    .cmo { --cmo-mode: 1 !important; }
}

.cmo__media {
    position: relative;
    z-index: 1;
    flex: 0 0 639px;
    width: 639px;
    height: 650px;
    border-radius: 20px;
    overflow: hidden;
}
.cmo__media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ----- image + card effects, unified on --cmo-p (selectable per instance;
   the frame's overflow is hidden, so transforms stay clipped to the rounded
   image). Each rule reduces to the EXACT former rest state at --cmo-p:0 and the
   EXACT former hover state at --cmo-p:1, so hover behaviour is unchanged. The
   same rules are scrubbed by scroll when --cmo-mode resolves to 1. */

/* Promote to a compositor layer ONLY the property the chosen effect animates —
   not unconditionally on every image (a "Kein Effekt" instance gets none). */
.cmo--fx-zoom .cmo__media img,
.cmo--fx-tilt .cmo__media img { will-change: transform; }
.cmo--slide-right .cmo__media img,
.cmo--slide-left  .cmo__media img { will-change: object-position; }
.cmo--fx-grayscale .cmo__media img { will-change: filter; }

/* Smooth the HOVER source: --cmo-hover-p is registered (@property), so this
   transition fires on its direct 0↔1 value change. The scroll source
   (--cmo-scroll-p, set by JS) is never transitioned, so scrubbing tracks the
   scroll exactly with no lag. */
.cmo--anim { transition: --cmo-hover-p var(--cmo-fx-dur, 600ms) cubic-bezier(0.2, 0.7, 0.2, 1); }
.cmo--anim:hover { --cmo-hover-p: 1; }

/* zoom: 1 → 1.08 */
.cmo--fx-zoom .cmo__media img { transform: scale(calc(1 + 0.08 * var(--cmo-p))); }
/* slide: a FULL side-to-side pan of the image, scrubbed by --cmo-p.
   object-fit:cover guarantees the frame is always filled; 0%/100% are the hard
   limits (it cannot slide past the image). Needs a LANDSCAPE source so there is
   width to pan across. right: 0%→100%, left: 100%→0%. */
.cmo--slide-right .cmo__media img { object-position: calc(var(--cmo-p) * 100%) center; }
.cmo--slide-left  .cmo__media img { object-position: calc((1 - var(--cmo-p)) * 100%) center; }
/* grayscale: 1 → 0 (desaturated at rest, full colour at full progress) */
.cmo--fx-grayscale .cmo__media img { filter: grayscale(calc(1 - var(--cmo-p))); }
/* tilt: zoom + slight rotation, scrubbed */
.cmo--fx-tilt .cmo__media img { transform: scale(calc(1 + 0.08 * var(--cmo-p))) rotate(calc(1.5deg * var(--cmo-p))); }

/* Card background interpolates base → hover colour by --cmo-p (a smooth blend;
   colours come from the card controls as --cmo-card-bg / --cmo-card-hover-bg).
   No own transition: it follows --cmo-p, which is smooth in hover mode (via the
   registered --cmo-hover-p) and stepped per frame in scroll mode. */
.cmo--card .cmo__card {
    background-color: color-mix(in srgb,
        var(--cmo-card-bg, #FFFFFF),
        var(--cmo-card-hover-bg, #E8F5F9) calc(var(--cmo-p) * 100%));
}
/* Fallback where color-mix is unsupported: solid base colour (no blend). */
@supports not (background-color: color-mix(in srgb, red, blue 50%)) {
    .cmo--card .cmo__card { background-color: var(--cmo-card-bg, #FFFFFF); }
}

@media (prefers-reduced-motion: reduce) {
    /* Lock to the rest state: no transition, and ignore hover. The JS scrubber
       also bails under reduced-motion, so --cmo-scroll-p stays 0 → --cmo-p 0. */
    .cmo--anim { transition: none; }
    .cmo--anim:hover { --cmo-hover-p: 0; }
    /* A grayscale instance at rest is FULLY desaturated and, with hover + the
       scrubber both disabled here, could never reach colour — that hides real
       content (not just motion). Show it in full colour instead. The geometric
       effects (zoom/slide/tilt) stay at their natural rest framing, which is
       fine for a static view. */
    .cmo--fx-grayscale .cmo__media img { filter: none; }
}

.cmo__card {
    position: relative;
    z-index: 2;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
    /* Optional position nudge from the widget's card width/height/position
       controls (defaults are no-ops). */
    transform: translate(var(--cmo-card-x, 0px), var(--cmo-card-y, 0px));
}

/* Overlap (or gap): pull the content over the image's inner edge. A negative
   --cmo-overlap flips the margin sign and becomes a gap instead. */
.cmo--img-left  .cmo__card { margin-left:  calc(-1 * var(--cmo-overlap, 0px)); }
.cmo--img-right .cmo__card { margin-right: calc(-1 * var(--cmo-overlap, 0px)); }

/* Card surface — only when the card background is enabled. The background
   colour is NOT set here: it comes from the color-mix rule above (single
   source), so a later same-specificity declaration must not override it. */
.cmo--card .cmo__card {
    border-radius: 20px;
    padding: 64px 73px;
    box-shadow: 0 30px 70px rgba(49, 49, 49, 0.12);
}

/* ----- text defaults (all overridable by the Style controls) ------------ */
.cmo__eyebrow {
    font-family: "Ubuntu", "Helvetica Neue", Arial, sans-serif;
    font-weight: 300;
    font-size: 24px;
    line-height: 29px;
    color: #C2006A;
}
.cmo__heading {
    font-family: "Ubuntu", "Helvetica Neue", Arial, sans-serif;
    font-weight: 500;
    font-size: 28px;
    line-height: 36px;
    color: #313131;
    margin: 0;
}
.cmo__body,
.cmo__body p {
    font-family: "Ubuntu", "Helvetica Neue", Arial, sans-serif;
    font-weight: 300;
    font-size: 18px;
    line-height: 28px;
    color: #313131;
}
.cmo__body p { margin: 0 0 1em; }
.cmo__body p:last-child { margin-bottom: 0; }

.cmo__btn {
    display: inline-block;
    align-self: flex-start;
    margin-top: 10px;
    font-family: "Ubuntu", "Helvetica Neue", Arial, sans-serif;
    font-weight: 700;
    font-size: 18px;
    text-transform: uppercase;
    color: #313131;
    border: 1px solid #313131;
    border-radius: 25px;
    padding: 14px 32px;
    text-decoration: none;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.cmo__btn:hover { background-color: #C2006A; border-color: #C2006A; color: #FFFFFF; }

/* ----- responsive: stack image on top, full-width content, no overlap --- */
@media (max-width: 1024px) {
    .cmo.cmo--img-left,
    .cmo.cmo--img-right { flex-direction: column; align-items: stretch; }
    .cmo__media { flex: 0 0 auto; width: 100%; }
    .cmo--img-left  .cmo__card,
    .cmo--img-right .cmo__card { margin: 0; }
    /* "Inhalt oben" (stack_order = content): card above the image when stacked. */
    .cmo--stack-content .cmo__card { order: -1; }
}
