/* Tokens */

:root {
  --bg: #000;
  --fg: #fff;
  --fg-muted: rgb(255 255 255 / 0.58);
  --fg-ghost: rgb(255 255 255 / 0.17);
  --line: rgb(255 255 255 / 0.14);

  --sans: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Cormorant Garamond", ui-serif, Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --gutter: clamp(1rem, 4vw, 3rem);
  --max: 88rem;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: dark;
}

/* Base */

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

* {
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html:not(.lenis) {
    scroll-behavior: smooth;
  }
}

body {
  min-height: 100svh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.5;
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: none;
}

ul {
  list-style: none;
}

em {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 4px;
  border-radius: 2px;
}

.container {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Links */

.u,
.u-hover {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 1px;
  padding-bottom: 0.08em;
  transition: background-size 0.6s var(--ease-out);
}

.u-hover {
  background-size: 0 1px;
}

@media (hover: hover) {
  .u:hover {
    background-position: 100% 100%;
    background-size: 0 1px;
  }

  .u-hover:hover {
    background-size: 100% 1px;
  }
}

/* Hero */

.hero {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding-block: 4rem;
  text-align: center;

  /* The subtitle is sized from this so both lines come out the same width */
  --hero-size: clamp(3.5rem, 0.5rem + 10vw, 11rem);
}

.hero__title {
  max-width: 11em;
  margin-inline: auto;
  font-size: var(--hero-size);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.055em;
  text-wrap: balance;
}

.hero__title em,
.contact__title em,
.not-found__title em {
  padding-right: 0.03em;
  font-size: 1.12em;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.hero__title .w,
.hero__sub .w,
.contact__title .w {
  display: inline-block;
}

/* Hero background: Gradient ASCII (assets/js/gradient-ascii.js), fading into the black page at the bottom */

.hero {
  position: relative;
  overflow-x: clip; /* the warp canvases reach a little past the text; on a phone that's past the screen edge */
}

.hero__bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent);
  mask-image: linear-gradient(to bottom, #000 60%, transparent);
}

.gradient-ascii-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hero > .container,
.scroll-cue {
  z-index: 1;
}

.hero > .container {
  position: relative;
}

/* Scroll cue: a chevron that slides down and fades, on a loop; appears after the intro, leaves on first scroll */

.scroll-cue {
  position: absolute;
  bottom: clamp(1.25rem, 4vh, 3rem);
  left: 50%;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 4.5rem;
  transform: translateX(-50%);
  transition: opacity 0.8s var(--ease-out);
}

.js .scroll-cue {
  opacity: 0;
}

.js .reveal.is-in ~ .scroll-cue {
  opacity: 1;
  transition-delay: 1.6s;
}

.js .reveal.is-in ~ .scroll-cue.is-hidden {
  opacity: 0;
  pointer-events: none;
  transition-delay: 0s;
}

/* Room around the chevron for the warp to bend into */
.scroll-cue .warp-canvas {
  top: -1.25rem;
  left: -1.25rem;
  width: calc(100% + 2.5rem);
  height: calc(100% + 2.5rem);
}

.scroll-cue.is-warped .scroll-cue__chevron {
  visibility: hidden;
  animation: none;
}

/* Without WebGL the SVG itself runs the loop; main.js paints the same chevron and timing into the warp */
.scroll-cue__chevron {
  display: block;
  width: 18px;
  height: 10px;
  overflow: visible;
  color: rgb(255 255 255 / 0.85);
  animation: scroll-cue 2.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

@keyframes scroll-cue {
  0% {
    opacity: 0;
    transform: translateY(-5px);
  }

  20%,
  65% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateY(5px);
  }
}

/*
  Optical lockup: the subtitle's inked width matches "Hi, I'm Marko!" (0.2694 = ink-width ratio),
  and `left` lines the ink up, since mono glyphs sit in wider side bearings than the grotesk.
  Re-measure both if either text or font changes.
*/
.hero__sub {
  left: 0.138em;
  margin-top: calc(var(--hero-size) * 0.12);
  font-family: var(--mono);
  font-size: calc(var(--hero-size) * 0.2694);
  line-height: 1.1;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

/* Warp words: painted by WebGL (assets/js/warp.js); the DOM text stays for screen readers and selection */

.hero__title,
.hero__sub {
  position: relative;
}

.warp-canvas {
  position: absolute;
  top: -0.35em;
  left: calc(-1 * var(--gutter));
  width: calc(100% + 2 * var(--gutter));
  height: calc(100% + 0.7em);
  pointer-events: none;
}

/* WebGL draws the words where they sit, so they must not be offset by the reveal */
.js .reveal .is-warped .w {
  color: transparent;
  transform: none;
  transition: none;
}

/* Reveal: blur into focus, word by word */

.js .reveal .w {
  opacity: 0;
  filter: blur(0.35rem);
  transform: translate3d(0, 0.35em, 0);
  transition:
    opacity 1.1s var(--ease-out),
    filter 1.2s var(--ease-out),
    transform 1.4s var(--ease-out);
  transition-delay: calc(var(--i, 0) * 70ms);
}

.js .reveal .hero__title .w,
.js .reveal .contact__title .w {
  filter: blur(0.12em);
}

.js .reveal.is-in .w {
  opacity: 1;
  filter: blur(0);
  transform: none;
}

/* Statement: words light up as you scroll */

.statement {
  position: relative;
  padding-block: clamp(5rem, 16vw, 15rem);
}

/* Statement background: Pixel Blast (assets/js/pixel-blast.js) with the hero's film grain */

/* Faded at both ends so the grain eases in from the hero and out into the work list */
.statement__bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 14rem, #000 calc(100% - 14rem), transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 14rem, #000 calc(100% - 14rem), transparent);
}

.pixel-blast-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.statement > .container {
  position: relative;
  z-index: 1;
}

.statement__text {
  max-width: 19em;
  font-size: clamp(1.75rem, 0.8rem + 3.6vw, 4.25rem);
  line-height: 1.1;
  letter-spacing: -0.035em;
  text-wrap: pretty;
}

.statement__text p + p {
  margin-top: 0.9em;
}

/* Lit via text colour, not opacity, so a text selection still renders solid black on white */
.js .statement__text .lw {
  white-space: nowrap;
  color: rgb(255 255 255 / 0.17);
  transition: color 0.2s linear;
}

/* Projects */

.projects {
  padding-block: clamp(4rem, 10vw, 10rem);
  overflow-x: clip; /* the cards' edge-glow canvases reach 24px past each card, past the screen edge on a phone */
}

.section-title {
  margin-bottom: clamp(2.5rem, 5vw, 4.5rem);
  font-size: clamp(2.25rem, 1.2rem + 3.2vw, 4.5rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.05em;
}

/* Three across on desktop, two on tablets, stacked on phones */
.projects__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr));
  gap: clamp(1rem, 2vw, 1.5rem);
}

/* Edges in the backgrounds' hues, amber through cobalt to azure, at low alpha: colour reads brighter than grey,
   so they sit below --line to look as quiet as it does. Each card turns the ramp its own way
   (specular-edge.js reads --edge-angle, so the highlight takes the same colours). */
.project {
  --edge-angle: 90deg;
  --edge-mid: rgb(5 64 217 / 0.28);
  --edge: linear-gradient(var(--edge-angle), rgb(244 148 37 / 0.16), var(--edge-mid), rgb(40 151 244 / 0.2));
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid;
  border-image: var(--edge) 1;
}

/* Amber in the outer cards' top corners and along the bottom of the middle one */
.projects__grid > li:nth-child(3n + 1) .project {
  --edge-angle: 135deg;
}

.projects__grid > li:nth-child(3n + 2) .project {
  --edge-angle: 0deg;
}

.projects__grid > li:nth-child(3n + 3) .project {
  --edge-angle: 225deg;
}

/* Highlight that runs along the edge toward the cursor (assets/js/specular-edge.js).
   The canvas spans the border box plus 24px of glow room; its containing block is the padding box, hence 25px. */
.specular-edge {
  position: absolute;
  top: -25px;
  left: -25px;
  width: calc(100% + 50px);
  height: calc(100% + 50px);
  pointer-events: none;
}

.project__visual,
.project__body {
  position: relative;
  z-index: 1;
}

/* Placeholder visual until there are screenshots: a dim prompt on a dotted field */
.project__visual {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  border-bottom: 1px solid var(--edge-mid);
  background-image: radial-gradient(rgb(255 255 255 / 0.12) 1px, transparent 1.5px);
  background-size: 14px 14px;
  background-position: center;
}

.project__cmd {
  padding: 0.4em 0.75em;
  background: var(--bg);
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
}

.project__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.75rem;
  padding: clamp(1.25rem, 2vw, 1.75rem);
}

.project__meta {
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 0.8125rem;
  letter-spacing: -0.01em;
}

.project__title {
  font-size: clamp(1.5rem, 1.1rem + 1vw, 2rem);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.project__desc {
  max-width: 34ch;
  color: var(--fg-muted);
  line-height: 1.5;
}

.project__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin-top: auto;
  padding-top: 1rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  letter-spacing: -0.01em;
}

/* Contact */

.contact {
  padding-block: clamp(6rem, 18vw, 16rem) clamp(5rem, 12vw, 10rem);
  text-align: center;
}

.contact__title {
  font-size: clamp(3.25rem, 1rem + 9vw, 11rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.055em;
}

.contact__lede {
  margin-top: clamp(1.5rem, 3vw, 2.5rem);
  color: var(--fg-muted);
  font-size: clamp(1.0625rem, 0.9rem + 0.5vw, 1.375rem);
  letter-spacing: -0.015em;
}

.contact__email {
  display: inline-block;
  margin-top: clamp(2rem, 4vw, 3.5rem);
  font-size: clamp(1.375rem, 0.9rem + 2vw, 2.75rem);
  line-height: 1.2;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
}

.contact__links {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 2rem;
  font-size: 1.125rem;
  letter-spacing: -0.015em;
}

/* 404 page (404.html): the hero's background behind a short note and a way home */

.not-found {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding-block: 4rem;
  text-align: center;
}

.not-found > .container {
  position: relative;
}

.not-found__code {
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
}

.not-found__title {
  margin-top: clamp(1rem, 2vw, 1.5rem);
  font-size: clamp(3.25rem, 1rem + 9vw, 9rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.055em;
}

.not-found__lede {
  margin-top: clamp(1.5rem, 3vw, 2.5rem);
  color: var(--fg-muted);
  font-size: clamp(1.0625rem, 0.9rem + 0.5vw, 1.375rem);
  letter-spacing: -0.015em;
}

.not-found__home {
  display: inline-block;
  margin-top: 2rem;
  font-size: 1.125rem;
  letter-spacing: -0.015em;
}

/* Footer */

.site-footer {
  padding-block: 2rem;
  border-top: 1px solid var(--line);
  color: var(--fg-muted);
  font-size: 0.9375rem;
}

.site-footer__inner {
  text-align: center;
}

/* Reduced motion: everything visible, nothing moves */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

  .js .reveal .w {
    opacity: 1;
    filter: none;
    transform: none;
  }

  .js .statement__text .lw {
    color: var(--fg);
  }

  .scroll-cue__chevron {
    animation: none;
  }
}
