:root {
  --bg: #f6f2ec;
  --panel: #fffdf9;
  --panel-strong: #ffffff;
  --ink: #211d18;
  --muted: #766f66;
  --line: #e5ded4;
  --accent: #7a4f2a;
  --accent-dark: #553316;
  --accent-soft: #efe2d4;
  --danger: #9f2a2a;
  --shadow: 0 18px 42px rgba(61, 43, 25, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(122,79,42,.16), transparent 28rem),
    linear-gradient(180deg, #faf7f2 0%, var(--bg) 45%, #f1ebe3 100%);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgba(255, 253, 249, 0.82);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(229,222,212,.8);
}
.brand {
  font-weight: 800;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar a { color: var(--accent-dark); text-decoration: none; font-weight: 650; }
.participant-chip {
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 13px;
}

.page {
  width: min(1500px, calc(100% - 32px));
  margin: 26px auto 56px;
}
.card {
  background: rgba(255,253,249,.94);
  border: 1px solid rgba(229,222,212,.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  padding: clamp(26px, 5vw, 54px);
  align-items: center;
}
.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 12px;
  font-weight: 800;
}
h1, h2, h3 { letter-spacing: -0.035em; line-height: 1.05; }
h1 { margin: 0 0 16px; font-size: clamp(34px, 5vw, 64px); }
h2 { margin: 0 0 18px; font-size: 26px; }
h3 { margin: 0 0 8px; font-size: 18px; }
.lead {
  font-size: clamp(18px, 2vw, 22px);
  color: #4d453d;
  max-width: 900px;
  line-height: 1.55;
}
.intro-copy {
  display: grid;
  gap: 14px;
}
.intro-copy p { margin: 0; }
.hero-stat {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-align: center;
  background: linear-gradient(180deg, #fff, var(--accent-soft));
  border: 1px solid #ddc8b4;
}
.hero-stat strong { display: block; font-size: 44px; }
.hero-stat span { color: var(--muted); font-size: 13px; }
.narrow-card, .readable {
  width: min(780px, 100%);
  margin: 24px auto;
  padding: clamp(22px, 4vw, 36px);
}
.readable { width: min(900px, 100%); }
.code-form { display: grid; gap: 12px; }
label { font-weight: 750; }
input[type="text"], input[type="email"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 13px 14px;
  font: inherit;
  outline: none;
}
input[type="text"]:focus, input[type="email"]:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(122,79,42,.12); }
button, .primary, .secondary {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.primary {
  background: var(--accent);
  color: #fff;
  padding: 13px 22px;
  box-shadow: 0 10px 18px rgba(122,79,42,.2);
}
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.secondary { background: #eee4da; color: var(--accent-dark); padding: 13px 22px; }
.big-button { margin-top: 18px; }
.ghost {
  background: #f2ebe3;
  color: var(--accent-dark);
  border: 1px solid #e0d4c8;
  padding: 8px 10px;
  box-shadow: none;
}
.ghost:hover { background: #e8dbce; }
.small-btn { width: 34px; height: 34px; padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
kbd {
  border: 1px solid #d8cbbd;
  background: #fff;
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: .9em;
}
.instruction-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 24px 0;
}
.instruction-grid > div {
  background: #fff8f0;
  border: 1px solid #eadbca;
  border-radius: 16px;
  padding: 18px;
}
.messages { width: min(900px, calc(100% - 32px)); margin: 18px auto 0; }
.message { padding: 12px 16px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.message.error { border-color: #d69; color: var(--danger); }

.trial-header {
  padding: 18px 22px;
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}
.trial-header h1 { font-size: clamp(24px, 3vw, 36px); margin: 0; }
.progress-wrap { width: min(380px, 42vw); color: var(--muted); font-size: 14px; }
.progress {
  height: 10px;
  background: #eee6dc;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress div { height: 100%; background: var(--accent); border-radius: inherit; }

.triad-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}
.line-card { overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.line-card-header {
  padding: 14px 14px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.line-label {
  min-width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  background: var(--accent);
}
.zoom-controls { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.zoom-controls input[type="range"] { width: 92px; accent-color: var(--accent); }
.image-viewport {
  height: clamp(430px, 58vh, 760px);
  overflow: auto;
  padding: 18px;
  cursor: default;
  touch-action: none;
  background:
    linear-gradient(45deg, rgba(0,0,0,.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0,0,0,.025) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,.025) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,.025) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}
.image-viewport img {
  display: block;
  width: auto;
  max-width: none;
  max-height: none;
  height: auto;
  margin: 0 auto;
  user-select: none;
  pointer-events: none;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.06), 0 12px 24px rgba(0,0,0,.08);
  background: #fff;
}

.answer-panel {
  margin-top: 16px;
  padding: 18px;
  display: grid;
  grid-template-columns: 1.2fr .8fr 1fr auto;
  gap: 18px;
  align-items: center;
}
.pair-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pair-option input { position: absolute; opacity: 0; pointer-events: none; }
.pair-option span {
  display: grid;
  place-items: center;
  min-height: 56px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 2px solid #e1d5ca;
  background: #fff;
  font-weight: 900;
  font-size: 20px;
  cursor: pointer;
  transition: .12s ease;
}
.pair-option input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  transform: translateY(-1px);
}
.confidence-block { display: grid; gap: 8px; }
.confidence-block input { accent-color: var(--accent); }
.confidence-ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.comment-block { display: grid; gap: 8px; }
.submit-button { min-height: 54px; }
.form-errors {
  grid-column: 1 / -1;
  color: var(--danger);
  background: #fff0f0;
  border: 1px solid #f2c7c7;
  border-radius: 12px;
  padding: 10px 12px;
}

.finish-card { text-align: center; }
.score-box {
  margin: 26px auto;
  width: min(420px, 100%);
  padding: 26px;
  border-radius: 22px;
  background: linear-gradient(180deg, #fff, var(--accent-soft));
  border: 1px solid #ddc8b4;
  display: grid;
  gap: 4px;
}
.score-box strong { font-size: clamp(46px, 8vw, 76px); letter-spacing: -.06em; }
.score-label { color: var(--accent); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 900; }
.mini-table { width: min(560px, 100%); margin: 20px auto; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; text-align: left; }
.mini-row { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 12px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.mini-row:last-child { border-bottom: 0; }
.mini-row.head { background: #f2ebe3; font-weight: 900; }

.modal[aria-hidden="true"] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(25,18,12,.72); backdrop-filter: blur(4px); }
.modal-content {
  position: absolute;
  inset: 28px;
  background: #fffdf9;
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.modal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-actions { display: flex; gap: 8px; }
.modal-viewport {
  flex: 1;
  overflow: auto;
  padding: 24px;
  background: #f4eee7;
  cursor: default;
  touch-action: none;
}
.modal-viewport img { display: block; width: auto; max-width: none; max-height: none; height: auto; margin: auto; pointer-events: none; background: #fff; }
.image-viewport.is-pannable,
.modal-viewport.is-pannable { cursor: grab; }
.image-viewport.is-dragging,
.modal-viewport.is-dragging { cursor: grabbing; }

@media (max-width: 1180px) {
  .triad-grid { grid-template-columns: 1fr; }
  .image-viewport { height: min(56vh, 560px); }
  .answer-panel { grid-template-columns: 1fr; }
  .pair-buttons { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; }
  .hero-stat { width: 120px; height: 120px; }
  .instruction-grid { grid-template-columns: 1fr; }
  .trial-header { flex-direction: column; align-items: stretch; }
  .progress-wrap { width: 100%; }
  .line-card-header { flex-direction: column; align-items: stretch; }
  .zoom-controls { justify-content: flex-start; }
  .pair-buttons { grid-template-columns: 1fr; }
}
