:root {
  --bg: #0b0f1a; --bg-2: #0f1526; --panel: #131a2b; --panel-2: #1b2338;
  --ink: #eef2ff; --muted: #8b95b3; --line: #273149;
  --accent: #a78bfa; --accent-2: #f472b6; --accent-3: #22d3ee;
  --grad: linear-gradient(135deg, #8b5cf6 0%, #ec4899 55%, #f97316 100%);
  --grad-soft: linear-gradient(135deg, rgba(139,92,246,.25), rgba(236,72,153,.18) 60%, rgba(249,115,22,.12));
  --ok: #34d399; --bad: #fb7185; --warn: #fbbf24;
  --radius: 16px; --shadow: 0 10px 30px rgba(0,0,0,.35);
  --font-head: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font-body); }
body { min-height: 100vh; background-image: radial-gradient(1200px 600px at 10% -10%, rgba(139,92,246,.18), transparent 60%), radial-gradient(900px 500px at 100% 0%, rgba(236,72,153,.12), transparent 60%); background-attachment: fixed; }
a { color: var(--accent); text-decoration: none; }
h1 { font-family: var(--font-head); font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; margin: 0 0 .25rem; line-height: 1.15; }
h2 { font-family: var(--font-head); font-size: 1.15rem; font-weight: 700; margin: 1.4rem 0 .5rem; }
p { margin: .3rem 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
input, select, button, textarea { font: inherit; color: inherit; }
input[type=text], input[type=url] { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--panel-2); padding: .1em .4em; border-radius: 6px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.2rem; padding: .7rem 1.2rem; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--font-head); font-weight: 800; font-size: 1.15rem; color: var(--ink); display: inline-flex; align-items: center; gap: .55rem; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: var(--grad); display: inline-block; position: relative; }
.logo::after { content: ""; position: absolute; inset: 7px 6px; background: repeating-linear-gradient(90deg, #fff 0 2px, transparent 2px 6px); border-radius: 2px; opacity: .9; mask: linear-gradient(180deg, transparent, #000 40%, #000 60%, transparent); }
.topnav { display: flex; gap: .2rem; }
.topnav a { color: var(--muted); padding: .4rem .8rem; border-radius: 10px; font-weight: 500; display: inline-flex; align-items: center; gap: .4rem; }
.topnav a:hover { color: var(--ink); background: var(--panel-2); }
.topnav a.active { color: var(--ink); background: var(--panel-2); }
.badge { background: var(--grad); color: #fff; font-size: .7rem; font-weight: 700; padding: 0 .45rem; border-radius: 999px; line-height: 1.5; }

.view { max-width: 1100px; margin: 0 auto; padding: 1.6rem 1.2rem 4rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.song { display: flex; flex-direction: column; gap: .6rem; position: relative; overflow: hidden; }
.song::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad); opacity: .9; }
.song h3 { margin: .3rem 0 0; font-family: var(--font-head); font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
.song .meta { color: var(--muted); font-size: .85rem; display: flex; gap: .6rem; flex-wrap: wrap; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip { font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.chip.vocals { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 40%, transparent); }
.chip.instrumental, .chip.other { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.chip.drums { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.bass { color: var(--accent-3); border-color: color-mix(in srgb, var(--accent-3) 40%, transparent); }
.song[data-id] { cursor: pointer; transition: transform .12s ease, border-color .15s ease; }
.song[data-id]:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); transform: translateY(-1px); }
.song[data-id]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.lyrics { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.song .actions { display: flex; gap: .5rem; margin-top: auto; align-items: center; flex-wrap: wrap; }
.downloads { display: flex; gap: .3rem .7rem; flex-wrap: wrap; font-size: .8rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); cursor: pointer; font-weight: 600; transition: transform .08s ease, filter .15s ease; white-space: nowrap; }
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.sm { padding: .35rem .7rem; font-size: .85rem; border-radius: 10px; }
.btn.on { background: var(--grad); color: #fff; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* Add page */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 2.4rem 1rem; text-align: center; background: var(--grad-soft); cursor: pointer; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel)); }
.drop strong { font-family: var(--font-head); font-size: 1.1rem; }
.row { display: flex; gap: .6rem; align-items: center; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; }
.mode { display: block; cursor: pointer; border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem; background: var(--panel-2); }
.mode:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode b { display: block; font-weight: 600; }
.mode span { color: var(--muted); font-size: .82rem; }

.jobs { display: flex; flex-direction: column; gap: .6rem; }
.job { display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; align-items: center; padding: .8rem 1rem; }
.job .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .detail { color: var(--muted); font-size: .85rem; grid-column: 1 / -1; }
.job .bar { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.job .bar i { display: block; height: 100%; background: var(--grad); width: 0; transition: width .3s; }
.job .bar.busy i { width: 40%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%);} 100% { transform: translateX(260%);} }
.status { font-size: .75rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; padding: .15rem .55rem; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.status.done { color: var(--ok); } .status.failed { color: var(--bad); }
.status.separating, .status.downloading_model, .status.encoding, .status.downloading, .status.preparing { color: var(--accent); }
.warn { grid-column: 1 / -1; color: var(--warn); font-size: .85rem; }
.err { grid-column: 1 / -1; color: var(--bad); font-size: .85rem; white-space: pre-wrap; word-break: break-word; }
.log { grid-column: 1 / -1; font-family: ui-monospace, Menlo, monospace; font-size: .72rem; color: var(--muted); max-height: 140px; overflow: auto; background: var(--bg-2); border-radius: 8px; padding: .5rem .7rem; }

/* Step timeline (queue + lyrics sync) */
.steps { grid-column: 1 / -1; list-style: none; margin: .5rem 0 .1rem; padding: 0; display: flex; flex-direction: column; gap: .15rem; }
.step { display: grid; grid-template-columns: 1.3rem 1fr auto; align-items: center; column-gap: .55rem; font-size: .9rem; color: var(--muted); padding: .2rem 0; }
.step .ic { width: .95rem; height: .95rem; border-radius: 50%; border: 2px solid var(--line); justify-self: center; position: relative; }
.step.done { color: var(--ink); }
.step.done .ic { background: var(--ok); border-color: var(--ok); }
.step.done .ic::after { content: ""; position: absolute; left: .22rem; top: .08rem; width: .2rem; height: .42rem; border: solid #0b0f1a; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.step.active { color: var(--ink); font-weight: 600; }
.step.active .ic { border-color: var(--accent); border-top-color: transparent; animation: spin .9s linear infinite; }
.step.failed .ic { background: var(--bad); border-color: var(--bad); }
.step.skipped { opacity: .5; }
.step .rt { font-variant-numeric: tabular-nums; font-size: .82rem; font-weight: 500; color: var(--muted); }
.step .dt { grid-column: 2 / -1; font-size: .8rem; font-weight: 400; color: var(--muted); }
.step .bar { grid-column: 2 / -1; height: 5px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin: .2rem 0 .25rem; }
.step .bar i { display: block; height: 100%; background: var(--grad); transition: width .4s ease; }
.step .bar.busy i { animation: slide 1.4s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.add-lyrics { margin-top: 1rem; }
.add-lyrics summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.add-lyrics .lyrics-input { min-height: 180px; }

/* Player */
.title-wrap { min-width: 0; flex: 1; }
.title-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.title-row h1 { overflow-wrap: anywhere; }
.title-row input { flex: 1; min-width: 12rem; font: 700 1.3rem var(--font-head); }
.btn.icon { padding: .3rem .55rem; font-size: 1rem; }
.player-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.player-grid > .card { margin: 0; }
.stems-card h2 { margin-top: 0; }
@media (min-width: 1000px) {
  .player-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); grid-template-areas: "player lyrics" "stems lyrics"; grid-template-rows: auto 1fr; align-items: start; }
  .player-grid .player { grid-area: player; }
  .player-grid .stems-card { grid-area: stems; }
  .player-grid .lyrics-card { grid-area: lyrics; position: sticky; top: 4.4rem; }
  .player-grid .lyrics-scroll { height: min(560px, calc(100vh - 11rem)); }
}
.player .wave { width: 100%; height: 110px; display: block; border-radius: 12px; background: var(--bg-2); cursor: pointer; }
.transport { display: flex; align-items: center; gap: .8rem; margin-top: .8rem; flex-wrap: wrap; }
.transport .time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 7.5rem; }
.presets { display: flex; gap: .5rem; flex-wrap: wrap; margin-left: auto; }
.stems { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.stem { display: grid; grid-template-columns: 7rem 1fr auto; gap: .8rem; align-items: center; padding: .6rem .9rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.stem.muted { opacity: .55; }
.stem .name { font-weight: 600; text-transform: capitalize; display: flex; align-items: center; gap: .5rem; }
.stem .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.stem.vocals .dot { background: var(--accent-2); } .stem.drums .dot { background: var(--warn); } .stem.bass .dot { background: var(--accent-3); }
.stem input[type=range] { width: 100%; accent-color: var(--accent); }
.stem .dl { font-size: .8rem; }
.play { width: 46px; height: 46px; border-radius: 50%; font-size: 1.1rem; padding: 0; }

/* Lyrics */
.lyrics-card { padding-bottom: .4rem; }
.lyrics-progress { padding: 1rem .2rem .4rem; }
.lyrics-progress .lead { font-weight: 600; margin: 0 0 .4rem; }
.lyrics-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }
.lyrics-head h2 { margin: 0; }
.lyrics-head .row { gap: .35rem; }
.lyrics-head .offset { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); min-width: 3.2rem; text-align: center; }
.lyrics-empty { text-align: center; padding: 2rem 1rem 1.6rem; color: var(--muted); max-width: 34rem; margin: 0 auto; }
.lyrics-input { width: 100%; min-height: 320px; margin-top: .8rem; resize: vertical; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; font: 1rem/1.6 var(--font-body); }
.lyrics-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.lyrics-actions { margin: .8rem 0 .6rem; }
.lyrics-scroll { position: relative; height: min(460px, 60vh); overflow-y: auto; scrollbar-width: none; margin-top: .4rem;
  mask: linear-gradient(180deg, transparent 0, #000 14%, #000 80%, transparent 100%); -webkit-mask: linear-gradient(180deg, transparent 0, #000 14%, #000 80%, transparent 100%); }
.lyrics-scroll::-webkit-scrollbar { display: none; }
.lyrics-pad { height: 40%; }
.lyric-line { --dim: rgba(238, 242, 255, .28);
  font: 800 clamp(1.35rem, 3.2vw, 2.05rem)/1.25 var(--font-head); letter-spacing: -.015em;
  padding: .45rem .6rem; margin: 0 -.6rem; border-radius: 12px; cursor: pointer; color: var(--dim);
  transform-origin: left center; transition: transform .35s ease, opacity .35s ease, filter .35s ease, color .35s ease; filter: blur(.6px); }
.lyric-line.stanza { margin-top: 1.1rem; }
.lyric-line:hover { background: color-mix(in srgb, var(--panel-2) 70%, transparent); filter: none; }
.lyric-line.past { opacity: .75; }
.lyric-line.active { transform: scale(1.03); filter: none; }
.lyric-line .w { --p: 0; }
.lyric-line.active .w, .lyric-line.past .w {
  background: linear-gradient(90deg, var(--ink) calc(var(--p) * 115% - 15%), var(--dim) calc(var(--p) * 115%));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.lyric-line.past .w { --p: 1 !important; background: none; color: var(--dim); }
.lyric-line.active .w { text-shadow: 0 0 22px rgba(167, 139, 250, calc(var(--p) * .35)); }
.lyric-gap { display: flex; gap: .55rem; padding: .9rem .1rem; height: 0; opacity: 0; overflow: hidden; transition: height .35s ease, opacity .35s ease, padding .35s ease; }
.lyric-gap.active { height: 2.6rem; opacity: 1; }
.lyric-gap i { --p: 0; width: .8rem; height: .8rem; border-radius: 50%; background: rgba(238, 242, 255, calc(.22 + var(--p) * .78));
  transform: scale(calc(.8 + var(--p) * .35)); animation: breathe 2.4s ease-in-out infinite; }
.lyric-gap.ending i { transform: scale(0); transition: transform .4s ease; }
@keyframes breathe { 50% { translate: 0 -2px; } }
@media (prefers-reduced-motion: reduce) { .lyric-line, .lyric-gap { transition: none; } .lyric-gap i { animation: none; } }

/* Covers, connection chip, phone app */
.cover-row { display: flex; gap: .8rem; align-items: center; min-width: 0; }
.cover-row > div { min-width: 0; }
.cover { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; background: var(--panel-2); }
.cover.blank { display: grid; place-items: center; color: var(--muted); font-size: 1.4rem; border: 1px solid var(--line); }
.cover.big { width: 64px; height: 64px; border-radius: 12px; box-shadow: var(--shadow); }
.conn-chip { margin-left: auto; font-size: .75rem; font-weight: 700; padding: .2rem .6rem; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.conn-chip::before { content: ""; display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; margin-right: .35rem; vertical-align: middle; background: var(--muted); }
.conn-chip.on { color: var(--ok); } .conn-chip.on::before { background: var(--ok); }
.conn-chip.off { color: var(--warn); } .conn-chip.off::before { background: var(--warn); }
body.offline .topnav a[data-route="add"], body.offline .topnav a[data-route="library"] { opacity: .45; }
.head-actions { gap: .5rem; flex-wrap: wrap; }
.autonext { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); cursor: pointer; }
.pair { max-width: 34rem; }
.pair-steps { padding-left: 1.2rem; color: var(--muted); }
.pair input { font-family: ui-monospace, Menlo, monospace; }
.phone-app code.copy { user-select: all; font-size: .9rem; }
.phone-app .pair-code { font-size: 1.15rem; letter-spacing: .08em; padding: .3em .6em; }
.origins { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; font: .9rem ui-monospace, Menlo, monospace; margin-bottom: .4rem; }
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: max(.7rem, env(safe-area-inset-top)); }
  .view { padding-bottom: max(4rem, env(safe-area-inset-bottom)); }
}

/* Settings */
.settings .card { margin-bottom: 1rem; }
.field { margin: .7rem 0; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
.radios { display: flex; gap: .5rem; flex-wrap: wrap; }
.radios label { display: inline-flex; gap: .4rem; align-items: center; padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); cursor: pointer; font-weight: 500; }
.radios label:has(input:checked) { border-color: var(--accent); }
.check { display: inline-flex; gap: .5rem; align-items: center; cursor: pointer; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
td { padding: .4rem .3rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td:first-child { color: var(--muted); white-space: nowrap; }
.ok { color: var(--ok); } .bad { color: var(--bad); }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: .7rem 1.1rem; border-radius: 12px; box-shadow: var(--shadow); z-index: 20; max-width: min(90vw, 480px); }
.toast.bad { border-color: var(--bad); }
@media (max-width: 640px) {
  .view { padding: 1rem .9rem 3rem; }
  h1 { font-size: 1.55rem; }
  .topbar { gap: .6rem; padding: .6rem .9rem; }
  .topnav a { padding: .45rem .6rem; }
  .card { padding: .95rem 1rem; }
  .stem { grid-template-columns: 1fr; gap: .4rem; }
  .presets { margin-left: 0; width: 100%; }
  .presets .btn { flex: 1; padding: .65rem .5rem; }
  .play { width: 54px; height: 54px; }
  .player .wave { height: 84px; }
  .lyrics-scroll { height: 52vh; }
  .lyrics-head .btn.sm { min-width: 2.2rem; min-height: 2.2rem; }
  .stem input[type=range] { height: 2rem; }
  .row:has(> #url) { flex-wrap: wrap; }
  .row:has(> #url) .btn { width: 100%; }
}
