/**
 * Aurora Hero — reusable media hero for core/video, core/image, core/cover.
 *
 * Activation (editor):
 *   - Block style “Aurora Hero” → class `is-style-aurora-hero`
 *   - and/or custom class `aurora-hero`
 *   - optional flush: `aurora-hero--flush` (home + leading block only)
 *
 * Width is never forced here — Gutenberg alignment owns it:
 *   (none) contentSize · alignwide → wideSize · alignfull → full
 *
 * Soft bottom curve uses an SVG mask sized to the media box (block width),
 * not the viewport. Figcaptions / cover inner content stay outside the mask.
 *
 * Debug (flush gap): if space remains above a leading flush hero, inspect the
 * wrapper around it and report that class — do not add global negative margins.
 */

/* -------------------------------------------------------------------------- */
/* Tokens (Losvika / child themes override without rewriting rules)            */
/* -------------------------------------------------------------------------- */

:root,
.losvika-theme,
.editor-styles-wrapper {
    --aurora-hero-height: clamp(18rem, 48vw, 34rem);
    --aurora-hero-height-mobile: clamp(14rem, 72vw, 24rem);
    --aurora-hero-curve-depth: 14%;
    --aurora-hero-curve-depth-mobile: 8%;
    --aurora-hero-surface: var(--aurora-color-bg, var(--losvika-bg, #f1f3f2));
    --aurora-hero-object-position: center 35%;
    --aurora-hero-object-position-mobile: center 30%;
    --aurora-hero-radius-top: 0;
    /* Soft bottom mask: path dips downward at center (Q cy = 100). */
    --aurora-hero-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath fill='black' d='M0 0H100V86Q50 100 0 86Z'/%3E%3C/svg%3E");
    --aurora-hero-mask-mobile: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath fill='black' d='M0 0H100V92Q50 100 0 92Z'/%3E%3C/svg%3E");
}

/* -------------------------------------------------------------------------- */
/* Shared hero shell — no full-bleed, no negative side margins                 */
/* -------------------------------------------------------------------------- */

.aurora-hero,
.is-style-aurora-hero,
.losvika-home-hero {
    background-color: var(--aurora-hero-surface);
    border-radius: var(--aurora-hero-radius-top);
    box-sizing: border-box;
    overflow-x: clip;
    position: relative;
}

/* Cover needs a definite hero height; media fills the frame. */
.wp-block-cover.aurora-hero,
.wp-block-cover.is-style-aurora-hero,
.wp-block-cover.losvika-home-hero {
    min-height: var(--aurora-hero-height);
}

.wp-block-cover.aurora-hero .wp-block-cover__inner-container,
.wp-block-cover.is-style-aurora-hero .wp-block-cover__inner-container,
.wp-block-cover.losvika-home-hero .wp-block-cover__inner-container {
    position: relative;
    z-index: 2;
}

/* -------------------------------------------------------------------------- */
/* Media layer — curve follows the block’s own width                           */
/* -------------------------------------------------------------------------- */

.aurora-hero > video,
.is-style-aurora-hero > video,
.losvika-home-hero > video,
.aurora-hero .wp-block-video > video,
.is-style-aurora-hero .wp-block-video > video,
.losvika-home-hero .wp-block-video > video,
.aurora-hero .aurora-hero__inner > .wp-block-video > video,
.wp-block-aurora-hero .aurora-hero__inner > .wp-block-video > video,
.aurora-hero > img,
.is-style-aurora-hero > img,
.losvika-home-hero > img,
.aurora-hero .wp-block-image > img,
.is-style-aurora-hero .wp-block-image > img,
.losvika-home-hero .wp-block-image > img,
.aurora-hero .aurora-hero__inner > .wp-block-image > img,
.wp-block-aurora-hero .aurora-hero__inner > .wp-block-image > img,
.aurora-hero > a > img,
.is-style-aurora-hero > a > img,
.losvika-home-hero > a > img,
.aurora-hero .wp-block-cover__image-background,
.is-style-aurora-hero .wp-block-cover__image-background,
.losvika-home-hero .wp-block-cover__image-background,
.aurora-hero .wp-block-cover__video-background,
.is-style-aurora-hero .wp-block-cover__video-background,
.losvika-home-hero .wp-block-cover__video-background,
.aurora-hero video.wp-block-cover__video-background,
.is-style-aurora-hero video.wp-block-cover__video-background,
.losvika-home-hero video.wp-block-cover__video-background {
    -webkit-mask-image: var(--aurora-hero-mask);
    -webkit-mask-mode: alpha;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: 100% 100%;
    border-radius: var(--aurora-hero-radius-top);
    display: block;
    height: var(--aurora-hero-height);
    mask-image: var(--aurora-hero-mask);
    mask-mode: alpha;
    mask-repeat: no-repeat;
    mask-size: 100% 100%;
    max-width: none;
    object-fit: cover;
    object-position: var(--aurora-hero-object-position);
    width: 100%;
}

/* Cover backgrounds are absolutely positioned — keep fill, inherit height. */
.wp-block-cover.aurora-hero .wp-block-cover__image-background,
.wp-block-cover.is-style-aurora-hero .wp-block-cover__image-background,
.wp-block-cover.losvika-home-hero .wp-block-cover__image-background,
.wp-block-cover.aurora-hero .wp-block-cover__video-background,
.wp-block-cover.is-style-aurora-hero .wp-block-cover__video-background,
.wp-block-cover.losvika-home-hero .wp-block-cover__video-background,
.wp-block-cover.aurora-hero video.wp-block-cover__video-background,
.wp-block-cover.is-style-aurora-hero video.wp-block-cover__video-background,
.wp-block-cover.losvika-home-hero video.wp-block-cover__video-background {
    height: 100%;
    inset: 0;
    width: 100%;
}

/* Captions stay below the masked media (never under the curve overlay). */
.aurora-hero > figcaption,
.is-style-aurora-hero > figcaption,
.losvika-home-hero > figcaption {
    position: relative;
    z-index: 1;
}

/* -------------------------------------------------------------------------- */
/* Flush — top spacing only, leading block on the front page                   */
/* -------------------------------------------------------------------------- */

/*
 * Selectors:
 *   body.home … .wp-block-post-content > .{hero}.aurora-hero--flush:first-child
 *   body.home … first .wp-block-group > .{hero}.aurora-hero--flush:first-child
 *   body.home … .losvika-home-hero as legacy alias for flush-when-leading
 *   main.losvika-site-main:has(…) → clear TOP padding + margin
 *
 * Important: FSE applies block-gap as margin-block-start on `.wp-site-blocks > *`
 * (header is :first-child, so main is NOT). Flush must zero that margin — padding
 * alone is not enough. Do not use site Custom CSS for this.
 */

body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .wp-block-aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .is-style-aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .losvika-home-hero:first-child
),
body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .wp-block-group:first-child > .wp-block-aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .wp-block-group:first-child > .aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .wp-block-group:first-child > .is-style-aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-site-blocks > main.losvika-site-main:has(
    > .wp-block-post-content > .wp-block-group:first-child > .losvika-home-hero:first-child
) {
    margin-block-start: 0;
    margin-top: 0;
    padding-block-start: 0;
    padding-top: 0;
}

body.home.losvika-theme .wp-block-post-content > .wp-block-aurora-hero.aurora-hero--flush:first-child,
body.home.losvika-theme .wp-block-post-content > .aurora-hero.aurora-hero--flush:first-child,
body.home.losvika-theme .wp-block-post-content > .is-style-aurora-hero.aurora-hero--flush:first-child,
body.home.losvika-theme .wp-block-post-content > .losvika-home-hero:first-child,
body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child:has(
    > .wp-block-aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child:has(
    > .aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child:has(
    > .is-style-aurora-hero.aurora-hero--flush:first-child
),
body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child:has(
    > .losvika-home-hero:first-child
) {
    margin-top: 0;
    padding-top: 0;
}

body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child > .wp-block-aurora-hero.aurora-hero--flush:first-child,
body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child > .aurora-hero.aurora-hero--flush:first-child,
body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child > .is-style-aurora-hero.aurora-hero--flush:first-child,
body.home.losvika-theme .wp-block-post-content > .wp-block-group:first-child > .losvika-home-hero:first-child {
    margin-top: 0;
}

/* -------------------------------------------------------------------------- */
/* Mobile                                                                      */
/* -------------------------------------------------------------------------- */

@media (max-width: 781px) {
    :root,
    .losvika-theme,
    .editor-styles-wrapper {
        --aurora-hero-height: var(--aurora-hero-height-mobile);
        --aurora-hero-mask: var(--aurora-hero-mask-mobile);
        --aurora-hero-object-position: var(--aurora-hero-object-position-mobile);
    }

    .wp-block-cover.aurora-hero,
    .wp-block-cover.is-style-aurora-hero,
    .wp-block-cover.losvika-home-hero {
        min-height: var(--aurora-hero-height-mobile);
    }
}

/* -------------------------------------------------------------------------- */
/* Reduced motion — JS pauses autoplay; muted / playsinline / tracks untouched */
/* -------------------------------------------------------------------------- */

/* -------------------------------------------------------------------------- */
/* Editor — aurora/hero flush mirrors frontend (canvas, not toolbar)           */
/*                                                                            */
/* Wrapper: section.wp-block-aurora-hero.aurora-hero-editor.aurora-hero       */
/*          (+ .aurora-hero--flush from Additional CSS classes)               */
/* Nested media lives in .aurora-hero__inner (InnerBlocks), not on the root.  */
/* -------------------------------------------------------------------------- */

.editor-styles-wrapper .aurora-hero,
.editor-styles-wrapper .is-style-aurora-hero,
.editor-styles-wrapper .losvika-home-hero,
.editor-styles-wrapper .wp-block-aurora-hero,
.block-editor-block-list__layout .aurora-hero,
.block-editor-block-list__layout .is-style-aurora-hero,
.block-editor-block-list__layout .losvika-home-hero,
.block-editor-block-list__layout .wp-block-aurora-hero {
    background-color: var(--aurora-hero-surface);
}

.editor-styles-wrapper .is-root-container > .wp-block-aurora-hero.aurora-hero--flush:first-child,
.editor-styles-wrapper .block-editor-block-list__layout > .wp-block-aurora-hero.aurora-hero--flush:first-child,
.editor-styles-wrapper .wp-block-post-content > .wp-block-aurora-hero.aurora-hero--flush:first-child,
.editor-styles-wrapper .wp-block-post-content > .wp-block-group:first-child > .wp-block-aurora-hero.aurora-hero--flush:first-child,
.block-editor-block-list__layout.is-root-container > .wp-block-aurora-hero.aurora-hero--flush:first-child {
    margin-block-start: 0;
    margin-top: 0;
    padding-block-start: 0;
    padding-top: 0;
}

.editor-styles-wrapper:has(> .is-root-container > .wp-block-aurora-hero.aurora-hero--flush:first-child),
.editor-styles-wrapper:has(> .block-editor-block-list__layout > .wp-block-aurora-hero.aurora-hero--flush:first-child),
.editor-styles-wrapper .is-root-container:has(> .wp-block-aurora-hero.aurora-hero--flush:first-child),
.editor-styles-wrapper .wp-block-post-content:has(> .wp-block-aurora-hero.aurora-hero--flush:first-child),
.editor-styles-wrapper .wp-block-post-content:has(> .wp-block-group:first-child > .wp-block-aurora-hero.aurora-hero--flush:first-child) {
    padding-block-start: 0;
    padding-top: 0;
}

.editor-styles-wrapper .is-root-container > .wp-block-group:first-child:has(> .wp-block-aurora-hero.aurora-hero--flush:first-child),
.editor-styles-wrapper .wp-block-post-content > .wp-block-group:first-child:has(> .wp-block-aurora-hero.aurora-hero--flush:first-child) {
    margin-block-start: 0;
    margin-top: 0;
    padding-block-start: 0;
    padding-top: 0;
}

/* Reachable selection edge — not page padding. */
.editor-styles-wrapper .wp-block-aurora-hero.aurora-hero--flush.is-selected,
.editor-styles-wrapper .wp-block-aurora-hero.aurora-hero--flush.has-child-selected {
    outline: 2px solid var(--wp-admin-theme-color, #007cba);
    outline-offset: -2px;
}
