:root {
  --bg: #0f1115;
  --bg2: #171a21;
  --card: #1d212b;
  --line: #2a2f3c;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #e50914;
  --accent2: #f5c518;
  --ok: #2fbf71;
  --err: #ff5c5c;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.danger { color: var(--err) !important; }
button { font: inherit; cursor: pointer; }
input, textarea {
  font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,17,21,.96); border-bottom: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px) * 0);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; max-width: 1100px; margin: 0 auto; }
.logo { background: none; border: none; color: var(--text); font-size: 19px; font-weight: 700; padding: 4px 0; }
.topnav { display: flex; gap: 6px; }
.nav-btn { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.nav-btn:active { background: var(--card); }
.searchbar { display: flex; gap: 8px; max-width: 1100px; margin: 10px auto 2px; }
.searchbar input { flex: 1; font-size: 16px; } /* 16px 防 iOS 自动放大 */
.primary-btn { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 10px 18px; font-weight: 600; white-space: nowrap; }
.primary-btn:active { opacity: .85; }
.ghost-btn { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 14px; }
.text-btn { background: none; border: none; color: var(--muted); padding: 6px 2px; font-size: 14px; }
.inline-link { background: none; border: none; color: var(--accent2); padding: 0; text-decoration: underline; }

main { max-width: 1100px; margin: 0 auto; padding: 14px; }
.view { animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.section-head h2, .section-head h3 { margin: 0; }
.home-empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.home-empty .big { font-size: 44px; margin: 0 0 8px; }

/* 海报网格 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.poster-card { background: var(--card); border-radius: var(--radius); overflow: hidden; cursor: pointer; border: 1px solid var(--line); }
.poster-card:active { transform: scale(.98); }
.poster-img { position: relative; aspect-ratio: 2/3; background: var(--bg2); }
.poster-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-badge {
  position: absolute; left: 0; bottom: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  color: #fff; font-size: 12px; padding: 14px 8px 6px;
  display: flex; justify-content: space-between; gap: 6px;
}
.poster-progress { position: absolute; top: 0; left: 0; height: 3px; background: var(--accent); }
.poster-info { padding: 8px 10px 10px; }
.poster-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poster-sub { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-tag { display: inline-block; background: var(--bg2); border: 1px solid var(--line); color: var(--accent2); border-radius: 4px; padding: 0 5px; font-size: 11px; margin-right: 5px; }

/* 搜索状态 */
.status-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.status-chip { font-size: 13px; border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 5px 11px; color: var(--muted); }
.status-chip.ok { color: var(--ok); }
.status-chip.err { color: var(--err); }
.result-group-title { margin: 20px 0 10px; font-size: 16px; }
.result-group-title .count { color: var(--muted); font-size: 13px; font-weight: 400; }
.empty-note { color: var(--muted); padding: 10px 0 4px; }

/* 详情 */
.detail-head { display: flex; gap: 16px; margin-top: 10px; }
.detail-head img { width: 150px; aspect-ratio: 2/3; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg2); }
.detail-info h2 { margin: 2px 0 8px; font-size: 21px; }
.detail-info p { margin: 4px 0; font-size: 14px; }
.detail-content { color: var(--muted); font-size: 14px; line-height: 1.65; margin-top: 14px; }
.line-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; }
.line-tab { background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px 14px; font-size: 14px; }
.line-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.line-tab .warn { color: var(--accent2); font-size: 12px; }
.line-tab.active .warn { color: #ffd9db; }
.episodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ep-btn { background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 10px 6px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ep-tools { display: flex; gap: 8px; margin: 4px 0 10px; }

/* 播放器 */
.player-title { font-size: 18px; margin: 8px 0 10px; }
.player-wrap { background: #000; border-radius: var(--radius); overflow: hidden; }
.player-wrap video { width: 100%; aspect-ratio: 16/9; display: block; background: #000; }
.player-meta { margin: 10px 0 2px; font-size: 13px; }
.error-bar { background: #3a1d1d; border: 1px solid var(--err); color: #ffb3b3; border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 14px; line-height: 1.6; }

/* 片源管理 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.card h3 { margin: 0 0 12px; }
.field { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.field input { margin-top: 6px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--muted); margin: 8px 0 12px; }
.check input { width: auto; margin-top: 3px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.source-item { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.source-item .grow { flex: 1; min-width: 0; }
.source-item .name { font-weight: 600; }
.source-item .api { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-item .ops { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn { background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px 10px; font-size: 13px; }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--line); border-radius: 999px; pointer-events: none; transition: .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { left: 23px; }
textarea { resize: vertical; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); background: #262b36; color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px;
  font-size: 14px; z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.5);
  max-width: 88vw; text-align: center;
}
.footer { text-align: center; padding: 22px 14px 30px; }

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .poster-info { padding: 6px 7px 8px; }
  .poster-title { font-size: 12.5px; }
  .detail-head { flex-direction: row; }
  .detail-head img { width: 108px; }
  .detail-info h2 { font-size: 17px; }
  .episodes { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
  .source-item { flex-wrap: wrap; }
  main { padding: 10px; }
}
