:root {
  --bg: #fafaf8;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-soft: #f3f3ef;
  --border: rgba(15, 15, 20, 0.08);
  --border-strong: rgba(15, 15, 20, 0.14);
  --text: #1a1a22;
  --text-soft: #3d3d48;
  --text-muted: #6f6f7a;
  --accent: #ea4b71;
  --accent-strong: #d62553;
  --accent-soft: rgba(234, 75, 113, 0.12);
  --accent-bg: #fdeef2;
  --pink: #ea4b71;
  --pink-soft: rgba(234, 75, 113, 0.12);
  --pink-bg: #fdeef2;
  --code-bg: #1e1e28;
  --code-text: #e6e6ec;
  --shadow-sm: 0 1px 2px rgba(15, 15, 20, 0.05);
  --shadow-md: 0 8px 28px rgba(15, 15, 20, 0.08);
  --shadow-lg: 0 24px 60px rgba(15, 15, 20, 0.1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Pretendard Variable", Pretendard, -apple-system,
    BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", sans-serif;
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-soft); color: var(--accent-strong); }
a {
  color: var(--accent-strong);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
}
a:hover { border-bottom-color: var(--accent-strong); }

/* 학생용 2컬럼 레이아웃 */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  max-width: 1380px;
  margin: 0 auto;
  min-height: 100vh;
}
.main {
  max-width: 820px;
  padding: 80px 56px 160px;
  margin: 0;
}

.chapter-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-bg);
  border: 1px solid rgba(234, 75, 113, 0.22);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 24px;
}

h1 {
  font-size: 38px;
  line-height: 1.2;
  font-weight: 800;
  margin: 0 0 20px;
  letter-spacing: -0.02em;
  color: var(--text);
}
h1 .accent { color: var(--accent-strong); }
.lead {
  font-size: 18px;
  line-height: 1.7;
  color: var(--text-soft);
  margin: 0 0 48px;
}
.lead b { color: var(--text); }

h2 {
  font-size: 30px;
  font-weight: 800;
  margin: 88px 0 20px;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--text);
  scroll-margin-top: 24px;
}
h3 {
  font-size: 21px;
  font-weight: 700;
  margin: 44px 0 14px;
  line-height: 1.35;
  color: var(--text);
}
p {
  margin: 0 0 20px;
  color: var(--text-soft);
}
p b, p strong { color: var(--text); }
ul, ol { margin: 0 0 24px; padding-left: 24px; }
li { margin-bottom: 8px; color: var(--text-soft); }
li::marker { color: var(--text-muted); }
hr { border: none; height: 1px; background: var(--border); margin: 72px 0; }

/* clip-section — 한 챕터 페이지 안의 클립 블록 (앵커 스크롤 단위) */
.clip-section {
  scroll-margin-top: 24px;
}
.clip-section + .clip-section {
  margin-top: 96px;
  padding-top: 56px;
  border-top: 1px solid var(--border);
}
.clip-section h2 {
  font-size: 30px;
  font-weight: 800;
  margin: 0 0 28px;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--text);
}
.clip-label {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent-strong);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
}
h4 {
  font-size: 17px;
  font-weight: 700;
  margin: 32px 0 12px;
  line-height: 1.4;
  color: var(--text);
}

/* section-label — 본문 흐름 안 작은 라벨 박스 (예: "1부. 이론") */
.section-label {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 72px 0 16px;
}

/* 코드 블록 */
pre {
  margin: 0 0 24px;
  padding: 16px 20px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 10px;
  overflow-x: auto;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.6;
}
pre code { background: transparent; padding: 0; color: inherit; font-family: inherit; }
:not(pre) > code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  color: var(--text);
}

blockquote {
  margin: 0 0 20px;
  padding: 14px 22px;
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  color: var(--text-soft);
  font-style: italic;
  border-radius: 0 8px 8px 0;
}
blockquote p { margin: 0; color: var(--text-soft); }

/* summary — 큰 콜아웃 박스 */
.summary {
  background: linear-gradient(135deg, rgba(234, 75, 113, 0.08), rgba(200, 50, 79, 0.06));
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px 32px;
  margin: 28px 0;
  box-shadow: var(--shadow-sm);
}
.summary p {
  font-size: 16.5px;
  line-height: 1.8;
  color: var(--text);
  margin: 0 0 12px;
}
.summary p:last-child { margin-bottom: 0; }
.summary b { color: var(--accent-strong); }

/* step-diagram — 순서 있는 짧은 리스트의 STEP 카드 그리드 */
.step-diagram {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 24px 0 36px;
}
.step-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 22px;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.step-card .step-num {
  display: inline-block;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--accent-strong);
  background: var(--accent-bg);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.step-card p {
  margin: 0;
  font-size: 14.5px;
  color: var(--text);
  font-weight: 600;
  line-height: 1.55;
}
.step-card p strong { color: var(--accent-strong); }
.step-card p code { font-size: 0.9em; }

/* compare-grid — vs 비교 두 컬럼 박스 */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 24px 0 36px;
}
.compare-card {
  padding: 22px 26px;
  border-radius: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.compare-card.bad {
  background: var(--bg-soft);
}
.compare-card.good {
  background: var(--accent-bg);
  border-color: rgba(234, 75, 113, 0.22);
}
.compare-card .cmp-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 800;
  margin-bottom: 10px;
}
.compare-card.bad .cmp-label { color: var(--text-muted); }
.compare-card.good .cmp-label { color: var(--accent-strong); }
.compare-card h4 {
  font-size: 17px;
  font-weight: 800;
  margin: 0 0 14px;
  color: var(--text);
}
.compare-card ul {
  margin: 0;
  padding-left: 20px;
}
.compare-card li {
  font-size: 14.5px;
  color: var(--text-soft);
  margin-bottom: 8px;
  line-height: 1.55;
}
.compare-card li:last-child { margin-bottom: 0; }
@media (max-width: 780px) {
  .compare-grid { grid-template-columns: 1fr; }
}

/* flow-diagram — 시스템 구조 흐름도 (박스 + 화살표) */
.flow-diagram {
  display: grid;
  gap: 14px;
  margin: 24px 0 36px;
  padding: 28px 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.flow-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.flow-node {
  flex: 1 1 0;
  min-width: 140px;
  padding: 18px 16px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  text-align: center;
  font-weight: 700;
  font-size: 14.5px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.flow-node small {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 6px;
}
.flow-node.primary {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.flow-arrow {
  font-weight: 800;
  font-size: 13px;
  color: var(--accent-strong);
  white-space: nowrap;
  padding: 0 4px;
}
.flow-arrow::before { content: "→"; margin-right: 4px; font-size: 18px; }
@media (max-width: 780px) {
  .flow-row { flex-direction: column; }
  .flow-arrow::before { content: "↓"; }
}

/* key-callout — 핵심 강조 박스 */
.key-callout {
  margin: 28px 0;
  padding: 22px 26px 22px 64px;
  border-radius: 12px;
  background: var(--accent-bg);
  border: 1px solid rgba(234, 75, 113, 0.22);
  position: relative;
}
.key-callout::before {
  content: "★";
  position: absolute;
  top: 22px;
  left: 24px;
  font-size: 22px;
  color: var(--accent-strong);
  line-height: 1;
}
.key-callout .kc-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--accent-strong);
  margin-bottom: 6px;
}
.key-callout p {
  margin: 0;
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.7;
}
.key-callout p strong { color: var(--accent-strong); }

/* feature-grid — "**키워드**: 설명" 패턴 리스트의 카드 그리드 변환 */
.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0 32px;
}
.feature-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}
.feature-card h4 {
  margin: 0 0 6px;
  font-size: 14.5px;
  font-weight: 800;
  color: var(--accent-strong);
  letter-spacing: -0.005em;
}
.feature-card p {
  margin: 0;
  font-size: 14px;
  color: var(--text-soft);
  line-height: 1.6;
}
@media (max-width: 780px) {
  .feature-grid { grid-template-columns: 1fr; }
}

/* routing-list — "A → B" 패턴 리스트의 라우팅 카드 */
.routing-list {
  display: grid;
  gap: 8px;
  margin: 16px 0 32px;
}
.routing-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: center;
  padding: 14px 22px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}
.routing-row .from {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
}
.routing-row .arrow {
  color: var(--accent-strong);
  font-weight: 800;
  font-size: 16px;
}
.routing-row .to {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--accent-strong);
}
@media (max-width: 780px) {
  .routing-row {
    grid-template-columns: 1fr;
    gap: 4px;
    text-align: left;
  }
  .routing-row .arrow { transform: rotate(90deg); justify-self: start; }
}

/* md-table — 마크다운 표 변환 */
.md-table-wrap {
  margin: 16px 0 32px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  background: var(--bg-elev);
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.md-table th, .md-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.md-table th {
  font-weight: 800;
  color: var(--text);
  background: var(--bg-soft);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.md-table td {
  color: var(--text-soft);
  line-height: 1.6;
}
.md-table tbody tr:last-child td { border-bottom: none; }

/* 다음 클립 CTA */
.next-cta {
  margin-top: 24px;
  padding: 22px 26px;
  border-radius: 12px;
  background: var(--accent-bg);
  border: 1px solid rgba(234, 75, 113, 0.24);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.next-cta .label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}
.next-cta .title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.next-cta a {
  border-bottom: none;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  background: var(--accent-strong);
  color: white;
  border-radius: 8px;
  white-space: nowrap;
}
.next-cta a:hover { background: var(--accent); }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 260px 1fr; }
  .main { padding: 64px 40px 120px; }
}
@media (max-width: 780px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 48px 24px 96px; }
}
