/* The contact page: the form as an uplink console, with the station it goes to alongside.
   The confirmation page uses the same console, and with motion on plays the message going
   out: the form's rows fold away and the readout types itself out, in time with the globe.
   Loaded after main.css, whose layers and tokens it uses. */

@layer components {
  /* ---------------------------------------------------------------- the console */

  .uplink {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    margin-block-start: 40px;
    overflow: hidden;
    border: 1px solid var(--screen-edge);
    border-radius: var(--radius-screen);
    background:
      radial-gradient(60% 80% at 85% 10%, rgb(var(--screen-haze-rgb) / 0.4), transparent 65%),
      var(--screen-base);
    box-shadow: inset 0 0 90px rgb(0 0 0 / 0.5);
    color: var(--screen-text);
  }

  /* Scan lines over the panel. */
  .uplink::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(to bottom, rgb(0 0 0 / 0.14) 0 1px, transparent 1px 3px);
  }

  /* Viewfinder brackets in the corners, as on the home page's hero. */
  .uplink__frame {
    position: absolute;
    inset: 12px;
    z-index: 1;
    pointer-events: none;
    background:
      linear-gradient(var(--screen-dim), var(--screen-dim)) 0 0 / 18px 1px no-repeat,
      linear-gradient(var(--screen-dim), var(--screen-dim)) 0 0 / 1px 18px no-repeat,
      linear-gradient(var(--screen-dim), var(--screen-dim)) 100% 0 / 18px 1px no-repeat,
      linear-gradient(var(--screen-dim), var(--screen-dim)) 100% 0 / 1px 18px no-repeat,
      linear-gradient(var(--screen-dim), var(--screen-dim)) 0 100% / 18px 1px no-repeat,
      linear-gradient(var(--screen-dim), var(--screen-dim)) 0 100% / 1px 18px no-repeat,
      linear-gradient(var(--screen-dim), var(--screen-dim)) 100% 100% / 18px 1px no-repeat,
      linear-gradient(var(--screen-dim), var(--screen-dim)) 100% 100% / 1px 18px no-repeat;
    opacity: 0.6;
  }

  .uplink__main {
    min-inline-size: 0;
    border-inline-end: 1px solid var(--screen-edge);
  }

  .uplink__bar {
    display: flex;
    justify-content: space-between;
    margin: 0;
    padding: 14px 22px;
    border-block-end: 1px solid var(--screen-edge);
    color: var(--screen-dim);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    letter-spacing: 0.06em;
  }

  /* The lamp in the bar. */
  .lamp {
    display: grid;
    justify-items: end;
  }

  .lamp__state {
    grid-area: 1 / 1;
    display: inline-flex;
    gap: 8px;
    align-items: center;
    color: var(--accent);
  }

  .lamp__state::before {
    content: "";
    inline-size: 8px;
    block-size: 8px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
  }

  .lamp__state--tx {
    display: none;
    color: #ffc75a;
  }

  /* ---------------------------------------------------------------- the form */

  .uplink__form {
    margin: 0;
  }

  .header-row {
    position: relative;
    display: grid;
    grid-template-columns: 9rem minmax(0, 1fr);
    gap: 20px;
    align-items: center;
    min-inline-size: 0;
    margin: 0;
    padding: 14px 22px;
    border: 0;
    border-block-end: 1px solid rgb(var(--screen-dim-rgb) / 0.14);
    transition: background-color 0.2s;
  }

  .header-row--top {
    align-items: start;
  }

  .header-row__key {
    color: rgb(var(--accent-rgb) / 0.7);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    letter-spacing: 0.12em;
    transition: color 0.2s;
  }

  .header-row--top .header-row__key {
    padding-block-start: 10px;
  }

  .header-row__fixed {
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
  }

  .header-row__value {
    display: grid;
    gap: 6px;
  }

  /* The row being filled in lights up. */
  .header-row:focus-within {
    background: linear-gradient(90deg, rgb(var(--accent-rgb) / 0.07), transparent 70%);
  }

  .header-row:focus-within::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    inline-size: 3px;
    background: var(--accent);
    box-shadow: 0 0 10px rgb(var(--accent-rgb) / 0.8);
  }

  .header-row:focus-within .header-row__key {
    color: var(--accent);
    text-shadow: 0 0 8px rgb(var(--accent-rgb) / 0.6);
  }

  .field__input {
    box-sizing: border-box;
    inline-size: 100%;
    padding: 8px 0;
    border: 0;
    border-block-end: 1px solid rgb(var(--screen-dim-rgb) / 0.3);
    border-radius: 0;
    background: none;
    color: var(--screen-text);
    caret-color: var(--accent);
    font-family: var(--font-mono);
    font-size: 1rem;
  }

  .field__input::placeholder {
    color: rgb(var(--screen-dim-rgb) / 0.55);
  }

  textarea.field__input {
    min-block-size: 150px;
    padding: 10px 12px;
    border: 1px solid rgb(var(--screen-dim-rgb) / 0.3);
    border-radius: 6px;
    resize: vertical;
  }

  /* The row's lighting shows where the focus is, so the input only needs its line lit. */
  .field__input:focus-visible {
    border-color: var(--accent);
    outline: none;
    box-shadow: none;
  }

  .row-error {
    margin: 0;
    color: var(--sell);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
  }

  .row-error::before {
    content: "! ";
  }

  .header-row:has(.row-error) .field__input {
    border-color: var(--sell);
  }

  .header-row:has(.row-error) .header-row__key {
    color: var(--sell);
  }

  /* Problems with the form as a whole, such as the rate limit. */
  .uplink__alert {
    padding: 12px 22px;
    border-block-end: 1px solid rgb(var(--screen-dim-rgb) / 0.14);
    background: rgb(255 158 196 / 0.08);
    color: var(--sell);
    font-family: var(--font-mono);
    font-size: 0.875rem;
  }

  .uplink__alert p {
    margin: 0;
  }

  .uplink__alert p::before {
    content: "! ";
  }

  /* The reasons, as channels to transmit on. Real radio buttons, hidden inside the labels. */
  .channels {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .channel {
    position: relative;
    display: grid;
    padding: 6px 12px;
    border: 1px solid rgb(var(--screen-dim-rgb) / 0.35);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    cursor: pointer;
  }

  .channel input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .channel small {
    color: var(--screen-dim);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
  }

  .channel:has(input:checked) {
    border-color: var(--accent);
    background: rgb(var(--accent-rgb) / 0.1);
    box-shadow: inset 3px 0 0 var(--accent);
  }

  .channel:has(input:checked) small {
    color: var(--accent);
  }

  .channel:has(input:focus-visible) {
    outline: 2px solid #fff;
    outline-offset: 2px;
  }

  /* Hidden from people, but not with display: none, which some bots look for. */
  .honeypot {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .uplink__foot {
    display: flex;
    gap: 20px;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px 20px;
  }

  .uplink__foot .button {
    flex: none;
    white-space: nowrap;
  }

  .uplink__meta {
    margin: 0;
    color: var(--screen-dim);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
  }

  .uplink__meta a,
  .uplink__station a {
    color: var(--accent);
    text-underline-offset: 3px;
  }

  .uplink__count b {
    color: var(--accent);
    font-weight: 400;
  }

  /* ---------------------------------------------------------------- the station */

  .uplink__station {
    display: grid;
    gap: 18px;
    align-content: start;
    padding: 22px 24px;
  }

  .station__globe {
    justify-self: center;
    inline-size: 290px;
    block-size: 290px;
  }

  .station__globe img,
  .station__globe canvas {
    inline-size: 100%;
    block-size: 100%;
  }

  .station__rows {
    display: grid;
    grid-template-columns: 9ch 1fr;
    gap: 8px 12px;
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.45;
  }

  .station__rows dt {
    color: var(--screen-dim);
  }

  .station__rows dd {
    margin: 0;
    overflow-wrap: anywhere;
  }

  /* ---------------------------------------------------------------- sent */

  /* The form as it was sent. It only shows while it folds away, with motion on. */
  .uplink__echo {
    display: none;
  }

  .tx {
    display: grid;
    gap: 14px;
    align-content: start;
    padding: 24px 22px 26px;
    font-family: var(--font-mono);
  }

  .tx p {
    margin: 0;
  }

  .tx__title {
    color: var(--screen-dim);
    font-size: 0.8125rem;
    letter-spacing: 0.08em;
  }

  .hexdump {
    display: grid;
    gap: 2px;
    overflow-x: auto;
    padding: 14px 16px;
    border: 1px solid rgb(var(--screen-dim-rgb) / 0.2);
    border-radius: 6px;
    background: rgb(0 0 0 / 0.25);
    color: rgb(var(--screen-text-rgb) / 0.85);
    font-size: 0.875rem;
    white-space: pre;
  }

  .hexdump--narrow {
    display: none;
  }

  .hexdump p:last-child {
    color: var(--screen-dim);
  }

  .tx__ok {
    color: var(--accent);
  }

  /* The details of the message that came in, as the console's last readout. */
  .tx__summary {
    display: grid;
    grid-template-columns: 9ch 1fr;
    gap: 6px 14px;
    margin: 6px 0 0;
    padding: 14px 16px;
    border: 1px solid rgb(var(--accent-rgb) / 0.35);
    border-radius: 6px;
    background: rgb(var(--accent-rgb) / 0.05);
    font-size: 0.875rem;
  }

  .tx__summary dt {
    color: var(--screen-dim);
  }

  .tx__summary dd {
    margin: 0;
    overflow-wrap: anywhere;
  }

  .tx__again {
    margin-block-start: 6px;
  }

  /* ---------------------------------------------------------------- privacy */

  .contact-privacy {
    margin-block-start: 40px;
    color: var(--muted);
    font-size: 0.9375rem;
    line-height: 1.55;
  }

  .contact-privacy__title {
    margin: 0 0 10px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: lowercase;
  }

  .contact-privacy p {
    max-inline-size: 70ch;
    margin: 0 0 8px;
  }

  /* On phones the station's details are a strip above the console. */
  .station-strip {
    display: none;
  }

  /* Tablets: the station goes under the console. */
  @media (width < 900px) {
    .uplink {
      grid-template-columns: minmax(0, 1fr);
    }

    .uplink__main {
      border-inline-end: 0;
      border-block-end: 1px solid var(--screen-edge);
    }

    .header-row {
      grid-template-columns: minmax(0, 1fr);
      gap: 6px;
    }

    .uplink__foot {
      flex-wrap: wrap;
    }
  }

  /* Phones: the station shrinks to the strip, and the globe only appears once a message has
     been sent, between the lamp and the readout so the packet can be seen arriving. */
  @media (max-width: 40em) {
    .station-strip {
      display: flex;
      flex-wrap: wrap;
      gap: 4px 12px;
      align-items: center;
      margin: 24px 0 0;
      padding: 10px 14px;
      border: 1px solid var(--screen-edge);
      border-radius: 10px;
      background: var(--screen-base);
      color: var(--screen-dim);
      font-family: var(--font-mono);
      font-size: 0.75rem;
    }

    .station-strip b {
      color: var(--screen-text);
      font-weight: 400;
    }

    .station-strip__lamp {
      inline-size: 8px;
      block-size: 8px;
      border-radius: 50%;
      background: var(--accent);
      box-shadow: 0 0 8px var(--accent);
    }

    .uplink {
      margin-block-start: 10px;
    }

    .uplink__frame {
      inset: 5px;
    }

    .uplink__bar {
      gap: 12px;
      padding: 12px 16px;
      font-size: 0.6875rem;
      letter-spacing: 0.02em;
      white-space: nowrap;
    }

    .uplink__bar > span:first-child {
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .header-row {
      padding: 12px 16px;
    }

    .header-row__key {
      font-size: 0.75rem;
    }

    .header-row--top .header-row__key {
      padding-block-start: 0;
    }

    .header-row__fixed {
      font-size: 0.9375rem;
    }

    .channels {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
    }

    .channel {
      min-block-size: 44px;
    }

    .uplink__foot {
      flex-direction: column;
      align-items: stretch;
      gap: 14px;
      padding: 16px;
    }

    .uplink__foot .button {
      min-block-size: 48px;
    }

    .uplink__alert {
      padding-inline: 16px;
    }

    .uplink__station {
      display: none;
    }

    .uplink[data-phase="sent"] .uplink__main,
    .uplink[data-phase="sent"] .uplink__station {
      display: contents;
    }

    .uplink[data-phase="sent"] .uplink__bar {
      order: -2;
      border-block-end: 1px solid var(--screen-edge);
    }

    .uplink[data-phase="sent"] .station__globe {
      order: -1;
      inline-size: 230px;
      block-size: 230px;
      margin-block-start: 10px;
    }

    .uplink[data-phase="sent"] .station__rows {
      display: none;
    }

    /* The confirmation doesn't need the invitation to write. */
    .site-main:has(.uplink[data-phase="sent"]) .page-head__lede {
      display: none;
    }

    .tx {
      padding: 18px 16px 20px;
    }

    .hexdump {
      padding: 12px;
      font-size: 0.75rem;
    }

    .hexdump--wide {
      display: none;
    }

    .hexdump--narrow {
      display: grid;
    }

    .tx__summary {
      grid-template-columns: 7ch minmax(0, 1fr);
      font-size: 0.8125rem;
    }

    .contact-privacy {
      margin-block-start: 32px;
    }
  }
}

@layer motion {
  /* ---------------------------------------------------------------- sending, as it plays */

  /* The lamp flashes tx while the packet is out, then settles on delivered. */
  [data-motion="on"] .lamp__state--tx {
    display: inline-flex;
    animation: lamp-tx 2.3s steps(1, end) both;
  }

  [data-motion="on"] .lamp__state--done {
    animation: appear 0.3s ease-out 2.3s both;
  }

  /* The form's rows fold away one after another. */
  [data-motion="on"] .uplink__echo {
    display: block;
  }

  [data-motion="on"] .uplink__echo > * {
    overflow: hidden;
    animation: fold-row 0.32s ease-in both;
  }

  [data-motion="on"] .uplink__echo > :nth-child(2) {
    animation-delay: 70ms;
  }

  [data-motion="on"] .uplink__echo > :nth-child(3) {
    animation-delay: 140ms;
  }

  [data-motion="on"] .uplink__echo > :nth-child(4) {
    animation-delay: 210ms;
  }

  [data-motion="on"] .uplink__echo > :nth-child(5) {
    animation-delay: 280ms;
  }

  /* Then the message goes out as code, line by line. */
  [data-motion="on"] .tx {
    animation: appear 0.3s ease-out 0.55s both;
  }

  [data-motion="on"] .hexdump p {
    overflow: hidden;
    animation: type 0.38s steps(40, end) both;
  }

  [data-motion="on"] .hexdump p:nth-child(1) {
    animation-delay: 0.75s;
  }

  [data-motion="on"] .hexdump p:nth-child(2) {
    animation-delay: 1.1s;
  }

  [data-motion="on"] .hexdump p:nth-child(3) {
    animation-delay: 1.45s;
  }

  [data-motion="on"] .hexdump p:nth-child(4),
  [data-motion="on"] .hexdump--narrow p:nth-child(5) {
    animation-delay: 1.75s;
  }

  [data-motion="on"] .tx__line,
  [data-motion="on"] .tx__summary,
  [data-motion="on"] .tx__again {
    animation: appear 0.25s ease-out both;
  }

  [data-motion="on"] .tx__line--1 {
    animation-delay: 1.9s;
  }

  [data-motion="on"] .tx__line--2 {
    animation-delay: 2.3s;
  }

  [data-motion="on"] .tx__line--3 {
    animation-delay: 2.6s;
  }

  [data-motion="on"] .tx__summary {
    animation-delay: 2.95s;
  }

  [data-motion="on"] .tx__again {
    animation-delay: 3.6s;
  }

  @keyframes lamp-tx {
    0%,
    20%,
    40%,
    60%,
    80% {
      opacity: 1;
    }

    10%,
    30%,
    50%,
    70%,
    90%,
    100% {
      opacity: 0;
    }
  }

  @keyframes fold-row {
    from {
      max-block-size: 320px;
    }

    to {
      max-block-size: 0;
      padding-block: 0;
      border-block-end-width: 0;
      opacity: 0;
    }
  }

  @keyframes type {
    from {
      inline-size: 0;
    }

    to {
      inline-size: 100%;
    }
  }

  @keyframes appear {
    from {
      opacity: 0;
      translate: 0 8px;
    }

    to {
      opacity: 1;
      translate: 0 0;
    }
  }
}
