.mdmt {
    container-type: inline-size;
    background: var(--bg);
    color: var(--ink);
    padding: clamp(12px, 2vw, 26px);
    overflow: hidden;
}
.mdmt * { box-sizing: border-box; }
.mdmt-header { text-align: center; margin: 0 auto clamp(16px, 3vw, 40px); }
.mdmt .mdmt-logo { display: block; width: clamp(96px, 15cqw, 175px); height: auto; margin: 0 auto 12px; }
.mdmt-title-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: clamp(6px, 1.6cqw, 22px);
    align-items: center;
}
.mdmt-title-row h1 {
    max-width: 75cqw;
    margin: 0;
    font: 800 var(--title-size)/1.14 var(--title-font), system-ui, sans-serif;
    color: inherit;
    overflow-wrap: anywhere;
}
.mdmt-title-row h1::after {
 content: ""; display:block; width:var(--underline-width,43%); height:calc(var(--underline-height,4px) * 3); margin:var(--underline-gap,12px) auto 0; background:var(--underline-color,#a5d8ed); mask:url("underline.svg") center / 100% 100% no-repeat; -webkit-mask:url("underline.svg") center / 100% 100% no-repeat;
}
@container (min-width: 701px) and (max-width: 1000px) { .mdmt-title-row h1 {font-size:var(--title-tablet,44px);} }
.mdmt-wave {
    width: 100%;
    height: clamp(18px, 4.8cqw, 56px);
    background: url("ondas-pastel.svg") center / 100% 100% no-repeat;
}
.mdmt-wave:last-child { transform: scaleX(-1); }
.mdmt-gallery {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(6px, .85cqw, 12px);
}
.mdmt-gallery picture {
    display: block;
    position: relative;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1.3;
    border-radius: clamp(9px, 1.4cqw, 22px);
}
.mdmt-gallery img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}
.mdmt-video { max-width: 850px; margin: clamp(18px, 3vw, 40px) auto 0; }
.mdmt-video iframe { display: block; width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 16px; }
@container (min-width: 701px) {
    .mdmt-gallery-mosaic {
        grid-template-columns: minmax(0, 1.03fr) minmax(0, 1.12fr) minmax(0, .98fr) minmax(0, .78fr);
        grid-template-rows: repeat(2, clamp(150px, 18cqw, 300px));
    }
    .mdmt-gallery-mosaic picture:nth-child(-n+6) { aspect-ratio: auto; }
    .mdmt-gallery-mosaic picture:nth-child(1) { grid-area: 1 / 1; }
    .mdmt-gallery-mosaic picture:nth-child(2) { grid-area: 2 / 1; }
    .mdmt-gallery-mosaic picture:nth-child(3) { grid-area: 1 / 2 / span 2; }
    .mdmt-gallery-mosaic picture:nth-child(4) { grid-area: 1 / 3; }
    .mdmt-gallery-mosaic picture:nth-child(5) { grid-area: 2 / 3; }
    .mdmt-gallery-mosaic picture:nth-child(6) { grid-area: 1 / 4 / span 2; }
    .mdmt-gallery-mosaic picture:nth-child(7) { grid-column: 1 / -1; aspect-ratio: 3; }
}
@container (max-width: 700px) {
    .mdmt-title-row h1 { font-size: var(--title-mobile); }
    .mdmt-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mdmt-gallery picture:nth-child(3n),
    .mdmt-gallery picture:last-child:nth-child(3n+1) {
        grid-column: 1 / -1;
        aspect-ratio: 1.8;
    }
}
.mdmt-admin { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.mdmt-admin input, .mdmt-admin textarea { max-width: 100%; width: 100%; }
#mdmt-preview { margin: auto; max-width: 100%; }
#mdmt-preview.mdmt-narrow { max-width: 390px; }

.mdmt-gallery img {
    object-position: var(--frame-x, 50%) var(--frame-y, 50%);
}
@container (max-width: 700px) {
    .mdmt-gallery img {
        object-position: var(--frame-mx, 50%) var(--frame-my, 50%);
    }
}
.mdmt-framing { border: 1px solid #c3c4c7; padding: 8px 14px 14px; margin-bottom: 14px; }
.mdmt-framing input[type="range"] { width: min(115px, 100%); vertical-align: middle; }
.mdmt-framing label:not(:first-of-type) { margin-inline-start: 8px; }
#mdmt-preview picture[data-mdmt-photo] { cursor: pointer; }
#mdmt-preview picture.mdmt-selected { outline: 3px solid #2271b1; outline-offset: -3px; z-index: 1; }

.mdmt-gallery picture {
    background: var(--bg, #fff);
    --photo-zoom: var(--frame-z, 100%);
    --photo-x: var(--frame-x, 50%);
    --photo-y: var(--frame-y, 50%);
}
.mdmt .mdmt-gallery picture img {
    inset: auto;
    left: var(--photo-x);
    top: var(--photo-y);
    width: var(--photo-zoom);
    height: var(--photo-zoom);
    max-width: none;
    max-height: none;
    object-position: var(--photo-x) var(--photo-y);
    transform: translate(calc(0% - var(--photo-x)), calc(0% - var(--photo-y)));
}
@container (max-width: 700px) {
    .mdmt-gallery picture {
        --photo-zoom: var(--frame-mz, 100%);
        --photo-x: var(--frame-mx, 50%);
        --photo-y: var(--frame-my, 50%);
    }
}
.mdmt-font-samples {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 8px;
}
.mdmt-font-sample.button { padding: 6px; white-space: normal; line-height: 1.35; }
.mdmt-font-sample span, .mdmt-font-sample strong { display: block; overflow-wrap: anywhere; }
.mdmt-font-sample strong { font-size: 21px; }
.mdmt-font-sample[aria-pressed="true"] { outline: 2px solid #2271b1; outline-offset: -2px; }

.mdmt .mdmt-lower {
    margin-top: clamp(6px, .85cqw, 12px);
    grid-template-columns: repeat(var(--lower-count), minmax(0, 1fr));
}
.mdmt .mdmt-lower picture { grid-column: auto; }
.mdmt .mdmt-lower-wide picture { aspect-ratio: 3; }
.mdmt .mdmt-lower-pair picture { aspect-ratio: 4 / 3; }
.mdmt .mdmt-lower-four picture { aspect-ratio: 4 / 5; }
@container (max-width: 700px) {
    .mdmt .mdmt-lower-four { grid-template-columns: repeat(min(2, var(--lower-count)), minmax(0, 1fr)); }
    .mdmt .mdmt-lower-wide picture { aspect-ratio: 1.8; }
}

/* Match the viewport breakpoint used by the mobile picture source. */
@media (max-width: 700px) {
    .mdmt .mdmt-gallery picture.mdmt-mobile-duplicate { display: none; }
    .mdmt .mdmt-gallery:not(:has(picture:not(.mdmt-mobile-duplicate))) { display: none; }
}

@media (max-width: 700px) {
    .mdmt .mdmt-gallery:not(.mdmt-lower) picture:nth-child(n) { grid-column: auto; aspect-ratio: 4 / 3; }
    .mdmt .mdmt-gallery:not(.mdmt-lower) picture:nth-child(3n of :not(.mdmt-mobile-duplicate)),
    .mdmt .mdmt-gallery:not(.mdmt-lower) picture:nth-last-child(1 of :not(.mdmt-mobile-duplicate)):nth-child(3n+1 of :not(.mdmt-mobile-duplicate)) { grid-column: 1 / -1; aspect-ratio: 1.8; }
}

/* Compact justified rows, isolated from legacy grid rules. */
.mdmt .mdmt-gallery.mdmt-auto-gallery,.mdm-page .mdm-gallery.mdm-auto-gallery{display:flex!important;flex-wrap:wrap!important;gap:6px!important;align-items:flex-start!important;justify-content:flex-start!important; height:auto!important;}
.mdmt .mdmt-gallery.mdmt-auto-gallery picture:nth-child(n),.mdm-page .mdm-gallery.mdm-auto-gallery>.mdm-card:nth-child(n){box-sizing:border-box!important;flex:0 0 var(--compact-w,calc(50% - 3px))!important;width:var(--compact-w,calc(50% - 3px))!important;height:var(--compact-h,auto)!important;min-width:0!important;min-height:0!important;max-width:100%!important;max-height:none!important;aspect-ratio:1.3;position:relative!important;overflow:hidden!important;border-radius:12px!important;margin:0!important;padding:0!important;}
.mdmt .mdmt-gallery.mdmt-auto-gallery picture img,.mdm-page .mdm-gallery.mdm-auto-gallery .mdm-photo img{position:absolute!important;inset:0!important;width:100%!important;height:100%!important;max-width:none!important;max-height:none!important;transform:none!important;object-fit:cover!important;object-position:center!important;aspect-ratio:auto!important;margin:0!important;}
.mdm-page .mdm-gallery.mdm-auto-gallery .mdm-photo{position:absolute!important;inset:0!important;margin:0!important;width:100%!important;height:100%!important;padding:0!important;aspect-ratio:auto!important;}
.mdm-page .mdm-auto-gallery .mdm-card-curve,.mdm-page .mdm-auto-gallery .mdm-photo-plinth{display:none!important;}

/* Theme galleries: intrinsic height, no reserved grid tracks or flex growth.
   Scope Elementor overrides to wrappers containing the thematic shortcode. */
.mdmt,.mdmt .mdmt-gallery,.mdm-auto-page:not(.mdm-home) .mdm-gallery-section,.mdm-auto-page:not(.mdm-home) .mdm-auto-gallery {
    height:auto!important; min-height:0!important; max-height:none!important;
    flex-grow:0!important; align-content:start!important;
}
.mdmt .mdmt-auto-gallery,.mdm-auto-page:not(.mdm-home) .mdm-auto-gallery {
    grid-template-rows:none!important; grid-auto-rows:auto!important;
    padding-bottom:0!important; margin-bottom:0!important;
}
.mdmt { padding-bottom:24px; }
.mdm-global-page-content:has(.mdmt) { height:auto!important; min-height:0!important; padding-bottom:0!important; }
.elementor-widget-shortcode:has(.mdmt),
.elementor-widget-shortcode:has(.mdmt) > .elementor-widget-container,
.elementor-shortcode:has(.mdmt),
.e-con:has(.elementor-widget-shortcode .mdmt),
.e-con:has(.elementor-widget-shortcode .mdmt) > .e-con-inner,
.elementor-section:has(.elementor-widget-shortcode .mdmt),
.elementor-column:has(.elementor-widget-shortcode .mdmt) > .elementor-widget-wrap {
    height:auto!important; min-height:0!important; max-height:none!important;
    --min-height:0px; flex-grow:0!important;
}

/* Auto gallery: do not reserve tracks or force legacy aspect ratios. */
.mdmt .mdmt-gallery.mdmt-auto-gallery,.mdm-page .mdm-gallery.mdm-auto-gallery {align-content:flex-start!important; min-height:0!important; padding:0!important;}
.mdmt .mdmt-gallery.mdmt-auto-gallery picture:nth-child(n),.mdm-page .mdm-gallery.mdm-auto-gallery>.mdm-card:nth-child(n) {aspect-ratio:auto!important; height:var(--compact-h,auto)!important;}
.mdmt .mdmt-gallery.mdmt-auto-gallery picture:not([style*="--compact-h"]),.mdm-page .mdm-gallery.mdm-auto-gallery>.mdm-card:not([style*="--compact-h"]) {aspect-ratio:1.3!important;}

/* 1.9.8: thematic title and mobile spacing. */
.mdmt-title-row h1::after{display:none!important;content:none!important;}
@media(max-width:767px){.mdm-global-page-content:has(.mdmt){padding-inline:0!important;}.mdmt{padding-inline:15px!important;}.mdm-page.mdm-auto-page:not(.mdm-home) .mdm-gallery-section{padding-inline:15px!important;}}
#mdmt-preview.mdmt-narrow .mdmt{padding-inline:15px!important;}
