/* =========================================
   메인 메뉴(1차) — 중앙 정렬 + 밑줄 하이라이트
   (메가패널에는 영향 없음)
========================================= */
.header-main .nav{
  flex: 1 1 auto;
  display: flex;
  justify-content: center;                 /* 중앙 정렬 */
}

.nav .menu{
  display: flex !important;
  align-items: center;
  gap: clamp(18px, 2.25vw, 34px);          /* 항목 간격 */
  margin: 0;
  padding: 0;
  list-style: none;
  white-space: nowrap;
  word-break: keep-all;
  writing-mode: horizontal-tb !important;  /* 혹시 남아있던 세로쓰기 해제 */
}

.nav .menu > li{ position: relative; }
.nav .menu > li > a{
  display:block;
  padding: clamp(8px, 0.85vw, 12px) clamp(12px, 1.2vw, 20px); /* 밑줄 공간 확보 */
  border-radius:0;
  background:transparent !important;
  color:#222;
  font-weight:620;
  font-size:var(--kegm-menu-size);
  line-height: var(--kegm-menu-line);
  letter-spacing: var(--kegm-menu-spacing);
  text-decoration:none;
  transition: color .2s ease;
}
.nav .menu > li > a:hover{ color:#0b5bd3; }

/* 밑줄 하이라이트 */
.nav .menu > li > a::after{
  content:"";
  position:absolute; left:0; right:0; bottom:-8px;
  height:3px; width:0; margin:0 auto;
  background:#0b5bd3; border-radius:3px;
  transition: width .25s ease;
}


/* hover 유지용 투명 버퍼 */
.nav::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 25px; /* hover 유지 구간 (20~30px 사이에서 조절 가능) */
  background: transparent;
  pointer-events: auto;
}

/* 메가패널 표시 조건 */
.nav:hover .mega-panel,
.nav:focus-within .mega-panel {
  display: block;
  opacity: 1;
  visibility: visible;
}


.nav .menu > li:hover > a::after,
.nav .menu > li:focus-within > a::after,
.nav .menu > li.current-menu-item > a::after,
.nav .menu > li.current-menu-ancestor > a::after{
  width:100%;
}

/* 키보드 포커스 */
.nav a:focus, .auth-buttons a:focus{
  outline:2px solid #0073e6; outline-offset:2px;
}


/* ========== 공용 메가패널 ========== */
.mega-panel{
  position:absolute; 
	left:0; 
	right:0; 
	top: calc(100% + 24px);
  background:#fff; 
	border-top:2px solid #e9e9e9;
  box-shadow:0 12px 24px rgba(0,0,0,.08);
  padding:28px 0;
  display:none; opacity:0; visibility:hidden;
  
  transition-property: opacity, transform, visibility;
  transition-duration: .22s, .22s, 0s;
  transition-timing-function: ease, ease, linear;
  transition-delay: .5s, .5s, .72s; /* ← "유지 0.5초" 핵심 */
}

/* 네 가지 트리거: nav에 hover/focus-within 되면 패널 노출 */
.nav:hover > .mega-panel,
.nav:focus-within > .mega-panel,
.nav .menu > li:hover ~ .mega-panel,
.nav .menu > li:focus-within ~ .mega-panel{
  display:block; opacity:1; visibility:visible;
}

/* 메가패널 내부 그리드 */

/* 실제 링크/목록에 직접 적용 */
.site-header .mega-panel .mega-inner ul li,
.site-header .mega-panel .mega-inner ul li a {
  font-size: var(--kegm-mega-size) !important;
  line-height: var(--kegm-mega-line) !important;
  font-weight: 470;
  letter-spacing: -0.012em;
}

.mega-inner{
  max-width:1200px; margin:0 auto; padding:0 32px;
  display:grid; grid-template-columns:repeat(4,1fr); gap:30px;
}
.mega-inner section ul{ list-style:none;
	margin:0; padding:0;
}

.mega-inner section li{ margin:0 0 6px; }

.mega-inner section a{
  color:#333; 
	text-decoration:none;
  font-size:var(--kegm-mega-size);
  line-height:var(--kegm-mega-line);
  transition:color .2s ease;
}
.mega-inner section a:hover{ color:#0073e6; }

/* 섹션 그룹 간 미세 구분선(선택) */
.mega-inner section{ padding-right:12px; }
.mega-inner section:not(:last-child){ border-right:1px solid #f0f0f0; }

/* === [Fix 1] 드롭 이펙트 기준값 명시 + 레이어 고정 (깜빡임/점프 방지) === */
.mega-panel{

  will-change: transform, opacity;    /* 스크롤 중 리페인트 깜빡임 감소 */
  backface-visibility: hidden;
  pointer-events: none;               /* 닫힘 상태에서 이벤트 차단 */
}

/* 열림 상태: 즉시 보이게 (닫힘 딜레이 제거), 포인터 허용 */
.nav:hover .mega-panel,
.nav:focus-within .mega-panel,
.nav:has(.mega-panel:hover) .mega-panel{
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;

  /* === [Fix 2] 열릴 때는 지연 0으로 재설정 (열림이 0.5s 지연되지 않도록) === */
  transition-delay: 0s, 0s, 0s;
}

/* === [Fix 3] 패널 위에 마우스가 있어도 열린 상태 유지 (스크롤 중 깜빡임 방지) === */
/* :has() 지원 브라우저(Chrome/Safari/Firefox 121+) */
.nav:has(.mega-panel:hover) .mega-panel{
  opacity: 1;
  visibility: visible;
}


/* ===== Mega Panel 투명 버퍼 (위/아래) ===== */
.mega-panel{
  /* 필요하면 원하는 값으로만 바꿔 쓰세요 */
  --buffer-top: 50px;      /* 패널 '위쪽' 버퍼 높이 */
  --buffer-bottom: 30px;   /* 패널 '아래쪽' 버퍼 높이 */
  position: absolute;      /* 기존과 동일 */
}

/* 위쪽 버퍼: 패널 위의 빈 공간도 호버로 인식 */
.mega-panel::before{
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: calc(var(--buffer-top) * -1);
  height: var(--buffer-top);
  background: transparent;      /* 완전 투명 */
  pointer-events: none;         /* 기본은 비활성화 */
}

/* 아래쪽 버퍼: 패널 하단 경계에서도 유지 */
.mega-panel::after{
  content: "";
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--buffer-bottom) * -1);
  height: var(--buffer-bottom);
  background: transparent;
  pointer-events: none;
}

/* 패널이 '열림/유지' 상태일 때만 버퍼들이 호버를 받아 유지되도록 */
.nav:hover .mega-panel::before,
.nav:focus-within .mega-panel::before,
.nav:has(.mega-panel:hover) .mega-panel::before,
.nav:hover .mega-panel::after,
.nav:focus-within .mega-panel::after,
.nav:has(.mega-panel:hover) .mega-panel::after{
  pointer-events: auto;
}

/* --- [1] 메가패널 상단 구분선 제거 --- */
.mega-panel{
  border-top: none !important;
}
/* ===== 메인 메뉴 ↔ 메가패널 텍스트 연동 강조 =====
   1: 교회소개 / 2: 설교 / 3: 훈련·양육 / 4: 교회부서
*/
:root{
  --kegm-accent:#0b5bd3;
}

/* 1. 교회소개 */
.nav:has(.menu > li:nth-child(1):hover) .mega-inner section:nth-child(1) a,
.nav:has(.menu > li:nth-child(1):focus-within) .mega-inner section:nth-child(1) a{
  color: var(--kegm-accent) !important;
  font-weight: 520;
}

/* 2. 설교 */
.nav:has(.menu > li:nth-child(2):hover) .mega-inner section:nth-child(2) a,
.nav:has(.menu > li:nth-child(2):focus-within) .mega-inner section:nth-child(2) a{
  color: var(--kegm-accent) !important;
  font-weight: 520;
}

/* 3. 훈련·양육 */
.nav:has(.menu > li:nth-child(3):hover) .mega-inner section:nth-child(3) a,
.nav:has(.menu > li:nth-child(3):focus-within) .mega-inner section:nth-child(3) a{
  color: var(--kegm-accent) !important;
  font-weight: 520;
}

/* 4. 교회부서 */
.nav:has(.menu > li:nth-child(4):hover) .mega-inner section:nth-child(4) a,
.nav:has(.menu > li:nth-child(4):focus-within) .mega-inner section:nth-child(4) a{
  color: var(--kegm-accent) !important;
  font-weight: 520;
}

/* ===== Desktop Menu Polish (Institutional Tone) ===== */
@media (min-width: 993px) {
  :root {
    --kegm-mega-open-delay: .2s;
  }

  .header-main {
    max-width: 1240px;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .header-main .nav {
    position: relative;
    margin-left: 20px;
    padding: 4px 6px;
    border: 1px solid #edf2f8;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: none;
  }

  .nav .menu {
    gap: clamp(14px, 2vw, 24px);
  }

  .nav .menu > li > a {
    padding: 8px 16px;
    border-radius: 999px;
    color: #16345c;
    font-weight: 650;
    font-size: clamp(14px, 0.9vw, 16px);
    letter-spacing: -0.015em;
    line-height: 1.3;
    word-break: keep-all;
  }

  .nav .menu > li > a::after {
    display: none;
  }

  .nav .menu > li > a:hover,
  .nav .menu > li:focus-within > a {
    color: var(--kegm-brand-700);
    background: #f1f6fc;
  }

  .nav .menu > li.current-menu-item > a,
  .nav .menu > li.current-menu-ancestor > a {
    background: #edf4fc;
    color: #0c3c78;
  }

  .nav::after {
    height: 18px;
    pointer-events: auto;
  }

  .mega-panel {
    display: block;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    width: auto;
    border: 1px solid #dce6f2 !important;
    border-radius: 20px;
    box-shadow: 0 20px 36px rgba(15, 23, 42, 0.12);
    padding: 0;
    overflow: hidden;
    background: #ffffff;
    transform: translateY(8px);
    opacity: 0;
    visibility: hidden;
    pointer-events: auto;
    transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s;
  }

  .mega-inner {
    max-width: 100%;
    padding: 22px;
    gap: 14px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    background: #ffffff;
  }

  .mega-inner section {
    border-right: 0 !important;
    padding: 16px 16px;
    border: 1px solid #e6edf5;
    border-radius: 14px;
    background: #fbfdff;
  }

  .mega-inner section li {
    margin: 0 0 8px;
  }

  .mega-inner section a {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 6px;
    border-radius: 8px;
    color: #1f3f67;
    font-size: clamp(13px, 0.84vw, 15px);
    line-height: 1.42;
    font-weight: 500;
    word-break: keep-all;
    overflow-wrap: normal;
    white-space: nowrap;
    transition: color .2s ease, background-color .2s ease;
  }

  .mega-inner section a:hover {
    color: var(--kegm-brand-700);
    background: #eef4fb;
  }

  .nav:hover .mega-panel,
  .nav:has(.mega-panel:hover) .mega-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    transition-delay: var(--kegm-mega-open-delay), var(--kegm-mega-open-delay), var(--kegm-mega-open-delay);
  }

  .nav:focus-within .mega-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    transition-delay: 0s;
  }

  .mega-panel:hover {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
  }
}


/* ====== 기본(데스크톱)에서는 햄버거/드로어 전부 숨김 ====== */
.kegm-hamburger, .kegm-overlay, .kegm-drawer { display: none; }

/* ====== 모바일(≤992px) 전용 ====== */
@media (max-width: 992px){

  html:has(#kegm-nav-toggle:checked),
  body:has(#kegm-nav-toggle:checked){
    overflow: hidden !important;
    height: 100dvh;
    overscroll-behavior: none;
  }

  /* 1) 데스크톱 메뉴/메가패널 숨기고, 로고 아래 세로 레이아웃 */

  .header-main {
    flex-direction: row;      /* 여전히 같은 줄 유지 */
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
  }
	
  .site-logo img{ height: 64px; }
  .header-main .nav{ display: none !important; } /* 데스크톱 메뉴 숨김 */
  .mega-panel{ display: none !important; opacity:0 !important; visibility:hidden !important; }

  /* 2) 햄버거 버튼(오른쪽 위) */
  .kegm-hamburger{
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px; height: 30px;
    cursor: pointer;
    margin-left: auto;           /* 로고 줄의 오른쪽 끝 */
  }
  .kegm-hamburger span{
    display: block; height: 2px; width: 24px;
    background: #1f2937; border-radius: 2px;
  }

  /* 3) 어두운 오버레이 */
  .kegm-overlay{
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    opacity: 0; visibility: hidden;
    transition: opacity .25s ease, visibility .25s ease;
    z-index: 999;
    display: block;
  }

/* ===== 왼쪽 슬라이드 네비게이션 (세미 다크 플랫 버전) ===== */
.kegm-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  height: 100dvh;
  max-height: 100dvh;
  width: min(80vw, 340px);
  background: #0C3C78;                /* 어두운 남색/회색톤 */
  color: #f8fafc;                     /* 거의 흰색 텍스트 */
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 6px 0 24px rgba(0,0,0,0.35);
}

  /* 열기 상태(체크박스 true) */
  #kegm-nav-toggle:checked ~ .kegm-overlay{
    opacity: 1; visibility: visible;
  }
	
  #kegm-nav-toggle:checked ~ .kegm-drawer{
    transform: translateX(0);
  }

  /* 5) 드로어 내부 스타일 */
  .kegm-drawer-head{
		position:relative;
    display: flex; 
		padding: 12px 48px 47px 18px;  
  }
	
  .kegm-close{
  position: absolute;      
  right: 18px;    
		border: none;
		background: #111827;
		
		color: #fff;
    font-size: 26px; line-height: 1; cursor: pointer;
  }
	
  .kegm-close:hover{ background: rgba(255,255,255,.18);
		  border-radius: 4px;
	}

  .kegm-drawer-nav{
    padding: 6px 20px calc(18px + env(safe-area-inset-bottom)) 22px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    display: grid; gap: 16px;
  }
  .kegm-drawer-nav details{
    background: transparent; border-radius: 10px; padding: 10px 8px;
  }
	
  .kegm-drawer-nav summary{
    list-style: none; cursor: pointer;
    font-size: var(--kegm-mobile-summary-size); font-weight: 620; color: #fff;
    line-height: 1.35;
    letter-spacing: -0.016em;
    display: flex; align-items: center; justify-content: space-between;
  }
	
  .kegm-drawer-nav summary::-webkit-details-marker{ display: none; }
  .kegm-drawer-nav summary::after{ content: "▾"; font-size: 16px; opacity: .9; }
  .kegm-drawer-nav details[open] summary::after{ content: "▴"; }

  .kegm-drawer-nav ul{
    margin: 10px 0 0 4px; padding: 0 0 0 12px;
    list-style: none; display: grid; gap: 10px;
  }
	
  .kegm-drawer-nav a{
    color: rgba(255,255,255,.95); text-decoration: none;
    font-size: var(--kegm-mobile-link-size); font-weight: 550;
    line-height: 1.45;
    letter-spacing: -0.01em;
  }
  .kegm-drawer-nav a:hover{ text-decoration: underline; }

  /* 6) 로그인 pill: 모바일에선 메뉴 아래에 자연스럽게 */
  .header-top{
    position: static; transform: none; right: auto; top: auto;
    margin-top: 4px;
  }
}
