/* ==========================================================================
 * 官网前台页面手机端收口（页脚横排 + 书架首屏不重叠）
 * 只影响 <=768px，且用 html body 前缀压住各页面自带样式。
 * ========================================================================== */
@media (max-width: 768px) {
  html body .footer {
    padding: 28px 0 18px !important;
  }

  html body .footer-content {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px 16px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 16px !important;
    box-sizing: border-box !important;
  }

  html body .footer-section {
    min-width: 0 !important;
  }

  html body .footer-section h4,
  html body .footer-section h5,
  html body .footer-section .footer-title {
    font-size: 14px !important;
    line-height: 1.3 !important;
    margin: 0 0 8px !important;
  }

  html body .footer-section ul {
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
  }

  html body .footer-section ul li {
    margin: 0 0 5px !important;
  }

  html body .footer-section a,
  html body .footer-section li {
    font-size: 12px !important;
    line-height: 1.4 !important;
  }

  html body .footer-bottom {
    padding-top: 14px !important;
    gap: 10px !important;
  }
}

/* ---------- 书架页：文字与书籍分开、顺序改为「文字在上，书在下」 ---------- */
@media (max-width: 768px) {
  html body:has(.books-fan-container) .hero {
    min-height: 0 !important;
    padding: 24px 0 8px !important;
  }

  html body:has(.books-fan-container) .hero-container {
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    margin-top: 0 !important;
    padding: 0 16px 24px !important;
  }

  html body:has(.books-fan-container) .hero-content {
    order: 1 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
  }

  html body:has(.books-fan-container) .books-fan-container {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    order: 2 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 20px 0 8px !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: flex-end !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto !important;
    z-index: auto !important;
  }

  html body:has(.books-fan-container) .books-fan-container .book-item {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
    flex: 0 0 56px !important;
    width: 56px !important;
    height: auto !important;
    margin: 0 !important;
  }

  /* 书籍下方的说明文字 */
  html body:has(.books-fan-container) .hero-container > div:not(.books-fan-container):not(.hero-content) {
    order: 3 !important;
    margin-top: 0 !important;
    font-size: 11px !important;
  }
}

@media (max-width: 480px) {
  html body:has(.books-fan-container) .books-fan-container .book-item {
    flex-basis: 50px !important;
    width: 50px !important;
  }
}

/* ---------- 教学页：工具截图不能被容器压成细条 ---------- */
@media (max-width: 768px) {
  html body:has(.tomtool-shot) .hero-section {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html body:has(.tomtool-shot) .ide-window {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html body:has(.tomtool-shot) .ide-content-wrapper {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html body:has(.tomtool-shot) .ide-content,
  html body:has(.tomtool-shot) .tomtool-panel {
    height: auto !important;
    min-height: 0 !important;
    flex: 0 0 auto !important;
  }

  html body:has(.tomtool-shot) .tomtool-shot {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  html body:has(.tomtool-shot) .tomtool-shot img {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: 0 0 auto !important;
    object-fit: contain !important;
  }

  /* 2026-11-22：上面的规则把 .ide-content-wrapper 改成 height:auto 后，
     .ide-content-module 仍是 position:absolute + height:100%（教学页 style.css），
     父级没有确定高度 → 模块塌成 0，激活 tab 的截图直接溢到下一节，
     压在「HARDWARE / 硬件产品」标题上。窄屏让 tab 模块回到正常文档流，
     只显示 active 那个，其余 display:none，保留下方按钮的切换能力。 */
  html body:has(.tomtool-shot) .ide-content-wrapper {
    display: block !important;
  }
  html body:has(.tomtool-shot) .ide-content-module {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    overflow: visible !important;
  }
  html body:has(.tomtool-shot) .ide-content-module:not(.active) {
    display: none !important;
  }
  html body:has(.tomtool-shot) .ide-content {
    display: block !important;
    width: 100% !important;
    height: auto !important;
  }
  html body:has(.tomtool-shot) .tomtool-panel {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    flex: 1 1 auto !important;
  }
  html body:has(.tomtool-shot) .tomtool-info,
  html body:has(.tomtool-shot) .tomtool-shot {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  html body:has(.tomtool-shot) .tomtool-shot img {
    display: block !important;
    max-width: 100% !important;
  }
}

/* ---------- Books 头部：看图学 / 语言切换器 / 汉堡按钮各占一列 ---------- */
@media (max-width: 768px) {
  html body.books-page .nav-container {
    grid-template-columns: minmax(0, 1fr) auto auto auto !important;
    column-gap: 8px !important;
  }

  html body.books-page .nav-container > .logo,
  html body.books-page .nav-container > .brand {
    grid-column: 1 !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  html body.books-page .nav-container > .tom-i18n-switch:not(.is-floating) {
    grid-column: 2 !important;
    grid-row: 1 !important;
    justify-self: end !important;
    margin: 0 !important;
    position: static !important;
  }

  html body.books-page .nav-container > .nav-actions {
    grid-column: 3 !important;
    grid-row: 1 !important;
    justify-self: end !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 6px !important;
    position: static !important;
    min-width: 0 !important;
  }

  html body.books-page .nav-container > .nav-actions > * {
    position: static !important;
    transform: none !important;
    flex: 0 0 auto !important;
  }

  html body.books-page .nav-container > .mobile-menu-toggle {
    grid-column: 4 !important;
    grid-row: 1 !important;
    justify-self: end !important;
    margin: 0 !important;
  }
}

/* ---------- 看图学：顶部固定、内容独立滚动、菜单放右上角 ---------- */
@media (max-width: 768px) {
  html body:has(.lookimg-sidebar-menu) {
    overflow: hidden !important;
  }

  html body:has(.lookimg-sidebar-menu) .app {
    height: calc(100dvh - 56px) !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  /* 顶部合成一行：品牌 / 中文 / 返回 / 切换列表模式 / 菜单 */
  html body:has(.lookimg-sidebar-menu) .tom-r-header__inner.lookimg-unified-header {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    min-height: 56px !important;
    padding: 0 12px !important;
  }

  html body:has(.lookimg-sidebar-menu) .tom-r-header__brand {
    order: 1 !important;
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  html body:has(.lookimg-sidebar-menu) .tom-r-header__actions {
    order: 2 !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    margin-left: 0 !important;
  }

  html body:has(.lookimg-sidebar-menu) #tomRFab,
  html body:has(.lookimg-sidebar-menu) .tom-r-header-toggle {
    display: none !important;
  }

  html body:has(.lookimg-sidebar-menu) .lookimg-mobile-back {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    order: 5 !important;
    margin-left: auto !important;
    min-height: 42px !important;
    padding: 0 10px !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 12px !important;
    background: rgba(12, 18, 30, 0.9) !important;
    color: var(--text-primary) !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
  }

  html body:has(.lookimg-sidebar-menu) #lookimgModeToggle {
    order: 3 !important;
    margin-left: 0 !important;
    width: auto !important;
    min-width: 0 !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 4px !important;
    gap: 5px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--text-primary, #e6e6e6) !important;
    font-size: 13px !important;
    font-weight: 600 !important;
  }

  html body:has(.lookimg-sidebar-menu) #lookimgModeToggle .lookimg-mode-toggle-text {
    display: inline !important;
    white-space: nowrap !important;
  }

  html body:has(.lookimg-sidebar-menu) #lookimgModeToggle .lookimg-mode-icon {
    display: block !important;
    flex: 0 0 18px !important;
    width: 18px !important;
    height: 18px !important;
    color: #06b6d4 !important;
  }

  html body:has(.lookimg-sidebar-menu) #lookimgMenuToggle {
    order: 4 !important;
    margin-left: 0 !important;
  }

  html body:has(.lookimg-sidebar-menu) .sidebar {
    top: 56px !important;
    padding: 0 12px !important;
    min-height: 0 !important;
    border-bottom: 0 !important;
  }

  html body:has(.lookimg-sidebar-menu) .sidebar {
    position: sticky !important;
    top: 0 !important;
    z-index: 120 !important;
    flex: 0 0 auto !important;
    flex-wrap: wrap !important;
  }

  html body:has(.lookimg-sidebar-menu) .main-content {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  html body:has(.lookimg-sidebar-menu) .top-bar {
    position: sticky !important;
    top: 0 !important;
    z-index: 110 !important;
    flex: 0 0 auto !important;
    background: rgba(8, 14, 24, 0.96) !important;
  }

  /* 缩略图不能被 flex/grid 挤扁：撑开自然高度，由网格自己纵向滚动 */
  html body:has(.lookimg-sidebar-menu) .image-grid {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    align-content: start !important;
    grid-auto-rows: max-content !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  html body:has(.lookimg-sidebar-menu) .image-card,
  html body:has(.lookimg-sidebar-menu) .folder-card {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
  }

  html body:has(.lookimg-sidebar-menu) .image-card img {
    width: 100% !important;
    height: 180px !important;
    min-height: 180px !important;
    flex: 0 0 180px !important;
    object-fit: cover !important;
  }

  html body:has(.lookimg-sidebar-menu) #lookimgMenuToggle {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    order: 4 !important;
    margin-left: 0 !important;
    width: auto !important;
    min-width: 0 !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 4px !important;
    gap: 5px !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--text-primary, #e6e6e6) !important;
    font-size: 13px !important;
    font-weight: 600 !important;
  }

  html body:has(.lookimg-sidebar-menu) #lookimgMenuToggle .lookimg-menu-toggle-text {
    display: inline !important;
    white-space: nowrap !important;
  }

  html body:has(.lookimg-sidebar-menu) #lookimgMenuToggle .lookimg-menu-toggle-bars {
    display: block !important;
    flex: 0 0 18px !important;
    width: 18px !important;
    height: 18px !important;
    color: #06b6d4 !important;
  }

  html body:has(.lookimg-sidebar-menu) .sidebar.lookimg-sidebar-collapsible:not(.mobile-nav-open) .lookimg-sidebar-menu {
    display: none !important;
  }

  html body:has(.lookimg-sidebar-menu) .sidebar.lookimg-sidebar-collapsible.mobile-nav-open .lookimg-sidebar-menu {
    order: 2 !important;
    flex: 1 1 100% !important;
    width: 100% !important;
    max-height: 45vh !important;
    overflow-y: auto !important;
    margin-top: 4px !important;
  }
}
