:root {
  --flipColour: white;
  --flipColourDark: brightness(35%);
  --textColour: black;
  --textColourDark: brightness(35%);
}

.clock {
  width: max-content;
  display: flex;
  margin: 0 auto;
  align-items: center;
}

.clock h1 {
  font-size: 1em;
  margin: 0 0.5em;
  color: white;
}

.digit {
  position: relative;
  float: left;
  width: 1em;
  height: 1.2em;
  background-color: var(--flipColour);
  border-radius: 0.25em;
  text-align: center;
  font-family: Oswald, sans-serif;
  font-weight: 600;
  font-size: 1.25em;
  margin-right: 0.15em;
}

.base {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--textColour);
}

.flap {
  display: none;
  position: absolute;
  width: 100%;
  height: 50%;
  background-color: var(--flipColour);
  left: 0;
  top: 0;
  border-radius: 0.25em 0.25em 0 0;
  transform-origin: 50% 100%;
  backface-visibility: hidden;
  overflow: hidden;
}

.flap::before {
  content: attr(data-content);
  position: absolute;
  left: 50%;
}

.flap.front::before,
.flap.under::before {
  top: 100%;
  transform: translate(-50%, -50%);
}

.flap.back {
  transform: rotateY(180deg);
}

.flap::before {
  top: 100%;
  transform: translate(-50%, -50%) rotateZ(180deg);
}

.flap.over {
  z-index: 2;
}

.flap.under {
  z-index: 1;
}

.flap.front {
  animation: flip-down-front 300ms ease-in both;
}

.flap.back {
  animation: flip-down-back 300ms ease-in both;
}

.flap.under {
  animation: fade-under 300ms ease-in both;
}

@keyframes flip-down-front {
  0% {
    transform: rotateX(0deg);
    filter: var(--flipColour);
  }
  100% {
    transform: rotateX(-180deg);
    filter: var(--flipColourDark);
  }
}

@keyframes flip-down-back {
  0% {
    transform: rotateY(180deg) rotateX(0deg);
    filter: var(--flipColourDark);
  }
  100% {
    transform: rotateY(180deg) rotateX(180deg);
    filter: var(--flipColour);
  }
}

@keyframes fade-under {
  0% {
    filter: var(--flipColourDark);
  }
  100% {
    filter: var(--flipColour);
  }
}

@media screen and (min-width: 768px) {
  .digit {
    font-size: 1.5em;
  }

  .clock h1 {
    font-size: 1.2em;
    margin: 0 0.5em;
  }
}

@media screen and (min-width: 1024px) {
  .clock h1 {
    font-size: 1.5em;
    margin: 0 0.5em;
  }

  .digit {
    font-size: 1.8em;
  }
}
