/* YuE2 Studio — tokens: light on bare :root, dark via prefers-color-scheme and data-theme. */
:root {
  --bg: #f3f2ee; --surface: #ffffff; --surface-2: #e9e7e1; --border: #d6d3cb; --border-strong: #bdb9ae;
  --text: #1f1e1a; --muted: #6a665e; --accent: #b0700f; --accent-ink: #fffaf0; --accent-soft: #f6e8cd;
  --ok: #2f8a5a; --warn: #b8860b; --err: #c33d3d; --info: #3b6fb6;
  --shadow: 0 1px 2px rgba(20, 18, 10, .08), 0 6px 20px -12px rgba(20, 18, 10, .25);
  --radius: 6px; --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131519; --surface: #1b1e24; --surface-2: #242830; --border: #2f333c; --border-strong: #454a55;
    --text: #e7e5df; --muted: #8f929b; --accent: #e3a33a; --accent-ink: #1b1305; --accent-soft: #3a2e14;
    --ok: #5cc48c; --warn: #e3b341; --err: #e56b6b; --info: #7aa7e6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131519; --surface: #1b1e24; --surface-2: #242830; --border: #2f333c; --border-strong: #454a55;
  --text: #e7e5df; --muted: #8f929b; --accent: #e3a33a; --accent-ink: #1b1305; --accent-soft: #3a2e14;
  --ok: #5cc48c; --warn: #e3b341; --err: #e56b6b; --info: #7aa7e6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-family: var(--font); font-size: 14px; line-height: 1.45; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0; }
code, pre, textarea.mono, .mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* header */
.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1080px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 12px; min-height: 48px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .01em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 18px; height: 18px; border-radius: 3px; background: linear-gradient(135deg, var(--accent), #7a4a06); display: inline-block; }
nav.main { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; flex: 1 1 auto; }
nav.main > a, nav.main > details.menu > summary { padding: 6px 10px; border-radius: var(--radius); color: var(--muted); font-weight: 500; cursor: pointer; white-space: nowrap; }
nav.main > a:hover, nav.main > details.menu > summary:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
nav.main > a[aria-current="page"], nav.main > details.menu > summary[aria-current="page"], nav.main > details.menu[open] > summary { color: var(--text); background: var(--surface-2); }
nav.main > .nav-queue { margin-left: auto; }
#engine-pill { margin-left: auto; }
nav.main .caret { font-size: 14px; line-height: 1; margin-left: 5px; opacity: .8; }
nav.main .menu-list { left: 0; right: auto; z-index: 20; min-width: 140px; }
nav.main .menu-list a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }
.badge-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; color: var(--muted); background: var(--bg); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill[data-state="ready"] .dot { background: var(--ok); }
.pill[data-state="busy"] .dot { background: var(--accent); animation: pulse 1.2s infinite; }
.pill[data-state="loading"] .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.pill[data-state="offline"] .dot { background: var(--err); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pill .dot { animation: none; } }

/* layout */
main { max-width: 1080px; margin: 0 auto; padding-block: 20px 48px; padding-inline: 16px; }
.view-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.view-head .sub { color: var(--muted); }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.cols.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) { .cols, .cols.even { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row > select, .row > input[type="number"] { width: auto; }
.row.nowrap { flex-wrap: nowrap; } .row.nowrap > input { flex: 1; min-width: 0; width: auto; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.panel.sticky { position: sticky; top: 60px; }
@media (max-width: 760px) { .panel.sticky { position: static; } }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 8px; }
.empty a { font-weight: 600; }
details > summary { cursor: pointer; color: var(--muted); font-weight: 500; user-select: none; }
details > summary:hover { color: var(--text); }
details[open] > summary { margin-bottom: 8px; }

/* forms */
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label.field > span.lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 6px 8px; width: 100%; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 80px; line-height: 1.4; }
textarea.lyrics { min-height: 200px; }
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="checkbox"] { width: auto; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 480px) { .grid2.stack-narrow { grid-template-columns: minmax(0, 1fr); } }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 480px) { .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--bg); color: var(--muted); padding: 5px 12px; flex: 1 0 auto; justify-content: center; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); }

button, .btn { font: inherit; font-weight: 600; color: var(--text); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; line-height: 1.3; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--text); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { color: var(--err); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); border-color: var(--border); }
button.sm, .btn.sm { padding: 3px 8px; font-size: 12px; }
button.icon { padding: 6px 8px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.card .title { font-weight: 650; font-size: 15px; overflow-wrap: anywhere; }
.card .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.card .meta b { color: var(--text); font-weight: 600; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.ok { color: var(--ok); } .tag.err { color: var(--err); } .tag.warn { color: var(--warn); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
audio { width: 100%; height: 36px; display: block; }
.warnbox { padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); font-size: 13px; }
.errbox { padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); font-size: 13px; overflow-wrap: anywhere; }

/* progress */
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.progress.indeterminate > i { width: 30%; animation: slide 1.4s infinite linear; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .progress.indeterminate > i { animation: none; width: 100%; opacity: .4; } }
.stages { display: flex; gap: 4px; flex-wrap: wrap; }
.stages span { font-size: 11px; padding: 1px 7px; border-radius: 3px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.stages span.done { color: var(--ok); }
.stages span.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.stats b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.abc-live.final { border-color: var(--ok); }
.score-head { gap: 6px; min-height: 22px; }
.score-head + .abc-live { margin-top: -4px; }
.abc-live { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 4px; }
.score { overflow-x: auto; background: #fff; color: #000; border-radius: var(--radius); border: 1px solid var(--border); padding: 6px; }
.score svg { max-width: 100%; height: auto; }

/* tables */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
pre.block { margin: 0; padding: 10px; background: var(--surface-2); border-radius: var(--radius); overflow: auto; max-height: 320px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* drop zone */
.drop { border: 2px dashed var(--border-strong); border-radius: 8px; padding: 28px 16px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.drop input { display: none; }

/* toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); font-size: 13px; display: flex; gap: 10px; align-items: flex-start; }
.toast.err { border-left-color: var(--err); } .toast.ok { border-left-color: var(--ok); }
.toast button { margin-left: auto; }

/* player bar: fixed under everything, outside #view so re-renders never touch its <audio> */
body { --player-h: 56px; }
.player-bar { position: fixed; inset: auto 0 0 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--border); box-shadow: var(--shadow); }
body:not(.has-player) .player-bar { display: none; }
.player-inner { max-width: 1080px; margin: 0 auto; min-height: var(--player-h); padding: 8px 16px; display: flex; align-items: center; gap: 8px; }
.player-bar audio { flex: 1 1 260px; max-width: 520px; width: auto; min-width: 0; }
.player-bar .now { flex: 1 1 160px; min-width: 0; display: flex; flex-direction: column; color: var(--text); line-height: 1.25; }
.player-bar .now:hover { text-decoration: none; color: var(--accent); }
.player-bar .now .title, .player-bar .now .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar .now .title { font-weight: 600; }
.player-bar .now .sub { font-size: 12px; color: var(--muted); }
.player-bar .pos { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Floating AI assistant */
.assistant-toggle {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 45;
  padding: 11px 17px;
  border: 1px solid color-mix(in srgb, var(--accent) 60%, var(--border));
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast, #1b1305);
  font-weight: 700;
  box-shadow: var(--shadow);
}
.assistant-panel {
  position: fixed;
  right: 22px;
  bottom: 150px;
  z-index: 46;
  width: min(430px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 180px));
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.assistant-head,
.assistant-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.assistant-head { justify-content: space-between; margin-bottom: 8px; }
.assistant-head > div { display: flex; flex-direction: column; min-width: 0; }
.assistant-model { color: var(--muted); font-size: 11px; }
.assistant-status { color: var(--muted); font-size: 12px; margin: 8px 0 12px; }
.assistant-status[data-state="ok"] { color: var(--ok); }
.assistant-status[data-state="error"] { color: var(--err); }
.assistant-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.assistant-brief,
.assistant-output { width: 100%; resize: vertical; }
.assistant-output { color: var(--text); background: var(--surface-2); }
.assistant-lyrics { min-height: 170px; }
.assistant-result { margin-top: 12px; }
.assistant-actions { flex-wrap: wrap; margin-top: 4px; }
.assistant-generate { flex: 1 1 180px; }
.assistant-apply { border-color: var(--accent); }
@media (max-width: 700px) {
  .assistant-toggle { right: 12px; bottom: 82px; }
  .assistant-panel { right: 12px; bottom: 136px; width: calc(100vw - 24px); max-height: calc(100vh - 150px); }
}
body.has-player main { padding-bottom: calc(48px + var(--player-h)); }
body.has-player #toasts { bottom: calc(16px + var(--player-h)); }
@media (max-width: 640px) {
  body { --player-h: 100px; }
  .player-inner { flex-wrap: wrap; }
  .player-bar audio { flex: 1 1 100%; max-width: none; order: 9; }
}
/* play buttons (playButton() in player.js): ▶ normally, ⏸ + accent while that song is playing */
button.play { flex: 0 0 auto; }
button.play.playing { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* create: form | results */
.cols.results-layout { grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); }
@media (max-width: 760px) { .cols.results-layout { grid-template-columns: minmax(0, 1fr); } }
@media (min-width: 761px) { .results-col { position: sticky; top: 60px; max-height: calc(100vh - 76px); overflow-y: auto; padding-right: 2px; } body.has-player .results-col { max-height: calc(100vh - 76px - var(--player-h)); } }
pre.lyrics-block { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--font); font-size: 14px; line-height: 1.5; max-height: none; }

/* library multi-select */
.selbar { position: sticky; top: 49px; z-index: 5; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; box-shadow: var(--shadow); }
.card input.sel { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

input:disabled, button:disabled { opacity: .55; }
.check.small { font-size: 12px; color: var(--muted); }

/* hum recorder */
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .08s linear; }
button.recording { background: var(--err); border-color: var(--err); color: #fff; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* projects */
.tag.take-tag { text-transform: none; letter-spacing: 0; }
.takebanner { padding: 8px 12px; margin-bottom: 14px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent-soft); font-size: 13px; }
.inline-edit { cursor: text; border-radius: 4px; padding: 0 4px; margin: 0 -4px; }
.inline-edit:hover { background: var(--surface-2); }
.inline-edit.placeholder { color: var(--muted); font-style: italic; }
h1.inline-edit, .inline-input { min-width: 120px; }
.album-player .btn.disabled { opacity: .5; cursor: not-allowed; }
ol.tracklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.track { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.track.dragging { opacity: .45; }
.track.drop-before::before, .track.drop-after::after { content: ""; position: absolute; left: 8px; right: 8px; height: 3px; border-radius: 2px; background: var(--accent); }
.track.drop-before::before { top: -7px; } .track.drop-after::after { bottom: -7px; }
.track.playing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.track-head { gap: 6px; }
.drag-handle { cursor: grab; color: var(--muted); font-size: 16px; padding: 2px 4px; user-select: none; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
.track-n { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; min-width: 28px; }
button.track-n { padding: 2px 6px; }
.track-title { flex: 1; min-width: 0; font-weight: 650; font-size: 15px; overflow-wrap: anywhere; }
.track-title .inline-edit { display: inline-block; max-width: 100%; }
.track details.takes > summary { font-size: 12px; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.take-row { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.take-row.chosen { border-color: var(--ok); }
.take-row.live { border-style: dashed; }
.take-row .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.take-row .meta b { color: var(--text); font-weight: 600; }
.take-row .title { font-weight: 600; overflow-wrap: anywhere; }
.take-controls { gap: 8px; }
.take-controls .note-wrap { flex: 1 1 160px; min-width: 0; }
.take-controls .note { padding: 3px 8px; font-size: 12px; }
.take-controls.saving { opacity: .7; }
.thumb { font-size: 14px; padding: 2px 6px; filter: grayscale(1); opacity: .6; }
.thumb[aria-pressed="true"] { filter: none; opacity: 1; background: var(--accent-soft); border-color: var(--accent); }
.stars { display: inline-flex; gap: 0; }
.stars button { border: 0; background: transparent; color: var(--border-strong); font-size: 18px; line-height: 1; padding: 0 2px; cursor: pointer; }
.stars button:hover, .stars button.on { color: var(--accent); }
.stars button:hover ~ button { color: var(--border-strong); }
button.choose.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details[open].menu > summary { margin-bottom: 0; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 6; min-width: 170px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; }
.menu-list a { padding: 6px 10px; border-radius: 4px; color: var(--text); }
.menu-list a:hover { background: var(--surface-2); text-decoration: none; }
.project-picker { flex: 1 1 320px; }
