/* ============================================================
   DHX Mobile Drawer — 子菡的世界 · 手机端右侧抽屉菜单
   仅 ≤768px 生效，桌面端零干预
   机制：父主题 navigation.js 给 .menu-toggle 加 toggled-on，
        本插件 JS 监听并同步 nav.dhm-open + body.dhm-nav-open
   ============================================================ */

/* 遮罩层：桌面端隐藏 */
.dhm-nav-overlay {
    display: none;
}

/* ============================================================
   页眉站点图标（桌面 + 手机通用）
   JS 注入结构：hgroup > a.dhx-site-icon-link + div.dhx-site-text
   ============================================================ */
.site-header hgroup {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 18px;
    text-align: left;
}
.dhx-site-icon-link {
    flex: none;
    display: block;
    width: 84px;
    height: 84px;
    line-height: 0;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(17, 24, 39, 0.15);
    transition: transform 0.2s ease;
}
.dhx-site-icon-link:hover {
    transform: scale(1.04);
}
.dhx-site-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.dhx-site-text {
    min-width: 0;
}

@media screen and (max-width: 768px) {

    /* ---------- 精简 sticky 顶栏 ---------- */
    /* 放开父容器裁切与左右内边距，让页眉白背景铺满屏幕两侧 */
    #page {
        overflow: visible;
    }
    .site-header {
        position: sticky;
        top: 0;
        z-index: 1500;
        box-sizing: border-box;
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        /* 抵消 #page 容器左右 24px 内边距，铺满屏幕（不依赖 vw，规避滚动条占位误差） */
        margin-left: -24px;
        margin-right: -24px;
        padding: 8px 14px !important;
        background: #fff;
        box-shadow: 0 1px 10px rgba(17, 24, 39, 0.08);
    }
    hgroup {
        text-align: left !important;
        max-width: none;
        flex: 1;
        min-width: 0;
        gap: 10px;
    }
    .dhx-site-icon-link {
        width: 44px;
        height: 44px;
    }
    .dhx-site-text {
        flex: 1;
        min-width: 0;
        /* 给右上角「菜单」按钮留位 */
        padding-right: 72px;
    }
    .site-header .site-title {
        margin: 0;
        font-size: 18px;
        font-weight: 700;
        line-height: 1.3;
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .site-header h2.site-description {
        display: block;
        margin: 2px 0 0;
        font-size: 11px;
        font-weight: 400;
        line-height: 1.3;
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #6b7280;
    }

    /* ---------- 导航容器：关闭态只占顶栏右侧按钮位 ---------- */
    .main-navigation {
        margin: 0;
        padding: 0;
        text-align: left;
        background: transparent;
        box-shadow: none;
        overflow: visible;
        flex: none;
    }
    /* 关闭态：菜单容器不占位（沿用父主题隐藏，靠 toggled 打开） */
    #site-navigation > div[class*="menu-"] {
        display: none;
    }

    /* ---------- 菜单按钮：纯文字胶囊（无三横图标） ---------- */
    .menu-toggle {
        display: block;
        position: absolute;
        top: 9px;
        right: 10px;
        z-index: 3;
        width: auto;
        height: 34px;
        padding: 0 16px;
        background: #fff;
        border: 1px solid rgba(31, 41, 55, 0.18);
        box-shadow: 0 1px 4px rgba(17, 24, 39, 0.12);
        border-radius: 17px;
        font-size: 14px;
        font-weight: 600;
        line-height: 32px;
        color: #1f2937;
        color-scheme: light;
        cursor: pointer;
        white-space: nowrap;
        -webkit-tap-highlight-color: transparent;
    }
    .menu-toggle::before,
    .menu-toggle::after {
        content: none !important;
        display: none !important;
    }
    .menu-toggle:active {
        background: #f3f4f6;
    }

    /* 打开态：按钮文字变为「关闭」，仍在抽屉右上角 */
    #site-navigation.dhm-open .menu-toggle {
        top: 8px;
        right: 8px;
        width: auto;
        height: 34px;
        padding: 0 16px;
        font-size: 14px;
        line-height: 32px;
        background: #f3f4f6;
        border: 1px solid rgba(31, 41, 55, 0.18);
        box-shadow: none;
        border-radius: 17px;
    }
    #site-navigation.dhm-open .menu-toggle::before,
    #site-navigation.dhm-open .menu-toggle::after {
        content: none !important;
        display: none !important;
    }
    /* 打开态用 JS 把按钮文字改成「关闭」，这里兜底设色 */
    #site-navigation.dhm-open .menu-toggle {
        color: #1f2937;
    }

    /* ---------- 打开态：nav 变成右侧滑入抽屉 ---------- */
    #site-navigation.main-navigation.dhm-open {
        position: fixed;
        top: 0;
        left: auto;
        right: 0;
        bottom: 0;
        width: min(84vw, 320px);
        padding: 58px 0 24px;
        margin: 0;
        background: #fff;
        z-index: 2000;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: -10px 0 36px rgba(17, 24, 39, 0.22);
        transform: translateX(0);
        animation: dhm-drawer-in 0.28s cubic-bezier(0.22, 0.9, 0.3, 1);
    }
    @keyframes dhm-drawer-in {
        from { transform: translateX(102%); }
        to   { transform: translateX(0); }
    }

    /* 抽屉内的菜单容器接管布局 */
    #site-navigation.dhm-open > div[class*="menu-"],
    #site-navigation.dhm-open > div[class*="menu-"] > ul.nav-menu {
        display: block !important;
        border: 0;
        width: 100%;
        text-align: left;
    }
    #site-navigation.dhm-open ul.nav-menu li {
        margin: 0;
        font-size: 16px;
    }
    #site-navigation.dhm-open ul.nav-menu li a {
        display: flex;
        align-items: center;
        min-height: 52px;
        padding: 8px 22px;
        margin: 0;
        font-size: 16px;
        line-height: 1.35;
        color: #1f2937;
        text-decoration: none;
        border-bottom: 1px solid #f0f1f3;
        white-space: normal;
        border-radius: 0;
    }
    #site-navigation.dhm-open ul.nav-menu li a:active {
        background: #f6f7f9;
    }
    #site-navigation.dhm-open ul.nav-menu .current-menu-item {
        box-shadow: inset 3px 0 0 #21759b;
    }
    #site-navigation.dhm-open ul.nav-menu .current-menu-item > a {
        color: #21759b;
        font-weight: 700;
    }

    /* ---------- 遮罩 + 锁滚动 ---------- */
    body.dhm-nav-open .dhm-nav-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1400;
        background: rgba(0, 0, 0, 0.45);
        opacity: 1;
        animation: dhm-fade 0.25s ease;
    }
    body.dhm-nav-open {
        overflow: hidden;
    }
    @keyframes dhm-fade {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

    /* ---------- 窄屏内容兜底 ---------- */
    .entry-content img,
    .entry-summary img,
    .comment-content img,
    .widget img,
    .entry-content video,
    .entry-content iframe,
    .entry-content embed,
    .entry-content object,
    .wp-caption {
        max-width: 100%;
        height: auto;
    }
    .entry-content table,
    .comment-content table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .entry-content,
    .entry-summary {
        overflow-wrap: break-word;
        word-break: break-word;
    }
}
