:root {
  --px: 3; /* one "pixel" in CSS px: background, tiles, icons and crumbs */
  --tile-color: #7a4022;
  --icon-color: #f3dbb5;
  --tile-size: 132px;
  --tile-depth: 21px; /* sizes are whole multiples of --px */
  --cream: #eadbc6;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--cream);
  background: radial-gradient(ellipse at 50% 45%, #22120a 0%, #0e0603 50%, #040100 100%) fixed;
  min-height: 100vh;
  overflow-x: hidden;
}

/* WebGL background: rendered at 1/--px resolution and scaled up with hard edges
   (background.js sets the exact size); fades in once the first frame renders */
#bg {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  opacity: 0;
  transition: opacity 1.2s ease;
  pointer-events: none;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
#bg.ready { opacity: 1; }

/* vignette keeps the tiles the brightest thing on screen */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 30%, rgba(3, 1, 0, 0.75) 100%);
}

main {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem 1rem;
  min-height: 100vh;
}

/* kept for screen readers; there is no visible heading */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  width: min(94vw, 560px);
  height: 600px;
  display: grid;
  place-items: center;
  perspective: 1300px;
  user-select: none;
  -webkit-user-select: none;
  opacity: 0; /* faded in by script.js as the entrance starts */
}

/* warm halo behind the tiles; a filter on the tiles themselves would flatten the 3D */
.glow {
  position: absolute;
  width: 380px;
  height: 540px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 130, 55, 0.3), rgba(220, 90, 40, 0.1) 55%, transparent);
  filter: blur(28px);
  animation: pulse 4.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse {
  0%, 100% { opacity: 0.7; transform: scale(0.96); }
  50%      { opacity: 1;   transform: scale(1.04); }
}
/* flare as the slab breaks */
.stage.broken .glow { animation: flare 1.2s ease-out, pulse 4.5s ease-in-out 1.2s infinite; }
@keyframes flare {
  0%   { opacity: 1;   transform: scale(1.3); filter: blur(22px) brightness(1.7); }
  100% { opacity: 0.7; transform: scale(0.96); filter: blur(28px) brightness(1); }
}

.shadow {
  position: absolute;
  bottom: 18px;
  width: 230px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.75), transparent);
  pointer-events: none;
  transition: transform 0.9s ease;
}
.stage.broken .shadow { transform: scaleX(1.3); }

/* these containers sit in the z=0 plane; when tilted, they'd cover parts of the
   faces and swallow taps, so only the faces receive pointers */
.scaler { transform-style: preserve-3d; pointer-events: none; }

.bar {
  position: relative;
  display: block;
  width: calc(var(--tile-size) * 2);
  height: calc(var(--tile-size) * 3);
  transform-style: preserve-3d;
  will-change: transform;
}

/* ---------- tiles: pixel-art chocolate, one link each ---------- */

.tile {
  --ink: var(--icon-color);
  position: absolute;
  left: calc(var(--tile-size) * var(--col));
  top: calc(var(--tile-size) * var(--row));
  width: var(--tile-size);
  height: var(--tile-size);
  transform-style: preserve-3d;
  pointer-events: none; /* see .scaler */
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.tile > span {
  position: absolute; /* blockified, so .tf can still be a grid */
  pointer-events: auto;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
/* textures from script.js: one canvas pixel per --px, scaled up with hard edges */
.tile canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.tf {
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  transform: translateZ(calc(var(--tile-depth) / 2));
  transition: color 0.2s ease;
}
.tf svg { position: relative; display: block; fill: currentColor; }

/* hover and focus turn the piece into white chocolate with a dark icon */
.tf canvas.white { opacity: 0; transition: opacity 0.2s ease; }
.stage.broken .tile:focus-visible,
.stage.broken .tile:active { --ink: var(--tile-color); }
.stage.broken .tile:focus-visible .white,
.stage.broken .tile:active .white { opacity: 1; }
@media (hover: hover) {
  .stage.broken .tile:hover { --ink: var(--tile-color); }
  .stage.broken .tile:hover .white { opacity: 1; }
}

.tb { inset: 0; transform: rotateY(180deg) translateZ(calc(var(--tile-depth) / 2)); }

/* side walls, one pixel short of the bar's rounded outer corners */
.te.l, .te.r { left: calc(50% - var(--tile-depth) / 2); width: var(--tile-depth); }
.te.t, .te.b { top: calc(50% - var(--tile-depth) / 2); height: var(--tile-depth); }
.te.l {
  top: calc(var(--o-tl) * var(--px) * 1px);
  bottom: calc(var(--o-bl) * var(--px) * 1px);
  transform: rotateY(-90deg) translateZ(calc(var(--tile-size) / 2));
}
.te.r {
  top: calc(var(--o-tr) * var(--px) * 1px);
  bottom: calc(var(--o-br) * var(--px) * 1px);
  transform: rotateY(90deg) translateZ(calc(var(--tile-size) / 2));
}
.te.t {
  left: calc(var(--o-tl) * var(--px) * 1px);
  right: calc(var(--o-tr) * var(--px) * 1px);
  transform: rotateX(90deg) translateZ(calc(var(--tile-size) / 2));
}
.te.b {
  left: calc(var(--o-bl) * var(--px) * 1px);
  right: calc(var(--o-br) * var(--px) * 1px);
  transform: rotateX(-90deg) translateZ(calc(var(--tile-size) / 2));
}

/* ---------- the break ---------- */

.crack {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  background: var(--icon-color);
  box-shadow: 0 0 8px 1px rgba(255, 200, 140, 0.6);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.crack.v {
  left: calc(var(--tile-size) - var(--px) * 0.5px);
  top: 0;
  width: calc(var(--px) * 1px);
  height: 100%;
}
.crack.h1, .crack.h2 { left: 0; width: 100%; height: calc(var(--px) * 1px); }
.crack.h1 { top: calc(var(--tile-size) - var(--px) * 0.5px); }
.crack.h2 { top: calc(var(--tile-size) * 2 - var(--px) * 0.5px); }

.crumb { position: absolute; pointer-events: none; } /* colour set by script.js */

/* ---------- email dialog ---------- */

.email-dialog {
  width: min(92vw, 440px);
  border: 3px solid var(--tile-color);
  border-radius: 0;
  padding: 1.5rem;
  color: var(--cream);
  background: #1a0d07;
  box-shadow: 9px 9px 0 rgba(0, 0, 0, 0.6);
}
.email-dialog::backdrop { background: rgba(5, 2, 1, 0.75); }
.email-dialog h2 { margin: 0 0 1rem; }
.email-dialog label { display: grid; gap: 0.35rem; margin-bottom: 0.9rem; font-size: 0.9rem; }
.email-dialog input, .email-dialog textarea {
  font: inherit;
  color: inherit;
  padding: 0.6rem 0.75rem;
  border-radius: 0;
  border: 3px solid rgba(255, 255, 255, 0.13);
  background: rgba(0, 0, 0, 0.35);
  resize: vertical;
}
.email-dialog input:focus, .email-dialog textarea:focus { outline: none; border-color: var(--icon-color); }
.address { font-size: 0.85rem; opacity: 0.75; margin: 0 0 1rem; }
.address a { color: var(--icon-color); }
.actions { display: flex; justify-content: flex-end; gap: 0.75rem; }
.actions button {
  font: inherit;
  padding: 0.6rem 1.1rem;
  border-radius: 0;
  border: 0;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6);
}
.actions button:active { transform: translate(3px, 3px); box-shadow: none; }
.actions .ghost { background: transparent; color: var(--cream); border: 3px solid rgba(255, 255, 255, 0.2); }
.actions .primary { background: var(--tile-color); color: var(--icon-color); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .glow, .stage.broken .glow { animation: none; }
}

/* ---------- small screens ---------- */

@media (max-width: 560px), (max-height: 760px) {
  .stage { height: 470px; }
  .scaler { transform: scale(0.82); }
  .glow { width: 320px; height: 460px; }
  .shadow { bottom: 2px; width: 190px; }
}

/* the WebGL background draws its own pixel-art glow, shadow and vignette */
.bg-ready .glow,
.bg-ready .shadow,
.bg-ready body::after { display: none; }
