:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1a2332;
  --text-2: #5a6678;
  --text-3: #8b95a5;
  --border: #e2e8f0;
  --border-2: #cbd5e1;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #ecfdf5;
  --accent: #ea580c;
  --accent-soft: #fff7ed;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 3px rgba(16, 32, 52, .06), 0 8px 24px rgba(16, 32, 52, .06);
  --shadow-lg: 0 4px 12px rgba(16, 32, 52, .10), 0 20px 48px rgba(16, 32, 52, .10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
img, video { display: block; max-width: 100%; }

/* ===== 顶栏 ===== */
.topbar {
  position: sticky; top: 0; z-index: 60;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto;
  padding: 12px 24px;
  display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; color: #fff;
  font-size: 22px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(15, 118, 110, .28);
}
.brand-text h1 { font-size: 20px; font-weight: 700; letter-spacing: .3px; line-height: 1.25; }
.brand-text p { font-size: 13px; color: var(--text-3); line-height: 1.3; }

.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav button {
  padding: 9px 16px; border-radius: 10px;
  font-size: 16px; font-weight: 600; color: var(--text-2);
  transition: background .16s, color .16s;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.on { background: var(--brand); color: #fff; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 10px;
  display: grid; place-items: center; font-size: 19px;
  border: 1px solid var(--border); background: var(--surface);
  transition: background .16s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ===== 容器 ===== */
.wrap { max-width: 1280px; margin: 0 auto; padding: 28px 24px 80px; }

/* ===== 英雄区 ===== */
.hero {
  background: linear-gradient(135deg, #0f766e 0%, #0d9488 45%, #14b8a6 100%);
  border-radius: var(--radius-lg); color: #fff;
  padding: 40px 44px; margin-bottom: 30px;
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px;
  width: 280px; height: 280px; border-radius: 50%;
  background: rgba(255, 255, 255, .10);
}
.hero h2 { font-size: 32px; font-weight: 700; letter-spacing: .5px; margin-bottom: 12px; position: relative; }
.hero p { font-size: 17px; opacity: .95; max-width: 660px; position: relative; }
.hero-stats { display: flex; gap: 34px; margin-top: 26px; position: relative; flex-wrap: wrap; }
.hero-stat b { display: block; font-size: 30px; font-weight: 700; line-height: 1.2; }
.hero-stat span { font-size: 14px; opacity: .88; }

/* ===== 分类导航 ===== */
.section-head {
  display: flex; align-items: baseline; gap: 12px; margin: 34px 0 16px; flex-wrap: wrap;
}
.section-head h3 { font-size: 22px; font-weight: 700; }
.section-head span { font-size: 15px; color: var(--text-3); }

.cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
.cat {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 20px 18px; text-align: left;
  transition: border-color .16s, transform .16s, box-shadow .16s;
  display: flex; flex-direction: column; gap: 4px;
}
.cat:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cat.on { border-color: var(--brand); background: var(--brand-soft); }
.cat-emoji { font-size: 30px; line-height: 1.2; }
.cat-name { font-size: 18px; font-weight: 700; }
.cat-count { font-size: 14px; color: var(--text-3); }

/* ===== 工具栏 ===== */
.toolbar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin: 26px 0 18px;
}
.search {
  flex: 1; min-width: 220px; position: relative;
}
.search input {
  width: 100%; padding: 13px 16px 13px 46px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); font-size: 16px; outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(20, 184, 166, .14); }
.search svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); opacity: .4; }
.sortbar { display: flex; gap: 8px; }
.sortbar button {
  padding: 12px 16px; border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); font-size: 15px; font-weight: 600; color: var(--text-2);
  transition: all .16s;
}
.sortbar button:hover { border-color: var(--border-2); }
.sortbar button.on { background: var(--text); color: #fff; border-color: var(--text); }

/* ===== 视频网格 ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .18s, box-shadow .18s, border-color .18s;
  cursor: pointer;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--border-2); }

.thumb {
  position: relative; aspect-ratio: 16/9;
  background: linear-gradient(135deg, #0f766e22, #14b8a633);
  display: grid; place-items: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-fallback { font-size: 52px; opacity: .9; }
.dur {
  position: absolute; right: 10px; bottom: 10px;
  background: rgba(10, 18, 30, .82); color: #fff;
  padding: 4px 10px; border-radius: 7px; font-size: 14px; font-weight: 600;
  backdrop-filter: blur(4px);
}
.badge {
  position: absolute; left: 10px; top: 10px;
  padding: 4px 11px; border-radius: 20px;
  font-size: 13px; font-weight: 700; color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.16);
}
.play-fab {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(8, 16, 28, .30); opacity: 0; transition: opacity .18s;
}
.card:hover .play-fab { opacity: 1; }
.play-fab i {
  width: 62px; height: 62px; border-radius: 50%;
  background: rgba(255,255,255,.95); color: var(--brand);
  display: grid; place-items: center; font-size: 24px; font-style: normal;
  padding-left: 4px; box-shadow: 0 6px 20px rgba(0,0,0,.24);
}

.body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.title { font-size: 17px; font-weight: 700; line-height: 1.45; }
.meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--text-3); }
.dot { width: 3px; height: 3px; border-radius: 50%; background: var(--border-2); }
.desc {
  font-size: 14.5px; color: var(--text-2); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.tag {
  font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 7px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}

/* ===== 播放器弹层 ===== */
.player-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 14, 24, .84); backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 24px;
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
.player-mask.on { opacity: 1; pointer-events: auto; }
.player-box {
  background: var(--surface); border-radius: var(--radius-lg);
  width: min(1060px, 100%); max-height: 92vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(.97); transition: transform .22s;
}
.player-mask.on .player-box { transform: scale(1); }
.player-head {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 22px 26px 18px; border-bottom: 1px solid var(--border);
}
.player-head h3 { font-size: 23px; font-weight: 700; line-height: 1.4; flex: 1; }
.player-head .sub { font-size: 14px; color: var(--text-3); margin-top: 5px; }
.close-btn {
  width: 42px; height: 42px; border-radius: 11px; font-size: 22px;
  border: 1px solid var(--border); background: var(--surface-2);
  display: grid; place-items: center; flex-shrink: 0;
  transition: background .16s;
}
.close-btn:hover { background: var(--border); }
.player-video { width: 100%; background: #000; aspect-ratio: 16/9; }

/* 「去 B 站看」提示条。
   视频存在家里 NAS 上，外网看要靠 Cloudflare 隧道跨海回源，
   第一个看的人等得久（实测 74KB/s）。B站有国内 CDN，几乎秒开，
   所以给一个直达出口。 */
.slow-tip {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 10px;
  padding: 11px 18px;
  background: #FEF4F7;
  border-bottom: 1px solid #F4D6E0;
  font-size: 15px; color: #7a3548;
}
.slow-tip a {
  display: inline-block;
  padding: 9px 20px; border-radius: 10px;
  background: #FB7299; color: #fff;
  font-size: 15.5px; font-weight: 600;
  text-decoration: none; white-space: nowrap;
}
.slow-tip a:active { opacity: .85; }
.player-info { padding: 20px 26px 26px; display: flex; flex-direction: column; gap: 14px; }
.player-info .desc { -webkit-line-clamp: unset; font-size: 15.5px; }
.pinfo-row { display: flex; gap: 22px; flex-wrap: wrap; font-size: 15px; color: var(--text-2); }
.pinfo-row b { color: var(--text); font-weight: 700; }

/* ===== 搜索范围切换 ===== */
.tabs {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.tab {
  padding: 11px 20px; border-radius: 11px; font-size: 16px; font-weight: 600;
  color: var(--text-2); border: 1.5px solid var(--border); background: var(--surface);
  transition: all .16s;
}
.tab:hover { border-color: var(--border-2); color: var(--text); }
.tab.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tab-hint { font-size: 14px; color: var(--text-3); margin-left: 4px; }

.link-btn {
  font-size: 15px; font-weight: 600; color: var(--brand);
  padding: 7px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface);
}
.link-btn:hover { background: var(--brand-soft); border-color: var(--brand); }
.link-btn[disabled] { opacity: .45; cursor: default; }

.bili-head {
  display: flex; align-items: center; gap: 14px; margin: 6px 0 16px;
  font-size: 15px; color: var(--text-2);
}
.bili-head .link-btn { margin-left: auto; }

/* B站结果卡片 */
.bcard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .18s, box-shadow .18s;
}
.bcard:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.bcard .thumb { aspect-ratio: 16/9; background: var(--surface-2); }
.bcard .thumb img { width: 100%; height: 100%; object-fit: cover; }
.bcard .dur { background: rgba(10, 18, 30, .85); }
.bcard .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.bcard .title {
  font-size: 16px; font-weight: 700; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.bcard .meta { font-size: 13.5px; color: var(--text-3); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bcard .desc {
  font-size: 13.5px; color: var(--text-2); line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.bcard .acts { display: flex; gap: 8px; margin-top: auto; padding-top: 10px; }
.bcard .acts a, .bcard .acts button {
  flex: 1; text-align: center; padding: 10px 8px; border-radius: 10px;
  font-size: 14.5px; font-weight: 600; border: 1.5px solid var(--border);
  background: var(--surface-2); color: var(--text-2); transition: all .16s;
}
.bcard .acts a:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.bcard .acts .own { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }

.bili-msg {
  background: var(--accent-soft); border: 1px solid #fed7aa; color: #7c2d12;
  border-radius: var(--radius); padding: 16px 20px; font-size: 15px; line-height: 1.6;
  margin-bottom: 16px;
}

/* ===== 训练计划 ===== */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.plan {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.plan-top { display: flex; align-items: center; gap: 12px; }
.plan-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; }
.plan h4 { font-size: 19px; font-weight: 700; }
.plan-col {
  margin-left: auto; color: #fff; font-size: 13px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; letter-spacing: 1px;
}
.plan .plan-desc { font-size: 14.5px; color: var(--text-2); }
.plan-items { display: flex; flex-direction: column; gap: 9px; }
.plan-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px;
  background: var(--surface-2); border-radius: 10px; font-size: 15px;
  border: 1px solid transparent; transition: all .16s; text-align: left; width: 100%;
}
.plan-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.plan-item .n {
  width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.plan-item .t { flex: 1; font-weight: 600; }
.plan-item .m { font-size: 13px; color: var(--text-3); }

/* ===== 统计条 ===== */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 22px 0; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-card .l { font-size: 14px; color: var(--text-3); margin-bottom: 4px; }
.stat-card .v { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-card .v small { font-size: 15px; font-weight: 600; color: var(--text-3); margin-left: 3px; }

/* ===== 提示 ===== */
.note {
  background: var(--accent-soft); border: 1px solid #fed7aa;
  border-radius: var(--radius); padding: 18px 22px; margin: 24px 0;
  display: flex; gap: 14px; align-items: flex-start;
}
.note .ico { font-size: 22px; line-height: 1.4; flex-shrink: 0; }
.note h4 { font-size: 17px; font-weight: 700; margin-bottom: 5px; color: #9a3412; }
.note p { font-size: 15px; color: #7c2d12; line-height: 1.65; }

.empty { text-align: center; padding: 70px 20px; color: var(--text-3); }
.empty .big { font-size: 56px; margin-bottom: 14px; }

.footer {
  border-top: 1px solid var(--border); margin-top: 50px; padding: 26px 24px;
  text-align: center; font-size: 14px; color: var(--text-3);
}

/* ===== 悬浮播放列表 ===== */
.queue {
  position: fixed; right: 20px; bottom: 20px; z-index: 80;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-width: 330px; width: calc(100vw - 40px); overflow: hidden;
}
.queue-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px;
}
.queue-head .sp { margin-left: auto; font-size: 14px; color: var(--text-3); font-weight: 500; }
.queue-list { max-height: 340px; overflow: auto; }
.qitem {
  display: flex; align-items: center; gap: 11px; padding: 11px 16px;
  font-size: 14.5px; border-bottom: 1px solid var(--border); width: 100%; text-align: left;
}
.qitem:hover { background: var(--surface-2); }
.qitem .qn { width: 24px; height: 24px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.qitem .qt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .qm { font-size: 12.5px; color: var(--text-3); flex-shrink: 0; }

/* ===== 大字号模式 ===== */
body.lg { font-size: 19.5px; }
body.lg .title { font-size: 19px; }
body.lg .desc { font-size: 16px; }
body.lg .nav button { font-size: 17.5px; }
body.lg .cat-name { font-size: 19.5px; }

/* ===== 响应式 ===== */
@media (max-width: 860px) {
  .topbar-inner { padding: 10px 16px; gap: 12px; }
  .brand-text p { display: none; }
  .wrap { padding: 20px 16px 70px; }
  .hero { padding: 28px 24px; border-radius: var(--radius); }
  .hero h2 { font-size: 25px; }
  .hero p { font-size: 16px; }
  /* iPad Air 竖屏视口 768px、手机也都在这个区间。
     原来这里直接 display:none，结果老人只剩「首页」，
     切不到「全部课程 / 训练计划 / 安全指南」——等于把一个按钮搞丢了。
     改成顶栏下方一整条可横向滑动的导航。 */
  .topbar-inner { flex-wrap: wrap; }
  .nav {
    display: flex; width: 100%; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: 0; margin-top: 6px; padding-bottom: 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav button { flex: 0 0 auto; white-space: nowrap; padding: 8px 14px; font-size: 15px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
  .player-head { padding: 16px 18px 14px; }
  .player-head h3 { font-size: 19px; }
  .player-info { padding: 16px 18px 22px; }
  .cat { padding: 16px 14px; }
  .cat-emoji { font-size: 25px; }
  .cat-name { font-size: 16.5px; }
  .queue { right: 12px; bottom: 12px; left: 12px; max-width: none; }
}

/* ============================================================
   iOS 12 / 老 Safari 兼容补丁
   ------------------------------------------------------------
   老人用的 iPad Air（MD789CH/A，2013 年机型）最高只能到 iOS 12.5.8，
   它的 Safari 不支持下面三个特性：
     - flex 布局里的 gap   （需要 iOS 14.5+）
     - aspect-ratio        （需要 iOS 15+）
     - inset               （需要 iOS 14.1+）
   不补的后果：元素全挤在一起、缩略图高度塌成 0、
   视频播放遮罩铺不满屏幕（看起来像播放器坏了）。
   用 @supports 隔离，新浏览器完全不受影响。
   ============================================================ */
@supports not (aspect-ratio: 1 / 1) {

  /* ---- 1. 16:9 缩略图：用 padding-bottom 撑出比例 ---- */
  .thumb,
  .bcard .thumb { height: 0; padding-bottom: 56.25%; }
  .thumb img,
  .bcard .thumb img {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%; object-fit: cover;
  }
  .thumb-fallback {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
  }

  /* ---- 2. inset 拆成四边 ---- */
  .play-fab,
  .player-mask { top: 0; right: 0; bottom: 0; left: 0; }

  /* ---- 3. 视频区高度 ----
     iOS 12 不认 aspect-ratio，<video> 在视频加载出来之前没有固有高度，
     只剩浏览器默认的 150px 细黑条，老人会以为播放器坏了。
     按弹层实际宽度（视口宽 - 两侧 24px padding）算出 16:9 的高度兜底；
     视频一旦加载出来，video 会按自己的真实比例撑开，这条就不起作用了。 */
  .player-video { min-height: calc((100vw - 48px) * 0.5625); }

  /* ---- 4. flex gap 换成相邻兄弟的外边距 ---- */
  .topbar-inner > * + * { margin-left: 20px; }
  .brand > * + * { margin-left: 12px; }
  .nav > * + * { margin-left: 4px; }
  .hero-stats > * + * { margin-left: 34px; }
  .section-head > * + * { margin-left: 12px; }
  .toolbar > * + * { margin-left: 12px; }
  .sortbar > * + * { margin-left: 8px; }
  .meta > * + * { margin-left: 8px; }
  .tags > * + * { margin-left: 6px; }
  .player-head > * + * { margin-left: 16px; }
  .pinfo-row > * + * { margin-left: 22px; }
  .tabs > * + * { margin-left: 10px; }
  .bili-head > * + * { margin-left: 14px; }
  .bcard .meta > * + * { margin-left: 8px; }
  .bcard .acts > * + * { margin-left: 8px; }
  .plan-top > * + * { margin-left: 12px; }
  .plan-item > * + * { margin-left: 11px; }
  .note > * + * { margin-left: 14px; }
  .queue-head > * + * { margin-left: 10px; }
  .qitem > * + * { margin-left: 11px; }
  .slow-tip > * + * { margin-left: 10px; }

  .cat > * + * { margin-top: 4px; }
  .body > * + * { margin-top: 9px; }
  .player-info > * + * { margin-top: 14px; }
  .bcard .body > * + * { margin-top: 8px; }
  .plan > * + * { margin-top: 14px; }
  .plan-items > * + * { margin-top: 9px; }

  @media (max-width: 860px) {
    .topbar-inner > * + * { margin-left: 12px; }
    .nav { margin-left: 0; }
  }
}

/* backdrop-filter：iOS 12 只认 -webkit- 前缀，
   不加的话顶栏和播放遮罩的毛玻璃会退化成纯色块。 */
.topbar { -webkit-backdrop-filter: saturate(180%) blur(14px); }
.dur { -webkit-backdrop-filter: blur(4px); }
.player-mask { -webkit-backdrop-filter: blur(8px); }
