:root {
	color-scheme: light;
	--bg: #f2f4f8; --card: #fff; --ink: #1a1f2b; --muted: #697386; --line: #e2e6ee;
	--accent: #2a62ff; --accent-ink: #fff; --sel: #eaf0ff; --hover: #f6f8fc;
	--ok: #0f7a56; --ok-bg: #e2f5ec; --warn: #8a5300; --warn-bg: #fff2d9; --bad: #c0281d; --bad-bg: #fde8e6; --info: #2a62ff; --info-bg: #e8eeff;
	--shadow: 0 1px 2px rgba(20,28,45,.06), 0 4px 14px rgba(20,28,45,.05);
	--r: 10px;
	--heat: #2a78d6; /* Popularity meter: the palette's medium blue, tinted toward the card at low values */
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--bg: #0e1117; --card: #161b24; --ink: #e7eaf1; --muted: #8d97ab; --line: #262d3b;
		--accent: #6f96ff; --accent-ink: #0a1020; --sel: #1c2742; --hover: #1a2030;
		--ok: #45d6a0; --ok-bg: #12301f; --warn: #f2b755; --warn-bg: #36280d; --bad: #ff8077; --bad-bg: #3a1714; --info: #8aa9ff; --info-bg: #1b2644;
		--shadow: 0 1px 2px rgba(0,0,0,.4); --heat: #3987e5;
	}
}
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #0e1117; --card: #161b24; --ink: #e7eaf1; --muted: #8d97ab; --line: #262d3b;
	--accent: #6f96ff; --accent-ink: #0a1020; --sel: #1c2742; --hover: #1a2030;
	--ok: #45d6a0; --ok-bg: #12301f; --warn: #f2b755; --warn-bg: #36280d; --bad: #ff8077; --bad-bg: #3a1714; --info: #8aa9ff; --info-bg: #1b2644;
	--shadow: 0 1px 2px rgba(0,0,0,.4); --heat: #3987e5;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
h2, h3, h4, p { margin: 0; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--hover); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.pad { padding: 18px; }
[hidden] { display: none !important; }

/* header: full-width bar, content held to the same 1050px column as the page */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1050px; margin: 0 auto; padding: 8px 18px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: baseline; gap: 2px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: inherit; text-decoration: none; }
.brand .dot { align-self: center; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-right: 8px; box-shadow: 0 0 0 3px var(--info-bg); }
.brand .ro { color: var(--accent); }
.brand.big { font-size: 28px; justify-content: center; margin-bottom: 18px; }
.nav { display: flex; gap: 2px; margin-right: auto; }
.nav a { padding: 6px 11px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a[aria-current] { color: var(--ink); background: var(--sel); }
.top-r { display: flex; align-items: center; gap: 4px; }
.top-r form { margin: 0; }
.banner { background: var(--warn-bg); color: var(--warn); font-size: 13px; border-bottom: 1px solid var(--line); }
.wrap { max-width: 1050px; margin: 0 auto; padding: 9px 18px; }

main { max-width: 1050px; margin: 0 auto; padding: 16px 18px 40px; display: grid; gap: 16px; }
main > * { min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }

/* controls */
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 13px; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
button.danger:hover:not(:disabled) { background: var(--bad-bg); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
button.icon { padding: 5px 9px; font-size: 16px; line-height: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:not([type=checkbox]) { width: 100%; padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
input:not([type=checkbox]):focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); border-color: var(--accent); }
input::placeholder { color: var(--muted); opacity: .8; }

/* login */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(360px, 92vw); }
.login-card { padding: 22px; display: grid; gap: 10px; }
.login-card label { font-weight: 600; font-size: 13px; }
.err { color: var(--bad); background: var(--bad-bg); padding: 7px 10px; border-radius: 8px; font-size: 13px; }

/* list */
.list-tools { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list-tools #q { max-width: 340px; }
.list-tools .muted { white-space: nowrap; font-size: 12px; }
#updated { margin-left: auto; }
.table-wrap { max-height: 420px; /* header + 10 rows */ overflow: auto; border-radius: 0 0 var(--r) var(--r); }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; z-index: 1; background: var(--card); text-align: left; border-bottom: 1px solid var(--line); padding: 0; }
th button { width: 100%; text-align: inherit; background: none; border: 0; border-radius: 0; padding: 9px 12px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
th button:hover { color: var(--ink); background: var(--hover); }
th[aria-sort] button { color: var(--ink); }
th[aria-sort=ascending] button::after { content: " ▲"; font-size: 9px; color: var(--accent); }
th[aria-sort=descending] button::after { content: " ▼"; font-size: 9px; color: var(--accent); }
td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
tbody tr.sel { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.c-name { min-width: 160px; font-weight: 600; }
.c-ch { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-pop { width: 1%; padding-right: 14px; }
.no-pop .c-pop { display: none; }
.heat { display: block; width: 90px; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.heat i { display: block; width: 0; height: 100%; border-radius: 4px; background: color-mix(in srgb, var(--heat) var(--m, 100%), var(--card)); }
.tip { position: fixed; z-index: 20; max-width: 260px; padding: 6px 9px; border-radius: 7px; background: var(--ink); color: var(--bg); font-size: 12.5px; line-height: 1.35; pointer-events: none; box-shadow: var(--shadow); }
.c-np { max-width: 0; width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.ldot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--line); margin-right: 8px; vertical-align: 1px; }
.ldot.off { background: var(--muted); }
.ldot.down { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.ldot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.c-name .sub { display: none; }
.c-no { font-variant-numeric: tabular-nums; white-space: nowrap; }
.c-src { color: var(--muted); }
.c-tv { max-width: 100px; }
.c-lname { max-width: 0; width: 100%; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-lname .sub { display: none; }
tbody tr.off td { opacity: .5; }
tbody tr.off.sel td, tbody tr.off:hover td { opacity: .85; }
.offtag { margin-left: 8px; padding: 0 6px; border-radius: 999px; border: 1px solid var(--line); font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); vertical-align: 1px; }

/* panel */
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-head h2 { font-size: 18px; letter-spacing: -.01em; }
.panel-head #p-close { margin-left: auto; }
.chip { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); }
.chip.on { background: var(--ok-bg); color: var(--ok); }
.panel.is-off .chip { background: var(--warn-bg); color: var(--warn); }
.cols { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 14px; align-items: start; }
.stack { display: grid; gap: 14px; min-width: 0; }
.col { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 0; }
.col-h { display: flex; width: 100%; align-items: center; justify-content: space-between; background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; padding: 11px 14px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: left; cursor: default; }
.col-h:disabled { opacity: 1; }
.col-h .chev { display: none; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .15s; margin-right: 3px; }
.col-b { padding: 14px; }
@media (min-width: 720px) { .col-b.scroll { max-height: 380px; overflow: auto; } }
.col-b h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 0 8px; }
.col-b h3:first-child { margin-top: 0; }
#f label { display: grid; gap: 4px; margin-bottom: 10px; font-size: 12px; font-weight: 600; color: var(--muted); }
#f label input { font-weight: 400; color: var(--ink); font-size: 14px; }
.warn { background: var(--warn-bg); color: var(--warn); padding: 7px 10px; border-radius: 8px; font-size: 12.5px; margin: -4px 0 10px; }
.actions { position: relative; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
button.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
button.ok:hover:not(:disabled) { background: var(--ok-bg); }
.pop { position: absolute; z-index: 5; top: calc(100% + 8px); left: 0; width: min(330px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.28); }
.pop::before { content: ""; position: absolute; top: -6px; left: var(--ax, 120px); width: 10px; height: 10px; background: var(--card); border-left: 1px solid var(--line); border-top: 1px solid var(--line); transform: rotate(45deg); }
.pop-t { font-weight: 700; margin-bottom: 4px; }
.pop-b { color: var(--muted); font-size: 13px; }
.pop-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.pop-actions .primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
#msg { font-size: 13px; color: var(--ok); }
#msg.bad { color: var(--bad); }

.ro-block { margin-top: 20px; padding-top: 14px; border-top: 1px dashed var(--line); }
.ro-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.ro-block h4 { font-size: 12px; margin: 12px 0 5px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* feeds */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed li.empty { color: var(--muted); }
.s-item { display: grid; grid-template-columns: 74px 1fr auto; gap: 4px 10px; align-items: baseline; cursor: default; }
.s-item time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.s-item .t { overflow-wrap: anywhere; }
.s-item .d { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.s-item.now { background: var(--sel); margin: 0 -14px; padding-left: 14px; padding-right: 14px; box-shadow: inset 3px 0 0 var(--accent); }
.s-item.now time { color: var(--accent); font-weight: 700; }
.s-item .tip { grid-column: 2 / -1; color: var(--muted); font-size: 12.5px; }
.s-item.has-tip { cursor: help; }
.player { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; overflow: hidden; }
.player video { display: block; width: 100%; height: 100%; background: #000; }
.vid-play { position: absolute; inset: 0; margin: auto; width: 62px; height: 62px; padding: 0 0 0 5px; border-radius: 50%; border: 0; background: rgba(255,255,255,.88); color: #111; font-size: 24px; line-height: 62px; box-shadow: 0 2px 14px rgba(0,0,0,.45); }
.vid-play:hover:not(:disabled) { background: #fff; }
.vid-play:disabled { background: rgba(255,255,255,.3); color: #555; }
.vid-status { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.vid-status.ok { color: var(--ok); }
.vid-status.bad { color: var(--bad); }
.s-item .syn { grid-column: 2 / -1; color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.s-item.open .syn { display: block; }
.s-item.has-syn { cursor: pointer; }
.expandable { cursor: pointer; }
.more { display: block; margin: 6px 0 -4px; padding: 4px 0; background: none; border: 0; color: var(--accent); font-size: 12.5px; font-weight: 600; }
.more:hover:not(:disabled) { background: none; text-decoration: underline; }
.x-item .t { display: block; overflow-wrap: anywhere; }
.x-item .m { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; color: var(--muted); font-size: 12px; margin-top: 2px; }
.x-item time { font-variant-numeric: tabular-nums; }
.tag { padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--hover); }
.tag.swap { background: var(--info-bg); color: var(--info); }
.tag.complete { background: var(--ok-bg); color: var(--ok); }
.tag.running { background: var(--warn-bg); color: var(--warn); }
.tag.failed { background: var(--bad-bg); color: var(--bad); }

/* dialog + toast */
dialog { border: 1px solid var(--line); border-radius: var(--r); background: var(--card); color: var(--ink); padding: 20px; width: min(440px, 92vw); box-shadow: 0 12px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,14,22,.55); }
dialog h3 { font-size: 16px; margin-bottom: 8px; }
dialog p { color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dlg-actions .primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 92vw; z-index: 10; }

/* narrow: the panel becomes one column and its sections collapse */
@media (max-width: 719px) {
	.cols { grid-template-columns: 1fr; }
	.col-h { cursor: pointer; }
	.col-h .chev { display: block; }
	.col.collapsed .col-h { border-bottom-color: transparent; border-radius: var(--r); }
	.col.collapsed .col-h .chev { transform: rotate(-45deg); }
	.col.collapsed .col-b { display: none; }
}
@media (max-width: 480px) { .top .brand .word, .top .brand .ro { display: none; } .top .brand .dot { margin-right: 2px; } } /* header only: room for three nav links; the login logo keeps its full name */
@media (max-width: 480px) { .actions { gap: 8px; } .actions > button { padding-left: 10px; padding-right: 10px; } } /* Save | Reset | Turn off on one row */
@media (max-width: 700px) {
	main { padding: 12px 10px 32px; }
	.top-in { padding: 8px 10px; gap: 6px; }
	.nav a { padding: 6px 8px; }
	.top-r button.ghost:not(.icon) { padding: 6px 8px; }
	.wrap { padding: 9px 10px; }
	.c-ch, .c-np, .c-pop { display: none; }
	.c-lname .sub { display: block; font-weight: 400; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
	.c-name { min-width: 0; }
	.c-name .sub { display: block; font-weight: 400; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34vw; }
	th button { padding: 9px 7px; letter-spacing: 0; font-size: 11px; }
	td { padding: 8px 8px; }
	#updated { display: none; }
	.list-tools { flex-wrap: wrap; gap: 8px 12px; }
	.list-tools #q { max-width: none; }
	.list-tools #count { flex: 1 1 0; min-width: 0; white-space: normal; }
	.table-wrap { max-height: 584px; } /* header + 10 two-line rows */
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
