/* Shared CN2026 layout and navigation. Match WordPress Columns' 781/782px boundary. */
.custom-navigation .menu-item.is-submenu-open > .submenu {
    display: block;
}

/* Wrap only when needed, including narrow desktop/tablet widths. */
.alasivut-palkki {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    flex-wrap: wrap;
}

/* Desktop buttons take no layout space; keyboard users can reveal and use them. */
.custom-navigation .cn-submenu-toggle {
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 1px;
    min-width: 0;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: 1;
    cursor: pointer;
    box-sizing: border-box;
}

.custom-navigation .cn-submenu-toggle:focus-visible {
    width: 32px;
    height: 32px;
    clip-path: none;
    overflow: visible;
    background: #2e08f3;
    outline: 2px solid currentColor;
    outline-offset: 2px;
    z-index: 1;
}

.custom-navigation .cn-submenu-toggle[aria-expanded="true"] > span {
    display: inline-block;
    transform: rotate(180deg);
}

@media (min-width: 782px) {
    /* Retain pointer/keyboard navigation if JavaScript is unavailable. */
    .custom-navigation:not(.cn-menu-ready) .menu-item:hover > .submenu,
    .custom-navigation:not(.cn-menu-ready) .menu-item:focus-within > .submenu {
        display: block;
    }

    .alasivut-palkki a {
        display: inline-block;
        margin: 0 15px;
    }
}

@media (max-width: 782px) {
    /* WordPress' admin bar is 46px through 782px, then 32px. */
    body.admin-bar .is-position-sticky {
        top: 46px;
    }
}

@media (max-width: 781px) {
    /* A long expanded menu must scroll with the document on small screens. */
    .wp-site-blocks > .is-position-sticky,
    body.admin-bar .wp-site-blocks > .is-position-sticky {
        position: static;
        top: auto;
    }

    .custom-navigation {
        min-width: 0;
        max-width: 100%;
        padding-block: 4px;
    }

    .custom-navigation .custom-menu {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .custom-navigation .custom-menu > .menu-item {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 44px;
        align-items: center;
        column-gap: 4px;
        min-width: 0;
        max-width: 100%;
    }

    .custom-navigation .custom-menu > .menu-item > a {
        min-width: 0;
        padding: 8px 6px;
        font-size: 16px;
        overflow-wrap: anywhere;
    }

    .custom-navigation .cn-submenu-toggle,
    .custom-navigation .cn-submenu-toggle:focus-visible {
        position: static;
        width: 44px;
        height: 44px;
        overflow: visible;
        clip-path: none;
        border: 1px solid currentColor;
        background: transparent;
        font-size: 24px;
    }

    .custom-navigation .submenu {
        grid-column: 1 / -1;
        position: static;
        top: auto;
        left: auto;
        right: auto;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
        text-align: left;
    }

    .custom-navigation .submenu li a {
        font-size: 16px;
        overflow-wrap: anywhere;
    }

    /* Override only the header member-bar's saved inline side padding. */
    .wp-site-blocks header.wp-block-template-part > .wp-block-group.has-base-2-background-color {
        display: block;
        padding-inline: clamp(12px, 3vw, 24px) !important;
    }

    .alasivut-palkki {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
        flex-wrap: wrap;
        gap: 8px 12px;
        padding: 10px;
        background-color: #f9f9f9;
    }

    .alasivut-palkki a {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
        margin: 0;
        padding: 4px;
        overflow-wrap: anywhere;
    }

    /* Preserve source order: main content, then sidebar. Footer order stays intact. */
    .wp-site-blocks main > .wp-block-columns {
        flex-direction: column;
    }

    .wp-site-blocks main > .wp-block-columns > .wp-block-column {
        flex-basis: auto !important;
        min-width: 0;
    }

    .wp-site-blocks main > .wp-block-columns > .wp-block-column[style*="padding-left"] {
        padding-inline: clamp(12px, 3vw, 24px) !important;
    }
}

/* Wide touch screens also need visible controls; mouse desktop layout is unchanged. */
@media (min-width: 782px) and (hover: none) and (pointer: coarse) {
    .custom-navigation .custom-menu > .menu-item.has-submenu > a {
        padding-right: 52px;
    }
    .custom-navigation .cn-submenu-toggle {
        width: 44px;
        height: 44px;
        overflow: visible;
        clip-path: none;
        border: 1px solid currentColor;
    }
}

/* Compact mobile menu: text disclosures instead of separate arrow controls. */
@media (max-width: 781px) {
    .wp-site-blocks header.wp-block-template-part > .wp-block-group:first-child > .wp-block-group.alignwide {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .wp-site-blocks header.wp-block-template-part .wp-block-site-logo img {
        width: 44px;
        max-width: 44px !important;
        height: auto;
    }

    .custom-navigation {
        position: relative;
        flex: 1 1 0;
    }

    .custom-navigation .custom-menu {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 4px 6px;
    }

    .custom-navigation .custom-menu > .menu-item {
        position: static;
        display: block;
    }

    .custom-navigation .custom-menu > .menu-item > a {
        padding: 6px 3px;
        font-size: 14px;
        line-height: 1.4;
        white-space: nowrap;
        color: #fff;
    }

    .custom-navigation .custom-menu > .menu-item > a:focus-visible {
        outline: 2px solid currentColor;
        outline-offset: 1px;
        border-radius: 3px;
    }

    .custom-navigation .cn-submenu-toggle,
    .custom-navigation .cn-submenu-toggle:focus-visible {
        display: none;
    }

    .custom-navigation .custom-menu > .menu-item > .submenu {
        position: absolute;
        top: 100%;
        left: 0;
        right: auto;
        width: 100%;
        background: #fff;
        color: blue;
        border: 1px solid #ddd;
    }

    .custom-navigation .custom-menu > .menu-item > .submenu a {
        color: blue;
        font-size: 15px;
        padding: 8px 10px;
    }

    .custom-navigation .submenu li {
        border-bottom-color: #eee;
    }

    .custom-navigation .submenu .cn-mobile-parent-link a {
        font-weight: 600;
    }

    .alasivut-palkki {
        background-color: #fff;
    }
}

/* Compact white mobile sublink areas, retaining comfortable individual targets. */
@media (max-width: 781px) {
    .alasivut-palkki {
        row-gap: 1px;
        padding-block: 2px;
        margin-block: 0 !important;
    }

    .alasivut-palkki a {
        min-height: 24px;
        margin-block: 0;
        padding-block: 2px;
        line-height: 1.3;
    }

    .custom-navigation .custom-menu > .menu-item > .submenu li {
        margin-block: 0;
    }

    .custom-navigation .custom-menu > .menu-item > .submenu a {
        min-height: 36px;
        box-sizing: border-box;
        margin-block: 0;
        padding-block: 6px;
        line-height: 1.3;
    }
}

/* One toolbar palette at every width, including mobile pseudo-element icons. */
html #wpadminbar {
    background-color: #CEFCC7 !important;
}

html #wpadminbar .ab-icon,
html #wpadminbar .ab-icon::before,
html #wpadminbar .ab-item::before,
html #wpadminbar .ab-item::after {
    color: #228B22 !important;
}

/* Toolbar text, including hover/focus and expanded items; icon palette stays separate. */
html #wpadminbar .ab-item,
html #wpadminbar .ab-label,
html #wpadminbar .display-name,
html #wpadminbar .username {
    color: #0000CC !important;
}

html #wpadminbar .quicklinks .ab-item:hover,
html #wpadminbar .quicklinks .ab-item:focus,
html #wpadminbar .quicklinks .ab-item:active,
html #wpadminbar .quicklinks .hover > .ab-item,
html #wpadminbar .quicklinks .ab-item[aria-expanded="true"] {
    background-color: #CEFCC7 !important;
    color: #0000CC !important;
}

html #wpadminbar .ab-sub-wrapper,
html #wpadminbar .ab-submenu {
    background-color: #CEFCC7 !important;
}

/* Smaller toolbar only through WordPress' mobile/tablet breakpoint. */
@media (max-width: 782px) {
    :root:has(#wpadminbar) {
        --wp-admin--admin-bar--height: 24px;
        margin-top: 24px !important;
    }

    #wpadminbar,
    #wpadminbar #wp-toolbar,
    #wpadminbar .quicklinks > ul > li,
    #wpadminbar .quicklinks > ul > li > .ab-item {
        height: 24px !important;
        min-height: 0;
        line-height: 24px !important;
    }

    #wpadminbar .quicklinks > ul > li > .ab-item {
        width: 26px !important;
        padding: 0 4px !important;
        font-size: 12px;
    }

    #wpadminbar #wp-toolbar > ul > li > .ab-item::before,
    #wpadminbar #wp-toolbar > ul > li > .ab-item > .ab-icon,
    #wpadminbar #wp-toolbar > ul > li > .ab-item > .ab-icon::before {
        top: 0 !important;
        width: 26px !important;
        height: 24px !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 20px !important;
        line-height: 24px !important;
    }

    #wpadminbar #wp-admin-bar-my-account > .ab-item {
        width: 26px !important;
    }

    #wpadminbar .quicklinks > ul > li > .ab-item img {
        top: 2px !important;
        width: auto !important;
        height: auto !important;
        max-width: 20px !important;
        max-height: 20px !important;
    }

    #wpadminbar .ab-top-menu > .menupop > .ab-sub-wrapper {
        top: 24px;
    }

    body.admin-bar .is-position-sticky {
        top: 24px;
    }
}

/* Readable mobile body copy; keep headings, navigation and desktop unchanged. */
@media (max-width: 781px) {
    main .entry-content {
        min-width: 0;
        font-size: 16px;
        line-height: 1.5;
        overflow-wrap: anywhere;
        word-break: normal;
        hyphens: auto;
    }

    main .entry-content p {
        font-size: 16px;
        line-height: 1.5;
    }

    main .entry-content a {
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: normal;
    }
}

/* Include the homepage column's padding in its mobile width. */
@media (max-width: 781px) {
    body.home main > .wp-block-columns > .wp-block-column {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Historiikki only: preserve every text/caption while laying out legacy blocks. */
.page-id-171 main .entry-content {
    display: flow-root;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* These legacy Columns blocks contain paragraphs/images without Column wrappers. */
.page-id-171 main .entry-content .wp-block-columns {
    display: block;
}

.page-id-171 main .entry-content .wp-block-image,
.page-id-171 main .entry-content center {
    max-width: 100%;
    box-sizing: border-box;
}

.page-id-171 main .entry-content .wp-block-image.alignleft,
.page-id-171 main .entry-content .wp-block-image.alignright {
    float: none;
    margin-inline: auto;
}

.page-id-171 main .entry-content img {
    max-width: 100%;
    height: auto;
    box-sizing: border-box;
}

.page-id-171 main .entry-content h2 {
    clear: both;
    margin-top: 2rem;
    margin-bottom: .75rem;
}

.page-id-171 main .entry-content pre {
    max-width: 100%;
    box-sizing: border-box;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
}

.page-id-171 main .entry-content blockquote {
    max-width: 100%;
    box-sizing: border-box;
    margin-inline: 0;
}

/* Keep absent image elements visible, without inventing replacement pictures. */
.page-id-171 main .entry-content img[src*="/sivuntiedostot/"],
.page-id-171 main .entry-content img[src$="/cn05rillit2.jpg"],
.page-id-171 main .entry-content img[src$="/cn06irkku.jpg"] {
    width: 100%;
    min-height: 72px;
    border: 1px dashed #888;
    background-color: #f8f8f8;
    box-shadow: none;
}

@media (max-width: 781px) {
    .page-id-171 main > .wp-block-columns > .wp-block-column {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Historiikki annual PDF text: exact source wording with responsive wrapping. */
.page-id-171 main .entry-content pre.cn-history-source{font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;overflow-wrap:anywhere;padding:0;background:transparent;border:0;max-width:100%;box-sizing:border-box;}

/* Historiikki: use intrinsic image size, bounded by available content width. */
.page-id-171 main .entry-content .wp-block-image,
.page-id-171 main .entry-content figure.wp-block-image.is-resized {
 width:auto !important; max-width:100% !important;
}
.page-id-171 main .entry-content img {
 width:auto !important; height:auto !important;
 max-width:100% !important; min-width:0; min-height:0;
 border:0 !important; background:transparent !important; box-shadow:none !important;
}

/* Historiikki: center poems and images, keep ordinary prose left aligned. */
.page-id-171 main .entry-content pre.wp-block-preformatted:not(.cn-history-source) {
    width: fit-content;
    max-width: 100%;
    margin: 1.75rem auto;
    padding: 0;
    text-align: center;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    box-sizing: border-box;
}
.page-id-171 main .entry-content figure.wp-block-image {
    display: block;
    float: none;
    margin: 1.5rem auto;
    text-align: center;
}
.page-id-171 main .entry-content img {
    display: block;
    margin-inline: auto;
}

/* Historiikki throughout: legacy galleries and quotations share the same spacing. */
.page-id-171 main .entry-content center {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 1.5rem auto;
    padding: 0;
    text-align: center;
    box-sizing: border-box;
}
.page-id-171 main .entry-content blockquote {
    width: fit-content;
    max-width: 100%;
    margin: 1.75rem auto;
    text-align: center;
    box-sizing: border-box;
}

/* Historiikki figures use block layout; captions must use the same layout. */
.page-id-171 main .entry-content figure.wp-block-image > figcaption {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    text-align: center;
}

/* Historiikki: inline emoji/media icons must not inherit photograph sizing. */
.page-id-171 main .entry-content :is(
    img.emoji,
    img.wp-smiley,
    img[src*="/wp-includes/images/media/"],
    img.cn-history-icon,
    svg.cn-history-icon
) {
    display: inline-block !important;
    width: auto !important;
    height: 48px !important;
    max-width: 48px !important;
    max-height: 48px !important;
    min-width: 0;
    min-height: 0;
    margin: 0 .4em 0 0 !important;
    padding: 0;
    vertical-align: middle;
    object-fit: contain;
    float: none;
    flex: none;
}
