:root {
  color-scheme: dark;
  --text-scale: 1;
  --ink: #f4efff;
  --title: #ffffff;
  --muted: #c8bbdd;
  --line: #46325f;
  --paper: #140c20;
  --panel: #20122f;
  --panel-strong: #2b1741;
  --accent: #b987ff;
  --accent-dark: #efe3ff;
  --accent-soft: #35204e;
  --red: #ffb4c2;
  --warning: #f7c948;
  --warning-ink: #211600;
  --focus: #d7bdff;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.26);
}

body[data-theme="light"] {
  color-scheme: light;
  --ink: #211c17;
  --title: #25143c;
  --muted: #4f473f;
  --line: #ded5c7;
  --paper: #f2eee4;
  --panel: #fffaf1;
  --panel-strong: #f7efe2;
  --accent: #5a2f92;
  --accent-dark: #2f184f;
  --accent-soft: #eee7dc;
  --red: #9b1c31;
  --warning: #8a5a00;
  --warning-ink: #fff9ed;
  --focus: #6c3ea8;
  --shadow: 0 12px 32px rgba(50, 39, 23, 0.1);
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  clip: rect(0 0 0 0);
  border: 0;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: calc(16px + (var(--text-scale) * 1px));
  line-height: 1.45;
}

body {
  background:
    radial-gradient(circle at top left, rgba(185, 135, 255, 0.18), transparent 34rem),
    var(--paper);
  margin: 0;
  min-height: 100vh;
}

a {
  color: var(--accent-dark);
  font-weight: 700;
}

.site-header,
main {
  margin: 0 auto;
  max-width: 1320px;
  padding: 18px 24px;
}

.notice {
  background: rgba(255, 180, 194, 0.12);
  border: 2px solid var(--red);
  color: var(--red);
  font-size: 1rem;
  font-weight: 800;
  margin: 0 0 18px;
  padding: 14px 16px;
  text-align: center;
}

.instructions-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 0 0 18px;
  padding: 18px 20px;
}

.instructions-panel h2 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.instructions-panel ol {
  margin: 0;
  padding-left: 22px;
}

.instructions-panel li + li {
  margin-top: 5px;
}

.preference-controls {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.theme-choice,
.text-size-row,
.text-size-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.theme-choice {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px;
}

.theme-choice button {
  flex: 1 1 0;
}

.theme-choice button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #170a25;
}

.text-size-row {
  color: var(--title);
  justify-content: space-between;
  font-weight: 800;
}

.text-size-actions {
  flex: 0 0 auto;
}

.notice-bottom {
  margin: 28px 0 0;
}

.header-grid {
  align-items: stretch;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 310px;
}

.header-grid-single {
  grid-template-columns: minmax(0, 1fr);
}

.eyebrow {
  color: var(--title);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  color: var(--title);
  letter-spacing: 0;
  line-height: 1.12;
  margin: 0;
}

h1 {
  font-size: clamp(1.05rem, 2vw, 2rem);
  max-width: 720px;
}

h2 {
  font-size: clamp(1.35rem, 2vw, 2rem);
}

h3 {
  font-size: 1.05rem;
}

.lede {
  color: var(--muted);
  font-size: 1.1rem;
  max-width: 760px;
  margin: 4px 0 0;
}

.progress-panel,
.output-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

form {
  display: grid;
  gap: 24px;
  min-width: 0;
}

.form-shell {
  align-items: start;
  display: grid;
  gap: 28px;
  grid-template-columns: 280px minmax(0, 1fr);
  margin-top: -8px;
}

.progress-panel {
  padding: 18px;
  position: sticky;
  top: 16px;
}

.progress-panel h2 {
  color: var(--title);
  font-size: 1.25rem;
}

.progress-track {
  background: var(--panel-strong);
  border-radius: 999px;
  height: 10px;
  margin: 18px 0 10px;
  overflow: hidden;
}

.progress-track span {
  background: var(--accent);
  display: block;
  height: 100%;
  width: 0%;
}

.form-section,
.output-section {
  padding: 0;
}

.section-heading {
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
  padding: 0 0 10px;
}

.section-heading h2 {
  color: var(--title);
  margin-bottom: 4px;
}

.section-heading p:last-child {
  color: var(--muted);
  margin-bottom: 0;
}

.field-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 4px;
}

.participant-row {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(180px, 0.42fr) minmax(260px, 1fr);
  margin-bottom: 4px;
  padding: 18px;
}

.participant-row h2 {
  color: var(--title);
  font-size: 1.4rem;
}

.participant-row:focus-within,
.question-card:focus-visible,
.question-card:focus-within {
  background: color-mix(in srgb, var(--accent) 26%, var(--panel));
  border-color: color-mix(in srgb, var(--accent) 72%, var(--line));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  outline: none;
}

.field {
  display: grid;
  gap: 6px;
}

.field-wide {
  grid-column: span 2;
}

.field span,
.question-title,
legend {
  color: var(--title);
  font-weight: 800;
}

input,
button {
  font: inherit;
}

input {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
}

input:focus,
button:focus-visible,
.choice input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--focus) 42%, transparent);
  outline-offset: 2px;
}

.question-list {
  display: grid;
  gap: 12px;
}

.question-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.question-card.skipped,
.question-card.invalid {
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--warning) 22%, transparent), transparent 72%),
    var(--panel);
  border-color: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 24%, transparent);
}

.question-card.skipped::before,
.question-card.invalid::before {
  background: var(--warning);
  border-radius: 999px;
  color: var(--warning-ink);
  content: "Answer needed";
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1;
  margin: 0 0 10px;
  padding: 5px 8px;
}

.question-title {
  display: block;
  margin-bottom: 2px;
}

.question-description {
  color: var(--muted);
  margin: 0 0 8px;
}

.scale-row,
.choice-list {
  border: 0;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.scale-options {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(11, minmax(44px, 1fr));
}

.choice-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.scale-guide {
  align-items: center;
  color: var(--muted);
  display: grid;
  font-size: 0.82rem;
  font-weight: 700;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.scale-guide span:nth-child(2) {
  text-align: center;
}

.scale-guide span:nth-child(3) {
  text-align: right;
}

.scale-choice {
  cursor: pointer;
  display: block;
  min-width: 0;
  position: relative;
}

.scale-choice input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.scale-choice > span {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 4px;
  justify-items: center;
  min-height: 64px;
  padding: 8px 4px;
  text-align: center;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.scale-number {
  font-size: 1.05rem;
  font-weight: 850;
  line-height: 1;
}

.scale-label {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.15;
  min-height: 1.7em;
}

.scale-choice input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #170a25;
}

.scale-choice input:checked + span .scale-label {
  color: #170a25;
  font-weight: 800;
}

.choice {
  cursor: pointer;
  display: block;
  min-width: 0;
  position: relative;
}

.choice input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.choice > span {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 8px;
  min-height: 44px;
  padding: 9px 10px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.choice-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.choice-hint {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.choice input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #170a25;
  font-weight: 800;
}

.compact .choice-list {
  grid-template-columns: 1fr;
}

.choice-value {
  align-items: center;
  background: color-mix(in srgb, var(--panel) 92%, white);
  border: 1px solid currentColor;
  border-radius: 999px;
  display: inline-flex;
  flex: 0 0 auto;
  font-weight: 800;
  height: 26px;
  justify-content: center;
  min-width: 26px;
  padding: 0 7px;
}

.output-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  padding: 24px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #170a25;
  cursor: pointer;
  font-weight: 800;
  flex: 0 1 auto;
  min-height: 42px;
  padding: 9px 14px;
}

button:hover {
  background: var(--accent-dark);
  color: var(--paper);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.secondary {
  background: var(--panel-strong);
  color: var(--accent-dark);
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.icon-button {
  min-width: 44px;
  padding: 9px 12px;
}

.status-message {
  color: var(--muted);
  margin: 8px 0 0;
}

.status-message.error,
.status-message.sending,
.status-message.success {
  font-weight: 800;
}

.status-message.error {
  color: var(--red);
}

.status-message.sending {
  color: var(--accent-dark);
}

.status-message.success {
  color: #72e097;
}

.delivery-note {
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent-dark);
  font-size: 0.95rem;
  font-weight: 700;
  margin: 12px 0 0;
  padding: 10px 12px;
}

pre {
  background: #0b0711;
  border-radius: 8px;
  color: #f1f6f8;
  margin: 0;
  max-height: 520px;
  overflow: auto;
  padding: 16px;
  white-space: pre-wrap;
}

body[data-theme="light"] .scale-choice input:checked + span,
body[data-theme="light"] .choice input:checked + span {
  color: #ffffff;
}

body[data-theme="light"] .scale-choice input:checked + span .scale-label {
  color: #ffffff;
}

body[data-theme="light"] button {
  color: #ffffff;
}

body[data-theme="light"] button.secondary,
body[data-theme="light"] button.ghost {
  color: var(--accent-dark);
}

body[data-theme="light"] .theme-choice button[aria-pressed="true"] {
  color: #ffffff;
}

body[data-theme="light"] .status-message.success {
  color: #146c2e;
}

@media (max-width: 860px) {
  .site-header,
  main {
    padding: 16px;
  }

  .header-grid,
  .form-shell,
  .field-grid,
  .participant-row {
    grid-template-columns: 1fr;
  }

  .progress-panel {
    position: static;
  }

  .field-wide {
    grid-column: auto;
  }

  .scale-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .choice-list {
    grid-template-columns: 1fr;
  }

  .actions button {
    flex: 1 1 160px;
  }
}

@media (max-width: 460px) {
  .notice {
    font-size: 0.92rem;
    padding: 12px;
  }

  .question-card {
    padding: 14px;
  }

  .output-section {
    padding: 16px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .actions button {
    width: 100%;
  }

  .scale-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scale-choice > span {
    min-height: 58px;
  }
}
