* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: system-ui, -apple-system, sans-serif; background: #f7f9fc; }

.panels {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  height: 100vh;
}

.top-row,
.bottom-row {
  display: flex;
  gap: 10px;
  height: 50%;
  transition: height 1s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: height;
}

.panel {
  background: #e6eefc;
  border-radius: 10px;
  overflow: hidden;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: width;
}

.row-expanded {
  height: 60%;
}

.row-collapsed {
  height: 40%;
}

.top-row .panel {
  width: 50%;
}

.bottom-row .panel {
  width: 33.333%;
}

.panel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (min-width: 640px) {
  .panels {
    grid-template-rows: 1fr 1fr;
    grid-template-columns: repeat(100, 1fr);
  }
  
  /* Top row: panels with variable width */
  .panels .panel:nth-child(1) { 
    grid-column: 1 / span var(--top-left-width); 
    grid-row: 1;
    width: 100%;
  }
  .panels .panel:nth-child(2) { 
    grid-column: calc(var(--top-left-width) + 1) / -1;
    grid-row: 1;
    width: 100%;
  }
  
  /* Bottom row: three equal panels */
  .panels .panel:nth-child(3) { 
    grid-column: 1 / 34; 
    grid-row: 2;
  }
  .panels .panel:nth-child(4) { 
    grid-column: 34 / 67; 
    grid-row: 2;
  }
  .panels .panel:nth-child(5) { 
    grid-column: 67 / -1; 
    grid-row: 2;
  }
}

@media (max-width: 639px) {
  .panels {
    gap: 10px;
  }
  
  .top-row,
  .bottom-row {
    flex-direction: column;
    height: auto !important;
  }
  
  .top-row .panel,
  .bottom-row .panel {
    width: 100% !important;
    height: 200px;
  }
  
  .row-expanded,
  .row-collapsed {
    height: auto !important;
  }
}