:root {
  --bg: #f8f6f2;
  --surface: #ffffff;
  --line: #e2ddd5;
  --text: #1a1a1a;
  --muted: #6b6560;
  --accent: #1a3a5c;
  --radius: 6px;
  --content-width: min(760px, calc(100vw - 32px));
  --wide-content-width: min(1120px, calc(100vw - 32px));
  --reading-width: min(760px, 100%);
  --font-sans: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC",
    "Microsoft YaHei", sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", "STSong", serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 180ms ease, opacity 180ms ease;
}

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

pre,
code {
  font-family: "SFMono-Regular", "JetBrains Mono", "Fira Code", Consolas, monospace;
}

.page-shell {
  width: var(--content-width);
  margin: 0 auto;
  padding: 58px 0 76px;
}

.page-shell-wide {
  width: var(--wide-content-width);
}

.site-header {
  margin-bottom: 42px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--line);
}

.site-header-compact {
  margin-bottom: 24px;
}

.site-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.site-header-row-compact {
  align-items: center;
}

.site-title,
.site-title-link {
  display: inline-block;
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.8rem, 6.8vw, 4.5rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
  color: var(--text);
}

.site-contact {
  margin: 14px 0 0;
  color: #9b9590;
  font-size: 0.88rem;
  line-height: 1.7;
  letter-spacing: 0.03em;
}

.site-search-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1;
  white-space: nowrap;
}

.site-search-link:hover {
  border-color: #adadad;
  background: #f1f1f1;
}

.site-search-link-current {
  border-color: var(--text);
  background: var(--text);
  color: #ffffff;
}

.site-logo-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
}

.site-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ededed;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  line-height: 1;
  transition: transform 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.site-logo-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.site-logo-name {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.site-logo-hint {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-logo-link:hover .site-logo-mark {
  transform: translateY(-1px);
  border-color: #a8a8a8;
  background: #e4e4e4;
}

.site-logo-link:hover .site-logo-name {
  color: var(--accent);
}

.site-logo-link:focus-visible,
.post-item-title a:focus-visible,
.prose a:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 4px;
}

.post-list {
  border-top: none;
}

.home-main,
.search-page {
  width: var(--reading-width);
  max-width: 100%;
}

.post-item {
  padding: 38px 0 42px;
  border-bottom: 1px solid var(--line);
  transition: background-color 200ms ease;
}

.post-item:hover {
  background: rgba(26, 58, 92, 0.02);
}

.post-item-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.post-item-title {
  margin: 0;
}

.post-item-title,
.post-item-title a {
  font-family: var(--font-serif);
  font-size: clamp(1.82rem, 4vw, 2.18rem);
  line-height: 1.14;
  letter-spacing: -0.038em;
  color: inherit;
}

.post-item-title a:hover {
  color: var(--accent);
}

.post-item-date,
.post-date {
  color: var(--muted);
  font-size: 0.92rem;
}

.post-item-summary {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.82;
}

.ai-tag {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 4px;
  background: rgba(26, 58, 92, 0.06);
  border-radius: 3px;
  font-size: 0.8em;
  color: var(--accent);
  letter-spacing: 0.02em;
  vertical-align: 1px;
}

.empty-state {
  padding: 28px 0 0;
  color: var(--muted);
}

.search-panel {
  margin-bottom: 24px;
}

.search-results-list {
  border-top: 0;
}

.search-label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input {
  width: 100%;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.4;
}

.search-input::placeholder {
  color: #909090;
}

.search-input:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.search-clear {
  flex: 0 0 auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.search-clear:hover {
  border-color: #adadad;
  background: #f1f1f1;
}

.search-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.7;
}

.search-empty {
  padding-top: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 24px;
}

.pagination-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
}

.pagination-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.pagination-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.94rem;
  line-height: 1;
}

.pagination-link:hover {
  border-color: #adadad;
  background: #f1f1f1;
}

.pagination-link-current {
  border-color: var(--text);
  background: var(--text);
  color: #ffffff;
}

.pagination-link-disabled {
  color: #a0a0a0;
  background: #f3f3f3;
}

.pagination-link-direction {
  padding-inline: 16px;
}

.post-layout {
  display: block;
}

.post-page {
  border-top: 1px solid var(--line);
  padding-top: 30px;
  animation: article-enter 520ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.post-toc {
  display: none;
}

.post-toc-inner {
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  max-height: calc(100vh - 56px);
  overflow: auto;
}

.post-toc-title {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.post-toc-list li + li {
  margin-top: 9px;
}

.toc-item a {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.toc-item a:hover {
  color: var(--text);
}

.toc-item-level-3 a {
  padding-left: 12px;
}

.toc-item-level-4 a {
  padding-left: 24px;
}

.post-hero-art {
  margin: 0 0 28px;
  border-radius: var(--radius);
  overflow: hidden;
}

.post-hero-art svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Line grow animation (topo, wave outlines, flow) */
.post-hero-art .art-line {
  stroke-dasharray: var(--line-len);
  stroke-dashoffset: var(--line-len);
  animation: line-grow 1.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes line-grow {
  to { stroke-dashoffset: 0; }
}

/* Dot fade-in animation */
.post-hero-art .art-dot {
  transform-origin: center;
  transform: scale(0);
  opacity: 0;
  animation: dot-pop 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes dot-pop {
  to { transform: scale(1); opacity: var(--target-opacity, 0.12); }
}

/* Ripple expand animation */
.post-hero-art .art-ripple {
  transform-origin: center;
  transform: scale(0);
  opacity: 0;
  animation: ripple-expand 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes ripple-expand {
  to { transform: scale(1); opacity: 1; }
}

/* Wave fill grow */
.post-hero-art .art-wave {
  clip-path: inset(0 100% 0 0);
  animation: wave-reveal 1.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes wave-reveal {
  to { clip-path: inset(0 0 0 0); }
}

.post-header {
  margin-bottom: 34px;
  animation: article-enter 620ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.post-header h1 {
  margin: 0 0 12px;
  font-family: var(--font-serif);
  font-size: clamp(2.45rem, 5.4vw, 3.7rem);
  line-height: 1.01;
  letter-spacing: -0.05em;
}

.post-date {
  margin: 0;
}

.post-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.post-meta-sep {
  color: #c0bab4;
}

.post-summary {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.99rem;
  line-height: 1.82;
}

.prose {
  font-size: 1.08rem;
  line-height: 1.94;
  overflow-wrap: anywhere;
}

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

.prose > * {
  animation: article-enter 680ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.prose > *:nth-child(2) {
  animation-delay: 40ms;
}

.prose > *:nth-child(3) {
  animation-delay: 80ms;
}

.prose > *:nth-child(4) {
  animation-delay: 120ms;
}

.prose > *:nth-child(5) {
  animation-delay: 160ms;
}

.prose > *:nth-child(6) {
  animation-delay: 200ms;
}

.prose > *:nth-child(7) {
  animation-delay: 240ms;
}

.prose > *:nth-child(8) {
  animation-delay: 280ms;
}

.prose > *:nth-child(9) {
  animation-delay: 320ms;
}

.prose > *:nth-child(10) {
  animation-delay: 360ms;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose pre,
.prose .table-wrap {
  margin: 1.4em 0;
}

.prose > p:first-of-type {
  color: #1d1d1d;
  font-size: 1.1em;
  line-height: 1.9;
}

.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  margin-top: 2.05em;
  margin-bottom: 0.62em;
  font-family: var(--font-serif);
  line-height: 1.12;
  letter-spacing: -0.03em;
}

.prose h2 {
  font-size: 2.02rem;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
}

.prose h3 {
  font-size: 1.48rem;
}

.prose a {
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

.prose blockquote {
  margin-left: 0;
  padding: 8px 0 8px 18px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.prose ul,
.prose ol {
  padding-left: 1.35em;
}

.prose code {
  padding: 0.1em 0.35em;
  background: #edeae5;
  border: 1px solid #ddd9d2;
  border-radius: var(--radius);
  font-size: 0.94em;
}

.prose pre {
  overflow-x: auto;
  padding: 18px 20px;
  background: #161616;
  border: 1px solid #2c2c2c;
  border-radius: var(--radius);
  border-top: 2px solid var(--accent);
}

.prose pre code {
  padding: 0;
  background: transparent;
  border: 0;
  color: #e6e6e6;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-built_in,
.hljs-name {
  color: #ff7b72;
}

.hljs-string,
.hljs-attr,
.hljs-template-tag,
.hljs-template-variable {
  color: #a5d6ff;
}

.hljs-number,
.hljs-literal {
  color: #79c0ff;
}

.hljs-comment,
.hljs-doctag {
  color: #8b949e;
  font-style: italic;
}

.hljs-type,
.hljs-class .hljs-title,
.hljs-title.class_,
.hljs-title.function_ {
  color: #d2a8ff;
}

.hljs-variable,
.hljs-params {
  color: #e6e6e6;
}

.hljs-meta {
  color: #79c0ff;
}

.hljs-attribute {
  color: #ffa657;
}

.hljs-regexp,
.hljs-link {
  color: #7ee787;
}

.hljs-symbol,
.hljs-bullet {
  color: #ffa657;
}

.hljs-section {
  color: #ff7b72;
  font-weight: bold;
}

.hljs-addition {
  color: #aff5b4;
  background-color: rgba(46, 160, 67, 0.15);
}

.hljs-deletion {
  color: #ffdcd7;
  background-color: rgba(248, 81, 73, 0.15);
}

.hljs-property {
  color: #79c0ff;
}

.hljs-punctuation {
  color: #c9d1d9;
}

.hljs-tag {
  color: #7ee787;
}

.hljs-tag .hljs-attr {
  color: #79c0ff;
}

.hljs-tag .hljs-name {
  color: #7ee787;
}

.hljs-selector-class,
.hljs-selector-id {
  color: #d2a8ff;
}

/* Site footer */
.site-footer {
  margin-top: 56px;
  padding: 24px 0 0;
  border-top: 1px solid var(--line);
  color: #9b9590;
  font-size: 0.82rem;
  line-height: 1.8;
  text-align: center;
}

.site-footer-inner {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.site-footer a {
  color: #9b9590;
  text-decoration: none;
}

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

.site-footer-sep {
  color: #c0bab4;
}

/* Reading progress bar */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  z-index: 1000;
  transition: width 80ms linear;
}

/* Back to top */
.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 260ms ease, transform 260ms ease, border-color 180ms ease, color 180ms ease;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Prev / next post navigation */
.post-nav {
  display: flex;
  gap: 16px;
  margin-top: 48px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.post-nav-item {
  flex: 1;
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.post-nav-item:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 6px rgba(26, 58, 92, 0.06);
}

.post-nav-label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.post-nav-title {
  display: block;
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 1.3;
  color: var(--text);
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.post-nav-item-next {
  text-align: right;
}

@keyframes article-enter {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .site-logo-mark,
  .post-page,
  .post-header,
  .prose > * {
    animation: none;
    transition: none;
    transform: none;
  }
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--line);
}

.prose .table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.prose table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.96rem;
  line-height: 1.65;
}

.prose thead {
  background: #f0ece6;
}

.prose th,
.prose td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: normal;
}

.prose th[data-align="center"],
.prose td[data-align="center"] {
  text-align: center;
}

.prose th[data-align="right"],
.prose td[data-align="right"] {
  text-align: right;
}

.prose tbody tr:nth-child(even) {
  background: #faf9f7;
}

.prose .table-wrap table:first-child {
  margin: 0;
}

.prose .table-wrap th:first-child,
.prose .table-wrap td:first-child {
  border-left: 0;
}

.prose .table-wrap th:last-child,
.prose .table-wrap td:last-child {
  border-right: 0;
}

.prose .table-wrap thead tr:first-child th {
  border-top: 0;
}

.prose .table-wrap tbody tr:last-child td {
  border-bottom: 0;
}

.post-image {
  margin: 1.4em 0;
}

.post-image img {
  width: 100%;
  border-radius: var(--radius);
}

.post-image figcaption {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

@media (max-width: 900px) {
  .page-shell {
    width: min(100vw - 36px, 100%);
    padding-top: 48px;
    padding-bottom: 64px;
  }

  .home-main,
  .search-page {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 32px, 100%);
    padding-top: 38px;
    padding-bottom: 52px;
  }

  .site-header {
    margin-bottom: 30px;
  }

  .site-header-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .site-title,
  .site-title-link {
    font-size: clamp(2.35rem, 12vw, 3.35rem);
  }

  .site-contact {
    margin-top: 14px;
    word-break: break-all;
  }

  .site-logo-link {
    gap: 10px;
  }

  .site-header-row-compact {
    align-items: flex-start;
  }

  .site-logo-mark {
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    font-size: 1.1rem;
  }

  .site-logo-name {
    font-size: 1.05rem;
  }

  .site-logo-hint {
    font-size: 0.74rem;
    letter-spacing: 0.06em;
  }

  .site-search-link {
    padding: 10px 13px;
  }

  .post-item {
    padding: 28px 0 32px;
  }

  .post-item-title,
  .post-item-title a {
    font-size: 1.56rem;
  }

  .post-item-summary {
    margin-top: 14px;
    font-size: 0.95rem;
  }

  .pagination {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-field {
    align-items: stretch;
    flex-direction: column;
  }

  .search-clear {
    width: 100%;
    justify-content: center;
  }

  .pagination-links {
    justify-content: flex-start;
  }

  .post-page {
    padding-top: 28px;
  }

  .post-header {
    margin-bottom: 24px;
  }

  .post-header h1 {
    font-size: clamp(2.12rem, 10vw, 2.72rem);
  }

  .post-summary {
    margin-top: 14px;
    font-size: 0.95rem;
  }

  .prose {
    font-size: 1.02rem;
    line-height: 1.86;
  }

  .prose > p:first-of-type {
    font-size: 1.06em;
  }

  .prose h2 {
    font-size: 1.78rem;
    padding-left: 12px;
  }

  .prose h3 {
    font-size: 1.38rem;
  }

  .prose ul,
  .prose ol {
    padding-left: 1.2em;
  }

  .prose pre {
    padding: 14px 14px 16px;
    border-radius: var(--radius);
    font-size: 0.92rem;
  }

  .post-nav {
    flex-direction: column;
    gap: 10px;
    margin-top: 36px;
  }

  .post-nav-item-next {
    text-align: left;
  }

  .back-to-top {
    bottom: 20px;
    right: 20px;
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
  }
}

@media (min-width: 1100px) {
  .page-shell-wide .site-header-compact .site-header-row-compact {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, var(--reading-width)) 220px;
    column-gap: 40px;
    align-items: center;
  }

  .page-shell-wide .site-header-compact .site-logo-link {
    grid-column: 2;
    justify-self: start;
  }

  .page-shell-wide .site-header-compact .site-search-link {
    grid-column: 3;
    justify-self: end;
  }

  .post-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, var(--reading-width)) 220px;
    column-gap: 40px;
    align-items: start;
  }

  .post-page {
    grid-column: 2;
  }

  .post-toc {
    display: block;
    grid-column: 3;
    position: sticky;
    top: 24px;
    align-self: start;
  }
}
