.contact {
  padding: 1rem 1.5rem 5rem;
}

.contact-container {
  max-width: 1280px;
  margin: 0 auto;
}

/* Header */

.contact-header {
  max-width: 640px;
  margin: 0 auto 3.5rem;
  text-align: center;
}

.contact-eyebrow {
  margin: 0 0 0.9rem;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-brand);
}

.contact-heading {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.5rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--color-heading);
}

.contact-lede {
  margin: 1.1rem 0 0;
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--color-text-muted);
}

/* Two-column body */

.contact-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 4rem;
  max-width: 1040px;
  margin: 0 auto;
}

/* Form */

.contact-form {
  display: flex;
  flex-direction: column;
}

.contact-field {
  margin-bottom: 1.4rem;
}

.contact-field label {
  display: block;
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-faint);
}

.contact-field input,
.contact-field textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.85rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-heading);
  font-family: inherit;
  font-size: 0.98rem;
  line-height: 1.5;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.contact-field input::placeholder,
.contact-field textarea::placeholder {
  color: var(--color-text-faint-2);
}

.contact-field textarea {
  resize: vertical;
  min-height: 140px;
}

.contact-field input:hover,
.contact-field textarea:hover {
  border-color: var(--color-border-strong);
}

.contact-field input:focus,
.contact-field textarea:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 4px rgba(var(--color-brand-rgb), 0.14);
}

.contact-field input.is-invalid,
.contact-field textarea.is-invalid {
  border-color: var(--color-error);
}

.contact-field input.is-invalid:focus,
.contact-field textarea.is-invalid:focus {
  box-shadow: 0 0 0 4px rgba(var(--color-error-rgb), 0.14);
}

.contact-field-error {
  margin: 0.45rem 0 0;
  min-height: 1.1em;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--color-error);
}

.contact-submit-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  align-self: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.contact-submit {
  padding: 0.9rem 2.2rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-brand);
  color: var(--color-on-brand);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(var(--color-brand-rgb), 0.24);
  transition: transform var(--response-fast) var(--ease-exit),
    box-shadow var(--response-fast) var(--ease-exit),
    background-color var(--response-fast) var(--ease-exit);
}

/*
  The primary action on the page — it acknowledges the press itself, on
  pointer-down, rather than waiting for the click to resolve and the form to
  validate. Waiting is what makes a button feel dead.
*/
.contact-submit.is-pressed,
.contact-submit.is-pressed:hover {
  transform: scale(var(--press-scale));
  box-shadow: 0 4px 12px rgba(var(--color-brand-rgb), 0.28);
  transition: transform var(--response-instant) var(--ease-enter),
    box-shadow var(--response-instant) var(--ease-enter);
}

/* Previous-message pill */

.contact-history {
  position: relative;
}

.contact-history-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1rem 0.55rem 0.7rem;
  border: 1.5px solid rgba(var(--color-brand-rgb), 0.5);
  border-radius: var(--radius-pill);
  background: rgba(var(--color-brand-rgb), 0.06);
  color: var(--color-brand);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.contact-history-pill:hover,
.contact-history-pill[aria-expanded="true"] {
  background: rgba(var(--color-brand-rgb), 0.12);
  border-color: var(--color-brand);
}

.contact-history-pill:focus-visible {
  outline: 3px solid rgba(var(--color-brand-rgb), 0.45);
  outline-offset: 2px;
}

.envelope {
  position: relative;
  flex-shrink: 0;
  width: 20px;
  height: 14px;
  border-radius: 3px;
  background: var(--color-surface);
  border: 1.5px solid var(--color-brand);
  perspective: 40px;
}

.envelope-letter {
  position: absolute;
  left: 2px;
  right: 2px;
  top: -1px;
  height: 8px;
  background: var(--color-toggle-envelope-bg);
  border: 1.5px solid var(--color-brand);
  border-bottom: none;
  border-radius: 2px 2px 0 0;
  transform: translateY(8px);
  transition: transform 0.35s ease;
}

.envelope-flap {
  position: absolute;
  left: -1.5px;
  right: -1.5px;
  top: -1.5px;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 7px solid var(--color-brand);
  transform-origin: top center;
  transition: transform 0.4s ease;
}

.contact-history-pill:hover .envelope-letter {
  transform: translateY(-6px);
}

.contact-history-pill:hover .envelope-flap {
  transform: rotateX(180deg);
}

/*
  The popover grows out of the pill that opened it. Scaling
  from its own centre would leave the panel floating with no visible cause;
  anchoring `transform-origin` to the trigger makes the relationship between
  button and content obvious without a word of explanation.

  It also leaves along the path it arrived on — `--ease-exit` is the exact
  cubic-bezier mirror of `--ease-enter` — so the return traces the outbound.

  `--popover-x` keeps the horizontal placement (0 here, centred on mobile)
  out of the animated part of the transform, so the two never collide.
*/
.contact-history-popover {
  --popover-x: 0px;
  position: absolute;
  bottom: calc(100% + 0.75rem);
  left: 0;
  width: 280px;
  box-sizing: border-box;
  padding: 1.1rem 1.2rem;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 16px 36px rgba(var(--color-black-rgb), 0.14);
  z-index: 5;
  transform-origin: bottom left;
  opacity: 0;
  transform: translate(var(--popover-x), 6px) scale(0.94);
  transition: opacity var(--response-fast) var(--ease-exit),
    transform var(--response-fast) var(--ease-exit);
}

.contact-history-popover.is-open {
  opacity: 1;
  transform: translate(var(--popover-x), 0) scale(1);
  transition: opacity var(--response) var(--ease-enter),
    transform var(--response) var(--ease-enter);
}

.contact-history-popover-title {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-faint);
}

.contact-history-details {
  margin: 0 0 1rem;
}

.contact-history-row {
  margin-bottom: 0.6rem;
}

.contact-history-row:last-child {
  margin-bottom: 0;
}

.contact-history-row dt {
  margin: 0 0 0.15rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-faint-2);
}

.contact-history-row dd {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--color-heading);
  overflow-wrap: anywhere;
  display: -webkit-box;
  line-clamp: 3;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.contact-history-load {
  width: 100%;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-brand);
  color: var(--color-on-brand);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.25s ease;
}

.contact-history-load:hover {
  background: var(--color-brand-hover);
}

.contact-submit:hover {
  transform: scale(1.02);
  box-shadow: 0 12px 26px rgba(var(--color-brand-rgb), 0.32);
  background: var(--color-brand-hover);
  transition: transform var(--response-fast) var(--ease-enter),
    box-shadow var(--response-fast) var(--ease-enter),
    background-color var(--response-fast) var(--ease-enter);
}

.contact-submit:focus-visible {
  outline: 3px solid rgba(var(--color-brand-rgb), 0.45);
  outline-offset: 3px;
}

.contact-form-status {
  margin: 0.85rem 0 0;
  min-height: 1.2em;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-success);
  text-align: right;
}

/* Right panel */

.contact-panel {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.contact-panel-title {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-heading);
}

.contact-social-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.contact-social-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 0;
  border-top: 1px solid var(--color-border);
  color: inherit;
  text-decoration: none;
}

.contact-social-list li:last-child .contact-social-item {
  padding-bottom: 0;
}

.contact-social-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--color-text-secondary);
  transition: color 0.25s ease;
}

.contact-social-name {
  flex: 1 1 auto;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--color-body);
  transition: color 0.25s ease;
}

.contact-social-arrow {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--color-text-faint);
  transition: transform 0.25s ease, color 0.25s ease;
}

.contact-social-item:hover .contact-social-icon,
.contact-social-item:focus-visible .contact-social-icon {
  color: var(--color-brand);
}

.contact-social-item:hover .contact-social-name,
.contact-social-item:focus-visible .contact-social-name {
  color: var(--color-brand);
}

.contact-social-item:hover .contact-social-arrow,
.contact-social-item:focus-visible .contact-social-arrow {
  color: var(--color-brand);
  transform: translateX(4px);
}

.contact-social-item:focus-visible {
  outline: none;
}

.contact-social-item:focus-visible .contact-social-name {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.contact-email-link {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--color-body);
  font-size: 0.98rem;
  font-weight: 600;
  text-decoration: none;
}

.contact-email-link .contact-social-icon {
  color: var(--color-text-secondary);
}

.contact-email-link:hover,
.contact-email-link:focus-visible {
  color: var(--color-brand);
}

.contact-email-link:hover .contact-social-icon,
.contact-email-link:focus-visible .contact-social-icon {
  color: var(--color-brand);
}

.contact-email-link:focus-visible {
  outline: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Scroll reveal (base hidden state + reduced-motion reset: css/components/reveal.css) */

.contact-header,
.contact-form,
.contact-panel {
  transition: opacity var(--response-slow) var(--ease-enter),
    transform var(--response-slow) var(--ease-enter);
}

.contact.in-view .contact-header {
  opacity: 1;
  transform: translateY(0);
}

.contact.in-view .contact-form {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 100ms;
}

.contact.in-view .contact-panel {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 190ms;
}

@media (prefers-reduced-motion: reduce) {
  .contact-submit:hover {
    transform: none;
  }

  .contact-social-item:hover .contact-social-arrow {
    transform: none;
  }

  .envelope-letter,
  .envelope-flap {
    transition: none;
  }
}

/* Tablet */

@media (max-width: 860px) {
  .contact-grid {
    gap: 2.5rem;
  }
}

@media (max-width: 720px) {
  .contact-grid {
    grid-template-columns: 1fr;
    gap: 2.75rem;
  }
}

/* Mobile */

@media (max-width: 640px) {
  .contact {
    padding: 1rem 1.25rem 3.5rem;
  }

  .contact-heading {
    font-size: 2rem;
  }

  .contact-header {
    margin-bottom: 2.5rem;
  }

  .contact-submit-row {
    position: relative;
    align-self: stretch;
    flex-wrap: wrap;
  }

  .contact-submit {
    flex: 1 1 auto;
  }

  .contact-history {
    position: static;
  }

  .contact-history-popover {
    --popover-x: -50%;
    left: 50%;
    right: auto;
    /* Centred over the row, so it grows from the bottom centre instead. */
    transform-origin: bottom center;
    width: min(280px, calc(100vw - 2.5rem));
  }
}
