@font-face {
  font-family: Rotor;
  src: url('/fonts/rotor.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: Alef;
  font-weight: 400;
  src: url('/fonts/alef-400.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: Alef;
  font-weight: 700;
  src: url('/fonts/alef-700.woff2') format('woff2');
  font-display: swap;
}

:root {
  --bg: #fdfdfd;
  --text: #404040;
  --muted: #757575;
  --link: #0b6bcb;
  --line: #d9d9d9;
  --edge: 2rem; /* distance of header, footer and controls from the viewport edge */
}

@view-transition {
  navigation: auto;
}

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

html {
  background: var(--bg);
  color: var(--text);
  font: 100%/1.75 Alef, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
}

a {
  color: var(--link);
}

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

/* Layout: logo top left, content, footer navigation at the bottom. */

.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Outside .page, so the mark keeps its color on the home page, where .page
   is blended over the drawings. */
header {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  padding: 1rem var(--edge);
}

.logo {
  display: block;
  border-radius: 8px;
}

.logo svg {
  display: block;
  transition: scale 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.logo:hover svg {
  scale: 1.06;
}

.logo:active svg {
  scale: 0.96;
}

main {
  flex: 1;
  padding: 5rem var(--edge) 2rem;
}

footer nav {
  display: flex;
  justify-content: space-between;
  padding: 0 var(--edge);
}

footer a {
  padding: 1.25rem 0;
  font-size: 0.75rem;
  line-height: 1.5rem;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
}

footer a:hover {
  color: var(--text);
}

/* Type */

.intro {
  max-width: 54rem;
  margin: 0;
  font: 1.2rem/1.4 Rotor, sans-serif;
  color: var(--muted);
}

.intro + .intro {
  margin-top: 1.4em;
}

.prose,
.links {
  max-width: 42rem;
  margin-top: 2rem;
  overflow-wrap: break-word;
}

.prose h2,
.prose h3 {
  margin: 2.5rem 0 0.5rem;
  line-height: 1.3;
}

.prose h2 {
  font-size: 1.5rem;
}

.prose h3 {
  font-size: 1.25rem;
}

.prose p,
.links p {
  margin: 0 0 1.75rem;
}

.links a {
  display: block;
  padding: 1rem 0;
  font-size: clamp(1.4rem, 4.5vw, 4rem);
  line-height: 1.2;
}

@media (min-width: 48em) {
  main {
    padding: 6rem;
  }

  .intro {
    font-size: 2.2rem;
  }
}

/* Home: the page is one screen and the canvas behind it is the drawing wall.
   The text sits on top in difference blending, so it stays readable over any
   stroke, and lets pointer input through to the canvas. */

.home {
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.home .page {
  position: relative;
  z-index: 1;
  height: 100dvh;
  mix-blend-mode: difference;
  pointer-events: none;
}

/* #888 in difference blending on the near-white page renders as --muted. */
.home .page,
.home .page a,
.home .intro {
  color: #888;
}

.home .page a {
  pointer-events: auto;
}

.home .page a:hover {
  color: #ccc;
}

.home .intro {
  font-size: 1.2rem;
}

.info {
  position: fixed;
  left: var(--edge);
  right: calc(var(--edge) + 4rem);
  bottom: 4rem;
  max-width: 19rem;
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.3;
}

/* Wheel and number keys only exist with a mouse and keyboard. */
.keys {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .keys {
    display: inline;
  }
}

@media (min-width: 48em) {
  .home main {
    padding: 2rem 6rem;
  }
}

/* Brush control: a round button, and a panel of pen, doodles, colors and size
   that grows out of it. Flat paper with a soft lift, little tilts on hover. */

#brush,
#brush-panel {
  --paper: #fff;
  --tile: #f3f3f0;
  --lift: 0 0 0 1px rgb(0 0 0 / 0.06), 0 10px 30px -12px rgb(0 0 0 / 0.3);
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

#brush {
  position: fixed;
  right: var(--edge);
  bottom: 4rem;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--lift);
  cursor: pointer;
  transition: scale 0.15s var(--ease);
}

#brush:active {
  scale: 0.96;
}

/* The dot shows the current brush; --color and --size are set by draw.js. */
#brush span,
#cursor {
  border-radius: 50%;
  background: var(--color);
  outline: 1px solid rgb(0 0 0 / 0.15);
}

#brush span {
  width: clamp(6px, var(--size), 30px);
  height: clamp(6px, var(--size), 30px);
}

#brush svg {
  width: 70%;
  height: 70%;
}

#cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2;
  width: var(--size);
  height: var(--size);
  pointer-events: none;
}

/* With a sticker chosen, the cursor shows it at the size it will be placed. */
[data-tool='sticker'] #cursor {
  width: auto;
  height: auto;
  background: none;
  outline: 0;
  border-radius: 0;
  opacity: 0.5;
}

[data-tool='sticker'] #cursor svg {
  display: block;
}

#brush-panel {
  inset: auto var(--edge) 7.25rem auto;
  width: min(18.5rem, calc(100vw - 2 * var(--edge)));
  margin: 0;
  padding: 0.75rem 0.75rem 0.5rem;
  border: 0;
  border-radius: 1.5rem; /* tiles: 0.75rem radius + 0.75rem padding */
  background: var(--paper);
  box-shadow: var(--lift);
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1.5;
  transform-origin: calc(100% - 1.375rem) calc(100% + 1.875rem); /* the button */
  transition:
    opacity 0.2s var(--ease),
    scale 0.2s var(--ease),
    display 0.2s allow-discrete,
    overlay 0.2s allow-discrete;
}

#brush-panel:not(:popover-open) {
  opacity: 0;
  scale: 0.97;
}

@starting-style {
  #brush-panel:popover-open {
    opacity: 0;
    scale: 0.9;
  }
}

#brush-panel fieldset {
  margin: 0 0 0.75rem;
  padding: 0;
  border: 0;
}

#brush-panel legend,
#brush-panel .legend {
  display: block;
  margin-bottom: 0.375rem;
  padding: 0 0.25rem;
  color: var(--muted);
}

/* Tools: pen and the doodle stickers, as a row of soft tiles. */
#brush-panel .tools {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.375rem;
  margin-bottom: 0.25rem;
}

.tools label {
  position: relative;
  aspect-ratio: 1;
  border-radius: 0.75rem;
  background: var(--tile);
  cursor: pointer;
  transition:
    background-color 0.2s var(--ease),
    box-shadow 0.2s var(--ease);
}

.tools label:has(:checked) {
  background: var(--paper);
  box-shadow: inset 0 0 0 2px var(--text);
}

.tools label:has(:focus-visible) {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

#brush-panel .tools input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.tools span {
  position: absolute;
  inset: 18%;
  transition: rotate 0.25s var(--ease), scale 0.25s var(--ease);
}

.tools label:hover span {
  rotate: -8deg;
  scale: 1.06;
}

.tools label:active span {
  scale: 0.96;
}

.tools svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* The pen is drawn in the brush color, with a faint rim so white shows too. */
.tools [value='pen'] + span svg {
  fill: none;
  stroke: var(--color);
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 0 0.5px rgb(0 0 0 / 0.5));
}

.hint {
  margin: 0 0.25rem 0.875rem;
  color: var(--muted);
  font-size: 0.6875rem;
}

/* Colors: little dabs of paint, each a slightly different blob. */
#brush-panel .colors {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.375rem;
}

#brush-panel input[name='color'] {
  appearance: none;
  aspect-ratio: 1;
  width: 100%;
  height: auto;
  margin: 0;
  border-radius: 48% 52% 44% 56% / 56% 46% 54% 44%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.1);
  cursor: pointer;
  transition:
    scale 0.2s var(--ease),
    rotate 0.2s var(--ease);
}

#brush-panel input[name='color']:nth-of-type(3n) {
  border-radius: 55% 45% 52% 48% / 45% 55% 45% 55%;
}

#brush-panel input[name='color']:nth-of-type(3n + 1) {
  border-radius: 44% 56% 50% 50% / 50% 44% 56% 50%;
}

#brush-panel input[name='color']:hover {
  scale: 1.08;
  rotate: -6deg;
}

#brush-panel input[name='color']:active {
  scale: 0.96;
}

#brush-panel input[name='color']:checked {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  scale: 1.04;
}

/* Size: a wedge from thin to thick, filled in the brush color up to the
   current size (--fill is set by draw.js). */
.size {
  position: relative;
}

.size::before,
.size::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0.75rem;
  right: 0.75rem;
  height: 0.875rem;
  translate: 0 -50%;
  clip-path: polygon(0 42%, 97% 0, 100% 25%, 100% 75%, 97% 100%, 0 58%);
  background: #e8e8e4;
}

.size::after {
  background: var(--color);
  mask: linear-gradient(90deg, #000 var(--fill), transparent 0);
}

#brush-size {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 2.75rem;
  margin: 0;
  background: transparent;
  appearance: none;
  cursor: pointer;
}

#brush-size:focus-visible {
  outline: none;
}

#brush-size::-webkit-slider-thumb {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--lift);
  appearance: none;
}

#brush-size::-moz-range-thumb {
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--lift);
}

#brush-size:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

#brush-size:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  #brush-panel,
  #brush-panel *,
  #brush-panel *::before {
    transition: none !important;
  }

  @view-transition {
    navigation: none;
  }
}
