/*
  Kinetic Signal: Contact page (DESIGN.md 6.5).
  #intro (two-line title, status row), #brief (the sentence form on the blue field, the
  success block), #next (five locking numerals, SM5), #channels (four profile rows).

  Order: page layout, components, sections, animations (hidden states), media queries.
  Tokens and regime variables come from base.css. The page has no CTA band: it is the CTA.
*/

/* ==========================================================================
   #intro: START A / PROJECT, then the status row
   ========================================================================== */

.page-contact .page-intro {
  padding-bottom: var(--s-8);
}

.contact-title {
  font-size: clamp(3rem, 1rem + 8vw, 9rem);
  font-stretch: 125%;
  font-weight: 900;
  line-height: 0.85;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

/* Each line rises as a whole in its own mask (13 letters are too many for a per-letter rise). */
.contact-mask {
  display: block;
}

.contact-line {
  display: inline-block;
}

.contact-status {
  display: grid;
  gap: var(--s-3);
  margin-top: var(--s-7);
  padding-top: var(--s-5);
  border-top: 1px solid var(--line);
}

.contact-status .icon {
  width: 1rem;
  height: 1rem;
}

/* ==========================================================================
   #brief: one sentence in big type; every fragment is a label, every answer is lime
   ========================================================================== */

.brief {
  padding-top: 0;
}

.brief-label {
  margin-bottom: var(--s-7);
}

/* Base (below 768px): each label sits above its field, and fields take the full width. */
.sentence {
  display: grid;
  gap: var(--s-7);
  font-size: var(--fs-form);
  font-stretch: 112%;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

/* The form sets display, so the hidden attribute needs its own rule (success hides the form). */
.sentence[hidden] {
  display: none;
}

.sentence-line {
  display: grid;
  gap: var(--s-7);
}

.sentence .control {
  display: grid;
  gap: var(--s-2);
  min-width: 0;
}

/* The visitor's words are the signal: answers set in the accent color on the field. */
.sentence .input {
  padding: 0.08em 0 0.12em;
  color: var(--accent);
  line-height: 1.15;
}

.sentence .select {
  display: grid;
}

/* Room for the drawn chevron (base.css .select::after). */
.sentence select.input {
  padding-inline-end: 1em;
}

/* The option list is a system popup: reading size, not display size. */
.sentence select.input option {
  font-size: 1rem;
  font-stretch: 100%;
  font-weight: 400;
  letter-spacing: 0;
}

/*
  The brief itself is long text: reading size. Like every field it sits directly on the blue
  field (DESIGN.md 5): the underline, plus a hairline on the start side that marks the block.
*/
.sentence textarea.input {
  padding: 0.4em 0 0.5em var(--s-4);
  border-inline-start: 1px solid var(--line);
  font-size: clamp(1.25rem, 1rem + 1vw, 1.875rem);
  font-stretch: 100%;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: 0;
}

.sentence .field-error {
  font-size: 1rem;
  font-stretch: 100%;
  letter-spacing: 0;
}

/* ---- Send row: the button, the response time, the error message ---- */
.sentence-send {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-5) var(--s-6);
  font-size: var(--fs-body);
  font-stretch: 100%;
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: 0;
}

.send {
  position: relative;
  display: grid;
  width: 100%;
}

/* While the brief is on its way, a tracer line runs under the button. */
.send::after {
  content: "";
  position: absolute;
  right: 1.75rem;
  bottom: -0.625rem;
  left: 1.75rem;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
}

.send.is-busy::after {
  transform: scaleX(1);
}

.send-note {
  color: var(--fg-2);
}

.send-error {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  flex: 0 0 100%;
  padding: var(--s-3) 0 var(--s-3) var(--s-4);
  border-inline-start: 3px solid var(--alarm);
  color: var(--fg);
  font-weight: 500;
}

.send-error[hidden] {
  display: none;
}

.send-error > span {
  max-width: var(--measure);
}

.send-error .icon {
  margin-top: 0.15em;
  color: var(--alarm);
}

.send-error-link {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

/* ---- Success: a tracer block replaces the form ---- */
.brief-success {
  display: grid;
  gap: var(--s-6);
  padding: clamp(1.5rem, 5vw, 4.5rem);
}

.brief-success[hidden] {
  display: none;
}

.success-label .readout-value {
  font-size: clamp(2.5rem, 1rem + 7vw, 7rem);
  text-transform: uppercase;
}

.success-title {
  max-width: 24ch;
  font-size: var(--fs-d2);
  font-stretch: 125%;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

/* ==========================================================================
   #next: five steps, each under a numeral that locks (SM5)
   ========================================================================== */

.steps {
  display: grid;
  border-top: 2px solid var(--fg);
}

.step {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  column-gap: var(--gutter);
  row-gap: var(--s-2);
  padding-block: var(--s-5);
  border-bottom: 1px solid var(--line);
}

.step-num {
  grid-row: 1 / span 2;
}

.step-title {
  align-self: end;
  font-size: clamp(1.25rem, 1rem + 0.7vw, 1.75rem);
  font-stretch: 125%;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.step-line {
  max-width: 34ch;
  color: var(--fg-2);
}

.next-receipt {
  margin-top: var(--s-8);
}

.receipt {
  display: grid;
  gap: var(--s-5);
}

.receipt blockquote {
  max-width: 30em;
  font-size: var(--fs-quote);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: pretty;
}

.receipt figcaption {
  color: var(--fg-2);
}

/* ==========================================================================
   #channels: four profile rows, Freelancer.com first
   ========================================================================== */

.channels {
  padding-top: 0;
}

.channel-list {
  border-top: 2px solid var(--fg);
}

.channel {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: var(--s-4);
  row-gap: var(--s-1);
  min-height: 4.5rem;
  padding-block: var(--s-4);
  border-bottom: 1px solid var(--line);
}

/* The fill bleeds 1rem past the text column so the text never touches its edge. */
.channel::before {
  content: "";
  position: absolute;
  inset: 0 calc(-1 * var(--s-4));
  z-index: -1;
  background: var(--ground-hover);
  opacity: 0;
  transition: opacity var(--dur-micro) linear;
}

.channel:focus-visible::before {
  opacity: 1;
}

.channel-icon {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--accent);
}

/* A name never breaks inside itself ("Freelancer.com" stays one word). */
.channel-name {
  font-size: var(--fs-lead);
  font-stretch: 125%;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.channel-note {
  grid-column: 2;
  color: var(--fg-2);
}

.channel-arrow {
  grid-column: 3;
  grid-row: 1 / span 2;
  width: 1.5rem;
  height: 1.5rem;
  transition: transform var(--dur-micro) var(--ease-lock);
}

.channel:focus-visible .channel-arrow {
  transform: translate(4px, -4px);
}

/* ==========================================================================
   Animations. Hidden states follow the base.css rule: JS on, motion on, intro not done.
   ========================================================================== */

@keyframes brief-rise {
  from { transform: translateY(1.5rem); }
}

@keyframes send-run {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@media (prefers-reduced-motion: no-preference) {
  /* The two title lines rise in their masks, 120ms apart, inside the page slide. */
  html.js:not(.motion-off):not(.intro-done) .contact-line {
    animation: char-rise var(--dur-hero) var(--ease-lock) calc(200ms + var(--i, 0) * 120ms) backwards;
  }

  html.js:not(.motion-off):not(.intro-done) .contact-status {
    animation: fade-rise var(--dur-reveal) var(--ease-lock) 520ms backwards;
  }

  /*
    The form is on the first screen, so it rises with a transform only (no fade): its text
    paints at first paint and the largest text is never held back.
  */
  html.js:not(.motion-off):not(.intro-done) .sentence > * {
    animation: brief-rise var(--dur-reveal) var(--ease-lock) 300ms backwards;
  }

  html.js:not(.motion-off):not(.intro-done) .sentence > :nth-child(n + 4) {
    animation-delay: 420ms;
  }

  /* Busy: the line under the button draws again and again until the answer arrives. */
  html:not(.motion-off) .send.is-busy::after {
    animation: send-run 900ms var(--ease-sweep) infinite;
  }
}

/* ==========================================================================
   Media queries
   ========================================================================== */

/* Row fills only where a pointer can hover, so a tap never leaves a row filled. */
@media (hover: hover) {
  .channel:hover::before {
    opacity: 1;
  }

  .channel:hover .channel-arrow {
    transform: translate(4px, -4px);
  }
}

@media (min-width: 480px) {
  .send {
    width: auto;
  }
}

@media (min-width: 768px) {
  /* One row of three at 768px; the wide gap comes back from 1024px. */
  .contact-status {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-3) var(--s-5);
  }

  /*
    The sentence flows inline. Each label and its control are one unit that never splits over
    two lines (a field alone on a line reads as a stray rule). The control is a grid, so its
    error message opens under the field it belongs to.
    The size follows the width up to --fs-form (reached at 1440px), so the longest unit,
    "and you can reach me at" plus the email field, fits one line from 768px.
  */
  .sentence {
    gap: var(--s-5);
    font-size: min(var(--fs-form), 3.9vw);
    line-height: 1.4;
  }

  .sentence-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 0.28em;
  }

  .sentence-line .field {
    display: flex;
    align-items: baseline;
    gap: 0.28em;
    max-width: 100%;
  }

  .sentence-line label {
    flex: none;
    white-space: nowrap;
  }

  .sentence-line .control {
    flex: 0 1 auto;
  }

  .sentence-line .control,
  .sentence-line .select {
    max-width: 100%;
  }

  /* The optional field starts its own line. */
  .sentence-line .field--newline {
    flex-basis: 100%;
  }

  /* Fixed ch widths first (every engine); field-sizing refines them where it exists. */
  .sentence-line .input {
    width: 12ch;
    max-width: 100%;
  }

  .sentence-line .input[type="email"] {
    width: 18ch;
  }

  .sentence-line select.input {
    width: auto;
  }

  .field--brief {
    margin-top: var(--s-4);
  }

  .steps {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    column-gap: var(--gutter);
    row-gap: var(--s-8);
    border-top: 0;
  }

  /* 2 + 3: the first two steps take half the row each, the next three a third each. */
  .step {
    grid-column: span 3;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    row-gap: var(--s-3);
    padding-block: var(--s-5) 0;
    border-top: 2px solid var(--fg);
    border-bottom: 0;
  }

  .step:nth-child(n + 3) {
    grid-column: span 2;
  }

  .step-num {
    grid-row: auto;
    margin-bottom: var(--s-4);
  }

  /* The note stays under the name until 1024px: beside it, the name has no room at this width. */
  .channel {
    grid-template-columns: 3rem minmax(0, 1fr) auto;
    column-gap: var(--s-5);
    min-height: 7rem;
  }

  .channel-icon {
    grid-row: 1 / span 2;
    width: 2rem;
    height: 2rem;
  }

  .channel-name {
    font-size: clamp(1.5rem, 3.4vw, 2.25rem);
  }

  /* A row without a note (LinkedIn, GitHub): the name centers on the icon. */
  .channel-name:nth-last-child(3) {
    grid-row: 1 / span 2;
  }

  .channel-arrow {
    width: 2rem;
    height: 2rem;
  }
}

@media (min-width: 768px) {
  @supports (field-sizing: content) {
    .sentence-line input.input {
      field-sizing: content;
      width: auto;
      min-width: 10ch;
    }

    .sentence-line .input[type="email"] {
      width: auto;
      min-width: 13ch;
    }

    /* A select takes the width of the chosen option, not of the longest one. */
    .sentence-line select.input {
      field-sizing: content;
    }

    /* The field grows with the text, so the resize grip has no job. */
    .sentence textarea.input {
      field-sizing: content;
      min-height: 4lh;
      resize: none;
    }
  }
}

@media (min-width: 1024px) {
  .contact-status {
    column-gap: var(--s-8);
  }

  .sentence {
    max-width: 78rem;
  }

  .channel {
    grid-template-columns: 3rem minmax(0, 1fr) auto auto;
  }

  .channel-icon,
  .channel-name:nth-last-child(3) {
    grid-row: auto;
  }

  .channel-name {
    font-size: var(--fs-d2);
  }

  .channel-note {
    grid-column: 3;
    text-align: end;
  }

  .channel-arrow {
    grid-column: 4;
    grid-row: 1;
  }

  .steps {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  /* Five narrow columns: the title follows the column width, so "specification" stays one word. */
  .step-title {
    font-size: clamp(1.125rem, 1.75vw, 1.75rem);
  }

  .step,
  .step:nth-child(n + 3) {
    grid-column: auto;
  }

  .receipt {
    grid-column: 2 / 10;
  }
}
