:root {
  /* One printed glyph sits in one square cell; everything scales from this. */
  --cell: clamp(4.5rem, 17vmin, 12rem);
  --gutter: clamp(0.75rem, 3vmin, 2.5rem);
}

html,
body {
  height: 100%;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* The page of printed glyphs sits in the middle while it is short. Once it is
   taller than the screen it hangs from the bottom edge and old rows leave off
   the top, like paper feeding out of a printer. The two flexible spacers do
   the centring and collapse to nothing when the page overflows. */
.stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  padding:
    max(var(--gutter), env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(var(--gutter), env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

.stage::before,
.stage::after {
  content: "";
  flex: 1 1 0;
}

.page {
  position: relative;
  flex: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--cell), 1fr));
  grid-auto-rows: var(--cell);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  font-size: calc(var(--cell) * 0.84);
  font-weight: 600;
  line-height: 1;
}

/* The glyph after a Return starts a new row. */
.line-start {
  grid-column-start: 1;
}

.glyph {
  display: block;
  transform: rotate(var(--tilt, 0deg));
  text-shadow: 0 0.05em 0 var(--depth);
  animation: stamp 0.34s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.glyph svg {
  display: block;
  width: 0.8em;
  height: 0.8em;
  overflow: visible;
  filter: drop-shadow(0 0.05em 0 var(--depth));
}

.is-space svg {
  filter: none;
  opacity: 0.55;
}

.flower-eye {
  fill: var(--paper);
}

.point-right { rotate: 90deg; }
.point-down { rotate: 180deg; }
.point-left { rotate: 270deg; }

@keyframes stamp {
  from {
    opacity: 0;
    transform: rotate(var(--tilt, 0deg)) scale(2.6);
  }
  45% {
    opacity: 1;
    transform: rotate(var(--tilt, 0deg)) scale(0.88);
  }
  70% {
    transform: rotate(var(--tilt, 0deg)) scale(1.06);
  }
}

.spark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.13em;
  height: 0.13em;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
}

.fx {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.fx .cell {
  position: absolute;
}

/* Moving a cell here would replay its stamp. */
.fx .glyph {
  animation: none;
}

.fx .spark {
  display: none;
}

.hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.5rem;
  padding: var(--gutter);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.is-empty .hint {
  opacity: 1;
}

.hint p {
  margin: 0;
}

.hint-big {
  font-size: clamp(2.25rem, 9vmin, 5.5rem);
  font-weight: 600;
  line-height: 1.1;
  animation: bob 1.8s ease-in-out infinite;
}

.hint-small {
  color: var(--muted);
  font-size: clamp(1rem, 3vmin, 1.5rem);
}

@keyframes bob {
  50% {
    transform: translateY(-0.12em);
  }
}

.controls {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  display: flex;
  gap: 0.4rem;
  transition: opacity 0.3s;
}

.control {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: color-mix(in oklab, var(--paper) 82%, transparent);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}

.control:hover {
  background: color-mix(in oklab, var(--ink) 10%, var(--paper));
  color: var(--ink);
}

.control[hidden] {
  display: none;
}

.control svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.control[aria-pressed="true"] .when-off,
.control[aria-pressed="false"] .when-on {
  display: none;
}

/* While the keyboard is busy, get the grown-up controls and the pointer out
   of the way. Moving the mouse or touching the screen brings them back. */
.is-quiet {
  cursor: none;
}

.is-quiet .controls {
  opacity: 0;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .glyph {
    animation: appear 0.15s backwards;
  }

  .hint-big {
    animation: none;
  }

  @keyframes appear {
    from {
      opacity: 0;
    }
  }
}
