/* ===== CSS 变量 — 暗色主题 ===== */
:root {
  --bg-primary: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-surface: #252525;
  --bg-input: #333;
  --text-primary: #e5e5e5;
  --text-secondary: #999;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

/* ===== 基础重置 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
}

/* ===== 通用组件 ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary.btn-small {
  padding: 6px 16px;
  font-size: 14px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid #444;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-secondary:hover {
  background: #333;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
}

.btn-text:hover {
  color: var(--text-primary);
}

.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--text-secondary);
  font-size: 18px;
}

.error-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  text-align: center;
}

.empty-text {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 0;
}

/* ===== 登录页 ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0f0f0f 70%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 0 16px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid #444;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color var(--transition);
}

.input-group input:focus {
  border-color: var(--accent);
}

.input-group input::placeholder {
  color: var(--text-secondary);
}

.error-message {
  color: var(--danger);
  font-size: 14px;
  text-align: left;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.login-form .btn-primary {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  margin-top: 8px;
}

/* ===== 站点头部 ===== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.site-title {
  font-size: 20px;
  font-weight: 600;
}

/* ===== 番剧卡片网格 ===== */
.series-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  padding-bottom: 40px;
}

.series-card {
  display: block;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
  color: var(--text-primary);
}

.series-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  color: var(--text-primary);
}

.card-cover {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg-surface);
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.resume-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
}

.card-info {
  padding: 12px 16px 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== 播放器页面 ===== */
.player-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}

.back-link {
  font-size: 14px;
  white-space: nowrap;
}

.series-title {
  font-size: 18px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-layout {
  display: flex;
  gap: 0;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

.player-main {
  flex: 1;
  min-width: 0;
}

.video-wrapper {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

/* Video.js 暗色皮肤 */
.video-js.vjs-theme-dark {
  --vjs-theme-color: var(--accent);
}

.vjs-theme-dark .vjs-control-bar {
  background: rgba(0, 0, 0, 0.7);
}

.vjs-theme-dark .vjs-play-progress,
.vjs-theme-dark .vjs-volume-level {
  background: var(--accent);
}

.vjs-theme-dark .vjs-big-play-button {
  background: rgba(59, 130, 246, 0.8);
  border: none;
  border-radius: 50%;
  width: 64px;
  height: 64px;
  line-height: 64px;
}

/* AirPlay 按钮 */
.vjs-airplay-button .vjs-icon-placeholder::before {
  content: "\f0a0";
  font-family: "VideoJS";
}

/* 自动连播提示 */
.auto-play-next {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-top: 8px;
}

.countdown {
  font-weight: 700;
  color: var(--accent);
  font-size: 18px;
  min-width: 20px;
  text-align: center;
}

/* ===== 集数侧边栏 ===== */
.episode-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-left: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 120px);
}

.sidebar-title {
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg-surface);
}

.episode-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.episode-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition);
  font-size: 14px;
}

.episode-item:hover {
  background: var(--bg-surface);
}

.episode-item.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.ep-number {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.episode-item.active .ep-number {
  background: var(--accent);
  color: #fff;
}

.ep-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ep-watched {
  color: #22c55e;
  font-size: 16px;
}

/* ===== 响应式 ===== */

/* 平板 */
@media (max-width: 1024px) {
  .series-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .episode-sidebar {
    width: 240px;
  }
}

/* 移动端 */
@media (max-width: 768px) {
  .series-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .player-layout {
    flex-direction: column;
  }

  .episode-sidebar {
    width: 100%;
    margin-left: 0;
    margin-top: 16px;
    max-height: 300px;
  }

  .player-header {
    padding: 8px 12px;
  }

  .series-title {
    font-size: 16px;
  }

  .auto-play-next {
    flex-wrap: wrap;
    font-size: 14px;
  }

  .login-card {
    padding: 32px 24px;
  }

  .form-row {
    flex-direction: column;
  }
}

/* ===== 下载管理页 ===== */
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.dl-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header .section-title {
  margin-bottom: 0;
}

.section-actions {
  display: flex;
  gap: 8px;
}

.dl-form .form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.form-group-small {
  flex: 0 0 100px;
}

.form-group label {
  font-size: 13px;
  color: var(--text-secondary);
}

.label-hint {
  font-size: 12px;
  color: #666;
}

.form-group input,
.form-group textarea {
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid #444;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.5;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.submit-msg {
  font-size: 14px;
}

.submit-msg.success { color: #22c55e; }
.submit-msg.error { color: var(--danger); }

/* 任务列表 */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.task-batch {
  background: var(--bg-surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.batch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.batch-title {
  font-weight: 600;
  font-size: 14px;
}

.batch-progress {
  font-size: 13px;
  color: var(--text-secondary);
}

.batch-progress.has-error {
  color: var(--danger);
}

.batch-items {
  display: flex;
  flex-direction: column;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.task-item:last-child {
  border-bottom: none;
}

.task-ep {
  font-weight: 600;
  font-family: monospace;
  width: 46px;
  flex-shrink: 0;
}

.task-status-icon {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.status-pending .task-status-icon { color: #666; }
.status-downloading .task-status-icon { color: var(--accent); animation: pulse 1s infinite; }
.status-done .task-status-icon { color: #22c55e; }
.status-error .task-status-icon { color: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.task-progress-text {
  flex: 1;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-error .task-progress-text {
  color: var(--danger);
}

.task-url {
  color: #555;
  font-size: 12px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-cancel {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-cancel:hover {
  color: var(--danger);
  background: rgba(239,68,68,0.1);
}

/* 首页下载按钮 */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 1px solid #444;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
  text-decoration: none;
}

.btn-icon:hover {
  background: #333;
  color: var(--text-primary);
}

/* 说明文字 */
.section-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* form-row 在 upload-form 中也适用 */
.upload-form .form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

/* 文件选择器 */
.file-input {
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid #444;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

.file-input::file-selector-button {
  background: var(--bg-surface);
  border: 1px solid #555;
  border-radius: 4px;
  color: var(--text-primary);
  padding: 4px 12px;
  margin-right: 10px;
  cursor: pointer;
}

/* 上传进度列表 */
.upload-progress-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upload-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-radius: 4px;
  font-size: 13px;
}

.upload-ep {
  font-weight: 600;
  font-family: monospace;
  width: 46px;
}

.upload-filename {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.upload-size {
  color: #666;
  font-size: 12px;
  width: 70px;
  text-align: right;
}

.upload-status {
  width: 80px;
  text-align: right;
  font-size: 12px;
}

.upload-status.uploading { color: var(--accent); }
.upload-status.done { color: #22c55e; }
.upload-status.error { color: var(--danger); }

/* 错误详情 — 完整显示 */
.task-error-detail {
  padding: 6px 16px 10px 72px;
  font-size: 12px;
  color: var(--danger);
  font-family: monospace;
  word-break: break-all;
  line-height: 1.6;
  background: rgba(239,68,68,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
