/* Memory Match Puzzle Game - Upgraded UI Styles */

/* === CSS Variables for Theme and Spacing === */
:root {
  --mmp-primary: #5f2eea;
  --mmp-secondary: #00c9a7;
  --mmp-accent: #ffb86c;
  --mmp-bg-gradient: linear-gradient(135deg, #e0e7ff 0%, #f8fafc 100%);
  --mmp-dark-bg-gradient: linear-gradient(135deg, #232946 0%, #121629 100%);
  --mmp-card-front: #fff;
  --mmp-card-back: #e0e7ff;
  --mmp-card-match: #00c9a7;
  --mmp-card-match-glow: #ffb86c;
  --mmp-sidebar-bg: rgba(255,255,255,0.7);
  --mmp-sidebar-glass: blur(12px);
  --mmp-btn-bg: #5f2eea;
  --mmp-btn-bg-hover: #00c9a7;
  --mmp-btn-text: #fff;
  --mmp-spacing: 20px;
  --mmp-radius: 18px;
  --mmp-shadow: 0 4px 32px rgba(95,46,234,0.10);
  --mmp-focus: 0 0 0 3px #00c9a7aa;
  --mmp-transition: 0.22s cubic-bezier(.4,0,.2,1);
}

/* === Dark Mode === */
body.mmp-dark {
  --mmp-bg-gradient: var(--mmp-dark-bg-gradient);
  --mmp-card-front: #232946;
  --mmp-card-back: #232946;
  --mmp-card-match: #00c9a7;
  --mmp-sidebar-bg: rgba(35,41,70,0.85);
  --mmp-btn-bg: #00c9a7;
  --mmp-btn-bg-hover: #5f2eea;
  --mmp-btn-text: #fff;
  color-scheme: dark;
}

/* === General Layout === */
body {
  background: radial-gradient(ellipse at 60% 40%, #fffbe6 60%, #fff8e1 100%);
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
  color: #232946;
  margin: 0;
  min-height: 100vh;
  transition: background var(--mmp-transition);
}

.mmp-start-screen-overlay {
  position: fixed;
  z-index: 1000;
  inset: 0;
  background: linear-gradient(120deg, #fffbe6 0%, #fff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: mmp-fade-in 0.7s;
}

@keyframes mmp-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mmp-start-card {
  background: #fff;
  border-radius: 32px;
  box-shadow: 0 8px 32px 0 #ffb00122, 0 1.5px 6px #ffb00111;
  padding: 48px 38px 38px 38px;
  min-width: 340px;
  max-width: 98vw;
  text-align: center;
  margin: 48px auto;
  animation: mmp-slide-up 0.7s;
}

@keyframes mmp-slide-up {
  from { transform: translateY(60px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.mmp-start-title {
  font-size: 2.4em;
  margin-bottom: 28px;
  font-weight: 900;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ffb001 10%, #ff7e5f 90%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  text-align: left;
}

.mmp-start-form-group {
  margin-bottom: 28px;
  text-align: left;
}

.mmp-start-label {
  font-weight: 700;
  margin-bottom: 8px;
  display: block;
  color: #232946;
  font-size: 1.13em;
  letter-spacing: 0.2px;
}

.mmp-start-input-wrapper {
  display: flex;
  align-items: center;
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 2px 8px #ffb00111;
  border: 2px solid #fff3cd;
}

.mmp-start-input-icon {
  font-size: 1.3em;
  margin-right: 12px;
  color: #ffb001;
}

.mmp-start-input, .mmp-start-select {
  border: none;
  background: transparent;
  font-size: 1.18em;
  outline: none;
  flex: 1;
  padding: 7px 0;
  color: #232946;
}

.mmp-start-input:focus, .mmp-start-select:focus {
  box-shadow: var(--mmp-focus);
  border-radius: 8px;
}

.mmp-btn {
  background: linear-gradient(90deg, #ffb001 10%, #ff7e5f 90%);
  color: #fff;
  border: none;
  border-radius: 18px;
  padding: 16px 0;
  font-size: 1.25em;
  font-weight: 800;
  cursor: pointer;
  margin: 0 auto;
  display: block;
  width: 80%;
  max-width: 320px;
  box-shadow: 0 4px 18px #ffb00122;
  transition: background 0.18s, transform 0.13s;
  letter-spacing: 0.5px;
  outline: none;
}
.mmp-btn:focus {
  outline: 2.5px solid #ffb001;
  outline-offset: 2px;
}
.mmp-btn:hover, .mmp-btn:active {
  background: linear-gradient(90deg, #ff7e5f 10%, #ffb001 90%);
  transform: scale(1.04);
}

.mmp-game-layout {
  display: flex;
  flex-direction: row;
  gap: 12px; /* Reduced gap for closer sidebar */
  justify-content: center;
  align-items: flex-start;
  margin: 0 auto;
  max-width: 1200px;
  padding: 36px 4px 24px 4px; /* Slightly reduced horizontal padding */
  box-sizing: border-box;
}

.mmp-game {
  flex: 1 1 0;
  min-width: 320px;
  max-width: 540px;
  margin: 0 auto;
  padding: 0;
}

.mmp-board-container {
  background: var(--mmp-sidebar-bg);
  border-radius: var(--mmp-radius);
  box-shadow: var(--mmp-shadow);
  padding: 28px 20px 20px 20px;
  backdrop-filter: var(--mmp-sidebar-glass);
  animation: mmp-fade-in 0.7s;
}

.mmp-board-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 22px;
}

.mmp-board {
  display: grid;
  grid-template-columns: repeat(var(--mmp-grid-size, 4), 1fr);
  grid-template-rows: repeat(var(--mmp-grid-rows, 4), 1fr);
  gap: var(--mmp-card-gap, 16px);
  justify-content: center;
  margin: 16px 0 18px 0;
  min-height: 240px;
  max-width: 98vw;
  width: 100%;
  height: auto;         /* Allow board to grow as needed */
  max-height: none;     /* Remove restriction */
  overflow-y: visible;  /* No cropping, allow full board */
  padding-bottom: 48px;
  box-sizing: border-box;
  justify-items: center;
}

.mmp-card {
  width: 100%;
  height: 100%;
  aspect-ratio: 1/1;
  background: var(--mmp-card-back);
  border-radius: 12px;
  box-shadow: 0 2px 12px #5f2eea11;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--mmp-card-font, 2.1em);
  color: var(--mmp-primary);
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: transform 0.22s, box-shadow 0.22s, background 0.22s;
  perspective: 600px;
  will-change: transform;
  outline: none;
  overflow: hidden;
}
.mmp-card:focus {
  box-shadow: var(--mmp-focus);
}
.mmp-card.mmp-flipped, .mmp-card.mmp-matched {
  background: var(--mmp-card-front);
  color: var(--mmp-secondary);
  cursor: default;
  box-shadow: 0 2px 18px #00c9a722;
  animation: mmp-card-flip 0.5s cubic-bezier(.4,0,.2,1);
}
.mmp-card.mmp-matched {
  background: var(--mmp-card-match);
  color: #fff;
  animation: mmp-card-match 0.7s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 0 0 6px var(--mmp-card-match-glow), 0 2px 18px #00c9a744;
}

@keyframes mmp-card-flip {
  0% { transform: rotateY(0deg); }
  60% { transform: rotateY(90deg) scale(1.08); }
  100% { transform: rotateY(0deg) scale(1); }
}
@keyframes mmp-card-match {
  0% { box-shadow: 0 0 0 0 var(--mmp-card-match-glow); }
  60% { box-shadow: 0 0 0 16px var(--mmp-card-match-glow); }
  100% { box-shadow: 0 0 0 6px var(--mmp-card-match-glow); }
}

.mmp-card-front, .mmp-card-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%; height: 100%;
  font-size: inherit;
  font-weight: 700;
  transition: color 0.18s;
}

.mmp-controls {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-bottom: 12px;
  min-height: 56px;
  flex-wrap: wrap;
}

.mmp-feedback {
  min-height: 28px;
  text-align: center;
  font-size: 1.13em;
  color: var(--mmp-primary);
  margin-top: 10px;
  font-weight: 600;
  animation: mmp-fade-in 0.5s;
}

.mmp-feedback[aria-live="polite"] {
  transition: color 0.18s;
}

.mmp-sidebar {
  width: 320px;
  min-width: 220px;
  background: var(--mmp-sidebar-bg);
  color: #232946;
  padding: 0 0.7em;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  box-shadow: 0 2px 16px #5f2eea11;
  border-radius: var(--mmp-radius);
  backdrop-filter: var(--mmp-sidebar-glass);
  animation: mmp-slide-up 0.7s;
  transition: width 0.35s cubic-bezier(.4,0,.2,1), min-width 0.35s cubic-bezier(.4,0,.2,1), opacity 0.25s;
  overflow: hidden;
}
/* .mmp-sidebar.mmp-collapsed {
  width: 0 !important;
  min-width: 0 !important;
  opacity: 0;
  pointer-events: none;
  padding: 0;
} */

.mmp-difficulty-badge {
  display: inline-block;
  padding: 6px 22px;
  font-size: 1.08em;
  font-weight: 700;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffe082 0%, #ffb001 100%);
  color: #b28704;
  box-shadow: 0 2px 8px #ffb00122;
  letter-spacing: 0.2px;
  margin: 16px auto 10px auto;
  text-align: center;
  min-width: 80px;
}
.mmp-difficulty-badge[data-difficulty="easy"] {
  background: linear-gradient(90deg, #b2ff59 0%, #ffe082 100%);
  color: #388e3c;
}
.mmp-difficulty-badge[data-difficulty="medium"] {
  background: linear-gradient(90deg, #ffe082 0%, #ffb001 100%);
  color: #b28704;
}
.mmp-difficulty-badge[data-difficulty="hard"] {
  background: linear-gradient(90deg, #ff8a65 0%, #ffb001 100%);
  color: #d84315;
}

.mmp-stats-card {
  position: sticky;
  top: 0;
  background: #fff;
  border-radius: 16px;
  margin-bottom: 22px;
  padding: 20px 18px 14px 18px;
  box-shadow: 0 2px 8px #ffb00111;
  z-index: 2;
  border-left: 5px solid #ffb001;
}

.mmp-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.13em;
  margin-bottom: 10px;
  color: #232946;
  font-weight: 700;
  letter-spacing: 0.2px;
  gap: 8px;
}
.mmp-stat-row span:first-child {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mmp-stat-row:last-child {
  margin-bottom: 0;
}

.mmp-stat-num {
  font-weight: 900;
  font-size: 1.32em;
  color: var(--mmp-primary);
  text-shadow: 0 2px 8px #5f2eea11;
}

.mmp-leaderboard-card {
  background: rgba(255,255,255,0.85);
  border-radius: 12px;
  box-shadow: 0 2px 8px #00c9a711;
  padding: 14px 10px 10px 10px;
  margin-top: 18px;
  font-size: 1.01em;
  backdrop-filter: var(--mmp-sidebar-glass);
}

.mmp-leaderboard-title {
  color: var(--mmp-secondary);
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.mmp-leaderboard-table th, .mmp-leaderboard-table td {
  padding: 4px 8px;
  text-align: left;
}

.mmp-leaderboard-table th {
  color: var(--mmp-primary);
  font-weight: 700;
}

.mmp-leaderboard-table tr {
  transition: background 0.18s;
}
.mmp-leaderboard-table tr.highlight {
  background: var(--mmp-accent);
  color: #fff;
  animation: mmp-pop 0.5s;
}
@keyframes mmp-pop {
  0% { transform: scale(1); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* === Responsive Design === */
@media (max-width: 900px) {
  .mmp-game-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 2vw 8px 2vw;
  }
  .mmp-sidebar {
    width: 100%;
    min-width: 0;
    margin-top: 0;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 8px;
    box-shadow: none;
    border-radius: 0 0 var(--mmp-radius) var(--mmp-radius);
    border-top: 1.5px solid #ececec;
    order: 2; /* Ensure sidebar appears after main game */
  }
  .mmp-game {
    order: 1;
  }
  .mmp-stats-card, .mmp-leaderboard-card {
    width: 100%;
    min-width: 0;
    margin-bottom: 8px;
  }
}

@media (max-width: 600px) {
  .mmp-game-layout {
      display: flex;
      flex-direction: column;
      gap: 24px;
      justify-content: center;
      align-items: flex-start;
      margin: 0 auto;
      max-width: 1200px;
      padding: 36px 4px 24px 4px;
      box-sizing: border-box;
  }
  .mmp-board-container {
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 2px 8px #ffb00111;
    padding: 10px 2px 8px 2px;
    margin: 0 2vw;
  }
  .mmp-board-header h2,
  .mmp-start-title {
    font-size: 1.25em !important;
    text-align: center !important;
    letter-spacing: 0.5px;
    background: none !important;
    -webkit-text-fill-color: initial !important;
    color: #232946 !important;
    font-weight: 800;
    margin-bottom: 10px;
    margin-top: 8px;
    white-space: normal;
    word-break: break-word;
  }
  .mmp-board {
    gap: 6px;
    min-height: 120px;
    padding-bottom: 24px;
    width: 100%;
    max-width: 100vw;
    overflow-x: auto;
    justify-content: center;
  }
  .mmp-card {
    font-size: 0.95em;
    border-radius: 8px;
    min-width: 38px;
    min-height: 38px;
    max-width: 48px;
    max-height: 48px;
  }
  .mmp-sidebar {
    flex-direction: column;
    width: 100%;
    gap: 8px;
    padding: 0 2vw;
    margin-top: 0;
    border-radius: 0 0 18px 18px;
    box-shadow: none;
    border: none;
  }
  .mmp-stats-card, .mmp-leaderboard-card {
    width: 100%;
    min-width: 0;
    margin-bottom: 8px;
    border-radius: 12px;
    padding: 10px 6px 8px 10px;
    font-size: 0.98em;
  }
  .mmp-leaderboard-table th, .mmp-leaderboard-table td {
    padding: 2px 4px;
    font-size: 0.98em;
  }
  .mmp-controls {
    gap: 6px;
    min-height: 38px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 6px;
  }
  .mmp-btn, .mmp-btn.mmp-btn-outline {
    display: flex;
    font-size: 0.98em;
    padding: 8px 0;
    min-width: 80px;
    border-radius: 10px;
    margin: 0 2px;
    width: auto;
    max-width: 100%;
    flex-direction: row;
    justify-content: center;
  }
  .mmp-tip-card {
    font-size: 0.98em;
    padding: 10px 8px 8px 10px;
    margin: 10px 0 0 0;
    border-radius: 10px;
  }
}

/* === Accessibility === */
.mmp-card:focus-visible, .mmp-btn:focus-visible {
  outline: 2.5px solid var(--mmp-secondary);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 8px;
  background: #e0e7ff;
}
::-webkit-scrollbar-thumb {
  background: #c3bff7;
  border-radius: 8px;
}

/* === Animated Background (Optional) === */
body.mmp-animated-bg {
  background: linear-gradient(120deg, #5f2eea 0%, #00c9a7 100%);
  background-size: 200% 200%;
  animation: mmp-bg-move 8s ease-in-out infinite;
}

@keyframes mmp-bg-move {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@media (min-width: 900px) {
  .mmp-start-card {
    margin-top: 12%;
    margin-bottom: auto;
    background: #fff;
    border-radius: 32px;
    box-shadow: 0 8px 32px 0 #ffb00122, 0 1.5px 6px #ffb00111;
    padding: 30px 25px 30px 25px;
    min-width: 336px;
    max-width: 86vw;
    text-align: center;
    /* margin: 42px auto; */
    animation: mmp-slide-up 0.7s;
  }
}

/* === Tip/Info Card === */
.mmp-tip-card {
  background: #fffde7;
  border: 2px solid #ffe082;
  border-radius: 16px;
  box-shadow: 0 2px 8px #ffb00111;
  padding: 18px 20px 14px 20px;
  margin: 18px 0 0 0;
  font-size: 1.08em;
  color: #b28704;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.mmp-tip-card .mmp-tip-icon {
  font-size: 1.3em;
  margin-right: 6px;
  color: #ffb001;
  flex-shrink: 0;
}

/* === Unique Shuffle Animation === */
.mmp-shuffling {
  animation: mmp-shuffle-fly 0.45s cubic-bezier(.4,0,.2,1);
  z-index: 2;
}
@keyframes mmp-shuffle-fly {
  0% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  40% {
    opacity: 0.2;
    transform: scale(0.7) translateY(-30px);
  }
  60% {
    opacity: 0.2;
    transform: scale(0.7) translateY(30px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
