:root {
  --bg: #fdfdfb;
  --fg: #1d1d1b;
  --muted: #6a6a64;
  --line: #e4e3dc;
  --accent: #0b5cad;
  --accent-fg: #fff;
  --code-bg: #f3f2ec;
  --danger: #b3261e;
  --ok: #1b6e3c;
  --measure: 42rem;
  --font: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #e8e7e1;
    --muted: #9a9990;
    --line: #2f2f2c;
    --accent: #6fb1f2;
    --accent-fg: #0b1824;
    --code-bg: #20201e;
    --danger: #f2877f;
    --ok: #7fd49c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1.125rem/1.65 var(--font);
}
a { color: var(--accent); text-underline-offset: 0.15em; }
.wrap { width: 100%; max-width: var(--measure); margin: 0 auto; padding: 0 1rem; }
.wrap.wide { max-width: 90rem; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 0.5rem; top: 0.5rem; background: var(--bg); padding: 0.4rem 0.6rem; z-index: 10; }

.site-header { border-bottom: 1px solid var(--line); font-family: var(--font-ui); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 0.9rem; padding-bottom: 0.9rem; }
.brand { display: flex; align-items: center; gap: 0.8rem; min-width: 0; flex: 1; }
.site-title { flex: none; font-weight: 650; font-size: 1.1rem; color: var(--fg); text-decoration: none; }
.site-desc {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); opacity: 0.8; font-size: 0.78rem; line-height: 1.3;
  padding-left: 0.8rem; border-left: 1px solid var(--line);
}
.site-header nav { flex: none; display: flex; gap: 1rem; align-items: center; font-size: 0.95rem; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--fg); }
@media (max-width: 38rem) {
  .site-header .wrap { flex-wrap: wrap; }
  .brand { flex-wrap: wrap; gap: 0.2rem 0.9rem; }
  .site-desc { flex-basis: 100%; padding-left: 0; border-left: 0; white-space: normal; }
}
main.wrap { padding-top: 1.5rem; padding-bottom: 3rem; }

h1, h2, h3, h4 { line-height: 1.25; font-family: var(--font-ui); }
h1 { font-size: 2rem; margin: 0.4em 0 0.3em; letter-spacing: -0.01em; }
.h1-small { font-size: 1.5rem; }
.lede { color: var(--muted); font-size: 1.1rem; margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* index */
.post-list { list-style: none; padding: 0; margin: 0 0 2rem; }
.post-list li { display: grid; grid-template-columns: 11rem 1fr; gap: 1.1rem; align-items: start; padding: 1.1rem 0; border-top: 1px solid var(--line); }
.thumb img, .hero { display: block; width: 100%; height: auto; aspect-ratio: 1200 / 630; object-fit: cover; border-radius: 6px; background: var(--code-bg); }
.hero { margin: 0 0 1.8rem; }
@media (max-width: 36rem) { .post-list li { grid-template-columns: 1fr; gap: 0.7rem; } }
.post-list li:first-child { border-top: 0; }
.post-link { font: 650 1.35rem/1.3 var(--font-ui); color: var(--fg); text-decoration: none; }
.post-link:hover { color: var(--accent); }
.post-list time { display: block; color: var(--muted); font: 0.85rem var(--font-ui); margin-top: 0.15rem; }
.post-list p { margin: 0.4rem 0 0; color: var(--muted); }

/* post */
.post-header h1 { font-size: 2.2rem; margin-bottom: 0.2em; }
.post-meta { color: var(--muted); font: 0.9rem var(--font-ui); margin: 0 0 1.4rem; }
.back { margin-top: 3rem; font-family: var(--font-ui); font-size: 0.95rem; }

.post-body { overflow-wrap: anywhere; }
.post-body > :first-child { margin-top: 0; }
.post-body h2 { font-size: 1.5rem; margin: 2.2em 0 0.5em; }
.post-body h3 { font-size: 1.2rem; margin: 1.8em 0 0.4em; }
.post-body img { max-width: 100%; height: auto; border-radius: 4px; }
.post-body p:has(> img:only-child), .post-body p:has(> a:only-child > img:only-child) { text-align: center; }
.post-body blockquote { margin: 1.4em 0; padding: 0.1em 1.1em; border-left: 3px solid var(--line); color: var(--muted); }
.post-body hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }
.post-body code { font: 0.88em var(--mono); background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; }
.post-body pre { background: var(--code-bg); padding: 0.9rem 1rem; border-radius: 6px; overflow-x: auto; line-height: 1.45; }
.post-body pre code { padding: 0; background: none; font-size: 0.85rem; }
.post-body sup.footnote-ref { line-height: 0; }
.post-body sup.footnote-ref a { text-decoration: none; padding: 0 0.1em; font: 600 0.75em var(--font-ui); }
.post-body hr.footnotes-sep { margin: 2.5em 0 1em; }
.footnotes { font-size: 0.9em; color: var(--muted); }
.footnotes-list { padding-left: 1.4em; margin: 0; }
.footnotes li { padding: 0.15em 0.4em; border-radius: 4px; }
.footnotes li:target { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.footnotes p { margin: 0.2em 0; }
.footnote-backref { text-decoration: none; margin-left: 0.2em; }
.post-body table { border-collapse: collapse; display: block; overflow-x: auto; }
.post-body th, .post-body td { border: 1px solid var(--line); padding: 0.35em 0.7em; }

/* highlight.js tokens */
.hljs-comment, .hljs-quote { color: var(--muted); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag { color: #b42a8e; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #1d7a3a; }
.hljs-number, .hljs-built_in, .hljs-type, .hljs-attr, .hljs-attribute { color: #0b64a8; }
.hljs-title, .hljs-section, .hljs-name, .hljs-selector-id, .hljs-selector-class { color: #8a5a00; }
.hljs-variable, .hljs-template-variable, .hljs-symbol, .hljs-bullet { color: #a63a1d; }
.hljs-deletion { color: #b3261e; }
.hljs-meta { color: var(--muted); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
@media (prefers-color-scheme: dark) {
  .hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag { color: #f08ad2; }
  .hljs-string, .hljs-regexp, .hljs-addition { color: #8fd7a1; }
  .hljs-number, .hljs-built_in, .hljs-type, .hljs-attr, .hljs-attribute { color: #7cc0f5; }
  .hljs-title, .hljs-section, .hljs-name, .hljs-selector-id, .hljs-selector-class { color: #e5b567; }
  .hljs-variable, .hljs-template-variable, .hljs-symbol, .hljs-bullet { color: #f0997f; }
  .hljs-deletion { color: #f2877f; }
}

/* history */
.history { list-style: none; padding: 0; margin: 1.5rem 0; font-family: var(--font-ui); }
.history li { border-top: 1px solid var(--line); padding: 1rem 0; }
.history time { display: block; color: var(--muted); font-size: 0.85rem; }
.commit-message { white-space: pre-wrap; font: 0.98rem/1.5 var(--font-ui); margin: 0.4rem 0 0.5rem; }
.commit-message.block { border-left: 3px solid var(--line); padding-left: 0.9rem; margin: 1rem 0 1.5rem; }

/* tracked changes ("what changed") */
.post-body ins, .rev-fields ins {
  text-decoration: none; color: var(--ok);
  background: color-mix(in srgb, var(--ok) 14%, transparent); border-radius: 2px;
}
.post-body del, .rev-fields del {
  text-decoration: line-through; text-decoration-color: var(--danger); color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent); border-radius: 2px;
}
.post-body del + ins, .rev-fields del + ins { margin-left: 0.2em; }
.rev-ins, .rev-del { margin: 1rem 0; padding: 0.1rem 0 0.1rem 1rem; border-left: 3px solid; }
.rev-ins { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); color: var(--ok); text-decoration: none; }
.rev-del { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, transparent); color: var(--danger); text-decoration: line-through; text-decoration-color: var(--danger); }
.rev-del img { opacity: 0.55; }
.rev-ins > :first-child, .rev-del > :first-child { margin-top: 0.5em; }
.rev-ins > :last-child, .rev-del > :last-child { margin-bottom: 0.5em; }
.rev-note { font: 0.9rem var(--font-ui); color: var(--muted); margin: 1.2rem 0; }
.post-body.revision { margin-top: 1.5rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.rev-fields { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; font: 0.95rem var(--font-ui); margin: 0 0 1.5rem; padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: 6px; }
.rev-fields dt { color: var(--muted); }
.rev-fields dd { margin: 0; }
.rev-thumbs { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.rev-thumbs img { height: auto; border-radius: 4px; border: 2px solid; }
.rev-thumbs img.rev-del { opacity: 0.55; border-color: var(--danger); padding: 0; margin: 0; background: none; }
.rev-thumbs img.rev-ins { border-color: var(--ok); padding: 0; margin: 0; background: none; }
.pager { display: flex; justify-content: space-between; gap: 1rem; font: 0.9rem var(--font-ui); margin-top: 2rem; }

/* shared form controls (login, admin) */
button, .button, input, textarea, select { font: 1rem var(--font-ui); }
button, .button {
  display: inline-block; cursor: pointer; text-decoration: none;
  padding: 0.5rem 0.9rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--code-bg); color: var(--fg);
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: var(--bg); }
button.link { background: none; border: 0; padding: 0; color: var(--muted); }
button:disabled { opacity: 0.55; cursor: progress; }
input, textarea {
  width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg);
}
input:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font: 0.9rem var(--font-ui); }
label > input, label > textarea { margin-top: 0.25rem; }
form.inline { display: inline; }
.error { color: var(--danger); font-family: var(--font-ui); }
