:root {
  --bg: #0e0f13; --panel: #16181f; --panel2: #1d2029; --line: #2a2e3a; --text: #e8e9ee; --muted: #8b90a0;
  --accent: #ff5c35; --accent2: #ff2d87; --ok: #2fd08a; --warn: #ffb020; --err: #ff4d5e; --blue: #4d9dff;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: 7px 12px; }
button:hover { border-color: #3d4354; }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; }
button.small, .small { padding: 5px 9px; font-size: 13px; }
button.icon { padding: 2px 8px; font-size: 16px; background: transparent; }
button.danger { color: var(--err); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; width: 100%; }
a { color: var(--blue); }

.topbar { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.logo { background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.user-chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; margin-left: 6px; cursor: pointer; }

.layout { display: flex; height: calc(100% - 52px); }
.sidebar { width: 240px; flex-shrink: 0; border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 10px; }
.side-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .8px; padding: 4px 6px 8px; }
.channel-list { list-style: none; margin: 0; padding: 0; }
.channel-list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.channel-list li:hover { background: var(--panel2); }
.channel-list li.active { background: linear-gradient(135deg, rgba(255,92,53,.18), rgba(255,45,135,.14)); }
.channel-list .count { color: var(--muted); font-size: 12px; }
.channel-list .edit { opacity: 0; font-size: 12px; padding: 0 4px; border: 0; background: none; }
.channel-list li:hover .edit { opacity: .7; }
.channel-list .cat { padding: 5px 10px 5px 24px; font-size: 13px; color: var(--muted); }
.channel-list .cat.active { color: var(--text); background: var(--panel2); }
.channel-list .ch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.main { flex: 1; overflow-y: auto; padding: 16px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.download-card.drag { border-color: var(--accent); background: #1e1a1c; }
.dl-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dl-row + .dl-row { margin-top: 8px; }
.spacer { flex: 1; }
.check { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.file-btn { border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }

.toolbar { display: flex; gap: 8px; margin: 14px 0 10px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }

.track-list { display: flex; flex-direction: column; gap: 6px; }
.track { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.track:hover { border-color: #3d4354; }
.track.active { border-color: var(--accent); }
.cover { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--panel2); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.t-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.t-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); white-space: nowrap; }
.st-new { color: var(--blue); border-color: rgba(77,157,255,.4); }
.st-in_work { color: var(--warn); border-color: rgba(255,176,32,.4); }
.st-generated { color: var(--accent2); border-color: rgba(255,45,135,.4); }
.st-published { color: var(--ok); border-color: rgba(47,208,138,.4); }
.st-rejected { color: var(--muted); }
.pill { background: var(--panel2); border-radius: 6px; padding: 1px 6px; font-size: 12px; color: var(--text); }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }

.detail { width: 560px; flex-shrink: 0; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 16px; }
.detail.hidden { display: none; }
.d-head { display: flex; gap: 12px; align-items: flex-start; }
.d-head img, .d-head .cover { width: 84px; height: 84px; }
.d-title { font-size: 16px; font-weight: 700; margin: 0 0 4px; word-break: break-word; }
.d-sub { color: var(--muted); font-size: 12px; }
.close { margin-left: auto; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0; }
.stat { background: var(--panel2); border-radius: 8px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 16px; }
.stat span { color: var(--muted); font-size: 11px; }
.section-title { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.wave-wrap { position: relative; background: var(--panel2); border-radius: 8px; overflow: hidden; }
canvas.wave { display: block; width: 100%; height: 140px; cursor: crosshair; }
.wave-legend { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.wave-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
audio { width: 100%; margin-top: 8px; height: 36px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 6px; }
.hook { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel2); border-radius: 8px; margin-bottom: 4px; }
.hook .n { font-weight: 700; color: var(--accent); width: 22px; }
.hook .bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.hook .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.clip { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 8px; background: var(--panel2); border-radius: 8px; margin-bottom: 6px; }
.clip .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip audio { grid-column: 1 / -1; margin: 0; height: 30px; }
.clip .acts { display: flex; gap: 4px; }
.prompt-box { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.prompt-box textarea { background: var(--bg); min-height: 70px; font-family: Consolas, monospace; font-size: 12.5px; }
.prompt-box label { font-size: 12px; color: var(--muted); display: block; margin: 8px 0 4px; }
.prompt-box label:first-child { margin-top: 0; }
.hint { color: var(--muted); font-size: 12px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; background: var(--panel2); border-radius: 4px; padding: 1px 6px; color: var(--muted); }
.form label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.form input, .form select, .form textarea { width: 100%; }

.jobs { position: fixed; right: 16px; bottom: 16px; width: 340px; display: flex; flex-direction: column; gap: 6px; z-index: 30; }
.job { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.job .jt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job .jm { color: var(--muted); }
.job.error { border-color: var(--err); }
.job.error .jm { color: var(--err); white-space: normal; }
.job.done { border-color: rgba(47,208,138,.5); }
.progress { height: 4px; background: var(--line); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }
.jobs-head { display: flex; justify-content: flex-end; }

.toast { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
.toast.show { opacity: 1; }
.toast.err { border-color: var(--err); color: #ffc2c8; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal-bg.hidden { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: 520px; max-width: calc(100% - 32px); max-height: calc(100% - 40px); overflow-y: auto; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal.wide { width: 820px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
.feed { max-height: 280px; overflow-y: auto; font-size: 12px; }
.feed div { padding: 4px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.feed b { color: var(--text); font-weight: 600; }

@media (max-width: 1100px) {
  .detail { position: fixed; right: 0; top: 52px; bottom: 0; width: min(560px, 100%); z-index: 20; box-shadow: -10px 0 30px rgba(0,0,0,.5); }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
}

.variant { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-top: 8px; }
.variant textarea { min-height: 60px; }
.v-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.mono { font-family: Consolas, monospace; font-size: 12.5px; background: var(--bg); border-radius: 6px; padding: 6px 8px; margin: 4px 0; word-break: break-word; }
.pre { white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.hist { background: var(--panel2); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.hist summary { cursor: pointer; font-size: 13px; }
.tips { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.tips li { margin-bottom: 3px; }
.tag.click { cursor: pointer; color: var(--text); }
.tag.click:hover { background: var(--line); }
.ai-btn { background: linear-gradient(135deg, #6b4dff, #b24dff); border: 0; color: #fff; font-weight: 600; }
.err-text { color: var(--err); margin-top: 8px; }
.hook .n { flex-shrink: 0; }
.top-actions button { white-space: nowrap; }
@media (max-width: 1000px) {
  .topbar { overflow-x: auto; gap: 12px; }
  .brand { white-space: nowrap; }
}
.banner { background: #5a3a00; color: #ffd98a; padding: 8px 16px; font-size: 13px; text-align: center; }
.edit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.edit-grid label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
.edit-grid input { width: 100%; min-width: 0; box-sizing: border-box; }
.clip > .hint { grid-column: 1 / -1; }
[hidden] { display: none !important; }
body:not(.signed-in) > .topbar, body:not(.signed-in) > .layout, body:not(.signed-in) > .jobs { display: none; }
.auth-gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; box-sizing: border-box; }
.auth-card { width: min(440px, 100%); padding: 28px; box-sizing: border-box; }
.auth-card h1 { font-size: 24px; }
.auth-card p { line-height: 1.5; }
.auth-card button { margin-top: 16px; }
