/* ============================================================
 *  Kirisame · 极简扁平样式
 *  设计参考 https://www.idol.ac.cn/
 *  特性：
 *    - 顶部双语导航（中文 + 小字英文），无 Hero
 *    - 内容直接铺开，靠留白和分隔线组织
 *    - 极轻阴影 / 极细分隔线 / 单一强调色
 * ============================================================ */

/* ---------- 1. 设计令牌 ---------- */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --font-serif: "Iowan Old Style", "Apple Garamond", Baskerville, "Times New Roman",
                "Source Serif Pro", "Songti SC", serif;

  --radius: 2px;                              /* 几乎所有圆角归零 = 扁平 */
  --transition: 180ms ease;
  --maxw: 1080px;
  --maxw-content: 720px;
}

/* ---------- 2. 亮 / 暗主题 ---------- */
:root,
:root[data-theme="light"] {
  --bg:           #fbfaf7;                    /* 米白 */
  --bg-soft:      #f3f1ec;
  --bg-elevated:  #ffffff;
  --fg:           #1a1a1a;
  --fg-soft:      #4a4a4a;
  --fg-muted:     #8a8a8a;
  --border:       #e6e3dc;
  --border-soft:  #efedea;
  --accent:       #b73e3e;                    /* 砖红 */
  --accent-soft:  rgba(183, 62, 62, 0.08);
  --code-bg:      #f3f1ec;
  --selection:    #f3dada;
}
:root[data-theme="dark"] {
  --bg:           #121212;
  --bg-soft:      #1a1a1a;
  --bg-elevated:  #1c1c1c;
  --fg:           #ededed;
  --fg-soft:      #b8b8b8;
  --fg-muted:     #7a7a7a;
  --border:       #262626;
  --border-soft:  #1e1e1e;
  --accent:       #e87a7a;
  --accent-soft:  rgba(232, 122, 122, 0.12);
  --code-bg:      #1a1a1a;
  --selection:    #5a2a2a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg:           #121212;
    --bg-soft:      #1a1a1a;
    --bg-elevated:  #1c1c1c;
    --fg:           #ededed;
    --fg-soft:      #b8b8b8;
    --fg-muted:     #7a7a7a;
    --border:       #262626;
    --border-soft:  #1e1e1e;
    --accent:       #e87a7a;
    --accent-soft:  rgba(232, 122, 122, 0.12);
    --code-bg:      #1a1a1a;
    --selection:    #5a2a2a;
  }
}

/* ---------- 3. 重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition), color var(--transition);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
::selection { background: var(--selection); color: var(--fg); }
img { max-width: 100%; height: auto; display: block; }
a { color: var(--fg); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent); }
button { font: inherit; cursor: pointer; }

/* ---------- 4. 顶部导航（核心） ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
}
.site-nav-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 32px;
}
.site-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--fg);
  flex-shrink: 0;
}
.site-brand:hover { color: var(--fg); }
.site-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.site-brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
}
.site-brand-sub {
  font-size: 10px;
  color: var(--fg-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

.site-nav-links {
  display: flex;
  margin-left: auto;
  align-items: stretch;
  list-style: none;
  padding: 0;
  gap: 8px;
  height: 100%;
}
.site-nav-links li { display: flex; align-items: stretch; }
.site-nav-links a {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 12px;
  color: var(--fg-soft);
  position: relative;
  transition: color var(--transition);
  min-width: 64px;
}
.site-nav-links a .zh {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
}
.site-nav-links a .en {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-top: 2px;
  font-family: var(--font-mono);
  line-height: 1;
}
.site-nav-links a:hover { color: var(--accent); }
.site-nav-links a:hover .en { color: var(--accent); }
.site-nav-links a.is-active { color: var(--accent); }
.site-nav-links a.is-active .en { color: var(--accent); }
.site-nav-links a.is-active::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: 0;
  height: 2px;
  background: var(--accent);
}

.site-nav-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 12px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
.nav-icon-btn {
  background: transparent;
  border: 0;
  color: var(--fg-soft);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}
.nav-icon-btn:hover { color: var(--accent); background: var(--accent-soft); }
.nav-icon-btn svg { width: 16px; height: 16px; }
.nav-mobile-toggle { display: none; }

@media (max-width: 860px) {
  .site-nav-inner { padding: 0 16px; height: 56px; gap: 16px; }
  .site-brand-sub { display: none; }
  .site-nav-links {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    height: auto;
    display: none;
    padding: 8px 0;
    gap: 0;
  }
  .site-nav-links.is-open { display: flex; }
  .site-nav-links a { padding: 12px 24px; flex-direction: row; gap: 8px; }
  .site-nav-links a .en { margin-top: 0; }
  .site-nav-links a.is-active::after { display: none; }
  .site-nav-links a.is-active { background: var(--accent-soft); }
  .nav-mobile-toggle { display: inline-flex; }
  .site-nav-actions { margin-left: auto; padding-left: 8px; border-left: 0; }
}

/* ---------- 5. 背景图（覆盖默认底色） ---------- */
body.has-custom-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image: var(--custom-bg);
  background-size: var(--custom-bg-size, cover);
  background-position: var(--custom-bg-pos, center center);
  background-repeat: no-repeat;
  background-attachment: fixed;
  /* 兜底：CSS 里的 url() 是相对 CSS 文件解析的，但我们在 main.js 里
     已经用 location.href 转成绝对 URL，所以下面这行仅作 fallback。
     真实生效的是通过 --custom-bg 注入的 url(http://localhost:8765/...)  */
}
body.has-custom-bg::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(0, 0, 0, var(--custom-bg-overlay, 0.35));
  transition: background var(--transition);
}
:root[data-theme="light"] body.has-custom-bg::after { background: rgba(255, 255, 255, 0.12); }

/* ---------- 6. 内容容器 ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 32px; }
.wrap-content { max-width: var(--maxw-content); margin: 0 auto; padding: 0 24px; }
@media (max-width: 720px) {
  .wrap, .wrap-content { padding: 0 16px; }
}

.page { padding: 48px 0 80px; }
.page-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--fg-soft);
  margin: 0 0 32px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.page-title .en {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-weight: 400;
}

/* ---------- 7. 首页：欢迎语 + 文章列表 ---------- */
.intro {
  padding: 56px 0 40px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 32px;
}
.intro h1 {
  font-family: var(--font-serif);
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 500;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.intro p {
  color: var(--fg-soft);
  margin: 0;
  max-width: 600px;
  font-size: 14px;
}

.section-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-soft);
}

.post-list { list-style: none; padding: 0; margin: 0; }
.post-item {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 24px;
  align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-soft);
  transition: background var(--transition);
}
.post-item:hover { background: var(--accent-soft); }
.post-item time {
  color: var(--fg-muted);
  font-size: 12px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.post-item-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--fg);
  margin: 0;
  line-height: 1.5;
}
.post-item-title a { color: inherit; }
.post-item-title a:hover { color: var(--accent); }
.post-item-cat {
  font-size: 11px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
@media (max-width: 640px) {
  .post-item { grid-template-columns: 1fr; gap: 4px; padding: 14px 0; }
  .post-item time { font-size: 11px; }
  .post-item-cat { display: none; }
}

/* 分页 */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 48px;
}
.pagination a, .pagination span {
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--fg-soft);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.pagination a:hover { color: var(--accent); border-color: var(--accent); }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 8. 归档页 ---------- */
.archive-year { margin: 0 0 32px; }
.archive-year h2 {
  font-size: 28px;
  font-family: var(--font-serif);
  font-weight: 400;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}
.archive-list { list-style: none; padding: 0; margin: 0; }
.archive-item {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border-soft);
  font-size: 14px;
  align-items: baseline;
}
.archive-item time {
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}
.archive-item a { color: var(--fg-soft); }
.archive-item a:hover { color: var(--accent); }
.archive-item .cat {
  font-size: 10px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---------- 9. 分类页 ---------- */
.cat-list { list-style: none; padding: 0; margin: 0; }
.cat-group { margin: 0 0 32px; }
.cat-group h2 {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 12px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.cat-group h2 .count {
  color: var(--fg-muted);
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 400;
  letter-spacing: 0.08em;
}

/* ---------- 10. 友链 ---------- */
.friends-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1px;
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--border-soft);
  border: 1px solid var(--border-soft);
}
.friend-card {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--bg);
  color: var(--fg);
  transition: background var(--transition);
  align-items: center;
}
.friend-card:hover { background: var(--accent-soft); }
.friend-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}
.friend-avatar img { width: 100%; height: 100%; object-fit: cover; }
.friend-info { min-width: 0; }
.friend-name { font-weight: 500; margin: 0 0 2px; font-size: 14px; }
.friend-desc {
  color: var(--fg-muted);
  font-size: 12px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

/* ---------- 11. 关于页 ---------- */
.about-grid {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 24px;
  align-items: start;
  margin-bottom: 40px;
}
.about-avatar {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  font-weight: 500;
  color: var(--fg-muted);
  font-family: var(--font-serif);
  flex-shrink: 0;
  overflow: hidden;
}
.about-avatar img { width: 100%; height: 100%; object-fit: cover; }
.about-name { font-size: 20px; margin: 0 0 4px; font-weight: 500; }
.about-bio  { color: var(--fg-soft); margin: 0 0 12px; font-size: 14px; }
.about-meta { color: var(--fg-muted); font-size: 12px; font-family: var(--font-mono); }

.about-content {
  font-size: 15px;
  line-height: 1.85;
  border-top: 1px solid var(--border-soft);
  padding-top: 24px;
}
.about-content p { margin: 0 0 16px; }
.about-content h2 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin: 32px 0 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-soft);
  text-transform: uppercase;
}
.about-content ul { padding-left: 20px; margin: 0 0 16px; }
.about-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 1px 6px;
}

/* ---------- 12. 文章详情 ---------- */
.article { padding: 56px 0 60px; }
.article-header { margin-bottom: 40px; }
.article-header h1 {
  font-family: var(--font-serif);
  font-size: clamp(24px, 3.5vw, 32px);
  font-weight: 500;
  letter-spacing: -0.005em;
  margin: 0 0 16px;
  line-height: 1.4;
}
.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 12px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-soft);
}
.article-meta a { color: var(--fg-soft); }
.article-meta a:hover { color: var(--accent); }
.article-meta .sep { opacity: 0.4; }

.article-content { font-size: 15px; line-height: 1.9; }
.article-content h2 {
  font-size: 20px;
  font-weight: 500;
  font-family: var(--font-serif);
  margin: 2em 0 0.8em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border-soft);
}
.article-content h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 1.6em 0 0.6em;
}
.article-content p { margin: 1em 0; }
.article-content ul, .article-content ol { padding-left: 1.6em; margin: 1em 0; }
.article-content li { margin: 0.3em 0; }
.article-content blockquote {
  margin: 1.5em 0;
  padding: 8px 16px;
  border-left: 2px solid var(--accent);
  color: var(--fg-soft);
  background: var(--accent-soft);
}
.article-content code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 2px 6px;
}
.article-content pre {
  background: var(--code-bg);
  padding: 16px 18px;
  overflow-x: auto;
  margin: 1.4em 0;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid var(--border-soft);
}
.article-content pre code { background: transparent; padding: 0; }
.article-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.4em 0;
  font-size: 13px;
}
.article-content th, .article-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.article-content th { background: var(--bg-soft); font-weight: 600; }
.article-content a { color: var(--accent); border-bottom: 1px solid transparent; }
.article-content a:hover { border-bottom-color: var(--accent); }
.article-content img { margin: 1.4em auto; }

/* 目录 */
.toc {
  position: fixed;
  top: 96px;
  right: max(24px, calc(50vw - var(--maxw-content) / 2 - 220px));
  width: 200px;
  font-size: 12px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
.toc-title {
  color: var(--fg-muted);
  font-weight: 600;
  margin: 0 0 8px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.toc ul { list-style: none; padding: 0; margin: 0; border-left: 1px solid var(--border); }
.toc li a {
  display: block;
  padding: 4px 12px;
  color: var(--fg-muted);
  border-left: 1px solid transparent;
  margin-left: -1px;
  line-height: 1.4;
}
.toc li a:hover, .toc li a.is-active { color: var(--accent); border-left-color: var(--accent); }
.toc .level-3 { padding-left: 20px; }
@media (max-width: 1200px) { .toc { display: none; } }

/* 阅读进度 */
.reading-progress {
  position: fixed;
  top: 64px; left: 0; right: 0;
  height: 1px;
  background: var(--accent);
  z-index: 99;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 60ms linear;
}
@media (max-width: 860px) { .reading-progress { top: 56px; } }

/* 回到顶部 */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), color var(--transition), border-color var(--transition);
  z-index: 50;
}
.back-to-top.is-visible { opacity: 1; pointer-events: auto; }
.back-to-top:hover { color: var(--accent); border-color: var(--accent); }
.back-to-top svg { width: 14px; height: 14px; }

/* ---------- 13. 搜索弹窗 ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
.modal-backdrop.is-open { display: flex; }
.modal {
  background: var(--bg-elevated);
  width: min(560px, 92vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; gap: 12px; }
.modal-header svg { width: 14px; height: 14px; color: var(--fg-muted); flex-shrink: 0; }
.modal-header input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-size: 14px;
  font-family: var(--font-sans);
}
.modal-header input::placeholder { color: var(--fg-muted); }
.modal-close {
  background: transparent; border: 0; color: var(--fg-muted);
  padding: 4px; border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
}
.modal-close:hover { color: var(--fg); }
.modal-body { overflow-y: auto; }
.search-result { padding: 10px 18px; display: block; color: var(--fg); border-bottom: 1px solid var(--border-soft); }
.search-result:hover { background: var(--accent-soft); }
.search-result-title { font-size: 14px; }
.search-result-meta { color: var(--fg-muted); font-size: 11px; font-family: var(--font-mono); margin-top: 2px; letter-spacing: 0.04em; }
.search-empty { padding: 20px; color: var(--fg-muted); text-align: center; font-size: 13px; }

/* ---------- 14. 页脚 ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 32px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.site-footer .sep { margin: 0 10px; opacity: 0.4; }
.site-footer a { color: var(--fg-muted); }
.site-footer a:hover { color: var(--accent); }

/* ---------- 15. 代码高亮（柔和版） ---------- */
.hljs { background: transparent; color: var(--fg-soft); display: block; }
.hljs-comment, .hljs-quote { color: var(--fg-muted); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-name { color: #c792ea; }
.hljs-string, .hljs-attr, .hljs-template-tag, .hljs-template-variable { color: #c3e88d; }
.hljs-number, .hljs-literal { color: #f78c6c; }
.hljs-title, .hljs-section, .hljs-function .hljs-title { color: #82aaff; }
.hljs-tag, .hljs-attribute, .hljs-symbol { color: #ffcb6b; }
.hljs-meta { color: #ff5370; }
