/* ---------- Theme tokens ---------- */
:root {
  --bg: #fdfdfc;
  --bg-panel: #f4f4f2;
  --bg-code: #f4f4f2;
  --text: #1c1e21;
  --text-muted: #6b7075;
  --link: #0b63c5;
  --link-visited: #0b63c5;
  --border: #e2e2df;
  --accent: #0b63c5;
  --tag-bg: #eef2f6;
  --tag-text: #45505c;
  --mark-bg: #fff3bf;

  --font-serif: "Source Serif 4", "Charter", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --measure: 60rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c;
    --bg-panel: #1e2126;
    --bg-code: #1e2126;
    --text: #d9dce1;
    --text-muted: #8b929b;
    --link: #6cb0f5;
    --link-visited: #6cb0f5;
    --border: #2b2f36;
    --accent: #6cb0f5;
    --tag-bg: #242a32;
    --tag-text: #a5adb8;
    --mark-bg: #4d431a;
  }
}

:root[data-theme="dark"] {
  --bg: #16181c;
  --bg-panel: #1e2126;
  --bg-code: #1e2126;
  --text: #d9dce1;
  --text-muted: #8b929b;
  --link: #6cb0f5;
  --link-visited: #6cb0f5;
  --border: #2b2f36;
  --accent: #6cb0f5;
  --tag-bg: #242a32;
  --tag-text: #a5adb8;
  --mark-bg: #4d431a;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.72;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga";
}

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

::selection { background: var(--accent); color: var(--bg); }

/* ---------- Header / footer chrome ---------- */
.site-header {
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
}

.site-nav {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.site-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.site-title:hover { text-decoration: none; color: var(--accent); }

.site-links {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;
  font-size: 0.92rem;
}
.site-links a { color: var(--text-muted); }
.site-links a:hover { color: var(--accent); text-decoration: none; }

#theme-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 0.15rem;
  line-height: 1;
}
#theme-toggle:hover { color: var(--accent); }

.site-main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.25rem 1.25rem 3rem;
}

.site-footer {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--accent); }

/* ---------- Home ---------- */
.home-intro {
  color: var(--text-muted);
  font-size: 1.02rem;
  margin-bottom: 2.5rem;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-list li {
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
}

.post-list-meta {
  display: flex;
  gap: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.post-list-title {
  margin: 0.35rem 0 0.4rem;
  font-size: 1.35rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.post-list-title a { color: var(--text); }
.post-list-title a:hover { color: var(--accent); text-decoration: none; }

.post-list-excerpt {
  margin: 0 0 0.6rem;
  color: var(--text-muted);
  font-size: 0.98rem;
}

/* ---------- Tags ---------- */
.post-tags { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; }

.tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 0.12rem 0.5rem;
  border-radius: 99px;
}
a.tag:hover { color: var(--accent); text-decoration: none; }

/* ---------- Tags page ---------- */
.tags-page ul { list-style: none; padding-left: 0; }
.tags-page li { display: flex; justify-content: space-between; gap: 1rem; }
.tags-page-date {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---------- Post ---------- */
.post-header { margin-bottom: 1.75rem; }

.post-title {
  font-size: 1.9rem;
  line-height: 1.22;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
}

.post-meta {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------- Table of contents ---------- */
.toc {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin: 0 0 2rem;
}
.toc summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}
.toc ul { margin: 0.6rem 0 0.2rem; padding-left: 1.1rem; }
.toc li { margin: 0.3rem 0; list-style: none; }
.toc li::before { content: "–"; color: var(--text-muted); margin-right: 0.5rem; margin-left: -1.1rem; }
.toc .toc-h3 { padding-left: 1.1rem; }
.toc a { color: var(--text); }
.toc a:hover { color: var(--accent); }

/* ---------- Article content ---------- */
.post-content h2,
.post-content h3,
.post-content h4 {
  font-family: var(--font-sans);
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin: 2.4rem 0 0.8rem;
  scroll-margin-top: 1.5rem;
  position: relative;
}
.post-content h2 { font-size: 1.45rem; }
.post-content h3 { font-size: 1.15rem; }
.post-content h4 { font-size: 1rem; }

.heading-anchor {
  margin-left: 0.45rem;
  color: var(--text-muted);
  opacity: 0;
  font-weight: 400;
  transition: opacity 0.12s;
}
.post-content h2:hover .heading-anchor,
.post-content h3:hover .heading-anchor { opacity: 1; }
.heading-anchor:hover { color: var(--accent); text-decoration: none; }

.post-content p { margin: 0 0 1.15rem; }

.post-content strong { font-weight: 600; }

.post-content ul, .post-content ol { padding-left: 1.4rem; margin: 0 0 1.15rem; }
.post-content li { margin: 0.35rem 0; }
.post-content li > p { margin-bottom: 0.5rem; }

.post-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem auto;
  width: 40%;
}

.post-content blockquote {
  margin: 1.5rem 0;
  padding: 0.6rem 1.2rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-panel);
  border-radius: 0 8px 8px 0;
  color: var(--text);
  font-style: italic;
}
.post-content blockquote p:last-child { margin-bottom: 0; }

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
  margin: 1.5rem auto;
}

.post-content figcaption,
.post-content em.caption {
  display: block;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: -0.9rem;
  margin-bottom: 1.5rem;
}

mark { background: var(--mark-bg); color: inherit; padding: 0 0.15em; }

/* ---------- Code ---------- */
code {
  font-family: var(--font-mono);
  font-size: 0.84em;
}

/* inline code */
p code, li code, td code, h2 code, h3 code, a code, blockquote code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.08em 0.35em;
  white-space: nowrap;
}

/* block code — also carries the ASCII diagrams, so: no wrap, scroll */
div.highlighter-rouge, figure.highlight, .post-content > pre {
  margin: 1.4rem 0;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  line-height: 1.55;
  margin: 0;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
  font-size: 0.82rem;
}

/* ---------- Tables ---------- */
.post-content table {
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.45;
  display: block;
  overflow-x: auto;
  max-width: 100%;
  font-variant-numeric: tabular-nums;
}

.post-content th, .post-content td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.post-content thead th {
  background: var(--bg-panel);
  font-weight: 600;
  white-space: nowrap;
}

.post-content tbody tr:nth-child(even) { background: color-mix(in srgb, var(--bg-panel) 45%, var(--bg)); }

.post-content td code, .post-content th code { white-space: nowrap; }

/* ---------- Post navigation ---------- */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.post-nav a { max-width: 46%; }
.post-nav-next { text-align: right; margin-left: auto; }

/* ---------- Syntax highlighting (Rouge) ---------- */
/* light */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: #767b82; font-style: italic; }
.highlight .k, .highlight .kn, .highlight .kd, .highlight .kc, .highlight .kt, .highlight .ow { color: #a626a4; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sd, .highlight .sh { color: #2e7d32; }
.highlight .se, .highlight .si { color: #b26a00; }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh, .highlight .mo { color: #b25c00; }
.highlight .nf, .highlight .fm { color: #2f6fd0; }
.highlight .nc, .highlight .nn { color: #b25c00; }
.highlight .nb, .highlight .bp { color: #0d7c85; }
.highlight .nd { color: #a626a4; }
.highlight .no, .highlight .na { color: #b25c00; }
.highlight .nt { color: #c62828; }
.highlight .o, .highlight .p { color: inherit; }
.highlight .gp { color: #767b82; }
.highlight .go { color: #565b61; }
.highlight .err { color: inherit; background: none; }

/* dark */
:root[data-theme="dark"] .highlight .c, :root[data-theme="dark"] .highlight .c1, :root[data-theme="dark"] .highlight .cm, :root[data-theme="dark"] .highlight .cs { color: #7f8792; }
:root[data-theme="dark"] .highlight .k, :root[data-theme="dark"] .highlight .kn, :root[data-theme="dark"] .highlight .kd, :root[data-theme="dark"] .highlight .kc, :root[data-theme="dark"] .highlight .kt, :root[data-theme="dark"] .highlight .ow { color: #c678dd; }
:root[data-theme="dark"] .highlight .s, :root[data-theme="dark"] .highlight .s1, :root[data-theme="dark"] .highlight .s2, :root[data-theme="dark"] .highlight .sb, :root[data-theme="dark"] .highlight .sd, :root[data-theme="dark"] .highlight .sh { color: #98c379; }
:root[data-theme="dark"] .highlight .se, :root[data-theme="dark"] .highlight .si { color: #e0af68; }
:root[data-theme="dark"] .highlight .m, :root[data-theme="dark"] .highlight .mi, :root[data-theme="dark"] .highlight .mf, :root[data-theme="dark"] .highlight .mh, :root[data-theme="dark"] .highlight .mo { color: #d19a66; }
:root[data-theme="dark"] .highlight .nf, :root[data-theme="dark"] .highlight .fm { color: #61afef; }
:root[data-theme="dark"] .highlight .nc, :root[data-theme="dark"] .highlight .nn { color: #e5c07b; }
:root[data-theme="dark"] .highlight .nb, :root[data-theme="dark"] .highlight .bp { color: #56b6c2; }
:root[data-theme="dark"] .highlight .nd { color: #c678dd; }
:root[data-theme="dark"] .highlight .no, :root[data-theme="dark"] .highlight .na { color: #d19a66; }
:root[data-theme="dark"] .highlight .nt { color: #e06c75; }
:root[data-theme="dark"] .highlight .gp { color: #7f8792; }
:root[data-theme="dark"] .highlight .go { color: #9aa1aa; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .highlight .c, :root:not([data-theme="light"]) .highlight .c1, :root:not([data-theme="light"]) .highlight .cm, :root:not([data-theme="light"]) .highlight .cs { color: #7f8792; }
  :root:not([data-theme="light"]) .highlight .k, :root:not([data-theme="light"]) .highlight .kn, :root:not([data-theme="light"]) .highlight .kd, :root:not([data-theme="light"]) .highlight .kc, :root:not([data-theme="light"]) .highlight .kt, :root:not([data-theme="light"]) .highlight .ow { color: #c678dd; }
  :root:not([data-theme="light"]) .highlight .s, :root:not([data-theme="light"]) .highlight .s1, :root:not([data-theme="light"]) .highlight .s2, :root:not([data-theme="light"]) .highlight .sb, :root:not([data-theme="light"]) .highlight .sd, :root:not([data-theme="light"]) .highlight .sh { color: #98c379; }
  :root:not([data-theme="light"]) .highlight .se, :root:not([data-theme="light"]) .highlight .si { color: #e0af68; }
  :root:not([data-theme="light"]) .highlight .m, :root:not([data-theme="light"]) .highlight .mi, :root:not([data-theme="light"]) .highlight .mf, :root:not([data-theme="light"]) .highlight .mh, :root:not([data-theme="light"]) .highlight .mo { color: #d19a66; }
  :root:not([data-theme="light"]) .highlight .nf, :root:not([data-theme="light"]) .highlight .fm { color: #61afef; }
  :root:not([data-theme="light"]) .highlight .nc, :root:not([data-theme="light"]) .highlight .nn { color: #e5c07b; }
  :root:not([data-theme="light"]) .highlight .nb, :root:not([data-theme="light"]) .highlight .bp { color: #56b6c2; }
  :root:not([data-theme="light"]) .highlight .nd { color: #c678dd; }
  :root:not([data-theme="light"]) .highlight .no, :root:not([data-theme="light"]) .highlight .na { color: #d19a66; }
  :root:not([data-theme="light"]) .highlight .nt { color: #e06c75; }
  :root:not([data-theme="light"]) .highlight .gp { color: #7f8792; }
  :root:not([data-theme="light"]) .highlight .go { color: #9aa1aa; }
}

/* ---------- Small screens ---------- */
@media (max-width: 600px) {
  body { font-size: 1rem; }
  .post-title { font-size: 1.55rem; }
  .site-nav { flex-wrap: wrap; }
  .site-main { padding-top: 1.5rem; }
}

/* figures: click to zoom */
.post-content svg[role="img"] { cursor: zoom-in; }
.svg-lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); cursor: zoom-out; padding: 1.5vh 1.5vw;
}
.svg-lightbox svg { width: 97vw; height: 96vh; }

/* private review mode (only active with ?review=on) */
.rv-badge {
  position: fixed; right: 14px; bottom: 14px; z-index: 900;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem 0.7rem; font-family: var(--font-sans); font-size: 0.8rem;
  color: var(--text-muted); box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.rv-badge button, .rv-item button {
  margin-left: 0.35rem; font-size: 0.75rem; cursor: pointer;
  background: none; border: 1px solid var(--border); border-radius: 5px;
  color: var(--text-muted); padding: 0.1rem 0.4rem;
}
.rv-badge button:hover, .rv-item button:hover { color: var(--accent); border-color: var(--accent); }
.rv-chip {
  position: absolute; z-index: 901; cursor: pointer;
  background: var(--accent); color: var(--bg); border: none; border-radius: 6px;
  padding: 0.2rem 0.55rem; font-size: 0.8rem; font-family: var(--font-sans);
}
.rv-list {
  position: fixed; right: 14px; bottom: 60px; z-index: 900;
  width: min(340px, 90vw); max-height: 60vh; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.7rem; font-family: var(--font-sans); font-size: 0.82rem; color: var(--text);
}
.rv-item { border-bottom: 1px solid var(--border); padding: 0.45rem 0; }
.rv-item blockquote { margin: 0 0 0.25rem; padding-left: 0.5rem; border-left: 2px solid var(--accent); color: var(--text-muted); font-style: italic; }
.rv-item p { margin: 0 0 0.3rem; }
