/* 카드형 · 먹색: 옅은 회색 바탕 위에 흰 카드. 강조색 없이 검정과 회색만 쓴다. */
:root {
  color-scheme: light;
  --bg: #f5f5f4;
  --card: #ffffff;
  --text: #1f1f1f;
  --sub: #4b4d52;
  --muted: #5c5f66;
  --line: #e4e4e2;
  --line-strong: #d6d6d3;
  --line-hover: #a9a9a5;
  --soft: #ececea;
  --accent: #1f1f1f;
  --on-accent: #ffffff;
  --code-bg: #1f1f1f;
  --code-text: #ececea;
  --font: 'Noto Sans KR', system-ui, -apple-system, 'Segoe UI', sans-serif;
  /* 한글은 JetBrains Mono에 없으므로 바로 다음의 Noto Sans KR로 그린다(시스템 고정폭 한글 글꼴로 넘어가지 않게). */
  --mono: 'JetBrains Mono', 'Noto Sans KR', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  --gutter: 24px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
  -webkit-text-size-adjust: 100%;
}
html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; height: auto; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4, p, figure { margin: 0; }
h1, h2, h3, h4 { text-wrap: balance; }
::selection { background: #1f1f1f; color: #ffffff; }

a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.skip-link {
  position: fixed; left: 16px; top: -100px; z-index: 200;
  background: var(--accent); color: var(--on-accent); padding: 10px 18px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

/* ───────── 머리말 ───────── */

.site-header { background: var(--card); border-bottom: 1px solid var(--line); }
.nav-inner {
  max-width: 1160px; min-height: 64px; margin: 0 auto; padding: 0 var(--gutter);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.brand-mark {
  display: inline-flex; width: 28px; height: 28px; border-radius: 8px; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent); font-size: 15px; font-weight: 800;
}
.site-nav { display: flex; flex-wrap: wrap; gap: 24px; font-size: 15px; font-weight: 500; color: var(--sub); }
.site-nav a:hover { color: #000000; }
.site-nav a[aria-current='page'] { color: var(--text); font-weight: 700; }

.site-main { max-width: 1160px; margin: 0 auto; padding: 56px var(--gutter) 96px; }
.site-main.is-post { padding-top: 40px; }

.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }

/* ───────── 글 목록 ───────── */

.list-head h1 { font-size: 26px; line-height: 1.3; font-weight: 800; letter-spacing: -0.02em; }
.list-head p { margin-top: 8px; font-size: 15.5px; line-height: 1.6; color: var(--muted); }

.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.chip {
  padding: 5px 14px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card);
  font-size: 14px; line-height: 1.7; color: var(--sub);
}
.chip:hover { border-color: var(--line-hover); color: var(--text); }
.chip[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }

.card-grid {
  list-style: none; margin: 32px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 24px;
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.card:hover { border-color: #c4c4c0; box-shadow: 0 8px 24px rgb(0 0 0 / 0.06); }
.card > a { display: block; height: 100%; }
.card-cover { width: 100%; height: 200px; object-fit: cover; object-position: center 22%; background: var(--soft); }
.card-body { padding: 20px 22px 22px; }
.card-series { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.card h2 { margin-top: 8px; font-size: 17.5px; line-height: 1.5; font-weight: 700; letter-spacing: -0.01em; }
.card-summary {
  margin-top: 10px; font-size: 14.5px; line-height: 1.65; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { margin-top: 16px; font-size: 13px; color: var(--muted); }
.list-empty { margin-top: 32px; font-size: 15px; color: var(--muted); }

/* ───────── 글 화면 ───────── */

.post-layout { display: grid; grid-template-columns: minmax(0, 1fr) 224px; gap: 28px; align-items: start; }
.post-layout.no-toc { grid-template-columns: minmax(0, 860px); }

.post-cover { width: 100%; height: 340px; object-fit: cover; object-position: center 22%; background: var(--soft); }
.sheet-body { padding: 48px 56px 56px; }

.post-series { font-size: 14px; font-weight: 700; color: var(--accent); }
.post-head h1 { margin-top: 12px; font-size: 40px; line-height: 1.35; font-weight: 800; letter-spacing: -0.02em; }
.post-sub { margin-top: 10px; font-size: 20px; line-height: 1.5; color: var(--muted); }
.post-meta {
  margin-top: 28px; padding-bottom: 32px; border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
}
.byline { display: flex; align-items: center; gap: 12px; }
.avatar {
  display: inline-flex; flex: none; width: 40px; height: 40px; border-radius: 50%; align-items: center; justify-content: center;
  background: var(--soft); font-size: 16px; font-weight: 700; color: var(--sub);
}
.byline p { font-size: 14.5px; line-height: 1.5; color: var(--muted); }
.byline strong { display: block; font-weight: 700; color: var(--text); }

.tag-row { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.tag-row a, .tag-row span {
  display: block; padding: 4px 12px; border: 1px solid var(--line-strong); border-radius: 6px;
  font-size: 13.5px; line-height: 1.6; color: var(--sub);
}
.tag-row a:hover { border-color: var(--line-hover); color: var(--text); }

/* 본문 */
.prose { margin-top: 36px; font-size: 17.5px; line-height: 1.85; }
.prose > * { margin: 22px 0 0; }
.prose > :first-child { margin-top: 0; }
.prose strong { font-weight: 700; }
.prose a { text-decoration: underline; text-decoration-color: #b4b4b0; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.prose a:hover { text-decoration-color: currentColor; }

.prose > h2 { margin-top: 56px; font-size: 28px; line-height: 1.4; font-weight: 800; letter-spacing: -0.01em; }
.prose > h2.has-num { display: flex; align-items: baseline; gap: 12px; }
.h-num { flex: none; font-family: var(--mono); font-size: 18px; font-weight: 500; color: var(--muted); }
.h-text { min-width: 0; }
.prose > h3 { margin-top: 40px; font-size: 21px; line-height: 1.45; font-weight: 700; }
.prose > h2 + *, .prose > h3 + * { margin-top: 18px; }

.prose ul, .prose ol { padding-left: 22px; }
.prose > ul, .prose > ol { margin-top: 18px; }
.prose li + li { margin-top: 6px; }
.prose li > ul, .prose li > ol { margin: 6px 0 0; }
.prose li::marker { color: var(--muted); }

.prose :not(pre) > code {
  font-family: var(--mono); font-size: 0.86em; background: #efefed;
  padding: 0.15em 0.4em; border-radius: 5px;
}
.prose > pre.code {
  margin-top: 18px; padding: 20px 22px; border-radius: 10px;
  background: var(--code-bg); color: var(--code-text);
  overflow-x: auto; font: 400 14px/1.7 var(--mono); tab-size: 2;
  word-break: normal; overflow-wrap: normal;
  scrollbar-width: thin; scrollbar-color: #6b6b68 transparent;
}
pre.code code { font: inherit; }
.hljs-keyword, .hljs-built_in, .hljs-literal, .hljs-meta { color: #ffffff; font-weight: 500; }
.hljs-string, .hljs-attr, .hljs-variable { color: #c3ccbb; }
.hljs-number { color: #d6c9a6; }
.hljs-comment { color: #92928e; font-style: italic; }

.prose > .table-wrap { margin-top: 28px; border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.prose > .table-wrap + * { margin-top: 28px; }
table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 1.65; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 13.5px; font-weight: 700; background: var(--bg); color: var(--sub); white-space: nowrap; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }

.prose > p.lesson { margin-top: 40px; padding: 20px 24px; border-radius: 10px; background: var(--bg); }
.prose > p.lesson + p { margin-top: 28px; }
.lesson-tag { display: block; margin-bottom: 6px; font-size: 13px; line-height: 1.6; font-weight: 700; color: var(--accent); }

.prose > .fig { margin-top: 40px; }
.prose > .fig + p, .prose > .fig + ul, .prose > .fig + ol { margin-top: 32px; }
.fig-open {
  position: relative; display: block; width: 100%; padding: 0;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--soft); cursor: zoom-in;
}
.fig-open img { width: 100%; }
.fig-open::after {
  content: '크게 보기'; position: absolute; right: 10px; bottom: 10px;
  font-size: 12px; line-height: 1; padding: 7px 11px; border-radius: 8px;
  background: rgb(31 31 31 / 0.86); color: #ffffff; opacity: 0; transition: opacity 0.2s;
}
.fig-open:hover::after, .fig-open:focus-visible::after { opacity: 1; }
.fig figcaption { margin-top: 12px; font-size: 14px; line-height: 1.6; color: var(--muted); }
.fig-no { margin-right: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }

/* 글 끝 */
.post-sources {
  margin-top: 56px; padding: 20px 24px; border-radius: 10px; background: var(--bg);
  font-size: 14px; line-height: 1.75; color: var(--muted);
}
.post-sources h2 { margin-bottom: 6px; font-size: 13px; line-height: 1.6; font-weight: 700; color: var(--sub); }
.post-sources ul { list-style: none; margin: 0; padding: 0; }
.post-sources p { margin-top: 8px; }
.post-sources a, .cross-post a { color: var(--text); text-decoration: underline; text-decoration-color: #b4b4b0; text-underline-offset: 3px; }
.post-sources a:hover, .cross-post a:hover { text-decoration-color: currentColor; }

.post-end { margin-top: 40px; padding-top: 28px; border-top: 1px solid var(--line); }
.cross-post { font-size: 14.5px; color: var(--muted); }
.post-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px; }
.post-nav a {
  display: block; padding: 16px 20px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15.5px; line-height: 1.5; font-weight: 700;
}
.post-nav a span { display: block; margin-bottom: 4px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.post-nav a:hover { border-color: var(--line-hover); }
.post-nav .is-next { text-align: right; }

/* 목차 */
.post-toc {
  position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 20px 24px;
}
.post-toc summary { list-style: none; font-size: 13px; font-weight: 700; color: var(--muted); pointer-events: none; }
.post-toc summary::-webkit-details-marker { display: none; }
.post-toc nav { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.post-toc a {
  padding-left: 12px; border-left: 2px solid transparent;
  font-size: 14px; line-height: 1.5; color: var(--sub);
}
.post-toc a:hover { color: #000000; }
.post-toc a.is-active { border-left-color: var(--accent); font-weight: 700; color: var(--accent); }

/* ───────── 그림 크게 보기 ───────── */

.lightbox {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #121212; color: #f0f0ee;
}
.lightbox[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.lightbox::backdrop { background: #121212; }
.lightbox-bar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid rgb(255 255 255 / 0.12); }
.lightbox-count { font-size: 13px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lightbox-caption {
  flex: 1; min-width: 0; margin: 0; font-size: 13.5px; line-height: 1.6; color: #c4c4c0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lightbox-btn {
  flex-shrink: 0; min-height: 36px; padding: 6px 14px; border: 1px solid rgb(255 255 255 / 0.25); border-radius: 8px;
  font-size: 13px; color: #f0f0ee; white-space: nowrap;
}
.lightbox-btn:hover, .lightbox-btn[aria-pressed='true'] { background: #f0f0ee; color: #121212; }
.lightbox-stage { overflow: auto; display: grid; place-items: center; padding: 16px 64px; }
.lightbox-stage img { width: auto; height: auto; max-width: 100%; max-height: calc(100dvh - 92px); cursor: zoom-in; }
.lightbox.is-zoomed .lightbox-stage { place-items: start; padding: 16px; }
.lightbox.is-zoomed .lightbox-stage img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 68px; font-size: 30px; line-height: 1; color: #f0f0ee;
  background: rgb(18 18 18 / 0.8); border: 1px solid rgb(255 255 255 / 0.18); border-radius: 8px;
}
.lightbox-arrow:hover { background: #f0f0ee; color: #121212; }
.lightbox-arrow.is-prev { left: 10px; }
.lightbox-arrow.is-next { right: 10px; }
.lightbox .lightbox-btn:focus-visible, .lightbox .lightbox-arrow:focus-visible { outline-color: #f0f0ee; }

/* ───────── 404 ───────── */

.not-found { max-width: 560px; margin: 0 auto; padding: 48px 40px 52px; text-align: center; }
.not-found-code { font-family: var(--mono); font-size: 14px; font-weight: 500; color: var(--muted); }
.not-found h1 { margin-top: 10px; font-size: 26px; line-height: 1.4; font-weight: 800; letter-spacing: -0.02em; }
.not-found h1 + p { margin-top: 10px; font-size: 15.5px; color: var(--muted); }
.button {
  display: inline-block; margin-top: 28px; padding: 10px 20px; border-radius: 8px;
  background: var(--accent); color: var(--on-accent); font-size: 15px; font-weight: 700;
}
.button:hover { background: #000000; }

/* ───────── 꼬리말 ───────── */

.site-footer { border-top: 1px solid var(--line); }
.footer-inner {
  max-width: 1160px; margin: 0 auto; padding: 24px var(--gutter) 40px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px;
  font-size: 13.5px; color: var(--muted);
}
.footer-inner nav { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.footer-inner a:hover { color: var(--text); }

/* ───────── 화면 크기별 ───────── */

@media (max-width: 1023px) {
  .site-main { padding: 40px var(--gutter) 72px; }
  .site-main.is-post { padding-top: 24px; }
  .post-layout, .post-layout.no-toc { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .post-toc { position: static; order: -1; max-height: none; padding: 14px 18px; }
  .post-toc summary {
    pointer-events: auto; cursor: pointer; min-height: 28px;
    display: flex; justify-content: space-between; align-items: center;
  }
  .post-toc summary::after { content: '+'; font: 400 18px/1 var(--mono); }
  .post-toc details[open] summary::after { content: '−'; }
  .post-toc nav { margin: 12px 0 6px; }
  .post-toc a { padding-top: 2px; padding-bottom: 2px; }
  .post-cover { height: 280px; }
  .sheet-body { padding: 36px 32px 40px; }
  .lightbox-stage { padding: 12px; }
  .lightbox-arrow { top: auto; bottom: 14px; transform: none; height: 46px; }
}

@media (max-width: 559px) {
  :root { --gutter: 16px; }
  .brand { font-size: 17px; }
  .site-nav { gap: 16px; font-size: 14px; }
  .site-main { padding: 32px var(--gutter) 64px; }
  .site-main.is-post { padding-top: 16px; }
  .post-cover { height: 200px; }
  .sheet-body { padding: 28px 20px 32px; }
  .post-head h1 { font-size: 28px; }
  .post-sub { font-size: 17px; }
  .post-meta { margin-top: 24px; padding-bottom: 24px; }
  .prose { margin-top: 28px; font-size: 16.5px; line-height: 1.8; }
  .prose > h2 { margin-top: 48px; font-size: 23px; }
  .prose > h2.has-num { gap: 10px; }
  .h-num { font-size: 16px; }
  .prose > h3 { font-size: 19px; }
  .prose > pre.code { padding: 16px; font-size: 13px; }
  table { font-size: 14px; }
  th, td { padding: 10px 12px; }
  .prose > p.lesson { padding: 16px 18px; }
  .post-nav { grid-template-columns: 1fr; }
  .post-nav .is-next { text-align: left; }
  .post-nav span:empty { display: none; }
  .not-found { padding: 36px 24px 40px; }
  .lightbox-caption { display: none; }
  .lightbox-bar { justify-content: space-between; }
}

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

@media print {
  body { background: #ffffff; }
  .site-header, .site-footer, .post-toc, .lightbox, .post-nav { display: none !important; }
  .site-main { max-width: none; padding: 0; }
  .post-layout { display: block; }
  .sheet { border: 0; border-radius: 0; }
  .sheet-body { padding: 0; }
  .post-cover { display: none; }
  .fig, pre.code, .table-wrap, .lesson { break-inside: avoid; }
}
