/* Mobile-first responsive optimizations */

@media (max-width: 768px) {
  body { font-size: 15px; }

  .container { padding: 0 16px; }

  .site-header .container { padding: 0 16px; }
  .topbar { display: none; }
  /* 헤더: 모바일에서 솔리드 화이트(반투명+블러로 인한 그라데이션/배경비침 제거), 라인 없음 */
  .site-header .mainbar,
  body.home .mainbar,
  body.home #siteHeader.scrolled .mainbar {
    background: #fff; backdrop-filter: none; -webkit-backdrop-filter: none;
    border-bottom: 0; box-shadow: none;
  }
  /* move quote + language inside the hamburger menu on mobile */
  .header-actions .btn-quote, .header-actions .lang-switcher { display: none; }
  .nav-mobile-extra { display: block; padding: 18px 20px 10px; }
  .nav-mobile-extra .nav-quote { display: block; text-align: center; background: var(--c-primary); color: #fff; padding: 13px; border: 0; border-radius: 6px; font-weight: 700; }
  .nav-mobile-extra .nav-quote:hover { color: #fff; text-decoration: none; }
  .nav-mobile-extra .nav-langs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
  .nav-mobile-extra .nav-langs a { padding: 8px 14px; border: 1px solid var(--c-line); border-radius: 6px; font-size: 14px; color: var(--c-fg); }
  .nav-mobile-extra .nav-langs a.on { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
  .nav-mobile-extra .nav-langs a:hover { text-decoration: none; }
  .logo img { height: 32px; }
  .primary-nav {
    position: fixed; top: var(--header-h); left: 0; right: 0;
    flex-direction: column; gap: 0;
    background: #fff;
    padding: 8px 0;
    max-height: calc(100vh - var(--header-h));
    max-height: calc(100dvh - var(--header-h));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    transform: translateY(-110%);
    transition: transform .25s ease;
  }
  .primary-nav.open { transform: translateY(0); }
  /* mobile menu panel is always white → force dark text even on home (transparent header) */
  body.home .mainbar .primary-nav a,
  body.home .mainbar .nav-item > a { color: var(--c-fg); }
  body.home .mainbar .has-dropdown > a::after { color: var(--c-muted); }
  /* keep red button / active language text white */
  body.home .mainbar .nav-mobile-extra .nav-quote { color: #fff; }
  body.home .mainbar .nav-mobile-extra .nav-langs a.on { color: #fff; }
  .primary-nav a { padding: 14px 20px; border-bottom: 1px solid var(--c-line-2); font-size: 16px; }
  .primary-nav a:last-child { border-bottom: 0; }

  /* nav dropdowns become inline expanded sections on mobile */
  .nav-item { width: 100%; }
  .nav-item > a { padding: 14px 20px; }
  .has-dropdown > a::after { margin-left: auto; }
  .nav-item .dropdown {
    position: static; transform: none; opacity: 1; visibility: visible;
    box-shadow: none; border: 0; border-radius: 0; padding: 0; min-width: 0;
    background: var(--c-line-2);
    max-height: 0; overflow: hidden;               /* 기본 접힘(아코디언) */
    transition: max-height .3s ease;
  }
  .nav-item.open .dropdown { max-height: 640px; }  /* 대메뉴 탭 시 펼침 */
  .nav-item .dropdown a { padding: 12px 20px 12px 38px; border-bottom: 1px solid #fff; font-size: 15px; }
  .nav-item .dropdown .dd-head { display: block; padding: 10px 20px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-muted); }
  /* 대메뉴 화살표: 펼침 시 회전 */
  .has-dropdown > a::after { transition: transform .25s ease; }
  .nav-item.open.has-dropdown > a::after { transform: rotate(180deg); }

  .nav-toggle { display: flex; }

  .hero { padding: 56px 0 40px; }
  .hero-title { font-size: 34px; }
  .hero-subtitle { font-size: 16px; }

  .two-col { grid-template-columns: 1fr; gap: 16px; padding: 32px 16px; }
  .feature-grid { grid-template-columns: repeat(3, 1fr); padding: 32px 16px 56px; gap: 10px; }
  .feature-tile { padding: 18px 8px; }
  .ft-icon { font-size: 22px; }
  .ft-title { font-size: 12px; }

  .board-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .board-title { font-size: 22px; }
  .board-tools { flex-direction: column; align-items: stretch; }
  .search { width: 100%; }
  .search input { flex: 1; }

  .board-table .meta-col:nth-child(n+5) { display: none; }
  .board-table th, .board-table td { font-size: 13px; padding: 10px 6px; }

  .photo-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  .calendar td { min-height: 70px; height: 70px; padding: 4px; }
  .calendar td .d { font-size: 12px; }
  .cal-event { font-size: 10px; padding: 1px 4px; }

  .post-view { padding: 24px 16px 60px; }
  .post-head h1 { font-size: 22px; }
  .post-body { font-size: 15px; padding: 16px 0; }

  .write-form .row { grid-template-columns: 1fr; }

  /* Popup mobile: image auto-resize, centered */
  .popup-stack {
    left: 16px !important; right: 16px !important; top: 50% !important;
    transform: translateY(-50%) !important;
    align-items: center;
  }
  .popup {
    width: calc(100vw - 32px) !important; max-width: 480px;
    margin: 0 auto;
  }
  .popup img { width: 100%; height: auto; }

  /* 푸터: margin-top:0 페이지(홈·격자페이지)에서 로고가 본문에 붙어 보이는 문제 —
     흰틈 없이 다크 푸터 안쪽 위 여백만 키워 로고에 숨 쉴 공간 확보 */
  .footer-top { flex-direction: column; align-items: center; text-align: center; gap: 18px; padding: 44px 18px 30px; }
  .footer-logo img { height: 58px; }
  .footer-company { text-align: center; }
  .footer-company p { font-size: 13px; }

  /* 푸터 사이트맵: 모바일 1열 스택 + 컬럼 제목 탭 시 하위메뉴 아코디언 */
  .footer-sitemap { grid-template-columns: 1fr; gap: 0; }
  .footer-sitemap .fcol h4 { margin: 0; padding: 16px 4px; position: relative; cursor: pointer; border-top: 1px solid rgba(255,255,255,.1); }
  .footer-sitemap .fcol:last-child h4 { border-bottom: 1px solid rgba(255,255,255,.1); }
  .footer-sitemap .fcol h4::after { content: ""; position: absolute; right: 8px; top: 50%; width: 8px; height: 8px;
    border-right: 2px solid rgba(255,255,255,.5); border-bottom: 2px solid rgba(255,255,255,.5);
    transform: translateY(-75%) rotate(45deg); transition: transform .25s ease; }
  .footer-sitemap .fcol.open h4::after { transform: translateY(-25%) rotate(-135deg); }
  /* 하위 없는 컬럼(예: 리니어스테이지)은 화살표 숨김 */
  .footer-sitemap .fcol:not(:has(ul)) h4::after { display: none; }
  .footer-sitemap .fcol ul { max-height: 0; overflow: hidden; transition: max-height .3s ease; }
  .footer-sitemap .fcol.open ul { max-height: 440px; padding-bottom: 8px; }
  .footer-sitemap .fcol li { margin: 0; }
  .footer-sitemap .fcol li a { display: block; padding: 10px 4px 10px 14px; font-size: 14px; }

  /* 푸터 하단바(카피라이트): 중앙 정렬 + 하단 여백 */
  .site-footer .footer-bottom { flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 18px 20px 34px; }
}

@media (max-width: 480px) {
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
  .calendar { font-size: 11px; }
  .calendar td { min-height: 56px; height: 56px; }
}

/* iOS notch / safe-area */
@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Reduce motion respect */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
