/* ==========================================================================
   yannworks: styles
   Everything you may want to change is in :root just below: colours,
   fonts, sizes and timings. The dark theme only swaps the colours.
   ========================================================================== */

:root {
  /* Colours: ink (text) on paper (background), and Clawd's orange, the only
     accent. The orange is for shapes and dots only: on white it is 3.1:1,
     enough for a shape, too little for small text. */
  --paper: #ffffff;
  --ink: #111111;
  --muted: #5c5c5c;          /* secondary text: 6.7:1 on paper, 6.1:1 on a card */
  --surface: #f5f5f5;        /* the component cards */
  --line: #e3e3e3;           /* card edges, empty days in the graph */
  --clawd: #d97757;          /* Clawd's body, the dots, the busiest days */
  --glow: rgb(217 119 87 / 0.14);   /* the warm light behind the dots */

  /* The graph's four levels (GitHub's 1 to 4), from Clawd's orange to darker:
     every level is at least 3:1 on paper, so a day with activity always shows. */
  --level-1: #d97757;
  --level-2: #bf5f3d;
  --level-3: #a24a2d;
  --level-4: #7c361f;

  /* Fonts: files in /fonts, licence in fonts/OFL.txt */
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Geist Serif", ui-serif, Georgia, serif;

  /* Type sizes */
  --size-intro: clamp(1.3125rem, 1.1rem + 0.9vw, 1.625rem);  /* 21px on phones, 26px wide */
  --size-keyword: 1.24em;                                  /* keywords, relative to the intro */
  --size-links: 1.0625rem;
  --size-small: 0.9375rem;

  /* Space */
  --gutter: 16px;
  --page-max: 1440px;
  --fringe-h: 40px;          /* the empty strip at the foot of each card, where its dots live */

  /* Motion */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --enter-duration: 640ms;   /* text entrance on load */
  --enter-stagger: 65ms;     /* delay between items */
  --enter-rise: 10px;        /* how far items rise (0 with reduced motion) */
  --hover-duration: 200ms;
  --press-duration: 140ms;
  --fringe-in: 300ms;        /* the light behind the dots of the card you reach for (as long as their random lighting)... */
  --fringe-out: 200ms;       /* ...and on the one you left (as long as their going out) */
  --dissolve: 500ms;         /* theme dissolve (main.js sets it again) */

  /* One dot of the dither masks (theme dissolve, keyword print, clock digits). */
  --cell: 2px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #0d0d0d;
  --ink: #ededed;
  --muted: #a3a3a3;
  --surface: #161616;
  --line: #262626;
  --glow: rgb(217 119 87 / 0.2);
  /* In the dark, more is brighter. */
  --level-1: #9a4f36;
  --level-2: #b65e40;
  --level-3: #d97757;
  --level-4: #f3a587;
  color-scheme: dark;
}

/* Without JavaScript there is no data-theme: follow the device. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #0d0d0d;
    --ink: #ededed;
    --muted: #a3a3a3;
    --surface: #161616;
    --line: #262626;
    --glow: rgb(217 119 87 / 0.2);
    --level-1: #9a4f36;
    --level-2: #b65e40;
    --level-3: #d97757;
    --level-4: #f3a587;
    color-scheme: dark;
  }
}

@media (min-width: 768px) { :root { --gutter: 32px; } }
@media (min-width: 1280px) { :root { --gutter: 48px; } }

@media (prefers-reduced-motion: reduce) {
  :root { --enter-rise: 0px; }
}

/* ---- Fonts ---------------------------------------------------------------- */

@font-face {
  font-family: "Geist";
  src: url("fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist Serif";
  src: url("fonts/GeistSerifVF.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ---- Base ----------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  font-synthesis: none;            /* never fake a bold or an italic */
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

/* ---- Layout: the intro, the three components, the graph ----------------- */

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

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 18px;
}

.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(2.5rem, 1.5rem + 3vw, 4.5rem);
  padding-block: clamp(1rem, 0.5rem + 3vw, 3.5rem) 0;
}

/* The intro on the left; on wide screens the links stand on its right, level with its last line. */
.hero { display: grid; grid-template-columns: minmax(0, 1fr); }

/* Wide screens: the links in a column right beside the intro, level with its first line. */
@media (min-width: 1100px) {
  .hero {
    grid-template-columns: minmax(0, 42.5rem) 17.5rem;
    align-items: start;
    column-gap: 80px;
  }

  .hero .links {
    display: grid;
    justify-items: start;
    margin: 0.45rem 0 0;           /* first link on the intro's first line */
  }

  .hero .links li { flex-wrap: wrap; row-gap: 0.15rem; }
  .hero .link__note { flex-basis: 100%; }
}

/* ---- Name and intro ------------------------------------------------------- */

.name {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.01em;
}

/* The logo beside the name (drawn by tools/make-logo.mjs): 16 cells at 1.5 px,
   so 3 screen pixels a cell on most phones and laptops. */
.name__logo { flex: none; display: block; }

.intro {
  max-width: 40rem;
  margin: 0;
  font-size: var(--size-intro);
  font-weight: 400;
  line-height: 1.65;               /* room between lines for the dots under the keywords */
  letter-spacing: -0.012em;
  text-wrap: pretty;
}

/* Highlighted keywords: Geist Serif, upright, bigger than the text around.
   Its ELSH axis at 25 gives square dots, like the dither's. */
.kw {
  font-family: var(--serif);
  font-size: var(--size-keyword);
  font-weight: 400;
  font-style: normal;
  font-variation-settings: "ELSH" 25;
  line-height: 1;
  letter-spacing: -0.008em;
}

/* While main.js prints them in dots. */
.kw.is-printing .kw__dots { visibility: hidden; }   /* the dots come once the word has printed */

.kw.is-printing {
  -webkit-mask-size: calc(var(--cell) * 8) calc(var(--cell) * 8);
  mask-size: calc(var(--cell) * 8) calc(var(--cell) * 8);
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

/* Yann's local time (js/clock.js). Geist's digits have different widths;
   tabular figures give them all the same, so nothing moves when the minute changes. */
.clock__time { font-variant-numeric: tabular-nums; }

/* A changed digit: the new one and the old one stacked in one box, each seen
   through complementary dot masks while they trade places. */
.clock__swap { display: inline-grid; }

.clock__swap > span {
  grid-area: 1 / 1;
  -webkit-mask-size: calc(var(--cell) * 8) calc(var(--cell) * 8);
  mask-size: calc(var(--cell) * 8) calc(var(--cell) * 8);
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

/* ---- Links ---------------------------------------------------------------- */

/* In a row under the intro; in a column beside it on wide screens (see .hero). */
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.75rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--size-links);
  font-weight: 500;
}

.links li {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;                     /* room for the focus ring before the note */
}

.link {
  position: relative;
  display: inline-block;
  padding: 0.35em 0.5em;
  margin: -0.35em -0.5em;          /* a bigger target without moving the text */
  color: inherit;
  text-decoration: none;
  transition: transform var(--press-duration) var(--ease-out);
}

.link__text {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  text-decoration: underline 1px;
  text-underline-offset: 0.24em;
}

/* Pixel arrow after each link, drawn on a 5 x 5 grid. */
.link__text::after {
  content: "";
  width: 10px;
  height: 10px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 5 5' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h4v1H1zM3 1h2v1H3zM2 2h1v1H2zM4 2h1v1H4zM1 3h1v1H1zM4 3h1v1H4zM0 4h1v1H0z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 5 5' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h4v1H1zM3 1h2v1H3zM2 2h1v1H2zM4 2h1v1H4zM1 3h1v1H1zM4 3h1v1H4zM0 4h1v1H0z'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform var(--hover-duration) var(--ease-out);
}

/* The inverted copy: ink background, paper text, revealed from the left. */
.link__fill {
  position: absolute;
  inset: 0;
  padding: inherit;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
  clip-path: inset(0 100% 0 0);
  transition: clip-path var(--hover-duration) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .link:hover .link__fill { clip-path: inset(0); }
  .link:hover .link__text::after { transform: translate(1px, -1px); }
}

.link:focus-visible .link__fill { clip-path: inset(0); }
.link:active { transform: scale(0.97); }
.link:active .link__fill { clip-path: inset(0); transition-duration: 60ms; }

.link__note {
  font-size: var(--size-small);
  font-weight: 400;
}

/* ---- Square icon button (theme) ------------------------------------------ */

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -10px;                   /* the target is bigger than it looks */
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: transform var(--press-duration) var(--ease-out);
}

.icon-button[hidden] { display: none; }
.icon-button svg { display: block; }

@media (hover: hover) and (pointer: fine) {
  .icon-button:hover { background: var(--ink); color: var(--paper); }
}

.icon-button:active { transform: scale(0.92); }

/* Theme toggle: half solid, half dithered; it turns over with the theme. */
.theme-toggle svg {
  width: 22px;
  height: 22px;
  transition: transform 360ms var(--ease-out);
}

:root[data-theme="dark"] .theme-toggle svg { transform: rotate(180deg); }

@media (prefers-reduced-motion: reduce) {
  .theme-toggle svg { transition: none; }
}

/* ---- Orange dots: where they appear ----------------------------------------
   js/accent.js draws them once per size on small canvases. They only ever sit
   in empty space: under a keyword's line, in the strip at the foot of a card,
   at the end of the page. Nothing is printed over them. */

/* Under the intro's keywords: a band of dots in the gap between two lines,
   dense against the word and thinning out downwards. */
.intro .kw {
  position: relative;
  white-space: nowrap;             /* one band per keyword */
}

.kw__dots {
  position: absolute;
  left: 0;
  top: calc(100% + 2px);           /* clear of the descenders (g, p) */
  width: 100%;
  height: 4px;                     /* two rows of 2 px dots, sparse. Two keyword lines in a row
                                      leave 0.41 em of the intro between them (1.65 - 1.24):
                                      8.6 px at 21 px, so 2 + 4 px always fit */
  pointer-events: none;
}

/* ---- Showcase: three components from Experiments --------------------------
   The components keep their own look (their CSS comes with them in
   showcase/showcase.css). Only the card around them is styled here. */

.showcase__title {
  margin: 0 0 1.5rem;
  font-size: var(--size-links);
  font-weight: 400;
  line-height: 1.4;
}

.showcase__list {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* A card: name, line, the component on its stage, the link, then an empty
   strip (--fringe-h) where the orange dots rise. */
.showcase__item {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  justify-items: start;
  min-width: 0;
  padding: 20px 20px var(--fringe-h);
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
  isolation: isolate;
}

.showcase__name {
  margin: 0;
  font-size: var(--size-links);
  font-weight: 500;
  line-height: 1.4;
}

.showcase__line {
  max-width: 34rem;
  margin: 0.25rem 0 0;
  font-size: var(--size-small);
  line-height: 1.45;
  color: var(--muted);
  text-wrap: pretty;
}

/* What to do with each component: shown only once it is live, in the words of
   the visitor's device (no hover on a phone). */
.showcase__hint { display: none; }

.showcase.is-live .showcase__hint:not(.showcase__hint--pointer, .showcase__hint--touch) { display: inline; }

@media (hover: hover) and (pointer: fine) {
  .showcase.is-live .showcase__hint--pointer { display: inline; }
}

@media (hover: none) {
  .showcase.is-live .showcase__hint--touch { display: inline; }
}

.showcase__link {
  position: relative;
  z-index: 1;
  margin-top: calc(0.75rem - 0.35em);
  font-size: var(--size-small);
  font-weight: 500;
}

/* The stage the component sits on. Without JavaScript, or if the components
   fail to load, it is not there at all: the name, the line and the link stay. */
.showcase__stage { display: none; }

.js .showcase__stage {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  justify-self: stretch;
  height: var(--stage-h, 19rem);
  margin-top: 0.5rem;
  padding: 16px 0;
}

/* Each stage just fits its component, so the section stays short. The heights
   are fixed, so nothing below moves when the components arrive. Gem Clip's
   command wraps on 1 to 4 lines depending on the card's width (measured), so its
   stage follows the card's own width. */
.showcase__item { container-type: inline-size; }
.showcase__item--shoji { --stage-h: 16rem; }
.showcase__item--clip { --stage-h: 11.5rem; }       /* 4 lines, narrowest phones */
.showcase__item--snooze { --stage-h: 7.5rem; }

@container (min-width: 270px) { .showcase__item--clip .showcase__stage { --stage-h: 10rem; } }  /* 3 lines */
@container (min-width: 300px) { .showcase__item--clip .showcase__stage { --stage-h: 8.5rem; } } /* 2 lines */
@container (min-width: 500px) { .showcase__item--clip .showcase__stage { --stage-h: 7rem; } }   /* 1 line */
/* Shoji Bento is 3:2, at most 380 px wide here: from a 336 px card it needs 285 px. */
@container (min-width: 336px) { .showcase__item--shoji .showcase__stage { --stage-h: 18.5rem; } }

.showcase.is-failed .showcase__stage,
.showcase__item.is-failed .showcase__stage { display: none; }

/* On a touch screen the page must keep scrolling when a finger lands on a
   Shoji Bento line: vertical swipes scroll, sideways drags move the line. */
@media (pointer: coarse) {
  .showcase .shoji__line { touch-action: pan-y; }
}

/* Wide screens: Shoji Bento leads, as tall as the two others stacked beside it.
   Its stage takes the room left in its card (still no shift: the card's height
   comes from the two fixed stages on the right). Its width goes up through the
   variable the component documents. */
@media (min-width: 900px) {
  .showcase__list {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  }

  .showcase__item--shoji { grid-row: span 2; }
  .js .showcase__item--shoji .showcase__stage { height: auto; min-height: var(--stage-h); }
  .showcase .showcase__item--shoji .shoji { --shoji-width: 480px; }
}

/* The fringe: dots at the foot of the active card, with a warm light behind
   them. js/dots.js decides which cells are on (Flow): they light in a random
   order when the card becomes active, drift while it stays active and on
   screen, and go out in a random order when another card takes over. Only the
   light behind them fades (the dots never do). */
.fringe {
  position: absolute;
  inset: auto 0 0;
  height: var(--fringe-h);
  pointer-events: none;
}

.fringe::before {
  content: "";
  position: absolute;
  inset: -100% 0 0;                /* the light starts above the strip, behind the link */
  background: linear-gradient(to bottom, transparent, var(--glow));
  opacity: 0;
  transition: opacity var(--fringe-out) ease;
}

.fringe canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.js .showcase__item.is-active .fringe::before { opacity: 1; transition-duration: var(--fringe-in); }

@media (prefers-reduced-motion: reduce) {
  .fringe::before { transition: none; }
}

/* ---- GitHub activity: the graph under the components ---------------------- */

.activity[hidden] { display: none; }

/* Wide screens: the words under the lead card, the graph under the two others,
   on the same two columns as the cards. */
@media (min-width: 900px) {
  .activity__body:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;    /* the day line right under the summary */
    column-gap: 16px;
    align-items: start;
  }

  .activity__summary { grid-column: 1; grid-row: 1; padding: 34px 20px 0 0; }
  .activity__graph { grid-column: 2; grid-row: 1 / span 2; }
  .activity__day { grid-column: 1; grid-row: 2; }
}

/* Without JavaScript: a plain link instead of the graph. */
.activity__fallback {
  margin: 0;
  font-size: var(--size-links);
  font-weight: 500;
}

.js .activity__fallback { display: none; }

.activity__summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1.25rem;
  margin: 0 0 0.75rem;
  font-size: var(--size-links);
  line-height: 1.4;
}

.activity__updated { font-size: var(--size-small); }

/* Less, the five colours, More. */
.activity__legend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.activity__legend i { width: var(--sq, 10px); height: var(--sq, 10px); }
.activity__legend i:first-of-type { margin-left: 0.35rem; }
.activity__legend i:last-of-type { margin-right: 0.35rem; }

/* One focusable element; the arrow keys move between days. js/activity.js sets
   the square size (--sq) so 26 weeks fill the width, up to 16 px. */
.activity__graph {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  padding-top: var(--clawd-h, 34px);   /* room for Clawd, who stands on the top row */
  touch-action: manipulation;
}

.activity__graph:focus-visible { outline-offset: 6px; }

.activity__months {
  position: relative;
  height: 14px;
  margin-top: 8px;
  font-size: 0.75rem;
  line-height: 1;
  color: var(--muted);
}

.activity__months span { position: absolute; top: 0; }

.activity__days {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--sq, 12px));
  grid-auto-columns: var(--sq, 12px);
  gap: 3px;
}

.activity__days i { background: var(--line); }
.activity__days i[data-level="1"] { background: var(--level-1); }
.activity__days i[data-level="2"] { background: var(--level-2); }
.activity__days i[data-level="3"] { background: var(--level-3); }
.activity__days i[data-level="4"] { background: var(--level-4); }
.activity__days i.is-blank { visibility: hidden; }

/* The chosen day (hover, tap or arrow keys): a 1 px ink frame. */
.activity__days i.is-selected { outline: 1px solid var(--ink); outline-offset: 1px; }

/* Clawd stands on today's column. His grid is 22 x 16 cells: 2 px a cell (44 x
   32 px) next to 16 px squares, about 1.5 px a cell on phones. js/activity.js
   sizes the canvas in whole screen pixels per cell, so cells stay sharp. */
.activity__clawd {
  position: absolute;
  top: 0;
  left: 0;
  image-rendering: pixelated;
  cursor: default;
}

.activity__day {
  min-height: 1.4em;
  margin: 0.75rem 0 0;
  font-size: var(--size-small);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

/* ---- The end of the page: orange dots rising from the bottom edge --------- */

/* Without JavaScript there are no dots, so no strip and no light either. */
.end { display: none; }

.js .end {
  display: block;
  position: relative;
  height: 56px;
  margin-top: clamp(3.5rem, 2.5rem + 3vw, 5rem);
  overflow: hidden;
}

.end::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 20%, var(--glow));
}

@media (min-width: 768px) { .js .end { height: 72px; } }

.end canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- Entrance: fade in and rise a little, one after the other ------------ */

.enter {
  animation: enter var(--enter-duration) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * var(--enter-stagger));
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(var(--enter-rise));
  }
}

/* ---- Theme change ----------------------------------------------------------
   The dissolve: the browser shows the old page, and the new one appears on
   top through a dot mask that main.js changes on every frame. */

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-new(root) {
  animation: dissolve-hold var(--dissolve) linear both;   /* keeps the transition alive */
  -webkit-mask-image: var(--dither-mask);
  mask-image: var(--dither-mask);
  -webkit-mask-size: calc(var(--cell) * 8) calc(var(--cell) * 8);
  mask-size: calc(var(--cell) * 8) calc(var(--cell) * 8);
  -webkit-mask-position: var(--dither-x, 0) var(--dither-y, 0);
  mask-position: var(--dither-x, 0) var(--dither-y, 0);
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

@keyframes dissolve-hold {
  from { opacity: 1; }
  to { opacity: 1; }
}

/* Browsers without view transitions: a plain cross-fade of the colours. */
.theme-fading,
.theme-fading * {
  transition-property: background-color, color, fill;
  transition-duration: var(--dissolve);
  transition-timing-function: ease;
}
