:root {
  color-scheme: dark;
  --background: #0f1211;
  --surface: #181d1b;
  --surface-raised: #222825;
  --text: #f5f7f6;
  --muted: #b8c3bd;
  --border: #46504b;
  --border-soft: #2d3531;
  --primary: #43c59e;
  --primary-strong: #65d8b6;
  --primary-text: #07140f;
  --accent: #ffd166;
  --block: #2f6fed;
  --danger: #ef8354;
  --focus: #ffe08a;
  --radius: 6px;
  --content-width: 960px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled),
a[href] {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

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

.portal-header,
.task-header {
  width: 100%;
  border-bottom: 1px solid var(--border-soft);
}

.portal-header__inner,
.task-header__inner {
  display: flex;
  width: min(calc(100% - 40px), var(--content-width));
  min-height: 64px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.task-header__inner > .muted {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-state {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
}

.server-state::before {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.server-state[data-state="online"]::before {
  background: var(--primary);
}

.server-state[data-state="offline"]::before {
  background: var(--danger);
}

.portal-main {
  width: min(calc(100% - 40px), var(--content-width));
  margin: 0 auto;
  padding: 64px 0 72px;
}

.portal-intro {
  max-width: 680px;
  margin-bottom: 48px;
}

.portal-intro h1,
.registration h1,
.instructions h1,
.completion h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.25;
  letter-spacing: 0;
}

.portal-intro p:last-child {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.task-list {
  border-top: 1px solid var(--border);
}

.task-row {
  display: grid;
  min-height: 132px;
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
  gap: 24px;
  grid-template-columns: 110px minmax(0, 1fr) auto;
}

.task-preview {
  position: relative;
  width: 110px;
  height: 78px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: #0b0d0c;
}

.preview-block {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid #dce6ff;
  background: var(--block);
}

.preview-block:nth-child(1) { left: 55px; top: 7px; }
.preview-block:nth-child(2) { left: 12px; top: 14px; }
.preview-block:nth-child(3) { left: 85px; top: 26px; }
.preview-block:nth-child(4) { left: 34px; top: 29px; }
.preview-block:nth-child(5) { left: 59px; top: 39px; background: var(--accent); }
.preview-block:nth-child(6) { left: 90px; top: 52px; }
.preview-block:nth-child(7) { left: 7px; top: 55px; }
.preview-block:nth-child(8) { left: 36px; top: 61px; }
.preview-block:nth-child(9) { left: 63px; top: 59px; }

.digit-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--text);
  font-size: 25px;
  font-variant-numeric: tabular-nums;
}

.digit-preview span:nth-child(2) {
  color: var(--accent);
}

.task-copy {
  min-width: 0;
}

.task-copy h2 {
  margin: 0 0 5px;
  font-size: 20px;
  line-height: 1.35;
}

.task-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.button,
.icon-button {
  display: inline-flex;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-decoration: none;
}

.button {
  min-width: 120px;
  padding: 10px 18px;
  background: var(--primary);
  color: var(--primary-text);
}

.button:hover {
  background: var(--primary-strong);
}

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

.button--secondary:hover {
  border-color: var(--primary);
  background: var(--surface);
}

.button--danger {
  min-width: auto;
  min-height: 40px;
  padding: 7px 12px;
  border-color: var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.button--danger:hover {
  border-color: var(--danger);
  color: var(--text);
}

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

.task-page {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
}

.task-page.experiment-running > .task-header {
  display: none;
}

.task-main {
  display: flex;
  width: 100%;
  flex: 1;
}

.task-section {
  width: min(calc(100% - 40px), 700px);
  margin: auto;
  padding: 52px 0 64px;
}

.task-section:focus {
  outline: none;
}

.registration .lead,
.instructions .lead {
  margin: 14px 0 32px;
  color: var(--muted);
  font-size: 16px;
}

.participant-form {
  padding: 28px 0 0;
  border-top: 1px solid var(--border);
}

.form-grid {
  display: grid;
  gap: 22px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field--wide {
  grid-column: 1 / -1;
}

.field label,
.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.field input:hover,
.field select:hover {
  border-color: #6f7c75;
}

.check-field {
  display: flex;
  min-height: 48px;
  margin: 24px 0;
  align-items: flex-start;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.check-field input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 3px 0 0;
  accent-color: var(--primary);
}

.follow-up-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.follow-up-fieldset legend {
  width: 100%;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.follow-up-options {
  display: grid;
  gap: 10px;
}

.follow-up-option {
  display: flex;
  min-height: 54px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-items: center;
  gap: 12px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.55;
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}

.follow-up-option:hover {
  border-color: #6f7c75;
  color: var(--text);
}

.follow-up-option:has(input:checked) {
  border-color: var(--primary);
  background: #142720;
  color: var(--text);
}

.follow-up-option:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.follow-up-option input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--primary);
}

.follow-up-description {
  margin: 24px 0 0;
  padding: 18px 0;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

.follow-up-description p {
  margin: 0;
}

.follow-up-description > p:first-child {
  color: var(--muted);
}

.follow-up-description > p:first-child .reward-money {
  color: var(--accent);
}

.follow-up-description p + p {
  margin-top: 10px;
}

.reward-money {
  color: var(--accent);
  font-weight: 700;
}

.effort-copy {
  font-weight: 600;
}

.follow-up-privacy {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.instruction-list {
  margin: 28px 0 34px;
  padding: 22px 0 22px 26px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

.instruction-list li + li {
  margin-top: 10px;
}

.experiment {
  display: flex;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  background: #080a09;
}

.experiment:focus {
  outline: none;
}

.experiment-toolbar {
  display: grid;
  min-height: 66px;
  padding: 10px 20px;
  border-bottom: 1px solid #29302d;
  align-items: center;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.experiment-title {
  overflow: hidden;
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.experiment-meta {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.save-status::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.save-status[data-state="saved"]::before {
  background: var(--primary);
}

.save-status[data-state="error"]::before {
  background: var(--danger);
}

.experiment-stage {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.phase-message {
  width: min(100%, 680px);
  min-height: 32px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.fixation {
  display: flex;
  width: 120px;
  height: 120px;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 58px;
  line-height: 1;
}

.corsi-board {
  position: relative;
  width: min(90vw, calc((100dvh - 190px) * 1.333), 820px);
  max-width: 820px;
  aspect-ratio: 4 / 3;
  touch-action: manipulation;
  user-select: none;
}

.corsi-block {
  position: absolute;
  width: 9.5%;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid #e8edff;
  border-radius: 2px;
  background: var(--block);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  transition: background-color 60ms linear, transform 60ms linear;
}

.corsi-block:hover:not(:disabled) {
  border-color: white;
}

.corsi-block.is-active {
  background: var(--accent);
  border-color: #fff4c7;
  transform: translate(-50%, -50%) scale(1.08);
}

.corsi-block:disabled {
  cursor: default;
}

.corsi-controls {
  display: flex;
  min-height: 52px;
  margin-top: 8px;
  align-items: center;
  justify-content: center;
}

.icon-button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 25px;
}

.digit-stage {
  display: grid;
  width: min(100%, 560px);
  min-height: 560px;
  align-content: center;
  justify-items: center;
}

.stimulus-value {
  display: flex;
  width: 180px;
  height: 160px;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 96px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.response-panel {
  display: grid;
  width: min(100%, 360px);
  min-height: 520px;
  align-content: start;
  justify-items: center;
}

.response-label {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 14px;
}

.response-value {
  width: 100%;
  min-height: 70px;
  overflow-wrap: anywhere;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  text-align: center;
}

.keypad {
  display: grid;
  width: 100%;
  margin-top: 16px;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
}

.keypad-button {
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
}

.keypad-button:hover {
  border-color: var(--primary);
  background: #2b332f;
}

.keypad-button--action {
  font-size: 17px;
}

.keypad-button--submit {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
}

.keypad-button--submit:hover {
  background: var(--primary-strong);
}

.completion {
  max-width: 760px;
}

.result-grid {
  display: grid;
  margin: 34px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-item {
  min-width: 0;
  padding: 24px 20px;
  border-right: 1px solid var(--border-soft);
}

.result-item:last-child {
  border-right: 0;
}

.result-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.result-value {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.completion-status {
  min-height: 30px;
  margin: 0 0 20px;
  color: var(--muted);
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.confirm-dialog {
  width: min(calc(100% - 32px), 440px);
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.76);
}

.confirm-dialog h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.35;
}

.confirm-dialog p {
  margin: 12px 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.confirm-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 700px) {
  .portal-header__inner,
  .task-header__inner,
  .portal-main,
  .task-section {
    width: min(calc(100% - 28px), var(--content-width));
  }

  .portal-main {
    padding-top: 42px;
  }

  .portal-intro h1,
  .registration h1,
  .instructions h1,
  .completion h1 {
    font-size: 29px;
  }

  .task-row {
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 16px;
  }

  .task-preview {
    width: 82px;
    height: 70px;
    transform-origin: left center;
  }

  .task-row .button {
    width: 100%;
    grid-column: 1 / -1;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .experiment-toolbar {
    min-height: 76px;
    padding: 8px 12px;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .experiment-meta {
    gap: 10px;
    grid-column: 1;
    grid-row: 2;
  }

  .button--danger {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .experiment-stage {
    padding: 12px;
  }

  .corsi-board {
    width: min(95vw, calc((100dvh - 220px) * 1.333));
  }

  .corsi-block {
    width: max(44px, 12%);
  }

  .corsi-block[data-block="6"] {
    left: 6.5% !important;
  }

  .digit-stage {
    min-height: 480px;
  }

  .stimulus-value {
    height: 130px;
    font-size: 72px;
  }

  .response-panel {
    min-height: 455px;
  }

  .keypad-button {
    min-height: 54px;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .result-item {
    display: flex;
    padding: 16px 0;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
    align-items: center;
    justify-content: space-between;
    gap: 20px;
  }

  .result-item:last-child {
    border-bottom: 0;
  }

  .result-label {
    margin: 0;
  }

  .result-value {
    font-size: 25px;
  }

  .button-group .button {
    width: 100%;
  }
}

@media (max-width: 360px) {
  .corsi-block[data-block="0"] {
    top: 10% !important;
  }

  .corsi-block[data-block="6"] {
    left: 7.5% !important;
  }

  .corsi-block[data-block="7"] {
    top: 90% !important;
  }
}

@media (max-height: 700px) {
  .experiment-toolbar {
    min-height: 64px;
  }

  .experiment-stage {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .phase-message {
    min-height: 24px;
    margin-bottom: 4px;
  }

  .digit-stage {
    min-height: 390px;
  }

  .response-panel {
    min-height: 370px;
  }

  .response-value {
    min-height: 56px;
    padding: 8px 12px;
    font-size: 24px;
  }

  .keypad {
    margin-top: 8px;
    gap: 6px;
  }

  .keypad-button {
    min-height: 48px;
  }
}

@media (max-width: 430px) {
  .brand {
    max-width: 176px;
    font-size: 15px;
    line-height: 1.3;
  }

  .server-state {
    max-width: 128px;
    justify-content: flex-end;
    line-height: 1.25;
    text-align: right;
  }

  .confirm-dialog__actions {
    flex-direction: column-reverse;
  }

  .confirm-dialog__actions .button {
    width: 100%;
  }

  .task-section {
    padding-top: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }

  .button,
  .corsi-block {
    transition: none;
  }
}

.workflow-header-meta {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
}

.workflow-header-meta > .muted {
  white-space: nowrap;
}

.resume-panel {
  display: flex;
  margin: 28px 0 8px;
  padding: 20px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  background: var(--surface);
}

.resume-panel p {
  margin: 5px 0 0;
  color: var(--muted);
}

.form-message {
  min-height: 28px;
  margin: -8px 0 14px;
  color: var(--accent);
  font-size: 14px;
}

.workflow-progress {
  display: grid;
  margin: 0 0 42px;
  padding: 0;
  list-style: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.workflow-progress li {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.workflow-progress li:not(:last-child)::after {
  position: absolute;
  z-index: -1;
  top: 17px;
  right: 10px;
  left: 44px;
  height: 1px;
  background: var(--border);
  content: "";
}

.workflow-progress li > span {
  display: inline-flex;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--border);
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  background: var(--background);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.workflow-progress li[data-state="current"] {
  color: var(--text);
}

.workflow-progress li[data-state="current"] > span {
  border-color: var(--accent);
  color: var(--accent);
}

.workflow-progress li[data-state="completed"] > span {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
}

.completion-summary {
  display: flex;
  margin: 34px 0 22px;
  padding: 22px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
}

.completion-summary strong {
  color: var(--text);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  .workflow-header-meta {
    gap: 8px;
  }

  .workflow-header-meta > .muted {
    display: none;
  }

  .resume-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .workflow-progress {
    gap: 6px;
  }

  .workflow-progress li {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
  }

  .workflow-progress li:not(:last-child)::after {
    top: 17px;
    right: 0;
    left: 38px;
  }

  .workflow-progress li strong {
    font-size: 12px;
    line-height: 1.35;
  }
}
