/* Contact page as a postcard (custom-contact.hbs). Hand-written, not built by vite.
   Styles the form the proxy renders (gallery-html-rewriter/contact.mjs) only
   inside .dmr-ct, so the plain form elsewhere is untouched. */

.dmr-ct {
  --dmr-ct-paper: hsl(40, 45%, 97%);
  --dmr-ct-ink: hsl(25, 9%, 15%);
  --dmr-ct-soft: hsla(25, 9%, 15%, 0.62);
  --dmr-ct-line: hsla(25, 9%, 15%, 0.28);
  --dmr-ct-rule: hsla(220, 45%, 45%, 0.2);
  --dmr-ct-stamp: hsl(0, 0%, 100%);
  --dmr-ct-blur-opacity: 0.4;
  --dmr-ct-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

[theme-mode="dark"] .dmr-ct {
  --dmr-ct-paper: hsl(30, 7%, 13%);
  --dmr-ct-ink: hsl(38, 25%, 90%);
  --dmr-ct-soft: hsla(38, 25%, 90%, 0.62);
  --dmr-ct-line: hsla(38, 25%, 90%, 0.26);
  --dmr-ct-rule: hsla(215, 50%, 75%, 0.14);
  --dmr-ct-stamp: hsl(38, 20%, 86%);
  --dmr-ct-blur-opacity: 0.5;
}

/* ---- the desk ---- */

.dmr-ct__desk {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: 7.5rem 1rem 4rem;
  overflow: hidden;
  isolation: isolate;
  perspective: 2400px;
}

.dmr-ct__blur {
  position: absolute;
  inset: -3rem;
  z-index: -2;
  background: var(--light-secondary-background) center / cover no-repeat;
  filter: blur(32px) saturate(1.15);
  opacity: var(--dmr-ct-blur-opacity);
}

.dmr-ct__desk::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, var(--background) 0%, transparent 28%, transparent 72%, var(--background) 100%);
  content: '';
}

.dmr-ct__title {
  max-width: 20ch;
  margin: 0 0 2rem;
  font-family: 'Montserrat', var(--gh-font-heading, var(--font-family));
  font-size: clamp(2rem, 7.5vw, 3.75rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--foreground);
  text-align: center;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

/* ---- the card ---- */

.dmr-ct__card {
  display: grid;
  width: 100%;
  max-width: 60rem;
  color: var(--dmr-ct-ink);
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.5, 0, 0.2, 1);
}

.dmr-ct__face {
  grid-area: 1 / 1;
  min-width: 0;
  border-radius: 0.25rem;
  background: var(--dmr-ct-paper);
  box-shadow: 0 1px 0 hsla(0, 0%, 100%, 0.35) inset, 0 30px 70px -28px rgba(0, 0, 0, 0.5), 0 4px 14px -6px rgba(0, 0, 0, 0.2);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.dmr-ct__front {
  display: grid;
  gap: 1.75rem;
  padding: 1.5rem 1.25rem 1.75rem;
}

.dmr-ct__back {
  display: none;
  position: relative;
  overflow: hidden;
  transform: rotateY(180deg);
}

.dmr-ct__card.is-postcard .dmr-ct__back {
  display: block;
}

.dmr-ct__card.is-turned {
  transform: rotateY(180deg);
}

/* The stamp and postmark are transformed, so they would show through the
   back; the front hides halfway through the turn instead. */
.dmr-ct__front {
  transition: visibility 0s 0.45s;
}

.dmr-ct__card.is-turned .dmr-ct__front {
  visibility: hidden;
}

/* ---- message side: the page's text and the message ---- */

.dmr-ct__message.g-post-content {
  margin: 0;
  padding: 0;
  color: var(--dmr-ct-ink);
  font-size: 1rem;
  line-height: 1.6;
}

.dmr-ct__message.g-post-content > * {
  max-width: none;
  margin-inline: 0;
}

.dmr-ct__message.g-post-content > p {
  margin-block: 0 0.875rem;
}

.dmr-ct__message.g-post-content > p:last-child {
  margin: 1rem 0 0;
  color: var(--dmr-ct-soft);
  font-style: italic;
}

.dmr-ct__message a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--dmr-ct-line);
  text-underline-offset: 0.2em;
}

.dmr-ct .dmr-contact {
  margin: 1.25rem 0 0;
}

.dmr-ct .dmr-contact__field {
  gap: 0.375rem;
  color: var(--dmr-ct-soft);
}

.dmr-ct .dmr-contact__field > span {
  font: 600 0.6875rem/1.2 var(--dmr-ct-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* The message is written on ruled lines that scroll with the text. */
.dmr-ct .dmr-contact__field textarea {
  min-height: 12rem;
  padding: 0 0.125rem;
  color: var(--dmr-ct-ink);
  font-size: 1.0625rem;
  line-height: 2rem;
  background: transparent repeating-linear-gradient(180deg, transparent 0 calc(2rem - 1px), var(--dmr-ct-rule) calc(2rem - 1px) 2rem);
  background-attachment: local;
  border: 0;
  border-radius: 0;
}

.dmr-ct .dmr-contact__field textarea:focus {
  box-shadow: none;
  outline: 2px solid var(--dmr-ct-line);
  outline-offset: 0.375rem;
}

/* ---- address side: stamp, postmark, recipient, sender ---- */

.dmr-ct__address {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    'mark stamp'
    'to to'
    'fields fields';
  align-content: start;
  gap: 1rem 0.75rem;
  padding-top: 1.75rem;
  border-top: 1px dashed var(--dmr-ct-line);
}

.dmr-ct__stamp {
  grid-area: stamp;
  justify-self: end;
  width: 5.5rem;
  padding: 0.25rem;
  background: var(--dmr-ct-stamp);
  transform: rotate(2deg);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    radial-gradient(circle at center, transparent 0.17rem, #000 0.19rem) -0.25rem -0.25rem / 0.5rem 0.5rem round;
  mask:
    linear-gradient(#000 0 0) content-box,
    radial-gradient(circle at center, transparent 0.17rem, #000 0.19rem) -0.25rem -0.25rem / 0.5rem 0.5rem round;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15));
}

.dmr-ct__stamp span {
  display: block;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: var(--light-secondary-background);
}

.dmr-ct__stamp img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dmr-ct__card:not(.is-postcard) .dmr-ct__stamp {
  display: none;
}

.dmr-ct__postmark {
  position: relative;
  grid-area: mark;
  align-self: center;
  justify-self: end;
  width: 6.25rem;
  height: 6.25rem;
  margin-inline-end: -2.25rem;
  color: var(--dmr-ct-ink);
  opacity: 0.55;
  transform: rotate(-14deg);
  pointer-events: none;
  z-index: 1;
}

.dmr-ct__postmark svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dmr-ct__postmark circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
}

.dmr-ct__postmark text {
  fill: currentColor;
  font: 600 8.5px var(--dmr-ct-mono);
  letter-spacing: 1.6px;
}

.dmr-ct__date {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.75rem;
  font: 600 0.625rem/1.15 var(--dmr-ct-mono);
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
}

.dmr-ct__to {
  grid-area: to;
  margin: 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--dmr-ct-line);
  font-size: 1.125rem;
  line-height: 1.4;
}

.dmr-ct__to-label {
  margin-inline-end: 0.5rem;
  color: var(--dmr-ct-soft);
  font: 600 0.6875rem/1 var(--dmr-ct-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Spaced capitals break Arabic letter joining. */
[dir="rtl"] .dmr-ct .dmr-contact__field > span,
[dir="rtl"] .dmr-ct__to-label {
  letter-spacing: 0;
}

.dmr-ct__fields {
  grid-area: fields;
  display: grid;
  gap: 1.25rem;
}

.dmr-ct .dmr-contact__field input {
  padding: 0.5rem 0.125rem;
  color: var(--dmr-ct-ink);
  font-size: 1.0625rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--dmr-ct-line);
  border-radius: 0;
}

.dmr-ct .dmr-contact__field input:focus {
  border-bottom-color: var(--dmr-ct-ink);
  box-shadow: 0 1px 0 var(--dmr-ct-ink);
}

.dmr-ct .dmr-contact__send {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding: 0.875rem 1.75rem;
  color: var(--dmr-ct-paper);
  background: var(--dmr-ct-ink);
  border-radius: 999px;
}

.dmr-ct .dmr-contact__send::after {
  font-size: 1.1em;
  line-height: 1;
  content: '→';
}

[dir="rtl"] .dmr-ct .dmr-contact__send::after {
  content: '←';
}

.dmr-ct .dmr-contact__note {
  color: var(--dmr-ct-soft);
}

/* The card shows its own thank-you on the back. */
.dmr-ct__card.is-postcard .dmr-contact__done {
  display: none !important;
}

.dmr-ct__card.is-postcard .dmr-contact.is-sent .dmr-contact__form {
  display: grid;
}

.dmr-ct .dmr-contact__failed {
  color: var(--dmr-ct-ink);
  background: transparent;
  border-color: var(--dmr-ct-line);
}

/* ---- back of the card ---- */

.dmr-ct__back-photo,
.dmr-ct__back-photo img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dmr-ct__back-photo {
  background: var(--light-secondary-background);
}

.dmr-ct__back-photo::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.72) 100%);
  content: '';
}

/* On phones the card is tall, so the thank-you sits at the top, in view. */
.dmr-ct__back-note {
  position: absolute;
  inset-inline: 1.5rem;
  top: 1.5rem;
  margin: 0;
  color: hsl(0, 0%, 100%);
  font-family: 'Montserrat', var(--gh-font-heading, var(--font-family));
  font-size: clamp(1.375rem, 4.5vw, 2.25rem);
  font-weight: bold;
  line-height: 1.15;
  text-wrap: balance;
}

.dmr-ct__back-note:focus {
  outline: none;
}

@media (min-width: 45rem) {
  .dmr-ct__desk {
    padding: 9rem 2.5rem 6rem;
  }

  .dmr-ct__front {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 0;
    padding: 2.25rem 2.25rem 2.5rem;
  }

  .dmr-ct__message.g-post-content {
    padding-inline-end: 2.25rem;
  }

  .dmr-ct__address {
    padding-top: 0;
    padding-inline-start: 2.25rem;
    border-top: 0;
    border-inline-start: 1px solid var(--dmr-ct-line);
  }

  .dmr-ct__to {
    margin-top: 1.5rem;
  }

  .dmr-ct__stamp {
    width: 6.5rem;
  }

  .dmr-ct__back-photo::after {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0) 40%, rgba(0, 0, 0, 0.72) 100%);
  }

  .dmr-ct__back-note {
    top: auto;
    bottom: 1.75rem;
    inset-inline: 2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dmr-ct__card,
  .dmr-ct__front {
    transition: none;
  }
}
