/* ---------- Theme tokens ---------- */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f7;
  --text: #1c1c1e;
  --text-soft: #5b5b60;
  --border: #e6e6e8;
  --link: #1a95e0;
  --accent: #F97316;
  --link-soft: #eef1ff;
  --code-bg: #f5f5f6;
  --inline-code: #f2f1ef;
  --quote-bar: #d8d8db;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Charter", "Iowan Old Style", "Georgia", "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #11141b;
  --bg-soft: #1a1a1c;
  --text: #e8e8ea;
  --text-soft: #9a9aa0;
  --border: #2a2a2d;
  --link: #1a95e0;
  --accent: #F97316;
  --link-soft: #1c2440;
  --code-bg: #1c1c1f;
  --inline-code: #171616;
  --quote-bar: #3a3a3d;
  --shadow: 0 1px 2px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141b;
    --bg-soft: #1a1a1c;
    --text: #e8e8ea;
    --text-soft: #9a9aa0;
    --border: #2a2a2d;
    --link: #1a95e0;
    --accent: #F97316;
    --link-soft: #1c2440;
    --code-bg: #1c1c1f;
    --quote-bar: #3a3a3d;
  }
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 25px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .15s ease, color .15s ease;
}

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

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.1rem 1.5rem;
  font-family: var(--font-sans);
}
.site-header .brand { font-weight: 600; color: var(--text); }
.site-header .brand-name { font-size: .95rem; }
.site-header .sep { color: var(--border); }
.site-header .brand:hover,
.site-header .brand-name:hover {
    color: var(--accent);
    text-decoration: underline;
}
.theme-toggle {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-soft);
}
.theme-toggle:hover { background: var(--bg-soft); }
.theme-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.6; }
#icon-sun circle { fill: currentColor; stroke: none; }
#icon-moon { display: none; fill: currentColor; }
[data-theme="dark"] #icon-sun { display: none; }
[data-theme="dark"] #icon-moon { display: block; }

/* ---------- Layout: TOC | content ---------- */
.layout {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(180px, 22%) minmax(0, 0.95fr);
  gap: 3.5rem;
  padding: 0 1.5rem 5rem;
}
.toc-wrap { min-width: 0; margin-top: 10px; }
.toc-spacer { display: none; }
.toc {
  position: sticky;
  top: 2.5rem;
  font-size: .82rem;
  font-family: var(--font-sans);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  padding: 1rem 1.1rem;
}
.toc-title {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: .68rem;
  color: var(--text-soft);
  margin: 0 0 .7rem;
}
#toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: toc-counter;
}
#toc-list > li:not(.toc-h3) { counter-increment: toc-counter; }
#toc-list > li:not(.toc-h3) > a::before {
  content: counter(toc-counter) ". ";
  color: var(--text-soft);
}
#toc-list a {
  display: block;
  color: var(--text-soft);
  padding: .2rem 0;
  line-height: 1.45;
}
#toc-list a:hover { color: var(--accent); text-decoration: none; }
#toc-list a.active {
  color: var(--link);
  font-weight: 700;
}
#toc-list .toc-h3 a { padding-left: 1.1rem; font-size: .8rem; }
#toc-list .toc-h3 a::before { content: ""; }

.article { min-width: 0; }
.loading { color: var(--text-soft); padding: 3rem 0; }

/* ---------- Article header ---------- */
.back-link {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: .85rem;
  color: var(--text-soft);
  margin-bottom: 2rem;
}
.back-link:hover { color: var(--accent); text-decoration: none; }

.article-header { margin-bottom: 3rem; }
.article-header h1 {
  font-size: 2.1rem;
  line-height: 1.25;
  margin: 0 0 1rem;
  font-weight: 700;
  letter-spacing: -.015em;
}
.article-description {
  color: var(--text-soft);
  font-size: 1.1rem;
  margin: 0 0 1.2rem;
  /* font-style: italic; */
}
.article-meta {
  font-family: var(--font-sans);
  font-size: .82rem;
  color: var(--text-soft);
  letter-spacing: .01em;
}
.article-meta .dot { margin: 0 .5rem; }

/* ---------- Markdown body ---------- */
.markdown-body h2 {
  font-size: 1.5rem;
  margin: 2.6rem 0 .9rem;
  font-weight: 700;
  scroll-margin-top: 1.5rem;
}
.markdown-body h3 {
  font-size: 1.2rem;
  margin: 2rem 0 .7rem;
  font-weight: 700;
  scroll-margin-top: 1.5rem;
}
.markdown-body h4 {
  font-size: 1.05rem;
  margin: 1.5rem 0 .5rem;
  font-weight: 700;
}
.markdown-body p { margin: .9rem 0; }
.markdown-body ul, .markdown-body ol { margin: .9rem 0; padding-left: 1.4rem; }
.markdown-body li { margin: .35rem 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: .35rem 0; }

.markdown-body img {
  /* max-width: 50%; */
  border-radius: 8px;
  display: block;
  margin: 1.2rem auto;
}
.markdown-body figcaption {
  text-align: center;
  font-size: .82rem;
  color: var(--text-soft);
  margin-top: -.6rem;
}

.markdown-body blockquote {
  margin: 1.5rem 0;
  padding: .75rem 1rem;
  background: rgba(245, 158, 11, 0.14); /* Amber */
  border-left: 4px solid #f59e0b;
  border-radius: 6px;
  color: var(--text-soft);
  font-size: .95em;
}
.markdown-body blockquote::before {
  content: "NOTE";
  display: block;
  font-family: var(--font-sans);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: #f57c0b;
  margin-bottom: .4rem;
}
.markdown-body blockquote p { margin: 0; }
.markdown-body blockquote p + p { margin-top: .5rem; }

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.markdown-body code:not(pre code) {
  font-family: var(--font-mono);
  font-size: .83em;
  font-weight: 600;
  background: var(--inline-code);
  color: #ed6363;
  padding: .15em .45em;
  border-radius: 5px;
}


/* Code block wrapper */
.code-block {
  margin: 1.6rem 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e8ddd0;
  background: #fdf8f2;
  font-size: .85rem;
}

/* Header */
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem .9rem;
  background: #f5ede2;
  border-bottom: 1px solid #e8ddd0;
}

/* Language label */
.code-lang {
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 500;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* Copy button */
.copy-btn {
  font-family: var(--font-sans);
  font-size: .7rem;
  font-weight: 500;
  color: var(--text-soft);
  background: none;
  border: 1px solid #d0d7de;
  border-radius: 5px;
  padding: .18rem .5rem;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.copy-btn:hover {
  color: var(--text);
  border-color: var(--text-soft);
  background: #ede3d8;
}

/* Code body */
.code-block pre {
  margin: 0;
  padding: 1.1rem 1rem;
  overflow-x: auto;
  background: transparent;
  border: none;
  border-radius: 0;
  line-height: 1.65;
}
.code-block pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: .84rem;
  font-family: var(--font-mono);
  font-weight: 500;
  /* no color here — hljs owns it */
}

/* Dark mode */
[data-theme="dark"] .code-block {
  background: #0d1117;
  border-color: #30363d;
}
[data-theme="dark"] .code-header {
  background: #161b22;
  border-color: #30363d;
}
[data-theme="dark"] .copy-btn {
  border-color: #30363d;
}
[data-theme="dark"] .copy-btn:hover {
  background: #21262d;
  border-color: #8b949e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .code-block { background: #0e1117; border-color: #30363d; }
  :root:not([data-theme="light"]) .code-header { background: #161b22; border-color: #30363d; }
  :root:not([data-theme="light"]) .copy-btn { border-color: #26292c; }
}

/* KaTeX display math centering */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: .5rem 0;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.2rem 0;
  font-size: .9rem;
  display: block;
  overflow-x: auto;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: .5rem .75rem;
  text-align: left;
}
.markdown-body th { background: var(--bg-soft); font-weight: 600; }

.markdown-body input[type="checkbox"] { margin-right: .5em; }
.markdown-body del { color: var(--text-soft); }

.markdown-body a { word-break: break-word; }


/* ---------- Back to Top ---------- */
#back-to-top {
  position: fixed;
  right: 1.8rem;
  bottom: 1.8rem;

  width: 42px;
  height: 42px;

  display: flex;
  align-items: center;
  justify-content: center;

  border: 1px solid var(--border);
  border-radius: 999px;

  background: var(--text); 
  color: var(--bg);  

  cursor: pointer;

  box-shadow: var(--shadow);

  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);

  transition:
    opacity .2s ease,
    transform .2s ease,
    color .2s ease,
    border-color .2s ease,
    background .2s ease;

  z-index: 999;
}

#back-to-top.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

#back-to-top:hover {
  color: var(--accent);
}

#back-to-top svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 760px) {
  #back-to-top {
    width: 38px;
    height: 38px;
    right: 1rem;
    bottom: 1rem;
  }

  #back-to-top svg {
    width: 16px;
    height: 16px;
  }
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 2rem 1.5rem 3rem;
  color: var(--text-soft);
  font-size: .82rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .toc-wrap { display: none; }
}
@media (max-width: 560px) {
  body { margin: 12px; }
  .site-header { padding: 1.1rem 1rem; gap: 0.35rem; }
  .site-header .brand {font-size: 15px; }
  .site-header .brand-name {font-size: 14.5px; }
  .layout { padding: 0 1rem 3rem; }
  .article-header h1 { font-size: 1.7rem; }
  .markdown-body h2 { font-size: 1.35rem; }
  .markdown-body h3 { font-size: 1.1rem; }
  .markdown-body h4 { font-size: 1rem; }
  .code-block { border-radius: 8px; }
  .code-block pre { padding: .9rem .85rem; }
  .code-lang { font-size: .68rem; }
  .copy-btn { font-size: .67rem; padding: .15rem .4rem; }
  /* .layout { padding: 0 1.1rem 3rem; gap: 1.5rem; } */
}