/*
 * 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(650px, 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;
  background-clip: padding-box;
}

.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.1);
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.no-border {
  border: none !important;
}

.square.flipped .card {
  transform: rotateY(180deg);
}

.square.spin .card {
  transform: rotateY(-180deg);
}

@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);
  }

  .card-face.back :hover {
    box-shadow: 0 0 0 2px black;
    border-radius: 5px;
    background-clip: padding-box;
    transform: scale(1.05);
  }

  .button:hover {
    box-sizing: border-box;
    background-color: peru;
  }

}

#scoreBoard {
  display: flex;
  max-width: 95vw;
  gap: 1.5rem;
  margin-top: 1rem;
  font-family: 'Caveat', cursive;
  font-size: 30px;
  justify-content: center;
  text-align: center;
}

#cpuHand {
  display: flex;
  gap: 10px;
  align-items: center;
}

.cpu-card {
  width: 60px;
  aspect-ratio: 65/50;
  border: 2px solid black;
  border-radius: 5px 5px 0 0; /* round only top corners for better effect */
  overflow: hidden;
  position: relative;
  background-color: white;
  box-sizing: border-box;
  opacity: 0;

  transform-style: preserve-3d;
  transition: transform 0.6s ease, opacity 0.5s ease;
}

.cpu-card.visible {
  opacity: 1; /* fade to fully visible */
}

.cpu-card img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 200%; /* double height to fill half container and show top half */
  object-fit: cover;
}

/* unflipped card: white background, no image */
.cpu-card.unflipped {
  background-color: white;
}

.cpu-card.flipped {
  transform: rotateY(180deg);
}

/* flipped card can have image */
.cpu-card.flipped img {
  display: block;
}

.score {
  min-width: 80px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.score-row {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

#cpuCard1 img {
  opacity: 0;
  transition: opacity 0.5s ease;
}

#cpuCard2 img {
  opacity: 0;
  transition: opacity 0.5s ease;
}

#buttons{
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
}

.button{
  margin-top: 20px;
  width: 200px;
  display: flex;
  background-color: moccasin;
  color: black;
  font-family: 'Caveat', cursive;
  white-space: nowrap;
  justify-content: center;
  align-items: center;
  font-size: 30px;
  padding: 0.5em 1em;
  border: 2px solid black;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.4s ease, color 0.4s ease, box-shadow 0.4s ease, transform 0.2s ease;
}

.button:active{
  transform: scale(0.95);
}

@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;
  }


  #scoreBoard{
    width: 90vw;
    font-size: 25px;
    gap: 0.5rem;
    flex-direction: column;
    align-items: center;
  }

  .score-row {
    gap: 0.3rem;
    padding: 0.2rem;
  }

  #score-row-2{
    gap: 2rem;
  }

  #buttons{
    display: flex;
    gap: 2.5rem;
  }

  #resetButton, #stayButton {
    width: 35vw;
    font-size: clamp(28px, 4vw, 35px);
    padding: 0.5em 1em;
    border-radius: 10px;
    justify-content: center;
  }

  #stayButton:hover {
    width: 35vw;
    background-color: #d4956a;
    justify-content: center;
  }

  #resetButton:hover {
    width: 35vw;
    background-color: #d4956a;
    justify-content: center;
  }

}
