:root {
  color-scheme: light;
  --ink: #1b1e3c;
  --paper: #eef0f8;
  --surface: #ffffff;
  --muted: #5b6080;
  --line: #d3d7e8;
  --teal: #0b6e8e;
  --sun: #ffc93c;
  --gone: #c4405a;
  --box-ink: #1b1e3c;
  --display: 'Bagel Fat One', 'Pretendard Variable', sans-serif;
  --body: 'Pretendard Variable', Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --wrap: 68rem;
  --text: 42rem;
  --top-h: 3.75rem;
  --side-w: 17rem;
  /* 글 안 코드 블록: Tokyo Night 팔레트 */
  --code-bg: #1a1b26;
  --code-line: #2a2e47;
  --code-fg: #c0caf5;
  --code-punct: #a9b1d6;
  --code-comment: #7a85a8; /* Tokyo Night 주석색(#565f89)은 대비가 낮아 읽기 좋게 한 단계 밝힘 */
  --code-keyword: #bb9af7;
  --code-type: #2ac3de;
  --code-func: #7aa2f7;
  --code-prop: #73daca;
  --code-string: #9ece6a;
  --code-number: #ff9e64;
  --code-operator: #89ddff;
  --code-regex: #b4f9f8;
  --code-tag: #f7768e;
  --code-param: #e0af68;
}
/* OS 가 다크일 때 (테마를 아직 고르지 않은 첫 방문이 따른다) */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #eceefa;
    --paper: #14162b;
    --surface: #1e2140;
    --muted: #a3a8c8;
    --line: #34385e;
    --teal: #6cc7e6;
    --gone: #ff8fa3;
    --code-bg: #20233c;
    --code-line: #373c60;
  }
}
/* 손으로 고른 테마는 OS 설정을 이긴다 (data-theme 이 있으면 위 media 규칙을 덮는다) */
:root[data-theme='dark'] {
  color-scheme: dark;
  --ink: #eceefa;
  --paper: #14162b;
  --surface: #1e2140;
  --muted: #a3a8c8;
  --line: #34385e;
  --teal: #6cc7e6;
  --gone: #ff8fa3;
  --code-bg: #20233c;
  --code-line: #373c60;
}
:root[data-theme='light'] {
  color-scheme: light;
  --ink: #1b1e3c;
  --paper: #eef0f8;
  --surface: #ffffff;
  --muted: #5b6080;
  --line: #d3d7e8;
  --teal: #0b6e8e;
  --gone: #c4405a;
  --code-bg: #1a1b26;
  --code-line: #2a2e47;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; border-radius: 4px; }
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3, p, ul, ol, dl, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }

.skip { position: absolute; left: -999px; top: 0; background: var(--sun); color: #1b1e3c; padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* 상단 */
.top {
  position: sticky; top: 0; z-index: 5; height: var(--top-h);
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1rem;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { font-family: var(--display); font-size: 1.5rem; color: var(--ink); text-decoration: none; line-height: 1; }
.burger { display: grid; gap: 5px; width: 2.5rem; height: 2.5rem; padding: 0 0.55rem; align-content: center; background: var(--surface); border: 2px solid var(--ink); border-radius: 0.75rem; cursor: pointer; }
.burger span { display: block; height: 2.5px; border-radius: 2px; background: var(--ink); transition: width 0.15s; }
.burger span:nth-child(2) { width: 70%; }
.burger:hover span:nth-child(2) { width: 100%; }
.burger:hover { background: var(--sun); border-color: #1b1e3c; }
.burger:hover span { background: #1b1e3c; }

/* 검색 · 테마 버튼 */
.top-tools { margin-left: auto; display: flex; align-items: center; gap: 0.35rem; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  height: 2.35rem; padding: 0 0.7rem;
  font: inherit; font-size: 0.88rem; font-weight: 800; line-height: 1;
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.12s;
}
.icon-btn:hover { border-color: #1b1e3c; background: var(--sun); color: #1b1e3c; }
.icon-btn:active { transform: translateY(1px); }
.icon-btn .ico { width: 1.05rem; height: 1.05rem; flex: none; }
.icon-btn .shortcut {
  font-family: var(--body); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.02em;
  color: var(--muted); background: var(--paper); border: 1px solid var(--line); border-radius: 0.35rem;
  padding: 0.12rem 0.3rem;
}
.icon-btn:hover .shortcut { color: #1b1e3c; border-color: #1b1e3c; background: transparent; }
/* 지금 테마에 따라 해 / 달 아이콘 하나만 보인다 */
.theme-btn .ico-sun { display: none; }
@media (prefers-color-scheme: dark) {
  .theme-btn .ico-sun { display: block; }
  .theme-btn .ico-moon { display: none; }
}
:root[data-theme='dark'] .theme-btn .ico-sun { display: block; }
:root[data-theme='dark'] .theme-btn .ico-moon { display: none; }
:root[data-theme='light'] .theme-btn .ico-sun { display: none; }
:root[data-theme='light'] .theme-btn .ico-moon { display: block; }

/* 언어 전환: 지구본 + 언어 코드 버튼을 누르면 KO / EN / JA / ZH 목록이 열린다.
   링크 네 개를 늘어놓지 않아 좁은 화면에서도 머리글이 개행되지 않는다. */
.lang { position: relative; flex: none; font-size: 0.9rem; font-weight: 800; letter-spacing: 0.01em; white-space: nowrap; }
.lang-box { display: block; position: relative; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 0.32rem;
  height: 2.35rem; padding: 0 0.6rem;
  font: inherit; font-size: 0.82rem; font-weight: 800; line-height: 1;
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 999px;
  cursor: pointer; list-style: none; user-select: none;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.lang-btn::-webkit-details-marker { display: none; }
.lang-btn::marker { content: ''; }
.lang-btn:hover, .lang-box[open] .lang-btn { border-color: #1b1e3c; background: var(--sun); color: #1b1e3c; }
.lang-btn .ico { flex: none; }
.lang-btn .lang-globe { width: 1.05rem; height: 1.05rem; }
.lang-btn .lang-caret { width: 0.78rem; height: 0.78rem; transition: transform 0.15s; }
.lang-box[open] .lang-btn .lang-caret { transform: rotate(180deg); }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 0.75rem); z-index: 6;
  min-width: 9.75rem; padding: 0.35rem;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 0.95rem;
  box-shadow: 0 18px 44px rgba(15, 17, 36, 0.24);
  animation: fade-in 0.14s ease-out;
}
.lang-menu a { display: flex; align-items: center; gap: 0.55rem; padding: 0.5rem 0.6rem; border-radius: 0.62rem; color: var(--ink); text-decoration: none; }
.lang-menu a:hover { background: var(--paper); }
.lang-menu a[aria-current='true'] { background: var(--sun); color: #1b1e3c; }
.lang-menu .lc { min-width: 1.75rem; font-size: 0.82rem; font-weight: 800; letter-spacing: 0.02em; color: inherit; }
.lang-menu .ln { font-size: 0.92rem; font-weight: 600; }
.lang-menu a:not([aria-current='true']) .lc { color: var(--muted); }

/* 왼쪽 메뉴: 넓은 화면은 펼친 채로 붙어 있고, 좁은 화면은 햄버거로 덮어 연다 */
.side {
  position: fixed; z-index: 4; left: 0; top: var(--top-h); bottom: 0; width: var(--side-w);
  padding: 1.25rem 0.75rem 2rem; overflow-y: auto;
  background: var(--paper); border-right: 1px solid var(--line);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0.22s;
}
.side-main a { display: block; padding: 0.5rem 0.75rem; border-radius: 0.6rem; font-size: 1.05rem; font-weight: 800; color: var(--ink); text-decoration: none; }
.side a:hover { background: var(--surface); }
.side a[aria-current] { background: var(--sun); color: #1b1e3c; }
.side h2 { margin: 1.25rem 0 0.4rem; padding: 1rem 0.75rem 0; border-top: 1px solid var(--line); font-size: 0.85rem; font-weight: 700; color: var(--muted); }
.side-posts a { display: block; padding: 0.55rem 0.75rem; border-radius: 0.6rem; color: var(--ink); text-decoration: none; font-size: 0.95rem; font-weight: 600; line-height: 1.45; }
.side-tools a { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border-radius: 0.6rem; color: var(--ink); text-decoration: none; font-size: 0.95rem; font-weight: 700; }
.side-tools a::before { content: ''; flex: none; width: 0.42rem; height: 0.42rem; border-radius: 999px; background: var(--sun); border: 1.5px solid #1b1e3c; }
.side-posts time { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-posts a[aria-current] time { color: #1b1e3c; }
.side-foot { margin-top: 1.25rem; padding: 0 0.75rem; font-size: 0.9rem; }
.side-backdrop { display: none; }
.page { transition: margin-left 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }

@media (min-width: 1000px) {
  .page { margin-left: var(--side-w); }
  .side-closed .page { margin-left: 0; }
  .side-closed .side { transform: translateX(-100%); visibility: hidden; }
}
@media (max-width: 999.98px) {
  .side { z-index: 21; top: 0; width: min(20rem, 86vw); padding-top: 1.5rem; border-right: 2px solid var(--ink); transform: translateX(-100%); visibility: hidden; }
  .side-main a { font-size: 1.2rem; padding: 0.55rem 0.75rem; }
  .side-open .side { transform: none; visibility: visible; }
  .side-open .side-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(15, 17, 36, 0.55); animation: fade-in 0.22s; }
  .side-open body { overflow: hidden; }
}
@keyframes fade-in { from { opacity: 0; } }

/* 읽기 진행률: 글 화면 상단에 노란 선이 스크롤만큼 차오른다 */
.read-progress { position: fixed; left: 0; right: 0; top: var(--top-h); height: 3px; z-index: 6; pointer-events: none; }
.read-progress-fill { display: block; height: 100%; width: 100%; background: var(--sun); transform: scaleX(0); transform-origin: 0 50%; transition: transform 0.12s linear; will-change: transform; }

/* 글 검색 모달 (Ctrl+K) */
.search { width: min(42rem, calc(100vw - 1.5rem)); margin: 9vh auto auto; padding: 0; border: 0; background: transparent; overflow: visible; }
.search::backdrop { background: rgba(15, 17, 36, 0.55); backdrop-filter: blur(3px); }
.search-in { display: flex; flex-direction: column; max-height: min(78vh, 46rem); background: var(--surface); border: 2px solid var(--ink); border-radius: 1.15rem; box-shadow: 0 22px 60px rgba(15, 17, 36, 0.35); overflow: hidden; animation: search-in 0.16s ease-out; }
@keyframes search-in { from { opacity: 0; transform: translateY(-0.6rem); } }
.search-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.9rem 1rem; border-bottom: 1px solid var(--line); }
.search-ico { width: 1.15rem; height: 1.15rem; flex: none; color: var(--muted); }
.search-row input { flex: 1; min-width: 0; font: inherit; font-size: 1.05rem; font-weight: 600; color: var(--ink); background: transparent; border: 0; padding: 0.2rem 0; }
.search-row input:focus { outline: none; }
.search-close { font: inherit; font-size: 0.75rem; font-weight: 800; color: var(--muted); background: var(--paper); border: 1px solid var(--line); border-radius: 0.4rem; padding: 0.2rem 0.45rem; cursor: pointer; }
.search-close:hover { color: #1b1e3c; border-color: #1b1e3c; background: var(--sun); }
.search-status { padding: 0.7rem 1rem 0.2rem; font-size: 0.82rem; font-weight: 700; color: var(--muted); }
.search-status:empty { display: none; }
.search-results { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0.35rem 0.5rem 0.5rem; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.search-results:empty { display: none; }
.search-results a { display: grid; gap: 0.15rem; padding: 0.6rem 0.7rem; border-radius: 0.7rem; color: var(--ink); text-decoration: none; }
.search-results a:hover { background: var(--paper); }
.search-results li[aria-selected='true'] a { background: var(--sun); color: #1b1e3c; }
.search-results .r-title { font-weight: 800; font-size: 1rem; line-height: 1.4; }
.search-results .r-meta { font-size: 0.75rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.search-results li[aria-selected='true'] .r-meta { color: #40466b; }
.search-results .r-sum { font-size: 0.86rem; color: var(--muted); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-results li[aria-selected='true'] .r-sum { color: #2a2e4d; }
.search-results mark { background: var(--sun); color: #1b1e3c; border-radius: 0.2rem; padding: 0 0.1em; }
.search-results li[aria-selected='true'] mark { background: #1b1e3c; color: var(--sun); }
.search-hint { display: flex; flex-wrap: wrap; gap: 0.9rem; padding: 0.65rem 1rem; border-top: 1px solid var(--line); font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.search-hint kbd { font-family: var(--body); font-size: 0.7rem; border: 1px solid var(--line); border-radius: 0.3rem; padding: 0.05rem 0.28rem; margin-right: 0.15rem; }

main { padding: 0 1rem; }

/* 히어로 */
.hero {
  max-width: var(--wrap); margin: 0 auto;
  padding: clamp(2.5rem, 7vw, 5rem) 0 clamp(2.5rem, 6vw, 4rem);
  display: grid; gap: clamp(2rem, 5vw, 3.5rem);
}
.hero h1 {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(2.5rem, 8.4vw, 5.6rem);
  line-height: 1.12; letter-spacing: -0.01em;
  max-width: 13em; text-wrap: balance;
}
.lead { margin-top: 1.25rem; max-width: 36rem; font-size: 1.15rem; color: var(--muted); }
.hero-links { margin-top: 1.75rem; display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; }
.btn {
  display: inline-block; background: var(--sun); color: #1b1e3c;
  font-weight: 700; text-decoration: none;
  padding: 0.8rem 1.4rem; border-radius: 999px;
  box-shadow: 0 4px 0 #1b1e3c; transition: transform 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: translateY(2px); box-shadow: 0 2px 0 #1b1e3c; }
.btn:active { transform: translateY(4px); box-shadow: none; }
.plain { font-weight: 600; }

/* 합쳐지는 무대 */
.stage {
  position: relative;
  display: grid; grid-template-columns: 1fr auto 15rem; align-items: center; gap: 1.5rem;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 1.75rem;
  padding: clamp(1.25rem, 3vw, 2.25rem) clamp(1.25rem, 3vw, 2.25rem) 3.5rem;
}
.cloud { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  font-size: 0.875rem; font-weight: 600; line-height: 1;
  padding: 0.55rem 0.8rem; border-radius: 0.6rem;
  background: var(--paper); border: 1.5px solid var(--ink); color: var(--ink);
  white-space: nowrap;
}
.chip.gone { border-style: dashed; border-color: var(--line); color: var(--muted); background: transparent; text-decoration: line-through; text-decoration-color: var(--gone); }
.chip.fly { position: fixed; z-index: 4; margin: 0; pointer-events: none; }
.arrow { width: 2.5rem; height: 2px; background: var(--ink); position: relative; }
.arrow::after { content: ''; position: absolute; right: 0; top: -5px; width: 10px; height: 10px; border-top: 2px solid var(--ink); border-right: 2px solid var(--ink); transform: rotate(45deg); }
.box {
  background: var(--sun); color: var(--box-ink);
  border: 2px solid #1b1e3c; border-radius: 1.25rem;
  padding: 1.25rem; text-align: center;
  box-shadow: 0 8px 0 #1b1e3c;
}
.box.hit { animation: hit 0.18s ease-out; }
@keyframes hit { 50% { transform: scale(1.045); } }
.count { font-family: var(--display); font-size: 4.5rem; line-height: 1; font-variant-numeric: tabular-nums; }
.count .unit { font-size: 1.5rem; margin-left: 0.15rem; }
.box-name { font-weight: 800; font-size: 1.15rem; margin-top: 0.25rem; }
.inside { margin-top: 0.75rem; display: grid; gap: 0.35rem; }
.inside li { background: #1b1e3c; color: #fff; border-radius: 0.5rem; font-size: 0.85rem; font-weight: 600; padding: 0.35rem; }
.replay {
  position: absolute; left: clamp(1.25rem, 3vw, 2.25rem); bottom: 0.9rem;
  font: inherit; font-size: 0.875rem; font-weight: 600; color: var(--teal);
  background: none; border: 0; padding: 0.25rem 0; cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em;
}
.replay[disabled] { opacity: 0.4; cursor: default; }

/* 글 */
.post { max-width: var(--wrap); margin: 0 auto; padding: clamp(2rem, 5vw, 3.5rem) 0 clamp(2.5rem, 6vw, 4rem); }
.post-head { max-width: var(--text); }
.date { color: var(--muted); font-size: 0.95rem; font-weight: 600; }
.post h1, .list h2, .repos h2, footer h2 { font-family: var(--display); font-weight: 400; font-size: clamp(1.9rem, 4.6vw, 3rem); line-height: 1.2; text-wrap: balance; }
.post h1 { margin-top: 0.5rem; }
.summary { margin-top: 1.25rem; font-size: 1.15rem; }

.prose > * { max-width: var(--text); }
.prose > .facts, .prose > .shots, .prose > .wide, .prose > .loop, .prose > .stage, .prose > .mermaid { max-width: none; }
.prose > .stage { margin-top: 1.25rem; }
.stage .sr-only { margin: 0; }

.prose h2 { font-size: 1.4rem; font-weight: 800; margin-top: 2.75rem; line-height: 1.35; }
.prose h3 { font-size: 1.15rem; font-weight: 800; margin-top: 2rem; }

/* 글 본문 + 우측 목차 */
.post-body { display: grid; grid-template-columns: minmax(0, 1fr); }
.toc { display: none; }
.toc-title { font-size: 0.76rem; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.toc-list { margin-top: 0.55rem; display: grid; gap: 0.1rem; }
.toc-list a { display: block; padding: 0.3rem 0.55rem; border-radius: 0.5rem; color: var(--muted); font-size: 0.9rem; font-weight: 600; line-height: 1.4; text-decoration: none; transition: color 0.15s, background 0.15s; }
.toc-list .lvl-3 a { padding-left: 1.3rem; font-size: 0.83rem; font-weight: 500; }
.toc-list a:hover { color: var(--ink); background: var(--surface); }
.toc-list a[aria-current='true'] { color: #1b1e3c; background: var(--sun); font-weight: 800; }

/* 좁은 화면 목차: 오른쪽 아래 떠 있는 버튼 + 누르면 열리는 카드. 넓은 화면은 위의 고정 목차를 쓴다 */
.toc-toggle { display: none; }
@media (max-width: 1239.98px) {
  .toc-toggle:not([hidden]) {
    display: inline-flex; align-items: center; gap: 0.45rem;
    position: fixed; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
    z-index: 15;
    font: inherit; font-size: 0.92rem; font-weight: 800; letter-spacing: 0.01em;
    color: var(--ink); background: var(--surface);
    border: 1.5px solid var(--ink); border-radius: 999px;
    padding: 0.5rem 0.95rem 0.5rem 0.6rem;
    box-shadow: 0 4px 0 var(--ink), 0 10px 22px rgba(15, 17, 36, 0.16);
    cursor: pointer; transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
  }
  .toc-toggle:hover { transform: translateY(1px); }
  .toc-toggle:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
  .toc-toggle[aria-expanded='true'] { background: var(--sun); }
  .toc-toggle-ico { display: grid; place-items: center; flex: none; width: 1.5rem; height: 1.5rem; padding: 0.26rem; border-radius: 999px; background: var(--sun); color: #1b1e3c; }
  .toc-toggle-ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
  .toc-toggle[aria-expanded='true'] .toc-toggle-ico { background: #1b1e3c; color: var(--sun); }

  .toc.toc-open:not([hidden]) {
    display: block;
    position: fixed; right: max(1rem, env(safe-area-inset-right)); bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 3.85rem);
    z-index: 15;
    width: min(21rem, calc(100vw - 2rem));
    max-height: 62vh;
    max-height: min(62vh, calc(100dvh - var(--top-h) - 8rem));
    overflow-y: auto; overscroll-behavior: contain;
    padding: 0.9rem 0.85rem 1rem;
    background: var(--surface); border: 2px solid var(--ink); border-radius: 1.1rem;
    box-shadow: 0 12px 0 -4px rgba(27, 30, 60, 0.1), 0 20px 44px rgba(15, 17, 36, 0.26);
    animation: toc-in 0.18s ease-out;
    scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  }
  .toc.toc-open .toc-list a { padding: 0.4rem 0.55rem; }
  .toc.toc-open .toc-list .lvl-3 a { padding-left: 1.25rem; }
  /* 떠 있는 버튼이 글 끝의 이전·다음 글 링크를 가리지 않게 */
  .post { padding-bottom: clamp(4.5rem, 12vw, 6rem); }
}
@keyframes toc-in { from { opacity: 0; transform: translateY(0.6rem); } }
@media (prefers-reduced-motion: reduce) { .toc.toc-open:not([hidden]) { animation: none; } }
@media (min-width: 1240px) {
  .post-body { grid-template-columns: minmax(0, 1fr) 14rem; gap: 2.5rem; align-items: start; }
  .toc:not([hidden]) { display: block; position: sticky; top: calc(var(--top-h) + 1.5rem); max-height: calc(100vh - var(--top-h) - 3rem); overflow-y: auto; overscroll-behavior: contain; padding: 0.15rem 0 0.5rem 1.1rem; border-left: 2px solid var(--line); scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
}
.prose p, .prose > ul, .prose > ol, .prose blockquote, .prose pre, .prose > figure, .prose > img { margin-top: 0.9rem; }
.prose ul:not([class]) { list-style: disc; padding-left: 1.3rem; }
.prose ol:not([class]) { list-style: decimal; padding-left: 1.4rem; }
.prose ul:not([class]) > li + li, .prose ol:not([class]) > li + li { margin-top: 0.25rem; }
.prose blockquote { margin-left: 0; margin-right: 0; padding: 0.1rem 0 0.1rem 1rem; border-left: 4px solid var(--sun); color: var(--muted); }
.prose blockquote p:first-child { margin-top: 0; }
.prose code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 0.9em; background: var(--surface); border: 1px solid var(--line); border-radius: 0.35rem; padding: 0.1em 0.35em; }
/* 코드 블록: Rouge 가 남기는 토큰 클래스에 Tokyo Night 색을 입힌다 */
.prose pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--code-line);
  border-radius: 0.9rem;
  padding: 1.05rem 1.2rem;
  overflow-x: auto;
  line-height: 1.6;
  font-size: 0.9rem;
  tab-size: 4;
  -webkit-font-smoothing: antialiased;
  scrollbar-width: thin;
  scrollbar-color: var(--code-line) transparent;
}
.prose pre::-webkit-scrollbar { height: 8px; }
.prose pre::-webkit-scrollbar-thumb { background: var(--code-line); border-radius: 999px; }
.prose pre::-webkit-scrollbar-track { background: none; }
.prose pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.prose pre ::selection { background: rgba(122, 162, 247, 0.32); }

/* 코드 블록 복사 버튼: main.js 가 블록마다 붙인다 */
.prose .code-block { position: relative; }
.prose .code-block pre { padding-top: 2.4rem; }
.code-copy {
  position: absolute; top: 0.5rem; right: 0.5rem; z-index: 1;
  font: inherit; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.02em; line-height: 1;
  color: var(--code-fg); background: rgba(42, 46, 71, 0.94);
  border: 1px solid var(--code-line); border-radius: 0.5rem;
  padding: 0.38rem 0.62rem; cursor: pointer;
  opacity: 0.72; transition: opacity 0.15s, background 0.15s, color 0.15s, border-color 0.15s;
}
.code-block:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.code-copy:hover { background: var(--sun); color: #1b1e3c; border-color: #1b1e3c; }
.code-copy.done { background: var(--sun); color: #1b1e3c; border-color: #1b1e3c; opacity: 1; }

/* 주석 */
.prose .highlight .c, .prose .highlight .c1, .prose .highlight .cm,
.prose .highlight .cs, .prose .highlight .ch, .prose .highlight .gp { color: var(--code-comment); font-style: italic; }
/* 전처리기 지시자 (#include, #if) */
.prose .highlight .cp, .prose .highlight .cpf { color: var(--code-type); }
/* 키워드·제어문 */
.prose .highlight .k, .prose .highlight .kc, .prose .highlight .kd,
.prose .highlight .kn, .prose .highlight .kp, .prose .highlight .kr { color: var(--code-keyword); }
/* 타입·클래스·네임스페이스 */
.prose .highlight .kt, .prose .highlight .nc, .prose .highlight .nn,
.prose .highlight .ne, .prose .highlight .nb, .prose .highlight .bp { color: var(--code-type); }
/* 함수·메서드 */
.prose .highlight .nf, .prose .highlight .fm { color: var(--code-func); }
/* 속성·키 (YAML·JSON 키, 헤더 이름) */
.prose .highlight .na { color: var(--code-prop); }
/* 문자열 */
.prose .highlight .s, .prose .highlight .sa, .prose .highlight .sb,
.prose .highlight .sc, .prose .highlight .dl, .prose .highlight .sd,
.prose .highlight .s1, .prose .highlight .s2, .prose .highlight .sh,
.prose .highlight .si, .prose .highlight .sx, .prose .highlight .ss { color: var(--code-string); }
/* 문자열 안의 이스케이프 */
.prose .highlight .se { color: var(--code-operator); }
/* 정규식 */
.prose .highlight .sr { color: var(--code-regex); }
/* 숫자·상수·날짜 */
.prose .highlight .m, .prose .highlight .mb, .prose .highlight .mf,
.prose .highlight .mh, .prose .highlight .mi, .prose .highlight .il,
.prose .highlight .mo, .prose .highlight .no, .prose .highlight .l,
.prose .highlight .ld { color: var(--code-number); }
/* 연산자 */
.prose .highlight .o, .prose .highlight .ow { color: var(--code-operator); }
/* 괄호·구두점 */
.prose .highlight .p { color: var(--code-punct); }
/* 태그 */
.prose .highlight .nt { color: var(--code-tag); }
/* 데코레이터·애노테이션·매개변수 */
.prose .highlight .nd { color: var(--code-param); }
/* 이름·변수 */
.prose .highlight .n, .prose .highlight .nx, .prose .highlight .nl,
.prose .highlight .py, .prose .highlight .nv, .prose .highlight .vc,
.prose .highlight .vg, .prose .highlight .vi, .prose .highlight .vm,
.prose .highlight .ni, .prose .highlight .w { color: var(--code-fg); }
/* diff 표시 */
.prose .highlight .gd { color: var(--code-tag); }
.prose .highlight .gi { color: var(--code-string); }
.prose .highlight .gh, .prose .highlight .gu { color: var(--code-func); }
.prose .highlight .gs { font-weight: 700; }
.prose .highlight .gt { color: var(--code-tag); }
/* Rouge 가 렉서 한계로 붙이는 err 토큰($1 같은 값)은 빨간 오류색 대신 본문색으로 */
.prose .highlight .err { color: var(--code-fg); background: none; }
.prose img { border: 2px solid var(--ink); border-radius: 1rem; background: #fff; cursor: zoom-in; transition: opacity 0.2s; }
.prose img.swap { opacity: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }
.prose table { width: 100%; border-collapse: collapse; margin-top: 1.25rem; font-size: 0.97rem; }
.prose th, .prose td { text-align: left; padding: 0.7rem 0.75rem 0.7rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { font-size: 0.9rem; color: var(--muted); border-bottom: 2px solid var(--ink); }
.prose th code, .prose td code { white-space: nowrap; }
.prose td:first-child { font-weight: 700; }
.prose td:last-child { font-weight: 600; }
/* 첫 열이 한 글자씩 세로로 쪼개지지 않게 최소 폭을 준다 */
.prose th:first-child, .prose td:first-child { min-width: 5.5rem; }
/* 표가 본문 폭을 넘으면 표만 가로로 스크롤한다 (main.js 가 .table-scroll 로 감싼다) */
.prose > .table-scroll { max-width: var(--text); margin-top: 1.25rem; overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.table-scroll > table { margin-top: 0; }
.table-scroll::-webkit-scrollbar { height: 8px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.table-scroll::-webkit-scrollbar-track { background: none; }
/* 글 안의 머메이드 그림: main.js 가 code.language-mermaid 를 옮겨 그린다 */
.prose > .mermaid { margin-top: 1.25rem; padding: 1.1rem 1rem; background: var(--surface); border: 2px solid var(--ink); border-radius: 1rem; overflow-x: auto; }
.prose .mermaid svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.prose .mermaid:not([data-processed]) { white-space: pre; font-size: .875rem; color: var(--muted); }

.facts { margin: 2.5rem 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 1px; border: 2px solid var(--ink); border-radius: 1.25rem; background: var(--line); overflow: hidden; }
.facts div { padding: 1.1rem 1.25rem; background: var(--surface); }
.facts dt { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; font-family: var(--display); font-size: 2.6rem; line-height: 1.15; }
.facts dd.long { font-size: 1.5rem; line-height: 1.3; }
.facts small { font-family: var(--body); font-size: 1rem; font-weight: 700; margin-left: 0.2rem; }

.loop { counter-reset: s; display: flex; align-items: center; overflow-x: auto; padding: 0.25rem 0.25rem 0.5rem; margin-top: 1.25rem; }
.loop li:last-child { margin-right: 0; }
.loop li { counter-increment: s; flex: none; white-space: nowrap; display: flex; align-items: center; font-weight: 700; font-size: 0.95rem; background: var(--surface); border: 1.5px solid var(--ink); border-radius: 999px; padding: 0.4rem 0.9rem 0.4rem 0.45rem; margin-right: 1.5rem; position: relative; }
.loop li::before { content: counter(s); display: grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: 0.8rem; margin-right: 0.5rem; }
.loop li:not(:last-child)::after { content: ''; position: absolute; right: -1.5rem; width: 1.5rem; height: 1.5px; background: var(--ink); }
.loop li.hot { background: var(--sun); color: #1b1e3c; border-color: #1b1e3c; }

.shots { margin-top: 1.25rem; }
.tabs { display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.25rem 0.25rem 0.75rem; }
.tabs button { font: inherit; font-size: 0.95rem; font-weight: 700; white-space: nowrap; cursor: pointer; color: var(--ink); background: transparent; border: 1.5px solid var(--line); border-radius: 999px; padding: 0.45rem 1rem; }
.tabs button:hover { border-color: var(--ink); }
.tabs button[aria-selected='true'] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.shots figure img { width: 100%; }
figcaption { margin-top: 0.75rem; color: var(--muted); max-width: var(--text); font-size: 0.97rem; }

.stack { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.stack li { font-size: 0.9rem; font-weight: 600; padding: 0.3rem 0.75rem; border-radius: 0.5rem; background: var(--surface); border: 1px solid var(--line); }
.note { color: var(--muted); font-size: 0.95rem; }

.pager { margin-top: 3.5rem; padding-top: 1.5rem; border-top: 2px solid var(--ink); display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.pager a { font-weight: 700; color: var(--ink); text-decoration: none; }
.pager a:hover { color: var(--teal); }
.pager span { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.pager .next { grid-column: 2; text-align: right; }
.pager .all { grid-column: 1 / -1; color: var(--teal); text-decoration: underline; }

/* 글 하단 댓글 (giscus) */
.comments { max-width: var(--text); margin-top: 3rem; padding-top: 1.5rem; border-top: 2px solid var(--ink); }
.comments h2 { font-size: 1.25rem; font-weight: 800; }

/* 글 목록 */
.list { max-width: var(--wrap); margin: 0 auto; padding: clamp(2.5rem, 6vw, 4rem) 0; border-top: 2px solid var(--ink); }
.filter { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 1.25rem; }
.filter button { font: inherit; font-size: 0.95rem; font-weight: 700; cursor: pointer; color: var(--ink); background: transparent; border: 1.5px solid var(--line); border-radius: 999px; padding: 0.4rem 1rem; }
.filter button:hover { border-color: var(--ink); }
.filter button.on[aria-pressed='true'] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.cat { display: inline-block; font-size: 0.78rem; font-weight: 700; line-height: 1.35; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0.1rem 0.5rem; vertical-align: 0.15em; text-decoration: none; }
.lt .cat { margin-left: 0.5rem; }
a.cat:hover { border-color: var(--ink); color: var(--ink); }
.date .cat { margin-left: 0.5rem; font-weight: 700; }
.list li[hidden] { display: none; }
.list ul { margin-top: 1.5rem; border-top: 1px solid var(--line); }
.list li { border-bottom: 1px solid var(--line); }
.list li > a { display: grid; grid-template-columns: 7rem 1fr; gap: 0.25rem 1rem; padding: 1.1rem 0.5rem; color: var(--ink); text-decoration: none; transition: background 0.15s, padding-left 0.15s; }
.list li > a:hover { background: var(--surface); padding-left: 1rem; }
/* 같은 글의 언어 판 태그 (KO · EN · JA · ZH) */
.langs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: -0.55rem; padding: 0 0.5rem 0.95rem calc(8.5rem); }
.langs a { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; line-height: 1.35; color: var(--muted); text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 0.1rem 0.55rem; transition: color 0.15s, background 0.15s, border-color 0.15s; }
.langs a:hover { color: var(--ink); border-color: var(--ink); }
.langs a[aria-current] { color: var(--paper); background: var(--ink); border-color: var(--ink); }
.list time { color: var(--muted); font-size: 0.95rem; font-variant-numeric: tabular-nums; padding-top: 0.2rem; }
.lt { font-weight: 800; font-size: 1.2rem; line-height: 1.4; }
.ls { grid-column: 2; color: var(--muted); font-size: 0.97rem; max-width: var(--text); }

/* 저장소 */
.repos { max-width: var(--wrap); margin: 0 auto; padding: clamp(2.5rem, 6vw, 4rem) 0; border-top: 2px solid var(--ink); }
.repos ul { margin: 1.5rem 0; border-top: 1px solid var(--line); }
.repos li a { display: grid; grid-template-columns: 1fr 7rem 3.5rem; gap: 1rem; align-items: baseline; padding: 0.9rem 0.5rem; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; transition: background 0.15s, padding-left 0.15s; }
.repos li a:hover { background: var(--surface); padding-left: 1rem; }
.rn { font-weight: 700; font-size: 1.1rem; }
.rl, .ry { color: var(--muted); font-size: 0.95rem; }
.ry { text-align: right; font-variant-numeric: tabular-nums; }

/* 바닥 */
footer { background: #1b1e3c; color: #eceefa; padding: clamp(2.5rem, 6vw, 4rem) 1rem; }
.foot-in { max-width: var(--wrap); margin: 0 auto; }
footer ul { margin-top: 1.25rem; display: grid; gap: 0.55rem; }
footer a { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--sun); font-size: 1.15rem; font-weight: 600; text-decoration: none; }
footer a span { text-decoration: underline; text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
footer a:hover span { text-decoration-thickness: 2px; }
footer a svg { width: 1.15rem; height: 1.15rem; flex: none; }
.copy { margin-top: 2.5rem; color: #a3a8c8; font-size: 0.9rem; }

/* 크게 보기 */
dialog { border: 0; padding: 0; background: transparent; max-width: min(96vw, 1187px); }
dialog::backdrop { background: rgba(15, 17, 36, 0.82); }
dialog img { border-radius: 0.75rem; background: #fff; }
.close { font: inherit; font-weight: 700; display: block; margin: 0 0 0.5rem auto; background: var(--sun); color: #1b1e3c; border: 0; border-radius: 999px; padding: 0.4rem 1rem; cursor: pointer; }

@media (max-width: 760px) {
  .stage { grid-template-columns: 1fr; justify-items: center; }
  .cloud { justify-content: center; }
  .arrow { transform: rotate(90deg); margin: 0.5rem 0; }
  .box { width: min(15rem, 100%); }
  .list li > a { grid-template-columns: 1fr; }
  .langs { padding-left: 0.5rem; }
  .ls { grid-column: 1; }
  .repos li a { grid-template-columns: 1fr auto; }
  .ry { display: none; }
  .prose table { font-size: 0.9rem; }
  .prose > .mermaid { padding: 0.85rem 0.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 520px) {
  /* 좁은 화면: 머리글에 들어가는 요소가 적도록 간격을 줄인다 */
  .top { gap: 0.5rem; padding: 0 0.7rem; }
  .logo { font-size: 1.4rem; }
  .lang-btn { padding: 0 0.5rem; font-size: 0.78rem; gap: 0.26rem; }
}

@media (max-width: 760px) {
  .icon-btn { padding: 0 0.55rem; }
  .icon-btn-label, .icon-btn .shortcut { display: none; }
  .search { margin-top: 4vh; }
  .search-in { max-height: 86vh; }
}

@media print {
  .top-tools, .lang, .read-progress, .toc-toggle, .code-copy { display: none !important; }
  .prose .code-block pre { padding-top: 1.05rem; }
}
