/* ---------- 基础 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #0e0e10;
  color: #eaeaea;
  user-select: none;
}
.hidden { display: none !important; }

/* ---------- 顶部 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0) 20px 0;
  height: calc(56px + env(safe-area-inset-top, 0));
  background: #16161a;
  border-bottom: 1px solid #26262c;
  position: relative;
  z-index: 10;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.icon-btn {
  background: none; border: none; color: #eaeaea;
  font-size: 22px; cursor: pointer; padding: 8px;
  border-radius: 8px;
}
.icon-btn:hover { background: #26262c; }

.mode-switch {
  display: flex;
  gap: 4px;
  background: #1b1b20;
  padding: 3px;
  border-radius: 8px;
}
.mode-btn {
  background: none;
  border: none;
  color: #9a9aa3;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover { color: #eaeaea; }
.mode-btn.active {
  background: #3a3a44;
  color: #eaeaea;
}

/* 作者分组 */
.author-group {
  padding: 20px 20px 0;
}
.author-group-title {
  font-size: 15px;
  font-weight: 600;
  color: #eaeaea;
  margin-bottom: 12px;
  padding-left: 2px;
}
.author-group .video-grid {
  padding: 0;
  margin-bottom: 8px;
}

/* 卡片里的作者 */
.card-author {
  color: #9a9aa3;
  font-size: 12px;
  margin-top: 2px;
}

/* ---------- 视图切换 ---------- */
.view { display: none; height: calc(100% - 56px); overflow-y: auto; }
.view.active { display: block; }
#player-view.active {
  display: block;
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  background: #000;
  z-index: 20;
  overflow: hidden;
}

/* ---------- 视频列表 ---------- */
.video-grid {
  list-style: none;
  display: grid;
  gap: 16px;
  padding: 20px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.video-card {
  background: #1b1b20;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  border: 1px solid #26262c;
}
.video-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.card-thumb {
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #2a2a35, #15151a);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: #55555f;
}
.card-body { padding: 12px 14px; }
.card-title { font-size: 15px; font-weight: 500; margin-bottom: 6px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { font-size: 12px; color: #999; display: flex; gap: 12px; }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #888;
}
.empty-state p { margin-bottom: 16px; }

.btn-primary {
  background: #4a8ef6; color: #fff; border: none;
  padding: 10px 20px; border-radius: 8px; cursor: pointer;
  font-size: 14px;
}
.btn-primary:hover { background: #3a7de0; }
.btn-ghost {
  background: transparent; color: #aaa; border: 1px solid #3a3a42;
  padding: 10px 20px; border-radius: 8px; cursor: pointer;
  font-size: 14px;
}
.btn-ghost:hover { border-color: #555; color: #eee; }

/* ---------- 播放器 ---------- */
.player-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  touch-action: none;
}
.video-stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  transition: transform .25s ease-out, right .25s ease-out;
  transform-origin: center center;
}
#video {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}

/* 控件层 */
.controls {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  background: linear-gradient(to bottom, rgba(0,0,0,.5) 0, transparent 20%, transparent 60%, rgba(0,0,0,.7) 100%);
}
.controls.show { opacity: 1; }
.controls.show .ctrl-btn,
.controls.show .ctrl-circle,
.controls.show .progress,
.controls.show .title-bar,
.controls.show .time { pointer-events: auto; }

.ctrl-btn {
  position: absolute; top: 16px;
  background: rgba(0,0,0,.4); color: #fff;
  border: none; width: 40px; height: 40px;
  border-radius: 50%; font-size: 22px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#btn-back { left: 16px; }
#btn-fullscreen { right: 16px; font-size: 18px; }
#btn-quality {
  right: 64px; width: auto; min-width: 44px; height: 36px; top: 18px;
  padding: 0 12px; border-radius: 18px;
  font-size: 13px; font-weight: 600; letter-spacing: .5px;
}

/* 分辨率菜单 */
.quality-menu {
  position: absolute; top: 62px; right: 16px;
  background: rgba(20, 20, 24, 0.95);
  border: 1px solid #2e2e36;
  border-radius: 10px;
  padding: 6px; min-width: 140px;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 5;
}
.quality-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: 6px;
  color: #eaeaea; font-size: 14px; cursor: pointer;
}
.quality-item:hover { background: #2a2a32; }
.quality-item.active { color: #4a8ef6; }
.quality-item .kbps { font-size: 11px; color: #888; margin-left: 12px; }
.quality-item.active .kbps { color: #4a8ef6aa; }

.title-bar {
  position: absolute; top: 20px; left: 70px; right: 70px;
  color: #fff; font-size: 15px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}

.center-controls {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; gap: 48px; align-items: center;
}
.ctrl-circle {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  border: 2px solid rgba(255,255,255,.3);
  color: #fff; font-size: 20px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.ctrl-circle.big { width: 72px; height: 72px; font-size: 28px; }
.ctrl-circle:hover { background: rgba(0,0,0,.75); border-color: rgba(255,255,255,.6); }
.seek-label { font-size: 12px; font-weight: 600; }

.bottom-bar {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  display: flex; align-items: center; gap: 12px;
}
.time { color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 48px; text-align: center; }
.progress {
  flex: 1; height: 20px; position: relative; cursor: pointer;
  display: flex; align-items: center;
  touch-action: none;
}
.progress::before {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  height: 4px; transform: translateY(-50%);
  background: rgba(255,255,255,.25); border-radius: 2px;
}
.progress-buffer, .progress-played {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  height: 4px; border-radius: 2px;
}
.progress-buffer { background: rgba(255,255,255,.4); width: 0; }
.progress-played { background: #4a8ef6; width: 0; }
.progress-thumb {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 14px; height: 14px; border-radius: 50%; background: #fff;
  left: 0; box-shadow: 0 0 4px rgba(0,0,0,.5);
}

/* ---------- 播放列表抽屉 ---------- */
.player-wrap {
  --drawer-w: 320px;
}
.player-wrap.drawer-open .video-stage,
.player-wrap.drawer-open .controls {
  right: var(--drawer-w);
}
.controls { transition: opacity .2s, right .25s ease-out; }

.drawer-handle {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 28px;
  height: 64px;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  border-radius: 8px 0 0 8px;
  color: #fff;
  font-size: 22px;
  line-height: 64px;
  text-align: center;
  cursor: pointer;
  z-index: 30;
  padding: 0;
  transition: right 0.25s ease-out;
}
.drawer-handle:hover { background: rgba(0, 0, 0, 0.75); }
.player-wrap.drawer-open .drawer-handle { right: var(--drawer-w); }

.drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--drawer-w);
  max-width: 80vw;
  height: 100%;
  background: #1b1b20;
  border-left: 1px solid #2e2e36;
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.5);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #2e2e36;
  font-size: 15px;
  font-weight: 600;
  color: #eaeaea;
  flex-shrink: 0;
}
.drawer-close {
  background: none;
  border: none;
  color: #9a9aa3;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
}
.drawer-close:hover { color: #eaeaea; }

.drawer-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
  flex: 1;
}
.drawer-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.drawer-item:hover { background: #24242b; }
.drawer-item.active {
  background: #242a38;
  border-left-color: #4a8ef6;
}
.drawer-item-idx {
  color: #6a6a73;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  width: 22px;
  flex-shrink: 0;
  text-align: right;
}
.drawer-item.active .drawer-item-idx { color: #4a8ef6; }
.drawer-item-body { flex: 1; min-width: 0; }
.drawer-item-title {
  color: #eaeaea;
  font-size: 13px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.drawer-item-meta {
  color: #9a9aa3;
  font-size: 11px;
  margin-top: 3px;
  display: flex;
  gap: 8px;
}

@media (max-width: 640px) {
  .drawer { width: 280px; }
  .drawer-handle { width: 24px; height: 56px; font-size: 18px; }
}

.zoom-hint {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,.7); color: #fff;
  padding: 8px 16px; border-radius: 20px;
  font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.zoom-hint.show { opacity: 1; }

/* ---------- 配置弹窗 ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-content {
  background: #1b1b20;
  border-radius: 14px;
  padding: 24px;
  width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal-content h2 { margin-bottom: 20px; font-size: 18px; }
.modal-content label {
  display: block; margin-bottom: 16px;
}
.modal-content label span {
  display: block; font-size: 13px; color: #aaa; margin-bottom: 6px;
}
.modal-content input {
  width: 100%;
  background: #0e0e10;
  border: 1px solid #2e2e36;
  border-radius: 8px;
  padding: 10px 12px;
  color: #eaeaea;
  font-size: 14px;
  font-family: inherit;
}
.modal-content input:focus { outline: none; border-color: #4a8ef6; }
.tip { font-size: 12px; color: #888; line-height: 1.6; margin: 8px 0 20px; }
.tip code { background: #0e0e10; padding: 1px 6px; border-radius: 4px; color: #b5a9f5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- 响应式：平板 ---------- */
@media (max-width: 1024px) {
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; padding: 16px; }
}

/* ---------- 响应式：手机 ---------- */
@media (max-width: 640px) {
  .topbar h1 { font-size: 16px; }
  .topbar { padding: env(safe-area-inset-top, 0) 12px 0; gap: 8px; }
  .mode-btn { padding: 5px 9px; font-size: 12px; }
  .video-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 12px; }
  .author-group { padding: 12px 12px 0; }
  .card-body { padding: 10px; }
  .card-title { font-size: 13px; }
  .card-meta { font-size: 11px; gap: 8px; }

  .center-controls { gap: 28px; }
  .ctrl-circle { width: 48px; height: 48px; font-size: 16px; }
  .ctrl-circle.big { width: 60px; height: 60px; font-size: 22px; }
  .seek-label { font-size: 11px; }

  .title-bar { font-size: 13px; left: 60px; right: 120px; top: 22px; }
  .ctrl-btn { width: 36px; height: 36px; font-size: 20px; }
  #btn-quality { right: 58px; height: 32px; font-size: 12px; padding: 0 10px; top: 20px; }
  .quality-menu { top: 58px; right: 10px; min-width: 130px; }
  .bottom-bar { left: 10px; right: 10px; bottom: 10px; gap: 8px; }
  .time { font-size: 11px; min-width: 40px; }
}

@media (max-width: 380px) {
  .video-grid { grid-template-columns: 1fr; }
}

/* 横屏手机 */
@media (max-height: 480px) and (orientation: landscape) {
  .ctrl-circle { width: 44px; height: 44px; font-size: 15px; }
  .ctrl-circle.big { width: 56px; height: 56px; }
  .center-controls { gap: 24px; }
}
