:root {
  --bg: #0f1115; --panel: #161920; --panel-2: #1a1d25; --raised: #1d2230; --line: #232731; --line-2: #2c303b;
  --text: #e7e9ee; --text-2: #c3c8d2; --muted: #9aa1ad; --faint: #6f7684;
  --blue: #8fb8ff; --blue-bg: #1f2a3d; --blue-ink: #0d1523; --blue-soft: #cfe0ff;
  --green: #5cc98a; --green-bg: #1d3326; --green-soft: #8fe0b0;
  --amber: #f0a73a; --amber-bg: #3a2a14; --amber-soft: #f5c27a; --amber-ink: #1a1205;
  --purple: #b69cff; --purple-bg: #2a2340; --purple-soft: #d7cbff;
  --pink: #e58fc9; --pink-bg: #3a2236;
  --red: #ff7a6b; --red-bg: #3a1c19;
  --chip: #22252d; --track: #262a33;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f8f9fb; --raised: #e9edf5; --line: #e3e6ec; --line-2: #d6dae2;
    --text: #15171c; --text-2: #343944; --muted: #5d6573; --faint: #858c99;
    --blue: #2f5fd0; --blue-bg: #e6eeff; --blue-ink: #ffffff; --blue-soft: #1f3f8f;
    --green: #1f8a4c; --green-bg: #e2f5ea; --green-soft: #17663a;
    --amber: #b86a00; --amber-bg: #fdf0dc; --amber-soft: #8a4f00; --amber-ink: #ffffff;
    --purple: #6a4fd1; --purple-bg: #eeeaff; --purple-soft: #4b33a8;
    --pink: #b4387f; --pink-bg: #fbe8f3;
    --red: #c4372a; --red-bg: #fde6e3;
    --chip: #eef0f4; --track: #e3e6ec;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 "IBM Plex Sans", system-ui, -apple-system, sans-serif; }
a { color: var(--blue); }
button, input, select { font: inherit; color: inherit; }
.mono, .num { font-family: var(--mono); }

/* layout */
.app { display: flex; flex-wrap: wrap; min-height: 100vh; }
.side { flex: 1 1 220px; max-width: 240px; padding: 20px 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; padding: 6px 10px; margin-bottom: 12px; border-radius: 10px; color: var(--text); text-decoration: none; }
.brand img { border-radius: 7px; flex: none; }
.brand:hover { background: var(--panel-2); }
.brand.on { background: var(--raised); }
.brand .count { margin-left: auto; font-family: var(--mono); font-size: 12px; font-weight: 400; color: var(--muted); }
.brand .count.alert { background: var(--amber); color: var(--amber-ink); border-radius: 10px; padding: 1px 8px; }
.brand .count.run { background: var(--blue); color: var(--blue-ink); border-radius: 10px; padding: 1px 8px; }
.nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; }
.nav:hover { background: var(--panel-2); }
.nav.on { background: var(--raised); color: var(--text); font-weight: 500; }
.nav .count { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.nav .count.alert { background: var(--amber); color: var(--amber-ink); border-radius: 10px; padding: 1px 8px; }
.nav .count.run { background: var(--blue); color: var(--blue-ink); border-radius: 10px; padding: 1px 8px; }
.nav .old { font-size: 11px; color: var(--faint); }
.health { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--green); flex: none; display: inline-block; }
.dot.bad { background: var(--red); } .dot.warn { background: var(--amber); }
.health div { display: flex; align-items: center; gap: 8px; }
main { flex: 999 1 560px; min-width: 0; padding: 24px clamp(16px, 3vw, 36px) 60px; display: flex; flex-direction: column; gap: 22px; max-width: 1240px; }
@media (max-width: 1100px) { .side { flex-basis: 190px; max-width: 200px; } }
/* Phones: one sticky row of sections that scrolls sideways, instead of a sidebar that wraps into a block. */
@media (max-width: 720px) {
  .side { position: sticky; top: 0; z-index: 20; max-width: none; flex-basis: 100%; border-right: none; border-bottom: 1px solid var(--line); background: var(--bg);
    flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 2px; padding: 6px 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .side::-webkit-scrollbar { display: none; }
  .brand { flex: none; margin: 0 4px 0 0; padding: 4px 6px; gap: 6px; }
  .brand-name { display: none; }
  .nav { flex: none; white-space: nowrap; padding: 9px 12px; gap: 6px; }
  .health { display: none; }
  main { padding: 16px 14px 48px; gap: 18px; }
  /* Tables become cards: the main block (title, chips, progress) takes the full width, the small values (size, seeds,
     score, time) sit in a line under it, and the action goes to the right. Column headers are hidden. */
  .scroll-x > div[style*="min-width"] { min-width: 0 !important; }
  .trow { display: flex !important; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 14px; }
  .trow.thead { display: none !important; }
  .trow > * { flex: 0 1 auto; min-width: 0; max-width: 100%; }
  .trow > div:not(.right):not(.chips) { flex: 1 1 100%; }
  .trow > .ellipsis { flex: 1 1 calc(100% - 40px); white-space: normal; overflow-wrap: anywhere; }
  .trow > input[type="checkbox"] { flex: none; }
  .trow > .right, .trow > div.right { margin-left: auto; text-align: right; }
  .trow .ellipsis { white-space: normal; overflow-wrap: anywhere; }
  .trow .small.sub.ellipsis { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a, .tabs button { flex: none; white-space: nowrap; }
}

h1 { margin: 0; font-size: 24px; font-weight: 600; }
h2 { margin: 0; font-size: 15px; font-weight: 600; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.eyebrow.amber { color: var(--amber); } .eyebrow.blue { color: var(--blue); }
.sub { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.back { font-size: 13px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--text-2); }

/* surfaces */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.card { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 16px 18px; }
.pad { padding: 18px; }
.scroll-x { overflow-x: auto; }

/* controls */
.btn { min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2); background: transparent; color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); color: var(--text); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.amber { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); font-weight: 500; }
.btn.small { min-height: 34px; padding: 0 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line-2); }
.seg button, .seg a { min-height: 34px; padding: 0 14px; border-radius: 8px; border: none; background: transparent; color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; text-decoration: none; font-size: 13px; }
.seg .on { background: var(--raised); color: var(--text); font-weight: 500; }
.chipbtn { min-height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line-2); background: transparent; color: var(--text-2); cursor: pointer; font-size: 13px; }
.chipbtn.on { border-color: var(--blue); background: var(--blue-bg); color: var(--blue-soft); }
.search { min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel); flex: 1 1 240px; max-width: 340px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs a, .tabs button { min-height: 44px; padding: 0 14px; border: none; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; cursor: pointer; }
.tabs .on { border-bottom-color: var(--blue); color: var(--text); font-weight: 500; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); min-height: 34px; cursor: pointer; }
.sr { position: absolute; left: -9999px; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.chip { padding: 2px 8px; border-radius: 6px; background: var(--chip); color: var(--text-2); white-space: nowrap; }
.chip.group { background: var(--purple-bg); color: var(--purple-soft); font-weight: 500; }
.chip.blue { background: var(--blue-bg); color: var(--blue); }
.chip.green { background: var(--green-bg); color: var(--green-soft); }
.chip.amber { background: var(--amber-bg); color: var(--amber-soft); }
.chip.red { background: var(--red-bg); color: var(--red); }

/* bars */
.bar { height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 3px; transition: width .6s ease; }
.bar.green > i { background: var(--green); } .bar.amber > i { background: var(--amber); } .bar.purple > i { background: var(--purple); }

/* tables built from grids */
.trow { display: grid; gap: 14px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: none; }
.thead { font-size: 12px; color: var(--muted); padding-top: 10px; padding-bottom: 10px; }
.trow.hl { background: color-mix(in srgb, var(--blue) 8%, var(--panel)); }
.right { text-align: right; justify-self: end; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* episode tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.tile { height: 56px; border-radius: 8px; background: var(--chip); border: 1px solid var(--line-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; cursor: default; position: relative; overflow: hidden; color: var(--text); padding: 0; }
.tile b { font-family: var(--mono); font-weight: 500; font-size: 13px; }
.tile small { font-size: 10px; color: var(--muted); max-width: 100%; padding: 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.missing { background: transparent; border: 1px dashed var(--amber); }
.tile.missing small { color: var(--amber-soft); }
.tile.pick { cursor: pointer; }
.tile.sel { outline: 2px solid var(--text); outline-offset: 1px; }
.tile.up { background: var(--blue-bg); border-color: var(--blue); } .tile.up small { color: var(--blue); }
.tile.fill { background: var(--green-bg); border-color: var(--green); } .tile.fill small { color: var(--green-soft); }
.tile.same { opacity: .55; }
/* live tile states */
.tile.s-downloading small, .tile.s-landed small { color: var(--muted); }
.tile.s-hashing, .tile.s-lookup, .tile.s-matched { background: var(--blue-bg); border-color: color-mix(in srgb, var(--blue) 50%, transparent); }
.tile.s-hashing small, .tile.s-lookup small, .tile.s-matched small { color: var(--blue); }
.tile.s-moved, .tile.s-replaced { background: color-mix(in srgb, var(--green-bg) 70%, var(--panel)); border-color: var(--green); }
.tile.s-moved small, .tile.s-replaced small { color: var(--green-soft); }
.tile.s-plex { background: var(--green-bg); border-color: var(--green-bg); } .tile.s-plex small { color: var(--green-soft); }
.tile .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--blue); transition: width .6s ease; }
.cover { display: grid; gap: 2px; }
.cover span { height: 10px; border-radius: 2px; background: var(--track); }
.cover .up { background: var(--blue); } .cover .fill { background: var(--green); } .cover .same { background: color-mix(in srgb, var(--muted) 45%, transparent); }

/* pipeline */
.pipe { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.pipe li { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pipe .lbl { font-size: 12px; font-weight: 500; }
.pipe .val { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.pipe .val.done { color: var(--green-soft); } .pipe .val.now { color: var(--blue-soft); }
@media (max-width: 720px) { .pipe { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.warn { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--amber-bg); border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent); color: var(--amber-soft); font-size: 13px; }
.log { font-family: var(--mono); font-size: 12px; max-height: 360px; overflow-y: auto; }
.log div { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 10px; padding: 7px 18px; border-bottom: 1px solid var(--line); }
.log time { color: var(--muted); }
.live-dot { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.live-dot .dot { animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live-dot .dot { animation: none; } .bar > i, .tile .prog { transition: none; } }

/* cards on home */
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 6px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--text); }
.stat:hover { border-color: var(--line-2); }
.stat .big { font-family: var(--mono); font-size: 28px; font-weight: 500; }

/* show list */
.poster { width: 44px; height: 62px; border-radius: 6px; background: var(--track); object-fit: cover; flex: none; }
.poster.lg { width: 96px; height: 136px; border-radius: 8px; }
.showrow { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.showrow:hover { background: var(--panel-2); }
.showrow:last-child { border-bottom: none; }

/* dialog */
dialog { border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(4, 5, 8, .72); }
.dlg-head { padding: 22px 24px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.dlg-body { padding: 18px 24px; display: flex; flex-direction: column; gap: 16px; max-height: 60vh; overflow-y: auto; }
.dlg-foot { padding: 16px 24px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); background: var(--bg); }
.counts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.counts div { padding: 12px 14px; border-radius: 10px; background: var(--chip); display: flex; flex-direction: column; gap: 2px; }
.counts b { font-family: var(--mono); font-size: 22px; font-weight: 500; }
.counts .b1 { background: var(--blue-bg); } .counts .b2 { background: var(--green-bg); }
.filelist { border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; font-size: 13px; }
.filelist div { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.filelist div:last-child { border-bottom: none; }
.empty { padding: 28px 18px; color: var(--muted); text-align: center; }
.err { color: var(--red); }
