/**
 * site 默认主题布局层（移动优先）。
 * 依赖 theme.css 的变量；两者随发布复制到 /assets/。
 */

/* ------------------------------- base ------------------------------- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  /* 窄屏兜底：任何漏网的宽元素都不产生整页横向滚动 */
  overflow-x: hidden;
  font-family: var(--font);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--spacing);
}

/* ------------------------------- header ----------------------------- */
.site-header {
  /* 建立自己的层叠上下文，避免下拉子菜单被下方内容（轮播图等）遮挡 */
  position: relative;
  z-index: 40;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.site-header-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: var(--nav-height);
  padding-top: 8px;
  padding-bottom: 8px;
}

/* 折叠开关：视觉隐藏但保留键盘可达（label 负责点击） */
.nav-toggle-checkbox {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.site-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 汉堡按钮（<1024px 显示，含平板；≥1024px 隐藏） */
.nav-toggle {
  display: inline-flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.nav-toggle-bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
}

.nav-toggle-checkbox:focus-visible ~ .site-header-bar .nav-toggle {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 面板默认收起，勾选后展开（纯 CSS） */
.site-header-panel {
  display: none;
}

.nav-toggle-checkbox:checked ~ .site-header-panel {
  display: block;
}

/* 点击遮罩默认隐藏；展开态仅在移动端 overlay 媒体查询里显示 */
.nav-toggle-backdrop {
  display: none;
}

.site-header-panel .site-nav {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.site-header-panel .site-search {
  padding-top: 8px;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
}

.site-logo {
  max-height: 32px;
  width: auto;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* 移动端：导航项为整行可点区域，满足最小点击高度；一级显式深色加粗与子项分层 */
.nav-item > a {
  display: block;
  padding: 11px 44px 11px 0;
  color: var(--text);
  font-weight: 600;
}

.nav-item {
  position: relative;
}

/* 子菜单手风琴：默认收起，勾选展开（纯 CSS，无 JS；桌面端 hover 下拉在此重置） */
.nav-acc {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.nav-acc-toggle {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--text-muted);
  cursor: pointer;
}

.nav-acc-toggle::before {
  content: '›';
  font-size: 1.375rem;
  line-height: 1;
  transform: rotate(90deg);
  transition: transform 0.15s ease;
}

.nav-acc:checked ~ .nav-acc-toggle::before {
  transform: rotate(-90deg);
}

.nav-acc:checked ~ .nav-sub {
  display: block;
}

.nav-sub {
  display: none;
  margin: 0;
  padding-left: 16px;
  list-style: none;
}

.nav-sub a {
  display: block;
  padding: 9px 0;
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* ------------------------------- main ------------------------------- */
.site-main {
  padding: var(--spacing) 0;
}

/* ------------------------- mobile tab bar (<1024) -------------------- */
.mobile-tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 45;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-tabbar a {
  flex: 1;
  padding: 10px 4px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 1023.98px) {
  /* 为固定底栏预留空间 */
  .site-main {
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }
}

@media (min-width: 1024px) {
  .mobile-tabbar {
    display: none;
  }
}

.page-title {
  margin: 8px 0 16px;
  font-size: 1.5rem;
}

.breadcrumb {
  margin-bottom: 12px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.breadcrumb-sep {
  margin: 0 6px;
}

/* -------------------- layout: content + sidebar column --------------- */
/* 有侧栏时正文列自适应、侧栏固定宽；窄屏（<1024px）自动堆叠为上下排列。
   两态都包一层 .site-content，见 default-templates.ts 的 pageChrome。 */
.site-layout {
  display: block;
}

@media (min-width: 1280px) {
  .site-layout.has-sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 32px;
    align-items: start;
  }
}

.site-sidebar {
  margin-top: 24px;
}

@media (min-width: 1280px) {
  .site-sidebar {
    margin-top: 0;
    position: sticky;
    top: 16px;
  }
}

.sidebar-block {
  padding: 12px 16px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.sidebar-block + .sidebar-block {
  margin-top: 16px;
}

.sidebar-block-title {
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  color: var(--text);
}

.sidebar-channel-list,
.sidebar-channel-sub,
.sidebar-latest-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar-channel-item + .sidebar-channel-item {
  margin-top: 4px;
}

.sidebar-channel-link {
  display: block;
  padding: 4px 0;
  font-size: 0.9375rem;
  color: var(--text);
}

.sidebar-channel-link.is-current {
  font-weight: 600;
  color: var(--primary);
}

.sidebar-channel-sub {
  margin: 4px 0;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.sidebar-channel-sub a {
  display: block;
  padding: 4px 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.sidebar-channel-sub a.is-current {
  font-weight: 600;
  color: var(--primary);
}

.sidebar-latest-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-latest-link {
  overflow: hidden;
  font-size: 0.9375rem;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-latest-item time {
  flex: none;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* home */
.home-columns {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-top: 24px;
}

.slot-home-hero .hero-item {
  display: block;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.slot-title {
  margin: 0 0 12px;
  font-size: 1.125rem;
  border-left: 4px solid var(--primary);
  padding-left: 8px;
}

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

.slot-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}

.slot-item time {
  color: var(--text-muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

/* channel list — thumbnail left, title row with inline date, summary below */
.article-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.article-list-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.article-thumb-link {
  flex: none;
}

.article-thumb {
  display: block;
  width: 128px;
  height: 85px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface, #f3f4f6);
}

.article-list-main {
  flex: 1;
  min-width: 0;
}

.article-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.article-list-link {
  min-width: 0;
  font-weight: 600;
}

/* Pinned badge rendered by the default templates when `item.pinned` is true. */
.article-pin {
  display: inline-block;
  flex: none;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent, #b91c1c);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  vertical-align: middle;
}

.article-list-time {
  flex: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

.article-summary {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* 平板+手机（<1024px）：缩略图正方形 */
@media (max-width: 1023.98px) {
  .article-list-item {
    gap: 12px;
  }

  .article-thumb {
    width: 80px;
    height: 80px;
    border-radius: 6px;
  }
}

/* 手机（<768px）：隐藏日期与摘要，列表条目仅保留缩略图+标题 */
@media (max-width: 767.98px) {
  .article-list-time {
    display: none;
  }

  .article-summary {
    display: none;
  }

  /* 栏目列表页：标题取消加粗、最多 3 行；内容与缩略图垂直居中 */
  .article-list-item {
    align-items: center;
  }

  .article-list-link {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    font-weight: 400;
  }

  /* 首页标签页文章列表：隐藏日期，标题最多 2 行 */
  .sp-dense-item .sp-dense-date {
    display: none;
  }

  .sp-dense-item .sp-dense-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    white-space: normal;
  }
}

/* channel children — underline-style jump links (same visual language as home tabs) */
.channel-children {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.channel-children-item {
  padding: 2px 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}

.channel-children-item:hover {
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

/* channel banner (optional per-channel list-page image) */
.channel-banner {
  margin: 0 0 16px;
}

.channel-banner img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* pagination */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
}

.pagination-current,
.pagination-link {
  min-width: 40px;
  padding: 8px 10px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pagination-current {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}

/* article */
.article-title {
  margin: 4px 0 8px;
  font-size: 1.5rem;
}

.article-subtitle {
  margin: 0 0 8px;
  color: var(--text-muted);
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.article-lead {
  padding: 12px;
  background: var(--bg-soft);
  border-radius: var(--radius);
}

.article-content {
  word-break: break-word;
}

.article-content img {
  border-radius: var(--radius);
}

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
}

.article-tag {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* article adjacent navigation */
.article-adjacent {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.article-adjacent-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.article-adjacent-label {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* blocks (blocks-renderer 输出) */
.block-image {
  margin: 16px 0;
}

.block-image figcaption {
  margin-top: 4px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.block-quote {
  margin: 16px 0;
  padding: 8px 16px;
  border-left: 4px solid var(--primary);
  background: var(--bg-soft);
}

.block-quote-cite {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.block-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.block-attachment a::before {
  content: '📎 ';
}

/* 宽内容在窄屏横向滚动，而不是撑破整页（表格 / 代码 / 嵌入视频） */
.block-table {
  display: block;
  max-width: 100%;
  margin: 16px 0;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.block-table th,
.block-table td {
  padding: 6px 10px;
  text-align: left;
  border: 1px solid var(--border);
}

.block-table thead th {
  background: var(--bg-soft);
}

.block-code {
  display: block;
  max-width: 100%;
  margin: 16px 0;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  background: var(--bg-soft);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

.block-embed {
  margin: 16px 0;
}

.block-embed iframe {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--radius);
}

.block-embed figcaption {
  margin-top: 4px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.block-video {
  margin: 16px 0;
}

.block-video video,
.block-video iframe {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--radius);
  background: #000;
}

.block-video-4-3 video,
.block-video-4-3 iframe {
  aspect-ratio: 4 / 3;
}

.block-video figcaption {
  margin-top: 4px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ------------------------------- footer ----------------------------- */
.site-footer {
  margin-top: 32px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
}

.footer-copyright,
.footer-icp {
  margin: 4px 0;
}

.footer-icp a {
  color: inherit;
  text-decoration: none;
}

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

.footer-qrcodes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin: 8px 0;
}

.footer-qrcode {
  margin: 0;
  text-align: center;
}

.footer-qrcode img {
  width: 88px;
  height: 88px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  transition: transform 0.15s ease;
}

.footer-qrcode:hover img {
  transform: scale(1.5);
}

.footer-qrcode figcaption {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ------------------------------- widgets ---------------------------- */
html {
  scroll-behavior: smooth;
}

.site-search {
  width: 100%;
}

.widget-search {
  position: relative;
}

.widget-search-input {
  width: 100%;
  padding: 6px 12px;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.widget-search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.widget-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 60;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgb(0 0 0 / 8%);
  max-height: 320px;
  overflow-y: auto;
}

.widget-search-results a {
  display: block;
  padding: 6px 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.widget-search-results a:hover {
  background: var(--bg-soft);
  color: var(--primary);
  text-decoration: none;
}

.site-social {
  margin-bottom: 8px;
}

.widget-social {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.widget-social-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.widget-social-link:hover {
  color: var(--primary);
  text-decoration: none;
}

.widget-social-icon {
  flex: none;
  fill: currentColor;
}

.widget-backtotop {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--bg);
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgb(0 0 0 / 18%);
  opacity: 0.85;
}

.widget-backtotop:hover {
  color: var(--bg);
  text-decoration: none;
  opacity: 1;
}

/* ------------------- mobile nav overlay (hamburger) ----------------- */
/*
 * 展开的导航面板必须作为覆盖层（脱离文档流），否则它会把 header 撑高、
 * 将下方内容整体顶下去。绝对定位相对 .site-header（已有 position: relative
 * 与 z-index 层叠上下文），因此面板悬浮在正文之上而不影响其布局。
 */
@media (max-width: 1023.98px) {
  /* 提升 header 层级，确保菜单与遮罩盖住正文及其他悬浮控件（如返回顶部按钮） */
  .site-header {
    z-index: 60;
  }

  /* 窄屏（含平板）：汉堡面板不放搜索框；侧栏（快捷导航）整体隐藏 */
  .site-header-panel .site-search {
    display: none;
  }

  .site-sidebar {
    display: none;
  }

  /* 点击遮罩：铺满 header 以下的可视区，点击即反选 checkbox 收起菜单 */
  .nav-toggle-checkbox:checked ~ .nav-toggle-backdrop {
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: calc(100vh - var(--nav-height));
    background: rgb(0 0 0 / 40%);
    cursor: pointer;
  }

  /* 面板在遮罩之后（DOM 靠后），同级 z-index 下自然绘制在遮罩之上 */
  .nav-toggle-checkbox:checked ~ .site-header-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: calc(100vh - var(--nav-height));
    overflow-y: auto;
    padding: 0 var(--spacing) var(--spacing);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 12px 24px rgb(0 0 0 / 12%);
  }
}

/* ------------------------- responsive (desktop ≥1024) ---------------- */
@media (min-width: 1024px) {
  .site-header-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  /* 桌面端：隐藏折叠开关，导航面板常驻并横向排列 */
  .nav-toggle,
  .nav-toggle-checkbox {
    display: none;
  }

  .site-header-bar {
    flex: none;
  }

  .site-header-panel {
    display: flex;
    align-items: center;
    gap: 24px;
  }

  /* 勾选态优先级高于基础收起规则，桌面端需强制常驻 flex（防移动端勾选后切到宽屏） */
  .nav-toggle-checkbox:checked ~ .site-header-panel {
    display: flex;
  }

  .site-header-panel .site-nav {
    padding-top: 0;
    border-top: 0;
  }

  .site-header-panel .site-search {
    padding-top: 0;
  }

  .site-search {
    width: 220px;
    flex: none;
  }

  .nav-list {
    flex-direction: row;
    gap: 24px;
    position: relative;
  }

  .nav-item > a {
    padding: 0;
  }

  /* 桌面端：隐藏手风琴箭头，子菜单回到 hover 下拉 */
  .nav-acc-toggle {
    display: none;
  }

  /* 桌面端：子菜单回到 hover 下拉（移动端的常驻展开在此重置） */
  .nav-sub {
    display: none;
    padding-left: 0;
  }

  .nav-sub a {
    padding: 4px 8px;
    font-size: 0.875rem;
    color: var(--text);
  }

  .nav-item {
    position: relative;
  }

  .nav-item:hover .nav-sub {
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 160px;
    padding: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgb(0 0 0 / 8%);
  }

  .home-columns {
    flex-direction: row;
  }

  .home-columns > .slot {
    flex: 1;
  }

  .home-columns > .slot-home-headline {
    flex: 2;
  }

  .page-title,
  .article-title {
    font-size: 1.75rem;
  }
}

/* Section 纵向节奏统一收敛（详见 docs/modules/site/sections.md §10 附录）
   特异性 (0,5,0) 高于 sections.css 里 py-* 的 (0,1,0)，加载顺序无关。
   新增 section 自动继承，无需改动组件。
   间距改由变量驱动：顶层 section 默认「无上留白 + 一节下留白」，显式配置了统一间距的
   section 由渲染层的 .sp-item 包裹层注入 --sp-section-*，这里读到即生效——
   不再出现「在组件上写了 py-* 却被归零规则压掉」的情况。 */
/* -------------------- unified horizontal content inset --------------- */
/* 左右内容缘对齐契约：header / footer / 模板页正文全部与 section 默认内容缘一致
   = 页面页边距(--spacing) + section 默认内缩(--sp-section-px，移动端 16)。
   之前各页面各自为政（header 靠站点 extra_css 手工 calc 对齐、footer 与模板页
   只有 16px），导致下方内容缘比顶部栏凸出 24px/侧。
   有侧栏页在 .site-layout 容器上整体内缩（正文列与侧栏一起对齐），其
   .site-content 子元素不再重复内缩；sections 页子节点是 .sp-section/.sp-item
   （自带内缩），同样排除。 */
.site-header .container,
.site-footer .container,
.site-main > .container.site-layout:not(.has-sidebar) > .site-content > :not(.sp-item):not(.sp-section),
.site-main > .container.site-layout.has-sidebar {
  padding-inline: calc(var(--spacing) + var(--sp-section-px, 24px));
}

/* ---------------- 窄屏覆写（置于对齐契约之后以生效） ---------------- */
@media (max-width: 1023.98px) {
  /* 平板：对齐缩进叠加过宽，页边距收敛 */
  .site-main > .container.site-layout.has-sidebar {
    padding-inline: 24px;
  }

  /* 窄屏：header/footer 与正文页边距对齐（对齐契约的 40px 仅适用桌面宽屏） */
  .site-header .container,
  .site-footer .container {
    padding-inline: var(--spacing);
  }

  /* 窄屏：返回顶部按钮上移，避开底部导航（本规则须位于基础规则之后） */
  .widget-backtotop {
    bottom: calc(64px + env(safe-area-inset-bottom));
  }

  /* 窄屏取消面包屑（底部导航/汉堡已覆盖导航需求） */
  .breadcrumb {
    display: none;
  }

  /* 汉堡面板为白底：面板内导航用深色系（特异性压过站点 extra_css 在绿渐变
     头部上的白字配色；桌面横向导航仍在渐变上，保持白色） */
  .site-header .site-nav .nav-item > a {
    color: var(--text);
  }

  .site-header .site-nav .nav-sub a {
    color: var(--text-muted);
  }

  /* 首页 sections：外层 .container 已提供页边距。sections 内部容器缩进由
     --sp-section-px/--sp-section-pl/--sp-section-pr 变量兜底（含 .sp-item
     .sp-container 等高特异性规则与祖先继承链），对所有 sections 层强制归零，
     避免逐条对抗特异性（!important 用于压过渲染器在中间层设置的变量） */
  .site-main,
  .site-main .sp-section,
  .site-main .sp-item,
  .site-main .sp-container {
    --sp-section-px: 0 !important;
    --sp-section-pl: 0 !important;
    --sp-section-pr: 0 !important;
  }

  .site-main .sp-container {
    padding-inline: 0;
  }

  /* 首页轮播：窄屏保持桌面同款 3:2 原始比例（原为固定高度裁切） */
  .sp-section .snap-x {
    height: auto;
    aspect-ratio: 3 / 2;
  }
}

@media (max-width: 767.98px) {
  /* 手机：统一 16px 页边距 */
  .site-main > .container.site-layout.has-sidebar {
    padding-inline: var(--spacing);
  }
}

/* 平板及以下（含 iPad 横屏 1024-1279）取消列表页侧栏，布局为单列 */
@media (max-width: 1279.98px) {
  .site-sidebar {
    display: none;
  }
}

/* 顶层 section 的直系链有两态：无侧栏时 .site-main > .container > .sp-section，
   有侧栏时正文被 .site-content 包裹（页面结构见 server/theme/default-templates.ts），
   两条选择器必须同时命中，否则未配置 spacing 的 section 会丢掉默认纵向节奏。 */
.site-main > .container > .sp-section > .sp-container,
.site-main > .container > .site-content > .sp-section > .sp-container {
  padding-block: var(--sp-section-pt, 0) var(--sp-section-pb, var(--sp-section-y));
  max-width: var(--sp-section-max-w, var(--sp-max-w));
  padding-inline: var(--sp-section-pl, var(--sp-section-px, 24px))
    var(--sp-section-pr, var(--sp-section-px, 24px));
}

/* 移动端纵向节奏压缩，作用于所有 section */
@media (max-width: 767px) {
  :root {
    --sp-section-y: 48px;
    --sp-section-px: 16px;
  }
  .site-main > .container > .sp-section > .sp-container,
  .site-main > .container > .site-content > .sp-section > .sp-container {
    padding-inline: var(--sp-section-pl, var(--sp-section-px, 16px))
      var(--sp-section-pr, var(--sp-section-px, 16px));
  }
}
