/* ==========================================================================
   主页「配套课件」面板：图片墙 + 内嵌式 PDF 阅读器
   只借用 site.css 的 token 与 .btn / .lightbox / .ppt-tile 的视觉语言，
   不引入任何 UI 库，也不覆盖站点里已有的选择器（统一 sp- 前缀）。
   ========================================================================== */

/* ---------- 1. tab ---------- */
.sp-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

.sp-tab {
  appearance: none;
  height: 34px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.sp-tab:hover {
  color: var(--ink);
  background: var(--paper-2);
}

.sp-tab.is-active,
.sp-tab.is-active:hover {
  background: var(--primary);
  color: #fff;
}

.sp-panel[hidden] {
  display: none;
}

/* ---------- 2. 图片预览：4 列 × 3 行，十二张一屏看完 ---------- */
.sp-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.sp-tile {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--paper);
  cursor: zoom-in;
  display: flex;
  flex-direction: column;
  transition: border-color 0.18s ease, transform 0.18s ease,
    box-shadow 0.18s ease;
}

.sp-tile:hover,
.sp-tile:focus-visible {
  border-color: var(--tint-primary-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  outline: none;
}

.sp-tile img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--paper-2);
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.sp-tile figcaption {
  margin-top: auto;
  font-size: 0.78rem;
  color: var(--ink-3);
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-empty {
  grid-column: 1 / -1;
  padding: 40px 0;
  text-align: center;
  color: var(--ink-3);
  font-size: 0.9rem;
}

/* 「展开全部」：只在手机端、且网格处于收起状态时出现。
   桌面与平板一眼能看全，按钮不占位。 */
.sp-more {
  display: none;
  width: 100%;
  margin-top: 14px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.sp-more:hover {
  color: var(--primary);
  border-color: var(--tint-primary-strong);
}

/* ---------- 3. 课时选择条 ----------
   16 课时按章分组，一条一份 PDF。横向可滚，不换行：
   换行会把阅读器挤到一两屏之外，滚一条比铺四行更省高度。 */
.sp-lectures {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 10px;
  margin-bottom: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--line);
}

.sp-lecture-ch {
  flex: none;
  margin-left: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--line-strong);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  white-space: nowrap;
}

.sp-lectures .sp-lecture-ch:first-child {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}

.sp-lecture {
  appearance: none;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sp-lecture:hover {
  color: var(--ink);
  background: var(--paper-2);
  border-color: var(--line-strong);
}

.sp-lecture.is-active,
.sp-lecture.is-active:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.sp-lecture-no {
  font-variant-numeric: tabular-nums;
  opacity: 0.72;
}

.sp-lecture.is-active .sp-lecture-no {
  opacity: 0.85;
}

.sp-lecture-now {
  margin: 0 0 12px;
  font-size: 0.86rem;
  color: var(--ink-2);
}

/* ---------- 4. 阅读器外壳 ---------- */
.sp-viewer {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}


/* ---------- 4. 左侧缩略图 + 右侧页面 ----------
   卡片里只放课件本身：没有工具条，所以 .sp-viewer 直接是「缩略图栏 + 舞台」两栏。
   舞台里一次只放一页，整页装进去、居中，不出现滚动条——翻页靠左右方向键。
   高度用 vh 但不低于 480px：课件是 16:9，太矮就会缩成看不清的一条。 */
.sp-body {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  height: clamp(480px, 76vh, 820px);
}

.sp-thumbs {
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px;
  border-right: 1px solid var(--line);
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}

.sp-thumb {
  appearance: none;
  flex: none;
  width: 100%;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s ease, background 0.15s ease,
    box-shadow 0.15s ease;
}

.sp-thumb:hover {
  background: var(--paper);
  border-color: var(--line);
}

.sp-thumb.is-current {
  background: var(--paper);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.sp-thumb-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
}

.sp-thumb-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.sp-thumb-no {
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1;
  color: var(--ink-3);
}

.sp-thumb.is-current .sp-thumb-no {
  color: var(--primary);
}

/* 舞台：固定视口，居中一页，不滚动 */
.sp-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 14px;
  background: var(--paper-2);
}

.sp-stage:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.sp-pages {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.sp-page {
  position: relative;
  flex: none;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}

.sp-page canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* 未渲染时的页码占位；canvas 一旦画好就藏起来 */
.sp-page-no {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-3);
}

.sp-page.is-ready .sp-page-no {
  display: none;
}

/* 左右翻页箭头：悬停才显形，键盘用户靠方向键，不依赖它们 */
.sp-arrow {
  appearance: none;
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 34px;
  height: 34px;
  margin-top: -17px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sp-arrow--prev {
  left: 10px;
}

.sp-arrow--next {
  right: 10px;
}

.sp-stage:hover .sp-arrow,
.sp-arrow:focus-visible {
  opacity: 1;
}

.sp-arrow:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.sp-arrow:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.sp-arrow:disabled {
  opacity: 0;
  cursor: default;
  pointer-events: none;
}

/* 触屏没有 hover，箭头常显 */
@media (hover: none) {
  .sp-arrow {
    opacity: 0.85;
  }
}


/* ---------- 5. 加载 / 失败 / 本地三种状态 ---------- */
.sp-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: auto;
  padding: 26px;
  background: var(--paper-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sp-state[hidden] {
  display: none;
}

.sp-state > [data-card] {
  display: none;
}

/* 状态卡只有两种：载入中与失败。没有 file:// 分支——
   课件按普通 HTTP 取，本地双击打不开是浏览器的事，不在卡片里解释。 */
.sp-state[data-mode="loading"] [data-card="loading"],
.sp-state[data-mode="fail"] [data-card="fail"] {
  display: block;
}

.sp-loadcard {
  width: min(420px, 100%);
  text-align: center;
  color: var(--ink-2);
}

.sp-loadtitle {
  margin: 0 0 4px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
}

.sp-loadnote {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.sp-progress {
  height: 4px;
  margin: 14px 0 10px;
  border-radius: var(--radius-pill);
  background: var(--tint-primary-strong);
  overflow: hidden;
}

.sp-progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.2s ease;
}

.sp-progress.is-indeterminate > span {
  width: 34%;
  animation: sp-slide 1.2s ease-in-out infinite;
}

@keyframes sp-slide {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(320%);
  }
}

.sp-failcard {
  width: min(460px, 100%);
  text-align: center;
  color: var(--ink-2);
}

.sp-failcard h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.sp-failcard p {
  font-size: 0.84rem;
  color: var(--ink-3);
  margin-bottom: 18px;
}

.sp-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* ---------- 6. 窄屏 ---------- */
@media (max-width: 900px) {
  .sp-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  /* 手机端：两列三行先给六张，其余折起，点按钮再铺开。
     十二张在两列下要滚六七屏，先给一个能扫完的开头更合适。 */
  .sp-grid.is-collapsed .sp-tile:nth-child(n + 7) {
    display: none;
  }
  .sp-more {
    display: block;
  }
  .sp-more[hidden] {
    display: none;
  }

  .sp-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: clamp(460px, 70vh, 640px);
  }
  /* 缩略图栏转到顶部，改成横向滚动条 */
  .sp-thumbs {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 8px;
    padding: 8px;
  }
  .sp-thumb {
    width: 84px;
  }
  .sp-pages {
    padding: 0;
  }
  .sp-stage {
    padding: 10px;
  }
  .sp-arrow {
    width: 30px;
    height: 30px;
    margin-top: -15px;
  }
  .sp-arrow--prev {
    left: 4px;
  }
  .sp-arrow--next {
    right: 4px;
  }
}

@media (max-width: 560px) {
  .sp-tabs {
    display: flex;
  }
  .sp-tab {
    flex: 1;
    padding: 0 10px;
  }
  .sp-grid {
    gap: 10px;
  }
  .sp-lectures {
    gap: 5px;
  }
  .sp-lecture {
    height: 28px;
    padding: 0 9px;
    font-size: 0.76rem;
  }
  .sp-lecture-ch {
    margin-left: 6px;
    padding-left: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sp-tab,
  .sp-tile,
  .sp-thumb,
  .sp-progress > span {
    transition: none;
  }
  .sp-progress.is-indeterminate > span {
    animation: none;
    width: 100%;
    opacity: 0.4;
  }
}
