/* ============================================================
   에이전트 평가 체계 구축 가이드 — Total Package Book CSS
   고퀄리티 서적 디자인 시스템 v2.0
   ============================================================ */

/* ── CSS Custom Properties ── */
:root {
  /* Color Palette — Warm Academic */
  --ink: #1a1a2e;
  --ink-soft: #3d3d5c;
  --paper: #faf9f6;
  --cream: #f5f3ee;
  --accent: #6b5b3e;
  --accent-light: #8b7a5e;
  --muted: #8a8a8a;
  --hairline: #e0ddd5;
  --border: #d0cdc5;
  --success: #2d7d46;
  --warning: #c77d1a;
  --danger: #b83232;
  --info: #2d5fa0;
  --code-bg: #f0ede6;
  --code-text: #2d2d3d;
  --formula-bg: #f8f6f0;
  --highlight: #fff3cd;
  --shadow: rgba(26, 26, 46, 0.08);
  --shadow-md: rgba(26, 26, 46, 0.12);
  --shadow-lg: rgba(26, 26, 46, 0.18);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 0.15s ease;
  --font-sans: 'Noto Sans KR', 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Noto Serif KR', 'Georgia', 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --max-width: 860px;
  --sidebar-width: 280px;
}

/* ── Dark Mode ── */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8e6e0;
    --ink-soft: #b8b5ad;
    --paper: #1a1a1e;
    --cream: #242428;
    --accent: #c4a96a;
    --accent-light: #d4bc8a;
    --muted: #6a6a6a;
    --hairline: #3a3a3e;
    --border: #4a4a4e;
    --success: #4caf6a;
    --warning: #e0a030;
    --danger: #e05050;
    --info: #5a9fd4;
    --code-bg: #2a2a2e;
    --code-text: #d4d4d4;
    --formula-bg: #222226;
    --highlight: #3a3520;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-md: rgba(0, 0, 0, 0.4);
    --shadow-lg: rgba(0, 0, 0, 0.5);
  }
}

/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.8;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Reading Progress Bar ── */
.book-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light), var(--accent));
  z-index: 9999;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px rgba(107, 91, 62, 0.4);
}

/* ── Chapter Hero ── */
.ch-hero {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 80px 24px 40px;
  animation: fadeSlideUp 0.8s ease-out;
}

.ch-part {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--accent);
  background: var(--cream);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--hairline);
  margin-bottom: 20px;
}

.ch-hero h1 {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 900;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.ch-hero .ch-subtitle {
  font-size: clamp(14px, 2vw, 18px);
  color: var(--ink-soft);
  font-weight: 400;
  line-height: 1.6;
  max-width: 680px;
}

.ch-hero .ch-epigraph {
  margin-top: 24px;
  padding: 16px 24px;
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.7;
  background: var(--cream);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.ch-hero .ch-epigraph cite {
  display: block;
  margin-top: 8px;
  font-style: normal;
  font-size: 12px;
  color: var(--muted);
}

/* ── Main Body ── */
.ch-body {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px 80px;
}

.ch-body.prose {
  animation: fadeSlideUp 0.8s ease-out 0.2s both;
}

/* ── Typography ── */
.ch-body h2 {
  font-size: clamp(22px, 3.5vw, 30px);
  font-weight: 800;
  color: var(--ink);
  margin: 56px 0 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--hairline);
  position: relative;
  scroll-margin-top: 24px;
}

.ch-body h2::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--accent);
  animation: expandWidth 0.6s ease-out;
}

.ch-body h3 {
  font-size: clamp(17px, 2.5vw, 22px);
  font-weight: 700;
  color: var(--ink);
  margin: 40px 0 16px;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
  scroll-margin-top: 24px;
}

.ch-body h4 {
  font-size: clamp(15px, 2vw, 18px);
  font-weight: 700;
  color: var(--ink-soft);
  margin: 28px 0 12px;
}

.ch-body p {
  font-size: 15.5px;
  line-height: 1.9;
  color: var(--ink);
  margin: 0 0 18px;
  text-align: justify;
  hyphens: auto;
}

.ch-body strong {
  font-weight: 700;
  color: var(--ink);
}

.ch-body em {
  font-style: italic;
  color: var(--ink-soft);
}

.ch-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--transition-fast);
}

.ch-body a:hover {
  color: var(--accent-light);
}

/* ── Lists ── */
.ch-body ul, .ch-body ol {
  margin: 0 0 18px 24px;
  font-size: 15px;
  line-height: 1.9;
}

.ch-body li {
  margin: 6px 0;
}

.ch-body li::marker {
  color: var(--accent);
}

/* ── Insight Box ── */
.insight-box {
  background: var(--cream);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 20px 24px;
  margin: 28px 0;
  position: relative;
  animation: fadeSlideRight 0.5s ease-out;
}

.insight-box::before {
  content: '💡';
  position: absolute;
  top: -12px;
  left: 16px;
  background: var(--paper);
  padding: 0 6px;
  font-size: 18px;
}

.insight-box .insight-title,
.insight-box .ib-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.insight-box p {
  font-size: 14px;
  line-height: 1.7;
  margin: 0;
  color: var(--ink-soft);
}

/* ── Warning Box ── */
.warning-box {
  background: var(--highlight);
  border: 1px solid #e6c84a;
  border-left: 4px solid var(--warning);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 20px 24px;
  margin: 28px 0;
  animation: fadeSlideRight 0.5s ease-out;
}

.warning-box .warning-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--warning);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.warning-box p {
  font-size: 14px;
  line-height: 1.7;
  margin: 0;
  color: var(--ink-soft);
}

/* ── Formula Box ── */
.formula-box {
  background: var(--formula-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin: 24px 0;
  text-align: center;
  overflow-x: auto;
  animation: fadeIn 0.5s ease-out;
}

.formula-box .formula-label,
.formula-box .fb-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 12px;
}

.formula-box .formula-desc {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 12px;
  text-align: left;
  line-height: 1.6;
}

/* ── Code Block ── */
.code-block {
  background: var(--code-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  margin: 20px 0;
  overflow: hidden;
  animation: fadeIn 0.5s ease-out;
}

.code-block .code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: rgba(0,0,0,0.03);
  border-bottom: 1px solid var(--hairline);
  font-size: 11px;
  color: var(--muted);
}

.code-block .code-header .code-lang {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.code-block .code-header .code-copy {
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  font-size: 10px;
  transition: all var(--transition-fast);
}

.code-block .code-header .code-copy:hover {
  background: var(--accent);
  color: var(--paper);
}

.code-block pre {
  padding: 16px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--code-text);
  tab-size: 4;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Inline code */
.ch-body code:not(pre code) {
  background: var(--code-bg);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--code-text);
}

/* ── Comparison Table ── */
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  animation: fadeIn 0.5s ease-out;
}

.comparison-table thead {
  background: var(--cream);
}

.comparison-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.comparison-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--hairline);
  color: var(--ink);
  line-height: 1.5;
  vertical-align: top;
}

.comparison-table tbody tr {
  transition: background var(--transition-fast);
}

.comparison-table tbody tr:hover {
  background: var(--cream);
}

.comparison-table tbody tr:last-child td {
  border-bottom: none;
}

/* ── Figure / Diagram ── */
.figure-box {
  margin: 32px 0;
  padding: 24px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  text-align: center;
  animation: fadeIn 0.5s ease-out;
}

.figure-box .figure-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.figure-box .figure-caption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 16px;
  font-style: italic;
}

/* ── Case Study Box ── */
.case-study {
  margin: 32px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: fadeSlideUp 0.5s ease-out;
  box-shadow: var(--shadow);
}

.case-study .cs-header {
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
}

.case-study .cs-header .cs-icon {
  font-size: 24px;
}

.case-study .cs-header .cs-title {
  font-size: 16px;
  font-weight: 700;
}

.case-study .cs-header .cs-subtitle {
  font-size: 12px;
  opacity: 0.85;
}

.case-study .cs-body {
  padding: 24px;
}

.case-study .cs-body p {
  font-size: 14px;
  line-height: 1.7;
}

/* ── Chapter Navigation ── */
.ch-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px;
  border-top: 2px solid var(--hairline);
}

.ch-nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  background: var(--cream);
  border: 1px solid var(--hairline);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition);
}

.ch-nav a:hover {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ── Interactive Demo ── */
.demo-box {
  margin: 28px 0;
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow-md);
  animation: fadeSlideUp 0.5s ease-out;
}

.demo-box .demo-header {
  padding: 12px 20px;
  background: var(--accent);
  color: var(--paper);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.demo-box .demo-body {
  padding: 20px;
}

.demo-box textarea, .demo-box input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--cream);
  color: var(--ink);
  resize: vertical;
  min-height: 60px;
  transition: border-color var(--transition-fast);
}

.demo-box textarea:focus, .demo-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(107, 91, 62, 0.15);
}

.demo-box button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--accent);
  color: var(--paper);
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.demo-box button:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
}

.demo-box .demo-result {
  margin-top: 16px;
  padding: 16px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  min-height: 40px;
}

/* ── Stat Cards ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.stat-card {
  text-align: center;
  padding: 20px 12px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: all var(--transition);
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.stat-card .sn {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
}

.stat-card .sl {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
  line-height: 1.4;
}

/* ── Viz Box (Chart container) ── */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 32px 0;
}

@media (max-width: 700px) {
  .chart-row { grid-template-columns: 1fr; }
}

.viz-box {
  padding: 20px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}

.viz-box h4 {
  font-size: 13px;
  color: var(--ink);
  margin: 0 0 12px;
  font-weight: 700;
}

/* ── Pill / Badge ── */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.pill.green { background: rgba(45,125,70,0.1); color: var(--success); }
.pill.amber { background: rgba(199,125,26,0.1); color: var(--warning); }
.pill.red { background: rgba(184,50,50,0.1); color: var(--danger); }
.pill.blue { background: rgba(45,95,160,0.1); color: var(--info); }

/* ── Timeline ── */
.timeline {
  position: relative;
  margin: 32px 0;
  padding-left: 32px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  animation: fadeSlideRight 0.5s ease-out;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -28px;
  top: 20px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 2px var(--accent);
}

.timeline-item .tl-date {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.timeline-item .tl-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin: 4px 0;
}

.timeline-item .tl-desc {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ── Accordion ── */
.accordion {
  margin: 24px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.accordion-item {
  border-bottom: 1px solid var(--hairline);
}

.accordion-item:last-child {
  border-bottom: none;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  background: var(--cream);
  transition: all var(--transition-fast);
}

.accordion-header:hover {
  background: rgba(107, 91, 62, 0.08);
}

.accordion-header::after {
  content: '▸';
  transition: transform var(--transition);
  color: var(--accent);
}

.accordion-item.open .accordion-header::after {
  transform: rotate(90deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-out;
}

.accordion-item.open .accordion-body {
  max-height: 2000px;
}

.accordion-body-inner {
  padding: 16px 20px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-soft);
}

/* ── Tabs ── */
.tabs {
  margin: 24px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tab-headers {
  display: flex;
  background: var(--cream);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-header {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  border-bottom: 2px solid transparent;
}

.tab-header:hover {
  color: var(--ink);
}

.tab-header.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  padding: 20px;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.3s ease-out;
}

/* ── Collapsible Sidebar TOC ── */
.sidebar-toc {
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  width: 200px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 12px;
  box-shadow: var(--shadow-md);
  z-index: 100;
  opacity: 0.85;
  transition: opacity var(--transition);
}

.sidebar-toc:hover {
  opacity: 1;
}

.sidebar-toc a {
  display: block;
  padding: 4px 8px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 4px;
  transition: all var(--transition-fast);
  line-height: 1.5;
}

.sidebar-toc a:hover,
.sidebar-toc a.active {
  color: var(--accent);
  background: var(--cream);
}

@media (max-width: 1200px) {
  .sidebar-toc { display: none; }
}

/* ── Animations ── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideRight {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes expandWidth {
  from { width: 0; }
  to { width: 60px; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Scroll-triggered animations */
.animate-on-scroll {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.animate-on-scroll.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Print Styles ── */
@media print {
  .book-progress, .sidebar-toc, .ch-nav, .demo-box button { display: none !important; }
  body { font-size: 11pt; line-height: 1.5; color: #000; background: #fff; }
  .ch-hero { padding-top: 0; }
  .comparison-table { font-size: 9pt; }
  .insight-box, .case-study, .figure-box { break-inside: avoid; }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .ch-hero { padding: 48px 16px 24px; }
  .ch-body { padding: 0 16px 48px; }
  .ch-nav { flex-direction: column; gap: 12px; padding: 24px 16px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .comparison-table { font-size: 11px; }
  .comparison-table th, .comparison-table td { padding: 6px 8px; }
}

/* ── Utility Classes ── */
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-small { font-size: 13px; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-8 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-8 { margin-bottom: 32px; }
.hidden { display: none; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--cream); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Selection ── */
::selection {
  background: rgba(107, 91, 62, 0.2);
  color: var(--ink);
}
