/* ==========================================================================
   《요즘 교사를 위한 웹앱 만들기 with 바이브 코딩》 
   도서 표지 정확 컬러 & 테크 미니멀 디자인 시스템
   ========================================================================== */

@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.css');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  /* Book Cover Exact Palette (실제 책 표지 색상 1:1 반영) */
  --brand-blue: #0077d4;         /* 표지 전면 비비드 코발트 블루 */
  --brand-blue-dark: #005fad;    /* 호버/포커스용 딥 블루 */
  --brand-blue-deep: #00427a;    /* 텍스트용 다크 블루 */
  --brand-blue-subtle: #f0f7ff;  /* 틴트 배경 */
  --brand-blue-border: #cce4fc;  /* 보더 라인 */
  
  --brand-orange: #ff5b00;       /* 표지 타이틀 '웹앱 만들기' 비비드 오렌지 */
  --brand-orange-dark: #e04b00;  /* 오렌지 다크 */
  --brand-orange-subtle: #fff4ed;/* 오렌지 틴트 */
  --brand-orange-border: #ffdec9;/* 오렌지 보더 */
  
  --brand-yellow: #ff9100;       /* 표지 'with 바이브 코딩' 옐로우오렌지 */
  --brand-postit: #fef08a;       /* 실습 프롬프트 포스트잇 옐로우 */

  /* Neutrals */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-muted: #f1f5f9;
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;
  
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  /* Semantic Box Colors */
  --box-summary-bg: #f8fafc;
  --box-summary-text: #1e293b;

  --box-easy-bg: #f0fdf4;
  --box-easy-text: #14532d;

  --box-study-bg: #fff7ed;
  --box-study-text: #7c2d12;

  --box-question-bg: #f0f7ff;
  --box-question-text: #00427a;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.07), 0 4px 6px -4px rgba(15, 23, 42, 0.03);
  --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.04), 0 1px 2px -1px rgba(0, 0, 0, 0.04);

  /* Precise Corner Radius */
  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

html {
  scroll-behavior: smooth;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.8;
  font-size: 15.5px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   Reading Progress Bar
   -------------------------------------------------------------------------- */
#reading-progress-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 1200;
}

#reading-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--brand-blue);
  box-shadow: 0 0 8px rgba(0, 119, 212, 0.6);
  transition: width 0.08s ease-out;
}

/* --------------------------------------------------------------------------
   Header Bar
   -------------------------------------------------------------------------- */
.book-header {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  z-index: 900;
}

.book-header-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  min-height: 60px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.book-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1 1 auto;
}

@media (max-width: 640px) {
  .book-header-inner {
    padding: 0.75rem 1rem;
    min-height: 56px;
    gap: 0.5rem;
  }
  .book-header-left {
    gap: 0.5rem;
  }
}

.book-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  line-height: 1.2;
}

.book-logo-tag {
  background: var(--brand-blue);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-xs);
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.book-title-text {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  margin: 0;
}

@media (max-width: 480px) {
  .book-title-text {
    font-size: 0.84rem;
  }
  .book-title-sub {
    display: none;
  }
}

.book-title-sub {
  color: var(--brand-orange);
  font-size: 0.85rem;
  font-weight: 600;
}

.book-nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.nav-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 36px;
  padding: 0 0.85rem;
  box-sizing: border-box;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  transition: all 0.15s ease;
  color: var(--text-secondary);
  background: #ffffff;
  border: 1px solid var(--border-color);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  vertical-align: middle;
  font-family: inherit;
}

.nav-pill-btn svg {
  display: block;
  flex-shrink: 0;
}

.nav-pill-btn:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
  border-color: #cbd5e1;
}

.nav-pill-btn.primary {
  background: var(--brand-blue);
  color: #ffffff;
  border-color: var(--brand-blue);
}

.nav-pill-btn.primary:hover {
  background: var(--brand-blue-dark);
}

@media (max-width: 640px) {
  .nav-pill-btn {
    height: 34px;
    padding: 0 0.7rem;
    font-size: 0.8rem;
  }
}

/* --------------------------------------------------------------------------
   Article Page Wrap
   -------------------------------------------------------------------------- */
.book-page-wrap {
  max-width: 820px;
  margin: 2.5rem auto 5rem;
  padding: 0 1.5rem;
}

.book-article {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 3rem 2.75rem;
  box-shadow: var(--shadow-card);
  position: relative;
}

@media (max-width: 768px) {
  .book-article {
    padding: 2rem 1.25rem;
    border-radius: var(--radius-sm);
  }
}

.chapter-meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.chapter-badge {
  display: inline-flex;
  align-items: center;
  background: var(--brand-blue-subtle);
  color: var(--brand-blue-dark);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--brand-blue-border);
}

.chapter-badge.orange {
  background: var(--brand-orange-subtle);
  color: var(--brand-orange-dark);
  border-color: var(--brand-orange-border);
}

.chapter-badge.purple {
  background: #faf5ff;
  color: #6b21a8;
  border-color: #e9d5ff;
}

.read-time-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
}

h1.book-chapter-title {
  font-size: clamp(1.8rem, 3.5vw, 2.2rem);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.35;
  margin-bottom: 2rem;
  letter-spacing: -0.02em;
  word-break: keep-all;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.25rem;
}

h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-color);
}

h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

h4 {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

p {
  font-size: 1.02rem;
  color: var(--text-secondary);
  margin-bottom: 1.4rem;
  line-height: 1.85;
  word-break: keep-all;
}

p strong, span strong {
  color: var(--text-primary);
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   Book Boxes (Clean 1px Border Technical Boxes)
   -------------------------------------------------------------------------- */
.box-summary, .box-easy, .box-study, .box-question {
  position: relative;
  padding: 1.25rem 1.4rem;
  border-radius: var(--radius-sm);
  margin: 2rem 0;
  border: 1px solid var(--border-color);
}

.box-summary {
  background: var(--box-summary-bg);
  border-color: var(--border-color);
  color: var(--box-summary-text);
}

.box-easy {
  background: var(--box-easy-bg);
  border-color: #dcfce7;
  color: var(--box-easy-text);
}

.box-study {
  background: var(--box-study-bg);
  border-color: #ffdec9;
  color: var(--box-study-text);
}

.box-question {
  background: var(--box-question-bg);
  border-color: var(--brand-blue-border);
  color: var(--box-question-text);
}

.box-header {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.box-summary .box-header { color: var(--brand-blue); }
.box-easy .box-header { color: #15803d; }
.box-study .box-header { color: var(--brand-orange); }
.box-question .box-header { color: var(--brand-blue); }

.box-body {
  font-size: 0.96rem;
  line-height: 1.75;
  word-break: keep-all;
}

/* --------------------------------------------------------------------------
   Code Snippet & Copy UI
   -------------------------------------------------------------------------- */
.code-wrapper {
  margin: 1.75rem 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #0f172a;
  border: 1px solid #1e293b;
}

.code-header {
  background: #1e293b;
  padding: 0.55rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #334155;
}

.code-header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.code-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: #cbd5e1;
  font-weight: 600;
}

.code-badge-tag {
  background: #334155;
  color: #38bdf8;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-xs);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #334155;
  color: #f8fafc;
  border: 1px solid #475569;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-xs);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: 'Pretendard', sans-serif;
}

.copy-btn:hover {
  background: var(--brand-blue);
  color: #ffffff;
  border-color: var(--brand-blue);
}

.copy-btn.copied {
  background: #16a34a;
  color: #ffffff;
  border-color: #16a34a;
}

.code-content {
  padding: 1.1rem 1.25rem;
  margin: 0;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.88rem;
  line-height: 1.65;
  color: #f8fafc;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --------------------------------------------------------------------------
   Citations & References
   -------------------------------------------------------------------------- */
.vibe-citation {
  background: rgba(0, 119, 212, 0.08);
  border-bottom: 1px solid var(--brand-blue);
  padding: 0.1rem 0.2rem;
}

/* --------------------------------------------------------------------------
   Navigation Footer
   -------------------------------------------------------------------------- */
.chapter-nav-footer {
  margin-top: 3rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.chapter-nav-card {
  flex: 1;
  min-width: 220px;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chapter-nav-card:hover {
  background: #ffffff;
  border-color: var(--brand-blue);
  box-shadow: var(--shadow-sm);
}

.chapter-nav-card.next {
  text-align: right;
  align-items: flex-end;
}

.chapter-nav-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-blue);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chapter-nav-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   Toast Notification
   -------------------------------------------------------------------------- */
.book-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #0f172a;
  color: #ffffff;
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  border: 1px solid #334155;
}

.book-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.book-toast-icon {
  color: #38bdf8;
  display: flex;
  align-items: center;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.book-footer {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border-color);
  background: #ffffff;
}

.book-footer p {
  font-size: 0.82rem;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.book-footer a {
  color: var(--brand-blue);
  text-decoration: none;
  font-weight: 600;
}

.book-footer a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   모바일 최적화 전용 컴포넌트 (Mobile Quick Nav, Drawer, FAB)
   ========================================================================== */

/* 1. 모바일 상단 퀵 네비게이션 바 (가로 스크롤 칩) */
.mobile-quick-nav {
  display: none;
  position: sticky;
  top: 56px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  z-index: 850;
  padding: 0.55rem 0.85rem;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  box-sizing: border-box;
}

.mobile-quick-nav::-webkit-scrollbar {
  display: none;
}

@media (max-width: 900px) {
  .mobile-quick-nav {
    display: flex;
    align-items: center;
    gap: 0.45rem;
  }
}

.quick-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  height: 32px;
  padding: 0 0.75rem;
  box-sizing: border-box;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text-secondary);
  text-decoration: none;
  flex-shrink: 0;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  vertical-align: middle;
}

.quick-chip svg {
  display: block;
  flex-shrink: 0;
}

.quick-chip:hover, .quick-chip:active {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.quick-chip.active {
  background: var(--brand-blue);
  color: #ffffff;
  border-color: var(--brand-blue);
}

.quick-chip-toc {
  background: var(--brand-orange-subtle);
  border-color: var(--brand-orange-border);
  color: var(--brand-orange-dark);
}

/* 2. 모바일 목차 오프캔버스 드로어 (Drawer) */
.mobile-toc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.mobile-toc-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-toc-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(85vw, 360px);
  background: var(--bg-surface);
  z-index: 1510;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.mobile-toc-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-app);
}

.drawer-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.drawer-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  transition: all 0.15s ease;
}

.drawer-close-btn:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.drawer-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

/* 3. 모바일 플로팅 액션 버튼 (FAB) */
.book-fab-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 950;
}

.fab-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  font-family: inherit;
}

.fab-btn:hover, .fab-btn:active {
  transform: scale(1.06);
  color: var(--brand-blue);
  border-color: var(--brand-blue-border);
}

.fab-btn.fab-toc {
  background: var(--brand-blue);
  color: #ffffff;
  border-color: var(--brand-blue);
}

.fab-btn.fab-toc:hover, .fab-btn.fab-toc:active {
  background: var(--brand-blue-dark);
  color: #ffffff;
}

.fab-btn.fab-top {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
}

.fab-btn.fab-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* 4. 모바일 및 태블릿 레이아웃 정밀 미디어 쿼리 */
@media (max-width: 900px) {
  /* 모바일에서는 사이드바가 본문 위에 길게 늘어서지 않도록 데스크톱용 사이드바 숨김 */
  .book-sidebar {
    display: none;
  }

  .book-main-layout {
    margin: 1rem auto 4rem;
    padding: 0 1rem;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  /* 히어로 섹션 */
  .book-hero {
    padding: 2rem 1rem 2.25rem;
  }

  .hero-title {
    font-size: 1.7rem;
    line-height: 1.3;
    margin-bottom: 0.8rem;
  }

  .hero-subtitle {
    font-size: 0.92rem;
    line-height: 1.65;
    margin-bottom: 1.25rem;
  }

  .hero-authors {
    font-size: 0.82rem;
    gap: 0.3rem;
  }

  .book-spec-card {
    padding: 1.1rem 1rem;
  }

  .spec-book-title {
    font-size: 1rem;
  }

  .spec-features {
    font-size: 0.78rem;
    gap: 0.35rem;
  }

  /* 본문 영역 */
  .chapter-section {
    padding: 1.4rem 1rem;
    margin-bottom: 1.5rem;
    border-radius: var(--radius-sm);
  }

  h1.book-chapter-title {
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.85rem;
  }

  h2 {
    font-size: 1.18rem;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
  }

  h3 {
    font-size: 1.05rem;
    margin-top: 1.5rem;
    margin-bottom: 0.6rem;
  }

  p {
    font-size: 0.94rem;
    line-height: 1.75;
    margin-bottom: 1.1rem;
  }

  /* 박스 컴포넌트 */
  .box-summary, .box-easy, .box-study, .box-question {
    padding: 0.95rem 1rem;
    margin: 1.25rem 0;
  }

  .box-header {
    font-size: 0.76rem;
    margin-bottom: 0.4rem;
  }

  .box-body {
    font-size: 0.9rem;
    line-height: 1.65;
  }

  /* 코드 및 프롬프트 블록 */
  .code-wrapper {
    margin: 1.25rem 0;
  }

  .code-header {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .code-title {
    font-size: 0.74rem;
  }

  .copy-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.72rem;
    min-height: 32px;
  }

  .code-content {
    padding: 0.85rem 0.95rem;
    font-size: 0.82rem;
    line-height: 1.6;
  }

  /* 데모 콜아웃 카드 */
  .demo-callout-card {
    padding: 0.95rem 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .demo-btn-group {
    width: 100%;
  }

  .demo-action-btn {
    flex: 1;
    justify-content: center;
    padding: 0.5rem 0.8rem;
    text-align: center;
  }

  /* 네비게이션 푸터 */
  .chapter-nav-footer {
    margin-top: 2rem;
    flex-direction: column;
    gap: 0.75rem;
  }

  .chapter-nav-card {
    min-width: 100%;
  }
}
