/*
 * The human check widget and the inline field errors.
 *
 * Loaded only on pages that carry a form — BaseLayout keys it off the same
 * flag as the reCAPTCHA meta tags, so the rest of the site pays nothing.
 *
 * Tokens come from style.css: --green, --ink, --muted, --line, --pale.
 */

.hc {
  margin: 26px 0 24px;
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--pale);
}

.hc[hidden] { display: none; }

.hc-legend {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.hc-hint {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* ------------------------------------------------------------- the puzzle */

.hc-track {
  position: relative;
  height: 44px;              /* a 44px target, per the touch guidance */
  border: 1px solid #8c9c8d;
  background: white;
  cursor: pointer;
  /* Stops a drag from selecting the surrounding copy, and stops touch
     scrolling from stealing the gesture mid-drag. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* The slot the handle has to land in. Sits under the handle, centred on the
   server-chosen target. */
.hc-gap {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 30px;
  transform: translate(-50%, -50%);
  border: 2px dashed #8c9c8d;
  background: var(--pale);
}

.hc-handle {
  position: absolute;
  top: 50%;
  left: 0;
  width: 42px;
  height: 34px;
  transform: translate(-50%, -50%);
  background: var(--green);
  cursor: grab;
  touch-action: none;
}

/* A grip, so the handle reads as draggable rather than as a coloured block. */
.hc-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 14px;
  transform: translate(-50%, -50%);
  background: white;
  box-shadow: -5px 0 0 white, 5px 0 0 white;
}

.hc-handle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

.hc-handle[aria-disabled='true'] { cursor: default; }

/* ----------------------------------------------------- press and hold */

.hc-hold {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 15px 20px;
  border: 1px solid var(--green);
  background: white;
  color: var(--green);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  cursor: pointer;
  /* A long press must not select text or raise the context menu. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.hc-hold:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Fills left to right as the hold progresses. Width is set from script. */
.hc-hold-fill {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 100%;
  background: var(--green);
  opacity: 0.18;
  transition: width 90ms linear;
}

.hc-hold-label { position: relative; }

.hc-hold:disabled {
  border-color: var(--green);
  background: var(--green);
  color: white;
  cursor: default;
  opacity: 1;
}

.hc-hold:disabled .hc-hold-fill { opacity: 0; }

/* -------------------------------------------------------- state + switch */

.hc-state {
  margin: 12px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.hc-state.hc-ok { color: var(--green); }

.hc-state:empty { display: none; }

.hc-switch {
  margin: 10px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

.hc-switch:hover { color: var(--ink); }

.hc-switch[hidden] { display: none; }

/* Solved: the gap and handle stop inviting interaction. */
.hc[data-hc-done='true'] .hc-track { cursor: default; }
.hc[data-hc-done='true'] .hc-gap { border-style: solid; border-color: var(--green); }
.hc[data-hc-done='true'] .hc-hint { display: none; }

/* --------------------------------------------------------- field errors */

.field-message {
  display: block;
  margin-top: 7px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
  color: #8a2f24;
}

/* Scoped to the inputs the forms actually use, so this cannot bleed into
   third-party markup that sets aria-invalid for its own reasons. */
input[aria-invalid='true'],
select[aria-invalid='true'],
textarea[aria-invalid='true'] {
  border-color: #8a2f24;
}

input[aria-invalid='true']:focus,
select[aria-invalid='true']:focus,
textarea[aria-invalid='true']:focus {
  outline-color: #8a2f24;
}

/* ------------------------------------------------------------ motion, fit */

@media (prefers-reduced-motion: reduce) {
  .hc-hold-fill { transition: none; }
}

@media (max-width: 760px) {
  .hc { padding: 16px; }
  .hc-gap { width: 52px; }
  .hc-handle { width: 48px; }
}
