/* ============================================
   Mail slot — the email link as a tiny letterbox
   Çilingir means locksmith, the theme toggle is a door,
   so contact is a letter slot in that door.

   Rest   → a small door plate with a slot.
   Hover  → a letter drifts over the slot, the flap starts to lift.
   Click  → the letter is pushed through, the flap swings in and
            clacks shut, the address is copied and the mail app opens.

   Markup: see index.html (About copy). Works as a plain mailto
   link without JS. States set by assets/js/mail-slot.js:
   .is-posting, .is-from-hover, .is-flap-open, .is-posted
   ============================================ */

.mail-slot {
  --ms-ease: var(--ease-entrance);
  --ms-hover-pose: translateY(0.18em) scale(1.9) rotate(-4deg);
  position: relative;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mail-slot:focus-visible {
  outline: 1px solid var(--color-text-primary);
  outline-offset: 2px;
}

/* ---------- The plate (sits where the flag emoji sits in the place chips) ---------- */

.mail-slot__box {
  position: relative;
  flex: none;
  display: inline-block;
  width: 1.5em;
  height: 0.9em;
  /* Lift onto the cap height like an emoji */
  vertical-align: -0.05em;
}

.mail-slot__plate {
  position: absolute;
  inset: 0;
  background-color: var(--color-door-plate);
  background-image: linear-gradient(180deg,
    color-mix(in srgb, #fff 16%, transparent) 0%,
    transparent 45%,
    color-mix(in srgb, #000 16%, transparent) 100%);
  box-shadow: inset 0 0 0 1px var(--color-door-plate-edge);
}

/* Two screws */
.mail-slot__plate::before,
.mail-slot__plate::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0.1em;
  height: 0.1em;
  margin-top: -0.05em;
  border-radius: 50%;
  background-color: var(--color-mocha-2);
  opacity: 0.8;
}

.mail-slot__plate::before { left: 0.12em; }
.mail-slot__plate::after  { right: 0.12em; }

.mail-slot__slot,
.mail-slot__flap {
  position: absolute;
  left: 0.32em;
  right: 0.32em;
  top: 0.36em;
  height: 0.16em;
}

.mail-slot__slot {
  background-color: var(--color-door-slot);
}

.mail-slot__flap {
  z-index: 2;
  top: 0.33em;
  height: 0.22em;
  background-color: var(--color-door-plate);
  background-image: linear-gradient(180deg,
    color-mix(in srgb, #fff 30%, transparent) 0%,
    transparent 40%,
    color-mix(in srgb, #000 22%, transparent) 100%);
  transform-origin: 50% 0;
  transition: transform 0.35s var(--ms-ease);
}

/* ---------- The letter ----------
   The peek window's bottom edge is the slot line, so anything
   pushed below it disappears into the door. */

.mail-slot__peek {
  position: absolute;
  /* In front of the flap: the letter pushes it in */
  z-index: 3;
  left: 50%;
  bottom: calc(100% - 0.42em);
  width: 3em;
  height: 2em;
  transform: translateX(-50%);
  overflow: hidden;
  pointer-events: none;
}

.mail-slot__letter {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0.8em;
  height: 0.54em;
  margin-left: -0.4em;
  /* Envelope: paper, flap V, a hint of stamp */
  background-color: var(--color-paper);
  background-image:
    linear-gradient(to bottom right, transparent calc(50% - 0.5px), var(--color-paper-rule) 50%, transparent calc(50% + 0.5px)),
    linear-gradient(to bottom left, transparent calc(50% - 0.5px), var(--color-paper-rule) 50%, transparent calc(50% + 0.5px)),
    linear-gradient(var(--color-mocha-4), var(--color-mocha-4));
  background-size: 50% 62%, 50% 62%, 0.12em 0.12em;
  background-position: left top, right top, calc(100% - 0.06em) 0.06em;
  background-repeat: no-repeat;
  box-shadow:
    inset 0 0 0 0.5px var(--color-paper-rule),
    0 0.08em 0.18em var(--color-paper-shadow);
  transform-origin: 50% 100%;
  transform: translateY(-0.5em) scale(1.9) rotate(-10deg);
  opacity: 0;
  transition:
    transform 0.45s var(--ms-ease),
    opacity 0.2s var(--ease-standard);
}

/* ---------- Labels: address ↔ confirmation, same box, crossfade ---------- */

.mail-slot__labels {
  display: inline-grid;
}

.mail-slot__label {
  grid-area: 1 / 1;
  transition:
    opacity 0.28s var(--ms-ease),
    filter 0.28s var(--ms-ease),
    transform 0.28s var(--ms-ease);
}

.mail-slot__label--done {
  opacity: 0;
  filter: blur(var(--blur-sm));
  transform: translateY(0.3em);
}

.mail-slot.is-posted .mail-slot__label--idle {
  opacity: 0;
  filter: blur(var(--blur-sm));
  transform: translateY(-0.3em);
}

.mail-slot.is-posted .mail-slot__label--done {
  opacity: 1;
  filter: blur(0);
  transform: translateY(0);
}

/* ---------- Hover: the letter drifts in, the flap notices ---------- */

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .mail-slot:hover:not(.is-posting):not(.is-posted) .mail-slot__letter,
  .mail-slot:focus-visible:not(.is-posting):not(.is-posted) .mail-slot__letter {
    opacity: 1;
    transform: var(--ms-hover-pose);
    animation: mail-slot-hover 2.4s 0.45s ease-in-out infinite;
  }

  .mail-slot:hover:not(.is-posted) .mail-slot__flap,
  .mail-slot:focus-visible:not(.is-posted) .mail-slot__flap {
    transform: scaleY(0.2);
  }
}

@keyframes mail-slot-hover {
  0%, 100% { transform: var(--ms-hover-pose); }
  50%      { transform: translateY(0.06em) scale(1.9) rotate(-2deg); }
}

/* ---------- Click: push it through ---------- */

.mail-slot.is-posting .mail-slot__letter {
  opacity: 1;
  animation: mail-slot-post 0.75s var(--ease-standard) forwards;
}

.mail-slot.is-posting.is-from-hover .mail-slot__letter {
  animation-name: mail-slot-post-from-hover;
  animation-duration: 0.55s;
}

@keyframes mail-slot-post {
  0%   { opacity: 0; transform: translateY(-0.5em) scale(1.9) rotate(-10deg); }
  30%  { opacity: 1; transform: var(--ms-hover-pose); }
  62%  { opacity: 1; transform: translateY(0.1em) scale(1.3) rotate(0deg); animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); }
  100% { opacity: 1; transform: translateY(110%) scale(1) rotate(0deg); }
}

@keyframes mail-slot-post-from-hover {
  0%   { transform: var(--ms-hover-pose); }
  48%  { transform: translateY(0.1em) scale(1.3) rotate(0deg); animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); }
  100% { transform: translateY(110%) scale(1) rotate(0deg); }
}

.mail-slot.is-flap-open .mail-slot__flap {
  transform: scaleY(0.12);
  transition-duration: 0.12s;
}

/* Flap clacks shut, the plate takes the knock */
.mail-slot.is-posted .mail-slot__flap {
  animation: mail-slot-clack 0.5s var(--ease-standard);
}

.mail-slot.is-posted .mail-slot__box {
  animation: mail-slot-knock 0.35s var(--ease-standard);
}

@keyframes mail-slot-clack {
  0%   { transform: scaleY(0.12); }
  40%  { transform: scaleY(1.15); }
  65%  { transform: scaleY(0.8); }
  100% { transform: scaleY(1); }
}

@keyframes mail-slot-knock {
  0%, 100% { transform: translateY(0); }
  35%      { transform: translateY(0.06em); }
}

/* ---------- Reduced motion: no flight, just the label swap ---------- */

@media (prefers-reduced-motion: reduce) {
  .mail-slot__letter,
  .mail-slot__flap,
  .mail-slot__label {
    transition: none;
  }

  .mail-slot .mail-slot__letter,
  .mail-slot.is-posting .mail-slot__letter,
  .mail-slot.is-posted .mail-slot__flap,
  .mail-slot.is-posted .mail-slot__box {
    animation: none;
    opacity: 0;
  }
}

/* Once it's through, it stays gone until the slot resets (no fly-back) */
.mail-slot.is-posted .mail-slot__letter {
  transition: none;
  opacity: 0;
}
