/* Porcupyn — the conversation dialog.
   Tokens, fonts and base type come from css/shared.css; the page layout from css/e.css.
   Everything here is prefixed .cx- so it cannot collide with those files.
   Motion: every travel distance is multiplied by --motion, which is 0 under reduced motion, leaving fades only. */
:root {
  --motion: 1;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --plum-tint: #EFE6F1;
  --wash: #EEE9EF;
  /* Control boundaries (WCAG 1.4.11, at least 3:1): #8A818B is 3.75:1 on white and 3.41:1 on the page ground. */
  --field-line: #8A818B;
  --plum-deep: #7A3B83;
  --error: #9B2C2C;
  --scrim: rgba(37, 35, 42, .42);
  --sheet-w: 640px;
  --pad-x: 28px;
}
@media (prefers-reduced-motion: reduce) { :root { --motion: 0; } }
html.cx-lock { overflow: hidden; }

/* The page’s CTA is a button; it keeps the link look. */
button.contact {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  border-radius: 0;
  padding-inline: 0;
  font: 600 var(--ui-size)/1.65 var(--body);
}

/* ───────────── Dialog shell ───────────── */
dialog.cx {
  position: fixed;
  inset: auto;
  left: 0;
  top: var(--vvtop, 0px);
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
  height: var(--vvh, 100%);
  max-width: none;
  max-height: none;
  background: transparent;
  color: var(--ink);
  overflow: hidden;
  font: 400 var(--ui-size)/1.65 var(--body);
}
dialog.cx[open] { display: grid; place-items: center; grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
dialog.cx::backdrop { background: transparent; }
.cx *, .cx *::before, .cx *::after { box-sizing: border-box; }
.cx h2, .cx p, .cx ul, .cx fieldset { margin: 0; padding: 0; }
.cx ul { list-style: none; }
.cx h2:focus { outline: none; }
.cx button, .cx input, .cx select, .cx textarea { font-family: inherit; }

.cx-scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity 240ms ease-out; }
.cx[data-state="open"] .cx-scrim { opacity: 1; }
.cx[data-state="closing"] .cx-scrim { transition-duration: 170ms; }

.cx-sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(var(--sheet-w), calc(100% - 48px));
  max-height: calc(100% - 32px);
  background: var(--ground);
  border: 1px solid var(--ink);
  border-radius: 4px;
  box-shadow: 0 28px 60px -28px rgba(37, 35, 42, .5);
  opacity: 0;
  transform: translateY(calc(16px * var(--motion))) scale(calc(1 - .02 * var(--motion)));
  transition: opacity 260ms ease-out, transform 300ms var(--ease-out);
}
.cx[data-state="open"] .cx-sheet { opacity: 1; transform: none; }
.cx[data-state="closing"] .cx-sheet { transition-duration: 150ms; transition-timing-function: ease-out; }

.cx-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 8px 0 var(--pad-x); }
.cx-step { color: var(--muted); font: 600 13px/1.4 var(--body); letter-spacing: .01em; }
.cx-close {
  display: grid; place-items: center;
  background: none; border: 0; color: var(--ink);
  cursor: pointer; touch-action: manipulation;
}
.cx-close .od-icon { --od-icon-size: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.cx-close:focus-visible { outline: 2px solid var(--focus); outline-offset: -4px; }

/* Panels: leave faster than they enter, a small sideways travel in the direction of the step. */
.cx-panel { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; min-width: 0; transition: opacity 260ms ease-out, transform 260ms var(--ease-out); }
.cx-panel.is-leaving { opacity: 0; transition-duration: 140ms; transition-timing-function: ease-out; transform: translateX(calc(-24px * var(--motion) * var(--dir, 1))); }
.cx-panel.is-entering { opacity: 0; transform: translateX(calc(24px * var(--motion) * var(--dir, 1))); }
.cx[data-dir="fwd"] { --dir: 1; }
.cx[data-dir="back"] { --dir: -1; }

.cx-body { flex: 1 1 auto; min-height: 0; padding: 4px var(--pad-x) 12px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
.cx-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px 24px; padding: 16px var(--pad-x) 24px; }

.cx-h { font: 500 clamp(30px, 3.4vw, 38px)/1.1 var(--display); letter-spacing: -.035em; text-wrap: balance; }
.cx-sub { margin-top: 8px; max-width: 46ch; font-size: 16px; line-height: 1.55; text-wrap: pretty; overflow-wrap: anywhere; }
.cx-label-sm { color: var(--muted); font: 600 13px/1.4 var(--body); }
.cx-label { display: block; margin-bottom: 8px; padding: 0; color: var(--ink); font: 600 14px/1.4 var(--body); }

/* ───────────── Buttons and links ───────────── */
.cx-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 48px; padding: 12px 24px;
  background: var(--plum); color: #fff; border: 1px solid var(--plum); border-radius: 2px;
  font: 600 16px/1.2 var(--body);
  cursor: pointer; touch-action: manipulation;
}
.cx-btn .od-icon, .cx-another .od-icon { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.cx-btn .od-icon { --od-icon-size: 20px; transition: transform var(--feedback) ease-out; }
.cx-btn { transition: transform 120ms var(--ease-out), background-color 180ms ease-out, border-color 180ms ease-out; }
.cx-btn:active:not([aria-disabled="true"]) { transform: scale(calc(1 - .02 * var(--motion))); }
.cx-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.cx-btn[aria-disabled="true"] { background: var(--muted); border-color: var(--muted); color: #fff; cursor: progress; }
.cx-link, .cx-clear, .cx-another {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 4px;
  background: none; border: 0; border-radius: 0;
  color: var(--muted); font: 600 14px/1.3 var(--body);
  cursor: pointer; touch-action: manipulation;
}
.cx-link { color: var(--plum-deep); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.cx-another .od-icon { --od-icon-size: 16px; transition: transform 280ms var(--ease-out); }
.cx-another:active .od-icon { transform: rotate(calc(180deg * var(--motion))); }
.cx-link:focus-visible, .cx-clear:focus-visible, .cx-another:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (hover: hover) {
  .cx-btn:hover:not([aria-disabled="true"]) { background: var(--plum-deep); border-color: var(--plum-deep); }
  .cx-btn:hover:not([aria-disabled="true"]) .od-icon { transform: translateX(calc(4px * var(--motion))); }
  .cx-link:hover, .cx-clear:hover, .cx-another:hover { color: var(--ink); }
}

/* ───────────── Step 1: note and thoughts ───────────── */
.cx-note {
  margin-top: 16px; padding: 12px 16px 0;
  background: #fff; border: 1px solid var(--field-line); border-radius: 4px;
  transition: border-color var(--feedback) ease-out;
}
/* One quiet line when focused: the border turns Plum and thickens by a single pixel. No second ring. */
.cx-note:focus-within { border-color: var(--plum); box-shadow: 0 0 0 1px var(--plum); }
.cx-note[data-flash] { animation: note-flash 520ms var(--ease-out); }
.cx-note[data-flash]:focus-within { animation-name: note-flash-focus; }
@keyframes note-flash {
  from { box-shadow: 0 0 0 0 rgba(145, 76, 154, .35); }
  to { box-shadow: 0 0 0 6px rgba(145, 76, 154, 0); }
}
@keyframes note-flash-focus {
  from { box-shadow: 0 0 0 1px var(--plum), 0 0 0 1px rgba(145, 76, 154, .35); }
  to { box-shadow: 0 0 0 1px var(--plum), 0 0 0 7px rgba(145, 76, 154, 0); }
}
.cx-msg {
  display: block; width: 100%; min-height: 52px; max-height: min(240px, 34dvh); padding: 0;
  border: 0; background: transparent; color: var(--ink);
  font: 400 17px/1.55 var(--body);
  resize: none; overflow-y: auto; outline: none;
}
.cx-msg::placeholder { color: var(--muted); }
.cx-note-foot { display: flex; justify-content: flex-end; height: 28px; margin-right: -8px; }
.cx-clear { align-self: center; min-height: 36px; padding: 0 8px; font-weight: 500; }
.cx-note[data-empty] .cx-clear[data-mode="clear"] { visibility: hidden; }

.cx-cloud { margin-top: 16px; }
.cx-cloud-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.cx-another { white-space: nowrap; }
.cx-cloud-label { color: var(--muted); font: 600 13px/1.4 var(--body); }
.cx-tokens { display: flex; flex-wrap: wrap; gap: 10px 8px; padding: 4px 4px 8px; }
.cx-tokens .slot {
  max-width: 100%;
  margin-left: calc(var(--shift, 0) * 1px);
  transform: translateY(calc(var(--nudge, 0) * 1px)) rotate(calc(var(--tilt, 0) * 1deg));
  transition: opacity 320ms ease-out;
  transition-delay: calc(var(--i, 0) * 30ms);
}
.slot.is-out { opacity: 0; }
.slot.is-enter { animation: slot-in 300ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 40ms); }
@keyframes slot-in {
  from { opacity: 0; translate: 0 calc(8px * var(--motion)); }
  to { opacity: 1; translate: 0 0; }
}

.cx-pill {
  display: flex; align-items: center; gap: 6px;
  max-width: 100%; min-height: 36px; padding: 6px 13px;
  background: var(--ground); border: 1px solid var(--ink); border-radius: 2px;
  color: var(--ink); font: 500 13.5px/1.3 var(--body); text-align: left;
  cursor: pointer; touch-action: manipulation;
  transition: transform 180ms var(--ease-out), background-color 180ms ease-out, border-color 180ms ease-out;
}
.cx-pill-label { display: block; min-width: 0; overflow-wrap: anywhere; }
.cx-pill:active { transform: translateY(1px) scale(.98); }
.cx-pill:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.cx-used { display: none; color: var(--plum-deep); }
.cx-used .od-icon { --od-icon-size: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cx-pill[data-used] { background: var(--plum-tint); border-color: var(--plum); }
.cx-pill[data-used] .cx-used { display: inline-flex; }
.cx-pill.is-picked { animation: settle 260ms var(--ease-out); }
@keyframes settle {
  from { transform: scale(calc(1 - .05 * var(--motion))); }
  to { transform: none; }
}
@media (hover: hover) {
  .cx-pill:hover { transform: translateY(calc(-2px * var(--motion))) rotate(calc(var(--tilt, 0) * -1deg * var(--motion))); background: var(--plum-tint); }
}

.cx-err { margin-top: 8px; color: var(--error); font: 500 14px/1.5 var(--body); }
.cx-err::before { content: "!"; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-right: 8px; border: 1.5px solid currentColor; border-radius: 50%; font-size: 11px; font-weight: 700; line-height: 1; vertical-align: 1px; }
.cx-err--block { margin-top: 12px; }
.cx [aria-invalid="true"] { border-color: var(--error) !important; }

/* ───────────── Step 2: contact ───────────── */
/* A lightweight recap of the note: a quiet tinted surface, no outline, the edit action inside it. */
.cx-recap {
  --recap-lines: 3;
  margin-top: 16px; padding: 12px 16px 14px;
  background: var(--wash); border-radius: 4px;
}
.cx-recap-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 0; }
.cx-recap-head .cx-link { margin-right: -4px; }
.cx-recap-text {
  color: var(--ink); font: 400 15px/1.6 var(--body);
  white-space: pre-line; overflow-wrap: anywhere;
}
.cx-recap-text.is-clamped { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--recap-lines); overflow: hidden; }
.cx-more {
  min-height: 36px; margin: 2px 0 -8px -4px; padding: 0 4px;
  background: none; border: 0; color: var(--plum-deep);
  font: 600 14px/1.3 var(--body); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
  cursor: pointer; touch-action: manipulation;
}
.cx-more:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.cx-recap--sent { margin-top: 20px; }
.cx-recap--sent .cx-label-sm { margin-bottom: 4px; }
.cx-recap--sent .cx-recap-text { display: block; }

/* Step 2 rhythm: the recap, then a clear gap, then one even stack of labelled fields. */
.cx-form { margin-top: 24px; }
.cx-row { margin-top: 16px; min-width: 0; border: 0; }
.cx-row:first-child { margin-top: 0; }
.cx-input {
  display: block; width: 100%; min-height: 44px; padding: 8px 12px;
  background: #fff; color: var(--ink);
  border: 1px solid var(--field-line); border-radius: 2px;
  font: 400 16px/1.4 var(--body);
  transition: border-color var(--feedback) ease-out;
}
.cx-input::placeholder { color: var(--muted); }
.cx-input:focus-visible { outline: none; border-color: var(--plum); box-shadow: 0 0 0 1px var(--plum); }
@media (hover: hover) {
  .cx-input:hover:not(:focus-visible) { border-color: var(--ink); }
}

/* ───────────── WhatsApp number: intl-tel-input, themed to match the other fields ─────────────
   The library supplies the behaviour and markup (.iti*); only colour, type, size and edges are set here.
   Its stylesheet is injected before this one, and these rules are scoped under .cx to win the cascade. */
.cx {
  --iti-border-color: var(--field-line);
  --iti-hover-color: var(--plum-tint);
  --iti-icon-color: var(--muted);
  --iti-country-selector-bg: #fff;
  --iti-spacer-horizontal: 12px;
  --iti-arrow-padding: 8px;
  --iti-flag-width: 20px;
  --iti-strict-reject-flash-color: rgba(155, 44, 44, .1);
}
.cx-phone { position: relative; }
.cx-phone[data-loading] .cx-input { opacity: .6; pointer-events: none; }
.cx .cx-phone .iti { display: block; width: 100%; }
.cx .iti__selected-country { color: var(--ink); font: 500 15px/1 var(--body); }
.cx .iti__selected-country-primary { border-radius: 1px 0 0 1px; }
.cx .iti__selected-dial-code { margin-left: 8px; }
.cx .iti__selected-country:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* The country list: same surface language as the form. One restrained shadow, because it floats over the modal. */
.cx .iti__country-selector {
  background: #fff; color: var(--ink);
  border: 1px solid var(--field-line); border-radius: 2px;
  font: 400 15px/1.4 var(--body);
}
.cx .iti--inline-country-selector .iti__country-selector { box-shadow: 0 12px 28px -16px rgba(37, 35, 42, .45); }
.cx .iti__search-input-wrapper { border-bottom-color: var(--rule); }
.cx .iti__search-input {
  min-height: 44px; background: transparent; color: var(--ink);
  font: 400 15px/1.4 var(--body); border-radius: 0;
}
.cx .iti__search-input::placeholder { color: var(--muted); }
.cx .iti__search-input:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.cx .iti__search-clear:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.cx .iti__country { min-height: 40px; }
.cx .iti__country.iti__highlight { background-color: #E8DCEB; box-shadow: inset 0 0 0 1px var(--plum); }
.cx .iti__dial-code { color: var(--muted); }
.cx .iti__no-results { color: var(--muted); }
.cx .iti--fullscreen-popup.iti--detached-country-selector { background-color: var(--scrim); }
/* While the full-screen country list is open, hide the dialog's own header so two close buttons never overlap. */
.cx:has(.iti--fullscreen-popup:not(.iti__hide)) .cx-head { visibility: hidden; }
.cx .iti--fullscreen-popup .iti__country { min-height: 44px; }
.cx .iti--fullscreen-popup .iti__search-input { font-size: 16px; }
.cx .iti--fullscreen-popup .iti__close-button { min-width: 44px; }
.cx .iti--fullscreen-popup .iti__close-button:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.cx-hint { margin-top: 6px; color: var(--muted); font: 400 14px/1.5 var(--body); }
/* The fieldset inherited a zero margin from the dialog reset, so its gap was tighter than every other row. */
.cx .cx-method { margin-top: 16px; }

/* Contact method: two small chips, in the same family as the thoughts but quieter. Plum marks the active one. */
.cx-method { padding: 0; min-width: 0; }
.cx-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cx-chip { position: relative; display: block; }
.cx-chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.cx-chip span {
  display: flex; align-items: center; justify-content: center;
  min-height: 40px; min-width: 88px; padding: 6px 16px;
  background: transparent; border: 1px solid var(--field-line); border-radius: 2px;
  color: var(--muted); font: 500 14.5px/1.3 var(--body);
  transition: background-color 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out;
}
.cx-chip input:checked + span {
  background: var(--plum-tint); border-color: var(--plum); box-shadow: inset 0 0 0 1px var(--plum);
  color: var(--plum-deep); font-weight: 600;
}
.cx-chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (hover: hover) {
  .cx-chip input:not(:checked):hover + span { border-color: var(--ink); color: var(--ink); }
}

/* ───────────── Confirmation ───────────── */
.cx-quills { display: block; width: 72px; height: auto; margin: 4px 0 16px; fill: var(--plum); overflow: visible; }
.cx-quills path { transform-box: fill-box; opacity: 0; animation: quill-in 380ms var(--ease-out) both; animation-delay: calc(var(--k) * 45ms); }
@keyframes quill-in {
  from { opacity: 0; transform: translateY(calc(10px * var(--motion))); }
  to { opacity: 1; transform: none; }
}

/* ───────────── Smaller laptop heights: keep the first step inside the viewport ───────────── */
@media (min-width: 641px) and (max-height: 700px) {
  .cx-sheet { max-height: calc(100% - 16px); }
  .cx-sub { margin-top: 6px; }
  .cx-note { margin-top: 12px; }
  .cx-cloud { margin-top: 12px; }
  .cx-foot { padding-block: 8px 16px; }
  .cx-recap { --recap-lines: 2; margin-top: 12px; }
  .cx-form { margin-top: 20px; }
  .cx-row { margin-top: 12px; }
}

/* ───────────── Mobile: a full-screen conversation surface ───────────── */
@media (max-width: 640px) {
  :root { --pad-x: 20px; }
  dialog.cx[open] { place-items: stretch; }
  .cx-sheet {
    width: 100%; max-height: none; height: 100%;
    border: 0; border-radius: 0; box-shadow: none;
    transform: translateY(calc(24px * var(--motion)));
  }
  .cx-head { padding: max(8px, env(safe-area-inset-top)) 8px 0 var(--pad-x); }
  .cx-body { padding-top: 8px; }
  .cx-h { font-size: 29px; }
  .cx-sub { font-size: 15px; }
  .cx-note { margin-top: 12px; padding: 10px 14px 0; }
  .cx-msg { font-size: 16px; min-height: 48px; max-height: 30dvh; }
  .cx-cloud { margin-top: 12px; }
  .cx-tokens { gap: 8px; padding: 4px 2px 4px; }
  .cx-tokens .slot { margin-left: calc(var(--shift, 0) * .5px); }
  .cx-pill { min-height: 44px; padding: 8px 14px; font-size: 14px; }
  .cx-foot {
    padding: 12px var(--pad-x) max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--rule);
  }
  .cx-foot .cx-btn { flex: 1 1 100%; }
  .cx-recap-text { font-size: 14px; }
}
@media (max-width: 640px) and (max-height: 560px) {
  .cx-sub { display: none; }
}
@media (max-width: 400px) {
  .cx-tail { display: none; }                      /* "A few thoughts [to start from]" so the row never wraps */
}
@media (max-width: 374px) {
  .cx-h { font-size: 26px; }
}
@media (pointer: coarse) {
  .cx-clear { min-height: 44px; margin-block: -8px; }
  .cx-more { min-height: 44px; margin-bottom: -14px; }
  .cx-chip span { min-height: 44px; }
}

/* ───────────── Reduced motion: fades only, nothing travels or loops ───────────── */
@media (prefers-reduced-motion: reduce) {
  .cx-note[data-flash], .cx-pill.is-picked { animation: none; }
  .cx-sheet, .cx-panel, .cx-pill, .slot, .cx-btn { transition-duration: 120ms; transition-delay: 0ms; }
  .slot.is-enter { animation-duration: 120ms; animation-delay: 0ms; }
  .cx-quills path { animation-duration: 120ms; animation-delay: 0ms; }
  .cx-btn .od-icon, .cx-another .od-icon { transition: none; }
}

/* ───────────── Footer privacy link: the footer keeps its height and the line on the left stays where it was ───────────── */
.footer { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; column-gap: var(--space-3); }
/* A 44px-tall target without adding height: the padding is cancelled by the negative margin. */
.footer-link {
  padding: 12px 0; margin-block: -12px;
  color: var(--muted); font-size: 14px; line-height: 1.65;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.footer-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (hover: hover) { .footer-link:hover { color: var(--ink); } }

/* ───────────── Privacy line, direct-email fallback, phone retry, no-script note ───────────── */
.cx-privacy { margin-top: 16px; color: var(--muted); font: 400 14px/1.5 var(--body); text-wrap: pretty; }
.cx-privacy a, .cx-fallback a, .nojs a { color: var(--plum-deep); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.cx-privacy a:focus-visible, .cx-fallback a:focus-visible, .nojs a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.cx-fallback { margin-top: 0; color: var(--muted); font: 400 14px/1.5 var(--body); overflow-wrap: anywhere; }
.cx-phone-retry { margin: 0 0 0 -4px; }
.cx-phone-retry[aria-disabled="true"] { color: var(--muted); cursor: progress; }
.nojs { margin: 0; max-width: 46ch; font-size: 16px; line-height: 1.65; overflow-wrap: anywhere; }
@media (hover: hover) {
  .cx-privacy a:hover, .cx-fallback a:hover, .nojs a:hover { color: var(--ink); }
}

/* ───────────── Sending: failure state and honeypot ───────────── */
.cx-retry { margin: 4px 0 0 -4px; }
.cx-hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
