/* The wooden tile title: a games table seen from above at an angle. The world is one 3D plane tilted with
   rotateX; the bag, the rack and every tile live inside it, the felt is the stage behind. The wood of the tiles comes from WOOD
   in script.js; every other colour is a variable here. */
:root {
  --felt: #1d4a43;          /* the felt on the table */
  --felt-deep: #0e2a26;     /* the felt far from the lamp */
  --rack: #7a4a26;          /* the wooden rack the tiles stand on */
  --rack-dark: #4a2a14;     /* its shaded faces */
  --bag: #a3392c;           /* the cloth bag */
  --bag-light: #d0634b;     /* the cloth in the light */
  --bag-dark: #64201a;      /* the cloth in the folds */
  --bag-inside: #2a0d09;    /* inside the open bag */
  --string: #ecdcb8;        /* the drawstring */
  --patch: #efe3c6;         /* the little sewn label */
  --hint: #a9c9bf;          /* the small text */
  --screen: 100vh;
}
@supports (height: 100lvh) {
  :root { --screen: 100lvh; }
}

* { box-sizing: border-box; }
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--felt-deep);
  overflow: hidden;
}

.stage {
  position: relative;
  height: var(--screen);
  overflow: hidden;
  cursor: pointer;
  outline: none;
  background-color: var(--felt);
  background-image: var(--felt-noise), radial-gradient(120% 100% at 50% 40%, var(--felt), var(--felt-deep));
  background-size: 160px 160px, 100% 100%;
  perspective-origin: 50% 28%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.reader {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  margin: 0;
}

/* the world: its origin is the middle of the screen, x to the right, y towards us, z up from the felt */
.world {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transform: rotateX(50deg);
}
.world > * {
  position: absolute;
  left: 0;
  top: 0;
}

/* a shadow is a soft blot on the felt, moved by the script under its tile */
.shadow {
  border-radius: 24%;
  background: radial-gradient(closest-side, rgba(4, 16, 14, 0.62), rgba(4, 16, 14, 0.32) 55%, rgba(4, 16, 14, 0) 100%);
  pointer-events: none;
}
.bag-shadow {
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(4, 16, 14, 0.6), rgba(4, 16, 14, 0));
  pointer-events: none;
}

/* the bag is a picture standing on the felt, turned to face us */
.bag {
  transform-style: preserve-3d;
  pointer-events: none;
}
.bag__tip {
  width: 100%;
  height: 100%;
  transform-origin: 86% 93.2%;
}
.bag__svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  font-family: 'Fraunces Variable', Georgia, serif;
}
.bag__weave { opacity: 0.6; }

/* ---- boxes: the rack and the tiles */
.box,
.box * {
  transform-style: preserve-3d;
}
.face {
  position: absolute;
  left: 0;
  top: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* the rack: the board with the base under it, and the lip that holds the tiles in */
.rack .face--board {
  background:
    linear-gradient(rgba(255, 220, 170, 0.28), rgba(255, 220, 170, 0) 10%),
    linear-gradient(transparent 0, transparent calc(var(--up) * 0.7), rgba(0, 0, 0, 0.32) var(--up), transparent var(--up)),
    linear-gradient(transparent var(--up), var(--rack) var(--up), var(--rack) calc(var(--up) + 22%), var(--rack-dark) calc(var(--up) + 22%), var(--rack-dark) 100%),
    var(--grain) var(--gx) 0 / 420px 140px,
    var(--rack);
}
.rack .face--foot {
  background: linear-gradient(rgba(3, 14, 12, 0.55), rgba(3, 14, 12, 0.22) 45%, rgba(3, 14, 12, 0));
}
.rack__seg--first .face--foot { -webkit-mask-image: linear-gradient(90deg, transparent, #000 60%); mask-image: linear-gradient(90deg, transparent, #000 60%); }
.rack__seg--last .face--foot { -webkit-mask-image: linear-gradient(270deg, transparent, #000 60%); mask-image: linear-gradient(270deg, transparent, #000 60%); }
.rack__seg--first .face--board { border-top-left-radius: calc(var(--up) * 0.14); }
.rack__seg--last .face--board { border-top-right-radius: calc(var(--up) * 0.14); }
.rack__seg--first .face--lip { border-radius: 4px 0 0 7px; }
.rack__seg--last .face--lip { border-radius: 0 4px 7px 0; }
.rack .face--lip {
  background:
    linear-gradient(rgba(255, 224, 178, 0.35), rgba(255, 224, 178, 0) 2px),
    linear-gradient(transparent 0, transparent var(--lu), rgba(0, 0, 0, 0.25) var(--lu), rgba(0, 0, 0, 0) calc(var(--lu) + 3px)),
    linear-gradient(transparent 70%, rgba(0, 0, 0, 0.3)),
    var(--grain) calc(var(--gx) + 37px) 0 / 420px 140px,
    var(--rack);
}

/* a tile: --s is its side, --t its thickness; the top face carries the engraved letter */
.tile {
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}
.tile__lift,
.tile__body {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}
.tile .face {
  background-color: var(--wood);
  background-image: var(--grain);
  background-size: calc(var(--s) * 4.2) calc(var(--s) * 1.6);
}
.tile .face--top,
.tile .face--bottom {
  width: var(--s);
  height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  border-radius: calc(var(--s) * 0.09);
}
.tile .face--top {
  pointer-events: auto;
  display: grid;
  place-items: center;
  transform: translateZ(calc(var(--t) / 2));
  box-shadow: inset 0 0 0 1px rgba(255, 238, 205, 0.28), inset calc(var(--s) * 0.04) calc(var(--s) * 0.05) calc(var(--s) * 0.06) rgba(255, 240, 210, 0.35), inset calc(var(--s) * -0.04) calc(var(--s) * -0.05) calc(var(--s) * 0.08) rgba(70, 35, 10, 0.32);
}
.tile .face--bottom {
  transform: rotateY(180deg) translateZ(calc(var(--t) / 2));
  filter: brightness(0.86);
  box-shadow: inset 0 0 0 1px rgba(70, 35, 10, 0.25);
}
.tile .face--ns {
  width: var(--s);
  height: var(--t);
  margin: calc(var(--t) / -2) 0 0 calc(var(--s) / -2);
  background-color: var(--wood-edge);
  background-image: repeating-linear-gradient(90deg, rgba(80, 40, 10, 0.18) 0 1px, transparent 1px 5px);
  background-size: auto;
}
.tile .face--s { transform: translateY(calc(var(--s) / 2)) rotateX(-90deg); }
.tile .face--n { transform: translateY(calc(var(--s) / -2)) rotateX(90deg); filter: brightness(1.12); }
.tile .face--we {
  width: var(--t);
  height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--t) / -2);
  background-color: var(--wood-edge);
  background-image: repeating-linear-gradient(0deg, rgba(80, 40, 10, 0.2) 0 1px, transparent 1px 4px);
  background-size: auto;
}
.tile .face--e { transform: translateX(calc(var(--s) / 2)) rotateY(90deg); filter: brightness(0.82); }
.tile .face--w { transform: translateX(calc(var(--s) / -2)) rotateY(-90deg); filter: brightness(1.05); }

/* the letter is cut into the wood: darker, with light on the lower lip of the cut and shade on the upper one */
.letter {
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: calc(var(--s) * 0.62);
  font-weight: 640;
  line-height: 1;
  color: var(--engrave);
  text-shadow: 0 calc(var(--s) * 0.014) 0 rgba(255, 240, 212, 0.55), 0 calc(var(--s) * -0.012) 0 rgba(60, 28, 6, 0.4);
  transform: translateY(calc(var(--s) * 0.02));
}

/* the lamp over the table: light in the middle, darker corners */
.lamp {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, rgba(255, 236, 196, 0.08), rgba(255, 236, 196, 0) 45%, rgba(0, 0, 0, 0.42) 100%);
}

.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 13px;
  font-style: italic;
  font-weight: 420;
  letter-spacing: 0.01em;
  text-align: center;
  color: var(--hint);
  pointer-events: none;
  opacity: 0;
}
