:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #1b1f27;
  --muted: #5d6573;
  --accent: #2f6fdf;
  --accent-soft: #e6eefc;
  --active: #1f8a4c;
  --active-soft: #e3f4ea;
  --maint: #a66300;
  --maint-soft: #fbf0dc;
  --arch: #6b7280;
  --arch-soft: #eceef1;
  --draft: #8a3ffc;
  --draft-soft: #f0e8ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "D2Coding", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1e232d;
    --border: #2a303c;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --accent: #6ea0ff;
    --accent-soft: #1d2a44;
    --active: #4cc283;
    --active-soft: #15301f;
    --maint: #e3a64a;
    --maint-soft: #33270f;
    --arch: #9aa3b2;
    --arch-soft: #252a33;
    --draft: #b48cff;
    --draft-soft: #2a2140;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #171b23;
  --surface-2: #1e232d;
  --border: #2a303c;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #6ea0ff;
  --accent-soft: #1d2a44;
  --active: #4cc283;
  --active-soft: #15301f;
  --maint: #e3a64a;
  --maint-soft: #33270f;
  --arch: #9aa3b2;
  --arch-soft: #252a33;
  --draft: #b48cff;
  --draft-soft: #2a2140;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px 48px; }

/* 머리 */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1240px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); flex: none;
  -webkit-mask: none; position: relative; }
.logo::after { content: ""; position: absolute; inset: 9px; background:
  linear-gradient(#fff 0 0) 0 0 / 7px 7px no-repeat, linear-gradient(#fff 0 0) 100% 0 / 7px 7px no-repeat,
  linear-gradient(#fff 0 0) 0 100% / 7px 7px no-repeat, linear-gradient(#fff 0 0) 100% 100% / 7px 7px no-repeat; }
h1 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .moon { display: none; }
:root[data-theme="dark"] .icon-btn .sun { display: none; }
:root[data-theme="dark"] .icon-btn .moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .sun { display: none; }
  :root:not([data-theme="light"]) .icon-btn .moon { display: inline; }
}

/* 요약 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; text-align: left; color: inherit; font: inherit; }
.stat:hover { border-color: var(--accent); }
.stat.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.langs { cursor: default; grid-column: span 2; }
.stat.langs:hover { border-color: var(--border); }
.bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; margin: 8px 0 6px; background: var(--surface-2); }
.bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: 0; }
@media (max-width: 520px) { .stat.langs { grid-column: 1 / -1; } }

/* 도구 막대 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 8px; }
.search { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; color: var(--muted); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: 9px 0; width: 100%; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
select { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; max-width: 160px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 14px; padding: 7px 14px; cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.result-count { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }

/* 카드 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 10px; text-align: left; color: inherit; font: inherit; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card:focus-visible, .stat:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card h3 { margin: 0; font-size: 16px; letter-spacing: -.01em; word-break: break-all; }
.card .t { color: var(--muted); font-size: 13px; margin-top: 1px; }
.card p.sum { margin: 0; font-size: 14px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.chip.lang { color: var(--text); }
.chip.lang i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.badge.active { color: var(--active); background: var(--active-soft); }
.badge.maintenance { color: var(--maint); background: var(--maint-soft); }
.badge.archived { color: var(--arch); background: var(--arch-soft); }
.badge.draft { color: var(--draft); background: var(--draft-soft); }
.badges { display: flex; gap: 4px; flex: none; }

/* 표 */
.table-view { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table-view table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px; }
.table-view th, .table-view td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table-view th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
.table-view tbody tr { cursor: pointer; }
.table-view tbody tr:hover { background: var(--surface-2); }
.table-view tbody tr:last-child td { border-bottom: 0; }
.table-view .nm { font-weight: 600; }
.table-view .s { color: var(--muted); font-size: 13px; max-width: 360px; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* 자세히 */
.scrim { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(880px, 100%); background: var(--bg); z-index: 10; box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.drawer-head h2 { margin: 2px 0 0; font-size: 20px; letter-spacing: -.01em; }
.d-name { font-family: var(--mono); font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.drawer-body { overflow-y: auto; padding: 18px 20px 48px; }
.lead { font-size: 15.5px; margin: 0 0 16px; }
.meta { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .meta { grid-template-columns: 1fr; gap: 2px; } .meta dd { margin-bottom: 8px; } }
.box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.box h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
.cmd { display: grid; grid-template-columns: 110px 1fr auto; gap: 6px 10px; align-items: center; font-size: 13.5px; }
.cmd .k { color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
.cmd code { display: block; overflow-x: auto; white-space: pre; padding: 4px 8px; }
@media (max-width: 560px) { .cmd { grid-template-columns: 1fr auto; } .cmd .k { grid-column: 1 / -1; margin-top: 4px; } }
.copy { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 6px; font-size: 12px; padding: 3px 8px; cursor: pointer; font-family: inherit; }
.copy:hover { color: var(--accent); border-color: var(--accent); }
.rel { display: flex; flex-direction: column; gap: 8px; }
.rel a { display: block; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.rel a:hover { border-color: var(--accent); text-decoration: none; }
.rel a b { color: var(--accent); margin-right: 6px; }
.rel a span { color: var(--muted); font-size: 13.5px; }
.rel .back { font-size: 12px; color: var(--muted); margin-left: 4px; }

/* 본문(마크다운) */
.md { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 18px 16px; font-size: 14.5px; }
.md h1, .md h2, .md h3 { letter-spacing: -.01em; }
.md h2 { font-size: 17px; margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 15px; margin: 18px 0 8px; }
.md p, .md ul, .md ol { margin: 8px 0; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 10px 0; padding: 4px 14px; border-left: 3px solid var(--draft); background: var(--draft-soft); border-radius: 0 8px 8px 0; }
.md .table-wrap { overflow-x: auto; margin: 10px 0; }
.md table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; }
.md pre code { background: none; padding: 0; }
.md pre.mermaid { font-family: var(--mono); white-space: pre; text-align: center; }
.md pre.mermaid[data-processed] { background: var(--surface); }
.md pre.mermaid svg { max-width: 100%; height: auto; }
.md hr { border: 0; border-top: 1px solid var(--border); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 20; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .filters { width: 100%; }
  .filters label { flex: 1 1 45%; }
  .filters select { flex: 1; max-width: none; width: 100%; }
  .cards { grid-template-columns: 1fr; }
}
.table-view .nw { white-space: nowrap; }
