:root {
  --text: #37352f;
  --muted: #787774;
  --faint: #9b9a97;
  --line: #e9e9e7;
  --line-strong: #d8d7d4;
  --surface: #ffffff;
  --surface-soft: #f7f6f3;
  --surface-hover: #f1f1ef;
  --link: #2f6f9f;
  --code-text: #3f3f3b;
  --selection: rgba(35, 131, 226, 0.18);
  --shadow: 0 1px 2px rgba(15, 15, 15, 0.03), 0 8px 28px rgba(15, 15, 15, 0.035);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 32px;
  background: var(--surface);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", "Apple SD Gothic Neo", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.78;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  height: 3px;
  background: transparent;
  pointer-events: none;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: #37352f;
  opacity: 0.55;
  transform-origin: left center;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 900px) 220px;
  gap: 68px;
  justify-content: center;
  align-items: start;
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: 0 42px;
}

.document {
  min-width: 0;
  padding: 78px 0 140px;
}

.page-outline {
  position: sticky;
  top: 32px;
  align-self: start;
  height: calc(100vh - 64px);
  padding: 68px 0 40px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.page-outline:hover {
  scrollbar-color: var(--line-strong) transparent;
}

.outline-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

.outline-nav a {
  display: block;
  padding: 4px 8px 4px 10px;
  color: var(--faint);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.45;
  text-decoration: none;
  transition: color 120ms ease, background 120ms ease;
}

.outline-nav a:hover {
  color: var(--text);
  background: var(--surface-soft);
}

.outline-nav a.is-active {
  color: var(--text);
  background: var(--surface-soft);
  font-weight: 600;
}

.document-title {
  max-width: 820px;
  word-break: keep-all;
  margin: 0 0 22px;
  font-size: clamp(36px, 5vw, 48px);
  font-weight: 750;
  line-height: 1.16;
  letter-spacing: -0.035em;
}

.document h1:not(.document-title) {
  margin: 104px 0 28px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
  font-size: 31px;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.document h2 {
  margin: 82px 0 20px;
  font-size: 28px;
  line-height: 1.34;
  letter-spacing: -0.025em;
}

.document h3 {
  margin: 52px 0 16px;
  font-size: 22px;
  line-height: 1.42;
  letter-spacing: -0.018em;
}

.document h4 {
  margin: 38px 0 12px;
  font-size: 18px;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

.document h5,
.document h6 {
  margin: 30px 0 10px;
  font-size: 16px;
  line-height: 1.55;
}

.document h1,
.document h2,
.document h3,
.document h4,
.document h5,
.document h6 {
  color: var(--text);
  font-weight: 700;
  scroll-margin-top: 34px;
}

.document p {
  margin: 0.72em 0;
}

.document strong {
  font-weight: 680;
}

.document a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: rgba(47, 111, 159, 0.38);
}

.document a:hover {
  text-decoration-color: currentColor;
}

.document ul,
.document ol {
  margin: 0.72em 0;
  padding-left: 1.75em;
}

.document li {
  margin: 0.32em 0;
  padding-left: 0.12em;
}

.document li::marker {
  color: #6f6e69;
}

.document li > ul,
.document li > ol {
  margin-top: 0.25em;
  margin-bottom: 0.25em;
}

.document hr {
  height: 1px;
  margin: 52px 0;
  border: 0;
  background: var(--line);
}

.document-meta {
  margin: 0 0 44px;
  padding: 14px 18px;
  border: 0;
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.72;
}

.document-meta p {
  margin: 0;
}

.document blockquote:not(.document-meta) {
  margin: 24px 0;
  padding: 1px 0 1px 18px;
  border-left: 3px solid var(--line-strong);
  color: var(--text);
}

.document blockquote:not(.document-meta) p {
  margin: 0.5em 0;
}

.document-toc {
  columns: 2;
  column-gap: 34px;
  padding: 20px 24px 20px 46px !important;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.document-toc li {
  break-inside: avoid;
  margin: 0.18em 0;
  font-size: 14px;
  line-height: 1.6;
}

.document-toc a {
  color: var(--text);
  text-decoration: none;
}

.document-toc a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.document code {
  padding: 0.16em 0.34em;
  border-radius: 4px;
  background: rgba(135, 131, 120, 0.15);
  color: #eb5757;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", "Noto Sans Mono CJK KR", monospace;
  font-size: 0.86em;
  line-height: inherit;
}

.code-wrap {
  position: relative;
  margin: 20px 0 26px;
  border: 1px solid rgba(55, 53, 47, 0.07);
  border-radius: 6px;
  background: var(--surface-soft);
  overflow: hidden;
}

.code-wrap pre {
  margin: 0;
  padding: 20px 22px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.code-wrap pre code {
  display: block;
  min-width: max-content;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--code-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", "Noto Sans Mono CJK KR", monospace;
  font-size: 13px;
  line-height: 1.68;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  tab-size: 2;
}

.table-wrap {
  width: 100%;
  margin: 22px 0 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.document table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  border-spacing: 0;
  background: #fff;
  font-size: 14px;
  line-height: 1.58;
}

.document th,
.document td {
  min-width: 96px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.document th:last-child,
.document td:last-child {
  border-right: 0;
}

.document tr:last-child td {
  border-bottom: 0;
}

.document th {
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 650;
}

.document td code,
.document th code {
  white-space: nowrap;
}

.diagram-scroll,
.structured-diagram {
  width: 100%;
  margin: 24px 0 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.diagram-scroll {
  padding: 24px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  cursor: grab;
}

.diagram-scroll.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.diagram-svg {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

.graphviz-diagram .diagram-svg {
  min-width: 0;
  max-height: none;
}

.graphviz-diagram .diagram-ultrawide {
  width: max(100%, 1800px);
}

.graphviz-diagram .diagram-wide {
  width: 100%;
}

.graphviz-diagram .diagram-balanced {
  width: min(100%, 720px);
}

.graphviz-diagram .diagram-vertical {
  width: min(100%, 360px);
}

.sequence-diagram .diagram-svg {
  width: max(100%, 1680px);
}

.sequence-svg .seq-lifeline {
  stroke: #d6d5d2;
  stroke-width: 1.2;
  stroke-dasharray: 5 5;
}

.sequence-svg .seq-participant {
  stroke: #d5d4d1;
  stroke-width: 1.2;
}

.sequence-svg .seq-participant-text {
  fill: #37352f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", Arial, sans-serif;
  font-size: 13px;
  font-weight: 650;
}

.sequence-svg .seq-message {
  stroke: #8e8d88;
  stroke-width: 1.25;
}

.sequence-svg .seq-message-text {
  fill: #565550;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", Arial, sans-serif;
  font-size: 11.5px;
  font-weight: 500;
}

.sequence-svg .seq-alt-box {
  fill: rgba(247, 246, 243, 0.62);
  stroke: #d8d7d4;
  stroke-width: 1.1;
}

.sequence-svg .seq-alt-separator {
  stroke: #d8d7d4;
  stroke-width: 1;
  stroke-dasharray: 5 4;
}

.sequence-svg .seq-alt-label-bg {
  fill: #f1f1ef;
  stroke: #d8d7d4;
  stroke-width: 1;
}

.sequence-svg .seq-alt-label {
  fill: #565550;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", Arial, sans-serif;
  font-size: 11px;
  font-weight: 650;
}

.structured-diagram {
  padding: 20px;
}

.definition-diagram {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.definition-card {
  display: grid;
  grid-template-columns: minmax(110px, auto) 24px minmax(0, 1fr);
  align-items: center;
  min-height: 76px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.definition-term {
  font-weight: 680;
}

.definition-equals {
  color: var(--faint);
  text-align: center;
  font-weight: 600;
}

.definition-description {
  color: #565550;
  font-size: 14px;
  line-height: 1.6;
}

.mapping-diagram {
  display: grid;
  gap: 10px;
}

.mapping-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
}

.mapping-row .mapping-node {
  flex: 1 1 0;
}

.mapping-row .mapping-arrow {
  flex: 0 0 34px;
}

.mapping-node,
.relation-node {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  text-align: center;
  font-size: 14px;
  line-height: 1.55;
}

.mapping-arrow,
.relation-operator {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 650;
}

.relation-diagram {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
}

.relation-node {
  flex: 1 1 180px;
  max-width: 360px;
}

.relation-operator {
  flex: 0 0 34px;
  min-height: 50px;
  font-size: 17px;
}

.footnote-ref {
  margin-left: 1px;
  font-size: 0.72em;
  line-height: 0;
}

.footnote-ref a {
  text-decoration: none;
}

.footnotes {
  margin-top: 84px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.footnotes ol {
  padding-left: 1.6em;
}

.footnotes li {
  margin: 0.72em 0;
}

.footnotes .footnote {
  margin-left: 7px;
  color: var(--muted);
  text-decoration: none;
}

[id^="fn-"] {
  scroll-margin-top: 28px;
}

@media (max-width: 1180px) {
  .page-grid {
    display: block;
    width: min(100%, 980px);
    padding: 0 36px;
  }

  .page-outline {
    display: none;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 15.5px;
    line-height: 1.74;
    word-break: normal;
  }

  .page-grid {
    padding: 0 20px;
  }

  .document {
    padding: 48px 0 96px;
  }

  .document-title {
    font-size: 34px;
  }

  .document h1:not(.document-title) {
    margin-top: 76px;
    font-size: 27px;
  }

  .document h2 {
    margin-top: 64px;
    font-size: 24px;
  }

  .document h3 {
    margin-top: 42px;
    font-size: 20px;
  }

  .document h4 {
    margin-top: 32px;
    font-size: 17px;
  }

  .document-toc {
    columns: 1;
    padding-left: 42px !important;
  }

  .code-wrap pre {
    padding: 17px 18px;
  }

  .diagram-scroll,
  .structured-diagram {
    margin: 20px 0 28px;
  }

  .diagram-scroll {
    padding: 16px;
  }

  .definition-diagram {
    grid-template-columns: 1fr;
  }

  .definition-card {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .definition-equals {
    justify-self: start;
  }

  .mapping-row {
    flex-direction: column;
  }

  .mapping-arrow {
    min-height: 26px;
    transform: rotate(90deg);
  }

  .relation-diagram {
    flex-direction: column;
    align-items: stretch;
  }

  .relation-node {
    max-width: none;
    flex-basis: auto;
  }

  .relation-operator {
    min-height: 25px;
    flex-basis: 25px;
  }

  .table-wrap {
    margin-right: -20px;
    width: calc(100% + 20px);
    border-radius: 6px 0 0 6px;
  }
}

@media print {
  .reading-progress,
  .page-outline {
    display: none !important;
  }

  .page-grid {
    display: block;
    width: auto;
    padding: 0;
  }

  .document {
    padding: 0;
  }

  .diagram-scroll,
  .table-wrap,
  .code-wrap {
    overflow: visible;
    break-inside: avoid;
    box-shadow: none;
  }

  .document a {
    color: inherit;
  }
}
