:root {
  --main-color: #fdffb6;
  --second-color: #ffaaff;
}

html {
  scrollbar-color: var(--second-color) var(--main-color);
}

body {
  text-align: center;
  font-family: "Balsamiq Sans", sans-serif;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(
    120deg,
    #d0f4ff,
    #ffe0f0,
    #d6f5d6,
    #d0f4ff,
    #ffe0f0,
    #d6f5d6,
    #d0f4ff
  );

  animation: gradientLoop 15s linear infinite;
  background-size: 300% 300%;
}

@keyframes gradientLoop {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}

body::before,
body::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.15;
  background-size: 250px auto;
  background-repeat: repeat;
  animation: flicker 5s linear infinite, move 30s linear infinite;
  pointer-events: none;
}

@keyframes flicker {
  0%,
  100% {
    opacity: 0.15;
  }
  50% {
    opacity: 0.05;
  }
}

@keyframes move {
  0% {
    background-position-x: 0;
  }
  100% {
    background-position-x: -250px;
  }
}

body::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='2800' width='2800'%3E%3Cpath d='M 200 400 Q 0 300 250 200 Q 350 200 450 250 L 650 400 L 650 300 L 650 200 L 450 350 Q 350 450 200 400' fill='%237FB0FF'/%3E%3C/svg%3E");
  background-position: 0 0;
}

body::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='2800' width='2800'%3E%3Cpath d='M 200 400 Q 0 300 250 200 Q 350 200 450 250 L 650 400 L 650 300 L 650 200 L 450 350 Q 350 450 200 400' fill='%2323c4be'/%3E%3C/svg%3E");
  background-position: -30px 120px;
  transform: scaleX(-1);
  animation: flicker 5s 2.5s linear infinite, move 30s linear infinite;
}

.fish {
  position: absolute;
  background-size: contain;
  background-repeat: no-repeat;
  pointer-events: none;
  animation: fall var(--duration, 5s) linear forwards;
  opacity: 0.2;
  transition: opacity 1s linear;
}

@keyframes fall {
  0% {
    transform: translateY(0) translateX(0) scaleX(var(--flip, 1));
  }
  50% {
    transform: translateY(calc(var(--endY) * 0.5)) translateX(var(--sway, 20px))
      scaleX(var(--flip, 1));
  }
  100% {
    transform: translateY(var(--endY)) translateX(calc(var(--sway, 20px) * -1))
      scaleX(var(--flip, 1));
  }
}

header {
  padding-bottom: 62px;
}

h1 {
  font-size: 48px;
  color: var(--second-color);
  -webkit-text-stroke: 2px darkmagenta;
  margin-top: 18px;
}

h2 {
  font-size: 20px;
  margin-top: -30px;
  color: #7fb0ff;
}

main {
  margin-bottom: 40px;
}

.calculator-wrapper {
  position: relative;
  width: fit-content;
  margin: auto;
  filter: drop-shadow(0 0 10px #5c5b182d) drop-shadow(6px 6px 5px #5c5b181f);

  z-index: 100;
}

.left-ear,
.right-ear {
  background: linear-gradient(0deg, #fcfdd2, #fcfdd2) padding-box,
    linear-gradient(0deg, #fcfdd2, #fcfdd2) border-box,
    url("./assets/images/fur.webp");
  background-blend-mode: color;
  position: absolute;
  top: -78px;
  --r: 15px;
  width: 100px;
  aspect-ratio: 1 / cos(30deg);
  mask: linear-gradient(#0000 calc(3 * var(--r) / 2), #000 0),
    radial-gradient(var(--r) at 50% calc(2 * var(--r)), #000 98%, #0000 101%);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.left-ear {
  left: 33px;
}

.right-ear {
  right: 33px;
}

.left-whiskers {
  position: absolute;
  left: -38px;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.whisker {
  position: absolute;
  width: 40px;
  height: 4px;
  background: darkmagenta;
  border-radius: 50%;
  top: 49px;
  rotate: 15deg;
}

.whisker:nth-child(2) {
  top: 70px;
  rotate: 0deg;
}

.whisker:nth-child(3) {
  top: 90px;
  rotate: -15deg;
}

.right-whiskers {
  position: absolute;
  right: -38px;
  transform: scale(-1, 1);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.calculator-container {
  background: linear-gradient(0deg, var(--main-color), #fcfdd2) padding-box,
    linear-gradient(0deg, var(--main-color), #fcfdd2) border-box,
    url("./assets/images/fur.webp") center/cover;
  background-blend-mode: color;
  border-radius: 25px;
  justify-content: center;
  justify-items: center;
  display: grid;
  border: 18px solid transparent;
  --r: 6px;
  aspect-ratio: 1;
  padding: calc(1.5 * var(--r));
  mask: linear-gradient(#000 0 0) no-repeat 50% / calc(100% - 1.5 * var(--r))
      calc(100% - 1.5 * var(--r)),
    radial-gradient(farthest-side, #000 97%, #0000) 0 0 / calc(1.5 * var(--r))
      calc(1.5 * var(--r)) round;
}

.screen-wrapper {
  position: relative;
  width: 330px;
}

.screen {
  font-size: 50px;
  background: #e2f8ff;
  height: 90px;
  margin-bottom: 20px;
  align-items: center;
  display: flex;
  justify-content: end;
  padding: 0 10px;
  border-radius: 15px;
  box-shadow: inset 3px 3px 3px #0000002e;
  position: relative;
  font-family: "Jersey 20", sans-serif;
  cursor: not-allowed;
  overflow: hidden;
}

.screen-text {
  white-space: nowrap;
}

.dot {
  display: inline-block;
  animation: jump 1.5s infinite;
}

.dot:nth-child(1) {
  animation-delay: 0s;
}
.dot:nth-child(2) {
  animation-delay: 0.2s;
}
.dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes jump {
  0%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-6px);
  }
}

.broken-screen-img,
.screen-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.broken-screen-img {
  display: none;
  background: #47cbff29;
  opacity: 0.8;
}

.screen img.overlay {
  position: absolute;
  width: 100px;
  pointer-events: none;
}

.screen-tooltip,
.button-tooltip {
  position: absolute;
  color: #cc3079;
  border-radius: 5px;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.2s ease;
  z-index: 10;
  font-family: "Balsamiq Sans", sans-serif;
  text-align: left;
  background: #ffededd2;
  padding: 3px 8px;
}

.screen-tooltip::before,
.button-tooltip::before {
  content: "";
  position: absolute;
  width: 13px;
  height: 17px;
  background: inherit;
  left: var(--tooltip-left, -12px);
  top: 13px;
  aspect-ratio: cos(30deg);
  clip-path: var(--tooltip-arrow-clip, polygon(100% 0, 0 50%, 100% 100%));
}

.button-tooltip {
  padding: 5px 10px;
  font-size: 18px;
  border-radius: 8px;
  background: #ffededea;
}

.button-tooltip::before {
  top: 30px;
}

.cat-face {
  width: 140px;
  height: 100px;
  left: 0;
  right: 0;
  margin-inline: auto;
  position: absolute;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.eye {
  width: 18px;
  height: 15px;
  background: #59a0cf;
  border-radius: 50%;
  top: 35px;
  position: absolute;
  animation: blink 6s infinite;
}

@keyframes blink {
  0%,
  95%,
  100% {
    height: 15px;
  }
  96%,
  97%,
  98%,
  99% {
    height: 2px;
  }
}

.eye::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  background: white;
  border-radius: 50%;
  top: 2px;
  right: 2px;
}

.eye.right {
  right: 0;
}

.nose {
  --r: 6px;
  background: #eb90a9;
  margin: auto;
  position: relative;
  top: 55px;
  height: 12px;
  aspect-ratio: 2;
  --_g: calc(var(--r) / tan(22.5deg)) top var(--r), #000 98%, #0000 101%;
  -webkit-mask: conic-gradient(
        from 157.5deg at 50%
          calc(var(--r) / (3 * sqrt(2) - 4) - 100% / tan(22.5deg)),
        #000 45deg,
        #0000 0
      )
      0 0/100% calc(100% - var(--r) / sqrt(2)) no-repeat,
    radial-gradient(
      var(--r) at 50% calc(100% - var(--r) * sqrt(2)),
      #000 98%,
      #0000 101%
    ),
    radial-gradient(var(--r) at left var(--_g)),
    radial-gradient(var(--r) at right var(--_g));
  clip-path: polygon(50% 100%, 100% 0, 0 0);
}

.glitch::before,
.glitch::after {
  color: black;
  content: "ERROR";
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.glitch::before {
  left: 87px;
  text-shadow: -2px 0 #eb6bcf;
  animation: glitch-animation-1 3s linear infinite;
}

.glitch::after {
  left: 93px;
  text-shadow: -2px 0 #58a7f1;
  animation: glitch-animation-2 3s linear infinite;
}

@keyframes glitch-animation-1 {
  0% {
    clip: rect(3px, 350px, 39px, 30px);
  }
  10% {
    clip: rect(75px, 350px, 137px, 30px);
  }
  20% {
    clip: rect(19px, 350px, 82px, 30px);
  }
  30% {
    clip: rect(42px, 350px, 7px, 30px);
  }
  40% {
    clip: rect(132px, 350px, 58px, 30px);
  }
  50% {
    clip: rect(44px, 350px, 121px, 30px);
  }
  60% {
    clip: rect(4px, 350px, 100px, 30px);
  }
  70% {
    clip: rect(23px, 350px, 25px, 30px);
  }
  80% {
    clip: rect(69px, 350px, 96px, 30px);
  }
  100% {
    clip: rect(114px, 350px, 109px, 30px);
  }
}
@keyframes glitch-animation-2 {
  0% {
    clip: rect(68px, 350px, 92px, 30px);
  }
  10% {
    clip: rect(138px, 350px, 35px, 30px);
  }
  20% {
    clip: rect(13px, 350px, 56px, 30px);
  }
  30% {
    clip: rect(145px, 350px, 126px, 30px);
  }
  40% {
    clip: rect(50px, 350px, 52px, 30px);
  }
  50% {
    clip: rect(33px, 350px, 26px, 30px);
  }
  60% {
    clip: rect(106px, 350px, 125px, 30px);
  }
  70% {
    clip: rect(48px, 350px, 7px, 30px);
  }
  80% {
    clip: rect(82px, 350px, 11px, 30px);
  }
  90% {
    clip: rect(27px, 350px, 93px, 30px);
  }
  100% {
    clip: rect(97px, 350px, 48px, 30px);
  }
}

.buttons-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px 6px;
}

.buttons-container button {
  width: 82px;
  height: 82px;
  font-size: 34px;
  cursor: pointer;
  border-radius: 25px;
  font-family: "Balsamiq Sans", sans-serif;
  color: #6a1d3da3;
  border: none;
  box-shadow: inset -3px -3px 2px #504c4c2e, -1px -1px 1px #504c4c2e;
  border-radius: 70% 70% 50% 50%/90% 90% 50% 50%;
}

.buttons-container .equal-button,
.buttons-container .backspace-button {
  grid-column: span 2;
  width: auto;
}

.buttons-container button:nth-child(1),
.buttons-container button:nth-child(n + 4):nth-child(-n + 6),
.buttons-container button:nth-child(20) {
  background: linear-gradient(#cbe9fd 60%, #a6dafd),
    url("./assets/images/fur.webp");
  background-blend-mode: color;
}

.buttons-container button:nth-child(n + 2):nth-child(-n + 3) {
  background: linear-gradient(#facedb 60%, #e6abbc),
    url("./assets/images/fur.webp");
  background-blend-mode: color;
}

.buttons-container button:nth-child(n + 8):nth-child(-n + 10),
.buttons-container button:nth-child(n + 12):nth-child(-n + 14),
.buttons-container button:nth-child(n + 16):nth-child(-n + 18),
.buttons-container button:nth-child(21) {
  background: linear-gradient(#facef3 60%, #ee9fe1),
    url("./assets/images/fur.webp");
  background-blend-mode: color;
}

.buttons-container button:nth-child(7),
.buttons-container button:nth-child(11),
.buttons-container button:nth-child(15),
.buttons-container button:nth-child(19) {
  background: linear-gradient(#fce7c8 60%, #f7d097),
    url("./assets/images/fur.webp");
  background-blend-mode: color;
}

.buttons-container button:nth-child(22) {
  background: linear-gradient(#c4f8b9 60%, #9ff28e),
    url("./assets/images/fur.webp");
  background-blend-mode: color;
}

.buttons-container button:hover {
  filter: contrast(1.2);
}

.buttons-container button:active {
  transform: translateY(2px);
  box-shadow: inset 0 0 2px #504c4c2e;
}

.buttons-container button.disable {
  opacity: 0.8;
}

.buttons-container button.disable:hover {
  filter: none;
  cursor: default;
}

.buttons-container button.disable:active {
  transform: none;
  box-shadow: inset -3px -3px 2px #504c4c2e, -1px -1px 1px #504c4c2e;
}

.history-button {
  background-image: url("./assets/images/history.webp");
  background-color: transparent;
  background-size: contain;
  border: none;
  width: 40px;
  height: 40px;
  margin-top: 35px;
  cursor: pointer;
  filter: invert(46%) sepia(17%) saturate(1056%) hue-rotate(276deg)
    brightness(88%) contrast(91%);
  transition: all 0.2s ease, opacity 0.2s ease;
  opacity: 1;
}

.history-button:hover {
  filter: invert(52%) sepia(10%) saturate(1097%) hue-rotate(276deg)
    brightness(104%) contrast(101%);
  zoom: 1.03;
  transform: translateY(-2px);
}

.history-button:active {
  transform: translateY(0);
}

.history-button.fade-out {
  opacity: 0;
}

.history-button.close-mode {
  background: none;
  font-size: 40px;
  color: #9d5c7e;
  margin-top: 26px;
}

.history-container {
  background: linear-gradient(#facef3 60%, #e6b6e6);
  width: 100%;
  height: 560px;
  position: absolute;
  bottom: 0;
  border-radius: 25px;
  display: none;
  transform: translateY(100%);
  opacity: 0.2;
  transition: all 0.3s ease-in-out;
  filter: drop-shadow(0 -5px 5px #8b008b36);
}

.history-container.active {
  display: block;
  transform: translateY(0);
  opacity: 0.96;
}

.history-list {
  list-style: none;
  padding: 0 20px;
  max-height: 450px;
  overflow-y: auto;
  margin-top: 40px;
}

.history-list li {
  background: #ffe9f8;
  color: #9d5c7e;
  margin-bottom: 10px;
  padding: 10px 0;
  border-radius: 12px;
  font-weight: bold;
  font-size: 18px;
}

.history-list li:nth-child(even) {
  background: #fdfdda;
}

.empty-history {
  font-style: italic;
  color: #9d5c7e;
  margin-top: 20px;
  background: transparent !important;
}

.trash-button:active {
  transform: translateY(2px);
}

.trash-button {
  background-image: url("./assets/images/trash.webp");
  background-color: transparent;
  background-size: contain;
  border: none;
  width: 40px;
  height: 40px;
  margin-top: 35px;
  cursor: pointer;
  position: absolute;
  bottom: 20px;
  right: 20px;
  filter: invert(46%) sepia(17%) saturate(1056%) hue-rotate(276deg)
    brightness(88%) contrast(91%);
}

.trash-button:hover {
  background-image: url("./assets/images/trash-hover.gif");
  filter: invert(52%) sepia(10%) saturate(1097%) hue-rotate(276deg)
    brightness(104%) contrast(101%);
}

footer {
  position: relative;
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
}

@media (max-width: 768px) {
  .calculator-container {
    zoom: 0.85;
  }
}
