Adjusts responsive layout with width observer

HTML

<div class="profile grid" data-width="0">
  <figure class="picture" data-width="0">
    <img src="https://upload.wikimedia.org/wikipedia/commons/0/08/Digital_design_of_woman_from_late_1980s_or_early_1990s.jpg" alt="Frau mit Telefon">
    <figcaption>Miss Management 1995</figcaption>
  </figure>
  <div class="description" data-width="0">
    <h2>Rechte Seite</h2>
    <p>Blinde Texte sind zu bedauern, sie sehen nichts, sie hören nichts, aber der Webseitenautor liebt sie doch. Denn was
wäre er ohne sie, er müsste ja ständig echten Inhalt bereithalten, um seine Seiten mit schwarzer Farbe zu füllen, und
wer möchte schon für jede Textdarstellung seine Tastatur für ein sldjfsdapkx seöoxfjarög aei3q04qf quälen?</p>
  </div>
  <dl class="info" data-width="0">
    <dt>Geburtstag</dt><dd>37.14.1954</dd>
    <dt>Telefon</dt><dd>+49-123 456789</dd>
    <dt>E-Mail</dt><dd>info@example.com</dd>
    <dt>Adresse</dt><dd>47471 Beispielhausen</dd>
  </dl>
</div>

<div class="profile flex" data-width="0">
  <figure class="picture" data-width="0">
    <img src="https://upload.wikimedia.org/wikipedia/commons/0/08/Digital_design_of_woman_from_late_1980s_or_early_1990s.jpg" alt="Frau mit Telefon">
    <figcaption>Miss Management 1995</figcaption>
  </figure>
  <div>
  <div class="description" data-width="0">
    <h2>Rechte Seite</h2>
    <p>Blinde Texte sind zu bedauern, sie sehen nichts, sie hören nichts, aber der Webseitenautor liebt sie doch. Denn was
wäre er ohne sie, er müsste ja ständig echten Inhalt bereithalten, um seine Seiten mit schwarzer Farbe zu füllen, und
wer möchte schon für jede Textdarstellung seine Tastatur für ein sldjfsdapkx seöoxfjarög aei3q04qf quälen?</p>
  </div>
  <dl class="info" data-width="0">
    <dt>Geburtstag</dt><dd>37.14.1954</dd>
    <dt>Telefon</dt><dd>+49-123 456789</dd>
    <dt>E-Mail</dt><dd>info@example.com</dd>
    <dt>Adresse</dt><dd>47471 Beispielhausen</dd>
  </dl>
  </div>
</div>

CSS

body {
  margin: 4px;
}
@media (width > 30em) {
  body {
    margin-inline: auto;
    padding-inline: 8px;
    max-width: 60em;
  }
}
.profile {
  padding-top: 1.5em;
  --gap: 0.5em;
  gap: 0 var(--gap);
}
.profile.grid {
  display: grid;
  grid: "links" "rechts" "info" / 1fr;
}
.profile.flex {
  display: flex;
  flex-flow: column;
  > * {
    flex: 1;
  }
  > :last-child {
    display: flex;
    flex-flow: column;
    > :first-child {
      flex: 1;
    }
  }
}

@media (width > 30em) {
  .profile.grid {
    grid: "links rechts" 1fr
          "links info" auto
          / minmax(calc(50% - var(--gap) / 2), 1fr) minmax(0em, 30em);;
  }
  .profile.flex {
    flex-flow: row;
    > :last-child {
      max-width: 30em;
    }
  }
}

.profile figure {
  grid-area: links;
  position: relative;
  background-color: #fcc;
  margin: 0;
}
.profile .picture img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile figcaption {
  display: block;
  background-color: #FFFC;
  font: 1.5em sans-serif;
  box-sizing: border-box;
  text-align: right;
  position:absolute;
  width: 100%;
  bottom: 0;
  padding: 1rem;
}

.profile .description {
  grid-area: rechts;
  background-color: #cfc;
  padding: 0em 1rem;
}

.profile .info { 
  grid-area: info;
  background-color: #222;
  color: white;
  
  display: grid;
  grid-template-columns: 6em 1fr;
  margin: 0;
  padding: 1em;
}
.profile .info > * { 
  margin: 0;
  padding: 0;
}
.profile .info dt {
  font-weight: bold;
}
.profile .info dt::after {
  content: ":";
}

/* Breiten-Watcher */
[data-width] {
  position: relative;
}
[data-width]::before {
  position: absolute;
  z-index: 1;
  content: attr(class) ": " attr(data-width) "px";
  background-color: #fffa;
  top:0; left: 0;
}

JavaScript

const widthWatcher = new ResizeObserver(
	entries => entries.forEach(
  	entry => entry.target.dataset.width = entry.borderBoxSize[0].inlineSize
  )
);
document.querySelectorAll("[data-width]").forEach(watched => widthWatcher.observe(watched));