:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #59636e;
  --border: #d1d9e0;
  --link: #0969da;
  --accent-bg: #f6f8fa;
  --bar-bg: rgba(255, 255, 255, .92);
  --max: 820px;
  --gutter: clamp(24px, 5vw, 40px);
  --tok-comment: #6e7781;
  --tok-keyword: #cf222e;
  --tok-string: #0a3069;
  --tok-number: #0550ae;
  --tok-title: #8250df;
  --tok-type: #953800;
  --tok-meta: #116329;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --fg: #e6edf3;
  --muted: #9198a1;
  --border: #30363d;
  --link: #4493f8;
  --accent-bg: #161b22;
  --bar-bg: rgba(13, 17, 23, .92);
  --tok-comment: #8b949e;
  --tok-keyword: #ff7b72;
  --tok-string: #a5d6ff;
  --tok-number: #79c0ff;
  --tok-title: #d2a8ff;
  --tok-type: #ffa657;
  --tok-meta: #7ee787;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #9198a1;
    --border: #30363d;
    --link: #4493f8;
    --accent-bg: #161b22;
    --bar-bg: rgba(13, 17, 23, .92);
    --tok-comment: #8b949e;
    --tok-keyword: #ff7b72;
    --tok-string: #a5d6ff;
    --tok-number: #79c0ff;
    --tok-title: #d2a8ff;
    --tok-type: #ffa657;
    --tok-meta: #7ee787;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 64px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", Helvetica, Arial, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding-inline: var(--gutter); }

/* headers */
.site-head { border-bottom: 1px solid var(--border); padding: clamp(28px, 6vw, 44px) 0 clamp(20px, 4vw, 28px); }
.site-head h1 { margin: 8px 0 6px; font-size: clamp(22px, 5vw, 28px); line-height: 1.25; }
.site-head .desc { margin: 0; color: var(--muted); max-width: 60ch; }
.site-head a.back { font-size: 13px; color: var(--muted); }
.site-head a.back:hover { color: var(--link); }

/* lists (studies + articles share styling) */
.studies { padding: clamp(16px, 4vw, 24px) 0 64px; }
.study-list, .article-list { list-style: none; margin: 0; padding: 0; }
.study-item, .article-item {
  padding: clamp(14px, 3.5vw, 18px) clamp(16px, 4vw, 20px);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.study-item:hover, .article-item:hover {
  border-color: var(--link);
  background: var(--accent-bg);
  box-shadow: 0 1px 3px rgba(31, 35, 40, .08);
}
.study-item a.title, .article-item a.title {
  font-size: clamp(15px, 4vw, 17px);
  font-weight: 600;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.study-item .meta, .article-item .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.study-item .summary, .article-item .summary {
  color: var(--fg);
  font-size: 14px;
  margin-top: 6px;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.empty-study { color: var(--muted); font-size: 14px; font-style: italic; list-style: none; }

/* sub-articles nested inside an article card */
.subarticle-list { list-style: none; margin: 12px 0 2px; padding-left: 14px; border-left: 2px solid var(--border); }
.subarticle-item { margin-top: 8px; }
.subarticle-item:first-child { margin-top: 0; }
.subarticle-item a { font-size: 14px; font-weight: 500; word-break: keep-all; overflow-wrap: anywhere; }
.subarticle-item .sub-summary { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; word-break: keep-all; overflow-wrap: anywhere; }

.foot { color: var(--muted); font-size: 13px; padding: 24px 0 48px; border-top: 1px solid var(--border); }

/* article viewer */
.viewer-bar { position: sticky; top: 0; z-index: 5; background: var(--bar-bg); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); }
.viewer-bar .wrap { display: flex; align-items: center; gap: 8px; min-width: 0; height: 52px; }
.viewer-bar a.back { font-size: 14px; white-space: nowrap; }
.viewer-bar .sep { color: var(--muted); flex: none; }
.viewer-bar #study-link { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-wrap { padding: clamp(20px, 5vw, 32px) 0 80px; }

/* zero-md renders github-markdown-css in shadow DOM (responsive images + scrollable code already) */
zero-md { display: block; }

/* theme toggle: fixed floating badge, consistent on every page */
.theme-toggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 50;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
.theme-toggle:hover { background: var(--accent-bg); border-color: var(--link); }

@media (max-width: 600px) {
  .study-item, .article-item { margin-bottom: 10px; }
  .foot { padding: 20px 0 40px; }
}
