/* ---------- 테마 변수 ---------- */
:root {
  --bg: #ffffff;
  --fg: #37352f;
  --muted: #787774;
  --border: #e9e9e7;
  --code-bg: #f7f6f3;
  --inline-code: #eb5757;
  --link: #37352f;
  --chip-bg: #f1f0ee;
  --callout-bg: #f7f6f3;
}
[data-theme="dark"] {
  --bg: #191919;
  --fg: #d4d4d4;
  --muted: #9b9b9b;
  --border: #2f2f2f;
  --code-bg: #202020;
  --inline-code: #ff7369;
  --link: #d4d4d4;
  --chip-bg: #252525;
  --callout-bg: #202020;
}
[data-theme="dark"] .shiki,
[data-theme="dark"] .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
}
[data-theme="dark"] .post img { filter: brightness(0.85); }
[data-theme="dark"] .sun { display: none; }
:root:not([data-theme="dark"]) .moon { display: none; }

/* ---------- 기본 ---------- */
* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 80px; /* 스티키 헤더에 앵커가 가려지지 않도록 */
  interpolate-size: allow-keywords; /* details 높이 애니메이션용 */
}
body {
  margin: 0 auto;
  padding: 0 20px;
  max-width: 720px;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 14px;
  line-height: 1.75;
  word-break: keep-all;
  transition: background 0.15s ease;
}
a { color: var(--link); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--muted); }
hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
img, video, iframe { max-width: 100%; }
img { border-radius: 4px; }

/* ---------- 헤더/푸터 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 14px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}
.site-title { font-weight: 700; font-size: 15px; text-decoration: none; }
.site-header nav { display: flex; align-items: center; gap: 14px; }
.site-header nav a { color: var(--muted); text-decoration: none; font-size: 13px; }
.site-header nav a:hover { color: var(--fg); }
#theme-toggle {
  display: flex;
  align-items: center;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
#theme-toggle:hover { background: var(--chip-bg); color: var(--fg); }
.site-footer {
  margin: 48px 0 24px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

/* ---------- 글 목록 ---------- */
.post-list { list-style: none; padding: 0; margin: 0; }
.post-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
}
.post-item .tags {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.post-item time {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.post-item a {
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.post-item a:hover { text-decoration: underline; }
.chip {
  flex: none;
  font-size: 11px;
  color: var(--muted);
  background: var(--chip-bg);
  border-radius: 3px;
  padding: 1px 6px;
  text-decoration: none;
}
a.chip:hover { color: var(--fg); }

/* ---------- 글 페이지 ---------- */
.post-title { font-size: 1.7em; line-height: 1.4; margin: 0.4em 0 0.3em; font-weight: 700; }
.post-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.post h1 { font-size: 1.45em; margin: 1.6em 0 0.5em; }
.post h2 { font-size: 1.25em; margin: 1.6em 0 0.5em; }
.post h3 { font-size: 1.1em; margin: 1.4em 0 0.4em; }
.post h4 { font-size: 1em; margin: 1.2em 0 0.4em; }
.post blockquote {
  margin: 1em 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--fg);
  color: var(--muted);
}
.post ul, .post ol { padding-left: 1.5em; }
.post li { margin: 2px 0; }
.post table {
  border-collapse: collapse;
  font-size: 13px;
  margin: 1em 0;
  display: block;
  overflow-x: auto;
}
.post th, .post td { border: 1px solid var(--border); padding: 5px 10px; }
.post th { background: var(--code-bg); font-weight: 600; }
.post details {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
}
.post summary { cursor: pointer; font-weight: 600; }

/* ---------- 코드 ---------- */
code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
}
:not(pre) > code {
  color: var(--inline-code);
  background: var(--code-bg);
  border-radius: 3px;
  padding: 1px 5px;
}
pre {
  background: var(--code-bg) !important;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.6;
}
pre code { font-size: 12.5px; }

/* ---------- 노션식 토글 (>! 문법) ---------- */
.post details.toggle {
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 1px 0;
}
.toggle > summary {
  display: flex;
  align-items: baseline;
  gap: 6px;
  list-style: none;
  cursor: pointer;
  padding: 2px 6px 2px 4px;
  margin-left: -4px;
  border-radius: 4px;
}
.toggle > summary::-webkit-details-marker { display: none; }
.toggle > summary::before {
  content: "▶";
  flex: none;
  font-size: 8px;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.toggle[open] > summary::before { transform: rotate(90deg); }
.toggle > summary:hover { background: var(--chip-bg); }
/* 내부 콘텐츠: 노션처럼 들여쓰고 위아래 간격은 촘촘하게 */
.toggle > *:not(summary) { margin-left: 19px; }
.toggle > p,
.toggle > ul,
.toggle > ol,
.toggle > blockquote,
.toggle > pre {
  margin-top: 3px;
  margin-bottom: 3px;
}
.toggle li { margin: 1px 0; }
/* 부드럽게 열리기 (지원 브라우저에서만, 미지원 시 즉시 열림) */
.toggle::details-content {
  opacity: 0;
  block-size: 0;
  overflow-y: clip;
  transition: content-visibility 0.2s allow-discrete, opacity 0.2s ease, block-size 0.2s ease;
}
.toggle[open]::details-content {
  opacity: 1;
  block-size: auto;
}

/* ---------- 시리즈/콜아웃/비디오 ---------- */
.series {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--code-bg);
  padding: 10px 16px;
  margin: 1.2em 0;
  font-size: 13px;
}
/* .post details의 테두리 스타일이 시리즈 박스 안쪽에 이중으로 그려지지 않도록 해제 */
.series details {
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0;
}
.series summary { cursor: pointer; font-weight: 600; }
.series ol { margin: 6px 0 4px; padding-left: 1.4em; }
.series li { margin: 2px 0; }
.series li.current { font-weight: 600; }
.series li time { color: var(--muted); font-size: 11px; margin-left: 8px; }
.series a { text-decoration: none; }
.series a:hover { text-decoration: underline; }
.callout {
  display: flex;
  gap: 10px;
  background: var(--callout-bg);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 1em 0;
}
.video { position: relative; aspect-ratio: 16 / 9; margin: 1em 0; }
.video iframe { width: 100%; height: 100%; border: 0; border-radius: 6px; }

/* ---------- 홈 ---------- */
.ghchart { display: block; width: 100%; margin: 14px 0 4px; }
[data-theme="dark"] .ghchart { filter: brightness(0.85); }

/* ---------- 태그 ---------- */
.page-title { font-size: 1.15em; font-weight: 700; margin: 0.4em 0 0.8em; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.tag-cloud-item {
  background: var(--chip-bg);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 13px;
  text-decoration: none;
}
.tag-cloud-item span { color: var(--muted); font-size: 11px; margin-left: 5px; }

/* ---------- 위로가기 버튼 ---------- */
#to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 20;
}
#to-top.show { opacity: 1; visibility: visible; }
#to-top:hover { color: var(--fg); background: var(--chip-bg); }

/* ---------- 우측 목차 (노션 스타일) ---------- */
.toc {
  position: fixed;
  top: 140px;
  right: 20px;
  display: none;
  z-index: 5;
}
@media (min-width: 800px) { .toc { display: block; } }
.toc-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
  padding: 6px 2px;
  transition: opacity 0.15s ease;
}
.toc-bars span {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  width: 16px;
}
.toc-bars span.lv1 { width: 11px; }
.toc-bars span.lv2 { width: 7px; }
.toc-bars span.active { background: var(--muted); }
.toc:hover .toc-bars { opacity: 0; }
.toc-list {
  position: absolute;
  top: 0;
  right: 0;
  width: 230px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}
.toc:hover .toc-list { opacity: 1; visibility: visible; }
.toc-list a {
  display: block;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-list a.lv1 { padding-left: 12px; }
.toc-list a.lv2 { padding-left: 24px; }
.toc-list a:hover { color: var(--fg); }
.toc-list a.active { color: var(--fg); font-weight: 600; }

/* ---------- 수식 ---------- */
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

@media (max-width: 480px) {
  .post-item a { white-space: normal; }
  .post-item .tags { display: none; }
}
