/* ==========================================================================
   千景的诗集
   桌面：左侧固定栏 + 书页式边注；移动：顶部固定栏 + 目录抽屉。
   版式按纸面来排：年份当章首页，日期退到页边，正文只留文字。
   ========================================================================== */

:root {
  --paper: #f7f5f0;
  --paper-rail: #f1eee6;
  --ink: #17161a;
  --ink-soft: #3d3a35;
  --muted: #6f6a61;
  --rule: #ddd7ca;

  --rail-w: 18rem;
  --reading-w: 38rem;

  --serif: "Source Han Serif SC", "Noto Serif SC", "Songti SC", STSong, SimSun,
    Georgia, "Times New Roman", serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Segoe UI", Helvetica, Arial, sans-serif;

  color-scheme: light;
}

html[data-theme="dark"] {
  --paper: #14161a;
  --paper-rail: #171a1f;
  --ink: #ddd8ce;
  --ink-soft: #b8b2a7;
  --muted: #8a857b;
  --rule: #2a2d33;

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --paper: #14161a;
    --paper-rail: #171a1f;
    --ink: #ddd8ce;
    --ink-soft: #b8b2a7;
    --muted: #8a857b;
    --rule: #2a2d33;

    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
}

::selection {
  background: rgba(23, 22, 26, 0.12);
}

html[data-theme="dark"] ::selection {
  background: rgba(221, 216, 206, 0.18);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) ::selection {
    background: rgba(221, 216, 206, 0.18);
  }
}

/* ==========================================================================
   左侧固定栏
   ========================================================================== */

.rail {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: var(--rail-w);
  padding: 1.9rem 1.6rem 1.6rem;
  background: var(--paper-rail);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  transition: background-color 0.2s ease, transform 0.25s ease;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.rail-back {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.rail-back:hover {
  color: var(--ink);
  border-color: var(--rule);
}

.rail-close {
  display: none;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.rail-title {
  margin: 2.6rem 0 0;
}

.rail-title h1 {
  margin: 0 0 0.6rem;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.3;
}

.rail-sub {
  margin: 0 0 0.8rem;
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}

.rail-meta {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.rail-toc {
  display: flex;
  flex-direction: column;
  margin: 2.2rem 0 0;
}

.rail-toc a {
  padding: 0.3rem 0;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.rail-toc a:hover {
  color: var(--ink-soft);
}

.rail-toc a.active {
  color: var(--ink);
  font-weight: 600;
}

.rail-foot {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  margin-top: auto;
  padding-top: 2rem;
}

.rail-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

/* ==========================================================================
   主题切换：文字开关，不用圆形图标按钮
   ========================================================================== */

.theme-toggle {
  padding: 0;
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--ink-soft);
}

.i-moon {
  display: none;
}

html[data-theme="dark"] .i-sun {
  display: none;
}

html[data-theme="dark"] .i-moon {
  display: inline;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .i-sun {
    display: none;
  }

  html:not([data-theme="light"]) .i-moon {
    display: inline;
  }
}

/* ==========================================================================
   移动端顶部栏
   ========================================================================== */

.topbar {
  display: none;
}

.rail-scrim {
  display: none;
}

/* ==========================================================================
   正文
   ========================================================================== */

.reading {
  margin-left: var(--rail-w);
}

.reading-inner {
  max-width: var(--reading-w);
  margin: 0 auto;
  padding: 4rem 2rem 5rem;
}

.notice {
  margin: 0 0 3.5rem;
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.9;
  color: var(--muted);
}

.year + .year {
  margin-top: 4.5rem;
}

/* 年份当章首页：大号数字，不加装饰线 */
.year-label {
  margin: 0 0 2.5rem;
  font-family: var(--serif);
  font-size: 36px;
  font-weight: 500;
  line-height: 1.1;
  color: var(--ink);
  scroll-margin-top: 5rem;
}

.poem {
  margin: 0 0 3rem;
}

.poem:last-child {
  margin-bottom: 0;
}

.poem-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
  margin: 0 0 0.85rem;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.poem-time {
  color: var(--muted);
}

.poem-note {
  font-family: var(--serif);
  font-style: italic;
}

.verse {
  margin: 0 0 1.4em;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.95;
  color: var(--ink);
}

.verse:last-child {
  margin-bottom: 0;
}

.reading-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem 1.5rem;
  margin-top: 5rem;
  padding-top: 1.2rem;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--rule);
}

.reading-foot p {
  margin: 0;
}

.reading-foot a {
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.reading-foot a:hover {
  color: var(--ink);
  border-color: var(--ink-soft);
}

/* ==========================================================================
   桌面：日期退到页边
   ========================================================================== */

@media (min-width: 900px) {
  .poem {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    column-gap: 1.5rem;
    align-items: start;
  }

  .poem-meta {
    grid-column: 1;
    grid-row: 1;
    justify-content: flex-end;
    margin: 0;
    padding-top: 0.6em;
    text-align: right;
  }

  .verse {
    grid-column: 2;
  }
}

/* ==========================================================================
   窄屏：侧栏变抽屉，顶栏常驻
   ========================================================================== */

@media (max-width: 899px) {
  .topbar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3.25rem;
    padding: 0 1rem;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    transition: background-color 0.2s ease;
  }

  .topbar-title {
    font-family: var(--serif);
    font-size: 15px;
  }

  .topbar-btn {
    padding: 0;
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.6;
    color: var(--muted);
    background: none;
    border: 0;
    cursor: pointer;
  }

  .topbar-btn.theme-toggle {
    border-bottom: 1px solid var(--rule);
  }

  .rail {
    z-index: 60;
    width: min(18rem, 84vw);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.18);
    transform: translateX(-100%);
  }

  .rail.open {
    transform: none;
  }

  .rail-close {
    display: block;
  }

  .rail-scrim {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: block;
    background: rgba(0, 0, 0, 0.34);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .rail-scrim.show {
    opacity: 1;
    pointer-events: auto;
  }

  .reading {
    margin-left: 0;
  }

  .reading-inner {
    max-width: 100%;
    padding: 4.75rem 1.25rem 4rem;
  }

  .notice {
    margin-bottom: 2.75rem;
  }

  .year + .year {
    margin-top: 3.5rem;
  }

  .year-label {
    font-size: 28px;
    margin-bottom: 2rem;
  }

  .poem {
    margin-bottom: 2.75rem;
  }

  .verse {
    font-size: 16px;
    line-height: 1.9;
  }

  .reading-foot {
    margin-top: 3.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  body,
  .rail,
  .rail-scrim,
  .topbar {
    transition: none;
  }
}

/* ==========================================================================
   打印
   ========================================================================== */

@media print {
  .rail,
  .topbar,
  .rail-scrim {
    display: none !important;
  }

  .reading {
    margin: 0;
  }

  .reading-inner {
    max-width: none;
    padding: 0;
  }

  body {
    background: #fff;
    color: #000;
  }

  .poem {
    page-break-inside: avoid;
    margin-bottom: 2rem;
  }
}
