/* ==========================================================================
   Second Brain — 디자인 시스템
   작가·아날로그: 크림 종이 위 세피아 잉크, 옥스블러드 만년필 링크, 형광펜 하이라이트.
   라이트 #F5EFE3/#EDE5D6/#2A2420/#8C3B2E · 다크 #1D1A17/#26221E/#E9E1D3/#E3A58F
   1px 헤어라인 · 2~4px 모서리 · 시스템 명조(웹폰트 없음) · 모든 텍스트 AA 대비
   ========================================================================== */

/* ---------- 토큰 ---------- */
:root {
  --paper: #f5efe3;
  --surface: #ede5d6;
  --surface-2: #e5dbc8;
  --ink: #2a2420;
  --ink-2: #544a41;
  --ink-3: #6b5f53; /* 종이 대비 5.4:1 — 3차 텍스트도 AA 충족 */
  --line: #dcd1bd;
  --line-2: #cbbda4;
  --link: #8c3b2e;
  --link-strong: #6f2d22;
  --mark: rgba(222, 178, 64, 0.36); /* 형광펜 */
  --accent-soft: rgba(140, 59, 46, 0.08);
  --danger: #a8321f;
  --warn: #8a5f10;
  --ok: #2f6b45;

  /* 이름은 그대로 두고 명조로 바꾼다 — 모든 규칙이 이 토큰을 참조한다 */
  --font-sans: "Iowan Old Style", "Palatino Linotype", Georgia, "Noto Serif KR", "Noto Serif CJK KR",
    "Nanum Myeongjo", "AppleMyungjo", "Batang", serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "D2Coding", monospace;

  --rail-w: 240px;
  --measure: 760px;
  --r-s: 2px;
  --r-m: 3px;
  --r-l: 4px;
  --shadow-pop: 0 10px 30px rgba(60, 40, 20, 0.16), 0 1px 3px rgba(60, 40, 20, 0.12);
  --shadow-float: 0 4px 14px rgba(60, 40, 20, 0.14);

  --topbar-h: 54px;
}

html[data-theme="dark"] {
  --paper: #1d1a17;
  --surface: #26221e;
  --surface-2: #2e2924;
  --ink: #e9e1d3;
  --ink-2: #c0b5a5;
  --ink-3: #9a8e7d;
  --line: #37312a;
  --line-2: #443c33;
  --link: #e3a58f;
  --link-strong: #eebaa7;
  --mark: rgba(222, 178, 64, 0.26);
  --accent-soft: rgba(227, 165, 143, 0.1);
  --danger: #e5836f;
  --warn: #d9a94c;
  --ok: #8cc49d;
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-float: 0 4px 14px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ---------- 기본기 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: 0;
  /* 종이 결 — 인라인 SVG 노이즈, 외부 요청 없음 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .15 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

::selection { background: var(--mark); }

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 3px;
}

/* 브라우저 기본 부분도 디자인에 포함시킨다 */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

@view-transition { navigation: auto; }

.icon { width: 18px; height: 18px; flex: none; }
kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--r-s);
  background: var(--paper);
  color: var(--ink-3);
  line-height: 1.4;
}

.skip-link {
  position: fixed;
  top: 10px; left: 10px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--link);
  color: #fff;
  border-radius: var(--r-s);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-64px);
  opacity: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.skip-link:focus-visible { transform: none; opacity: 1; }

/* ---------- 레이아웃: 240 / 1fr / 240 ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--rail-w);
  max-width: 1400px;
  margin: 0 auto;
  min-height: 100dvh;
}

/* ---------- 사이드바 ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 16px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  padding: 2px 4px;
  border-radius: var(--r-s);
}
.brand__mark { width: 22px; height: 22px; color: var(--link); }
.brand__name {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.searchtrigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--ink-3);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.searchtrigger:hover { border-color: var(--line-2); box-shadow: 0 1px 3px rgba(40,30,20,0.05); }
.searchtrigger:hover .searchtrigger__label { color: var(--ink-2); }
.searchtrigger__label { flex: 1; text-align: left; }
.searchtrigger .icon { width: 16px; height: 16px; }

/* 폴더 트리 */
.tree { flex: 1; min-height: 0; font-size: 14px; }
.tree__list, .tree__list ul { list-style: none; margin: 0; padding: 0; }
.tree__list > .tree__branch:first-child, .tree__list > .tree__leaf:first-child { margin-top: 2px; }

.tree__folder { border-radius: var(--r-s); }
.tree__folder > .tree__foldername { margin-left: calc(var(--depth, 0) * 12px); }
.tree__foldername {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  color: var(--ink-2);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  list-style: none;
  border-radius: var(--r-s);
  transition: background-color 0.12s ease, color 0.12s ease;
}
.tree__foldername::-webkit-details-marker { display: none; }
.tree__foldername:hover { background: var(--surface-2); color: var(--ink); }
.tree__foldericon { width: 15px; height: 15px; opacity: 0.75; }
.tree__chevron { width: 13px; height: 13px; opacity: 0.65; transition: transform 0.18s ease; }
.tree__folder[open] > .tree__foldername .tree__chevron { transform: rotate(90deg); }
.tree__folder > ul { margin-top: 1px; }

.tree__leaf { margin-left: calc(var(--depth, 0) * 12px); }
.tree__item {
  display: block;
  padding: 5.5px 9px;
  border-radius: var(--r-s);
  color: var(--ink-2);
  text-decoration: none;
  line-height: 1.5;
  overflow-wrap: break-word;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.tree__item:hover { background: var(--surface-2); color: var(--ink); }
.tree__item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--link);
  font-weight: 650;
}

.sidebar__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.themetoggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
.themetoggle:hover { border-color: var(--line-2); color: var(--ink); background: var(--surface-2); }
.themetoggle__icons { display: grid; width: 17px; height: 17px; }
.themetoggle__icon { grid-area: 1 / 1; width: 17px; height: 17px; opacity: 0; transform: scale(0.6); transition: opacity 0.2s ease, transform 0.2s ease; }
html[data-mode="light"] .themetoggle__icon[data-when="light"],
html[data-mode="dark"] .themetoggle__icon[data-when="dark"],
html[data-mode="system"] .themetoggle__icon[data-when="system"] { opacity: 1; transform: none; }

/* ---------- 모바일 탑바 ---------- */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  padding: 0 10px;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { justify-content: flex-start; }
.iconbtn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: var(--r-m);
  cursor: pointer;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.scrim {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(40, 30, 20, 0.42);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.scrim.is-open { opacity: 1; }

/* ---------- 중앙 본문 ---------- */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 48px 48px 32px;
}
.page {
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  flex: 1;
}
.page__head { margin-bottom: 8px; }
.page__title {
  margin: 0 0 10px;
  font-size: clamp(28px, 3.4vw, 36px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
  text-wrap: balance;
  overflow-wrap: break-word;
}
.page__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 13.5px;
  color: var(--ink-3);
}
.page__meta time { font-variant-numeric: tabular-nums; }
.chip {
  display: inline-block;
  padding: 2px 9px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
}

.sitefooter {
  max-width: var(--measure);
  margin: 40px auto 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-3);
}
.sitefooter p { margin: 0; }

/* ---------- 본문 타이포 (.prose) ---------- */
.prose { font-size: 17px; }

.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1.1em; }

.prose .md-h { scroll-margin-top: 84px; position: relative; }
.prose .md-h2, .prose h2.md-h {
  margin: 2.2em 0 0.7em;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0;
}
.prose h3.md-h { margin: 1.8em 0 0.55em; font-size: 20px; font-weight: 600; line-height: 1.45; }
.prose h4.md-h, .prose h5.md-h, .prose h6.md-h { margin: 1.5em 0 0.5em; font-size: 17.5px; font-weight: 650; }
.md-anchor {
  position: absolute;
  left: -0.75em;
  color: var(--link);
  text-decoration: none;
  opacity: 0;
  font-weight: 500;
  transition: opacity 0.15s ease;
}
@media (hover: hover) {
  .prose .md-h:hover .md-anchor { opacity: 0.55; }
  .md-anchor:hover { opacity: 1 !important; }
}

/* 링크 — 색상 + 밑줄의 이중 약속(기획 §5.4) */
.prose a, .backlinks__link, .graphcard__list a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--link) 45%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.14s ease, text-decoration-color 0.14s ease;
}
.prose a:hover, .backlinks__link:hover, .graphcard__list a:hover {
  color: var(--link-strong);
  text-decoration-color: var(--link-strong);
  text-decoration-thickness: 1.5px;
}
.wikilink--dead {
  color: var(--ink-3);
  text-decoration: underline dotted;
  text-decoration-color: var(--line-2);
  text-underline-offset: 3px;
  cursor: default;
}
.prose strong { font-weight: 680; }
.prose mark {
  background: var(--mark);
  color: inherit;
  padding: 0.06em 0.22em;
  border-radius: 4px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.prose del { color: var(--ink-3); }
.tag {
  color: var(--link);
  text-decoration: none;
  font-size: 0.88em;
  background: var(--accent-soft);
  border-radius: var(--r-s);
  padding: 0.1em 0.6em;
  white-space: nowrap;
}

.prose ul, .prose ol { margin: 0 0 1.1em; padding-left: 1.55em; }
.prose li { margin: 0.3em 0; }
.prose li::marker { color: var(--ink-3); }
.prose li.task { list-style: none; margin-left: -1.45em; display: flex; gap: 9px; align-items: baseline; }
.prose li.task input { transform: translateY(2px); accent-color: var(--link); }
.prose li.task--done > span { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line-2); }

.prose blockquote {
  margin: 0 0 1.2em;
  padding: 2px 0 2px 18px;
  border-left: 2px solid var(--line-2);
  color: var(--ink-2);
}

.prose hr {
  margin: 2.4em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

/* 인라인 코드 */
.prose code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.855em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  padding: 0.1em 0.38em;
  overflow-wrap: anywhere;
}

/* 코드 블록 */
.codeblock {
  position: relative;
  margin: 0 0 1.3em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  overflow: hidden;
}
.codeblock pre {
  margin: 0;
  padding: 15px 17px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  tab-size: 2;
}
.codeblock code { font-family: inherit; background: none; padding: 0; border: 0; }
.codeblock__lang {
  position: absolute;
  top: 8px;
  right: 44px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  text-transform: lowercase;
}
.codeblock__copy {
  position: absolute;
  top: 7px;
  right: 7px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  font: inherit;
  font-size: 12px;
  color: var(--ink-3);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.codeblock:hover .codeblock__copy, .codeblock__copy:focus-visible, .codeblock__copy.is-copied { opacity: 1; }
.codeblock__copy:hover { color: var(--ink); border-color: var(--line-2); }
.codeblock__copy .icon { width: 13px; height: 13px; }
.codeblock__copy.is-copied { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.codeblock__copy.is-copied span { font-weight: 600; }
@media (hover: none) { .codeblock__copy { opacity: 1; } }

.tok-kw { color: #8250c8; font-weight: 600; }
.tok-str { color: #1f7a4d; }
.tok-com { color: var(--ink-3); font-style: italic; }
.tok-num { color: #a1490c; }
.tok-fn { color: #255fa3; }
html[data-theme="dark"] .tok-kw { color: #c8a5f8; }
html[data-theme="dark"] .tok-str { color: #86d3a8; }
html[data-theme="dark"] .tok-num { color: #e8a06a; }
html[data-theme="dark"] .tok-fn { color: #7fb2e8; }

/* 표 */
.table-wrap {
  margin: 0 0 1.3em;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  -webkit-overflow-scrolling: touch;
}
.prose table { border-collapse: collapse; width: 100%; font-size: 15px; }
.prose th, .prose td {
  padding: 9px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.prose tbody tr:last-child td { border-bottom: 0; }
.prose thead th {
  background: var(--surface);
  font-weight: 650;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  color: var(--ink-2);
  white-space: nowrap;
}
.prose tbody tr { transition: background-color 0.12s ease; }
@media (hover: hover) { .prose tbody tr:hover { background: color-mix(in srgb, var(--surface) 55%, transparent); } }

/* 이미지·미디어 */
.prose .md-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.4em auto 0.6em;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}
.prose img.md-image--external { border-style: dashed; }
.md-broken-media {
  display: inline-block;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  border: 1px dashed color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: var(--r-s);
}
.filecard {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0 0 1.2em;
  padding: 13px 16px;
  color: var(--ink);
  text-decoration: none !important;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.filecard:hover { border-color: var(--link); background: var(--accent-soft); }
.filecard .icon { color: var(--link); }
.filecard__name { font-weight: 650; font-size: 14.5px; }
.filecard__meta { margin-left: auto; font-size: 12.5px; color: var(--ink-3); }

/* 콜아웃 */
.callout {
  margin: 0 0 1.25em;
  padding: 13px 17px 13px 15px;
  border: 1px solid color-mix(in srgb, currentColor 18%, var(--line));
  border-left: 3px solid currentColor;
  border-radius: var(--r-m);
  background: color-mix(in srgb, currentColor 5%, var(--paper));
}
.callout .callout__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 650;
  font-size: 15px;
  line-height: 1.5;
}
.callout__icon { width: 17px; height: 17px; flex: none; }
.callout__body { margin-top: 6px; font-size: 15.5px; line-height: 1.7; }
.callout__body > :last-child { margin-bottom: 0; }
.callout--note, .callout--info { color: var(--link); }
.callout--note .callout__body, .callout--info .callout__body { color: var(--ink); }
.callout--tip, .callout--hint { color: var(--ok); }
.callout--tip .callout__body, .callout--hint .callout__body { color: var(--ink); }
.callout--success, .callout--check { color: var(--ok); }
.callout--success .callout__body, .callout--check .callout__body { color: var(--ink); }
.callout--warning, .callout--caution { color: var(--warn); }
.callout--warning .callout__body, .callout--caution .callout__body { color: var(--ink); }
.callout--danger, .callout--error { color: var(--danger); }
.callout--danger .callout__body, .callout--error .callout__body { color: var(--ink); }
.callout--question, .callout--help, .callout--faq { color: var(--link); }
.callout--question .callout__body, .callout--help .callout__body, .callout--faq .callout__body { color: var(--ink); }
.callout--example, .callout--abstract, .callout--summary, .callout--tldr { color: var(--ink-2); }
.callout--example .callout__body, .callout--abstract .callout__body, .callout--summary .callout__body, .callout--tldr .callout__body { color: var(--ink); }
.callout--quote { color: var(--ink-2); }
.callout--quote .callout__body { color: var(--ink-2); }

details.callout > .callout__title { cursor: pointer; user-select: none; list-style: none; }
details.callout > .callout__title::-webkit-details-marker { display: none; }
.callout__chevron { margin-left: auto; width: 15px; height: 15px; opacity: 0.6; transition: transform 0.2s ease; }
details.callout[open] > .callout__title .callout__chevron { transform: rotate(90deg); }

/* 임베드 */
.embed {
  margin: 0 0 1.3em;
  padding: 14px 17px 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}
.embed__src {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3) !important;
  text-decoration: none !important;
}
.embed__src::before { content: "⤷"; color: var(--link); }
.embed__src:hover { color: var(--link) !important; }
.embed .embed .embed { margin-bottom: 0.9em; }
.embed--error {
  padding: 11px 15px;
  font-size: 14px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 6%, var(--paper));
  border: 1px dashed color-mix(in srgb, var(--danger) 40%, transparent);
}

/* 수식 */
.math-block {
  margin: 0 0 1.25em;
  padding: 6px 4px;
  overflow-x: auto;
  text-align: center;
  font-size: 16.5px;
}
.math-inline { white-space: nowrap; }

/* 다이어그램 (Mermaid) */
.mermaid-host { margin: 0 0 1.3em; text-align: center; overflow-x: auto; padding: 10px 0; }
.mermaid-host svg { max-width: 100%; height: auto; }
.mermaid-host.is-error {
  padding: 11px 15px;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 7%, var(--paper));
  border: 1px dashed color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: var(--r-m);
  font-size: 13.5px;
  text-align: left;
}

/* 각주 */
.footnotes { margin-top: 3em; font-size: 13.5px; color: var(--ink-2); }
.footnotes hr { margin: 0 0 1em; }
.footnotes ol { list-style: none; padding-left: 0; margin: 0; }
.footnote { margin: 0.35em 0; }
.footnote__num { color: var(--ink-3); margin-right: 2px; }
.footnote__back { text-decoration: none !important; }
.fnref a { text-decoration: none !important; font-size: 0.82em; color: var(--link); }
.fnref a:hover { text-decoration: underline !important; }

/* ---------- 백링크 ---------- */
.backlinks {
  margin-top: 56px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.backlinks__title {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-2);
}
.backlinks__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.backlinks__item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.backlinks__item:hover { border-color: color-mix(in srgb, var(--link) 40%, var(--line)); background: var(--accent-soft); }
.backlinks__link { font-weight: 650; font-size: 14.5px; }
.backlinks__context {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 오른쪽 레일 ---------- */
.rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px 20px 28px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.rail__heading {
  margin: 0 0 10px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink-3);
}

.graphcard {
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: var(--paper);
  overflow: hidden;
}
.graphcard__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 6px;
}
.graphcard__head .rail__heading { margin: 0; }
.graphcard__count { margin-left: auto; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.graphcard__expand {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.graphcard__expand:hover { color: var(--link); border-color: color-mix(in srgb, var(--link) 40%, var(--line)); background: var(--accent-soft); }
.graphcard__expand .icon { width: 14px; height: 14px; }
.graphcard__viewport {
  height: 300px;
  background: var(--paper);
  cursor: grab;
}
.graphcard__canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.graphcard__list { border-top: 1px solid var(--line); font-size: 13px; }
.graphcard__list summary {
  padding: 8px 14px;
  color: var(--ink-3);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color 0.15s ease;
}
.graphcard__list summary::-webkit-details-marker { display: none; }
.graphcard__list summary::before { content: "▸ "; }
.graphcard__list[open] summary::before { content: "▾ "; }
.graphcard__list summary:hover { color: var(--ink); }
.graphcard__list ul { list-style: none; margin: 0; padding: 2px 14px 10px; display: grid; gap: 4px; }
.graphcard__list li a { font-weight: 500; }
.graphcard__dir { color: var(--ink-3); }

.toc { font-size: 13.5px; }
.toc__list, .toc__sub { list-style: none; margin: 0; padding: 0; }
.toc__item { position: relative; }
.toc__link {
  display: block;
  padding: 4.5px 10px;
  color: var(--ink-3);
  text-decoration: none;
  border-left: 1px solid var(--line);
  line-height: 1.5;
  transition: color 0.14s ease, border-color 0.14s ease, background-color 0.14s ease;
  overflow-wrap: anywhere;
}
.toc__link:hover { color: var(--ink); }
.toc__link.is-active {
  color: var(--link);
  font-weight: 650;
  border-left: 2px solid var(--link);
  margin-left: -1px;
  background: linear-gradient(to right, var(--accent-soft), transparent);
}
.toc__sub { padding-left: 14px; }
.toc__item--sub .toc__link { font-size: 12.8px; }

/* ---------- 검색 다이얼로그 ---------- */
.search {
  width: min(620px, calc(100vw - 32px));
  margin: auto;
  margin-top: min(14vh, 160px);
  padding: 0;
  border: 0;
  border-radius: var(--r-l);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.search::backdrop {
  background: rgba(40, 30, 20, 0.4);
  backdrop-filter: blur(2px);
}
.search[open] { animation: search-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes search-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.search__box {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 17px;
  border-bottom: 1px solid var(--line);
}
.search__magnifier { color: var(--ink-3); }
.search__input {
  flex: 1;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: none;
  caret-color: var(--link);
}
.search__input::placeholder { color: var(--ink-3); }
.search__input::-webkit-search-cancel-button { display: none; }
.search__esc { display: none; }
@media (hover: none) {
  .search__esc {
    display: block;
    font: inherit; font-size: 12px;
    padding: 5px 10px;
    color: var(--ink-3);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-s);
  }
}
.search__status { padding: 8px 18px 0; font-size: 12.5px; color: var(--ink-3); min-height: 1.4em; }
.search__results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0 8px 8px;
  max-height: min(52vh, 430px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.search__results:empty { margin: 0; padding: 0; }
.search__item {
  margin: 2px 0;
  padding: 9px 12px;
  border-radius: var(--r-m);
  cursor: pointer;
}
.search__item.is-active { background: var(--surface); }
.search__item-top { display: flex; align-items: baseline; gap: 8px; }
.search__item-title { font-weight: 650; font-size: 14.5px; overflow-wrap: anywhere; }
.search__item-title mark, .search__item-excerpt mark {
  background: var(--mark);
  color: var(--link-strong);
  border-radius: 3px;
  padding: 0 1px;
}
.search__item-path { font-size: 12px; color: var(--ink-3); flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search__item-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.55;
  margin-top: 2px;
}
.search__empty { padding: 26px 20px 30px; text-align: center; color: var(--ink-3); font-size: 14px; }
.search__hint {
  padding: 9px 17px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  gap: 4px;
  align-items: center;
}
@media (hover: none) {
  .search__hint { display: none; }
  .searchtrigger__kbd { display: none; } /* 터치 기기에 하드웨어 키 힌트는 노이즈다 */
}

/* ---------- 그래프 크게 보기 ---------- */
.graphview {
  width: min(1100px, calc(100vw - 48px));
  height: min(720px, calc(100dvh - 88px));
  padding: 0;
  border: 0;
  border-radius: var(--r-l);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  flex-direction: column;
}
/* display는 열렸을 때만 — 닫힌 dialog에 display를 주면 기본 숨김이 풀려 페이지 맨 아래에 보인다 */
.graphview[open] { display: flex; }
.graphview::backdrop {
  background: rgba(40, 30, 20, 0.45);
  backdrop-filter: blur(2px);
}
.graphview[open] { animation: search-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1); }
.graphview__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.graphview__icon { width: 18px; height: 18px; color: var(--link); flex: none; }
.graphview__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.graphview__close {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.graphview__close:hover { color: var(--ink); border-color: var(--line-2); }
.graphview__stage { flex: 1; min-height: 0; position: relative; }
.graphview__stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.graphview__hint {
  margin: 0;
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-3);
}

/* ---------- 맨 위로 ---------- */
.totop {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--ink-2);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: var(--shadow-float);
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease, border-color 0.15s ease;
}
.totop.is-visible { opacity: 1; transform: none; }
.totop:hover { color: var(--link); border-color: var(--link); }

/* ---------- 404 ---------- */
.page--notfound { text-align: center; padding-top: 8vh; }
.notfound__code {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(72px, 14vw, 120px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--line-2);
}
.page--notfound .page__title { margin-top: 10px; }
.notfound__lead { color: var(--ink-2); margin: 0 0 26px; }
.notfound__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 650;
  color: #fff;
  background: var(--link);
  border: 1px solid transparent;
  border-radius: var(--r-m);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.btn:hover { background: var(--link-strong); }
.btn:active { transform: translateY(1px); }
.btn--ghost {
  color: var(--ink-2);
  background: transparent;
  border-color: var(--line-2);
}
.btn--ghost:hover { background: var(--surface); color: var(--ink); }

/* 태블릿에서 본문 상단에 들어가는 접기 목차/그래프 */
.page__extras { display: none; }

/* ---------- 반응형 ---------- */
/* 768–1199 (태블릿): 본문 중심 1열, 목차는 본문 상단 접기 영역, 탐색은 버튼(기획 §5.4) */
@media (max-width: 1199px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .topbar { display: grid; }
  .page__extras {
    display: block;
    margin: 6px 0 26px;
  }
  .page__extras .toc, .page__extras .graphcard { max-width: var(--measure); margin: 0 0 12px; }
  .page__extras .graphcard__viewport { height: 260px; }
  .page__extras .toc__list { border: 1px solid var(--line); border-radius: var(--r-m); padding: 8px 6px; background: var(--surface); }
  .page__extras .toc__link.is-active { background: none; }
  .main { padding: calc(var(--topbar-h) + 20px) 32px 28px; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(320px, 88vw);
    height: 100dvh;
    transform: translateX(-102%);
    transition: transform 0.26s cubic-bezier(0.3, 0.9, 0.3, 1);
    box-shadow: none;
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow-pop); }
  .prose .md-h { scroll-margin-top: calc(var(--topbar-h) + 18px); }
}

@media (max-width: 767px) {
  body { font-size: 16px; }
  .main { padding: calc(var(--topbar-h) + 12px) 18px 24px; }
  .prose { font-size: 16px; }
  .page__title { font-size: 24px; }
  .prose h2.md-h { font-size: 21.5px; margin-top: 1.9em; }
  .prose h3.md-h { font-size: 18.5px; }
  .callout { padding: 11px 14px 11px 13px; }
  .callout__body { font-size: 15px; }
  .prose table { font-size: 14px; }
  .codeblock pre { font-size: 12.5px; padding: 13px 14px; }
  .backlinks { margin-top: 42px; }
}

/* ---------- 접근성: 모션 최소화 ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- 인쇄 ---------- */
@media print {
  .sidebar, .rail, .topbar, .scrim, .totop, .search, .skip-link, .sitefooter, .codeblock__copy { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  body { font-size: 12pt; }
}
