#matchify-game {
  width: 100%;
  touch-action: manipulation;
}

.matchify-box {
  text-align: center;
  padding: 0 !important;
  overflow: hidden;
}

.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  flex-wrap: wrap;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 10px;
  text-align: left;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.game-bar-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-bar-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 5px 12px;
  font-family: var(--font-family-primary);
  font-size: var(--font-size-s);
  text-transform: lowercase;
  white-space: nowrap;
}

.stat-label {
  font-weight: bold;
  opacity: 0.8;
}

.game-bar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.game-bar-actions .icon-button-bar {
  width: auto;
  height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-family-primary);
  font-size: var(--font-size-s);
  text-transform: lowercase;
  -webkit-mask-image: none !important;
  mask-image: none !important;
  touch-action: manipulation;
  color: var(--text-primary);
}

.icon-button-bar:hover {
  background: rgba(255, 255, 255, 0.25);
}

#matchify-settings {
  padding: 40px;
}

.matchify-subtitle {
  font-family: var(--font-family-secondary);
  font-size: var(--font-size-l);
  color: var(--text-wrappers);
  margin-bottom: 20px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  max-width: 520px;
  margin: 0 auto 25px;
  text-align: left;
}

.settings-group label {
  display: block;
  font-family: var(--font-family-primary);
  font-size: var(--font-size-s);
  font-weight: bold;
  opacity: 0.8;
  text-transform: lowercase;
  margin-bottom: 8px;
}

.settings-group select {
  width: 100%;
}

#matchify-settings #back-button {
  margin: 0 auto;
}

.matchify-stage {
  padding: 25px 30px;
  position: relative;
  overflow: hidden;
}

#matchify-game #game-board {
  display: grid;
  grid-gap: 14px;
  justify-items: center;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  position: relative;
  max-width: 700px;
  margin: 0 auto;
}

#matchify-game .card {
  width: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  cursor: pointer;
  perspective: 1000px;
}

#matchify-game .card-inner {
  position: absolute;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
  transition: transform 0.5s ease;
}

#matchify-game .card.flipped .card-inner {
  transform: rotateY(180deg);
}

#matchify-game .card.matched .card-inner {
  transform: rotateY(180deg);
}

#matchify-game .front,
#matchify-game .back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

#matchify-game .front {
  background: var(--bg-form-fields);
  border: 2px solid var(--border-form-fields);
  font-family: var(--font-family-secondary);
  font-size: var(--font-size-xl);
  color: var(--text-wrappers);
}

#matchify-game .back {
  transform: rotateY(180deg);
  background: var(--bg-form-fields);
  border: 2px solid var(--border-form-fields);
  padding: 8px;
  box-sizing: border-box;
}

#matchify-game .back img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 5px;
  object-fit: contain;
}

#win-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;

  z-index: 10;
  border-radius: 12px;
  background: var(--bg-wrappers);
  width: max-content;
  height: max-content;
  padding: 15px;
  font-size: var(--font-size-m);
}

#win-message p {
  font-size: inherit;
  font-weight: bold;
  font-family: var(--font-family-secondary);
}

#win-message.visible {
  display: flex;
}

#win-message canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: 8px;
}

#win-message .win-actions {
  display: flex;
  gap: 10px;
  z-index: 11;
  flex-wrap: wrap;
  justify-content: center;
}

#pairs-left.green  { color: #8de0a4; }
#pairs-left.orange { color: #f0c477; }
#pairs-left.red    { color: #ec8b8b; }

#matchify-game .hidden {
  display: none;
}

@media (max-width: 600px) {
  #matchify-settings {
    padding: 20px 16px;
  }

  .matchify-subtitle {
    font-size: var(--font-size-m);
    margin-bottom: 14px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .game-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    padding: 8px 10px;
    gap: 8px;
  }

  .game-bar-left {
    flex: 1;
    min-width: 0;
  }

  .game-bar-stats {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
    mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
  }

  .game-bar-stats::-webkit-scrollbar { display: none; }

  .stat-pill {
    padding: 4px 9px;
    font-size: 12px;
    flex-shrink: 0;
  }

  .game-bar-actions {
    flex-wrap: nowrap;
    flex-shrink: 0;
    gap: 6px;
  }

  .game-bar-actions .icon-button-bar {
    height: 34px;
    padding: 0;
    width: 34px;
    justify-content: center;
    border-radius: 50%;
  }

  .game-bar-actions .icon-button-bar span { display: none; }
  .game-bar-actions .icon-button-bar i   { font-size: 16px; }

  .matchify-stage {
    padding: 12px 10px;
  }

  #matchify-game #game-board {
    grid-gap: 8px;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  }
}