/* ============================================================
   marimo 한국어 문서 — GitBook 스타일 테마
   ============================================================ */

:root {
  --sidebar-w: 296px;
  --toc-w: 248px;
  --topbar-h: 60px;
  --radius: 10px;
  --font-sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  --font-mono: "SFMono-Regular", ui-monospace, "JetBrains Mono", Menlo, Consolas,
    "D2Coding", "Noto Sans Mono CJK KR", monospace;

  /* 라이트 팔레트 */
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-sunken: #f1f3f6;
  --surface: #ffffff;
  --border: #e6e8ec;
  --border-strong: #d5d9e0;
  --text: #1b1f24;
  --text-soft: #5b6472;
  --text-faint: #868f9d;
  --accent: #1a7f64;
  --accent-soft: #e6f4ef;
  --accent-strong: #126250;
  --link: #1a7f64;
  --code-bg: #f6f8fa;
  --code-text: #24292f;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .10);
  --shadow-lg: 0 24px 64px rgba(16, 24, 40, .18);

  /* 구문 강조 */
  --hl-kw: #b1268a;
  --hl-str: #0a6f4d;
  --hl-num: #b3541e;
  --hl-com: #8a93a0;
  --hl-fn: #4b46c9;
  --hl-builtin: #0a63a8;
  --hl-op: #57606a;
  --hl-attr: #953800;
}

[data-theme="dark"] {
  --bg: #0e1116;
  --bg-soft: #12161c;
  --bg-sunken: #171c23;
  --surface: #141a21;
  --border: #232a33;
  --border-strong: #2f3742;
  --text: #e7ecf2;
  --text-soft: #a4b0bf;
  --text-faint: #7c8896;
  --accent: #4ecfa6;
  --accent-soft: #122b25;
  --accent-strong: #7fe3c3;
  --link: #4ecfa6;
  --code-bg: #11161d;
  --code-text: #dbe4ee;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);

  --hl-kw: #ff7bd5;
  --hl-str: #7fdba9;
  --hl-num: #ffb37a;
  --hl-com: #6f7b8a;
  --hl-fn: #9d97ff;
  --hl-builtin: #6cc4ff;
  --hl-op: #9aa5b1;
  --hl-attr: #ffab70;
}

* { box-sizing: border-box; }

/* hidden 속성이 display 지정보다 우선하도록 */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.fill { fill: currentColor; stroke: none; }

kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  line-height: 1;
  padding: 3px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-soft);
  color: var(--text-soft);
}

.skip-link {
  position: fixed; top: -60px; left: 12px; z-index: 200;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

/* ---------- 상단바 ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 60;
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); flex: 0 0 auto; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-weight: 800; font-size: 17px; letter-spacing: -.04em;
}
.brand-text { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; white-space: nowrap; }
.brand-text em { font-style: normal; font-weight: 500; color: var(--text-faint); }

.search-trigger {
  flex: 1 1 auto; max-width: 460px; margin-left: 8px;
  display: flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 10px 0 12px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-faint);
  font-family: inherit; font-size: 14px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--surface); }
.search-trigger svg { width: 17px; height: 17px; }
.search-trigger span { flex: 1; text-align: left; }

.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }

.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 9px;
  background: none; border: 0; color: var(--text-soft); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.nav-toggle { display: none; }

[data-theme="light"] .ico-moon { display: none; }
[data-theme="dark"] .ico-sun { display: none; }

.reading-progress {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; height: 2px; z-index: 59;
  pointer-events: none;
}
.reading-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

/* ---------- 레이아웃 ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  max-width: 1560px;
  margin: 0 auto;
  padding-top: var(--topbar-h);
}

/* ---------- 사이드바 ---------- */
.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.sidebar-inner { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 22px 14px 28px 22px; }
.sidebar-foot {
  border-top: 1px solid var(--border); padding: 12px 22px;
  font-size: 12.5px; color: var(--text-faint);
}
.sidebar-foot a { color: var(--text-faint); }

.nav-group + .nav-group { margin-top: 22px; }
.nav-group-title {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 4px 8px; margin: 0 0 6px;
  background: none; border: 0; cursor: pointer;
  font-family: inherit; font-size: 11.5px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint); text-align: left;
}
.nav-group-title .chev { width: 13px; height: 13px; transition: transform .2s; margin-left: auto; }
.nav-group.collapsed .chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-list { display: none; }

.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.nav-list a {
  display: block; padding: 6px 10px; border-radius: 7px;
  font-size: 14.2px; color: var(--text-soft); line-height: 1.5;
  border-left: 2px solid transparent;
  transition: background .12s, color .12s;
}
.nav-list a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.nav-list a.active {
  background: var(--accent-soft); color: var(--accent-strong); font-weight: 600;
}
.nav-list .sub a { padding-left: 22px; font-size: 13.6px; }
.nav-list .sub { list-style: none; margin: 1px 0 3px; padding: 0; display: flex; flex-direction: column; gap: 1px; }

.scrim {
  position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 45;
  background: rgba(10, 14, 20, .5); backdrop-filter: blur(2px);
}

/* ---------- 본문 ---------- */
.content { min-width: 0; padding: 44px 56px 96px; }
.doc { max-width: 780px; }

.breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--text-faint); margin-bottom: 12px; }
.breadcrumb .sep { opacity: .5; }

.doc h1 {
  font-size: 34px; line-height: 1.35; letter-spacing: -.025em;
  margin: 0 0 10px; font-weight: 800;
}
.doc .lead { font-size: 17.5px; color: var(--text-soft); margin: 0 0 30px; line-height: 1.72; }

.doc h2 {
  font-size: 24px; font-weight: 750; letter-spacing: -.02em; line-height: 1.4;
  margin: 52px 0 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.doc h3 { font-size: 19px; font-weight: 700; letter-spacing: -.015em; margin: 34px 0 10px; }
.doc h4 { font-size: 16.5px; font-weight: 700; margin: 26px 0 8px; color: var(--text); }

.doc h2 .anchor, .doc h3 .anchor, .doc h4 .anchor {
  opacity: 0; margin-left: 8px; font-weight: 400; color: var(--text-faint);
  font-size: .8em; text-decoration: none;
}
.doc h2:hover .anchor, .doc h3:hover .anchor, .doc h4:hover .anchor { opacity: 1; }

.doc p { margin: 0 0 16px; }
.doc ul, .doc ol { margin: 0 0 16px; padding-left: 24px; }
.doc li { margin: 5px 0; }
.doc li > ul, .doc li > ol { margin: 5px 0 2px; }
.doc strong { font-weight: 700; color: var(--text); }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 36px 0; }

.doc blockquote {
  margin: 0 0 18px; padding: 2px 0 2px 18px;
  border-left: 3px solid var(--border-strong); color: var(--text-soft);
}
.doc blockquote p:last-child { margin-bottom: 0; }

.doc img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }

/* 인라인 코드 */
.doc :not(pre) > code {
  font-family: var(--font-mono); font-size: .875em;
  background: var(--bg-sunken); color: var(--code-text);
  padding: .15em .4em; border-radius: 5px;
  border: 1px solid var(--border);
  word-break: break-all;
}

/* 코드 블록 */
.code-block { position: relative; margin: 0 0 20px; }
.code-block-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; font-size: 12px; color: var(--text-faint);
  background: var(--bg-soft);
  border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.code-block-head .lang { font-family: var(--font-mono); letter-spacing: .02em; }
.code-block pre {
  margin: 0; padding: 15px 16px; overflow-x: auto;
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13.6px; line-height: 1.7;
}
.code-block.has-head pre { border-radius: 0 0 var(--radius) var(--radius); }
.code-block pre code { font-family: var(--font-mono); color: var(--code-text); background: none; padding: 0; border: 0; }

.copy-btn {
  position: absolute; top: 8px; right: 8px;
  display: flex; align-items: center; gap: 5px;
  padding: 4px 9px; font-size: 12px; font-family: inherit;
  color: var(--text-soft); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px;
  cursor: pointer; opacity: 0; transition: opacity .15s, color .15s;
}
.code-block.has-head .copy-btn { top: 5px; }
.code-block:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }
.copy-btn.done { color: var(--accent); border-color: var(--accent); }
.copy-btn svg { width: 13px; height: 13px; }

/* 구문 강조 토큰 */
.tk-kw { color: var(--hl-kw); }
.tk-str { color: var(--hl-str); }
.tk-num { color: var(--hl-num); }
.tk-com { color: var(--hl-com); font-style: italic; }
.tk-fn { color: var(--hl-fn); }
.tk-bi { color: var(--hl-builtin); }
.tk-op { color: var(--hl-op); }
.tk-attr { color: var(--hl-attr); }

/* 표 */
.table-wrap { overflow-x: auto; margin: 0 0 22px; border: 1px solid var(--border); border-radius: var(--radius); }
.doc table { border-collapse: collapse; width: 100%; font-size: 14.4px; }
.doc th, .doc td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc thead th { background: var(--bg-soft); font-weight: 700; white-space: nowrap; }
.doc tbody tr:last-child td { border-bottom: 0; }
.doc td code { white-space: nowrap; }

/* 콜아웃 */
.callout {
  display: flex; gap: 12px; margin: 0 0 20px;
  padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); border-left-width: 3px;
  background: var(--bg-soft); font-size: 15px;
}
.callout-icon { flex: 0 0 auto; font-size: 16px; line-height: 1.55; }
.callout-body { min-width: 0; flex: 1; }
.callout-title { font-weight: 700; margin-bottom: 3px; }
.callout-body > :last-child { margin-bottom: 0; }
.callout.note    { border-left-color: #3b82f6; }
.callout.tip     { border-left-color: var(--accent); background: var(--accent-soft); }
.callout.warning { border-left-color: #e0a03a; }
.callout.danger  { border-left-color: #e05a4e; }

/* 카드 그리드 */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 14px; margin: 0 0 24px; }
.card {
  display: block; padding: 16px 18px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
  color: var(--text); transition: border-color .15s, box-shadow .15s, transform .15s;
}
.card:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.card-title { font-weight: 700; margin-bottom: 4px; font-size: 15.5px; }
.card-desc { font-size: 13.6px; color: var(--text-soft); line-height: 1.6; }

/* ---------- 이전/다음 ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 780px; margin: 56px 0 0; }
.pager a {
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.pager a:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow-sm); }
.pager .dir { font-size: 12.5px; color: var(--text-faint); }
.pager .ttl { font-weight: 650; font-size: 15px; }
.pager .next { text-align: right; grid-column: 2; }

.doc-foot { max-width: 780px; margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--text-faint); display: flex; flex-wrap: wrap; gap: 14px; justify-content: space-between; }
.doc-foot .brand-link, .doc-foot .brand-link:hover { color: #16a34a; font-weight: 700; }

/* ---------- 우측 목차 ---------- */
.toc { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 44px 22px 60px 6px; }
.toc-title { font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-faint); margin: 0 0 10px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc li a {
  display: block; padding: 4px 0 4px 12px; margin-left: -1px;
  border-left: 2px solid transparent;
  font-size: 13.4px; line-height: 1.55; color: var(--text-faint);
}
.toc li a:hover { color: var(--text); text-decoration: none; }
.toc li a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.toc li.lv3 a { padding-left: 24px; font-size: 13px; }
.toc.empty { display: none; }

/* ---------- 검색 모달 ---------- */
.search-modal { position: fixed; inset: 0; z-index: 100; display: flex; justify-content: center; padding: 84px 16px 24px; }
.search-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 20, .55); backdrop-filter: blur(3px); }
.search-panel {
  position: relative; width: 100%; max-width: 660px; max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.search-field { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--border); }
.search-field svg { color: var(--text-faint); flex: 0 0 auto; }
.search-field input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none;
  font-family: inherit; font-size: 16px; color: var(--text);
}
.search-field input::placeholder { color: var(--text-faint); }
.search-results { overflow-y: auto; padding: 8px; flex: 1; }
.search-empty { padding: 34px 16px; text-align: center; color: var(--text-faint); font-size: 14.5px; }
.sr-item { display: block; padding: 10px 12px; border-radius: 9px; color: var(--text); }
.sr-item:hover, .sr-item.sel { background: var(--bg-sunken); text-decoration: none; }
.sr-item.sel { outline: 1px solid var(--accent); }
.sr-crumb { font-size: 12px; color: var(--text-faint); margin-bottom: 2px; }
.sr-title { font-weight: 650; font-size: 15px; }
.sr-snippet { font-size: 13.3px; color: var(--text-soft); margin-top: 2px; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sr-item mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-hint { display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-faint); background: var(--bg-soft); }
.search-hint span { display: flex; align-items: center; gap: 5px; }

/* ---------- 홈 히어로 ---------- */
.hero { padding: 6px 0 8px; }
.hero h1 { font-size: 42px; letter-spacing: -.03em; margin-bottom: 14px; }
.hero .lead { font-size: 19px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 40px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 18px; border-radius: 9px; font-weight: 650; font-size: 15px;
  border: 1px solid var(--border-strong); color: var(--text); background: var(--surface);
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }

/* ---------- 반응형 ---------- */
@media (max-width: 1240px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
  .content { padding: 40px 44px 90px; }
}

@media (max-width: 940px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: grid; }
  .brand-text em { display: none; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 50;
    width: min(86vw, var(--sidebar-w));
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: none; }
  .content { padding: 30px 22px 80px; }
  .doc h1 { font-size: 28px; }
  .hero h1 { font-size: 32px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .search-trigger kbd { display: none; }
  .search-modal { padding-top: 60px; }
}

@media (max-width: 520px) {
  body { font-size: 15.5px; }
  .search-trigger span { display: none; }
  .search-trigger { flex: 0 0 auto; max-width: none; width: 38px; padding: 0; justify-content: center; }
  .topbar { gap: 8px; padding: 0 12px; }
}

@media print {
  .topbar, .sidebar, .toc, .pager, .search-modal, .reading-progress, .scrim { display: none !important; }
  .layout { display: block; padding: 0; }
  .content { padding: 0; }
}

/* ---------- 그림(공식 문서 이미지 인용) ---------- */
.doc .fig { margin: 0 0 24px; }
.doc .fig img {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-soft);
}
.doc .fig figcaption {
  margin-top: 8px; font-size: 13.2px; line-height: 1.6; color: var(--text-faint);
  padding-left: 2px;
}
.doc .fig figcaption p { margin: 0; }
.doc .fig figcaption a { color: var(--text-soft); }

.doc .fig.logo img { border: 0; background: none; max-width: 340px; }
