/* Paper Blog — Default Theme */

:root, [data-theme="light"] {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #2f2a24;
  --muted: #74685b;
  --line: #ded3c2;
  --link: #6a4b2f;
  --link-hover: #4a3520;
  --accent: #a88a68;
  --shadow: rgba(60, 40, 20, .08);
  --code-bg: #f0ebe0;
  --tag-bg: #ede6d8;
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --paper: #242424;
  --ink: #e0dcd6;
  --muted: #9a9088;
  --line: #3a3632;
  --link: #c9a87c;
  --link-hover: #e0c49a;
  --accent: #8a7560;
  --shadow: rgba(0, 0, 0, .3);
  --code-bg: #2a2826;
  --tag-bg: #332f2a;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #1a1a1a;
    --paper: #242424;
    --ink: #e0dcd6;
    --muted: #9a9088;
    --line: #3a3632;
    --link: #c9a87c;
    --link-hover: #e0c49a;
    --accent: #8a7560;
    --shadow: rgba(0, 0, 0, .3);
    --code-bg: #2a2826;
    --tag-bg: #332f2a;
  }
}

/* ── Reset ─────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Noto Serif SC", "Songti SC", "STSong", "Georgia", serif; line-height: 1.8; -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; transition: color .15s; }
a:hover { color: var(--link-hover); }
img { max-width: 100%; height: auto; border-radius: 8px; }

/* ── Reading Progress Bar ──────────────────────── */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  z-index: 200;
  transition: width .1s linear;
}

/* ── Header ────────────────────────────────────── */

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

.header-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: .3px;
}
.site-title:hover { color: var(--link); }

.site-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}

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

.search-toggle, .theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  transition: color .15s;
}
.search-toggle:hover, .theme-toggle:hover { color: var(--ink); }

/* Theme toggle icon visibility — show current state icon */
.icon-sun { display: inline; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .icon-sun { display: none; }
  [data-theme="auto"] .icon-moon { display: inline; }
}

/* ── Layout ────────────────────────────────────── */

.wrap {
  max-width: 820px;
  margin: 32px auto;
  padding: 0 16px;
}

.paper {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px var(--shadow);
  padding: 36px 34px;
}

@media (max-width: 600px) {
  .paper { padding: 24px 18px; }
  .header-inner { padding: 10px 12px; }
  .site-nav { gap: 10px; font-size: 13px; }
}

/* ── Post List ─────────────────────────────────── */

.post-list { padding: 24px 34px; }

.post-item { padding: 20px 0; }
.post-item + .post-item { border-top: 1px solid var(--line); }

.post-item-title { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.post-item-title a { color: var(--ink); border-bottom: none; }
.post-item-title a:hover { color: var(--link); }

.post-meta { font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.post-meta .sep { opacity: .4; }
.post-meta svg { vertical-align: -2px; flex-shrink: 0; }

.post-excerpt { color: var(--muted); margin: 8px 0 0; font-size: 15px; }

/* ── Tags ──────────────────────────────────────── */

.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--muted);
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 12px;
  transition: all .15s;
}
.tag:hover { color: var(--ink); background: var(--line); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.tag-item { font-size: 15px; }
.tag-item sup { color: var(--accent); font-size: 11px; }

.tag-section { margin-top: 24px; }

/* ── Post Full ─────────────────────────────────── */

.post-header { margin-bottom: 24px; }
.post-header h1 { margin: 0 0 8px; font-size: 32px; }

/* ── Post Cover ────────────────────────────────── */

.post-cover {
  margin: -8px 0 24px;
  border-radius: 8px;
  overflow: hidden;
}
.post-cover img {
  display: block;
  width: 100%;
  border-radius: 8px;
}

/* ── Post Content ──────────────────────────────── */

.post-content h1, .post-content h2, .post-content h3,
.post-content h4, .post-content h5, .post-content h6 {
  margin: 28px 0 12px;
  font-weight: 600;
  letter-spacing: .3px;
}
.post-content h2 { font-size: 24px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.post-content h3 { font-size: 20px; }

.post-content p { margin: 14px 0; }

.post-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  color: var(--muted);
  margin: 20px 0;
  background: var(--code-bg);
  border-radius: 0 8px 8px 0;
}
.post-content blockquote p:first-child { margin-top: 0; }
.post-content blockquote p:last-child { margin-bottom: 0; }

.post-content ul, .post-content ol { padding-left: 24px; }
.post-content li { margin: 6px 0; }

/* Task list checkboxes */
.post-content li input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  vertical-align: -3px;
  margin-right: 6px;
  cursor: default;
  position: relative;
  flex-shrink: 0;
}
.post-content li input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.post-content li input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0px;
  width: 5px;
  height: 9px;
  border: solid var(--paper);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.post-content code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: "JetBrains Mono", "Fira Code", monospace;
}

.post-content pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}
.post-content pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* Code copy button */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: all .15s;
}
pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: var(--ink); border-color: var(--muted); }
.code-copy-btn.copied { color: var(--accent); border-color: var(--accent); }

.post-content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 20px 0;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.post-content th, .post-content td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
}
.post-content th:last-child, .post-content td:last-child { border-right: none; }
.post-content tr:last-child td { border-bottom: none; }
.post-content th { background: var(--code-bg); font-weight: 600; }

.post-content hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 28px 0;
}

.post-content a { border-bottom: 1px dotted var(--accent); }
.post-content a:hover { border-bottom-style: solid; }

/* ── Callouts / Admonitions ────────────────────── */

.callout {
  border-radius: 8px;
  padding: 16px 18px;
  margin: 24px 0;
  border: 1px solid var(--line);
  border-left: 3px solid;
  background: var(--paper);
  box-shadow: 1px 1px 3px rgba(0,0,0,.04);
}
.callout-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.callout-header svg { opacity: .7; }
.callout-body { font-size: 15px; }
.callout-body p:first-child { margin-top: 0; }
.callout-body p:last-child { margin-bottom: 0; }

.callout-note { border-left-color: #8b7355; }
.callout-note .callout-header { color: #8b7355; }

.callout-tip { border-left-color: #6b7c5e; }
.callout-tip .callout-header { color: #6b7c5e; }

.callout-important { border-left-color: #7c6b8a; }
.callout-important .callout-header { color: #7c6b8a; }

.callout-warning { border-left-color: #a08040; }
.callout-warning .callout-header { color: #a08040; }

.callout-caution { border-left-color: #9e5b5b; }
.callout-caution .callout-header { color: #9e5b5b; }

[data-theme="dark"] .callout { background: var(--code-bg); box-shadow: none; }
[data-theme="dark"] .callout-note { border-left-color: #b8a080; }
[data-theme="dark"] .callout-note .callout-header { color: #b8a080; }
[data-theme="dark"] .callout-tip { border-left-color: #8fa87a; }
[data-theme="dark"] .callout-tip .callout-header { color: #8fa87a; }
[data-theme="dark"] .callout-important { border-left-color: #a890b8; }
[data-theme="dark"] .callout-important .callout-header { color: #a890b8; }
[data-theme="dark"] .callout-warning { border-left-color: #c8a860; }
[data-theme="dark"] .callout-warning .callout-header { color: #c8a860; }
[data-theme="dark"] .callout-caution { border-left-color: #c07878; }
[data-theme="dark"] .callout-caution .callout-header { color: #c07878; }

/* ── TOC ───────────────────────────────────────── */

.toc {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: 14px;
}
.toc summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.toc ul { list-style: none; padding-left: 0; margin: 8px 0 0; }
.toc li { margin: 4px 0; }
.toc a { color: var(--muted); }
.toc a:hover { color: var(--ink); }

/* ── Links / Friends ──────────────────────────── */

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.link-card {
  display: block;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
  transition: box-shadow .2s, border-color .2s;
}
.link-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.link-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}
.link-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Related Posts ─────────────────────────────── */

.related-posts {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.related-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.related-posts ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.related-posts li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
}
.related-posts li a { font-size: 14px; }
.related-posts li time { font-size: 12px; color: var(--muted); flex-shrink: 0; margin-left: 12px; }

/* ── Post Nav ──────────────────────────────────── */

.post-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.post-nav-link { max-width: 45%; display: inline-flex; align-items: center; gap: 6px; }
.post-nav-link.next { margin-left: auto; text-align: right; }

/* ── Comments ──────────────────────────────────── */

.comments-title { font-size: 20px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }

/* ── Archive ───────────────────────────────────── */

.archive-year { font-size: 28px; margin: 28px 0 8px; color: var(--accent); }

.archive-list { list-style: none; padding: 0; }
.archive-list li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
}
.archive-list time {
  font-size: 14px;
  color: var(--muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── Pagination ────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  transition: all .15s;
}
.page-link:hover { background: var(--code-bg); color: var(--ink); }
.page-info { color: var(--muted); }

/* ── Search Overlay ────────────────────────────── */

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  backdrop-filter: blur(4px);
}

.search-box {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px var(--shadow);
  padding: 20px;
  width: 90%;
  max-width: 560px;
  position: relative;
}

.search-box input {
  flex: 1;
  min-width: 0;
  padding: 10px 50px 10px 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}
.search-kbd {
  position: absolute;
  right: 52px;
  background: var(--line);
  color: var(--muted);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  pointer-events: none;
}

.search-close {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  transition: all .15s;
}
.search-close:hover { color: var(--ink); border-color: var(--muted); }

#searchResults {
  margin-top: 12px;
  max-height: 400px;
  overflow-y: auto;
}
#searchResults a {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--ink);
  transition: background .1s;
}
#searchResults a:hover { background: var(--code-bg); }
#searchResults .sr-date { font-size: 12px; color: var(--muted); }
#searchResults .sr-empty { padding: 20px; text-align: center; color: var(--muted); }

/* ── Footer ────────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 40px;
  padding: 20px 0;
  font-size: 13px;
  color: var(--muted);
}
.footer-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.footer-inner .sep { opacity: .3; }

/* ── Back to Top ───────────────────────────────── */

.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px var(--shadow);
  color: var(--muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  z-index: 50;
}
.back-to-top.visible { display: flex; }
.back-to-top:hover { color: var(--ink); border-color: var(--muted); }

/* ── Lang Switch ───────────────────────────────── */

.lang-switch {
  display: inline-flex;
  gap: 2px;
  background: var(--code-bg);
  border-radius: 6px;
  padding: 2px;
}
.lang-switch button {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  transition: all .15s;
}
.lang-switch button:hover { color: var(--ink); }
.lang-switch button.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ── Smooth scroll ─────────────────────────────── */

html { scroll-behavior: smooth; scroll-padding-top: 60px; }

/* ── Selection ─────────────────────────────────── */

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

/* ── Print ─────────────────────────────────────── */

@media print {
  .site-header, .site-footer, .search-toggle, .theme-toggle, .toc, .post-nav, .comments, .pagination, .back-to-top, .reading-progress { display: none !important; }
  .paper { box-shadow: none; border: none; }
  body { background: #fff; }
}
