/* ==========================================================================
   Donastar Mobile Styles
   모바일 디바이스(768px 이하)에서의 반응형 오버라이드

   이 파일은 head-common.html에서 마지막으로 로드되므로 Tailwind 유틸리티보다
   specificity가 같거나 높다. !important 사용 금지 — 필요하다고 느껴진다면
   인라인 style("...") 충돌인지부터 의심하라.
   ========================================================================== */

/* ── 햄버거 메뉴 버튼 (768px 이상에서는 숨김) ── */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  z-index: var(--z-modal);
}

.hamburger-btn span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-white);
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* 햄버거 → X 변환 */
.hamburger-btn.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-btn.active span:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ── "PC 전용" 안내 (기본 숨김) ── */
.mobile-desktop-only {
  display: none;
}

/* ── 가이드 드로어 토글 버튼·스크림 (기본 숨김; 모바일에서만 노출 — .hamburger-btn 와 동일 패턴) ── */
.guide-nav-toggle,
.guide-drawer-backdrop {
  display: none;
}

/* ==========================================================================
   768px 이하 — 모바일 레이아웃
   ========================================================================== */
@media (max-width: 768px) {

  /* ── 햄버거 메뉴 표시 ── */
  .hamburger-btn {
    display: flex;
    order: 2;
  }

  /* ── 네비게이션 링크 기본 숨김 ── */
  .nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-chrome);
    padding: 1rem 0;
    gap: 0;
    z-index: var(--z-header);
    box-shadow: 0 4px 12px var(--color-shadow-strong);
  }

  .nav-links.mobile-open {
    display: flex;
  }

  .nav-links li {
    text-align: center;
  }

  .nav-links li a {
    display: block;
    padding: 14px 2rem;
    font-size: var(--text-lg);
    transition: background 0.2s;
  }

  .nav-links li a:hover {
    background: var(--color-white-10);
    transform: none;
  }

  .nav-links li a::after {
    display: none;
  }

  /* ── 네비게이션 레이아웃 ── */
  .nav {
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    position: relative;
  }

  .logo {
    order: 1;
  }

  .logo img {
    height: 60px;
  }

  .page-donastar .logo img {
    height: 70px;
  }

  #auth-area {
    order: 3;
    margin-right: 0;
  }

  .cta-btn {
    padding: 0.5rem 1rem;
    font-size: var(--text-md);
  }

  /* ── 헤더 높이 정상화 ── */
  .header {
    padding: 0.5rem 0;
  }

  /* ── 모바일 body 스크롤 허용 ── */
  body.overflow-hidden {
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* ── main-container: Grid 레이아웃이 처리하므로 margin-top 불필요 ── */
  .main-container {
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* ── 사이드바 숨김 (인라인 스타일 오버라이드 — !important 필수) ── */
  .w-64.bg-white.shadow-lg,
  div[style*="position:fixed"][style*="left:0"][style*="height:100vh"] {
    display: none !important;
  }

  /* ── 유저 드롭다운 위치 보정 (header.html의 인라인 style 오버라이드 — !important 필수) ── */
  #user-dropdown {
    left: auto !important;
    right: 0 !important;
    transform: none !important;
  }

  /* ── "PC 전용" 안내 표시 ── */
  .mobile-desktop-only {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 150px);
    padding: 2rem;
    text-align: center;
  }

  /* ── 데스크탑 전용 콘텐츠 숨김 ──
     studio 페이지(body.overflow-hidden)는 layout.css 의
     `body.overflow-hidden .desktop-only-content{display:flex}`(특정도 0,2,1)를 이겨야 한다.
     동일 특정도 선택자를 함께 둬 mobile.css 後로드로 승(재발 방지). 첫(bare) 선택자는
     overflow-hidden 없는 페이지(chat-memory 등)까지 커버 → !important·min-width 갭 불필요. */
  .desktop-only-content,
  body.overflow-hidden .desktop-only-content {
    display: none;
  }

  /* ── 사이드바 페이지(가이드·크레딧·프리미엄·계정): 모바일 레이아웃 ──
     데스크탑 좌측 보조 사이드바(가이드 목록·결제 안내 메뉴)는 모바일에서 숨긴다 —
     상단 햄버거 메뉴가 1차 내비라 중복. 사이드바를 숨기면 본문(flex-1)이 자동으로 전폭.
     body 100vh 락(:has(.main-container--scrollable))을 풀고 본문 내부 스크롤 영역을
     해제해, 중첩 스크롤 없이 자연스러운 페이지 스크롤로 만든다. */
  body:has(.sidebar-page) {
    height: auto;
  }

  .sidebar-page.main-container {
    height: auto;
    overflow: visible;
  }

  .sidebar-page .sidebar-container {
    display: none;
  }

  .sidebar-page .guide-content-area,
  .sidebar-page .flex-1.overflow-y-auto {
    overflow: visible;
  }

  .sidebar-page .guide-content-area {
    padding: 1rem;
    /* flex 자식이 콘텐츠 너비 밑으로 수축하도록 — 위 overflow:visible 가 flex min-width:auto
       바닥을 되살려, min-width:0 없으면 전폭 이미지가 컬럼을 뷰포트보다 넓게 밀어 본문이 잘린다. */
    min-width: 0;
  }

  .sidebar-page .guide-table {
    display: block;
    overflow-x: auto;
  }

  /* ── 가이드 페이지: 좌측 사이드바를 슬라이드 드로어로 ──
     위 `.sidebar-page .sidebar-container{display:none}`(0,2,0) 를 `.sidebar-page.guide-layout`(0,3,0)
     으로 이겨, 가이드에서만 사이드바를 오프캔버스 드로어로 되살린다(다른 sidebar-page 는 계속 숨김).
     사이드바 DOM 1개를 그대로 재사용 — #guide-nav-toggle 이 .open 을 토글(guide-page-top.html 인라인 스크립트). */
  .sidebar-page.guide-layout .sidebar-container {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 20rem);
    height: 100%;
    z-index: var(--z-modal);
    transform: translateX(-100%);
    /* 닫힘: 슬라이드 아웃이 끝난 뒤 숨겨, 화면 밖 사이드바 링크가 탭 포커스·가로 스크롤에 잡히지 않게 */
    visibility: hidden;
    transition: transform 0.28s ease, visibility 0s linear 0.28s;
  }

  .sidebar-page.guide-layout .sidebar-container.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.28s ease;
    box-shadow: 4px 0 24px var(--color-shadow-strong);
  }

  .sidebar-page.guide-layout #left-sidebar {
    height: 100%;
    overflow-y: auto;
  }

  /* 가이드 목록 열기 버튼 — fixed 헤더 바로 아래에 sticky 고정(top:0 이면 헤더 뒤로 가려짐) */
  .guide-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    position: sticky;
    top: var(--header-height);
    z-index: var(--z-sidebar);
    width: 100%;
    margin-bottom: 1rem;
    padding: 0.7rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-gray-300);
    border-radius: 10px;
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--color-brand);
    cursor: pointer;
  }

  /* 드로어 스크림 — 열렸을 때만 표시 */
  .guide-drawer-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--color-overlay-medium);
    z-index: calc(var(--z-modal) - 1);
  }

  /* ── 푸터 모바일 ── */
  .footer {
    padding: 2rem 1rem;
  }

  .footer-links {
    flex-direction: column;
    gap: 0.8rem;
  }

  /* ── .section-title 사용 비-홈 페이지(account 등)용. 홈은 donastar.html <style> 가 변수로 자체 통일(.platforms/.key-features 스코프) ── */
  .section-title {
    font-size: 1.6rem;
  }

  /* ── 로그인/인증 페이지 ── */
  .auth-container {
    padding: 24px;
    max-width: calc(100% - 2rem);
    border-radius: 16px;
  }

  .auth-header h1 {
    font-size: 1.6rem;
  }

  .auth-header p {
    font-size: var(--text-md);
  }

  /* ── Premium/Credit 페이지 ── */
  .plan-card {
    padding: 24px 12px;
  }

  .plan-card .plan-name {
    font-size: var(--text-2xl);
  }

  .plan-card .plan-price {
    font-size: var(--text-3xl);
  }

  .plan-card button {
    padding: 8px 20px;
    font-size: var(--text-md);
  }

  /* 본문 카드 패딩 축소 (credit/premium .info-card) */
  .info-card {
    padding: 20px;
  }

  /* ── Support 페이지 ── */
  .main-content {
    padding: 20px 0;
  }

  .page-header {
    margin-bottom: 1.5rem;
    padding: 1.2rem;
  }

  .page-header h1 {
    font-size: 1.6rem;
  }

  .page-header p {
    font-size: 0.95rem;
  }

  .tab-buttons {
    flex-direction: column;
  }

  .tab-btn {
    padding: 1rem;
    font-size: 0.95rem;
  }

  /* ── 모달 모바일 최적화 (인라인 style 오버라이드 — !important 필수) ── */
  div[style*="position:fixed"][style*="inset:0"] > div,
  div[style*="position: fixed"][style*="inset: 0"] > div {
    max-width: 90% !important;
    width: 90% !important;
    padding: 20px !important;
  }
}

/* ==========================================================================
   480px 이하 — 소형 모바일
   ========================================================================== */
@media (max-width: 480px) {
  .auth-container {
    padding: 20px;
  }

  .plan-card .plan-name {
    font-size: var(--text-xl);
  }

  .plan-card .plan-price {
    font-size: var(--text-2xl);
  }
}
