@font-face {
  font-family: "Kingnam Maiyuan";
  src: url("/fonts/KingnamMaiyuan.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-sans: "Kingnam Maiyuan", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

:root,
[data-theme="light"] {
  --bg: #faf6f0;
  --surface: #f5f0eb;
  --text: #2c241c;
  --text-secondary: #6b6258;
  --text-tertiary: #a09888;
  --border: #e5ddd5;
  --border-light: #eee8e0;
  --accent: #b33a26;
  --accent-hover: #8c2b1c;
  --accent-bg: rgba(179, 58, 38, 0.07);
  --code-bg: #ede7e0;
  --quote-border: #d5ccc2;
  --theme-btn: "\2600";
}

[data-theme="dark"],
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181612;
    --surface: #24201c;
    --text: #e2d7ca;
    --text-secondary: #9e9488;
    --text-tertiary: #6e655a;
    --border: #332e28;
    --border-light: #2a2520;
    --accent: #d46a55;
    --accent-hover: #e08570;
    --accent-bg: rgba(212, 106, 85, 0.1);
    --code-bg: #2a2520;
    --quote-border: #403a33;
    --theme-btn: "\2601";
  }
}

[data-theme="dark"] {
  --bg: #181612;
  --surface: #24201c;
  --text: #e2d7ca;
  --text-secondary: #9e9488;
  --text-tertiary: #6e655a;
  --border: #332e28;
  --border-light: #2a2520;
  --accent: #d46a55;
  --accent-hover: #e08570;
  --accent-bg: rgba(212, 106, 85, 0.1);
  --code-bg: #2a2520;
  --quote-border: #403a33;
  --theme-btn: "\2601";
}

* { box-sizing: border-box; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; overflow-y: scroll; }

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  margin: 0;
  transition: background-color .25s, color .25s;
}

::selection { background: var(--accent); color: #fff; }

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

a { color: inherit; text-decoration: none; transition: color .2s; }
a:hover { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

img { max-width: 100%; height: auto; border-radius: 6px; }
video, iframe { width: 100%; height: auto; }
iframe { aspect-ratio: 16/9; }

/* ========== Layout ========== */

.site-header {
  max-width: 720px; margin: 0 auto; padding: 2.5rem 1.25rem 0;
  display: flex; justify-content: space-between; align-items: center;
}

.site-brand {
  font-size: 1rem; font-weight: 500; letter-spacing: .02em;
  color: var(--text);
}
.site-brand:hover { color: var(--accent); }

.site-nav { display: flex; gap: 1.25rem; list-style: none; padding: 0; margin: 0; }
.site-nav a { font-size: .85rem; color: var(--text-secondary); }
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--text); }

.theme-toggle {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; padding: .25rem; line-height: 1;
  color: var(--text-secondary); border-radius: 4px;
  transition: color .2s;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main {
  max-width: 720px; margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  min-height: calc(100vh - 200px);
}
main > :first-child { margin-top: 0; }

.site-footer {
  max-width: 720px; margin: 0 auto; padding: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--text-tertiary); font-size: .8rem;
  display: flex; gap: 1rem; flex-wrap: wrap;
}
.site-footer a { color: var(--text-secondary); }
.site-footer a:hover { color: var(--accent); }

/* ========== Typography ========== */

.page-title {
  font-size: 1.5rem; font-weight: 500; letter-spacing: .01em;
  margin: 2rem 0 1.25rem; line-height: 1.3;
}

.section-title {
  font-size: .7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-tertiary); margin: 2.5rem 0 .75rem;
}

/* ========== Home hero ========== */

.home-hero { margin: 1.5rem 0 1rem; }
.home-hero h1 {
  font-size: 1.6rem; font-weight: 500; letter-spacing: .02em;
  line-height: 1.2; margin: 0 0 .35rem;
}
.home-hero p { font-size: .9rem; color: var(--text-secondary); margin: 0; }

/* ========== Archive list ========== */

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

.archive-item {
  display: flex; gap: .75rem; align-items: baseline;
  padding: .6rem 0; border-bottom: 1px solid var(--border-light);
}
.archive-list--plain .archive-item { border-bottom: none; }
.archive-item:first-child { padding-top: 0; }
.archive-item-date {
  font-size: .78rem; color: var(--text-tertiary);
  font-variant-numeric: tabular-nums; white-space: nowrap; flex-shrink: 0;
  min-width: 5em;
}
.archive-item-title { font-size: .95rem; line-height: 1.45; }
.archive-item-title a { color: var(--text); }
.archive-item-title a:hover { color: var(--accent); }
.archive-item-tags { display: inline-flex; gap: .3rem; margin-left: .5rem; }

.home-articles .archive-item {
  border-bottom: none; padding: .25rem 0;
}

/* ========== Post entries (full) ========== */

.post-entries { display: flex; flex-direction: column; }
.post-entry { padding: 1.25rem 0; border-bottom: 1px solid var(--border-light); }
.post-entry:first-of-type { padding-top: 0; }
.post-entry-header { display: flex; align-items: center; gap: .5rem; margin-bottom: .2rem; flex-wrap: wrap; }
.post-entry-date { font-size: .8rem; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.post-entry-tags { display: flex; gap: .25rem; flex-wrap: wrap; }
.post-entry-tag {
  font-size: .7rem; color: var(--text-tertiary);
  padding: 1px 7px; background: var(--border-light); border-radius: 3px;
  transition: all .2s;
}
.post-entry-tag:hover { background: var(--accent-bg); color: var(--accent); }
.post-entry-title { font-size: 1.1rem; font-weight: 500; line-height: 1.4; margin-bottom: .35rem; }
.post-entry-title a { color: var(--text); }
.post-entry-title a:hover { color: var(--accent); }
.post-entry-summary { font-size: .88rem; color: var(--text-secondary); line-height: 1.65; }
.post-entry-summary p { margin: 0; }
.post-entry-summary p + p { margin-top: .5rem; }
.post-entry-summary a { color: var(--accent); }

.home-more { margin-top: 1rem; font-size: .88rem; }
.home-more a { color: var(--text-secondary); }
.home-more a:hover { color: var(--accent); }

/* ========== Post page ========== */

.post-page { max-width: 680px; margin: 1.5rem auto 0; }
.post-header { margin-bottom: 1.5rem; }
.post-title {
  font-size: 1.5rem; font-weight: 500; line-height: 1.3;
  margin: 0 0 .5rem;
}
.post-source { font-size: .85rem; color: var(--text-secondary); margin-bottom: .5rem; }
.post-source a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.post-meta {
  font-size: .82rem; color: var(--text-secondary);
  display: flex; flex-wrap: wrap; gap: .35rem .75rem;
}
.post-meta time { font-variant-numeric: tabular-nums; }
.post-meta-divider { color: var(--text-tertiary); }
.post-meta a { color: var(--text-secondary); }
.post-meta a:hover { color: var(--accent); }

.post-content { font-size: .95rem; line-height: 1.75; color: var(--text); }
.post-content > * + * { margin-top: .85rem; }
.post-content h2 {
  font-size: 1.2rem; font-weight: 500; margin: 2rem 0 .6rem; line-height: 1.3;
}
.post-content h3 { font-size: 1.05rem; font-weight: 500; margin: 1.5rem 0 .4rem; }
.post-content h4, .post-content h5, .post-content h6 {
  font-size: .95rem; font-weight: 600; margin: 1.25rem 0 .4rem;
}
.post-content p { line-height: 1.75; margin: 0; }
.post-content p + p { margin-top: .6rem; }
.post-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.post-content a:hover { text-decoration-thickness: 2px; }
.post-content blockquote {
  margin: 1rem 0; padding-left: 1rem;
  border-left: 3px solid var(--quote-border);
  color: var(--text-secondary);
}
.post-content blockquote p { line-height: 1.65; }
.post-content ul, .post-content ol { padding-left: 1.25rem; margin: 0; }
.post-content li + li { margin-top: .2rem; }
.post-content img { display: block; max-width: 100%; border-radius: 6px; margin: 1.25rem auto; }
.post-content pre {
  background: var(--code-bg); border-radius: 6px;
  padding: .9rem 1rem; overflow-x: auto;
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.5;
  margin: 1rem 0;
}
.post-content code {
  font-family: var(--font-mono); font-size: .85em;
  background: var(--code-bg); padding: 2px 5px; border-radius: 3px;
  word-break: break-word;
}
.post-content pre code { background: transparent; padding: 0; word-break: normal; }

/* ========== Post nav ========== */

.post-nav {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 2.5rem; padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.post-nav a { flex: 1; padding: .6rem .75rem; border-radius: 4px; transition: background .2s; }
.post-nav a:hover { background: var(--border-light); }
.post-nav-label { font-size: .72rem; color: var(--text-tertiary); display: block; margin-bottom: .15rem; }
.post-nav-title { font-size: .88rem; color: var(--text); line-height: 1.4; }
.post-nav-next { text-align: right; }

/* ========== Tags ========== */

.tag, .post-tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; font-size: .72rem; font-weight: 500;
  color: var(--text-secondary);
  background: var(--border-light); border-radius: 4px;
  transition: all .2s; text-decoration: none;
}
.tag:hover, .post-tag:hover { background: var(--accent-bg); color: var(--accent); }

.post-tags ul { display: flex; flex-wrap: wrap; gap: .3rem; list-style: none; padding: 0; margin: 0; }
.post-tags li { display: inline-block; }

.tags-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.tags-list ul { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; padding: 0; margin: 0; }

/* ========== Projects ========== */

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}
.home-projects { display: flex; flex-direction: column; gap: .5rem; }
.project-card { margin: 0; }
.project-card img {
  width: 100%; aspect-ratio: 16/10; object-fit: cover;
  border-radius: 6px; margin-bottom: .5rem;
  transition: transform .25s;
}
.project-card:hover img { transform: translateY(-2px); }
.project-card-title { font-size: .95rem; font-weight: 500; margin-bottom: .2rem; }
.project-card-title a { color: var(--text); }
.project-card-title a:hover { color: var(--accent); }
.project-card-desc { font-size: .82rem; color: var(--text-secondary); line-height: 1.5; margin: 0; }

/* ========== Archive layout ========== */

.archive-layout { display: flex; gap: 2.5rem; align-items: flex-start; }
.archive-layout > :first-child { flex: 1; min-width: 0; }
.archive-sidebar { width: 180px; flex-shrink: 0; }
.archive-sidebar h2 {
  font-size: .7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-tertiary); margin: 0 0 .5rem;
}

/* ========== Misc ========== */

table { margin: 1rem 0; border-collapse: collapse; width: 100%; }
table td, table th { padding: .4rem .6rem; border-bottom: 1px solid var(--border); text-align: left; }

.message-box {
  background: var(--border-light); border: 1px solid var(--border);
  border-radius: 6px; padding: .75rem 1rem; margin: 1rem 0;
}

.clippings-intro { font-size: .9rem; color: var(--text-secondary); margin-bottom: 1rem; line-height: 1.65; }

/* ========== Responsive ========== */

@media (max-width: 700px) {
  .site-header { padding: 1.25rem 1rem 0; }
  main { padding: 1rem 1rem 2rem; }
  .site-header { flex-wrap: wrap; gap: .4rem; }
  .site-nav { gap: .9rem; }
  .archive-item { flex-direction: column; gap: .15rem; padding: .5rem 0; }
  .archive-layout { flex-direction: column; gap: 1rem; }
  .archive-sidebar { width: auto; }
  .post-nav { flex-direction: column; gap: .5rem; }
  .post-nav-next { text-align: left; }
  .project-grid { grid-template-columns: 1fr; }
  .post-page { margin-top: .5rem; }
}
