:root {
  --bg: #0e1116; --panel: #171b22; --ink: #e6edf3; --muted: #8b949e;
  --accent: #2f81f7; --line: #262c36; --ok: #2ea043;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; }
header h1 { margin: 0 0 4px; font-size: 22px; }
.sub { color: var(--muted); margin: 0 0 18px; }
code { background: #0b0e13; padding: 1px 5px; border-radius: 4px; }
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: #21262d; color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 14px; font-size: 14px;
}
.btn:hover { border-color: #3d444d; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
select, input[type=number] {
  background: #0b0e13; color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 8px; font-size: 14px;
}
.hint, .status { color: var(--muted); font-size: 13px; }
.status { margin-top: 8px; min-height: 20px; }
.manifest { color: var(--accent); font-size: 13px; margin: 10px 0 0; }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; }
.filelist { max-height: 180px; overflow: auto; margin: 12px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.fps { flex-direction: row; align-items: center; gap: 8px; }
.stage { display: flex; justify-content: center; margin-top: 14px; }
#qr { width: min(90vw, 560px); height: auto; image-rendering: pixelated; background: #fff; border-radius: 8px; }

h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .cols { grid-template-columns: 1fr; } }

.textinput { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.textinput input, .textinput textarea {
  background: #0b0e13; color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px; font-size: 13px; font-family: inherit; width: 100%;
}
.textinput textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.textinput .btn { align-self: flex-start; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat {
  background: #0b0e13; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.stat .k { font-size: 11px; color: var(--muted); }
.stat .k em { font-style: normal; opacity: .7; }
.stat .v { font-size: 16px; font-variant-numeric: tabular-nums; }

.entrylist {
  list-style: none; margin: 0; padding: 0; max-height: 220px; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px; background: #0b0e13;
}
.entrylist .muted { padding: 10px 12px; color: var(--muted); font-size: 13px; }
.entry {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  font-size: 12px; border-bottom: 1px solid #1b2027;
}
.entry:last-child { border-bottom: 0; }
.entry .path {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.entry .size { color: var(--muted); font-variant-numeric: tabular-nums; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 10px; white-space: nowrap; }
.tag-binary { background: #4a2a12; color: #f0a868; }
.tag-ignored-dir { background: #33234f; color: #c69bf0; }
.tag-too-large { background: #4a1f24; color: #f08a8a; }
.inline { flex-direction: row; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 12px; }

.rangebox {
  margin-top: 14px; padding: 12px; border: 1px solid var(--line);
  border-radius: 8px; background: #0b0e13;
}
.rangebox h3 { margin-bottom: 8px; }
.rangebox .row { flex-wrap: nowrap; }
.rangebox input[type=text] {
  flex: 1; min-width: 0; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px;
  font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.rangebox select {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px; font-size: 13px; flex: none;
}
.rangebox .hint { margin: 8px 0 0; }
.rangeinfo { font-size: 12px; color: var(--accent); margin: 8px 0 0; min-height: 16px; }
.rangeinfo.bad { color: #f08a8a; }
@media (max-width: 560px) { .rangebox .row { flex-wrap: wrap; } }

.progress { height: 6px; background: #0b0e13; border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }

/* receiver-specific */
.viewport { margin-top: 12px; border-radius: 10px; overflow: hidden; background: #000; }
#video { width: 100%; display: block; }
#grid.grid { display: grid; gap: 3px; margin-top: 12px; }
.cell { aspect-ratio: 1; background: #30363d; border-radius: 2px; }
.cell.got { background: var(--ok); }

/* ---- receiver: file tree, selection & viewer ------------------------------ */
.resultbox { margin-top: 14px; }
.tree {
  margin-top: 10px; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; max-height: 50vh; overflow: auto; font-size: 14px;
}
.tree summary {
  cursor: pointer; display: flex; align-items: center; gap: 7px;
  padding: 3px 4px; border-radius: 6px; list-style: none;
}
.tree summary::before { content: "▾"; color: var(--muted); font-size: 11px; }
.tree details:not([open]) > summary::before { content: "▸"; }
.tree summary:hover { background: #ffffff0d; }
.tree .kids { margin-left: 20px; }
.dirname { user-select: none; font-weight: 600; }
.dirname::before { content: "📁 "; }
.filerow { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 6px; }
.filerow:hover { background: #ffffff0d; }
.filename { cursor: pointer; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.filename:hover { color: var(--accent); text-decoration: underline; }
.filesize { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tree input[type=checkbox] { accent-color: var(--accent); flex: none; }

.viewer {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .65); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 14px;
}
.viewer[hidden] { display: none; }
.viewer-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  width: min(900px, 100%); max-height: 92vh; min-height: 0;
  display: flex; flex-direction: column; overflow: hidden;
}
.viewer-head {
  display: flex; gap: 8px; align-items: center;
  padding: 10px; border-bottom: 1px solid var(--line);
}
.viewer-head span {
  flex: 1; min-width: 0; overflow-wrap: anywhere;
  font-size: 13px; color: var(--muted);
}
.viewer-panel pre {
  margin: 0; padding: 12px; overflow: auto; min-height: 0;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.viewer-panel img { max-width: 100%; max-height: 75vh; object-fit: contain; padding: 12px; }
