* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  background-color: #fafafa;
  overflow-y: scroll;
  overscroll-behavior: contain; /* Prevent overscroll bounce */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#grid-container {
  display: grid;
  grid-template-columns: repeat(3, 90px);
  gap: 5px;
  padding: 10px;
  width: 100%;
  max-width: 300px;
  grid-auto-flow: dense; /* Ensures a dense fill of items */
  justify-content: center;
}

.post {
  background-color: #eee;
  border: 1px solid #ddd;
  position: relative;
  overflow: hidden;
  min-width: 90px;
  min-height: 90px;
  max-width: 270px; /* Max width: 3 columns */
  max-height: 270px; /* Max height: 3 rows */
  cursor: default;
  transition: all 0.2s ease;
  border-radius: 4px;
}

.post:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

.post img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* Ensures images fit within the block */
  pointer-events: none; /* Prevent image from interfering with resize */
  transition: transform 0.2s ease;
}

.post:hover img {
  transform: scale(1.02);
}

.post::after {
  content: 'Drag Me';
  position: absolute;
  bottom: 5px;
  right: 5px;
  font-size: 10px;
  color: #888;
  pointer-events: none;
  background: rgba(255,255,255,0.8);
  padding: 2px 4px;
  border-radius: 2px;
  font-weight: 500;
}

/* Resize handle */
.post::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, transparent 0%, transparent 50%, #888 50%, #888 100%);
  cursor: nw-resize;
  z-index: 10;
  transition: all 0.2s ease;
}

.post:hover::before {
  background: linear-gradient(135deg, transparent 0%, transparent 50%, #007bff 50%, #007bff 100%);
  transform: scale(1.1);
}

.post.resizing {
  cursor: nw-resize;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transform: scale(1.01);
}

.post.resizing::after {
  content: 'Resizing...';
  color: #007bff;
  background: rgba(255,255,255,0.9);
  font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  #grid-container {
    grid-template-columns: repeat(auto-fit, 80px);
    gap: 3px;
    padding: 5px;
  }
  
  .post {
    min-width: 80px;
    min-height: 80px;
    max-width: 240px;
    max-height: 240px;
  }
  
  .post::after {
    font-size: 9px;
    bottom: 3px;
    right: 3px;
  }
  
  .post::before {
    width: 18px;
    height: 18px;
  }
}
