/* ========== AISong 深色现代音乐风 ========== */

:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --card-2: #21252e;
  --border: #2a2e38;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #8b5cf6;
  --accent-2: #ec4899;
  --grad: linear-gradient(135deg, #8b5cf6, #ec4899);
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin: 8px 0 20px;
}

.num { font-variant-numeric: tabular-nums; }

/* ---------- 导航 ---------- */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-decoration: none;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  flex-shrink: 0;
  line-height: 56px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  transition: color .15s, background .15s;
}

.nav-links a:hover { color: var(--text); background: var(--card-2); }

.nav-links a.active {
  color: var(--text);
  background: var(--card-2);
  font-weight: 600;
}

/* ---------- 按钮体系 ----------
   三类:主按钮 .btn-primary(渐变填充,每页最多一个主操作)
        次按钮 .btn-ghost(描边)
        危险按钮 .btn-danger(红色描边)
   统一 40px 高度 / 12px 圆角 / 6px 图标文字间距 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: filter .15s, transform .1s, background .15s, border-color .15s;
  user-select: none;
}

.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.98); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover { border-color: #3a3f4d; }

.btn-danger {
  background: transparent;
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--err);
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.12); }

.btn-link {
  background: none;
  border-color: transparent;
  color: var(--accent);
  padding: 0 8px;
}

.btn-sm {
  min-height: 40px;
  padding: 0 14px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-lg {
  min-height: 48px;
  padding: 0 28px;
  font-size: 15px;
}

.btn-block { width: 100%; }

.btn.loading { pointer-events: none; opacity: 0.7; }

.btn.loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn-ghost.loading::after, .btn-link.loading::after, .btn-danger.loading::after {
  border-color: rgba(139, 92, 246, 0.3);
  border-top-color: var(--accent);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast 轻提示 ---------- */

#toast-root {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 80vw;
  word-break: break-word;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .25s, transform .25s;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { border-color: rgba(52, 211, 153, 0.5); color: var(--ok); }
.toast-err { border-color: rgba(248, 113, 113, 0.5); color: var(--err); }

/* ---------- 表单 ---------- */

.field {
  display: block;
  margin-bottom: 16px;
  position: relative;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-hint {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.field-stat {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

.input::placeholder { color: #565d6b; }

textarea.input { resize: vertical; }

select.input {
  appearance: none;
  cursor: pointer;
}

.lyrics-input {
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  min-height: 320px;
}

.theme-input { font-size: 15px; }

/* ---------- 卡片 / 通用 ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.error-box {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--err);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin: 12px 0;
  word-break: break-word;
}

.loading-line, .empty-line {
  color: var(--muted);
  font-size: 14px;
  padding: 18px 4px;
  text-align: center;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-ok { background: rgba(52, 211, 153, 0.14); color: var(--ok); }
.badge-warn { background: rgba(251, 191, 36, 0.14); color: var(--warn); }
.badge-err { background: rgba(248, 113, 113, 0.14); color: var(--err); }

.text-ok { color: var(--ok); }
.text-err { color: var(--err); }

.tag {
  display: inline-block;
  background: rgba(139, 92, 246, 0.14);
  color: #c4b5fd;
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 12px;
  word-break: break-word;
}

audio {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  outline: none;
}

audio::-webkit-media-controls-panel { background: var(--card-2); }

/* ---------- 登录页 ---------- */

.auth-page {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 36px 32px;
}

.auth-brand { text-align: center; margin-bottom: 24px; }

.auth-logo {
  font-size: 34px;
  font-weight: 800;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.auth-slogan {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 0;
}

.auth-tabs { margin-bottom: 20px; }

/* ---------- Tabs ---------- */

.tabs {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 7px 16px;
  min-height: 36px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
}

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

.tab.active {
  background: var(--card-2);
  color: var(--text);
  font-weight: 600;
}

/* ---------- 向导 ---------- */

.steps {
  display: flex;
  align-items: center;
  margin-bottom: 28px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: all .2s;
}

.step-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.step.active .step-dot {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.45);
}

.step.active .step-label { color: var(--text); font-weight: 600; }

.step.done { cursor: pointer; }

.step.done .step-dot {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.step.done:hover .step-dot { background: rgba(139, 92, 246, 0.3); }

.step-line {
  flex: 1;
  min-width: 16px;
  height: 1px;
  background: var(--border);
  margin: 0 8px 22px;
}

.step-line.done { background: var(--accent); }

.wizard-body { min-height: 200px; }

.step-card { margin-bottom: 20px; }

.step-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 8px;
}

.step-desc {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 18px;
}

.step-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.wizard-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

/* chips */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 4px;
}

.chip {
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 14px;
  min-height: 32px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* tips 卡片 */

.tips-card {
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 16px 0;
}

.tips-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  color: #c4b5fd;
}

.tips-body {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* AI 改写小工具 */

.rewrite-tool {
  display: flex;
  gap: 8px;
  margin: -8px 0 16px;
}

.rewrite-tool .input { flex: 1; min-width: 0; }
.rewrite-tool .btn { flex-shrink: 0; align-self: center; }

/* ---------- 参考歌曲 ---------- */

.ref-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.ref-search { max-width: 260px; }

.ref-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ref-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.ref-card:hover { border-color: #3a3f4d; }

.ref-card.selected {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.08);
}

.ref-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.ref-card.selected .ref-check {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
}

.ref-main { min-width: 0; max-width: 100%; }

.ref-title {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.ref-artist {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.ref-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.ref-bpm { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ref-structure { word-break: break-word; }

.ref-note { color: var(--muted); word-break: break-word; }

/* 旋律参考 */

.melody-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.melody-form .btn { align-self: flex-end; }

.melody-or {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.melody-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.melody-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  flex-wrap: wrap;
}

.melody-use {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  min-height: 40px;
}

.melody-use input { accent-color: var(--accent); }

.melody-body { flex: 1; min-width: 220px; }

.melody-link {
  color: var(--accent);
  font-size: 13px;
  word-break: break-all;
}

.melody-note { color: var(--muted); font-size: 12px; margin-top: 4px; word-break: break-word; }

/* ---------- 生成 ---------- */

.confirm-grid { margin: 8px 0 4px; }

.confirm-row {
  display: flex;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.confirm-row:last-child { border-bottom: none; }

.confirm-label {
  width: 90px;
  flex-shrink: 0;
  color: var(--muted);
}

.confirm-value {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.confirm-lyrics { flex: 1; min-width: 0; }

.confirm-lyrics summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
}

.confirm-lyrics pre {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

.gen-progress { text-align: center; padding: 48px 24px; }

.progress-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 24px 0 16px;
}

.progress-fill {
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: var(--grad);
  animation: slide 1.4s ease-in-out infinite;
}

@keyframes slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

.clip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.clip-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.clip-cover {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
}

.clip-cover-empty {
  background: var(--grad);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: rgba(255, 255, 255, 0.85);
}

.clip-title {
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 完成页 ---------- */

.done-card { text-align: center; }

.done-cover { display: flex; justify-content: center; margin: 16px 0; }

.cover {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: var(--grad);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-lg { max-width: 280px; }

.cover-placeholder {
  font-size: 56px;
  color: rgba(255, 255, 255, 0.85);
}

.cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.done-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
  word-break: break-word;
}

.done-audio { max-width: 480px; margin: 0 auto; }

.done-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.done-downloads { margin-top: 22px; }

.cover-regen {
  max-width: 480px;
  margin: 14px auto 0;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.cover-regen .input { flex: 1; min-width: 200px; }
.cover-regen .error-box { width: 100%; margin: 4px 0 0; }

/* ---------- 作品库 ---------- */

.song-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.song-card {
  padding: 14px;
  cursor: pointer;
  transition: border-color .15s;
}

.song-card:hover { border-color: #3a3f4d; }

.song-card .cover { margin-bottom: 12px; }
.song-card .cover-placeholder { font-size: 40px; }

.song-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.song-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-detail {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: default;
}

.song-lyrics summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
}

.song-lyrics pre {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

.song-prompt {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 4px;
  word-break: break-word;
}

.song-actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.song-actions .song-del { margin-left: auto; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}

.empty-icon {
  font-size: 56px;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  margin-bottom: 12px;
}

.empty-state p { margin: 0 0 20px; font-size: 15px; }

/* ---------- 参考库管理表单 ---------- */

.ref-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.ref-form-wide { grid-column: 1 / -1; }

.ref-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.ref-form-actions .error-box { margin: 0; flex: 1; }

/* ---------- 个人中心 ---------- */

.account-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.account-info { flex: 1; min-width: 0; }

.account-name {
  font-size: 17px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-sub {
  color: var(--muted);
  font-size: 13px;
}

.setting-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

.setting-label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 2px;
}

.setting-value {
  font-size: 15px;
  font-weight: 600;
  word-break: break-word;
}

.setting-hint {
  color: var(--muted);
  font-size: 12px;
  max-width: 420px;
  text-align: right;
}

.settings-list {
  display: flex;
  flex-direction: column;
}

/* ---------- 移动端 ---------- */

@media (max-width: 640px) {
  .card { padding: 18px; }
  .clip-grid { grid-template-columns: 1fr; }
  .ref-form { grid-template-columns: 1fr; }
  .ref-toolbar { flex-direction: column; align-items: stretch; }
  .ref-search { max-width: none; }
  .tabs { align-self: flex-start; }
  .setting-row { flex-direction: column; gap: 4px; }
  .setting-hint { text-align: left; }
  .step-label { display: none; }
  .nav-links a { padding: 8px 10px; font-size: 13px; }
  .confirm-row { flex-direction: column; gap: 4px; }
  .confirm-label { width: auto; }
  .ref-title, .ref-artist { max-width: 200px; }
  /* 防 iOS 聚焦自动缩放 */
  .input { font-size: 16px; }
  .lyrics-input { font-size: 14px; }
}
