:root {
  color-scheme: light dark;
  --paper: #f2f3ef;
  --paper-raised: #e8eae4;
  --ink: #1b1d19;
  --muted: #62665e;
  --line: #cdd1c8;
  --accent: #2448bd;
  --code: #1d201c;
  --code-ink: #e9ebe4;
  --selection: #c8d4ff;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-display: "Songti SC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --font-mono: "SFMono-Regular", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171916;
    --paper-raised: #21241f;
    --ink: #eef0e9;
    --muted: #a4a99f;
    --line: #383d35;
    --accent: #8da6ff;
    --code: #0f110f;
    --code-ink: #e8ebe3;
    --selection: #3b5197;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 6rem;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 20rem;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--selection);
  color: var(--ink);
}

a {
  color: inherit;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.2em;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

button,
input,
textarea,
select {
  font: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.shell {
  width: min(100% - 4rem, 80rem);
  margin-inline: auto;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.65rem 0.9rem;
  background: var(--ink);
  color: var(--paper);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.site-header__inner {
  display: flex;
  min-height: 4.5rem;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.wordmark {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2.25rem);
  font-size: 0.88rem;
}

.site-nav a {
  display: inline-flex;
  min-width: 2.75rem;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  padding-inline: 0.5rem;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--accent);
  text-decoration: underline;
}

.site-main {
  min-height: calc(100dvh - 12rem);
}

.home-hero {
  display: grid;
  min-height: min(42rem, calc(100dvh - 4.5rem));
  grid-template-columns: minmax(0, 7fr) minmax(15rem, 3fr);
  gap: clamp(3rem, 7vw, 7rem);
  align-items: end;
  padding-block: clamp(5rem, 11vw, 9rem) clamp(4.5rem, 9vw, 7rem);
}

.home-hero h1 {
  max-width: 10em;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 7vw, 6.6rem);
  font-weight: 600;
  letter-spacing: -0.055em;
  line-height: 1.06;
  text-wrap: balance;
}

.home-hero__aside {
  border-left: 1px solid var(--line);
  padding-left: clamp(1.5rem, 3vw, 2.5rem);
  padding-bottom: 0.55rem;
}

.home-hero__aside p {
  max-width: 24rem;
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: clamp(1rem, 1.7vw, 1.2rem);
  line-height: 1.8;
}

.home-hero__aside a,
.error-page a {
  color: var(--accent);
  font-weight: 650;
}

.writing {
  padding-block: clamp(4rem, 8vw, 7rem) clamp(7rem, 13vw, 11rem);
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 2rem;
}

.section-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 5vw, 4.5rem);
  font-weight: 600;
  letter-spacing: -0.05em;
  line-height: 1;
}

.section-header p {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.post-list {
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
  list-style: none;
}

.post-row {
  display: grid;
  grid-template-columns: 8rem minmax(0, 1fr) 11rem;
  gap: clamp(1.25rem, 4vw, 4rem);
  align-items: start;
  padding-block: clamp(1.6rem, 3vw, 2.35rem);
  border-bottom: 1px solid var(--line);
}

.post-row time {
  display: grid;
  gap: 0.1rem;
  padding-top: 0.38rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.4;
}

.post-row time span {
  color: var(--ink);
}

.post-link {
  min-width: 0;
  text-decoration: none;
}

.post-link h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 3vw, 2.75rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.22;
  text-wrap: balance;
  transition: color 160ms ease;
}

.post-link p {
  max-width: 42rem;
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.post-link:hover h3 {
  color: var(--accent);
}

.post-tags {
  margin: 0;
  padding-top: 0.38rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.7;
  text-align: right;
}

.page {
  padding-block: clamp(5rem, 10vw, 9rem) clamp(7rem, 12vw, 10rem);
}

.page-header {
  max-width: 54rem;
  margin-bottom: clamp(4rem, 8vw, 7rem);
}

.page-header h1,
.error-page h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3.5rem, 7vw, 6.5rem);
  font-weight: 600;
  letter-spacing: -0.055em;
  line-height: 1.05;
}

.page-header p {
  max-width: 36rem;
  margin: 1.5rem 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.3rem);
}

.page-body {
  max-width: 68rem;
}

.about-grid {
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(16rem, 3fr);
  gap: clamp(3rem, 9vw, 8rem);
  align-items: start;
}

.about-copy {
  max-width: 43rem;
  font-size: clamp(1.05rem, 1.8vw, 1.25rem);
  line-height: 1.9;
}

.about-copy p {
  margin: 0 0 1.5rem;
}

.about-copy .lede {
  margin-bottom: 2rem;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  font-weight: 600;
  line-height: 1.35;
}

.about-links {
  display: flex;
  gap: 1.5rem;
  padding-top: 1rem;
}

.about-links a {
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 650;
}

.about-portrait {
  margin: 0;
}

.about-portrait img {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  object-fit: cover;
}

.article-header {
  padding-block: clamp(5rem, 10vw, 9rem) clamp(4rem, 7vw, 6rem);
}

.article-back {
  display: inline-block;
  margin-bottom: 2.5rem;
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 650;
}

.article-header h1 {
  max-width: 62rem;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3rem, 6.7vw, 6rem);
  font-weight: 600;
  letter-spacing: -0.055em;
  line-height: 1.08;
  text-wrap: balance;
}

.article-subtitle {
  max-width: 44rem;
  margin: 1.6rem 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1.7;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
  margin-top: 2rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

.article-grid {
  display: grid;
  grid-template-columns: 12.5rem minmax(0, 47.5rem) minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
  padding-bottom: clamp(5rem, 10vw, 9rem);
}

.toc {
  position: sticky;
  top: 7rem;
  grid-column: 1;
  max-height: calc(100dvh - 9rem);
  overflow: auto;
}

.toc[hidden] {
  display: none;
}

.toc__label {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

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

.toc li {
  margin: 0 0 0.65rem;
}

.toc li[data-level="3"] {
  padding-left: 1rem;
}

.toc a {
  display: block;
  border-left: 1px solid var(--line);
  padding-left: 0.8rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
  text-decoration: none;
}

.toc a:hover,
.toc a[aria-current="true"] {
  border-color: var(--accent);
  color: var(--ink);
}

.prose {
  min-width: 0;
  grid-column: 2;
  font-size: clamp(1.03rem, 1.4vw, 1.12rem);
  line-height: 1.95;
  overflow-wrap: break-word;
}

.prose > :first-child {
  margin-top: 0;
}

.prose > :last-child {
  margin-bottom: 0;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose pre,
.prose table,
.prose figure {
  margin-block: 1.45rem;
}

.prose h2,
.prose h3,
.prose h4 {
  scroll-margin-top: 6.5rem;
  color: var(--ink);
  text-wrap: balance;
}

.prose h2 {
  margin: 4.5rem 0 1.35rem;
  font-family: var(--font-display);
  font-size: clamp(2rem, 3.5vw, 2.8rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.28;
}

.prose h3 {
  margin: 3.25rem 0 1.1rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: 600;
  line-height: 1.35;
}

.prose h4 {
  margin: 2.5rem 0 0.9rem;
  font-size: 1.08rem;
  line-height: 1.5;
}

.prose a {
  color: var(--accent);
}

.prose a:hover {
  color: var(--ink);
}

.prose strong {
  font-weight: 700;
}

.prose ul,
.prose ol {
  padding-left: 1.4rem;
}

.prose li {
  margin-block: 0.45rem;
  padding-left: 0.25rem;
}

.prose li::marker {
  color: var(--accent);
}

.prose blockquote {
  margin-inline: 0;
  border-left: 2px solid var(--accent);
  padding: 0.3rem 0 0.3rem 1.5rem;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 1.08em;
}

.prose blockquote > :first-child {
  margin-top: 0;
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

.prose code {
  padding: 0.16em 0.35em;
  background: var(--paper-raised);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.prose pre,
.prose .highlight {
  overflow-x: auto;
  background: var(--code);
  color: var(--code-ink);
}

.prose pre {
  border-top: 2px solid var(--accent);
  padding: 1.35rem 1.5rem;
  line-height: 1.7;
  tab-size: 2;
}

.prose pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 0.84rem;
}

.highlight .c,
.highlight .cm,
.highlight .c1,
.highlight .cp {
  color: #8f968b;
}

.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kp,
.highlight .kr,
.highlight .kt,
.highlight .o,
.highlight .ow {
  color: var(--accent);
}

.prose img {
  width: auto;
  margin-block: 2.25rem;
  border: 1px solid var(--line);
}

.prose hr {
  width: 25%;
  margin: 4rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.prose table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.prose th,
.prose td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.article-footer {
  width: min(100% - 4rem, 51.5rem);
  padding-bottom: clamp(6rem, 10vw, 9rem);
}

.article-footer__nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: 2rem;
}

.article-footer__nav a {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.45;
  text-decoration: none;
}

.article-footer__nav a:hover {
  color: var(--accent);
}

.article-footer__nav span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
}

.article-edit {
  grid-column: 2;
  color: var(--muted);
  font-family: var(--font-body) !important;
  font-size: 0.78rem;
  font-weight: 500 !important;
}

.article-next {
  grid-column: 3;
  text-align: right;
}

.error-page {
  display: grid;
  min-height: calc(100dvh - 9.5rem);
  align-content: center;
  justify-items: start;
  padding-block: 5rem;
}

.error-code {
  margin: 0 0 1.5rem;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.error-page p:not(.error-code) {
  max-width: 30rem;
  margin: 1.5rem 0;
  color: var(--muted);
}

.site-footer {
  border-top: 1px solid var(--line);
}

.site-footer__inner {
  display: flex;
  min-height: 7.5rem;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.site-footer p {
  margin: 0;
}

.site-footer nav {
  display: flex;
  gap: 1.5rem;
}

.site-footer a:hover {
  color: var(--accent);
}

.reading-progress {
  display: none;
}

@supports (animation-timeline: scroll()) {
  .reading-progress {
    position: fixed;
    inset: 0 0 auto;
    z-index: 30;
    display: block;
    height: 2px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    animation: reading-progress linear;
    animation-timeline: scroll();
  }

  @keyframes reading-progress {
    to {
      transform: scaleX(1);
    }
  }
}

@media (max-width: 68.75rem) {
  .article-grid {
    display: block;
    width: min(100% - 4rem, 47.5rem);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 48rem) {
  .shell,
  .article-grid,
  .article-footer {
    width: min(100% - 2.5rem, 80rem);
  }

  .site-header__inner {
    min-height: 4.25rem;
  }

  .site-nav {
    gap: 0.15rem;
    font-size: 0.8rem;
  }

  .home-hero {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 3.5rem;
    align-items: start;
    padding-block: 5.5rem 4.5rem;
  }

  .home-hero h1 {
    font-size: clamp(2.85rem, 12vw, 4rem);
  }

  .home-hero__aside {
    border-top: 1px solid var(--line);
    border-left: 0;
    padding: 1.5rem 0 0;
  }

  .section-header {
    align-items: flex-end;
  }

  .post-row {
    grid-template-columns: 4.5rem minmax(0, 1fr);
    gap: 1rem;
  }

  .post-tags {
    grid-column: 2;
    padding: 0;
    text-align: left;
  }

  .about-grid {
    grid-template-columns: 1fr;
    gap: 3rem;
  }

  .about-portrait {
    width: min(100%, 22rem);
  }

  .article-header {
    padding-block: 4.5rem 3.5rem;
  }

  .article-header h1,
  .page-header h1,
  .error-page h1 {
    font-size: clamp(3rem, 14vw, 4.6rem);
  }

  .article-grid {
    padding-bottom: 5rem;
  }

  .prose {
    font-size: 1rem;
    line-height: 1.88;
  }

  .prose h2 {
    margin-top: 3.75rem;
  }

  .prose pre {
    margin-inline: -1.25rem;
    padding-inline: 1.25rem;
  }

  .article-footer__nav {
    display: flex;
    flex-direction: column;
    gap: 2rem;
  }

  .article-edit {
    order: 3;
  }

  .article-next {
    text-align: left;
  }

  .site-footer__inner {
    min-height: 8rem;
  }
}

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

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .reading-progress {
    display: none;
  }
}

@media print {
  .site-header,
  .site-footer,
  .toc,
  .article-back,
  .article-footer,
  .reading-progress {
    display: none !important;
  }

  body {
    background: var(--paper);
  }

  .article-header,
  .article-grid {
    width: 100%;
    padding-block: 2rem;
  }

  .prose a {
    color: inherit;
  }
}
