/* AI Atlas participant study and research workspace.
   A document-like instrument: white page, one readable column, rules instead of cards,
   one muted accent for primary actions and links. No web fonts.
   Type scale: four sizes (--fs-1 14 px, --fs-2 16 px, --fs-3 20 px, --fs-4 24 px).
   Spacing scale: 8 px steps (--s1 8, --s2 16, --s3 24, --s4 32, --s5 48). */

:root {
 --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
 --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
 --ink: #1b1b1b;
 --ink-muted: #555555;
 --rule: #d4d4d4;
 --rule-light: #e6e6e6;
 --surface: #ffffff;
 --surface-muted: #f4f4f4;
 --accent: #2f4f7a;
 --accent-hover: #233c5e;
 --danger: #9a2a2a;
 --warning: #7a5a00;
 --recording: #9a2a2a;
 --control-border: #767676;
 --disabled-ink: #6f6f6f;
 --disabled-border: #c4c4c4;
 --disabled-surface: #f4f4f4;
 --fs-1: .875rem;
 --fs-2: 1rem;
 --fs-3: 1.25rem;
 --fs-4: 1.5rem;
 --s1: 8px;
 --s2: 16px;
 --s3: 24px;
 --s4: 32px;
 --s5: 48px;
 --measure: 70ch;
 --bar-height: 48px;
 --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231b1b1b' stroke-width='1.5'/%3E%3C/svg%3E");
 --chevron-muted: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236f6f6f' stroke-width='1.5'/%3E%3C/svg%3E");
 font-family: var(--font);
 color: var(--ink);
 background: var(--surface);
 font-size: 16px;
 line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header: the study name and what this page is, closed by a thin rule. */
header {
 display: flex;
 justify-content: space-between;
 align-items: center;
 gap: var(--s2);
 min-height: var(--bar-height);
 padding: var(--s1) var(--s3);
 border-bottom: 1px solid var(--rule);
}
header a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: var(--fs-2); }
header a + span { margin-right: auto; }
header span { font-size: var(--fs-1); font-weight: 400; color: var(--ink-muted); }

main { max-width: 44rem; margin: 0 auto; padding: var(--s3) var(--s3) var(--s5); }
main:has(#task:not([hidden])) { max-width: 1200px; }

/* Type: four sizes, heavy left-aligned headings, a measured column for running text. */
h1 { font-size: var(--fs-4); line-height: 1.25; font-weight: 700; letter-spacing: -.01em; margin: 0 0 var(--s2); max-width: var(--measure); }
h2 { font-size: var(--fs-3); line-height: 1.3; font-weight: 700; margin: 0 0 var(--s1); }
h3 { font-size: var(--fs-2); line-height: 1.4; font-weight: 700; margin: var(--s2) 0 var(--s1); }
p { margin: 0 0 var(--s2); max-width: var(--measure); }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
strong { font-weight: 600; }
.intro { max-width: var(--measure); margin-bottom: var(--s2); }
.step-label { font-size: var(--fs-1); font-weight: 500; color: var(--ink-muted); margin: 0 0 var(--s1); }
.hint { font-size: var(--fs-1); color: var(--ink-muted); }
.hint a { color: var(--accent); }
.field-help { display: block; font-size: var(--fs-1); font-weight: 400; color: var(--ink-muted); margin-top: 2px; }

/* Visit steps: setup, task 1, break, task 2, finish. study.mjs sets the class
   (at-setup, at-task1, at-break, at-task2, at-finish; single for one-task visits). */
.steps {
 list-style: none;
 display: flex;
 flex-wrap: wrap;
 gap: var(--s1) var(--s3);
 margin: 0 0 var(--s3);
 padding: 0 0 var(--s2);
 border-bottom: 1px solid var(--rule-light);
 font-size: var(--fs-1);
 color: var(--ink-muted);
 counter-reset: step;
}
.steps li { display: flex; align-items: center; counter-increment: step; }
.steps li::before {
 content: counter(step);
 display: inline-flex;
 margin-right: var(--s1);
 align-items: center;
 justify-content: center;
 width: 24px;
 height: 24px;
 border: 1px solid var(--rule);
 border-radius: 50%;
 font-size: var(--fs-1);
 line-height: 1;
 color: var(--ink-muted);
 background: var(--surface);
}
.steps.single li:nth-child(3), .steps.single li:nth-child(4), .steps.single .step-n { display: none; }
.steps.at-setup li:nth-child(1), .steps.at-task1 li:nth-child(2), .steps.at-break li:nth-child(3), .steps.at-task2 li:nth-child(4), .steps.at-finish li:nth-child(5) { color: var(--ink); font-weight: 600; }
.steps.at-setup li:nth-child(1)::before, .steps.at-task1 li:nth-child(2)::before, .steps.at-break li:nth-child(3)::before, .steps.at-task2 li:nth-child(4)::before, .steps.at-finish li:nth-child(5)::before { border: 2px solid var(--accent); color: var(--accent); font-weight: 600; }
.steps.at-task1 li:nth-child(1)::before, .steps.at-break li:nth-child(-n+2)::before, .steps.at-task2 li:nth-child(-n+3)::before, .steps.at-finish li:nth-child(-n+4)::before { content: "\2713"; background: var(--accent); border-color: var(--accent); color: #fff; }

/* Sections replace cards: a rule above, no fill, square corners. */
.card { background: transparent; border: 0; border-top: 1px solid var(--rule); border-radius: 0; padding: var(--s3) 0; margin: 0; }
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
#loading { padding-top: var(--s3); color: var(--ink-muted); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s3); }
#finish .grid { grid-template-columns: 1fr; }
#finish textarea { min-height: 96px; }

/* Alerts: a left border and plain text, never a tinted box. */
#error, .notice {
 border: 0;
 border-left: 3px solid var(--ink-muted);
 border-radius: 0;
 background: transparent;
 padding: 0 0 0 var(--s2);
 margin: 0 0 var(--s3);
 max-width: var(--measure);
 color: var(--ink);
}
#error { border-left-color: var(--danger); color: var(--danger); }
#error:empty { display: none; }
#displayStatus { margin: var(--s2) 0; }
#displayStatus:empty { display: none; }
.sharing-banner {
 position: sticky;
 top: 0;
 z-index: 30;
 background: var(--surface);
 border-left: 3px solid var(--warning);
 border-bottom: 1px solid var(--rule);
 padding: var(--s2) 0 var(--s2) var(--s2);
 color: var(--ink);
}
.sharing-banner strong { display: block; margin-bottom: var(--s1); }
.sharing-banner button { margin: var(--s1) 0 0; }

/* Support disclosure sits under the steps as a single line. */
.support { border-bottom: 1px solid var(--rule-light); margin: 0 0 var(--s3); padding: 0 0 var(--s2); font-size: var(--fs-2); }
.support summary { cursor: pointer; font-weight: 500; color: var(--accent); }
.support[open] summary { margin-bottom: var(--s1); }
.support p { margin-bottom: var(--s1); overflow-wrap: anywhere; }

/* Forms. One control style: 1 px border, 2 px radius, 8 px padding. */
label { display: block; font-size: var(--fs-2); font-weight: 600; line-height: 1.4; max-width: var(--measure); margin: 0 0 var(--s2); }
input, textarea, select, button { font: inherit; }
input:not([type=checkbox]), textarea, select {
 display: block;
 width: 100%;
 margin: var(--s1) 0 0;
 border: 1px solid var(--control-border);
 border-radius: 2px;
 padding: var(--s1);
 background: var(--surface);
 color: var(--ink);
 font-weight: 400;
 line-height: 1.5;
}
input:not([type=checkbox]):focus-visible, textarea:focus-visible, select:focus-visible { border-color: var(--accent); }
input:disabled, textarea:disabled, select:disabled { color: var(--disabled-ink); border-color: var(--disabled-border); background: var(--disabled-surface); }
select {
 appearance: none;
 -webkit-appearance: none;
 padding-right: var(--s4);
 background: var(--surface) var(--chevron) no-repeat right 12px center;
 cursor: pointer;
}
select:disabled { background-image: var(--chevron-muted); background-color: var(--disabled-surface); cursor: not-allowed; }
input[type=checkbox] { width: 18px; height: 18px; flex-shrink: 0; margin: 2px 0 0; accent-color: var(--accent); }
textarea { min-height: 88px; resize: vertical; }
textarea::placeholder, input::placeholder { color: #6f6f6f; }
.check { display: flex; align-items: flex-start; gap: var(--s2); margin: var(--s2) 0; font-weight: 500; }
.check input { margin-top: 3px; }

/* File pickers: the native input stays in the DOM (same id, same change handler) but is
   visually hidden; the sibling span is the button. Chosen files are listed below it. */
.file-field { position: relative; margin-bottom: var(--s1); }
.file-field > span:first-child { display: block; }
.file-field input[type=file] { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.file-button {
 display: inline-block;
 margin: var(--s1) 0 0;
 padding: var(--s1) var(--s2);
 border: 1px solid var(--control-border);
 border-radius: 2px;
 background: var(--surface);
 color: var(--ink);
 font-size: var(--fs-2);
 font-weight: 500;
 line-height: 1.4;
 cursor: pointer;
}
.file-field:hover .file-button { background: var(--surface-muted); border-color: var(--ink); }
.file-field input:focus-visible + .file-button { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-field input:disabled + .file-button, .file-field:hover input:disabled + .file-button { color: var(--disabled-ink); border-color: var(--disabled-border); background: var(--disabled-surface); cursor: not-allowed; }

/* Buttons: one filled accent for the primary action; outlined secondary; disabled
   controls are outlined grey rather than a faded copy of the primary button. */
button, .button {
 display: inline-block;
 background: var(--accent);
 color: #fff;
 border: 1px solid var(--accent);
 border-radius: 2px;
 padding: var(--s1) var(--s2);
 font-size: var(--fs-2);
 font-weight: 500;
 line-height: 1.4;
 text-decoration: none;
 cursor: pointer;
 margin: 0 var(--s1) var(--s1) 0;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.secondary { background: var(--surface); color: var(--ink); border-color: var(--control-border); }
.secondary:hover { background: var(--surface-muted); color: var(--ink); border-color: var(--ink); }
button:disabled, button:disabled:hover, .secondary:disabled, .secondary:disabled:hover {
 background: var(--disabled-surface);
 color: var(--disabled-ink);
 border-color: var(--disabled-border);
 cursor: not-allowed;
 opacity: 1;
}
.actions { display: flex; flex-wrap: wrap; gap: var(--s1); margin: var(--s2) 0; }
.actions button { margin: 0; }
.download { font-weight: 500; }

/* Task page. A slim sticky bar keeps the step, recording state and clock in view. */
.task-bar {
 position: sticky;
 top: 0;
 z-index: 20;
 display: flex;
 align-items: center;
 flex-wrap: wrap;
 gap: var(--s1) var(--s3);
 min-height: var(--bar-height);
 margin: 0 0 var(--s2);
 padding: var(--s1) 0;
 background: var(--surface);
 border-bottom: 1px solid var(--rule);
}
.task-bar .step-label { margin: 0; color: var(--ink); font-weight: 600; }
.recording-state { display: inline-flex; align-items: center; gap: var(--s1); font-size: var(--fs-1); color: var(--ink-muted); }
.recording-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--rule); flex-shrink: 0; }
.recording-state.is-recording { color: var(--recording); font-weight: 600; }
.recording-state.is-recording::before { background: var(--recording); }
.clock { margin-left: auto; display: flex; align-items: baseline; gap: var(--s1); white-space: nowrap; }
.clock strong { font-family: var(--mono); font-size: var(--fs-3); line-height: 1.2; font-weight: 500; font-variant-numeric: tabular-nums; }
.clock > span { font-size: var(--fs-1); color: var(--ink-muted); }
#taskTitle { margin-bottom: var(--s2); }

.recorder { border: 1px solid var(--rule); border-radius: 2px; padding: var(--s2) var(--s3); margin: 0 0 var(--s3); }
.recorder h2 { margin-top: 0; }
.recorder > .hint:last-child { margin-top: var(--s1); }
#displaySetup { margin-top: var(--s2); }
.preview { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s2); margin: var(--s2) 0; }
.preview > div { min-width: 0; }
.preview video { display: block; width: 100%; height: 160px; background: #222; border-radius: 0; object-fit: contain; }
.preview span { font-size: var(--fs-1); color: var(--ink-muted); }
.preview button { font-size: var(--fs-1); padding: 2px var(--s1); float: right; margin: var(--s1) 0 0; }
#displayCount { max-width: 240px; }
#taskLocked { margin: var(--s3) 0; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, .8fr); gap: var(--s4); align-items: start; }
.workspace:has(#aiPanel[hidden]) { grid-template-columns: 1fr; max-width: 56rem; }
.workspace section > .card { border-top: 0; padding-top: 0; }
.prompt { white-space: pre-wrap; margin-top: var(--s2); max-width: var(--measure); }
#referenceLinks { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s1); margin-bottom: var(--s2); }
#referenceLinks a { overflow-wrap: anywhere; }

/* The AI assistant is a docked tool inside the task: a bordered panel with a transcript,
   no bubbles, offset under the sticky bar. */
.chat {
 position: sticky;
 top: calc(var(--bar-height) + var(--s2));
 max-height: calc(100vh - var(--bar-height) - var(--s4));
 overflow: auto;
 border: 1px solid var(--rule);
 border-top: 1px solid var(--rule);
 border-radius: 2px;
 padding: var(--s2);
 margin: 0;
}
.chat h2 { margin-bottom: 0; }
.chat > .hint:first-of-type { margin: 0 0 var(--s2); }
#chatLog { min-height: 120px; max-height: 40vh; overflow: auto; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin: var(--s1) 0 var(--s2); padding: 0; }
.bubble { padding: var(--s2) 0; border-top: 1px solid var(--rule-light); border-radius: 0; margin: 0; background: transparent; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble:first-child { border-top: 0; }
.bubble.user { background: transparent; }
.bubble strong { display: block; font-size: var(--fs-1); font-weight: 600; color: var(--ink-muted); margin-bottom: 2px; }
.bubble a { display: block; white-space: normal; margin-top: var(--s1); }
#chatForm { margin-top: var(--s2); }
#chatForm label { margin-bottom: var(--s2); }
#chatForm textarea { min-height: 72px; }
#chatStatus { margin-left: var(--s1); }
.selection { padding: 0; margin: 0 0 var(--s1); list-style: none; }
.selection li { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); padding: var(--s1) 0; border-bottom: 1px solid var(--rule-light); overflow-wrap: anywhere; }
.selection button { font-size: var(--fs-1); padding: 2px var(--s1); margin: 0; }
.file { display: flex; gap: var(--s1); padding: var(--s1) 0; align-items: center; overflow-wrap: anywhere; border-bottom: 1px solid var(--rule-light); }
#finalWorkbooks label { font-weight: 400; margin: var(--s1) 0; }
#timingSummary { font-variant-numeric: tabular-nums; }
#aiAttached:not(:empty) { margin-bottom: var(--s1); }

/* Visit bar (Prolific). */
#visitBar { border: 1px solid var(--rule); padding: var(--s2) var(--s3); margin-bottom: var(--s3); }
#visitClock { display: block; font-family: var(--mono); font-size: var(--fs-3); font-weight: 500; margin-bottom: var(--s1); font-variant-numeric: tabular-nums; }

/* Footer: the study name and the contact route from the support panel. The two routes
   follow the support panel's visibility, which study.mjs sets per entry type. */
footer { padding: var(--s2) 0 0; margin-top: var(--s5); border-top: 1px solid var(--rule); color: var(--ink-muted); font-size: var(--fs-1); }
footer p { margin: 0 0 var(--s1); max-width: none; }
main:has(#prolificSupport[hidden]) .footer-prolific, main:has(#emailSupport[hidden]) .footer-email { display: none; }

@media (max-width: 850px) {
 header { padding: var(--s1) var(--s2); }
 header a + span { display: none; }
 main { padding: var(--s2) var(--s2) var(--s4); }
 .workspace, .grid { grid-template-columns: 1fr; }
 .chat { position: static; max-height: none; }
 .clock { margin-left: 0; width: 100%; }
 .recorder { padding: var(--s2); }
 .preview { grid-template-columns: 1fr 1fr; }
 .steps { gap: var(--s1) var(--s2); }
 .actions button, #chatForm button, #begin, #submit, #toFinish, #nextTask, #export, .file-button { width: 100%; text-align: center; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* One consent document, with its action outside the scrollable reading area. */
.consent-shell { max-width: 780px; margin: var(--s3) auto var(--s4); }
.consent-panel { overflow: hidden; background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; }
.consent-heading { padding: var(--s3); }
.consent-heading .eyebrow { font-size: var(--fs-1); color: var(--ink-muted); margin-bottom: var(--s1); }
.consent-heading h1 { margin: 0 0 var(--s1); }
.consent-heading > p:last-child { color: var(--ink-muted); font-size: var(--fs-1); margin: 0; }
.consent-document { height: clamp(240px, 43vh, 430px); overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: var(--s3); background: var(--surface-muted); border-block: 1px solid var(--rule-light); font-size: var(--fs-2); line-height: 1.6; }
.consent-document h2 { font-size: var(--fs-2); margin: var(--s3) 0 var(--s1); }
.consent-document h2:first-child { margin-top: 0; }
.consent-document p:last-child { margin-bottom: 0; }
.consent-actions { padding: var(--s3); }
.consent-affirmation { font-size: var(--fs-1); line-height: 1.5; color: var(--ink-muted); margin-bottom: var(--s2); }
.consent-action-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.consent-action-row button { margin: 0; }
.text-button { background: none; border: 0; padding: var(--s1) 0; color: var(--ink-muted); font-size: var(--fs-1); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { background: none; color: var(--accent); }
.consent-copy { margin-left: auto !important; }
#agreeConsent { padding: var(--s1) var(--s2); }
#agreeConsent span { margin-left: var(--s2); }
.consent-document:focus-visible { outline-offset: -4px; }
.consent-heading h1:focus, .consent-shell h1:focus { outline: none; }
body:has(#agreement:not([hidden])) #studyFooter, body:has(#declined:not([hidden])) #studyFooter { display: none; }
body:has(#agreement:not([hidden])) #testingNotice, body:has(#agreement:not([hidden])) #liveTestingNotice { max-width: 780px; margin: 0 auto var(--s2); font-size: var(--fs-1); }
@media (max-width: 600px) {
 .consent-shell { margin: var(--s2) auto var(--s3); }
 .consent-heading, .consent-actions, .consent-document { padding: var(--s2); }
 .consent-document { height: 34vh; min-height: 220px; }
 .consent-action-row { gap: var(--s1) var(--s2); }
 #agreeConsent { width: 100%; }
}
