/*
 * Copyright (c) 2025-2026 Evolution Creek Software. All rights reserved.
 *
 * Unauthorized copying, linking, or other unintended use of this file
 * (in part or in whole) is strictly prohibited.
 */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#grid {
  width: min(580px, 90vw);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: clamp(10px, 0.5vw, 20px);
  position: relative;
  overflow: visible !important;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  margin-top: 2.5rem;
}

.square {
  width: 100%;
  box-sizing: border-box;
  aspect-ratio: 65/96;
  overflow: visible;
  border: none;
  font-weight: normal;
  border-radius: 5px;
  font-family: 'Caveat', cursive;
  font-size: clamp(20px, 3vw, 30px);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  perspective: 1000px;
  position: relative;
  backface-visibility: hidden;
  transform: translateZ(0);
  z-index: 1;
  will-change: transform;
  transition: background-color 0.2s ease, transform 0.8s ease;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.square.absolute {
  position: absolute;
  z-index: 10;
}

.square.animating {
  z-index: 999;
  position: relative;
}

.card {
  width: 100%;
  height: 100%;
  position: absolute;
  overflow: visible;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  overflow: visible;
  backface-visibility: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background-clip: padding-box;
  transform: translateZ(0);
  transition: background-color 0.7s ease, transform 0.8s ease;
  border-radius: 5px;
}

.front {
  background-color: blanchedalmond;
  box-sizing: border-box;
  box-shadow: 0 0 0 2px saddlebrown;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.3s ease, background-color 0.4s ease;

  background-image:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      rgba(139, 69, 19, 0.1) 10px,
      rgba(139, 69, 19, 0.1) 12px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 10px,
      rgba(139, 69, 19, 0.1) 10px,
      rgba(139, 69, 19, 0.1) 12px
    );
}

.front::after {
  content: 'EC';
  position: absolute;
  top: 50%;
  left: 46%;
  transform: translate(-50%, -50%);
  font-family: 'Imperial Script', cursive;
  font-size: 3rem;
  color: rgba(139, 69, 19, 0.7);
  font-weight: bold;
  pointer-events: none;
  user-select: none;
  will-change: transform;
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
}

.back {
  width: 100%;
  height: 100%;
  position: relative;
  box-sizing: border-box;
  background-color: white;
  box-shadow: 0 0 0 2px black;
  transform: rotateY(180deg);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.3s ease;
}

.card-face.back img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 4px;
  box-shadow: none;
  transition: transform 0.3s ease;
}

.overlay {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: rgba(211, 211, 211, 0.0);
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease, background-color 0.8s ease;
}

.square.revealed .overlay {
  background-color: rgba(100, 100, 100, 0.3);
}

.square.flipped .card {
  transform: rotateY(180deg);
}

.square.spin .card {
  transform: rotateY(-180deg);
}

.square.matched .card-face.back {
  box-shadow: 0 0 0 2px black, 0 0 5px 3px rgba(0, 0, 0, 0.8);
  transition: box-shadow 0.3s ease;
}


@keyframes zoomAnimation {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.zoom {
  animation: zoomAnimation 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
  .card-face.front:hover {
    background-color: burlywood;
    transform: scale(1.05);
  }

  .button:hover {
    background-color: peru;
    border-color: peru;
    color: wheat;
  }
}

#scoreBoard {
  display: flex;
  gap: 2rem;
  margin-top: 1.25rem;
  font-family: 'Afacad Flux', sans-serif;
  font-weight: 400;
  font-size: 1.4rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.score {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.button {
  font-family: "Afacad Flux", sans-serif;
  font-weight: 500;
  font-size: 1.2rem;
  padding: 0.4em 1em;
  background-color: moccasin;
  border: 2px solid saddlebrown;
  color: saddlebrown;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border 0.2s ease;
  margin-top: 1rem;
}

.button:active {
  transform: scale(0.95);
}

#endlessBtn {
  font-family: "Afacad Flux", sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
  color: saddlebrown;
  cursor: pointer;
  margin-top: 0rem;
}

#endlessBtn:hover {
  font-weight: 600;
}

#endlessWrapper {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  line-height: 1.2;
  margin-top: -0.2rem;
}

.info-icon {
  font-size: 0.8rem;
  color: saddlebrown;
  opacity: 1;
  cursor: pointer;
  position: relative;
}

.info-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid saddlebrown;
  font-size: 0.9rem;
  font-family: "Afacad Flux", sans-serif;
  font-weight: 700;
  color: saddlebrown;
  line-height: 1;
  cursor: pointer;
}

.info-icon:hover {
  opacity: 1;
}

.info-tooltip {
  width: min(400px, 60vw);
  text-align: center;
  display: none;
  position: absolute;
  top: 125%;
  left: -50%;
  transform: translateX(-50%);
  background-color: white;
  color: black;
  border: 2px solid saddlebrown;
  font-family: "Afacad Flux", sans-serif;
  font-size: 1rem;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  white-space: normal;
  z-index: 100;
  pointer-events: none;
}

.info-icon:hover .info-tooltip,
.info-icon.active .info-tooltip {
  display: block;
}

@media (max-width: 600px) {
  #grid {
    width: 85vw;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: clamp(5px, 3vw, 10px);
  }

  #grid div {
    font-size: clamp(40px, 17vw, 70px);
    line-height: 1;
  }

  .front::after {
    font-size: 2rem;
    padding: 0 4px;
  }

  #scoreBoard {
    width: 90vw;
    font-size: 1.2rem;
    gap: 1rem;
  }

  #buttons {
    gap: 0.5rem;
  }

  #resetButton {
    font-size: 1.1rem;
    padding: 0.4em 0.7em;
  }

}
