/*
  Outseam puts the seams of its baby clothes on the outside. The page says the
  same thing with its buttons: each one is a label whose stitching runs outside
  its edge instead of inside it.
*/

@font-face {
  font-family: "Montserrat Alternates";
  src: url("/fonts/montserrat-alternates-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Montserrat Alternates";
  src: url("/fonts/montserrat-alternates-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Paper and sage come from the shop theme; ink is the logo colour. */
  --paper: #eef1ea;
  --cotton: #fbfcf9;
  --ink: #141414;
  --sage: #7faf9a;
  --sage-deep: #73a48e;
  --thread: #8a5a3c;

  --radius: 14px;
  /* How far outside the button edge the seam runs. The stitch <rect rx> in
     index.html is --radius + --seam; change them together. */
  --seam: 7px;

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Montserrat Alternates", ui-rounded, system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

.page {
  max-width: 25.5rem;
  margin: 0 auto;
  padding: clamp(3rem, 11svh, 7rem) 1.5rem 4rem;
}

/* Brand */

.brand {
  text-align: center;
}

.brand-name {
  margin: 0;
  line-height: 0;
}

.logo {
  width: 11.5rem;
  height: auto;
}

.tagline {
  max-width: 17rem;
  margin: 1.5rem auto 0;
  font-size: 1.0625rem;
  text-wrap: balance;
}

/* Links */

.links {
  display: grid;
  gap: calc(1rem + 2 * var(--seam));
  margin: 3rem 0 0;
  padding: 0 var(--seam);
  list-style: none;
}

.link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.75rem;
  padding: 0.875rem 1.375rem;
  /* Transparent until forced-colors mode paints it and gives the button an edge. */
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--cotton);
  color: var(--ink);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, transform 0.15s;
}

.link--primary {
  background: var(--sage);
}

.link:active {
  transform: scale(0.985);
}

.link:focus-visible {
  outline: none;
}

.link-name,
.link-where {
  display: block;
}

.link-name {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
}

.link-where {
  font-size: 0.875rem;
  line-height: 1.45;
  opacity: 0.8;
}

.link-icon {
  flex: none;
  width: 1.625rem;
  height: 1.625rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.link-icon-dot {
  fill: currentColor;
}

/* The seam */

.stitch {
  position: absolute;
  top: calc(-1 * var(--seam) - 1px);
  left: calc(-1 * var(--seam) - 1px);
  width: calc(100% + 2 * var(--seam) + 2px);
  height: calc(100% + 2 * var(--seam) + 2px);
  overflow: visible;
  fill: none;
  pointer-events: none;
}

.stitch-thread {
  stroke: var(--thread);
  stroke-width: 1.75;
  stroke-linecap: round;
  /* The rect carries pathLength="69", so these are fractions of one stitch
     and the pattern always closes evenly where the seam meets itself. */
  stroke-dasharray: 0.48 0.52;
  transition: stroke-dashoffset 0.5s cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* A paper-coloured stroke lying over the thread. It is fully retracted here,
   so without animation the seam is simply there. */
.stitch-cover {
  stroke: var(--paper);
  stroke-width: 5;
  stroke-dasharray: 1 1;
  stroke-dashoffset: -1;
}

/* Keyboard focus: the running stitch closes into a solid ink line. */
.link:focus-visible .stitch-thread {
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-dasharray: none;
}

@media (hover: hover) {
  .link:hover {
    background: #fff;
  }

  .link--primary:hover {
    background: var(--sage-deep);
  }

  /* The thread is pulled through by one stitch. */
  .link:hover .stitch-thread {
    stroke-dashoffset: -1;
  }
}

/* On load each button is sewn on in turn: the cover retreats along the seam. */
@media (prefers-reduced-motion: no-preference) {
  .stitch-cover {
    animation: sew 1.1s cubic-bezier(0.45, 0, 0.2, 1) 0.15s both;
  }

  .links li:nth-child(2) .stitch-cover { animation-delay: 0.4s; }
  .links li:nth-child(3) .stitch-cover { animation-delay: 0.65s; }
  .links li:nth-child(4) .stitch-cover { animation-delay: 0.9s; }
  .links li:nth-child(n + 5) .stitch-cover { animation-delay: 1.15s; }

  @keyframes sew {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -1; }
  }
}

@media (prefers-reduced-motion: reduce) {
  .link,
  .stitch-thread {
    transition: none;
  }
}

@media (forced-colors: active) {
  .link:focus-visible {
    outline: 2px solid;
    outline-offset: 3px;
  }

  .stitch {
    display: none;
  }
}
