html, body {
  height: auto;
  margin: 0;
  font-family: 'Cabin', Arial, sans-serif;
  background: white;
}

body {
  padding-top: 70px;
}

#memory-game-section {
  position: relative;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: white;
  padding: 10px 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.memory-game-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 2rem;
  padding: 1.5rem 1rem 2rem;
  min-height: calc(100vh - 80px);
  flex-wrap: wrap;
}

#game-shell {
  flex: 0 1 auto;
  position: relative;
}

#game-shell.game-active {
}

#game-board {
  position: relative;
  width: min(56vw, 600px);
  height: min(56vw, 600px);
  padding: 4px;
  box-sizing: border-box;
  overflow: visible;
  background: transparent;
  border-radius: 18px;
  box-shadow: none;
}

.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.9rem;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: 6px;
  box-sizing: border-box;
}

.game-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  display: none;
}

.game-button,
#playAgain {
  font-family: 'Cabin', Arial, sans-serif;
  padding: 0.75rem 1.7rem;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 1.32rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.game-button,
#playAgain {
  width: fit-content;
  margin: 0 auto;
}

.game-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.game-button:disabled,
#playAgain:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.game-button:not([disabled]):hover,
#playAgain:not([disabled]):hover {
  background: #0000FF;
}

#loading {
  margin-top: 0.5rem;
  font-size: 0.95rem;
  color: #555;
}

@media (min-width: 769px) {
  .memory-game-container {
    flex-wrap: nowrap;
  }
  
  #game-shell,
  .game-sidebar {
    flex: 0 0 auto;
  }
}

.game-sidebar {
  position: relative;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-size: 1rem;
  padding: 0 0.5rem;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  align-self: center;
  align-items: flex-start;
}

#message {
  font-size: 1.1rem;
  font-weight: 400;
  color: #0000FF;
  background: transparent;
  border: none;
  display: none;
  margin-top: 4.8rem;
  margin-bottom: 0.05rem;
  line-height: 1.6;
  text-align: center;
}

#hintMessage {
  position: sticky;
  top: 1.5rem;
  left: auto;
  right: auto;
  width: 100%;
  font-size: 0.95rem;
  font-weight: 400;
  color: #0000FF;
  display: block;
  opacity: 0;
  line-height: 1.6;
  background: rgba(0, 0, 255, 0.05);
  border-left: 4px solid #0000FF;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  transition: opacity 0.35s ease;
  text-align: left;
  box-sizing: border-box;
  z-index: 10;
  margin-bottom: 0.4rem;
}

.selection-count {
  font-size: 0.95rem;
  font-weight: 400;
  color: #111;
  text-align: left;
  position: absolute;
  bottom: -1.8rem;
  right: -0.04rem;
  pointer-events: none;
}

#playAgain {
  display: none;
  justify-content: center;
  width: fit-content;
  margin-top: -1rem;
}

#app {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  box-sizing: border-box;
  width: 100%;
  height: auto;
}

.card {
  width: 100%;
  aspect-ratio: 1;
  background-size: cover;
  background-position: center;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background-color: transparent;
  box-shadow: none;
  border: none;
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  contain: layout paint;
  transition: transform 0.18s, border-color 0.18s, opacity 0.25s ease;
}

@keyframes shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.card:hover {
  transform: none;
}

.card.selected {
  border-color: #0000FF;
  border-width: 4px;
  border-style: solid;
  box-shadow: 0 6px 16px rgba(0,0,255,0.25), 0 0 0 8px rgba(30,102,255,0.12);
  transform: translateY(-4px) scale(1.02);
}

.card.correct {
  border-color: #0000FF;
  border-width: 4px;
  border-style: solid;
  background-color: rgba(0, 0, 255, 0.05);
  box-shadow: 0 6px 16px rgba(0,0,255,0.25), 0 0 0 8px rgba(30,102,255,0.12);
}

.card.card-hidden {
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
}

.card.incorrect {
  border-color: #0000FF;
  border-width: 4px;
  border-style: solid;
  background-color: rgba(0, 0, 255, 0.08);
  box-shadow: 0 0 0 8px rgba(30,102,255,0.12);
  animation: shake 0.35s ease;
}

.card.blurred {
  opacity: 0.3;
  filter: blur(1px);
  pointer-events: none;
}

.card .front {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  justify-content: flex-end;
}

.card .title {
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 4px;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 768px) {
  .memory-game-container {
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem 1rem;
  }
  
  #game-shell {
    width: 100%;
  }
  
  .game-sidebar {
    width: 100%;
    padding: 1.25rem;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem;
  }
  
  #app {
    gap: 10px;
  }
}

.card .back {
  display: none;
}
#stats.hidden,
#hintMessage.hidden {
  opacity: 0;
}

.visible {
  opacity: 1 !important;
}
