dehezhang2 commited on
Commit
f781a57
·
verified ·
1 Parent(s): eb4149f

deploy rater (Docker/FastAPI): registration + completeness gate + /api/submit → dataset

Browse files
Files changed (2) hide show
  1. static/index.html +96 -3
  2. static/mobile.html +1231 -0
static/index.html CHANGED
@@ -66,6 +66,12 @@
66
 
67
  /* ---------- main layout ---------- */
68
  main { flex: 1; display: flex; min-height: 0; }
 
 
 
 
 
 
69
  aside.list { width: 240px; border-right: 1px solid var(--border); background: var(--panel);
70
  overflow-y: auto; flex-shrink: 0; }
71
  .list-header { padding: 10px 14px; font-size: 11px; color: var(--muted);
@@ -209,9 +215,17 @@
209
  /* Long prompts: cap their height so the sticky block doesn't eat the viewport;
210
  prompt scrolls inside its own box. */
211
  .prompt-box { max-height: 6em; overflow-y: auto; }
 
 
 
 
 
 
 
 
212
 
213
  /* ---------- footer / nav ---------- */
214
- footer.bottom { position: fixed; bottom: 0; left: 240px; right: 0;
215
  background: var(--panel); border-top: 1px solid var(--border);
216
  padding: 10px 24px; display: flex; gap: 12px; align-items: center;
217
  z-index: 10; }
@@ -1385,7 +1399,14 @@ function renderShell() {
1385
  function renderHeader() {
1386
  // Title + subtitle removed per request — only the progress bar remains in
1387
  // the top strip. The header keeps `class="top"` for spacing / borders.
 
1388
  return el("header", { class: "top" },
 
 
 
 
 
 
1389
  el("div", { class: "progress" },
1390
  el("div", { class: "progress-bar" },
1391
  el("div", { class: "progress-fill", id: "progressFill" })),
@@ -1394,6 +1415,16 @@ function renderHeader() {
1394
  );
1395
  }
1396
 
 
 
 
 
 
 
 
 
 
 
1397
  function renderLangSelect() {
1398
  const sel = el("select", {
1399
  title: t("lang_label"),
@@ -1558,6 +1589,13 @@ function renderSidebar() {
1558
  function renderFooter() {
1559
  return el("footer", { class: "bottom" },
1560
  el("div", { class: "summary", id: "footerSummary" }),
 
 
 
 
 
 
 
1561
  el("div", { class: "nav-btns" },
1562
  el("button", { class: "btn", onclick: () => step(-1) }, t("prev")),
1563
  el("button", { class: "btn", onclick: () => step(1) }, t("next")),
@@ -1579,12 +1617,19 @@ function renderDetail() {
1579
  const c = CASES[currentIdx];
1580
  // Prompt + videos + controls float together at the top of the scrolling
1581
  // detail pane so the rater always has them in view while scrolling rows.
1582
- const sticky = el("div", { class: "sticky-top" });
1583
  sticky.appendChild(renderCaseHeader(c));
1584
  sticky.appendChild(renderVideoGrid(c));
1585
  sticky.appendChild(renderVideoControls(c));
1586
  detail.appendChild(sticky);
1587
  detail.appendChild(renderRatingsTable(c));
 
 
 
 
 
 
 
1588
 
1589
  // Update sidebar active row + footer
1590
  document.querySelectorAll(".case-row").forEach((row, i) => {
@@ -1593,6 +1638,44 @@ function renderDetail() {
1593
  updateFooterSummary();
1594
  }
1595
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1596
  function renderInstructions(forceOpen) {
1597
  const det = el("details", { class: "instructions" });
1598
  if (forceOpen) det.setAttribute("open", "");
@@ -1830,11 +1913,14 @@ function renderLikertCell(caseObj, slotIdx, qkey) {
1830
  const cell = el("td", { class: "rate-cell" });
1831
  const inner = el("div", { class: "cell-inner" });
1832
 
 
 
 
1833
  const chip = el("span", {
1834
  class: "slot-chip",
1835
  title: anonymize ? t("video_label_anon", letter)
1836
  : t("video_label_revealed", letter, video.model),
1837
- }, anonymize ? letter : `${letter} · ${video.model}`);
1838
  inner.appendChild(chip);
1839
 
1840
  const group = el("div", { class: "likert" });
@@ -2330,6 +2416,13 @@ function migrateLegacyRatingsV1(legacy, allCases) {
2330
  // Non-admins always see anonymized view — they can't toggle.
2331
  if (!isAdmin()) anonymize = true;
2332
 
 
 
 
 
 
 
 
2333
  buildShuffle(CASES);
2334
  saveState();
2335
 
 
66
 
67
  /* ---------- main layout ---------- */
68
  main { flex: 1; display: flex; min-height: 0; }
69
+ /* Sidebar can be collapsed via the toolbar button. Footer.bottom uses
70
+ --sidebar-w so it sits flush against the sidebar when expanded, or
71
+ covers the full width when collapsed. */
72
+ :root { --sidebar-w: 240px; }
73
+ body.sidebar-collapsed { --sidebar-w: 0px; }
74
+ body.sidebar-collapsed aside.list { display: none; }
75
  aside.list { width: 240px; border-right: 1px solid var(--border); background: var(--panel);
76
  overflow-y: auto; flex-shrink: 0; }
77
  .list-header { padding: 10px 14px; font-size: 11px; color: var(--muted);
 
215
  /* Long prompts: cap their height so the sticky block doesn't eat the viewport;
216
  prompt scrolls inside its own box. */
217
  .prompt-box { max-height: 6em; overflow-y: auto; }
218
+ /* Dimension row inside the ratings table is also sticky — it sits just
219
+ below the sticky-top region so the rater always sees which dimension
220
+ they're rating while scrolling rows. --sticky-top-h is published by a
221
+ ResizeObserver since the top region's height varies per case (prompt
222
+ length, 2 vs 3 videos, etc.). */
223
+ .ratings-table .dim-row { position: sticky;
224
+ top: var(--sticky-top-h, 0); z-index: 4; }
225
+ .ratings-table .dim-row td { background: var(--panel-2); }
226
 
227
  /* ---------- footer / nav ---------- */
228
+ footer.bottom { position: fixed; bottom: 0; left: var(--sidebar-w); right: 0;
229
  background: var(--panel); border-top: 1px solid var(--border);
230
  padding: 10px 24px; display: flex; gap: 12px; align-items: center;
231
  z-index: 10; }
 
1399
  function renderHeader() {
1400
  // Title + subtitle removed per request — only the progress bar remains in
1401
  // the top strip. The header keeps `class="top"` for spacing / borders.
1402
+ const collapsed = document.body.classList.contains("sidebar-collapsed");
1403
  return el("header", { class: "top" },
1404
+ el("button", {
1405
+ class: "btn ghost",
1406
+ style: "padding:4px 10px;font-size:16px;line-height:1",
1407
+ title: collapsed ? "Show cases sidebar" : "Hide cases sidebar",
1408
+ onclick: toggleSidebar,
1409
+ }, collapsed ? "›" : "‹"),
1410
  el("div", { class: "progress" },
1411
  el("div", { class: "progress-bar" },
1412
  el("div", { class: "progress-fill", id: "progressFill" })),
 
1415
  );
1416
  }
1417
 
1418
+ function toggleSidebar() {
1419
+ document.body.classList.toggle("sidebar-collapsed");
1420
+ try {
1421
+ localStorage.setItem("user_study_sidebar_collapsed",
1422
+ document.body.classList.contains("sidebar-collapsed") ? "1" : "0");
1423
+ } catch (e) { /* ignore */ }
1424
+ // Re-render header so the chevron + tooltip flip; everything else is CSS.
1425
+ renderShell();
1426
+ }
1427
+
1428
  function renderLangSelect() {
1429
  const sel = el("select", {
1430
  title: t("lang_label"),
 
1589
  function renderFooter() {
1590
  return el("footer", { class: "bottom" },
1591
  el("div", { class: "summary", id: "footerSummary" }),
1592
+ el("a", {
1593
+ href: "./mobile.html",
1594
+ style: "font-size:11px;color:var(--muted);text-decoration:none;"
1595
+ + "padding:4px 10px;border:1px solid var(--border);border-radius:12px;"
1596
+ + "background:var(--panel-3);margin-right:8px",
1597
+ title: "switch to the phone-optimized layout",
1598
+ }, "📱 Mobile"),
1599
  el("div", { class: "nav-btns" },
1600
  el("button", { class: "btn", onclick: () => step(-1) }, t("prev")),
1601
  el("button", { class: "btn", onclick: () => step(1) }, t("next")),
 
1617
  const c = CASES[currentIdx];
1618
  // Prompt + videos + controls float together at the top of the scrolling
1619
  // detail pane so the rater always has them in view while scrolling rows.
1620
+ const sticky = el("div", { class: "sticky-top", id: "stickyTop" });
1621
  sticky.appendChild(renderCaseHeader(c));
1622
  sticky.appendChild(renderVideoGrid(c));
1623
  sticky.appendChild(renderVideoControls(c));
1624
  detail.appendChild(sticky);
1625
  detail.appendChild(renderRatingsTable(c));
1626
+ // Publish the sticky-top region's height so .dim-row can stick below it.
1627
+ // ResizeObserver keeps the offset in sync as the prompt collapses, videos
1628
+ // load, or the window resizes.
1629
+ observeStickyTop(sticky);
1630
+ bindAutoCollapseInstructions();
1631
+ detail.__resetAutoCollapse?.();
1632
+ detail.scrollTop = 0;
1633
 
1634
  // Update sidebar active row + footer
1635
  document.querySelectorAll(".case-row").forEach((row, i) => {
 
1638
  updateFooterSummary();
1639
  }
1640
 
1641
+ // Track the height of the sticky-top region and publish it as a CSS variable
1642
+ // so .dim-row inside the ratings table can stick just below it.
1643
+ let _STICKY_RO = null;
1644
+ function observeStickyTop(node) {
1645
+ if (_STICKY_RO) { _STICKY_RO.disconnect(); _STICKY_RO = null; }
1646
+ const update = () => {
1647
+ document.documentElement.style.setProperty(
1648
+ "--sticky-top-h", node.offsetHeight + "px");
1649
+ };
1650
+ update();
1651
+ if (typeof ResizeObserver !== "undefined") {
1652
+ _STICKY_RO = new ResizeObserver(update);
1653
+ _STICKY_RO.observe(node);
1654
+ } else {
1655
+ window.addEventListener("resize", update, { passive: true });
1656
+ }
1657
+ }
1658
+
1659
+ // Once per case visit: auto-collapse the instructions panel as soon as the
1660
+ // user scrolls past it. Keeps the rubric out of the way once they start
1661
+ // scrolling through rating rows. The user can manually re-expand the panel
1662
+ // at any time — we only auto-close, never auto-open.
1663
+ function bindAutoCollapseInstructions() {
1664
+ const detail = document.getElementById("detail");
1665
+ if (!detail || detail.__autoCollapseBound) return;
1666
+ detail.__autoCollapseBound = true;
1667
+ let closed = false;
1668
+ detail.addEventListener("scroll", () => {
1669
+ if (closed) return;
1670
+ if (detail.scrollTop > 80) {
1671
+ const ins = detail.querySelector("details.instructions[open]");
1672
+ if (ins) { ins.removeAttribute("open"); closed = true; }
1673
+ }
1674
+ }, { passive: true });
1675
+ // Reset the once-per-case flag whenever a new case is rendered.
1676
+ detail.__resetAutoCollapse = () => { closed = false; };
1677
+ }
1678
+
1679
  function renderInstructions(forceOpen) {
1680
  const det = el("details", { class: "instructions" });
1681
  if (forceOpen) det.setAttribute("open", "");
 
1913
  const cell = el("td", { class: "rate-cell" });
1914
  const inner = el("div", { class: "cell-inner" });
1915
 
1916
+ // Chip text is always just the slot letter — even in admin mode the model
1917
+ // name is redundant here (it's already on the video tile above and in the
1918
+ // chip's tooltip for hover/long-press).
1919
  const chip = el("span", {
1920
  class: "slot-chip",
1921
  title: anonymize ? t("video_label_anon", letter)
1922
  : t("video_label_revealed", letter, video.model),
1923
+ }, letter);
1924
  inner.appendChild(chip);
1925
 
1926
  const group = el("div", { class: "likert" });
 
2416
  // Non-admins always see anonymized view — they can't toggle.
2417
  if (!isAdmin()) anonymize = true;
2418
 
2419
+ // Restore sidebar collapse state.
2420
+ try {
2421
+ if (localStorage.getItem("user_study_sidebar_collapsed") === "1") {
2422
+ document.body.classList.add("sidebar-collapsed");
2423
+ }
2424
+ } catch (e) { /* ignore */ }
2425
+
2426
  buildShuffle(CASES);
2427
  saveState();
2428
 
static/mobile.html ADDED
@@ -0,0 +1,1231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport"
6
+ content="width=device-width, initial-scale=1.0, viewport-fit=cover">
7
+ <meta name="theme-color" content="#0f1115">
8
+ <title>Video user study — mobile</title>
9
+ <style>
10
+ :root {
11
+ --bg: #0f1115;
12
+ --panel: #161922;
13
+ --panel-2: #1c2030;
14
+ --panel-3: #232839;
15
+ --border: #2a2f42;
16
+ --border-strong: #3a4060;
17
+ --fg: #e6e8ef;
18
+ --muted: #8b91a8;
19
+ --muted-2: #5e6480;
20
+ --accent: #6aa9ff;
21
+ --accent-strong: #8ec0ff;
22
+ --good: #28c76f;
23
+ --warn: #ff9f43;
24
+ --bad: #ea5455;
25
+ --score-1: #ea5455;
26
+ --score-2: #ff7d52;
27
+ --score-3: #ffa84a;
28
+ --score-4: #8acf6d;
29
+ --score-5: #28c76f;
30
+ --safe-bot: env(safe-area-inset-bottom, 0px);
31
+ --bar-h: 56px;
32
+ }
33
+ * { box-sizing: border-box; }
34
+ html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg);
35
+ font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC",
36
+ "Microsoft YaHei", sans-serif;
37
+ font-size: 15px; line-height: 1.4;
38
+ -webkit-tap-highlight-color: transparent;
39
+ overscroll-behavior-y: contain; }
40
+
41
+ /* ---------- top header ---------- */
42
+ header.top { position: sticky; top: 0; z-index: 50;
43
+ background: var(--panel); border-bottom: 1px solid var(--border);
44
+ padding: 8px 12px; padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
45
+ display: flex; align-items: center; gap: 8px; }
46
+ header.top .title { font-weight: 600; font-size: 14px; flex: 1;
47
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
48
+ header.top .pill { font-size: 11px; padding: 3px 8px; border-radius: 10px;
49
+ background: var(--panel-3); color: var(--muted); white-space: nowrap;
50
+ font-family: ui-monospace, monospace; border: 1px solid var(--border); }
51
+ header.top .pill[data-state="idle"] { background:#1f2a44; color: var(--accent); border-color:#3a4a78; }
52
+ header.top .pill[data-state="submitting"] { background:#1f2a44; color: var(--accent); border-color:#3a4a78; }
53
+ header.top .pill[data-state="submitted"] { background:#1c3422; color: var(--good); border-color:#2a5a37; }
54
+ header.top .pill[data-state="local-only"] { background:#3a3520; color: var(--warn); border-color:#5a4a25; }
55
+ header.top .pill[data-state="error"] { background:#3a2020; color: var(--bad); border-color:#5a2828; }
56
+ header.top button.icon { background: transparent; border: none; color: var(--fg);
57
+ font-size: 22px; padding: 4px 8px; cursor: pointer; line-height: 1; }
58
+ header.top select { background: var(--panel-3); border: 1px solid var(--border);
59
+ color: var(--fg); padding: 4px 6px; border-radius: 4px; font-size: 12px;
60
+ font-family: inherit; }
61
+
62
+ /* ---------- progress strip ---------- */
63
+ .case-strip { position: sticky; top: 56px; z-index: 40;
64
+ background: var(--panel); border-bottom: 1px solid var(--border);
65
+ padding: 6px 12px; display: flex; align-items: center; gap: 8px;
66
+ font-size: 12px; color: var(--muted); }
67
+ .case-strip .case-id { color: var(--fg); font-weight: 600;
68
+ font-family: ui-monospace, monospace; }
69
+ .case-strip .bar { flex: 1; height: 4px; background: var(--panel-3); border-radius: 2px;
70
+ overflow: hidden; }
71
+ .case-strip .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--good));
72
+ transition: width 0.2s; }
73
+ .case-strip button.jumper { background: var(--panel-3); border: 1px solid var(--border);
74
+ color: var(--fg); padding: 4px 10px; border-radius: 4px;
75
+ font-size: 12px; font-family: inherit; cursor: pointer; }
76
+
77
+ /* ---------- main scroll content ---------- */
78
+ main { padding: 8px 12px calc(var(--bar-h) + var(--safe-bot) + 24px); }
79
+
80
+ /* prompt */
81
+ .prompt-card { background: var(--panel); border: 1px solid var(--border);
82
+ border-radius: 8px; padding: 10px 12px; margin-bottom: 10px;
83
+ font-size: 14px; line-height: 1.6; }
84
+ .prompt-card .label { font-size: 10px; color: var(--muted); letter-spacing: 0.5px;
85
+ text-transform: uppercase; margin-bottom: 4px; }
86
+ .prompt-card details summary { cursor: pointer; user-select: none;
87
+ list-style: none; color: var(--muted); font-size: 13px; }
88
+ .prompt-card details summary::before { content: '▸ '; }
89
+ .prompt-card details[open] summary::before { content: '▾ '; }
90
+ .prompt-card details[open] summary { margin-bottom: 6px; }
91
+ .prompt-card .ref-img { max-width: 100%; max-height: 200px; border-radius: 6px;
92
+ border: 1px solid var(--border); display: block; margin-top: 8px; }
93
+
94
+ /* videos */
95
+ .video-stack { display: flex; flex-direction: column; gap: 10px;
96
+ margin-bottom: 14px; }
97
+ .video-tile { position: relative; }
98
+ .video-tile .slot-label { font-size: 12px; color: var(--muted);
99
+ font-family: ui-monospace, monospace; display: flex; align-items: center;
100
+ gap: 8px; margin-bottom: 4px; }
101
+ .video-tile .slot-letter { display: inline-flex; align-items: center;
102
+ justify-content: center; width: 24px; height: 24px; border-radius: 4px;
103
+ background: var(--panel-3); color: var(--fg); font-weight: 700;
104
+ font-size: 13px; border: 1px solid var(--border-strong); }
105
+ .video-frame { position: relative; background: #000; border: 1px solid var(--border);
106
+ border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; }
107
+ .video-frame video { width: 100%; height: 100%; display: block; background: #000; }
108
+ .video-frame .empty-state { position: absolute; inset: 0; display: flex;
109
+ flex-direction: column; align-items: center; justify-content: center;
110
+ background: repeating-linear-gradient(45deg, #1a1d28 0 10px, #16191f 10px 20px);
111
+ color: var(--muted); font-size: 12px; gap: 4px; text-align: center;
112
+ padding: 12px; }
113
+
114
+ /* video controls */
115
+ .video-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
116
+ background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
117
+ padding: 8px 10px; margin-bottom: 14px; font-size: 12px; }
118
+ .video-controls button { background: var(--panel-3); border: 1px solid var(--border-strong);
119
+ color: var(--fg); padding: 8px 12px; border-radius: 6px; font-size: 13px;
120
+ font-family: inherit; min-height: 36px; cursor: pointer; }
121
+ .video-controls button.on { background: var(--accent); color: #0a1a2a; border-color: var(--accent); }
122
+ .video-controls select { background: var(--panel-3); border: 1px solid var(--border);
123
+ color: var(--fg); padding: 6px 8px; border-radius: 4px; font-size: 13px;
124
+ font-family: inherit; margin-left: auto; }
125
+
126
+ /* dimension + question cards. .dim-header is sticky just below the top
127
+ header + case-strip so the rater always sees which dimension they're
128
+ rating while scrolling the question cards. The 96px offset matches
129
+ header.top (~56px) + .case-strip (~40px). */
130
+ .dim-header { position: sticky; top: 96px; z-index: 30;
131
+ background: var(--bg); margin: 16px -12px 6px; padding: 6px 12px 6px;
132
+ border-bottom: 1px solid var(--border);
133
+ font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
134
+ color: var(--accent-strong); font-weight: 700;
135
+ display: flex; align-items: baseline; gap: 8px; }
136
+ .dim-header .dim-hint { font-size: 11px; color: var(--muted); font-weight: 400;
137
+ text-transform: none; letter-spacing: 0; }
138
+ .q-card { background: var(--panel); border: 1px solid var(--border);
139
+ border-radius: 8px; padding: 12px; margin-bottom: 10px; }
140
+ .q-card .q-name { font-size: 15px; font-weight: 600; color: var(--fg);
141
+ margin-bottom: 2px; }
142
+ .q-card .q-desc { font-size: 12px; color: var(--muted); margin-bottom: 10px;
143
+ line-height: 1.5; }
144
+ .q-card .video-rate { display: flex; align-items: center; gap: 8px;
145
+ padding: 6px 0; }
146
+ .q-card .video-rate + .video-rate { border-top: 1px solid var(--border); }
147
+ .q-card .video-rate .slot-letter { min-width: 28px; height: 28px;
148
+ display: inline-flex; align-items: center; justify-content: center;
149
+ border-radius: 4px; background: var(--panel-3); color: var(--fg);
150
+ font-weight: 700; font-size: 13px; font-family: ui-monospace, monospace;
151
+ border: 1px solid var(--border-strong); flex-shrink: 0; }
152
+ .q-card .likert { display: flex; gap: 4px; flex: 1; justify-content: space-between; }
153
+ .q-card .likert button { flex: 1; min-height: 42px; min-width: 0;
154
+ border: 1px solid var(--border); background: var(--panel-3); color: var(--fg);
155
+ border-radius: 6px; font-family: inherit; font-size: 14px; font-weight: 500;
156
+ cursor: pointer; }
157
+ .q-card .likert button.selected { font-weight: 700; color: #0a1a0a;
158
+ border-color: rgba(255,255,255,0.2); }
159
+ .q-card .likert button.selected[data-score="1"] { background: var(--score-1); }
160
+ .q-card .likert button.selected[data-score="2"] { background: var(--score-2); }
161
+ .q-card .likert button.selected[data-score="3"] { background: var(--score-3); }
162
+ .q-card .likert button.selected[data-score="4"] { background: var(--score-4); }
163
+ .q-card .likert button.selected[data-score="5"] { background: var(--score-5); }
164
+
165
+ /* bottom fixed action bar */
166
+ footer.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
167
+ background: var(--panel); border-top: 1px solid var(--border);
168
+ padding: 8px 10px calc(8px + var(--safe-bot));
169
+ display: grid; grid-template-columns: 1fr 1fr auto 1fr 1fr; gap: 6px;
170
+ height: calc(var(--bar-h) + var(--safe-bot)); align-items: center; }
171
+ footer.bottom button { background: var(--panel-3); border: 1px solid var(--border-strong);
172
+ color: var(--fg); padding: 0; height: 40px; border-radius: 6px;
173
+ font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
174
+ footer.bottom .submit-btn { background: var(--good); color: #0a1a0a;
175
+ border-color: var(--good); font-weight: 700; }
176
+ footer.bottom .submit-btn:disabled { background: var(--panel-3); color: var(--muted-2);
177
+ border-color: var(--border); font-weight: 500; }
178
+ footer.bottom .top-btn { font-size: 18px; }
179
+
180
+ /* slide-in drawer (case list) */
181
+ .drawer-backdrop { position: fixed; inset: 0; background: rgba(8,10,16,0.7);
182
+ z-index: 60; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
183
+ .drawer-backdrop.open { opacity: 1; pointer-events: auto; }
184
+ .drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 86%;
185
+ max-width: 360px; background: var(--panel); border-left: 1px solid var(--border);
186
+ z-index: 61; transform: translateX(100%); transition: transform 0.22s ease;
187
+ display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); }
188
+ .drawer.open { transform: translateX(0); }
189
+ .drawer header { padding: 12px 14px; border-bottom: 1px solid var(--border);
190
+ display: flex; align-items: center; justify-content: space-between;
191
+ font-weight: 600; }
192
+ .drawer .list { flex: 1; overflow-y: auto; padding: 4px 0; }
193
+ .drawer .case-row { padding: 12px 14px; border-bottom: 1px solid var(--border);
194
+ display: flex; align-items: center; gap: 10px; }
195
+ .drawer .case-row.active { background: var(--panel-2);
196
+ border-left: 3px solid var(--accent); padding-left: 11px; }
197
+ .drawer .case-row .dot { width: 9px; height: 9px; border-radius: 50%;
198
+ background: var(--muted-2); flex-shrink: 0; }
199
+ .drawer .case-row.partial .dot { background: var(--warn); }
200
+ .drawer .case-row.complete .dot { background: var(--good); }
201
+ .drawer .case-row .id { flex: 1; font-family: ui-monospace, monospace;
202
+ font-size: 13px; }
203
+ .drawer .case-row .pct { font-size: 11px; color: var(--muted); }
204
+
205
+ /* registration overlay (re-used from desktop) */
206
+ .overlay { position: fixed; inset: 0; background: rgba(8,10,16,0.84);
207
+ backdrop-filter: blur(4px); display: flex; align-items: center;
208
+ justify-content: center; z-index: 100; padding: 14px; }
209
+ .overlay.hidden { display: none; }
210
+ .reg-card { background: var(--panel); border: 1px solid var(--border-strong);
211
+ border-radius: 10px; padding: 18px 18px 16px; max-width: 420px; width: 100%; }
212
+ .reg-card h2 { margin: 0 0 4px; font-size: 17px; }
213
+ .reg-card .lead { color: var(--muted); font-size: 13px; line-height: 1.6;
214
+ margin: 0 0 14px; }
215
+ .reg-card label { display: block; font-size: 11px; text-transform: uppercase;
216
+ letter-spacing: 0.5px; color: var(--muted); margin: 10px 0 4px; }
217
+ .reg-card input, .reg-card textarea { width: 100%; background: var(--panel-3);
218
+ border: 1px solid var(--border); color: var(--fg); padding: 10px;
219
+ border-radius: 6px; font-family: inherit; font-size: 16px; /* 16 ≥ iOS no-zoom */ }
220
+ .reg-card textarea { min-height: 50px; resize: vertical; font-size: 14px; }
221
+ .reg-card .err { color: var(--bad); font-size: 12px; min-height: 14px;
222
+ margin-top: 6px; }
223
+ .reg-card .top-row { display: flex; align-items: center;
224
+ justify-content: space-between; margin-bottom: 8px; gap: 12px; }
225
+ .reg-card select { background: var(--panel-3); border: 1px solid var(--border);
226
+ color: var(--fg); padding: 4px 6px; border-radius: 4px; font-size: 12px;
227
+ font-family: inherit; }
228
+ .reg-card .go-btn { width: 100%; background: var(--accent); color: #0a1a2a;
229
+ border: 1px solid var(--accent); padding: 12px; border-radius: 8px;
230
+ font-weight: 700; font-size: 15px; cursor: pointer; margin-top: 14px; }
231
+
232
+ /* submitted overlay */
233
+ .submitted-card { background: var(--panel); border: 1px solid var(--good);
234
+ border-radius: 10px; padding: 22px; max-width: 420px; width: 100%;
235
+ text-align: center; }
236
+ .submitted-card .check { font-size: 44px; color: var(--good); }
237
+ .submitted-card h2 { margin: 8px 0 4px; font-size: 17px; }
238
+ .submitted-card p { color: var(--muted); font-size: 13px; margin: 4px 0;
239
+ line-height: 1.6; }
240
+ .submitted-card code { background: var(--panel-3); padding: 2px 6px;
241
+ border-radius: 3px; font-size: 11px; color: var(--accent-strong);
242
+ word-break: break-all; }
243
+ .submitted-card .btn { background: var(--panel-3); border: 1px solid var(--border-strong);
244
+ color: var(--fg); padding: 10px 14px; border-radius: 6px; font-size: 14px;
245
+ font-family: inherit; margin-top: 12px; cursor: pointer; min-width: 100px; }
246
+
247
+ /* toast */
248
+ .toast { position: fixed; bottom: calc(var(--bar-h) + var(--safe-bot) + 14px);
249
+ left: 12px; right: 12px; background: var(--good); color: #0a1a0a;
250
+ padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
251
+ text-align: center; opacity: 0; transition: opacity 0.2s;
252
+ z-index: 90; pointer-events: none; }
253
+ .toast.show { opacity: 1; }
254
+ .toast.error { background: var(--bad); color: #fff; }
255
+
256
+ /* desktop switch link */
257
+ .desktop-link { font-size: 11px; color: var(--muted); text-decoration: none;
258
+ padding: 4px 8px; border: 1px solid var(--border); border-radius: 12px;
259
+ background: var(--panel-3); }
260
+ .desktop-link:hover { color: var(--fg); }
261
+
262
+ /* admin / submitted badges */
263
+ .badge { display: inline-flex; align-items: center; padding: 2px 8px;
264
+ border-radius: 10px; font-size: 10px; font-weight: 700; }
265
+ .badge.admin { background: #3a2f60; color: #d9b6ff; border: 1px solid #5a4080; }
266
+ .badge.submitted { background: #1c3422; color: var(--good); border: 1px solid #2a5a37; }
267
+
268
+ /* shut down landscape if it gets weird */
269
+ @media (orientation: landscape) and (max-height: 460px) {
270
+ header.top { padding: 4px 12px; }
271
+ .case-strip { top: 44px; padding: 4px 12px; }
272
+ main { padding-top: 6px; }
273
+ }
274
+
275
+ kbd { background: var(--panel-3); border: 1px solid var(--border-strong);
276
+ border-radius: 3px; padding: 1px 4px; font-family: ui-monospace, monospace;
277
+ font-size: 11px; }
278
+ </style>
279
+ </head>
280
+ <body>
281
+
282
+ <!-- ============ Top bar ============ -->
283
+ <header class="top" id="topBar">
284
+ <button class="icon" id="drawerBtn" title="Cases">☰</button>
285
+ <span class="title" id="topTitle">Video user study</span>
286
+ <span class="pill" id="syncPill" data-state="idle">●</span>
287
+ <select id="langSelect" title="Language"></select>
288
+ </header>
289
+
290
+ <div class="case-strip" id="caseStrip">
291
+ <span class="case-id" id="caseId">—</span>
292
+ <span id="caseCounter">—</span>
293
+ <div class="bar"><div class="fill" id="progressFill" style="width:0%"></div></div>
294
+ <span id="progressTxt">0/0</span>
295
+ </div>
296
+
297
+ <main id="main">
298
+ <!-- prompt + videos + controls + question cards inserted here -->
299
+ </main>
300
+
301
+ <footer class="bottom">
302
+ <button id="prevBtn">← Prev</button>
303
+ <button id="saveBtn">💾</button>
304
+ <button class="top-btn" id="scrollTopBtn" title="Back to videos">↑</button>
305
+ <button id="submitBtn" class="submit-btn" disabled>Submit</button>
306
+ <button id="nextBtn">Next →</button>
307
+ </footer>
308
+
309
+ <div class="toast" id="toast"></div>
310
+
311
+ <!-- Slide-in drawer with case list -->
312
+ <div class="drawer-backdrop" id="drawerBackdrop"></div>
313
+ <aside class="drawer" id="drawer" aria-hidden="true">
314
+ <header>
315
+ <span>Cases</span>
316
+ <button class="icon" id="drawerCloseBtn"
317
+ style="background:transparent;border:none;color:var(--fg);font-size:22px;cursor:pointer">✕</button>
318
+ </header>
319
+ <div class="list" id="drawerList"></div>
320
+ <div style="padding:10px 14px;border-top:1px solid var(--border);display:flex;gap:8px;align-items:center">
321
+ <a href="./" class="desktop-link" style="flex:1;text-align:center">🖥 Desktop view</a>
322
+ </div>
323
+ </aside>
324
+
325
+ <!-- Registration overlay -->
326
+ <div id="loginOverlay" class="overlay" role="dialog" aria-modal="true">
327
+ <div class="reg-card">
328
+ <div class="top-row">
329
+ <h2 id="regHeader">Register to start rating</h2>
330
+ <select id="regLangSelect"></select>
331
+ </div>
332
+ <p class="lead" id="regLead"></p>
333
+ <label for="regName" id="regNameLabel">Your name</label>
334
+ <input id="regName" type="text" autocomplete="name" maxlength="80">
335
+ <label for="regEmail" id="regEmailLabel">Email</label>
336
+ <input id="regEmail" type="email" autocomplete="email" inputmode="email" maxlength="120">
337
+ <label for="regNote" id="regNoteLabel">Affiliation / notes (optional)</label>
338
+ <textarea id="regNote" maxlength="280"></textarea>
339
+ <div class="err" id="regErr"></div>
340
+ <button class="go-btn" id="regGoBtn"><span id="regContinueText">Continue →</span></button>
341
+ <div style="color:var(--muted-2);font-size:11px;margin-top:8px;line-height:1.5"
342
+ id="regFootText"></div>
343
+ </div>
344
+ </div>
345
+
346
+ <!-- Submitted overlay -->
347
+ <div id="submittedOverlay" class="overlay hidden" role="dialog" aria-modal="true">
348
+ <div class="submitted-card">
349
+ <div class="check">✓</div>
350
+ <h2 id="submittedHeading">Submission recorded</h2>
351
+ <p id="submittedDetail"></p>
352
+ <p><code id="submittedRef">—</code></p>
353
+ <div style="display:flex;gap:8px;justify-content:center;flex-wrap:wrap">
354
+ <button class="btn" id="submittedCloseBtn">Close</button>
355
+ <button class="btn" id="submittedDownloadBtn">↓ Backup JSON</button>
356
+ </div>
357
+ </div>
358
+ </div>
359
+
360
+ <script>
361
+ /* =========================================================================
362
+ * Same rubric + i18n + admin list + API contract as desktop index.html.
363
+ * Kept in sync manually for now (small enough). localStorage key is shared
364
+ * so progress made on desktop carries to mobile and vice-versa.
365
+ * ========================================================================= */
366
+ const DIMENSIONS = [
367
+ { key: "instruction_following", name: "Instruction following",
368
+ hint: "Does the video do what the prompt asked?", questions: [
369
+ { key: "controllability", name: "Controllability",
370
+ desc: "Does the video respond to control signals (camera motion, conditioning, scene cues)?" },
371
+ { key: "prompt_adherence", name: "Prompt adherence",
372
+ desc: "Does the content match what the prompt described (subjects, actions, setting)?" } ] },
373
+ { key: "visual_quality", name: "Visual quality",
374
+ hint: "How good does each frame look?", questions: [
375
+ { key: "aesthetics", name: "Aesthetics",
376
+ desc: "Composition, color, lighting, overall pleasing look." },
377
+ { key: "sharpness", name: "Sharpness",
378
+ desc: "Clarity and detail; absence of blur or compression artifacts." },
379
+ { key: "realism", name: "Realism",
380
+ desc: "Photorealism or stylistic fidelity (no uncanny / broken artifacts)." } ] },
381
+ { key: "temporal_consistency", name: "Temporal consistency",
382
+ hint: "How stable is the content across frames?", questions: [
383
+ { key: "anti_flicker", name: "Anti-flicker",
384
+ desc: "Absence of frame-to-frame brightness, color, or texture flicker." },
385
+ { key: "person_stability", name: "Person stability",
386
+ desc: "Faces, identities, and body proportions stay consistent across frames." },
387
+ { key: "object_stability", name: "Object stability",
388
+ desc: "Props, clothing, and objects keep their shape and position over time." },
389
+ { key: "environment_stability", name: "Environment stability",
390
+ desc: "Background, lighting, and scene layout stay coherent across frames." } ] },
391
+ { key: "motion_realism", name: "Motion realism",
392
+ hint: "Does motion behave plausibly?", questions: [
393
+ { key: "physics", name: "Physics",
394
+ desc: "Gravity, collisions, fluid / cloth dynamics behave plausibly." },
395
+ { key: "movement", name: "Movement",
396
+ desc: "Body and object motion flows smoothly without warping or teleporting." },
397
+ { key: "camera", name: "Camera",
398
+ desc: "Camera movement (pan, dolly, focal change) feels natural and intentional." } ] },
399
+ ];
400
+
401
+ const TOTAL_QUESTIONS = DIMENSIONS.reduce((n, d) => n + d.questions.length, 0);
402
+ const STORAGE_KEY = "user_study_video_ratings_v1"; // shared with desktop
403
+ const ADMIN_NAMES = new Set(["deheng zhang", "zhendong li"]);
404
+
405
+ const LANGUAGES = [
406
+ { code: "en", label: "English" },
407
+ { code: "zh", label: "Chinese" },
408
+ { code: "bg", label: "Bulgarian" },
409
+ ];
410
+
411
+ const STRINGS = {
412
+ en: {
413
+ title:"Video user study",
414
+ prompt_label:"Prompt / instruction",
415
+ no_prompt:"(no prompt provided)",
416
+ case_n_of_m:"Case {0}/{1}",
417
+ play:"▶ Play", pause:"⏸", restart:"⏮", loop:"↻", mute:"🔇", sound:"🔊", speed:"Speed",
418
+ no_video_file:"no video file at this path",
419
+ prev:"← Prev", next:"Next →",
420
+ save_progress:"💾",
421
+ submit:"Submit ({0})",
422
+ submit_resubmit:"✓ Re-submit",
423
+ submit_disabled:"Submit ({0} left)",
424
+ reg_title:"Register to start rating",
425
+ reg_lead:"We record who submitted each set of ratings. No password — just your name and an email that uniquely identifies you.",
426
+ reg_name:"Your name", reg_name_ph:"e.g. Alex Chen",
427
+ reg_email:"Email", reg_email_ph:"e.g. alex@example.com",
428
+ reg_note:"Affiliation / notes (optional)", reg_note_ph:"e.g. INSAIT, internal pilot, etc.",
429
+ reg_continue:"Continue →",
430
+ reg_foot:"Submissions are written to the <code>dehezhang2/Frameworker_User_Study</code> dataset on Hugging Face.",
431
+ reg_err_name:"Please enter your name.",
432
+ reg_err_email:"Please enter a valid email address.",
433
+ pill_idle:"●", pill_submitting:"↻", pill_submitted:"✓", pill_local_only:"💾", pill_error:"✕", pill_checking:"●",
434
+ toast_registered:"Registered as {0}",
435
+ toast_pls_signin:"Please sign in before submitting",
436
+ toast_missing:"{0} ratings still missing",
437
+ toast_no_server:"No server reachable — use Export instead",
438
+ toast_submit_failed:"Submit failed: {0}",
439
+ toast_progress_saved:"Progress saved ({0} ratings)",
440
+ toast_progress_save_failed:"Save failed: {0}",
441
+ submitted_title:"Submission recorded",
442
+ submitted_thanks:"Thanks, {0}. We recorded {1} ratings across {2} videos.",
443
+ submitted_close:"Close", submitted_download:"↓ Backup",
444
+ drawer_cases:"Cases",
445
+ scale_1:"1 Very poor", scale_5:"5 Excellent",
446
+ expand_prompt:"Read full prompt",
447
+ case_complete:"✓ complete",
448
+ confirm_reset:"Reset all ratings + registration on this device? This cannot be undone.",
449
+ admin:"⚙ admin", submitted_badge:"✓ submitted",
450
+ },
451
+ zh: {
452
+ title:"视频用户研究",
453
+ prompt_label:"提示词 / 指令",
454
+ no_prompt:"(未提供提示词)",
455
+ case_n_of_m:"案例 {0}/{1}",
456
+ play:"▶ 播放", pause:"⏸", restart:"⏮", loop:"↻", mute:"🔇", sound:"🔊", speed:"速度",
457
+ no_video_file:"该路径下没有视频文件",
458
+ prev:"← 上一个", next:"下一个 →",
459
+ save_progress:"💾",
460
+ submit:"提交 ({0})",
461
+ submit_resubmit:"✓ 重新提交",
462
+ submit_disabled:"提交 (还剩 {0})",
463
+ reg_title:"注册以开始评分",
464
+ reg_lead:"我们会记录每份评分的提交者。无需密码 — 只需姓名和一个唯一识别您的邮箱。",
465
+ reg_name:"您的姓名", reg_name_ph:"例如:陈小明",
466
+ reg_email:"邮箱", reg_email_ph:"例如:xiaoming@example.com",
467
+ reg_note:"所属单位 / 备注(可选)", reg_note_ph:"例如:INSAIT、内部预测试 等",
468
+ reg_continue:"继续 →",
469
+ reg_foot:"提交将写入 Hugging Face 上的 <code>dehezhang2/Frameworker_User_Study</code> 数据集。",
470
+ reg_err_name:"请输入您的姓名。",
471
+ reg_err_email:"请输入有效的邮箱地址。",
472
+ pill_idle:"●", pill_submitting:"↻", pill_submitted:"✓", pill_local_only:"💾", pill_error:"✕", pill_checking:"●",
473
+ toast_registered:"已注册为 {0}",
474
+ toast_pls_signin:"请先登录后再提交",
475
+ toast_missing:"尚有 {0} 项未完成",
476
+ toast_no_server:"无法连接服务器 — 请使用导出功能",
477
+ toast_submit_failed:"提交失败: {0}",
478
+ toast_progress_saved:"进度已保存 ({0} 项评分)",
479
+ toast_progress_save_failed:"保存失败: {0}",
480
+ submitted_title:"提交成功",
481
+ submitted_thanks:"{0},感谢您的参与。我们已写入 {2} 个视频 × {1} 项评分。",
482
+ submitted_close:"关闭", submitted_download:"↓ 备份",
483
+ drawer_cases:"案例",
484
+ scale_1:"1 很差", scale_5:"5 极佳",
485
+ expand_prompt:"查看完整提示词",
486
+ case_complete:"✓ 已完成",
487
+ confirm_reset:"重置本设备的所有评分和注册信息吗?该操作不可撤销。",
488
+ admin:"⚙ 管理员", submitted_badge:"✓ 已提交",
489
+ },
490
+ bg: {
491
+ title:"Видео проучване",
492
+ prompt_label:"Подкана / инструкция",
493
+ no_prompt:"(няма подкана)",
494
+ case_n_of_m:"Случай {0}/{1}",
495
+ play:"▶ Пусни", pause:"⏸", restart:"⏮", loop:"↻", mute:"🔇", sound:"🔊", speed:"Скорост",
496
+ no_video_file:"няма видео файл на този път",
497
+ prev:"← Назад", next:"Напред →",
498
+ save_progress:"💾",
499
+ submit:"Изпрати ({0})",
500
+ submit_resubmit:"✓ Повторно",
501
+ submit_disabled:"Изпрати (остават {0})",
502
+ reg_title:"Регистрирайте се, за да започнете",
503
+ reg_lead:"Записваме кой е изпратил всеки набор от оценки. Без парола — само името и имейл, които ви идентифицират уникално.",
504
+ reg_name:"Вашето име", reg_name_ph:"напр. Алекс Иванов",
505
+ reg_email:"Имейл", reg_email_ph:"напр. alex@example.com",
506
+ reg_note:"Принадлежност / бележки (по избор)", reg_note_ph:"напр. INSAIT, вътрешен пилот",
507
+ reg_continue:"Продължи →",
508
+ reg_foot:"Изпращанията се записват в <code>dehezhang2/Frameworker_User_Study</code> на Hugging Face.",
509
+ reg_err_name:"Моля, въведете името си.",
510
+ reg_err_email:"Моля, въведете валиден имейл адрес.",
511
+ pill_idle:"●", pill_submitting:"↻", pill_submitted:"✓", pill_local_only:"💾", pill_error:"✕", pill_checking:"●",
512
+ toast_registered:"Регистриран(а) като {0}",
513
+ toast_pls_signin:"Моля, влезте преди изпращане",
514
+ toast_missing:"Все още липсват {0} оценки",
515
+ toast_no_server:"Сървърът не е достъпен — използвайте Изтегли",
516
+ toast_submit_failed:"Изпращането се провали: {0}",
517
+ toast_progress_saved:"Прогресът е запазен ({0} оценки)",
518
+ toast_progress_save_failed:"Запазването се провали: {0}",
519
+ submitted_title:"Записано",
520
+ submitted_thanks:"Благодарим, {0}. Записахме {1} оценки за {2} видеа.",
521
+ submitted_close:"Затвори", submitted_download:"↓ Копие",
522
+ drawer_cases:"Случаи",
523
+ scale_1:"1 Много слабо", scale_5:"5 Отлично",
524
+ expand_prompt:"Покажи цялата подкана",
525
+ case_complete:"✓ завършен",
526
+ confirm_reset:"Изчистване на всички оценки и регистрация на това устройство? Действието е необратимо.",
527
+ admin:"⚙ администратор", submitted_badge:"✓ изпратено",
528
+ },
529
+ };
530
+
531
+ const RUBRIC_I18N = {
532
+ zh: {
533
+ instruction_following:{name:"指令遵循",hint:"视频是否按提示完成?"},
534
+ visual_quality:{name:"画面质量",hint:"每一帧的视觉效果如何?"},
535
+ temporal_consistency:{name:"时间一致性",hint:"内容在帧间的稳定程度?"},
536
+ motion_realism:{name:"运动真实感",hint:"运动是否符合物理规律?"},
537
+ controllability:{name:"可控性",desc:"视频是否响应控制信号(相机运动、条件输入、场景线索)?"},
538
+ prompt_adherence:{name:"提示一致性",desc:"内容是否与提示的描述一致(主体、动作、场景)?"},
539
+ aesthetics:{name:"美学",desc:"构图、色彩、光照及整体观感。"},
540
+ sharpness:{name:"清晰度",desc:"清晰度与细节;无模糊或压缩伪影。"},
541
+ realism:{name:"真实感",desc:"照片级真实感或风格忠实度(无诡异感或失真伪影)。"},
542
+ anti_flicker:{name:"防闪烁",desc:"帧间无亮度、色彩或纹理闪烁。"},
543
+ person_stability:{name:"人物稳定性",desc:"面部、身份及身体比例在帧间保持一致。"},
544
+ object_stability:{name:"物体稳定性",desc:"道具、服饰及物体随时间保持形状和位置。"},
545
+ environment_stability:{name:"环境稳定性",desc:"背景、光照及场景布局在帧间保持连贯。"},
546
+ physics:{name:"物理规律",desc:"重力、碰撞、流体/布料动力学是否合理。"},
547
+ movement:{name:"运动连贯性",desc:"身体与物体的运动流畅,无形变或瞬移。"},
548
+ camera:{name:"相机运动",desc:"相机运动(平移、推拉、焦距变化)自然且有意图。"},
549
+ },
550
+ bg: {
551
+ instruction_following:{name:"Следване на инструкции",hint:"Видеото изпълнява ли подканата?"},
552
+ visual_quality:{name:"Визуално качество",hint:"Колко добре изглежда всеки кадър?"},
553
+ temporal_consistency:{name:"Времева съгласуваност",hint:"Колко стабилно е съдържанието между кадрите?"},
554
+ motion_realism:{name:"Реалистичност на движението",hint:"Движението изглежда ли правдоподобно?"},
555
+ controllability:{name:"Контролируемост",desc:"Реагира ли видеото на контролни сигнали (движение на камерата, обуславяне, насоки за сцена)?"},
556
+ prompt_adherence:{name:"Съответствие с подканата",desc:"Съответства ли съдържанието на описаното в подканата (обекти, действия, обстановка)?"},
557
+ aesthetics:{name:"Естетика",desc:"Композиция, цвят, осветление, цялостен приятен вид."},
558
+ sharpness:{name:"Острота",desc:"Яснота и детайли; липса на размазване или компресионни артефакти."},
559
+ realism:{name:"Реализъм",desc:"Фотореалистичност или стилова достоверност (без странни / счупени артефакти)."},
560
+ anti_flicker:{name:"Анти-трептене",desc:"Липса на трептене на яркост, цвят или текстура между кадрите."},
561
+ person_stability:{name:"Стабилност на хората",desc:"Лица, идентичности и пропорции на тялото остават постоянни между кадрите."},
562
+ object_stability:{name:"Стабилност на обектите",desc:"Реквизити, дрехи и обекти запазват форма и позиция във времето."},
563
+ environment_stability:{name:"Стабилност на средата",desc:"Фон, осветление и подредба на сцената остават последователни между кадрите."},
564
+ physics:{name:"Физика",desc:"Гравитация, сблъсъци, динамика на флуиди / тъкани се държат правдоподобно."},
565
+ movement:{name:"Движение",desc:"Движенията на тела и обекти текат плавно, без деформации или телепортация."},
566
+ camera:{name:"Камера",desc:"Движението на камерата (панорама, дъли, промяна на фокус) изглежда естествено и целенасочено."},
567
+ },
568
+ };
569
+
570
+ /* ----- State (shared with desktop via localStorage) ----- */
571
+ let CASES = [];
572
+ let SHUFFLE = {};
573
+ let RATINGS = {};
574
+ let RATER = { id:"", name:"", email:"", note:"",
575
+ started_at:null, submitted_at:null };
576
+ let LANG = "en";
577
+ let anonymize = true;
578
+ let currentIdx = 0;
579
+ let SYNC_STATUS = "idle";
580
+ let SYNC_LAST_DETAIL = "";
581
+ const API_SUBMIT = "./api/submit";
582
+ const API_HEALTH = "./api/health";
583
+ const API_SAVE_PROGRESS = "./api/save_progress";
584
+ const PROGRESS_DEBOUNCE_MS = 60000;
585
+ let PROGRESS_TIMER = null;
586
+
587
+ /* ----- Helpers ----- */
588
+ function t(key, ...args){
589
+ let s = (STRINGS[LANG]&&STRINGS[LANG][key])??STRINGS.en[key]??key;
590
+ if(args.length) s = s.replace(/\{(\d+)\}/g,(_,i)=>args[Number(i)]??"");
591
+ return s;
592
+ }
593
+ function dimName(d){ return LANG==="en"?d.name:(RUBRIC_I18N[LANG]?.[d.key]?.name??d.name); }
594
+ function dimHint(d){ return LANG==="en"?d.hint:(RUBRIC_I18N[LANG]?.[d.key]?.hint??d.hint); }
595
+ function qName(q){ return LANG==="en"?q.name:(RUBRIC_I18N[LANG]?.[q.key]?.name??q.name); }
596
+ function qDesc(q){ return LANG==="en"?q.desc:(RUBRIC_I18N[LANG]?.[q.key]?.desc??q.desc); }
597
+ function isAdmin(){ return ADMIN_NAMES.has((RATER.name||"").trim().toLowerCase()); }
598
+ const EMAIL_RE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
599
+ function hashStr(s){ let h=2166136261>>>0; for(let i=0;i<s.length;i++){h^=s.charCodeAt(i);h=(h*16777619)>>>0;} return h; }
600
+ function escapeHtml(s){return String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'})[c]);}
601
+ function showToast(msg, isErr=false){
602
+ const tt = document.getElementById("toast");
603
+ tt.textContent = msg;
604
+ tt.classList.toggle("error", !!isErr);
605
+ tt.classList.add("show");
606
+ setTimeout(()=>tt.classList.remove("show"), 1800);
607
+ }
608
+ function genRaterId(){ return "rater_"+Math.random().toString(36).slice(2,8)+"_"+Date.now().toString(36).slice(-4); }
609
+
610
+ /* ----- LocalStorage (shared key) ----- */
611
+ function loadState(){ try{ return JSON.parse(localStorage.getItem(STORAGE_KEY)||"null"); }catch(e){return null;} }
612
+ function saveState(){
613
+ try{ localStorage.setItem(STORAGE_KEY, JSON.stringify({
614
+ rater: RATER, anonymize, lang: LANG, shuffle: SHUFFLE, ratings: RATINGS,
615
+ saved_at: new Date().toISOString(),
616
+ })); }catch(e){ showToast("Save failed: "+e.message, true); }
617
+ }
618
+
619
+ /* ----- Shuffle ----- */
620
+ function buildShuffle(cases){
621
+ for (const c of cases){
622
+ if (SHUFFLE[c.id] && SHUFFLE[c.id].length===c.videos.length) continue;
623
+ const idx = c.videos.map((_,i)=>i);
624
+ if (anonymize){
625
+ let s = hashStr(RATER.id+":"+c.id);
626
+ for (let i=idx.length-1;i>0;i--){
627
+ s = (s*1664525+1013904223)>>>0;
628
+ const j = s%(i+1);
629
+ [idx[i],idx[j]] = [idx[j],idx[i]];
630
+ }
631
+ }
632
+ SHUFFLE[c.id] = idx;
633
+ }
634
+ }
635
+ function rowSlotOrder(caseId, qKey, slotCount){
636
+ if (!anonymize) return Array.from({length:slotCount},(_,i)=>i);
637
+ const idx = Array.from({length:slotCount},(_,i)=>i);
638
+ let s = hashStr(RATER.id+":"+caseId+":"+qKey);
639
+ for (let k=0;k<6;k++) s = (s*1664525+1013904223)>>>0;
640
+ for (let i=idx.length-1;i>0;i--){
641
+ s = (s*1664525+1013904223)>>>0;
642
+ const j = (s>>>16)%(i+1);
643
+ [idx[i],idx[j]] = [idx[j],idx[i]];
644
+ }
645
+ return idx;
646
+ }
647
+
648
+ /* ----- Ratings ----- */
649
+ function getCaseR(cid){ if(!RATINGS[cid]) RATINGS[cid]={}; return RATINGS[cid]; }
650
+ function getSlotR(cid, s){ const m = getCaseR(cid); if(!m[s]) m[s]={}; return m[s]; }
651
+ function setRating(cid, sIdx, qk, score){
652
+ getSlotR(cid, sIdx)[qk] = score;
653
+ saveState();
654
+ updateProgress();
655
+ if (RATER.submitted_at){
656
+ RATER.submitted_at = null; saveState();
657
+ setSyncStatus(SYNC_STATUS==="local-only"?"local-only":"idle");
658
+ }
659
+ updateSubmitBtn();
660
+ scheduleProgressSave();
661
+ }
662
+ function studyCompleteness(){
663
+ const qkeys = DIMENSIONS.flatMap(d=>d.questions.map(q=>q.key));
664
+ let done=0, expected=0; const missing=[];
665
+ for (const c of CASES){
666
+ const slots = SHUFFLE[c.id] || c.videos.map((_,i)=>i);
667
+ for (let s=0; s<slots.length; s++){
668
+ const r = (RATINGS[c.id]||{})[s] || {};
669
+ for (const qk of qkeys){
670
+ expected++;
671
+ if (typeof r[qk]==="number" && r[qk]>=1 && r[qk]<=5) done++;
672
+ else missing.push({case_id:c.id, slot:String.fromCharCode(65+s), q:qk});
673
+ }
674
+ }
675
+ }
676
+ return { done, expected, missing };
677
+ }
678
+ function caseProgress(c){
679
+ const slots = SHUFFLE[c.id] || [];
680
+ const expected = slots.length * TOTAL_QUESTIONS;
681
+ let done=0;
682
+ for (let s=0;s<slots.length;s++){
683
+ const r = (RATINGS[c.id]||{})[s] || {};
684
+ done += Object.keys(r).filter(k=>typeof r[k]==="number"&&r[k]>=1&&r[k]<=5).length;
685
+ }
686
+ return { done, expected };
687
+ }
688
+
689
+ /* ----- Sync pill + server status ----- */
690
+ function setSyncStatus(state, detail){
691
+ SYNC_STATUS = state;
692
+ if (detail!==undefined) SYNC_LAST_DETAIL = detail;
693
+ const pill = document.getElementById("syncPill");
694
+ if (!pill) return;
695
+ pill.dataset.state = state;
696
+ pill.textContent = t({
697
+ idle:"pill_idle", submitting:"pill_submitting", submitted:"pill_submitted",
698
+ "local-only":"pill_local_only", error:"pill_error",
699
+ }[state] || "pill_checking");
700
+ pill.title = SYNC_LAST_DETAIL || "";
701
+ }
702
+ async function probeSync(){
703
+ try{
704
+ const r = await fetch(API_HEALTH, {cache:"no-cache"});
705
+ if (r.ok){
706
+ const j = await r.json().catch(()=>({}));
707
+ setSyncStatus(j.ok && j.has_token ? "idle" : "local-only");
708
+ } else setSyncStatus("local-only");
709
+ }catch(e){ setSyncStatus("local-only"); }
710
+ }
711
+
712
+ /* ----- Payloads + API calls ----- */
713
+ function buildProgressPayload(){
714
+ const comp = studyCompleteness();
715
+ return {
716
+ rater: RATER, anonymize_used: anonymize, is_admin: isAdmin(),
717
+ rubric: DIMENSIONS, progress_saved_at: new Date().toISOString(),
718
+ completeness: { done: comp.done, expected: comp.expected, missing_count: comp.missing.length },
719
+ cases: CASES.map(c => {
720
+ const slots = SHUFFLE[c.id] || c.videos.map((_,i)=>i);
721
+ return {
722
+ id: c.id, category: c.category||null, prompt: c.prompt,
723
+ videos: slots.map((origIdx, slotIdx) => ({
724
+ slot: String.fromCharCode(65+slotIdx), slot_index: slotIdx,
725
+ original_index: origIdx, model: c.videos[origIdx].model,
726
+ path: c.videos[origIdx].path,
727
+ ratings: (RATINGS[c.id]||{})[slotIdx] || {},
728
+ })),
729
+ };
730
+ }),
731
+ };
732
+ }
733
+ function buildFullPayload(){
734
+ const p = buildProgressPayload();
735
+ p.submitted_at = new Date().toISOString();
736
+ delete p.progress_saved_at; delete p.completeness;
737
+ return p;
738
+ }
739
+ async function saveProgress(opts={}){
740
+ if (!RATER.email || !RATER.name) return;
741
+ if (SYNC_STATUS==="local-only" && opts.source!=="manual") return;
742
+ try{
743
+ const r = await fetch(API_SAVE_PROGRESS, {
744
+ method:"POST", headers:{"Content-Type":"application/json"},
745
+ body: JSON.stringify(buildProgressPayload()),
746
+ });
747
+ if (r.ok){
748
+ const j = await r.json().catch(()=>({}));
749
+ if (!opts.silent) showToast(t("toast_progress_saved", j.n_scores ?? 0));
750
+ } else if (r.status===404||r.status===503){
751
+ setSyncStatus("local-only");
752
+ } else if (!opts.silent){
753
+ showToast(t("toast_progress_save_failed", "HTTP "+r.status), true);
754
+ }
755
+ }catch(e){
756
+ if (!opts.silent) showToast(t("toast_progress_save_failed", e.message), true);
757
+ }
758
+ }
759
+ function scheduleProgressSave(){
760
+ if (!RATER.email) return;
761
+ if (SYNC_STATUS==="local-only") return;
762
+ if (PROGRESS_TIMER) clearTimeout(PROGRESS_TIMER);
763
+ PROGRESS_TIMER = setTimeout(()=>{ PROGRESS_TIMER=null; saveProgress({silent:true,source:"auto"}); }, PROGRESS_DEBOUNCE_MS);
764
+ }
765
+ function beaconProgress(){
766
+ if (!RATER.email || SYNC_STATUS==="local-only") return;
767
+ try{ navigator.sendBeacon(API_SAVE_PROGRESS,
768
+ new Blob([JSON.stringify(buildProgressPayload())], {type:"application/json"})); }catch(e){}
769
+ }
770
+ async function submitWholeStudy(){
771
+ if (!RATER.email||!RATER.name){ showToast(t("toast_pls_signin"), true); openRegister(); return; }
772
+ const comp = studyCompleteness();
773
+ if (comp.missing.length>0){
774
+ showToast(t("toast_missing", comp.missing.length), true);
775
+ const firstId = comp.missing[0].case_id;
776
+ const idx = CASES.findIndex(c=>c.id===firstId);
777
+ if (idx>=0) goTo(idx);
778
+ return;
779
+ }
780
+ if (SYNC_STATUS==="local-only"){ showToast(t("toast_no_server"), true); return; }
781
+ setSyncStatus("submitting");
782
+ try{
783
+ const r = await fetch(API_SUBMIT, {
784
+ method:"POST", headers:{"Content-Type":"application/json"},
785
+ body: JSON.stringify(buildFullPayload()),
786
+ });
787
+ if (r.ok){
788
+ const body = await r.json().catch(()=>({}));
789
+ RATER.submitted_at = new Date().toISOString();
790
+ saveState();
791
+ setSyncStatus("submitted");
792
+ updateSubmitBtn();
793
+ showSubmittedOverlay(body);
794
+ } else if (r.status===404||r.status===503){
795
+ setSyncStatus("local-only"); showToast(t("toast_no_server"), true);
796
+ } else {
797
+ setSyncStatus("error");
798
+ showToast(t("toast_submit_failed", "HTTP "+r.status), true);
799
+ }
800
+ }catch(e){
801
+ setSyncStatus("local-only"); showToast(t("toast_submit_failed", e.message), true);
802
+ }
803
+ }
804
+ function exportJSON(){
805
+ const out = {
806
+ rater: RATER, anonymize_used: anonymize, exported_at: new Date().toISOString(),
807
+ rubric: DIMENSIONS,
808
+ cases: CASES.map(c => {
809
+ const slots = SHUFFLE[c.id] || c.videos.map((_,i)=>i);
810
+ return { id:c.id, prompt:c.prompt,
811
+ videos: slots.map((oi,si)=>({
812
+ slot:String.fromCharCode(65+si), slot_index:si, original_index:oi,
813
+ model:c.videos[oi].model, path:c.videos[oi].path,
814
+ ratings:(RATINGS[c.id]||{})[si]||{},
815
+ })),
816
+ };
817
+ }),
818
+ };
819
+ const blob = new Blob([JSON.stringify(out,null,2)], {type:"application/json"});
820
+ const url = URL.createObjectURL(blob);
821
+ const a = document.createElement("a");
822
+ a.href = url; a.download = `user_study_${RATER.id||"anon"}_${new Date().toISOString().slice(0,10)}.json`;
823
+ document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url);
824
+ }
825
+
826
+ /* =========================================================================
827
+ * Mobile rendering
828
+ * ========================================================================= */
829
+ function renderShell(){
830
+ // language selectors
831
+ for (const id of ["langSelect","regLangSelect"]){
832
+ const sel = document.getElementById(id);
833
+ sel.innerHTML = "";
834
+ for (const L of LANGUAGES){
835
+ const o = document.createElement("option");
836
+ o.value = L.code; o.textContent = L.label;
837
+ if (L.code===LANG) o.selected = true;
838
+ sel.appendChild(o);
839
+ }
840
+ }
841
+ document.getElementById("topTitle").textContent = t("title");
842
+ // bottom-bar labels (kept short on mobile)
843
+ document.getElementById("prevBtn").textContent = t("prev");
844
+ document.getElementById("nextBtn").textContent = t("next");
845
+ document.getElementById("saveBtn").textContent = t("save_progress");
846
+ document.getElementById("submittedCloseBtn").textContent = t("submitted_close");
847
+ document.getElementById("submittedDownloadBtn").textContent = t("submitted_download");
848
+ applyRegistrationI18n();
849
+ updateSubmitBtn();
850
+ renderCase();
851
+ renderDrawer();
852
+ }
853
+
854
+ function renderCase(){
855
+ const main = document.getElementById("main");
856
+ main.innerHTML = "";
857
+ if (!CASES.length) return;
858
+ const c = CASES[currentIdx];
859
+ document.getElementById("caseId").textContent = c.id;
860
+ document.getElementById("caseCounter").textContent = t("case_n_of_m", currentIdx+1, CASES.length);
861
+
862
+ // prompt card
863
+ main.appendChild(renderPromptCard(c));
864
+ // video stack
865
+ main.appendChild(renderVideoStack(c));
866
+ // controls
867
+ main.appendChild(renderVideoControls());
868
+ // rubric
869
+ for (const dim of DIMENSIONS){
870
+ main.appendChild(renderDimHeader(dim));
871
+ for (const q of dim.questions) main.appendChild(renderQuestionCard(c, q));
872
+ }
873
+ updateProgress();
874
+ refreshDrawerActive();
875
+ }
876
+
877
+ function renderPromptCard(c){
878
+ const wrap = document.createElement("div");
879
+ wrap.className = "prompt-card";
880
+ const localized = (c.prompt_i18n && c.prompt_i18n[LANG]) || c.prompt || t("no_prompt");
881
+ const isLong = (localized||"").length > 160;
882
+ wrap.innerHTML = isLong
883
+ ? `<div class="label">${escapeHtml(t("prompt_label"))}</div>
884
+ <details><summary>${escapeHtml(localized.slice(0,150)+"…")} <span style="color:var(--accent)">(${t("expand_prompt")})</span></summary>
885
+ <div style="margin-top:6px">${escapeHtml(localized)}</div></details>`
886
+ : `<div class="label">${escapeHtml(t("prompt_label"))}</div>
887
+ <div>${escapeHtml(localized)}</div>`;
888
+ if (c.reference_image){
889
+ const img = document.createElement("img");
890
+ img.src = c.reference_image; img.className = "ref-img";
891
+ img.onerror = function(){ this.style.display="none"; };
892
+ wrap.appendChild(img);
893
+ }
894
+ return wrap;
895
+ }
896
+
897
+ function renderVideoStack(c){
898
+ const slots = SHUFFLE[c.id];
899
+ const wrap = document.createElement("div");
900
+ wrap.className = "video-stack";
901
+ wrap.id = "videoStack";
902
+ slots.forEach((origIdx, slotIdx) => {
903
+ const v = c.videos[origIdx];
904
+ const letter = String.fromCharCode(65+slotIdx);
905
+ const tile = document.createElement("div");
906
+ tile.className = "video-tile";
907
+ tile.innerHTML = `
908
+ <div class="slot-label">
909
+ <span class="slot-letter">${letter}</span>
910
+ <span>${anonymize ? `Video ${letter}` : `Video ${letter} · ${escapeHtml(v.model)}`}</span>
911
+ </div>
912
+ <div class="video-frame">
913
+ <video data-slot="${slotIdx}" preload="metadata" playsinline controls
914
+ style="width:100%;height:100%">
915
+ <source src="${escapeHtml(v.path)}" type="video/mp4">
916
+ </video>
917
+ <div class="empty-state" style="display:none">
918
+ <div style="font-size:24px;opacity:0.3">▶</div>
919
+ <div>${escapeHtml(t("no_video_file"))}</div>
920
+ </div>
921
+ </div>`;
922
+ const video = tile.querySelector("video");
923
+ const empty = tile.querySelector(".empty-state");
924
+ const onErr = () => { empty.style.display="flex"; video.style.display="none"; };
925
+ video.addEventListener("error", onErr);
926
+ video.querySelector("source").addEventListener("error", onErr);
927
+ wrap.appendChild(tile);
928
+ });
929
+ return wrap;
930
+ }
931
+
932
+ function renderVideoControls(){
933
+ const wrap = document.createElement("div");
934
+ wrap.className = "video-controls";
935
+ const mkBtn = (label, fn, id) => {
936
+ const b = document.createElement("button");
937
+ b.textContent = label; b.onclick = fn; if (id) b.id = id;
938
+ return b;
939
+ };
940
+ wrap.appendChild(mkBtn(t("play"), playAll));
941
+ wrap.appendChild(mkBtn(t("pause"), pauseAll));
942
+ wrap.appendChild(mkBtn(t("restart"), restartAll));
943
+ const loop = mkBtn(t("loop"), () => toggleLoop(loop));
944
+ wrap.appendChild(loop);
945
+ const mute = mkBtn(t("mute"), () => toggleMute(mute));
946
+ wrap.appendChild(mute);
947
+ const sel = document.createElement("select");
948
+ sel.onchange = (e)=>setSpeed(parseFloat(e.target.value));
949
+ for (const v of ["0.5","0.75","1","1.5","2"]){
950
+ const o = document.createElement("option"); o.value=v; o.textContent=v+"×";
951
+ if (v==="1") o.selected = true; sel.appendChild(o);
952
+ }
953
+ wrap.appendChild(sel);
954
+ return wrap;
955
+ }
956
+
957
+ function renderDimHeader(dim){
958
+ const d = document.createElement("div");
959
+ d.className = "dim-header";
960
+ d.innerHTML = `<span>${escapeHtml(dimName(dim))}</span><span class="dim-hint">${escapeHtml(dimHint(dim))}</span>`;
961
+ return d;
962
+ }
963
+
964
+ function renderQuestionCard(c, q){
965
+ const card = document.createElement("div");
966
+ card.className = "q-card";
967
+ card.innerHTML = `<div class="q-name">${escapeHtml(qName(q))}</div>
968
+ <div class="q-desc">${escapeHtml(qDesc(q))}</div>`;
969
+ const slots = SHUFFLE[c.id];
970
+ const order = rowSlotOrder(c.id, q.key, slots.length);
971
+ for (const slotIdx of order){
972
+ const origIdx = slots[slotIdx];
973
+ const v = c.videos[origIdx];
974
+ const letter = String.fromCharCode(65+slotIdx);
975
+ const row = document.createElement("div");
976
+ row.className = "video-rate";
977
+ const chip = document.createElement("span");
978
+ chip.className = "slot-letter";
979
+ chip.textContent = anonymize ? letter : `${letter}`;
980
+ chip.title = anonymize ? `Video ${letter}` : `Video ${letter} · ${v.model}`;
981
+ row.appendChild(chip);
982
+ const group = document.createElement("div");
983
+ group.className = "likert";
984
+ const cur = getSlotR(c.id, slotIdx)[q.key];
985
+ for (let s=1; s<=5; s++){
986
+ const b = document.createElement("button");
987
+ b.dataset.score = String(s);
988
+ b.textContent = String(s);
989
+ if (cur===s) b.classList.add("selected");
990
+ b.onclick = () => {
991
+ setRating(c.id, slotIdx, q.key, s);
992
+ Array.from(group.children).forEach((bb,i)=>bb.classList.toggle("selected", (i+1)===s));
993
+ };
994
+ group.appendChild(b);
995
+ }
996
+ row.appendChild(group);
997
+ card.appendChild(row);
998
+ }
999
+ return card;
1000
+ }
1001
+
1002
+ /* ----- Drawer ----- */
1003
+ function renderDrawer(){
1004
+ const list = document.getElementById("drawerList");
1005
+ list.innerHTML = "";
1006
+ CASES.forEach((c, i) => {
1007
+ const p = caseProgress(c);
1008
+ let cls = "case-row";
1009
+ if (i===currentIdx) cls += " active";
1010
+ if (p.done === p.expected && p.expected>0) cls += " complete";
1011
+ else if (p.done > 0) cls += " partial";
1012
+ const row = document.createElement("div");
1013
+ row.className = cls;
1014
+ row.innerHTML = `<span class="dot"></span>
1015
+ <span class="id">${c.id}</span>
1016
+ <span class="pct">${p.done}/${p.expected}</span>`;
1017
+ row.onclick = () => { closeDrawer(); goTo(i); };
1018
+ list.appendChild(row);
1019
+ });
1020
+ }
1021
+ function refreshDrawerActive(){
1022
+ document.querySelectorAll("#drawerList .case-row").forEach((r,i)=>{
1023
+ r.classList.toggle("active", i===currentIdx);
1024
+ });
1025
+ }
1026
+ function openDrawer(){
1027
+ document.getElementById("drawer").classList.add("open");
1028
+ document.getElementById("drawerBackdrop").classList.add("open");
1029
+ }
1030
+ function closeDrawer(){
1031
+ document.getElementById("drawer").classList.remove("open");
1032
+ document.getElementById("drawerBackdrop").classList.remove("open");
1033
+ }
1034
+
1035
+ /* ----- Video controls ----- */
1036
+ function allVideos(){ return Array.from(document.querySelectorAll("video[data-slot]")); }
1037
+ function playAll(){ allVideos().forEach(v=>{ try{ v.play(); }catch(e){} }); }
1038
+ function pauseAll(){ allVideos().forEach(v=>v.pause()); }
1039
+ function restartAll(){ allVideos().forEach(v=>{ v.currentTime=0; try{ v.play(); }catch(e){} }); }
1040
+ let LOOPING=false;
1041
+ function toggleLoop(btn){ LOOPING=!LOOPING; allVideos().forEach(v=>v.loop=LOOPING); btn.classList.toggle("on",LOOPING); }
1042
+ let MUTED=false;
1043
+ function toggleMute(btn){ MUTED=!MUTED; allVideos().forEach(v=>v.muted=MUTED); btn.classList.toggle("on",MUTED); btn.textContent=MUTED?t("muted"||"sound"):t("mute"); }
1044
+ function setSpeed(rate){ allVideos().forEach(v=>v.playbackRate=rate); }
1045
+
1046
+ /* ----- Navigation ----- */
1047
+ function goTo(idx){
1048
+ if (idx<0 || idx>=CASES.length) return;
1049
+ pauseAll();
1050
+ currentIdx = idx;
1051
+ renderCase();
1052
+ // scroll to top of main on case switch
1053
+ window.scrollTo({top:0, behavior:"instant"});
1054
+ }
1055
+ function step(d){ goTo((currentIdx + d + CASES.length) % CASES.length); }
1056
+
1057
+ /* ----- Submit button + progress ----- */
1058
+ function updateSubmitBtn(){
1059
+ const btn = document.getElementById("submitBtn");
1060
+ if (!btn) return;
1061
+ const comp = studyCompleteness();
1062
+ const remaining = comp.expected - comp.done;
1063
+ if (remaining > 0){
1064
+ btn.disabled = true; btn.textContent = t("submit_disabled", remaining);
1065
+ } else if (SYNC_STATUS === "submitted"){
1066
+ btn.disabled = false; btn.textContent = t("submit_resubmit");
1067
+ } else {
1068
+ btn.disabled = false; btn.textContent = t("submit", comp.expected);
1069
+ }
1070
+ }
1071
+ function updateProgress(){
1072
+ const { done, expected } = studyCompleteness();
1073
+ document.getElementById("progressFill").style.width =
1074
+ expected>0 ? (done/expected*100).toFixed(1)+"%" : "0%";
1075
+ document.getElementById("progressTxt").textContent = `${done}/${expected}`;
1076
+ updateSubmitBtn();
1077
+ // also refresh per-case status in drawer (cheap)
1078
+ refreshDrawerCounts();
1079
+ }
1080
+ function refreshDrawerCounts(){
1081
+ document.querySelectorAll("#drawerList .case-row").forEach((row,i)=>{
1082
+ const c = CASES[i]; if (!c) return;
1083
+ const p = caseProgress(c);
1084
+ row.classList.remove("partial","complete");
1085
+ if (p.done===p.expected && p.expected>0) row.classList.add("complete");
1086
+ else if (p.done>0) row.classList.add("partial");
1087
+ const pct = row.querySelector(".pct");
1088
+ if (pct) pct.textContent = `${p.done}/${p.expected}`;
1089
+ });
1090
+ }
1091
+
1092
+ /* ----- Registration overlay ----- */
1093
+ function openRegister(){
1094
+ document.getElementById("loginOverlay").classList.remove("hidden");
1095
+ document.getElementById("regName").value = RATER.name || "";
1096
+ document.getElementById("regEmail").value = RATER.email || "";
1097
+ document.getElementById("regNote").value = RATER.note || "";
1098
+ applyRegistrationI18n();
1099
+ }
1100
+ function closeRegister(){ document.getElementById("loginOverlay").classList.add("hidden"); }
1101
+ function applyRegistrationI18n(){
1102
+ document.getElementById("regHeader").textContent = t("reg_title");
1103
+ document.getElementById("regLead").textContent = t("reg_lead");
1104
+ document.getElementById("regNameLabel").textContent = t("reg_name");
1105
+ document.getElementById("regEmailLabel").textContent = t("reg_email");
1106
+ document.getElementById("regNoteLabel").textContent = t("reg_note");
1107
+ document.getElementById("regContinueText").textContent = t("reg_continue");
1108
+ document.getElementById("regFootText").innerHTML = t("reg_foot");
1109
+ document.getElementById("regName").placeholder = t("reg_name_ph");
1110
+ document.getElementById("regEmail").placeholder = t("reg_email_ph");
1111
+ document.getElementById("regNote").placeholder = t("reg_note_ph");
1112
+ document.getElementById("submittedHeading").textContent = t("submitted_title");
1113
+ }
1114
+ function handleRegister(){
1115
+ const name = document.getElementById("regName").value.trim();
1116
+ const email = document.getElementById("regEmail").value.trim().toLowerCase();
1117
+ const note = document.getElementById("regNote").value.trim();
1118
+ const err = document.getElementById("regErr");
1119
+ err.textContent = "";
1120
+ if (!name){ err.textContent = t("reg_err_name"); return; }
1121
+ if (!EMAIL_RE.test(email)){ err.textContent = t("reg_err_email"); return; }
1122
+ RATER.name = name; RATER.email = email; RATER.note = note;
1123
+ if (!RATER.id || RATER.id.startsWith("rater_")){
1124
+ RATER.id = email.replace(/[^a-z0-9]+/gi,"_").replace(/^_+|_+$/g,"");
1125
+ }
1126
+ if (!RATER.started_at) RATER.started_at = new Date().toISOString();
1127
+ // Non-admins always anonymized
1128
+ if (!isAdmin()) anonymize = true;
1129
+ SHUFFLE = {}; buildShuffle(CASES); saveState();
1130
+ closeRegister();
1131
+ renderShell();
1132
+ (async()=>{
1133
+ await probeSync();
1134
+ if (SYNC_STATUS!=="local-only"){
1135
+ await saveProgress({silent:true, source:"register"});
1136
+ }
1137
+ showToast(t("toast_registered", name));
1138
+ })();
1139
+ }
1140
+
1141
+ /* ----- Submitted overlay ----- */
1142
+ function showSubmittedOverlay(body){
1143
+ const ov = document.getElementById("submittedOverlay");
1144
+ document.getElementById("submittedDetail").textContent =
1145
+ t("submitted_thanks", RATER.name, body.n_scores ?? "?", body.n_videos ?? "?");
1146
+ document.getElementById("submittedRef").textContent = body.stored_as || "—";
1147
+ ov.classList.remove("hidden");
1148
+ }
1149
+ function hideSubmittedOverlay(){ document.getElementById("submittedOverlay").classList.add("hidden"); }
1150
+
1151
+ /* =========================================================================
1152
+ * Init
1153
+ * ========================================================================= */
1154
+ (async function init(){
1155
+ // restore lang first
1156
+ try{
1157
+ const prior0 = JSON.parse(localStorage.getItem(STORAGE_KEY)||"null");
1158
+ if (prior0 && STRINGS[prior0.lang]) LANG = prior0.lang;
1159
+ }catch(e){}
1160
+ if (LANG === "en"){
1161
+ const nav = (navigator.language||"en").toLowerCase();
1162
+ if (nav.startsWith("zh")) LANG = "zh";
1163
+ else if (nav.startsWith("bg")) LANG = "bg";
1164
+ }
1165
+ document.documentElement.lang = LANG;
1166
+
1167
+ // fetch manifest
1168
+ let manifest = null;
1169
+ for (const p of ["./cases.json", "./cases.example.json"]){
1170
+ try{ const r = await fetch(p, {cache:"no-cache"}); if (r.ok){ manifest = await r.json(); break; } }catch(e){}
1171
+ }
1172
+ if (!manifest || !Array.isArray(manifest) || manifest.length===0){
1173
+ document.getElementById("main").innerHTML =
1174
+ '<div style="padding:40px;color:var(--bad);text-align:center">Could not load cases.json</div>';
1175
+ return;
1176
+ }
1177
+ CASES = manifest;
1178
+
1179
+ // restore state
1180
+ const prior = loadState();
1181
+ const blankRater = () => ({ id:genRaterId(), name:"", email:"", note:"",
1182
+ started_at:new Date().toISOString(), submitted_at:null });
1183
+ if (prior){
1184
+ RATER = Object.assign(blankRater(), prior.rater||{});
1185
+ anonymize = prior.anonymize !== false;
1186
+ RATINGS = prior.ratings || {};
1187
+ SHUFFLE = prior.shuffle || {};
1188
+ } else { RATER = blankRater(); }
1189
+ if (!isAdmin()) anonymize = true;
1190
+ buildShuffle(CASES); saveState();
1191
+
1192
+ // wire DOM events
1193
+ document.getElementById("drawerBtn").onclick = openDrawer;
1194
+ document.getElementById("drawerCloseBtn").onclick = closeDrawer;
1195
+ document.getElementById("drawerBackdrop").onclick = closeDrawer;
1196
+ document.getElementById("prevBtn").onclick = () => step(-1);
1197
+ document.getElementById("nextBtn").onclick = () => step(1);
1198
+ document.getElementById("submitBtn").onclick = submitWholeStudy;
1199
+ document.getElementById("saveBtn").onclick = () => saveProgress({silent:false, source:"manual"});
1200
+ document.getElementById("scrollTopBtn").onclick = () => {
1201
+ document.getElementById("videoStack")?.scrollIntoView({behavior:"smooth", block:"start"});
1202
+ };
1203
+ document.getElementById("regGoBtn").onclick = handleRegister;
1204
+ document.getElementById("submittedCloseBtn").onclick = hideSubmittedOverlay;
1205
+ document.getElementById("submittedDownloadBtn").onclick = exportJSON;
1206
+ document.getElementById("langSelect").onchange = (e) => {
1207
+ LANG = e.target.value; document.documentElement.lang = LANG;
1208
+ saveState(); renderShell();
1209
+ };
1210
+ document.getElementById("regLangSelect").onchange = (e) => {
1211
+ LANG = e.target.value; document.documentElement.lang = LANG;
1212
+ saveState(); applyRegistrationI18n();
1213
+ };
1214
+ // best-effort save on close
1215
+ window.addEventListener("beforeunload", beaconProgress);
1216
+ document.addEventListener("visibilitychange", () => {
1217
+ if (document.visibilityState==="hidden") beaconProgress();
1218
+ });
1219
+
1220
+ // gate on registration
1221
+ if (!RATER.name || !RATER.email || !EMAIL_RE.test(RATER.email)){
1222
+ openRegister();
1223
+ } else {
1224
+ renderShell();
1225
+ closeRegister();
1226
+ probeSync();
1227
+ }
1228
+ })();
1229
+ </script>
1230
+ </body>
1231
+ </html>