/* =========================================================
   Nebula Drop · 星云坞 — 响应式适配层
   载入顺序：base.css → site.css / admin.css → responsive.css
   断点：≥1600 超宽 · ≤1280 笔记本 · ≤1080 平板横 · ≤900 平板竖
         ≤768 大手机 · ≤600 手机 · ≤430 小屏 · ≤360 极窄
   ========================================================= */

/* ---------------------------------------------------------
   0. 流体变量
   --------------------------------------------------------- */
:root {
  --gutter: clamp(13px, 3.6vw, 24px);
  --hdr-h: 68px;
  --tap: 42px;
}

/* 超宽屏：内容不再无限拉伸，改为更大的留白 */
@media (min-width: 1600px) {
  :root { --maxw: 1400px; }
}

/* ---------------------------------------------------------
   1. 全局防溢出
   --------------------------------------------------------- */
img, video, iframe, svg { max-width: 100%; }
pre, code { overflow-wrap: break-word; }
pre { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mono, .ver-pill, .ms-lk-file, .dl-note { overflow-wrap: anywhere; }

/* 可横向滚动的容器统一隐藏滚动条并保留惯性 */
.ms-table-wrap, .tbl-scroll, .cat-bar, .filter-bars {
  -webkit-overflow-scrolling: touch;
}

/* ---------------------------------------------------------
   1.5 分类条：等宽网格，换行后每行均分、右边缘对齐
   列数取分类数的公因数（6 / 4 / 3），避免最后一行只剩一两个
   --------------------------------------------------------- */
.cat-bar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  overflow: visible;
  padding-bottom: 0;
}
.cat-bar > * { min-width: 0; }
.cat-bar > .cat-chip {
  width: 100%;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cat-chip > .count,
.cat-chip > svg { flex: none; }

@media (max-width: 1023px) {
  .cat-bar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .cat-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* 数量不整除时，最后一个标签占满剩余空间，不留孤块 */
  .cat-bar > .cat-chip:last-child:nth-child(3n + 1) { grid-column: 1 / -1; }
  .cat-bar > .cat-chip:last-child:nth-child(3n + 2) { grid-column: span 2; }
}
@media (max-width: 360px) {
  .cat-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 微软 / Office / 镜像站工具栏里的家族筛选数量少，保持自适应宽度 */
.ms-toolbar .cat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ms-toolbar .cat-bar > .cat-chip { width: auto; }

/* ---------------------------------------------------------
   2. 头部：移动端抽屉导航
   --------------------------------------------------------- */
.header-inner { height: var(--hdr-h); gap: 14px; }
.header-search { max-width: 272px; }

.nav-toggle {
  display: none;
  flex: none;
  width: var(--tap);
  height: var(--tap);
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 11px;
  border: 1px solid var(--line-2);
  background: var(--ov-3);
  color: var(--fg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.nav-toggle:hover { background: var(--ov-5); border-color: var(--line-3); }
.nav-toggle:active { transform: scale(.96); }
.nav-toggle svg { pointer-events: none; }
.nav-toggle .ico-close { display: none; }
body.nav-open .nav-toggle { position: relative; z-index: 130; }
body.nav-open .nav-toggle .ico-menu { display: none; }
body.nav-open .nav-toggle .ico-close { display: block; }

.nav-scrim {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(3, 5, 12, .66);
  backdrop-filter: blur(3px);
  animation: nd-scrim-in .24s var(--ease);
}
@keyframes nd-scrim-in { from { opacity: 0; } }

/* 抽屉内部件（桌面端隐藏） */
.nav-drawer-top,
.nav-extra { display: none; }

.nav-search {
  position: relative;
  display: block;
  margin-bottom: 10px;
}
.nav-search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-4);
  pointer-events: none;
}
.nav-search .input {
  height: 42px;
  padding-left: 36px;
  border-radius: 12px;
  font-size: 13.5px;
}
.nav-extra {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

/* ---------------------------------------------------------
   3. ≤1280 笔记本：目录略紧
   --------------------------------------------------------- */
@media (max-width: 1280px) {
  .nav a { padding-left: 10px; padding-right: 10px; }
  .header-search { max-width: 230px; }
}

/* ---------------------------------------------------------
   4. ≤1080 平板横屏
   --------------------------------------------------------- */
@media (max-width: 1080px) {
  .hero { padding: 48px 0 28px; }
  .detail-layout { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
  .ms-src-grid,
  .ms-lic-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 268px), 1fr)); }
}

/* ---------------------------------------------------------
   5. ≤900 平板竖屏 → 导航切抽屉
   --------------------------------------------------------- */
@media (max-width: 900px) {
  :root { --hdr-h: 60px; }

  .header-inner { gap: 10px; }
  .header-search,
  .header-actions { display: none; }
  .nav-toggle { display: inline-flex; margin-left: auto; }
  .brand-sub { font-size: 8.5px; letter-spacing: .18em; }

  .nav {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    width: min(86vw, 340px);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: calc(var(--hdr-h) + 10px) 12px calc(16px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(13, 17, 31, .99), rgba(7, 10, 19, .99));
    border-left: 1px solid var(--line-2);
    box-shadow: -40px 0 90px -46px #000;
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(101%);
    visibility: hidden;
    transition: transform .32s var(--ease), visibility .32s var(--ease);
  }
  body.nav-open .nav { transform: none; visibility: visible; }
  body.nav-open { overflow: hidden; }

  .nav a {
    display: flex;
    align-items: center;
    min-height: 46px;
    padding: 0 14px;
    border-radius: 11px;
    font-size: 14.5px;
    color: var(--fg-2);
  }
  .nav a.is-active {
    color: #fff;
    background: rgba(var(--brand-rgb), .18);
    box-shadow: inset 0 0 0 1px rgba(var(--brand-rgb), .28);
  }
  .nav-drawer-top,
  .nav-extra { display: block; }
  .nav-extra .btn { justify-content: center; min-height: 42px; font-size: 13.5px; }

  /* 抽屉打开时锁住底层页面，避免穿透滚动 */
  body.nav-open .site-header { background: transparent; }

  /* 首页 hero 与页面容器 */
  .hero { padding: 36px 0 24px; }
  .hero h1 { font-size: clamp(28px, 6.4vw, 40px); }
  .hero-lead { font-size: 14.5px; margin-bottom: 22px; }
  .hero-search { max-width: none; }
  .hero-search .input { padding-right: 116px; }

  .app-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
  .app-grid.is-featured { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
}

/* ---------------------------------------------------------
   6. ≤768 大手机
   --------------------------------------------------------- */
@media (max-width: 768px) {
  body { font-size: 14px; }

  .btn { height: 40px; }
  .btn-sm { height: 32px; }
  .btn-lg { height: 46px; }

  .hero h1 { font-size: clamp(26px, 7.2vw, 34px); letter-spacing: -.03em; }
  .hero-lead { font-size: 14px; line-height: 1.72; }
  .hero-stats { gap: 8px 18px; font-size: 12px; }
  .hero-search .input { height: 50px; padding-left: 44px; padding-right: 104px; font-size: 14px; }
  .hero-search .btn { height: 38px; padding: 0 16px; font-size: 13px; }

  .section { padding-top: 30px; }
  .sect-head { flex-wrap: wrap; gap: 8px; }

  /* 表格：改为横向滚动，不压缩列宽 */
  .ms-table { min-width: 720px; }
  .tbl { min-width: 640px; }

  /* 直链面板：操作按钮换行到下一排 */
  .ms-lk { flex-wrap: wrap; row-gap: 7px; }
  .ms-lk-body { flex-basis: calc(100% - 62px); }
  .ms-lk-act {
    width: 100%;
    justify-content: flex-end;
    padding-top: 2px;
  }
  .ms-lk-act .ms-cp,
  .ms-lk-act .ms-open { padding: 5px 12px; font-size: 11.2px; }

  .ms-toolbar { gap: 8px; }
  .ms-search { width: 100%; }
  .ms-toolbar .cat-bar { flex-basis: 100%; }

  .dl-grid { padding: 12px; }

  .detail-hero { padding: 18px; border-radius: var(--r-lg); }
  .detail-id { gap: 12px; }
  .detail-id h1 { font-size: 21px; }
  .detail-desc { font-size: 13px; margin-top: 16px; }
  .ver-panel-head { padding: 12px 14px; }
  .meta-row { font-size: 12px; }

  .footer-grid { grid-template-columns: 1fr; gap: 24px; }
  .site-footer { margin-top: 30px; padding: 32px 0 calc(28px + env(safe-area-inset-bottom)); }
  .footer-bottom { font-size: 11px; }
}

/* ---------------------------------------------------------
   7. ≤600 手机
   --------------------------------------------------------- */
@media (max-width: 600px) {
  .app-grid,
  .app-grid.is-featured,
  .hl-list,
  .mc-grid,
  .ms-src-grid,
  .ms-lic-grid,
  .ad-slot-grid { grid-template-columns: 1fr; }

  /* 手机上分类标签收紧密度，减少换行行数 */
  .cat-bar { gap: 7px; row-gap: 7px; }
  .cat-chip { height: 30px; padding: 0 11px; font-size: 12px; }

  .app-card { padding: 15px; }
  .app-card h3 { font-size: 14px; }

  /* 广告位：横条改竖排 */
  .ad-hero { flex-wrap: wrap; }
  .ad-hero .ad-cta { width: 100%; justify-content: center; margin-left: 0; }

  /* 详情页版本表 */
  .os-tabs { overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .os-tabs::-webkit-scrollbar { display: none; }
  .os-tab { flex: none; }

  /* 复制/跳转按钮在触屏上要够大 */
  .ms-cp, .ms-open { min-height: 32px; }

  .ms-uup-bar code { font-size: 10.5px; }
  .ms-lk-note, .ms-lk-foot { margin-left: 12px; margin-right: 12px; }

  .modal-host { padding: 10px; align-items: flex-end; }
  .modal { max-height: 90vh; max-height: 90dvh; border-radius: var(--r-lg); }
  .modal-head { padding: 15px 16px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 13px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; }

  .toast-host {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .toast { min-width: 0; max-width: none; width: 100%; }
}

/* ---------------------------------------------------------
   8. ≤430 小屏手机
   --------------------------------------------------------- */
@media (max-width: 430px) {
  :root { --gutter: 12px; --hdr-h: 56px; }

  .brand-mark { width: 30px; height: 30px; }
  .brand-mark img { width: 20px; height: 20px; }
  .brand-name { font-size: 14px; }

  .hero-badge { font-size: 10.5px; height: 25px; padding: 0 10px 0 8px; }
  .hero h1 { font-size: 25px; }
  .hero-search .input { height: 46px; padding-right: 92px; }
  .hero-search .btn { padding: 0 13px; }
  .hero-search .btn span { display: none; }

  .section { padding-top: 24px; }
  .btn { padding: 0 13px; font-size: 13px; }

  .detail-icon { width: 48px; height: 48px; border-radius: 12px; }
  .detail-id h1 { font-size: 19px; }
  .detail-id .tagline { font-size: 12.5px; }

  .dl-point { padding: 10px; gap: 9px; }
  .dl-label { font-size: 12.5px; }

  .ms-lk-list { padding: 0 10px 8px; }
  .ms-lk { padding: 7px 8px; }
  .ms-lk-tag { min-width: 38px; font-size: 9.5px; }

  .nav { width: 92vw; }
}

/* ---------------------------------------------------------
   9. ≤360 极窄屏
   --------------------------------------------------------- */
@media (max-width: 360px) {
  :root { --gutter: 10px; }
  .hero-stats { gap: 6px 12px; }
  .app-card-foot { flex-wrap: wrap; row-gap: 5px; }
  .ver-pill { margin-left: 0; }
  .nav-toggle { width: 38px; height: 38px; }
}

/* ---------------------------------------------------------
   10. 低高度横屏（手机横放）
   --------------------------------------------------------- */
@media (max-height: 520px) and (orientation: landscape) {
  .hero { padding: 22px 0 16px; }
  .hero h1 { font-size: clamp(22px, 4.4vw, 30px); }
  .hero-lead { margin-bottom: 14px; }
  .hero-badge { margin-bottom: 10px; }
  .hero-search { margin-bottom: 16px; }
  .nav { padding-top: 16px; }
  .site-header .header-inner { height: 54px; }
}

/* ---------------------------------------------------------
   11. 触屏与指针设备
   --------------------------------------------------------- */
/* 只在真正支持悬停的设备上做位移/放大，触屏点击后不会卡住 hover 态 */
@media (hover: none) {
  .app-card:hover { transform: none; box-shadow: none; }
  .app-card:hover .app-icon { transform: none; }
  .dl-point:hover { transform: none; }
  .ad:hover { box-shadow: none; }
  .btn:hover { background: var(--btn-bg); border-color: var(--line-2); }
  .btn-primary:hover { background: var(--grad-brand); filter: none; }
  .nav a:hover { background: transparent; }
  .nav a.is-active:hover { background: rgba(var(--brand-rgb), .18); }
  .cat-chip:hover { background: var(--panel-2); color: var(--fg-2); }
}

/* 指针粗（手指）：放大点按区、去掉过小的文字 */
@media (pointer: coarse) {
  .nav a { min-height: 44px; }
  .cat-chip { height: 38px; }
  .os-tab { height: 32px; }
  .btn-sm { height: 34px; }
  .ms-cp, .ms-open { min-height: 34px; }
  .footer-col a { padding: 6px 0; }
  .header-search .kbd { display: none; }
}

/* ---------------------------------------------------------
   12. 控制台（admin.html）
   --------------------------------------------------------- */
@media (max-width: 900px) {
  .auth-screen { padding: 16px; }
  .auth-card { width: 100%; max-width: 430px; padding: 26px 20px; }
  .aside {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(8, 11, 20, .96);
    backdrop-filter: blur(18px);
    scrollbar-width: none;
  }
  .aside::-webkit-scrollbar { display: none; }
  .main { padding: 18px 14px calc(56px + env(safe-area-inset-bottom)); }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head > .row { flex-wrap: wrap; }
  .tbl { min-width: 700px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
}

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .dl-row { grid-template-columns: 1fr !important; }
  .mirror-admin-row,
  .ms-admin-row { grid-template-columns: 1fr; gap: 8px; padding: 12px 2px; }
  .mirror-admin-row .btn,
  .ms-admin-row .btn { justify-self: start; }
  .tbl-scroll { margin: 0 -2px; }
  .modal-foot .btn { flex: 1 1 auto; }
}

/* ---------------------------------------------------------
   13. 打印
   --------------------------------------------------------- */
@media print {
  .site-header, .site-footer, .nav, .nav-toggle, .nav-scrim,
  .ambient, .toast-host, .ad, .hero-search { display: none !important; }
  body { background: #fff; color: #111; }
  .wrap { max-width: none; padding: 0; }
  .panel, .app-card, .detail-hero, .ver-panel { border-color: #ccc; background: #fff; box-shadow: none; }
  a { color: #111; text-decoration: underline; }
}
