/* ------------------------------------------------------------------
   cf-blog main stylesheet
   Design goals: clean, modern, readable, dark-mode aware, fast.
   No external CSS frameworks. Plain CSS, mobile-first.
------------------------------------------------------------------ */

:root {
  --bg:        #fbfbfd;
  --bg-soft:   #f3f4f7;
  --panel:     #ffffff;
  --border:    #e5e7eb;
  --text:      #1a1d23;
  --muted:     #5b6471;
  --accent:    #2f6df6;
  --accent-2:  #6b4dff;
  --code-bg:   #0f1115;
  --code-text: #e6edf3;
  --success:   #16a34a;
  --danger:    #dc2626;
  --shadow:    0 1px 2px rgba(20,25,40,.04), 0 4px 16px rgba(20,25,40,.06);
  --radius:    12px;
  --maxw:      880px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0e1116;
    --bg-soft:  #161a21;
    --panel:    #131820;
    --border:   #232a36;
    --text:     #e6e9ef;
    --muted:    #97a0af;
    --accent:   #6b8dff;
    --accent-2: #9d7dff;
    --code-bg:  #0a0d12;
    --code-text:#e6edf3;
    --shadow:   0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

img { max-width: 100%; height: auto; border-radius: 6px; }

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

/* --- layout ---------------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 20px;
  display: flex; align-items: center; gap: 18px;
}
.site-title {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.site-title:hover { text-decoration: none; }
.site-tagline { color: var(--muted); font-size: 13px; margin-left: 6px; }
.site-nav { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.site-nav a {
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
}
.site-nav a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.site-nav a.active { color: var(--text); background: var(--bg-soft); }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  padding: 22px 20px;
  text-align: center;
}

/* --- hero (home) ----------------------------------------------------- */

.hero {
  padding: 28px 0 18px;
}
.hero h1 {
  font-size: clamp(28px, 4vw, 38px);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.hero p { color: var(--muted); margin: 0; max-width: 56ch; }

/* --- post list ------------------------------------------------------- */

.post-list { display: grid; gap: 14px; margin-top: 18px; }
.post-card {
  display: block;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.post-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  box-shadow: var(--shadow);
  text-decoration: none;
}
.post-card h2 {
  font-size: 19px;
  margin: 0 0 6px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.post-card .meta {
  font-size: 12px; color: var(--muted);
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 6px;
}
.post-card .excerpt { color: var(--muted); margin: 0; }
.post-card .cover {
  width: 100%; height: 180px; object-fit: cover; border-radius: 8px; margin-bottom: 10px;
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--border);
}
.tag.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- post page ------------------------------------------------------- */

.post-page { padding-top: 12px; }
.post-page h1 {
  font-size: clamp(28px, 4.2vw, 40px);
  letter-spacing: -0.02em;
  margin: 8px 0 12px;
}
.post-meta {
  color: var(--muted);
  font-size: 13px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 18px;
}
.post-cover {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: var(--radius);
  margin: 6px 0 18px;
}

.prose { line-height: 1.8; font-size: 17px; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  letter-spacing: -0.01em;
  margin: 1.6em 0 0.6em;
}
.prose h2 { font-size: 24px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.prose h3 { font-size: 20px; }
.prose p { margin: 0.8em 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose blockquote {
  margin: 1.2em 0;
  padding: 8px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  border-radius: 6px;
  color: var(--muted);
}
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.prose code:not(pre code) {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

/* --- code block with copy button ----------------------------------- */

.codeblock {
  position: relative;
  margin: 1.2em 0;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #1d2230;
}
.codeblock pre {
  margin: 0;
  padding: 16px 16px 16px 16px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.codeblock code { font-family: inherit; }
.cb-lang {
  position: absolute; top: 8px; left: 12px;
  font-size: 11px;
  color: #9aa4b1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  pointer-events: none;
}
.cb-copy {
  position: absolute; top: 8px; right: 10px;
  font-size: 12px;
  background: rgba(255,255,255,0.07);
  color: #e6edf3;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s ease;
}
.cb-copy:hover { background: rgba(255,255,255,0.15); }
.cb-copy.copied { background: #16a34a; border-color: #16a34a; color: #fff; }

/* --- admin ---------------------------------------------------------- */

.login-card {
  max-width: 380px;
  margin: 60px auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 14px; font-size: 22px; }
.field { display: block; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, .textarea, select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; line-height: 1.6; min-height: 320px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
}
.btn:hover { background: color-mix(in srgb, var(--accent) 12%, var(--bg-soft)); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }

.admin-grid { display: grid; grid-template-columns: 280px 1fr; gap: 20px; }
@media (max-width: 820px) { .admin-grid { grid-template-columns: 1fr; } }

.admin-side {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; position: sticky; top: 70px; align-self: start;
  max-height: calc(100vh - 90px); overflow: auto;
}
.admin-side h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 14px 0 6px; }
.admin-side h3:first-child { margin-top: 0; }
.admin-side .post-row {
  display: block; padding: 8px 10px; border-radius: 6px; font-size: 14px;
  color: var(--text); margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.admin-side .post-row:hover { background: var(--bg-soft); text-decoration: none; }
.admin-side .post-row.active { background: var(--bg-soft); color: var(--accent); }
.admin-side .post-row .status-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--success); margin-right: 6px; }
.admin-side .post-row.draft .status-dot { background: #f59e0b; }

.admin-main { min-width: 0; }
.editor-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.editor-bar .grow { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tab {
  padding: 8px 14px; cursor: pointer; color: var(--muted); font-size: 14px;
  border: none; background: transparent; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.preview {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; min-height: 320px;
}

.link-card {
  border: 1px solid var(--border); background: var(--panel); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.link-card .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.link-card .favicon { width: 16px; height: 16px; border-radius: 3px; }
.link-card a.title { font-weight: 600; color: var(--text); }
.link-card a.title:hover { color: var(--accent); text-decoration: none; }
.link-card .meta { color: var(--muted); font-size: 12px; }
.link-card .desc { color: var(--muted); font-size: 14px; margin-top: 6px; }

.toast {
  position: fixed; right: 18px; bottom: 18px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; box-shadow: var(--shadow);
  font-size: 14px; z-index: 100;
  transform: translateY(20px); opacity: 0; transition: all .25s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.toast.success { color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, var(--border)); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.search {
  position: relative; flex: 1; max-width: 320px;
}
.search input { width: 100%; padding: 8px 10px 8px 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-soft); color: var(--text); }
.search::before { content: "🔍"; position: absolute; left: 9px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: 0.6; }

.empty {
  border: 1px dashed var(--border); border-radius: var(--radius); padding: 28px;
  text-align: center; color: var(--muted);
}

@media (max-width: 600px) {
  .container { padding: 18px 14px 60px; }
  .site-header-inner { padding: 12px 14px; }
  .prose { font-size: 16px; }
  .admin-side { position: static; max-height: none; }
}
