/* ============ 英语课程音频伴侣 · 浅色科技风 ============ */
:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #1e2a3a;
  --ink-2: #64748b;
  --ink-3: #94a3b8;
  --brand: #2563eb;
  --brand-2: #06b6d4;
  --brand-grad: linear-gradient(135deg, #2563eb, #06b6d4);
  --line: #e2e8f0;
  --hover: #f0f6ff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(30, 42, 58, .06), 0 4px 16px rgba(30, 42, 58, .05);
  --shadow-lg: 0 4px 12px rgba(37, 99, 235, .12), 0 12px 32px rgba(37, 99, 235, .10);
  /* 播放器高度（随断点覆盖）+ iOS 底部安全区，供内容区占位与 toast 定位使用 */
  --player-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }

/* ============ 登录页 ============ */
.login-view {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background:
    radial-gradient(ellipse 60% 50% at 70% 20%, rgba(6, 182, 212, .10), transparent),
    radial-gradient(ellipse 50% 40% at 20% 80%, rgba(37, 99, 235, .10), transparent),
    #f4f7fb;
}
.login-bg-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(37, 99, 235, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, .05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, #000, transparent);
}
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 360px; padding: 36px 34px 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo { margin-bottom: 14px; }
.login-card h1 { font-size: 19px; letter-spacing: 1px; }
.login-sub { margin: 6px 0 24px; color: var(--ink-2); font-size: 12px; letter-spacing: 2px; }
.field { text-align: left; margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; color: var(--ink-2); font-size: 12px; }
.field input {
  width: 100%; padding: 10px 12px;
  font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  background: #fafbfd; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
  background: #fff;
}
.login-error { color: #e11d48; font-size: 12px; margin-bottom: 12px; }
.btn-primary {
  width: 100%; padding: 10px 0;
  border: none; border-radius: 8px;
  background: var(--brand-grad); color: #fff;
  font-size: 15px; letter-spacing: 6px;
  transition: filter .15s, box-shadow .15s;
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: var(--shadow-lg); }
.login-tip { margin-top: 18px; color: var(--ink-3); font-size: 11px; }

/* ============ 顶栏 ============ */
.app-view { min-height: 100%; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 24px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--brand-grad); color: #fff; font-size: 14px;
}
.topbar-title { font-size: 15px; font-weight: 600; letter-spacing: .5px; }
.topbar-badge {
  padding: 2px 8px; border-radius: 999px;
  background: #ecf5ff; color: var(--brand);
  border: 1px solid rgba(37, 99, 235, .18);
  font-size: 11px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-2); font-size: 12px;
}
.user-chip::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, .6);
}
.btn-ghost {
  padding: 5px 12px; border-radius: 7px;
  border: 1px solid var(--line); background: #fff;
  color: var(--ink-2); font-size: 12px;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }

/* ============ 内容区 ============ */
/* 底部留白 = 播放器高度 + 安全区，避免内容被固定播放器遮挡 */
.content { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 20px 24px calc(var(--player-h) + 28px + var(--safe-b)); }

.grade-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.grade-tab {
  padding: 6px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff;
  color: var(--ink-2); font-size: 13px;
  transition: all .15s;
}
.grade-tab:hover { border-color: var(--brand); color: var(--brand); }
.grade-tab.active {
  background: var(--brand-grad); border-color: transparent; color: #fff;
  box-shadow: 0 2px 10px rgba(37, 99, 235, .25);
}

.book-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; margin-bottom: 18px;
  background: linear-gradient(120deg, #eaf2ff 0%, #f0fbff 60%, #fff 100%);
  border: 1px solid rgba(37, 99, 235, .14);
  border-radius: var(--radius);
  position: relative; overflow: hidden;
}
.book-banner::before {
  content: ""; position: absolute; right: -30px; top: -30px;
  width: 140px; height: 140px; border-radius: 50%;
  background: radial-gradient(circle, rgba(6, 182, 212, .14), transparent 70%);
}
.book-title { font-size: 16px; font-weight: 600; color: #1d4ed8; }
.book-meta { margin-top: 4px; color: var(--ink-2); font-size: 12px; }
.book-stat { color: var(--ink-2); font-size: 12px; text-align: right; position: relative; }
.book-stat b { color: var(--brand); font-size: 15px; }

.unit-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.unit-card {
  padding: 16px 18px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s;
  position: relative;
}
.unit-card:hover { transform: translateY(-3px); border-color: rgba(37, 99, 235, .4); box-shadow: var(--shadow-lg); }
.unit-card.playing { border-color: var(--brand); }
.unit-num {
  display: inline-block; margin-bottom: 8px;
  font-size: 11px; font-weight: 700; color: var(--brand);
  letter-spacing: 1px;
}
.unit-card h3 { font-size: 14px; margin-bottom: 10px; }
.unit-card h3 .unit-full { font-weight: 400; color: var(--ink-2); font-size: 11px; }
.unit-progress { height: 4px; border-radius: 2px; background: #eef2f7; overflow: hidden; }
.unit-progress-fill { height: 100%; width: 0; background: var(--brand-grad); border-radius: 2px; transition: width .3s; }
.unit-card-meta { margin-top: 8px; display: flex; justify-content: space-between; color: var(--ink-3); font-size: 11px; }
.unit-card-meta .now { color: var(--brand); }

/* ============ 单元详情 ============ */
.btn-back {
  margin-bottom: 14px; padding: 5px 14px 5px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  color: var(--ink-2); font-size: 12px;
}
.btn-back:hover { border-color: var(--brand); color: var(--brand); }
.unit-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.unit-head h2 { font-size: 17px; }
.unit-meta { margin-top: 4px; color: var(--ink-2); font-size: 12px; }
.btn-play-all {
  width: auto; padding: 8px 22px; letter-spacing: 2px; font-size: 13px;
}
.track-list {
  list-style: none; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.track-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background .12s;
}
.track-item:last-child { border-bottom: none; }
.track-item:hover { background: var(--hover); }
.track-item.playing { background: #eef6ff; }
.track-idx {
  width: 24px; height: 24px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #f1f5f9; color: var(--ink-3);
  font-size: 11px;
}
.track-item.playing .track-idx {
  background: var(--brand-grad); color: #fff;
  box-shadow: 0 0 8px rgba(37, 99, 235, .35);
}
.track-name { flex: 1; font-size: 13px; }
.track-name .eq { display: none; gap: 2px; align-items: flex-end; margin-left: 8px; }
.track-item.playing .track-name .eq { display: inline-flex; }
.eq i { width: 2.5px; background: var(--brand); animation: eq 1s infinite ease-in-out; border-radius: 1px; }
.eq i:nth-child(1) { height: 6px; animation-delay: 0s; }
.eq i:nth-child(2) { height: 10px; animation-delay: .25s; }
.eq i:nth-child(3) { height: 5px; animation-delay: .5s; }
@keyframes eq { 0%, 100% { transform: scaleY(.4); } 50% { transform: scaleY(1); } }
.track-dur { color: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.track-done { color: #10b981; font-size: 11px; }
.track-resume { color: var(--brand-2); font-size: 11px; }

/* ============ 播放器 ============ */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  height: 72px; padding: 0 24px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 24px rgba(30, 42, 58, .06);
}
.player-info { display: flex; align-items: center; gap: 12px; width: 220px; min-width: 0; flex-shrink: 0; }
.player-disc {
  display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand-grad); color: #fff; font-size: 16px;
  box-shadow: 0 2px 10px rgba(37, 99, 235, .3);
}
.player.playing .player-disc { animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.player-text { overflow: hidden; }
.player-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-sub { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.p-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: none; background: transparent; color: var(--ink-2);
  font-size: 13px; transition: background .12s, color .12s;
}
.p-btn:hover { background: var(--hover); color: var(--brand); }
.p-play {
  width: 40px; height: 40px; font-size: 15px;
  background: var(--brand-grad); color: #fff;
  box-shadow: 0 2px 10px rgba(37, 99, 235, .3);
}
.p-play:hover { background: var(--brand-grad); color: #fff; filter: brightness(1.08); }
.player-progress { flex: 1; display: flex; align-items: center; gap: 10px; }
.p-time { color: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; width: 36px; }
.p-bar {
  flex: 1; height: 5px; border-radius: 3px; background: #e8eef5;
  cursor: pointer; position: relative;
}
.p-bar-fill {
  height: 100%; width: 0; border-radius: 3px;
  background: var(--brand-grad); position: relative;
}
.p-bar-fill::after {
  content: ""; position: absolute; right: -5px; top: 50%; transform: translateY(-50%);
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand);
  opacity: 0; transition: opacity .12s;
}
.p-bar:hover .p-bar-fill::after { opacity: 1; }
.player-extra { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.p-rate { display: flex; align-items: center; gap: 5px; color: var(--ink-2); font-size: 11px; }
.p-rate select {
  padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--brand); font-size: 11px; outline: none; cursor: pointer;
}
.p-toggle { display: flex; align-items: center; gap: 5px; color: var(--ink-2); font-size: 11px; cursor: pointer; user-select: none; }
.p-toggle input { accent-color: var(--brand); cursor: pointer; }
#posHint { color: var(--brand-2); font-size: 11px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--player-h) + 20px + var(--safe-b)); transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 8px 18px; border-radius: 8px;
  background: rgba(30, 42, 58, .92); color: #fff;
  font-size: 12px; z-index: 40;
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============ 响应式 ============ */
/* 【1】中大屏（笔记本 / 小桌面）：压缩播放器与间距，功能全部保留 */
@media (max-width: 1023px) {
  .player { gap: 12px; padding: 0 16px; }
  .player-info { width: 170px; }
  .player-extra { gap: 10px; }
  .p-rate-label { display: none; }   /* 下拉框本身已显示 "1x"，省去文字 */
}

/* 【2】平板竖屏 / 大手机（≤860px）：内容区收紧，书本横幅纵向堆叠 */
@media (max-width: 860px) {
  .content { padding: 16px 16px calc(var(--player-h) + 24px + var(--safe-b)); }
  .book-banner { flex-direction: column; align-items: flex-start; gap: 10px; }
  .book-stat { text-align: left; }
  .unit-head { flex-wrap: wrap; gap: 10px; }
}

/* 【3】手机（≤759px）：播放器改为两行网格，顶栏与列表紧凑化 */
@media (max-width: 759px) {
  :root { --player-h: 96px; }

  /* 顶栏 */
  .topbar { height: 48px; padding: 0 12px; gap: 8px; }
  .topbar-badge { display: none; }
  .topbar-title { font-size: 14px; }
  .topbar-right { gap: 8px; }
  .user-chip .user-full { display: none; }
  .user-chip .user-short { display: inline; }
  .btn-ghost { padding: 6px 10px; min-height: 32px; }

  /* 年级标签：横向滑动，避免换行溢出 */
  .grade-tabs {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 2px;
  }
  .grade-tabs::-webkit-scrollbar { display: none; }
  .grade-tab { flex: 0 0 auto; white-space: nowrap; padding: 7px 14px; }

  /* 单元网格：min() 保证窄屏下单列且不出横向滚动 */
  .unit-grid { grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 12px; }
  .unit-card { padding: 14px 15px; }

  /* 曲目列表：加大触摸热区 */
  .track-item { gap: 10px; padding: 12px 14px; min-height: 46px; }
  .track-name { font-size: 12.5px; }

  /* 播放器：两行网格 —— 第一行信息+控制，第二行进度+倍速/连播 */
  .player {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "info     controls"
      "progress extra";
    align-items: center;
    height: auto;
    gap: 6px 10px;
    padding: 8px 12px calc(8px + var(--safe-b));
  }
  .player-info     { grid-area: info; width: auto; gap: 8px; }
  .player-controls { grid-area: controls; gap: 4px; }
  .player-progress { grid-area: progress; gap: 8px; flex-wrap: nowrap; }
  .player-extra    { grid-area: extra; justify-content: flex-end; gap: 10px; flex-wrap: nowrap; }
  .player-disc { width: 36px; height: 36px; font-size: 14px; }
  /* 触摸热区：上一首/下一首 ≥38px，播放键 44px */
  .p-btn { width: 38px; height: 38px; font-size: 14px; }
  .p-play { width: 44px; height: 44px; font-size: 16px; }
  .p-time { width: auto; font-size: 10px; }
  .p-bar { height: 6px; }
  /* 触摸端无 hover，进度滑块常显 */
  .p-bar-fill::after { width: 12px; height: 12px; right: -6px; opacity: 1; }
  .p-rate { font-size: 11px; }
  .p-rate select { padding: 5px 4px; font-size: 11px; }
  /* 连播开关加大纵向热区 */
  .p-toggle { font-size: 11px; min-height: 30px; padding: 0 2px; }
  /* 断点续播提示浮到播放器上方，空内容时自动隐藏 */
  #posHint {
    position: absolute; left: 12px; bottom: calc(100% + 6px);
    padding: 3px 10px; border-radius: 999px;
    background: rgba(6, 182, 212, .12); font-size: 10px;
  }
  #posHint:empty { display: none; }

  /* 输入框 ≥16px，避免 iOS Safari 聚焦时自动放大页面 */
  .field input { font-size: 16px; }
}

/* 【4】小屏手机（≤400px）：单元单列；播放器改三行，让进度条占满整行 */
@media (max-width: 400px) {
  :root { --player-h: 112px; }
  .content { padding: 14px 12px calc(var(--player-h) + 20px + var(--safe-b)); }
  .unit-grid { grid-template-columns: 1fr; }
  .book-banner { padding: 14px 15px; }
  .book-title { font-size: 15px; }
  .player {
    grid-template-areas:
      "info     controls"
      "progress progress"
      "extra    extra";
  }
  .player-extra { gap: 8px; }
  .p-toggle { font-size: 10px; }
  .p-rate select { font-size: 10px; }
}

/* 【5】大屏手机（401~520px）：单元卡片排两列，减少滚动 */
@media (min-width: 401px) and (max-width: 520px) {
  .unit-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}

/* 【6】横屏矮屏（如手机横放）：压缩纵向占用 */
@media (max-height: 480px) {
  .topbar { height: 44px; }
  .content { padding-top: 12px; }
  .player { padding-top: 4px; padding-bottom: calc(4px + var(--safe-b)); }
}

/* 【6】触摸设备：去掉易粘滞的 hover 位移效果 */
@media (hover: none) {
  .unit-card:hover { transform: none; box-shadow: var(--shadow); border-color: var(--line); }
  .unit-card.playing:hover { border-color: var(--brand); }
  .track-item:hover { background: transparent; }
  .track-item.playing { background: #eef6ff; }
  .track-item.playing:hover { background: #eef6ff; }
  .btn-ghost:hover { border-color: var(--line); color: var(--ink-2); }
}

/* 【7】无障碍：尊重"减少动态效果"系统设置 */
@media (prefers-reduced-motion: reduce) {
  .player.playing .player-disc { animation: none; }
  .eq i { animation: none; }
  .toast { animation: none; }
}
