:root {
  --bg: #fdfdfc;
  --fg: #1f2328;
  --muted: #656d76;
  --line: #e4e4e0;
  --soft: #f3f3f0;
  --accent: #2557d6;
  --danger: #c42b1c;
  --card: #ffffff;
  --code-bg: #f5f5f2;
  --hl-comment: #6e7781;
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-number: #0550ae;
  --hl-title: #8250df;
  --hl-attr: #953800;
  --hl-meta: #116329;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --fg: #e6e6e3;
    --muted: #9aa0a6;
    --line: #2c2f34;
    --soft: #1f2227;
    --accent: #7aa2ff;
    --danger: #ff7b72;
    --card: #1c1f23;
    --code-bg: #1d2025;
    --hl-comment: #8b949e;
    --hl-keyword: #ff7b72;
    --hl-string: #a5d6ff;
    --hl-number: #79c0ff;
    --hl-title: #d2a8ff;
    --hl-attr: #ffa657;
    --hl-meta: #7ee787;
  }
}

/* ---------- base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.7 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
img { max-width: 100%; height: auto; }
main, header.site, footer.site { max-width: 720px; margin: 0 auto; padding: 0 16px; }
body.wide main, body.wide header.site { max-width: 1240px; }
main { padding-bottom: 64px; min-height: 60vh; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; font-weight: 400; }
.accent { color: var(--accent); }

header.site {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-top: 24px; padding-bottom: 24px; margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.2rem; color: var(--fg); text-decoration: none; }
header nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
header nav form { margin: 0; }
footer.site {
  padding-top: 24px; padding-bottom: 32px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem;
}

h1 { font-size: 2.1rem; line-height: 1.2; margin: 24px 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; line-height: 1.3; margin: 0 0 4px; }
.meta, time { color: var(--muted); font-size: 0.9rem; }
.intro { margin-bottom: 8px; }
.intro p { color: var(--muted); margin: 0; font-size: 1.05rem; }

/* ---------- post list */
.post-list { list-style: none; padding: 0; margin: 0; }
.post-list > li {
  display: grid; grid-template-columns: 1fr; gap: 16px;
  padding: 24px 0; border-bottom: 1px solid var(--line);
}
.post-list > li:has(.thumb) { grid-template-columns: 1fr 200px; }
.post-list .thumb { order: 2; }
.post-list .thumb img {
  display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover;
  border-radius: 10px; background: var(--soft);
}
.post-list h2 a { color: var(--fg); text-decoration: none; }
.post-list h2 a:hover { color: var(--accent); }
.post-list .meta { margin: 0; }
.post-list p:last-child { margin: 8px 0 0; }
.pager { display: flex; justify-content: space-between; margin-top: 24px; }

/* ---------- article */
.post-head .meta { margin: 0 0 24px; }
.cover { margin: 0 0 32px; }
.cover img { display: block; width: 100%; border-radius: 12px; background: var(--soft); }

.prose { overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose table { margin: 0 0 1.2em; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.3; margin: 1.8em 0 0.6em; scroll-margin-top: 16px; }
.prose h2 { font-size: 1.5rem; }
.prose h3 { font-size: 1.2rem; }
.prose img { display: block; margin: 0 auto; border-radius: 10px; }
.prose blockquote { padding: 2px 0 2px 18px; border-left: 3px solid var(--line); color: var(--muted); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose li + li { margin-top: 0.3em; }
.prose .task-list-item { list-style: none; margin-left: -1.4em; }
.prose table { display: block; overflow-x: auto; border-collapse: collapse; }
.prose th, .prose td { padding: 6px 12px; border: 1px solid var(--line); }
.prose th { background: var(--soft); }

code, pre { font: 0.88em/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
:not(pre) > code { padding: 0.15em 0.35em; border-radius: 5px; background: var(--code-bg); }
pre { padding: 16px; overflow-x: auto; border-radius: 10px; background: var(--code-bg); border: 1px solid var(--line); }
pre code { font-size: inherit; }

/* syntax highlighting (highlight.js classes, rendered on the server) */
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-type, .hljs-doctag { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-selector-attr, .hljs-template-tag { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable, .hljs-template-variable, .hljs-link { color: var(--hl-number); }
.hljs-title, .hljs-section, .hljs-name, .hljs-selector-id, .hljs-selector-class { color: var(--hl-title); }
.hljs-built_in, .hljs-attr, .hljs-attribute, .hljs-params, .hljs-property { color: var(--hl-attr); }
.hljs-meta, .hljs-tag { color: var(--hl-meta); }
.hljs-deletion { color: var(--danger); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------- tags */
.tags { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 32px 0 0; }
.tags a {
  display: inline-block; padding: 2px 12px; border-radius: 999px;
  background: var(--soft); border: 1px solid var(--line); text-decoration: none; font-size: 0.9rem;
}
.tags.big a { font-size: 1rem; padding: 6px 14px; }

.badge {
  display: inline-block; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 0.8rem; color: var(--muted);
}

/* ---------- forms */
form label { display: block; margin: 12px 0; font-weight: 600; }
form label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 0; }
input:not([type=checkbox]):not([type=file]), textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  font: inherit; font-weight: 400; color: var(--fg); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button {
  display: inline-block; padding: 9px 18px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; line-height: 1.4;
  cursor: pointer; text-decoration: none;
}
.button.secondary { background: var(--soft); color: var(--fg); border: 1px solid var(--line); font-weight: 500; }
button.link { background: none; padding: 0; color: var(--accent); font-weight: 400; text-decoration: underline; }
button.danger { background: var(--danger); padding: 4px 12px; font-size: 0.9rem; }

.card { max-width: 380px; margin: 48px auto; }
.error {
  padding: 10px 14px; border-radius: 8px; color: var(--danger);
  border: 1px solid var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent);
}
.row { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ---------- dashboard */
table.admin { width: 100%; border-collapse: collapse; }
table.admin th, table.admin td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.admin th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
td.actions { display: flex; gap: 12px; align-items: flex-start; white-space: nowrap; }
details summary { cursor: pointer; color: var(--danger); }
details form { margin-top: 6px; }

/* ---------- editor */
.editor h1 { margin: 16px 0; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.fields .span { grid-column: 1 / -1; }
.prefixed { display: flex; align-items: center; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.prefixed > span { padding: 0 0 0 12px; color: var(--muted); font-weight: 400; }
.prefixed input { margin: 0 !important; border: 0 !important; padding-left: 2px !important; }
#desc-count.over { color: var(--danger); }

.cover-field { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 12px 0; }
.cover-field .label { font-weight: 600; width: 100%; }
.cover-field label.button { margin: 0; }
#cover-preview { display: none; width: 160px; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.cover-field.has-cover #cover-preview { display: block; }
#cover-remove { display: none; }
.cover-field.has-cover #cover-remove { display: inline; }

.md { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.md-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 6px; border-bottom: 1px solid var(--line); background: var(--soft); }
.toolbar { display: flex; flex-wrap: wrap; gap: 2px; }
.toolbar button, .tabs button {
  padding: 4px 10px; border-radius: 6px; font-weight: 500; font-size: 0.85rem;
  background: transparent; color: var(--fg);
}
.toolbar button:hover, .tabs button:hover { background: var(--line); }
.tabs { display: none; margin-left: auto; }
.tabs button[aria-selected=true] { background: var(--card); box-shadow: 0 0 0 1px var(--line); }
.md-panes { display: grid; grid-template-columns: 1fr 1fr; min-height: 60vh; }
.md-panes textarea {
  margin: 0; border: 0; border-radius: 0; min-height: 60vh; resize: none;
  font: 15px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.md-panes textarea:focus { outline: none; }
#preview { padding: 12px 20px; border-left: 1px solid var(--line); overflow-y: auto; max-height: 80vh; }

@media (max-width: 860px) {
  .fields { grid-template-columns: 1fr; }
  .tabs { display: flex; }
  .md-panes { grid-template-columns: 1fr; }
  .md[data-view=write] #preview, .md[data-view=preview] textarea { display: none; }
  #preview { border-left: 0; max-height: none; min-height: 60vh; }
}
@media (max-width: 560px) {
  h1 { font-size: 1.7rem; }
  .post-list > li:has(.thumb) { grid-template-columns: 1fr; }
  .post-list .thumb { order: 0; }
  table.admin th:nth-child(3), table.admin td:nth-child(3) { display: none; }
  td.actions { flex-direction: column; gap: 4px; }
}
