/* =========================================
   Mobile Header Redesign (2026-02-11)
   ========================================= */

/* Desktop defaults */
.header-menu-container {
    display: none;
}

.mobile-search-wrapper {
    display: none;
}

/* Mobile Adjustments */
@media screen and (max-width: 768px) {

    /* Reduce Header Height - Compact but Touchable */
    .site-header {
        padding: 12px 0 12px 0 !important;
        /* Balanced padding for vertical center */
        margin-bottom: 0 !important;
        min-height: auto !important;
        position: relative !important;
        overflow: visible !important;
        z-index: 1000 !important;
        box-sizing: border-box !important;
        height: auto !important;
    }

    .header-content {
        padding-bottom: 0 !important;
        /* Reset, handled by header padding */
    }

    /* Reset inner containers to static so nav allows full width relative to header */
    .site-header .container,
    .site-header .header-content {
        position: static !important;
    }

    /* Flex layout for top row */
    .header-top-row {
        display: flex;
        align-items: center;
        width: 100%;
        justify-content: space-between;
        /* position: relative; Remove this to fallback to site-header */
    }

    /* Title and Subtitle Side-by-Side */
    .site-title-wrapper {
        flex-direction: row !important;
        align-items: center !important;
        flex: 1;
        min-width: 0;
        gap: 8px;
        z-index: 10;
        /* Lower than menu */
        margin-top: 5px !important;
        /* Push down more for vertical center */
    }

    .site-title {
        font-size: 20px !important;
        /* Increased from 16px */
        white-space: nowrap;
        line-height: 1.2;
        padding-bottom: 0 !important;
    }

    .site-title a {
        color: #FFD700 !important;
    }

    .site-subtitle {
        font-size: 11px !important;
        /* Slightly larger */
        color: rgba(255, 255, 255, 0.9) !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0 !important;
        flex: 1;
        display: inline-block !important;
        line-height: 1.2;
    }

    /* Toggle visibility of containers */
    .header-search-container {
        display: none !important;
    }

    .header-menu-container {
        display: block !important;
        margin-left: 10px;
        position: relative;
        z-index: 1002;
        /* Ensure it is top-most clickable */
    }

    /* Menu Button Style */
    .menu-toggle-btn {
        background: none;
        border: none;
        color: #fff;
        font-size: 24px;
        /* Default size */
        cursor: pointer;
        padding: 5px;
        /* Slightly reduced padding to keep alignment but maintain hit area */
        display: flex;
        align-items: center;
        justify-content: center;
        /* z-index is handled by container now */
    }

    /* Navigation Menu (Slide/Dropdown) */
    .main-navigation {
        display: none !important;
        position: absolute;
        top: 100%;
        /* Position right below the header container */
        left: 0;
        /* Align with viewport left if container is relative, or adjust */
        right: 0;
        /* Align with viewport right */
        width: 100%;
        /* Ensure full width */
        background-color: #fff;
        padding: 0;
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
        z-index: 1001;
        border-top: 1px solid #ddd;
        margin-top: 0;
        /* Align perfectly with bottom of header */
    }

    /* Force display when toggled with high specificity */
    nav.main-navigation.toggled,
    .main-navigation.toggled {
        display: block !important;
    }

    /* Reset Nav Menu Layout for Mobile */
    .main-navigation ul.nav-menu,
    .main-navigation .menu {
        display: block !important;
        /* Force block to kill flex */
        padding: 0 !important;
        margin: 0 !important;
        list-style: none !important;
        width: 100% !important;
    }

    .main-navigation ul.nav-menu>li,
    .main-navigation .menu>li {
        display: block !important;
        /* Force items to stack */
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none;
        float: none !important;
    }

    .main-navigation ul.nav-menu>li>a,
    .main-navigation .menu>li>a,
    .nav-menu a {
        color: #333 !important;
        padding: 19px 20px !important;
        /* Adjusted to 90% size */
        border-bottom: 1px solid #f0f0f0;
        width: 100%;
        display: block !important;
        text-shadow: none !important;
        font-weight: bold;
        font-size: 16px !important;
        box-sizing: border-box;
        text-decoration: none !important;
    }

    .nav-menu a:hover {
        background: #f9f9f9 !important;
        color: #FFD700 !important;
    }

    .nav-menu a::after {
        display: none !important;
    }

    /* Mobile Search */
    .mobile-search-wrapper {
        display: block !important;
        padding: 10px 20px;
        /* Reduced vertical padding */
        background: #f5f5f5;
        border-top: 1px solid #ddd;
    }

    .mobile-search-wrapper form {
        display: flex;
        gap: 5px;
    }

    .mobile-search-wrapper input[type="search"] {
        flex: 1;
        padding: 6px 10px;
        /* Smaller input padding to reduce size */
        border: 1px solid #ddd;
        border-radius: 4px;
        font-size: 14px;
        color: #333;
        height: 36px;
        /* Explicit height control */
    }

    .mobile-search-wrapper input[type="submit"] {
        padding: 0 15px;
        background: #FFD700;
        border: none;
        border-radius: 4px;
        font-weight: bold;
        color: #333;
        font-size: 14px;
        height: 36px;
        line-height: normal;
    }

    /* Breadcrumbs - Reset List Styles to avoid double padding */
    .fx-breadcrumbs ul,
    .rank-math-breadcrumb ul,
    .breadcrumb ul,
    #breadcrumbs ul {
        margin: 0 !important;
        padding: 0 !important;
        list-style: none !important;
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
    }

    .fx-breadcrumbs li,
    .rank-math-breadcrumb li,
    .breadcrumb li,
    #breadcrumbs li {
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Breadcrumbs spacing fix - FORCE REMOVE GAPS & FULL WIDTH */
    .rank-math-breadcrumb,
    nav[aria-label="breadcrumbs"],
    .breadcrumb,
    .fx-breadcrumbs,
    /* Custom function class */
    #breadcrumbs {
        margin-top: 0 !important;
        margin-bottom: 0 !important;

        /* Force full width to cover gaps */
        margin-left: -20px !important;
        margin-right: -20px !important;
        padding: 12px 40px 12px 40px !important;
        /* Increase left padding to 40px to compensate for negative margin */
        width: auto !important;

        background-color: #f5f5f5;
        /* Restore gray background */
        line-height: 1.4 !important;
        font-size: 12px !important;
        position: relative;
        left: 0;
        box-sizing: border-box !important;
    }

    /* Remove gaps from main content containers */
    .site-main {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    .site-main>.container {
        padding-top: 0 !important;
    }

    .content-area {
        margin-top: 0 !important;
        padding-top: 0 !important;
        gap: 0 !important;
    }

    /* Restore spacing above Article Title (H1) */
    article.post {
        margin-top: 0 !important;
        padding-top: 30px !important;
        /* Space between breadcrumbs and Title */
        background-color: #fff;
    }

    /* Reduce spacing between Date and Body Content */
    .post-content {
        margin-top: 0 !important;
        padding-top: 0 !important;
        /* Remove inner padding top of content */
        background-color: #fff;
    }

    .post-header {
        margin-bottom: 20px !important;
        /* Adjust gap between date and content start */
        padding-bottom: 0 !important;
    }

    /* Archive Title & Description Size Fix */
    .archive-header {
        padding-top: 30px !important;
        padding-left: 30px !important;
        padding-right: 20px !important;
        /* Ensure text doesn't hit right edge */
    }

    .archive-title {
        font-size: 20px !important;
        /* Reduce from default large size */
        margin-bottom: 10px !important;
        font-weight: bold !important;
        line-height: 1.3 !important;
    }

    .archive-description {
        font-size: 13px !important;
        /* Reduce description size */
        line-height: 1.5 !important;
        color: #555 !important;
        margin-bottom: 20px !important;
    }

    /* Fix Archive Card Image Alignment and Width */
    article.archive-post-card,
    .archive-post-card {
        padding: 0 !important;
        /* Reset all padding */
        border-radius: 12px !important;
        overflow: hidden !important;
        margin-top: 0 !important;

        /* Make card 90% width and centered */
        width: 90% !important;
        margin-left: auto !important;
        margin-right: auto !important;
        margin-bottom: 20px !important;
        box-sizing: border-box !important;
    }

    /* Additional safety for link wrapper */
    .archive-post-link {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        margin: 0 !important;
    }

    /* Ensure thumbnail fills width of the card */
    .archive-post-thumbnail {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 16/9 !important;
        margin: 0 !important;
    }

    /* Footer Content Width Adjustment (90% width, centered) */
    .site-footer .container {
        width: 90% !important;
        max-width: 90% !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        box-sizing: border-box !important;
    }

    .site-footer .footer-content,
    .site-footer .footer-bottom {
        width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        box-sizing: border-box !important;
    }

    /* Pagination Styling */
    .navigation.pagination {
        margin-top: 30px !important;
        margin-bottom: 40px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        padding-right: 0 !important;
        /* Remove right padding for center align */

        display: flex !important;
        justify-content: center !important;
        /* Center align */
    }

    .nav-links {
        display: flex !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        /* Center align */
    }

    .nav-links .page-numbers {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 8px 12px !important;
        background-color: #fff !important;
        border: 1px solid #eee !important;
        border-radius: 6px !important;
        text-decoration: none !important;
        color: #555 !important;
        font-size: 14px !important;
        line-height: normal !important;
        min-width: 36px !important;
        box-sizing: border-box !important;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
    }

    .nav-links .page-numbers.current {
        background-color: #FFD700 !important;
        /* Gold */
        color: #333 !important;
        border-color: #FFD700 !important;
        font-weight: bold !important;
    }

    .nav-links .page-numbers:hover:not(.current) {
        background-color: #f9f9f9 !important;
        border-color: #ddd !important;
    }

    .nav-links .page-numbers.dots {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        min-width: auto !important;
        padding: 0 5px !important;
    }

    /* Table Horizontal Scroll - Target the WRAPPER, not the table */
    figure.wp-block-table,
    .post-content>.wp-block-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 20px !important;
    }




    /* Ensure the table inside keeps its natural width */
    figure.wp-block-table table,
    .post-content>.wp-block-table table {
        min-width: 500px !important;
        /* Force wider than viewport to enable scroll */
    }


    /* Fix TOC Top Spacing on Mobile */
    .toc-box {
        margin-top: 5px !important;
        margin-bottom: 30px !important;
        padding-top: 12px !important;
        /* Reduce internal top padding */
    }

    .toc-box h2 {
        margin-top: 0 !important;
        /* Remove h2 top margin inside toc-box */
    }

    /* Gap between learning box and TOC */
    .learning-box+.toc-box,
    .learning-box+p+.toc-box {
        margin-top: 20px !important;
        /* Restore original gap */
    }

    /* Reduce learning-box bottom margin */
    .learning-box {
        margin-bottom: 20px !important;
        /* Restore original */
    }

    /* -----------------------------------------
       筆者コメント吹き出し モバイル対応
       ----------------------------------------- */
    .author-comment {
        flex-direction: column !important;
        align-items: center !important;
    }

    .author-comment .ac-icon {
        margin-top: 0 !important;
        margin-bottom: 30px !important;
    }

    .author-comment .ac-bubble {
        margin-left: 0 !important;
        padding: 24px 20px 20px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .author-comment .ac-label {
        top: -12px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
}