/* ===== Design tokens ===== */
:root, [data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f6f7;
  --surface-3: #f0f0f1;
  --border: #e6e6e8;
  --border-strong: #d6d6d9;
  --text: #0a0a0b;
  --text-muted: #62636a;
  --text-faint: #9a9ba2;
  --accent: #0a0a0b;
  --accent-contrast: #ffffff;
  --link: #2563eb;
  --active-bg: #f2f2f3;
  --active-text: #0a0a0b;
  --code-bg: #f4f4f5;
  --logo-mark: #ffffff;
  --tag-a: #1d4ed8;
  --tag-a-bg: #eff4ff;
  --tag-b: #b45309;
  --tag-b-bg: #fff5e8;
  --sidebar-w: 270px;
  --toc-w: 250px;
  --topbar-h: 56px;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.875rem;
  --text-3xl: 2.25rem;
  --font-body: 'Inter', 'IBM Plex Sans KR', system-ui, sans-serif;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.14);
}
[data-theme="dark"] {
  --bg: #09090b;
  --surface: #0c0c0e;
  --surface-2: #161618;
  --surface-3: #1c1c1f;
  --border: #232326;
  --border-strong: #303035;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-faint: #6b6b73;
  --accent: #f4f4f5;
  --accent-contrast: #09090b;
  --link: #60a5fa;
  --active-bg: #1a1a1d;
  --active-text: #ffffff;
  --code-bg: #18181b;
  --logo-mark: #09090b;
  --tag-a: #93b4ff;
  --tag-a-bg: #16213d;
  --tag-b: #f5c07a;
  --tag-b-bg: #2c2113;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { color-scheme: dark; }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 20px); }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; background: none; border: none; color: inherit; font: inherit; }
img, svg { display: block; max-width: 100%; }
::selection { background: color-mix(in srgb, var(--link) 25%, transparent); }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: var(--radius-sm); }

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: 100%;
  display: flex; align-items: center; gap: 22px;
  padding: 0 22px;
  max-width: 1600px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand-logo { color: var(--accent); border-radius: 7px; }
.brand-name { font-weight: 700; font-size: 0.95rem; letter-spacing: -0.01em; }
.brand-sub { color: var(--text-faint); font-weight: 600; }
.topnav { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
.topnav a { font-size: var(--text-sm); font-weight: 500; color: var(--text-muted); transition: color .15s; }
.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--text); font-weight: 600; }
.topbar-search {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 11px;
  min-width: 240px; max-width: 320px; width: 100%;
  color: var(--text-faint);
  cursor: text;
}
.topbar-search input { flex: 1; border: none; background: none; outline: none; color: var(--text); font-size: var(--text-sm); }
.topbar-search input::placeholder { color: var(--text-faint); }
.topbar-search kbd {
  font-family: var(--font-body); font-size: 0.7rem; color: var(--text-faint);
  border: 1px solid var(--border-strong); border-radius: 5px; padding: 1px 5px;
  background: var(--surface);
}
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: var(--radius-sm); color: var(--text-muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.menu-btn { display: none; }

/* ===== Layout grid ===== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0,1fr) var(--toc-w);
  max-width: 1600px; margin: 0 auto;
  align-items: start;
}

/* ===== Sidebar ===== */
.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar-scroll { height: 100%; overflow-y: auto; padding: 26px 16px 60px 22px; }
.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
.nav-group { margin-bottom: 26px; }
.nav-group-title {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--text-faint);
  padding: 0 10px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 7px;
}
.nav-group-title .badge {
  font-size: 0.62rem; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  letter-spacing: 0.02em; text-transform: none;
}
.badge-a { color: var(--tag-a); background: var(--tag-a-bg); }
.badge-b { color: var(--tag-b); background: var(--tag-b-bg); }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 6.5px 10px; border-radius: var(--radius-sm);
  font-size: var(--text-sm); color: var(--text-muted);
  transition: background .13s, color .13s;
  line-height: 1.35;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--active-bg); color: var(--active-text); font-weight: 600; }
.nav-item .nav-ico { font-size: 0.95rem; width: 18px; text-align: center; flex-shrink: 0; }
.nav-item .nav-txt { flex: 1; }
.nav-month-label {
  font-size: 0.68rem; font-weight: 700; color: var(--text-faint);
  padding: 12px 10px 5px; letter-spacing: 0.04em;
}

/* ===== Content ===== */
.content { min-width: 0; display: flex; flex-direction: column; min-height: calc(100dvh - var(--topbar-h)); }
.doc { padding: 40px clamp(24px, 4vw, 60px) 40px; max-width: 820px; width: 100%; margin: 0 auto; flex: 1; }

.doc-eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--text-xs); font-weight: 600; color: var(--text-muted);
  margin-bottom: 14px;
}
.doc-eyebrow .pill { padding: 2px 9px; border-radius: 999px; font-weight: 700; font-size: 0.68rem; }
.doc-h1 { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin-bottom: 12px; }
.doc-lead { font-size: var(--text-md); color: var(--text-muted); line-height: 1.6; margin-bottom: 22px; }
.doc-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 30px; flex-wrap: wrap; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: var(--text-sm); font-weight: 500; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 12px; transition: background .15s, border-color .15s, color .15s;
}
.tool-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 26px 0; }

/* markdown body */
.md h1 { font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.015em; margin: 34px 0 14px; scroll-margin-top: 80px; }
.md h2 { font-size: var(--text-lg); font-weight: 700; letter-spacing: -0.01em; margin: 32px 0 12px; padding-top: 6px; scroll-margin-top: 80px; }
.md h3 { font-size: var(--text-md); font-weight: 700; margin: 24px 0 10px; scroll-margin-top: 80px; }
.md h4 { font-size: var(--text-base); font-weight: 700; color: var(--text); margin: 18px 0 8px; scroll-margin-top: 80px; }
.md p { margin: 12px 0; color: var(--text); line-height: 1.72; }
.md ul, .md ol { margin: 12px 0 12px 2px; padding-left: 22px; }
.md li { margin: 6px 0; line-height: 1.68; }
.md li::marker { color: var(--text-faint); }
.md strong { font-weight: 700; color: var(--text); }
.md a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.md a:hover { text-decoration-thickness: 2px; }
.md code { background: var(--code-bg); border-radius: 5px; padding: 2px 6px; font-size: 0.86em; font-family: 'SFMono-Regular', ui-monospace, Menlo, monospace; }
.md blockquote { border-left: 3px solid var(--border-strong); padding: 4px 0 4px 16px; margin: 16px 0; color: var(--text-muted); }
.md table { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: var(--text-sm); display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* footnote superscript */
sup.fn {
  color: var(--link); font-size: 0.68em; font-weight: 600;
  cursor: pointer; padding: 0 1px; vertical-align: super;
}
sup.fn:hover { text-decoration: underline; }

/* references section */
.refs { margin-top: 40px; border-top: 1px solid var(--border); padding-top: 22px; }
.refs summary {
  font-size: var(--text-sm); font-weight: 700; color: var(--text-muted);
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px;
}
.refs summary::-webkit-details-marker { display: none; }
.refs summary::before { content: "▸"; color: var(--text-faint); transition: transform .15s; }
.refs[open] summary::before { transform: rotate(90deg); }
.refs ol { margin: 14px 0 0; padding-left: 26px; }
.refs li { font-size: var(--text-xs); margin: 5px 0; word-break: break-all; }
.refs li a { color: var(--link); text-decoration: none; }
.refs li a:hover { text-decoration: underline; }

/* home / index cards */
.home-hero { padding: 20px 0 34px; border-bottom: 1px solid var(--border); margin-bottom: 34px; }
.home-hero h1 { font-size: var(--text-3xl); font-weight: 800; letter-spacing: -0.03em; line-height: 1.12; margin-bottom: 16px; }
.home-hero p { font-size: var(--text-md); color: var(--text-muted); max-width: 62ch; }
.home-stats { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.stat { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 20px; min-width: 120px; background: var(--surface); }
.stat .num { font-size: var(--text-2xl); font-weight: 800; letter-spacing: -0.02em; }
.stat .lbl { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.home-section-title { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin: 34px 0 16px; display: flex; align-items: center; gap: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; text-align: left; transition: border-color .15s, box-shadow .15s, transform .15s;
  background: var(--surface); display: flex; flex-direction: column; gap: 6px;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.card .card-ico { font-size: 1.3rem; }
.card .card-title { font-weight: 700; font-size: var(--text-base); letter-spacing: -0.01em; }
.card .card-meta { font-size: var(--text-xs); color: var(--text-faint); }

/* ===== TOC ===== */
.toc { position: sticky; top: var(--topbar-h); height: calc(100dvh - var(--topbar-h)); overflow: hidden; }
.toc-sticky { height: 100%; overflow-y: auto; padding: 40px 22px 60px 20px; }
.toc-sticky::-webkit-scrollbar { width: 6px; }
.toc-sticky::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
.toc-head { font-size: var(--text-xs); font-weight: 700; color: var(--text); margin-bottom: 14px; }
.toc-list { display: flex; flex-direction: column; gap: 2px; border-left: 1px solid var(--border); }
.toc-link {
  font-size: var(--text-xs); color: var(--text-muted);
  padding: 5px 0 5px 14px; margin-left: -1px;
  border-left: 2px solid transparent; line-height: 1.4;
  transition: color .13s, border-color .13s; cursor: pointer;
}
.toc-link:hover { color: var(--text); }
.toc-link.lv3 { padding-left: 26px; font-size: 0.72rem; }
.toc-link.active { color: var(--text); font-weight: 600; border-left-color: var(--accent); }

.promo {
  margin-top: 30px; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px; background: var(--surface-2);
}
.promo-title { font-weight: 700; font-size: var(--text-sm); margin-bottom: 8px; }
.promo-body { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.6; margin-bottom: 14px; }
.promo-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; padding: 8px 12px; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-contrast);
  font-size: var(--text-sm); font-weight: 600;
  transition: opacity .15s;
}
.promo-btn:hover { opacity: 0.88; }

/* footer */
.doc-footer { border-top: 1px solid var(--border); }
.doc-footer-inner { max-width: 820px; margin: 0 auto; padding: 24px clamp(24px, 4vw, 60px); font-size: var(--text-xs); color: var(--text-faint); display: flex; align-items: center; gap: 8px; }
.doc-footer .dot { opacity: 0.5; }

/* prev/next */
.pager { display: flex; gap: 12px; margin-top: 40px; }
.pager a {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px 16px; transition: border-color .15s, background .15s;
}
.pager a:hover { border-color: var(--border-strong); background: var(--surface-2); }
.pager .dir { font-size: var(--text-xs); color: var(--text-faint); }
.pager .ttl { font-size: var(--text-sm); font-weight: 600; margin-top: 3px; }
.pager .next { text-align: right; }

/* ===== search modal ===== */
.search-modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.4); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
.search-modal[hidden] { display: none; }
.search-box {
  width: min(560px, 92vw); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden;
}
.search-input-row { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--text-faint); }
.search-input-row input { flex: 1; border: none; background: none; outline: none; font-size: var(--text-md); color: var(--text); }
.search-results { max-height: 52vh; overflow-y: auto; padding: 8px; }
.search-result { display: block; padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; }
.search-result:hover, .search-result.sel { background: var(--surface-2); }
.search-result .sr-t { font-size: var(--text-sm); font-weight: 600; }
.search-result .sr-m { font-size: var(--text-xs); color: var(--text-faint); margin-top: 2px; }
.search-empty { padding: 30px; text-align: center; color: var(--text-faint); font-size: var(--text-sm); }

/* ===== responsive ===== */
.sidebar-overlay { display: none; }
@media (max-width: 1200px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0,1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  :root { --topbar-h: 52px; }
  .topnav { display: none; }
  .topbar-search { min-width: 0; max-width: none; }
  .topbar-search kbd { display: none; }
  .menu-btn { display: grid; }
  .layout { grid-template-columns: minmax(0,1fr); }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 45;
    width: 82vw; max-width: 320px; background: var(--bg);
    transform: translateX(-100%); transition: transform .22s ease;
    border-right: 1px solid var(--border);
  }
  body.menu-open .sidebar { transform: translateX(0); }
  body.menu-open .sidebar-overlay { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 44; background: rgba(0,0,0,.4); }
  .doc { padding: 28px 20px; }
  .home-hero h1 { font-size: var(--text-2xl); }
}
@media (max-width: 480px) {
  .brand-sub { display: none; }
  .topbar-inner { gap: 12px; padding: 0 14px; }
}
