/* survey.css: see header in app.css "Reading layer (2026-11-23)". Loaded after app.css.
   The questionnaire screens (views/questionnaire.ts): step header, answer tiles, ranking, scale,
   slider, matrix and grades. Everything is scoped to .q-step and built on the reading-layer tokens.
   Side Rule: the student's (and Explore's) survey is lit amber, the parent's teal. The native
   radios, checkboxes and selects stay in the page (visually hidden or styled), so every question
   works without JavaScript and reads correctly to a screen reader. */

/* ---------- Side colour ---------- */
.q-step {
  --side: var(--amber, #FFC847);
  --side-edge: #A87400;          /* 3.3:1 on white: borders and marks that carry a selected state */
  --side-wash: #FFF4D6;
  --side-text: var(--amber-text, #7A4E00);
  --opt-line: var(--line-strong, rgba(21, 25, 46, 0.22));
}
.q-step:has(.q-parent) {
  --side: var(--teal, #39D0C3);
  --side-edge: #0A8276;          /* 4.4:1 on white */
  --side-wash: #DDF4F1;
  --side-text: var(--teal-text, #006B60);
}

/* ---------- Column: wide enough for two answer tiles or a matrix row on a laptop; single-column
   answers keep a comfortable measure inside it. ---------- */
html body.lt main#main.shell.narrow:has(.q-step) { width: min(820px, calc(100% - 24px)); max-width: 820px; }
.q-step .q-form :is(.opts:not(.opts-grid):not(.opts-pair), .rank-list, .slider, .scale, .scale-labels, .grades-grid, .field) { max-width: 620px; }

/* ---------- Step header: section and count, trail, progress, title, help ---------- */
.q-step .step-label { margin: 0 0 6px; font-size: 0.875rem; color: var(--ink-2); }
.q-step .section-tag { color: var(--side-text); font-weight: 700; }
.q-step .trail { margin: 4px 0 2px; }
.q-step .trail-line { stroke: var(--line-strong); }
.q-step .trail-line.done { stroke: var(--side-edge); }
.q-step .trail-dot .dot { fill: var(--surface); stroke: var(--ink-3); }
.q-step .trail-dot.done .dot, .q-step .trail-dot.now .dot { fill: var(--side-edge); stroke: var(--side-edge); }
.q-step .trail-labels { margin: 0 0 14px; font-size: 0.75rem; color: var(--ink-3); gap: 8px; }
.q-step .trail-labels span { flex: 1 1 0; text-align: center; line-height: 1.25; }
.q-step .trail-labels span:first-child { text-align: left; }
.q-step .trail-labels span:last-child { text-align: right; }
.q-step .trail-labels span.done { color: var(--ink-2); }
.q-step .trail-labels span.now { color: var(--side-text); font-weight: 700; }
/* On a phone the section is already named in the line above; seven labels under the trail only collide. */
@media (max-width: 639px) { .q-step .trail-labels { display: none; } .q-step .trail { margin-bottom: 4px; } }
.q-step .progress { height: 4px; margin: 10px 0 22px; background: var(--surface-3); border-radius: 2px; }
.q-step .progress > span { background: var(--side-edge); border-radius: 2px; }
.q-step .cheer { background: var(--side-wash); color: var(--ink-1); border-radius: var(--r-md); padding: 10px 14px; margin: 0 0 14px; font-weight: 700; }
.q-step .cheer small { color: var(--ink-2); font-weight: 400; }
.q-step .q-form legend { padding: 0; max-width: 100%; }
.q-step .q-title { font-size: clamp(1.55rem, 1.1rem + 2.4vw, 2.35rem); line-height: 1.12; margin: 2px 0 10px; text-wrap: balance; }
.q-step .q-form .help { color: var(--ink-2); max-width: 62ch; margin: 0 0 18px; }
.q-step .q-form .help.opts-note { margin: 10px 0 0; font-size: 0.9rem; }
.q-step .q-form .error { margin-top: 12px; }
.q-step .q-actions { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ---------- Answer tiles (single, multi, pair, cards, list) ---------- */
.q-step .opts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
/* Two-up only when the form itself has room for two readable tiles (about 300px each). */
.q-step .q-form { container-type: inline-size; }
@container (min-width: 600px) {
  .q-step .opts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .q-step .opts-pair { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}
.q-step .opts > li { max-width: none; }
.q-step .opt { position: relative; display: flex; margin: 0; }
.q-step .opt-input, .q-step .scale-pt input { position: absolute; left: 12px; top: 50%; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.q-step .opt-label { display: flex; flex: 1; min-width: 0; margin: 0; cursor: pointer; font-weight: 400; }
.q-step .opt-box {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 10px 12px 10px 12px;
  border: 1.5px solid var(--opt-line); border-radius: var(--r-md); background: var(--surface); color: var(--ink-1);
}
.q-step .opts:not(.opts-icons) .opt-box { min-height: 52px; padding-left: 16px; }
.q-step .opt-ico { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); color: var(--side-text); box-shadow: inset 0 0 0 1px var(--line); }
.q-step .sv-ico { display: block; width: 20px; height: 20px; }
.q-step .opt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.q-step .opt-title { font-weight: 700; font-size: 1rem; line-height: 1.3; }
.q-step .opt-help { font-size: 0.875rem; line-height: 1.35; color: var(--ink-2); }
/* The mark: an empty circle (one answer) or rounded square (several), filled with a check when chosen. */
.q-step .opt-mark { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border: 1.5px solid var(--ink-3); border-radius: 50%; background: var(--surface); }
.q-step .opt-multi .opt-mark { border-radius: 6px; }
.q-step .opt-check { width: 16px; height: 16px; color: var(--ink-1); opacity: 0; stroke-width: 3; }

.q-step .opt-label:hover .opt-box { border-color: var(--ink-3); background: var(--surface-2); }
.q-step .opt-input:checked + .opt-label .opt-box { border-color: var(--side-edge); background: var(--side-wash); box-shadow: inset 0 0 0 1px var(--side-edge); }
.q-step .opt-input:checked + .opt-label .opt-ico { background: var(--side); color: var(--ink-1); box-shadow: none; }
.q-step .opt-input:checked + .opt-label .opt-mark { background: var(--side); border-color: var(--side-edge); }
.q-step .opt-input:checked + .opt-label .opt-check { opacity: 1; }
.q-step .opt-input:focus-visible + .opt-label .opt-box { outline: 3px solid var(--side-edge); outline-offset: 2px; }
.q-step .opt-input:disabled + .opt-label { cursor: not-allowed; opacity: 0.55; }

/* ---------- Ranking ---------- */
.q-step .rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.q-step .rank-item {
  max-width: none; display: grid; align-items: center; gap: 10px 12px;
  grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label ctrl";
  padding: 10px 10px 10px 14px; border: 1.5px solid var(--opt-line); border-radius: var(--r-md); background: var(--surface);
}
.q-step .rank-item.has-ico { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "ico label ctrl"; padding-left: 10px; }
.q-step .rank-ico { grid-area: ico; }
.q-step .rank-label { grid-area: label; margin: 0; font-weight: 700; font-size: 1rem; line-height: 1.3; color: var(--ink-1); min-width: 0; }
.q-step .rank-ctrl { grid-area: ctrl; display: flex; align-items: center; gap: 6px; }
.q-step .rank-pick { position: relative; display: inline-flex; }
.q-step .rank-select {
  -webkit-appearance: none; appearance: none; width: 68px; min-width: 0; height: 44px; min-height: 44px; margin: 0;
  padding: 0 24px 0 14px; border: 1.5px solid var(--opt-line); border-radius: var(--r-sm); background: var(--surface);
  color: var(--ink-1); font: inherit; font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; cursor: pointer;
}
.q-step .rank-caret { position: absolute; right: 6px; top: 50%; width: 16px; height: 16px; margin-top: -8px; color: var(--ink-2); pointer-events: none; }
.q-step .rank-select:hover { border-color: var(--ink-3); }
.q-step .rank-tools:not([hidden]) { display: inline-flex; gap: 6px; }
.q-step .rank-btn { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border: 1.5px solid var(--opt-line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink-1); cursor: pointer; }
.q-step .rank-btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.q-step .rank-btn[disabled] { opacity: 0.35; cursor: default; }
.q-step .rank-btn:focus-visible, .q-step .rank-select:focus-visible { outline: 3px solid var(--side-edge); outline-offset: 2px; }
/* Ranked: the row and its position take the side's colour; the number itself says the place. */
.q-step .rank-item.ranked { border-color: var(--side-edge); background: var(--side-wash); }
.q-step .rank-item.ranked .rank-select { background: var(--side); border-color: var(--side-edge); }
.q-step .rank-item.ranked .rank-caret { color: var(--ink-1); }
.q-step .rank-item.ranked .rank-ico { background: var(--side); color: var(--ink-1); box-shadow: none; }
/* Without JS the select alone carries the rank, so the .ranked class is only a hint; :has() covers a fresh choice. */
.q-step .rank-item:has(.rank-select option:checked:not([value=""])) { border-color: var(--side-edge); background: var(--side-wash); }
.q-step .rank-item:has(.rank-select option:checked:not([value=""])) .rank-select { background: var(--side); border-color: var(--side-edge); }
/* On a phone the label keeps the whole row; the position and the moves sit on their own row beneath it. */
@media (max-width: 559px) {
  .q-step .rank-item { grid-template-columns: minmax(0, 1fr); grid-template-areas: "label" "ctrl"; }
  .q-step .rank-item.has-ico { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "ico label" ". ctrl"; }
}

/* ---------- Scale (numbered points) ---------- */
.q-step .scale { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.q-step .scale-pt { position: relative; }
.q-step .scale-pt label { display: block; margin: 0; cursor: pointer; }
.q-step .scale-pt .box { display: grid; place-items: center; min-height: 48px; border: 1.5px solid var(--opt-line); border-radius: var(--r-sm); background: var(--surface); font-weight: 800; color: var(--ink-1); }
.q-step .scale-pt label:hover .box { border-color: var(--ink-3); background: var(--surface-2); }
.q-step .scale-pt input:checked + label .box { background: var(--side); border-color: var(--side-edge); box-shadow: inset 0 0 0 1px var(--side-edge); }
.q-step .scale-pt input:focus-visible + label .box { outline: 3px solid var(--side-edge); outline-offset: 2px; }
.q-step .scale-labels { margin-top: 8px; gap: 12px; font-size: 0.875rem; color: var(--ink-2); }
.q-step .scale-labels span:last-child { text-align: right; }

/* ---------- Slider ---------- */
.q-step .slider { padding: 6px 2px 4px; }
.q-step .slider input[type="range"] { display: block; width: 100%; height: 44px; margin: 0; accent-color: var(--side-edge); cursor: pointer; }
.q-step .slider-anchors { height: auto; min-height: 22px; margin-top: 2px; }
.q-step .slider-anchors span { font-size: 0.8125rem; color: var(--ink-2); line-height: 1.3; }
.q-step .slider-out { display: table; margin: 16px auto 0; padding: 6px 16px; border-radius: 999px; background: var(--side-wash); box-shadow: inset 0 0 0 1px var(--side-edge); color: var(--ink-1); font-family: inherit; font-size: 1.05rem; font-weight: 700; }
/* Narrow screens: the two ends only, each allowed to wrap; the chip below names wherever you are. */
@media (max-width: 639px) {
  .q-step .slider-anchors { display: flex; justify-content: space-between; gap: 16px; }
  .q-step .slider-anchors span { position: static; transform: none !important; display: none; max-width: 48%; white-space: normal; }
  .q-step .slider-anchors span:first-child, .q-step .slider-anchors span:last-child { display: block; }
  .q-step .slider-anchors span:last-child { text-align: right; }
}

/* ---------- Matrix (Explore): one row per item, a three-way choice beneath or beside it ---------- */
.q-step .matrix { margin: 4px 0 0; gap: 8px; }
.q-step .matrix-row { max-width: none; padding: 12px; gap: 10px 16px; border-radius: var(--r-md); background: var(--surface); border: 1.5px solid var(--line); }
.q-step .matrix-row:has(input:checked) { border-color: color-mix(in srgb, var(--side-edge) 55%, transparent); }
.q-step .matrix-item { font-weight: 700; color: var(--ink-1); }
.q-step .matrix-scale { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 6px; }
.q-step .matrix-scale label {
  min-height: 44px; min-width: 0; margin: 0; padding: 6px 8px; text-align: center; line-height: 1.2;
  font-size: 0.875rem; font-weight: 600; color: var(--ink-1);
  border: 1.5px solid var(--opt-line); border-radius: var(--r-sm); background: var(--surface);
}
.q-step .matrix-scale label:hover { border-color: var(--ink-3); background: var(--surface-2); }
.q-step .matrix-scale input:checked + label { background: var(--side); border-color: var(--side-edge); box-shadow: inset 0 0 0 1px var(--side-edge); color: var(--ink-1); font-weight: 800; }
.q-step .matrix-scale input:focus-visible + label { outline: 3px solid var(--side-edge); outline-offset: 2px; }
@media (min-width: 640px) { .q-step .matrix-row { grid-template-columns: minmax(0, 1fr) minmax(300px, 22rem); } }
@media (max-width: 639px) { .q-step .matrix-scale { width: 100%; } .q-step .matrix-scale label { padding: 6px 4px; } }

/* ---------- Grades, number and text ---------- */
.q-step .grades-grid { grid-template-columns: minmax(0, 1fr) 104px; gap: 10px 14px; }
.q-step .grades-grid label { font-weight: 600; line-height: 1.3; color: var(--ink-1); }
.q-step .grades-grid input, .q-step .q-form input[type="number"] { min-height: 44px; font-variant-numeric: tabular-nums; }
.q-step .q-form textarea { min-height: 120px; }

/* ---------- Motion: quiet state changes, none under reduced motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .q-step :is(.opt-box, .opt-ico, .opt-mark, .rank-item, .rank-select, .rank-btn, .scale-pt .box, .matrix-scale label) {
    transition: border-color 120ms ease-out, background-color 120ms ease-out, box-shadow 120ms ease-out, color 120ms ease-out;
  }
  .q-step .opt-check { transition: opacity 120ms ease-out; }
  .q-step .opt-label:active .opt-box { transform: scale(0.99); }
}

/* ---------- Spacing (2026-11-23, owner screenshots) ----------
   The question sat directly on the tiles, and three tiles side by side left each one too narrow
   for icon + text + mark in a row. Narrow tiles now stack: icon and mark on top, text below. */
.q-step .q-title { margin-bottom: 0; }
.q-step .q-form legend { margin-bottom: 22px; }
.q-step legend + .help { margin-top: -12px; }
.q-step .opts { gap: 12px; }
.q-step .opts > li { container-type: inline-size; }
@media (min-width: 640px) {
@container (max-width: 340px) {
    .q-step .opts-icons .opt-box { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "ico . mark" "text text text"; align-items: start; align-content: start; gap: 12px; padding: 16px; }
    .q-step .opts-icons .opt-ico { grid-area: ico; }
    .q-step .opts-icons .opt-mark { grid-area: mark; }
    .q-step .opts-icons .opt-text { grid-area: text; }
  }
}
