/* ===== 综合门户首页 ===== */
.portal-page { background: var(--bg); }
.portal-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px calc(var(--footer-stack) + env(safe-area-inset-bottom, 0px) + 60px);
}
.portal-hero { padding: 0 0 26px; }
.portal-kicker {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--brand);
  text-transform: uppercase;
}
.portal-title {
  margin: 0 0 10px;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4.4vw, 3rem);
  line-height: 1.15;
}
.portal-sub {
  margin: 0 0 22px;
  color: var(--text-soft);
  font-size: .98rem;
  max-width: 46em;
}
.portal-search {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
/* 搜索框吸顶：与书籍页 .search-well 一致（--header-h 由脚本按实际顶栏高度写入） */
.portal-search-bar {
  position: sticky;
  top: var(--header-h, calc(var(--bar-h) + env(safe-area-inset-top, 0px)));
  z-index: 35;
  width: 100%;
  padding: 16px 24px 12px;
  background: var(--bg);
  box-shadow: 0 1px 0 var(--border);
}
.portal-search-bar .portal-search {
  max-width: 1072px;
  margin: 0 auto;
}
.portal-search-field {
  flex: 1 1 320px;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  height: 52px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow, 0 18px 40px -28px rgba(0,0,0,.45));
}
/* 与书籍页 .search-icon 一致 */
.portal-search-field .search-icon {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  margin-left: 18px;
  color: var(--muted);
}
.portal-search-field input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  outline: none;
}
.portal-scope {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
}
.portal-scope-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.portal-scope select {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  outline: none;
  cursor: pointer;
}
.portal-search-btn {
  height: 52px;
  min-width: 108px;
  padding: 0 26px;
  border-radius: 14px;
  font-size: 15px;
}
.portal-search-hint { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }
.portal-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  width: 100%;
  margin: 8px 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-2) 86%, transparent);
  overflow: hidden;
}
.portal-stats li {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 16px 18px;
  border: 0;
}
.portal-stats li + li {
  border-left: 0;
}
.portal-stats strong {
  font-family: var(--font-serif);
  font-size: 1.45rem;
  font-weight: 650;
  line-height: 1.15;
  color: var(--text);
  letter-spacing: 0;
  white-space: nowrap;
}
.portal-stats span {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.2;
}
html[data-theme="dark"] .portal-stats {
  background: var(--card);
  border-color: var(--border-strong);
}
html[data-theme="dark"] .portal-stats li + li {
  border-left: 0;
}

.portal-h2 {
  margin: 0 0 12px;
  font-size: 1.02rem;
  letter-spacing: .02em;
}
.portal-h2-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
body.portal-page .portal-more,
body.portal-page .portal-more:hover,
body.portal-page .portal-more:focus,
body.portal-page .portal-more:visited {
  color: #0052D9;
  font-size: 13px;
  text-decoration: none;
}
body.portal-page .portal-more:hover,
body.portal-page .portal-more:focus { text-decoration: underline; }

.portal-sections { margin: 16px 0 34px; }
.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.portal-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 16px;
  border: 1px solid color-mix(in srgb, var(--card-border, var(--border)) 85%, transparent);
  border-radius: 16px;
  background: var(--card-face);
  box-shadow: var(--card-shadow, 0 1px 2px rgba(0,0,0,.06));
  color: var(--text);
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.portal-card:hover {
  border-color: var(--brand);
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover, 0 12px 26px -18px rgba(0,0,0,.5));
}
.portal-card-icon { font-size: 26px; line-height: 1; }
.portal-card-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.portal-card-title { font-weight: 650; font-size: 1rem; }
.portal-card-desc { color: var(--text-soft); font-size: 12.5px; line-height: 1.45; }
.portal-card-meta { color: var(--brand); font-size: 12px; font-weight: 600; }
.portal-card-go { margin-left: auto; align-self: center; color: var(--muted); }

.portal-hot { margin: 0 0 24px; }
.portal-hot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.portal-hot-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--card-border, var(--border)) 80%, transparent);
  border-radius: 12px;
  background: var(--card-face);
  box-shadow: var(--card-shadow, 0 1px 2px rgba(0,0,0,.05));
  text-decoration: none;
  transition: border-color .16s ease, transform .16s ease;
}
.portal-hot-card:hover { border-color: var(--brand); transform: translateY(-1px); }
.portal-hot-card .hot-icon { width: 30px; height: 30px; border-radius: 8px; object-fit: contain; background: rgba(255,248,236,.08); }
.portal-hot-card .hot-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.portal-hot-card .hot-name { color: var(--text); font-size: .86rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-hot-card .hot-count { color: var(--amber); font-size: .74rem; }
body.portal-page .portal-hot:not(#portal-open-source-section) .hot-count {
  color: var(--amber);
}

@media (max-width: 720px) {
  .portal-main { padding: 0 14px calc(var(--footer-stack) + env(safe-area-inset-bottom, 0px) + 70px); }
  .portal-search-bar { padding: 16px 14px 10px; }
  .portal-search-bar .portal-search,
  .portal-search-bar .portal-ticker { max-width: none; }
  .portal-search-field { flex-basis: 100%; }
  .portal-scope { flex: 1 1 auto; }
  .portal-search-btn { flex: 1 1 auto; }
  .portal-stats li { padding: 12px 10px; }
  .portal-stats strong { font-size: 1.12rem; }
  .portal-stats span { font-size: 11px; }
}

/* 搜索主按钮：两种主题下保持对比度 */
.portal-search-btn {
  background: var(--brand);
  border: 1px solid transparent;
  color: #fff;
  font-weight: 600;
}
.portal-search-btn:hover { background: var(--brand-2); }
html[data-theme="dark"] .portal-search-btn { color: var(--on-brand); }
html[data-theme="dark"] .portal-search-btn:hover { background: var(--brand-2); color: var(--on-brand); }

/* 窄屏顶栏：品牌单独一行 + 导航第二行，避免挤压 */
@media (max-width: 720px) {
  body.portal-page .topbar {
    height: auto;
    min-height: 0;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 0 8px;
  }
  body.portal-page .topbar-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "nav nav";
    align-items: center;
    column-gap: 10px;
    row-gap: 8px;
    height: auto;
    padding: 0 16px;
  }
  body.portal-page .topbar-inner .brand {
    grid-area: brand;
    justify-self: start;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: 17px;
    text-align: left;
  }
  body.portal-page .topbar-inner .header-tools {
    grid-area: actions;
    justify-self: end;
    margin-left: 0;
  }
  body.portal-page .topbar-inner .header-nav {
    grid-area: nav;
    justify-content: center;
    flex-wrap: wrap;
    margin-left: 0;
    gap: 4px 8px;
  }
  body.portal-page .header-home,
  body.portal-page .header-papers { padding: 0 6px; font-size: 13px; }
}

/* 搜索框：与书籍/软件页搜索框同款质感 */
.portal-search-field {
  border: 1px solid color-mix(in srgb, var(--brand) 46%, var(--border-strong));
  background: var(--search-bg);
  box-shadow:
    0 1px 0 color-mix(in srgb, #fff 50%, transparent),
    0 4px 10px -6px rgba(48, 36, 20, 0.32);
}
.portal-search-field:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand), var(--shadow);
}
.portal-search-field:focus-within .search-icon { color: var(--brand); }
.portal-scope {
  border: 1px solid color-mix(in srgb, var(--brand) 46%, var(--border-strong));
  background: var(--search-bg);
  box-shadow:
    0 1px 0 color-mix(in srgb, #fff 50%, transparent),
    0 4px 10px -6px rgba(48, 36, 20, 0.32);
}
html[data-theme="dark"] .portal-search-field,
html[data-theme="dark"] .portal-scope {
  border-color: var(--card-border);
  background: var(--search-bg);
  box-shadow:
    inset 0 1px 0 rgba(255, 244, 220, 0.14),
    2px 3px 4px rgba(0, 0, 0, 0.55),
    4px 7px 12px rgba(0, 0, 0, 0.62);
}
html[data-theme="dark"] .portal-search-field:focus-within,
html[data-theme="dark"] .portal-scope:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 55%, transparent);
}

/* 搜索按钮：紧凑尺寸，不参与 flex 拉伸 */
.portal-search-btn {
  flex: 0 0 auto;
  width: auto;
  height: 48px;
  min-height: 48px;
  min-width: 0;
  padding: 0 22px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
}
@media (max-width: 720px) {
  body.portal-page .portal-search-btn {
    flex: 0 0 auto;
    height: 46px;
    padding: 0 18px;
  }
}

/* 覆盖 .btn.primary 的 flex 拉伸（更高优先级） */
.btn.primary.portal-search-btn {
  flex: 0 0 auto;
  width: auto;
  height: 48px;
  min-height: 48px;
  padding: 0 22px;
}
@media (max-width: 720px) {
  body.portal-page .btn.primary.portal-search-btn {
    flex: 0 0 auto;
    height: 46px;
    padding: 0 16px;
  }
}

/* Hero 文案移除后收紧留白 */
.portal-hero { padding: 8px 0 10px; background: transparent; }

/* 首页内容流：热门书籍 / 精选论文 / 随机 LoRA */
.portal-feed { margin: 0 0 26px; }
.portal-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.portal-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--card-border, var(--border)) 82%, transparent);
  border-radius: 12px;
  background: var(--card-face);
  box-shadow: var(--card-shadow, 0 1px 2px rgba(0,0,0,.05));
  color: var(--text);
  text-decoration: none;
  transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.portal-item:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: var(--card-shadow-hover, 0 10px 22px -16px rgba(0,0,0,.45));
}
.portal-item-title {
  font-size: .9rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.portal-item-meta {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.portal-empty { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
@media (max-width: 720px) {
  .portal-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .portal-item { padding: 10px 11px; }
  .portal-item-title { font-size: .84rem; }
}

/* 首页内容卡片：下载按钮 */
.portal-item { padding-bottom: 10px; }
.portal-item-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.portal-item-dl {
  align-self: flex-start;
  margin-top: 8px;
  padding: 3px 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 55%, var(--border));
  border-radius: 999px;
  color: var(--brand);
  font-size: 12px;
  line-height: 1.6;
  text-decoration: none;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.portal-item-dl:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand, #fff);
}
html[data-theme="dark"] .portal-item-dl { color: var(--brand); }
html[data-theme="dark"] .portal-item-dl:hover { color: var(--on-brand); }

/* 首页内容卡片的下载按钮：与书籍卡片一致（绿色胶囊） */
.portal-item-dl {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 30px;
  margin-top: 8px;
  padding: 0 10px;
  border: 1px solid #07C160;
  border-radius: 999px;
  background: #07C160;
  color: #fff;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .04em;
  line-height: 1;
  text-decoration: none;
  transition: background .14s ease, border-color .14s ease;
}
.portal-item-dl:hover,
html[data-theme="dark"] .portal-item-dl:hover {
  border-color: #06ad56;
  background: #06ad56;
  color: #fff;
}
html[data-theme="dark"] .portal-item-dl {
  border-color: #07C160;
  background: #07C160;
  color: #fff;
}

/* 热门书籍 / 热门软件：固定两行展示 */
#portal-books {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.portal-hot-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
@media (max-width: 1099px) {
  #portal-books,
  .portal-hot-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  #portal-books > *:nth-child(n + 9),
  .portal-hot-grid > *:nth-child(n + 9) {
    display: none;
  }
}
@media (max-width: 720px) {
  #portal-books,
  .portal-hot-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #portal-books > *:nth-child(n + 5),
  .portal-hot-grid > *:nth-child(n + 5) {
    display: none;
  }
}
/* 桌面 5 列时热门软件正好 10 张。开源目录更长，同样只留两行。 */
#portal-open-source > *:nth-child(n + 11) {
  display: none;
}

/* 下载按钮固定在卡片底部 */
.portal-item {
  height: 100%;
}
.portal-item-main {
  flex: 1 1 auto;
}
.portal-item-dl {
  flex: 0 0 auto;
  margin-top: auto;
}

/* 首页书籍卡片：大小/次数这一行固定在下载按钮上方（标题长短不同也对齐） */
#portal-books .portal-item-meta {
  margin-top: auto;
}

/* 首页论文卡片：分类/大小（cs.AI · 1.4MB）这一行同样固定在下载按钮上方 */
#portal-papers .portal-item-meta {
  margin-top: auto;
}

/* 精选论文 / 热门 LoRA：固定单行（列数随宽度变化） */
#portal-papers,
#portal-lora {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
@media (max-width: 1099px) {
  #portal-papers,
  #portal-lora { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  #portal-papers,
  #portal-lora { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 移动端搜索区：输入框 + 范围 + 按钮同一行 */
@media (max-width: 720px) {
  .portal-search {
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
  }
  .portal-search-field {
    flex: 1 1 auto;
    min-width: 0;
    height: 46px;
    padding: 0 12px;
  }
  .portal-search-field input {
    font-size: 14px;
    padding: 0 4px;
  }
  .portal-scope {
    flex: 0 0 auto;
    height: 46px;
    padding: 0 8px;
    gap: 4px;
  }
  .portal-scope-label { display: none; }
  .portal-scope select { font-size: 14px; }
  body.portal-page .btn.primary.portal-search-btn {
    flex: 0 0 auto;
    height: 46px;
    padding: 0 14px;
    font-size: 14px;
  }
}

/* 热门开源项目：列表行 */
.portal-repos { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.portal-repo {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--card-border, var(--border)) 82%, transparent);
  border-radius: 12px;
  background: var(--card-face);
  box-shadow: var(--card-shadow, 0 1px 2px rgba(0,0,0,.05));
  color: var(--text);
  text-decoration: none;
  transition: border-color .16s ease, transform .16s ease;
}
.portal-repo:hover { border-color: var(--brand); transform: translateY(-1px); }
.portal-repo-avatar { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; background: var(--surface-3); }
.portal-repo-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.portal-repo-name { font-size: .88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-repo-desc { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-repo-meta { flex: 0 0 auto; font-size: 12px; color: var(--brand); white-space: nowrap; }
@media (max-width: 720px) {
  .portal-repo { padding: 9px 12px; gap: 10px; }
  .portal-repo-desc { display: none; }
}

/* 热门开源项目：多列卡片，单行展示 */
#portal-repos { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.portal-repo-card { gap: 6px; padding: 12px 14px; }
.portal-repo-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.portal-repo-card .portal-item-title { flex: 1 1 auto; min-width: 0; }
.portal-repo-card-desc {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
@media (max-width: 1099px) {
  #portal-repos { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  #portal-repos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .portal-repo-card-desc { display: none; }
}

/* 热门开源项目：固定 2 列 × 5 行 */
#portal-repos {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}
#portal-repos .portal-repo-card-desc {
  display: -webkit-box;
}
@media (max-width: 720px) {
  #portal-repos { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  #portal-repos .portal-repo-card-desc { display: none; }
}

/* 热门开源项目：桌面一行 3 个；平板 2 个；最窄 1 个 */
#portal-repos {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}
@media (max-width: 1099px) {
  #portal-repos { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
@media (max-width: 720px) {
  #portal-repos { grid-template-columns: 1fr !important; }
  #portal-repos .portal-repo-card-desc { display: -webkit-box; }
}

/* 窄屏顶栏：品牌居中 + 导航固定单行（覆盖前面的 portal 规则） */
@media (max-width: 720px) {
  body.portal-page .topbar-inner {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas:
      ". brand actions"
      "nav nav nav";
  }
  body.portal-page .brand {
    grid-area: brand;
    justify-self: center;
    justify-content: center;
    text-align: center;
    font-size: 17px;
  }
  body.portal-page .header-tools { grid-area: actions; justify-self: end; margin-left: 0; }
  body.portal-page .header-nav {
    grid-area: nav;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  body.portal-page .header-nav::-webkit-scrollbar { display: none; }
  body.portal-page .header-home,
  body.portal-page .header-papers { padding: 0 5px; font-size: 12px; }
  body.portal-page .header-nav .header-github-hot--nav { height: 28px; padding: 0 2px; }
  body.portal-page .header-nav .header-help--nav { height: 28px; padding: 0 4px; font-size: 12px; }
}

/* 首页窄屏导航行：垂直居中对齐 */
@media (max-width: 720px) {
  body.portal-page .header-nav { align-items: center; }
  body.portal-page .header-nav .header-home,
  body.portal-page .header-nav .header-papers,
  body.portal-page .header-nav .header-github-hot--nav,
  body.portal-page .header-nav .header-help--nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    line-height: 1;
  }
}

/* 窄屏导航：强制单行可滚动（覆盖 wrap 规则） */
@media (max-width: 720px) {
  body.portal-page .topbar-inner .header-nav,
  body.portal-page .header-nav {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
  }
  body.portal-page .header-nav .header-help--nav,
  body.portal-page .header-nav .header-github-hot--nav { display: inline-flex !important; }
}

/* 首页窄屏导航：左对齐安全居中，避免首项被裁切 */
@media (max-width: 720px) {
  body.portal-page .topbar-inner .header-nav,
  body.portal-page .header-nav { justify-content: safe center !important; }
}

/* 窄屏：GitHub / 帮助 固定第一行 */
@media (max-width: 720px) {
  body.portal-page .header-tools .header-github-hot { display: inline-flex !important; }
  body.portal-page .header-tools .header-help--desk { display: inline-flex !important; }
  body.portal-page .header-nav .header-github-hot--nav,
  body.portal-page .header-nav .header-help--nav { display: none !important; }
}

/* 窄屏导航字号统一 */
@media (max-width: 720px) {
  .header-nav .header-home,
  .header-nav .header-papers {
    font-size: 13px !important;
    padding: 0 8px !important;
    height: 32px;
  }
  .header-nav .header-github-hot--nav,
  .header-nav .header-help--nav { height: 32px; }
}

/* 窄屏导航项高度统一 */
@media (max-width: 720px) {
  body.portal-page .header-nav .header-home,
  body.portal-page .header-nav .header-papers { height: 32px !important; }
}

/* 卡片副标题（另一语言） */
.portal-item-alt {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}

/* 首页书籍卡片：标题/大小/次数/下载按钮按当前语言只显示一种 */
.portal-item .l-en { display: none; }
html[data-site-lang="en"] .portal-item .l-zh { display: none; }
html[data-site-lang="en"] .portal-item .l-en { display: inline; }

/* HERO: a slow brass lamp drifting behind the reading-room stats.
   Search stays opaque and sticky; this layer never covers the field. */
@keyframes portal-ink-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes portal-rise {
  from { opacity: 0; translate: 0 10px; }
  to { opacity: 1; translate: 0 0; }
}
@keyframes portal-lamp {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(2.2%, -1.4%, 0) scale(1.06); }
}

body.portal-page .portal-search-bar {
  animation: portal-ink-in 720ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
body.portal-page .portal-hero {
  position: relative;
  isolation: isolate;
}
body.portal-page .portal-stats {
  animation: portal-rise 860ms cubic-bezier(0.16, 1, 0.3, 1) 90ms both;
}
body.portal-page .portal-hero::before,
body.portal-page .portal-hero::after,
html[data-theme="dark"] body.portal-page .portal-hero::before,
html[data-theme="dark"] body.portal-page .portal-hero::after {
  content: none;
  background: none;
  display: none;
}

body.portal-page .portal-hot-grid > .portal-hot-card {
  animation: portal-rise 560ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(1) { animation-delay: 40ms; }
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(2) { animation-delay: 80ms; }
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(3) { animation-delay: 120ms; }
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(4) { animation-delay: 160ms; }
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(5) { animation-delay: 200ms; }
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(6) { animation-delay: 240ms; }
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(7) { animation-delay: 280ms; }
body.portal-page .portal-hot-grid > .portal-hot-card:nth-child(n + 8) { animation-delay: 320ms; }

body.portal-page .portal-hot-card,
body.portal-page .portal-item {
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), border-color 180ms ease, box-shadow 180ms ease;
}
body.portal-page .portal-hot-card:hover,
body.portal-page .portal-hot-card:focus-visible,
body.portal-page .portal-item:hover,
body.portal-page .portal-item:focus-visible {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--brand) 72%, #6b4520);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--brand) 48%, transparent),
    var(--card-shadow-hover);
}
body.portal-page .portal-hot-card:focus-visible,
body.portal-page .portal-item:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

#portal-open-source .os-mark {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  overflow: hidden;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
#portal-open-source .os-mark img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#portal-open-source .hot-count {
  display: block;
  color: var(--muted);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  body.portal-page .portal-hero::before,
  body.portal-page .portal-hero::after,
  body.portal-page .portal-search-bar,
  body.portal-page .portal-stats,
  body.portal-page .portal-hot-grid > .portal-hot-card {
    animation: none !important;
  }
  body.portal-page .portal-hot-card,
  body.portal-page .portal-item {
    transition: none;
  }
  body.portal-page .portal-hot-card:hover,
  body.portal-page .portal-hot-card:focus-visible,
  body.portal-page .portal-item:hover,
  body.portal-page .portal-item:focus-visible {
    transform: none;
  }
}
