:root {
  --bg: #0f1115;
  --bg2: #161922;
  --card: #1b1f2a;
  --line: #2a3040;
  --text: #e8eaf0;
  --muted: #9097a8;
  --accent: #ff5d73;
  --accent2: #ffb35c;
  --ok: #4cd08a;
  --warn: #ffc857;
  --bad: #ff6b6b;
  --yt: #ff3b3b;
  --sc: #ff7a1a;
  --au: #a35cff;
  --ar: #5cc8ff;
  --ja: #3ad6b0;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 500px at 85% -10%, #2a1630 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.7 Vazirmatn, Tahoma, "Segoe UI", sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent2); }
img { display: block; }

.top {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 21, .8); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; }
.brand svg { width: 26px; height: 26px; fill: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip {
  font-size: 12px; padding: 2px 10px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.top-actions { display: flex; gap: 6px; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px;
  padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto;
}
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .top { padding: 10px 16px; flex-wrap: wrap; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.search { padding: 22px; }
.search h1 { font-size: 18px; margin: 0 0 12px; font-weight: 700; }
textarea, input, select {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; outline: none; transition: border-color .15s;
}
textarea { resize: vertical; min-height: 56px; font-size: 16px; }
textarea:focus, input:focus, select:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row.between { justify-content: space-between; }
.hint, .muted { color: var(--muted); font-size: 12px; }

button { cursor: pointer; border: 0; border-radius: 10px; padding: 8px 16px; transition: filter .15s, background .15s; }
button:disabled { opacity: .5; cursor: progress; }
.primary { background: linear-gradient(135deg, var(--accent), #ff7b5c); color: #fff; font-weight: 700; }
.primary:hover { filter: brightness(1.1); }
.secondary { background: #2a3040; }
.secondary:hover { background: #343b4f; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.ghost:hover { color: var(--text); border-color: var(--muted); }
.link { background: none; padding: 0; color: var(--muted); font-size: 12px; }
.link:hover { color: var(--text); }
.icon { padding: 6px 10px; background: #2a3040; font-size: 13px; }
.icon:hover { background: #343b4f; }

.paste { margin-top: 14px; color: var(--muted); }
.paste summary { cursor: pointer; font-size: 13px; }
.paste .row input { flex: 1; min-width: 200px; }

section h2.sec { font-size: 16px; margin: 26px 0 12px; display: flex; align-items: center; gap: 10px; }
section h2.sec small { color: var(--muted); font-weight: 400; font-size: 12px; }

/* song cards */
.songs { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.song { display: flex; gap: 12px; padding: 12px; }
.song.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cover {
  width: 84px; height: 84px; border-radius: 10px; object-fit: cover; flex: none;
  background: linear-gradient(135deg, #2a3040, #1b1f2a);
}
.song .info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.song .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song .a { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.badge { font-size: 10.5px; padding: 0 7px; border-radius: 6px; background: #2a3040; color: var(--muted); }
.badge.lyric { background: color-mix(in srgb, var(--accent2) 18%, transparent); color: var(--accent2); }
.badge.best { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.snippet {
  font-size: 12.5px; color: #c9cdd8; margin: 4px 0 2px; white-space: pre-line; direction: ltr; text-align: left;
  border-inline-start: 2px solid var(--accent2); padding-inline-start: 8px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.snippet mark { background: none; color: var(--accent2); font-weight: 700; }
.song .acts { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; flex-wrap: wrap; }
.song .acts button { padding: 5px 12px; font-size: 13px; }

/* chosen song + sources */
.chosen { display: flex; gap: 16px; padding: 16px; align-items: flex-start; }
.chosen .cover { width: 120px; height: 120px; }
.chosen h3 { margin: 0; font-size: 20px; }
.chosen .meta { color: var(--muted); font-size: 13px; }
.chosen .links { display: flex; gap: 10px; font-size: 12px; margin-top: 6px; flex-wrap: wrap; }
.lyrics {
  margin-top: 10px; max-height: 260px; overflow: auto; white-space: pre-line; font-size: 13px;
  background: var(--bg2); border-radius: 10px; padding: 10px 14px; direction: ltr; text-align: left; color: #c9cdd8;
}
.group { margin-top: 14px; }
.group-h { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.group-h .dot { width: 9px; height: 9px; border-radius: 50%; }
.group-h .st { font-weight: 400; color: var(--muted); font-size: 12px; }
.src {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 8px; border-radius: 12px; border: 1px solid transparent;
}
.src:hover { background: var(--bg2); border-color: var(--line); }
.src.best { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 6%, transparent); }
.src .thumb { width: 96px; height: 54px; border-radius: 8px; object-fit: cover; background: #2a3040; }
.src .t { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src .u { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.src .acts { display: flex; gap: 6px; }
.diff.good { color: var(--ok); }
.diff.mid { color: var(--warn); }
.diff.bad { color: var(--bad); }
@media (max-width: 600px) {
  .src { grid-template-columns: 64px minmax(0, 1fr); }
  .src .thumb { width: 64px; height: 40px; }
  .src .acts { grid-column: 1 / -1; justify-content: flex-end; }
  .chosen .cover { width: 80px; height: 80px; }
}

/* side */
aside { padding: 16px; align-self: start; position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto; }
@media (max-width: 1000px) { aside { position: static; max-height: none; } }
.side-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.side-head h2 { font-size: 15px; margin: 0; }
#jobs { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.job { background: var(--bg2); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.job .jt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .js { color: var(--muted); font-size: 11.5px; display: flex; justify-content: space-between; gap: 8px; }
.job.error .js { color: var(--bad); }
.job.done .js { color: var(--ok); }
.bar { height: 5px; border-radius: 9px; background: #2a3040; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); width: 0; transition: width .4s; }
.bar.indet i { width: 35% !important; animation: indet 1.1s infinite linear; }
@keyframes indet { from { transform: translateX(120%); } to { transform: translateX(-320%); } }
.lib { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.lib .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Latin names inside the RTL page: lay out (and truncate) by their own direction */
.song .t, .song .a, .src .t, .src .u span, .lib .n, .job .jt, .player-title { unicode-bidi: plaintext; text-align: start; }
.lib .s { color: var(--muted); font-size: 11px; white-space: nowrap; }
.lib button, .lib a.icon { padding: 3px 8px; font-size: 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.lib.playing .n { color: var(--accent2); }
.player { position: sticky; bottom: -16px; background: var(--card); padding: 10px 0 2px; margin-top: 10px; }
.player-title { font-size: 12px; color: var(--accent2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player audio { width: 100%; height: 38px; }
.empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

/* states */
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 16px 4px; }
.spin { width: 18px; height: 18px; border: 2px solid #3a4154; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { padding: 12px 16px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); font-size: 13px; margin-top: 12px; }
.err { color: var(--bad); font-size: 13px; min-height: 1em; margin: 6px 0 0; }

dialog {
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: block; margin-bottom: 12px; font-size: 13px; }
dialog label small { color: var(--muted); margin-inline-start: 6px; }
dialog label input, dialog label select { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.log { background: var(--bg2); border-radius: 10px; padding: 10px; font-size: 11px; max-height: 180px; overflow: auto; direction: ltr; white-space: pre-wrap; }

/* login / setup */
body.auth { display: grid; place-items: center; padding: 16px; }
.auth-box { width: min(400px, 100%); padding: 26px; display: flex; flex-direction: column; gap: 12px; }
.auth-box h1 { font-size: 18px; margin: 6px 0 0; }
.auth-box p { margin: 0; line-height: 1.9; }
.auth-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.auth-box .primary { padding: 10px; margin-top: 4px; }
code { background: var(--bg2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }

/* health check */
.diag { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.diag-row { display: grid; grid-template-columns: 22px 150px minmax(0, 1fr); gap: 8px; font-size: 12.5px; padding: 6px 8px; border-radius: 8px; background: var(--bg2); }
.diag-row .v { overflow-wrap: anywhere; }
.diag-row .h { grid-column: 3; color: var(--warn); font-size: 12px; white-space: pre-line; overflow-wrap: anywhere; user-select: all; }
.diag-row.fail .h { color: var(--bad); }
.diag-row .i { font-weight: 800; }
.diag-row.ok .i { color: var(--ok); }
.diag-row.warn .i, .diag-row.info .i { color: var(--warn); }
.diag-row.fail .i { color: var(--bad); }
@media (max-width: 600px) { .diag-row { grid-template-columns: 22px minmax(0, 1fr); } .diag-row .v, .diag-row .h { grid-column: 2; } }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 4px; margin: 0 0 12px; }
legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
dialog textarea { font-size: 11px; min-height: 70px; direction: ltr; margin-top: 4px; }
dialog { max-height: calc(100vh - 32px); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #2a3040; border: 1px solid var(--line); padding: 10px 18px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); z-index: 50; font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.bad { border-color: var(--bad); }
