:root {
  color-scheme: light;
  --page: #fbfbfa;
  --surface: #fff;
  --text: #222;
  --muted: #737373;
  --line: #dededb;
  --soft: #f1f1ef;
  --code: #ececea;
  --width: 780px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #181818;
  --surface: #202020;
  --text: #e8e8e5;
  --muted: #aaa;
  --line: #3a3a38;
  --soft: #252525;
  --code: #2b2b2b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #181818;
    --surface: #202020;
    --text: #e8e8e5;
    --muted: #aaa;
    --line: #3a3a38;
    --soft: #252525;
    --code: #2b2b2b;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  font-size: 17px;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--muted); text-decoration: underline; text-underline-offset: .18em; }
button, input, textarea { font: inherit; }
.site-shell {
  display: flex;
  flex-direction: column;
  width: min(calc(100% - 40px), var(--width));
  min-height: 100vh;
  margin: 0 auto;
}
.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 30px;
  padding: 72px 0 28px;
}
.site-title, .article-title {
  max-width: 660px;
  color: var(--text);
  font-size: clamp(2.6rem, 8vw, 4rem);
  font-weight: 760;
  letter-spacing: -.055em;
  line-height: 1.05;
}
.site-title:hover, .article-title:hover { text-decoration: none; color: var(--text); }
.article-title { font-size: clamp(2rem, 6vw, 3rem); }
.header-tools { display: flex; gap: 5px; margin-top: 5px; }
.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.icon-button:hover { color: var(--text); background: var(--soft); }
.site-main { flex: 1; padding: 44px 0 20px; animation: enter .45s ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
.site-flash {
  margin: 0 0 28px;
  padding: 11px 14px;
  border: 1px solid #b9d7bc;
  border-radius: 6px;
  color: #285d2d;
  background: #edf7ee;
  font-size: .88rem;
}
.site-flash.error { border-color: #e3b9b5; color: #8c2520; background: #fff0ef; }
.post-list { display: grid; gap: 4px; }
.post-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 4px 0;
}
.post-row a { min-width: 0; overflow-wrap: anywhere; }
.post-row time, .article-meta time {
  flex: none;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: .92rem;
  white-space: nowrap;
}
.compact { padding-top: 12px; }
.pagination { display: flex; gap: 8px; margin: 72px 0 12px; }
.pagination a {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 4px;
  background: var(--soft);
  color: var(--muted);
}
.pagination a.current, .pagination a:hover {
  background: var(--text);
  color: var(--page);
  text-decoration: none;
}
.site-footer {
  margin-top: 45px;
  padding: 26px 0 44px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: .78rem;
  line-height: 1.8;
}
.site-footer p { margin: 2px 0; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.site-footer a:hover { color: var(--text); }
.article-meta {
  display: flex;
  gap: 8px;
  margin: -6px 0 38px;
  color: var(--muted);
  font-size: .9rem;
}
.article-body { overflow-wrap: anywhere; }
.article-body h1, .article-body h2, .article-body h3 {
  line-height: 1.28;
  letter-spacing: -.025em;
}
.article-body h1 { margin: 1.8em 0 .55em; font-size: 2rem; }
.article-body h2 { margin: 2em 0 .55em; font-size: 1.45rem; }
.article-body h3 { margin: 1.8em 0 .5em; font-size: 1.15rem; }
.article-body p { margin: 1em 0; }
.article-body a { text-decoration: underline; text-underline-offset: .18em; }
.article-body ul, .article-body ol { padding-left: 1.35em; }
.article-body blockquote {
  margin: 1.6em 0;
  padding: 14px 18px;
  border-left: 4px solid var(--text);
  border-radius: 0 5px 5px 0;
  background: var(--soft);
  font-weight: 620;
}
.article-body blockquote p { margin: 0; }
.article-body hr { margin: 2.4em 0; border: 0; border-top: 1px dashed var(--muted); }
.article-body code {
  padding: .15em .32em;
  border-radius: 4px;
  background: var(--code);
  font: .88em "SFMono-Regular", Consolas, monospace;
}
.codehilite {
  position: relative;
  overflow: hidden;
  margin: 1.4em 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--code);
}
.codehilite pre {
  max-height: 460px;
  margin: 0;
  padding: 20px;
  overflow: auto;
}
.codehilite code { padding: 0; background: transparent; }
.copy-code {
  position: absolute;
  top: 9px;
  right: 9px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface);
  font-size: .72rem;
  cursor: pointer;
}
.codehilite .k, .codehilite .kd, .codehilite .kn { color: #9b3e9f; }
.codehilite .s, .codehilite .s1, .codehilite .s2 { color: #387b38; }
.codehilite .c, .codehilite .c1, .codehilite .cm { color: #7b7b75; font-style: italic; }
.codehilite .nf, .codehilite .nc { color: #285f9e; }
.codehilite .mi, .codehilite .mf { color: #9a5d16; }
.article-body table { display: block; width: 100%; margin: 1.5em 0; overflow-x: auto; border-collapse: collapse; }
.article-body th, .article-body td { padding: 9px 12px; border: 1px solid var(--line); text-align: left; }
.article-body th { background: var(--soft); }
.article-body video { width: 100%; border-radius: 7px; background: #000; }
.reveal-image { margin: 1.5em 0; }
.reveal-image img { display: block; width: 100%; border-radius: 7px; animation: reveal .35s ease both; }
.reveal-image img[hidden] { display: none; }
@keyframes reveal { from { opacity: 0; filter: blur(6px); } }
.image-reveal-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--soft);
  cursor: pointer;
}
.image-reveal-button small { color: var(--muted); }
.reveal-image.is-open .image-reveal-button { margin-bottom: 10px; }
.article-tags { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 48px; color: var(--muted); font-size: .84rem; }
.post-neighbors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 74px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  font-size: .85rem;
}
.post-neighbors a:last-child { text-align: right; }
.comments {
  margin-top: 76px;
  padding-top: 30px;
  border-top: 1px solid var(--line);
}
.comments-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.comments-heading h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.025em; }
.comments-heading span, .comments-empty { color: var(--muted); font-size: .84rem; }
.comment-list { display: grid; gap: 0; margin: 0 0 42px; padding: 0; list-style: none; }
.comment-list li { padding: 20px 0; border-bottom: 1px solid var(--line); }
.comment-list li:first-child { border-top: 1px solid var(--line); }
.comment header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.comment header strong { font-size: .92rem; }
.comment header time { color: var(--muted); font: .75rem "SFMono-Regular", Consolas, monospace; }
.comment p { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form {
  display: grid;
  gap: 16px;
  margin-top: 34px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.comment-form label { display: grid; gap: 6px; font-size: .86rem; font-weight: 650; }
.comment-form label small { color: var(--muted); font-weight: 400; }
.comment-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.comment-form input, .comment-form textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  background: var(--page);
  outline: none;
}
.comment-form input:focus, .comment-form textarea:focus {
  border-color: var(--muted);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent);
}
.comment-form textarea { resize: vertical; }
.comment-submit { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.comment-submit small { color: var(--muted); font-size: .75rem; }
.comment-submit button {
  flex: none;
  padding: 9px 15px;
  border: 0;
  border-radius: 5px;
  color: var(--page);
  background: var(--text);
  cursor: pointer;
}
.comment-trap {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.page-search { display: flex; gap: 10px; margin-bottom: 20px; }
.page-search input, .search-row input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
}
.page-search button, .search-row button {
  padding: 10px 16px;
  border: 0;
  border-radius: 5px;
  color: var(--page);
  background: var(--text);
  cursor: pointer;
}
.result-count, .empty-state { color: var(--muted); }
.search-dialog {
  width: min(540px, calc(100% - 32px));
  padding: 25px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 80px rgb(0 0 0 / .18);
}
.search-dialog::backdrop { background: rgb(0 0 0 / .28); backdrop-filter: blur(3px); }
.search-form > label { display: block; margin-bottom: 12px; font-size: 1.2rem; font-weight: 700; }
.search-form p { margin: 12px 0 0; color: var(--muted); font-size: .75rem; }
.search-row { display: flex; gap: 8px; }
.dialog-close { position: absolute; top: 10px; right: 12px; border: 0; color: var(--muted); background: none; cursor: pointer; }
kbd { padding: 1px 5px; border: 1px solid var(--line); border-radius: 3px; background: var(--soft); }
.error-page { display: grid; min-height: 40vh; place-content: center; text-align: center; }
.error-page strong { font-size: 5rem; letter-spacing: -.06em; }

@media (max-width: 620px) {
  body { font-size: 16px; }
  .site-shell { width: min(calc(100% - 32px), var(--width)); }
  .site-header { padding-top: 48px; }
  .header-tools { margin-top: -5px; }
  .post-row { gap: 12px; }
  .post-row time { font-size: .78rem; }
  .post-neighbors { grid-template-columns: 1fr; }
  .post-neighbors a:last-child { text-align: left; }
  .comment-fields { grid-template-columns: 1fr; }
  .comment-submit { align-items: stretch; flex-direction: column; }
  .comment-submit button { width: 100%; }
}
