:root {
  --bg: #0d1117;
  --bg-soft: #151b24;
  --card: #1a2230;
  --line: #263041;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #22d3ee;
  --accent-soft: rgba(34, 211, 238, 0.15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(13, 17, 23, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.brand-mark { color: var(--accent); }
.search {
  flex: 1;
  display: flex;
  gap: 8px;
  max-width: 520px;
}
.search input {
  flex: 1;
  min-width: 0;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search button {
  padding: 9px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #06232b;
  font-weight: 600;
  cursor: pointer;
}
.search button:hover { filter: brightness(1.08); }

/* ---------- layout ---------- */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* ---------- stage: player + playlist ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  margin-bottom: 28px;
}
.player-box {
  background: #000;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
#video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  object-fit: contain;
}
.player-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.now {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}
.player-ctrl { display: flex; align-items: center; gap: 10px; }
.switch { display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }

.btn {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06232b;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); color: #06232b; }
.btn-text {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.btn-text:hover { color: #ff6b6b; }
.btn-text:disabled { opacity: 0.5; cursor: default; }
.btn-text:disabled:hover { color: var(--muted); }

.side {
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.side-head h2 { margin: 0; font-size: 15px; }
.side-actions { display: flex; align-items: center; gap: 12px; }
.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  text-align: center;
}
.custom-add {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.custom-add input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  outline: none;
}
.custom-add input:focus { border-color: var(--accent); }

.playlist {
  flex: 1;
  margin: 0;
  padding: 6px;
  list-style: none;
  overflow-y: auto;
  max-height: 420px;
}
.playlist li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.playlist li:hover { background: var(--card); }
.playlist li.active { background: var(--accent-soft); }
.playlist li.active .pl-name { color: var(--accent); }
.pl-title { flex: 1; min-width: 0; }
.pl-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pl-sub { display: block; color: var(--muted); font-size: 12px; }
.pl-del {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
}
.pl-del:hover { color: #ff6b6b; }
.side-empty { padding: 14px; color: var(--muted); }

/* ---------- browse ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
#typeSelect {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
}
.pager, .pager-bottom { display: flex; align-items: center; gap: 10px; }
.pager-bottom { justify-content: center; margin-top: 18px; }
.page-info { color: var(--muted); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-pic {
  position: relative;
  aspect-ratio: 3 / 4;
  background: #0a0e14 center / cover no-repeat;
}
.card-pic .fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
}
.card-body { padding: 8px 10px 10px; }
.card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-meta { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.note {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 11px;
}
.state { padding: 30px 0; text-align: center; color: var(--muted); }
.skeleton { height: 220px; border-radius: 10px; background: linear-gradient(90deg, #151b24, #1c2534, #151b24); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; }
.modal-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.7); }
.modal-body {
  position: relative;
  width: min(920px, 94vw);
  max-height: 88vh;
  margin: 4vh auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-soft);
  overflow-y: auto;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.detail { display: flex; gap: 18px; }
#dPic {
  width: 160px;
  flex: none;
  border-radius: 10px;
  background: #0a0e14;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}
.detail-info { min-width: 0; }
#dName { margin: 0 0 6px; font-size: 20px; }
.meta { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.des {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  max-height: 72px;
  overflow-y: auto;
}
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.eps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-top: 18px;
}
.eps button {
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.eps button:hover { border-color: var(--accent); color: var(--accent); }
.eps button.added { border-color: var(--accent); color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  max-width: 90vw;
  text-align: center;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
}

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
  .playlist { max-height: 260px; }
  .detail { flex-direction: column; }
  #dPic { width: 120px; }
  .topbar-inner { flex-wrap: wrap; }
  .search { max-width: none; }
}

@media (max-width: 600px) {
  .layout { padding: 12px 12px 24px; }

  .topbar-inner { padding: 10px 12px; gap: 10px; }
  .brand { font-size: 16px; }
  .search { flex: 1 1 100%; }
  .search input { padding: 8px 12px; }
  .search button { padding: 8px 16px; }

  .stage { gap: 12px; margin-bottom: 20px; }
  .player-meta { padding: 8px 10px; }
  .now { flex: 1 1 100%; max-width: 100%; }
  .player-ctrl { flex: 1; justify-content: flex-end; }

  .side-head { padding: 8px 12px; }
  .custom-add { padding: 8px 10px; }
  .playlist { max-height: 220px; }

  .toolbar { gap: 8px; margin-bottom: 12px; }
  #typeSelect { padding: 6px 8px; font-size: 13px; }
  .btn-sm { padding: 4px 10px; font-size: 12px; }
  .page-info { font-size: 12px; }

  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .card-body { padding: 6px 6px 8px; }
  .card-title { font-size: 12px; }
  .card-meta { font-size: 11px; }
  .note { left: 4px; bottom: 4px; padding: 1px 4px; font-size: 10px; }

  .modal-body { width: 94vw; margin: 2vh auto; padding: 14px; }
  #dName { font-size: 17px; }
  .des { max-height: 56px; }
  .eps { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .eps button { padding: 6px 2px; font-size: 12px; }
  .toast { bottom: 20px; padding: 8px 14px; }
}

/* 触屏浏览器（尤其 iOS）聚焦字号 <16px 的输入框时会自动放大页面，
   且输入法收起后缩放不会自行还原，这里统一提到 16px 从源头避免放大 */
@media (hover: none) and (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
}
