:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2129;
  --muted: #646a73;
  --line: #e3e5e8;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --warn: #a8670f;
  --warn-bg: #fff6e5;
  --bad: #d64545;
  --soft: #eef3fe;
  --radius: 14px;
  --tabh: 58px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1f2226;
    --text: #e8eaed;
    --muted: #a0a6ad;
    --line: #34383d;
    --accent: #5b8cff;
    --soft: #23304a;
    --warn: #e0a84a;
    --warn-bg: #2e2617;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.wrap {
  max-width: 640px; margin: 0 auto;
  padding: 4px max(16px, env(safe-area-inset-right)) calc(var(--tabh) + 24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* top bar */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.appbar h1 { font-size: 19px; margin: 0; }
.who { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; min-width: 0; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; font-size: 14px; padding: 0 6px; min-height: 44px; cursor: pointer; }
.intro { color: var(--muted); font-size: 14px; margin: 10px 2px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.card h2 { font-size: 17px; margin: 18px 0 8px; }
.card h2:first-child { margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.note { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }
.banner { border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.warn { color: var(--warn); font-size: 14px; margin: 6px 0; }
.banner.warn, .note.warn { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 10px; }
.err { color: var(--bad); font-size: 15px; margin: 6px 0; }

/* file pickers */
.picker {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--line); border-radius: 12px; min-height: 112px; padding: 12px;
  text-align: center; cursor: pointer; position: relative; background: var(--bg);
}
.picker:active { background: var(--soft); }
.picker input[type=file] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.picker .big { font-size: 17px; font-weight: 600; color: var(--accent); }
.picker .small { font-size: 13px; color: var(--muted); }
.picker .preview { display: none; }
.picker.has { border-style: solid; padding: 8px; }
.picker.has .preview { display: block; }
.picker.has .big, .picker.has .small { display: none; }
.preview img, .preview video { display: block; max-width: 100%; max-height: 34vh; margin: 0 auto; border-radius: 8px; background: #000; }
.fileinfo { font-size: 13px; color: var(--muted); margin-top: 6px; word-break: break-all; text-align: center; }

/* choices */
.field { margin: 12px 0; }
.field > label, .field > .label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { flex: 1 1 calc(33% - 8px); min-width: 84px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); font-size: 15px; cursor: pointer; line-height: 1.25;
}
.seg small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.seg input:checked + span { border-color: var(--accent); background: var(--soft); color: var(--accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg input:disabled + span { opacity: .4; }
#lengths label:first-child { flex-basis: 100%; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; font-weight: 600; font-size: 15px; }
.switch input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
input[type=text], input[type=number], textarea {
  width: 100%; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font-family: inherit;
}
input[type=range] { width: 100%; height: 32px; accent-color: var(--accent); }
details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--accent); list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸"; margin-right: 6px; transition: transform .15s; }
details[open] summary::before { transform: rotate(90deg); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  min-height: 50px; border-radius: 12px; border: 0; font-size: 17px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); cursor: pointer; text-decoration: none;
  padding: 0 16px; font-family: inherit; margin-top: 10px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--soft); color: var(--accent); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn.small { min-height: 44px; font-size: 15px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.row > * { flex: 1 1 120px; }

.msg { padding: 10px 12px; border-radius: 10px; font-size: 15px; margin: 10px 0 0; display: none; }
.msg.error { display: block; background: rgba(214, 69, 69, .1); color: var(--bad); }
.msg.info { display: block; background: var(--soft); color: var(--text); }
.bar { display: block; height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.bar > * { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }

/* job list */
.chips { display: flex; gap: 8px; margin: 12px 0 4px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: 1 0 auto; min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
#jobs { margin-top: 8px; }
.job { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 10px 0; overflow: hidden; }
.job .sum {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 10px 10px 10px; min-height: 92px;
  background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.job .sum:active { background: var(--soft); }
.thumb { flex: none; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; background: var(--line); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.line1 { display: flex; align-items: center; gap: 8px; }
.when { font-size: 14px; color: var(--muted); white-space: nowrap; }
.line2 { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line3 { font-size: 14px; font-weight: 600; }
.st-failed .line3 { color: var(--bad); font-weight: 400; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.st-done .line3, .st-cancelled .line3, .st-missing .line3 { font-weight: 400; color: var(--muted); }
.job .bar { margin: 4px 0 2px; height: 6px; }
.chev { flex: none; font-size: 26px; color: var(--muted); transition: transform .15s; line-height: 1; }
.job.open .chev { transform: rotate(90deg); }
.detail { padding: 0 12px 14px; border-top: 1px solid var(--line); }
.detail video { display: block; width: 100%; max-height: 70vh; background: #000; border-radius: 10px; margin: 12px 0 2px; }
.badge { font-size: 13px; padding: 1px 10px; border-radius: 99px; background: var(--soft); color: var(--accent); white-space: nowrap; font-weight: 600; }
.badge.done { background: rgba(31, 157, 85, .14); color: var(--ok); }
.badge.failed, .badge.missing { background: rgba(214, 69, 69, .13); color: var(--bad); }
.badge.cancelled { background: var(--line); color: var(--muted); }
.score { font-size: 14px; background: var(--bg); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.score .num { font-size: 20px; font-weight: 700; }
.segtable { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.segtable td, .segtable th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.empty { color: var(--muted); font-size: 14px; text-align: center; margin: 32px 0; }
ul.tips { padding-left: 20px; margin: 6px 0; font-size: 14px; }
ul.tips li { margin: 4px 0; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 20px; }

/* bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tab {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: var(--tabh); background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; gap: 0;
}
.tab .ico { font-size: 20px; line-height: 1.1; }
.tab.on { color: var(--accent); font-weight: 600; }
.tab .count {
  position: absolute; top: 5px; left: calc(50% + 10px); min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabh) + 16px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, .82); color: #fff; padding: 10px 20px; border-radius: 99px; font-size: 15px;
  max-width: calc(100% - 32px); text-align: center;
}

/* login page */
.login { max-width: 400px; margin: 10vh auto 0; }
.login .field input { min-height: 48px; }
.login .btn { margin-top: 12px; }

/* input source choice: upload a new file or pick one from the library */
.src { display: flex; gap: 8px; margin: 0 0 8px; }
.srcbtn {
  flex: 1 1 0; min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--accent); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px 8px;
}
.srcbtn:active { background: var(--soft); }
.preview video[poster] { object-fit: contain; }
body.noscroll { overflow: hidden; }

/* library sheet: full screen on phones, a centred panel on wide screens */
.sheetbg {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; height: 100%;
  display: flex; flex-direction: column; overflow: hidden;
  padding-top: env(safe-area-inset-top);
}
@media (min-width: 700px) {
  .sheet { height: 88vh; border-radius: 16px 16px 0 0; }
}
.sheethead {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.sheethead h2 { font-size: 18px; margin: 0; }
.sheetbg .chips { margin: 6px 16px 0; }
.sheetbg .note { margin: 8px 16px 0; }
.sheetbody { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 8px 16px 16px; }
.sheetfoot {
  border-top: 1px solid var(--line); background: var(--card);
  padding: 0 max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.libgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 520px) { .libgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { position: relative; min-width: 0; display: flex; flex-direction: column; }
.tile .pick {
  position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; border: 3px solid transparent;
  border-radius: 12px; overflow: hidden; background: var(--line); cursor: pointer;
}
.tile .pick img, .tile .pick video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.on .pick { border-color: var(--accent); }
.tile .dur {
  position: absolute; right: 4px; bottom: 4px; z-index: 2; background: rgba(0, 0, 0, .7); color: #fff;
  font-size: 12px; line-height: 1; padding: 4px 6px; border-radius: 6px;
}
.tile .tick {
  position: absolute; left: 4px; top: 4px; z-index: 2; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 16px; line-height: 26px; text-align: center; display: none;
}
.tile.on .tick { display: block; }
.tmeta { display: flex; flex-direction: column; min-width: 0; margin-top: 3px; }
.tname { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tsub { font-size: 11px; color: var(--muted); }
.tdel {
  align-self: stretch; min-height: 36px; margin-top: 2px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--bad); font: inherit; font-size: 13px; cursor: pointer;
}
.tdel:disabled { opacity: .5; }

.btn.busy { opacity: .75; pointer-events: none; }
.dlprog { margin: 8px 0; }
.dlprog .bar { margin: 0 0 6px; }
