:root {
  --bg: #0e0f13;
  --panel: #171920;
  --panel-2: #1f222b;
  --text: #eceef3;
  --muted: #8b90a0;
  --accent: #ff7a45;
  --accent-2: #ffb36b;
  --ok: #4cc38a;
  --bad: #ff5d6c;
  --wip: #6aa8ff;
  --line: #2a2e39;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
a { color: var(--accent-2); }
h1, h2, h3 { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
h3 { margin-bottom: 8px; }
.mt { margin-top: 20px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); }
code { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 13px; overflow-wrap: anywhere; }
main:focus { outline: none; }
[hidden] { display: none !important; }
body.public .admin-only, body:not(.public) .public-only { display: none !important; }
.admin-link { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 8px; padding: 4px 10px; font: inherit; font-size: 13px; text-decoration: none; cursor: pointer; }
.admin-link:hover { color: var(--text); border-color: var(--accent); }

/* layout */
.top { display: flex; align-items: center; gap: 16px; padding: 12px 20px; max-width: 1100px; margin: 0 auto; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--accent); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,122,69,.6); } 70% { box-shadow: 0 0 0 10px rgba(255,122,69,0); } 100% { box-shadow: 0 0 0 0 rgba(255,122,69,0); } }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--text); background: var(--panel-2); }
.listeners { display: flex; align-items: center; gap: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.listeners svg { width: 18px; height: 18px; fill: currentColor; }
main { max-width: 1100px; margin: 0 auto; padding: 0 20px 24px; display: grid; gap: 16px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 12px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.card { background: var(--panel); border-radius: var(--radius); padding: 18px 20px; display: grid; gap: 12px; align-content: start; }
.card > p { margin: 0; }
.card.error { color: var(--bad); }

/* hero / now playing */
.hero { grid-template-columns: 260px 1fr; gap: 28px; align-items: center; background: linear-gradient(135deg, var(--panel), var(--panel-2)); padding: 24px; }
.art { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #262a35; }
.art img { width: 100%; height: 100%; object-fit: cover; display: none; }
.art.has img { display: block; }
.art.has .art-empty { display: none; }
.art-empty { position: absolute; inset: 0; display: grid; place-items: center; font-size: 72px; color: #3a3f4d; }
.kicker { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .14em; }
.meta h1 { font-size: 28px; line-height: 1.2; margin: 6px 0 4px; overflow-wrap: anywhere; }
.artist { font-size: 18px; }
.album { color: var(--muted); margin-top: 2px; }
.progress { margin-top: 18px; }
.pbar, .scanbar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.pbar span, .scanbar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .9s linear; }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.controls { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.play { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--accent); cursor: pointer; display: grid; place-items: center; transition: transform .1s; flex: none; }
.play:active { transform: scale(.95); }
.play svg { width: 30px; height: 30px; fill: #111; }
.play.small { width: 44px; height: 44px; }
.play.small svg { width: 22px; height: 22px; }
.script { white-space: pre-wrap; line-height: 1.6; margin: 0; }
.sources { margin: 0; padding-left: 18px; display: grid; gap: 4px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.list li { display: flex; align-items: center; gap: 12px; padding: 6px; border-radius: 8px; min-width: 0; }
.list li:hover { background: var(--panel-2); }
.list li.click { cursor: pointer; }
.list li.active { background: var(--panel-2); outline: 1px solid var(--accent); }
.list .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .a { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: #262a35; flex: none; }
.noart { display: grid; place-items: center; color: #4a5060; font-size: 18px; }
.dur, .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions { display: flex; gap: 2px; opacity: .55; }
.list li:hover .actions { opacity: 1; }
.tracks li.dragging { opacity: .4; }
.reorder li { cursor: grab; }
.folders { max-height: 50vh; overflow: auto; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; margin-left: 6px; color: var(--muted); white-space: nowrap; }
.tag.on { color: var(--ok); border-color: var(--ok); }
.tag.live { color: var(--accent); border-color: var(--accent); }
.tag.bad { color: var(--bad); border-color: var(--bad); }
.tag.wip { color: var(--wip); border-color: var(--wip); }

/* library */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.crumbs { color: var(--muted); }
.crumbs a { margin-right: 8px; }
.grid-list { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.album-tile { background: none; border: 0; color: inherit; text-align: left; padding: 0; cursor: pointer; font: inherit; min-width: 0; }
.album-tile .cover { width: 100%; aspect-ratio: 1; border-radius: 8px; object-fit: cover; background: #262a35; display: grid; place-items: center; font-size: 40px; color: #3a3f4d; }
.album-tile .t { font-weight: 600; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-tile .a { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-tile:hover .cover { outline: 2px solid var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font: inherit; }
.chip:hover { border-color: var(--accent); }

/* forms */
input, select, textarea { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; line-height: 1.5; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select { color: var(--text); font-size: 15px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: span 2; }
.settings-form { display: grid; gap: 14px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
.icon-btn:disabled { opacity: .3; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.switch { position: relative; width: 40px; height: 22px; flex: none; display: block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 22px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--text); border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); background: #111; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: min(360px, 90vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog .wide { min-width: min(560px, 85vw); }
.login { max-width: 420px; margin: 40px auto; width: 100%; }

/* AI host */
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.svc { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; border-left: 3px solid var(--line); overflow-wrap: anywhere; }
.svc.ok { border-color: var(--ok); }
.svc.bad { border-color: var(--bad); }
.svc span { font-size: 13px; color: var(--muted); }
.topic { padding: 10px 6px !important; }
.topic .a { white-space: normal; }
.seg-foot audio { height: 32px; max-width: 100%; }

/* stats */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--panel-2); border-radius: 10px; padding: 12px; display: grid; }
.tile b { font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; }
.barcol { flex: 1; display: grid; grid-template-rows: 1fr auto; height: 100%; text-align: center; }
.stack-bar { display: flex; flex-direction: column-reverse; justify-content: flex-start; height: 100%; }
.stack-bar span { display: block; border-radius: 3px 3px 0 0; }
.b-trk { background: var(--accent); }
.b-seg { background: var(--wip); }
.barcol small { color: var(--muted); font-size: 11px; margin-top: 4px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; }
.kv { border-collapse: collapse; width: 100%; }
.kv th { text-align: left; font-weight: 500; padding: 4px 0; }
.kv td { text-align: right; font-variant-numeric: tabular-nums; }

/* player bar */
.bar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(23,25,32,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); z-index: 10; }
.bar .thumb { width: 44px; height: 44px; }
.bar-meta { flex: 1; min-width: 0; }
.bar-meta .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-meta .a { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toasts { position: fixed; right: 16px; bottom: 90px; display: grid; gap: 8px; z-index: 20; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 8px;
  opacity: 0; transform: translateY(8px); transition: .25s; max-width: 360px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }

@media (max-width: 800px) {
  .cols, .split { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; padding: 18px; gap: 18px; }
  .art { max-width: 300px; width: 100%; margin: 0 auto; }
  .meta h1 { font-size: 22px; }
  .controls { justify-content: center; }
  .top { padding: 10px 12px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  main { padding: 0 10px 20px; }
  .grid-form { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .actions { opacity: 1; }
  .list .dur { display: none; }
  .reorder li { flex-wrap: wrap; }
  .reorder .grow { flex-basis: calc(100% - 60px); }
  .reorder .actions { width: 100%; justify-content: flex-end; }
  .bars { gap: 3px; }
}
