/* ============================================================
   hxrTV · style.css · 方案 4 深色沉浸（ui-design spec 锁定）
   结构：1. tokens → 2. 基础 → 3. 组件 → 4. 视图 → 5. 响应式
   ============================================================ */

/* ---------- 1. tokens（spec.md 契约，禁止发明新值） ---------- */
:root {
  --color-bg: #0f1115;
  --color-bg-play: #0b0d10;
  --color-surface: #1a1d23;
  --color-surface-2: #22262e;
  --color-text-primary: #f2f3f5;
  --color-text-secondary: #b6bcc6;
  --color-text-muted: #8a91a0;
  --color-border: rgba(255, 255, 255, .12);
  --color-accent: #22d3ee;
  --color-accent-soft: #1b333b;
  --color-accent-2: #a78bfa;
  --color-accent-2-soft: #2a2540;
  --color-success: #34d399;
  --color-warning: #fbbf24;
  --color-error: #f87171;
  --color-error-soft: #3a1d1d;
  --color-player-bg: #000;
  --color-btn-on-accent: #04222a;

  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --space-1: .25rem; --space-2: .3125rem; --space-3: .4rem; --space-4: .5rem;
  --space-5: .625rem; --space-6: .78rem; --space-7: 1rem; --space-8: 1.25rem;

  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-sheet: 0 -8px 32px rgba(0,0,0,.5);
  --glow-accent: 0 0 12px color-mix(in srgb, #22d3ee 35%, transparent);

  --motion-fast: 150ms ease-out;
  --motion-base: 250ms ease-out;
}

/* ---------- 2. 基础 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-display);
  background: var(--color-bg);
  color: var(--color-text-primary);
  line-height: 1.6;
  min-height: 100vh;
}
/* 播放视图：沉浸底 body 级切换（S10） */
body[data-route="play"] { background: var(--color-bg-play); }
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font-family: inherit; }
a { color: var(--color-accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
::placeholder { color: var(--color-text-muted); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 3. 组件 ---------- */

/* 3.1 按钮（三态变体） */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-7); border-radius: var(--radius-pill);
  font-size: 15px; font-weight: 500; transition: background var(--motion-fast), opacity var(--motion-fast), transform var(--motion-fast);
  user-select: none; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--color-accent); color: var(--color-btn-on-accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--color-surface-2); border: 1px solid var(--color-border); color: var(--color-text-primary); }
.btn-secondary:hover:not(:disabled) { background: #2a303a; }
.btn-ghost { color: var(--color-text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--color-surface-2); color: var(--color-text-primary); }
.btn-danger { background: var(--color-error-soft); border: 1px solid var(--color-error); color: var(--color-error); }
.btn-sm { min-height: 36px; padding: 0 var(--space-6); font-size: 13.5px; }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md); color: var(--color-text-secondary); transition: background var(--motion-fast), color var(--motion-fast);
}
.icon-btn:hover { background: var(--color-surface-2); color: var(--color-text-primary); }
.icon-btn svg { width: 20px; height: 20px; }

/* 3.2 输入框 */
.input {
  width: 100%; min-height: 44px; padding: 0 var(--space-7);
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-pill); color: var(--color-text-primary); font-size: 15px;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}
.input:hover { border-color: rgba(255,255,255,.28); }
.input:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-accent) 30%, transparent); }
.input-error { border-color: var(--color-error); }
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field label { font-size: 13.5px; color: var(--color-text-secondary); }
.field-error { font-size: 13px; color: var(--color-error); }

/* 3.3 卡片（结果/历史） */
.card {
  background: var(--color-surface); border-radius: var(--radius-md); overflow: hidden;
  box-shadow: var(--shadow-card); border: 1px solid var(--color-border);
  cursor: pointer; transition: transform var(--motion-base), box-shadow var(--motion-base);
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.4); }
.card-cover {
  aspect-ratio: 3/4; display: flex; align-items: center; justify-content: center;
  padding: var(--space-5); text-align: center;
}
.card-title { font-size: 15px; font-weight: 500; padding: var(--space-3) var(--space-4) 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-2) var(--space-4) var(--space-4); font-size: 12px; color: var(--color-text-muted); }

/* 3.4 徽章（来源标识，全局一致 U7） */
.badge {
  display: inline-flex; align-items: center; gap: 3px; min-height: 20px; padding: 1px var(--space-3);
  border-radius: var(--radius-sm); font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.badge-source { background: var(--color-accent-soft); color: var(--color-accent); }
.badge-line { background: var(--color-accent-2-soft); color: var(--color-accent-2); }
.badge-plain { background: var(--color-surface-2); color: var(--color-text-secondary); }

/* 3.5 chip（搜索历史） */
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 var(--space-6);
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-pill); font-size: 14px; color: var(--color-text-secondary);
  transition: background var(--motion-fast), color var(--motion-fast);
}
.chip:hover { background: #2a303a; color: var(--color-text-primary); }
.chip-x { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-muted); margin-right: -6px; }
.chip-x:hover { background: var(--color-surface); color: var(--color-text-primary); }
.chip-x svg { width: 14px; height: 14px; }

/* 3.6 switch */
.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-pill); transition: background var(--motion-fast); pointer-events: none; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--color-text-muted); transition: transform var(--motion-fast), background var(--motion-fast); pointer-events: none; }
.switch input:checked + .switch-track { background: var(--color-accent-soft); border-color: var(--color-accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); background: var(--color-accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-7); min-height: 48px; }

/* 3.7 bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90; animation: fadeIn var(--motion-fast); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91;
  background: var(--color-surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sheet); padding: var(--space-7); max-height: 70vh; overflow-y: auto;
  animation: sheetUp var(--motion-base);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); }
.sheet-title { font-size: 16px; font-weight: 600; }
.sheet-item {
  display: flex; align-items: center; gap: var(--space-5); min-height: 52px; width: 100%;
  padding: var(--space-3) var(--space-6); border-radius: var(--radius-md);
  font-size: 15px; color: var(--color-text-primary); transition: background var(--motion-fast);
}
.sheet-item:hover { background: var(--color-surface-2); }
.sheet-item.is-current { background: var(--color-accent-soft); color: var(--color-accent); }
.sheet-item .badge { margin-left: auto; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

/* 3.8 toast */
.toast {
  position: fixed; top: var(--space-7); left: 50%; transform: translateX(-50%);
  z-index: 99; display: flex; align-items: center; gap: var(--space-3);
  background: var(--color-surface); border: 1px solid var(--color-accent); box-shadow: var(--glow-accent), var(--shadow-card);
  color: var(--color-text-primary); font-size: 14px; padding: var(--space-3) var(--space-7);
  border-radius: var(--radius-pill); animation: toastIn var(--motion-base);
}
.toast-error { border-color: var(--color-error); }
.toast-warning { border-color: var(--color-warning); }
@keyframes toastIn { from { transform: translate(-50%, -12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* 3.9 骨架屏 */
.skeleton { background: linear-gradient(90deg, var(--color-surface) 25%, #232830 50%, var(--color-surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-md); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* 3.10 空状态 */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); padding: 48px 16px; text-align: center; color: var(--color-text-muted); }
.empty svg { width: 44px; height: 44px; opacity: .6; }
.empty .empty-title { font-size: 16px; color: var(--color-text-secondary); }

/* 3.11 进度条（历史覆盖） */
.progress { height: 3px; background: var(--color-surface-2); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--color-accent); box-shadow: var(--glow-accent); }

/* 3.12 区块标题 */
.sec-title { font-size: 19px; font-weight: 600; margin: var(--space-8) 0 var(--space-6); display: flex; align-items: baseline; gap: var(--space-3); }
.sec-title .hint { font-size: 12.5px; color: var(--color-text-muted); font-weight: 400; }

/* ---------- 4. 视图 ---------- */

/* 4.0 顶栏（搜索/设置） */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: var(--space-6); padding: var(--space-5) var(--space-8); background: color-mix(in srgb, var(--color-bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--color-border); }
.brand { display: flex; align-items: center; gap: var(--space-2); font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent); box-shadow: var(--glow-accent); }
.topbar-search { flex: 1; max-width: 640px; margin: 0 auto; display: flex; align-items: center; position: relative; }
.topbar-search .input { padding-right: 48px; }
.btn-search { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--color-text-muted); }
.btn-search:hover { background: var(--color-surface); color: var(--color-accent); }
.btn-search svg { width: 17px; height: 17px; }

/* 4.1 密码门 */
.view-gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-8); }
.gate-card { width: 100%; max-width: 380px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 40px 32px; display: flex; flex-direction: column; gap: var(--space-6); text-align: center; }
.gate-card .brand { justify-content: center; font-size: 22px; }
.gate-card .brand-dot { width: 10px; height: 10px; }
.gate-sub { font-size: 14px; color: var(--color-text-muted); }
.gate-form { display: flex; flex-direction: column; gap: var(--space-4); text-align: left; }

/* 4.2 搜索视图 */
.view-search { padding-bottom: 64px; }
.container { max-width: 1440px; margin: 0 auto; padding: 0 var(--space-8); }
.chips-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.chips-head { display: flex; align-items: center; justify-content: space-between; margin: var(--space-7) 0 var(--space-4); }
.chips-head .sec-label { font-size: 13.5px; color: var(--color-text-muted); }

/* 继续观看条带 */
.hscroll { display: flex; gap: var(--space-6); overflow-x: auto; padding-bottom: var(--space-4); scrollbar-width: thin; }
.hscroll::-webkit-scrollbar { height: 4px; }
.hscroll::-webkit-scrollbar-thumb { background: var(--color-surface-2); border-radius: 2px; }
.hcard { flex: 0 0 132px; }
.hcard .card-cover { aspect-ratio: 3/4; }
.hcard .card-meta { font-size: 11.5px; }

/* 来源 tab */
.tabs { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-6); }
.tab {
  min-height: 44px; padding: 0 var(--space-7); border-radius: var(--radius-pill);
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  font-size: 14px; color: var(--color-text-secondary); transition: background var(--motion-fast), color var(--motion-fast);
}
.tab:hover { color: var(--color-text-primary); }
.tab.is-active { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent); }

/* 结果网格 */
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: var(--space-6); }
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: var(--space-6); }
.skeleton-card { aspect-ratio: 3/4; }
.alert-bar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-6); border-radius: var(--radius-md); font-size: 13.5px; margin-bottom: var(--space-6); }
.alert-warning { background: color-mix(in srgb, var(--color-warning) 12%, transparent); border: 1px solid color-mix(in srgb, var(--color-warning) 40%, transparent); color: var(--color-warning); }
.alert-error { background: var(--color-error-soft); border: 1px solid var(--color-error); color: var(--color-error); }

/* 4.3 播放视图 */
.play-top { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: var(--space-5); padding: var(--space-4) var(--space-8); background: color-mix(in srgb, var(--color-bg-play) 90%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--color-border); }
.play-top .pt-title { font-size: 17px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-wrap { position: relative; width: 100%; aspect-ratio: 16/9; background: var(--color-player-bg); }
.player-wrap .artplayer { width: 100%; height: 100%; }
.play-body { max-width: 960px; margin: 0 auto; padding: var(--space-7) var(--space-8) 64px; }
.resume-bar {
  display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap;
  margin: var(--space-6) 0; padding: var(--space-4) var(--space-6);
  background: var(--color-accent-soft); border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-sm); font-size: 14px;
}
.resume-bar .rb-actions { margin-left: auto; display: flex; gap: var(--space-3); }
/* 选集 */
.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: var(--space-3); flex: 1; min-width: 0; }
.ep {
  min-height: 44px; border-radius: var(--radius-md); background: var(--color-surface-2);
  border: 1px solid var(--color-border); font-size: 14px; color: var(--color-text-secondary);
  transition: background var(--motion-fast), color var(--motion-fast);
}
.ep:hover { color: var(--color-text-primary); border-color: rgba(255,255,255,.3); }
.ep.is-current { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent); }
.ep-nav { display: flex; gap: var(--space-3); align-items: center; }
/* 操作区 */
.actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-7); align-items: center; }
.actions .spacer { flex: 1; }
.cast-btn { background: var(--color-accent-soft); border: 1px solid var(--color-accent); color: var(--color-accent); }
/* 连播倒计时 */
.countdown {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: var(--space-6); padding: var(--space-4) var(--space-7);
  background: var(--color-surface); border: 1px solid var(--color-accent); border-radius: var(--radius-pill);
  box-shadow: var(--glow-accent), var(--shadow-card); font-size: 14px; animation: toastIn var(--motion-base);
}

/* 4.4 设置视图 */
.settings-body { max-width: 960px; margin: 0 auto; padding: var(--space-8); }
.set-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-7); margin-bottom: var(--space-7); }
.set-card h3 { font-size: 16px; margin-bottom: var(--space-5); }
.set-card .sub { font-size: 13px; color: var(--color-text-muted); margin-bottom: var(--space-5); }
.source-row { display: flex; align-items: center; gap: var(--space-5); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.source-row:last-child { border-bottom: none; }
.source-row .src-name { font-weight: 500; }
.source-row .src-api { font-size: 12px; color: var(--color-text-muted); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 2fr auto; gap: var(--space-3); align-items: start; }
.custom-list { margin-top: var(--space-6); }
.custom-item { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-3); border-radius: var(--radius-md); background: var(--color-surface-2); margin-bottom: var(--space-2); }
.custom-item .ci-info { flex: 1; min-width: 0; }
.custom-item .ci-name { font-size: 14px; font-weight: 500; }
.custom-item .ci-api { font-size: 12px; color: var(--color-text-muted); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.about-note { font-size: 13px; color: var(--color-text-muted); }

/* ---------- 5. 响应式（spec 断点） ---------- */
@media (max-width: 767px) {
  .topbar { padding: var(--space-4); gap: var(--space-4); }
  .container { padding: 0 var(--space-4); }
  .result-grid, .skeleton-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
  .card-title { font-size: 14px; }
  .card-meta { font-size: 11.5px; }
  .hcard { flex-basis: 108px; }
  .form-grid { grid-template-columns: 1fr; }
  .player-wrap { aspect-ratio: 16/9; }
  .play-body { padding: var(--space-6) var(--space-4) 64px; }
  .actions .btn { flex: 1 1 calc(50% - var(--space-3)); }
  .ep-grid { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); }
  .resume-bar .rb-actions { width: 100%; }
  .resume-bar .rb-actions .btn { flex: 1; }
  /* S1：ArtPlayer 控制栏移动端 ≥44px 触控目标 */
  .artplayer-controls { height: 44px !important; }
  .artplayer-control .art-icon, .artplayer-controls .art-icon { width: 44px; height: 44px; min-width: 44px; }
}
@media (min-width: 768px) and (max-width: 1079px) {
  .result-grid, .skeleton-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1080px) {
  .result-grid, .skeleton-grid { grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); }
  .play-body { max-width: 960px; }
}
