body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 1rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

fieldset,
.container {
  border: 2px solid red;
  background: #fff0d5;
  border-radius: 5px;
  margin-bottom: 15px;
}
legend {
  padding: 0 10px;
}

.container {
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 25px;

  @media (max-width: 1024px) {
    justify-content: center;
  }
}
/* comment */
.item {
  background: blue;
  color: #fff;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 14px 0;
  min-height: 56px;
}

/* niebieski*/
@scope (header:has([value="blue"]:checked) + .container) {
  .item {
    flex: 0 1 calc((100% - 50px) / 3);

    @media (max-width: 1024px) {
      flex: 0 1 100%;
      max-width: 60%;
    }
  }

  .item:nth-child(1) {
    order: 1;
  }
  .item:nth-child(2) {
    order: 2;
  }
  .item:nth-child(3) {
    order: 3;
  }
  .item:nth-child(4) {
    order: 4;
  }
  .item:nth-child(5) {
    order: 6;
  }

  :scope::after {
    content: '';
    flex: 0 1 calc((100% - 50px) / 3);
    order: 5;

    @media (max-width: 1024px) {
      display: none;
    }
  }
}

/* czerwone */
@scope (header:has([value="red"]:checked) + .container) {
  :scope {
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: stretch;

    @media (max-width: 1024px) {
      flex-wrap: wrap;
      justify-content: center;
      gap: 25px;
    }
  }

  .item {
    background: red;
    color: #fff;
    flex: 1 1 0;
    font-weight: 400;

    @media (max-width: 1024px) {
      flex: 1 1 calc(50% - 12.5px);
      max-width: calc(50% - 12.5px);
    }
  }

  .item:nth-child(1) {
    order: 3;
    flex: 1.5 1 0;
    font-weight: 700;

    @media (max-width: 1024px) {
      order: 3;
      flex: 1 1 100%;
      max-width: 100%;
    }

    &::after {
      content: 'Jestem większy i na środku!';
      font-size: 19px;
      font-weight: normal;
      display: block;
      margin-top: 5px;
    }
  }

  .item:nth-child(2) {
    order: 1;
  }
  .item:nth-child(3) {
    order: 2;
  }
  .item:nth-child(4) {
    order: 4;
  }
  .item:nth-child(5) {
    order: 5;
  }

  :scope::after {
    display: none;
  }
}

/* zielone */
@scope (header:has([value="green"]:checked) + .container) {
  :scope {
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: stretch;

    @media (max-width: 1024px) {
      flex-direction: column-reverse;
      gap: 30px;
    }
  }

  .item {
    background: green;
    color: #fff;
    flex: 1 1 0;
    position: relative;

    @media (max-width: 1024px) {
      flex: 0 0 auto;
      max-width: none;
      margin-left: auto;
    }
  }

  .item:nth-child(1) {
    flex-grow: 5;
    padding-left: 45px;
    padding-right: 45px;

    @media (max-width: 1024px) {
      width: 100%;
    }

    &::before,
    &::after {
      content: '😀';
      position: absolute;
      top: 50%;
      transform: translateY(-50%) scale(2);
      line-height: 1;
      pointer-events: none;
    }
    &::before {
      left: 10px;
    }
    &::after {
      right: 10px;
    }
  }

  .item:nth-child(2) {
    flex-grow: 4;

    @media (max-width: 1024px) {
      width: 80%;
    }
  }
  .item:nth-child(3) {
    flex-grow: 3;

    @media (max-width: 1024px) {
      width: 65%;
    }
  }
  .item:nth-child(4) {
    flex-grow: 2;

    @media (max-width: 1024px) {
      width: 50%;
    }
  }
  .item:nth-child(5) {
    flex-grow: 1;

    @media (max-width: 1024px) {
      width: 35%;
    }
  }

  :scope::after {
    display: none;
  }
}
