.site-header {
  margin: 25px 0;
}

.site-header.has-theme-toggle,
.site-header.theme-only {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.site-header.theme-only { justify-content: flex-end; }

.header-main { display: block; }
.top-nav { display: inline-block; }

.top-nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 1.05em;
  text-transform: lowercase;
}

.top-nav li { display: inline; margin: 0 3px; }
.top-nav a { color: var(--header-nav, #454545); }

.site-title {
  color: var(--header-title, #313a3d);
  display: inline;
  font-size: 21px;
  font-weight: 700;
  margin: 0 8px 0 0;
}

:root[data-theme="dark"] {
  --header-nav: #ccc;
  --header-title: #e0e0e0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --header-nav: #ccc;
    --header-title: #e0e0e0;
  }
}

.theme-switch { display: inline-flex; }

.theme-switch-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.theme-switch-label {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 28px);
  width: 60px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  cursor: pointer;
  user-select: none;
}

.theme-switch-label::before {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 1px 4px rgb(0 0 0 / 18%);
  content: "";
  transition: transform 160ms ease;
}

.theme-switch-label span {
  z-index: 1;
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
  opacity: 0.45;
}

.theme-switch-input:not(:checked) + .theme-switch-label span:first-child,
.theme-switch-input:checked + .theme-switch-label span:last-child { opacity: 1; }

.theme-switch-input:checked + .theme-switch-label::before { transform: translateX(28px); }
.theme-switch-input:focus-visible + .theme-switch-label { outline: 2px solid var(--accent); outline-offset: 3px; }

@media (min-width: 770px) {
  .site-title { font-size: 25px; }
}

@media (max-width: 520px) {
  .site-header.has-theme-toggle { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-switch-label::before { transition: none; }
}

:root {
  color-scheme: light dark;
  --bg: #fff;
  --text: #313a3d;
  --body: #394548;
  --muted: #767676;
  --line: #d8d8d8;
  --soft: #f5f5f5;
  --accent: #007dfa;
  --code-comment: #6a737d;
  --code-keyword: #a626a4;
  --code-name: #005cc5;
  --code-number: #986801;
  --code-string: #22863a;
  --measure: 600px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --text: #ebebeb;
  --body: #f5f5f5;
  --muted: #a7a7a7;
  --line: #5c5c5c;
  --soft: #202020;
  --accent: #00b1ed;
  --code-comment: #8b949e;
  --code-keyword: #ff7b72;
  --code-name: #79c0ff;
  --code-number: #d2a8ff;
  --code-string: #a5d6ff;
}

* { box-sizing: border-box; }

html {
  font-size: 62.5%;
  scroll-behavior: smooth;
  scrollbar-color: var(--muted) var(--bg);
}

body {
  width: 100%;
  margin: 0 auto;
  padding: 0 16px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 16px;
  font-size: 1.6rem;
  line-height: 1.6;
  overflow-wrap: break-word;
}

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

a:hover { text-decoration: underline; }

:root[data-theme="dark"] body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main { margin-bottom: 56px; }

.home-title {
  margin-bottom: 0;
  font-size: 19px;
  font-size: 1.9rem;
  line-height: 1.15;
}

.post-list {
  margin-top: 0;
  padding: 0;
  list-style: none;
  font-size: 16px;
  font-size: 1.6rem;
}
.post-list li { margin: 5px 0; padding: 0; }
.post-list a { text-decoration: none; }
.post-list small { margin-left: 10px; color: var(--muted); font-size: 0.8em; }
.post-list a:hover { color: #369aff; }
.post-list a:hover small { color: inherit; }
:root[data-theme="dark"] .post-list a:hover { color: #21c7ff; }
.site-footer { margin: 48px 0 28px; color: var(--muted); font-size: 0.86em; }

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  margin-bottom: 0;
  line-height: 1.15;
}

.prose h1 {
  display: block;
  font-size: 23px;
  font-size: 2.3rem;
  font-weight: 600;
}

.prose h3 {
  font-size: 19px;
  font-size: 1.9rem;
}

.prose .post-date {
  margin: 4px 0 22px;
  color: var(--muted);
  font-size: 0.84em;
}

.prose h1 + p,
.prose h2 + p,
.prose h3 + p,
.prose h4 + p,
.prose h5 + p,
.prose h6 + p { margin-top: 5px; }

.prose p { margin: 16px 0; color: var(--body); }
.prose hr { height: 1px; border: 0; background: var(--line); }
.prose img { max-width: 100%; height: auto; margin: 0 auto; }
.prose figure { margin: 16px 0; }
.prose figure img { display: block; max-width: 100%; margin: 0 auto; }
.prose figure figcaption { margin-top: 6px; padding: 0 10px; font-size: 0.92em; font-style: italic; line-height: 22px; text-align: center; }
.prose blockquote { margin: 10px 0 10px 50px; padding-left: 15px; border-left: 3px solid #ccc; font-style: italic; }
.prose table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.92em; }
.prose th, .prose td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; }
.prose code, .prose pre { font-family: Menlo, monospace; }
.prose code { padding: 0 5px; font-size: 0.96em; }
.prose pre { display: block; overflow-x: auto; margin: 20px 0; padding: 1.5rem; background: var(--soft); font-size: 14px; font-size: 1.4rem; line-height: 1.4; white-space: pre; }
.prose pre code { padding: 0; }
.codehilite .c, .codehilite .ch, .codehilite .cm, .codehilite .cp, .codehilite .cpf, .codehilite .c1, .codehilite .cs { color: var(--code-comment); font-style: italic; }
.codehilite .k, .codehilite .kc, .codehilite .kd, .codehilite .kn, .codehilite .kp, .codehilite .kr, .codehilite .kt { color: var(--code-keyword); font-weight: 600; }
.codehilite .n, .codehilite .na, .codehilite .nb, .codehilite .nc, .codehilite .nd, .codehilite .ne, .codehilite .nf, .codehilite .ni, .codehilite .nl, .codehilite .nn, .codehilite .nt, .codehilite .nv { color: var(--code-name); }
.codehilite .m, .codehilite .mb, .codehilite .mf, .codehilite .mh, .codehilite .mi, .codehilite .mo, .codehilite .il { color: var(--code-number); }
.codehilite .s, .codehilite .sa, .codehilite .sb, .codehilite .sc, .codehilite .dl, .codehilite .sd, .codehilite .s1, .codehilite .s2, .codehilite .se, .codehilite .sh, .codehilite .si, .codehilite .sr, .codehilite .ss, .codehilite .sx { color: var(--code-string); }
.codehilite .o, .codehilite .ow { color: var(--code-keyword); }
.codehilite .gd { color: #cf222e; }
.codehilite .gi { color: #1a7f37; }
.codehilite .err { color: #cf222e; text-decoration: underline; }

.sidenote {
  display: block;
  margin: 0.6rem 0 1rem;
  color: var(--muted);
  font-size: 0.82em;
  line-height: 1.45;
}

.sidenote::before {
  content: attr(data-footnote-label) ". ";
  color: var(--text);
  font-weight: 600;
}

.footnote-ref { font-size: 0.72em; }
.unresolved { color: #c65353; text-decoration: dotted underline; }

.page-toc { display: none; }

.page-toc-title {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 0.9em;
  font-weight: 700;
}

.page-toc ol { margin: 0; padding: 0; list-style: none; }
.page-toc li { margin: 0; }

.toc-link {
  display: block;
  padding: 5px 8px 5px 12px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: 0.82em;
  line-height: 1.35;
}

.toc-level-2 .toc-link { padding-left: 12px; }
.toc-level-3 .toc-link { padding-left: 24px; font-size: 0.78em; }
.toc-level-4 .toc-link { padding-left: 36px; font-size: 0.76em; }
.toc-level-5 .toc-link { padding-left: 48px; font-size: 0.74em; }
.toc-level-6 .toc-link { padding-left: 60px; font-size: 0.72em; }
.toc-link:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }
.toc-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.prose h2, .prose h3, .prose h4, .prose h5, .prose h6 { scroll-margin-top: 24px; }

@keyframes toc-current-section {
  from, to {
    border-color: var(--accent);
    color: var(--text);
    font-weight: 600;
  }
}

@supports (animation-timeline: view()) {
  .toc-scroll-section {
    view-timeline-axis: block;
    view-timeline-inset: 24px calc(100% - 25px);
  }

  .toc-link {
    animation-name: toc-current-section;
    animation-duration: auto;
    animation-fill-mode: none;
    animation-range: cover 0% cover 100%;
    animation-timing-function: linear;
  }
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 32px;
  margin: 40px 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 0.9em;
}

.home-shell { padding-top: clamp(48px, 12vh, 120px); }

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.home-header h1 {
  margin: 0;
  font-size: 21px;
  font-size: 2.1rem;
  line-height: 1.2;
}

.filesystem { overflow: hidden; }

.folder-row,
.file-link { min-height: 36px; }

.folder-group[hidden], .file-entry[hidden] { display: none; }

.folder-row {
  display: flex;
  align-items: center;
  margin-top: 0;
  padding: 0;
  color: var(--text);
  font-weight: 600;
}

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

.file-link {
  display: block;
  align-items: center;
  padding: 6px 0 6px 20px;
}

.file-link:hover { text-decoration: none; }
.file-link:hover .file-name { color: var(--accent); }

.file-title {
  overflow: hidden;
  color: var(--text);
  font-size: 0.96em;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 770px) {
  body { width: var(--measure); line-height: 1.5; }
  .home-title { font-size: 20px; font-size: 2rem; }
  .post-list { font-size: 18px; font-size: 1.8rem; }
  .prose h1 { font-size: 24px; font-size: 2.4rem; }
  .prose h3 { font-size: 20px; font-size: 2rem; }
  .prose hr, .prose img, .prose pre { width: 108%; max-width: 108%; margin-left: -3.8%; }
  .prose figure { width: 108%; margin-left: -3.8%; }
}

@media (min-width: 1100px) {
  .page-toc {
    position: fixed;
    top: 50%;
    left: max(20px, calc(50vw - var(--measure) / 2 - 260px));
    display: block;
    width: 220px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    transform: translateY(-50%);
  }

  .sidenote {
    --sidenote-width: min(280px, calc((100vw - var(--measure)) / 2 - 32px));
    float: right;
    clear: right;
    width: var(--sidenote-width);
    margin: 0 calc(0px - var(--sidenote-width) - 32px) 1.2rem 32px;
  }
}

@media (max-width: 520px) {
  .file-title { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
