/* Fallacies — inline AI-evaluation backdrop + shared fallacy anchors/popovers
   (used by the composer AND the thread-detail read view; mirrors lib/fallacies.js) */

.compose-highlight {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
}

.compose-highlight textarea {
  position: relative;
  z-index: 1;
  display: block;
  border-color: transparent;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
}

.compose-backdrop {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
  padding: var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-reading);
  line-height: var(--line-reading);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  pointer-events: none;
}

/* Only the flagged sentences react to the pointer, so clicks elsewhere still
   reach the textarea underneath. */
.compose-backdrop .fallacy-anchor {
  pointer-events: auto;
}

mark {
  padding: 0;
  background: var(--mark);
  color: var(--ink);
}

.fallacy-anchor {
  position: relative;
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--mark);
  color: var(--ink);
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  vertical-align: baseline;
  appearance: none;
}

.fallacy-popover {
  position: absolute;
  top: calc(100% + 8px);
  bottom: auto;
  left: 0;
  z-index: 3;
  display: none;
  width: min(310px, calc(100vw - 44px));
  padding: var(--space-3);
  border: 1px solid var(--color-highlight-border);
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-family: var(--font-reading);
  line-height: var(--line-reading);
  text-align: left;
  white-space: normal;
}

/* Flip above the anchor when there isn't room below (set in JS). */
.fallacy-popover.is-above {
  top: auto;
  bottom: calc(100% + 8px);
}

.fallacy-popover strong,
.fallacy-popover span {
  display: block;
}

.fallacy-popover strong {
  margin-bottom: var(--space-2);
  color: var(--ink);
  text-align: center;
}

.fallacy-popover span + span {
  margin-top: var(--space-2);
}

.fallacy-anchor:hover .fallacy-popover,
.fallacy-anchor:focus .fallacy-popover,
.fallacy-anchor:focus-within .fallacy-popover,
.fallacy-anchor.is-locked .fallacy-popover {
  display: block;
}
