/* TuneMover 樣式 */

:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --surface-2: #282828;
  --border: #333;
  --text: #eaeaea;
  --text-muted: #9a9a9a;
  --accent: #1db954;
  --accent-hover: #1ed760;
  --danger: #e2504c;
  --radius: 10px;
  --font: system-ui, -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

/* ── 亮色主題 ── */
:root[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #eaeaea;
  --border: #d0d0d0;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #16a34a;
  --accent-hover: #15803d;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.9em; }

/* ── 頂欄 ── */
.topbar {
  background: linear-gradient(180deg, #0a3d24 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 32px 16px 24px;
}
:root[data-theme="light"] .topbar {
  background: linear-gradient(180deg, #d4edda 0%, var(--bg) 100%);
}
.topbar-inner { max-width: 860px; margin: 0 auto; }
.logo { margin: 0; font-size: 2rem; letter-spacing: 0.5px; }
.tagline { margin: 4px 0 16px; color: var(--text-muted); }

/* ── 按鈕 ── */
.btn {
  font-family: var(--font);
  font-size: 0.95rem;
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  display: inline-block;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #062b14; font-weight: 700; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); }
.btn-secondary:hover:not(:disabled) { filter: brightness(0.92); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(220, 38, 38, 0.12); }
.btn-lg { font-size: 1.05rem; padding: 12px 32px; }

/* ── 提示橫幅 ── */
.banner {
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 0.95rem;
}
.banner-warn {
  background: #3d3320;
  border: 1px solid #8a7430;
  color: #f0dfa8;
}
:root[data-theme="light"] .banner-warn {
  background: #fef9e7;
  border-color: #f0d060;
  color: #6b5900;
}
.banner-warn code { background: rgba(0,0,0,0.3); padding: 1px 6px; border-radius: 4px; }
.banner-warn a { color: #ffd97a; }
:root[data-theme="light"] .banner-warn a { color: #8a6d00; }
.banner-error {
  background: #3d2020;
  border: 1px solid #a04040;
  color: #ffb4b0;
}
:root[data-theme="light"] .banner-error {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

/* ── 輸入卡片 ── */
.input-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 16px 0;
}
.resolve-form { display: flex; gap: 10px; }
#url-input {
  flex: 1;
  font-size: 1rem;
  font-family: var(--font);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
#url-input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ── 歌手+歌名 快速定位卡 ── */
.quick-card { margin-top: 0; }
.quick-title {
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 0.95rem;
}
.quick-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.quick-form input {
  flex: 1;
  min-width: 120px;
  font-size: 0.95rem;
  font-family: var(--font);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.quick-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.quick-result { margin-top: 10px; }
.quick-result-text {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.5;
}
.quick-result-text a { color: var(--accent); }
.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 40px 0;
  color: var(--text-muted);
}
.spinner {
  width: 20px; height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 曲目清單 ── */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 20px 0 8px;
}
.list-header h2 { margin: 0; font-size: 1.25rem; }
.list-actions { display: flex; align-items: center; gap: 12px; }
.select-all { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }

.track-list {
  list-style: none;
  margin: 0; padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.track-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.track-row:last-child { border-bottom: none; }
.track-row.selected { background: rgba(29, 185, 84, 0.08); }

.track-index { color: var(--text-muted); min-width: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.track-thumb {
  width: 44px; height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}
.track-main { flex: 1; min-width: 0; }
.track-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-sub { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-duration { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* 進度面板用的狀態欄 */
.track-status { min-width: 130px; text-align: right; font-size: 0.88rem; }
.track-status.done { color: var(--accent); }
.track-status.failed, .track-status.no-match { color: var(--danger); }
.track-status.cancelled { color: var(--text-muted); }
.track-status .msg { display: block; color: var(--text-muted); font-size: 0.78rem; max-width: 200px; margin-left: auto; }

.mini-bar {
  width: 90px; height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}
.mini-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.3s; border-radius: 3px; }

.file-link { color: var(--accent); font-size: 0.85rem; text-decoration: none; }
.file-link:hover { text-decoration: underline; }

/* ── 下載列 ── */
.download-bar {
  display: flex;
  justify-content: center;
  padding: 20px 0 8px;
}

/* ── 進度總覽 ── */
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0 8px;
}
.progress-header h2 { margin: 0; font-size: 1.25rem; }
.progress-actions { display: flex; gap: 8px; }
.overall { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.overall-bar {
  flex: 1; height: 10px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
}
.overall-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  transition: width 0.4s;
  border-radius: 5px;
}

/* ── 空狀態 ── */
.empty { text-align: center; padding: 48px 0; font-size: 1.1rem; }

/* ── 來源標示(Spotify 試聽檔)── */
.badge-sp {
  display: inline-block;
  background: rgba(29, 185, 84, 0.2);
  color: var(--accent);
  border: 1px solid var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 4px;
  padding: 0 6px;
  margin-right: 6px;
  vertical-align: middle;
}

/* 原曲已驗證(來源驗證層)*/
.badge-orig {
  display: inline-block;
  background: rgba(29, 185, 84, 0.12);
  color: var(--accent);
  border: 1px solid rgba(29, 185, 84, 0.5);
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 4px;
  padding: 0 6px;
  margin-right: 6px;
  vertical-align: middle;
}

/* ── 歌單庫 / 歌單詳細 ── */
.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 0 0;
}
#theme-toggle { margin-right: 4px; }

/* 歌單庫清單行 */
.lib-row { flex-wrap: wrap; }
.lib-actions { display: flex; gap: 8px; margin-left: auto; }
.lib-actions .btn { padding: 6px 14px; font-size: 0.85rem; }

/* 歌單詳細 */
.pd-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 4px 0 12px;
}
.pd-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.pd-row { flex-wrap: wrap; row-gap: 8px; }
.pd-check {
  width: 16px; height: 16px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.pd-check:disabled { cursor: not-allowed; opacity: 0.4; }
.pd-state {
  min-width: 88px;
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.pd-state.done { color: var(--accent); }
.pd-state.warn { color: var(--danger); }
.pd-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  padding-left: 34px;
}
.pd-row-actions .btn,
.pd-row-actions .pd-file { padding: 6px 14px; font-size: 0.82rem; }
.pd-src {
  flex: 1;
  min-width: 200px;
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.pd-src:focus { outline: 2px solid var(--accent); border-color: transparent; }
.pd-file {
  display: inline-block;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border-radius: 999px;
}
.pd-audio {
  width: 100%;
  margin-top: 16px;
  height: 40px;
}

/* ── YouTube 小視窗預覽 ── */
.yt-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.yt-preview-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 360px;
  max-width: 92vw;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.yt-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.yt-preview-title { font-weight: 600; font-size: 0.95rem; }
.yt-preview-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.yt-preview-close:hover { color: var(--text); }
.yt-preview-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  display: block;
  background: #000;
}
.yt-preview-media { position: relative; }
.yt-preview-meta {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.5;
}
.yt-preview-fallback {
  padding: 16px 14px;
  background: var(--surface-2);
}
.yt-fb-msg { margin: 0 0 6px; font-weight: 600; font-size: 0.9rem; }
.yt-fb-sub { margin: 0; font-size: 0.82rem; }
.yt-preview-foot {
  padding: 8px 14px;
  display: flex;
  justify-content: flex-end;
}
.yt-preview-open {
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
}
.yt-preview-open:hover { text-decoration: underline; }

/* ── 設定頁 ── */
.settings-card,
.env-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.settings-group { display: flex; flex-direction: column; gap: 14px; }
.setting-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.setting-label { min-width: 200px; font-weight: 600; }
.setting-label small { display: block; font-weight: 400; color: var(--text-muted); font-size: 0.78rem; }
.setting-row select,
.setting-row input {
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  min-width: 240px;
}
.setting-row input[type='number'] { min-width: 90px; }
.setting-note { margin-left: auto; font-size: 0.8rem; }
.settings-actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; }

/* ── AI 設定區塊 ── */
.ai-group {
  padding: 16px;
  margin-top: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.ai-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.ai-group-header h3 { margin: 0; font-size: 1rem; }
.ai-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
}
.ai-desc {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}
.ai-key-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 240px; }
.ai-key-row input { flex: 1; }
.ai-model-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 240px; }
.ai-model-row input { flex: 1; }
.ai-models-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.ai-model-btn { padding: 5px 12px; font-size: 0.8rem; }
.ai-status {
  margin-top: 10px;
  font-size: 0.85rem;
  line-height: 1.5;
}
.btn-sm { padding: 6px 14px; font-size: 0.82rem; }

.env-box h3 { margin: 0 0 10px; font-size: 1.05rem; }
.env-detail {
  margin: 0 0 14px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}
.env-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.env-ready { font-weight: 600; }
.env-ready.ok { color: var(--accent); }
.env-ready.warn { color: var(--danger); }

/* ── 頁尾 ── */
.footer {
  text-align: center;
  padding: 24px 16px 32px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

/* ── RWD ── */
@media (max-width: 560px) {
  .resolve-form { flex-direction: column; }
  .track-status { min-width: 90px; }
  .mini-bar { width: 60px; }
  .logo { font-size: 1.5rem; }
}
