/* ===== 색상 / 크기 ===== */
:root { color-scheme: light;
  --bg: #ffffff; --bg-soft: #f7f8fa; --fg: #1d2129; --fg-soft: #3b414d; --muted: #6b7280;
  --line: #e5e7eb; --line-strong: #d1d5db;
  --accent: #2563eb; --accent-soft: #eff4ff; --accent-fg: #1e40af;
  --code-bg: #f3f4f6; --pre-bg: #0f172a; --pre-fg: #e2e8f0;
  --note-bg: #fffbeb; --note-line: #f59e0b;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
  --top-h: 56px; --nav-w: 288px; --toc-w: 232px; --read-w: 780px;
}
:root[data-theme="dark"] { color-scheme: dark;
  --bg: #0e1116; --bg-soft: #151a21; --fg: #e6e9ef; --fg-soft: #c5cbd5; --muted: #8b93a1;
  --line: #262c36; --line-strong: #343b47;
  --accent: #6b9cff; --accent-soft: #1a2436; --accent-fg: #a9c4ff;
  --code-bg: #1d232c; --pre-bg: #0a0d12; --pre-fg: #dbe3ee;
  --note-bg: #2a2214; --note-line: #d99a2b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
}

/* ===== 기본 ===== */
* { box-sizing: border-box; }
html { font-size: 16px; scroll-padding-top: calc(var(--top-h) + 16px); }
body { margin: 0; background: var(--bg); color: var(--fg);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  line-height: 1.8; word-break: keep-all; overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ===== 상단 바 ===== */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--top-h);
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(10px); -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.02rem; color: var(--fg); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; font-size: 14px; }
.topbar-spacer { flex: 1; }
.icon-btn { background: none; border: 1px solid var(--line); color: var(--fg-soft); border-radius: 8px;
  width: 36px; height: 36px; display: inline-grid; place-items: center; font-size: 16px; cursor: pointer; }
.icon-btn:hover { background: var(--bg-soft); }
.menu-toggle { display: none; }

/* ===== 3단 레이아웃: 사이드바 | 본문(가운데) | 목차 ===== */
.layout { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--toc-w); align-items: start; }
.sidebar { position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); overflow-y: auto;
  padding: 20px 12px 48px; border-right: 1px solid var(--line); font-size: 14px; line-height: 1.5;
  scrollbar-width: thin; }
.content { min-width: 0; padding: 40px 48px 96px; }
.content-inner { max-width: var(--read-w); margin: 0 auto; }
.toc { position: sticky; top: calc(var(--top-h) + 24px); max-height: calc(100vh - var(--top-h) - 48px);
  overflow-y: auto; padding: 0 20px 24px 8px; font-size: 13px; line-height: 1.5; scrollbar-width: thin; }
.toc-title { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px 12px; }
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc ul ul { padding-left: 12px; }
.toc a { display: block; padding: 4px 0 4px 12px; color: var(--muted); border-left: 2px solid var(--line); }
.toc a:hover { color: var(--fg); text-decoration: none; }
.toc a.current { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

/* ===== 사이드바 내비게이션 ===== */
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav a { display: block; padding: 6px 10px; border-radius: 8px; color: var(--fg-soft); }
.nav a:hover { background: var(--bg-soft); text-decoration: none; color: var(--fg); }
.nav a.active { background: var(--accent-soft); color: var(--accent-fg); font-weight: 600; }
.nav-src { margin-bottom: 6px; }
.nav-src-link { font-weight: 800; font-size: 15px; color: var(--fg) !important; letter-spacing: -0.01em; }
.nav-svc { margin: 2px 0 10px 4px !important; }
.nav-svc-link { font-weight: 700; font-size: 14px; color: var(--fg) !important; }
.nav-ch { margin: 2px 0 6px 8px !important; }
.nav-ch > li > a { font-weight: 600; font-size: 13.5px; }
.nav-pages { margin: 2px 0 8px 12px !important; padding-left: 6px !important; border-left: 1px solid var(--line); }
.nav-pages a { font-size: 13px; color: var(--muted); padding: 4px 10px; }
.nav-pages li.d2 { padding-left: 10px; } .nav-pages li.d3 { padding-left: 20px; }
.nav-pages li.d4 { padding-left: 30px; } .nav-pages li.d5 { padding-left: 40px; }

/* ===== 본문 ===== */
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--muted); } .breadcrumb a:hover { color: var(--accent); }
.doc { color: var(--fg-soft); font-size: 1.0625rem; }
.doc h1 { color: var(--fg); font-size: 2.05rem; line-height: 1.3; letter-spacing: -0.025em; margin: 0 0 28px; font-weight: 800; }
.doc h2 { color: var(--fg); font-size: 1.45rem; line-height: 1.4; letter-spacing: -0.015em; margin: 2.2em 0 .7em;
  padding-top: 1em; border-top: 1px solid var(--line); font-weight: 700; }
.doc h1 + h2, .doc > h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.doc h3 { color: var(--fg); font-size: 1.18rem; margin: 2em 0 .6em; font-weight: 700; }
.doc h4 { color: var(--fg); font-size: 1.02rem; margin: 1.6em 0 .5em; }
.doc p { margin: 0 0 1.1em; }
.doc ul, .doc ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.doc li { margin: .35em 0; }
.doc li::marker { color: var(--muted); }
.doc strong { color: var(--fg); font-weight: 700; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.doc img { max-width: 100%; border-radius: 10px; }

/* 페이지 상단 원문·위치 정보 */
.doc h1 + ul { list-style: none; padding: 12px 16px; margin: -8px 0 32px; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 12px; font-size: .86rem; line-height: 1.6; color: var(--muted); }
.doc h1 + ul li { margin: 2px 0; }
.doc h1 + ul + h2, .doc h1 + ul + hr + h2 { border-top: 0; padding-top: 0; margin-top: 0; }
.doc h1 + ul + hr { display: none; }

/* 표 */
.table-wrap { overflow-x: auto; margin: 1.2em 0 1.6em; border: 1px solid var(--line); border-radius: 12px; }
.doc table { border-collapse: collapse; width: 100%; font-size: .9rem; line-height: 1.6; }
.doc th, .doc td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.doc th { background: var(--bg-soft); color: var(--fg); font-weight: 700; white-space: nowrap; }
.doc tr:last-child td { border-bottom: 0; }
.doc tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }

/* 코드 */
.doc code { font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace; background: var(--code-bg);
  padding: .15em .4em; border-radius: 6px; font-size: .86em; color: var(--fg); }
.doc pre { background: var(--pre-bg); color: var(--pre-fg); padding: 16px 18px; border-radius: 12px;
  overflow-x: auto; line-height: 1.6; font-size: .9rem; margin: 1.2em 0 1.6em; }
.doc pre code { background: none; padding: 0; color: inherit; font-size: .86rem; }

/* 인용/메모 박스 */
.doc blockquote { margin: 1.4em 0; padding: 14px 18px; background: var(--accent-soft); border-left: 4px solid var(--accent);
  border-radius: 0 12px 12px 0; color: var(--fg-soft); }
.doc blockquote.note { background: var(--note-bg); border-left-color: var(--note-line); }
.doc blockquote p:last-child { margin-bottom: 0; }
.doc blockquote p { margin: 0 0 .5em; }
.link-pending { color: var(--muted); border-bottom: 1px dotted var(--muted); cursor: help; }

/* 이전/다음 */
.prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 64px; }
.prevnext a { display: block; padding: 14px 18px; border: 1px solid var(--line); border-radius: 12px; color: var(--fg); font-size: .95rem; }
.prevnext a:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow); }
.prevnext .label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.prevnext .next { text-align: right; grid-column: 2; }

/* 홈 카드 */
.hero { padding: 8px 0 8px; }
.hero p { font-size: 1.1rem; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin: 28px 0; }
.card { display: block; border: 1px solid var(--line); border-radius: 14px; padding: 20px; color: var(--fg); background: var(--bg); transition: .15s; }
.card:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow); transform: translateY(-2px); }
.card-title { font-weight: 700; font-size: 1.08rem; line-height: 1.45; margin-bottom: 6px; }
.card-meta { color: var(--muted); font-size: 13.5px; line-height: 1.4; }

/* ===== 반응형 ===== */
@media (max-width: 1280px) {
  .layout { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-toggle { display: inline-grid; }
  .sidebar { display: none; position: fixed; z-index: 40; top: var(--top-h); left: 0; width: min(86vw, 320px);
    background: var(--bg); box-shadow: 0 12px 32px rgba(0,0,0,.25); }
  body.nav-open .sidebar { display: block; }
  .content { padding: 24px 20px 72px; }
  .doc { font-size: 1rem; }
  .doc h1 { font-size: 1.65rem; }
  .prevnext { grid-template-columns: 1fr; }
  .prevnext .next { grid-column: 1; }
}

/* ===== 읽기 도구: 북마크 · 여기까지 읽음 · 이어 읽기 ===== */
.td-star { background: none; border: 0; cursor: pointer; font-size: .8em; color: var(--muted); padding: 0 .3em 0 0;
  vertical-align: .08em; line-height: 1; }
.td-star:hover { color: #f59e0b; }
.td-star.on { color: #f59e0b; }

.td-mark { margin-left: 10px; vertical-align: middle; font-size: 12px; font-weight: 600; line-height: 1;
  padding: 5px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  cursor: pointer; opacity: 0; transition: opacity .15s, background .15s; font-family: inherit; letter-spacing: 0; }
.doc h1 .td-mark { font-size: 12px; }
.doc h1:hover .td-mark, .doc h2:hover .td-mark, .doc h3:hover .td-mark, .td-mark:focus-visible { opacity: 1; }
.td-mark:hover { border-color: var(--accent); color: var(--accent); }
.td-mark.on { opacity: 1; background: var(--accent); border-color: var(--accent); color: #fff; }
.td-here { scroll-margin-top: calc(var(--top-h) + 24px); }
.doc h2.td-here, .doc h3.td-here { position: relative; }
.doc h2.td-here::before, .doc h3.td-here::before { content: ""; position: absolute; left: -18px; top: .25em; bottom: .25em;
  width: 4px; border-radius: 4px; background: var(--accent); }
.doc h2.td-here::before { top: calc(1em + .25em); }
@media (hover: none) { .td-mark { opacity: .85; } }

.toc a.td-here { color: var(--accent); font-weight: 700; }
.toc a.td-here::after { content: " 📍"; }

.sidebar a.td-read::before { content: "✓ "; color: #16a34a; font-weight: 700; }
.sidebar a.td-read { color: var(--muted); }
.sidebar a.td-at { box-shadow: inset 3px 0 0 var(--accent); }
.sidebar a.td-at::after { content: " 📍"; }

.td-resume-box { display: grid; gap: 10px; margin: 0 0 24px; }
.td-resume { display: block; padding: 14px 16px; border: 1px solid var(--accent); border-radius: 12px;
  background: var(--accent-soft); color: var(--fg); }
.td-resume:hover { text-decoration: none; box-shadow: var(--shadow); }
.td-resume-label { display: block; font-size: 12px; font-weight: 700; color: var(--accent-fg); margin-bottom: 2px; }
.td-resume-title { display: block; font-weight: 700; line-height: 1.45; }
.td-resume-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.td-bar { display: block; height: 4px; border-radius: 4px; background: var(--line); margin-top: 8px; overflow: hidden; }
.td-bar-fill { display: block; height: 100%; background: var(--accent); }

.td-panel { position: fixed; top: 0; right: 0; z-index: 60; width: min(420px, 92vw); height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0,0,0,.18);
  transform: translateX(105%); transition: transform .2s ease; font-size: 14px; line-height: 1.55; }
body.td-panel-open .td-panel { transform: none; }
.td-shade { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .2s; }
body.td-panel-open .td-shade { opacity: 1; pointer-events: auto; }
.td-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; height: var(--top-h);
  border-bottom: 1px solid var(--line); font-size: 15px; }
.td-panel-body { flex: 1; overflow-y: auto; padding: 8px 16px 24px; }
.td-panel-body h4 { margin: 18px 0 10px; font-size: 13px; color: var(--muted); letter-spacing: .02em; }
.td-panel-body .td-resume { margin-bottom: 10px; }
.td-group { font-size: 12px; font-weight: 700; color: var(--fg); margin: 12px 0 4px; }
.td-list { list-style: none; margin: 0; padding: 0; }
.td-list li { display: flex; align-items: flex-start; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.td-list a { flex: 1; color: var(--fg-soft); }
.td-x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.td-x:hover { color: #dc2626; }
.td-empty { color: var(--muted); font-size: 13px; margin: 0; }
.td-panel-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.td-btn { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); cursor: pointer; }
.td-btn:hover { border-color: var(--accent); color: var(--accent); }
.td-note { margin-left: auto; font-size: 11.5px; color: var(--muted); }

.td-toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); z-index: 70;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; }
.td-toast.show { opacity: 1; transform: translate(-50%, 0); }
.sidebar a.td-in { color: var(--accent-fg); }
.sidebar a.td-in::before { content: "▸ "; color: var(--accent); }
.td-resume-group { display: grid; gap: 8px; }
.td-resume.td-last { border-color: var(--line); background: var(--bg-soft); padding: 10px 14px; }
.td-resume.td-last .td-resume-label { color: var(--muted); }
.td-resume.td-last .td-resume-title { font-weight: 600; font-size: .95em; }
.td-resume.td-last:hover { border-color: var(--accent); }
