/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--cream); }
body { margin: 0; }

/* ===== Variables ===== */
:root {
  --ink: #26313c;
  --muted: #7d8791;
  --cream: #fffaf1;
  --coral: #ff7469;
  --orange: #ffac57;
  --mint: #75c9b5;
}

/* ===== Base ===== */
body {
  color: var(--ink);
  background: radial-gradient(circle at 9% 0%, #fff0d5 0, transparent 28rem), var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", sans-serif;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 4px solid rgba(86,153,220,.55); outline-offset: 3px; }
.player-open { overflow: hidden; }

/* ===== Layout ===== */
.app-shell {
  min-height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) clamp(22px, 5vw, 70px) calc(28px + env(safe-area-inset-bottom));
}

/* ===== Topbar ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: clamp(20px, 2.4vw, 28px); letter-spacing: -.5px; }
.brand-mark {
  display: grid; place-items: center;
  width: 48px; height: 48px; border-radius: 17px;
  background: #77cddd; color: white; font-size: 29px;
  box-shadow: 0 7px 0 #d8eef0;
}
.top-actions { display: flex; align-items: center; gap: 10px; }
.add-button, .quiet-button, .primary-cta { border: 0; cursor: pointer; font-weight: 800; }
.add-button {
  display: flex; align-items: center; gap: 7px;
  padding: 13px 18px; border-radius: 18px;
  background: var(--coral); color: #fff;
  box-shadow: 0 7px 0 #ef554f;
}
.add-button span { font-size: 22px; line-height: 1; }
.add-button:active, .primary-cta:active { transform: translateY(3px); box-shadow: 0 4px 0 #ef554f; }
.quiet-button { background: #fff; padding: 12px 17px; border-radius: 16px; box-shadow: 0 4px 12px #785a2b16; }
.quiet-button.active { color: var(--coral); }
.file-input { display: none; }

/* ===== Intro ===== */
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 58px 0 31px; }
.eyebrow { color: #e68145; font-weight: 850; margin: 0 0 7px; font-size: 15px; letter-spacing: 1.4px; }
h1 { font-size: clamp(35px, 5vw, 61px); letter-spacing: -2.7px; line-height: 1.05; margin: 0; }
.subtitle { color: var(--muted); margin: 14px 0 0; font-size: clamp(15px, 1.8vw, 19px); }
.offline-pill { flex: none; background: #e8f7f1; color: #3b927c; font-weight: 800; padding: 12px 16px; border-radius: 999px; }
.offline-pill i {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: #4eb795; margin-right: 7px; box-shadow: 0 0 0 4px #ccebe0;
}

/* ===== Toast ===== */
.toast {
  position: fixed; top: calc(24px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%); z-index: 20;
  background: #29323b; color: white; padding: 13px 20px; border-radius: 99px;
  box-shadow: 0 10px 30px #18212a40; font-weight: 700; max-width: 80vw; text-align: center;
}

/* ===== 更新提示条 ===== */
.update-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  display: none; align-items: center; justify-content: center; gap: 12px;
  background: #2b7de9; color: #fff; padding: 9px 14px;
  font-weight: 700; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.22);
}
.update-banner button {
  background: #fff; color: #2b7de9; border: 0; border-radius: 9px;
  padding: 6px 13px; font-weight: 800; font-size: 13px; cursor: pointer;
}

/* ===== Video Grid（5 列等高网格，框框统一大小、按行填满） ===== */
.video-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
.video-card, .add-tile { margin: 0; }
.video-card { cursor: pointer; }
.cover {
  position: relative; aspect-ratio: 16 / 9; border-radius: 18px; overflow: hidden;
  background-size: cover; background-position: center;
  box-shadow: 0 5px 14px #69522215;
  transition: transform .2s, box-shadow .2s;
}
.video-card:active .cover { transform: scale(.98); }
.fallback-cover { background: linear-gradient(145deg, #8ed9dd, #f6ca70); }
.fallback-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 14px 18px; text-align: center;
  font-size: clamp(13px, 2vw, 18px); font-weight: 800;
  color: white; text-shadow: 0 1px 6px rgba(0,0,0,.35);
  line-height: 1.35; word-break: break-word;
  pointer-events: none; z-index: 1;
}
.cover-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: linear-gradient(145deg, #8ed9dd, #f6ca70); pointer-events: none; }
.duration {
  position: absolute; right: 10px; bottom: 10px;
  color: #fff; font-size: 11px; font-weight: 800;
  padding: 4px 7px; background: #1e2a34a8; backdrop-filter: blur(10px); border-radius: 8px;
}
.delete-button {
  position: absolute; top: 9px; right: 9px; border: 0;
  width: 34px; height: 34px; border-radius: 50%;
  background: #e94e4e; color: white; font-size: 24px; line-height: 1;
  box-shadow: 0 4px 12px #5d25264d;
}
.card-copy { padding: 12px 2px 0; }
.card-copy h2 { font-size: clamp(11px, 1.15vw, 14px); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.card-copy p { margin: 3px 0 0; color: #84a499; font-size: 11px; font-weight: 600; }

/* ===== Empty State ===== */
.empty-state {
  min-height: 500px; background: #fff; border-radius: 38px;
  padding: 40px 25px 35px; text-align: center;
  box-shadow: 0 18px 60px #7b572717; overflow: hidden;
}
.empty-art {
  position: relative; width: min(360px, 85vw); height: 205px; margin: 0 auto 12px;
  background: #d9f2f1; border-radius: 48% 52% 44% 56% / 52% 49% 51% 48%;
}
.screen {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -44%) rotate(-2deg);
  width: 190px; height: 125px; display: grid; place-items: center;
  border: 11px solid #344754; border-radius: 23px;
  background: linear-gradient(145deg, #ffdd7d, #ff957c);
  box-shadow: 0 15px 0 #b9d9d8;
}
.screen span {
  display: grid; place-items: center; padding-left: 5px;
  width: 54px; height: 54px; border-radius: 50%;
  background: white; color: var(--coral); font-size: 22px;
}
.sun { position: absolute; font-size: 38px; color: #ffb638; top: 19px; right: 37px; }
.cloud { position: absolute; color: white; font-size: 44px; }
.cloud-a { left: 14px; top: 45px; }
.cloud-b { right: 3px; bottom: 7px; font-size: 54px; }
.empty-state h2 { font-size: clamp(25px, 3.5vw, 34px); margin: 10px 0 6px; }
.empty-state > p { color: var(--muted); max-width: 520px; margin: 0 auto 24px; line-height: 1.7; }
.primary-cta { padding: 16px 23px; color: #fff; background: var(--coral); border-radius: 18px; box-shadow: 0 7px 0 #ef554f; }
.tips { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 13px; color: #9f8872; font-weight: 700; font-size: 13px; margin-top: 30px; }
.tips b { color: #edc38f; }

/* ===== Loading ===== */
.loading-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.loading-grid i {
  height: 300px; border-radius: 25px;
  background: linear-gradient(110deg, #f3eada 8%, #fff 18%, #f3eada 33%);
  background-size: 200% 100%; animation: shine 1.2s linear infinite;
}
@keyframes shine { to { background-position-x: -200%; } }

/* ===== Footer ===== */
footer { text-align: center; color: #b5a895; padding-top: 52px; font-size: 12px; font-weight: 700; }

/* ===== Player ===== */
.player { position: fixed; inset: 0; z-index: 50; background: #05090c; touch-action: pan-x; overflow: hidden; }
.player-layout {
  display: flex;
  width: 100%; height: 100%;
  align-items: stretch;
}
.player-main {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
}
/* iPad/iOS Safari 已知 bug：<video> 尺寸正确但帧不绘制（只有声音、黑屏）。
   关键修复：① 用 absolute + inset:0 锚定，避免嵌套百分比高度在 iOS 上解析失败；
   ② translateZ(0) 强制 GPU 合成层，让视频帧真正绘制出来。 */
.player-stage { position: absolute; inset: 0; z-index: 1; overflow: hidden; background: #05090c; }
.player-stage video { position: absolute; inset: 0; z-index: 2; display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player-video-slot { opacity: 0; visibility: hidden; transition: opacity .16s ease; }
.player-video-slot.is-active { opacity: 1; visibility: visible; z-index: 3; }

/* 轻点播放反馈：短暂出现，不挡住视频操作 */
.playback-feedback {
  position: absolute; left: 50%; top: 50%; z-index: 8;
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; background: rgba(0, 0, 0, .48);
  font: 700 28px/1 system-ui, sans-serif;
  opacity: 0; transform: translate(-50%, -50%) scale(.86);
  transition: opacity .13s ease, transform .13s ease;
  pointer-events: none;
}
.playback-feedback.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* 视觉轨道保持纤细，实际拖动区域为 34px，便于 iPad 拖动且不干扰画面轻点。 */
.player-progress-wrap {
  position: absolute; z-index: 9; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom));
  width: min(620px, calc(100% - 150px)); height: 34px;
  transform: translateX(-50%); display: flex; align-items: center;
  opacity: .48; transition: opacity .18s ease;
}
.player-progress-wrap:active, .player-progress-wrap:focus-within { opacity: .9; }
.player-progress {
  width: 100%; height: 34px; margin: 0; padding: 0;
  appearance: none; -webkit-appearance: none; background: transparent;
  touch-action: none; cursor: pointer;
}
.player-progress::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px;
  background: linear-gradient(to right, rgba(255,255,255,.72) 0 var(--progress, 0%), rgba(255,255,255,.2) var(--progress, 0%) 100%);
}
.player-progress::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: -6px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.78); box-shadow: 0 1px 4px rgba(0,0,0,.28);
}
.player-progress::-moz-range-track { height: 4px; border-radius: 999px; background: rgba(255,255,255,.2); }
.player-progress::-moz-range-progress { height: 4px; border-radius: 999px; background: rgba(255,255,255,.72); }
.player-progress::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: rgba(255,255,255,.78); }

@media (max-width: 520px) {
  .player-progress-wrap { width: calc(100% - 112px); bottom: calc(7px + env(safe-area-inset-bottom)); }
  .playback-feedback { width: 58px; height: 58px; font-size: 25px; }
}

/* 容量提示保持低调，只作为需要时可查看的辅助信息。 */
.offline-summary { display: inline-flex; align-items: center; gap: 5px; }
.storage-note {
  display: block; margin-top: 3px; white-space: nowrap;
  color: inherit; opacity: .48; font-size: 10px; font-weight: 500;
  letter-spacing: .01em;
}

/* ===== Player Sidebar (右侧视频列表) ===== */
.player-sidebar {
  width: 320px; min-width: 260px; max-width: 400px;
  background: #0d1117;
  border-left: 1px solid #ffffff12;
  display: flex; flex-direction: column;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.sidebar-title {
  margin: 0; padding: 18px 20px 10px;
  font-size: 15px; font-weight: 800; color: #fff;
  letter-spacing: .3px; white-space: nowrap;
  position: sticky; top: 0; background: #0d1117; z-index: 2;
}
.sidebar-list { padding: 4px 14px 24px; display: flex; flex-direction: column; gap: 8px; }

.sidebar-item {
  display: flex; gap: 11px; cursor: pointer;
  border-radius: 12px; padding: 7px 8px;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-item:hover, .sidebar-item:focus { background: #ffffff0e; }
.sidebar-item.active { background: #ffffff1a; outline: 2px solid rgba(255,255,255,.25); }
.sidebar-thumb {
  flex: 0 0 140px; max-width: 160px; width: 140px; height: 79px;
  border-radius: 8px; overflow: hidden;
  background: linear-gradient(145deg, #8ed9dd, #f6ca70);
  position: relative; flex-shrink: 0;
}
.sidebar-thumb img, .sidebar-thumb video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.sidebar-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.sidebar-name {
  font-size: 13px; font-weight: 700; color: #e8eaed;
  line-height: 1.35; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
.sidebar-duration {
  font-size: 11px; font-weight: 600; color: #aaa;
  margin-top: 2px;
}

/* 播放器内不再需要的旧元素隐藏 */
.player-blur { display: none !important; }
.player-shade { display: none !important; }
.player-title { display: none !important; }
.close-player, .switch-video {
  position: absolute; z-index: 4; border: 0; display: grid; place-items: center;
  border-radius: 50%; color: white; background: #ffffff2b; backdrop-filter: blur(13px); cursor: pointer;
}
.close-player { left: calc(16px + env(safe-area-inset-left)); top: calc(14px + env(safe-area-inset-top)); width: 44px; height: 44px; font-size: 30px; }
.switch-video { right: calc(12px + env(safe-area-inset-right)); width: 48px; height: 48px; font-size: 26px; }
.previous { top: 40%; }
.next { top: calc(40% + 60px); }

/* ===== Responsive（自适应列数：随屏幕收窄减少列数，保证每格可用） ===== */
/* 平板 / iPad mini 竖屏（701–1024px）：保持 5 列，间距收紧更紧凑 */
@media (max-width: 1024px) and (min-width: 701px) {
  .video-grid { grid-template-columns: repeat(5, 1fr); gap: 11px; }
  .card-copy { padding: 8px 2px 0; }
  .card-copy h2 { font-size: 13px; }
}

/* ===== Responsive ===== */
@media (max-width: 700px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .brand span:last-child { display: none; }
  .brand-mark { width: 40px; height: 40px; }
  .quiet-button { display: none; }
  .add-button { padding: 9px 12px; font-size: 13px; }
  .intro { margin-top: 28px; align-items: flex-start; flex-direction: column; }
  .intro h1 { font-size: clamp(22px, 5.5vw, 32px); }
  .offline-pill { font-size: 11px; }
  .video-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .video-grid .video-card .cover { border-radius: 10px; }
  .card-copy h2 { font-size: 11px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .card-copy p { font-size: 10px; }
  .play-bubble { width: 38px; height: 38px; font-size: 15px; }
  .duration { font-size: 10px; padding: 2px 5px; }
  .play-bubble { display: none; }
  .empty-state { padding: 24px 14px; }
  .switch-video { display: none; }
  .player-title { display: none; } /* iPad：底部不显示视频名字 */
  .loading-grid { grid-template-columns: 1fr 1fr; }
  .loading-grid i:last-child { display: none; }

  /* iPad 竖屏：隐藏右侧列表，全屏播放 */
  .player-sidebar { display: none !important; }
  .player-layout { display: block; }
  .player-main { width: 100%; height: 100%; }
}

/* 横屏或宽屏：显示右侧视频列表 */
@media (min-width: 701px) {
  .player-sidebar { display: flex !important; }
}

@media (orientation: landscape) and (max-height: 650px) {
  .player-title { bottom: 18px; }
  .intro { margin-top: 34px; }
  .empty-state { min-height: 390px; display: grid; grid-template-columns: 1fr 1fr; align-items: center; text-align: left; }
  .empty-art { grid-row: 1/5; }
  .empty-state > p { margin: 0 0 18px; }
  .tips { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; }
}

/* ===== v39：全设备自适应与播放器性能优化 ===== */
html, body { width: 100%; min-height: 100%; overflow-x: hidden; }
body { min-height: 100svh; }
.app-shell {
  width: 100%; max-width: 1440px; min-height: 100svh;
  padding: calc(clamp(10px, 2.2vmin, 24px) + env(safe-area-inset-top))
           clamp(12px, 4vw, 56px)
           calc(clamp(16px, 3vmin, 32px) + env(safe-area-inset-bottom));
}
.intro { margin: clamp(20px, 6vmin, 54px) 0 clamp(18px, 3.5vmin, 30px); }
.empty-state {
  min-height: 0; padding: clamp(18px, 4vmin, 38px) clamp(14px, 3vw, 28px);
  border-radius: clamp(20px, 4vmin, 38px);
}
.empty-art { width: min(320px, 72vw); height: clamp(128px, 24vmin, 190px); }
.screen {
  width: clamp(120px, 28vmin, 178px); height: clamp(78px, 18vmin, 116px);
  border-width: clamp(7px, 1.4vmin, 10px);
}
.video-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 42vw), 1fr));
  gap: clamp(9px, 1.8vw, 18px);
}
.loading-grid { grid-template-columns: repeat(auto-fit, minmax(min(180px, 42vw), 1fr)); }
.loading-grid i { height: auto; aspect-ratio: 16 / 9; }

.player {
  width: 100vw; height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.player-layout, .player-main, .player-stage { min-width: 0; min-height: 0; }
.player-stage video {
  max-width: 100%; max-height: 100%; object-fit: contain;
  transform: translateZ(0);
}
.player-sidebar { width: clamp(240px, 25vw, 340px); min-width: 0; }
.sidebar-placeholder {
  width: 100%; height: 100%; display: grid; place-items: center;
  color: #fff; font-size: 22px; background: linear-gradient(145deg, #8ed9dd, #f6ca70);
}
.sidebar-static-frame {
  width: 100%; height: 100%; display: block; object-fit: cover;
  background: linear-gradient(145deg, #8ed9dd, #f6ca70);
}
.sidebar-static-frame.is-ready { background: #111; }
.sidebar-item.active { background: #ffffff1a; outline: 2px solid rgba(255,255,255,.3); }

@media (max-width: 1024px), (orientation: portrait) {
  .player-sidebar { display: none !important; }
  .player-layout { display: block; }
  .player-main { width: 100%; height: 100%; }
}

@media (max-width: 520px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .topbar { gap: 8px; }
  .intro { margin-top: 18px; gap: 10px; }
  .subtitle { margin-top: 7px; font-size: 13px; }
  .eyebrow { font-size: 12px; margin-bottom: 4px; }
  .video-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .empty-state > p { margin-bottom: 16px; line-height: 1.5; font-size: 13px; }
  .tips { margin-top: 18px; gap: 7px; font-size: 11px; }
  footer { padding-top: 28px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell { padding-top: calc(8px + env(safe-area-inset-top)); }
  .intro { margin: 10px 0 12px; }
  .intro .eyebrow, .intro .subtitle, footer { display: none; }
  .empty-state { min-height: 0; padding: 12px 20px; }
  .empty-art { height: min(54vh, 180px); }
  .player-sidebar { display: none !important; }
}
