:root {
  --bg: #fbfaf7;
  --fg: #1d1b18;
  --fg-soft: #4a453e;
  --muted: #7a7369;
  --border: #e7e1d6;
  --accent: #8a5a3b;
  --accent-soft: #f1e6da;
  --code-bg: #f4efe6;
  --mark: #f6dfa8;
  --shadow: 0 1px 2px rgba(28, 25, 21, 0.05);
  --serif: Georgia, "Noto Serif SC", "Songti SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

html[data-theme="dark"] {
  --bg: #141311;
  --fg: #e9e4db;
  --fg-soft: #c3bcb1;
  --muted: #948c80;
  --border: #2b2824;
  --accent: #d29b74;
  --accent-soft: #2a211a;
  --code-bg: #1c1a17;
  --mark: #6a5520;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #141311;
    --fg: #e9e4db;
    --fg-soft: #c3bcb1;
    --muted: #948c80;
    --border: #2b2824;
    --accent: #d29b74;
    --accent-soft: #2a211a;
    --code-bg: #1c1a17;
    --mark: #6a5520;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(100% - 2.5rem, 760px);
  margin-inline: auto;
}

/* ---------- header ---------- */
.site-header {
  border-bottom: 1px solid var(--border);
  margin-bottom: 3rem;
}

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

.site-title {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.01em;
}

.site-title:hover {
  text-decoration: none;
  color: var(--accent);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.9rem;
}

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

.site-nav a:hover {
  color: var(--fg);
  text-decoration: none;
}

.nav-new {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent) !important;
  font-size: 0.85rem;
}

.nav-new:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  line-height: 1;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}

.theme-toggle:hover {
  color: var(--fg);
  border-color: var(--muted);
}

/* ---------- intro ---------- */
.intro {
  margin-bottom: 2.5rem;
}

.intro h1 {
  font-family: var(--serif);
  font-size: clamp(1.9rem, 4vw, 2.5rem);
  line-height: 1.25;
  margin: 0 0 0.5rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.intro p {
  margin: 0;
  color: var(--muted);
}

/* ---------- post list ---------- */
.post-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.post-card--entry {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 1.5rem;
  padding: 2rem 0;
  border-top: 1px solid var(--border);
}

.post-card--entry:first-child {
  border-top: 0;
  padding-top: 0.35rem;
}

.post-card__date {
  padding-top: 0.3rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.8;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.post-card__body {
  min-width: 0;
}

.post-card--entry .post-card__title {
  margin-top: 0;
}

.post-card--entry .post-card__media {
  margin-bottom: 0.85rem;
}

.post-card--entry:hover .post-card__title a {
  color: var(--accent);
}

.post-card__title {
  font-family: var(--serif);
  font-size: 1.3rem;
  line-height: 1.4;
  margin: 0 0 0.4rem;
  font-weight: 600;
}

.post-card__title a {
  color: var(--fg);
}

.post-card__title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.post-card__summary {
  margin: 0.5rem 0 0;
  color: var(--fg-soft);
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- post card media ---------- */
.post-card__media {
  display: grid;
  gap: 4px;
  margin-bottom: 0.9rem;
  border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
}

.post-card__media--1 {
  grid-template-columns: 1fr;
}

.post-card__media--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.post-card__media--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.media-tile {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--code-bg);
}

.media-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

.media-tile:hover img {
  transform: scale(1.03);
}

.media-tile--video {
  cursor: default;
}

.media-tile hover-video-player {
  display: block;
  width: 100%;
  height: 100%;
}

hover-video-player:not(:defined) {
  display: none;
}

.media-tile__play {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.6rem;
  height: 2.6rem;
  margin: -1.3rem 0 0 -1.3rem;
  border-radius: 50%;
  background: rgba(18, 16, 14, 0.58);
  backdrop-filter: blur(2px);
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.media-tile__play::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  margin: -0.42rem 0 0 -0.24rem;
  border-left: 0.7rem solid #fff;
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
}

.media-tile--video:hover .media-tile__play {
  opacity: 0;
}

.media-tile__badge {
  position: absolute;
  right: 0.45rem;
  bottom: 0.45rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: rgba(18, 16, 14, 0.62);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1.4;
  pointer-events: none;
  z-index: 2;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.dot {
  opacity: 0.6;
}

.tags a {
  color: var(--muted);
  border-bottom: 1px dotted var(--border);
  margin-right: 0.45rem;
}

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

.empty {
  color: var(--muted);
  font-style: italic;
}

/* ---------- pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 3.5rem 0 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.pagination__info {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- article ---------- */
.post {
  padding-bottom: 2rem;
}

.post__header {
  margin-bottom: 2rem;
}

.post__header h1 {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 1.3;
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.post__cover {
  margin: 0 0 2rem;
}

.post__cover img {
  width: 100%;
  height: auto;
  border-radius: 4px;
}

.toc {
  border-left: 2px solid var(--border);
  padding: 0.25rem 0 0.25rem 1.1rem;
  margin: 0 0 2rem;
  font-size: 0.9rem;
}

.toc__title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.5rem;
  font-weight: 600;
}

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

.toc__item--h3 {
  padding-left: 1rem;
}

.toc a {
  color: var(--fg-soft);
}

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

/* ---------- prose ---------- */
.post__content {
  font-size: 1.02rem;
  color: var(--fg);
}

.post__content h2,
.post__content h3,
.post__content h4 {
  font-family: var(--serif);
  line-height: 1.4;
  margin: 2.4rem 0 0.9rem;
  font-weight: 600;
  scroll-margin-top: 1.5rem;
}

.post__content h2 {
  font-size: 1.5rem;
}

.post__content h3 {
  font-size: 1.25rem;
}

.post__content p {
  margin: 0 0 1.25rem;
}

.post__content ul,
.post__content ol {
  padding-left: 1.4rem;
  margin: 0 0 1.25rem;
}

.post__content li {
  margin-bottom: 0.35rem;
}

.post__content blockquote {
  margin: 1.5rem 0;
  padding: 0.25rem 0 0.25rem 1.1rem;
  border-left: 3px solid var(--accent-soft);
  color: var(--muted);
}

.post__content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 4px;
}

.post__content .post-video {
  width: 100%;
  max-height: 70vh;
  margin: 1.5rem 0;
  border-radius: 4px;
  background: #000;
}

.post__content code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 3px;
}

.post__content pre {
  background: var(--code-bg);
  padding: 1rem 1.1rem;
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.55;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
}

.post__content pre code {
  background: none;
  padding: 0;
  font-size: 0.86rem;
}

.post__content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.post__content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin: 1.5rem 0;
}

.post__content th,
.post__content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

.post__content th {
  background: var(--code-bg);
}

.post__footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  font-size: 0.9rem;
}

.post-nav > div {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.post-nav__next {
  text-align: right;
}

.post-nav__label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.post-nav a {
  color: var(--fg-soft);
}

/* ---------- tags page ---------- */
.tag-cloud {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
}

.tag-cloud a {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg-soft);
  font-size: 0.92rem;
  background: var(--bg);
}

.tag-cloud a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.tag-count {
  color: var(--muted);
  font-size: 0.78rem;
}

/* ---------- archive ---------- */
.archive-year {
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.archive-year summary {
  cursor: pointer;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  padding: 0.35rem 0;
  list-style: none;
}

.archive-year summary::-webkit-details-marker {
  display: none;
}

.archive-year summary::before {
  content: "▸ ";
  color: var(--muted);
}

.archive-year[open] summary::before {
  content: "▾ ";
}

.archive-count {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: 0.35rem;
}

.archive-year ul {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.archive-year li {
  display: flex;
  gap: 1rem;
  padding: 0.3rem 0;
  font-size: 0.94rem;
}

.archive-date {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  font-size: 0.85rem;
  padding-top: 0.1rem;
}

/* ---------- search ---------- */
.search-form {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.search-form input {
  flex: 1;
  font: inherit;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.search-form input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.search-form button {
  font: inherit;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.search-form button:hover {
  opacity: 0.9;
}

.search-status {
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 1.5rem;
}

.search-results .post-card__summary mark {
  background: var(--mark);
  color: inherit;
  padding: 0 0.1em;
}

/* ---------- 404 ---------- */
.not-found {
  text-align: center;
  padding: 4rem 0;
}

.not-found__code {
  font-family: var(--serif);
  font-size: 4rem;
  margin: 0;
  color: var(--border);
  line-height: 1;
}

/* ---------- footer ---------- */
.site-footer {
  margin-top: 4rem;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer p {
  margin: 0.2rem 0;
}

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

/* ---------- highlight.js ---------- */
.hljs-comment,
.hljs-quote {
  color: #8a8377;
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-subst {
  color: #9a5b3c;
}

.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr {
  color: #7a6a2f;
}

.hljs-string,
.hljs-doctag {
  color: #4f7a4a;
}

.hljs-title,
.hljs-section,
.hljs-selector-id {
  color: #3f6396;
  font-weight: 600;
}

.hljs-type,
.hljs-class .hljs-title {
  color: #6b4f9a;
}

.hljs-tag,
.hljs-name,
.hljs-attribute {
  color: #3f6396;
}

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

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

.hljs-built_in,
.hljs-builtin-name {
  color: #6b4f9a;
}

.hljs-meta {
  color: #8a8377;
}

.hljs-deletion {
  background: #f8d7da;
}

.hljs-addition {
  background: #d9f0d3;
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

html[data-theme="dark"] .hljs-keyword,
html[data-theme="dark"] .hljs-selector-tag,
html[data-theme="dark"] .hljs-subst {
  color: #e0a17c;
}

html[data-theme="dark"] .hljs-string,
html[data-theme="dark"] .hljs-doctag {
  color: #9fc98f;
}

html[data-theme="dark"] .hljs-title,
html[data-theme="dark"] .hljs-section {
  color: #8fb6e8;
}

html[data-theme="dark"] .hljs-number,
html[data-theme="dark"] .hljs-literal {
  color: #d6c37a;
}

@media (max-width: 640px) {
  .site-header__inner {
    flex-wrap: wrap;
    padding: 0.75rem 0;
    min-height: 0;
  }

  .site-nav {
    gap: 0.9rem;
  }

  .post-nav {
    grid-template-columns: 1fr;
  }

  .post-nav__next {
    text-align: left;
  }

  .archive-year li {
    flex-direction: column;
    gap: 0.1rem;
  }

  .post-card__media--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .post-card__media--3 .media-tile:first-child {
    grid-column: span 2;
  }

  .post-card--entry {
    grid-template-columns: 1fr;
    gap: 0.55rem;
    padding: 1.75rem 0;
  }

  .post-card__date {
    padding-top: 0;
    font-size: 0.76rem;
  }
}
