/********************
 * GLOBAL VARIABLES *
 ********************/

:root {
  /* viewport */
  --vh: 100vh;
  --cw: 100vw;

  /* Base unit */
  /* width has a floor so short viewports don't shrink the stage by height alone */
  --u: calc(min(0.9 * var(--cw) + 580px,
        1400px,
        max(var(--vh) * 14 / 11, 0.72 * var(--cw), 1120px - 2 * (var(--cw) - 600px))) / 1728);

  /* stage */
  --stage-w: calc(1728 * var(--u));
  --rise: clamp(0px, calc((1100px - var(--vh)) * 0.45), calc(160 * var(--u)));
  /* Keep the left anchor until the content and its right margin no longer fit. */
  --side-space: clamp(170 * var(--u), var(--cw) - 900 * var(--u), 320 * var(--u));
  --intro-left: var(--side-space);

  /* truss */
  --truss: calc(170 * var(--u));

  /* navigation */
  --nav-left: calc(var(--side-space) + 234 * var(--u));
  --nav-gap: calc(12 * var(--u));
  --cards-h: calc(126 * var(--u) + var(--rise) / 3);

  --corner-radius: 8px;
  --header-gap: max(16px, calc(32 * var(--u)));
  --divider: rgb(26 26 26 / .14);

  /* colours */
  --green: #c6ffb2;
  --pink: #ff4587;
  --orange: #ffa245;
  --ink: #1a1a1a;
  --paper: #f3f3f3;
  --card: #fff;
}

@supports (height: 100svh) and (width: 100cqw) {
  :root {
    --vh: 100svh;
    --cw: 100cqw;
  }
}

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

html {
  --glow-color: var(--paper);
  --glow-opacity: 0;
  scroll-behavior: smooth;

  /* Safari paints its rubber-band area from the root background. */
  background: url("assets/noise.svg") 0 0 / 240px 240px, var(--paper);
  background-color: color-mix(in srgb, var(--glow-color) calc(var(--glow-opacity) * 100%), var(--paper));
  transition: background-color .4s ease;
}


/*************
 * Main body *
 *************/

body {
  /* presence */
  margin: 0;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  container-type: inline-size;

  /* font */
  font-family: Rubik, system-ui, -apple-system,
    "Segoe UI", Roboto, sans-serif;
  font-weight: 400;
  /* Rubik's x-height ratio. If the webfont fails to load, this keeps
     any fallback face at the same optical size, so the plank copy doesn't
     swell and crowd its plank. No-op when Rubik itself is used. */
  font-size-adjust: 0.52;
  color: var(--ink);

  /* background */
  background: url("assets/noise.svg") 0 0 / 240px 240px, var(--paper);
}


/**************
 * Main stage *
 **************/

.stage {
  position: relative;
  width: min(100%, var(--stage-w));

  /* Full viewport height, with clearance and rubble below. */
  height: calc(max(1350 * var(--u) - var(--rise), var(--vh)) + 630 * var(--u));

  /* clip planks at the edges */
  overflow: hidden;

  /* fade out at the bottom so overscroll has no hard edge */
  mask-image: linear-gradient(to top, transparent, #000 calc(40 * var(--u)));
}


/**********
 * Planks *
 **********/

.plank {
  /* presence */
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(80 * var(--u));
  letter-spacing: calc(1 * var(--u));
  line-height: 1.2;

  /* colour */
  background-color: var(--plank-color);
}

.plank--green {
  --plank-color: var(--green);
  width: calc(270 * var(--u));

}

.plank--pink {
  --plank-color: var(--pink);
  width: calc(440 * var(--u));

}

.plank--orange {
  --plank-color: var(--orange);
  width: calc(540 * var(--u));

}


/***********************
 * Scaffolding trusses *
 ***********************/

.trusses {
  /* presence */
  position: absolute;
  left: var(--side-space);
  width: calc(220 * var(--u));
  top: calc(500 * var(--u) - var(--rise));
  bottom: 0;
  isolation: isolate;
  pointer-events: none;
}

.truss-frame {
  position: absolute;
  inset: 0;
  z-index: 1;

  /* background */
  background: url("assets/tower.svg") left top / 100% var(--truss) repeat-y;
  filter: drop-shadow(0 0 1px black);
}

.truss-ribbon {
  position: absolute;
  left: calc(-40 * var(--u));
  top: 0;
  width: calc(300 * var(--u));
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 0 calc(2 * var(--u)) color-mix(in srgb, var(--ribbon-color) 35%, transparent));
}

.truss-ribbon--back {
  z-index: 0;
}

.truss-ribbon--front {
  z-index: 2;
}


/****************
 * Intro planks *
 ****************/

.intro-planks .plank {
  z-index: 1;
  margin: 0;

  /* font */
  font-size: inherit;
  font-weight: 400;
  font-size: calc(24 * var(--u));

  /* background */
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-blend-mode: overlay;

  /* glow */
  box-shadow: 0 0 calc(6 * var(--u)) calc(2 * var(--u)) var(--plank-color);
}

.pronunciation {
  position: relative;
  cursor: help;
}

.pronunciation::after {
  content: "";
  position: absolute;
  left: -.06em;
  right: -.06em;
  bottom: -.34em;
  height: .6em;
  pointer-events: none;
  background: url("assets/grain-pink.png") center / 200px, var(--pink);
  background-blend-mode: overlay;
  mask: url("assets/underline.svg") center / 100% 100% no-repeat;
}

.pronunciation [role="tooltip"] {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  text-decoration: none;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: var(--corner-radius);
  background: var(--paper);
  box-shadow: 0 2px 6px rgb(0 0 0 / .15);
  font-size: 14px;
  line-height: 1.4;
  white-space: nowrap;
  transition: opacity .2s ease, visibility 0s linear .2s;
}

.pronunciation:hover [role="tooltip"],
.pronunciation:focus [role="tooltip"] {
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}

.intro-planks .plank--green {
  /* background */
  background-image: url("assets/grain-green.png");

  /* presence */
  left: calc(var(--intro-left) + 10 * var(--u));
  top: calc(260 * var(--u) - var(--rise));
}

.intro-planks .plank--pink {
  /* background */
  background-image: url("assets/grain-pink.png");
  background-position: 50% 25%;

  /* presence */
  left: calc(var(--intro-left) + 70 * var(--u));
  top: calc(340 * var(--u) - var(--rise));
}

.intro-planks .plank--orange {
  /* background */
  background-image: url("assets/grain-orange.png");
  background-position: 50% 25%;
  background-blend-mode: soft-light;

  /* presence */
  left: calc(var(--intro-left) - 150 * var(--u));
  top: calc(420 * var(--u) - var(--rise));
}

/**************
 * Navigation *
 **************/

.nav>a,
.to-contact,
.link {
  text-transform: capitalize;
  text-decoration: none;
  color: var(--ink);
}

.nav>a,
.to-contact {
  /* presence */
  position: relative;
  display: flex;
  align-items: center;

  /* font */
  font-size: calc(24 * var(--u));
  letter-spacing: calc(1 * var(--u));
  line-height: 1.2;
}

.nav {
  /* presence */
  position: absolute;
  left: var(--nav-left);
  right: 0;
  top: calc(550 * var(--u) - var(--rise));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.nav>a {
  flex: none;
  align-items: baseline;
  height: calc(44 * var(--u));
  margin-bottom: calc(5 * var(--u));
}

.nav-see-all {
  margin-left: .25em;
  font-size: .65em;
  color: #737478;
  letter-spacing: 0;
  text-transform: none;
}

/* hover */
.nav>a,
.link,
.card-pages button {
  transition: translate .35s ease, font-weight .35s ease, background-color .3s ease;
}

.nav>a:is(:hover, :focus-visible),
.link:is(:hover, :focus-visible),
.card-pages button:is(:hover, :focus-visible) {
  translate: 0 calc(-1 * var(--u));
}

.nav>a:is(:hover, :focus-visible),
.link:is(:hover, :focus-visible),
.page-home:is(:hover, :focus-visible),
.explorer-home:is(:hover, :focus-visible) {
  font-weight: 500;
}

.card,
.card-pages button,
.to-contact,
.contact-icons,
.contact-icons a,
.page-home,
.explorer-home,
.explorer button,
.explorer select,
.explorer textarea,
.explorer-selection,
.explorer-winner,
.explorer-link {
  border-radius: var(--corner-radius);
}

/* Shared home button and top bar. */
.page-home,
.explorer-home {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 36px;
  padding: 0 14px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 1px;
  line-height: 1.4;
  text-decoration: none;
  background: url("/assets/grain-green.png") center / cover, var(--green);
  background-blend-mode: overlay;
  transition: font-weight .35s ease;
}

.index-header,
.explorer-bar {
  position: relative;
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 var(--header-gap);
}

.index-header::after,
.explorer-bar::after {
  content: "";
  position: absolute;
  left: var(--header-gap);
  right: var(--header-gap);
  bottom: 0;
  border-bottom: 1px solid var(--divider);
}

.index-title,
.explorer-title {
  margin: 0 0 0 16px;
  padding: 0 16px;
  border-left: 1px solid var(--divider);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 1px;
  line-height: 1.4;
}

/* extends the hover area down to the cards so the glow stays on */
.nav>a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: calc(8 * var(--u));
}

/* hover glow along the top edge, in the hovered section's colour */
body::before {
  /* presence */
  content: "";
  position: fixed;
  top: calc(-120 * var(--u));
  left: 0;
  right: 0;
  height: calc(520 * var(--u));
  pointer-events: none;

  /* fade and grain */
  mask-image: radial-gradient(120% 100% at 50% 0, #000, transparent 72%);
  background-image: url("assets/noise.svg");
  background-size: 240px 240px;
  background-color: var(--glow-color);

  /* motion */
  opacity: var(--glow-opacity);
  transition: opacity .4s ease, background-color .4s ease;
}

/* each carries its own strength — green is pale against paper, pink is not */
html:has(.nav-projects:is(:hover, :focus-visible),
  .nav-projects + .card-gallery:is(:hover, :focus-within)) {
  --glow-color: var(--green);
  --glow-opacity: .9;
}

html:has(.nav-work:is(:hover, :focus-visible),
  .nav-work + .card-gallery:is(:hover, :focus-within)) {
  --glow-color: var(--pink);
  --glow-opacity: .4;
}

html:has(.nav-articles:is(:hover, :focus-visible),
  .nav-articles + .card-gallery:is(:hover, :focus-within)) {
  --glow-color: var(--orange);
  --glow-opacity: .42;
}


/*****************
 * Project cards *
 *****************/

.card-gallery {
  position: relative;
  width: min(calc(547 * var(--u)), 100%);
  height: var(--cards-h);
  margin-bottom: var(--nav-gap);
}

.card-row {
  --bleed: clamp(0px, calc(547 * var(--u) - 100%), calc(234 * var(--u)));
  --fade: calc(12 * var(--u));

  /* presence */
  position: relative;
  top: calc(-12 * var(--u));
  height: calc(100% - 28 * var(--u));
  width: calc(100% - 24 * var(--u) + 2 * var(--fade) + var(--bleed));
  margin-left: calc(-1 * var(--fade) - var(--bleed));
  display: flex;
  align-items: stretch;
  gap: calc(24 * var(--u));
  padding: calc(12 * var(--u)) var(--fade);

  mask-image: linear-gradient(to right,
      transparent 0,
      #000 var(--fade),
      #000 calc(100% - var(--fade)),
      transparent 100%);

  /* scroll */
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scroll-padding-left: var(--fade);
  scrollbar-width: none;
}

.card-pages {
  position: absolute;
  bottom: calc(12 * var(--u));
  left: calc(12 * var(--u));
  display: flex;
  gap: calc(4 * var(--u));
}

.card-pages button {
  --corner-radius: calc(3 * var(--u));
  width: calc(15 * var(--u));
  height: calc(15 * var(--u));
  padding: 0;
  border: 0;
  background: #e5e5e5;
  cursor: default;
}

.card-gallery[data-source="/projects/index.html"] .card-pages button {
  rotate: var(--selector-rotation, 0deg);
}

.card-gallery[data-source="/projects/index.html"] .card-pages button:is([aria-current="true"], :hover, :focus-visible) {
  background: var(--selector-color, #b1b2b5);
}

.card-pages button[aria-current="true"],
.card-pages button:is(:hover, :focus-visible) {
  background: #b1b2b5;
}

.card {
  /* presence */
  position: relative;
  flex: none;
  width: min(calc(523 * var(--u)), 100%);
  min-height: calc(84 * var(--u));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) calc(24 * var(--u));
  gap: calc(6 * var(--u)) calc(24 * var(--u));
  padding: calc(12 * var(--u)) calc(24 * var(--u));
  scroll-snap-align: start;
  scroll-snap-stop: always;

  /* colour */
  background: #fbfbfb;
  box-shadow: 0 calc(2 * var(--u)) calc(6 * var(--u)) rgb(0 0 0 / .08);
  color: var(--ink);

  /* motion */
  transition: background-color .3s ease;
}

.card:has(a):is(:hover, :focus-within),
.to-contact:is(:hover, :focus-visible),
.contact-icons a:is(:hover, :focus-visible) {
  background: #e5e5e5;
}

.card-main {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.gallery-image {
  display: none;
}

.card-icons a {
  position: relative;
}

.card-meta {
  display: flex;
  align-items: baseline;
  gap: calc(20 * var(--u));
  min-width: 0;
  font-size: calc(20 * var(--u));
  letter-spacing: calc(1 * var(--u));
}

.card-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-transform: none;
}

.card-date {
  flex: none;
  font-size: calc(16 * var(--u));
  opacity: .5;
}

.card-description {
  grid-column: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: calc(17 * var(--u));
  line-height: 1.4;
  text-transform: none;
}

.card-icons {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  align-items: center;
  gap: calc(14 * var(--u));
}

.card-icon {
  display: block;
  width: calc(28 * var(--u));
  height: calc(28 * var(--u));
}


/******************
 * Contact button *
 ******************/

/* pinned to the stage's corner */
.to-contact {
  position: fixed;
  right: calc((var(--cw) - min(var(--cw), var(--stage-w))) / 2 + max(16px, calc(44 * var(--u))));
  bottom: max(16px, calc(44 * var(--u)));
  z-index: 10;
  padding: calc(6 * var(--u)) calc(16 * var(--u));
  background: url("assets/noise.svg") 0 0 / 240px 240px fixed, var(--paper);
  transition: background-color .3s ease, opacity .3s ease;
}

.contact-icons {
  position: fixed;
  right: max(16px, calc(44 * var(--u)));
  bottom: max(16px, calc(44 * var(--u)));
  z-index: 10;
  display: none;
  padding: 4px;
  background: url("assets/noise.svg") 0 0 / 240px 240px fixed, var(--paper);
}

.contact-icons a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  transition: background-color .3s ease;
}

.contact-icons img {
  width: 22px;
  height: 22px;
}

/* Only contact visibility switches; the layout keeps its continuous scale.
   Below 780px the phone scale crops the pile; elsewhere its fit follows height. */
@media (max-width: 780px),
(max-width: 1400px) and (max-aspect-ratio: 14/11) {

  .to-contact {
    display: none;
  }

  .rubble .link {
    color: transparent;
    pointer-events: none;
  }

  .contact-icons {
    display: flex;
  }
}

/* the script drops this on the button once the rubble is in view */
.hidden {
  opacity: 0;
  transform: translateY(calc(10 * var(--u)));
  pointer-events: none;
}


/**********
 * Rubble *
 **********/

/* anchored to the bottom of the page */
.rubble {
  /* presence */
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(460 * var(--u));

  /* it spans the full width — don't eat clicks */
  pointer-events: none;

  /* keeps the layering below contained */
  isolation: isolate;
}

/* crop the pile evenly on both sides */
.pile,
.rubble .links {
  position: absolute;
  left: calc((100% - var(--stage-w)) / 2);
  bottom: 0;
  width: var(--stage-w);
  height: 100%;
}

/* Rubble planks */

.pile .plank:nth-child(1) {
  left: calc(1244 * var(--u));
  bottom: calc(127 * var(--u));
  transform: rotate(-42deg);
}

.pile .plank:nth-child(2) {
  left: calc(42 * var(--u));
  bottom: calc(127 * var(--u));
  transform: rotate(-21deg);
}

.pile .plank:nth-child(3) {
  left: calc(315 * var(--u));
  bottom: calc(152 * var(--u));
  transform: rotate(1deg);
}

.pile .plank:nth-child(4) {
  left: calc(597 * var(--u));
  bottom: 0;
}

.pile .plank:nth-child(5) {
  left: calc(914 * var(--u));
  bottom: 0;
}

.pile .plank:nth-child(6) {
  left: calc(1260 * var(--u));
  bottom: calc(-6 * var(--u));
}

.pile .plank:nth-child(7) {
  left: calc(1535 * var(--u));
  bottom: calc(65 * var(--u));
  transform: rotate(91deg);
}

.pile .plank:nth-child(8) {
  left: calc(258 * var(--u));
  bottom: calc(80 * var(--u));
}

.pile .plank:nth-child(9) {
  left: calc(994 * var(--u));
  bottom: calc(160 * var(--u));
  transform: rotate(80deg);
}

.pile .plank:nth-child(10) {
  left: calc(131 * var(--u));
  bottom: calc(250 * var(--u));
  transform: rotate(5deg);
}

.pile .plank:nth-child(11) {
  left: 0;
  bottom: 0;
}

.pile .plank:nth-child(12) {
  left: calc(640 * var(--u));
  bottom: calc(122 * var(--u));
  transform: rotate(10deg);
}

.pile .plank:nth-child(13) {
  left: calc(700 * var(--u));
  bottom: calc(200 * var(--u));
  transform: rotate(10deg);

  /* font */
  font-size: calc(24 * var(--u));

  /* background */
  background-image: url("assets/grain-pink.png");
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-blend-mode: overlay;

  /* glow */
  box-shadow: 0 0 calc(6 * var(--u)) calc(2 * var(--u)) var(--plank-color);
}

.link--twitter,
.link--linkedin {
  z-index: 2;
}

.link--github,
.link--email {
  z-index: 4;
}


/*****************
 * Contact links *
 *****************/

.links {
  pointer-events: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: calc(24 * var(--u));
}

/* geometry from the .penpot file, same source as the pile above */
.link--twitter {
  left: calc(1272.3 * var(--u));
  bottom: calc(337.7 * var(--u));
  transform: rotate(-9.2deg);
}

.link--github {
  left: calc(1252 * var(--u));
  bottom: calc(225 * var(--u));
}

.link--email {
  left: calc(1242 * var(--u));
  bottom: calc(146 * var(--u));
}

.link--linkedin {
  left: calc(1284.3 * var(--u));
  bottom: calc(71.2 * var(--u));
  transform: rotate(-0.47deg);
}


/******************
 * Reduced motion *
 ******************/

@media (prefers-reduced-motion: reduce) {

  html,
  .card-row {
    scroll-behavior: auto;
  }

  .nav>a,
  .link,
  .page-home,
  .explorer-home,
  .card,
  .card-pages button,
  .contact-icons a,
  .to-contact,
  .pronunciation [role="tooltip"] {
    transition: none;
  }
}

/************
 * Subpages *
 ************/

.page-header {
  display: flex;
  align-items: center;
  gap: max(16px, calc(40 * var(--u)));
  margin-bottom: max(24px, calc(48 * var(--u)));
}

.project {
  width: min(100%, 1600px);
  padding: calc(60 * var(--u)) calc(80 * var(--u)) calc(160 * var(--u));
  font-size: max(16px, calc(24 * var(--u)));
  line-height: 1.5;
}

.project a {
  color: var(--ink);
  text-decoration: none;
}

.project-repo:hover,
.project-repo:focus-visible,
.project-link:hover,
.project-link:focus-visible {
  text-decoration: underline;
}

.project-name {
  margin: 0;
  font-size: max(32px, calc(72 * var(--u)));
  font-weight: 600;
  line-height: 1.1;
}

.project-date {
  margin: calc(8 * var(--u)) 0 0;
  opacity: .7;
}

.project-blurb {
  margin: calc(32 * var(--u)) 0 0;
  max-width: 60ch;
}

.project-repo {
  display: inline-flex;
  align-items: center;
  height: calc(80 * var(--u));
  min-height: 44px;
  margin: calc(48 * var(--u)) 0 0;
  padding: 0 calc(28 * var(--u));
  background: var(--green);
  text-transform: capitalize;
}

/* Section indexes fill the viewport; their cards can grow with the text. */
.project-index {
  width: 100%;
  min-height: var(--vh);
  padding: 0;
}

.project-list {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 24px var(--header-gap);
}

.project-list .card {
  width: 100%;
  min-height: 104px;
  grid-template-rows: auto auto;
  gap: 8px 24px;
  padding: 20px 24px;
}

.project-list .card-meta {
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 18px;
}

.project-list .card-name,
.project-list .card-description {
  white-space: normal;
  overflow-wrap: anywhere;
}

.project-list .card-date {
  font-size: 14px;
}

.project-list .card-description {
  font-size: 15px;
}

.project-list .card-icon {
  width: 24px;
  height: 24px;
}

.project-demo {
  display: block;
  width: 100%;
  height: 75vh;
  margin-top: calc(48 * var(--u));
  border: 0;
  background: var(--card);
}

@media (max-width: 600px) {
  .project-list .card {
    gap: 8px 16px;
    padding: 16px;
  }
}
