:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #5b6472;
  --line: #d8dee8;
  --accent: #136f63;
  --accent-dark: #0f574e;
  --accent-soft: #e6f1ef;
  --danger: #a52828;
  --slot-a: #1f6feb;
  --slot-b: #b8730f;
}

/* Alternate palette for the second questionnaire, so the two studies look
   distinct at a glance. Activated by body[data-theme], which app.js sets from
   study.theme in the backend config. Only the brand accent + page background
   change; the A/B decision colors (--slot-a / --slot-b) and the error red stay
   the same so those cues read identically across both studies. */
body[data-theme="violet"] {
  --accent: #6d28d9;
  --accent-dark: #57208f;
  --accent-soft: #ede9fe;
  --bg: #f7f6fb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ---------- Header / progress ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.app-header-inner {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
}
.brand { font-weight: 700; font-size: 18px; }
.progress { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.progress-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: #fff;
  border-radius: 99px;
  transition: width 0.3s ease;
}
.progress-text { font-size: 13px; white-space: nowrap; }

/* ---------- Layout ---------- */
main {
  width: min(960px, calc(100% - 32px));
  margin: 28px auto 80px;
}
h1 { font-size: 28px; margin: 0 0 12px; }
h2 { font-size: 20px; margin: 0 0 10px; }
h3 { font-size: 17px; margin: 0 0 6px; }
p { margin: 0 0 14px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  margin: 16px 0;
}

.field { margin: 14px 0; }
.field:first-child { margin-top: 0; }
label { display: block; font-weight: 700; margin: 0 0 6px; }
select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 84px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
/* Inside a grid both cells must align at the top (no asymmetric first-child margin). */
.grid-2 .field { margin: 0; }

/* ---------- Buttons ---------- */
.actions { display: flex; gap: 10px; margin: 20px 0; align-items: center; }
.actions.wrap { flex-wrap: wrap; }
button {
  border: 0;
  border-radius: 8px;
  padding: 11px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.secondary { background: #eef1f5; color: #334155; border: 1px solid var(--line); }
button.secondary:hover { background: #e2e7ee; }
button.link {
  background: none; color: var(--accent); padding: 0; font-weight: 700;
  text-decoration: underline; cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Consent ---------- */
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 4px; }
.consent-card span { color: var(--text); }
.resume-note { font-size: 14px; }

/* ---------- Instructions ---------- */
.instructions-card { border-left: 4px solid var(--accent); }
.steps-list {
  list-style: none;
  counter-reset: step;
  margin: 0;
  padding: 0;
}
.steps-list li {
  position: relative;
  counter-increment: step;
  padding: 12px 0 12px 44px;
  border-top: 1px solid #edf0f5;
  color: var(--text);
}
.steps-list li:first-child { border-top: 0; }
.steps-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 12px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
}
.notes-list { margin: 0; padding-left: 20px; color: var(--text); }
.notes-list li { margin: 6px 0; }

/* ---------- Likert (1-7) ---------- */
.likert-row {
  padding: 14px 0;
  border-top: 1px solid #edf0f5;
}
.likert-row:first-child { border-top: 0; padding-top: 0; }
.likert-statement { font-weight: 700; margin-bottom: 8px; }
/* Pills on one row, the two end-anchors on their own row underneath. This keeps
   long anchors like "Very appropriate" beside their end instead of wrapping
   below the buttons, and works in narrow (half-width) decision cards. */
.likert-scale { max-width: 400px; }
.likert-options { display: flex; gap: 6px; justify-content: space-between; flex-wrap: wrap; }
.likert-ends { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; }
.likert-anchor { font-size: 12px; color: var(--muted); max-width: 48%; }
.likert-anchor.right { text-align: right; }
.likert-options label {
  margin: 0;
  font-weight: 700;
  cursor: pointer;
}
.likert-options input { position: absolute; opacity: 0; pointer-events: none; }
.likert-options .pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  user-select: none;
}
.likert-options input:checked + .pill {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.likert-options label:hover .pill { border-color: var(--accent); }

/* ---------- Preferences ---------- */
.pref-group { margin-bottom: 18px; }
.pref-group > h3 {
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 8px 12px;
  border-radius: 8px;
}
.pref-row {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.2fr);
  gap: 16px;
  align-items: start;
  padding: 14px 4px;
  border-top: 1px solid #edf0f5;
}
.pref-row:first-of-type { border-top: 0; }
.pref-label { font-weight: 700; }
.pref-desc { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.pref-controls { display: flex; flex-direction: column; gap: 10px; }
.choice-group { display: flex; flex-direction: column; gap: 6px; }
.choice-group .opt {
  display: flex; gap: 8px; align-items: center;
  font-weight: 400; margin: 0; cursor: pointer;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
}
.choice-group .opt input { margin: 0; }
.choice-group .opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.importance { display: none; }
.importance.show { display: block; }
.importance > .imp-label { font-size: 13px; font-weight: 700; margin-bottom: 4px; }

/* ---------- Scenarios ---------- */
.scenario-card { border-left: 4px solid var(--accent); }
.scenario-axis-tag {
  display: inline-block;
  font-size: 12px;
  text-transform: capitalize;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 99px;
  padding: 2px 10px;
  margin-bottom: 8px;
}
.scenario-desc { color: var(--text); font-size: 16px; }

.decision-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.decision-card { border: 1px solid var(--line); border-radius: 10px; padding: 16px; background: #fff; }
.decision-card .decision-name {
  font-weight: 700; font-size: 15px; margin-bottom: 8px;
  display: inline-block; padding: 2px 10px; border-radius: 6px; color: #fff;
}
.decision-card.slot-a .decision-name { background: var(--slot-a); }
.decision-card.slot-b .decision-name { background: var(--slot-b); }
.decision-text { font-size: 16px; color: var(--text); margin-bottom: 4px; }

.metric { padding: 10px 0; border-top: 1px solid #edf0f5; }
.metric:first-of-type { border-top: 0; }
.metric-q { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.metric .likert-options label .pill { width: 32px; height: 32px; font-size: 14px; }

.compare-card { background: var(--accent-soft); border-color: #cfe3df; }
.compare-q { margin: 12px 0; }
.compare-q .compare-label { font-weight: 700; margin-bottom: 6px; }
.ab-choice { display: flex; gap: 10px; }
.ab-choice label {
  flex: 1; margin: 0; font-weight: 700; text-align: center; cursor: pointer;
  padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.ab-choice input { position: absolute; opacity: 0; pointer-events: none; }
.ab-choice label.sel-a { }
.ab-choice input:checked + .pill-ab { }
.ab-choice .opt-a.checked { border-color: var(--slot-a); background: #e7f0fe; color: var(--slot-a); }
.ab-choice .opt-b.checked { border-color: var(--slot-b); background: #fdf1e1; color: var(--slot-b); }

.ideal-action-q { padding-top: 12px; border-top: 1px solid #cfe3df; }
.ideal-action-choice {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.ideal-action-choice label {
  margin: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}
.ideal-action-choice input { position: absolute; opacity: 0; pointer-events: none; }
.ideal-action-choice label.checked {
  border-color: var(--accent);
  background: #fff;
  color: var(--accent-dark);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ---------- Misc ---------- */
.error { color: var(--danger); font-weight: 700; }
.error-card { border-color: var(--danger); }
.loading-card { text-align: center; padding: 40px; }
.spinner {
  width: 36px; height: 36px; margin: 0 auto 14px;
  border: 4px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-ok { color: var(--accent-dark); font-weight: 700; }
.status-warn { color: var(--danger); font-weight: 700; }

.scenario-counter { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field-error label { color: var(--danger); }

@media (max-width: 760px) {
  .grid-2, .decision-grid, .pref-row, .ideal-action-choice { grid-template-columns: 1fr; }
  .likert-anchor { min-width: 64px; }
  .likert-options .pill { width: 34px; height: 34px; }
}
