/* 深夜故事 — 主题变量 */
:root {
  --bg-deep: #0d0f14;
  --bg-card: #14171f;
  --bg-paper: #1a1e28;
  --border: #2a3140;
  --text: #e8e4dc;
  --text-muted: #9a958a;
  --accent: #c9a227;
  --accent-dim: #8b7324;
  --accent-glow: rgba(201, 162, 39, 0.25);
  --serif: "Noto Serif SC", "Source Han Serif SC", serif;
  --display: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--serif);
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.7;
  position: relative;
  overflow-x: hidden;
}

/* 阅读页：与首页一致深色背景 + 噪点星点 */
body.page-story {
  background: var(--bg-deep);
}

/* 背景层次：噪点 + 星点 */
.noise {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.stars {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1.2px 1.2px at 12% 8%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.2px 1.2px at 28% 22%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1px 1px at 65% 15%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1.2px 1.2px at 88% 70%, rgba(255,255,255,0.25), transparent),
    radial-gradient(1px 1px at 45% 85%, rgba(255,255,255,0.2), transparent);
  pointer-events: none;
  z-index: 0;
}

/* 顶栏 */
.site-header {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(20, 23, 31, 0.95) 0%, transparent 100%);
}

.site-header--compact {
  padding: 0.75rem 1rem 0.5rem;
}

.site-header--compact .site-desc {
  margin: 0 auto 0.5rem;
  font-size: 0.8rem;
  text-align: center;
}

.site-header--compact .tabs {
  margin-top: 0.25rem;
}

.site-header--story {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  text-align: left;
}

.site-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-decoration: none;
  color: inherit;
}

.site-title-wrap:hover {
  color: var(--accent);
}

.lantern {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.site-header--compact .lantern {
  font-size: 1.25rem;
  margin-bottom: 0;
}

.site-title {
  font-family: var(--display);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 400;
  margin: 0 0 0.35em;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.site-header--compact .site-title {
  font-size: 1.1rem;
  margin: 0;
}

.site-title--small {
  font-size: 0.95rem !important;
  color: var(--text-muted);
}

.back-link {
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

.site-desc {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 36ch;
  margin-left: auto;
  margin-right: auto;
}

.tabs {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.tab {
  font-family: var(--serif);
  font-size: 0.8rem;
  padding: 0.25rem 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* 主内容区 */
.main {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  max-width: 1200px;
  margin: 0 auto;
  min-height: calc(100vh - 220px);
}

.main--list-only {
  grid-template-columns: 1fr;
  display: flex;
  flex-direction: column;
  max-width: 48rem;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
  padding: 0.5rem 1rem 1.5rem;
  flex: 1;
}

/* 阅读页顶栏：与首页一致，左标题右返回 */
body.page-story .site-header--story {
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(20, 23, 31, 0.95) 0%, transparent 100%);
}

body.page-story .site-header--story .back-link {
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* 阅读页：单列块级布局，与首页风格统一的衬底 */
.main--story {
  display: block;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  box-sizing: border-box;
  flex: 1;
  background: var(--bg-card);
  position: relative;
  z-index: 1;
}

/* 阅读页顶栏与正文同宽 */
body.page-story .site-header--story {
  box-sizing: border-box;
}

/* 阅读页 PC 端优化 */
@media (min-width: 769px) {
  body.page-story .site-header--story {
    max-width: 48rem;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 0.75rem 2rem;
    box-sizing: border-box;
  }

  body.page-story .main--story {
    max-width: 48rem;
    width: 100%;
    padding: 2rem 2rem 3rem;
    box-sizing: border-box;
  }

  body.page-story .story-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
  }

  body.page-story .story-title {
    font-size: 1.35rem;
  }

  body.page-story .story-meta,
  body.page-story .story-github {
    font-size: 0.85rem;
  }

  body.page-story .story-body {
    font-size: 1.05rem;
    line-height: 1.85;
  }

  body.page-story .story-back-wrap {
    margin-top: 1.5rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .main--list-only {
    padding: 0.5rem 0.75rem 1rem;
  }
}

/* 列表容器：撑满 main，分页靠底 */
.main--list-only .list-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.list-wrap {
  width: 100%;
}

.main--list-only .list-wrap .pagination {
  margin-top: auto;
}

/* 侧边栏 */
.sidebar {
  padding: 1.25rem 1rem;
  border-right: 1px solid var(--border);
  background: rgba(20, 23, 31, 0.6);
  overflow-y: auto;
}

@media (max-width: 768px) {
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 240px;
  }
}

.list-loading,
.list-error {
  padding: 0.75rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.list-error {
  color: #c95c5c;
}

.list-empty {
  padding: 0.75rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

.hidden {
  display: none !important;
}

.story-list.hidden {
  display: none;
}

.story-list li {
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
}

.story-list li:last-child {
  border-bottom: none;
}

.story-list a {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.4rem 0.5rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  transition: background 0.15s, color 0.15s;
}

.story-list a:hover {
  background: var(--bg-paper);
  color: var(--accent);
}

.story-list .list-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.story-list .list-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 分页 */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 2rem;
  padding: 1rem 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pagination-btn {
  font-family: var(--serif);
  font-size: 0.8rem;
  padding: 0.25rem 0;
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.pagination-btn:hover:not(:disabled) {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-bottom-color: transparent;
}

.pagination-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* 加载动画 */
.loading-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: 0 3px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1); }
}

/* 故事子页面 */
.page-story .story-loading,
.page-story .story-article,
.page-story .story-error {
  width: 100%;
  max-width: none;
  margin: 0;
  box-sizing: border-box;
}

.story-loading {
  text-align: center;
  padding: 2rem 1rem;
}

.story-loading.hidden,
.story-article.hidden,
.story-error.hidden {
  display: none;
}

.page-story .story-article {
  padding-bottom: 1rem;
}

.page-story .story-back-wrap {
  width: 100%;
  margin-top: 1rem;
  box-sizing: border-box;
}

/* 阅读页文章头部 */
.page-story .story-header {
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.page-story .story-title {
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 400;
  margin: 0 0 0.25rem;
  color: var(--text);
  letter-spacing: 0.02em;
}

.page-story .story-meta {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.page-story .story-github {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.page-story .story-github:hover {
  color: var(--accent);
}

.story-body {
  font-size: 0.95rem;
}

.story-error {
  color: #c95c5c;
  padding: 1rem;
  font-size: 0.9rem;
}

.story-back-wrap {
  margin-top: 1rem;
  font-size: 0.85rem;
}

.back-link-inline {
  color: var(--accent);
  text-decoration: none;
}

.back-link-inline:hover {
  color: var(--text);
}

/* 阅读页底部：← 上一篇 | ↑ 返回顶部 | 下一篇 →（与「回到目录」同风格） */
.story-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding: 0;
  font-size: 0.85rem;
}

.story-nav-left {
  min-width: 5em;
  text-align: left;
}

.story-nav-right {
  min-width: 5em;
  text-align: right;
}

.story-nav .story-nav-btn {
  font-family: var(--serif);
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

.story-nav .story-nav-btn:hover {
  color: var(--text);
}

.story-nav .story-nav-btn.is-disabled {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

.page-story .story-copyright {
  margin-top: 1.5rem;
  padding-top: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.page-story .story-copyright a {
  color: var(--accent);
  text-decoration: none;
}

.page-story .story-copyright a:hover {
  color: var(--text);
}

/* 阅读区（保留以兼容 markdown 样式） */
.reader {
  padding: 1.5rem 2rem 3rem;
  background: var(--bg-card);
  overflow-y: auto;
}

.reader-body {
  font-size: 1rem;
}

/* Markdown 正文 */
.markdown h1,
.markdown h2,
.markdown h3 {
  font-family: var(--display);
  color: var(--accent);
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 600;
}

.markdown h1 { font-size: 1.35rem; }
.markdown h2 { font-size: 1.2rem; }
.markdown h3 { font-size: 1.05rem; }

.markdown p {
  margin: 0 0 1em;
  text-indent: 2em;
}

.markdown p:first-of-type {
  margin-top: 0;
}

.markdown hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 1.5em 0;
}

.markdown em {
  color: var(--text-muted);
  font-style: italic;
}

.markdown strong {
  color: var(--text);
  font-weight: 600;
}

.markdown a {
  color: var(--accent);
  text-decoration: none;
}

.markdown a:hover {
  text-decoration: underline;
}

.markdown blockquote {
  margin: 1em 0;
  padding-left: 1em;
  border-left: 3px solid var(--accent-dim);
  color: var(--text-muted);
}

/* 页脚：靠底 */
.site-footer {
  position: relative;
  z-index: 1;
  width: 100%;
  margin-top: auto;
  padding: 1.25rem 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.site-footer--compact {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer p {
  margin: 0.25em 0;
}

.site-footer .footer-copyright {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.9;
}
