/* =========================================================================
   凌晨四點 · 样式
   白纸、楷体正文（大字号）、明朝标题、黑体小字。页面上没有装饰性的线。
   一屏一条记录，整页不滚动：内容装得下就单栏通宽，装不下就排成两栏跨页，
   用底部按钮左右翻——像一本电子书。
   ========================================================================= */

:root {
  color-scheme: light;

  --paper: #ffffff;
  --ink: #111111;
  --body: #242424;
  --muted: #6b6b6b;
  --faint: #9c9c9c;
  --shu: #c0281f;
  --soft: #f4f3f1;

  --kai: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif SC", "Songti SC", serif;
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", "Songti SC", "Noto Serif SC", serif;
  --gothic: "Hiragino Kaku Gothic ProN", "Hiragino Sans", -apple-system, BlinkMacSystemFont,
    "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --rail: 9.5rem;
  --gap: 3rem;
  --pad: 2rem;
  --body-size: calc(1.875rem * var(--font-scale, 1)); /* 默认 30px，可用右上角缩放 */
  --col-gap: 3.5rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 类里的 display 会盖掉浏览器对 [hidden] 的默认处理，这里显式兜底 */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--body);
  font-family: var(--kai);
  font-size: 16px;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 阅读页锁成一屏，不上下滚动也不左右滚动 */
body.page-reader {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  /* 否则 macOS 的双指横滑会被浏览器当成前进/后退 */
  overscroll-behavior-x: none;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--shu);
}

img {
  max-width: 100%;
}

/* ------------------------------------------------------------------ 骨架 */

.page {
  margin: 0 auto;
  padding: 0 var(--pad);
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: var(--gap);
}

.page--reader {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.main {
  min-width: 0;
  padding: 2.5rem 0 4rem;
}

.page--reader .main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 2rem 0 1.25rem;
}

/* --------------------------------------------------------- 侧栏（书脊） */

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 2rem 0;
}

.page--reader .rail {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.rail__spine {
  margin: 0;
  writing-mode: vertical-rl;
  font-family: var(--mincho);
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.26em;
  line-height: 1;
  color: var(--ink);
}

.rail__sub {
  margin: 1rem 0 0;
  writing-mode: vertical-rl;
  font-family: var(--gothic);
  font-size: 0.95rem;
  letter-spacing: 0.26em;
  color: var(--muted);
}

.rail__nav {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-top: 2.5rem;
}

.rail__label {
  padding-bottom: 0.6rem;
  font-family: var(--gothic);
  font-size: 0.85rem;
  letter-spacing: 0.26em;
  color: var(--faint);
}

.rail__label::before {
  content: "●";
  margin-right: 0.5em;
  font-size: 0.75em;
  color: var(--shu);
}

.rail__nav a {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.3rem 0;
  font-family: var(--gothic);
  font-size: 1.05rem;
  color: var(--body);
  font-variant-numeric: tabular-nums;
}

.rail__dots {
  display: none;
}

.rail__foot {
  margin: 2.5rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-family: var(--gothic);
  font-size: 0.9rem;
  line-height: 1.9;
  color: var(--faint);
}

/* 视口不高时先收起年份和页脚，保证一屏放得下 */
@media (max-height: 760px) {
  .rail__nav--years,
  .rail__foot {
    display: none;
  }
}

/* ------------------------------------------------- 左栏底部：字号（低调） */

.tools {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin-top: 2rem;
  flex: none;
}

.tools__btn {
  font: inherit;
  font-family: var(--gothic);
  font-size: 0.82rem;
  line-height: 1;
  padding: 0;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
}

.tools__btn:hover {
  color: var(--shu);
}

/* 当前档只是深一点，不做底色、不加框 */
.tools__btn[aria-pressed="true"] {
  color: var(--ink);
}

.tools__btn[aria-pressed="true"]:hover {
  color: var(--shu);
}

/* ------------------------------------------------------------ 一条记录 */

.entry {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.entry__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  font-family: var(--gothic);
  font-size: calc(1.05rem * var(--font-scale, 1));
  letter-spacing: 0.13em;
  font-variant-numeric: tabular-nums;
  flex: none;
}

.entry__no {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  color: var(--shu);
}

.entry__stamp {
  color: var(--muted);
}

.entry__title {
  margin: 0 0 0.6rem;
  font-family: var(--mincho);
  font-size: calc(2.9rem * var(--font-scale, 1));
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
  flex: none;
}

.entry__byline {
  margin: 0;
  font-family: var(--gothic);
  font-size: calc(1.2rem * var(--font-scale, 1));
  letter-spacing: 0.16em;
  color: var(--muted);
  flex: none;
}

.entry__reader {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 2rem;
  /* clip 而不是 hidden：hidden 仍是可滚容器，焦点移动到隐藏栏里的链接时会被浏览器滚走 */
  overflow: clip;
  /* 横向手势交给 reader.js 翻页，纵向仍归浏览器 */
  touch-action: pan-y;
}

/* 窗口矮到没法分栏时的兜底：允许在框内纵向滚动，至少不丢内容 */
.entry.is-tight .entry__reader {
  overflow-y: auto;
}

.entry__body {
  max-width: none;
}

/* 装不下：两栏跨页。栏宽与总宽由 reader.js 算准，翻页用 transform 平移 */
.entry[data-mode="spread"] .entry__body {
  height: 100%;
  column-fill: auto;
  column-gap: var(--col-gap);
  transition: transform 0.22s ease;
  will-change: transform;
}

/* ------------------------------------------------------ 底部：条目与翻页 */

.entry__bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding-top: 1.25rem;
  flex: none;
}

.entry__step {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  max-width: 38%;
}

.entry__step--next {
  align-items: flex-end;
  text-align: right;
}

.entry__step-label {
  font-family: var(--gothic);
  font-size: calc(1rem * var(--font-scale, 1));
  letter-spacing: 0.16em;
  color: var(--shu);
}

.entry__step-title {
  font-family: var(--kai);
  font-size: calc(1.3rem * var(--font-scale, 1));
  line-height: 1.4;
  color: var(--body);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.entry__step:hover .entry__step-title {
  color: var(--shu);
}

/* 标题前面标出这一条固定下来的编号 */
.entry__step-no {
  font-family: var(--gothic);
  font-size: 0.8em;
  letter-spacing: 0.1em;
  color: var(--shu);
  margin-right: 0.5em;
  white-space: nowrap;
}

.turns {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: none;
}

.turns__btn {
  font: inherit;
  font-family: var(--gothic);
  font-size: 1.6rem;
  line-height: 1;
  width: 3.4rem;
  height: 3.4rem;
  border: 0;
  background: var(--soft);
  color: var(--ink);
  cursor: pointer;
}

.turns__btn:hover:not(:disabled) {
  background: var(--shu);
  color: #fff;
}

.turns__btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.turns__count {
  font-family: var(--gothic);
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 4.5rem;
  text-align: center;
}

.entry__draft {
  font-family: var(--gothic);
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  color: var(--faint);
}

/* ---------------------------------------------------------------- 正文 */

.prose {
  font-family: var(--kai);
  font-size: var(--body-size);
  line-height: 1.95;
  color: var(--body);
}

.prose > p {
  margin: 0 0 1.4em;
}

.prose h2,
.prose h3 {
  font-family: var(--mincho);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.5;
}

.prose h2 {
  margin: 1.8em 0 0.7em;
  font-size: 1.2em;
}

.prose h2::before {
  content: "";
  display: inline-block;
  width: 0.42em;
  height: 0.42em;
  margin-right: 0.5em;
  vertical-align: 0.08em;
  background: var(--shu);
}

.prose h3 {
  margin: 1.6em 0 0.6em;
  font-size: 1.05em;
}

.prose a {
  color: var(--ink);
  border-bottom: 1px solid var(--faint);
}

.prose a:hover {
  color: var(--shu);
  border-bottom-color: var(--shu);
}

.prose strong {
  color: var(--ink);
  font-weight: 600;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.72em;
  background: var(--soft);
  padding: 0.1em 0.28em;
}

.prose pre {
  font-family: var(--mono);
  font-size: 0.62em;
  line-height: 1.7;
  background: var(--soft);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  margin: 1.6em 0;
}

.prose pre code {
  background: none;
  padding: 0;
}

.prose ul,
.prose ol {
  margin: 0 0 1.3em;
  padding-left: 1.1em;
}

.prose li {
  margin-bottom: 0.35em;
}

.prose ul {
  list-style: none;
  padding-left: 1.1em;
}

.prose ul > li::before {
  content: "●";
  display: inline-block;
  width: 1.1em;
  margin-left: -1.1em;
  font-size: 0.42em;
  vertical-align: 0.45em;
  color: var(--shu);
}

.prose ol {
  list-style: none;
  counter-reset: n;
  padding-left: 1.6em;
}

.prose ol > li {
  counter-increment: n;
}

.prose ol > li::before {
  content: counter(n) ".";
  display: inline-block;
  width: 1.6em;
  margin-left: -1.6em;
  font-family: var(--gothic);
  font-size: 0.75em;
  color: var(--muted);
}

.prose blockquote {
  margin: 1.6em 0;
  padding-left: 1.4em;
  color: var(--muted);
}

.prose blockquote p {
  margin: 0;
}

.prose hr {
  border: 0;
  margin: 2em 0;
}

.prose img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--soft);
}

.prose .figure {
  margin: 1.8em 0;
  break-inside: avoid;
}

/* 点图片看原图 */
.prose .figure > a {
  display: block;
}

.prose figcaption {
  position: relative;
  margin-top: 0.5em;
  padding-left: 3.4em;
  font-family: var(--gothic);
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--muted);
}

.prose figcaption::before {
  content: "照片";
  position: absolute;
  left: 0;
  top: 0.2em;
  font-size: 0.95rem;
  color: var(--shu);
}

.prose .embed {
  position: relative;
  margin: 1.8em 0;
  aspect-ratio: 16 / 9;
  background: #000;
  break-inside: avoid;
}

.prose .embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.prose .embed::after {
  content: "视频";
  position: absolute;
  left: 0;
  top: 0;
  padding: 0.2em 0.55em;
  background: var(--shu);
  color: #fff;
  font-family: var(--gothic);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
}

/* -------------------------------------------------------------- 总目录 */

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 2.5rem;
}

.page-head h1 {
  margin: 0;
  font-family: var(--mincho);
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--ink);
}

.page-head__meta {
  font-family: var(--gothic);
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.year {
  margin-bottom: 3.5rem;
}

.year__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 1rem;
  font-family: var(--mincho);
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--ink);
}

.year__count {
  font-family: var(--gothic);
  font-size: 1rem;
  letter-spacing: 0.16em;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

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

.year__list a {
  display: grid;
  grid-template-columns: 9rem 3rem 1fr;
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.5rem 0;
  font-size: 1.55rem;
}

.year__list time {
  font-family: var(--gothic);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.toc__dots {
  display: none;
}

.toc__no {
  font-family: var(--gothic);
  font-size: 1.1rem;
  color: var(--shu);
  font-variant-numeric: tabular-nums;
}

.toc__title {
  color: var(--ink);
}

.year__list a:hover .toc__title {
  color: var(--shu);
}

/* ------------------------------------------------------------ 空状态 */

.empty {
  padding: 3rem 0;
}

.empty h1 {
  font-family: var(--mincho);
  font-size: 2rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 0.8rem;
}

.empty p {
  margin: 0;
  font-size: 1.4rem;
  color: var(--muted);
}

.empty a {
  color: var(--shu);
}

:focus-visible {
  outline: 3px solid var(--shu);
  outline-offset: 3px;
}

/* --------------------------------------------------------------- 窄屏 */

/* 窄屏不锁屏：一屏放不下这么大的字号，改回正常纵向阅读 */
@media (max-width: 899px) {
  :root {
    --pad: 1.25rem;
    --body-size: 1.25rem;
  }

  body.page-reader {
    height: auto;
    overflow: visible;
  }

  .page--reader {
    height: auto;
    overflow: visible;
    grid-template-columns: 1fr;
    gap: 0;
  }

  .page--reader .rail {
    height: auto;
    overflow: visible;
  }

  .page--reader .main {
    display: block;
    padding: 0.75rem 0 3rem;
  }

  .entry {
    display: block;
  }

  .entry__reader {
    height: auto;
    overflow: visible;
  }

  .entry[data-mode="spread"] .entry__body {
    height: auto;
    column-width: auto !important;
    width: auto !important;
    transform: none !important;
    max-width: 34rem;
    transition: none;
  }

  .entry__title {
    font-size: 1.9rem;
  }

  .entry__byline {
    font-size: 1.05rem;
  }

  .entry__head {
    font-size: 0.95rem;
  }

  /* 手机端把字号控件钉在右上角，不占一行的空间 */
  .tools {
    position: fixed;
    top: 0.5rem;
    right: 0.6rem;
    z-index: 30;
    margin: 0;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    background: rgba(255, 255, 255, 0.88);
  }

  .tools__btn {
    font-size: 0.9rem;
  }

  .turns {
    display: none;
  }

  .entry__bar {
    padding-top: 1.5rem;
  }

  .entry__step {
    max-width: 45%;
  }

  .entry__step-title {
    font-size: 1.1rem;
  }
}

@media (max-width: 860px) {
  .rail {
    position: static;
    align-items: stretch;
    padding: 1.5rem 0 0;
  }

  .rail__spine,
  .rail__sub {
    writing-mode: horizontal-tb;
    letter-spacing: 0.1em;
  }

  .rail__spine {
    font-size: 1.5rem;
  }

  .rail__sub {
    margin-top: 0.4rem;
  }

  .rail__nav {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 1.2rem;
    margin-top: 1rem;
  }

  .rail__nav a,
  .rail__label {
    padding: 0.15rem 0;
    font-size: 0.95rem;
  }

  .rail__nav--years,
  .rail__foot {
    display: none;
  }
}
