:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #1f2933;
  --muted: #637083;
  --line: #d7dee7;
  --line-strong: #b8c4d2;
  --canvas: #101827;
  --accent: #0f766e;
  --accent-hover: #0b5f59;
  --selected: #e8f7f1;
  --selected-line: #159570;
  --danger: #b42318;
  --model-a: #0e7490;
  --model-b: #c2410c;
  --model-c: #7e22ce;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button, input, select { font: inherit; }
button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  padding: 8px 13px;
  cursor: pointer;
}
button:hover { border-color: #8795a8; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 1px;
}
button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
button.primary:hover { background: var(--accent-hover); }
button.danger { color: var(--danger); border-color: #efaaa4; background: #fff4f2; }
button.compact { min-height: 32px; padding: 5px 9px; }
button.linkish {
  border: 0;
  background: transparent;
  min-height: 0;
  padding: 0;
  color: var(--accent);
  font-weight: 700;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--line);
}
.title-block { min-width: 0; }
h1 { margin: 0; font-size: 21px; line-height: 1.2; }
.subtitle { margin-top: 4px; color: var(--muted); }

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.signed-in { text-align: right; }
.signed-in .email { font-weight: 700; }
.signed-in .hint { color: var(--muted); font-size: 12px; }

.layout {
  width: 100%;
  max-width: 2200px;
  margin: 0 auto;
  padding: 16px 18px 28px;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(460px, 100%);
  padding: 28px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.gate-card h1 { margin-bottom: 8px; }
.gate-card p { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.gate-card label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.gate-card input {
  width: 100%;
  min-height: 42px;
  margin-bottom: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 11px;
}
.gate-card button { width: 100%; }

.status-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.progress-wrap {
  min-width: 0;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.progress-labels { display: flex; justify-content: space-between; gap: 16px; font-weight: 700; }
.progress-labels span:last-child { color: var(--muted); font-weight: 600; }
.progress-track { height: 5px; margin-top: 9px; overflow: hidden; background: #e5eaf0; border-radius: 3px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 180ms ease; }
.save-state { color: var(--accent); font-size: 12px; font-weight: 700; white-space: nowrap; }

.majority-banner {
  display: none;
  margin-bottom: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.majority-banner.open { display: block; }
.majority-banner h2 { margin: 0 0 6px; font-size: 16px; }
.majority-banner p { margin: 0; color: var(--muted); line-height: 1.45; }
.majority-banner .stats { margin-top: 8px; font-weight: 700; }

.results-panel {
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.results-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}
.results-panel > summary::-webkit-details-marker { display: none; }
.results-panel > summary::before { content: "+"; color: var(--accent); }
.results-panel[open] > summary::before { content: "-"; }
.results-panel > summary span:first-child { margin-right: auto; }
.results-summary { color: var(--muted); font-size: 12px; font-weight: 650; }

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr)) minmax(145px, 0.8fr);
  gap: 8px;
  padding: 0 10px 10px;
}
.score-card {
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--model-color, var(--line-strong));
  border-radius: 7px;
}
.score-card .score-name { color: var(--muted); font-size: 12px; font-weight: 700; }
.score-card .score-value { margin-top: 3px; font-size: 20px; font-weight: 800; }
.score-card .score-detail { color: var(--muted); font-size: 12px; }
.score-card.overall { border-top-color: var(--accent); }

.comparison-scroll { overflow-x: auto; padding-bottom: 5px; }
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}
.majority-order {
  display: none;
  margin-bottom: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-weight: 700;
}
.majority-order.open { display: block; }
.majority-order span { color: var(--muted); font-weight: 600; }

.model-card {
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}
.model-card.ranked { border-color: var(--selected-line); box-shadow: 0 0 0 3px rgba(21, 149, 112, 0.12), var(--shadow); }
.model-card.rank-1 { border-color: #159570; }
.model-card.rank-2 { border-color: #4f7cac; }
.model-card.rank-3 { border-color: #b7791f; }
.model-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 46px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.model-name { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 800; }
.model-swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--model-color); flex: 0 0 auto; }
.selected-label { color: var(--accent); font-size: 12px; font-weight: 800; min-width: 76px; text-align: right; }

.image-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--canvas);
}
.image-stage img { width: 100%; height: 100%; display: block; object-fit: contain; }
.image-stage.image-error::before {
  content: "Preview unavailable";
  color: #aeb9c8;
  font-size: 13px;
  font-weight: 700;
}
.image-stage.image-error img { display: none; }
.inspect-button {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 30px;
  padding: 4px 9px;
  color: #fff;
  border-color: rgba(255,255,255,0.55);
  background: rgba(8, 15, 27, 0.76);
}

.rank-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.rank-control select {
  width: 100%;
  min-height: 40px;
  padding: 7px 30px 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 750;
}
.model-card.ranked .rank-control select {
  border-color: var(--selected-line);
  background: var(--selected);
}

.majority-meta {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 10px 10px;
  padding: 8px 10px;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
}
.majority-meta.open { display: grid; }
.majority-meta strong { display: block; font-size: 13px; }
.majority-meta.match { border-color: #8dcbbb; background: #e9f5f1; }
.majority-meta.differ { border-color: #e4bd68; background: #fff8e6; }

.comparison-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 8px;
}
.comparison-toolbar span { margin-right: 3px; color: var(--muted); font-size: 12px; font-weight: 750; }
.comparison-toolbar button { min-height: 32px; padding: 5px 10px; }
.comparison-toolbar button.active {
  border-color: var(--accent);
  background: var(--selected);
  color: #075f46;
  font-weight: 800;
}
.comparison-grid.top-two {
  grid-template-columns: repeat(2, minmax(340px, 1fr));
  min-width: 690px;
  max-width: 1500px;
  margin: 0 auto;
}
.model-card.view-hidden { display: none; }

.review-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.navigation-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.navigation-status { min-width: 220px; text-align: right; }
.navigation-status strong { display: block; }
.navigation-status span { color: var(--muted); font-size: 12px; }

.frame-map {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.frame-map summary {
  padding: 11px 13px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 750;
}
.frame-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 5px;
  padding: 0 12px 12px;
}
.frame-buttons button { min-height: 32px; padding: 4px; font-size: 12px; }
.frame-buttons button.started { background: #fff8e6; border-color: #e4bd68; }
.frame-buttons button.reviewed { background: #e9f5f1; border-color: #8dcbbb; }
.frame-buttons button.current { color: #fff; background: var(--accent); border-color: var(--accent); }

.danger-zone {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

dialog {
  width: min(96vw, 1500px);
  max-height: 94vh;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.3);
}
dialog::backdrop { background: rgba(10, 16, 28, 0.72); }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.dialog-header h2 { margin: 0; font-size: 17px; }
.zoom-stage { background: var(--canvas); overflow: auto; max-height: calc(94vh - 62px); }
.zoom-stage img { display: block; width: 100%; height: auto; min-width: 900px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: 360px;
  padding: 10px 13px;
  color: #fff;
  background: #263444;
  border-radius: 6px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: none; }

.hidden { display: none !important; }

@media (max-width: 980px) {
  .app-header { position: static; align-items: flex-start; }
  .scoreboard { grid-template-columns: repeat(2, 1fr); }
  .comparison-grid { grid-template-columns: repeat(3, minmax(260px, 1fr)); min-width: 800px; }
}

@media (max-width: 680px) {
  .app-header { display: grid; }
  .header-actions { justify-content: start; }
  .layout { padding-inline: 10px; }
  .status-row { grid-template-columns: 1fr; }
  .scoreboard { grid-template-columns: 1fr 1fr; }
  .review-navigation { align-items: stretch; flex-direction: column; }
  .navigation-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .navigation-status { min-width: 0; text-align: left; }
}
