/* ==================================================================
   Suno 歌曲下载器 — 样式表
   ================================================================== */

:root {
  --bg: oklch(99% 0.004 275);
  --surface: #ffffff;
  --ink: oklch(20% 0.035 275);
  --muted: oklch(52% 0.03 275);
  --line: oklch(91% 0.015 275);
  --field: oklch(97.5% 0.006 275);
  --purple: oklch(58% 0.24 285);
  --purple-dark: oklch(48% 0.23 282);
  --purple-soft: oklch(95% 0.03 285);
  --green: oklch(58% 0.15 150);
  --red: oklch(58% 0.2 25);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20, 18, 40, 0.06);
  --shadow-md: 0 8px 28px rgba(20, 18, 40, 0.09);
  --shadow-lg: 0 20px 60px rgba(20, 18, 40, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  /* 阿拉伯语字形与拉丁 / 中文不同，单独一套字体栈 */
  --font-ar: "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma,
    "Geeza Pro", "Arabic Typesetting", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 阿拉伯语（RTL） ---------- */
/* 布局方向不在这里硬编码：全站使用逻辑属性（inline-start/end），
   切换 <html dir="rtl"> 后浏览器会自动镜像。这里只处理字体与行高。 */

html[lang="ar"] body {
  font-family: var(--font-ar);
  /* 阿拉伯语的升部/降部更高，行高需要放宽，否则标点容易被裁切 */
  line-height: 1.85;
}

html[lang="ar"] .song-title,
html[lang="ar"] h1,
html[lang="ar"] .info-block h2,
html[lang="ar"] .playlist-title {
  /* 阿拉伯语没有"字重加粗"的传统，但现代字体支持，略微收敛一点更协调 */
  letter-spacing: 0;
}

/* 列表序号在 RTL 下由 start 侧自然镜像 */
html[dir="rtl"] .playlist-index {
  font-variant-numeric: normal;
}

a {
  color: var(--purple-dark);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-size: 0.88em;
  background: var(--purple-soft);
  color: var(--purple-dark);
  padding: 1px 6px;
  border-radius: 5px;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 700;
  font-size: 17px;
}
.brand:hover {
  text-decoration: none;
}

.brand-mark {
  font-size: 20px;
  line-height: 1;
}

.topnav {
  display: flex;
  gap: 20px;
  font-size: 14px;
}
.topnav a {
  color: var(--muted);
  font-weight: 500;
}
.topnav a:hover {
  color: var(--purple-dark);
  text-decoration: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
}

/* ---------- 语言切换器 ---------- */

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.lang-switch button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  padding: 7px 12px;
  border-radius: 999px;
  transition: background 0.16s, color 0.16s, box-shadow 0.16s;
  white-space: nowrap;
}

.lang-switch button:hover:not(.active) {
  color: var(--purple-dark);
  background: var(--purple-soft);
}

.lang-switch button.active {
  color: #fff;
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
  box-shadow: 0 2px 8px oklch(58% 0.24 285 / 0.3);
}

.lang-switch button:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

/* ---------- 主区域 ---------- */

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 44px 20px 80px;
}

.hero {
  text-align: center;
}

h1 {
  font-size: clamp(26px, 4.4vw, 38px);
  line-height: 1.22;
  margin: 0 0 12px;
  letter-spacing: -0.02em;
  font-weight: 800;
}

.subtitle {
  color: var(--muted);
  font-size: 16px;
  max-width: 620px;
  margin: 0 auto 34px;
}

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

#form {
  text-align: start;
  max-width: 640px;
  margin: 0 auto;
}

#form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}

.query {
  display: flex;
  gap: 10px;
}

#songId {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
#songId::placeholder {
  color: oklch(66% 0.02 275);
}
#songId:focus {
  border-color: var(--purple);
  background: #fff;
  box-shadow: 0 0 0 4px oklch(58% 0.24 285 / 0.13);
}

button {
  font-family: inherit;
  cursor: pointer;
}

.primary {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 14px oklch(58% 0.24 285 / 0.32);
  transition: transform 0.16s, box-shadow 0.16s, opacity 0.16s;
}
.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 7px 22px oklch(58% 0.24 285 / 0.4);
}
.primary:active:not(:disabled) {
  transform: translateY(0);
}
.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-icon {
  margin-inline-end: 2px;
}

.playlist-hint {
  margin: 14px 2px 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
}
.playlist-hint strong {
  color: var(--purple-dark);
  margin-inline-end: 8px;
}

/* ---------- 状态提示 ---------- */

.status {
  min-height: 22px;
  margin: 20px auto 6px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  transition: color 0.2s;
  /* 服务端返回的排障提示是多行的，保留换行以便阅读 */
  white-space: pre-line;
  line-height: 1.65;
}
.status.error {
  color: var(--red);
  font-weight: 500;
}
.status:empty {
  display: none;
}

/* ---------- 歌曲卡片 ---------- */

.song-card {
  display: flex;
  gap: 22px;
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 22px;
  box-shadow: var(--shadow-md);
  transition: opacity 0.25s, box-shadow 0.25s;
}

.song-card.hidden {
  display: none;
}

.cover {
  width: 132px;
  height: 132px;
  flex: 0 0 132px;
  border-radius: 11px;
  object-fit: cover;
  background: linear-gradient(135deg, oklch(94% 0.03 285), oklch(90% 0.05 300));
  box-shadow: var(--shadow-sm);
}

.details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.song-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 8px;
  line-height: 1.35;
  word-break: break-word;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.metadata {
  font-size: 13.5px;
  color: var(--muted);
  margin: 0 0 18px;
}

.success {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  background: oklch(96% 0.04 150);
  padding: 3px 9px;
  border-radius: 20px;
}

.downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  transition: all 0.16s;
  text-decoration: none;
}
.download:hover:not(:disabled) {
  border-color: var(--purple);
  color: var(--purple-dark);
  background: var(--purple-soft);
  text-decoration: none;
}
.download:disabled {
  opacity: 0.55;
  cursor: wait;
}

.download.primary {
  color: #fff;
  border-color: transparent;
  /* 必须显式声明 background：.download 的浅色背景与 .primary 同优先级，
     且在源码中更靠后，否则会覆盖掉紫色渐变 */
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
  box-shadow: 0 4px 14px oklch(58% 0.24 285 / 0.28);
}
.download.primary:hover:not(:disabled) {
  color: #fff;
  background: linear-gradient(135deg, var(--purple-dark), var(--purple-dark));
}

.download-icon {
  font-size: 15px;
  line-height: 1;
}

/* 占位状态 */
.song-placeholder {
  opacity: 0.72;
  box-shadow: none;
}
.song-placeholder.is-loading {
  opacity: 1;
}
.song-placeholder.is-loading .cover {
  animation: pulse 1.4s ease-in-out infinite;
}
.placeholder-title,
.placeholder-meta {
  color: oklch(70% 0.02 275);
}
.placeholder-download {
  opacity: 0.6;
  cursor: not-allowed;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.private-note {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}

/* ---------- 歌单面板 ---------- */

.playlist-panel {
  margin-top: 22px;
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-md);
}
.playlist-panel.hidden {
  display: none;
}

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

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

.playlist-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.playlist-actions .download {
  padding: 8px 13px;
  font-size: 13px;
}

.playlist-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 420px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.playlist-item:last-child {
  border-bottom: none;
}

.playlist-index {
  flex: 0 0 26px;
  font-size: 12px;
  color: var(--muted);
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.playlist-thumb {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--field);
}

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

.playlist-song-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-song-meta {
  font-size: 12px;
  color: var(--muted);
  margin: 1px 0 0;
}

.playlist-item .download {
  padding: 6px 11px;
  font-size: 12px;
}

/* ---------- 转换说明 ---------- */

.convert-note {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.convert-note.hidden {
  display: none;
}

/* ---------- 信息区块 ---------- */

.info-block {
  margin-top: 56px;
  padding-top: 34px;
  border-top: 1px solid var(--line);
  text-align: start;
}
.info-block h2 {
  font-size: 21px;
  font-weight: 700;
  margin: 0 0 18px;
}

.steps {
  margin: 0;
  padding-inline-start: 22px;
  color: var(--ink);
}
.steps li {
  margin-bottom: 12px;
  padding-inline-start: 4px;
}
.steps strong {
  color: var(--purple-dark);
}

.tip {
  margin-top: 18px;
  font-size: 13.5px;
  color: var(--muted);
  background: var(--purple-soft);
  /* 逻辑属性：RTL 下竖线自动跑到右侧，圆角也随之镜像 */
  border-inline-start: 3px solid var(--purple);
  border-start-start-radius: 0;
  border-end-start-radius: 0;
  border-start-end-radius: 8px;
  border-end-end-radius: 8px;
  padding: 12px 16px;
}

details {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 10px;
  background: var(--surface);
  transition: border-color 0.18s;
}
details[open] {
  border-color: oklch(85% 0.05 285);
}
details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
details summary::-webkit-details-marker {
  display: none;
}
details summary::after {
  content: "+";
  color: var(--muted);
  font-weight: 400;
  font-size: 19px;
  transition: transform 0.2s;
}
details[open] summary::after {
  content: "−";
}
details p {
  margin: 12px 0 2px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.7;
}

/* ---------- 广告位 ----------
   容器默认 hidden，只有 /api/config 说启用广告、且配置了对应 slot 时
   才由 ads.js 取消隐藏。因此未启用广告时页面上不会留下任何空白块。 */

.ad-slot {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px;
}

.ad-slot-top {
  padding-top: 22px;
}

.ad-slot-bottom {
  padding-bottom: 26px;
}

/* 占位预览：AdSense 审核通过前广告位是空白的，用虚线框把位置标出来 */
.ad-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  padding: 14px;
  border: 1.5px dashed oklch(80% 0.06 285);
  border-radius: var(--radius-sm);
  background: oklch(97.5% 0.015 285 / 0.7);
  color: var(--purple-dark);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- 页脚 ---------- */

.footer {
  border-top: 1px solid var(--line);
  padding: 26px 20px 34px;
  text-align: center;
}
.footer p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  max-width: 620px;
  margin: 0 auto;
}

/* ---------- 响应式 ---------- */

@media (max-width: 640px) {
  .page {
    padding: 30px 16px 60px;
  }
  /* 广告位左右留白与 .page 对齐 */
  .ad-slot {
    padding: 0 16px;
  }
  .ad-slot-top {
    padding-top: 16px;
  }
  .query {
    flex-direction: column;
  }
  .primary {
    width: 100%;
  }
  .song-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px 18px;
  }
  .cover {
    width: 168px;
    height: 168px;
    flex-basis: 168px;
  }
  .song-title {
    justify-content: center;
  }
  .downloads {
    justify-content: center;
  }
  .playlist-item .download span.download-text {
    display: none;
  }
  .topnav {
    display: none;
  }
  /* 语言切换器在小屏上保留（否则无法切语言），只是收紧内边距 */
  .topbar-inner {
    padding: 10px 14px;
  }
  .lang-switch button {
    padding: 6px 9px;
    font-size: 12px;
  }
  .brand-text {
    font-size: 15px;
  }
}
