/* fpga.love 移动端适配层 v1 —— 全局共享，勿在各页面重复内联
   作用域：≤768px / ≤480px；用 !important 覆盖各页面内联样式 */

html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, svg, video, iframe { max-width: 100%; height: auto; }

@media (max-width: 768px) {
  /* 顶栏：logo 与搜索按钮一行，导航独占一行，避免折行压到 logo */
  header > div {
    height: auto !important;
    flex-wrap: wrap !important;
    row-gap: 6px !important;
    padding: 8px 14px !important;
  }
  header > div > a { font-size: 20px !important; }
  header > div > nav {
    order: 3;
    width: 100% !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    row-gap: 4px !important;
  }
  header > div > nav a { font-size: 13px !important; white-space: nowrap; }
  header > div > div {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    flex-wrap: wrap !important;
    justify-content: flex-end !important;
    gap: 8px !important;
  }
  header > div > div input { width: 100% !important; min-width: 0 !important; }

  /* 首页 */
  .quick-tools { flex-wrap: wrap !important; }
  .hero-title { font-size: 26px !important; line-height: 1.35 !important; }
  .hot-grid { grid-template-columns: 1fr !important; }
  .hot-main-title, .hot-meta { overflow-wrap: anywhere; }

  /* 选型页（boards）筛选面板：单列 + 去掉 flex-basis 撑出的空白 */
  .selgrid { display: block !important; padding: 0 6px !important; }
  .selfrow { gap: 6px !important; padding: 10px 0 !important; }
  .selflab { flex: 0 0 auto !important; padding-top: 0 !important; }
  .selpanel { margin-top: -20px !important; padding: 10px 12px !important; }

  /* 长表格、代码块独立滚动，不撑破页面 */
  table { display: block; overflow-x: auto; max-width: 100%; }
  pre { overflow-x: auto; max-width: 100%; }
}

@media (max-width: 480px) {
  header > div { padding: 8px 10px !important; }
  header > div > nav { gap: 6px !important; }
  header > div > nav a { font-size: 12px !important; letter-spacing: -.2px; }
}

@media (max-width: 768px) {
  /* 兜底：页面主体与卡片一律不超过视口，避免某个固定宽度元素把整页撑宽 */
  html, body { width: 100% !important; max-width: 100vw !important; }
  .mainbox, .wrap, .container, .hot-section, .section, .hero {
    max-width: 100% !important; width: auto !important; box-sizing: border-box !important;
  }
  .hot-grid { width: 100% !important; }
  .hot-main, .hot-item, .hot-side { width: 100% !important; max-width: 100% !important; min-width: 0 !important; box-sizing: border-box !important; }
  .hot-main-title, .hot-meta { white-space: normal !important; overflow-wrap: anywhere !important; }
}

@media (max-width: 768px) {
  /* 网格/弹性容器的自动最小宽度会把整页撑宽：统一放开 */
  .container { grid-template-columns: minmax(0, 1fr) !important; }
  main, aside, section, .hot-grid, .hot-side, .hot-main { min-width: 0 !important; }
  .hot-meta, .hot-main-title, .hot-item-title, .section-more { white-space: normal !important; }
}

@media (max-width: 768px) {
  /* 页脚与 Cookie 提示条：允许折行并限制在视口内 */
  footer, footer > div, footer > div > div { max-width: 100% !important; box-sizing: border-box !important; }
  footer span, footer a { white-space: normal !important; overflow-wrap: anywhere !important; }
  #ckbar {
    left: 8px !important; right: 8px !important; width: auto !important;
    max-width: calc(100vw - 16px) !important; box-sizing: border-box !important;
  }
  #ckbar span { max-width: 100% !important; }
}

@media (max-width: 768px) {
  /* 页脚：收紧内边距，ICP 号允许断行 */
  footer > div { padding: 28px 20px !important; }
  footer span, footer a { word-break: break-all !important; }
  /* 订阅表单：输入框与按钮换行排列 */
  .content-container form { flex-wrap: wrap !important; padding: 0 !important; gap: 8px !important; }
  .content-container form input { flex: 1 1 100% !important; width: 100% !important; min-width: 0 !important; }
  .content-container form button { flex: 0 0 auto !important; }
}

@media (max-width: 768px) {
  /* 期刊列表卡片：徽标、标题、按钮改为纵向堆叠，标题不再被压成 4-5 行 */
  div[style*="padding: 20px 24px"] {
    flex-wrap: wrap !important;
    align-items: flex-start !important;
    padding: 16px 14px !important;
    gap: 8px !important;
  }
  div[style*="padding: 20px 24px"] > span { width: auto !important; flex: 0 0 auto !important; }
  div[style*="padding: 20px 24px"] > div { flex: 1 1 100% !important; min-width: 0 !important; }
  div[style*="padding: 20px 24px"] > div > div[style*="font-size: 20px"],
  div[style*="padding: 20px 24px"] > div > div[style*="font-size: 22px"] { font-size: 17px !important; line-height: 1.45 !important; }
  div[style*="padding: 20px 24px"] > a { margin-left: auto !important; }
}

@media (max-width: 768px) {
  /* 卡片标题行（如开源项目名 + star 数）在窄屏改为堆叠 */
  h3 { display: block !important; }
  h3, h3 > * { max-width: 100% !important; white-space: normal !important; overflow-wrap: anywhere !important; }
  /* 订阅/搜索类表单：输入框整行，按钮另起一行 */
  form { flex-wrap: wrap !important; }
  form input { flex: 1 1 100% !important; width: 100% !important; min-width: 0 !important; }
  form button { flex: 0 0 auto !important; }
}

@media (max-width: 768px) {
  /* 侧栏在窄屏改为上下堆叠，避免并排挤压出屏 */
  aside { display: block !important; width: auto !important; max-width: 100% !important; }
  aside > * { width: 100% !important; max-width: 100% !important; box-sizing: border-box !important; }
}

@media (max-width: 768px) {
  /* 蓝色订阅块：输入框、按钮各占整行 */
  div[style*="background: #2563eb"] { display: block !important; text-align: center !important; padding: 16px 14px !important; }
  div[style*="background: #2563eb"] input { width: 100% !important; box-sizing: border-box !important; margin: 0 0 10px !important; }
  div[style*="background: #2563eb"] button,
  div[style*="background: #2563eb"] a[style] { width: 100% !important; display: block !important; box-sizing: border-box !important; }
}

@media (max-width: 768px) {
  /* 底部订阅行：flex 行改为换行，输入框占满、按钮另起一行 */
  div[style*="max-width: 500px"] { flex-wrap: wrap !important; gap: 10px !important; max-width: 100% !important; }
  div[style*="max-width: 500px"] > input { flex: 1 1 100% !important; width: 100% !important; min-width: 0 !important; box-sizing: border-box !important; }
  div[style*="max-width: 500px"] > button { flex: 1 1 100% !important; width: 100% !important; }
}

@media (max-width: 768px) {
  /* 输入类控件统一边框盒模型，避免撑出屏幕 */
  input, textarea, select { box-sizing: border-box !important; max-width: 100% !important; }
  form > button { width: 100% !important; }
  /* 开源项目列表行：徽标、标题+描述、查看 纵向堆叠 */
  div[style*="padding: 13px 16px"] { flex-wrap: wrap !important; align-items: flex-start !important; gap: 8px !important; padding: 12px 14px !important; }
  div[style*="padding: 13px 16px"] > span { width: auto !important; }
  div[style*="padding: 13px 16px"] > div { flex: 1 1 100% !important; min-width: 0 !important; }
  div[style*="padding: 13px 16px"] > a { margin-left: auto !important; }
}

@media (max-width: 768px) {
  /* 首页/AI问答的首屏搜索框：上下排布，各自占满整行、圆角复原 */
  form[style*="max-width: 900px"] { display: block !important; max-width: 100% !important; border-radius: 12px !important; }
  form[style*="max-width: 900px"] input { width: 100% !important; border: 2px solid #2563eb !important; border-radius: 12px !important; margin: 0 0 10px !important; box-sizing: border-box !important; }
  form[style*="max-width: 900px"] button { width: 100% !important; border: 2px solid #2563eb !important; border-radius: 12px !important; padding: 12px 0 !important; box-sizing: border-box !important; }
}

/* ============ 移动端顶部导航：汉堡按钮 + 下拉菜单（≤768px） ============ */
@media (max-width: 768px) {
  /* 8 项导航收进下拉面板，不再横向铺开 */
  header > div > nav { display: none !important; }

  header > div > a { flex: 0 0 auto !important; font-size: 19px !important; white-space: nowrap !important; }

  /* 右侧工具区：只留搜索 + 汉堡按钮，EN/App 移到面板里 */
  /* 搜索框、语言切换、App 入口统一留在顶部栏，只有 8 项导航收进菜单 */
  header > div > div {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    flex-wrap: nowrap !important;
  }
  header > div > div > span[style*="width:1px"] { display: none !important; }
  header > div > div > div { flex: 0 0 auto !important; }
  header > div > div > a {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    font-size: 12px !important;
    padding: 5px 8px !important;
    margin-left: 0 !important;
    border-radius: 6px !important;
  }
  header > div > a { margin-right: 6px !important; }

  /* 顶部只留放大镜图标，点击后在 header 下方展开整行搜索条 */
  .nav-sbtn {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }
  .nav-sbtn svg { display: block; }
  .nav-sbox {
    position: absolute !important;
    top: 100% !important;
    left: 8px !important;
    right: 8px !important;
    height: 44px !important;
    display: none !important;
    padding: 0 12px !important;
    background: #fff;
    box-shadow: 0 10px 26px rgba(15, 23, 42, .14);
    z-index: 70 !important;
  }
  .nav-sbox.nav-sopen { display: flex !important; }
  .nav-sbox svg { display: none !important; }
  .nav-sbox input#nav-search { width: 100% !important; height: 100% !important; font-size: 14px !important; }

  .mnav-btn {
    display: block !important;
    position: relative;
    width: 34px;
    height: 32px;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    flex: 0 0 auto;
    box-sizing: border-box;
  }
  .mnav-btn span {
    position: absolute;
    left: 8px;
    right: 8px;
    height: 2px;
    background: #334155;
    border-radius: 2px;
    transition: transform .18s ease, opacity .18s ease;
  }
  .mnav-btn span:nth-child(1) { top: 11px; }
  .mnav-btn span:nth-child(2) { top: 15px; }
  .mnav-btn span:nth-child(3) { top: 19px; }
  .mnav-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(4px) rotate(45deg); }
  .mnav-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .mnav-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-4px) rotate(-45deg); }

  .mnav-panel {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 12px 24px rgba(15, 23, 42, .10);
    padding: 6px 16px 14px;
    max-height: 76vh;
    overflow-y: auto;
    z-index: 60;
    box-sizing: border-box;
  }
  .mnav-panel.mnav-open { display: block; }

  .mnav-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
  .mnav-list a {
    display: block !important;
    width: 100% !important;
    padding: 12px 2px !important;
    font-size: 15px !important;
    line-height: 1.35 !important;
    border-bottom: 1px solid #f1f5f9;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
  }

  .mnav-extra { display: flex; gap: 10px; margin-top: 12px; }
  .mnav-ex {
    flex: 1 1 0 !important;
    text-align: center;
    padding: 9px 0 !important;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px !important;
    color: #334155 !important;
    text-decoration: none !important;
    font-weight: 600 !important;
    white-space: nowrap;
    box-sizing: border-box;
  }
  .mnav-ex-app {
    background: #2563eb !important;
    border-color: #2563eb !important;
    color: #fff !important;
  }
}

@media (min-width: 769px) {
  .mnav-btn, .mnav-panel, .nav-sbtn { display: none !important; }
}
