:root {
  color-scheme: light dark;
  font-family: system-ui, -apple-system, sans-serif;
  --accent: #6d4aff;
  --accent-contrast: #ffffff;
  /* 70% CanvasText clears WCAG AA 4.5:1 on both Canvas and the slightly
     tinted --surface; 55% measured 4.34:1 and failed the axe gate. */
  --muted: color-mix(in srgb, CanvasText 70%, Canvas);
  --border: color-mix(in srgb, CanvasText 18%, Canvas);
  --surface: color-mix(in srgb, CanvasText 4%, Canvas);
  --danger: #c0392b;
}

/* [hidden] must outrank every author rule below it, or setting .hidden
   from JavaScript has no visible effect.

   The browser's own [hidden] rule is a user-agent rule, so any author
   rule beats it — `button { display: inline-block }` below is enough to
   keep a hidden button on screen. Respondent navigation depends on
   .hidden working: the Back and Next buttons and the language picker's
   submit button are all hidden this way.

   !important is appropriate here and in few other places: this is a
   global invariant rather than a local override. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding: 2rem;
  line-height: 1.5;
}

main {
  max-width: 40rem;
  margin: 0 auto;
}

.site-header {
  max-width: 40rem;
  margin: 0 auto 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  /* Wraps rather than overflowing: the signed-in email is unbounded in
     length, and a nav that pushes the page wider than the viewport gives
     every page a horizontal scrollbar on a phone. */
  flex-wrap: wrap;
}

.site-header .brand {
  font-weight: 700;
  text-decoration: none;
  color: inherit;
  margin-right: auto;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  min-width: 0;
}

/* A long address must shrink rather than widen the page. */
.site-header .muted {
  min-width: 0;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.card {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  padding: 1.25rem;
  margin: 1rem 0;
}

.field {
  display: block;
  margin: 0.75rem 0;
}

.field span {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

input[type="email"],
input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: Canvas;
  color: CanvasText;
  font: inherit;
}

.button,
button {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.375rem;
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

.button.secondary,
button.secondary {
  background: transparent;
  color: inherit;
  border-color: var(--border);
}

.button.danger,
button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.button-link {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.notice {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 0.375rem;
  padding: 0.6rem 0.8rem;
  margin: 1rem 0;
}

.error-text {
  color: var(--danger);
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  margin: 1.25rem 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border);
}

/* --- survey building (M3) ------------------------------------------- */

.title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.title-row h1,
.title-row h2 {
  margin-right: auto;
}

.breadcrumb {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.chip {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.chip-open {
  background: color-mix(in srgb, #1a7f37 20%, Canvas);
  border-color: #1a7f37;
}

.chip-closed {
  background: color-mix(in srgb, var(--danger) 18%, Canvas);
  border-color: var(--danger);
}

.chip-draft {
  background: var(--surface);
}

.chip-small {
  font-size: 0.7rem;
  padding: 0.05rem 0.45rem;
}

.survey-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.survey-title {
  font-size: 1.15rem;
  font-weight: 600;
  text-decoration: none;
  color: inherit;
}

.survey-title:hover {
  text-decoration: underline;
}

.questions {
  padding-left: 1.25rem;
  margin: 0;
}

.question {
  margin: 0.5rem 0;
}

.question summary {
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.qtype {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
}

.qtext {
  font-weight: 500;
}

.question details[open] > form,
.question details[open] > .question-actions {
  margin: 0.75rem 0 1rem 0;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border);
}

.question-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.question-actions button {
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
}

.field-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.field-row .field {
  flex: 1 1 10rem;
}

textarea,
select,
input[type="date"],
input[type="number"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: Canvas;
  color: CanvasText;
  font: inherit;
}

input[type="number"] {
  max-width: 8rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.75rem 1rem;
}

.choice {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 0.6rem 0;
}

.choice small,
.field small {
  display: block;
  color: var(--muted);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.warn {
  font-size: 0.9rem;
  border-left: 3px solid var(--accent);
  padding-left: 0.6rem;
  margin: 0.75rem 0 0;
}

.versions,
.audit {
  padding-left: 1.25rem;
}

.versions {
  list-style: none;
  padding: 0;
}

.versions li {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.audit li {
  padding: 0.3rem 0;
}

.participants {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  max-height: 16rem;
  overflow-y: auto;
}

.participants li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.danger-zone {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.share-link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

/* --- respondent pages (M4) ------------------------------------------ */

.respond main {
  max-width: 34rem;
}

.preview-banner {
  border: 1px solid var(--accent);
  border-radius: 0.375rem;
  background: color-mix(in srgb, var(--accent) 12%, Canvas);
  padding: 0.6rem 0.9rem;
  margin-bottom: 1.5rem;
}

.disclosure {
  border-left: 3px solid var(--border);
  padding-left: 0.9rem;
  margin: 1rem 0 2rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.error-summary {
  border: 2px solid var(--danger);
  border-radius: 0.375rem;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.5rem;
}

.error-summary h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.error-summary ul {
  margin-bottom: 0;
}

.respond-questions {
  list-style: none;
  padding: 0;
  margin: 0;
}

.respond-question fieldset {
  border: none;
  padding: 0;
  margin: 0 0 2.5rem 0;
}

.respond-form.paged .respond-question fieldset {
  margin-bottom: 1.5rem;
}

.respond-question legend {
  padding: 0;
  margin-bottom: 0.9rem;
}

.q-position {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.q-text {
  display: block;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.35;
}

.q-required,
.q-optional {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  cursor: pointer;
}

/* Key hints (SPEC.md story 80).
   Hidden by default, and shown only when two conditions hold: JavaScript
   has upgraded the form (respond.js adds .paged, and the shortcuts do not
   exist without it) and the device reports a keyboard. Displaying a
   shortcut that cannot be pressed misleads the reader. */
.key-hint {
  display: none;
  flex: none;
  min-width: 1.5rem;
  padding: 0.05rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  text-align: center;
  font-variant: tabular-nums;
}

@media (hover: hover) and (pointer: fine) {
  .paged .key-hint {
    display: inline-block;
  }

  /* On a button the hint follows the label rather than sitting in the
     flex row an option uses. */
  .paged button > .key-hint {
    margin-left: 0.5rem;
  }
}

.option:hover {
  border-color: var(--accent);
}

.option:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.scale {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.scale-point {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  min-width: 2.75rem;
  padding: 0.5rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  cursor: pointer;
}

.scale-point:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.scale-hint {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.4rem;
}

.respond-progress {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.respond-nav {
  display: flex;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.respond-actions {
  margin-top: 1.5rem;
}

.respond-submit {
  font-size: 1.05rem;
  padding: 0.65rem 1.5rem;
}

/* The honeypot must be unreachable for people (including screen reader
   and keyboard users) while staying a normal, fillable field for a bot
   that parses the HTML. display:none would be skipped by naive bots too;
   moving it off-screen catches more of them. */
.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* --- voice answering (M5) ------------------------------------------- */

.voice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.voice-button.recording {
  border-color: var(--danger);
  color: var(--danger);
}

/* A dot that reads as "live" without relying on colour alone — the
   button label changes too. */
.voice-button.recording::before {
  content: "";
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--danger);
}

.voice-status {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Shown while a transcription is in flight. Indeterminate on purpose:
   the model reports no progress, so a filling bar would be a number this
   page invented. This one says "working" and claims nothing else. */
.voice-progress {
  display: block;
  flex-basis: 100%;
  height: 3px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  position: relative;
}

.voice-progress::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 35%;
  border-radius: 3px;
  background: var(--accent);
  animation: voice-progress-sweep 1.4s ease-in-out infinite;
}

@keyframes voice-progress-sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(340%);
  }
}

/* Motion is decoration here; the status line carries the same fact in
   words. A respondent who asked for less of it gets a still bar. */
@media (prefers-reduced-motion: reduce) {
  .voice-progress::after {
    animation: none;
    width: 100%;
    opacity: 0.5;
  }
}

.voice-preview-note {
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* The consent moment (M5-T3): shown once, before the first microphone
   request, stating that the voice is never stored. */
.voice-consent {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(28rem, calc(100% - 2rem));
  height: fit-content;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.25rem;
  box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 25%);
  z-index: 10;
}

.voice-consent h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.voice-consent-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* --- results (M7) --------------------------------------------------- */

.button-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.results-actions {
  margin-bottom: 1.5rem;
}

.result h2 {
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.result-summary {
  font-weight: 600;
}

.wordings summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

.wordings ul {
  list-style: none;
  padding-left: 0;
}

.wordings li {
  margin: 0.35rem 0;
}

.distribution {
  list-style: none;
  padding-left: 0;
  margin: 0.75rem 0 0;
}

.distribution li {
  display: grid;
  grid-template-columns: minmax(4rem, 10rem) 1fr auto;
  gap: 0.75rem;
  align-items: center;
  margin: 0.35rem 0;
}

.bar {
  display: block;
  background: color-mix(in srgb, CanvasText 10%, Canvas);
  border-radius: 0.25rem;
  height: 0.85rem;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
}

.bar-count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.9rem;
}

.transcripts {
  margin: 0.75rem 0 0;
  padding-left: 1.25rem;
}

.transcripts li {
  margin-bottom: 0.9rem;
}

.transcript-text {
  margin: 0 0 0.2rem;
  white-space: pre-wrap;
}

.transcript-meta {
  font-size: 0.85rem;
  margin: 0;
}

.stat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin: 0 0 0.75rem;
}

.stat-grid dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-grid dd {
  margin: 0;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.stats h3 {
  font-size: 1rem;
  margin-bottom: 0.2rem;
}

.stats h4 {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.75rem 0 0.2rem;
}

/* AI output is visually distinct from data on purpose: a summary must
   never be mistakable for the answers it summarises. */
.ai-label {
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
}

.insight-output {
  white-space: pre-wrap;
  font-family: inherit;
  background: color-mix(in srgb, var(--accent) 6%, Canvas);
  border-radius: 0.375rem;
  padding: 0.9rem 1rem;
  margin: 0 0 1rem;
  overflow-x: auto;
}

.language-picker {
  margin-bottom: 1rem;
}

.language-picker .field {
  max-width: 16rem;
}

.translate-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.translate-form .field {
  max-width: 10rem;
  margin: 0;
}

/* A translation is visibly secondary to the words a respondent chose. */
.transcript-translation {
  margin: 0.2rem 0;
  padding-left: 0.75rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.translations {
  padding-left: 1.25rem;
}

.translations li {
  margin-bottom: 1.25rem;
}

.source-text {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.responses {
  border-collapse: collapse;
  font-size: 0.9rem;
}

.responses th,
.responses td {
  text-align: left;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}

/* Available to screen readers, invisible on screen — for a table column
   whose header would otherwise be an empty cell. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Tables (results, admin) scroll on their own rather than pushing the
   page sideways — the phone-width overflow check depends on it. */
.table-scroll {
  overflow-x: auto;
}

@media (max-width: 30rem) {
  .distribution li {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}

@media (max-width: 30rem) {
  body {
    padding: 1rem;
  }
}
