/* =============================================================
   三藏閣 — 모바일 디자인
   -------------------------------------------------------------
   원칙
     · 헤더 = 로고 + 검색 아이콘만
     · 메뉴 = 하단 탭바
     · 화면 전환 = 풀스크린 슬라이드 느낌
     · 단어 탭 = 새 화면 (bottom sheet 아님)
     · 다크 모드 = prefers-color-scheme 자동
   ============================================================= */

/* ============================================================
   1. 헤더 — 극단적 최소
   ============================================================ */
@media (max-width: 767px) {
  .site-header {
    background: var(--paper);
    border-bottom: 1px solid var(--rule-faint);
    transition: transform 240ms ease;
  }
  .site-header.is-hidden { transform: translateY(-100%); }

  .site-header__inner {
    height: 52px;
    padding: 0 16px;
    gap: 0;
  }
  .site-header__brand {
    flex: 1;
    justify-content: flex-start;
    gap: 8px;
  }
  .site-header__brand .han {
    font-size: 17px;
    letter-spacing: 0.12em;
  }
  .site-header__brand .kr { display: none; }

  /* 데스크톱 요소 모두 숨김 */
  .site-header__sep,
  .site-header__nav,
  .site-header__search-trigger { display: none; }
  .site-header__spacer { display: none; }

  /* 검색만 아이콘 */
  .site-header__icon-btn-search {
    display: inline-flex;
    margin-left: auto;
    width: 40px;
    height: 40px;
  }

  /* 더보기 드롭다운은 모바일에서 비활성 — 하단 탭바로 대체 */
  .site-header__more-backdrop,
  .site-header__more { display: none !important; }
}

/* ============================================================
   2. 홈 — 모바일 레이아웃
   ============================================================ */
@media (max-width: 767px) {
  .home__inner {
    padding: 24px 16px calc(80px + env(safe-area-inset-bottom));
  }

  /* Hero */
  .home-hero {
    padding-bottom: 24px;
    margin-bottom: 24px;
    gap: 16px;
  }
  .home-hero__eyebrow {
    font-size: 9.5px;
    letter-spacing: 0.32em;
    padding-top: 10px;
  }
  .home-hero__title {
    font-size: clamp(28px, 8vw, 36px);
    line-height: 1.22;
  }
  .home-hero__sub {
    font-size: 14px;
    line-height: 1.7;
  }
  .home-hero__meta {
    gap: 28px;
    margin-top: 12px;
    padding-top: 16px;
  }
  .home-hero__meta-val { font-size: 18px; }
  .home-hero__meta-key { font-size: 9px; letter-spacing: 0.32em; }

  /* 세 대장경 직진 카드 */
  .home-canons { margin-bottom: 32px; }
  .home-canons__head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding-bottom: 12px;
  }
  .home-canons__eyebrow { font-size: 12px; }
  .home-canons__sub { font-size: 11.5px; }
  .home-canons__grid { grid-template-columns: 1fr; }
  .home-canon {
    border-right: 0;
    border-bottom: 1px solid var(--rule-soft);
    padding: 18px 8px;
    gap: 6px;
  }
  .home-canon:last-child { border-bottom: 0; }
  .home-canon__num { font-size: 11.5px; letter-spacing: 0.24em; }
  .home-canon__zh { font-size: 28px; margin-top: 4px; }
  .home-canon__kr { font-size: 16px; margin-top: 4px; }
  .home-canon__tag { gap: 6px; }
  .home-canon__tag span:first-child { font-size: 12px; }
  .home-canon__tag-en { font-size: 9.5px; letter-spacing: 0.24em; }
  .home-canon__meta {
    font-size: 10px;
    letter-spacing: 0.18em;
    padding-top: 8px;
    margin-top: 6px;
  }
  .home-canon__cta { font-size: 12px; margin-top: 8px; }

  /* 통합 검색 */
  .home-search { margin-bottom: 32px; }
  .home-search__form {
    height: 52px;
    padding: 0 12px;
  }
  .home-search__form > svg { width: 18px; height: 18px; }
  .home-search__input { font-size: 14.5px; }
  .home-search__submit {
    display: none;          /* 모바일은 엔터/리턴키로 */
  }
  .home-search__chips {
    margin-top: 12px;
    padding-left: 0;
    gap: 10px;
  }
  .home-search__chips-label {
    flex-basis: 100%;
    margin-bottom: 4px;
  }
  .home-search__chip { font-size: 13px; }
  .home-search__chip-tip { display: none; }

  /* 4 핵심 카드 — 세로 스택 + 가로 컴팩트 */
  .home-core {
    grid-template-columns: 1fr;
    margin-bottom: 32px;
  }
  .home-core__card {
    border-right: 0;
    border-bottom: 1px solid var(--rule-soft);
    padding: 22px 12px 20px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    align-items: baseline;
  }
  .home-core__card:last-child { border-bottom: 0; }
  .home-core__card-num {
    flex-basis: 28px;
    font-size: 11px;
    letter-spacing: 0.18em;
    color: var(--ink-dim);
  }
  .home-core__card-zh {
    font-size: 28px;
    margin-top: 0;
    flex: 1;
    line-height: 1;
  }
  .home-core__card-en {
    flex-basis: 100%;
    font-size: 10px;
    letter-spacing: 0.24em;
    margin-top: 0;
  }
  .home-core__card-kr {
    flex-basis: 100%;
    font-size: 16px;
    font-weight: 500;
    margin-top: 4px;
  }
  .home-core__card-desc {
    flex-basis: 100%;
    font-size: 13px;
    line-height: 1.65;
    margin: 6px 0 0;
  }
  .home-core__card-meta {
    flex-basis: 100%;
    padding-top: 10px;
    border-top: 1px solid var(--rule-faint);
    margin-top: 10px;
    font-size: 10px;
    letter-spacing: 0.18em;
  }
  .home-core__card-cta {
    flex-basis: 100%;
    margin-top: 8px;
    font-size: 12px;
  }

  /* 추천 경로 */
  .home-paths { margin-bottom: 32px; }
  .home-paths__head { margin-bottom: 16px; padding-bottom: 12px; }
  .home-paths__title { font-size: 22px; }
  .home-paths__sub { font-size: 13px; }

  .home-paths__item {
    grid-template-columns: 28px 1fr;
    gap: 12px;
    padding: 16px 4px;
  }
  .home-paths__item:hover { padding-left: 4px; }
  .home-paths__item-num { font-size: 11.5px; }
  .home-paths__item-eyebrow { font-size: 10.5px; letter-spacing: 0.24em; }
  .home-paths__item-title { font-size: 16px; line-height: 1.3; }
  .home-paths__item-sub { font-size: 12.5px; line-height: 1.55; }
  .home-paths__item-parts { display: none; }

  /* 최근 업데이트 */
  .home-updates__item {
    grid-template-columns: 56px 1fr auto;
    gap: 10px;
    padding: 12px 4px;
  }
  .home-updates__item:hover { padding-left: 4px; }
  .home-updates__kind {
    font-size: 10.5px;
    padding: 2px 6px;
    letter-spacing: 0.12em;
  }
  .home-updates__title { font-size: 13.5px; }
  .home-updates__sub { display: none; }
  .home-updates__date { font-size: 10.5px; }
}

/* ============================================================
   3. 백과 — 모바일
   ============================================================ */
@media (max-width: 767px) {
  .ency__hero-inner { padding: 24px 16px; }
  .ency__hero-title { font-size: 26px; margin-bottom: 8px; }
  .ency__hero-sub { font-size: 13px; line-height: 1.65; margin-bottom: 16px; }
  .ency__search {
    padding: 0 12px;
    height: 48px;
    border-radius: 2px;
  }
  .ency__search input { font-size: 14px; }

  .ency__inner {
    padding: 16px 12px calc(80px + env(safe-area-inset-bottom));
  }

  .ency__cats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow-x: visible;
    margin-bottom: 16px;
  }
  .ency__cat {
    padding: 6px 10px !important;
    font-size: 12px !important;
    border-radius: 2px !important;
  }
  .ency__cat-han { font-size: 11px !important; }
  .ency__cat-count { font-size: 10px !important; padding-left: 4px !important; }

  .ency__grid { grid-template-columns: 1fr !important; gap: 8px !important; }
  .ency-card { padding: 14px 14px !important; }
  .ency-card__title-han { font-size: 18px !important; }
  .ency-card__title-kr { font-size: 16px !important; }
  .ency-card__one { font-size: 13px !important; line-height: 1.55 !important; }

  /* 항목 상세 */
  .ency-detail__inner { padding: 16px 16px 80px; }
  .ency-detail__back {
    margin-bottom: 16px;
    padding: 6px 0;
    font-size: 13px;
  }
  .ency-detail__title-kr { font-size: 32px; }
  .ency-detail__title-han { font-size: 18px; }
  .ency-detail__title-romans { gap: 14px; font-size: 12.5px; flex-direction: column; }
  .ency-detail__title-romans span { gap: 6px; }

  .ency-detail__grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
  .ency-detail__side { order: 2; padding-top: 16px; border-top: 1px solid var(--rule-soft); }

  /* 학술 시그널 — 모바일 컴팩트 */
  .sch-version {
    grid-template-columns: 1fr 1fr;
  }
  .sch-version__cell {
    border-right: 1px solid var(--rule-faint);
    border-bottom: 1px solid var(--rule-faint);
    padding: 12px 14px;
  }
  .sch-version__cell:nth-child(2n) { border-right: 0; }
  .sch-version__cell:nth-last-child(-n+2) { border-bottom: 0; }

  .sch-multi { padding: 14px 16px; }
  .sch-multi__list { gap: 4px 16px; }
  .sch-multi__val { font-size: 14.5px; }
  .sch-multi__val--tib { font-size: 17px; }
  .sch-multi__key { font-size: 9.5px; letter-spacing: 0.24em; }

  .sch-def { padding: 14px 16px; }
  .sch-def__body { font-size: 15px; line-height: 1.7; }

  .sch-lic__row { grid-template-columns: 68px 1fr; gap: 8px; }
}

/* ============================================================
   4. 연구 — 모바일
   ============================================================ */
@media (max-width: 767px) {
  .research__hero-inner { padding: 28px 16px; }
  .research__hero-title { font-size: 28px; }
  .research__hero-sub { font-size: 13.5px; line-height: 1.7; }
  .research__hero-meta { gap: 20px; margin-top: 20px; padding-top: 16px; }
  .research__hero-meta-val { font-size: 18px; }

  .research__inner { padding: 24px 16px calc(80px + env(safe-area-inset-bottom)); }
  .research__section { margin-bottom: 32px; }
  .research__section-head { flex-direction: column; align-items: flex-start; gap: 8px; padding-bottom: 12px; }
  .research__section-title { font-size: 22px; }

  .research__tabs { gap: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .research__tab { font-size: 12px; }

  .research__series { grid-template-columns: 1fr; }
  .research__series-card { border-right: 0; padding: 20px 16px; }
  .research__series-card.is-accent { padding-left: 13px; }
  .research__series-title { font-size: 18px; }
  .research__series-sub { font-size: 13px; }
  .research__series-desc { font-size: 13px; line-height: 1.65; }
  .research__series-meta { flex-wrap: wrap; }
  .research__series-prog { width: 100%; }
  .research__series-prog-bar { max-width: none; }
  .research__series-cta { padding-top: 6px; }

  .research__note {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 14px 6px;
  }
  .research__note-date { font-size: 10.5px; letter-spacing: 0.12em; }
  .research__note-series { font-size: 11px; letter-spacing: 0.06em; }
  .research__note-title { font-size: 14.5px; line-height: 1.45; }
  .research__note-parts { font-size: 10px; }

  .research__legal { grid-template-columns: 1fr; gap: 20px; }
}

/* ============================================================
   5. 사전 — 모바일 (knowledge.css 기본 위 보강)
   ============================================================ */
@media (max-width: 767px) {
  .dict__inner { padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); }
  .dict__search { height: 48px; }
  .dict__grid { grid-template-columns: 1fr; }
}

/* ============================================================
   6. 하단 탭바 — 5 탭 (홈/읽기/백과/사전/연구)
   적색 액티브 시그너처
   ============================================================ */
@media (max-width: 767px) {
  .mobile-tabbar {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: saturate(140%) blur(14px);
    -webkit-backdrop-filter: saturate(140%) blur(14px);
    border-top: 1px solid var(--rule-soft);
    box-shadow: 0 -2px 12px -8px rgba(15, 15, 14, 0.12);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-tabbar__btn {
    position: relative;
    width: 100%;
    min-width: 0;
    padding: 9px 2px 8px !important;
    font-size: 9.5px !important;
    letter-spacing: 0.04em;
    transition: color 120ms ease;
  }
  .mobile-tabbar__btn svg {
    stroke-width: 1.4 !important;
    width: 22px !important;
    height: 22px !important;
    opacity: 0.7;
    transition: opacity 120ms ease;
  }
  .mobile-tabbar__btn span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
  }
  .mobile-tabbar__btn.is-active {
    color: var(--ink) !important;
  }
  .mobile-tabbar__btn.is-active svg { opacity: 1; }
  .mobile-tabbar__btn.is-active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 36%;
    right: 36%;
    height: 2px;
    background: var(--signal);
    border-radius: 0 0 1px 1px;
  }

  /* 라이브러리 등에 하단 탭바 공간 확보 (knowledge.css 의 셀렉터 보강) */
  .app[data-route="library"],
  .app[data-route="encyclopedia"],
  .app[data-route="dictionary"],
  .app[data-route="explore"],
  .app[data-route="about"],
  .app[data-route="research"],
  .app[data-route="releases"] {
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }
}

/* ============================================================
   7. 푸터 — 모바일에서 하단 탭바와 겹치지 않게
   ============================================================ */
@media (max-width: 767px) {
  .site-footer { padding: 32px 16px 80px; }
  .site-footer__inner { grid-template-columns: 1fr; gap: 24px; }
  .site-footer__legal { flex-direction: column; gap: 6px; }
}

/* ============================================================
   8. 다크 모드 — 자동 (밤 독서)
   ------------------------------------------------------------
   학술지 톤을 지키되 종이를 잉크로, 잉크를 종이로 뒤집기.
   적색 시그너처는 약간 밝게 조정.
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #0f0e0c;
    --paper-soft:   #181715;
    --paper-deep:   #1d1c19;
    --paper-edge:   #2a2823;
    --chrome:       #161513;
    --chrome-soft:  #1e1d1a;

    --ink:          #f0eee7;
    --ink-soft:     #d4d1c8;
    --ink-mute:     #8b8780;
    --ink-dim:      #5e5a55;

    --rule:         #3a3833;
    --rule-soft:    #2a2823;
    --rule-faint:   #211f1c;

    --signal:       #d65656;
    --signal-soft:  #e88080;
    --signal-wash:  rgba(214, 86, 86, 0.10);
  }

  body { background: var(--paper); }

  /* 칸논 표지 — 다크에서는 한 톤 밝게 (배경 대비 확보) */
  .canon-card__cover { background: #232220; }
  .entry-row__chip { background: #232220; }

  /* 헤더 — 다크 톤 */
  .site-header {
    background: rgba(15, 14, 12, 0.94);
  }
  .mobile-tabbar {
    background: rgba(15, 14, 12, 0.96) !important;
  }

  /* 검색 모달 등 backdrop */
  .sch-cite-modal__backdrop {
    background: rgba(0, 0, 0, 0.55);
  }
}

/* ============================================================
   9. 초소형 화면 (≤ 360)
   ============================================================ */
@media (max-width: 360px) {
  .home-hero__title { font-size: 26px; }
  .home-canon__zh { font-size: 24px; }
  .home-core__card-zh { font-size: 26px; }
  .ency-detail__title-kr { font-size: 28px; }
  .research__hero-title { font-size: 24px; }
}
