/*
 * Manic Millionaire - behaviour styles.
 *
 * styles.css is the compiled design (colours, type, layout) and is left alone.
 * This file holds what the page's script animates, the member link in the
 * header (added after the design was compiled), and at the end the layout
 * repairs the compiled design needs.
 */

/* ---- Entrance animations -------------------------------------------------
 * [data-anim] elements start hidden and offset, then settle when the script
 * adds .is-in. Per-element timing comes from inline custom properties:
 *   --y / --scale   where it starts
 *   --dur / --delay / --ease   how it gets there
 * The .js gate means the page is fully visible if JavaScript never runs.
 */
.js [data-anim] {
  opacity: 0;
  transform: translateY(var(--y, 0px)) scale(var(--scale, 1));
}

.js [data-anim].is-in {
  opacity: 1;
  transform: none;
  transition:
    opacity var(--dur, 0.7s) var(--ease, ease-out) var(--delay, 0s),
    transform var(--dur, 0.7s) var(--ease, ease-out) var(--delay, 0s);
}

/* ---- Floating hat ---------------------------------------------------------
 * Position, tilt and size follow the scroll (site.js); the bob is constant.
 */
.mm-hat-bob {
  animation: mm-hat-bob 3.5s ease-in-out infinite;
}

@keyframes mm-hat-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    /* --mm-bob goes to 0 as the hat lands somewhere (site.js). */
    transform: translateY(calc(-14px * var(--mm-bob, 1)));
  }
}

/* ---- Challenge progress bar ---------------------------------------------- */
[data-progress] {
  transition: width 1.2s cubic-bezier(0, 0, 0.58, 1);
}

/* ---- Mobile menu ----------------------------------------------------------
 * Slides down from the top; links then slide in from the left one by one.
 */
.mm-menu[hidden] {
  display: none;
}

.mm-menu {
  /* On a short phone the links and the foot are taller than the screen. */
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  transform: translateY(-100%);
  transition:
    opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.mm-menu.is-open {
  opacity: 1;
  transform: none;
}

.mm-menu [data-menu-link] {
  opacity: 0;
  transform: translateX(-40px);
}

.mm-menu.is-open [data-menu-link] {
  opacity: 1;
  transform: none;
  transition:
    opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1) calc(0.1s + var(--i, 0) * 0.08s),
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1) calc(0.1s + var(--i, 0) * 0.08s),
    background-color 0.15s;
}

.mm-menu .mm-menu-foot {
  opacity: 0;
  transform: translateY(20px);
}

.mm-menu.is-open .mm-menu-foot {
  opacity: 1;
  transform: none;
  transition:
    opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1) 0.45s,
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1) 0.45s;
}

/* ---- Contact form ---------------------------------------------------------
 * Honeypot field: off-screen for people, present for bots.
 */
.mm-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.mm-success {
  animation: mm-success-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes mm-success-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---- Member link ----------------------------------------------------------
 * "Join free" in the header and the mobile menu; site.js turns it into
 * "Member area" (.is-member, with a dot) for someone who is signed in.
 */
.member-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid #222222;
  background: #ffd701;
  color: #222222;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: -0.025em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background-color 0.2s;
}

.member-link:hover,
.member-link.is-member {
  background: #fff7da;
}

.member-link.is-member::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1f8a3b;
}

.member-link-block {
  display: flex;
  width: 100%;
  padding: 16px 20px;
  font-size: 16px;
  line-height: 24px;
}

.member-link-block.is-member {
  margin-bottom: 12px;
}

.member-signin {
  margin: 10px 0 18px;
  text-align: center;
  font-size: 14px;
}

.member-signin[hidden] {
  display: none;
}

.member-signin a {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (min-width: 640px) {
  .member-link {
    padding: 10px 20px;
  }
}

@media (min-width: 768px) {
  .member-link {
    padding: 12px 24px;
    font-size: 14px;
    line-height: 20px;
  }

  .member-link-block {
    padding: 16px 20px;
  }
}

/* Between the tablet and the desktop width the navigation and two buttons do
 * not fit on one line. The plans button gives way: the navigation's own
 * "Membership" link leads to the same place. (The membership page has one
 * button and room for it, so its button is not marked.) */
@media (min-width: 768px) and (max-width: 1139px) {
  .header-plans {
    display: none;
  }

  .member-link:not(.member-link-block) {
    padding: 12px 14px;
  }

  /* A link that breaks onto two lines makes the whole bar look broken. */
  header nav[class~="md:flex"],
  header a.inline-flex {
    white-space: nowrap;
  }
}

/* The narrowest tablets: the links close up rather than wrap. */
@media (min-width: 768px) and (max-width: 899px) {
  header nav[class~="md:flex"] {
    gap: 1.125rem;
    font-size: 0.8125rem;
  }

  header a.inline-flex {
    padding-inline: 1rem;
  }
}

/* ---- Layout repairs -------------------------------------------------------
 * "For the ones who want a sharper edge": the compiled design puts the
 * headline and the list of services side by side from 768px, but the list
 * needs 535px of its own and ran off the right edge on a tablet held
 * upright. Up to 920px the two stack, as they do on a phone.
 */
@media (min-width: 768px) and (max-width: 919.98px) {
  #work .grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* On the narrowest phones (320px) the longest service name made the same
 * list 10px wider than the screen. */
@media (max-width: 343.98px) {
  #work .grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #work li .font-display {
    font-size: 17px;
  }
}
