/* H5 / 移动端自适应 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

body.nav-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* 移动端菜单按钮 */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.nav-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1100;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s, visibility 0.3s;
}

.mobile-nav-overlay.is-open {
  display: block;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.mobile-nav-drawer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(280px, 85vw);
  background: var(--bg-card);
  z-index: 1101;
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.3s ease, visibility 0.3s;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
  overflow-y: auto;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
}

.mobile-nav-drawer.is-open {
  display: block;
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.mobile-nav-drawer .drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.mobile-nav-drawer .drawer-close {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg-page);
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
}

.mobile-nav-drawer nav a {
  display: block;
  padding: 14px 20px;
  font-size: 16px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.mobile-nav-drawer nav a.active,
.mobile-nav-drawer nav a:hover {
  color: var(--primary);
  background: var(--primary-bg);
}

.mobile-nav-drawer .drawer-actions {
  padding: 20px;
}

.mobile-nav-drawer .drawer-actions .btn-primary {
  display: block;
  width: 100%;
  text-align: center;
  padding: 12px;
}

/* 平板 */
@media (max-width: 992px) {
  .main-content {
    padding: 16px 12px;
  }

  .footer-inner {
    padding-left: 12px;
    padding-right: 12px;
  }

  .page-hero {
    padding: 16px;
  }

  .page-hero h1 {
    font-size: 18px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select,
  .filter-bar input {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .filter-bar .btn-primary {
    width: 100%;
  }

  .form-page {
    max-width: none;
    padding: 20px 16px;
  }

  .login-container {
    margin: 0 8px;
  }
}

/* ========== 手机 H5（≤768px）========== */
@media (max-width: 768px) {
  :root {
    --header-main-h: auto;
    --header-nav-h: 0;
    --header-total: 0;
  }

  .site-header {
    position: relative;
    z-index: 100;
    background: linear-gradient(105deg, #fff0e6 0%, #ffe8dc 45%, #fff5ee 100%);
    box-shadow: 0 1px 0 var(--primary-border);
  }

  .page-wrap {
    padding-top: 0;
  }

  /* 顶栏两行：Logo + 菜单/登录 | 通栏搜索 */
  .header-main {
    height: auto;
    padding: 10px 0 12px;
  }

  .page-home .header-main {
    padding-bottom: 14px;
  }

  .header-main-inner {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas:
      "logo . toggle login"
      "search search search search";
    gap: 10px 6px;
    align-items: center;
    padding: 0 12px;
    width: 100%;
    max-width: 100%;
  }

  .header-brand {
    grid-area: logo;
    min-width: 0;
    gap: 6px;
  }

  .header-slogan {
    display: none;
  }

  .logo {
    min-width: 0;
  }

  .logo-img {
    height: 36px;
    max-width: 160px;
  }

  .logo-label {
    font-size: 18px;
  }

  .nav-toggle {
    display: flex;
    grid-area: toggle;
    margin: 0;
    width: 40px;
    height: 40px;
    padding: 8px;
  }

  .header-end {
    grid-area: login;
    margin: 0;
    gap: 6px;
  }

  .header-quick-nav {
    display: none;
  }

  .header-actions {
    margin: 0;
  }

  .header-actions .btn-login {
    padding: 0 12px;
    height: 32px;
    min-height: 32px;
    line-height: 32px;
    font-size: 13px;
    white-space: nowrap;
    border-radius: 16px;
  }

  /* 通栏搜索：灰底圆角条 + 右侧橙色按钮贴边（无内边距缝隙） */
  .header-search {
    grid-area: search;
    width: 100%;
    max-width: 100%;
    height: 36px;
    min-height: 36px;
    border-radius: 18px;
    background: #f5f5f5;
    border: 1px solid #e8e8e8;
    overflow: hidden;
  }

  .header-search select {
    display: none;
  }

  .header-search input {
    flex: 1;
    min-width: 0;
    padding: 0 12px;
    font-size: 16px;
    line-height: 36px;
    height: 36px;
  }

  .header-search button {
    width: 64px;
    min-width: 64px;
    min-height: 36px !important;
    height: 36px;
    margin: 0;
    padding: 0;
    border-radius: 0;
    font-size: 16px;
    flex-shrink: 0;
  }

  /* 首页分类胶囊（搜索下方留白） */
  .home-categories-mobile {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 4px -12px 14px;
    padding: 0 12px 4px;
    scrollbar-width: none;
  }

  .home-categories-mobile::-webkit-scrollbar {
    display: none;
  }

  .home-categories-mobile a {
    flex-shrink: 0;
    padding: 7px 12px;
    font-size: var(--font-size-sidebar);
    line-height: 1.3;
    background: var(--bg-card);
    border: 1px solid #e8e8e8;
    border-radius: 16px;
    color: var(--text);
    white-space: nowrap;
  }

  .main-content {
    padding: 0 12px 16px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .page-home .main-content {
    padding-top: 14px;
  }

  .page-home .home-hero,
  .page-home .home-new-books {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* 内页筛选条 — 与顶栏搜索风格统一 */
  .filter-bar {
    padding: 10px;
    border-radius: 8px;
    gap: 10px;
  }

  .filter-bar input[type="search"],
  .filter-bar input[type="text"] {
    height: 36px;
    border-radius: 8px;
    border: 1px solid #e8e8e8;
    padding: 0 12px;
  }

  .filter-bar .btn-primary {
    height: 40px;
    width: 100%;
    border-radius: 8px;
  }

  .float-sidebar {
    right: 6px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0));
    width: 48px;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  }

  .float-sidebar [data-float-qr] {
    display: none;
  }

  .float-sidebar li:not(:last-child)::after {
    margin: 0 6px;
  }

  .float-sidebar a {
    padding: 10px 4px;
    font-size: 9px;
    gap: 2px;
  }

  .float-sidebar-icon {
    width: 20px;
    height: 20px;
  }

  .float-sidebar-label {
    line-height: 1.2;
    transform: scale(0.92);
  }

  .section-head h2 {
    font-size: 17px;
  }

  .section-head h2::before {
    height: 16px;
  }

  .breadcrumb {
    padding: 8px 0;
    font-size: 12px;
    overflow-x: auto;
    white-space: nowrap;
  }

  .btn,
  .btn-login,
  .nav-toggle,
  .drawer-close {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255, 107, 53, 0.15);
  }

  .header-search button {
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  a,
  button,
  input,
  select,
  label {
    touch-action: manipulation;
  }

  .page-wrap,
  .main-content {
    position: relative;
    z-index: 1;
  }

  .site-footer {
    padding: 24px 0 calc(24px + env(safe-area-inset-bottom, 0));
  }

  .footer-inner {
    padding-left: 12px;
    padding-right: 12px;
  }

  .footer-layout {
    flex-direction: column;
    gap: 24px;
  }

  .footer-app--side {
    align-self: center;
    padding-left: 0;
    padding-top: 8px;
    min-width: 0;
    width: 100%;
  }

  .footer-partners-bar {
    flex-direction: column;
    gap: 6px;
  }

  .footer-partners-row {
    gap: 6px 12px;
  }

  .footer-partners-row span {
    white-space: normal;
  }

  .footer-bottom {
    grid-template-columns: 1fr;
    gap: 20px;
    text-align: center;
  }

  .footer-brand {
    justify-content: center;
  }

  .footer-app {
    margin: 0 auto;
  }

  /* 内页 */
  .books-layout {
    grid-template-columns: 1fr;
  }

  .books-sidebar {
    position: static;
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .books-list .books-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .books-list .books-toolbar .sort {
    overflow-x: auto;
    width: 100%;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .books-list .book-grid-wrap {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .book-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .content-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .feature-list {
    grid-template-columns: 1fr;
  }

  .learn-dashboard {
    grid-template-columns: repeat(2, 1fr);
  }

  .course-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .course-row .progress-bar {
    width: 100%;
    max-width: none;
  }

  .course-row .btn {
    width: 100%;
  }

  .publish-hero {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .publish-hero-visual {
    min-height: 120px;
  }

  .resource-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .resource-tabs a {
    flex-shrink: 0;
  }

  .resource-grid {
    grid-template-columns: 1fr;
  }

  .about-intro {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .contact-cards {
    grid-template-columns: 1fr;
  }

  .app-download {
    flex-direction: column;
    text-align: center;
    padding: 20px 16px;
  }

  .wechat-section {
    grid-template-columns: 1fr;
  }

  .login-page {
    padding: 16px 12px;
    align-items: flex-start;
  }

  .login-container {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .login-form-wrap {
    padding: 24px 20px;
  }

  /* 内页通用 H5 间距 */
  .page-books .page-wrap,
  .page-book-detail .page-wrap,
  .page-resources-download .page-wrap,
  .page-help .page-wrap,
  .page-user-center .page-wrap,
  .page-legal .page-wrap {
    padding-top: 0;
  }

  .page-hero {
    border-radius: 8px;
  }

  .form-page {
    padding: 16px;
    border-radius: 8px;
  }
}

/* 首页轮播 — 移动端补充（布局见 index.css） */
@media (max-width: 768px) {
  .page-home .home-hero {
    display: block;
    width: 100%;
  }

  .page-home .home-carousel-wrap {
    width: 100%;
  }

  .page-home .home-slider {
    width: 100%;
    max-width: 100%;
    padding: 0;
  }

  .page-home .slider-content {
    max-width: 100%;
    padding-right: 0;
  }
}

/* 小屏手机 */
@media (max-width: 480px) {
  .header-main-inner {
    padding: 0 10px;
  }

  .logo-label {
    font-size: 17px;
  }

  .header-actions .btn-login {
    padding: 0 10px;
    font-size: 12px;
  }

  .home-categories-mobile {
    margin: 4px -10px 12px;
    padding: 0 10px 4px;
  }

  .main-content {
    padding: 0 10px 12px;
  }

  .page-home .main-content {
    padding-top: 12px;
  }

  .footer-inner {
    padding-left: 10px;
    padding-right: 10px;
  }

  .header-search {
    height: 34px;
    min-height: 34px;
    border-radius: 17px;
  }

  .header-search input {
    height: 34px;
    line-height: 34px;
    font-size: 14px;
  }

  .header-search button {
    width: 56px;
    min-width: 56px;
    height: 34px;
    min-height: 34px !important;
    font-size: 16px;
  }

  .page-home .slider-content h1 {
    font-size: 20px;
  }

  .page-home .book-new-row {
    padding: 16px 12px;
  }

  .books-list .book-grid-wrap {
    grid-template-columns: repeat(2, 1fr);
  }

  .books-list .book-item .book-info::after {
    display: block;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }

  .footer-partners-names span {
    white-space: normal;
  }

  .footer-nav-sep {
    display: none;
  }

  .footer-nav {
    gap: 8px 12px;
  }

  .exam-banner,
  .page-hero {
    margin-bottom: 12px;
  }

  .download-center,
  .help-center,
  .user-center {
    padding-left: 10px;
    padding-right: 10px;
  }

  .legal-document {
    padding: 14px;
  }
}

/* 横屏手机 */
@media (max-width: 896px) and (orientation: landscape) {
  .home-hero-body .home-carousel-wrap {
    aspect-ratio: 2.4 / 1;
    min-height: 120px;
    max-height: 180px;
  }

  .login-promo {
    display: none;
  }
}

/* 平板：首页分类横滑 */
@media (min-width: 769px) and (max-width: 992px) {
  .page-home .main-content {
    padding-top: 12px;
  }

  .home-categories-mobile {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0 12px;
    margin: 8px 0 12px;
    scrollbar-width: none;
  }

  .home-categories-mobile::-webkit-scrollbar {
    display: none;
  }

  .home-categories-mobile a {
    flex-shrink: 0;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: var(--font-size-sidebar);
    color: var(--text-secondary);
    white-space: nowrap;
  }
}

@media (min-width: 993px) {
  .home-categories-mobile {
    display: none;
  }
}

@media (max-width: 992px) {
  .page-home .home-categories {
    display: none !important;
  }

  .page-home .home-hero {
    width: 100%;
    max-width: 100%;
  }
}
