/* =========================================================
   H5 / 移动端响应式样式
   ---------------------------------------------------------
   只在 max-width / hover:none 媒体查询里覆盖样式，
   桌面端（>1024px）完全沿用 style.css，不受影响。
   ========================================================= */

/* ---------- 平板 / 小笔记本 ---------- */
@media (max-width: 1024px) {
  .container { padding: 0 18px; }
  .navbar-inner { padding: 0 18px; gap: 18px; }
  .nav-link { padding: 9px 12px; }
  .nav-search-input { width: clamp(180px, 22vw, 290px); }

  .carousel { margin: 16px 20px; }
  .carousel-slide { height: 280px; padding: 0 48px; }

  .course-grid { grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .course-detail { grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; }
  .account-orders .table { min-width: 760px; }
}

/* ---------- 手机 / 平板竖屏 ---------- */
@media (max-width: 768px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  body { padding-top: calc(56px + env(safe-area-inset-top, 0px)); }
  body.has-bottom-nav {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  }

  /* ---- 顶部导航：精简版 ---- */
  .navbar {
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
  }
  .navbar-inner { height: 56px; padding: 0 12px; gap: 8px; }
  .logo { font-size: 19px; gap: 8px; flex-shrink: 0; }
  .logo-icon { width: 34px; height: 34px; font-size: 16px; border-radius: 8px; }

  .nav-links, .nav-search { display: none; }

  .nav-search-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: 0; background: transparent;
    font-size: 18px; color: var(--text); flex-shrink: 0;
    cursor: pointer;
  }
  .mobile-search-bar {
    position: fixed; top: calc(56px + env(safe-area-inset-top, 0px));
    left: 0; right: 0;
    display: flex; padding: 8px 12px; background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 6px 14px rgba(0,0,0,.06);
    z-index: 110;
  }
  .mobile-search-bar input {
    width: 100%; height: 40px; padding: 0 14px; font-size: 16px;
    border: 1px solid var(--border); border-radius: 20px; outline: none;
    font-family: inherit;
  }
  [data-theme="dark"] .mobile-search-bar { background: #1e293b; border-color: #334155; }

  .user-area { gap: 6px; }
  .user-name, .user-level { display: none; }
  .user-area .btn { min-height: 34px; padding: 5px 12px; font-size: 13px; }
  .user-area .btn-primary { display: none; } /* 注册入口放在登录页 */
  .theme-toggle { width: 38px; height: 38px; }

  /* ---- 底部 Tab 栏 ---- */
  .bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #fff; border-top: 1px solid var(--border);
  }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: var(--text-gray); font-size: 11px; line-height: 1;
    -webkit-tap-highlight-color: transparent;
  }
  .bn-item span { font-size: 20px; line-height: 1; }
  .bn-item b { font-weight: normal; }
  .bn-item.active { color: var(--primary); }
  [data-theme="dark"] .bottom-nav { background: #1e293b; border-color: #334155; }

  /* ---- 首页横向分类标签 ---- */
  .course-tabs {
    display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 2px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .course-tabs::-webkit-scrollbar { display: none; }
  .ct-item {
    flex: 0 0 auto; padding: 7px 14px; border-radius: 16px;
    background: #fff; border: 1px solid var(--border);
    font-size: 13px; color: var(--text-gray); white-space: nowrap;
  }
  .ct-item.active { background: var(--primary); border-color: var(--primary); color: #fff; }
  [data-theme="dark"] .ct-item { background: #1e293b; border-color: #334155; }

  /* ---- 通用容器 ---- */
  .container {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .section { padding: 20px 0; }
  .section-title { font-size: 18px; margin-bottom: 14px; }

  /* ---- 轮播 ---- */
  .carousel { margin: 12px 16px; border-radius: 12px; }
  .carousel-slide { height: clamp(180px, 46vw, 240px); padding: 0 22px; }
  .carousel-slide .slide-title { font-size: clamp(22px, 5.6vw, 28px); line-height: 1.25; margin-bottom: 8px; }
  .carousel-slide .slide-desc {
    font-size: 13px; line-height: 1.5; max-width: 90%;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .carousel-slide .slide-btn { margin-top: 12px; padding: 8px 18px; font-size: 14px; }
  .carousel-dots { bottom: 10px; }
  .carousel-dots span { width: 22px; height: 6px; }

  /* ---- VIP 横幅 ---- */
  .vip-banner {
    flex-direction: column; align-items: flex-start; gap: 12px;
    padding: 18px; margin-top: 14px; border-radius: 12px;
  }
  .vip-banner .vip-title { font-size: 17px; line-height: 1.4; }
  .vip-banner .vip-sub { font-size: 13px; }
  .vip-banner .btn {
    width: 100%; min-height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
  }

  /* ---- 课程网格 / 卡片 ---- */
  .course-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .category-block { padding: 16px 14px 18px; margin-bottom: 16px; border-radius: 10px; }
  .category-block-title { font-size: 16px; margin-bottom: 12px; }
  .course-cover { height: 110px; }
  .course-body { padding: 12px; }
  .course-title-row { flex-direction: column; gap: 2px; margin-bottom: 6px; }
  .course-title { font-size: 14px; line-height: 1.4; }
  .course-date { font-size: 11px; }
  .course-meta { flex-wrap: wrap; gap: 4px 8px; font-size: 12px; margin-bottom: 8px; }
  .course-price { font-size: 15px; }

  /* ---- 登录 / 注册 ---- */
  .auth-page { padding-top: 0; }
  .auth-page .auth-wrap {
    min-height: 100vh; min-height: 100dvh;
    align-items: flex-start;
    padding: calc(28px + env(safe-area-inset-top, 0px)) 16px
             calc(28px + env(safe-area-inset-bottom, 0px));
  }
  .auth-card { width: 100%; max-width: 420px; padding: 26px 20px; border-radius: 12px; }
  .auth-card h2 { font-size: 22px; }
  .auth-page .theme-toggle-fixed { top: calc(12px + env(safe-area-inset-top, 0px)); }

  .form-group input, .form-group textarea, .form-group select,
  .code-row input, .mobile-search-bar input, .nav-search-input,
  .danmaku-send input, .reply-form input { font-size: 16px; }
  .form-group input, .form-group select, .code-btn { min-height: 44px; }

  /* ---- 课程详情 ---- */
  .course-detail { grid-template-columns: 1fr; gap: 16px; padding: 16px 0 24px; }
  .course-info { padding: 16px; border-radius: 10px; }
  .course-info h1 { font-size: 19px; line-height: 1.4; }
  .course-info .info-meta { flex-wrap: wrap; gap: 6px 12px; font-size: 12px; margin-bottom: 10px; }
  .course-info .info-desc { font-size: 13px; line-height: 1.6; }
  .course-info .info-price { font-size: 22px; }
  .player-wrap { border-radius: 10px; }
  .side-panel { max-height: none; overflow: visible; }
  .side-body { overflow: visible; }
  .side-tab { min-height: 44px; padding: 12px 0; }
  .episode-item { min-height: 46px; }
  .comment-content, .reply-item { font-size: 13px; }

  /* ---- 播放器控制条：进度条占满第一行 ---- */
  .player-controls { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .pc-progress { order: -1; flex: 1 0 100%; height: 26px; touch-action: none; }
  .pc-round { width: 40px; height: 40px; }
  .pc-btn { min-height: 40px; padding: 6px 9px; font-size: 12px; }
  .pc-time { font-size: 12px; }
  .pc-play-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; padding: 0;
  }
  .pc-desktop-label { display: none; }
  .pc-mobile-label { display: inline; }
  .speed-menu { bottom: calc(100% + 6px); }
  .pc-speed.open .speed-menu { display: block; }

  /* ---- 我的学习 ---- */
  .history-item {
    display: grid; grid-template-columns: 104px minmax(0, 1fr);
    grid-template-areas: "cover info" "action action";
    gap: 10px 12px; align-items: start; padding: 14px 0;
  }
  .course-cover.small { grid-area: cover; width: 104px; height: 64px; border-radius: 8px; }
  .history-info { grid-area: info; }
  .history-item > .btn {
    grid-area: action; width: 100%; min-height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .history-title { font-size: 15px; line-height: 1.4; }
  .history-sub { flex-wrap: wrap; gap: 4px 8px; font-size: 12px; }

  /* ---- 账号订单：表格转卡片 ---- */
  .account-orders { overflow: visible; }
  .account-orders .table { min-width: 0; }
  .account-orders thead { display: none; }
  .account-orders, .account-orders tbody,
  .account-orders tr, .account-orders td { display: block; width: 100%; }
  .account-orders tr {
    border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 12px; margin-bottom: 12px; background: #fff;
  }
  .account-orders td {
    display: flex; gap: 10px; align-items: flex-start;
    border: 0; padding: 5px 0; text-align: left; word-break: break-word;
  }
  .account-orders td::before {
    content: attr(data-label);
    flex: 0 0 68px; padding-top: 2px;
    color: var(--text-gray); font-size: 12px;
  }
  .account-orders .op-link { display: inline-flex; align-items: center; min-height: 36px; }
  [data-theme="dark"] .account-orders tr { background: #1e293b; border-color: #334155; }

  /* ---- 弹窗：底部面板 ---- */
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal, .modal.modal-lg {
    width: 100%; max-width: none; max-height: 92vh; max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .modal h3 { font-size: 17px; margin-bottom: 14px; }
  .pay-title { font-size: 14px; }
  .pay-amount { font-size: 28px; }
  .pay-tip { font-size: 12px; line-height: 1.5; }
  .pay-qrcode { padding: 8px; max-width: 100%; }
  .pay-qrcode img, .pay-qrcode canvas { max-width: 100%; height: auto; }
  .pay-tip-mobile {
    display: block; margin-top: 10px; padding: 8px 10px;
    color: #6b7280; background: #f9fafb; border-radius: 8px;
    font-size: 12px; line-height: 1.5;
  }
  [data-theme="dark"] .pay-tip-mobile { background: #0f172a; color: #9ca3af; }

  .vip-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .vip-option { padding: 14px 8px; }
  .vip-option .vo-name { font-size: 16px; }
  .vip-option .vo-price { font-size: 19px; }

  /* ---- 分页 / 按钮 / 页脚 ---- */
  .pager { justify-content: flex-start; gap: 6px; }
  .pager-info { flex: 1 0 100%; margin: 0 0 4px; font-size: 12px; }
  .page-btn { min-width: 40px; height: 40px; }
  .page-size { height: 40px; }
  .btn {
    min-height: 42px; padding: 10px 16px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .btn-sm { min-height: 36px; padding: 8px 12px; }
  .footer { padding: 24px 16px calc(30px + env(safe-area-inset-bottom, 0px)); }
  .toast { top: calc(56px + env(safe-area-inset-top, 0px) + 14px); }
}

/* ---------- 小屏手机 ---------- */
@media (max-width: 480px) {
  .container { padding-left: 14px; padding-right: 14px; }
  .carousel { margin: 10px 14px; }
  .carousel-slide { height: 190px; padding: 0 18px; }
  .carousel-slide .slide-title { font-size: 22px; }
  .carousel-slide .slide-desc { font-size: 12px; max-width: 100%; }
  .course-cover { height: 96px; }
  .course-body { padding: 10px; }
  .course-title { font-size: 13px; }
  .course-date { display: none; }
  .history-item { grid-template-columns: 96px minmax(0, 1fr); }
  .course-cover.small { width: 96px; height: 58px; }
  .history-title { font-size: 14px; }
}

/* ---------- 超窄屏 ---------- */
@media (max-width: 360px) {
  .course-grid { grid-template-columns: 1fr; }
  .course-cover { height: 150px; }
  .vip-options { grid-template-columns: 1fr; }
  .logo-text { display: none; }
}

/* ---------- 触屏设备：关闭粘性 hover，菜单改点击 ---------- */
@media (hover: none) {
  .nav-dropdown:hover .dropdown-menu { display: none; }
  .nav-dropdown.open .dropdown-menu { display: block; }
  .course-card:hover { transform: none; }
  .pc-speed:hover .speed-menu { display: none; }
  .pc-speed.open .speed-menu { display: block; }
}
