/* Tile faces, shared by the game (index.html) and the gallery (tiles.html). paintFace in
   palette.mjs sets the custom properties and, past 4096, a data-tier for the special tiles. */
.g-face {
  position: relative; width: 100%; height: 100%; display: grid; place-items: center;
  border-radius: calc(var(--cell) * .14); overflow: hidden; isolation: isolate;
  background: var(--tbg); color: var(--tfg);
  font: 400 var(--fs) / 1 var(--font-display, Bungee, "Arial Black", sans-serif); letter-spacing: -.02em;
  box-shadow: inset 0 calc(var(--cell) * -.07) 0 rgba(0,0,0,.26), inset 0 2px 0 rgba(255,255,255,.22), 0 0 var(--glowR, 0) var(--tglow, transparent);
  user-select: none;
}
.g-face[data-tier]::before, .g-face[data-tier]::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; z-index: -1; pointer-events: none;
}

/* Every special tile animates only transform and opacity, which the GPU does without
   redrawing. Animating backgrounds, filters, conic angles or self-animating SVG made the
   gallery use 20-40% CPU per tile and lag. */

/* 8192: foil, a slowly turning rainbow (a big conic disc spinning under the tile) */
.g-face[data-tier="foil"] { background: #c79bff; color: #3a1670; }
.g-face[data-tier="foil"]::before {
  inset: -50%; border-radius: 0;
  background: conic-gradient(#ff8fd1, #ffe27a, #8ff7c8, #8fd3ff, #c79bff, #ff8fd1);
  animation: g-turn 6s linear infinite;
}

/* 16384: lava, plates of dark crust split by glowing cracks that throb with heat.
   art/lava.svg is the crust and cracks; art/lava-glow.svg is the cracks blurred. */
.g-face[data-tier="molten"] {
  background: #0e0302 url(art/lava.svg) center / cover;
  color: #fff4d6;
  text-shadow: 0 0 calc(var(--cell) * .03) #1c0603, 0 0 calc(var(--cell) * .03) #1c0603, 0 0 calc(var(--cell) * .12) #ff7a1a;
}
.g-face[data-tier="molten"]::before {
  background: url(art/lava-glow.svg) center / cover;
  mix-blend-mode: screen;
  animation: g-heat 2.6s ease-in-out infinite alternate;
}
.g-face[data-tier="molten"]::after { box-shadow: inset 0 0 calc(var(--cell) * .16) rgba(0, 0, 0, .6); z-index: 0; }

/* 32768: aurora, curtains of green light rippling over a night sky, their tops fading to violet.
   art/aurora.svg is one curtain, periodic across its width. Two strips of it slide sideways at
   different speeds (the back one blurred, for the glow), slowly; mostly the curtain's light
   surges and fades. (Fading the blurred layer itself made the browser redraw it every frame.) */
.g-face[data-tier="aurora"] {
  background: radial-gradient(1px 1px at 12% 18%, #fff 99%, transparent),
    radial-gradient(1px 1px at 82% 12%, #fff 99%, transparent),
    radial-gradient(1.2px 1.2px at 64% 30%, #fff 99%, transparent),
    radial-gradient(1px 1px at 30% 40%, #fff 99%, transparent),
    radial-gradient(1px 1px at 90% 46%, #fff 99%, transparent),
    radial-gradient(1px 1px at 46% 8%, #fff 99%, transparent),
    linear-gradient(to bottom, #040818, #071430 55%, #0a2a2c);
  color: #f2fff6;
  text-shadow: 0 0 calc(var(--cell) * .03) #031a10, 0 0 calc(var(--cell) * .03) #031a10, 0 0 calc(var(--cell) * .14) #39ff9e;
}
.g-face[data-tier="aurora"]::before, .g-face[data-tier="aurora"]::after {
  inset: 0 auto 0 0; width: calc(var(--cell) * 6); border-radius: 0;
  background: url(art/aurora.svg) 0 0 / calc(var(--cell) * 2) 100% repeat-x;
}
.g-face[data-tier="aurora"]::before { animation: g-slide2 55s linear infinite, g-surge 10s ease-in-out infinite; }
.g-face[data-tier="aurora"]::after {
  background-size: calc(var(--cell) * 2) 92%; background-position: 0 -8%;
  filter: blur(calc(var(--cell) * .07)) saturate(1.4); mix-blend-mode: screen; z-index: 0; opacity: .85;
  animation: g-slide2 85s linear infinite reverse;
}

/* 65536: a black hole, as in the Interstellar pictures. It's ray-traced (art/blackhole-render.mjs),
   so the accretion disk bends around the shadow the way gravity bends it: the far side arcs over
   the top and under the bottom, the near side crosses in front. art/blackhole-spin.webp is 24
   frames of the disk turning, in a 6 × 4 grid; the tile slides the grid one frame at a time
   (steps() on transforms, so no redraw): .g-rows steps down a row while .g-strip steps
   across its six frames. Behind it, clouds of orange gas (art/blackhole-sky.svg)
   breathe and sway; over it, a blurred copy of its light pulses. */
.g-face[data-tier="blackhole"] { background: #050201; color: #ffffff;
  text-shadow: 0 0 calc(var(--cell) * .035) #000, 0 0 calc(var(--cell) * .035) #000, 0 0 calc(var(--cell) * .14) #ff9a3a; }
.g-face[data-tier="blackhole"]::after {
  inset: -14%; z-index: -2; border-radius: 0;
  background: url(art/blackhole-sky.svg) center / cover;
  animation: g-sway 20s ease-in-out infinite alternate, g-clouds 4.5s ease-in-out infinite alternate;
}
.g-face[data-tier="blackhole"] .g-fx { position: absolute; inset: -4%; z-index: -1; pointer-events: none; }
.g-face[data-tier="blackhole"] .g-fx[data-fx="spin"] { overflow: hidden; animation: g-hover 9s ease-in-out infinite alternate; }
.g-face[data-tier="blackhole"] .g-rows {
  position: absolute; left: 0; top: 0; width: 100%; height: 400%;
  animation: g-rows 2.6s steps(4) infinite;
}
.g-face[data-tier="blackhole"] .g-strip {
  position: absolute; left: 0; top: 0; width: 600%; height: 100%;
  background: url(art/blackhole-spin.webp) 0 0 / 100% 100% no-repeat;
  animation: g-frames .65s steps(6) infinite;
}
.g-face[data-tier="blackhole"] .g-fx[data-fx="glow"] {
  background: url(art/blackhole-glow.webp) center / contain no-repeat;
  mix-blend-mode: screen;
  animation: g-hover 9s ease-in-out infinite alternate, g-halo 2.8s ease-in-out infinite alternate;
}

/* 131072, the biggest tile the game can make: a spiral galaxy, tilted and slowly turning, in
   front of a star field */
.g-face[data-tier="galaxy"] {
  background: radial-gradient(circle at 50% 50%, #120a33, #04020e 75%);
  color: #ffffff;
  text-shadow: 0 0 calc(var(--cell) * .03) #04020e, 0 0 calc(var(--cell) * .03) #04020e, 0 0 calc(var(--cell) * .14) #8a7dff;
}
.g-face[data-tier="galaxy"]::before {
  inset: -14%; border-radius: 0;
  background: url(art/galaxy.svg) center / contain no-repeat;
  animation: g-galaxy 40s linear infinite;
}
.g-face[data-tier="galaxy"]::after {
  z-index: -2;
  background: radial-gradient(1px 1px at 12% 18%, #fff 99%, transparent),
    radial-gradient(1px 1px at 82% 12%, #fff 99%, transparent),
    radial-gradient(1.2px 1.2px at 64% 30%, #fff 99%, transparent),
    radial-gradient(1px 1px at 30% 40%, #fff 99%, transparent),
    radial-gradient(1px 1px at 90% 46%, #fff 99%, transparent),
    radial-gradient(1px 1px at 46% 8%, #fff 99%, transparent);
}

@keyframes g-turn { to { transform: rotate(360deg); } }
@keyframes g-heat { 0% { opacity: .2; } 100% { opacity: .85; } }
@keyframes g-slide2 { to { transform: translateX(calc(var(--cell) * -2)); } }
@keyframes g-surge { 0% { opacity: .35; } 30% { opacity: 1; } 45% { opacity: .7; } 60% { opacity: 1; } 100% { opacity: .35; } }
@keyframes g-galaxy { from { transform: scaleY(.72) rotate(0deg); } to { transform: scaleY(.72) rotate(-360deg); } }
@keyframes g-twinkle { from { opacity: .25; } to { opacity: 1; } }
@keyframes g-halo { from { opacity: .35; } to { opacity: 1; } }
@keyframes g-frames { to { transform: translateX(-100%); } }
@keyframes g-rows { to { transform: translateY(-100%); } }
@keyframes g-hover { from { transform: translate(-1%, .5%) rotate(-1.5deg) scale(.99); } to { transform: translate(1%, -.5%) rotate(1.5deg) scale(1.02); } }
@keyframes g-sway { from { transform: rotate(-4deg) scale(1.02); } to { transform: rotate(4deg) scale(1.1); } }
@keyframes g-clouds { from { opacity: .6; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .g-face[data-tier], .g-face[data-tier]::before, .g-face[data-tier]::after, .g-fx, .g-rows, .g-strip { animation: none !important; }
}
