/* Atomrose —— 极简文字为主，黑白灰（暖调纸感，不是纯白纯黑） */

:root {
  --bg: #fbfaf8;          /* 暖白，像纸；纯白在亮屏上会晃眼 */
  --fg: #221f1c;          /* 暖墨；纯黑对比太硬，长文容易累 */
  --muted: #6f685f;
  --line: #e7e2da;
  --soft: #f4f1eb;
  /* 文学版式用的字体：西文和数字用 Times New Roman（等高数字，不会上下错落），
     中文优先仿宋（笔画细、书卷气），没有再退回宋体系。
     注意别把 Georgia 放前面——它的数字是旧式写法，跟中文排一起会歪。 */
  --serif: "Times New Roman", "FangSong", "STFangsong", "仿宋",
           "FangSong_GB2312", "Songti SC", "STSong", SimSun, serif;
  --max: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --fg: #e8e4de;
    --muted: #8f877c;
    --line: #2b2825;
    --soft: #1b1917;
  }
}

* { box-sizing: border-box; }

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

/* 视觉上不显示，但读屏软件和搜索引擎照样能读到。
   四个 index 页的 h1 用它：页面上不想出现大标题，但语义要保留。 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  padding: 0 1.25rem;
  background: var(--bg);
  color: var(--fg);
  /* 17px / 1.9：中文长文在这个字号行高下最松快；字距加一点点切开笔画。
     46rem 的版心在 17px 下大约是 46 个汉字一行，正好在舒适区。 */
  font: 17px/1.9 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
        "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0.012em;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--max); margin: 0 auto; }

/* ── 页头 ─────────────────────────────── */

.site-head {
  border-bottom: 1px solid var(--line);
  padding: 1.5rem 0 1.7rem;
  margin-bottom: 2.75rem;
}

.site-head .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}

/* 站名两行：QY博客 与右边导航底部对齐，AtomRose.com 挂在它下面一行。
   跟导航同一套字形（不加粗、同色），只有字号更大。 */
.brand {
  position: relative;
  display: inline-block;
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.25;
  color: var(--muted);
  text-decoration: none;
}

.brand:hover { color: var(--fg); }

.brand-site {
  position: absolute;
  left: 0;
  top: calc(100% + 1px);
  font-size: 0.66rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--muted);
  white-space: nowrap;
}

.site-head nav a {
  margin-left: 1.1rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.94rem;
}

.site-head nav a:first-child { margin-left: 0; }
.site-head nav a:hover { color: var(--fg); }
.site-head nav a.on { color: var(--fg); }

/* ── 正文 ─────────────────────────────── */

/* 标题层级：只靠字号、字重、颜色拉开，不加下划线也不加背景块。
   h1 = 文章标题（不加粗），h2/h3 是正文章节，h4~h6 逐级退到灰色。
   markdown 里的 # 到 ###### 全都映射到这儿，不会再掉回浏览器默认样式。 */
h1 {
  font-size: 1.5rem;
  line-height: 1.4;
  margin: 0 0 1.5rem;
  font-weight: 400;
  letter-spacing: 0.01em;
}

h2 {
  font-size: 1.16rem;
  line-height: 1.5;
  margin: 3rem 0 0.9rem;
  font-weight: 600;
}

h3 {
  font-size: 1.02rem;
  line-height: 1.55;
  margin: 2.2rem 0 0.6rem;
  font-weight: 600;
}

h4 {
  font-size: 0.98rem;
  line-height: 1.6;
  margin: 1.9rem 0 0.5rem;
  font-weight: 600;
}

h5 {
  font-size: 0.94rem;
  line-height: 1.6;
  margin: 1.7rem 0 0.4rem;
  font-weight: 600;
  color: var(--muted);
}

h6 {
  font-size: 0.9rem;
  line-height: 1.6;
  margin: 1.5rem 0 0.4rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ── 文学版式（随笔 / 自选集） ─────────── */
/* 由 build.pyw 在 <body> 上打 class="prose" 决定，映射表在 tools/build.pyw 的 SECTIONS。
   只改正文（article）的字体和排版；页头导航、列表、卡片仍然是无衬线，
   外层框架保持原样。想改哪个栏目用哪种版式，改 build.pyw 那张表。 */
body.prose article {
  font-family: var(--serif);
  font-size: 17.5px;
  line-height: 2.05;
  letter-spacing: 0.02em;
  /* 颜色不单独设，跟随全站默认的 --fg */
  text-align: justify;
  text-justify: inter-ideograph;
}

/* 文学/随笔的标题一律居中。想只让 h1/h2 居中，把下面 h3~h6 那几行删掉即可。 */
body.prose article h1,
body.prose article h2,
body.prose article h3,
body.prose article h4,
body.prose article h5,
body.prose article h6 {
  font-family: var(--serif);
  text-align: center;
}

/* ── 纸张效果（所有文章页，不分栏目） ─── */
/* 页面底色不另设，跟全站一致，免得从索引页点进来时背景突变；
   只有正文区铺一层极浅的纸白，靠那点色差和几乎看不见的投影分出来。 */
body.prose article,
body.doc article {
  background: #fcfbf9;
  padding: 3rem 3.4rem;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 28px rgba(0, 0, 0, 0.03);
}

@media (prefers-color-scheme: dark) {
  body.prose article,
  body.doc article {
    background: #131211;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.25);
  }
}

/* 手机上纸面铺满整宽，否则一行只剩二十来个字 */
@media (max-width: 640px) {
  body.prose article,
  body.doc article {
    margin-left: -1.25rem;
    margin-right: -1.25rem;
    padding: 1.6rem 1.25rem;
    border-radius: 0;
    box-shadow: none;
  }
}

/* ── 传统排版（文章 / 小说） ─────────── */
/* 段首缩两字、段与段之间不留空，靠缩进分段，跟纸书一样 */
body.prose article p {
  margin: 0;
  text-indent: 2em;
}

/* 非段落块自己留白，免得跟正文粘成一坨 */
body.prose article ul,
body.prose article ol,
body.prose article pre,
body.prose article blockquote,
body.prose article table {
  margin-top: 1.4rem;
  margin-bottom: 1.4rem;
}

/* ::: noindent 包住的段落：不缩进（编辑器里把缩进关掉时用） */
body.prose article .noindent p { text-indent: 0; }

/* 编辑器生成的页面：段落/标题不再自带外边距，间距完全由空行决定，
   这样「编辑器里空一行」和「网页上空一行」才是同一件事 */
body.lined article h1,
body.lined article h2,
body.lined article h3,
body.lined article h4,
body.lined article h5,
body.lined article h6,
body.lined article p {
  margin-top: 0;
  margin-bottom: 0;
}

/* 编辑器里留的空行，build 出来是一个真正的空段 */
article .gap { height: 2em; margin: 0; }

/* md 里 ::: center … ::: 包住的块：居中、不缩进（编辑器「居中」按钮写的就是这个） */
body.prose article .center { text-align: center; }

body.prose article .center p { text-indent: 0; }

/* ── 诗歌：整篇居中 ────────────────── */
/* body 上同时有 prose 和 poetry 两个 class（build.pyw 选的） */
body.prose.poetry article { text-align: center; }

body.prose.poetry article p {
  margin: 0 0 1.3rem;
  text-indent: 0;
}

p { margin: 0 0 1.3rem; }

a { color: var(--fg); text-decoration-thickness: 1px; text-underline-offset: 2px; }

hr { border: 0; border-top: 1px solid var(--line); margin: 2.75rem 0; }

.muted { color: var(--muted); }
.intro { font-size: 1.06rem; }
.hero { margin-bottom: 3rem; }

/* 栏目页顶部原来有一句占位说明，去掉后留同样高度的空白 */
.lede-gap { height: 2.6rem; }

/* ── 文章列表 ─────────────────────────── */

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

.posts li {
  padding: 0.62rem 0 0.08rem;   /* 底下不留空，文字直接压在分隔线上 */
  border-bottom: 1px solid var(--line);
}

.posts li a {
  position: relative;
  display: block;
  padding-right: 5.6rem;
}

/* 列表右侧的日期：从文件名里的时间解析，精确到日 */
.item-date {
  position: absolute;
  right: 0;
  bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.posts a { text-decoration: none; }
.posts a:hover { text-decoration: underline; text-underline-offset: 3px; }

.tag-new {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 3px;
  padding: 0.1rem 0.36rem;
  margin-left: 0.55rem;
  vertical-align: 0.14em;
}

@media (prefers-color-scheme: dark) {
  .tag-new { color: #fca5a5; background: #3f1d1d; }
}

/* ── 卡片式列表（work 页用） ────────────── */
/* 这组规则配合 tools/update_work_index.py 生成的卡片结构使用。
   卡片 DOM 由那个脚本产出，别在这里假设别的结构；反过来，改结构也要同步这里。
   .posts / .cards / .card / .card-title / .card-desc 这几个 class 名是跨文件约定，
   改名要同时改 tools/update_work_index.py 和 assets/new-tag.js。 */

.posts.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1.25rem;
  margin: 0;
  padding: 0;
}

.posts.cards li.card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0;
  margin: 0;
}

.posts.cards li.card > a {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  text-decoration: none;
}

.posts.cards li.card > a:hover { text-decoration: none; }
.posts.cards li.card > a:hover .card-title {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.card img {
  display: block;
  width: 100%;
  height: 10.5rem;
  object-fit: cover;
  border-radius: 3px;
  margin: 0 0 0.85rem;
}

.card-title {
  display: block;
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.45;
  margin: 0;
}

.card-desc {
  display: block;
  flex: 1 1 auto;
  margin: 0 0 0.7rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.65;
}

/* new 标签在 DOM 里排最后，用绝对定位挂回卡片右上角 */
.posts.cards .tag-new {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  margin: 0;
}

/* ── 搜索 ─────────────────────────────── */

.search { display: none; margin: 0 0 3rem; }
.search.on { display: block; }

/* 搜索框居中、限宽，左边放个放大镜 */
.search-field {
  position: relative;
  max-width: 22rem;
  margin: 0 auto;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 1em;
  height: 1em;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  padding: 0.65rem 0.8rem 0.65rem 2.3rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
}

.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--muted); }

.search-results {
  list-style: none;
  max-width: 22rem;
  margin: 0.5rem auto 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.search-results:empty { display: none; }
.search-results li { border-bottom: 1px solid var(--line); }
.search-results li:last-child { border-bottom: 0; }

.search-results a {
  display: block;
  padding: 0.6rem 0.85rem;
  font-size: 0.95rem;
  text-decoration: none;
}

.search-results a:hover { background: var(--soft); }
.search-results .sec { color: var(--muted); font-size: 0.8rem; margin-left: 0.6rem; }
.search-results .none { padding: 0.6rem 0.85rem; color: var(--muted); font-size: 0.9rem; }

/* ── 文章内页 ─────────────────────────── */

article { margin-bottom: 4rem; }

/* 文章里的图片：最多占版心宽度的 70%，高度按比例，水平居中。
   原图比这个宽度还小的时候保持原尺寸显示，不放大。
   点图片看原图，行为在 assets/img-view.js。 */
article img {
  display: block;
  max-width: 70%;
  height: auto;
  margin: 1.75rem auto;
}

article img.zoomable { cursor: zoom-in; }

/* 小屏上 70% 太窄了，最多铺满版心 */
@media (max-width: 640px) {
  article img { max-width: 100%; }
}

/* 看原图的遮罩层（由 img-view.js 动态塞进 body） */
.img-view {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 3vh 3vw;
  background: rgba(0, 0, 0, 0.82);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.img-view.on { display: flex; }

.img-view img {
  max-width: 94vw;
  max-height: 94vh;
  width: auto;
  height: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

body.no-scroll { overflow: hidden; }

article pre {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.65;
}

article code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

article :not(pre) > code {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 0.05em 0.3em;
}

article blockquote {
  margin: 1.75rem 0;
  padding: 0 1.1rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
}

article blockquote p:last-child { margin-bottom: 0; }

article table { border-collapse: collapse; width: 100%; font-size: 0.92rem; margin: 1.5rem 0; }
article th, article td { border: 1px solid var(--line); padding: 0.45rem 0.7rem; text-align: left; }
article th { font-weight: 600; background: var(--soft); }

article ul, article ol { padding-left: 1.4rem; }
article li { margin: 0.3rem 0; }

/* ── 页脚 ─────────────────────────────── */

footer {
  border-top: 1px solid var(--line);
  margin-top: 4rem;
  padding: 1.5rem 0 3.5rem;
  color: var(--muted);
  font-size: 0.86rem;
}

footer p { margin: 0; }
footer a { color: var(--muted); }
