/* =============================================
   CSS 변수 (라이트 / 다크 테마)
   ============================================= */
:root {
  --bg: #f0f7f6;
  --surface: #ffffff;
  --border: #c8e6e2;
  --text: #1a2e2c;
  --text-muted: #5a7d79;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --code-bg: #e8f5f3;
  --shadow: 0 2px 8px rgba(13,148,136,0.08);
  --header-bg: #ffffffcc;
  --sidebar-bg: #ffffff;
  --tag-bg: #ccfbf1;
  --tag-color: #0f766e;
}

[data-theme="dark"] {
  --bg: #0d1f1e;
  --surface: #132e2c;
  --border: #1e4a47;
  --text: #e0f2f0;
  --text-muted: #7ab8b3;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --code-bg: #0d2a28;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --header-bg: #132e2ccc;
  --sidebar-bg: #132e2c;
  --tag-bg: #134e4a;
  --tag-color: #5eead4;
}

/* =============================================
   기본 리셋 & 공통
   ============================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Noto Sans KR', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background 0.25s, color 0.25s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
img { max-width: 100%; height: auto; border-radius: 6px; }

/* =============================================
   헤더
   ============================================= */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-title { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.header-clock {
  font-family: 'DM Sans', 'Noto Sans KR', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.site-title:hover { text-decoration: none; color: var(--accent); }
.site-nav { display: flex; align-items: center; gap: 1.2rem; }
.site-nav a { font-size: 0.9rem; color: var(--text-muted); }
.site-nav a:hover { color: var(--accent); text-decoration: none; }
.dark-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
  transition: background 0.2s;
}
.dark-toggle:hover { background: var(--border); }

/* =============================================
   레이아웃
   ============================================= */
.layout {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2rem;
  align-items: start;
}

/* =============================================
   사이드바
   ============================================= */
.sidebar {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-profile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 0.8rem;
  border: 3px solid var(--border);
}
.sidebar-name { font-weight: 700; font-size: 1.05rem; margin-bottom: 0.3rem; }
.sidebar-bio { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 0.8rem; }
.sidebar-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; }
.sidebar-links a {
  font-size: 0.78rem;
  background: var(--tag-bg);
  color: var(--tag-color);
  padding: 2px 8px;
  border-radius: 20px;
}
.sidebar-links a:hover { text-decoration: none; opacity: 0.8; }

.sidebar-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
}
.sidebar-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

.category-list { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }
.category-list li a {
  font-size: 0.88rem;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.category-list li a:hover { color: var(--accent); text-decoration: none; }
.category-count {
  font-size: 0.78rem;
  background: var(--tag-bg);
  color: var(--tag-color);
  padding: 1px 7px;
  border-radius: 20px;
}

.search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--accent); }

/* =============================================
   목차 (TOC)
   ============================================= */
.toc-list { list-style: none; display: flex; flex-direction: column; gap: 0.2rem; }
.toc-list li a {
  display: block;
  font-size: 0.83rem;
  color: var(--text-muted);
  padding: 2px 0;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}
.toc-list li a:hover { color: var(--accent); text-decoration: none; }
.toc-list li a.active { color: var(--accent); font-weight: 600; }
.toc-h1 { padding-left: 0; }
.toc-h2 { padding-left: 0.8rem; }
.toc-h3 { padding-left: 1.6rem; font-size: 0.78rem !important; }

/* 코드 복사 버튼 */
.code-wrap { position: relative; }
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--border);
  border: none;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.code-wrap:hover .copy-btn { opacity: 1; }
.copy-btn.copied { background: var(--accent); color: #fff; opacity: 1; }

/* 정렬 토글 */
.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.sort-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.78rem;
}
.sort-toggle button {
  background: none;
  border: none;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.sort-toggle button.active {
  background: var(--accent);
  color: #fff;
}
.sort-toggle button:hover:not(.active) { background: var(--border); }

/* 메인 요약 카드 */
.summary-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.8rem;
}
.summary-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.summary-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}
.mini-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: color 0.15s;
}
.mini-card:first-of-type { border-top: none; }
.mini-card:hover .mini-card-title { color: var(--accent); }
.mini-card-title {
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.mini-card-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* 글 목록 (홈) */
.post-list { display: flex; flex-direction: column; gap: 1.2rem; }
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem 1.6rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}
.post-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.post-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.post-card-category {
  font-size: 0.75rem;
  background: var(--tag-bg);
  color: var(--tag-color);
  padding: 2px 9px;
  border-radius: 20px;
  font-weight: 600;
}
.post-card-date { font-size: 0.78rem; color: var(--text-muted); }
.post-card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.4rem; color: var(--text); }
.post-card-excerpt { font-size: 0.88rem; color: var(--text-muted); line-height: 1.6; }
.post-card-tags { margin-top: 0.8rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag { font-size: 0.73rem; background: var(--code-bg); color: var(--text-muted); padding: 2px 8px; border-radius: 4px; }

/* =============================================
   글 본문
   ============================================= */
.post-header { margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.post-title { font-size: 1.9rem; font-weight: 800; line-height: 1.3; margin-bottom: 0.8rem; }
.post-meta { display: flex; gap: 0.8rem; flex-wrap: wrap; align-items: center; font-size: 0.85rem; color: var(--text-muted); }
.post-body { max-width: 100%; }

.post-body h1, .post-body h2, .post-body h3,
.post-body h4, .post-body h5, .post-body h6 { margin: 2rem 0 0.8rem; line-height: 1.3; }
.post-body h2 { font-size: 1.4rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.post-body h3 { font-size: 1.15rem; }
.post-body p { margin-bottom: 1rem; }
.post-body ul, .post-body ol { margin: 0.5rem 0 1rem 1.5rem; }
.post-body li { margin-bottom: 0.3rem; }
.post-body blockquote {
  border-left: 4px solid var(--accent);
  margin: 1rem 0;
  padding: 0.6rem 1.2rem;
  background: var(--code-bg);
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
}
.post-body code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'Fira Code', 'Consolas', monospace;
}
.post-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
  overflow-x: auto;
  margin: 1rem 0;
}
.post-body pre code { background: none; padding: 0; }
.post-body table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; }
.post-body th, .post-body td { border: 1px solid var(--border); padding: 0.5rem 0.9rem; text-align: left; }
.post-body th { background: var(--code-bg); font-weight: 600; }
.post-body hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* 유튜브 임베드 */
.yt-wrapper {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: 10px;
  margin: 1.2rem 0;
}
.yt-wrapper iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
  border-radius: 10px;
}

/* 글 하단 네비게이션 */
.post-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}
.post-nav a { font-size: 0.88rem; color: var(--text-muted); max-width: 45%; }
.post-nav a:hover { color: var(--accent); }

/* 뒤로가기 버튼 */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
.back-btn:hover { color: var(--accent); }

/* Giscus 댓글 */
.comments-section { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border); }
.comments-section h3 { font-size: 1.1rem; margin-bottom: 1.2rem; }

/* =============================================
   포트폴리오
   ============================================= */
.portfolio-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }
.portfolio-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.2s;
}
.portfolio-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.portfolio-thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; }
.portfolio-info { padding: 1rem; }
.portfolio-info h3 { font-size: 1rem; margin-bottom: 0.3rem; }
.portfolio-info p { font-size: 0.83rem; color: var(--text-muted); }

/* =============================================
   페이지 타이틀 공통
   ============================================= */
.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* =============================================
   푸터
   ============================================= */
.site-footer {
  text-align: center;
  padding: 2rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

/* 버거 버튼 (모바일 전용, 기본 숨김) */
.burger-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text);
  transition: background 0.2s;
}
.burger-btn:hover { background: var(--border); }

/* 오버레이 딤 (모바일 사이드바 열릴 때 배경) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 150;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* =============================================
   반응형 — 태블릿 (768px ~ 1024px)
   ============================================= */
@media (min-width: 768px) and (max-width: 1024px) {
  .layout {
    grid-template-columns: 200px 1fr;
    gap: 1.2rem;
    padding: 0 1rem;
    margin: 1.2rem auto;
  }

  .sidebar {
    top: 64px;
    max-height: calc(100vh - 80px);
  }

  .sidebar-profile { padding: 1rem; }
  .avatar { width: 60px; height: 60px; }
  .sidebar-name { font-size: 0.95rem; }
  .sidebar-bio { font-size: 0.75rem; }
  .sidebar-links a { font-size: 0.72rem; padding: 2px 6px; }

  .sidebar-section { padding: 0.9rem; }
  .sidebar-section h3 { font-size: 0.78rem; }

  .header-inner { padding: 0 1rem; }
  .header-clock { font-size: 0.88rem; }
  .site-title { font-size: 1.05rem; }

  .post-title { font-size: 1.6rem; }

  .summary-section { grid-template-columns: 1fr 1fr; gap: 0.8rem; }

  .portfolio-grid { grid-template-columns: repeat(2, 1fr); }
}

/* =============================================
   반응형 — 모바일 (~768px)
   ============================================= */
@media (max-width: 767px) {
  /* 헤더 */
  .header-inner {
    padding: 0 1rem;
    height: 50px;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }
  .site-title { font-size: 0.95rem; }
  .header-clock { display: none; } /* 모바일에선 시계 숨김 */
  .site-nav { gap: 0.6rem; }
  .site-nav a { font-size: 0.8rem; }
  .dark-toggle { padding: 3px 6px; font-size: 0.9rem; }

  /* 버거 버튼 표시 */
  .burger-btn { display: flex; }

  /* 사이드바: 고정 드로어로 전환 */
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    z-index: 200;
    padding: 1rem;
    overflow-y: auto;
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: none;
    flex-direction: column;
    gap: 1rem;
  }
  .sidebar.open { left: 0; }

  /* 프로필: 드로어 안에서는 세로 배치로 복원 */
  .sidebar-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.2rem 1rem 1rem;
    margin-top: 0.5rem;
  }
  .avatar { width: 64px; height: 64px; margin-bottom: 0.6rem; }
  .sidebar-bio { margin-bottom: 0.6rem; }
  .sidebar-links { justify-content: center; }

  /* 레이아웃: 사이드바 없이 본문 전체 너비 */
  .layout {
    grid-template-columns: 1fr;
    padding: 0 0.8rem;
    margin: 1rem auto;
    gap: 1rem;
  }

  /* 원래 사이드바 자리 숨김 (드로어로 대체) */
  .layout > .sidebar { display: none; }
  .layout > .sidebar.open { display: flex; }

  /* TOC: 모바일에서 숨김 (본문 위에 있으면 너무 복잡) */
  #tocSection { display: none !important; }

  /* 본문 */
  .post-title { font-size: 1.3rem; }
  .post-body h2 { font-size: 1.2rem; }
  .post-body h3 { font-size: 1rem; }
  .post-body pre { font-size: 0.82rem; padding: 0.9rem; }
  .post-body table { font-size: 0.8rem; }
  .post-body th, .post-body td { padding: 0.4rem 0.6rem; }

  /* 요약 카드: 세로 배치 */
  .summary-section { grid-template-columns: 1fr; gap: 0.6rem; }

  /* 글 목록 카드 */
  .post-card { padding: 1rem 1.1rem; }
  .post-card-title { font-size: 0.98rem; }

  /* 정렬 토글 */
  .page-title-row { flex-wrap: wrap; gap: 0.5rem; }
  .page-title { font-size: 1.2rem; }

  /* 포트폴리오 */
  .portfolio-grid { grid-template-columns: 1fr; }

  /* 푸터 */
  .site-footer { padding: 1.2rem; font-size: 0.78rem; }
}