@layer reset, tokens, base, components, screens, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { color-scheme: dark; }
  body, h1, h2, h3, p, fieldset, legend { margin: 0; }
  button, input, textarea { font: inherit; }
  button { color: inherit; }
  img, svg { display: block; }
}

@layer tokens {
  :root {
    /* WalkWith palette */
    --navy: #292a50;
    --navy-deep: #071f34;
    --tan: #f2ecdb;
    --tan-light: #fffcf5;
    --white: #ffffff;
    --red: #e46141;
    /* Brand red darkened 20%, for surfaces of OURS that carry small light text.
       White on the true #e46141 is 3.45:1 and fails AA; this is 5.09:1, chosen
       for headroom rather than the 4.52:1 that only just scrapes past. The mock
       screens under test keep the true #e46141 — they reproduce the site. */
    --red-deep: #b64e34;
    --gold: #f5b13f;
    --green: #3f533a;
    --green-light: #697b69;
    --pink: #f9d6c3;
    --blue-light: #6ccacd;
    --blue-dark: #175778;

    /* Semantic surfaces */
    --canvas: var(--navy);
    --panel: var(--tan);
    --field: var(--white);

    /* Ink */
    --ink: var(--navy);
    --ink-muted: #5c5d7c;
    --ink-faint: #6e6f8c; /* 4.9:1 on white — placeholders must still be legible */
    --on-dark: var(--white);
    --on-dark-muted: #b6b7cb;

    /* Lines */
    --line: #cdc6b3;
    --line-strong: var(--navy);
    --line-dark: #43446a;

    /* Measured off the Figma nodes: things you READ are square (panels, cards,
       tiles, chips, boards); things you PRESS or TYPE INTO are rounded 8px. */
    --radius: 0;
    --radius-control: 8px;

    --max: 1180px;
    --gutter: 36px;

    --serif: "Playfair Display", "Noto Serif Display", Lora, Georgia, "Times New Roman", serif;
    --sans: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  }
}

@layer base {
  html { min-width: 320px; background: var(--canvas); scroll-behavior: smooth; }
  body {
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--canvas);
    color: var(--on-dark);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }
  button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
  button { cursor: pointer; }
  button:disabled { cursor: not-allowed; }
  /* Concentric white-then-navy ring. Both sit outside the element, over its
     container, so one of the two always contrasts: navy carries on the tan
     panels, white carries on the navy canvas and the coloured tiles.
     A single colour fails somewhere — gold on tan is 1.5:1. */
  :focus-visible {
    outline: 3px solid var(--navy);
    outline-offset: 3px;
    box-shadow: 0 0 0 3px var(--white);
  }
  /* focusMain() parks focus on the heading after each render — suppress both
     halves of the ring there, or every screen change flashes a focus box. */
  main h1[tabindex="-1"]:focus { outline: none; box-shadow: none; }
  .page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
  .sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
  .skip-link {
    position: fixed;
    left: 16px;
    top: 12px;
    z-index: 5000;
    padding: 10px 16px;
    background: var(--tan);
    color: var(--navy);
    font-weight: 600;
    transform: translateY(-160%);
  }
  .skip-link:focus { transform: none; }
  .icon { flex: 0 0 auto; }
}

@layer components {
  /* ---- Brand + header ---- */
  .site-header {
    position: relative;
    z-index: 100;
    flex: 0 0 auto;
    background: var(--navy);
  }
  .site-header__inner {
    width: min(calc(100% - 40px), var(--max));
    min-height: 76px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
  }
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--white);
    text-decoration: none;
  }
  .brand strong { font-size: 21px; font-weight: 700; }
  .header-note {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--on-dark-muted);
    font-size: 13px;
  }

  /* ---- Buttons ---- */
  .button {
    min-height: 44px;
    padding: 0 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    font-size: 14px;
    font-weight: 700;
    transition: background .16s ease, color .16s ease, border-color .16s ease, opacity .16s ease;
  }
  .button--dark { background: var(--navy); color: var(--white); }
  .button--dark:not(:disabled):hover { background: var(--navy-deep); }
  .button--secondary { border-color: var(--navy); background: transparent; color: var(--navy); }
  .button--secondary:not(:disabled):hover { background: var(--navy); color: var(--white); }
  .button:disabled { background: rgba(41, 42, 80, .1); border-color: transparent; color: #67657a; }
  .button--large { min-height: 52px; padding: 0 28px; font-size: 15px; }
  .button--compact { min-height: 36px; padding: 0 14px; font-size: 13px; }
  .button-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

  .icon-button {
    width: 40px;
    height: 40px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 1px solid var(--line-dark);
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--white);
    transition: background .16s ease, border-color .16s ease;
  }
  .icon-button:hover { border-color: var(--tan); background: rgba(255, 255, 255, .08); }
  .text-button {
    min-height: 34px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 0;
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--ink-muted);
    font-size: 13px;
    font-weight: 600;
  }
  .text-button:not(:disabled):hover { background: rgba(41, 42, 80, .08); color: var(--navy); }
  .text-button:disabled { opacity: .35; }

  /* ---- Footer ---- */
  .site-footer {
    flex: 0 0 auto;
    margin-top: auto;
    padding: 30px 0;
    background: var(--navy);
    color: var(--on-dark-muted);
    font-size: 13px;
  }
  .site-footer__inner {
    width: min(calc(100% - 40px), var(--max));
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
  }
  .site-footer__brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-right: 12px;
    color: var(--white);
  }
  .site-footer__brand strong { font-size: 17px; font-weight: 700; }
  .site-footer button {
    margin-left: auto;
    padding: 0;
    border: 0;
    background: none;
    color: var(--on-dark-muted);
    font-size: 13px;
    text-decoration: underline;
    text-underline-offset: 3px;
  }
  .site-footer button:hover { color: var(--white); }

  /* ---- Task chrome ---- */
  .task-header-meta {
    margin-left: auto;
    color: var(--on-dark-muted);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
  }
  .task-progress { height: 4px; background: var(--line-dark); }
  .task-progress span { display: block; height: 100%; background: var(--gold); transition: width .35s ease; }

  .action-bar {
    position: sticky;
    z-index: 80;
    left: 0;
    right: 0;
    bottom: 0;
    margin-top: auto;
    border-top: 1px solid var(--line);
    background: var(--tan);
  }
  .action-bar__inner {
    width: min(calc(100% - 40px), 760px);
    min-height: 74px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }
  .action-bar__inner > span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--ink-muted);
    font-size: 13px;
  }

  /* ---- Toast ---- */
  .toast {
    position: fixed;
    z-index: 10000;
    left: 50%;
    bottom: 26px;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 9px;
    background: var(--tan);
    color: var(--navy);
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    transform: translate(-50%, 14px);
    transition: opacity .2s ease, transform .2s ease;
  }
  .toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
}

@layer screens {
  /* ===================== Dashboard ===================== */
  .dashboard-main {
    width: min(calc(100% - 40px), var(--max));
    margin: 0 auto;
    padding: 34px 0 56px;
    display: grid;
    gap: 22px;
  }
  .study-intro {
    padding: 46px 44px;
    background: var(--panel);
    color: var(--ink);
  }
  .study-intro__copy { max-width: 620px; }
  .study-intro h1 {
    margin: 10px 0 16px;
    font-family: var(--serif);
    font-size: clamp(38px, 5vw, 58px);
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 1.04;
  }
  .study-intro__copy > p {
    max-width: 540px;
    color: var(--ink-muted);
    font-size: 17px;
  }

  .section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 20px;
  }
  .section-heading h2 {
    color: var(--on-dark);
    font-size: 20px;
    font-weight: 700;
  }
  .section-heading > span { color: var(--on-dark-muted); font-size: 13px; }

  .task-picker { display: grid; gap: 14px; }
  .task-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

  .task-card {
    min-height: 230px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    border: 0;
    border-radius: var(--radius);
    background: var(--tile, var(--green));
    color: var(--tile-ink, var(--white));
    text-align: left;
    transition: filter .18s ease;
  }
  .task-card:nth-child(1) { --tile: var(--green); --tile-ink: var(--white); }
  .task-card:nth-child(2) { --tile: var(--gold); --tile-ink: var(--navy); }
  .task-card:nth-child(3) { --tile: var(--red-deep); --tile-ink: var(--white); }
  .task-card:nth-child(4), .task-card:nth-child(5) { --tile: var(--pink); --tile-ink: var(--navy); }
  .task-card__title {
    font-family: var(--serif);
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 1.1;
  }
  /* No opacity on tile text: it silently cost ~1.2x contrast on every tile and
     pushed the red one under AA. Size and family already carry the de-emphasis. */
  .task-card__desc { font-size: 13px; font-weight: 500; line-height: 1.4; }
  /* The title now leads the tile, so margin-top:auto moves to the chip row. */
  .task-card__tags {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .task-card__tag {
    padding: 4px 10px;
    background: var(--tan-light);
    color: var(--navy);
    font-size: 13px;
    font-weight: 600;
  }
  .task-card__tag--status { background: var(--navy); color: var(--tan-light); }
  .task-card:hover { filter: brightness(1.06); }
  .task-card:nth-child(2):hover, .task-card:nth-child(4):hover, .task-card:nth-child(5):hover { filter: brightness(.97); }

  .finish-panel {
    padding: 22px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    background: var(--panel);
    color: var(--ink);
  }
  .finish-panel p { font-size: 15px; font-weight: 600; }
  .finish-panel.is-ready { background: var(--gold); }

  /* ===================== Shared task screens ===================== */
  .task-main {
    width: min(calc(100% - 40px), var(--max));
    margin: 0 auto;
    padding: 34px 0 56px;
  }
  .task-main--narrow { width: min(calc(100% - 40px), 800px); }
  .question-card, .activity-brief, .completion-card {
    padding: 44px;
    background: var(--panel);
    color: var(--ink);
  }
  .question-card h1, .activity-brief h1, .recall-head h1, .completion-card h1 {
    font-family: var(--serif);
    font-size: clamp(30px, 4vw, 42px);
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 1.08;
  }
  .question-card > p, .recall-head p, .activity-brief > p {
    margin-top: 12px;
    max-width: 60ch;
    color: var(--ink-muted);
    font-size: 16px;
  }

  .choice-list { margin-top: 30px; padding: 0; display: grid; gap: 8px; border: 0; }
  .choice-option {
    min-height: 56px;
    padding: 13px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--field);
    color: var(--ink);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
  }
  .choice-option:hover { border-color: var(--navy); }
  .choice-option:has(input:checked) {
    border-color: var(--navy);
    box-shadow: inset 0 0 0 1px var(--navy);
    font-weight: 700;
  }
  .choice-option input { position: absolute; opacity: 0; pointer-events: none; }
  /* Square everywhere else, but radios stay round: it is the only cue that
     tells a participant "pick one" rather than "pick several". */
  .choice-option__mark {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border: 1.5px solid var(--ink-faint);
    border-radius: var(--radius);
    background: var(--white);
  }
  input[type="radio"] + .choice-option__mark { border-radius: 50%; }
  .choice-option input:checked + .choice-option__mark { border-color: var(--navy); background: var(--navy); }
  input[type="checkbox"]:checked + .choice-option__mark::after {
    content: "";
    width: 9px;
    height: 5px;
    border: solid var(--white);
    border-width: 0 0 2px 2px;
    transform: translateY(-1px) rotate(-45deg);
  }
  input[type="radio"]:checked + .choice-option__mark { box-shadow: inset 0 0 0 3.5px var(--white); }
  .choice-option:has(input:focus-visible) { outline: 3px solid var(--navy); outline-offset: 3px; box-shadow: 0 0 0 3px var(--white); }
  /* Kept inside the card, not the action bar, so it stays visible on small screens.
     Red is the signal, but as a rule — white-on-red is only 3.4:1 and fails AA at this size. */
  .question-card .choice-error:empty { display: none; }
  .question-card .choice-error {
    margin-top: 14px;
    padding: 11px 15px;
    max-width: none;
    border-left: 4px solid var(--red);
    background: var(--tan-light);
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
  }

  .activity-brief > p { font-size: 17px; }
  .activity-brief .button { margin-top: 28px; }
  .activity-note {
    margin-top: 22px;
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--tan-light);
    color: var(--ink-muted);
    font-size: 14px;
  }
  .completion-card { text-align: left; }
  .completion-card p { margin: 12px 0 26px; color: var(--ink-muted); }

  /* ===================== Click map ===================== */
  .clickmap-main {
    width: min(calc(100% - 32px), 1320px);
    margin: 0 auto;
    padding: 18px 0;
  }
  .click-prompt {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--tan);
    color: var(--ink);
  }
  .click-prompt h1 { font-size: 17px; font-weight: 700; }
  .click-prompt > b { flex: 0 0 auto; color: var(--ink-muted); font-size: 13px; font-weight: 600; }
  .stimulus-shell {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: calc(100vh - 240px);
    min-height: 400px;
    overflow: hidden;
    /* The mock site is navy like the page, so it needs an edge to read as a screen. */
    outline: 1px solid rgba(255, 255, 255, .16);
    background: var(--tan-light);
  }
  .stimulus-scale { position: absolute; inset: 0; }
  .click-overlay {
    position: absolute;
    z-index: 30;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: crosshair;
  }
  .click-overlay:disabled { cursor: default; }
  .keyboard-crosshair {
    position: absolute;
    z-index: 35;
    width: 26px;
    height: 26px;
    border: 2px solid var(--white);
    border-radius: 50%;
    background: rgba(41, 42, 80, .78);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%);
  }
  .keyboard-crosshair::before, .keyboard-crosshair::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    background: var(--white);
    transform: translate(-50%, -50%);
  }
  .keyboard-crosshair::before { width: 12px; height: 1px; }
  .keyboard-crosshair::after { width: 1px; height: 12px; }
  .keyboard-crosshair.is-visible { opacity: 1; }
  .click-marker {
    position: absolute;
    z-index: 40;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 2px solid var(--white);
    border-radius: 50%;
    background: var(--red);
    color: var(--white);
    font-size: 12px;
    font-weight: 800;
    transform: translate(-50%, -50%);
    animation: marker-pop .24s cubic-bezier(.2, .9, .3, 1.3);
  }
  @keyframes marker-pop { from { opacity: 0; transform: translate(-50%, -50%) scale(.4); } }
  .action-bar--clickmap .action-bar__inner { width: min(calc(100% - 32px), 1320px); }

  /* ===================== WalkWith mock product ===================== */
  .product-mock {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--navy);
    color: var(--white);
    font-family: var(--sans);
    font-size: clamp(7px, .82vw, 13px);
  }
  .mock-masthead {
    min-height: 9%;
    padding: 0 2.5%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--navy);
  }
  .mock-brand { display: flex; align-items: center; gap: .6em; font-size: 1.35em; font-weight: 700; }
  .mock-masthead > small { color: var(--on-dark-muted); font-size: .82em; }
  .mock-topnav {
    min-height: 6.5%;
    padding: 0 2.5%;
    display: flex;
    align-items: center;
    gap: 2.4%;
    border-top: 1px solid var(--line-dark);
    border-bottom: 1px solid var(--line-dark);
    color: var(--white);
    font-size: .82em;
  }
  .mock-topnav .mock-account { margin-left: auto; display: flex; align-items: center; gap: .5em; }
  .mock-body { min-height: 0; flex: 1; padding: 2.2% 2.5% 2.5%; display: flex; flex-direction: column; gap: 1.6%; overflow: hidden; }
  .mock-h { color: var(--white); font-size: 1.25em; font-weight: 700; }
  .mock-hero { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 1%; flex: 1.35; min-height: 0; }
  .mock-hero-main {
    position: relative;
    padding: 6% 6% 5%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    background: var(--tan);
    color: var(--navy);
  }
  .mock-hero-main h3 { font-family: var(--serif); font-size: 2.1em; font-weight: 700; line-height: 1.05; }
  .mock-hero-main p { margin-top: 4%; color: var(--ink-muted); font-size: .92em; }
  .mock-hero-main b { margin-top: 7%; font-size: .92em; }
  .mock-tiles { display: grid; grid-template-rows: 1fr 1fr; gap: 6%; }
  .mock-tile {
    position: relative;
    padding: 7%;
    display: flex;
    align-items: flex-start;
    background: var(--green);
    color: var(--white);
    font-size: 1em;
    font-weight: 600;
  }
  .mock-tile--gold { background: var(--gold); color: var(--navy); }
  .mock-tile--red { background: var(--red); color: var(--white); }
  .mock-tile--pink { background: var(--pink); color: var(--navy); }
  .mock-tile::after { content: "+"; position: absolute; right: 6%; bottom: 3%; font-size: 1.3em; font-weight: 700; }
  .mock-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.1%; flex: 1; min-height: 0; }
  .mock-card {
    padding: 5%;
    display: flex;
    flex-direction: column;
    background: var(--tan-light);
    color: var(--navy);
    overflow: hidden;
  }
  .mock-card > i { height: 34%; margin-bottom: 8%; background: var(--green-light); }
  .mock-card:nth-child(2) > i { background: var(--pink); }
  .mock-card:nth-child(3) > i { background: var(--gold); }
  .mock-card:nth-child(4) > i { background: var(--blue-light); }
  .mock-card strong { font-size: .92em; font-weight: 700; line-height: 1.25; }
  .mock-card small { margin-top: auto; color: var(--ink-muted); font-size: .72em; }
  .mock-tag { align-self: flex-start; margin-top: 6%; padding: .25em .6em; background: var(--tan); font-size: .68em; font-weight: 600; }
  .mock-form { padding: 3% 3.5%; display: grid; grid-template-columns: 1fr 1fr; gap: 0 6%; background: var(--tan); color: var(--navy); }
  .mock-form h3 { grid-column: 1; font-family: var(--serif); font-size: 1.5em; font-weight: 700; }
  .mock-form label { margin-top: 3%; display: grid; gap: .3em; font-size: .78em; }
  .mock-form span { display: block; padding: .7em .8em; border: 1px solid var(--line); border-radius: 6px; background: var(--white); color: var(--ink-faint); font-size: .95em; }
  .mock-form .mock-submit { margin-top: 4%; padding: .7em 1.6em; justify-self: start; border-radius: 6px; background: var(--navy); color: var(--white); font-size: .8em; font-weight: 700; }
  .mock-form-aside { grid-column: 2; grid-row: 1 / span 6; align-self: center; color: var(--ink-muted); font-size: .8em; }
  .mock-rail { display: flex; gap: 1.5%; }
  .mock-rail > span { padding: .5em 1em; background: var(--green-light); color: var(--white); font-size: .82em; font-weight: 600; }
  .mock-rail > span.is-active { background: var(--tan); color: var(--navy); }
  .mock-footer {
    min-height: 8%;
    padding: 0 2.5%;
    display: flex;
    align-items: center;
    gap: 4%;
    border-top: 1px solid var(--line-dark);
    color: var(--on-dark-muted);
    font-size: .78em;
  }

  /* ===================== Five-second exposure ===================== */
  .exposure-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--navy);
  }
  .exposure-top {
    height: 52px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    color: var(--white);
  }
  .exposure-top strong {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    background: var(--gold);
    color: var(--navy);
    font-size: 15px;
  }
  .exposure-progress { height: 4px; background: var(--line-dark); }
  .exposure-progress span { display: block; width: 100%; height: 100%; background: var(--gold); transform-origin: left center; }
  .exposure-content { min-height: 0; padding: 22px; display: grid; place-items: center; flex: 1; }
  .impression-mock {
    position: relative;
    width: min(100%, 1320px);
    aspect-ratio: 16 / 9;
    min-height: 500px;
    overflow: hidden;
    outline: 1px solid rgba(255, 255, 255, .16);
    background: var(--navy);
    color: var(--white);
    font-family: var(--sans);
    font-size: clamp(8px, .86vw, 14px);
  }
  .impression-mock .product-mock { position: absolute; inset: 0; }

  /* ===================== Recall ===================== */
  .task-main--recall { width: min(calc(100% - 40px), 800px); }
  .recall-panel { padding: 44px; background: var(--panel); color: var(--ink); }
  .recall-form { margin-top: 30px; display: grid; gap: 26px; }
  .recall-field { padding: 0; display: grid; gap: 9px; border: 0; }
  .recall-field > span, .recall-field legend {
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
  }
  .recall-field textarea {
    width: 100%;
    resize: vertical;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--field);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.55;
  }
  .recall-field textarea:focus { border-color: var(--navy); }
  .recall-field textarea::placeholder { color: var(--ink-faint); }
  .choice-list--compact { margin-top: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-list--compact .choice-option { min-height: 50px; }

  /* ===================== Card sort ===================== */
  .sort-screen {
    height: 100vh;
    height: 100dvh;
    min-height: 620px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--navy);
  }
  .sort-header {
    min-height: 68px;
    padding: 0 20px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    background: var(--navy);
    color: var(--white);
  }
  .sort-header__copy { min-width: 0; }
  .sort-header__copy strong {
    display: block;
    overflow: hidden;
    font-size: 17px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .sort-header__copy small { color: var(--on-dark-muted); font-size: 13px; }
  .sort-header__actions { display: flex; align-items: center; gap: 6px; }
  .sort-header__actions .text-button { color: var(--on-dark-muted); }
  .sort-header__actions .text-button:not(:disabled):hover { background: rgba(255, 255, 255, .1); color: var(--white); }
  .sort-header__actions .button--dark { background: var(--tan); color: var(--navy); }
  .sort-header__actions .button--dark:disabled { background: rgba(255, 255, 255, .14); color: rgba(255, 255, 255, .45); }

  .sort-layout { min-height: 0; display: grid; grid-template-columns: 230px minmax(0, 1fr); flex: 1; gap: 14px; padding: 14px; }
  .card-tray { min-height: 0; padding: 18px 16px; overflow-y: auto; background: var(--tan); color: var(--ink); }
  .card-tray__head {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
  }
  .card-tray__head b {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: grid;
    place-items: center;
    background: var(--navy);
    color: var(--tan);
    font-size: 11px;
  }
  /* The deck runs to ~100 cards, so the tray is searchable and each entry shows
     its description — participants decide what a card is before dragging it. */
  .card-tray__search {
    width: 100%;
    margin-bottom: 10px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--tan-light);
    color: var(--ink);
    font-size: 12px;
  }
  .card-tray__search::placeholder { color: var(--ink-faint); }
  .card-tray__search:focus { border-color: var(--navy); }
  .card-tray__search[hidden] { display: none; }
  .card-tray__hint { margin-bottom: 12px; color: var(--ink-muted); font-size: 12px; line-height: 1.4; }
  .card-tray__status { margin-bottom: 10px; color: var(--ink-muted); font-size: 11px; line-height: 1.4; }
  .card-tray__status[hidden] { display: none; }
  .card-tray__cards { display: grid; gap: 8px; }
  .tray-card {
    width: 100%;
    min-height: 46px;
    padding: 9px 11px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--tan-light);
    color: var(--ink);
    text-align: left;
    transition: border-color .15s ease, background .15s ease;
    touch-action: none;
  }
  .tray-card:hover, .tray-card[aria-pressed="true"] { border-color: var(--navy); }
  .tray-card[aria-pressed="true"] { background: var(--navy); color: var(--tan-light); }
  .tray-card b { font-size: 13px; font-weight: 600; line-height: 1.25; }
  /* Two lines of description is enough to tell two similarly-titled resources
     apart. Dimmed by opacity rather than a fixed colour so it reads correctly
     both on the tan card and on the navy selected state. */
  .tray-card small {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    color: inherit;
    font-size: 11px;
    line-height: 1.35;
    opacity: .74;
  }
  .tray-card.is-dragging { opacity: .35; }
  .tray-card--ghost {
    position: fixed;
    z-index: 9999;
    width: 176px;
    pointer-events: none;
    background: var(--tan-light);
    color: var(--ink);
    transform: translate(-50%, -50%);
  }

  .sort-canvas-wrap { min-width: 0; min-height: 0; }
  .sort-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 470px;
    overflow: hidden;
    background-color: var(--tan-light);
    background-image: radial-gradient(rgba(41, 42, 80, .16) 1px, transparent 1px);
    background-position: -1px -1px;
    background-size: 22px 22px;
    touch-action: none;
    transition: box-shadow .15s ease;
  }
  .sort-canvas.is-drop-target { box-shadow: inset 0 0 0 3px var(--gold); }
  .sort-hulls, .sort-groups, .sort-cards { position: absolute; inset: 0; width: 100%; height: 100%; }
  .sort-hulls { z-index: 2; overflow: visible; pointer-events: none; }
  .sort-groups { z-index: 12; pointer-events: none; }
  .sort-cards { z-index: 10; pointer-events: none; }
  .sort-hull {
    fill: color-mix(in srgb, var(--group-color) 16%, transparent);
    stroke: var(--group-color);
    stroke-width: 1.5;
    stroke-dasharray: 5 5;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .sort-group-label {
    position: absolute;
    min-height: 30px;
    padding: 5px 9px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--group-color);
    background: var(--tan-light);
    pointer-events: auto;
    transform: translate(-50%, -50%);
  }
  .sort-group-label > span { width: 9px; height: 9px; flex: 0 0 auto; background: var(--group-color); }
  .sort-group-label input {
    width: 104px;
    min-width: 74px;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
  }
  .sort-group-label input::placeholder { color: var(--ink-faint); font-weight: 500; }
  .sort-group-label b { color: var(--ink-muted); font-size: 11px; }
  /* After the testing-tools card component: a title over a description, folded
     to a fixed height with the description clipped behind a fade, and a chevron
     that opens the card in place. --card-surface keeps that fade matched to
     whichever background the card is currently wearing. */
  .sort-card {
    --card-surface: var(--tan-light);
    position: absolute;
    left: 0;
    top: 0;
    width: 176px;
    height: 112px;
    padding: 10px 11px 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow: hidden;
    border: 1px solid var(--navy);
    background: var(--card-surface);
    color: var(--ink);
    cursor: grab;
    pointer-events: auto;
    user-select: none;
    will-change: transform;
    transition: background .15s ease;
    touch-action: none;
  }
  .sort-card.is-expanded { height: auto; padding-bottom: 24px; }
  .sort-card:hover { --card-surface: var(--tan); }
  .sort-card.is-dragging { --card-surface: var(--navy); color: var(--tan-light); cursor: grabbing; }
  /* Space held for the remove button whether or not it is showing, so the title
     does not reflow on hover. */
  .sort-card__title {
    padding-right: 20px;
    overflow-wrap: anywhere;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
  }
  .sort-card__desc { overflow-wrap: anywhere; font-size: 12px; line-height: 1.35; }
  .sort-card__fade {
    position: absolute;
    z-index: 1;
    right: 0;
    bottom: 0;
    left: 0;
    height: 36px;
    background: linear-gradient(to bottom, transparent, var(--card-surface) 70%);
    pointer-events: none;
  }
  .sort-card.is-expanded .sort-card__fade { display: none; }
  .sort-card__chevron {
    position: absolute;
    z-index: 2;
    bottom: 1px;
    left: 50%;
    width: 26px;
    height: 20px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--ink-muted);
    transform: translateX(-50%);
  }
  .sort-card__chevron:hover { color: var(--navy); }
  .sort-card.is-expanded .sort-card__chevron { transform: translateX(-50%) rotate(180deg); }
  .sort-card__remove {
    position: absolute;
    z-index: 2;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: transparent;
  }
  .sort-card:hover .sort-card__remove,
  .sort-card:focus .sort-card__remove,
  .sort-card__remove:focus {
    background: var(--tan);
    color: var(--ink-muted);
  }
  .sort-card.is-dragging .sort-card__chevron,
  .sort-card.is-dragging .sort-card__remove { background: transparent; color: transparent; }
  /* The card clips its own overflow, which would swallow an outset focus ring on
     either inner button — so draw theirs inside the button box instead. */
  .sort-card__chevron:focus-visible,
  .sort-card__remove:focus-visible { outline-offset: -2px; box-shadow: none; }
  .canvas-place-target {
    position: absolute;
    z-index: 6;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    pointer-events: none;
  }
  .canvas-place-target.is-active { background: rgba(245, 177, 63, .1); pointer-events: auto; cursor: crosshair; }
  .sort-empty {
    position: absolute;
    z-index: 1;
    inset: 0;
    display: grid;
    place-content: center;
    color: var(--ink-muted);
    pointer-events: none;
    text-align: center;
    font-size: 14px;
  }
  .sort-empty[hidden] { display: none; }

  /* ===================== Thank you ===================== */
  .page--thanks { background: var(--navy); }
  .thanks-main {
    width: min(calc(100% - 40px), var(--max));
    margin: auto;
    padding: 70px 0;
  }
  .thanks-panel { padding: 56px 48px; background: var(--panel); color: var(--ink); }
  .thanks-panel h1 {
    margin-bottom: 16px;
    font-family: var(--serif);
    font-size: clamp(38px, 5.4vw, 62px);
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 1.02;
  }
  .thanks-panel > p { max-width: 56ch; color: var(--ink-muted); font-size: 17px; }
  .thanks-code {
    width: fit-content;
    margin: 28px 0;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--navy);
    color: var(--tan);
  }
  .thanks-code small { font-size: 14px; font-weight: 500; }
  .thanks-code strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; letter-spacing: .08em; }
}

@layer responsive {
  @media (max-width: 1080px) {
    .task-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .task-card { min-height: 200px; }
  }

  @media (max-width: 820px) {
    .site-header__inner { gap: 14px; }
    .brand strong { font-size: 18px; }
    .study-intro { padding: 36px 28px; }
    .question-card, .activity-brief, .completion-card { padding: 32px 26px; }
    .recall-panel { padding: 32px 26px; }
    .thanks-panel { padding: 40px 28px; }
    .sort-layout { grid-template-columns: 190px minmax(0, 1fr); }
  }

  @media (max-width: 640px) {
    :root { --gutter: 16px; }
    .site-header__inner { width: calc(100% - 28px); min-height: 64px; }
    .header-note { display: none; }
    .dashboard-main, .task-main, .task-main--narrow, .task-main--recall, .thanks-main {
      width: calc(100% - 28px);
      padding: 22px 0 44px;
    }
    .study-intro h1 { font-size: 34px; }
    .task-list { grid-template-columns: 1fr; gap: 10px; }
    .task-card { min-height: 0; padding: 20px; }
    .task-card__title { margin-top: 8px; font-size: 23px; }
    .finish-panel { align-items: stretch; flex-direction: column; padding: 20px; }
    .finish-panel .button { width: 100%; }
    .site-footer__inner { width: calc(100% - 28px); gap: 10px; }
    .action-bar__inner { width: calc(100% - 28px); min-height: 68px; }
    .action-bar__inner > span { min-width: 0; font-size: 12px; }
    .action-bar__inner .button:last-child { margin-left: auto; }
    .choice-list--compact { grid-template-columns: 1fr; }
    .clickmap-main { width: calc(100% - 20px); padding-top: 12px; }
    .click-prompt > b { display: none; }
    .stimulus-shell { min-height: 380px; aspect-ratio: auto; }
    .action-bar--clickmap .action-bar__inner { width: calc(100% - 20px); }
    .exposure-content { padding: 10px; }
    .impression-mock { min-height: 480px; }
    .sort-screen { min-height: 700px; overflow: auto; }
    .sort-header { position: sticky; z-index: 100; top: 0; padding: 0 12px; }
    /* No room for the status text here, but it is an aria-live region —
       display:none would stop it announcing. Hide it visually only. */
    .sort-header__copy small {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
    }
    .sort-header__actions .text-button[data-sort-reset] { display: none; }
    .sort-layout { min-height: 660px; grid-template-columns: 1fr; grid-template-rows: auto 1fr; padding: 10px; gap: 10px; }
    /* Tall enough for the longest title in the deck to wrap to four lines without
       the horizontal tray clipping it — overflow-y is hidden here, so anything
       that does not fit is simply lost. */
    .card-tray { max-height: 236px; padding: 12px; overflow-x: auto; overflow-y: hidden; }
    /* On a phone the search field earns the space the hint was using — the deck
       is far too long to scroll a horizontal tray through. */
    .card-tray__hint { display: none; }
    .card-tray__search { margin-bottom: 8px; }
    .card-tray__status { margin-bottom: 8px; }
    .card-tray__cards { display: flex; gap: 8px; }
    .tray-card { width: 176px; min-width: 176px; }
    /* Titles stay whole; the description gives up a line to pay for them. */
    .tray-card small { -webkit-line-clamp: 1; }
    .sort-canvas-wrap { min-height: 450px; }
    .sort-canvas { min-height: 440px; }
  }

  @media (max-width: 390px) {
    .button-row { flex-direction: column; align-items: stretch; }
    .button-row .button { width: 100%; }
    /* Undo collapses to an icon rather than disappearing — a mis-drop is most
       likely on touch, and this is the only way back from one. */
    .sort-header__actions .text-button { width: 38px; padding: 0; justify-content: center; font-size: 0; }
    .sort-header__actions .text-button svg { width: 18px; height: 18px; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      scroll-behavior: auto !important;
      animation-duration: .01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: .01ms !important;
    }
  }
}
