/* TaleNest Neuro — docs 레이아웃 셸 스타일
   docs-shell.js가 주입하는 .tn-topnav / .tn-layout / .tn-sidebar / .tn-content 용.
   body.tn-docs 일 때만 활성. 기존 .wrap 등 본문 스타일은 그대로 둔다. */

/* 로고 글씨체 — Sour Gummy (브랜드 로고용) */
@import url('https://fonts.googleapis.com/css2?family=Sour+Gummy:wght@500;700&display=swap');

/* 스킵 링크 — 키보드 포커스 시에만 표시 (웹접근성) */
.tn-skip {
  position: fixed; top: 8px; left: 8px; z-index: 300;
  background: var(--tn-slate, #4E6F79); color: #fff;
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 700;
  text-decoration: none; transform: translateY(-160%); transition: transform .15s ease;
}
.tn-skip:focus { transform: translateY(0); outline: 2px solid #fff; outline-offset: 1px; }

body.tn-docs {
  --tn-nav-h: 56px;
  --tn-side-w: 264px;
  --tn-line: #E5DDC8;
  --tn-slate: #4E6F79;
  --tn-slate-light: #547582;
  --tn-coral: #D08B74;
  --tn-coral-deep: #B96B52;
  --tn-paper: #F9F7F3;
  --tn-cream: #FCF3DC;
  background: var(--tn-paper);
  /* 구식 챕터가 body 에 display:flex/justify-content 를 걸어 sticky 사이드바를 깨는 걸 무력화.
     body.tn-docs(클래스 특이도)가 챕터 인라인 body{} 를 이겨 항상 블록 레이아웃 보장. */
  display: block;
  padding: 0;
}

/* 본문 폭 제한 해제 — docs는 넓게 */
body.tn-docs .wrap { max-width: 760px; }

/* ── 상단 네비 ── */
.tn-topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  height: var(--tn-nav-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--tn-line);
}
.tn-topnav-inner {
  max-width: 1440px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px;
}
.tn-logo {
  font-family: 'Sour Gummy', 'Quicksand', system-ui, sans-serif;
  font-size: 18px; font-weight: 700; color: #5E7C86;
  text-decoration: none; letter-spacing: -0.2px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
}
.tn-logo-mark { width: 24px; height: 24px; vertical-align: middle; border-radius: 6px; }
/* Learn — 파비콘 'tn' 하늘색(#9FBBD4)에 맞춤 (또렷함 위해 살짝 진하게) */
.tn-logo-accent { color: #8AAAC6; }
.tn-topnav-menu { display: flex; gap: 4px; margin-left: 8px; flex: 1; }
/* 톤다운하되 또렷하게 — 채도 낮은 진한 slate (#56707A) */
.tn-topnav-menu a {
  font-size: 13.5px; font-weight: 600; color: #56707A;
  text-decoration: none; padding: 7px 12px; border-radius: 8px;
  transition: all .14s ease;
}
.tn-topnav-menu a:hover { background: var(--tn-paper); color: var(--tn-slate); }
.tn-topnav-menu a.active { color: var(--tn-coral-deep); background: rgba(208,139,116,0.1); }

/* ── 우측 도구 (검색·AI·다크) ── */
.tn-topnav-tools { display: flex; align-items: center; gap: 8px; }
.tn-search-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--tn-paper); border: 1px solid var(--tn-line);
  border-radius: 9px; padding: 6px 10px; cursor: pointer;
  font-family: inherit; font-size: 12.5px; color: var(--tn-slate-light);
  transition: all .14s ease;
}
.tn-search-btn:hover { border-color: var(--tn-coral); color: var(--tn-slate); }
.tn-search-kbd {
  font-size: 10.5px; font-weight: 700; color: var(--tn-slate-light);
  background: #fff; border: 1px solid var(--tn-line); border-radius: 5px;
  padding: 1px 5px;
}
.tn-ai-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; border: 1px solid var(--tn-line); border-radius: 9px;
  padding: 7px 12px; font-size: 12.5px; font-weight: 700;
  color: var(--tn-slate); text-decoration: none; transition: all .14s ease;
}
.tn-ai-btn:hover { border-color: #D98BA6; color: #B05C7A; }
.tn-dark-btn {
  background: none; border: 1px solid var(--tn-line); border-radius: 9px;
  width: 34px; height: 34px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .14s ease;
}
.tn-dark-btn:hover { border-color: var(--tn-slate-light); }
.tn-share-btn {
  background: none; border: 1px solid var(--tn-line); border-radius: 9px;
  width: 34px; height: 34px; cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .14s ease;
}
.tn-share-btn:hover { border-color: var(--tn-coral); }

/* 공유 카드 모달 */
.tn-share-overlay {
  position: fixed; inset: 0; z-index: 200; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(46,42,38,0.45); backdrop-filter: blur(3px);
}
.tn-share-box {
  background: #fff; border-radius: 18px; padding: 24px 22px;
  max-width: 360px; width: 100%; box-shadow: 0 16px 50px rgba(0,0,0,0.22);
  font-family: inherit;
}
.tn-share-h { font-size: 17px; font-weight: 800; color: var(--tn-slate); margin-bottom: 6px; }
.tn-share-sub { font-size: 12.5px; color: var(--tn-slate-light); line-height: 1.6; margin-bottom: 16px; }
.tn-share-fmts { display: flex; gap: 8px; margin-bottom: 16px; }
.tn-fmt {
  flex: 1; padding: 10px 4px; border: 1px solid var(--tn-line); border-radius: 11px;
  background: #fff; font-size: 12px; font-weight: 700; color: var(--tn-slate-light);
  cursor: pointer; transition: all .14s ease; font-family: inherit;
}
.tn-fmt.active { border-color: var(--tn-coral); color: var(--tn-slate); background: #FCF3DC; }
.tn-share-dl {
  width: 100%; padding: 13px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--tn-slate); color: #fff; font-size: 14px; font-weight: 700; font-family: inherit;
}
.tn-share-dl:hover { background: var(--tn-slate-light); }
.tn-share-dl:disabled { opacity: .6; cursor: default; }
.tn-share-note { font-size: 10.5px; color: var(--tn-slate-light); text-align: center; margin-top: 11px; }
html.tn-dark .tn-share-btn { border-color: #2E3940; }
html.tn-dark .tn-share-box { background: #1E262B; }
html.tn-dark .tn-share-h { color: #E8EEF0; }
html.tn-dark .tn-fmt { background: #232C32; border-color: #2E3940; color: #9FB4BE; }
html.tn-dark .tn-fmt.active { background: #2E3940; color: #fff; }

.tn-burger {
  display: none; background: none; border: 0; font-size: 20px;
  color: var(--tn-slate); cursor: pointer; padding: 4px 8px;
}

/* ── 임베드 모드 (?embed=1) — 셸 숨기고 본문만, 기관·본진 iframe 삽입용 ── */
body.tn-embed .tn-topnav,
body.tn-embed .tn-sidebar,
body.tn-embed .tn-breadcrumb,
body.tn-embed .tn-backdrop { display: none !important; }
body.tn-embed .tn-layout { display: block; max-width: none; margin: 0; padding-top: 0; grid-template-columns: none; }
body.tn-embed .tn-content { padding: 0; }
body.tn-embed .tn-main { padding: 14px 18px 0; }
body.tn-embed { background: #fff; }
.tn-embed-credit { text-align: center; padding: 16px; margin-top: 20px; border-top: 1px solid var(--tn-line); }
.tn-embed-credit a {
  font-family: 'Sour Gummy', 'Quicksand', system-ui, sans-serif;
  font-size: 12.5px; font-weight: 700; color: var(--tn-slate-light); text-decoration: none;
}
.tn-embed-credit a:hover { color: var(--tn-coral-deep); }

/* ── 연결된 내용 (양방향 관계 그래프) ── */
.tn-related {
  margin: 28px auto 0; max-width: 760px;
  border-top: 1px solid var(--tn-line); padding-top: 22px;
}
.tn-related-h {
  font-size: 14px; font-weight: 800; color: var(--tn-slate);
  margin-bottom: 13px; letter-spacing: -0.2px;
}
.tn-related-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 9px;
}
.tn-related-card {
  display: flex; align-items: center; gap: 9px;
  background: #fff; border: 1px solid var(--tn-line); border-radius: 11px;
  padding: 11px 13px; text-decoration: none; transition: all .14s ease;
}
.tn-related-card:hover { border-color: var(--tn-coral); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(78,111,121,0.08); }
.tn-related-emoji { font-size: 18px; line-height: 1; flex-shrink: 0; }
.tn-related-title { font-size: 13px; font-weight: 600; color: var(--tn-slate); line-height: 1.35; }
html.tn-dark .tn-related-card { background: #232C32; border-color: #2E3940; }
html.tn-dark .tn-related-title { color: #C5D2D8; }

/* ── 검색 오버레이 ── */
.tn-search-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(45, 57, 61, 0.35); backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
.tn-search-box {
  width: 92%; max-width: 520px;
  background: #fff; border: 1px solid var(--tn-line); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(45,57,61,0.25); overflow: hidden;
}
.tn-search-field {
  width: 100%; border: 0; border-bottom: 1px solid var(--tn-line);
  padding: 16px 18px; font-size: 15px; font-family: inherit;
  color: var(--tn-slate); outline: none;
  -webkit-user-select: text; user-select: text;
}
.tn-search-results { max-height: 360px; overflow-y: auto; padding: 6px; }
.tn-search-item {
  display: block; padding: 10px 14px; border-radius: 9px;
  font-size: 13.5px; color: var(--tn-slate); text-decoration: none;
}
.tn-search-item:hover, .tn-search-item:focus { background: var(--tn-paper); color: var(--tn-coral-deep); }
.tn-search-sub { display: block; font-size: 11.5px; font-weight: 400; color: var(--tn-slate-light); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.tn-dark .tn-search-sub { color: #7E97A1; }
.tn-search-empty { padding: 24px; text-align: center; color: var(--tn-slate-light); font-size: 13px; }

/* ── 전역 링크 줄 (페이지 자체 푸터 안에 합쳐짐) ── */
.tn-sf-links {
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  justify-content: center;
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--tn-line);
  font-size: 12px; color: var(--tn-slate-light);
}
.tn-sf-brand { font-family: 'Sour Gummy','Quicksand',sans-serif; font-weight: 700; color: var(--tn-slate); font-size: 14px; }
.tn-sf-links a { color: var(--tn-slate-light); text-decoration: none; font-weight: 600; }
.tn-sf-links a:hover { color: var(--tn-coral-deep); }
/* 독립 docs 푸터(페이지 자체 푸터가 없을 때만) */
.tn-site-footer { margin-top: 40px; padding: 8px 28px 28px; }

/* ── 레이아웃 (사이드바 + 본문) ── */
.tn-layout {
  max-width: 1440px; margin: 0 auto;
  padding-top: var(--tn-nav-h);
  display: grid; grid-template-columns: var(--tn-side-w) 1fr;
  align-items: start;
}

/* ── 좌측 사이드바 ── */
.tn-sidebar {
  position: sticky; top: var(--tn-nav-h);
  height: calc(100vh - var(--tn-nav-h));
  overflow-y: auto;
  border-right: 1px solid var(--tn-line);
  padding: 22px 14px 40px 20px;
}
.tn-sidebar::-webkit-scrollbar { width: 6px; }
.tn-sidebar::-webkit-scrollbar-thumb { background: var(--tn-line); border-radius: 999px; }
.tn-side-group {
  font-size: 11px; font-weight: 800; color: var(--tn-slate);
  text-transform: none; letter-spacing: 0.2px;
  margin: 18px 0 7px 6px;
}
.tn-side-group:first-child { margin-top: 0; }
.tn-side-list { list-style: none; margin: 0 0 4px; padding: 0; }
.tn-side-list li { margin: 0; }
.tn-side-list a {
  display: block; font-size: 13px; font-weight: 500;
  color: #547582; text-decoration: none;
  padding: 6px 10px; border-radius: 7px; line-height: 1.4;
  transition: all .12s ease;
}
.tn-side-list a:hover { background: var(--tn-paper); color: var(--tn-slate); }
.tn-side-list a.active {
  background: rgba(208,139,116,0.12); color: var(--tn-coral-deep);
  font-weight: 700;
}

/* ── 본문 영역 ── */
.tn-content { min-width: 0; padding: 0 0 60px; }
.tn-breadcrumb {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--tn-slate-light); font-weight: 600;
  padding: 18px 28px 0;
}
.tn-breadcrumb a { color: var(--tn-slate-light); text-decoration: none; }
.tn-breadcrumb a:hover { color: var(--tn-coral-deep); }
.tn-bc-sep { opacity: 0.5; }
.tn-bc-here { color: var(--tn-slate); }
.tn-main { padding: 4px 28px 0; }
/* 본문 안의 .wrap 은 docs에서 패딩 중복 제거 */
body.tn-docs .tn-main .wrap { padding-left: 0; padding-right: 0; margin: 0; max-width: 100%; }
/* 구식 플래그십(.container · body flex 로 중앙정렬하던 카드형)은 body:block 후 중앙정렬 유지 */
body.tn-docs .tn-main .container { margin-left: auto; margin-right: auto; }
/* 분자·수용체 도식 애니메이션(svg.stage)이 넓은 본문에서 과하게 커지지 않게 — 캡+가운데.
   (인터랙티브 플래그십 시냅스 뷰는 .synapse 라 영향 없음) */
body.tn-docs .tn-main svg.stage { max-width: 480px; margin-left: auto; margin-right: auto; }

/* 챕터의 sticky pin-header 가 docs 상단 네비(56px)와 겹치지 않게 보정 */
body.tn-docs .pin-header { top: var(--tn-nav-h); z-index: 19; }
/* 챕터 상단 topbar(← 모든 분자 / 브랜드)는 docs 네비와 중복 → 숨김 */
body.tn-docs .tn-main .topbar { display: none; }

/* ── 집중(학습) 모드 + docs 네비 충돌 보정 ──
   집중모드 배너(tn-focus::before, top:0 z:100)가 docs 네비를 덮는 문제 해결.
   수직 적층: [배너 24px] → [네비 56px] → [본문]. 배너는 맨 위, 네비는 그 아래로. */
body.tn-docs.tn-focus { padding-top: 0 !important; }      /* tn-focus 기본 패딩 무효화 */
body.tn-docs.tn-focus .tn-topnav { top: 24px; }            /* 네비를 배너(24px) 아래로 */
body.tn-docs.tn-focus .tn-layout { padding-top: calc(24px + var(--tn-nav-h)); }
body.tn-docs.tn-focus .tn-sidebar {
  top: calc(24px + var(--tn-nav-h));
  height: calc(100vh - 24px - var(--tn-nav-h));
}
body.tn-docs.tn-focus .pin-header { top: calc(24px + var(--tn-nav-h)) !important; }

/* ── 백드롭(모바일) ── */
.tn-backdrop {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: rgba(45, 57, 61, 0.4);
}

/* ── 반응형: 모바일 ── */
@media (max-width: 860px) {
  .tn-layout { grid-template-columns: 1fr; }
  .tn-burger { display: block; }
  .tn-sidebar {
    position: fixed; top: var(--tn-nav-h); left: 0; z-index: 55;
    width: var(--tn-side-w); max-width: 80vw;
    height: calc(100vh - var(--tn-nav-h));
    background: #fff; transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(78,111,121,0.12);
  }
  body.tn-sidebar-open .tn-sidebar { transform: translateX(0); }
  body.tn-sidebar-open .tn-backdrop { display: block; }
  .tn-main, .tn-breadcrumb { padding-left: 18px; padding-right: 18px; }
  /* 상단 가로 메뉴는 좁은 화면에서 넘쳐 잘림 → 숨기고 ☰(사이드바 '바로가기'에 둘러보기·워크북·자료실·관찰일지 다 있음)로 접근 */
  .tn-topnav-menu { display: none; }
  /* 상단 툴바 공간 확보 → ☰ 가 화면 밖으로 밀리지 않게: 검색=아이콘만, 공유 숨김, Ask AI=✨만 */
  .tn-search-tx, .tn-search-kbd { display: none; }
  .tn-search-btn { padding: 7px 10px; }
  .tn-share-btn { display: none; }
  .tn-ai-btn { font-size: 0; padding: 7px 9px; }
  .tn-ai-btn .tn-ai-spark { font-size: 15px; }
  .tn-topnav-tools { gap: 5px; }
}

/* ════════════════════════════════════════════════
   다크 모드 (html.tn-dark) — 셸 크롬 위주
   페이지 본문 카드는 자체 인라인 색을 쓰므로 캔버스·크롬만 어둡게.
   ════════════════════════════════════════════════ */
html.tn-dark body.tn-docs { background: #1A2024; }
html.tn-dark .tn-topnav { background: rgba(26,32,36,0.92); border-bottom-color: #2E3940; }
html.tn-dark .tn-logo { color: #E8EEF0; }
html.tn-dark .tn-topnav-menu a { color: #9FB4BE; }
html.tn-dark .tn-topnav-menu a:hover { background: #232C32; color: #E8EEF0; }
html.tn-dark .tn-topnav-menu a.active { color: #E8A98F; background: rgba(208,139,116,0.14); }
html.tn-dark .tn-search-btn { background: #232C32; border-color: #2E3940; color: #9FB4BE; }
html.tn-dark .tn-search-kbd { background: #1A2024; border-color: #3A464E; color: #9FB4BE; }
html.tn-dark .tn-ai-btn { background: #232C32; border-color: #2E3940; color: #E8EEF0; }
html.tn-dark .tn-dark-btn { border-color: #2E3940; }

html.tn-dark .tn-sidebar { border-right-color: #2E3940; }
html.tn-dark .tn-side-group { color: #C5D2D8; }
html.tn-dark .tn-side-list a { color: #8FA6B0; }
html.tn-dark .tn-side-list a:hover { background: #232C32; color: #E8EEF0; }
html.tn-dark .tn-side-list a.active { background: rgba(208,139,116,0.16); color: #E8A98F; }

html.tn-dark .tn-breadcrumb { color: #8FA6B0; }
html.tn-dark .tn-breadcrumb a { color: #8FA6B0; }
html.tn-dark .tn-bc-here { color: #C5D2D8; }

/* ── 본문 전체 다크화 (필터 방식) ──
   페이지들이 인라인 라이트 색을 박아둬서, 본문(.tn-main)에 invert+hue-rotate로
   한 번에 어둡게. 단 SVG·이미지·canvas는 되-반전해 분자 도식 색을 보존. */
html.tn-dark body.tn-docs .tn-main {
  filter: invert(0.92) hue-rotate(180deg);
}
/* 다이어그램·이미지·인터랙티브는 색 보존 (재반전) */
html.tn-dark body.tn-docs .tn-main svg,
html.tn-dark body.tn-docs .tn-main img,
html.tn-dark body.tn-docs .tn-main canvas,
html.tn-dark body.tn-docs .tn-main video,
html.tn-dark body.tn-docs .tn-main .synapse,
html.tn-dark body.tn-docs .tn-main [class*="emoji"],
html.tn-dark body.tn-docs .tn-main .mol-svg {
  filter: invert(1) hue-rotate(180deg);
}

html.tn-dark .tn-sf-links { border-top-color: #2E3940; }
html.tn-dark .tn-sf-brand { color: #E8EEF0; }
html.tn-dark .tn-sf-links, html.tn-dark .tn-sf-links a { color: #8FA6B0; }

html.tn-dark .tn-search-box { background: #232C32; border-color: #2E3940; }
html.tn-dark .tn-search-field { background: #232C32; color: #E8EEF0; border-bottom-color: #2E3940; }
html.tn-dark .tn-search-item { color: #C5D2D8; }
html.tn-dark .tn-search-item:hover { background: #1A2024; color: #E8A98F; }

/* 검색 결과 카테고리 라벨 (이 페이지에서 / 다른 챕터) */
.tn-search-cat { font-size: 10.5px; font-weight: 800; color: var(--tn-slate-light); padding: 10px 14px 4px; letter-spacing: 0.3px; }
html.tn-dark .tn-search-cat { color: #8FA6B0; }
