/* ======================================================================
   西窗 · 双栏竖排阅读器
   左：目录　右：竖排右起（writing-mode: vertical-rl）
   昼（宣纸）默认；夜（夜窗烛光）由 [data-theme="night"] 切换
   ====================================================================== */

:root {
  --paper:     #f3ede0;
  --paper-2:   #ece3d2;
  --panel:     #f7f1e6;
  --ink:       #221f1a;
  --ink-soft:  #443f37;
  --muted:     #8a8070;
  --seal:      #a8443a;
  --seal-ink:  #fbf6ec;
  --hair:      rgba(34, 31, 26, 0.13);
  --hair-soft: rgba(34, 31, 26, 0.06);
  --glow:      rgba(168, 68, 58, 0.10);
  --ghost:     rgba(34, 31, 26, 0.04);
  --grain:     0.04;
}
:root[data-theme="night"] {
  --paper:     #13151c;
  --paper-2:   #0f1118;
  --panel:     #171a22;
  --ink:       #e9e2d1;
  --ink-soft:  #c7c0ad;
  --muted:     #88836f;
  --seal:      #cb5a4c;
  --seal-ink:  #13151c;
  --hair:      rgba(233, 226, 209, 0.15);
  --hair-soft: rgba(233, 226, 209, 0.06);
  --glow:      rgba(216, 162, 74, 0.18);
  --ghost:     rgba(233, 226, 209, 0.045);
  --grain:     0.05;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: background 0.6s ease, color 0.6s ease;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(120% 80% at 82% -10%, var(--glow), transparent 60%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 100%);
  transition: background 0.6s ease;
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.layout { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }

/* ---------- 左：目录 ---------- */
.sidebar {
  flex: 0 0 286px;
  display: flex; flex-direction: column;
  padding: 40px 30px 26px;
  border-right: 1px solid var(--hair);
  background: linear-gradient(90deg, var(--panel), transparent);
  overflow-y: auto; scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.brand-mini { display: flex; align-items: center; gap: 14px; text-decoration: none; margin-bottom: 38px; }
.brand-mini .seal {
  font-size: 14px; font-weight: 600; line-height: 1.05; letter-spacing: 1px;
  color: var(--seal-ink); background: var(--seal); padding: 9px 7px; border-radius: 5px;
  transform: rotate(-3deg); box-shadow: 0 6px 18px var(--glow);
}
.brand-text { font-size: 26px; font-weight: 900; letter-spacing: 0.12em; color: var(--ink); line-height: 1; }
.brand-text small {
  display: block; margin-top: 5px; font-family: "EB Garamond", serif; font-weight: 400;
  font-size: 9.5px; letter-spacing: 0.46em; color: var(--muted);
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  width: 100%; text-align: left; cursor: pointer;
  padding: 13px 14px; border: 0; border-radius: 9px;
  background: transparent; color: var(--ink-soft);
  position: relative; transition: background 0.25s, color 0.25s;
}
.nav-item::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%) scaleY(0);
  width: 3px; height: 22px; border-radius: 2px; background: var(--seal); transition: transform 0.3s ease;
}
.nav-item:hover { background: var(--hair-soft); }
.nav-item.on { background: var(--hair-soft); color: var(--ink); }
.nav-item.on::before { transform: translateY(-50%) scaleY(1); }
.nav-title { font-size: 16.5px; font-weight: 500; letter-spacing: 0.06em; }
.nav-meta { font-size: 11.5px; font-weight: 300; letter-spacing: 0.12em; color: var(--muted); }

.side-foot {
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--hair-soft);
  font-size: 11px; letter-spacing: 0.28em; color: var(--muted); font-weight: 300;
}

/* ---------- 右：竖排阅读 ---------- */
.reader {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow-x: auto; overflow-y: hidden; padding: 7vh 56px;
  scrollbar-width: none;
}
.reader::-webkit-scrollbar { display: none; }

.scroll-row {
  display: flex; flex-direction: row-reverse; align-items: flex-start;
  gap: 36px; margin: auto;
  animation: fade 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fade { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

.col {
  writing-mode: vertical-rl;
  text-orientation: upright;
  -webkit-text-orientation: upright;
  max-height: 72vh;
  line-height: 1.85;
}

/* 题 */
.r-title { margin-left: 6px; }
.r-title .title, .r-title .tune {
  font-size: 34px; font-weight: 600; letter-spacing: 0.1em; color: var(--ink);
}
.r-title .subtitle {
  display: inline; font-size: 15px; font-weight: 300; letter-spacing: 0.16em; color: var(--muted);
  margin-top: 14px;
}
/* 作者 */
.r-byline { font-size: 14px; font-weight: 300; letter-spacing: 0.2em; color: var(--muted); align-self: flex-start; }
/* 序 */
.r-preface { font-size: 13.5px; font-weight: 300; letter-spacing: 0.06em; color: var(--muted); line-height: 2.1; }
/* 正文 */
.r-line { font-size: 25px; font-weight: 400; letter-spacing: 0.12em; color: var(--ink-soft); }

/* ---------- 主题切换 ---------- */
.theme-toggle {
  position: fixed; top: 22px; right: 24px; z-index: 6;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--hair); background: transparent; color: var(--ink-soft);
  font-size: 19px; line-height: 1; cursor: pointer; display: grid; place-items: center;
  transition: border-color 0.3s, color 0.3s, transform 0.5s;
}
.theme-toggle:hover { border-color: var(--seal); color: var(--seal); transform: rotate(20deg); }
.theme-toggle .ico-sun { display: none; }
:root[data-theme="night"] .theme-toggle .ico-moon { display: none; }
:root[data-theme="night"] .theme-toggle .ico-sun { display: block; }

/* ---------- 响应式：窄屏改上下 ---------- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    flex: 0 0 auto; flex-direction: row; align-items: center; gap: 16px;
    padding: 16px 18px; border-right: 0; border-bottom: 1px solid var(--hair);
    background: linear-gradient(180deg, var(--panel), transparent);
    overflow-x: auto; overflow-y: hidden;
  }
  .brand-mini { margin-bottom: 0; flex: 0 0 auto; }
  .brand-text small { display: none; }
  .nav { flex-direction: row; gap: 6px; flex: 1; }
  .nav-item { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--hair); }
  .nav-item::before { display: none; }
  .nav-meta { display: none; }
  .nav-title { font-size: 14px; }
  .side-foot { display: none; }
  .reader { padding: 5vh 28px; }
  .col { max-height: 64vh; }
  .r-line { font-size: 22px; }
  .r-title .title, .r-title .tune { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-row { animation: none; }
}
