html {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100vh;
  width: 100%;
  background: url("../../bg.webp");
  background-position: center;
  background-size: contain;
}

#mainContent {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Level Selection Styles */
.level-screen {
  text-align: center;
  padding: 20px;
  min-height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.level-screen h1 {
  font-size: clamp(2em, 8vw, 3em);
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.level-screen h2 {
  font-size: clamp(1.5em, 6vw, 2em);
  color: #574908;
  font-size: 32px;
  font-weight: 500;
}

.level-buttons {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 10px;
}

.level-btn {
  background: url(button.png);
  border: none;
  border-radius: 15px;
  padding: 20px 20px;
  width: 280px;
  cursor: pointer;
  transition: all 0.3s ease;
  touch-action: manipulation;
  /* color: white !important; */
  background-size: contain;
  background-position: center;
  background-size: auto;
  background-repeat: no-repeat;
}

.level-btn:hover,
.level-btn:active {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.3);
}

.level-btn h3 {
  font-size: clamp(1.4em, 5vw, 1.8em);
  margin: 0 0 12px 0;
  font-weight: bold;
}

.level-btn p {
  font-size: clamp(0.9em, 3.5vw, 1em);
  color: #666;
  margin: 0;
  line-height: 1.4;
}

.level-btn.beginner h3 {
  color: #ffffff;
  font-size: 26px;
}

.level-btn.intermediate {
  border-left: 5px solid #ff9800;
}

.level-btn.intermediate h3 {
  color: #ff9800;
}

.level-btn.advanced {
  border-left: 5px solid #f44336;
}

.level-btn.advanced h3 {
  color: #f44336;
}

/* Game Container Styles */
.game-container {
  height: 100vh;
  display: flex;
  flex-direction: row;
  padding: 10px;
  max-width: 1280px;
  margin: 0 auto;
  gap: 12px;
  box-sizing: border-box;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.game-info {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  flex-shrink: 0;
}

.info-card {
  background: #f8f7eb;
  border-radius: 20px;
  padding: 30px 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid #e8e6d4;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-width: 150px;
}

.info-section {
  text-align: center;
}

.info-label {
  font-family: "Fredoka", sans-serif;
  font-size: 18px;
  font-weight: bold;
  color: #2c1810;
  margin-bottom: 8px;
}

.info-value {
  font-family: "Fredoka", sans-serif;
  font-size: 16px;
  font-weight: 400;
  color: #2c1810;
}

/* Board and Card Styles */
#board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 6px;
  width: auto;
  margin: 0 auto;
  padding: 0;
  border-radius: 10px;
  box-sizing: border-box;
  flex: 1;
  align-self: center;
  min-height: 0;
  min-width: 0;
  /* Calculate max size to fit viewport: 100vh - container padding (20px) - info card space */
  max-height: calc(100vh - 20px);
  max-width: calc(100vw - 200px); /* Account for info card + gaps */
  /* Scale down if needed */
  transform-origin: center;
}

.card-wrapper {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border-radius: 8px;
  background: url(./wood-frame.png);
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  padding: 4px;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  /* Ensure card fits within its grid cell and maintains square */
  max-width: 100%;
  max-height: 100%;
  /* Force square aspect ratio */
  object-fit: contain;
}

.card {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 4px;
  object-fit: fill;
  /* Ensure image fills the square card */
}

.card-wrapper:hover,
.card-wrapper:active {
  transform: scale(1.02);
}

/* Matched card styles */
.card-wrapper.matched {
  opacity: 0.7;
  cursor: default;
  pointer-events: none;
  transform: scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.card-wrapper.matched .card {
  filter: brightness(1.1);
  border: 2px solid #4caf50;
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.card-wrapper.matched:hover {
  transform: scale(0.95);
}

/* Game Status Styles */
#gameStatus {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.statuscont {
  background-color: #000000d1;
  justify-content: center;
  position: absolute;
  width: 100vw;
  height: 100vh;
  justify-content: center;
  display: none;
  align-content: center;
  align-items: center;
  top: 0;
  left: 0;
  z-index: 1;
}

#gameStatus h1 {
  font-size: clamp(1.5em, 6vw, 2.5em);
  margin: 10px 0;
}

/* Confetti Styles */
.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  background: #f00;
  animation: confetti-fall 3s linear forwards;
  z-index: 1000;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-100vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Success/Game Over Modal Styles */
.success-modal {
  width: min(400px, 90vw);
  background: #f8f7eb;
  border-radius: 20px;
  padding: 40px 30px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border: 1px solid #e8e6d4;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.success-title {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(28px, 6vw, 36px);
  font-weight: 500;
  color: #574908;
  margin: 0;
}

.stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.star {
  filter: drop-shadow(0 2px 4px rgba(255, 215, 0, 0.3));
}

.star.small {
  font-size: 48px;
}

.star.large {
  font-size: 72px;
}

.points-display {
  display: flex;
  align-items: center;
  gap: 4px;
}

.points-number {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(40px, 8vw, 56px);
  font-weight: 500;
  color: #574908;
}

.points-label {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(40px, 4vw, 24px);
  font-weight: 400;
  color: #574908;
}

.restart-btn {
  padding: 14px 100px;
  background: linear-gradient(180deg, #b99d27 0%, #c7b052 100%);
  border: 2px solid #b99d27;
  border-radius: 50px;
  font-family: "Fredoka", sans-serif;
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.restart-btn:active {
  transform: translateY(0);
}

/* Lose Modal Styles */
.lose-modal .success-title {
  color: #c44536;
}

.lose-icon {
  font-size: 64px;
  line-height: 1;
}

.game-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-text {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(16px, 3.5vw, 18px);
  color: #2c1810;
  margin: 0;
}

/* Responsive design */
/* @media (min-width: 1220px) {
  #board {
    max-width: 40% !important;
  }
} */

@media (max-width: 630px) {
  .game-container {
    flex-direction: column;
    height: 100vh;
    padding: 8px;
    gap: 8px;
  }

  .game-info {
    flex-shrink: 0;
    width: 100%;
    margin-bottom: 0;
  }

  .info-card {
    flex-shrink: 0;
    padding: 16px 12px;
    flex-direction: row;
    justify-content: space-around;
    gap: 16px;
  }

  #board {
    /* Grid will be set by JavaScript for precise sizing */
    gap: 3px;
    flex: 1;
    min-height: 0;
    padding: 0;
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 180px);
    /* Ensure board doesn't overflow */
    overflow: visible;
  }

  .card-wrapper {
    padding: 2px;
    /* Ensure square on mobile */
    aspect-ratio: 1 / 1;
  }
}

/* Medium screens (tablets) */
@media (max-width: 1024px) and (min-width: 631px) {
  .game-container {
    padding: 12px;
    gap: 16px;
  }

  .info-card {
    padding: 24px 20px;
    min-width: 140px;
  }

  #board {
    max-width: calc(100vw - 180px);
  }
}

@media (max-width: 768px) {
  .level-screen {
    padding: 15px 10px;
    max-height: 100vh;
    overflow: hidden;
  }

  .level-buttons {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
  }

  .level-btn {
    width: 100%;
    max-width: 320px;
    padding: 20px 15px;
  }

  .game-container {
    height: 100vh;
    flex-direction: column;
    padding: 10px;
    gap: 10px;
  }

  .game-info {
    width: 100%;
    flex-shrink: 0;
    margin-bottom: 0;
  }

  .info-card {
    flex-shrink: 0;
    padding: 18px 14px;
    gap: 18px;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    max-width: 100%;
  }

  .info-label {
    font-size: 16px;
  }

  .info-value {
    font-size: 14px;
  }

  #board {
    /* Grid will be set by JavaScript for precise sizing */
    gap: 4px;
    padding: 0;
    flex: 1;
    min-height: 0;
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 200px);
    overflow: visible;
  }

  .card-wrapper {
    padding: 3px;
    aspect-ratio: 1 / 1;
  }
}

@media (max-width: 480px) {
  .level-screen {
    padding: 10px 5px;
    max-height: 100vh;
    overflow: hidden;
  }

  .level-screen h1 {
    font-size: 2em;
    margin-bottom: 15px;
  }

  .level-screen h2 {
    font-size: 32px;
    margin-bottom: 20px;
  }

  .level-btn {
    padding: 18px 12px;
    border-radius: 12px;
  }

  .level-btn h3 {
    font-size: 1.4em;
    margin-bottom: 8px;
  }

  .level-btn p {
    font-size: 0.9em;
  }

  .game-container {
    height: 100vh;
    padding: 6px 4px;
    flex-direction: column;
    gap: 6px;
  }

  .info-card {
    padding: 12px 10px;
    gap: 12px;
    min-width: auto;
    width: 100%;
    max-width: 100%;
    flex-shrink: 0;
  }

  .info-label {
    font-size: 14px;
  }

  .info-value {
    font-size: 13px;
  }

  #board {
    /* Grid will be set by JavaScript for precise sizing */
    gap: 2px;
    flex: 1;
    min-height: 0;
    padding: 0;
    max-width: calc(100vw - 8px);
    max-height: calc(100vh - 160px);
    overflow: visible;
  }

  .card-wrapper {
    padding: 2px;
    border-radius: 4px;
    aspect-ratio: 1 / 1;
  }
}

@media (max-width: 320px) {
  .level-btn {
    padding: 15px 10px;
  }

  .level-btn h3 {
    font-size: 1.2em;
  }

  .level-btn p {
    font-size: 0.8em;
  }

  #board {
    grid-template-columns: repeat(3s, 1fr);
    gap: 3px;
  }
}

/* Landscape orientation adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .level-screen {
    padding: 10px;
    min-height: auto;
  }

  .level-screen h1 {
    font-size: 1.8em;
    margin-bottom: 10px;
  }

  .level-screen h2 {
    font-size: 1.3em;
    margin-bottom: 15px;
  }

  .level-buttons {
    flex-direction: column;
    gap: 15px;
  }

  .level-btn {
    width: 200px;
    padding: 15px 10px;
  }

  .level-btn h3 {
    font-size: 1.2em;
    margin-bottom: 5px;
  }

  .level-btn p {
    font-size: 0.8em;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .card-wrapper {
    border-radius: 6px;
  }

  .level-btn {
    border-radius: 20px;
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .card-wrapper,
  .level-btn {
    transition: none;
  }

  .card-wrapper:hover,
  .card-wrapper:active,
  .level-btn:hover,
  .level-btn:active {
    transform: none;
  }

  .confetti {
    animation: none;
  }
}
