:root {
  --bg: #f5f1ea;
  --bg-subtle: #ebe6dc;
  --ink: #1a1814;
  --ink-soft: #5a554d;
  --accent: #6b3a2e;
  --rule: #c4bdaf;

  --serif: "Noto Serif KR", "IBM Plex Serif", Georgia, serif;
  --sans: "Pretendard", "Pretendard Variable", "Noto Sans KR", sans-serif;
  --mono: "JetBrains Mono", "IBM Plex Mono", monospace;

  --measure: 680px;
  --measure-wide: 880px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1814;
    --bg-subtle: #252119;
    --ink: #ebe6dc;
    --ink-soft: #a09a8d;
    --accent: #c47a6a;
    --rule: #3d3830;
  }
}

:root[data-theme="light"] {
  --bg: #f5f1ea;
  --bg-subtle: #ebe6dc;
  --ink: #1a1814;
  --ink-soft: #5a554d;
  --accent: #6b3a2e;
  --rule: #c4bdaf;
}

:root[data-theme="dark"] {
  --bg: #1a1814;
  --bg-subtle: #252119;
  --ink: #ebe6dc;
  --ink-soft: #a09a8d;
  --accent: #c47a6a;
  --rule: #3d3830;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.75;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 한국어 조판: 어절(띄어쓰기) 단위로만 줄바꿈 — "대하여"가 "대하/여"로 깨지지 않도록 */
  word-break: keep-all;
  overflow-wrap: break-word;
  transition: background 0.3s ease, color 0.3s ease;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

/* ── 다크모드 토글 ─────────────────────────────── */
.theme-toggle {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 10;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.3s ease;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── 레이아웃 ─────────────────────────────────── */
.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 6rem 1.5rem 4rem;
  animation: rise 0.6s ease-out both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .page {
    animation: none;
  }
  html {
    scroll-behavior: auto;
  }
}

/* ── 헤더 / 인트로 ─────────────────────────────── */
header.intro {
  margin-bottom: 4rem;
}

.intro .sitename {
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1.5rem;
}

h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 2.4rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 0 0 1.5rem;
}

.intro p {
  color: var(--ink-soft);
}

.intro h1 + p::first-letter {
  float: left;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 4.2rem;
  line-height: 0.82;
  padding: 0.1em 0.12em 0 0;
  color: var(--accent);
}

/* ── 본문 타이포 ──────────────────────────────── */
h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1.35;
  margin: 5rem 0 1.5rem;
  scroll-margin-top: 2rem;
}

h3 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.2rem;
  margin: 3rem 0 1rem;
  color: var(--ink);
}

p {
  margin: 0 0 1.5rem;
}

strong {
  font-weight: 600;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--accent);
}

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

/* 섹션 제목 옆 anchor */
.anchor {
  text-decoration: none;
  color: var(--rule);
  margin-left: 0.4em;
  font-size: 0.7em;
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease;
}

h2:hover .anchor,
h2:focus-within .anchor,
.anchor:focus-visible {
  opacity: 1;
}

.anchor:hover {
  color: var(--accent);
}

/* ── 구분선 ───────────────────────────────────── */
hr {
  border: none;
  text-align: center;
  margin: 4rem 0;
}

hr::before {
  content: "· · ·";
  color: var(--rule);
  letter-spacing: 0.5em;
  font-size: 1.2rem;
}

/* ── 인용 ─────────────────────────────────────── */
blockquote {
  margin: 2rem 0;
  padding: 0.25rem 0 0.25rem 1.5rem;
  border-left: 3px solid var(--accent);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--ink);
}

blockquote p {
  margin: 0.5rem 0;
}

/* 정의/요점 박스 — 들여쓴 강조 단락 */
.callout {
  background: var(--bg-subtle);
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  border-radius: 2px;
}

.callout p {
  margin: 0;
}

.callout .lede {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--accent);
  line-height: 1.6;
}

/* ── 목차 ─────────────────────────────────────── */
nav.toc {
  margin: 3rem 0 2rem;
  padding: 1.75rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

nav.toc h2 {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 1rem;
}

nav.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: toc;
}

nav.toc li {
  counter-increment: toc;
  margin: 0.4rem 0;
  line-height: 1.5;
}

nav.toc li::before {
  content: counter(toc, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
  margin-right: 0.75rem;
}

nav.toc a {
  text-decoration: none;
}

nav.toc a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

/* ── 표 ───────────────────────────────────────── */
.table-wrap {
  position: relative;
  max-width: var(--measure-wide);
  margin: 2rem calc(50% - 50vw) 2.5rem;
  margin-left: max(calc(50% - 50vw), calc(-1 * (var(--measure-wide) - var(--measure)) / 2));
  margin-right: max(calc(50% - 50vw), calc(-1 * (var(--measure-wide) - var(--measure)) / 2));
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.6;
}

thead th {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1.5px solid var(--ink-soft);
  white-space: nowrap;
}

tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

tbody th {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:last-child td,
tbody tr:last-child th {
  border-bottom: none;
}

/* 모바일 가로 스크롤 우측 페이드 */
.table-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 2rem;
  height: 100%;
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

@media (max-width: 880px) {
  .table-wrap.is-scrollable::after {
    opacity: 1;
  }
}

/* ── 코드 / 기술 용어 ─────────────────────────── */
code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-subtle);
  padding: 0.1em 0.35em;
  border-radius: 2px;
}

.callout code,
table code {
  background: none;
  padding: 0;
}

/* ── 리스트 ───────────────────────────────────── */
ol.body-list,
ul.body-list {
  margin: 0 0 1.5rem;
  padding-left: 1.5rem;
}

ol.body-list li,
ul.body-list li {
  margin: 0.6rem 0;
}

/* ── 푸터 ─────────────────────────────────────── */
footer {
  margin-top: 6rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.7;
}

footer p {
  margin: 0 0 0.5rem;
}

/* ── 반응형 ───────────────────────────────────── */
@media (max-width: 768px) {
  body {
    font-size: 17px;
  }
  .page {
    padding: 4.5rem 1.5rem 3rem;
  }
  h1 {
    font-size: 1.9rem;
  }
  h2 {
    font-size: 1.4rem;
    margin-top: 4rem;
  }
  .intro h1 + p::first-letter {
    font-size: 3.2rem;
  }
  .table-wrap {
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    padding: 0 1.5rem;
  }
}

/* ── 떠 있는 챕터 레일 (데스크톱) ─────────────────── */
.chapter-rail {
  position: fixed;
  top: 50%;
  right: 1.5rem;
  transform: translateY(-50%);
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  align-items: flex-end;
}

.chapter-rail a {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  height: 1rem;
  text-decoration: none;
}

.chapter-rail .tick {
  flex: none;
  width: 16px;
  height: 1.5px;
  background: var(--rule);
  transition: width 0.2s ease, background 0.2s ease;
}

.chapter-rail a:hover .tick,
.chapter-rail a:focus-visible .tick {
  width: 26px;
  background: var(--accent);
}

.chapter-rail a.active .tick {
  width: 30px;
  background: var(--accent);
}

.chapter-rail .label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  white-space: nowrap;
  opacity: 0;
  transform: translateX(4px);
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.2s ease;
  pointer-events: none;
}

.chapter-rail a:hover .label,
.chapter-rail a:focus-visible .label {
  opacity: 1;
  transform: translateX(0);
  color: var(--accent);
}

/* 현재 챕터 라벨은 여백이 넉넉한 큰 화면에서만 상시 노출 */
@media (min-width: 1200px) {
  .chapter-rail a.active .label {
    opacity: 1;
    transform: translateX(0);
    color: var(--accent);
  }
}

.chapter-rail a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 2px;
}

/* ── 우하단 떠 있는 버튼 (맨 위로 / 다음) ──────────── */
.floats {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.floats button {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease, color 0.2s ease,
    border-color 0.2s ease, background 0.3s ease;
}

.floats button.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.floats button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.floats button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 화면이 좁으면 레일은 숨기고 떠 있는 버튼만 남긴다 */
@media (max-width: 999px) {
  .chapter-rail {
    display: none;
  }
}

@media (max-width: 768px) {
  .floats {
    right: 1rem;
    bottom: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chapter-rail .tick,
  .chapter-rail .label,
  .floats button {
    transition: none;
  }
}

/* ── "사건의 일생" 선화 인포그래픽 ───────────────── */
.lifecycle {
  margin: 3.5rem auto;
  max-width: 540px;
  padding: 0;
}

.lifecycle figcaption {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

.lc-steps {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* 세로 레일(배경) */
.lc-steps::before {
  content: "";
  position: absolute;
  left: 23px;
  top: 24px;
  bottom: 24px;
  width: 2px;
  background: var(--rule);
}

/* 진행 채움(옥스블러드) */
.lc-steps::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 24px;
  width: 2px;
  height: 0;
  background: var(--accent);
}

.lc-step {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 1.1rem;
  padding: 0.7rem 0;
}

.lc-ico {
  flex: none;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--bg);
  color: var(--accent);
  position: relative;
  z-index: 1;
}

.lc-ico svg {
  width: 24px;
  height: 24px;
}

.lc-body {
  padding-top: 0.35rem;
}

.lc-t {
  display: block;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.3;
}

.lc-s {
  display: block;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.55;
  margin-top: 0.15rem;
}

.lc-replay {
  margin-top: 1.25rem;
  margin-left: 12px;
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.lc-replay:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.lc-replay:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lifecycle.lc-ready .lc-replay {
  display: inline-flex;
}

.lifecycle.lc-ready.run .lc-step {
  animation: lc-rise 0.55s ease both;
  animation-delay: calc(var(--i) * 0.7s + 0.15s);
}

.lifecycle.lc-ready.run .lc-steps::after {
  animation: lc-fill 3.6s ease forwards;
}

@keyframes lc-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes lc-fill {
  to {
    height: calc(100% - 48px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lifecycle .lc-step {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
  .lifecycle .lc-steps::after {
    height: calc(100% - 48px);
    animation: none !important;
  }
  .lifecycle .lc-replay {
    display: none !important;
  }
}

/* ── 모노스페이스 흐름/상태 다이어그램 ───────────── */
.flow {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg-subtle);
  border-left: 3px solid var(--accent);
  border-radius: 2px;
  padding: 1.1rem 1.3rem;
  margin: 2rem 0;
  white-space: pre;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
