:root {
  --bg: #f5f7f4; --surface: #ffffff; --ink: #16231c; --muted: #5b6b62; --line: #e1e7e2;
  --accent: #2f7d5b; --accent-ink: #ffffff; --action: #4650c9; --action-ink: #ffffff;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 8px 24px rgba(20, 40, 30, .08);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512; --surface: #172019; --ink: #e8f0eb; --muted: #9db0a4; --line: #26332b;
    --accent: #5cc39a; --accent-ink: #06210f; --action: #8d97ff; --action-ink: #0d1030;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); min-height: 100dvh;
  display: flex; flex-direction: column; -webkit-text-size-adjust: 100%;
}
.top { display: flex; justify-content: space-between; align-items: center; width: 100%; max-width: 860px; margin: 0 auto; padding: 12px 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--accent); }
.brand span { color: var(--ink); }
.lang { display: flex; gap: 6px; }
.chip { font: inherit; font-size: .8rem; font-weight: 600; min-height: 44px; min-width: 48px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 4px 16px 28px; }
.screen[hidden] { display: none !important; }   /* beats the id rule on #s-trial */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
h1 { font-size: clamp(1.5rem, 4.4vw, 2.1rem); line-height: 1.2; margin: 0 0 12px; letter-spacing: -.01em; }
h2 { font-size: clamp(1.25rem, 3.4vw, 1.6rem); line-height: 1.25; margin: 0 0 8px; }
h1:focus, h2:focus { outline: none; }
.lead { color: var(--muted); margin: 0 0 16px; }
h2.lead { font-size: 1rem; font-weight: 400; line-height: 1.5; }
.fine { color: var(--muted); font-size: .82rem; margin: 14px 0 0; }
.center { text-align: center; }
.meta { font-weight: 600; margin: 0 0 16px; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; padding: 0; margin: 20px 0; list-style: none; }
.steps li { display: flex; align-items: center; gap: 10px; }
.steps b { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); }

.btn { appearance: none; font: inherit; font-weight: 600; min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; transition: transform .06s, background .15s, opacity .15s; -webkit-tap-highlight-color: transparent; }
.btn.primary { background: var(--action); color: var(--action-ink); border-color: transparent; }
.btn.wide { width: 100%; }
.btn:active { transform: scale(.98); }
.btn:focus-visible, .chip:focus-visible, .link:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { font: inherit; background: none; border: 0; color: var(--muted); text-decoration: underline; min-height: 44px; margin-top: 8px; cursor: pointer; }
.opts { display: grid; gap: 10px; margin-bottom: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row .btn { flex: 1 1 160px; }

#s-trial { display: flex; flex-direction: column; gap: 10px; max-width: 780px; margin: 0 auto; }
.progress-row { display: flex; align-items: center; gap: 12px; }
.progress { flex: 1; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.count { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.q { margin: 4px 0 0; }
.hint { color: var(--muted); font-size: .9rem; margin: 0; }
.panel { position: relative; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel img { display: block; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; background: color-mix(in srgb, var(--ink) 5%, transparent); transition: opacity .15s; }
.tag { position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, .6); color: #fff; font-size: .75rem; font-weight: 600; padding: 2px 10px; border-radius: 99px; }
.ref { height: clamp(150px, 30vh, 320px); }
.species { margin: 6px 0 0; text-align: center; font-size: .85rem; font-style: italic; color: var(--muted); }
.cands { --cands-vh: 72vh; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; margin-inline: auto; max-width: calc(var(--cands-vh) + 12px); }   /* max-width keeps each A/B button as wide as its image */
.cand { display: flex; flex-direction: column; gap: 8px; }
.cand .panel { aspect-ratio: 1 / 1; width: 100%; }
/* Same square box and same crop for every candidate, so the real-photo attention check cannot be spotted by its shape. */
.cand .panel img, dialog img.sq { object-fit: cover; }
body.loading #s-trial .panel img { opacity: 0; }
body.loading #s-trial .panel { background: linear-gradient(90deg, var(--line), transparent, var(--line)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
body.loading #s-trial .btn { pointer-events: none; opacity: .5; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
kbd { font: inherit; font-size: .75rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; }
@media (max-width: 899px) {
  .ref-wrap { position: sticky; top: 0; z-index: 2; background: var(--bg); padding-block: 2px; }
  .kbds { display: none; }
}
@media (min-width: 900px) {
  /* Laptop: real photo on the left, A/B and their buttons on the right, so the whole trial fits one screen. */
  main { padding-top: 8px; }
  #s-trial { max-width: 1040px; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); column-gap: 20px; row-gap: 8px; align-items: start; }
  #s-trial > .progress-row, #s-trial > .q, #s-trial > .hint, #s-trial > .fine { grid-column: 1 / -1; }
  .q { margin-top: 0; }
  .ref-wrap { grid-column: 1; grid-row: 4 / span 2; align-self: stretch; display: flex; flex-direction: column; }
  .ref { flex: 1; height: auto; min-height: 200px; }
  .ref img { position: absolute; inset: 0; }
  .cands { --cands-vh: 76vh; grid-column: 2; grid-row: 4; }
  #btn-same { grid-column: 2; grid-row: 5; }
}

.spinner { width: 28px; height: 28px; margin: 0 auto 12px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
dialog { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 94dvh; }
dialog::backdrop { background: rgba(0, 0, 0, .78); }
dialog img { display: block; max-width: 96vw; max-height: 82dvh; margin: 0 auto 12px; border-radius: 12px; }
dialog img.sq { width: min(96vw, 82dvh); height: min(96vw, 82dvh); max-width: none; max-height: none; }
dialog .btn { display: block; margin: 0 auto; }
#toast { position: fixed; width: max-content; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: calc(100vw - 32px); z-index: 10; opacity: 0; pointer-events: none; transition: opacity .15s; }
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
