/* Projects section. Phones get a swipeable row; from 900px up the cards sit on an arc. */
.projects {
  position: relative;
  z-index: 1;
  margin-top: -70px;
  padding: 145px clamp(17px, 7vw, 64px) 40px;
  background: var(--surface);
}

.projects-arc {
  display: flex;
  gap: 14px;
  margin: 44px calc(clamp(17px, 7vw, 64px) * -1) 0;
  padding: 18px clamp(17px, 7vw, 64px) 28px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding-inline: clamp(17px, 7vw, 64px);
  scrollbar-width: none;
}
.projects-arc::-webkit-scrollbar { display: none; }

/* ---------- Card ---------- */
.project-card {
  display: block;
  flex-shrink: 0;
  width: min(62vw, 260px);
  padding: 8px 8px 10px;
  border: 0;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .07);
  scroll-snap-align: start;
  transform: rotate(var(--tilt));
  transition: transform 260ms cubic-bezier(0.23, 1, 0.32, 1), box-shadow 260ms ease;
}
.project-face { display: block; }
.project-media { position: relative; display: block; }
.project-media img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  object-fit: cover;
  object-position: top;
  filter: grayscale(1);
  transition: filter 220ms ease;
}
.project-name {
  display: block;
  margin-top: 10px;
  padding-inline: 2px;
  overflow: hidden;
  font-size: .8125rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-tag {
  display: block;
  margin-top: 1px;
  padding-inline: 2px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: .6875rem;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The full sentence appears when a card opens, and adds to the short tag above it */
.project-more { display: none; }
.project-summary {
  display: block;
  padding-inline: 2px;
  color: var(--ink);
  font-size: .75rem;
  line-height: 1.45;
}

.project-card:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.project-card:focus-visible img { filter: none; }

@media (hover: hover) and (pointer: fine) {
  .project-card:hover { box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 10px 26px rgba(0, 0, 0, .09); }
  .project-card:hover img { filter: none; }
}

/* An open card may reach past this section, so the next one must sit below it */
.services { z-index: 0; }

/* ---------- Arc ---------- */
/* An open card straightens and its neighbours part. On the way back the card settles first and
   changes layer while they are still apart, then they close over it, so nothing pops in front.
   Only translate, rotate and scale animate, so the motion stays off the main thread. */

@media (min-width: 900px) {
  .projects-arc {
    --card-w: clamp(116px, 15vw, 290px);
    --arc-radius: calc(var(--card-w) * 5.4);
    --arc-step: 6.8deg;
    --ease-part: cubic-bezier(0.32, 0.72, 0, 1);
    --ease-slide: cubic-bezier(0.23, 1, 0.32, 1);
    position: relative;
    display: block;
    height: calc(var(--card-w) * 2);
    margin-inline: 0;
    padding: 0;
    overflow: visible;
  }
  .project-card {
    --open: 0;
    --angle: calc(var(--slot) * var(--arc-step) + var(--push, 0deg));
    --arc-x: calc(var(--arc-radius) * sin(var(--angle)));
    --arc-y: calc(var(--arc-radius) * (1 - cos(var(--angle))));
    position: absolute;
    top: 0;
    left: calc(50% - var(--card-w) / 2);
    z-index: var(--layer);
    width: var(--card-w);
    padding: 0;
    background: none;
    box-shadow: none;
    transform: none;
    translate: var(--arc-x) calc(var(--arc-y) - var(--open) * 10px);
    rotate: calc(var(--angle) * (1 - var(--open)));
    scale: calc(1 + var(--open) * .05);
    /* A closing card drops to its own layer at once, while its neighbours are still parted, so it never flips behind one mid-way */
    transition:
      translate 320ms var(--ease-part),
      rotate 320ms var(--ease-part),
      scale 320ms var(--ease-part),
      z-index 0s;
  }
  .project-face {
    position: relative;
    z-index: 1;
    padding: 8px 8px 10px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .07);
    transition: box-shadow 260ms ease;
  }
  /* Titles rest on the side a neighbour does not cover, and slide to their reading side when open */
  .project-text { display: inline-block; }
  .project-name, .project-tag {
    overflow: visible;
    translate: var(--slide, 0px) 0;
    transition: translate 200ms var(--ease-slide);
  }
  .project-more {
    position: absolute;
    top: 100%;
    right: 10px;
    left: 10px;
    z-index: 0;
    display: block;
    margin-top: -14px;
    clip-path: inset(0 -30px -40px -30px);
    pointer-events: none;
  }
  .project-summary {
    display: block;
    margin: 0;
    padding: 22px 10px 12px;
    border-radius: 0 0 14px 14px;
    background: #fff;
    box-shadow: 0 14px 28px rgba(0, 0, 0, .12);
    visibility: hidden;
    translate: 0 -100%;
    transition: translate 170ms var(--ease-slide), visibility 0s linear 170ms;
  }

  .project-card:focus-visible {
    --open: 1;
    z-index: 20;
    transition: translate 300ms var(--ease-part), rotate 300ms var(--ease-part), scale 300ms var(--ease-part), z-index 0s;
  }
  .project-card:focus-visible :is(.project-name, .project-tag) { translate: 0 0; transition-duration: 280ms; }
  .project-card:focus-visible .project-more { pointer-events: auto; }
  .project-card:focus-visible .project-summary {
    visibility: visible;
    translate: 0 0;
    transition: translate 280ms var(--ease-slide) 90ms, visibility 0s;
  }
}

@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .project-card:hover {
    --open: 1;
    z-index: 20;
    box-shadow: none;
    transition: translate 300ms var(--ease-part), rotate 300ms var(--ease-part), scale 300ms var(--ease-part), z-index 0s;
  }
  /* Keeps the card under the cursor while it lifts away from its old place */
  .project-card:hover::after { content: ""; position: absolute; inset: 0 0 -24px; z-index: -1; }
  .project-card:hover .project-face { box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 16px 36px rgba(0, 0, 0, .11); }
  .project-card:hover :is(.project-name, .project-tag) { translate: 0 0; transition-duration: 280ms; }
  .project-card:hover .project-more { pointer-events: auto; }
  .project-card:hover .project-summary {
    visibility: visible;
    translate: 0 0;
    transition: translate 280ms var(--ease-slide) 90ms, visibility 0s;
  }
}

/* A large, very faint word behind the projects heading */
.projects .subtitle { position: relative; isolation: isolate; }
.ghost-word {
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(4rem, 19vw, 8rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.05em;
  opacity: .05;
  pointer-events: none;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
[dir="rtl"] .ghost-word { font-family: "Fatimah", "Thmanyah Sans", sans-serif; font-weight: 900; letter-spacing: 0; }

@media (min-width: 900px) {
  .ghost-word { font-size: calc(var(--u) * 128); }
  .projects {
    margin-top: calc(var(--u) * -90);
    padding: calc(var(--u) * 190) calc(var(--u) * 72) calc(var(--u) * 40);
  }
  .projects .divider { margin-inline: calc(var(--u) * 164); }
  .projects-arc { margin-top: calc(var(--u) * 80); }
}

@media (prefers-reduced-motion: reduce) {
  .project-card, .project-media img, .project-face, .project-name, .project-tag, .project-summary { transition: none !important; }
}
