/* Responsive layout. Loaded after style.css; #page overrides legacy !important rules. */
:root {
    --page-gutter: clamp(12px, 2.3vw, 32px);
    --layout-gap: clamp(20px, 3vw, 48px);
}

body, .site { overflow-x: visible; }
#page .container {
    width: 100%;
    max-width: var(--container-width);
    padding-inline: var(--page-gutter) !important;
    overflow: visible;
}
#page .content-area {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap;
    align-items: flex-start !important;
    gap: var(--layout-gap) !important;
    min-width: 0;
}
#page .content-area > .main-content {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    width: auto !important;
    max-width: 100%;
}
#page .content-area > .sidebar {
    flex: 0 0 clamp(300px, 25vw, 350px) !important;
    width: clamp(300px, 25vw, 350px) !important;
    min-width: 0 !important;
    max-width: 350px !important;
    margin-top: 20px !important;
}
#page .header-content {
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 24px;
    min-height: 80px;
    padding-block: 12px;
}
#page .site-branding {
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
    justify-content: flex-start;
}
#page .brand-logo, #page .brand-text { min-width: 0; }
#page .logo-container { justify-content: flex-start; gap: 12px; }
#page .logo-icon { width: 56px; height: 56px; }
#page .brand-name {
    font-size: clamp(1.1rem, 2.2vw, 1.9rem) !important;
    letter-spacing: 0.3px;
}
#page .brand-subtitle {
    font-size: 0.85rem !important;
    text-align: left;
    text-align-last: auto;
    letter-spacing: 0;
}
#page .main-navigation { flex: 0 0 auto; width: auto; order: 2; }
#page .nav-menu {
    gap: clamp(8px, 1vw, 16px);
    align-items: center;
}
#page .nav-menu > li > a {
    display: flex;
    align-items: center;
    min-height: 44px;
    font-size: 0.9rem !important;
    white-space: nowrap;
}
#page .nav-menu li:focus-within > .sub-menu {
    opacity: 1;
    visibility: visible;
    transform: none;
}
#page .nav-menu > li:last-child > .sub-menu { left: auto; right: 0; }
#page .menu-toggle {
    display: none;
    position: relative;
    inset: auto;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 10px;
    margin: 0;
    z-index: 2;
    border-radius: 8px;
}
#page a:focus-visible, #page button:focus-visible,
.back-to-top:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 3px;
}
#page .featured-image > a:focus-visible { outline-offset: -4px; }

/* The cover and news list grow with their text instead of clipping at 500px. */
#page .news-hero-container {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    grid-template-areas: "featured recent";
    height: auto;
}
#page .featured-article, #page .featured-post {
    height: 100%;
    min-height: 0;
    min-width: 0;
}
#page .featured-image {
    display: flex;
    height: 100%;
    min-height: clamp(320px, 38vw, 500px);
    isolation: isolate;
}
#page .featured-image > a { position: absolute; inset: 0; }
#page .featured-img { width: 100%; height: 100%; object-fit: cover; }
#page .featured-overlay {
    position: relative;
    inset: auto;
    width: 100%;
    min-height: inherit;
    padding: clamp(16px, 2.5vw, 32px);
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.86));
}
#page .featured-title {
    font-size: clamp(1.25rem, 2.3vw, 2rem);
    line-height: 1.25;
}
#page .recent-news-list { height: auto; min-width: 0; }
#page .recent-item-content { padding: 14px clamp(16px, 2vw, 24px); }
#page .recent-item-title { font-size: 0.9rem; }

/* Zero minimums let long headlines wrap inside their columns. */
#page .posts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: clamp(16px, 2vw, 32px) !important;
}
#page .related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
#page .now-reading-list {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)) !important;
}
#page :where(.post-card, .related-card, .now-reading-item, .widget,
    .news-content, .recent-post-content, .nav-content, .nav-previous, .nav-next,
    .footer-section, .wp-block-search__inside-wrapper) { min-width: 0; }
#page :where(.post-title, .featured-title, .article-title, .archive-title,
    .recent-item-title, .reading-text, .related-title-text, .widget,
    .footer-section, .footer-bottom, .nav-content) { overflow-wrap: anywhere; }
#page .post-content { padding: clamp(16px, 2vw, 24px); }
#page .post-title { font-size: clamp(1.125rem, 1.7vw, 1.5rem); }
#page .breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    overflow-wrap: anywhere;
    margin-bottom: 0;
}
#page .breadcrumbs .separator { margin: 0; }

#page .article-hero {
    min-height: clamp(320px, 40vw, 500px);
    margin-block: 20px 32px;
}
#page .hero-content { padding: clamp(24px, 4vw, 56px) clamp(16px, 3vw, 40px); }
#page .article-title {
    font-size: clamp(1.65rem, 3.4vw, 3.2rem);
    line-height: 1.15;
    hyphens: auto;
}
#page .article-meta, #page .publish-details, #page .social-share,
#page .share-buttons-large {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}
#page .publish-date, #page .reading-time { max-width: 100%; }
#page .publish-details svg { flex-shrink: 0; }
#page .article-content { margin-block: clamp(24px, 4vw, 50px); }
#page .content-wrapper {
    width: 100%;
    min-width: 0;
    font-size: clamp(1rem, 1.4vw, 1.125rem);
    line-height: 1.8;
    overflow-wrap: anywhere;
}
#page .content-wrapper h2 { font-size: clamp(1.4rem, 2.4vw, 2rem); padding-left: 14px; }
#page .content-wrapper h3 { font-size: clamp(1.2rem, 2vw, 1.5rem); }
#page .content-wrapper blockquote { padding: clamp(16px, 2vw, 30px); }
#page .content-wrapper :where(img, video, figure, .wp-caption, .wp-block-image,
    .wp-block-gallery, .wp-block-columns) { max-width: 100%; }
#page .content-wrapper :where(img, video) { height: auto; }
#page .content-wrapper :where(iframe, embed, object) { max-width: 100%; }
#page .content-wrapper iframe[src*="youtube"],
#page .content-wrapper iframe[src*="youtu.be"],
#page .content-wrapper iframe[src*="rutube"],
#page .content-wrapper iframe[src*="vimeo"] { width: 100%; height: auto; aspect-ratio: 16 / 9; }
#page .content-wrapper .wp-block-table, #page .article-table-scroll {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    margin-block: 24px;
}
#page .content-wrapper table {
    display: table;
    width: 100%;
    max-width: none;
    border-collapse: collapse;
    white-space: normal;
    font-size: 0.95em;
}
#page .content-wrapper :where(th, td) {
    min-width: 100px;
    padding: 10px;
    border: 1px solid var(--border-color);
    overflow-wrap: normal;
}
#page .content-wrapper pre {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre;
    overflow-wrap: normal;
    padding: 16px;
}
#page .article-footer { padding: clamp(16px, 3vw, 40px); }
#page .share-btn { width: 44px; height: 44px; }
#page .share-btn-large { min-height: 44px; padding: 12px 18px; }
#page .tag-item { overflow-wrap: anywhere; max-width: 100%; }
#page .nav-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#page .nav-link-card { height: auto; min-height: 80px; }
#page .nav-thumb { flex: 0 0 48px; }
#page .nav-thumb img { width: 48px; height: 48px; }
#page .related-title { font-size: clamp(1.5rem, 3vw, 2.5rem); }
#page .pagination-wrapper, #page .page-navigation { display: flex; flex-wrap: wrap; justify-content: center; }
#page .pagination .page-numbers, #page .pagination .modern-page-num {
    min-width: 44px !important;
    height: 44px !important;
}
#page .footer-content { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
#page .footer-navigation ul { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; }
#page .footer-navigation a { display: inline-block; padding-block: 10px; }
.back-to-top { right: max(12px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }

/* Search stays usable at narrow widths and avoids iOS zoom on focus. */
#page .search-form, #page .searchform, #page .wp-block-search__inside-wrapper {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap;
    gap: 8px !important;
    width: 100%;
}
#page .search-form label { flex: 1 1 120px; min-width: 0; }
#page input[type="search"] {
    flex: 1 1 120px !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100%;
    min-height: 44px !important;
    font-size: 16px !important;
    padding: 8px !important;
}
#page .search-submit, #page .wp-block-search__button {
    flex: 0 1 auto;
    min-height: 44px !important;
    max-width: 100%;
    margin: 0 !important;
    padding: 8px 14px !important;
    font-size: 1rem !important;
}
#page :where(input, textarea, select) { max-width: 100%; }
#page :where(input[type="text"], input[type="email"], textarea, select) { font-size: 16px; }

/* Compact navigation also covers laptops, tablets, zoom and landscape phones. */
@media (max-width: 1279.98px) {
    #page .main-navigation { position: static; }
    #page .main-navigation.menu-enhanced .menu-toggle { display: inline-flex; }
    #page .main-navigation.menu-enhanced .nav-menu:not(.menu-open) { display: none; }
    #page .nav-menu {
        position: absolute;
        inset: 100% 0 auto;
        width: 100%;
        height: auto;
        max-height: calc(100vh - var(--site-header-bottom, 80px));
        max-height: calc(100dvh - var(--site-header-bottom, 80px));
        overflow-y: auto;
        overscroll-behavior: contain;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0;
        padding: 12px var(--page-gutter) max(16px, env(safe-area-inset-bottom));
        background: #fff;
        box-shadow: 0 12px 20px rgba(0, 0, 0, 0.12);
        transform: none;
        transition: none;
        z-index: 1;
    }
    #page .nav-menu li { text-align: left; }
    #page .nav-menu > li > a { padding: 10px 12px; font-size: 1rem !important; white-space: normal; }
    #page .nav-menu .sub-menu {
        position: static;
        min-width: 0;
        max-width: 100%;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        padding: 0 0 8px 16px;
        margin: 0;
    }
    #page .nav-menu .sub-menu a { display: block; padding: 10px 12px; font-size: 0.95rem !important; }
    #page .main-navigation:not(.menu-enhanced) { flex: 1 1 100%; }
    #page .main-navigation:not(.menu-enhanced) .nav-menu { position: static; max-height: none; }
    #page .header-content:has(.main-navigation:not(.menu-enhanced)) { flex-wrap: wrap; }
}
@media (max-width: 1024.98px) {
    #page .content-area { flex-direction: column !important; }
    #page .content-area > .main-content, #page .content-area > .sidebar {
        flex: 0 1 auto !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-top: 0 !important;
    }
    #page .news-hero-container { grid-template-columns: minmax(0, 1fr); grid-template-areas: "featured" "recent"; }
    #page .featured-image { min-height: clamp(300px, 48vw, 440px); }
    #page .recent-news-list { border-left: 0; border-top: 1px solid var(--border-light); }
    #page .recent-news-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #page .latest-news-item { flex-direction: row; text-align: left; }
    #page .latest-news-item .news-thumbnail { align-self: flex-start; flex-shrink: 0; }
    #page .latest-news-item .news-image { width: 100px; height: 75px; }
    #page .widget-recent-posts .recent-post-thumbnail { flex-shrink: 0; }
    #page .footer-content { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
@media (max-width: 639.98px) {
    #page .header-content { gap: 8px; min-height: 64px; padding-block: 10px; }
    #page .logo-container { gap: 8px; }
    #page .logo-icon { width: 36px; height: 36px; }
    #page .brand-name { font-size: clamp(1.05rem, 5.1vw, 1.6rem) !important; }
    #page .brand-subtitle { font-size: 0.65rem !important; line-height: 1.3; }
    #page .posts-grid, #page .related-grid, #page .nav-links,
    #page .recent-news-items, #page .footer-content { grid-template-columns: minmax(0, 1fr) !important; }
    #page .featured-image { min-height: 300px; }
    #page .featured-title { font-size: clamp(1.2rem, 5vw, 1.6rem); }
    #page .article-category { margin-bottom: 12px; }
    #page .article-title { margin-block: 16px; }
    #page .article-hero { min-height: 300px; }
    #page .article-excerpt { font-size: 1rem; }
    #page .publish-date, #page .reading-time { padding: 6px 10px; font-size: 0.8rem; }
    #page .post-navigation { padding-inline: 0; }
    #page .share-buttons-large { gap: 8px; }
    #page .share-btn-large { flex: 1 1 150px; justify-content: center; }
    #page .content-wrapper :where(ul, ol) { padding-left: 22px; }
    #page .content-wrapper .wp-block-columns { flex-wrap: wrap !important; }
    #page .content-wrapper .wp-block-column { flex-basis: 100% !important; min-width: 0; }
    #page .latest-news-item { gap: 12px; padding: 8px 0; }
    #page .latest-news-item .news-image { width: 80px; height: 60px; }
}
@media (prefers-reduced-motion: reduce) {
    #page .news-ticker-wrapper { overflow-x: auto; height: auto; min-height: 50px; }
    #page .news-ticker-content { animation: none !important; transform: none; }
    #page .news-ticker-wrapper::before, #page .news-ticker-wrapper::after { display: none; }
}
