/* Apple Music Downloader — clean neutral UI, single red accent, auto dark mode */

:root {
  --bg: #f4f4f6;
  --surface: rgba(255, 255, 255, .68);
  --surface-2: rgba(255, 255, 255, .85);
  --surface-solid: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #424245;
  --muted: #86868b;
  --line: rgba(0, 0, 0, .09);
  --line-2: rgba(0, 0, 0, .16);
  --accent: #fa233b;
  --accent-down: #d81e33;
  --ok: #1d8a46;
  --err: #d70015;
  --focus: rgba(10, 110, 220, 0.55);
  --shadow: 0 1px 1px rgba(0,0,0,.03), 0 8px 28px rgba(31,25,45,.07);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0c;
    --surface: rgba(28, 28, 32, .60);
    --surface-2: rgba(44, 44, 50, .70);
    --surface-solid: #1c1c1e;
    --ink: #f5f5f7;
    --ink-2: #d1d1d6;
    --muted: #98989d;
    --line: rgba(255, 255, 255, .10);
    --line-2: rgba(255, 255, 255, .17);
    --accent: #ff453a;
    --accent-down: #e03d33;
    --ok: #30d158;
    --err: #ff453a;
    --focus: rgba(64, 156, 255, 0.6);
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 14px 40px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

/* ---------- ambient background: elegant square grid ---------- */

:root {
  --grid-line: rgba(29, 29, 31, .055);
  --glow-1: rgba(250, 35, 59, .10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --grid-line: rgba(255, 255, 255, .05);
    --glow-1: rgba(255, 69, 58, .13);
  }
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg);
}

/* square grid, fading out from the top */
.bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 42px 42px;
  -webkit-mask-image: radial-gradient(120% 85% at 50% -5%, #000 25%, transparent 78%);
  mask-image: radial-gradient(120% 85% at 50% -5%, #000 25%, transparent 78%);
}

/* soft accent glow behind the hero */
.bg::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -22vh;
  width: 90vw;
  height: 55vh;
  transform: translateX(-50%);
  background: radial-gradient(48% 60% at 50% 40%, var(--glow-1), transparent 70%);
  filter: blur(40px);
}

html { background: var(--bg); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
input { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 13.5px; font-weight: 600; letter-spacing: -.01em; }
.brand-text small {
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ---------- Layout ---------- */

.main {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 20px 56px;
}

.hero h1 {
  font-size: 38px;
  font-weight: 750;
  letter-spacing: -.035em;
  line-height: 1.06;
}

.hero h1 .dot { color: var(--accent); }

.hero p {
  margin-top: 8px;
  font-size: 15px;
  color: var(--muted);
  max-width: 52ch;
}

/* ---------- Format + search ---------- */

.controls { margin-top: 32px; }

.format {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border-radius: 10px;
}

.format button {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 6px 18px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--ink-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
  transition: background .15s ease, box-shadow .15s ease;
}

.format button span {
  display: block;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}

.format button.on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.format button.on span { color: var(--muted); }

.format-info {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  background: var(--surface);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  max-width: 640px;
}

.format-info b { color: var(--ink); font-weight: 600; }
.format-info .size { display: block; margin-top: 4px; color: var(--ink-2); }

/* ---------- lyric search toggle ---------- */

.lyrics-toggle {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}

.lyrics-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-box {
  width: 34px;
  height: 20px;
  border-radius: 100px;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
  position: relative;
  flex-shrink: 0;
  transition: background .15s ease;
}

.toggle-box::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .15s ease;
}

.lyrics-toggle input:checked ~ .toggle-box { background: var(--accent); }
.lyrics-toggle input:checked ~ .toggle-box::after { transform: translateX(14px); }

.lyrics-toggle input:focus-visible ~ .toggle-box {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.lyrics-toggle span:nth-of-type(2) { font-weight: 500; }
.lyrics-toggle small { color: var(--muted); font-size: 12px; }

.search {
  margin-top: 14px;
  display: flex;
  gap: 10px;
}

.search-field {
  position: relative;
  flex: 1;
}

.search-field svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-field input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--surface-solid);
  padding: 0 16px 0 40px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  -webkit-appearance: none;
  appearance: none;
}

@media (prefers-color-scheme: dark) {
  .search-field input { background: rgba(28, 28, 32, .75); }
}

.search-field input::placeholder { color: var(--muted); }

.search-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 22%, transparent);
}

.search-field input::-webkit-search-cancel-button { -webkit-appearance: none; }

.btn-primary {
  height: 48px;
  padding: 0 26px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease;
}

.btn-primary:hover { background: var(--accent-down); }
.btn-primary:active { transform: scale(.985); }
.btn-primary[disabled] { opacity: .55; cursor: default; }

.quick {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quick > span { font-size: 12.5px; color: var(--muted); }

.quick button {
  appearance: none;
  border: 1px solid var(--line-2);
  background: transparent;
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}

.quick button:hover { background: var(--surface); border-color: var(--muted); }

/* ---------- Results ---------- */

.results { margin-top: 44px; }

.results-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  min-height: 32px;
}

.results-head h2 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.results-head small { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }

.tabs {
  display: inline-flex;
  gap: 2px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border-radius: 9px;
  padding: 2px;
}

.tabs button {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.tabs button.on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

.rows { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 10px 10px;
  box-shadow: var(--shadow);
  transition: border-color .15s ease, transform .18s ease, box-shadow .18s ease;
}

.row:hover {
  border-color: var(--line-2);
  transform: translateY(-1.5px);
  box-shadow: 0 2px 4px rgba(0,0,0,.04), 0 16px 40px rgba(31,25,45,.11);
}

.art {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--line);
}

.art img { width: 100%; height: 100%; object-fit: cover; display: block; }

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

.row-title {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-badges {
  margin-top: 5px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.badge {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  padding: 1px 6px;
}

.badge.kind { color: var(--ink-2); }

.row-side {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 118px;
}

.btn-dl {
  height: 36px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease;
  white-space: nowrap;
}

.btn-dl:hover:not([disabled]) { background: var(--accent-down); }
.btn-dl[disabled] { opacity: .55; cursor: default; }

.btn-dl.busy {
  position: relative;
  color: transparent !important;
}

.btn-dl.busy::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}

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

/* ---------- download dialog ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--ink) 32%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.dialog {
  position: relative;
  width: min(100%, 420px);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 24px 80px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.08);
}

.dlg-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.dlg-close:hover { background: color-mix(in srgb, var(--ink) 14%, transparent); color: var(--ink); }

.dlg-head {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.dlg-art { width: 84px; height: 84px; }

.dlg-head-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.dlg-head-info b {
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -.01em;
  line-height: 1.25;
  max-height: 2.6em;
  overflow: hidden;
}
.dlg-head-info small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.dlg-body { margin-top: 22px; }

.bar {
  height: 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  overflow: hidden;
}

.bar > div {
  height: 100%;
  width: 30%;
  border-radius: 3px;
  background: var(--accent);
  animation: slide 1.2s ease-in-out infinite;
}

.bar.done > div { width: 100%; animation: none; transition: width .3s ease; }
.bar.err > div { animation: none; width: 100%; background: color-mix(in srgb, var(--err) 45%, transparent); }

@keyframes slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(380%); }
}

.dlg-status { margin-top: 12px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.dlg-status.ok { color: var(--ok); }
.dlg-status.err { color: var(--err); }

.dlg-note { margin-top: 6px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }

.dlg-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary.dlg-btn { height: 42px; padding: 0 22px; font-size: 14px; }

/* ---------- States ---------- */

.state {
  background: var(--surface);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.state b { color: var(--ink); font-weight: 600; }

.state kbd {
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  background: var(--surface-2);
  color: var(--ink-2);
}

.state .retry {
  display: inline-block;
  margin-top: 12px;
  border: 1px solid var(--line-2);
  background: transparent;
  border-radius: 9px;
  padding: 7px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.state .retry:hover { background: var(--surface-2); }

.skeleton {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 10px 10px;
}

.sk-art {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  flex-shrink: 0;
}

.sk-lines { flex: 1; }

.sk-line { height: 12px; border-radius: 6px; }
.sk-line.w1 { width: 55%; margin-bottom: 9px; }
.sk-line.w2 { width: 80%; }

.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 2px 2px;
}

.sk-art, .sk-line {
  background: linear-gradient(
    100deg,
    color-mix(in srgb, var(--ink) 7%, transparent) 40%,
    color-mix(in srgb, var(--ink) 12%, transparent) 50%,
    color-mix(in srgb, var(--ink) 7%, transparent) 60%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 130% 0; }
  100% { background-position: -70% 0; }
}

/* ---------- Footer / toast ---------- */

.foot {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 100px;
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
  max-width: 92vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 50;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */

@media (max-width: 620px) {
  .main { padding: 28px 16px 44px; }
  .hero h1 { font-size: 27px; }
  .search { flex-direction: column; }
  .btn-primary { width: 100%; }
  .format { display: flex; width: 100%; }
  .format button { flex: 1; }
  .row { flex-wrap: wrap; }
  .row-info { flex: 1 1 calc(100% - 74px); }
  .row-side { flex: 1 1 100%; flex-direction: row; align-items: center; }
  .btn-dl { flex: 1; }
  .tabs button { padding: 5px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
