:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #66717e;
  --line: #d8dee6;
  --paper: #ffffff;
  --wash: #f3f5f7;
  --accent: #175f55;
  --accent-soft: #e2f0ed;
  --warning: #9a5b00;
  --danger: #aa2e25;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--wash); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
kbd { display: inline-block; min-width: 1.35em; padding: 1px 4px; border: 1px solid #b8c2ca; border-bottom-width: 2px; border-radius: 4px; background: #f3f5f7; color: #3f4d58; font-size: .78em; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
[hidden] { display: none !important; }
.device-check-pending > :not(script) { visibility: hidden; }
.device-restricted > :not(#deviceRestriction) { display: none !important; }
.device-restriction { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.device-card { width: min(560px, 100%); padding: 32px 24px; text-align: center; background: white; border: 1px solid var(--line); border-radius: 12px; line-height: 1.8; }
.device-card h1 { margin: 0 0 18px; font-size: clamp(22px, 5vw, 28px); line-height: 1.5; }
.device-card p { margin: 12px 0 0; color: var(--muted); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: 0 18px 50px rgba(28, 39, 49, .08); }
.login-card h1 { margin: 4px 0 10px; font-size: 28px; }
.eyebrow { color: var(--accent); font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.muted, .meta, .gesture-hint { color: var(--muted); }
label { display: block; margin: 22px 0 7px; font-weight: 700; }
input, textarea, select { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: white; }
input:focus, textarea:focus { outline: 3px solid rgba(23, 95, 85, .16); border-color: var(--accent); }
.wide { width: 100%; margin-top: 14px; }
.primary { color: white; background: var(--accent); border: 1px solid var(--accent); border-radius: 10px; padding: 11px 18px; font-weight: 750; }
.quiet { color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 9px; padding: 9px 13px; }
.error { color: var(--danger); min-height: 1.5em; }

.app-shell { min-height: 100vh; padding: 12px max(12px, env(safe-area-inset-right)) 160px max(12px, env(safe-area-inset-left)); }
.topbar { max-width: 1600px; margin: 0 auto 10px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 13px; position: sticky; top: 8px; z-index: 10; backdrop-filter: blur(10px); }
.instruction { margin: 0; font-weight: 760; }
.meta { margin: 4px 0 0; font-size: 14px; }
.status-area { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.sync { padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 750; }
.sync.synced { background: var(--accent-soft); color: var(--accent); }
.sync.local { background: #fff0cf; color: var(--warning); }
.sync.conflict { background: #fee4e1; color: var(--danger); }
.sync.saving { background: #e8edf3; color: #4d5d6d; }
.notice { max-width: 1600px; margin: 0 auto 10px; padding: 10px 14px; border-left: 4px solid var(--warning); background: #fff8e9; border-radius: 8px; }
.state-view { max-width: 760px; margin: 14vh auto; padding: 42px 28px; text-align: center; background: white; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 16px 46px rgba(28,39,49,.08); }
.state-view h2 { margin-top: 0; font-size: 28px; }
.pair { max-width: 1600px; height: min(72vh, 900px); min-height: 430px; margin: auto; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; }
.viewer { min-width: 0; margin: 0; padding: 10px; display: flex; flex-direction: column; background: white; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.viewer figcaption { font-weight: 800; font-size: 18px; padding: 0 4px 8px; }
.viewport { position: relative; flex: 1; overflow: hidden; background: #e9edf0; border-radius: 8px; touch-action: pan-y; user-select: none; }
.zoom-image { width: 100%; height: 100%; display: block; object-fit: contain; transform-origin: center; will-change: transform; }
.image-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.viewport.loaded .image-state { display: none; }
.viewport.failed .image-state { color: var(--danger); }
.gesture-hint { max-width: 1600px; margin: 8px auto 0; text-align: center; font-size: 13px; }
.answer-panel { position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 12; width: min(980px, calc(100% - 24px)); padding: 13px; background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 18px 45px rgba(26, 38, 48, .18); backdrop-filter: blur(10px); }
.choices { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.choice { min-height: 46px; padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: white; font-weight: 720; }
.choice.preference { border-color: #a8c9c3; }
.choice.secondary { color: #4f5b67; }
.choice[aria-pressed="true"] { color: white; border-color: var(--accent); background: var(--accent); }
.edit-row { display: flex; align-items: flex-start; gap: 8px; margin-top: 9px; }
.edit-row details { margin-left: auto; width: min(420px, 55%); }
.edit-row .shortcut-help { width: auto; margin-left: 0; }
.edit-row summary { cursor: pointer; padding: 8px; color: var(--muted); }
.edit-row textarea { min-height: 70px; resize: vertical; }
.shortcut-help p { margin: 4px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.mobile-switch { display: none; }
.pilot-profile .choices { grid-template-columns: repeat(4, 1fr); }
.pilot-profile .app-shell { padding-bottom: 200px; }
.pilot-guide { text-align: left; line-height: 1.7; }
#pilotInstructions { max-width: 1040px; margin: 24px auto; padding: 28px; }
#pilotInstructions h2 { margin-bottom: 10px; }
.guide-intro { margin: 0 0 18px; text-align: center; }
.guide-diagram { margin: 0; padding: 8px 12px 12px; border: 1px solid var(--line); border-radius: 10px; }
.guide-diagram svg { display: block; width: 100%; max-width: 760px; margin: auto; }
.guide-diagram figcaption { text-align: center; font-size: 14px; }
.guide-device { fill: #edf1f4; stroke: #485767; stroke-width: 3; }
.guide-lens { fill: white; stroke: #485767; stroke-width: 3; }
.guide-power { fill: white; stroke: #485767; stroke-width: 2; }
.guide-leader { fill: none; stroke: #17212b; stroke-width: 2.5; }
.guide-label { fill: white; stroke: #17212b; stroke-width: 2; }
.guide-label-text { fill: #17212b; font-size: 23px; text-anchor: middle; }
.guide-anchor { fill: #175f55; stroke: white; stroke-width: 2; }
.guide-callout { fill: none; stroke: #175f55; stroke-width: 1.5; stroke-dasharray: 5 4; }
.guide-caption { fill: #175f55; font-size: 22px; font-weight: 700; text-anchor: middle; }
.guide-definitions, .guide-controls { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; }
.guide-definitions p { margin: 14px 0 0; }
.guide-definitions span, .guide-options span:not(.guide-option-icon), .guide-options strong { display: block; }
.pilot-guide h3 { margin: 22px 0 10px; font-size: 20px; }
.guide-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.guide-options > div { display: flex; align-items: center; gap: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.guide-option-icon { display: grid; place-items: center; width: 46px; height: 46px; flex: 0 0 46px; border: 2px solid var(--ink); border-radius: 8px; font-size: 28px; font-weight: 700; }
.guide-options p, .guide-controls p { margin: 0; }
.guide-footer { padding-top: 16px; border-top: 1px solid var(--line); }
.guide-baseline { margin-top: 22px; padding: 0 0 16px; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); }
.guide-failures, .guide-decision { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.guide-failures figure { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.guide-failures svg { display: block; width: 100%; }
.guide-failures span, .guide-decision span { display: block; }
.guide-failures figcaption strong { display: block; margin: 6px 0; }
.guide-problem { fill: none; stroke: #aa2e25; stroke-width: 3; }
.guide-baseline-note { padding: 12px 0; border-bottom: 1px solid var(--line); }
.guide-decision p { margin: 0; }
@media (max-width: 600px) {
  #pilotInstructions { padding: 20px 14px; }
  #pilotInstructions h2 { font-size: 23px; }
  .guide-definitions, .guide-controls, .guide-options, .guide-failures, .guide-decision { grid-template-columns: 1fr; gap: 10px; }
  .guide-diagram { padding: 8px 0; }
  .guide-diagram figcaption { font-size: 13px; padding: 0 8px; }
}
.pilot-image-controls { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 10px; }
.pilot-profile .answer-panel { width: min(1050px, calc(100% - 24px)); }
.pilot-profile .pair { height: min(calc(100dvh - 330px), 850px); min-height: 220px; }

dialog { width: min(620px, calc(100% - 28px)); border: 1px solid var(--line); border-radius: 15px; padding: 24px; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(15, 23, 30, .55); }
.conflict-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.conflict-grid section { padding: 12px; background: var(--wash); border-radius: 9px; }
.conflict-grid h3 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@media (max-width: 760px) {
  .app-shell { padding-bottom: 205px; }
  .topbar { top: 5px; align-items: flex-start; }
  .status-area { flex-direction: column; align-items: flex-end; gap: 5px; }
  .status-area .quiet { padding: 6px 9px; font-size: 13px; }
  .mobile-switch { display: grid; grid-template-columns: 1fr 1fr; max-width: 320px; margin: 7px auto; padding: 3px; background: #dfe5e8; border-radius: 10px; }
  .mobile-switch button { border: 0; border-radius: 8px; padding: 8px; background: transparent; }
  .mobile-switch button.active { background: white; color: var(--accent); font-weight: 800; }
  .pair { display: block; height: 58vh; min-height: 330px; }
  .viewer { height: 100%; }
  body[data-mobile-side="A"] .viewer[data-side="B"],
  body[data-mobile-side="B"] .viewer[data-side="A"] { display: none; }
  .choices { grid-template-columns: repeat(3, 1fr); }
  .choice.secondary { grid-column: span 1; }
  .edit-row { flex-wrap: wrap; }
  .edit-row details { width: 100%; margin-left: 0; }
  .edit-row .shortcut-help { width: auto; }
  .gesture-hint { padding: 0 8px; }
  .conflict-grid { grid-template-columns: 1fr; }
}

@media (min-width: 761px) and (max-width: 1100px) {
  .pair { height: 65vh; }
}

/* Pilot comparisons always use the same two-column canvas, including tablets. */
.pilot-profile .app-shell { padding-bottom: 24px; }
.pilot-profile .topbar { flex-wrap: wrap; position: static; }
.pilot-profile .status-area { flex-wrap: wrap; white-space: normal; }
.pilot-profile .pair { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); height: min(60dvh,850px); min-height: 240px; }
.pilot-profile .viewer { display: flex !important; height: 100%; }
.pilot-profile .mobile-switch { display: none; }
.pilot-profile .answer-panel { position: static; transform: none; margin: 12px auto; box-shadow: none; }
.pilot-profile .pilot-image-controls { flex-wrap: wrap; }
.pilot-profile .guide-options { align-items: stretch; }
.pilot-profile .completed-export { display: inline-block; margin: 12px; }
.centralized .completed-export, .centralized #pilotImageControls a { display: none; }
.pilot-profile.comparison-blocked #taskView,
.pilot-profile.comparison-blocked #acceptInstructions,
.pilot-profile.comparison-blocked #startFormal { display: none !important; }
@media (min-width: 761px) and (max-width: 1100px) {
  #pilotInstructions { padding: 22px; }
  .guide-controls, .guide-definitions, .guide-failures { gap: 10px; }
  .guide-options > div { padding: 10px; gap: 10px; }
}

/* At fit scale, a single finger scrolls the page; zoomed images own panning. */
.viewport.image-zoomed { touch-action: none; }
.pilot-profile.tablet-device.comparison-active .app-shell { height: 100dvh; min-height: 480px; display: flex; flex-direction: column; padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
.pilot-profile.tablet-device.comparison-active .topbar { width: 100%; flex: 0 0 auto; padding: 8px 12px; gap: 8px; margin-bottom: 6px; }
.pilot-profile.tablet-device.comparison-active .instruction { display: none; }
.pilot-profile.tablet-device.comparison-active .meta { margin: 0; }
.pilot-profile.tablet-device.comparison-active .notice { width: 100%; flex: 0 0 auto; margin-bottom: 6px; padding: 6px 10px; }
.pilot-profile.tablet-device.comparison-active #taskView { flex: 1 0 0; min-height: 0; display: grid; grid-template-rows: minmax(240px, 1fr) auto auto; gap: 4px; }
.pilot-profile.tablet-device.comparison-active .pair { width: 100%; height: 100%; min-height: 240px; gap: 8px; }
.pilot-profile.tablet-device.comparison-active .viewer { padding: 6px; min-height: 0; }
.pilot-profile.tablet-device.comparison-active .viewer figcaption { font-size: 16px; padding-bottom: 4px; }
.pilot-profile.tablet-device.comparison-active .pilot-image-controls { margin: 0; gap: 8px; }
.pilot-profile.tablet-device.comparison-active .pilot-image-controls .quiet { padding: 6px 10px; }
.pilot-profile.tablet-device.comparison-active .pilot-image-controls label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.pilot-profile.tablet-device.comparison-active .pilot-image-controls input { width: auto; }
.pilot-profile.tablet-device.comparison-active .answer-panel { width: 100%; max-width: 1600px; margin: 0 auto; padding: 6px; }
.pilot-profile.tablet-device.comparison-active .choice { min-height: 52px; }
.pilot-profile.tablet-device.comparison-active .edit-row { margin-top: 4px; }
@media (max-height: 600px) {
  .pilot-profile.tablet-device.comparison-active .topbar { padding: 6px 10px; margin-bottom: 4px; }
  .pilot-profile.tablet-device.comparison-active .notice { font-size: 13px; padding: 4px 8px; margin-bottom: 4px; }
  .pilot-profile.tablet-device.comparison-active .edit-row summary { padding: 4px; }
}
