:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1f2430;
  --text-soft: #5b6472;
  --text-muted: #8a93a2;
  --primary: #2f6fed;
  --primary-soft: #e8f0fe;
  --accent: #0e9f6e;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-hover: 0 6px 16px rgba(16, 24, 40, .12);
  --radius: 12px;
  --maxw: 1120px;
  --maxw-read: 820px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 22px 0;
}
.site-header.compact { padding: 16px 0; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .5px;
}
.brand-text { font-size: 19px; font-weight: 500; }
.brand-text b { font-weight: 800; }

.tagline {
  margin: 12px 0 0;
  color: var(--text-soft);
  font-size: 14px;
}

/* Search */
.search-section { margin: 36px auto 26px; max-width: 100%; }
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0 22px;
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.search-icon {
  width: 24px;
  height: 24px;
  color: var(--text-muted);
  flex: 0 0 auto;
}
#search {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 18px;
  padding: 20px 14px;
  color: var(--text);
  font-family: inherit;
}
#search::placeholder { color: var(--text-muted); }

.result-count {
  margin: 12px 4px 0;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

/* Topic list */
.topic-section { margin-bottom: 48px; }
.topic-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.topic-list li { display: flex; }
.topic-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .15s, border-color .15s;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.topic-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: #cdd5e0;
}
.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.topic-card .card-category {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.topic-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.topic-card .card-summary {
  margin: 0 0 14px;
  color: var(--text-soft);
  font-size: 14px;
  flex: 1 1 auto;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.tag {
  font-size: 12px;
  color: var(--text-muted);
  background: #f0f2f5;
  padding: 3px 9px;
  border-radius: 6px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-updated {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 0;
  font-size: 15px;
}

/* Topic detail */
.back-link {
  display: inline-block;
  margin: 28px 0 8px;
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.back-link:hover { text-decoration: underline; }

.topic-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 56px 48px;
  margin-bottom: 48px;
}
/* 상세 페이지는 메인과 동일한 넓은 폭 사용 */
.back-link,
.topic-detail { max-width: 100%; }
/* 긴 문단은 읽기 편한 폭으로, 표/구분선은 전체 폭으로 */
.markdown-body > p,
.markdown-body > ul,
.markdown-body > ol,
.markdown-body > blockquote,
.markdown-body > h1,
.markdown-body > h2,
.markdown-body > h3 { max-width: 1000px; }
.topic-meta { border-bottom: 1px solid var(--border); padding-bottom: 18px; margin-bottom: 8px; }
.topic-meta .card-category { display: inline-block; font-size: 12px; font-weight: 700; color: var(--primary); background: var(--primary-soft); padding: 3px 10px; border-radius: 999px; }
.topic-meta .meta-tags { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.topic-meta .meta-updated { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* Markdown */
.markdown-body { font-size: 15.5px; }
.markdown-body h1 { font-size: 26px; font-weight: 800; margin: 22px 0 14px; line-height: 1.35; }
.markdown-body h2 {
  font-size: 20px; font-weight: 700; margin: 32px 0 12px;
  padding-bottom: 8px; border-bottom: 2px solid var(--primary-soft);
}
.markdown-body h3 { font-size: 17px; font-weight: 700; margin: 22px 0 8px; }
.markdown-body p { margin: 10px 0; }
.markdown-body ul, .markdown-body ol { padding-left: 22px; margin: 10px 0; }
.markdown-body li { margin: 5px 0; }
.markdown-body strong { color: #10233f; }
.markdown-body a { color: var(--primary); }
.markdown-body code {
  background: #f0f2f5; padding: 2px 6px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
}
.markdown-body blockquote {
  margin: 14px 0; padding: 8px 16px; border-left: 4px solid var(--accent);
  background: #f0faf6; color: var(--text-soft); border-radius: 0 8px 8px 0;
}
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 26px 0; }

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14.5px;
  display: block;
  overflow-x: auto;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}
.markdown-body thead th {
  background: #eef2f8;
  font-weight: 700;
  white-space: nowrap;
}
.markdown-body tbody tr:nth-child(even) { background: #fafbfc; }

/* 차트 / 다이어그램 */
.chart-wrap {
  max-width: 660px;
  margin: 22px auto;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.mermaid {
  margin: 22px 0;
  text-align: center;
  overflow-x: auto;
}
.mermaid svg { max-width: 100%; height: auto; }

.loading { color: var(--text-muted); }
.error-box { color: #b42318; background: #fef3f2; border: 1px solid #fecdca; padding: 16px 18px; border-radius: 8px; }

/* Footer */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 0;
}
.site-footer p { margin: 0; color: var(--text-muted); font-size: 13px; text-align: center; }
.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}
.feedback-link {
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s;
}
.feedback-link:hover { color: var(--primary); text-decoration: underline; }

/* Responsive */
@media (max-width: 560px) {
  .topic-list { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topic-detail { padding: 22px 20px 28px; }
  .brand-text { font-size: 17px; }
}
