.matrix-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.matrix-axis-labels {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  width: min(52vw, 520px);
  gap: 1px;
}

.matrix-axis-label {
  text-align: center;
  font-size: clamp(6px, 1.1vw, 10px);
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

#matrix-grid {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  grid-template-rows: repeat(13, 1fr);
  width: min(52vw, 520px);
  aspect-ratio: 1;
  gap: 1px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.matrix-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(6px, 1.15vw, 10px);
  font-weight: 700;
  font-family: var(--font-mono);
  cursor: pointer;
  background: var(--color-fold);
  color: rgba(255, 255, 255, 0.55);
  position: relative;
  overflow: hidden;
  transition: transform 0.1s ease;
  user-select: none;
}

.matrix-cell:hover {
  z-index: 2;
  transform: scale(1.15);
  box-shadow: 0 0 0 1px var(--border);
}

/* Heatmap overlay via pseudo-element */
.matrix-cell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--heatmap-overlay, transparent);
  pointer-events: none;
}

/* Action colors */
.matrix-cell.action-raise {
  background: var(--color-raise);
  color: rgba(255,255,255,0.85);
}

.matrix-cell.action-call {
  background: var(--color-call);
  color: rgba(255,255,255,0.85);
}

.matrix-cell.action-fold {
  background: var(--color-fold);
  color: rgba(255,255,255,0.45);
}

.matrix-cell.action-push {
  background: #8957e5;
  color: rgba(255,255,255,0.85);
}

.matrix-cell.action-allin {
  background: var(--color-allin);
  color: rgba(255,255,255,0.85);
}

/* Feedback flash states */
.matrix-cell.flash-correct {
  animation: flash-correct 0.7s ease-out forwards;
}

.matrix-cell.flash-wrong {
  animation: flash-wrong 0.7s ease-out forwards;
}

.matrix-cell.current-hand {
  outline: 2px solid #f0e68c;
  outline-offset: -2px;
  z-index: 1;
}

@keyframes flash-correct {
  0%   { box-shadow: inset 0 0 0 2px #2ea043, 0 0 12px #2ea04388; }
  100% { box-shadow: none; }
}

@keyframes flash-wrong {
  0%   { box-shadow: inset 0 0 0 2px #f85149, 0 0 12px #f8514988; }
  100% { box-shadow: none; }
}

/* Legend */
.matrix-legend {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-swatch.raise { background: var(--color-raise); }
.legend-swatch.call  { background: var(--color-call); }
.legend-swatch.fold  { background: var(--color-fold); }
.legend-swatch.push  { background: #8957e5; }

@media (max-width: 767px) {
  .matrix-axis-labels,
  #matrix-grid {
    width: min(94vw, 520px);
  }
}
