:root {
  counter-set:
    countdown 10
    second 2 /* used with the seconds counter-style */
  ;
}

body {
  /* Centre the main element */
  height: 100vh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;

  color: #ddd;
  background: #222;

  /* Story-telling properties */
  animation: timer 10s step-end forwards paused;
  --display: none;
}

/* Create a main element at the default size of an iframe */
main {
  position: relative;
  width: 300px;
  height: 150px;
  border: 1px solid #fff;
  border-radius: 8px;
  box-sizing: border-box;
  background-color: #030;
  overflow: hidden;
}

label,
div {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
}

span {
  text-align: center; /* cosmetic */
}
span::before {
  content: "My hero!";
  display: block;
}
/* Use an admiring message */
span::after {
  content: "You saved us all... with only " counter(countdown) counter(second, seconds) " to go!"
}

/* Wrap the rules for spans inside the rule that selects the
 * body only when the checbox is not checked.
 */
body:has(input:not(:checked)) {
  animation-play-state: running;

  span::before {
    content: "Click me! Before it's too late...";
  }

  span::after {
    content: "We have only " counter(countdown) counter(second, seconds) " left!";
  }
}

div {
  background-color: #900;
  display: var(--display);
}

/* Make the Replay button more discrete */
a.replay {
  position: absolute;
  top: 0.5em;
  left: 0.5em;
  color: inherit;
  opacity: 0.5;
}
a:hover {
  opacity: 1;
}

/* Show the GitHub logo */
a.github {
  width: 0;
  height: 0;

  img {
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 32px;
    height: 32px;
    filter: grayscale(1);
    opacity: 0.25;

    &:hover {
      opacity: 1;
    }
  }
}

/* Create a counter-style to use "2 seconds" and "1 second"
 * correctly. Use a non-breaking space between the number
 * and "seconds" so that the whole chunk "X seconds" will 
 * wrap to the next line together.
 */
@counter-style seconds {
  system: cyclic;
  symbols: "\00A0second" "\00A0seconds";
}

@keyframes timer {
   0% { counter-increment: countdown   0; }
  10% { counter-increment: countdown  -1; }
  20% { counter-increment: countdown  -2; }
  30% { counter-increment: countdown  -3; }
  40% { counter-increment: countdown  -4; }
  50% { counter-increment: countdown  -5; }
  60% { counter-increment: countdown  -6; }
  70% { counter-increment: countdown  -7; }
  80% { counter-increment: countdown  -8; }
  90% { counter-increment: countdown  -9 second -1;
      }
 100% { counter-increment: countdown -10;
        --display: flex;
      }
}