.formal-toolbar {
  justify-content: space-between;
  gap: 22px;
}

.formal-brand {
  display: grid;
  gap: 2px;
}

.formal-brand strong {
  font-size: 14px;
}

.formal-brand span,
.formal-progress__label,
.formal-reference-toggle-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.formal-toolbar__controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.formal-progress {
  width: min(320px, 38vw);
}

.formal-progress__track {
  height: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.formal-progress__fill {
  height: 100%;
  background: var(--blue);
  transition: width 180ms ease;
}

.formal-progress__label {
  margin-top: 5px;
  text-align: right;
}

.formal-participant-stage {
  align-items: center;
  padding: clamp(12px, 3vh, 34px) 24px;
}

.formal-experiment-frame {
  height: min(680px, calc(100vh - var(--toolbar-height) - 32px));
  min-height: 0;
}

@supports (height: 100svh) {
  .formal-experiment-frame {
    height: min(680px, calc(100svh - var(--toolbar-height) - 32px));
  }
}

.formal-experiment-frame .audio-pane,
.formal-experiment-frame .decision-pane {
  min-height: 0;
}

.formal-experiment-frame .audio-pane {
  overflow-y: auto;
}

.formal-experiment-frame .decision-pane {
  overflow: hidden;
}

.formal-study-panel .reference-item.is-complete {
  border-color: var(--blue-line);
  background: #f8fbff;
}

.formal-reference-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.formal-status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.formal-status.is-complete {
  border-color: #86efac;
  background: var(--green-soft);
  color: #047857;
}

.formal-context-strip strong {
  color: #334155;
}

.formal-audio-space {
  flex: 0 0 auto;
  min-height: 176px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.formal-audio-space__head,
.formal-listening-panel {
  display: flex;
  align-items: center;
}

.formal-audio-space__head {
  justify-content: space-between;
  gap: 14px;
}

.formal-audio-space__head .eyebrow {
  margin: 0;
}

.formal-listening-panel {
  flex: 0 0 auto;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.formal-listening-icon {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--blue);
}

.formal-listening-icon svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.formal-audio-space h2 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.25;
}

.formal-audio-space p,
.formal-reference-inspector p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.formal-audio-disabled {
  min-height: 38px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.formal-candidate-row {
  position: relative;
  display: block;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.formal-candidate-row:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: #f8fafc;
}

.formal-candidate-row.is-selected {
  border-color: var(--blue);
  background: var(--blue-soft);
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.45);
}

.formal-candidate-row .candidate-button {
  min-height: 64px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.formal-candidate-row.has-reference .candidate-button {
  padding-left: 64px;
}

.formal-candidate-row .candidate-button:hover {
  transform: none;
  border-color: transparent;
  background: transparent;
}

.formal-candidate-row .candidate-button.is-selected {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.formal-reference-icon-button {
  position: absolute;
  top: 50%;
  left: 16px;
  z-index: 2;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  transform: translateY(-50%);
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.formal-reference-icon-button:hover {
  background: #fff;
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.28);
}

.formal-reference-icon-button.is-active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.formal-reference-icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.formal-reference-toggle {
  min-height: 34px;
  padding: 0 11px;
  font-size: 12px;
}

.formal-reference-inspector {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.formal-reference-inspector__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.formal-reference-inspector__head h2 {
  margin: 4px 0 3px;
  font-size: 16px;
  line-height: 1.25;
}

.formal-reference-inspector audio {
  width: 100%;
}

.formal-experiment-frame .candidate-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.formal-experiment-frame .submit-zone {
  flex: 0 0 auto;
}

@media (max-width: 980px) {
  .formal-participant-stage {
    align-items: start;
    padding: 18px;
  }

  .formal-experiment-frame {
    height: auto;
    overflow: visible;
  }

  .formal-experiment-frame .audio-pane {
    max-height: min(430px, calc(100vh - var(--toolbar-height) - 96px));
    overflow-y: auto;
  }

  @supports (height: 100svh) {
    .formal-experiment-frame .audio-pane {
      max-height: min(430px, calc(100svh - var(--toolbar-height) - 96px));
    }
  }

  .formal-experiment-frame .decision-pane {
    min-height: 0;
    overflow: visible;
  }

  .formal-experiment-frame .candidate-list {
    overflow: visible;
  }

  .formal-experiment-frame .submit-zone {
    position: static;
    margin: 18px 0 0;
    padding: 0;
    background: transparent;
  }

  .formal-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .formal-toolbar__controls {
    align-items: stretch;
    width: 100%;
  }

  .formal-progress {
    width: 100%;
  }

  .formal-progress__label {
    text-align: left;
  }

  .formal-audio-space {
    min-height: 164px;
    gap: 14px;
  }

  .formal-listening-panel {
    padding: 14px 0;
  }

  .formal-reference-icon-button {
    left: 14px;
    width: 34px;
  }
}

@media (min-width: 760px) and (max-width: 980px) {
  .formal-toolbar {
    align-items: center;
    flex-direction: row;
  }

  .formal-toolbar__controls {
    align-items: center;
    width: auto;
  }

  .formal-progress {
    width: min(320px, 38vw);
  }

  .formal-progress__label {
    text-align: right;
  }

  .formal-participant-stage {
    align-items: center;
    padding: clamp(12px, 3vh, 24px) 18px;
  }

  .formal-experiment-frame {
    height: min(680px, calc(100vh - var(--toolbar-height) - 32px));
    grid-template-columns: minmax(0, 1fr) minmax(340px, 0.96fr);
    overflow: hidden;
  }

  @supports (height: 100svh) {
    .formal-experiment-frame {
      height: min(680px, calc(100svh - var(--toolbar-height) - 32px));
    }
  }

  .formal-experiment-frame .audio-pane {
    max-height: none;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .formal-experiment-frame .decision-pane {
    overflow: hidden;
  }

  .formal-experiment-frame .candidate-list {
    overflow-y: auto;
  }

  .formal-experiment-frame .submit-zone {
    position: static;
    margin: 18px 0 0;
    padding: 0;
    background: transparent;
  }
}

@media (max-width: 620px) {
  .formal-experiment-frame .audio-pane {
    max-height: min(360px, calc(100vh - var(--toolbar-height) - 96px));
  }

  @supports (height: 100svh) {
    .formal-experiment-frame .audio-pane {
      max-height: min(360px, calc(100svh - var(--toolbar-height) - 96px));
    }
  }

  .formal-toolbar__controls {
    flex-direction: column;
    gap: 10px;
  }

  .formal-toolbar .language-trigger {
    width: 100%;
  }

  .formal-toolbar .language-options {
    left: 0;
    right: auto;
  }
}
