/* Fonts */

@font-face {
  font-family: "TT Norms Pro";
  font-style: normal;
  font-weight: 400;
  src: url("https://assets.htmlacademy.ru/fonts/tt-norms-pro-400-normal.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "TT Norms Pro";
  font-style: italic;
  font-weight: 400;
  src: url("https://assets.htmlacademy.ru/fonts/tt-norms-pro-400-italic.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "TT Norms Pro";
  font-style: normal;
  font-weight: 700;
  src: url("https://assets.htmlacademy.ru/fonts/tt-norms-pro-700-normal.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "TT Norms Pro";
  font-style: italic;
  font-weight: 700;
  src: url("https://assets.htmlacademy.ru/fonts/tt-norms-pro-700-italic.woff2") format("woff2");
  font-display: swap;
}


/* Global settings */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  --color-1: #C7B2FF;
  --color-2: #642EFF;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 320px;
  min-height: 500px;
  margin: 0;

  font-family: "TT Norms Pro", sans-serif;
  color: white;

  background: white;
  background-image: repeating-radial-gradient(circle at center center, transparent 0px, transparent 2px,rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 3px,transparent 3px, transparent 5px,rgba(0,0,0,0.03) 5px, rgba(0,0,0,0.03) 7px),repeating-radial-gradient(circle at center center, rgb(255,255,255) 0px, rgb(255,255,255) 9px,rgb(255,255,255) 9px, rgb(255,255,255) 21px,rgb(255,255,255) 21px, rgb(255,255,255) 31px,rgb(255,255,255) 31px, rgb(255,255,255) 40px); background-size: 20px 20px;
}


/* Formula bar */

.formula {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  padding: 40px 0px;
  max-width: 380px;
  gap: 10px;
  color: #222;
}

.formula--wider .formula {
  max-width: 420px;
}

.formula-preview {
  width: 100%;
  margin-bottom: 10px;
  text-align: center;
  font-size: 30px;
  line-height: 35px;
  font-weight: bold;
  color: var(--color-2);
}

.formula-params {
  color: #333;
}

.formula button {
  padding: 10px 14px;
  font: inherit;
  text-align: center;
  color: #333;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 5px;
}

.formula button:active {
  color: white;
  background: rgba(0, 0, 0, 0.5);
}

.formula button.current {
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.7);
}

.formula-custom {
  display: none;
}

.custom .formula-custom {
  display: block;
}

.custom .formula-regular {
  display: none;
}

/* Cards */

.cards-list {
  display: flex;
  flex-wrap: wrap;
  gap: 15px 15px;
  justify-content: center;

  width: 380px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cards-list--narrow .cards-list {
  width: 300px;
}

li {
  position: relative;
  perspective: 1000px;

  --delay-step: 0.5s;
  --n-reveal-delay: 0.5s;
  --n-reveal-duration: 1.5s;
  --global-delay: 0s;
  --open: 0;
  --delay: calc(var(--global-delay) + var(--i) * var(--delay-step));

  animation-fill-mode: both;
}

li::before {
  content:  "n=" counter(n-index); 

  position: absolute;
  z-index: 10;

  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  padding-top: 2px;
  margin-top: 75px;
  margin-left: 10px;

  font-size: 20px;
  line-height: 40px;
  font-weight: bold;

  color: #333;

  background-color: white;
  border-radius: 5px;
  box-shadow: inset 0 0 0 2px var(--color-2);
  
  opacity: 0;
  animation-name: reveal;
  animation-duration: var(--n-reveal-duration);
  animation-delay: calc(var(--delay) - var(--n-reveal-delay)); 
  animation-timing-function: cubic-bezier(0.25, 1.5, 0.5, 1);
}

.no-counter li::before {
  content: none;
}

@keyframes reveal {
  0% {opacity: 0;}
  100% {opacity: var(--open);}
}

li.reset-animation::before {
  animation-name: none !important;
}

.card {
  position: relative;
  flex-shrink: 0;
  width: 80px;
  height: 110px;
  padding: 20px;
  transform-style: preserve-3d;
  transition: transform 1s cubic-bezier(0.25, 1.5, 0.5, 1);

  animation-name: open;
  animation-duration: calc(0.5s);
  animation-delay: var(--delay); 
  animation-timing-function: cubic-bezier(0.25, 1.5, 0.5, 1);
  animation-fill-mode: forwards;
}

@keyframes open {
  0% {transform: rotateY(0deg);}
  100% {transform: rotateY(calc(180deg * var(--open)));}
}

.card::before,
.card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 5px;
  box-shadow: inset 0 0 1px #999, 0 2px 5px rgba(0, 0, 0, 0.2);
  background-color: #333;
}

.card::before {
  background-size: 50% auto;
  background-repeat: no-repeat;
  background-position: center;
  background-image: url("keks.png");
  background-color: var(--color-1);
  border-radius: 3px;
  color: rgba(255, 255, 255, 0.5);
}

.card::after {
  content: counter(cardnumber);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: bold;
  transform: rotateY(180deg);
}

.cards-list {
  counter-reset: cardnumber n-index 0; 
}

.card {
  counter-increment: cardnumber;
}

@media (max-width: 400px) {
  .cards-list {
    width: 90%;
    gap: 4%;
  }

  .cards-list li {
    width: 20%;
  }

  .cards-list--narrow .cards-list {
    max-width: 300px;
  }

  .cards-list--narrow .cards-list li {
    width: 28%;
  }

  .card {
    width: 100%;
    height: auto;
    aspect-ratio: 2/3;
  }

  .card::after {
    font-size: 20px;
  }

  li::before {
    content:  "n=" counter(n-index); 

    width: 80%;
    bottom: -5px;
    left: 50%;
    margin-top: 0;
    margin-left: -40%;

    font-size: 12px;
    line-height: 30px;
    font-weight: bold;
  }
}


/* Restart btn */

#restart-btn {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 1000;

  padding: 12px 24px;

  font-size: 16px;
  color: #fff;
  background-color: #333;
  
  border: 2px solid #666;
  border-radius: 5px;
  cursor: pointer;
  transform: translateX(-50%);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  transition: all 0.3s ease;
}

#restart-btn:hover {
  color: #333;
  background-color: white;
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

#restart-btn:active {
  transform: translateX(-50%) scale(0.98);
  box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}