/* ==========================================================================
   Layout and styling. Content lives in content.js, not here.

   The whole page sits on one square grid. --cell is the size of one square.
   Every size and gap below is a whole number of cells, so the text blocks,
   the icon tiles and the animated pixels all share the same lines.
   ========================================================================== */

/* Fonts (stored in the fonts folder, so the page makes no outside requests) */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("../fonts/BricolageGrotesque-Bold.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/InstrumentSans-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Design tokens ----------------------------------------------------------- */
:root {
  --charcoal: #1A1B1E;   /* page background */
  --ink: #EDEBE6;        /* name, labels */
  --ink-soft: #C9C8C4;   /* running text */
  --smoke: #A6A8AE;      /* small print */
  --rule: rgba(237, 235, 230, 0.3);   /* tile and placeholder outlines */
  --grid-line: rgba(237, 235, 230, 0.045);
  --accent: #8FD3DC;     /* washed cyan; overridden by accentColor in content.js */
  --accent-2: #E2D595;   /* washed yellow; overridden by secondColor in content.js */

  --cell: 24px;          /* one grid square */
  --margin: 1;           /* page side margin, in cells */
  --ox: 0px;             /* set by pixels.js so the grid is centred */
  --page-h: 100vh;       /* set by pixels.js to a whole number of cells */

  --font-text: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Bricolage Grotesque", var(--font-text);
}
@supports (height: 100svh) {
  :root { --page-h: 100svh; }
}
@media (min-width: 600px) {
  :root { --margin: 2; }
}
@media (min-width: 1100px) {
  :root { --cell: 28px; --margin: 3; }
}

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

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

body {
  margin: 0;
  background: var(--charcoal);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: var(--cell);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Static grid for visitors without JavaScript (the canvas draws it otherwise) */
html:not(.js) body {
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}

::selection { background: var(--accent); color: var(--charcoal); }

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

/* Pixel background --------------------------------------------------------- */
.pixels {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* Page frame --------------------------------------------------------------- */
.page {
  position: relative;
  z-index: 1;
  min-height: var(--page-h);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-block: calc(var(--cell) * 2);
  padding-inline: calc(var(--ox) + var(--cell) * var(--margin));
}

/* Logo --------------------------------------------------------------------- */
.masthead { height: calc(var(--cell) * 3); }

.logo img {
  display: block;
  height: calc(var(--cell) * 3);
  width: auto;
  max-width: calc(var(--cell) * 10);
  object-fit: contain;
  object-position: left center;
}

.logo-placeholder {
  /* +1px so the outline lands on the grid lines on all four sides */
  width: calc(var(--cell) * 3 + 1px);
  height: calc(var(--cell) * 3 + 1px);
  display: grid;
  place-items: center;
  border: 1px dashed var(--rule);
  color: var(--smoke);
  font-size: 13px;
}

/* Name and one-line description -------------------------------------------- */
.card {
  align-self: end;
  padding-top: calc(var(--cell) * 3);
}

.name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 44px;
  line-height: calc(var(--cell) * 2);
  letter-spacing: -0.035em;
  text-wrap: balance;
  overflow-wrap: break-word;
}

.tagline {
  margin: var(--cell) 0 0;
  max-width: 36em;
  color: var(--ink-soft);
  font-size: 18px;
  text-wrap: pretty;
}

@media (min-width: 600px) {
  .name { font-size: 68px; line-height: calc(var(--cell) * 3); }
  .tagline { font-size: 20px; }
}
@media (min-width: 1100px) {
  .name { font-size: 88px; }
  .tagline { font-size: 22px; }
}
@media (min-width: 1600px) {
  .name { font-size: 112px; line-height: calc(var(--cell) * 4); }
}

/* About and links ----------------------------------------------------------- */
.details {
  margin-top: calc(var(--cell) * 3);
  display: grid;
  row-gap: calc(var(--cell) * 2);
}
@media (min-width: 900px) {
  .details {
    grid-template-columns: calc(var(--cell) * 20) max-content;
    column-gap: calc(var(--cell) * 4);
  }
}

.about-heading {
  margin: 0 0 var(--cell);
  font-size: inherit;
  font-weight: 400;
  color: var(--ink);
}

.about-text p {
  margin: 0 0 var(--cell);
  max-width: 34em;
  color: var(--ink-soft);
  text-wrap: pretty;
}
.about-text p:last-child { margin-bottom: 0; }

@media (min-width: 1100px) {
  body { font-size: 17px; }
}

.links ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--cell);
}
@media (min-width: 600px) and (max-width: 899.98px) {
  /* side by side, each link 8 cells wide so the tiles stay on the grid */
  .links ul {
    display: grid;
    grid-template-columns: repeat(auto-fill, calc(var(--cell) * 8));
    gap: var(--cell) 0;
  }
}

.link {
  display: flex;
  align-items: center;
  gap: var(--cell);
  color: var(--ink);
  text-decoration: none;
}

.link-tile {
  flex: none;
  /* a 2 x 2 block of grid cells; +1px and the negative margin keep the
     outline on the grid lines without changing the size of the row */
  width: calc(var(--cell) * 2 + 1px);
  height: calc(var(--cell) * 2 + 1px);
  margin: 0 -1px -1px 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  background: var(--charcoal);
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}
.link-tile svg {
  /* each icon fills exactly one grid cell */
  width: var(--cell);
  height: var(--cell);
  display: block;
}

.link-label {
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  transition: text-decoration-color 160ms ease;
}

.link:hover .link-tile,
.link:focus-visible .link-tile {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--charcoal);
}
.link:hover .link-label,
.link:focus-visible .link-label {
  text-decoration-color: currentColor;
}

/* Footer -------------------------------------------------------------------- */
.footer {
  margin-top: calc(var(--cell) * 3);
  min-height: var(--cell);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  column-gap: var(--cell);
  color: var(--smoke);
  font-size: 13px;
}

.copyright { margin: 0; }

.motion-toggle {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: var(--cell);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.motion-toggle[hidden] { display: none; }
.motion-toggle::before {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--accent);
  border: 1px solid var(--accent);
}
.motion-toggle.is-paused::before { background: transparent; border-color: var(--smoke); }
.motion-toggle:hover { color: var(--ink); }

/* Message shown when content.js cannot be read, or JavaScript is off -------- */
.notice {
  position: relative;
  z-index: 2;
  max-width: 34em;
  margin: calc(var(--cell) * 2);
  padding: var(--cell);
  border: 1px solid var(--rule);
  background: var(--charcoal);
  color: var(--ink);
}

/* Reduced motion: the background is drawn once and stays still (see
   pixels.js). Hover colour changes also become instant. */
@media (prefers-reduced-motion: reduce) {
  .link-tile, .link-label { transition: none; }
}

@media print {
  .pixels, .motion-toggle { display: none; }
  html, body { background: #fff; color: #000; }
  .page { min-height: 0; }
  .name, .about-heading, .link { color: #000; }
  .tagline, .about-text p, .footer { color: #333; }
  .link-tile { background: none; border-color: #999; }
}
