@font-face {
  font-family: "Bricolage Grotesque";
  src: url("assets/fonts/bricolage-grotesque-latin-wght.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Big Shoulders Display";
  src: url("assets/fonts/big-shoulders-display-latin-800.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* 1-bit black and white from the game, the two Playdate LCD tones, and Playdate yellow */
  --ink: #000;
  --paper: #fff;
  --lcd: #b1aea7;
  --lcd-dark: #312f28;
  --crank: #ffc833;

  --wrap: 75rem;
  --gutter: clamp(1.25rem, 4vw, 3rem);
  --gap: clamp(1.75rem, 4vw, 3rem);
  --space: clamp(3.5rem, 9vw, 7rem);
  --measure: 34rem;
  --measure-wide: 44rem;
  --screen: 400px; /* the game's own width; gameplay clips are encoded at twice this */

  color-scheme: dark;
}

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  font-size: 1.125rem;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

img,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Gameplay clips are 1-bit pixel art: scale them without smoothing */
.pixel {
  image-rendering: pixelated;

  /* Below its own size, unsmoothed pixel art drops pixels, so let the browser smooth it */
  @media (width <= 53rem) {
    image-rendering: auto;
  }
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Big Shoulders Display", Impact, "Arial Narrow", sans-serif;
  font-weight: 800;
  /* Sets the lowercase height, so the condensed face reads at full size and the fallback matches it while the font loads */
  font-size-adjust: 0.6;
  line-height: 1.05;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.5rem, 7vw, 5rem);
}

h2 {
  font-size: clamp(2rem, 4.5vw, 3.25rem);
}

h3 {
  font-size: 1.25rem;
}

p,
ul {
  margin: 0;
}

a {
  color: inherit;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;

  &:hover {
    color: var(--hover, var(--crank));
  }
}

:focus-visible {
  outline: 3px solid var(--focus, var(--crank));
  outline-offset: 3px;
}

/* Yellow areas carry black text, so links and focus rings inside them must not turn yellow */
.yellow {
  --hover: currentColor;
  --focus: var(--ink);
  background: var(--crank);
  color: var(--ink);
}

/* Centres content at --wrap wide using padding, so a background on the same element still reaches both edges */
.wrap {
  padding-inline: max(var(--gutter), (100% - var(--wrap)) / 2);
}

.muted {
  color: var(--lcd);
}

.skip {
  position: absolute;
  inset-block-start: -4rem;
  inset-inline-start: var(--gutter);
  padding: 0.5rem 0.9rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  text-decoration: none;

  &:focus {
    inset-block-start: 0.75rem;
  }
}

.button {
  display: inline-block;
  padding: 0.7rem 1.1rem;
  border: 0;
  background: var(--crank);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;

  &:hover {
    background: var(--paper);
    color: var(--ink);
  }
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block: clamp(1.25rem, 3vw, 2.25rem);
  /* One more pixel of yellow underneath, so no hairline shows where the header meets the yellow home page intro */
  box-shadow: 0 1px var(--crank);

  .logo img {
    width: clamp(8.5rem, 16vw, 11rem);
  }
}

.site-nav {
  display: flex;
  gap: clamp(1rem, 3vw, 2rem);
  font-weight: 500;

  a {
    text-decoration: none;

    &:hover {
      text-decoration: underline;
    }
  }
}

/* Ordered dither from yellow to the black page, centred on the line where they meet. The image is a strip of
   8x40 frames shown at twice their size: the first is a hard line and each one after spreads it further, so
   stepping through them blurs the line. At rest it shows the last frame. */
.hero::after {
  content: "";
  display: block;
  height: 80px;
  background: url("assets/dither-blur.png") 0 100% / 16px auto repeat-x;
  image-rendering: pixelated;
}

.intro {
  padding-block: clamp(2rem, 5vw, 3.5rem);

  h1 {
    font-size: clamp(3rem, 7vw, 5.75rem);
    line-height: 0.88;
    text-transform: uppercase;
  }

  p {
    max-width: var(--measure);
    margin-block-start: clamp(1.25rem, 3vw, 2rem);
    font-size: clamp(1.125rem, 1.6vw, 1.375rem);
    font-weight: 600;
  }

  a:hover {
    text-decoration-thickness: 0.16em;
  }
}

/* Colour key art with the trailer button over its bottom left corner */
.game-hero {
  position: relative;
  container-type: inline-size;

  /* On the game page the art opens the page, so keep it clear of the header */
  main > & {
    margin-block-start: var(--gap);
  }

  img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
  }
}

.play {
  position: absolute;
  inset-block-end: clamp(1rem, 7%, 3rem);
  inset-inline-start: clamp(1rem, 4%, 3rem);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 0.8rem 1.2rem;
  font-size: clamp(1rem, 1.6vw, 1.25rem);

  &::before {
    content: "";
    border-block: 0.5em solid transparent;
    border-inline-start: 0.8em solid currentColor;
  }

  /* When the art is too small to carry the button, the button sits under it */
  @container (width <= 33rem) {
    position: static;
    margin-block-start: 0.75rem;
  }
}

/* The trailer opens in a modal, sized so the whole 16:9 video fits on screen */
.trailer-dialog {
  width: min(100% - 2 * var(--gutter), var(--wrap), (100dvh - 7rem) * 16 / 9);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: none;
  color: var(--paper);
  overflow: visible;

  &::backdrop {
    background: rgb(0 0 0 / 0.88);
  }

  .button {
    display: block;
    margin-block-end: 0.75rem;
    margin-inline-start: auto;
    padding: 0.5rem 0.9rem;
  }

  iframe {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
    background: var(--ink);
  }

  /* On a phone the trailer runs edge to edge */
  @media (width <= 36rem) {
    width: 100%;

    .button {
      margin-inline-end: var(--gutter);
    }
  }
}

/* Stop the page scrolling behind the open trailer */
html:has(.trailer-dialog[open]) {
  overflow: hidden;
}

/* Never stretch a gameplay clip beyond the size it was encoded at */
.screen {
  width: 100%;
  max-width: calc(2 * var(--screen));
  background: var(--ink);
  outline: 1px solid var(--lcd-dark);
}

.game-copy {
  > * + * {
    margin-block-start: 1.25rem;
  }

  > * + h2 {
    margin-block-start: 2.75rem;
  }

  > * + h3 {
    margin-block-start: 1.75rem;
  }

  > h3 + p {
    margin-block-start: 0.4rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .tagline {
    font-size: 1.375rem;
    line-height: 1.3;
  }

  .stores {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-block-start: 0.75rem;
    padding: 0;
    list-style: none;
  }
}

.steam {
  padding-inline-start: 0.9rem;
  border-inline-start: 4px solid var(--crank);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.games {
  padding-block: var(--space);

  > h2 {
    margin-block-end: var(--gap);
  }
}

.summary {
  & + & {
    margin-block-start: var(--space);
  }

  h3 {
    font-size: clamp(2rem, 4.5vw, 3.25rem);

    a {
      text-decoration: none;
    }
  }

  .muted {
    max-width: var(--measure);
  }
}

.summary-art {
  display: block;
}

.summary-body {
  display: grid;
  /* The clip sits at the game's own width, or the nearest width site.js finds that lands on whole screen pixels */
  grid-template-columns: minmax(0, 1fr) var(--screen-snapped, var(--screen));
  gap: var(--gap);
  align-items: start;
  padding-block-start: var(--gap);

  @media (width <= 60rem) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.game-head,
.game {
  display: grid;
  grid-template-columns: minmax(0, calc(2 * var(--screen))) minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;

  /* Below 1280px the text beside a full-size clip gets too narrow, so stack them */
  @media (width <= 80rem) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.game-head {
  padding-block-start: var(--gap);

  .muted {
    max-width: var(--measure);
  }
}

.game-section {
  padding-block-start: var(--space);

  > h2 {
    margin-block-end: var(--gap);
  }
}

.features {
  padding-inline-start: 1.1rem;

  li + li {
    margin-block-start: 0.4rem;
  }

  li::marker {
    color: var(--crank);
  }
}

/* Two half-size clips sit flush under the full-size gameplay clip */
.stills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: calc(2 * var(--screen));

  figure {
    margin: 0;
  }

  video {
    width: 100%;
    outline: 1px solid var(--lcd-dark);
  }

  figcaption {
    margin-block-start: 0.6rem;
    font-size: 0.9375rem;
    color: var(--lcd);
  }

  @media (width <= 36rem) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.info {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space) var(--gap);

  .game-copy {
    max-width: var(--measure);
  }

  @media (width <= 36rem) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.5rem 1.5rem;
  margin-block-end: 0;

  dt {
    color: var(--lcd);
  }

  dd {
    margin: 0;
  }
}

.support {
  padding-block-end: var(--space);

  p {
    max-width: var(--measure);
  }
}

/* A 50% dither, the way the game draws grey */
.dither {
  height: 12px;
  border: 0;
  margin: 0;
  background: repeating-conic-gradient(var(--lcd-dark) 0 25%, var(--ink) 0 50%) 0 0 / 4px 4px;
}

.contact {
  padding-block: var(--space);

  p {
    max-width: var(--measure);
    margin-block-start: 1.25rem;
    color: var(--lcd);
  }

  .email {
    display: inline-block;
    margin-block-start: 1.25rem;
    font-size: clamp(1.375rem, 4.4vw, 3.25rem);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    overflow-wrap: anywhere;
    color: var(--crank);

    &:hover {
      color: var(--paper);
    }
  }
}

.site-footer {
  padding-block: 2.5rem 3.5rem;
  font-size: 0.9375rem;
  color: var(--lcd);

  .legal-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.75rem;
    padding: 0;
    list-style: none;
    color: var(--paper);
  }

  p {
    max-width: var(--measure-wide);
    margin-block-start: 1rem;
  }
}

.doc {
  max-width: var(--measure-wide);
  padding-block: clamp(2rem, 6vw, 4.5rem) var(--space);

  h1 {
    font-size: clamp(2.25rem, 5.5vw, 3.75rem);
  }

  h2 {
    margin-block-start: 2.75rem;
    font-size: 1.5rem;
  }

  p,
  ul {
    margin-block-start: 1rem;
  }

  ul {
    padding-inline-start: 1.25rem;
  }

  li + li {
    margin-block-start: 0.4rem;
  }

  .updated {
    color: var(--lcd);
  }
}

/* All motion lives in this block, and none of it runs in print or for people who prefer reduced motion */
@media screen and (prefers-reduced-motion: no-preference) {
  /* The Games and Contact links scroll to their section instead of jumping */
  html {
    scroll-behavior: smooth;
  }

  /* On load the edge of the yellow starts as a hard line, then blurs into the dither one frame at a time */
  .hero::after {
    animation: blur-line 0.8s 0.4s steps(16) both;
  }

  .trailer-dialog,
  .trailer-dialog::backdrop {
    transition: opacity 0.2s;
  }

  @starting-style {
    .trailer-dialog,
    .trailer-dialog::backdrop {
      opacity: 0;
    }
  }

  /* Blocks further down a page fade up as they scroll into view. site.js adds .below only to blocks that start
     below the screen and removes it as each one arrives, so nothing is hidden unless that script is running. */
  .reveal {
    transition: opacity 0.5s, translate 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .below {
    opacity: 0;
    translate: 0 1.5rem;
    transition: none;
  }

  @keyframes blur-line {
    from {
      background-position-y: 0;
    }
  }
}
