/* Text-compare tool. Every rule is scoped to .pv-text-compare and reads only the site's existing theme
   tokens (--text, --muted, --line, --panel, --accent, --accent-dark, --danger, --pv-*), with local
   fallbacks, so the html[data-theme] light/dark switch restyles it without re-mounting or new
   listeners. Layout (TEXT_COMPARE_PROPOSAL §3): the two inputs stack on narrow screens and sit side by
   side from 48rem; the result is full width below. Long lines wrap (pre-wrap, anywhere) without
   changing logical line numbers; an empty line keeps one line of height. Targets: reflow at 320 CSS
   px and 200% text, 44x44 CSS px controls, visible focus, kinds shown by sign and word (never colour
   alone). [hidden] always wins. No global textarea/button rules. */

.pv-text-compare {
  --pv-tc-remove-bg: var(--pv-error-bg, rgba(164, 14, 38, 0.08));
  --pv-tc-add-bg: var(--pv-success-bg, rgba(31, 79, 209, 0.08));
  --pv-tc-active: var(--pv-focus, var(--accent, currentColor));
  color: var(--text);
  overflow-wrap: anywhere;
}

.pv-text-compare [hidden] {
  display: none !important;
}

.pv-text-compare .pv-text-compare__title {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  line-height: 1.3;
}

@media (min-width: 48rem) {
  .pv-text-compare .pv-text-compare__title {
    font-size: 1.875rem;
  }
}

.pv-text-compare .pv-text-compare__local,
.pv-text-compare .pv-text-compare__note,
.pv-text-compare .pv-text-compare__empty {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.pv-text-compare .pv-text-compare__form {
  display: grid;
  gap: 0.75rem;
  margin: 0 0 1.5rem;
}

.pv-text-compare .pv-text-compare__form .pv-text-compare__note {
  margin: 0;
}

.pv-text-compare .pv-text-compare__inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

@media (min-width: 48rem) {
  .pv-text-compare .pv-text-compare__inputs {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.pv-text-compare .pv-text-compare__field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.pv-text-compare .pv-text-compare__label {
  font-weight: 600;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-text-compare .pv-text-compare__count {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

.pv-text-compare .pv-text-compare__error {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
}

/* Never below 16px so mobile browsers do not zoom on focus. */
.pv-text-compare .pv-text-compare__textarea {
  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 12rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--pv-control, var(--line));
  border-radius: 6px;
  background: var(--pv-field, var(--panel));
  color: var(--text);
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: max(1rem, 16px);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  resize: vertical;
}

.pv-text-compare .pv-text-compare__textarea[aria-invalid="true"] {
  border-color: var(--danger);
  border-width: 2px;
}

.pv-text-compare .pv-text-compare__actions,
.pv-text-compare .pv-text-compare__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.pv-text-compare .pv-text-compare__button {
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent-dark, var(--accent));
  font: inherit;
  font-weight: 600;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.pv-text-compare .pv-text-compare__button--primary {
  background: var(--accent);
  color: var(--pv-on-primary, #ffffff);
}

.pv-text-compare .pv-text-compare__button--danger {
  border-color: var(--danger);
  color: var(--danger);
}

.pv-text-compare .pv-text-compare__button:disabled,
.pv-text-compare .pv-text-compare__button[aria-disabled="true"] {
  border-color: var(--pv-disabled-line, var(--line));
  background: var(--pv-disabled-bg, var(--panel));
  color: var(--pv-disabled-text, var(--muted));
  cursor: not-allowed;
}

.pv-text-compare .pv-text-compare__textarea:disabled {
  border-color: var(--pv-disabled-line, var(--line));
  background: var(--pv-disabled-bg, var(--panel));
  color: var(--pv-disabled-text, var(--muted));
}

.pv-text-compare :focus-visible {
  outline: 3px solid var(--pv-focus, var(--accent));
  outline-offset: 2px;
}

.pv-text-compare .pv-text-compare__status {
  min-height: 1.6em;
  margin: 0;
  font-weight: 600;
}

.pv-text-compare .pv-text-compare__status[data-tone="error"] {
  color: var(--danger);
}

.pv-text-compare .pv-text-compare__output {
  box-sizing: border-box;
  min-width: 0;
  /* Capped by the viewport so large root font sizes cannot eat the row width at 320 CSS px. */
  padding: min(1rem, 4vw);
  border: 1px solid var(--pv-result-line, var(--line));
  border-radius: 0.75rem;
  background: var(--panel);
}

.pv-text-compare .pv-text-compare__result-title {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
}

.pv-text-compare .pv-text-compare__summary {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pv-text-compare .pv-text-compare__position {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.pv-text-compare .pv-text-compare__rows {
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.5;
  /* The row layout below follows the list's own width, not the viewport. */
  container-type: inline-size;
}

/* Default (any width): a wrapping line — kind, then the before and after numbers, each moving to its
   own line when space runs out — and the text on a full line below. No cell has a fixed minimum
   width, so all four stay inside the panel at 320 CSS px with 200–400% text. */
.pv-text-compare .pv-text-compare__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.75em;
  padding: 0.25rem min(0.5rem, 2vw);
  border-left: 4px solid transparent;
  border-bottom: 1px solid var(--line);
}

.pv-text-compare .pv-text-compare__kind,
.pv-text-compare .pv-text-compare__line {
  flex: 0 1 auto;
  max-width: 100%;
}

/* Aligned columns only when the result list itself is wide enough for them. */
@container (min-width: 36em) {
  .pv-text-compare .pv-text-compare__row {
    display: grid;
    grid-template-columns: 7.5em 3.5em 3.5em minmax(0, 1fr);
    grid-template-areas: "kind before after text";
  }
}

.pv-text-compare .pv-text-compare__row[data-kind="remove"] {
  border-left-color: var(--danger);
  background: var(--pv-tc-remove-bg);
}

.pv-text-compare .pv-text-compare__row[data-kind="add"] {
  border-left-color: var(--accent);
  background: var(--pv-tc-add-bg);
}

.pv-text-compare .pv-text-compare__row[data-active="true"] {
  border-left-width: 8px;
  border-left-color: var(--pv-tc-active);
}

.pv-text-compare .pv-text-compare__row:focus-visible {
  outline-offset: -3px;
}

.pv-text-compare .pv-text-compare__kind {
  grid-area: kind;
  min-width: 0;
  font-weight: 600;
}

.pv-text-compare .pv-text-compare__sign {
  display: inline-block;
  min-width: 1ch;
  font-weight: 700;
}

.pv-text-compare .pv-text-compare__line {
  min-width: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.pv-text-compare .pv-text-compare__line[data-side="before"] {
  grid-area: before;
}

.pv-text-compare .pv-text-compare__line[data-side="after"] {
  grid-area: after;
}

/* Wrapped display only: wrapping never changes the logical line or its number. */
.pv-text-compare .pv-text-compare__text {
  grid-area: text;
  flex: 1 0 100%;
  display: block;
  min-width: 0;
  min-height: 1.5em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.pv-text-compare .pv-text-compare__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.pv-text-compare .pv-text-compare__dialog {
  box-sizing: border-box;
  max-width: min(32rem, calc(100% - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--panel);
  color: var(--text);
}

.pv-text-compare .pv-text-compare__dialog-message {
  margin: 0 0 1rem;
}
