/* The split-flap button: a row of tiles like a departures board, on a black page. Each tile is cut in two at the
   middle; turning, its upper flap falls and the next letter's lower flap lands on it. */
:root {
  --page: #000000;          /* the page */
  --case: #151515;          /* the case around the tiles */
  --tile-top: #2b2b2b;      /* a tile, upper half */
  --tile-bottom: #1f1f1f;   /* a tile, lower half */
  --letter: #f1ede4;        /* the letters at rest */
  --lit: #ffc93d;           /* the letters of the other words */
  --gap: 4px;               /* between two tiles */
  --count: 8;               /* set by the script: how many tiles */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--letter);
  font-family: 'Oswald Variable', 'Arial Narrow', sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 16px;
}

/* ---------------------------------------------------------------- the case */
.board {
  --w: min(50px, calc((100vw - 32px - 24px - (var(--count) - 1) * var(--gap)) / var(--count)));
  --h: calc(var(--w) * 1.42);
  display: inline-block;
  padding: 12px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #1c1c1c, var(--case));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 24px 48px -24px rgba(255, 255, 255, 0.08);
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.board:focus-visible {
  outline: 2px solid var(--lit);
  outline-offset: 5px;
}

.board__tiles {
  display: flex;
  gap: var(--gap);
}

/* ---------------------------------------------------------------- a tile */
.tile {
  position: relative;
  width: var(--w);
  height: var(--h);
  perspective: calc(var(--h) * 4);
}

/* the two pins the flaps turn on, at the sides of the cut */
.tile::before,
.tile::after {
  content: '';
  position: absolute;
  top: 50%;
  z-index: 4;
  width: 3px;
  height: calc(var(--h) * 0.14);
  margin-top: calc(var(--h) * -0.07);
  border-radius: 1px;
  background: #0b0b0b;
}

.tile::before {
  left: 0;
}

.tile::after {
  right: 0;
}

/* the four halves: the upper and the lower one that stay, and the two flaps that turn */
.half,
.flap {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(50% - 1px);
  overflow: hidden;
}

.half--top,
.flap--top {
  top: 0;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, #303030, var(--tile-top));
}

.half--bottom,
.flap--bottom {
  bottom: 0;
  border-radius: 2px 2px 5px 5px;
  background: linear-gradient(180deg, var(--tile-bottom), #191919);
}

.flap {
  z-index: 2;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flap--top {
  transform-origin: 50% 100%;
}

.flap--bottom {
  transform-origin: 50% 0%;
}

/* a letter is as tall as the whole tile: the upper halves show its top, the lower ones its bottom */
.char {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: var(--h);
  font-size: calc(var(--h) * 0.7);
  font-weight: 600;
  line-height: var(--h);
  text-align: center;
  color: var(--letter);
}

.half--bottom .char,
.flap--bottom .char {
  top: calc(var(--h) / -2 - 1px);
}

.char.is-lit {
  color: var(--lit);
}

/* the shadow on a half or a flap while the flap above it turns */
.shade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}
