/* Mobile Header Drawer - isolated to mobile, no desktop impact */
@media (max-width: 768px) {
  /* Hide theme's mobile UI to avoid double menus */
  .mobile-menu-control-wrapper,
  .main-navigation .menu-toggle,
  .has-inline-mobile-toggle #site-navigation.toggled,
  #site-navigation.toggled,
  #site-navigation .main-nav {
    display: none !important;
  }

  /* Ensure header layout is not broken */
  .site-header .inside-header {
    position: relative;
  }

  /* Our hamburger button */
  .m-header-toggle {
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: transparent;
    width: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    position: absolute;
    right: 16px;
    top: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    cursor: pointer;
  }
  .m-header-toggle:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    border-radius: 6px;
  }
  /* Hamburger icon (3 bars) */
  .m-hamburger,
  .m-hamburger::before,
  .m-hamburger::after {
    display: block;
    content: "";
    width: 22px;
    height: 2px;
    background: #ffffff;
    border-radius: 2px;
    transition: transform .25s ease, opacity .2s ease;
  }
  .m-hamburger::before { transform: translateY(-6px); }
  .m-hamburger::after { transform: translateY(6px); }
  body.is-mobile-menu-open .m-hamburger { opacity: 0; }

  /* Drawer container */
  .m-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100dvh;
    width: min(80vw, 360px);
    background: #323e57;
    color: #fff;
    transform: translateX(100%);
    transition: transform .3s ease;
    z-index: 1300;
    box-shadow: -8px 0 24px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    outline: none;
  }
  .m-drawer.open {
    transform: translateX(0);
  }

  .m-drawer-nav {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px 12px 28px;
  }

  /* Nested menu styles */
  .m-drawer-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .m-drawer-nav > .m-built > ul { /* top level */
    padding: 4px 4px 8px 4px;
  }

  .m-drawer-nav li {
    position: relative;
  }

  .m-drawer-nav li > a {
    display: block;
    color: #fff;
    text-decoration: none;
    padding: 12px 64px 12px 12px; /* more space for bigger toggle on the right */
    border-radius: 8px;
  }

  .m-drawer-nav li > a:focus,
  .m-drawer-nav li > a:hover {
    background: #2a364f;
  }
  /* subtle affordance for items with submenu */
  .m-drawer-nav li.m-has-sub > a {
    background: rgba(255,255,255,0.08);
  }
  .m-drawer-nav li.m-has-sub.m-open > a {
    background: rgba(255,255,255,0.16);
  }

  /* Submenu block (collapsed by default via hidden attr) */
  .m-drawer-nav ul.m-sub {
    margin: 4px 0 6px;
    padding-left: 14px; /* indent level */
    border-left: 2px solid rgba(255,255,255,0.08);
  }

  /* Submenu toggle button (arrow on the right) */
  .m-sub-toggle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0; /* full row height for easier tapping */
    transform: none;
    width: 52px;
    height: 44px; /* minimum size; actual height follows row */
    border: 0;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1; /* ensure it's above the link area */
    -webkit-tap-highlight-color: transparent;
  }
  /* visual button background inside the hit area */
  .m-sub-toggle::after {
    content: "";
    display: inline-block;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: rgba(255,255,255,0.24);
    transition: background-color .2s ease, border-color .2s ease, opacity .2s ease;
  }
  .m-sub-toggle:focus-visible::after,
  .m-sub-toggle:hover::after {
    background: rgba(255,255,255,0.35);
  }
  .m-sub-toggle::before {
    content: "";
    display: inline-block;
    width: 14px;
    height: 14px;
    border-right: 3px solid #fff;
    border-bottom: 3px solid #fff;
    transform: rotate(-45deg);
    transition: transform .2s ease;
  }
  /* Expanded state rotates the arrow */
  li.m-open > .m-sub-toggle::before,
  li.m-open > a + .m-sub-toggle::before {
    transform: rotate(45deg); /* pointing up */
  }
  /* highlight the button bubble when expanded */
  li.m-open > .m-sub-toggle::after,
  li.m-open > a + .m-sub-toggle::after {
    background: #1e73be;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.25) inset;
  }

  /* Level-based indentation (progressive) */
  .m-drawer-nav ul > li > ul.m-sub > li > a { padding-left: 18px; }
  .m-drawer-nav ul > li > ul.m-sub > li > ul.m-sub > li > a { padding-left: 24px; }

  /* Small transition when revealing sub lists (hidden attr toggled in JS) */
  .m-drawer-nav ul.m-sub[hidden] { display: none; }
  .m-drawer-nav ul.m-sub:not([hidden]) { display: block; }

  /* Active/hover affordance */
  .m-drawer-nav a:active { opacity: 0.9; }

  .m-drawer-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .m-drawer-list li { margin: 0; }
  .m-drawer-list a {
    display: block;
    color: #fff;
    text-decoration: none;
    padding: 12px 10px;
    border-radius: 6px;
    line-height: 1.2;
  }
  .m-drawer-list a:hover,
  .m-drawer-list a:focus {
    background: #2a364f;
  }

  /* Overlay */
  .m-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    opacity: 0;
    transition: opacity .25s ease;
    z-index: 1200;
  }
  body.is-mobile-menu-open .m-drawer-overlay {
    opacity: 1;
  }
  .m-drawer-overlay[hidden] { display: none; }

  /* Body scroll lock when drawer open */
  body.is-mobile-menu-open {
    overflow: hidden;
    touch-action: none;
  }
}

/* Desktop: ensure no visual changes */
@media (min-width: 769px) {
  .m-header-toggle { display: none !important; }
  .m-drawer, .m-drawer-overlay { display: none !important; }
}

/* Mobile header visual tuning based on logo 600x262 */
@media (max-width: 768px) {
  /* tighter header rhythm on mobile */
  .site-header { padding: 0 !important; }

  .site-header .inside-header {
    padding: 8px 56px 8px 16px !important; /* right side space for hamburger */
    display: flex;
    align-items: center;
    justify-content: flex-start !important; /* 强制左对齐，覆盖首页等居中影响 */
    text-align: left !important;
    gap: 12px;
  }
  /* 首页（.home）在移动端统一与内页相同的左右内边距 */
  .home .site-header .inside-header {
    padding-left: 16px !important;
    padding-right: 56px !important;
  }
  /* 统一子元素顺序与左右分布（无视不同页面的 DOM 插入顺序差异） */
  .site-header .inside-header > .site-logo {
    order: 1;
    margin-right: auto;   /* 将汉堡按钮推到最右 */
    flex: 0 1 auto;
  }
  .site-header .inside-header > .m-header-toggle {
    order: 2;
  }

  .site-header .site-logo { line-height: 0; }
  .site-header .site-logo,
  .site-header .site-logo a {
    display: flex;
    align-items: center;
  }

  /* logo keep aspect ratio, cap height to avoid “too tall” look */
  .site-header .header-image,
  .home .site-header .header-image {
    height: 60px !important;
    width: auto !important;
    max-width: 70vw !important;
    display: block;              /* 统一为块级，消除基线差异 */
    vertical-align: middle;      /* 保险：即使作为内联元素也不中线抖动 */
  }

  /* 统一 logo 容器与链接在 flex 中的对齐与间距 */
  .site-header .site-logo,
  .site-header .site-logo a {
    margin: 0 !important;
    padding: 0 !important;
  }

  /* fine tune hamburger placement to match new padding */
  .m-header-toggle {
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
  }

  /* Ensure consistent left alignment across all pages (including .home) on mobile */
  .site-header .site-logo { flex: 0 0 auto; }
  .site-header .site-logo,
  .site-header .site-logo a,
  .site-header .site-logo img {
    margin: 0 !important;
  }
  .home .site-header .inside-header {
    justify-content: flex-start !important;
    text-align: left !important;
  }
}

/* --- START: small touch/click compatibility patch --- */
/* Improve tap target and touch behavior for menu toggle and sub-toggle */
@media (max-width: 768px) {
  /* Ensure primary header toggle is large enough and prioritized above overlays */
  .m-header-toggle, .menu-toggle {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 6px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation; /* reduce 300ms delay on some browsers */
    z-index: 1400 !important; /* ensure above overlays */
    -webkit-user-select: none;
    user-select: none;
  }

  /* Make sure sub-toggle uses full row height for easier tapping (already set, reinforce) */
  .m-sub-toggle {
    width: 56px;
    height: 100%;
    min-height: 48px;
    right: 6px;
    z-index: 1400;
    touch-action: manipulation;
  }

  /* If overlays are hidden via [hidden], still avoid pointer capture issues */
  .m-drawer-overlay[hidden] { display: none; pointer-events: none; }

  /* When open, ensure overlay does not cover the toggle */
  body.is-mobile-menu-open .m-header-toggle {
    z-index: 1500 !important;
    position: fixed; /* keep it reachable even during transitions */
  }
}
/* --- END: small touch/click compatibility patch --- */